]> Shamusworld >> Repos - rmac/blob - sect.c
More readability cleanups.
[rmac] / sect.c
1 //
2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // SECT.C - Code Generation, Fixups and Section Management
4 // Copyright (C) 199x Landon Dyer, 2011 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source Utilised with the Kind Permission of Landon Dyer
7 //
8
9 #include "sect.h"
10 #include "error.h"
11 #include "mach.h"
12 #include "token.h"
13 #include "mark.h"
14 #include "expr.h"
15 #include "symbol.h"
16 #include "risca.h"
17 #include "listing.h"
18
19 // Section descriptors
20 SECT sect[NSECTS];                                          // All sections... 
21 int cursect;                                                // Current section number
22
23 // These are copied from the section descriptor, the current code chunk descriptor and the current
24 // fixup chunk descriptor when a switch is made into a section.  They are copied back to the 
25 // descriptors when the section is left.
26 WORD scattr;                                                // Section attributes 
27 LONG sloc;                                                  // Current loc in section 
28
29 CHUNK * scode;                                              // Current (last) code chunk 
30 LONG challoc;                                               // #bytes alloc'd to code chunk 
31 LONG ch_size;                                               // #bytes used in code chunk 
32 char * chptr;                                               // Deposit point in code chunk buffer 
33
34 CHUNK * sfix;                                               // Current (last) fixup chunk
35 LONG fchalloc;                                              // #bytes alloc'd to fixup chunk
36 LONG fchsize;                                               // #bytes used in fixup chunk
37 PTR fchptr;                                                 // Deposit point in fixup chunk buffer
38
39 unsigned fwdjump[MAXFWDJUMPS];                              // forward jump check table
40 unsigned fwindex = 0;                                       // forward jump index
41
42 // Return a size (SIZB, SIZW, SIZL) or 0, depending on what kind of fixup is associated
43 // with a location.
44 static char fusiztab[] = {
45    0,                                                       // FU_QUICK
46    1,                                                       // FU_BYTE
47    2,                                                       // FU_WORD
48    2,                                                       // FU_WBYTE
49    4,                                                       // FU_LONG
50    1,                                                       // FU_BBRA
51    0,                                                       // (unused)
52    1,                                                       // FU_6BRA
53 };
54
55 // Offset to REAL fixup location
56 static char fusizoffs[] = {
57    0,                                                       // FU_QUICK
58    0,                                                       // FU_BYTE
59    0,                                                       // FU_WORD
60    1,                                                       // FU_WBYTE
61    0,                                                       // FU_LONG
62    1,                                                       // FU_BBRA
63    0,                                                       // (unused)
64    0,                                                       // FU_6BRA
65 };
66
67
68 //
69 // Make a New (Clean) Section
70 //
71 void mksect(int sno, WORD attr)
72 {
73         SECT * p;                                                 // Section pointer
74
75         p = &sect[sno];
76         p->scattr = attr;
77         p->sloc = 0;
78         p->scode = p->sfcode = NULL;
79         p->sfix = p->sffix = NULL;
80 }
81
82
83 //
84 // Switch to Another Section (Copy Section & Chunk Descriptors to Global Vars
85 // for Fast Access)
86 //
87 void switchsect(int sno)
88 {
89         SECT * p;                                                // Section pointer
90         CHUNK * cp;                                              // Chunk pointer
91
92         cursect = sno;
93         p = &sect[sno];
94
95         scattr = p->scattr;                                      // Copy section vars
96         sloc = p->sloc;
97         scode = p->scode;
98         sfix = p->sfix;
99
100         if ((cp = scode) != NULL)
101         {                               // Copy code chunk vars
102                 challoc = cp->challoc;
103                 ch_size = cp->ch_size;
104                 chptr = cp->chptr + ch_size;
105         }
106         else
107                 challoc = ch_size = 0;
108
109         if ((cp = sfix) != NULL)
110         {                                // Copy fixup chunk vars 
111                 fchalloc = cp->challoc;
112                 fchsize = cp->ch_size;
113                 fchptr.cp = cp->chptr + fchsize;
114         }
115         else
116                 fchalloc = fchsize = 0;
117 }
118
119
120 //
121 // Save Current Section
122 //
123 void savsect(void)
124 {
125         SECT * p = &sect[cursect];
126
127         p->scattr = scattr;                                      // Bailout section vars
128         p->sloc = sloc;
129
130         if (scode != NULL)                                        // Bailout code chunk
131                 scode->ch_size = ch_size;
132
133         if (sfix != NULL)                                         // Bailout fixup chunk
134                 sfix->ch_size = fchsize;
135 }
136
137
138 //
139 // Initialize Sections; Setup initial ABS, TEXT, DATA and BSS sections
140 //
141 void init_sect(void)
142 {
143         int i;                                                   // Iterator
144
145         // Cleanup all sections
146         for(i=0; i<NSECTS; ++i)
147                 mksect(i, 0);
148
149         // Construct default sections, make TEXT the current section
150         mksect(ABS,   SUSED|SABS|SBSS);                          // ABS
151         mksect(TEXT,  SUSED|TEXT     );                          // TEXT
152         mksect(DATA,  SUSED|DATA     );                          // DATA
153         mksect(BSS,   SUSED|BSS |SBSS);                          // BSS
154 //      mksect(M6502, SUSED|TEXT     );                          // 6502 code section
155
156         switchsect(TEXT);                                        // Switch to TEXT for starters
157 }
158
159
160 //
161 // Test to see if a location has a fixup sic'd on it.  This is used by the
162 // listing generator to print 'xx's instead of '00's for forward references
163 //
164 int fixtest(int sno, LONG loc)
165 {
166         CHUNK * ch;
167         PTR fup;
168         char * fuend;
169         WORD w;
170         LONG xloc;
171
172         stopmark();                                              // Force update to sect[] variables
173
174         // Hairy, ugly linear search for a mark on our location;
175         // the speed doesn't matter, since this is only done when generating a listing, which is SLOW.
176         for(ch=sect[sno].sffix; ch!=NULL; ch=ch->chnext)
177         {
178                 fup.cp = (char *)ch->chptr;
179                 fuend = fup.cp + ch->ch_size;
180
181                 while (fup.cp < fuend)
182                 {
183                         w = *fup.wp++;
184                         xloc = *fup.lp++ + (int)fusizoffs[w & FUMASK];
185                         fup.wp += 2;
186
187                         if (xloc == loc)
188                                 return (int)fusiztab[w & FUMASK];
189
190                         if (w & FU_EXPR)
191                         {
192                                 w = *fup.wp++;
193                                 fup.lp += w;
194                         }
195                         else
196                                 ++fup.lp;
197                 }
198         }
199
200         return 0;
201 }
202
203
204 // 
205 // Check that there are at least `amt' bytes left in the current chunk. If
206 // there are not, allocate another chunk of at least `amt' bytes (and probably
207 // more).
208 // 
209 // If `amt' is zero, ensure there are at least CH_THRESHOLD bytes, likewise.
210 //
211 int chcheck(LONG amt)
212 {
213         CHUNK * cp;
214         SECT * p;
215
216         if (scattr & SBSS)
217                 return 0;                             // If in BSS section, forget it
218
219         if (!amt)
220                 amt = CH_THRESHOLD;
221
222         if ((int)(challoc - ch_size) >= (int)amt) 
223                 return 0;
224
225         if (amt < CH_CODE_SIZE)
226                 amt = CH_CODE_SIZE;
227
228         p = &sect[cursect];
229         cp = (CHUNK *)amem((long)(sizeof(CHUNK) + amt));
230
231         if (scode == NULL)
232         {                                      // First chunk in section
233                 cp->chprev = NULL;
234                 p->sfcode = cp;
235         }
236         else
237         {                                                 // Add chunk to other chunks
238                 cp->chprev = scode;
239                 scode->chnext = cp;
240                 scode->ch_size = ch_size;                             // Save old chunk's globals 
241         }
242
243         // Setup chunk and global vars
244         cp->chloc = sloc;
245         cp->chnext = NULL;
246         challoc = cp->challoc = amt;
247         ch_size = cp->ch_size = 0;
248         chptr = cp->chptr = ((char *)cp) + sizeof(CHUNK);
249         scode = p->scode = cp;
250
251         return 0;
252 }
253
254
255 //
256 // Arrange for a fixup on a location
257 //
258 int fixup(WORD attr, LONG loc, TOKEN * fexpr)
259 {
260         LONG i;
261         LONG len = 0;
262         CHUNK * cp;
263         SECT * p;
264
265         // Compute length of expression (could be faster); determine if it's the single-symbol case;
266         // no expression if it's just a mark. This code assumes 16 bit WORDs and 32 bit LONGs
267         if (*fexpr == SYMBOL && fexpr[2] == ENDEXPR)
268         {
269                 //if ((attr & 0x0F00) == FU_JR) {
270                 if ((attr & 0x0200) == FU_JR)
271                 {
272                         i = 18;                  // Just a single symbol
273                 }
274                 else
275                 {
276                         i = 14;
277                 }
278         }
279         else
280         {
281                 attr |= FU_EXPR;
282
283                 for(len=0; fexpr[len]!=ENDEXPR; ++len)
284                 {
285                         if (fexpr[len] == CONST || fexpr[len] == SYMBOL)
286                                 ++len;
287                 }
288
289                 ++len;                                                // Add 1 for ENDEXPR 
290                 i = (len << 2) + 12;
291         }
292
293         // Maybe alloc another fixup chunk for this one to fit in
294         if ((fchalloc - fchsize) < i)
295         {
296                 p = &sect[cursect];
297                 cp = (CHUNK *)amem((long)(sizeof(CHUNK) + CH_FIXUP_SIZE));
298
299                 if (sfix == NULL)
300                 {                                 // First fixup chunk in section
301                         cp->chprev = NULL;
302                         p->sffix = cp;
303                 }
304                 else
305                 {                                           // Add to other chunks
306                         cp->chprev = sfix;
307                         sfix->chnext = cp;
308                         sfix->ch_size = fchsize;
309                 }
310
311                 // Setup fixup chunk and its global vars
312                 cp->chnext = NULL;
313                 fchalloc = cp->challoc = CH_FIXUP_SIZE;
314                 fchsize = cp->ch_size = 0;
315                 fchptr.cp = cp->chptr = ((char *)cp) + sizeof(CHUNK);
316                 sfix = p->sfix = cp;
317         }
318
319         // Record fixup type, fixup location, and the file number and line number the fixup is 
320         // located at.
321         *fchptr.wp++ = attr;
322         *fchptr.lp++ = loc;
323         *fchptr.wp++ = cfileno;
324         *fchptr.wp++ = (WORD)curlineno;
325
326         // Store postfix expression or pointer to a single symbol, or nothing for a mark.
327         if (attr & FU_EXPR)
328         {
329                 *fchptr.wp++ = (WORD)len;
330
331                 while (len--)
332                         *fchptr.lp++ = (LONG)*fexpr++;
333         }
334         else
335         {
336                 *fchptr.lp++ = (LONG)fexpr[1];
337         }
338
339         //if ((attr & 0x0F00) == FU_JR) {
340         if ((attr & 0x0200) == FU_JR)
341         {
342                 if (orgactive)
343                         *fchptr.lp++ = orgaddr;
344                 else
345                         *fchptr.lp++ = 0x00000000;
346         }
347
348         fchsize += i;
349
350         return 0;
351 }
352
353
354 //
355 // Resolve all Fixups
356 //
357 int fixups(void)
358 {
359         unsigned i;
360         char buf[EBUFSIZ];
361
362         // Make undefined symbols GLOBL
363         if (glob_flag)
364                 syg_fix();
365
366         resfix(TEXT);
367         resfix(DATA);
368         
369         // We need to do a final check of forward 'jump' destination addresses that are external
370         for(i=0; i<MAXFWDJUMPS; i++)
371         {
372                 if (fwdjump[i])
373                 {
374                         err_setup();
375                         sprintf(buf, "* \'jump\' at $%08X - destination address is external to this source file and cannot have its aligment validated", fwdjump[i]);
376
377                         if (listing > 0)
378                                 ship_ln(buf);
379
380                         if (err_flag)
381                                 write(err_fd, buf, (LONG)strlen(buf));
382                         else
383                                 printf("%s\n", buf);
384                 }
385         }
386
387         return 0;
388 }
389
390
391 //
392 // Resolve Fixups in a Section
393 //
394 int resfix(int sno)
395 {
396         SECT * sc;                                      // Section
397         CHUNK * ch;
398         PTR fup;                                        // Current fixup
399         WORD * fuend;                           // End of last fixup (in this chunk)
400         CHUNK * cch;                            // Cached chunk for target
401         WORD w;                                         // Fixup word (type+modes+flags)
402         char * locp;                            // Location to fix (in cached chunk) 
403         LONG loc;                                       // Location to fixup
404         VALUE eval;                                     // Expression value 
405         WORD eattr;                                     // Expression attrib
406         SYM * esym;                                     // External symbol involved in expr
407         SYM * sy;                                       // (Temp) pointer to a symbol
408         WORD i;                                         // (Temp) word
409         WORD tdb;                                       // eattr & TDB
410         LONG oaddr;
411         int reg2;
412         WORD flags;
413         unsigned page_jump = 0;
414         unsigned address = 0;
415         unsigned j;
416         char buf[EBUFSIZ];
417         
418         sc = &sect[sno];
419         ch = sc->sffix;
420
421         if (ch == NULL)
422                 return 0;
423
424         cch = sc->sfcode;                                        // "cache" first chunk
425
426         if (cch == NULL)                                          // Can't fixup a sect with nothing in it
427                 return 0;
428
429         do
430         {
431                 fup.cp = ch->chptr;                                   // fup -> start of chunk
432                 fuend = (WORD *)(fup.cp + ch->ch_size);               // fuend -> end of chunk
433
434                 while (fup.wp < fuend)
435                 {
436                         w = *fup.wp++;
437                         loc = *fup.lp++;
438                         cfileno = *fup.wp++;
439                         curlineno = (int)*fup.wp++;
440
441                         esym = NULL;
442
443                         // Search for chunk containing location to fix up; compute a pointer to the location 
444                         // (in the chunk). Often we will find the fixup is in the "cached" chunk, so the 
445                         // linear-search is seldom executed.
446                         if (loc < cch->chloc || loc >= (cch->chloc + cch->ch_size))
447                         {
448                                 for(cch=sc->sfcode; cch!=NULL; cch=cch->chnext)
449                                 {
450                                         if (loc >= cch->chloc && loc < (cch->chloc + cch->ch_size))
451                                                 break;
452                                 }
453
454                                 if (cch == NULL)
455                                 {
456                                         interror(7);                                 // Fixup (loc) out of range 
457                                         // NOTREACHED
458                                 }
459                         }
460
461                         locp = cch->chptr + (loc - cch->chloc);
462
463                         eattr = 0;
464
465                         // Compute expression/symbol value and attribs
466                         if (w & FU_EXPR)
467                         {                                  // Complex expression
468                                 i = *fup.wp++;
469
470                                 if (evexpr(fup.tk, &eval, &eattr, &esym) != OK)
471                                 {
472                                         fup.lp += i;
473                                         continue;
474                                 }
475
476                                 fup.lp += i;
477                         }
478                         else
479                         {                                           // Simple symbol
480                                 sy = *fup.sy++;
481                                 eattr = sy->sattr;
482
483                                 if (eattr & DEFINED)
484                                         eval = sy->svalue;
485                                 else
486                                         eval = 0;
487
488                                 if ((eattr & (GLOBAL|DEFINED)) == GLOBAL)
489                                         esym = sy;
490                         }
491
492                         tdb = (WORD)(eattr & TDB);
493
494                         // If the expression is undefined and no external symbol is
495                         // involved, then it's an error.
496                         if (!(eattr & DEFINED) && esym == NULL)
497                         {
498                                 error(undef_error);
499                                 continue;
500                         }
501
502                         if (((w & 0x0F00) == FU_MOVEI) && esym)
503                                 esym->sattre |= RISCSYM;
504
505                         // Do the fixup
506                         // 
507                         // If a PC-relative fixup is undefined, its value is *not* subtracted from the location
508                         // (that will happen in the linker when the external reference is resolved).
509                         // 
510                         // MWC expects PC-relative things to have the LOC subtracted from the value, if the 
511                         // value is external (that is, undefined at this point).
512                         // 
513                         // PC-relative fixups must be DEFINED and either in the same section (whereupon the 
514                         // subtraction takes place) or ABS (with no subtract).
515                         if (w & FU_PCREL)
516                         {
517                                 if (eattr & DEFINED)
518                                 {
519                                         if (tdb == sno)
520                                                 eval -= (VALUE)loc;
521                                         else if (tdb)
522                                         {
523                                                 error("PC-relative expr across sections");
524                                                 continue;
525                                         }
526
527                                         if (sbra_flag && (w & FU_LBRA) && (eval + 0x80 < 0x100))
528                                                 warn("unoptimized short branch");
529                                 }
530                                 else if (obj_format == MWC)
531                                         eval -= (VALUE)loc;
532
533                                 tdb = 0;
534                                 eattr &= ~TDB;
535                         }
536
537                         // Do fixup classes
538                         switch ((int)(w & FUMASK))
539                         {
540                         // FU_BBRA fixes up a one-byte branch offset.
541                         case FU_BBRA:
542                                 if (!(eattr & DEFINED))
543                                 {
544                                         error("external short branch");
545                                         continue;
546                                 }
547
548                                 eval -= 2;
549
550                                 if (eval + 0x80 >= 0x100)
551                                         goto range;
552
553                                 if (eval == 0)
554                                 {
555                                         error("illegal bra.s with zero offset");
556                                         continue;
557                                 }
558
559                                 *++locp = (char)eval;
560                                 break;
561                         // Fixup one-byte value at locp + 1.
562                         case FU_WBYTE:
563                                 ++locp;
564                                 // FALLTHROUGH
565                         // Fixup one-byte forward references
566                         case FU_BYTE:
567                                 if (!(eattr & DEFINED))
568                                 {
569                                         error("external byte reference");
570                                         continue;
571                                 }
572
573                                 if (tdb)
574                                 {
575                                         error("non-absolute byte reference");
576                                         continue;
577                                 }
578
579                                 if ((w & FU_PCREL) && eval + 0x80 >= 0x100)
580                                         goto range;
581
582                                 if (w & FU_SEXT)
583                                 {
584                                         if (eval + 0x100 >= 0x200)
585                                                 goto range;
586                                 }
587                                 else if (eval >= 0x100)
588                                         goto range;
589
590                                 *locp = (char)eval;
591                                 break;
592                         // Fixup WORD forward references; 
593                         // the word could be unaligned in the section buffer, so we have to be careful.
594                         case FU_WORD:
595                                 if (((w & 0x0F00) == FU_JR) || ((w & 0x0F00) == FU_MJR))
596                                 {
597                                         oaddr = *fup.lp++;
598
599                                         if (oaddr)
600                                         {
601                                                 reg2 = (signed)((eval - (oaddr + 2)) / 2);// & 0x1F;
602                                         }
603                                         else
604                                         {
605                                                 reg2 = (signed)((eval - (loc + 2)) / 2);// & 0x1F;
606                                         }
607
608                                         if ((w & 0x0F00) == FU_MJR)
609                                         {
610                                                 // Main code destination alignment checking here for forward declared labels
611                                                 address = (oaddr) ? oaddr : loc;
612
613                                                 if (((address >= 0xF03000) && (address < 0xF04000)
614                                                         && (eval < 0xF03000)) || ((eval >= 0xF03000)
615                                                         && (eval < 0xF04000) && (address < 0xF03000)))
616                                                 {
617                                                         warni("* \'jr\' at $%08X - cannot jump relative between "
618                                                                 "main memory and local gpu ram", address);
619                                                 }
620                                                 else
621                                                 {
622                                                         page_jump = (address & 0xFFFFFF00) - (eval & 0xFFFFFF00);
623
624                                                         if (page_jump)
625                                                         {
626                                                                 // This jump is to a page outside of the current 256 byte page
627                                                                 if (eval % 4)
628                                                                 {
629                                                                         warni("* \'jr\' at $%08X - destination address not aligned for long page jump, insert a \'nop\' before the destination address", address);
630                                                                 }
631                                                         }
632                                                         else
633                                                         {
634                                                                 // This jump is in the current 256 byte page
635                                                                 if ((eval - 2) % 4)
636                                                                 {
637                                                                         warni("* \'jr\' at $%08X - destination address not aligned for short page jump, insert a \'nop\' before the destination address", address);
638                                                                 }
639                                                         }
640                                                 }
641                                         }
642
643                                         if ((reg2 < -16) || (reg2 > 15))
644                                         {
645                                                 error("relative jump out of range");
646                                                 break;
647                                         }
648
649                                         *locp = (char)(*locp | ((reg2 >> 3) & 0x03));
650                                         locp++;
651                                         *locp = (char)(*locp | ((reg2 & 0x07) << 5));
652                                         break;
653                                 }
654
655                                 if ((w & 0x0F00) == FU_NUM15)
656                                 {
657                                         if (eval < -16 || eval > 15)
658                                         {
659                                                 error("constant out of range");
660                                                 break;
661                                         }
662
663                                         *locp = (char)(*locp | ((eval >> 3) & 0x03));
664                                         locp++;
665                                         *locp = (char)(*locp | ((eval & 0x07) << 5));
666                                         break;
667                                 }
668
669                                 if ((w & 0x0F00) == FU_NUM31)
670                                 {
671                                         if (eval < 0 || eval > 31)
672                                         {
673                                                 error("constant out of range");
674                                                 break;
675                                         }
676
677                                         *locp = (char)(*locp | ((eval >> 3) & 0x03));
678                                         locp++;
679                                         *locp = (char)(*locp | ((eval & 0x07) << 5));
680                                         break;
681                                 }
682
683                                 if ((w & 0x0F00) == FU_NUM32)
684                                 {
685                                         if (eval < 1 || eval > 32)
686                                         {
687                                                 error("constant out of range");
688                                                 break;
689                                         }
690
691                                         if (w & FU_SUB32)
692                                                 eval = (32 - eval);
693
694                                         eval = (eval == 32) ? 0 : eval;
695                                         *locp = (char)(*locp | ((eval >> 3) & 0x03));
696                                         locp++;
697                                         *locp = (char)(*locp | ((eval & 0x07) << 5));
698                                         break;
699                                 }
700
701                                 if ((w & 0x0F00) == FU_REGONE)
702                                 {
703                                         if (eval < 0 || eval > 31)
704                                         {
705                                                 error("register value out of range");
706                                                 break;
707                                         }
708
709                                         *locp = (char)(*locp | ((eval >> 3) & 0x03));
710                                         locp++;
711                                         *locp = (char)(*locp | ((eval & 0x07) << 5));
712                                         break;
713                                 }
714
715                                 if ((w & 0x0F00) == FU_REGTWO)
716                                 {
717                                         if (eval < 0 || eval > 31)
718                                         {
719                                                 error("register value out of range");
720                                                 break;
721                                         }
722
723                                         locp++;
724                                         *locp = (char)(*locp | (eval & 0x1F));
725                                         break;
726                                 }
727
728                                 if (!(eattr & DEFINED))
729                                 {
730                                         if (w & FU_PCREL)
731                                                 w = MPCREL | MWORD;
732                                         else
733                                                 w = MWORD;
734
735                                         rmark(sno, loc, 0, w, esym);
736                                 }
737                                 else
738                                 {
739                                         if (tdb)
740                                                 rmark(sno, loc, tdb, MWORD, NULL);
741
742                                         if (w & FU_SEXT)
743                                         {
744                                                 if (eval + 0x10000 >= 0x20000)
745                                                         goto range;
746                                         }
747                                         else
748                                         {
749                                                 // Range-check BRA and DBRA
750                                                 if (w & FU_ISBRA)
751                                                 {
752                                                         if (eval + 0x8000 >= 0x10000)
753                                                         goto range;
754                                                 }
755                                                 else if (eval >= 0x10000)
756                                                         goto range;
757                                         }
758                                 }
759
760                                 *locp++ = (char)(eval >> 8);
761                                 *locp = (char)eval;
762                                 break;
763                         // Fixup LONG forward references;
764                         // the long could be unaligned in the section buffer, so be careful (again).
765                         case FU_LONG:
766                                 if ((w & 0x0F00) == FU_MOVEI)
767                                 {
768                                         address = loc + 4;
769
770                                         if (eattr & DEFINED)
771                                         {
772                                                 for(j=0; j<fwindex; j++)
773                                                 {
774                                                         if (fwdjump[j] == address)
775                                                         {
776                                                                 page_jump = (address & 0xFFFFFF00) - (eval & 0xFFFFFF00);
777
778                                                                 if (page_jump)
779                                                                 {
780                                                                         if (eval % 4)
781                                                                         {
782                                                                                 err_setup();
783                                                                                 sprintf(buf, "* \'jump\' at $%08X - destination address not aligned for long page jump, insert a \'nop\' before the destination address", address);
784
785                                                                                 if (listing > 0)
786                                                                                         ship_ln(buf);
787
788                                                                                 if (err_flag)
789                                                                                         write(err_fd, buf, (LONG)strlen(buf));
790                                                                                 else
791                                                                                         printf("%s\n", buf);
792                                                                         }          
793                                                                 }
794                                                                 else
795                                                                 {
796                                                                         if (!(eval & 0x0000000F) || ((eval - 2) % 4))
797                                                                         {
798                                                                                 err_setup();
799                                                                                 sprintf(buf, "* \'jump\' at $%08X - destination address not aligned for short page jump, insert a \'nop\' before the destination address", address);
800
801                                                                                 if (listing > 0)
802                                                                                         ship_ln(buf);
803
804                                                                                 if (err_flag)
805                                                                                         write(err_fd, buf, (LONG)strlen(buf));
806                                                                                 else
807                                                                                         printf("%s\n", buf);
808                                                                         }          
809                                                                 }
810
811                                                                 // Clear this jump as it has been checked
812                                                                 fwdjump[j] = 0;
813                                                                 j = fwindex;
814                                                         }
815                                                 }
816                                         }
817
818                                         eval = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000);
819                                         flags = (MLONG|MMOVEI);
820                                 }
821                                 else
822                                         flags = MLONG;
823
824                                 if (!(eattr & DEFINED))
825                                 {
826                                         rmark(sno, loc, 0, flags, esym);
827                                 }
828                                 else if (tdb)
829                                 {
830                                         rmark(sno, loc, tdb, flags, NULL);
831                                 }
832
833                                 *locp++ = (char)(eval >> 24);
834                                 *locp++ = (char)(eval >> 16);
835                                 *locp++ = (char)(eval >> 8);
836                                 *locp = (char)eval;
837                                 break;
838                         // Fixup a 3-bit "QUICK" reference in bits 9..1
839                         // (range of 1..8) in a word.  Really bits 1..3 in a byte.
840                         case FU_QUICK:
841                                 if (!(eattr & DEFINED))
842                                 {
843                                         error("External quick reference");
844                                         continue;
845                                 }
846
847                                 if (eval < 1 || eval > 8)
848                                         goto range;
849
850                                 *locp |= (eval & 7) << 1;
851                                 break;
852                         // Fix up 6502 funny branch
853                         case FU_6BRA:
854                                 eval -= (loc + 1);
855
856                                 if (eval + 0x80 >= 0x100)
857                                         goto range;
858
859                                 *locp = (char)eval;
860                                 break;
861                         default:
862                                 interror(4);                                 // Bad fixup type
863                                 // NOTREACHED
864                         }
865                         continue;
866 range:
867                         error("expression out of range");
868                 }
869
870                 ch = ch->chnext;
871         }
872         while (ch != NULL);
873
874         return 0;
875 }