No more crash whith some assembler file :
[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) // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN !
270                 {
271                         i = 18;                  // Just a single symbol
272                 }
273                 else
274                 {
275                         i = 14;
276                 }
277         }
278         else
279         {
280                 attr |= FU_EXPR;
281
282                 for(len=0; fexpr[len]!=ENDEXPR; ++len)
283                 {
284                         if (fexpr[len] == CONST || fexpr[len] == SYMBOL)
285                                 ++len;
286                 }
287
288                 ++len;                                                // Add 1 for ENDEXPR 
289                 i = (len << 2) + 12;
290         }
291
292         // Maybe alloc another fixup chunk for this one to fit in
293         if ((fchalloc - fchsize) < i)
294         {
295                 p = &sect[cursect];
296                 cp = (CHUNK *)amem((long)(sizeof(CHUNK) + CH_FIXUP_SIZE));
297
298                 if (sfix == NULL)
299                 {                                 // First fixup chunk in section
300                         cp->chprev = NULL;
301                         p->sffix = cp;
302                 }
303                 else
304                 {                                           // Add to other chunks
305                         cp->chprev = sfix;
306                         sfix->chnext = cp;
307                         sfix->ch_size = fchsize;
308                 }
309
310                 // Setup fixup chunk and its global vars
311                 cp->chnext = NULL;
312                 fchalloc = cp->challoc = CH_FIXUP_SIZE;
313                 fchsize = cp->ch_size = 0;
314                 fchptr.cp = cp->chptr = ((char *)cp) + sizeof(CHUNK);
315                 sfix = p->sfix = cp;
316         }
317
318         // Record fixup type, fixup location, and the file number and line number the fixup is 
319         // located at.
320         *fchptr.wp++ = attr;
321         *fchptr.lp++ = loc;
322         *fchptr.wp++ = cfileno;
323         *fchptr.wp++ = (WORD)curlineno;
324
325         // Store postfix expression or pointer to a single symbol, or nothing for a mark.
326         if (attr & FU_EXPR)
327         {
328                 *fchptr.wp++ = (WORD)len;
329
330                 while (len--)
331                         *fchptr.lp++ = (LONG)*fexpr++;
332         }
333         else
334         {
335                 *fchptr.lp++ = (LONG)fexpr[1];
336         }
337
338         if ((attr & 0x0F00) == FU_JR)  // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN !
339         {
340                 if (orgactive)
341                         *fchptr.lp++ = orgaddr;
342                 else
343                         *fchptr.lp++ = 0x00000000;
344         }
345
346         fchsize += i;
347
348         return 0;
349 }
350
351
352 //
353 // Resolve all Fixups
354 //
355 int fixups(void)
356 {
357         unsigned i;
358         char buf[EBUFSIZ];
359
360         // Make undefined symbols GLOBL
361         if (glob_flag)
362                 syg_fix();
363
364         resfix(TEXT);
365         resfix(DATA);
366         
367         // We need to do a final check of forward 'jump' destination addresses that are external
368         for(i=0; i<MAXFWDJUMPS; i++)
369         {
370                 if (fwdjump[i])
371                 {
372                         err_setup();
373                         sprintf(buf, "* \'jump\' at $%08X - destination address is external to this source file and cannot have its aligment validated", fwdjump[i]);
374
375                         if (listing > 0)
376                                 ship_ln(buf);
377
378                         if (err_flag)
379                                 write(err_fd, buf, (LONG)strlen(buf));
380                         else
381                                 printf("%s\n", buf);
382                 }
383         }
384
385         return 0;
386 }
387
388
389 //
390 // Resolve Fixups in a Section
391 //
392 int resfix(int sno)
393 {
394         SECT * sc;                                      // Section
395         CHUNK * ch;
396         PTR fup;                                        // Current fixup
397         WORD * fuend;                           // End of last fixup (in this chunk)
398         CHUNK * cch;                            // Cached chunk for target
399         WORD w;                                         // Fixup word (type+modes+flags)
400         char * locp;                            // Location to fix (in cached chunk) 
401         LONG loc;                                       // Location to fixup
402         VALUE eval;                                     // Expression value 
403         WORD eattr;                                     // Expression attrib
404         SYM * esym;                                     // External symbol involved in expr
405         SYM * sy;                                       // (Temp) pointer to a symbol
406         WORD i;                                         // (Temp) word
407         WORD tdb;                                       // eattr & TDB
408         LONG oaddr;
409         int reg2;
410         WORD flags;
411         unsigned page_jump = 0;
412         unsigned address = 0;
413         unsigned j;
414         char buf[EBUFSIZ];
415         
416         sc = &sect[sno];
417         ch = sc->sffix;
418
419         if (ch == NULL)
420                 return 0;
421
422         cch = sc->sfcode;                                        // "cache" first chunk
423
424         if (cch == NULL)                                          // Can't fixup a sect with nothing in it
425                 return 0;
426
427         do
428         {
429                 fup.cp = ch->chptr;                                   // fup -> start of chunk
430                 fuend = (WORD *)(fup.cp + ch->ch_size);               // fuend -> end of chunk
431
432                 while (fup.wp < fuend)
433                 {
434                         w = *fup.wp++;
435                         loc = *fup.lp++;
436                         cfileno = *fup.wp++;
437                         curlineno = (int)*fup.wp++;
438
439                         esym = NULL;
440
441                         // Search for chunk containing location to fix up; compute a pointer to the location 
442                         // (in the chunk). Often we will find the fixup is in the "cached" chunk, so the 
443                         // linear-search is seldom executed.
444                         if (loc < cch->chloc || loc >= (cch->chloc + cch->ch_size))
445                         {
446                                 for(cch=sc->sfcode; cch!=NULL; cch=cch->chnext)
447                                 {
448                                         if (loc >= cch->chloc && loc < (cch->chloc + cch->ch_size))
449                                                 break;
450                                 }
451
452                                 if (cch == NULL)
453                                 {
454                                         interror(7);                                 // Fixup (loc) out of range 
455                                         // NOTREACHED
456                                 }
457                         }
458
459                         locp = cch->chptr + (loc - cch->chloc);
460
461                         eattr = 0;
462
463                         // Compute expression/symbol value and attribs
464                         if (w & FU_EXPR)
465                         {                                  // Complex expression
466                                 i = *fup.wp++;
467
468                                 if (evexpr(fup.tk, &eval, &eattr, &esym) != OK)
469                                 {
470                                         fup.lp += i;
471                                         continue;
472                                 }
473
474                                 fup.lp += i;
475                         }
476                         else
477                         {                                           // Simple symbol
478                                 sy = *fup.sy++;
479                                 eattr = sy->sattr;
480
481                                 if (eattr & DEFINED)
482                                         eval = sy->svalue;
483                                 else
484                                         eval = 0;
485
486                                 if ((eattr & (GLOBAL|DEFINED)) == GLOBAL)
487                                         esym = sy;
488                         }
489
490                         tdb = (WORD)(eattr & TDB);
491
492                         // If the expression is undefined and no external symbol is
493                         // involved, then it's an error.
494                         if (!(eattr & DEFINED) && esym == NULL)
495                         {
496                                 error(undef_error);
497                                 continue;
498                         }
499
500                         if (((w & 0x0F00) == FU_MOVEI) && esym)
501                                 esym->sattre |= RISCSYM;
502
503                         // Do the fixup
504                         // 
505                         // If a PC-relative fixup is undefined, its value is *not* subtracted from the location
506                         // (that will happen in the linker when the external reference is resolved).
507                         // 
508                         // MWC expects PC-relative things to have the LOC subtracted from the value, if the 
509                         // value is external (that is, undefined at this point).
510                         // 
511                         // PC-relative fixups must be DEFINED and either in the same section (whereupon the 
512                         // subtraction takes place) or ABS (with no subtract).
513                         if (w & FU_PCREL)
514                         {
515                                 if (eattr & DEFINED)
516                                 {
517                                         if (tdb == sno)
518                                                 eval -= (VALUE)loc;
519                                         else if (tdb)
520                                         {
521                                                 error("PC-relative expr across sections");
522                                                 continue;
523                                         }
524
525                                         if (sbra_flag && (w & FU_LBRA) && (eval + 0x80 < 0x100))
526                                                 warn("unoptimized short branch");
527                                 }
528                                 else if (obj_format == MWC)
529                                         eval -= (VALUE)loc;
530
531                                 tdb = 0;
532                                 eattr &= ~TDB;
533                         }
534
535                         // Do fixup classes
536                         switch ((int)(w & FUMASK))
537                         {
538                         // FU_BBRA fixes up a one-byte branch offset.
539                         case FU_BBRA:
540                                 if (!(eattr & DEFINED))
541                                 {
542                                         error("external short branch");
543                                         continue;
544                                 }
545
546                                 eval -= 2;
547
548                                 if (eval + 0x80 >= 0x100)
549                                         goto range;
550
551                                 if (eval == 0)
552                                 {
553                                         error("illegal bra.s with zero offset");
554                                         continue;
555                                 }
556
557                                 *++locp = (char)eval;
558                                 break;
559                         // Fixup one-byte value at locp + 1.
560                         case FU_WBYTE:
561                                 ++locp;
562                                 // FALLTHROUGH
563                         // Fixup one-byte forward references
564                         case FU_BYTE:
565                                 if (!(eattr & DEFINED))
566                                 {
567                                         error("external byte reference");
568                                         continue;
569                                 }
570
571                                 if (tdb)
572                                 {
573                                         error("non-absolute byte reference");
574                                         continue;
575                                 }
576
577                                 if ((w & FU_PCREL) && eval + 0x80 >= 0x100)
578                                         goto range;
579
580                                 if (w & FU_SEXT)
581                                 {
582                                         if (eval + 0x100 >= 0x200)
583                                                 goto range;
584                                 }
585                                 else if (eval >= 0x100)
586                                         goto range;
587
588                                 *locp = (char)eval;
589                                 break;
590                         // Fixup WORD forward references; 
591                         // the word could be unaligned in the section buffer, so we have to be careful.
592                         case FU_WORD:
593                                 if (((w & 0x0F00) == FU_JR) || ((w & 0x0F00) == FU_MJR))
594                                 {
595                                         oaddr = *fup.lp++;
596
597                                         if (oaddr)
598                                         {
599                                                 reg2 = (signed)((eval - (oaddr + 2)) / 2);// & 0x1F;
600                                         }
601                                         else
602                                         {
603                                                 reg2 = (signed)((eval - (loc + 2)) / 2);// & 0x1F;
604                                         }
605
606                                         if ((w & 0x0F00) == FU_MJR)
607                                         {
608                                                 // Main code destination alignment checking here for forward declared labels
609                                                 address = (oaddr) ? oaddr : loc;
610
611                                                 if (((address >= 0xF03000) && (address < 0xF04000)
612                                                         && (eval < 0xF03000)) || ((eval >= 0xF03000)
613                                                         && (eval < 0xF04000) && (address < 0xF03000)))
614                                                 {
615                                                         warni("* \'jr\' at $%08X - cannot jump relative between "
616                                                                 "main memory and local gpu ram", address);
617                                                 }
618                                                 else
619                                                 {
620                                                         page_jump = (address & 0xFFFFFF00) - (eval & 0xFFFFFF00);
621
622                                                         if (page_jump)
623                                                         {
624                                                                 // This jump is to a page outside of the current 256 byte page
625                                                                 if (eval % 4)
626                                                                 {
627                                                                         warni("* \'jr\' at $%08X - destination address not aligned for long page jump, insert a \'nop\' before the destination address", address);
628                                                                 }
629                                                         }
630                                                         else
631                                                         {
632                                                                 // This jump is in the current 256 byte page
633                                                                 if ((eval - 2) % 4)
634                                                                 {
635                                                                         warni("* \'jr\' at $%08X - destination address not aligned for short page jump, insert a \'nop\' before the destination address", address);
636                                                                 }
637                                                         }
638                                                 }
639                                         }
640
641                                         if ((reg2 < -16) || (reg2 > 15))
642                                         {
643                                                 error("relative jump out of range");
644                                                 break;
645                                         }
646
647                                         *locp = (char)(*locp | ((reg2 >> 3) & 0x03));
648                                         locp++;
649                                         *locp = (char)(*locp | ((reg2 & 0x07) << 5));
650                                         break;
651                                 }
652
653                                 if ((w & 0x0F00) == FU_NUM15)
654                                 {
655                                         if (eval < -16 || eval > 15)
656                                         {
657                                                 error("constant out of range");
658                                                 break;
659                                         }
660
661                                         *locp = (char)(*locp | ((eval >> 3) & 0x03));
662                                         locp++;
663                                         *locp = (char)(*locp | ((eval & 0x07) << 5));
664                                         break;
665                                 }
666
667                                 if ((w & 0x0F00) == FU_NUM31)
668                                 {
669                                         if (eval < 0 || eval > 31)
670                                         {
671                                                 error("constant out of range");
672                                                 break;
673                                         }
674
675                                         *locp = (char)(*locp | ((eval >> 3) & 0x03));
676                                         locp++;
677                                         *locp = (char)(*locp | ((eval & 0x07) << 5));
678                                         break;
679                                 }
680
681                                 if ((w & 0x0F00) == FU_NUM32)
682                                 {
683                                         if (eval < 1 || eval > 32)
684                                         {
685                                                 error("constant out of range");
686                                                 break;
687                                         }
688
689                                         if (w & FU_SUB32)
690                                                 eval = (32 - eval);
691
692                                         eval = (eval == 32) ? 0 : eval;
693                                         *locp = (char)(*locp | ((eval >> 3) & 0x03));
694                                         locp++;
695                                         *locp = (char)(*locp | ((eval & 0x07) << 5));
696                                         break;
697                                 }
698
699                                 if ((w & 0x0F00) == FU_REGONE)
700                                 {
701                                         if (eval < 0 || eval > 31)
702                                         {
703                                                 error("register value out of range");
704                                                 break;
705                                         }
706
707                                         *locp = (char)(*locp | ((eval >> 3) & 0x03));
708                                         locp++;
709                                         *locp = (char)(*locp | ((eval & 0x07) << 5));
710                                         break;
711                                 }
712
713                                 if ((w & 0x0F00) == FU_REGTWO)
714                                 {
715                                         if (eval < 0 || eval > 31)
716                                         {
717                                                 error("register value out of range");
718                                                 break;
719                                         }
720
721                                         locp++;
722                                         *locp = (char)(*locp | (eval & 0x1F));
723                                         break;
724                                 }
725
726                                 if (!(eattr & DEFINED))
727                                 {
728                                         if (w & FU_PCREL)
729                                                 w = MPCREL | MWORD;
730                                         else
731                                                 w = MWORD;
732
733                                         rmark(sno, loc, 0, w, esym);
734                                 }
735                                 else
736                                 {
737                                         if (tdb)
738                                                 rmark(sno, loc, tdb, MWORD, NULL);
739
740                                         if (w & FU_SEXT)
741                                         {
742                                                 if (eval + 0x10000 >= 0x20000)
743                                                         goto range;
744                                         }
745                                         else
746                                         {
747                                                 // Range-check BRA and DBRA
748                                                 if (w & FU_ISBRA)
749                                                 {
750                                                         if (eval + 0x8000 >= 0x10000)
751                                                         goto range;
752                                                 }
753                                                 else if (eval >= 0x10000)
754                                                         goto range;
755                                         }
756                                 }
757
758                                 *locp++ = (char)(eval >> 8);
759                                 *locp = (char)eval;
760                                 break;
761                         // Fixup LONG forward references;
762                         // the long could be unaligned in the section buffer, so be careful (again).
763                         case FU_LONG:
764                                 if ((w & 0x0F00) == FU_MOVEI)
765                                 {
766                                         address = loc + 4;
767
768                                         if (eattr & DEFINED)
769                                         {
770                                                 for(j=0; j<fwindex; j++)
771                                                 {
772                                                         if (fwdjump[j] == address)
773                                                         {
774                                                                 page_jump = (address & 0xFFFFFF00) - (eval & 0xFFFFFF00);
775
776                                                                 if (page_jump)
777                                                                 {
778                                                                         if (eval % 4)
779                                                                         {
780                                                                                 err_setup();
781                                                                                 sprintf(buf, "* \'jump\' at $%08X - destination address not aligned for long page jump, insert a \'nop\' before the destination address", address);
782
783                                                                                 if (listing > 0)
784                                                                                         ship_ln(buf);
785
786                                                                                 if (err_flag)
787                                                                                         write(err_fd, buf, (LONG)strlen(buf));
788                                                                                 else
789                                                                                         printf("%s\n", buf);
790                                                                         }          
791                                                                 }
792                                                                 else
793                                                                 {
794                                                                         if (!(eval & 0x0000000F) || ((eval - 2) % 4))
795                                                                         {
796                                                                                 err_setup();
797                                                                                 sprintf(buf, "* \'jump\' at $%08X - destination address not aligned for short page jump, insert a \'nop\' before the destination address", address);
798
799                                                                                 if (listing > 0)
800                                                                                         ship_ln(buf);
801
802                                                                                 if (err_flag)
803                                                                                         write(err_fd, buf, (LONG)strlen(buf));
804                                                                                 else
805                                                                                         printf("%s\n", buf);
806                                                                         }          
807                                                                 }
808
809                                                                 // Clear this jump as it has been checked
810                                                                 fwdjump[j] = 0;
811                                                                 j = fwindex;
812                                                         }
813                                                 }
814                                         }
815
816                                         eval = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000);
817                                         flags = (MLONG|MMOVEI);
818                                 }
819                                 else
820                                         flags = MLONG;
821
822                                 if (!(eattr & DEFINED))
823                                 {
824                                         rmark(sno, loc, 0, flags, esym);
825                                 }
826                                 else if (tdb)
827                                 {
828                                         rmark(sno, loc, tdb, flags, NULL);
829                                 }
830
831                                 *locp++ = (char)(eval >> 24);
832                                 *locp++ = (char)(eval >> 16);
833                                 *locp++ = (char)(eval >> 8);
834                                 *locp = (char)eval;
835                                 break;
836                         // Fixup a 3-bit "QUICK" reference in bits 9..1
837                         // (range of 1..8) in a word.  Really bits 1..3 in a byte.
838                         case FU_QUICK:
839                                 if (!(eattr & DEFINED))
840                                 {
841                                         error("External quick reference");
842                                         continue;
843                                 }
844
845                                 if (eval < 1 || eval > 8)
846                                         goto range;
847
848                                 *locp |= (eval & 7) << 1;
849                                 break;
850                         // Fix up 6502 funny branch
851                         case FU_6BRA:
852                                 eval -= (loc + 1);
853
854                                 if (eval + 0x80 >= 0x100)
855                                         goto range;
856
857                                 *locp = (char)eval;
858                                 break;
859                         default:
860                                 interror(4);                                 // Bad fixup type
861                                 // NOTREACHED
862                         }
863                         continue;
864 range:
865                         error("expression out of range");
866                 }
867
868                 ch = ch->chnext;
869         }
870         while (ch != NULL);
871
872         return 0;
873 }