static void _xa51_genAssemblerPreamble (FILE * of) { symbol *mainExists=newSymbol("main", 0); mainExists->block=0; if ((mainExists=findSymWithLevel(SymbolTab, mainExists))) { fprintf (of, "\t.area GSINIT\t(CODE)\n"); fprintf (of, "__interrupt_vect:\n"); fprintf (of, "\t.dw\t0x8f00\n"); fprintf (of, "\t.dw\t__sdcc_gsinit_startup\n"); fprintf (of, "\n"); fprintf (of, "__sdcc_gsinit_startup:\n"); fprintf (of, ";\tmov.b\t_SCR,#0x01\t; page zero mode\n"); fprintf (of, "\t.db 0x96,0x48,0x40,0x01\n"); fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc); fprintf (of, "\tcall\t_external_startup\n"); _xa51_genXINIT(of); fprintf (of, "\t.area CSEG\t(CODE)\n"); fprintf (of, "\tcall\t_main\n"); fprintf (of, "\treset\t;main should not return\n"); } }
/*-----------------------------------------------------------------*/ static void pic14createInterruptVect (struct dbuf_s * vBuf) { mainf = newSymbol ("main", 0); mainf->block = 0; /* only if the main function exists */ if (!(mainf = findSymWithLevel (SymbolTab, mainf))) { struct options *op = &options; if (!(op->cc_only || noAssemble)) // werror (E_NO_MAIN); fprintf(stderr,"WARNING: function 'main' undefined\n"); return; } /* if the main is only a prototype ie. no body then do nothing */ if (!IFFUNC_HASBODY(mainf->type)) { /* if ! compile only then main function should be present */ if (!(options.cc_only || noAssemble)) // werror (E_NO_MAIN); fprintf(stderr,"WARNING: function 'main' undefined\n"); return; } dbuf_printf (vBuf, "%s", iComments2); dbuf_printf (vBuf, "; reset vector \n"); dbuf_printf (vBuf, "%s", iComments2); // Lkr file should place section STARTUP at address 0x0, but does not ... dbuf_printf (vBuf, "STARTUP\t%s 0x0000\n", CODE_NAME); dbuf_printf (vBuf, "\tnop\n"); /* first location for used by incircuit debugger */ dbuf_printf (vBuf, "\tpagesel __sdcc_gsinit_startup\n"); dbuf_printf (vBuf, "\tgoto\t__sdcc_gsinit_startup\n"); popGetExternal("__sdcc_gsinit_startup", 0); }
/*-----------------------------------------------------------------*/ int allocVariables (symbol * symChain) { symbol *sym; symbol *csym; int stack = 0; int saveLevel = 0; /* go thru the symbol chain */ for (sym = symChain; sym; sym = sym->next) { /* if this is a typedef then add it */ /* to the typedef table */ if (IS_TYPEDEF (sym->etype)) { /* check if the typedef already exists */ csym = findSym (TypedefTab, NULL, sym->name); if (csym && csym->level == sym->level) werror (E_DUPLICATE_TYPEDEF, sym->name); SPEC_EXTR (sym->etype) = 0; addSym (TypedefTab, sym, sym->name, sym->level, sym->block, 0); continue; /* go to the next one */ } /* make sure it already exists */ csym = findSymWithLevel (SymbolTab, sym); if (!csym || (csym && csym->level != sym->level)) csym = sym; /* check the declaration */ checkDecl (csym, 0); /* if this is a function or a pointer to a */ /* function then do args processing */ if (funcInChain (csym->type)) { processFuncArgs (csym); } /* if this is an extern variable then change */ /* the level to zero temporarily */ if (IS_EXTERN (csym->etype) || IS_FUNC (csym->type)) { saveLevel = csym->level; csym->level = 0; } /* if this is a literal then it is an enumerated */ /* type so need not allocate it space for it */ if (IS_LITERAL (sym->etype)) continue; /* generate the actual declaration */ if (csym->level) { allocLocal (csym); if (csym->onStack) stack += getSize (csym->type); } else allocGlobal (csym); /* restore the level */ if (IS_EXTERN (csym->etype) || IS_FUNC (csym->type)) csym->level = saveLevel; } return stack; }
/*-----------------------------------------------------------------*/ void picglue () { FILE *asmFile; struct dbuf_s ovrBuf; struct dbuf_s vBuf; dbuf_init(&ovrBuf, 4096); dbuf_init(&vBuf, 4096); pCodeInitRegisters(); /* check for main() */ mainf = newSymbol ("main", 0); mainf->block = 0; mainf = findSymWithLevel (SymbolTab, mainf); if (!mainf || !IFFUNC_HASBODY(mainf->type)) { /* main missing -- import stack from main module */ //fprintf (stderr, "main() missing -- assuming we are NOT the main module\n"); pic14_options.isLibrarySource = 1; } /* At this point we've got all the code in the form of pCode structures */ /* Now it needs to be rearranged into the order it should be placed in the */ /* code space */ movepBlock2Head('P'); // Last movepBlock2Head(code->dbName); movepBlock2Head('X'); movepBlock2Head(statsg->dbName); // First /* print the global struct definitions */ if (options.debug) cdbStructBlock (0); /* do the overlay segments */ pic14emitOverlay(&ovrBuf); /* PENDING: this isnt the best place but it will do */ if (port->general.glue_up_main) { /* create the interrupt vector table */ pic14createInterruptVect (&vBuf); } AnalyzepCode('*'); ReuseReg(); // ReuseReg where call tree permits InlinepCode(); AnalyzepCode('*'); if (options.debug) pcode_test(); /* now put it all together into the assembler file */ /* create the assembler file name */ if ((noAssemble || options.c1mode) && fullDstFileName) { sprintf (buffer, "%s", fullDstFileName); } else { sprintf (buffer, "%s", dstFileName); strcat (buffer, ".asm"); } if (!(asmFile = fopen (buffer, "w"))) { werror (E_FILE_OPEN_ERR, buffer); exit (1); } /* prepare statistics */ resetpCodeStatistics (); /* initial comments */ pic14initialComments (asmFile); /* print module name */ fprintf (asmFile, "%s\t.file\t\"%s\"\n", options.debug ? "" : ";", fullSrcFileName); /* Let the port generate any global directives, etc. */ if (port->genAssemblerPreamble) { port->genAssemblerPreamble(asmFile); } /* Put all variables into a cblock */ AnalyzeBanking(); /* emit initialized data */ showAllMemmaps(asmFile); /* print the locally defined variables in this module */ writeUsedRegs(asmFile); /* create the overlay segments */ fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; overlayable items in internal ram \n"); fprintf (asmFile, "%s", iComments2); dbuf_write_and_destroy (&ovrBuf, asmFile); /* copy the interrupt vector table */ if (mainf && IFFUNC_HASBODY(mainf->type)) dbuf_write_and_destroy (&vBuf, asmFile); else dbuf_destroy(&vBuf); /* create interupt ventor handler */ pic14_emitInterruptHandler (asmFile); /* copy over code */ fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; code\n"); fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "code_%s\t%s\n", moduleName, port->mem.code_name); /* unknown */ copypCode(asmFile, 'X'); /* _main function */ copypCode(asmFile, 'M'); /* other functions */ copypCode(asmFile, code->dbName); /* unknown */ copypCode(asmFile, 'P'); dumppCodeStatistics (asmFile); fprintf (asmFile,"\tend\n"); fclose (asmFile); pic14_debugLogClose(); }
static void _hc08_genAssemblerPreamble (FILE * of) { int i; int needOrg = 1; symbol *mainExists=newSymbol("main", 0); mainExists->block=0; fprintf (of, "\t.area %s\n",HOME_NAME); fprintf (of, "\t.area GSINIT0 (CODE)\n"); fprintf (of, "\t.area %s\n",port->mem.static_name); fprintf (of, "\t.area %s\n",port->mem.post_static_name); fprintf (of, "\t.area %s\n",CODE_NAME); fprintf (of, "\t.area %s\n",port->mem.xinit_name); fprintf (of, "\t.area %s\n",port->mem.const_name); fprintf (of, "\t.area %s\n",port->mem.data_name); fprintf (of, "\t.area %s\n",port->mem.overlay_name); fprintf (of, "\t.area %s\n",port->mem.xdata_name); fprintf (of, "\t.area %s\n",port->mem.xidata_name); if ((mainExists=findSymWithLevel(SymbolTab, mainExists))) { // generate interrupt vector table fprintf (of, "\t.area\tCODEIVT (ABS)\n"); for (i=maxInterrupts; i>0; i--) { if (interrupts[i]) { if (needOrg) { fprintf (of, "\t.org\t0x%04x\n", (0xfffe - (i * 2))); needOrg = 0; } fprintf (of, "\t.dw\t%s\n", interrupts[i]->rname); } else needOrg = 1; } if (needOrg) fprintf (of, "\t.org\t0xfffe\n"); fprintf (of, "\t.dw\t%s", "__sdcc_gs_init_startup\n\n"); fprintf (of, "\t.area GSINIT0\n"); fprintf (of, "__sdcc_gs_init_startup:\n"); if (options.stack_loc) { fprintf (of, "\tldhx\t#0x%04x\n", options.stack_loc+1); fprintf (of, "\ttxs\n"); } else fprintf (of, "\trsp\n"); fprintf (of, "\tjsr\t__sdcc_external_startup\n"); fprintf (of, "\tbeq\t__sdcc_init_data\n"); fprintf (of, "\tjmp\t__sdcc_program_startup\n"); fprintf (of, "__sdcc_init_data:\n"); fprintf (of, "; _hc08_genXINIT() start\n"); fprintf (of, " ldhx #0\n"); fprintf (of, "00001$:\n"); fprintf (of, " cphx #l_XINIT\n"); fprintf (of, " beq 00002$\n"); fprintf (of, " lda s_XINIT,x\n"); fprintf (of, " sta s_XISEG,x\n"); fprintf (of, " aix #1\n"); fprintf (of, " bra 00001$\n"); fprintf (of, "00002$:\n"); fprintf (of, "; _hc08_genXINIT() end\n"); fprintf (of, "\t.area GSFINAL\n"); fprintf (of, "\tjmp\t__sdcc_program_startup\n\n"); fprintf (of, "\t.area CSEG\n"); fprintf (of, "__sdcc_program_startup:\n"); fprintf (of, "\tjsr\t_main\n"); fprintf (of, "\tbra\t.\n"); } }