OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [AS64/] [source/] [Table888mmu.cpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2014  Robert Finch, Stratford
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// A64 - Assembler
9
//  - 64 bit CPU
10
//
11
// This source file is free software: you can redistribute it and/or modify 
12
// it under the terms of the GNU Lesser General Public License as published 
13
// by the Free Software Foundation, either version 3 of the License, or     
14
// (at your option) any later version.                                      
15
//                                                                          
16
// This source file is distributed in the hope that it will be useful,      
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
19
// GNU General Public License for more details.                             
20
//                                                                          
21
// You should have received a copy of the GNU General Public License        
22
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
23
//                                                                          
24
// ============================================================================
25
//
26
#include "stdafx.h"
27
 
28
static void emitAlignedCode(int cd);
29
static void process_shifti(int oc);
30
static void ProcessEOL(int opt);
31
 
32
extern int first_rodata;
33
extern int first_data;
34
extern int first_bss;
35
static int64_t ca;
36
 
37
int use_gp = 0;
38
 
39
// ---------------------------------------------------------------------------
40
// ---------------------------------------------------------------------------
41
 
42
static void emit_insn(int64_t oc)
43
{
44
     emitAlignedCode(oc & 255);
45
     emitCode((oc >> 8) & 255);
46
     emitCode((oc >> 16) & 255);
47
     emitCode((oc >> 24) & 255);
48
     emitCode((oc >> 32) & 255);
49
}
50
 
51
// ---------------------------------------------------------------------------
52
// ---------------------------------------------------------------------------
53
 
54
static void emit_insn2(int64_t oc)
55
{
56
     emitCode(oc & 255);
57
     emitCode((oc >> 8) & 255);
58
     emitCode((oc >> 16) & 255);
59
     emitCode((oc >> 24) & 255);
60
     emitCode((oc >> 32) & 255);
61
}
62
 
63
 
64
// ---------------------------------------------------------------------------
65
// Emit code aligned to a code address.
66
// ---------------------------------------------------------------------------
67
 
68
static void emitAlignedCode(int cd)
69
{
70
     int64_t ad;
71
 
72
     ad = code_address & 15;
73
     while (ad != 0 && ad != 5 && ad != 10) {
74
         emitByte(0x00);
75
         ad = code_address & 15;
76
     }
77
     ad = code_address & 0xfff;
78
     if ((ad > 0xFF0 && cd == 0xFD) || (ad > 0xFEA && cd == 0x61)) {
79
         emit_insn(0xEAEAEAEAEA);
80
         emit_insn(0xEAEAEAEAEA);
81
         if (cd==0x61)
82
             emit_insn(0xEAEAEAEAEA);
83
         ProcessEOL(0);
84
         ad = code_address & 0xfff;
85
         while (ad != 0 && ad != 5 && ad != 10) {
86
             emitByte(0x00);
87
             ad = code_address & 15;
88
         }
89
     }
90
     emitByte(cd);
91
}
92
 
93
 
94
// ---------------------------------------------------------------------------
95
// Emit constant extension for memory operands.
96
// ---------------------------------------------------------------------------
97
 
98
static void emitImm0(int64_t v, int force)
99
{
100
     if (v != 0 || force) {
101
          emitAlignedCode(0xfd);
102
          emitCode(v & 255);
103
          emitCode((v >> 8) & 255);
104
          emitCode((v >> 16) & 255);
105
          emitCode((v >> 24) & 255);
106
     }
107
     if (((v < 0) && ((v >> 32) != -1L)) || ((v > 0) && ((v >> 32) != 0L)) || (force && data_bits > 32)) {
108
          emitAlignedCode(0xfe);
109
          emitCode((v >> 32) & 255);
110
          emitCode((v >> 40) & 255);
111
          emitCode((v >> 48) & 255);
112
          emitCode((v >> 56) & 255);
113
     }
114
}
115
 
116
// ---------------------------------------------------------------------------
117
// Emit constant extension for memory operands.
118
// ---------------------------------------------------------------------------
119
 
120
static void emitImm2(int64_t v, int force)
121
{
122
     if (v < 0L || v > 3L || force) {
123
          emitAlignedCode(0xfd);
124
          emitCode((v >> 2) & 255);
125
          emitCode((v >> 10) & 255);
126
          emitCode((v >> 18) & 255);
127
          emitCode((v >> 26) & 255);
128
     }
129
     if (((v < 0) && ((v >> 34) != -1L)) || ((v > 0) && ((v >> 34) != 0L)) || (force && data_bits > 34)) {
130
          emitAlignedCode(0xfe);
131
          emitCode((v >> 34) & 255);
132
          emitCode((v >> 42) & 255);
133
          emitCode((v >> 50) & 255);
134
          emitCode((v >> 58) & 255);
135
     }
136
}
137
 
138
// ---------------------------------------------------------------------------
139
// Emit constant extension for memory operands.
140
// ---------------------------------------------------------------------------
141
 
142
static void emitImm12(int64_t v, int force)
143
{
144
     if (v < -2048L || v > 2047L || force) {
145
          emitAlignedCode(0xfd);
146
          emitCode((v >> 12) & 255);
147
          emitCode((v >> 20) & 255);
148
          emitCode((v >> 28) & 255);
149
          emitCode((v >> 36) & 255);
150
     }
151
     if (((v < 0) && ((v >> 44) != -1L)) || ((v > 0) && ((v >> 44) != 0L)) || (force && data_bits > 44)) {
152
          emitAlignedCode(0xfe);
153
          emitCode((v >> 44) & 255);
154
          emitCode((v >> 52) & 255);
155
          emitCode((v >> 60) & 255);
156
          emitCode(0x00);
157
     }
158
}
159
 
160
// ---------------------------------------------------------------------------
161
// Emit constant extension for 16-bit operands.
162
// ---------------------------------------------------------------------------
163
 
164
static void emitImm16(int64_t v, int force)
165
{
166
     if (v < -32768L || v > 32767L || force) {
167
          emitAlignedCode(0xfd);
168
          emitCode((v >> 16) & 255);
169
          emitCode((v >> 24) & 255);
170
          emitCode((v >> 32) & 255);
171
          emitCode((v >> 40) & 255);
172
     }
173
     if (((v < 0) && ((v >> 48) != -1L)) || ((v > 0) && ((v >> 48) != 0L)) || (force && (code_bits > 48 || data_bits > 48))) {
174
          emitAlignedCode(0xfe);
175
          emitCode((v >> 48) & 255);
176
          emitCode((v >> 56) & 255);
177
          emitCode(0x00);
178
          emitCode(0x00);
179
     }
180
}
181
 
182
// ---------------------------------------------------------------------------
183
// Emit constant extension for 24-bit operands.
184
// ---------------------------------------------------------------------------
185
 
186
static void emitImm20(int64_t v, int force)
187
{
188
     if (v < -524288L || v > 524287L || force) {
189
          emitAlignedCode(0xfd);
190
          emitCode((v >> 20) & 255);
191
          emitCode((v >> 28) & 255);
192
          emitCode((v >> 36) & 255);
193
          emitCode((v >> 44) & 255);
194
     }
195
     if (((v < 0) && ((v >> 52) != -1L)) || ((v > 0) && ((v >> 52) != 0L)) || (force && (code_bits > 52 || data_bits > 52))) {
196
          emitAlignedCode(0xfe);
197
          emitCode((v >> 52) & 255);
198
          emitCode((v >> 60) & 255);
199
          emitCode(0x00);
200
          emitCode(0x00);
201
     }
202
}
203
 
204
// ---------------------------------------------------------------------------
205
// Emit constant extension for 24-bit operands.
206
// ---------------------------------------------------------------------------
207
 
208
static void emitImm24(int64_t v, int force)
209
{
210
     if (v < -8388608L || v > 8388607L || force) {
211
          emitAlignedCode(0xfd);
212
          emitCode((v >> 24) & 255);
213
          emitCode((v >> 32) & 255);
214
          emitCode((v >> 40) & 255);
215
          emitCode((v >> 48) & 255);
216
     }
217
     if (((v < 0) && ((v >> 56) != -1L)) || ((v > 0) && ((v >> 56) != 0L)) || (force && (code_bits > 56 || data_bits > 56))) {
218
          emitAlignedCode(0xfe);
219
          emitCode((v >> 56) & 255);
220
          emitCode(0x00);
221
          emitCode(0x00);
222
          emitCode(0x00);
223
     }
224
}
225
 
226
// ---------------------------------------------------------------------------
227
// Emit constant extension for 32-bit operands.
228
// ---------------------------------------------------------------------------
229
 
230
static void emitImm32(int64_t v, int force)
231
{
232
     if (v < -2147483648LL || v > 2147483647LL || force) {
233
          emitAlignedCode(0xfd);
234
          emitCode((v >> 32) & 255);
235
          emitCode((v >> 40) & 255);
236
          emitCode((v >> 48) & 255);
237
          emitCode((v >> 56) & 255);
238
     }
239
}
240
 
241
// ---------------------------------------------------------------------------
242
// jmp main
243
// jsr [r19]
244
// jmp (tbl,r2)
245
// jsr [gp+r20]
246
// ---------------------------------------------------------------------------
247
 
248
static void process_jmp(int oc)
249
{
250
    int64_t addr;
251
    int Ra, Rb;
252
    int sg;
253
 
254
    sg = 1; // Assume data segment
255
    NextToken();
256
    // Memory indirect ?
257
    if (token=='(' || token=='[') {
258
       Ra = getRegister();
259
       if (Ra==-1) {
260
           Ra = 0;
261
           NextToken();
262
           addr = expr();
263
           prevToken();
264
           if (token==',') {
265
               Ra = getRegister();
266
               if (Ra==-1) Ra = 0;
267
               if (Ra==255 || Ra==253)
268
                  sg = 14;
269
               else if (Ra==254)
270
                    sg = 15;
271
               else if (Ra==252)
272
                    sg = 12;
273
           }
274
            if (segprefix >= 0)
275
               sg = segprefix;
276
           if (token!=')' && token != ']')
277
               printf("Missing close bracket.\r\n");
278
/*
279
           if (lastsym != (SYM *)NULL)
280
               emitImm20(addr,!lastsym->defined);
281
           else
282
               emitImm20(addr,0);
283
*/
284
           emitImm20(addr,lastsym!=(SYM*)NULL);
285
           emitAlignedCode(oc+2);
286
            if (bGen)
287
                if (lastsym && !use_gp) {
288
                    if( lastsym->segment < 5)
289
                        sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | 8 | (lastsym->isExtern ? 128 : 0) | (code_bits << 8));
290
                }
291
           emitCode(Ra);
292
           emitCode(((addr << 4) & 0xF0)|sg);
293
           emitCode((addr >> 4) & 255);
294
           emitCode((addr >> 12) & 255);
295
           return;
296
       }
297
       // Simple [Rn] or [Rn+Rn]?
298
       else {
299
            if (token == '+') {
300
                //NextToken();
301
                Rb = getRegister();
302
                emitAlignedCode(0x65);  // JSR [Ra+Rb]
303
                emitCode(Ra);
304
                emitCode(Rb);
305
                emitCode(0x00);
306
                emitCode(0x00);
307
                return;
308
            }
309
            else {
310
                if (token != ')' && token!=']')
311
                    printf("Missing close bracket\r\n");
312
                emitAlignedCode(oc + 4);
313
                emitCode(Ra);
314
                emitCode(0x00);
315
                emitCode(0x00);
316
                emitCode(0x00);
317
                return;
318
            }
319
       }
320
    }
321
    addr = expr();
322
    prevToken();
323
    // d(Rn)? 
324
    if (token=='(' || token=='[') {
325
        NextToken();
326
        Ra = getRegister();
327
        if (Ra==-1) {
328
            printf("Illegal jump address mode.\r\n");
329
            Ra = 0;
330
        }
331
        if (token=='+') {
332
            emitImm0(addr,0);
333
            Rb = getRegister();
334
            emitAlignedCode(0x65);  // JSR [Ra+Rb]
335
            emitCode(Ra);
336
            emitCode(Rb);
337
            emitCode(0x00);
338
            emitCode(0x00);
339
            return;
340
        }
341
        else {
342
            emitImm24(addr,0);
343
            emitAlignedCode(oc+4);
344
            emitCode(Ra);
345
            emitCode(addr & 255);
346
            emitCode((addr >> 8) & 255);
347
            emitCode((addr >> 16) & 255);
348
            return;
349
        }
350
    }
351
 
352
    emitImm32(addr, code_bits > 32);
353
    emitAlignedCode(oc);
354
    if (bGen)
355
       if (lastsym && !use_gp) {
356
            if( lastsym->segment < 5)
357
                sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | 1 | (lastsym->isExtern ? 128 : 0) | (code_bits << 8));
358
        }
359
    emitCode(addr & 255);
360
    emitCode((addr >> 8) & 255);
361
    emitCode((addr >> 16) & 255);
362
    emitCode((addr >> 24) & 255);
363
}
364
 
365
// ---------------------------------------------------------------------------
366
// subui r1,r2,#1234
367
// ---------------------------------------------------------------------------
368
 
369
static void process_riop(int oc)
370
{
371
    int Ra;
372
    int Rt;
373
    char *p;
374
    int64_t val;
375
 
376
    p = inptr;
377
    Rt = getRegister();
378
    need(',');
379
    Ra = getRegister();
380
    need(',');
381
    NextToken();
382
    val = expr();
383
/*
384
   if (lastsym != (SYM *)NULL)
385
       emitImm16(val,!lastsym->defined);
386
   else
387
       emitImm16(val,0);
388
*/
389
    emitImm16(val,lastsym!=(SYM*)NULL);
390
    emitAlignedCode(oc);
391
    if (bGen)
392
    if (lastsym && !use_gp) {
393
        if( lastsym->segment < 5)
394
        sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | 3 | (lastsym->isExtern ? 128 : 0) |
395
        (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
396
    }
397
    emitCode(Ra);
398
    emitCode(Rt);
399
    emitCode(val & 255);
400
    emitCode((val >> 8) & 255);
401
}
402
 
403
// ---------------------------------------------------------------------------
404
// addu r1,r2,r12
405
// ---------------------------------------------------------------------------
406
 
407
static void process_rrop(int oc)
408
{
409
    int Ra;
410
    int Rb;
411
    int Rt;
412
    char *p;
413
 
414
    p = inptr;
415
    Rt = getRegister();
416
    need(',');
417
    Ra = getRegister();
418
    need(',');
419
    NextToken();
420
    if (token=='#') {
421
        inptr = p;
422
        switch(oc) {
423
        case 0x04: process_riop(0x04); return;  // add
424
        case 0x14: process_riop(0x14); return;  // addu
425
        case 0x05: process_riop(0x05); return;  // sub
426
        case 0x15: process_riop(0x15); return;  // subu
427
        case 0x06: process_riop(0x06); return;  // cmp
428
        case 0x07: process_riop(0x07); return;  // mul
429
        case 0x08: process_riop(0x08); return;  // div
430
        case 0x09: process_riop(0x09); return;  // mod
431
        case 0x17: process_riop(0x17); return;  // mulu
432
        case 0x18: process_riop(0x18); return;  // divu
433
        case 0x19: process_riop(0x19); return;  // modu
434
        case 0x20: process_riop(0x0C); return;  // and
435
        case 0x21: process_riop(0x0D); return;  // or
436
        case 0x22: process_riop(0x0E); return;  // eor
437
        // Sxx
438
        case 0x60: process_riop(0x30); return;
439
        case 0x61: process_riop(0x31); return;
440
        case 0x68: process_riop(0x38); return;
441
        case 0x69: process_riop(0x39); return;
442
        case 0x6A: process_riop(0x3A); return;
443
        case 0x6B: process_riop(0x3B); return;
444
        case 0x6C: process_riop(0x3C); return;
445
        case 0x6D: process_riop(0x3D); return;
446
        case 0x6E: process_riop(0x3E); return;
447
        case 0x6F: process_riop(0x3F); return;
448
        // Shift
449
        case 0x40: process_shifti(0x50); return;
450
        case 0x41: process_shifti(0x51); return;
451
        case 0x42: process_shifti(0x52); return;
452
        case 0x43: process_shifti(0x53); return;
453
        case 0x44: process_shifti(0x54); return;
454
        }
455
        return;
456
    }
457
    prevToken();
458
    Rb = getRegister();
459
    prevToken();
460
    emitAlignedCode(2);
461
    emitCode(Ra);
462
    emitCode(Rb);
463
    emitCode(Rt);
464
    emitCode(oc);
465
}
466
 
467
// ---------------------------------------------------------------------------
468
// fabs.d fp1,fp2[,rm]
469
// ---------------------------------------------------------------------------
470
 
471
static void process_fprop(int oc)
472
{
473
    int Ra;
474
    int Rt;
475
    char *p;
476
    int  sz;
477
    int fmt;
478
    int rm;
479
 
480
    rm = 0;
481
    sz = 'd';
482
    if (*inptr=='.') {
483
        inptr++;
484
        if (strchr("sdtqSDTQ",*inptr)) {
485
            sz = tolower(*inptr);
486
            inptr++;
487
        }
488
        else
489
            printf("Illegal float size.\r\n");
490
    }
491
    p = inptr;
492
    if (oc==0xF6)        // fcmp
493
        Rt = getRegister();
494
    else
495
        Rt = getFPRegister();
496
    need(',');
497
    Ra = getFPRegister();
498
    if (token==',')
499
       rm = getFPRoundMode();
500
    prevToken();
501
    emitAlignedCode(0x01);
502
    emitCode(Ra);
503
    emitCode(Rt);
504
    switch(sz) {
505
    case 's': fmt = 0; break;
506
    case 'd': fmt = 1; break;
507
    case 't': fmt = 2; break;
508
    case 'q': fmt = 3; break;
509
    }
510
    emitCode((fmt << 3)|rm);
511
    emitCode(oc);
512
}
513
 
514
// ---------------------------------------------------------------------------
515
// fadd.d fp1,fp2,fp12[,rm]
516
// fcmp.d r1,fp3,fp10[,rm]
517
// ---------------------------------------------------------------------------
518
 
519
static void process_fprrop(int oc)
520
{
521
    int Ra;
522
    int Rb;
523
    int Rt;
524
    char *p;
525
    int  sz;
526
    int fmt;
527
    int rm;
528
 
529
    rm = 0;
530
    sz = 'd';
531
    if (*inptr=='.') {
532
        inptr++;
533
        if (strchr("sdtqSDTQ",*inptr)) {
534
            sz = tolower(*inptr);
535
            inptr++;
536
        }
537
        else
538
            printf("Illegal float size.\r\n");
539
    }
540
    p = inptr;
541
    if (oc==0xF6)        // fcmp
542
        Rt = getRegister();
543
    else
544
        Rt = getFPRegister();
545
    need(',');
546
    Ra = getFPRegister();
547
    need(',');
548
    Rb = getFPRegister();
549
    if (token==',')
550
       rm = getFPRoundMode();
551
    prevToken();
552
    emitAlignedCode(oc);
553
    emitCode(Ra);
554
    emitCode(Rb);
555
    emitCode(Rt);
556
    switch(sz) {
557
    case 's': fmt = 0; break;
558
    case 'd': fmt = 1; break;
559
    case 't': fmt = 2; break;
560
    case 'q': fmt = 3; break;
561
    }
562
    emitCode((fmt << 3)|rm);
563
}
564
 
565
// ---------------------------------------------------------------------------
566
// fcx r0,#2
567
// fdx r1,#0
568
// ---------------------------------------------------------------------------
569
 
570
static void process_fpstat(int oc)
571
{
572
    int Ra;
573
    int64_t bits;
574
    char *p;
575
 
576
    p = inptr;
577
    bits = 0;
578
    Ra = getRegister();
579
    if (token==',') {
580
       NextToken();
581
       bits = expr();
582
    }
583
    prevToken();
584
    emitAlignedCode(0x01);
585
    emitCode(Ra);
586
    emitCode(bits & 0xff);
587
    emitCode(0x00);
588
    emitCode(oc);
589
}
590
 
591
// ---------------------------------------------------------------------------
592
// not r3,r3
593
// ---------------------------------------------------------------------------
594
 
595
static void process_rop(int oc)
596
{
597
    int Ra;
598
    int Rt;
599
 
600
    Rt = getRegister();
601
    need(',');
602
    Ra = getRegister();
603
    prevToken();
604
    emitAlignedCode(1);
605
    emitCode(Ra);
606
    emitCode(Rt);
607
    emitCode(0x00);
608
    emitCode(oc);
609
}
610
 
611
// ---------------------------------------------------------------------------
612
// brnz r1,label
613
// ---------------------------------------------------------------------------
614
 
615
static void process_bcc(int oc)
616
{
617
    int Ra;
618
    int64_t val;
619
    int64_t disp;
620
    int64_t ad;
621
 
622
    Ra = getRegister();
623
    need(',');
624
    NextToken();
625
    val = expr();
626
    ad = code_address + 5;
627
    if ((ad & 15)==15)
628
       ad++;
629
    disp = ((val & 0xFFFFFFFFFFFFF000L) - (ad & 0xFFFFFFFFFFFFF000L)) >> 12;
630
    emitAlignedCode(oc);
631
    emitCode(Ra);
632
    emitCode(val & 255);
633
    emitCode(((disp & 15) << 4)|((val >> 8) & 15));
634
    emitCode((disp >> 4) & 31);
635
}
636
 
637
// ---------------------------------------------------------------------------
638
// bra label
639
// ---------------------------------------------------------------------------
640
 
641
static void process_bra(int oc)
642
{
643
    int64_t val;
644
    int64_t disp;
645
    int64_t ad;
646
 
647
    NextToken();
648
    val = expr();
649
    ad = code_address + 5;
650
    if ((ad & 15)==15)
651
       ad++;
652
    disp = ((val & 0xFFFFFFFFFFFFF000L) - (ad & 0xFFFFFFFFFFFFF000L)) >> 12;
653
    emitAlignedCode(oc);
654
    emitCode(0x00);
655
    emitCode(val & 255);
656
    emitCode(((disp & 15) << 4)|((val >> 8) & 15));
657
    if (oc==0x56)   // BSR
658
        emitCode((disp >> 4) & 255);
659
    else
660
        emitCode((disp >> 4) & 31);
661
}
662
 
663
// ---------------------------------------------------------------------------
664
// expr
665
// expr[Reg]
666
// expr[Reg+Reg*sc]
667
// [Reg]
668
// [Reg+Reg*sc]
669
// ---------------------------------------------------------------------------
670
 
671
static void mem_operand(int64_t *disp, int *regA, int *regB, int *sc, int *sg)
672
{
673
     int64_t val;
674
 
675
     // chech params
676
     if (disp == (int64_t *)NULL)
677
         return;
678
     if (regA == (int *)NULL)
679
         return;
680
     if (regB == (int *)NULL)
681
         return;
682
     if (sc==(int *)NULL)
683
         return;
684
     if (sg==(int *)NULL)
685
         return;
686
 
687
     *disp = 0;
688
     *regA = -1;
689
     *regB = -1;
690
     *sc = 0;
691
     *sg = 1;
692
     if (token!='[') {;
693
          val = expr();
694
          *disp = val;
695
     }
696
     if (token=='[') {
697
         *regA = getRegister();
698
         if (*regA == -1) {
699
             printf("expecting a register\r\n");
700
         }
701
         if (*regA==255 || *regA==253)
702
            *sg = 14;
703
         else if (*regA==254)
704
            *sg = 15;
705
         else if (*regA==252)
706
             *sg = 12;
707
//         NextToken();
708
         if (token=='+') {
709
              *sc = 0;
710
              *regB = getRegister();
711
              if (*regB == -1) {
712
                  printf("expecting a register\r\n");
713
              }
714
              if (token=='*' && !fSeg)
715
                  printf("Index scaling not supported.\r\n");
716
              if (token=='*') {
717
                  NextToken();
718
                  val = expr();
719
                  prevToken();
720
//                  if (token!=tk_icon) {
721
//                      printf("expecting a scaling factor.\r\n");
722
//                      printf("token %d %c\r\n", token, token);
723
//                  }
724
                  switch(val) {
725
                  case 0: *sc = 0; break;
726
                  case 1: *sc = 0; break;
727
                  case 2: *sc = 1; break;
728
                  case 4: *sc = 2; break;
729
                  case 8: *sc = 3; break;
730
                  default: printf("Illegal scaling factor.\r\n");
731
                  }
732
              }
733
         }
734
         need(']');
735
     }
736
}
737
 
738
// ---------------------------------------------------------------------------
739
// sw disp[r1],r2
740
// sw [r1+r2],r3
741
// ----------------------------------------------------------------------------
742
 
743
static void process_store(int oc)
744
{
745
    int Ra;
746
    int Rb;
747
    int Rs;
748
    int sc;
749
    int sg;
750
    int fixup;
751
    int64_t disp;
752
 
753
    Rs = getRegister();
754
    expect(',');
755
    mem_operand(&disp, &Ra, &Rb, &sc, &sg);
756
    if (segprefix >= 0)
757
       sg = segprefix;
758
    if (Rs < 0) {
759
        printf("Expecting a source register.\r\n");
760
        ScanToEOL();
761
        return;
762
    }
763
    if (Rb > 0) {
764
       fixup = 11;
765
       emitImm0(disp,lastsym!=(SYM*)NULL);
766
       emitAlignedCode(oc + 8);
767
        if (bGen)
768
        if (lastsym && Ra != 249 && !use_gp) {
769
        if( lastsym->segment < 5)
770
            sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | fixup | (lastsym->isExtern ? 128 : 0)|
771
            (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
772
        }
773
       emitCode(Ra);
774
       emitCode(Rb);
775
       emitCode(Rs);
776
       emitCode(sc | ((sg & 15) << 2));
777
       return;
778
    }
779
        fixup = 10;
780
        if (disp < 0xFFFFFFFFFFFFF800LL || disp > 0x7FFLL) /*{
781
           if (lastsym != (SYM *)NULL)
782
               emitImm12(disp,!lastsym->defined);
783
           else
784
               emitImm12(disp,0);
785
        } */
786
            emitImm12(disp,lastsym!=(SYM*)NULL);
787
    emitAlignedCode(oc);
788
    if (bGen && lastsym && Ra != 249 && !use_gp)
789
    if( lastsym->segment < 5)
790
    sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | fixup | (lastsym->isExtern ? 128 : 0)|
791
    (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
792
    if (Ra < 0) Ra = 0;
793
    emitCode(Ra);
794
    emitCode(Rs);
795
    emitCode(((disp << 4) & 0xF0) | (sg & 15));
796
    emitCode((disp >> 4) & 255);
797
    ScanToEOL();
798
}
799
 
800
// ----------------------------------------------------------------------------
801
// ----------------------------------------------------------------------------
802
 
803
static void process_ldi(int oc)
804
{
805
    int Rt;
806
    int64_t val;
807
 
808
    Rt = getRegister();
809
    expect(',');
810
    val = expr();
811
/*
812
   if (lastsym != (SYM *)NULL)
813
       emitImm24(val,!lastsym->defined);
814
   else
815
       emitImm24(val,0);
816
*/
817
    emitImm24(val,lastsym!=(SYM*)NULL);
818
    emitAlignedCode(oc);
819
    if (bGen && lastsym && !use_gp)
820
    if( lastsym->segment < 5)
821
    sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | 2 | (lastsym->isExtern ? 128 : 0)|
822
    (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
823
    emitCode(Rt);
824
    emitCode(val & 255);
825
    emitCode((val >> 8) & 255);
826
    emitCode((val >> 16) & 255);
827
}
828
 
829
// ----------------------------------------------------------------------------
830
// ----------------------------------------------------------------------------
831
 
832
static void process_jsp(int oc)
833
{
834
    int Ra;
835
    int64_t val;
836
 
837
    Ra = getRegister();
838
    expect(',');
839
    val = expr();
840
    emitAlignedCode(oc);
841
    if (bGen && lastsym && !use_gp)
842
    if( lastsym->segment < 5)
843
    sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | 2 | (lastsym->isExtern ? 128 : 0)|
844
    (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
845
    emitCode(Ra);
846
    emitCode(val & 255);
847
    emitCode((val >> 8) & 255);
848
    emitCode((val >> 16) & 255);
849
}
850
 
851
// ----------------------------------------------------------------------------
852
// lw r1,disp[r2]
853
// lw r1,[r2+r3]
854
// ----------------------------------------------------------------------------
855
 
856
static void process_load(int oc)
857
{
858
    int Ra;
859
    int Rb;
860
    int Rt;
861
    int sc;
862
    int sg;
863
    char *p;
864
    int64_t disp;
865
    int fixup = 5;
866
 
867
    p = inptr;
868
    Rt = getRegister();
869
    if (Rt < 0) {
870
        printf("Expecting a target register.\r\n");
871
//        printf("Line:%.60s\r\n",p);
872
        ScanToEOL();
873
        inptr-=2;
874
        return;
875
    }
876
    expect(',');
877
    mem_operand(&disp, &Ra, &Rb, &sc, &sg);
878
    if (segprefix >= 0)
879
        sg = segprefix;
880
    if (Rb >= 0) {
881
       emitImm0(disp,lastsym!=(SYM*)NULL);
882
       fixup = 11;
883
       if (oc==0x87) {  //LWS
884
          printf("Address mode not supported.\r\n");
885
          return;
886
       }
887
       if (oc==0x9F) oc = 0x8F;  // LEA
888
       else oc = oc + 8;
889
       emitAlignedCode(oc);
890
        if (bGen && lastsym && Ra != 249 && !use_gp)
891
        if( lastsym->segment < 5)
892
        sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | fixup | (lastsym->isExtern ? 128 : 0)|
893
        (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
894
       emitCode(Ra);
895
       emitCode(Rb);
896
       emitCode(Rt);
897
       emitCode(sc | ((sg & 15) << 2));
898
       return;
899
    }
900
    fixup = 10;       // 12 bit
901
    if (disp < 0xFFFFFFFFFFFFF700LL || disp > 0x7FFLL) /*{
902
       if (lastsym != (SYM *)NULL)
903
           emitImm12(disp,!lastsym->defined);
904
       else
905
           emitImm12(disp,0);
906
    } */
907
        emitImm12(disp,lastsym!=(SYM*)NULL);
908
    emitAlignedCode(oc);
909
    if (bGen && lastsym && Ra != 249 && !use_gp)
910
    if( lastsym->segment < 5)
911
    sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | fixup | (lastsym->isExtern ? 128 : 0)|
912
    (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
913
    if (Ra < 0) Ra = 0;
914
    emitCode(Ra);
915
    emitCode(Rt);
916
    emitCode(((disp << 4) & 0xF0) | (sg & 15));
917
    emitCode((disp >> 4) & 255);
918
    ScanToEOL();
919
}
920
 
921
// ----------------------------------------------------------------------------
922
// ----------------------------------------------------------------------------
923
 
924
static void process_inc(int oc)
925
{
926
    int Ra;
927
    int Rb;
928
    int sc;
929
    int sg;
930
    int64_t incamt;
931
    int64_t disp;
932
    char *p;
933
    int fixup = 5;
934
 
935
    NextToken();
936
    p = inptr;
937
    mem_operand(&disp, &Ra, &Rb, &sc, &sg);
938
    incamt = 1;
939
    if (token==']')
940
       NextToken();
941
    if (token==',') {
942
        NextToken();
943
        incamt = expr();
944
        prevToken();
945
    }
946
    if (segprefix >= 0)
947
        sg = segprefix;
948
    if (Rb >= 0) {
949
       emitImm0(disp,lastsym!=(SYM*)NULL);
950
       fixup = 11;
951
       oc = 0xC1;  // INCX
952
       emitAlignedCode(oc);
953
        if (bGen && lastsym && Ra != 249 && !use_gp)
954
        if( lastsym->segment < 5)
955
        sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | fixup | (lastsym->isExtern ? 128 : 0)|
956
        (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
957
       emitCode(Ra);
958
       emitCode(Rb);
959
       emitCode(incamt & 255);
960
       emitCode(sc | ((sg & 15) << 2));
961
       return;
962
    }
963
    oc = 0xC0;        // INC
964
    fixup = 10;       // 12 bit
965
    if (disp < 0xFFFFFFFFFFFFF700LL || disp > 0x7FFLL) /*{
966
         if (lastsym != (SYM *)NULL)
967
           emitImm12(disp,!lastsym->defined);
968
       else
969
           emitImm12(disp,0);
970
    }*/
971
        emitImm12(disp,lastsym!=(SYM*)NULL);
972
    emitAlignedCode(oc);
973
    if (bGen && lastsym && Ra != 249 && !use_gp)
974
    if( lastsym->segment < 5)
975
    sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | fixup | (lastsym->isExtern ? 128 : 0)|
976
    (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
977
    if (Ra < 0) Ra = 0;
978
    emitCode(Ra);
979
    emitCode(incamt & 255);
980
    emitCode(((disp << 4) & 0xF0) | (sg & 15));
981
    emitCode((disp >> 4) & 255);
982
    ScanToEOL();
983
}
984
 
985
// ----------------------------------------------------------------------------
986
// pea disp[r2]
987
// pea [r2+r3]
988
// ----------------------------------------------------------------------------
989
 
990
static void process_pea()
991
{
992
    int oc;
993
    int Ra;
994
    int Rb;
995
    int sc;
996
    int sg;
997
    char *p;
998
    int64_t disp;
999
    int fixup = 5;
1000
 
1001
    p = inptr;
1002
    NextToken();
1003
    mem_operand(&disp, &Ra, &Rb, &sc, &sg);
1004
    if (segprefix >= 0)
1005
        sg = segprefix;
1006
    if (Rb >= 0) {
1007
       emitImm0(disp,lastsym!=(SYM*)NULL);
1008
       fixup = 11;
1009
       oc = 0xB9;  // PEAX
1010
       emitAlignedCode(oc);
1011
        if (bGen && lastsym && Ra != 249 && !use_gp)
1012
        if( lastsym->segment < 5)
1013
        sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | fixup | (lastsym->isExtern ? 128 : 0)|
1014
        (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
1015
       emitCode(Ra);
1016
       emitCode(Rb);
1017
       emitCode(0x00);
1018
       emitCode(sc | ((sg & 15) << 2));
1019
       return;
1020
    }
1021
    oc = 0xB8;        // PEA
1022
    fixup = 10;       // 12 bit
1023
    if (disp < 0xFFFFFFFFFFFFF700LL || disp > 0x7FFLL) /*{
1024
         if (lastsym != (SYM *)NULL)
1025
           emitImm12(disp,!lastsym->defined);
1026
       else
1027
           emitImm12(disp,0);
1028
    }*/
1029
        emitImm12(disp,lastsym!=(SYM*)NULL);
1030
    emitAlignedCode(oc);
1031
    if (bGen && lastsym && Ra != 249 && !use_gp)
1032
    if( lastsym->segment < 5)
1033
    sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | fixup | (lastsym->isExtern ? 128 : 0)|
1034
    (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
1035
    if (Ra < 0) Ra = 0;
1036
    emitCode(Ra);
1037
    emitCode(0x00);
1038
    emitCode((disp << 4) & 255);
1039
    emitCode((disp >> 4) & 255);
1040
    ScanToEOL();
1041
}
1042
 
1043
// ----------------------------------------------------------------------------
1044
// lmr r1,r12,d[r252]
1045
// ----------------------------------------------------------------------------
1046
 
1047
static void process_lmr(int oc)
1048
{
1049
    int Ra;
1050
    int Rb;
1051
    int Rc;
1052
    int sg;
1053
    int fixup;
1054
    int64_t disp;
1055
 
1056
    disp = 0;
1057
    Ra = getRegister();
1058
    need(',');
1059
    Rb = getRegister();
1060
    need(',');
1061
    NextToken();
1062
    if (token=='[') {
1063
        Rc = getRegister();
1064
        need(']');
1065
    }
1066
    else {
1067
        Rc = getRegister();
1068
        if (Rc==-1) {
1069
            disp = expr();
1070
            if (token!='[') {
1071
                printf("Expecting register indirection.\r\n");
1072
                return;
1073
            }
1074
            Rc = getRegister();
1075
            need(']');
1076
            if (Rc==-1) {
1077
                printf("Expecting a register.\r\n");
1078
                return;
1079
            }
1080
            fixup = 11;
1081
            emitImm0(disp,lastsym!=(SYM*)NULL);
1082
            sg = 1;
1083
            if (Rc==255 || Rc==253)
1084
               sg = 14;
1085
            else if (Rc==254)
1086
                 sg = 15;
1087
            else if (Rc==252)
1088
                 sg = 12;
1089
            if (segprefix >= 0)
1090
               sg = segprefix;
1091
            emitAlignedCode(oc);
1092
            if (bGen && lastsym && Rc != 249 && !use_gp)
1093
            if( lastsym->segment < 5)
1094
            sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | fixup | (lastsym->isExtern ? 128 : 0)|
1095
            (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
1096
            emitCode(Ra);
1097
            emitCode(Rb);
1098
            emitCode(Rc);
1099
            emitCode(sg);
1100
            return;
1101
        }
1102
    }
1103
    sg = 1;
1104
    if (Rc==255 || Rc==253)
1105
       sg = 14;
1106
    else if (Rc==254)
1107
         sg = 15;
1108
    else if (Rc==252)
1109
         sg = 12;
1110
    if (segprefix >= 0)
1111
       sg = segprefix;
1112
    emitAlignedCode(oc);
1113
    emitCode(Ra);
1114
    emitCode(Rb);
1115
    emitCode(Rc);
1116
    emitCode(sg);
1117
}
1118
 
1119
// ----------------------------------------------------------------------------
1120
// push r1/r2/r3/r4
1121
// push #123
1122
// ----------------------------------------------------------------------------
1123
 
1124
static void process_pushpop(int oc)
1125
{
1126
    int Ra,Rb,Rc,Rd;
1127
    int64_t val;
1128
 
1129
    Ra = -1;
1130
    Rb = -1;
1131
    Rc = -1;
1132
    Rd = -1;
1133
    NextToken();
1134
    if (token=='#' && oc==0xA6) {  // Filter to PUSH
1135
       val = expr();
1136
       emitImm32(val,(code_bits > 32 || data_bits > 32) && lastsym!=(SYM *)NULL);
1137
       emitAlignedCode(0xAD);
1138
        if (bGen && lastsym && !use_gp)
1139
        if( lastsym->segment < 5)
1140
        sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | 1 | (lastsym->isExtern ? 128 : 0)|
1141
        (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
1142
       emitCode(val & 255);
1143
       emitCode((val >> 8) & 255);
1144
       emitCode((val >> 16) & 255);
1145
       emitCode((val >> 24) & 255);
1146
    }
1147
    else {
1148
        prevToken();
1149
        Ra = getRegister();
1150
        if (token=='/' || token==',') {
1151
            Rb = getRegister();
1152
            if (token=='/' || token==',') {
1153
                Rc = getRegister();
1154
                if (token=='/' || token==',') {
1155
                    Rd = getRegister();
1156
                }
1157
            }
1158
        }
1159
        prevToken();
1160
        emitAlignedCode(oc);
1161
        emitCode(Ra>=0 ? Ra : 0);
1162
        emitCode(Rb>=0 ? Rb : 0);
1163
        emitCode(Rc>=0 ? Rc : 0);
1164
        emitCode(Rd>=0 ? Rd : 0);
1165
    }
1166
}
1167
 
1168
// ----------------------------------------------------------------------------
1169
// mov r1,r2
1170
// ----------------------------------------------------------------------------
1171
 
1172
static void process_mov(int oc)
1173
{
1174
     int Ra;
1175
     int Rt;
1176
 
1177
     Rt = getRegister();
1178
     need(',');
1179
     Ra = getRegister();
1180
     emitAlignedCode(0x01);
1181
     emitCode(Ra);
1182
     emitCode(Rt);
1183
     emitCode(0x00);
1184
     emitCode(oc);
1185
     prevToken();
1186
}
1187
 
1188
// ----------------------------------------------------------------------------
1189
// rts
1190
// rts #24
1191
// ----------------------------------------------------------------------------
1192
 
1193
static void process_rts(int oc)
1194
{
1195
     int64_t val;
1196
 
1197
     val = 0;
1198
     NextToken();
1199
     if (token=='#') {
1200
        val = expr();
1201
     }
1202
     emitAlignedCode(oc);
1203
     emitCode(0x00);
1204
     emitCode(val & 255);
1205
     emitCode((val >> 8) & 255);
1206
     emitCode(0x00);
1207
}
1208
 
1209
// ----------------------------------------------------------------------------
1210
// shli r1,r2,#5
1211
// ----------------------------------------------------------------------------
1212
 
1213
static void process_shifti(int oc)
1214
{
1215
     int Ra;
1216
     int Rt;
1217
     int64_t val;
1218
 
1219
     Rt = getRegister();
1220
     need(',');
1221
     Ra = getRegister();
1222
     need(',');
1223
     NextToken();
1224
     val = expr();
1225
     emitAlignedCode(0x02);
1226
     emitCode(Ra);
1227
     emitCode(val & 63);
1228
     emitCode(Rt);
1229
     emitCode(oc);
1230
}
1231
 
1232
// ----------------------------------------------------------------------------
1233
// gran r1
1234
// ----------------------------------------------------------------------------
1235
 
1236
static void process_gran(int oc)
1237
{
1238
    int Rt;
1239
 
1240
    Rt = getRegister();
1241
    emitAlignedCode(0x01);
1242
    emitCode(0x00);
1243
    emitCode(Rt);
1244
    emitCode(0x00);
1245
    emitCode(oc);
1246
    prevToken();
1247
}
1248
 
1249
// ----------------------------------------------------------------------------
1250
// ----------------------------------------------------------------------------
1251
 
1252
static void process_mtspr(int oc)
1253
{
1254
    int spr;
1255
    int Ra;
1256
 
1257
    spr = getSprRegister();
1258
    need(',');
1259
    Ra = getRegister();
1260
    emitAlignedCode(0x01);
1261
    emitCode(Ra);
1262
    emitCode(spr);
1263
    emitCode(0x00);
1264
    emitCode(oc);
1265
    if (Ra >= 0)
1266
    prevToken();
1267
}
1268
 
1269
// ----------------------------------------------------------------------------
1270
// ----------------------------------------------------------------------------
1271
 
1272
static void process_mtfp(int oc)
1273
{
1274
    int fpr;
1275
    int Ra;
1276
 
1277
    fpr = getFPRegister();
1278
    need(',');
1279
    Ra = getRegister();
1280
    emitAlignedCode(0x01);
1281
    emitCode(Ra);
1282
    emitCode(fpr);
1283
    emitCode(0x00);
1284
    emitCode(oc);
1285
    if (Ra >= 0)
1286
    prevToken();
1287
}
1288
 
1289
// ----------------------------------------------------------------------------
1290
// ----------------------------------------------------------------------------
1291
 
1292
static void process_mfspr(int oc)
1293
{
1294
    int spr;
1295
    int Rt;
1296
 
1297
    Rt = getRegister();
1298
    need(',');
1299
    spr = getSprRegister();
1300
    emitAlignedCode(0x01);
1301
    emitCode(spr);
1302
    emitCode(Rt);
1303
    emitCode(0x00);
1304
    emitCode(oc);
1305
    if (spr >= 0)
1306
    prevToken();
1307
}
1308
 
1309
// ----------------------------------------------------------------------------
1310
// ----------------------------------------------------------------------------
1311
 
1312
static void process_mffp(int oc)
1313
{
1314
    int fpr;
1315
    int Rt;
1316
 
1317
    Rt = getRegister();
1318
    need(',');
1319
    fpr = getFPRegister();
1320
    emitAlignedCode(0x01);
1321
    emitCode(fpr);
1322
    emitCode(Rt);
1323
    emitCode(0x00);
1324
    emitCode(oc);
1325
    if (fpr >= 0)
1326
    prevToken();
1327
}
1328
 
1329
// ----------------------------------------------------------------------------
1330
// ----------------------------------------------------------------------------
1331
 
1332
static void process_fprdstat(int oc)
1333
{
1334
    int Rt;
1335
 
1336
    Rt = getRegister();
1337
    emitAlignedCode(0x01);
1338
    emitCode(0x00);
1339
    emitCode(Rt);
1340
    emitCode(0x00);
1341
    emitCode(oc);
1342
}
1343
 
1344
// ----------------------------------------------------------------------------
1345
// ----------------------------------------------------------------------------
1346
 
1347
static void ProcessEOL(int opt)
1348
{
1349
    int nn,mm;
1350
    int first;
1351
    int cc;
1352
 
1353
     //printf("Line: %d\r", lineno);
1354
     segprefix = -1;
1355
     if (bGen && (segment==codeseg || segment==dataseg || segment==rodataseg)) {
1356
     if ((ca & 15)==15 && segment==codeseg) {
1357
         ca++;
1358
         binstart++;
1359
     }
1360
    nn = binstart;
1361
    cc = 8;
1362
    if (segment==codeseg) {
1363
       cc = 5;
1364
/*
1365
        if (sections[segment].bytes[binstart]==0x61) {
1366
            fprintf(ofp, "%06LLX ", ca);
1367
            for (nn = binstart; nn < binstart + 5 && nn < sections[segment].index; nn++) {
1368
                fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
1369
            }
1370
            fprintf(ofp, "   ; imm\n");
1371
             if (((ca+5) & 15)==15) {
1372
                 ca+=6;
1373
                 binstart+=6;
1374
                 nn++;
1375
             }
1376
             else {
1377
                  ca += 5;
1378
                  binstart += 5;
1379
             }
1380
        }
1381
*/
1382
/*
1383
        if (sections[segment].bytes[binstart]==0xfd) {
1384
            fprintf(ofp, "%06LLX ", ca);
1385
            for (nn = binstart; nn < binstart + 5 && nn < sections[segment].index; nn++) {
1386
                fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
1387
            }
1388
            fprintf(ofp, "   ; imm\n");
1389
             if (((ca+5) & 15)==15) {
1390
                 ca+=6;
1391
                 binstart+=6;
1392
                 nn++;
1393
             }
1394
             else {
1395
                  ca += 5;
1396
                  binstart += 5;
1397
             }
1398
        }
1399
         if (sections[segment].bytes[binstart]==0xfe) {
1400
            fprintf(ofp, "%06LLX ", ca);
1401
            for (nn = binstart; nn < binstart + 5 && nn < sections[segment].index; nn++) {
1402
                fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
1403
            }
1404
            fprintf(ofp, "   ; imm\n");
1405
             if (((ca+5) & 15)==15) {
1406
                 ca+=6;
1407
                 nn++;
1408
             }
1409
             else {
1410
                  ca += 5;
1411
             }
1412
        }
1413
*/
1414
    }
1415
 
1416
    first = 1;
1417
    while (nn < sections[segment].index) {
1418
        fprintf(ofp, "%06LLX ", ca);
1419
        for (mm = nn; nn < mm + cc && nn < sections[segment].index; nn++) {
1420
            fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
1421
        }
1422
        for (; nn < mm + cc; nn++)
1423
            fprintf(ofp, "   ");
1424
        if (first & opt) {
1425
            fprintf(ofp, "\t%.*s\n", inptr-stptr-1, stptr);
1426
            first = 0;
1427
        }
1428
        else
1429
            fprintf(ofp, opt ? "\n" : "; NOP Ramp\n");
1430
        ca += cc;
1431
         if ((ca & 15)==15 && segment==codeseg) {
1432
             ca++;
1433
             nn++;
1434
         }
1435
    }
1436
    // empty (codeless) line
1437
    if (binstart==sections[segment].index) {
1438
        fprintf(ofp, "%24s\t%.*s", "", inptr-stptr, stptr);
1439
    }
1440
    } // bGen
1441
    if (opt) {
1442
       stptr = inptr;
1443
       lineno++;
1444
    }
1445
    binstart = sections[segment].index;
1446
    ca = sections[segment].address;
1447
}
1448
 
1449
// ----------------------------------------------------------------------------
1450
// ----------------------------------------------------------------------------
1451
 
1452
void Table888mmu_processMaster()
1453
{
1454
    int nn,mm;
1455
    int64_t bs1, bs2;
1456
 
1457
    lineno = 1;
1458
    binndx = 0;
1459
    binstart = 0;
1460
    bs1 = 0;
1461
    bs2 = 0;
1462
    inptr = &masterFile[0];
1463
    stptr = inptr;
1464
    code_address = 0;
1465
    bss_address = 0;
1466
    start_address = 0;
1467
    first_org = 1;
1468
    first_rodata = 1;
1469
    first_data = 1;
1470
    first_bss = 1;
1471
    for (nn = 0; nn < 12; nn++) {
1472
        sections[nn].index = 0;
1473
        if (nn == 0)
1474
        sections[nn].address = 0;
1475
        else
1476
        sections[nn].address = 0;
1477
        sections[nn].start = 0;
1478
        sections[nn].end = 0;
1479
    }
1480
    ca = code_address;
1481
    segment = codeseg;
1482
    memset(current_label,0,sizeof(current_label));
1483
    NextToken();
1484
    while (token != tk_eof) {
1485
//        printf("\t%.*s\n", inptr-stptr-1, stptr);
1486
//        printf("token=%d\r", token);
1487
        switch(token) {
1488
        case tk_eol: ProcessEOL(1); break;
1489
        case tk_add:  process_rrop(0x04); break;
1490
        case tk_addi: process_riop(0x04); break;
1491
        case tk_addu: process_rrop(0x14); break;
1492
        case tk_addui: process_riop(0x14); break;
1493
        case tk_align: process_align(); continue; break;
1494
        case tk_and:  process_rrop(0x20); break;
1495
        case tk_andi:  process_riop(0x0C); break;
1496
        case tk_asr:  process_rrop(0x44); break;
1497
        case tk_asri: process_shifti(0x54); break;
1498
        case tk_beq: process_bcc(0x40); break;
1499
        case tk_bge: process_bcc(0x4A); break;
1500
        case tk_bgeu: process_bcc(0x4E); break;
1501
        case tk_bgt: process_bcc(0x48); break;
1502
        case tk_bgtu: process_bcc(0x4C); break;
1503
        case tk_ble: process_bcc(0x49); break;
1504
        case tk_bleu: process_bcc(0x4D); break;
1505
        case tk_blt: process_bcc(0x4B); break;
1506
        case tk_bltu: process_bcc(0x4F); break;
1507
        case tk_bmi: process_bcc(0x44); break;
1508
        case tk_bne: process_bcc(0x41); break;
1509
        case tk_bpl: process_bcc(0x45); break; // also brpl
1510
        case tk_bra: process_bra(0x46); break;
1511
        case tk_brnz: process_bcc(0x59); break;
1512
        case tk_brz:  process_bcc(0x58); break;
1513
        case tk_bvc: process_bcc(0x43); break;
1514
        case tk_bvs: process_bcc(0x42); break;
1515
        case tk_bsr: process_bra(0x56); break;
1516
        case tk_bss:
1517
            if (first_bss) {
1518
                while(sections[segment].address & 4095)
1519
                    emitByte(0x00);
1520
                sections[3].address = sections[segment].address;
1521
                first_bss = 0;
1522
                binstart = sections[3].index;
1523
                ca = sections[3].address;
1524
            }
1525
            segment = bssseg;
1526
            break;
1527
        case tk_cli: emit_insn(0x3100000001); break;
1528
        case tk_cmp: process_rrop(0x06); break;
1529
        case tk_code: process_code(); break;
1530
        case tk_com: process_rop(0x06); break;
1531
        case tk_cs:  segprefix = 15; break;
1532
        case tk_data:
1533
            if (first_data) {
1534
                while(sections[segment].address & 4095)
1535
                    emitByte(0x00);
1536
                sections[2].address = sections[segment].address;   // set starting address
1537
                first_data = 0;
1538
                binstart = sections[2].index;
1539
                ca = sections[2].address;
1540
            }
1541
            process_data(dataseg);
1542
            break;
1543
        case tk_db:  process_db(); break;
1544
        case tk_dbnz: process_bcc(0x5A); break;
1545
        case tk_dc:  process_dc(); break;
1546
        case tk_dh:  process_dh(); break;
1547
        case tk_div: process_rrop(0x08); break;
1548
        case tk_divu: process_rrop(0x18); break;
1549
        case tk_ds:  segprefix = 1; break;
1550
        case tk_dw:  process_dw(); break;
1551
        case tk_end: goto j1;
1552
        case tk_endpublic: break;
1553
        case tk_eor: process_rrop(0x22); break;
1554
        case tk_eori: process_riop(0x0E); break;
1555
        case tk_extern: process_extern(); break;
1556
        case tk_fabs: process_fprop(0x88); break;
1557
        case tk_fadd: process_fprrop(0xF4); break;
1558
        case tk_fcmp: process_fprrop(0xF6); break;
1559
        case tk_fcx: process_fpstat(0x74); break;
1560
        case tk_fdiv: process_fprrop(0xF8); break;
1561
        case tk_fdx: process_fpstat(0x77); break;
1562
        case tk_fex: process_fpstat(0x76); break;
1563
        case tk_fill: process_fill(); break;
1564
        case tk_fix2flt: process_fprop(0x84); break;
1565
        case tk_flt2fix: process_fprop(0x85); break;
1566
        case tk_fmov: process_fprop(0x87); break;
1567
        case tk_fmul: process_fprrop(0xF7); break;
1568
        case tk_fnabs: process_fprop(0x89); break;
1569
        case tk_fneg: process_fprop(0x8A); break;
1570
        case tk_frm: process_fpstat(0x78); break;
1571
        case tk_fstat: process_fprdstat(0x86); break;
1572
        case tk_fsub: process_fprrop(0xF5); break;
1573
        case tk_ftx: process_fpstat(0x75); break;
1574
        case tk_gran: process_gran(0x14); break;
1575
        case tk_inc: process_inc(0xC0); break;
1576
        case tk_ios: segprefix = 11; break;
1577
        case tk_jgr: process_jsp(0x57); break;
1578
        case tk_jmp: process_jmp(0x50); break;
1579
        case tk_jsp: process_jsp(0x61); break;
1580
        case tk_jsr: process_jmp(0x51); break;
1581
        case tk_lb:  process_load(0x80); break;
1582
        case tk_lbu: process_load(0x81); break;
1583
        case tk_lc:  process_load(0x82); break;
1584
        case tk_lcu: process_load(0x83); break;
1585
        case tk_ldi: process_ldi(0x16); break;
1586
        case tk_lea: process_load(0x9F); break;
1587
        case tk_lh:  process_load(0x84); break;
1588
        case tk_lhu: process_load(0x85); break;
1589
        case tk_lmr: process_lmr(0x9C); break;
1590
        case tk_lw:  process_load(0x86); break;
1591
        case tk_mffp: process_mffp(0x4B); break;
1592
        case tk_mfspr: process_mfspr(0x49); break;
1593
        case tk_mod: process_rrop(0x09); break;
1594
        case tk_modu: process_rrop(0x19); break;
1595
        case tk_mov: process_mov(0x04); break;
1596
        case tk_mtfp: process_mtfp(0x4A); break;
1597
        case tk_mtspr: process_mtspr(0x48); break;
1598
        case tk_mul: process_rrop(0x07); break;
1599
        case tk_muli: process_riop(0x07); break;
1600
        case tk_mulu: process_rrop(0x17); break;
1601
        case tk_mului: process_riop(0x17); break;
1602
        case tk_neg: process_rop(0x05); break;
1603
        case tk_nop: emit_insn(0xEAEAEAEAEA); break;
1604
        case tk_not: process_rop(0x07); break;
1605
        case tk_or:  process_rrop(0x21); break;
1606
        case tk_ori: process_riop(0x0D); break;
1607
        case tk_org: process_org(); break;
1608
        case tk_pea: process_pea(); break;
1609
        case tk_php: emit_insn(0x3200000001); break;
1610
        case tk_plp: emit_insn(0x3300000001); break;
1611
        case tk_pop:  process_pushpop(0xA7); break;
1612
        case tk_public: process_public(); break;
1613
        case tk_push: process_pushpop(0xA6); break;
1614
        case tk_rodata:
1615
            if (first_rodata) {
1616
                while(sections[segment].address & 4095)
1617
                    emitByte(0x00);
1618
                sections[1].address = sections[segment].address;
1619
                first_rodata = 0;
1620
                binstart = sections[1].index;
1621
                ca = sections[1].address;
1622
            }
1623
            segment = rodataseg;
1624
            break;
1625
        case tk_rol: process_rrop(0x41); break;
1626
        case tk_ror: process_rrop(0x43); break;
1627
        case tk_rti: emit_insn(0x4000000001); break;
1628
        case tk_rts: process_rts(0x60); break;
1629
        case tk_sb:  process_store(0xa0); break;
1630
        case tk_sc:  process_store(0xa1); break;
1631
        case tk_sei: emit_insn(0x3000000001); break;
1632
        case tk_seq:  process_rrop(0x60); break;
1633
        case tk_seqi: process_riop(0x30); break;
1634
        case tk_sge:  process_rrop(0x6A); break;
1635
        case tk_sgt:  process_rrop(0x68); break;
1636
        case tk_sle:  process_rrop(0x69); break;
1637
        case tk_slt:  process_rrop(0x6B); break;
1638
        case tk_sgeu:  process_rrop(0x6E); break;
1639
        case tk_sgtu:  process_rrop(0x6C); break;
1640
        case tk_sleu:  process_rrop(0x6D); break;
1641
        case tk_sltu:  process_rrop(0x6F); break;
1642
        case tk_sgei:  process_rrop(0x3A); break;
1643
        case tk_sgti:  process_rrop(0x38); break;
1644
        case tk_slei:  process_rrop(0x39); break;
1645
        case tk_slti:  process_rrop(0x3B); break;
1646
        case tk_sgeui:  process_rrop(0x3E); break;
1647
        case tk_sgtui:  process_rrop(0x3C); break;
1648
        case tk_sleui:  process_rrop(0x3D); break;
1649
        case tk_sltui:  process_rrop(0x3F); break;
1650
        case tk_sne:  process_rrop(0x61); break;
1651
        case tk_snei: process_riop(0x31); break;
1652
        case tk_sh:  process_store(0xa2); break;
1653
        case tk_shl:  process_rrop(0x40); break;
1654
        case tk_shli: process_shifti(0x50); break;
1655
        case tk_shru: process_rrop(0x42); break;
1656
        case tk_shrui: process_shifti(0x52); break;
1657
        case tk_smr: process_lmr(0xBC); break;
1658
        case tk_ss:  segprefix = 14; break;
1659
        case tk_sub:  process_rrop(0x05); break;
1660
        case tk_subi: process_riop(0x05); break;
1661
        case tk_subu: process_rrop(0x15); break;
1662
        case tk_subui: process_riop(0x15); break;
1663
        case tk_sxb: process_rop(0x08); break;
1664
        case tk_sxc: process_rop(0x09); break;
1665
        case tk_sxh: process_rop(0x0A); break;
1666
        case tk_sw:  process_store(0xa3); break;
1667
        case tk_swap: process_rop(0x03); break;
1668
        case tk_xor: process_rrop(0x22); break;
1669
        case tk_xori: process_riop(0x0E); break;
1670
        case tk_id:  process_label(); break;
1671
        }
1672
        NextToken();
1673
    }
1674
j1:
1675
    ;
1676
}
1677
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.