X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=sect.c;h=fe630b15d3a2f8aaf1b4f8a36ac0d33f34b65f78;hp=3fd627a409560ea80ad3c38f5fc47ac1db93ffa1;hb=75969398d9b8a9f82ea76fc4e4cbfb97b11160a4;hpb=233e5e908f5a865233f775520dc35917f13d2d26 diff --git a/sect.c b/sect.c index 3fd627a..fe630b1 100644 --- a/sect.c +++ b/sect.c @@ -13,67 +13,89 @@ #include "listing.h" #include "mach.h" #include "mark.h" -#include "risca.h" +#include "riscasm.h" #include "symbol.h" #include "token.h" + +// Function prototypes +void mksect(int, WORD); +void switchsect(int); + // Section descriptors -SECT sect[NSECTS]; // All sections... -int cursect; // Current section number +SECT sect[NSECTS]; // All sections... +int cursect; // Current section number // These are copied from the section descriptor, the current code chunk // descriptor and the current fixup chunk descriptor when a switch is made into // a section. They are copied back to the descriptors when the section is left. -WORD scattr; // Section attributes -LONG sloc; // Current loc in section +WORD scattr; // Section attributes +LONG sloc; // Current loc in section -CHUNK * scode; // Current (last) code chunk -LONG challoc; // # bytes alloc'd to code chunk -LONG ch_size; // # bytes used in code chunk -char * chptr; // Deposit point in code chunk buffer +CHUNK * scode; // Current (last) code chunk +LONG challoc; // # bytes alloc'd to code chunk +LONG ch_size; // # bytes used in code chunk +char * chptr; // Deposit point in code chunk buffer -CHUNK * sfix; // Current (last) fixup chunk -LONG fchalloc; // # bytes alloc'd to fixup chunk -LONG fchsize; // # bytes used in fixup chunk -PTR fchptr; // Deposit point in fixup chunk buffer - -unsigned fwdjump[MAXFWDJUMPS]; // forward jump check table -unsigned fwindex = 0; // forward jump index +CHUNK * sfix; // Current (last) fixup chunk +LONG fchalloc; // # bytes alloc'd to fixup chunk +LONG fchsize; // # bytes used in fixup chunk +PTR fchptr; // Deposit point in fixup chunk buffer // Return a size (SIZB, SIZW, SIZL) or 0, depending on what kind of fixup is // associated with a location. static char fusiztab[] = { - 0, // FU_QUICK - 1, // FU_BYTE - 2, // FU_WORD - 2, // FU_WBYTE - 4, // FU_LONG - 1, // FU_BBRA - 0, // (unused) - 1, // FU_6BRA + 0, // FU_QUICK + 1, // FU_BYTE + 2, // FU_WORD + 2, // FU_WBYTE + 4, // FU_LONG + 1, // FU_BBRA + 0, // (unused) + 1, // FU_6BRA }; // Offset to REAL fixup location static char fusizoffs[] = { - 0, // FU_QUICK - 0, // FU_BYTE - 0, // FU_WORD - 1, // FU_WBYTE - 0, // FU_LONG - 1, // FU_BBRA - 0, // (unused) - 0, // FU_6BRA + 0, // FU_QUICK + 0, // FU_BYTE + 0, // FU_WORD + 1, // FU_WBYTE + 0, // FU_LONG + 1, // FU_BBRA + 0, // (unused) + 0, // FU_6BRA }; +// +// Initialize Sections; Setup initial ABS, TEXT, DATA and BSS sections +// +void InitSection(void) +{ + int i; + + // Cleanup all sections + for(i=0; iscattr = attr; p->sloc = 0; p->scode = p->sfcode = NULL; @@ -125,39 +147,17 @@ void savsect(void) { SECT * p = §[cursect]; - p->scattr = scattr; // Bailout section vars + p->scattr = scattr; // Bailout section vars p->sloc = sloc; - if (scode != NULL) // Bailout code chunk + if (scode != NULL) // Bailout code chunk scode->ch_size = ch_size; - if (sfix != NULL) // Bailout fixup chunk + if (sfix != NULL) // Bailout fixup chunk sfix->ch_size = fchsize; } -// -// Initialize Sections; Setup initial ABS, TEXT, DATA and BSS sections -// -void init_sect(void) -{ - int i; - - // Cleanup all sections - for(i=0; i= (int)amt) return 0; if (amt < CH_CODE_SIZE) amt = CH_CODE_SIZE; + DEBUG { printf(" amt (adjusted)=%u\n", amt); } SECT * p = §[cursect]; CHUNK * cp = malloc(sizeof(CHUNK) + amt); @@ -266,7 +269,8 @@ int fixup(WORD attr, LONG loc, TOKEN * fexpr) LONG len = 0; CHUNK * cp; SECT * p; - // Shamus: Expression lengths are voodoo ATM (varibale "i"). Need to fix this. + // Shamus: Expression lengths are voodoo ATM (variable "i"). Need to fix this. +#warning "!!! fixup() is filled with VOODOO !!!" DEBUG printf("FIXUP@$%X: $%X\n", loc, attr); // Compute length of expression (could be faster); determine if it's the @@ -383,7 +387,9 @@ int ResolveAllFixups(void) ResolveFixups(TEXT); DEBUG printf("Resolving DATA sections...\n"); ResolveFixups(DATA); - + +//No, no we don't. +#if 0 // We need to do a final check of forward 'jump' destination addresses that // are external for(i=0; i 15)) { @@ -790,6 +799,7 @@ int ResolveFixups(int sno) case FU_LONG: if ((w & 0x0F00) == FU_MOVEI) { +#if 0 address = loc + 4; if (eattr & DEFINED) @@ -839,27 +849,33 @@ int ResolveFixups(int sno) } } } +#endif eval = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000); - flags = (MLONG|MMOVEI); + flags = (MLONG | MMOVEI); } else flags = MLONG; if (!(eattr & DEFINED)) { +//printf("Fixup (long): Symbol undefined. loc = $%X, long = $%X, flags = $%x\n", loc, eval, flags); rmark(sno, loc, 0, flags, esym); } else if (tdb) { +//printf("Fixup (long): TDB = $%X. loc =$%X, long = $%X, flags = $%x\n", tdb, loc, eval, flags); rmark(sno, loc, tdb, flags, NULL); } +//else +//printf("Fixup (long): TDB = $%X. loc =$%X, long = $%X, flags = $%x\n", tdb, loc, eval, flags); *locp++ = (char)(eval >> 24); *locp++ = (char)(eval >> 16); *locp++ = (char)(eval >> 8); *locp = (char)eval; break; + // Fixup a 3-bit "QUICK" reference in bits 9..1 // (range of 1..8) in a word. Really bits 1..3 in a byte. case FU_QUICK: @@ -874,6 +890,7 @@ int ResolveFixups(int sno) *locp |= (eval & 7) << 1; break; + // Fix up 6502 funny branch case FU_6BRA: eval -= (loc + 1); @@ -883,6 +900,7 @@ int ResolveFixups(int sno) *locp = (char)eval; break; + default: interror(4); // Bad fixup type // NOTREACHED @@ -898,3 +916,4 @@ range: return 0; } +