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

Subversion Repositories thor

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

Go to most recent revision | 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
#define BCC(x)       (((x) << 12)|0x38)
29
 
30
// Fixup types
31
#define FUT_C15       1
32
#define FUT_C40       2
33
#define FUT_C64       3
34
#define FUT_R27       4
35
 
36
 
37
static void emitAlignedCode(int cd);
38
static void process_shifti(int oc);
39
static void ProcessEOL(int opt);
40
 
41
extern int first_rodata;
42
extern int first_data;
43
extern int first_bss;
44
static int64_t ca;
45
extern int isInitializationData;
46
extern int use_gp;
47
 
48
// This structure not used.
49
typedef struct tagInsn
50
{
51
    union {
52
        struct {
53
            unsigned int opcode : 7;
54
            unsigned int Ra : 5;
55
            unsigned int Rt : 5;
56
            unsigned int imm : 15;
57
        } ri;
58
        struct {
59
            unsigned int opcode : 7;
60
            unsigned int Ra : 5;
61
            unsigned int Rt : 5;
62
            unsigned int Rb : 5;
63
            unsigned int resv : 3;
64
            unsigned int funct : 7;
65
        } rr;
66
    };
67
};
68
 
69
// ----------------------------------------------------------------------------
70
// Return the register number or -1 if not a register.
71
// Parses pretty register names like SP or BP in addition to r1,r2,etc.
72
// ----------------------------------------------------------------------------
73
 
74
static int getRegisterX()
75
{
76
    int reg;
77
 
78
    while(isspace(*inptr)) inptr++;
79
    switch(*inptr) {
80
    case 'r': case 'R':
81
         if (isdigit(inptr[1])) {
82
             reg = inptr[1]-'0';
83
             if (isdigit(inptr[2])) {
84
                 reg = 10 * reg + (inptr[2]-'0');
85
                 if (isdigit(inptr[3])) {
86
                     reg = 10 * reg + (inptr[3]-'0');
87
                     if (isIdentChar(inptr[4]))
88
                         return -1;
89
                     inptr += 4;
90
                     NextToken();
91
                     return reg;
92
                 }
93
                 else if (isIdentChar(inptr[3]))
94
                     return -1;
95
                 else {
96
                     inptr += 3;
97
                     NextToken();
98
                     return reg;
99
                 }
100
             }
101
             else if (isIdentChar(inptr[2]))
102
                 return -1;
103
             else {
104
                 inptr += 2;
105
                 NextToken();
106
                 return reg;
107
             }
108
         }
109
         else return -1;
110
    case 'b': case 'B':
111
        if ((inptr[1]=='P' || inptr[1]=='p') && !isIdentChar(inptr[2])) {
112
            inptr += 2;
113
            NextToken();
114
            return 27;
115
        }
116
        break;
117
    case 'g': case 'G':
118
        if ((inptr[1]=='P' || inptr[1]=='p') && !isIdentChar(inptr[2])) {
119
            inptr += 2;
120
            NextToken();
121
            return 26;
122
        }
123
        break;
124
    case 's': case 'S':
125
        if ((inptr[1]=='P' || inptr[1]=='p') && !isIdentChar(inptr[2])) {
126
            inptr += 2;
127
            NextToken();
128
            return 30;
129
        }
130
        break;
131
    case 't': case 'T':
132
        if ((inptr[1]=='P' || inptr[1]=='p') && !isIdentChar(inptr[2])) {
133
            inptr += 2;
134
            NextToken();
135
            return 25;
136
        }
137
        if ((inptr[1]=='R' || inptr[1]=='r') && !isIdentChar(inptr[2])) {
138
            inptr += 2;
139
            NextToken();
140
            return 24;
141
        }
142
        break;
143
    case 'p': case 'P':
144
        if ((inptr[1]=='c' || inptr[1]=='C') && !isIdentChar(inptr[2])) {
145
            inptr += 2;
146
            NextToken();
147
            return 29;
148
        }
149
        break;
150
    case 'l': case 'L':
151
        if ((inptr[1]=='R' || inptr[1]=='r') && !isIdentChar(inptr[2])) {
152
            inptr += 2;
153
            NextToken();
154
            return 31;
155
        }
156
        break;
157
    case 'x': case 'X':
158
        if ((inptr[1]=='l' || inptr[1]=='L') && (inptr[2]=='r' || inptr[2]=='R') &&
159
        !isIdentChar(inptr[3])) {
160
            inptr += 3;
161
            NextToken();
162
            return 28;
163
        }
164
        break;
165
    default:
166
        return -1;
167
    }
168
    return -1;
169
}
170
 
171
 
172
static int getBoundsRegister()
173
{
174
    int reg;
175
 
176
    while(isspace(*inptr)) inptr++;
177
    switch(*inptr) {
178
    case 'b': case 'B':
179
         if (isdigit(inptr[1])) {
180
             reg = inptr[1]-'0';
181
             if (isdigit(inptr[2])) {
182
                 reg = 10 * reg + (inptr[2]-'0');
183
                 if (isdigit(inptr[3])) {
184
                     reg = 10 * reg + (inptr[3]-'0');
185
                     if (isIdentChar(inptr[4]))
186
                         return -1;
187
                     inptr += 4;
188
                     NextToken();
189
                     return reg;
190
                 }
191
                 else if (isIdentChar(inptr[3]))
192
                     return -1;
193
                 else {
194
                     inptr += 3;
195
                     NextToken();
196
                     return reg;
197
                 }
198
             }
199
             else if (isIdentChar(inptr[2]))
200
                 return -1;
201
             else {
202
                 inptr += 2;
203
                 NextToken();
204
                 return reg;
205
             }
206
         }
207
         else return -1;
208
    }
209
    return -1;
210
}
211
 
212
 
213
// ----------------------------------------------------------------------------
214
// Get the friendly name of a special purpose register.
215
// ----------------------------------------------------------------------------
216
 
217
static int FISA64_getSprRegister()
218
{
219
    while(isspace(*inptr)) inptr++;
220
    switch(*inptr) {
221
 
222
    case '0':
223
    case '1':
224
    case '2':
225
    case '3':
226
    case '4':
227
    case '5':
228
    case '6':
229
    case '7':
230
    case '8':
231
    case '9':
232
         NextToken();
233
         NextToken();
234
         return (int)ival.low;
235
 
236
    // bear
237
    case 'b': case 'B':
238
         if ((inptr[1]=='e' || inptr[1]=='E') &&
239
             (inptr[2]=='a' || inptr[2]=='A') &&
240
             (inptr[3]=='r' || inptr[3]=='R') &&
241
             !isIdentChar(inptr[4])) {
242
             inptr += 4;
243
             NextToken();
244
             return 11;
245
         }
246
         break;
247
    // cas clk cr0 cr3
248
    case 'c': case 'C':
249
         if ((inptr[1]=='a' || inptr[1]=='A') &&
250
             (inptr[2]=='s' || inptr[2]=='S') &&
251
             !isIdentChar(inptr[3])) {
252
             inptr += 3;
253
             NextToken();
254
             return 44;
255
         }
256
         if ((inptr[1]=='l' || inptr[1]=='L') &&
257
             (inptr[2]=='k' || inptr[2]=='K') &&
258
             !isIdentChar(inptr[3])) {
259
             inptr += 3;
260
             NextToken();
261
             return 0x06;
262
         }
263
         if ((inptr[1]=='r' || inptr[1]=='R') &&
264
             (inptr[2]=='0') &&
265
             !isIdentChar(inptr[3])) {
266
             inptr += 3;
267
             NextToken();
268
             return 0x00;
269
         }
270
         if ((inptr[1]=='r' || inptr[1]=='R') &&
271
             (inptr[2]=='3') &&
272
             !isIdentChar(inptr[3])) {
273
             inptr += 3;
274
             NextToken();
275
             return 0x03;
276
         }
277
         break;
278
 
279
    // dbad0 dbad1 dbctrl dpc dsp
280
    case 'd': case 'D':
281
         if ((inptr[1]=='b' || inptr[1]=='B') &&
282
             (inptr[2]=='a' || inptr[2]=='A') &&
283
             (inptr[3]=='d' || inptr[3]=='D') &&
284
             (inptr[4]=='0' || inptr[4]=='0') &&
285
             !isIdentChar(inptr[5])) {
286
             inptr += 5;
287
             NextToken();
288
             return 50;
289
         }
290
         if ((inptr[1]=='b' || inptr[1]=='B') &&
291
             (inptr[2]=='a' || inptr[2]=='A') &&
292
             (inptr[3]=='d' || inptr[3]=='D') &&
293
             (inptr[4]=='1' || inptr[4]=='1') &&
294
             !isIdentChar(inptr[5])) {
295
             inptr += 5;
296
             NextToken();
297
             return 51;
298
         }
299
         if ((inptr[1]=='b' || inptr[1]=='B') &&
300
             (inptr[2]=='a' || inptr[2]=='A') &&
301
             (inptr[3]=='d' || inptr[3]=='D') &&
302
             (inptr[4]=='2' || inptr[4]=='2') &&
303
             !isIdentChar(inptr[5])) {
304
             inptr += 5;
305
             NextToken();
306
             return 52;
307
         }
308
         if ((inptr[1]=='b' || inptr[1]=='B') &&
309
             (inptr[2]=='a' || inptr[2]=='A') &&
310
             (inptr[3]=='d' || inptr[3]=='D') &&
311
             (inptr[4]=='3' || inptr[4]=='3') &&
312
             !isIdentChar(inptr[5])) {
313
             inptr += 5;
314
             NextToken();
315
             return 53;
316
         }
317
         if ((inptr[1]=='b' || inptr[1]=='B') &&
318
             (inptr[2]=='c' || inptr[2]=='C') &&
319
             (inptr[3]=='t' || inptr[3]=='T') &&
320
             (inptr[4]=='r' || inptr[4]=='R') &&
321
             (inptr[5]=='l' || inptr[5]=='L') &&
322
             !isIdentChar(inptr[6])) {
323
             inptr += 6;
324
             NextToken();
325
             return 54;
326
         }
327
         if ((inptr[1]=='p' || inptr[1]=='P') &&
328
             (inptr[2]=='c' || inptr[2]=='C') &&
329
             !isIdentChar(inptr[3])) {
330
             inptr += 3;
331
             NextToken();
332
             return 7;
333
         }
334
         if (
335
             (inptr[1]=='b' || inptr[1]=='B') &&
336
             (inptr[2]=='p' || inptr[2]=='P') &&
337
             (inptr[3]=='c' || inptr[3]=='C') &&
338
             !isIdentChar(inptr[4])) {
339
             inptr += 4;
340
             NextToken();
341
             return 7;
342
         }
343
         if ((inptr[1]=='s' || inptr[1]=='S') &&
344
             (inptr[2]=='p' || inptr[2]=='P') &&
345
             !isIdentChar(inptr[3])) {
346
             inptr += 3;
347
             NextToken();
348
             return 16;
349
         }
350
         break;
351
 
352
    // ea epc esp
353
    case 'e': case 'E':
354
         if ((inptr[1]=='a' || inptr[1]=='A') &&
355
             !isIdentChar(inptr[2])) {
356
             inptr += 2;
357
             NextToken();
358
             return 40;
359
         }
360
         if ((inptr[1]=='p' || inptr[1]=='P') &&
361
             (inptr[2]=='c' || inptr[2]=='C') &&
362
             !isIdentChar(inptr[3])) {
363
             inptr += 3;
364
             NextToken();
365
             return 9;
366
         }
367
         if ((inptr[1]=='s' || inptr[1]=='S') &&
368
             (inptr[2]=='p' || inptr[2]=='P') &&
369
             !isIdentChar(inptr[3])) {
370
             inptr += 3;
371
             NextToken();
372
             return 17;
373
         }
374
         break;
375
 
376
    // fault_pc
377
    case 'f': case 'F':
378
         if ((inptr[1]=='a' || inptr[1]=='A') &&
379
             (inptr[2]=='u' || inptr[2]=='U') &&
380
             (inptr[3]=='l' || inptr[3]=='L') &&
381
             (inptr[4]=='t' || inptr[4]=='T') &&
382
             (inptr[5]=='_' || inptr[5]=='_') &&
383
             (inptr[6]=='p' || inptr[6]=='P') &&
384
             (inptr[7]=='c' || inptr[7]=='C') &&
385
             !isIdentChar(inptr[8])) {
386
             inptr += 8;
387
             NextToken();
388
             return 0x08;
389
         }
390
         break;
391
 
392
    // history
393
    case 'h': case 'H':
394
         if ((inptr[1]=='i' || inptr[1]=='I') &&
395
             (inptr[2]=='s' || inptr[2]=='S') &&
396
             (inptr[3]=='t' || inptr[3]=='T') &&
397
             (inptr[4]=='o' || inptr[4]=='O') &&
398
             (inptr[5]=='r' || inptr[5]=='R') &&
399
             (inptr[6]=='y' || inptr[6]=='Y') &&
400
             !isIdentChar(inptr[7])) {
401
             inptr += 7;
402
             NextToken();
403
             return 0x0D;
404
         }
405
         break;
406
 
407
    // ipc isp ivno
408
    case 'i': case 'I':
409
         if ((inptr[1]=='p' || inptr[1]=='P') &&
410
             (inptr[2]=='c' || inptr[2]=='C') &&
411
             !isIdentChar(inptr[3])) {
412
             inptr += 3;
413
             NextToken();
414
             return 8;
415
         }
416
         if ((inptr[1]=='s' || inptr[1]=='S') &&
417
             (inptr[2]=='p' || inptr[2]=='P') &&
418
             !isIdentChar(inptr[3])) {
419
             inptr += 3;
420
             NextToken();
421
             return 15;
422
         }
423
         if ((inptr[1]=='v' || inptr[1]=='V') &&
424
             (inptr[2]=='n' || inptr[2]=='N') &&
425
             (inptr[3]=='o' || inptr[3]=='O') &&
426
             !isIdentChar(inptr[4])) {
427
             inptr += 4;
428
             NextToken();
429
             return 0x0C;
430
         }
431
         break;
432
 
433
 
434
    // LOTGRP
435
    case 'l': case 'L':
436
         if ((inptr[1]=='o' || inptr[1]=='O') &&
437
             (inptr[2]=='t' || inptr[2]=='T') &&
438
             (inptr[3]=='g' || inptr[3]=='G') &&
439
             (inptr[4]=='r' || inptr[4]=='R') &&
440
             (inptr[5]=='p' || inptr[5]=='P') &&
441
             !isIdentChar(inptr[6])) {
442
             inptr += 6;
443
             NextToken();
444
             return 42;
445
         }
446
         break;
447
 
448
    // rand
449
    case 'r': case 'R':
450
         if ((inptr[1]=='a' || inptr[1]=='A') &&
451
             (inptr[2]=='n' || inptr[2]=='N') &&
452
             (inptr[3]=='d' || inptr[3]=='D') &&
453
             !isIdentChar(inptr[4])) {
454
             inptr += 4;
455
             NextToken();
456
             return 0x12;
457
         }
458
         break;
459
    // ss_ll srand1 srand2
460
    case 's': case 'S':
461
         if ((inptr[1]=='s' || inptr[1]=='S') &&
462
             (inptr[2]=='_' || inptr[2]=='_') &&
463
             (inptr[3]=='l' || inptr[3]=='L') &&
464
             (inptr[4]=='l' || inptr[4]=='L') &&
465
             !isIdentChar(inptr[5])) {
466
             inptr += 5;
467
             NextToken();
468
             return 0x1A;
469
         }
470
         if ((inptr[1]=='r' || inptr[1]=='R') &&
471
             (inptr[2]=='a' || inptr[2]=='A') &&
472
             (inptr[3]=='n' || inptr[3]=='N') &&
473
             (inptr[4]=='d' || inptr[4]=='D') &&
474
             (inptr[5]=='1') &&
475
             !isIdentChar(inptr[6])) {
476
             inptr += 6;
477
             NextToken();
478
             return 0x10;
479
         }
480
         if ((inptr[1]=='r' || inptr[1]=='R') &&
481
             (inptr[2]=='a' || inptr[2]=='A') &&
482
             (inptr[3]=='n' || inptr[3]=='N') &&
483
             (inptr[4]=='d' || inptr[4]=='D') &&
484
             (inptr[5]=='2') &&
485
             !isIdentChar(inptr[6])) {
486
             inptr += 6;
487
             NextToken();
488
             return 0x11;
489
         }
490
         if ((inptr[1]=='p' || inptr[1]=='P') &&
491
             (inptr[2]=='r' || inptr[2]=='R') &&
492
             isdigit(inptr[3]) && isdigit(inptr[4]) &&
493
             !isIdentChar(inptr[5])) {
494
             inptr += 5;
495
             NextToken();
496
             return (inptr[3]-'0')*10 + (inptr[4]-'0');
497
         }
498
         break;
499
 
500
    // tag tick 
501
    case 't': case 'T':
502
         if ((inptr[1]=='i' || inptr[1]=='I') &&
503
             (inptr[2]=='c' || inptr[2]=='C') &&
504
             (inptr[3]=='k' || inptr[3]=='K') &&
505
             !isIdentChar(inptr[4])) {
506
             inptr += 4;
507
             NextToken();
508
             return 4;
509
         }
510
         if ((inptr[1]=='a' || inptr[1]=='A') &&
511
             (inptr[2]=='g' || inptr[2]=='G') &&
512
             !isIdentChar(inptr[3])) {
513
             inptr += 3;
514
             NextToken();
515
             return 41;
516
         }
517
         break;
518
 
519
    // vbr
520
    case 'v': case 'V':
521
         if ((inptr[1]=='b' || inptr[1]=='B') &&
522
             (inptr[2]=='r' || inptr[2]=='R') &&
523
             !isIdentChar(inptr[3])) {
524
             inptr += 3;
525
             NextToken();
526
             return 10;
527
         }
528
         break;
529
    }
530
    return -1;
531
}
532
 
533
// ---------------------------------------------------------------------------
534
// ---------------------------------------------------------------------------
535
 
536
static void emit_insn(int64_t oc)
537
{
538
     emitAlignedCode(oc & 255);
539
     emitCode((oc >> 8) & 255);
540
     emitCode((oc >> 16) & 255);
541
     emitCode((oc >> 24) & 255);
542
     num_bytes += 4;
543
     num_insns += 1;
544
}
545
 
546
// ---------------------------------------------------------------------------
547
// ---------------------------------------------------------------------------
548
 
549
static void emit_insn2(int64_t oc)
550
{
551
     emitCode(oc & 255);
552
     emitCode((oc >> 8) & 255);
553
     emitCode((oc >> 16) & 255);
554
     emitCode((oc >> 24) & 255);
555
     num_bytes += 4;
556
     num_insns += 1;
557
}
558
 
559
 
560
static void emit2(int64_t oc)
561
{
562
     emitAlignedCode(oc & 255);
563
     emitCode((oc >> 8) & 255);
564
     num_bytes += 2;
565
     num_insns += 1;
566
}
567
 
568
static void emit6(int64_t oc)
569
{
570
     emitAlignedCode(oc & 255);
571
     emitCode((oc >> 8) & 255);
572
     emitCode((oc >> 16) & 255);
573
     emitCode((oc >> 24) & 255);
574
     emitCode((oc >> 32) & 255);
575
     emitCode((oc >> 40) & 255);
576
     num_bytes += 6;
577
     num_insns += 1;
578
}
579
 
580
// ---------------------------------------------------------------------------
581
// Emit code aligned to a code address.
582
// ---------------------------------------------------------------------------
583
 
584
static void emitAlignedCode(int cd)
585
{
586
     int64_t ad;
587
 
588
 
589
     ad = code_address & 15;
590
     while (ad != 0 && ad != 2 && ad != 4 && ad != 6 &&
591
            ad != 8 && ad != 10 && ad != 12 && ad != 14) {
592
         emitByte(0x00);
593
         ad = code_address & 15;
594
     }
595
 
596
     emitByte(cd);
597
}
598
 
599
 
600
// ---------------------------------------------------------------------------
601
// Determine how big of a prefix is required.
602
// ---------------------------------------------------------------------------
603
 
604
static int fitsIn0(int64_t v)
605
{
606
    return (((v < 0) && ((v >> 14) == -1L)) || ((v >= 0) && ((v >> 14) == 0)));
607
}
608
 
609
static int fitsIn10(int64_t v)
610
{
611
    return (((v < 0) && ((v >> 24) == -1L)) || ((v >= 0) && ((v >> 24) == 0)));
612
}
613
 
614
static int fitsIn28(int64_t v)
615
{
616
    return (((v < 0) && ((v >> 42) == -1L)) || ((v >= 0) && ((v >> 42) == 0)));
617
}
618
 
619
static int fitsIn41(int64_t v)
620
{
621
    return (((v < 0) && ((v >> 55) == -1L)) || ((v >= 0) && ((v >> 55) == 0)));
622
}
623
// ---------------------------------------------------------------------------
624
// Emit constant extension for 15-bit operands.
625
// Returns number of constant prefixes placed.
626
// ---------------------------------------------------------------------------
627
 
628
static int emitImm15(int64_t v, int force)
629
{
630
     int nn;
631
 
632
     if (fitsIn0(v))
633
        return 0;
634
     else if (fitsIn10(v)) {
635
         emit2(
636
            ((v >> 16) << 7) | ((v>>15) & 1) |
637
            0x10
638
         );
639
         return 1;
640
     }
641
     else if (fitsIn28(v)) {
642
         emit_insn(0x78|(((v >> 18)&0x1FFFFFFLL) << 7)|((v >> 15)&7));
643
         return 1;
644
     }
645
     else if (fitsIn41(v)) {
646
         emit6(0x13|((v >> 15)&0x1FFFFFFFFFFLL) << 7);
647
         return 1;
648
     }
649
     else {
650
         emit_insn(0x78|(((v >> 46)&0x3FFFFLL) << 7)|((v >> 43)&7));
651
         emit_insn(0x78|(((v >> 18)&0x1FFFFFFLL) << 7)|((v >> 15)&7));
652
         return 2;
653
     }
654
 
655
     // ToDo: modify the fixup record type based on the number of prefixes emitted.
656
    if (bGen && lastsym && !use_gp && (lastsym->isExtern || lastsym->defined==0))
657
    if( lastsym->segment < 5)
658
    sections[segment+7].AddRel(sections[segment].index,((int64_t)(lastsym->ord+1) << 32) | nn+1 | (lastsym->isExtern ? 128 : 0)|
659
    (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
660
     return nn;
661
}
662
 
663
// ---------------------------------------------------------------------------
664
// bfextu r1,r2,#1,#63
665
// ---------------------------------------------------------------------------
666
 
667
static void process_bitfield(int oc)
668
{
669
    int Ra;
670
    int Rt;
671
    int mb;
672
    int me;
673
 
674
    Rt = getRegisterX();
675
    need(',');
676
    Ra = getRegisterX();
677
    need(',');
678
    NextToken();
679
    mb = (int)expr();
680
    need(',');
681
    NextToken();
682
    me = (int)expr();
683
    emit_insn(
684
        (oc << 29) |
685
        (me << 23) |
686
        (mb << 17) |
687
        (Rt << 12) |
688
        (Ra << 7) |
689
        0x03          // bitfield
690
    );
691
}
692
 
693
// ---------------------------------------------------------------------------
694
// sys 4
695
// ---------------------------------------------------------------------------
696
 
697
static void process_brk(int oc)
698
{
699
    int val;
700
 
701
    NextToken();
702
    val = (int)expr();
703
    emit_insn(
704
        (oc << 30) |
705
        ((val & 0x1ff) << 17) |
706
        (30 << 7) |
707
        0x38
708
    );
709
}
710
 
711
// ----------------------------------------------------------------------------
712
// chk r1,r2,b32
713
// ----------------------------------------------------------------------------
714
 
715
static void process_chk(int oc)
716
{
717
     int Ra;
718
     int Br;
719
     int Rt;
720
 
721
     Rt = getRegisterX();
722
     need(',');
723
     Ra = getRegisterX();
724
     need(',');
725
     Br = getBoundsRegister();
726
     emit_insn(
727
         (oc << 25) |
728
         (Br << 17) |
729
         (Rt << 12) |
730
         (Ra << 7) |
731
         0x02
732
     );
733
     prevToken();
734
}
735
 
736
// ---------------------------------------------------------------------------
737
// COM is an alternate mnemonic for EOR Rt,Ra,#-1
738
// com r3,r3
739
// ---------------------------------------------------------------------------
740
 
741
static void process_com()
742
{
743
    int Ra;
744
    int Rt;
745
 
746
    Rt = getRegister();
747
    need(',');
748
    Ra = getRegister();
749
    prevToken();
750
    emit_insn(
751
        (0x7fff << 17) |
752
        (Rt << 12) |
753
        (Ra << 7) |
754
        0x0e           // EOR
755
    );
756
}
757
 
758
// ----------------------------------------------------------------------------
759
// cpuid r1,r2,#0
760
// ----------------------------------------------------------------------------
761
 
762
static void process_cpuid(int oc)
763
{
764
     int Ra;
765
     int Rt;
766
     int val;
767
 
768
     Rt = getRegisterX();
769
     need(',');
770
     Ra = getRegisterX();
771
     need(',');
772
     NextToken();
773
     val = (int)expr();
774
     emit_insn(
775
         (oc << 25) |
776
         ((val & 15) << 17) |
777
         (Rt << 12) |
778
         (Ra << 7) |
779
         0x02
780
     );
781
     prevToken();
782
}
783
 
784
// ---------------------------------------------------------------------------
785
// JAL also processes JMP and JSR
786
// jal r0,main
787
// jal r0,[r19]
788
// jmp (tbl,r2)
789
// ---------------------------------------------------------------------------
790
 
791
static void process_jal(int oc, int Rt)
792
{
793
    int64_t addr;
794
    int Ra;
795
 
796
    // -1 indicates to parse a target register
797
    if (Rt == -1) {
798
        Rt = getRegisterX();
799
        if (Rt==-1) {
800
            printf("Expecting a target register.");
801
            return ;
802
        }
803
        need(',');
804
    }
805
    NextToken();
806
    // Memory indirect ?
807
    if (token=='(' || token=='[') {
808
       Ra = getRegisterX();
809
       if (Ra==-1) {
810
           Ra = 0;
811
           NextToken();
812
           addr = expr();
813
           prevToken();
814
           if (token==',') {
815
               NextToken();
816
               Ra = getRegisterX();
817
               if (Ra==-1) Ra = 0;
818
           }
819
           else if (token=='[') {
820
                NextToken();
821
               Ra = getRegisterX();
822
               if (Ra==-1) Ra = 0;
823
               need(']');
824
               NextToken();
825
           }
826
           if (token!=')' && token != ']')
827
               printf("Missing close bracket.\r\n");
828
           emitImm15(addr,lastsym!=(SYM*)NULL);
829
           emit_insn(
830
               ((addr & 0x7fffLL) << 17) |
831
               (Rt << 12) |
832
               (Ra << 7) |
833
               0x3e
834
           );
835
           return;
836
       }
837
       // Simple [Rn]
838
       else {
839
            if (token != ')' && token!=']')
840
                printf("Missing close bracket\r\n");
841
            emit_insn(
842
                (Rt << 12) |
843
                (Ra << 7) |
844
                0x3C
845
            );
846
            return;
847
       }
848
    }
849
    addr = expr() >> 1;
850
    prevToken();
851
    // d(Rn)? 
852
    if (token=='(' || token=='[') {
853
        NextToken();
854
        Ra = getRegisterX();
855
        if (Ra==-1) {
856
            printf("Illegal jump address mode.\r\n");
857
            Ra = 0;
858
        }
859
        emitImm15(addr,0);
860
        emit_insn(
861
            ((addr & 0x7fffLL) << 17) |
862
            (Rt << 12) |
863
            (Ra << 7) |
864
            0x3C
865
        );
866
        return;
867
    }
868
    emitImm15(addr, code_bits > 32);
869
    emit_insn(
870
        ((addr & 0x7fffLL) << 17) |
871
        (Rt << 12) |
872
        0x3C
873
    );
874
}
875
 
876
// ---------------------------------------------------------------------------
877
// subi r1,r2,#1234
878
// ---------------------------------------------------------------------------
879
 
880
static void process_riop(int oc)
881
{
882
    int Ra;
883
    int Rt;
884
    char *p;
885
    int64_t val;
886
 
887
    p = inptr;
888
    Rt = getRegisterX();
889
    need(',');
890
    Ra = getRegisterX();
891
    need(',');
892
    NextToken();
893
    val = expr();
894
    emitImm15(val,lastsym!=(SYM*)NULL);
895
    if (oc == 0x14 && Ra==Rt && val >= 0 && val <= 15) {
896
        emit2(
897
            ((val & 15) << 12) |
898
            (Ra << 7) |
899
            0x22
900
        );
901
    }
902
    else if (oc==0x15 && Ra==30 && Rt==30 && val >=0 && val < 4096 && (val &7)==0) {
903
        emit2(
904
            (((val >> 3)&0x1ff) << 7) |
905
            0x25
906
        );
907
    }
908
    else
909
        emit_insn(
910
            ((val & 0x7fff) << 17) |
911
            (Rt << 12) |
912
            (Ra << 7) |
913
            oc
914
        );
915
}
916
 
917
// ---------------------------------------------------------------------------
918
// add r1,r2,r12
919
// ---------------------------------------------------------------------------
920
 
921
static void process_rrop(int oc)
922
{
923
    int Ra;
924
    int Rb;
925
    int Rt;
926
    char *p;
927
 
928
    p = inptr;
929
    Rt = getRegisterX();
930
    need(',');
931
    Ra = getRegisterX();
932
    need(',');
933
    NextToken();
934
    if (token=='#') {
935
        inptr = p;
936
        switch(oc & 0x7F) {
937
        case 4: process_riop(4); return;  // add
938
        case 5: process_riop(5); return;  // sub
939
        case 6: process_riop(6); return;  // cmp
940
        case 7: process_riop(7); return;  // mul
941
        case 8: process_riop(8); return;  // div
942
        case 9: process_riop(9); return;  // mod
943
        case 12: process_riop(12); return;  // and
944
        case 13: process_riop(13); return;  // or
945
        case 14: process_riop(14); return;  // eor
946
        case 0x14: process_riop(0x14); return;  // addu
947
        case 0x15: process_riop(0x15); return;  // subu
948
        case 0x16: process_riop(0x16); return;  // cmpu
949
        case 0x17: process_riop(0x17); return;  // mulu
950
        case 0x18: process_riop(0x18); return;  // divu
951
        case 0x19: process_riop(0x19); return;  // modu
952
        // Shift
953
        case 0x30:
954
        case 0x31:
955
        case 0x32:
956
        case 0x33:
957
        case 0x34:
958
             process_shifti((oc & 0x7F) + 8); return;
959
        default:    process_riop(oc); return;
960
        }
961
        return;
962
    }
963
    prevToken();
964
    Rb = getRegisterX();
965
    prevToken();
966
    emit_insn(
967
              ((oc & 0x7f) << 25) |
968
//              ((oc >> 6) << 31) | // for shifts
969
              (Rb << 17) |
970
              (Rt << 12) |
971
              (Ra << 7)|
972
              2
973
    );
974
}
975
 
976
// ---------------------------------------------------------------------------
977
// fabs.d fp1,fp2[,rm]
978
// ---------------------------------------------------------------------------
979
 
980
static void process_fprop(int oc)
981
{
982
    int Ra;
983
    int Rt;
984
    char *p;
985
    int  sz;
986
    int fmt;
987
    int rm;
988
 
989
    rm = 0;
990
    sz = 'd';
991
    if (*inptr=='.') {
992
        inptr++;
993
        if (strchr("sdtqSDTQ",*inptr)) {
994
            sz = tolower(*inptr);
995
            inptr++;
996
        }
997
        else
998
            printf("Illegal float size.\r\n");
999
    }
1000
    p = inptr;
1001
    if (oc==0x65 || oc==0x66)  // mffp, mv2fix
1002
        Rt = getRegister();
1003
    else
1004
        Rt = getFPRegister();
1005
    need(',');
1006
    if (oc==0x1C || oc==0x1D)  // mtfp, mv2flt
1007
        Ra = getRegister();
1008
    else
1009
        Ra = getFPRegister();
1010
    if (token==',')
1011
       rm = getFPRoundMode();
1012
    prevToken();
1013
 
1014
    switch(sz) {
1015
    case 's': fmt = 0; break;
1016
    case 'd': fmt = 1; break;
1017
    case 't': fmt = 2; break;
1018
    case 'q': fmt = 3; break;
1019
    }
1020
    emit_insn(
1021
        (oc << 25) |
1022
        (fmt << 20) |
1023
        (rm << 17) |
1024
        (Rt << 12) |
1025
        (Ra << 7) |
1026
        0x02
1027
    );
1028
}
1029
 
1030
// ---------------------------------------------------------------------------
1031
// fadd.d fp1,fp2,fp12[,rm]
1032
// fcmp.d r1,fp3,fp10[,rm]
1033
// ---------------------------------------------------------------------------
1034
 
1035
static void process_fprrop(int oc)
1036
{
1037
    int Ra;
1038
    int Rb;
1039
    int Rt;
1040
    char *p;
1041
    int  sz;
1042
    int fmt;
1043
    int rm;
1044
 
1045
    rm = 0;
1046
    sz = 'd';
1047
    if (*inptr=='.') {
1048
        inptr++;
1049
        if (strchr("sdtqSDTQ",*inptr)) {
1050
            sz = tolower(*inptr);
1051
            inptr++;
1052
        }
1053
        else
1054
            printf("Illegal float size.\r\n");
1055
    }
1056
    p = inptr;
1057
    if (oc==0x2A)        // fcmp
1058
        Rt = getRegister();
1059
    else
1060
        Rt = getFPRegister();
1061
    need(',');
1062
    Ra = getFPRegister();
1063
    need(',');
1064
    Rb = getFPRegister();
1065
    if (token==',')
1066
       rm = getFPRoundMode();
1067
    prevToken();
1068
    switch(sz) {
1069
    case 's': fmt = 0; break;
1070
    case 'd': fmt = 1; break;
1071
    case 't': fmt = 2; break;
1072
    case 'q': fmt = 3; break;
1073
    }
1074
    emit_insn(
1075
        (fmt << 25) |
1076
        (rm << 22) |
1077
        (Rb << 17) |
1078
        (Rt << 12) |
1079
        (Ra << 7) |
1080
        oc
1081
    );
1082
}
1083
 
1084
// ---------------------------------------------------------------------------
1085
// fcx r0,#2
1086
// fdx r1,#0
1087
// ---------------------------------------------------------------------------
1088
 
1089
static void process_fpstat(int oc)
1090
{
1091
    int Ra;
1092
    int64_t bits;
1093
    char *p;
1094
 
1095
    p = inptr;
1096
    bits = 0;
1097
    Ra = getRegister();
1098
    if (token==',') {
1099
       NextToken();
1100
       bits = expr();
1101
    }
1102
    prevToken();
1103
    emitAlignedCode(0x01);
1104
    emitCode(Ra);
1105
    emitCode(bits & 0xff);
1106
    emitCode(0x00);
1107
    emitCode(oc);
1108
}
1109
 
1110
// ---------------------------------------------------------------------------
1111
// not r3,r3
1112
// ---------------------------------------------------------------------------
1113
 
1114
static void process_rop(int oc)
1115
{
1116
    int Ra;
1117
    int Rt;
1118
 
1119
    Rt = getRegister();
1120
    need(',');
1121
    Ra = getRegister();
1122
    prevToken();
1123
    emit_insn(
1124
        (oc << 25) |
1125
        (Rt << 12) |
1126
        (Ra << 7) |
1127
        0x02
1128
    );
1129
}
1130
 
1131
// ---------------------------------------------------------------------------
1132
// beq r1,label
1133
// ---------------------------------------------------------------------------
1134
 
1135
static void process_bcc(int oc)
1136
{
1137
    int Ra;
1138
    int64_t val;
1139
    int64_t disp,disp1;
1140
    int64_t ad;
1141
 
1142
    val = 0;
1143
    Ra = getRegisterX();
1144
    need(',');
1145
    NextToken();
1146
    val = expr();
1147
    ad = code_address;
1148
    disp1 = ((val - ad) >> 1);
1149
    disp = ((val - ad) >> 1) & 0x7fffLL;
1150
 
1151
    if ((oc == 0 || oc==1) && disp1 != 0 && disp1 >= -8 && disp1 <= 7) {
1152
       emit2(
1153
           ((disp & 15) << 12) |
1154
           (Ra << 7) |
1155
           (oc ? 0x33 : 0x32)
1156
       );
1157
    }
1158
    else
1159
 
1160
        emit_insn(
1161
            (disp << 17) |
1162
            (oc << 12) |
1163
            (Ra << 7) |
1164
            0x3D
1165
        );
1166
}
1167
 
1168
// ---------------------------------------------------------------------------
1169
// bra label
1170
// ---------------------------------------------------------------------------
1171
 
1172
static void process_bra(int oc)
1173
{
1174
    int64_t val;
1175
    int64_t disp,disp1;
1176
    int64_t ad;
1177
 
1178
    val = 0;
1179
    NextToken();
1180
    val = expr();
1181
     // ToDo: modify the fixup record type based on the number of prefixes emitted.
1182
    if (bGen && lastsym && (lastsym->isExtern || lastsym->defined==0))
1183
    if( lastsym->segment < 5)
1184
    sections[segment+7].AddRel(sections[segment].index,((int64_t)(lastsym->ord+1) << 32) | FUT_R27 | (lastsym->isExtern ? 128 : 0)|
1185
    (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
1186
    ad = code_address;
1187
    disp1 = ((val - ad) >> 1);
1188
    disp = ((val - ad) >> 1) & 0x1ffffffLL;
1189
    if (disp1 >= -256 && disp1 <= 255 && disp1 != 0 && oc==0x3A)
1190
       emit2(
1191
            ((disp1 & 0x1ff) << 7) |
1192
            0x23
1193
       );
1194
    else
1195
        emit_insn(
1196
            (disp << 7) |
1197
            (oc & 0x7f)
1198
        );
1199
}
1200
 
1201
// ---------------------------------------------------------------------------
1202
// ---------------------------------------------------------------------------
1203
 
1204
static void getIndexScale(int *sc)
1205
{
1206
      int64_t val;
1207
 
1208
      NextToken();
1209
      val = expr();
1210
      prevToken();
1211
      switch(val) {
1212
      case 0: *sc = 0; break;
1213
      case 1: *sc = 0; break;
1214
      case 2: *sc = 1; break;
1215
      case 4: *sc = 2; break;
1216
      case 8: *sc = 3; break;
1217
      default: printf("Illegal scaling factor.\r\n");
1218
      }
1219
}
1220
 
1221
// ---------------------------------------------------------------------------
1222
// ---------------------------------------------------------------------------
1223
static void process_message()
1224
{
1225
    char buf[200];
1226
    int nn;
1227
 
1228
    while(*inptr != '"' && *inptr != '\n') inptr++;
1229
    if (*inptr=='\n') { NextToken(); return; }
1230
    nn = 0;
1231
    inptr++;
1232
    while (*inptr != '"' && *inptr != '\n' && nn < 197) {
1233
        buf[nn] = *inptr;
1234
        inptr++;
1235
        nn++;
1236
    }
1237
    buf[nn] = '\0';
1238
    strcat_s(buf, sizeof(buf), "\r\n");
1239
    printf(buf);
1240
    ScanToEOL();
1241
}
1242
 
1243
// ---------------------------------------------------------------------------
1244
// expr
1245
// expr[Reg]
1246
// expr[Reg+Reg*sc]
1247
// [Reg]
1248
// [Reg+Reg*sc]
1249
// ---------------------------------------------------------------------------
1250
 
1251
static void mem_operand(int64_t *disp, int *regA, int *regB, int *sc, int *md)
1252
{
1253
     int64_t val;
1254
     int8_t ind;
1255
 
1256
     ind = false;
1257
 
1258
     // chech params
1259
     if (disp == (int64_t *)NULL)
1260
         return;
1261
     if (regA == (int *)NULL)
1262
         return;
1263
     if (regB == (int *)NULL)
1264
         return;
1265
     if (sc==(int *)NULL)
1266
         return;
1267
     if (md==(int *)NULL)
1268
         return;
1269
 
1270
     *disp = 0;
1271
     *regA = -1;
1272
     *regB = -1;
1273
     *sc = 0;
1274
     if (token!='[') {;
1275
          val = expr();
1276
          *disp = val;
1277
     }
1278
     if (token=='[') {
1279
         *regA = getRegisterX();
1280
         // Memory indirect ?
1281
         if (*regA == -1) {
1282
             ind = true;
1283
             prevToken();
1284
             *disp = expr();
1285
             if (token=='[') {
1286
                 *regA = getRegisterX();
1287
                 need(']');
1288
                 if (*regA==-1)
1289
                     printf("expecting a register\r\n");
1290
                 NextToken();
1291
             }
1292
             else
1293
                 *regA = 0;
1294
             need(']');
1295
             NextToken();
1296
             if (token=='[') {
1297
                 *regB = getRegisterX();
1298
                 if (*regB==-1)
1299
                     printf("expecting a register\r\n");
1300
                 if (token=='*')
1301
                     getIndexScale(sc);
1302
                 need(']');
1303
             }
1304
             NextToken();
1305
             if (token=='+') {
1306
                 NextToken();
1307
                 if (token=='+') {
1308
                     *md = 7;
1309
                     return;
1310
                 }
1311
             }
1312
             else if (token=='-') {
1313
                  NextToken();
1314
                  if (token=='-') {
1315
                      *md = 6;
1316
                      return;
1317
                  }
1318
             }
1319
             *md = 5;
1320
             return;
1321
         }
1322
         if (token=='+') {
1323
              *sc = 0;
1324
              *regB = getRegisterX();
1325
              if (*regB == -1) {
1326
                  printf("expecting a register\r\n");
1327
              }
1328
              if (token=='*') {
1329
                  getIndexScale(sc);
1330
              }
1331
         }
1332
         need(']');
1333
         if (token=='+') {
1334
             NextToken();
1335
             if (token=='+') {
1336
                 *md = 3;
1337
                 return;
1338
             }
1339
         }
1340
         else if (token=='-') {
1341
              NextToken();
1342
              if (token=='-') {
1343
                  *md = 2;
1344
                  return;
1345
              }
1346
         }
1347
         *md = 1;
1348
     }
1349
}
1350
 
1351
// ---------------------------------------------------------------------------
1352
// sw disp[r1],r2
1353
// sw [r1+r2],r3
1354
// ----------------------------------------------------------------------------
1355
 
1356
static void process_store(int oc)
1357
{
1358
    int Ra;
1359
    int Rb;
1360
    int Rs;
1361
    int sc;
1362
    int md;
1363
    int64_t disp;
1364
 
1365
    if (oc==0x71)
1366
        Rs = getFPRegister();
1367
    else
1368
        Rs = getRegisterX();
1369
    expect(',');
1370
    mem_operand(&disp, &Ra, &Rb, &sc, &md);
1371
    if (Rs < 0) {
1372
        printf("Expecting a source register.\r\n");
1373
        ScanToEOL();
1374
        return;
1375
    }
1376
    if (Rb > 0) {
1377
       if (disp < 0)
1378
           printf("store offset must be greater than zero.\r\n");
1379
       if (disp > 255LL)
1380
           printf("store offset too large.\r\n");
1381
        emit_insn(
1382
            ((disp & 0xff) << 24) |
1383
            (sc << 22) |
1384
            (Rb << 17) |
1385
            (Rs << 12) |
1386
            (Ra << 7) |
1387
            (oc==0x71 ? 0x75 : oc+8)
1388
        );
1389
       return;
1390
    }
1391
    emitImm15(disp,lastsym!=(SYM*)NULL);
1392
    if (Ra < 0) Ra = 0;
1393
    // Convert SW Rn,D[BP] to short form
1394
    if (oc==0x63 && Ra==27 && ((disp & 0x7)==0) && ((disp >> 3) >= -8) && ((disp >> 3) <= 7)) {
1395
        emit2(
1396
           (((disp >> 3) & 0x0f) << 12) |
1397
           (Rs << 7) |
1398
           0x67
1399
        );
1400
    }
1401
    else
1402
        emit_insn(
1403
            ((disp & 0x7fff) << 17) |
1404
            (Rs << 12) |
1405
            (Ra << 7) |
1406
            oc
1407
        );
1408
    ScanToEOL();
1409
}
1410
 
1411
// ----------------------------------------------------------------------------
1412
// ----------------------------------------------------------------------------
1413
 
1414
static void process_ldi(int oc)
1415
{
1416
    int Rt;
1417
    int64_t val;
1418
 
1419
    Rt = getRegisterX();
1420
    if (Rt==-1) {
1421
        Rt = getFPRegister();
1422
        oc = 0x1A;
1423
    }
1424
    expect(',');
1425
    val = expr();
1426
    emitImm15(val,lastsym!=(SYM*)NULL);
1427
 
1428
    if (val <= 7 && val >= -8)
1429
       emit2(
1430
           ((val & 15) << 12) |
1431
           (Rt << 7) |
1432
           0x34
1433
       );
1434
    else
1435
 
1436
        emit_insn(
1437
            ((val & 0x7FFFLL) << 17) |
1438
            (Rt << 12) |
1439
            oc
1440
        );
1441
}
1442
 
1443
// ----------------------------------------------------------------------------
1444
// lw r1,disp[r2]
1445
// lw r1,[r2+r3]
1446
// cas r2,disp[r1]
1447
// ----------------------------------------------------------------------------
1448
 
1449
static void process_load(int oc)
1450
{
1451
    int Ra;
1452
    int Rb;
1453
    int Rt;
1454
    int sc;
1455
    int md;
1456
    char *p;
1457
    int64_t disp;
1458
    int fixup = 5;
1459
 
1460
    sc = 0;
1461
    p = inptr;
1462
    if (oc==0x51)
1463
       Rt = getFPRegister();
1464
    else
1465
        Rt = getRegisterX();
1466
    if (Rt < 0) {
1467
        printf("Expecting a target register.\r\n");
1468
//        printf("Line:%.60s\r\n",p);
1469
        ScanToEOL();
1470
        inptr-=2;
1471
        return;
1472
    }
1473
    expect(',');
1474
    mem_operand(&disp, &Ra, &Rb, &sc, &md);
1475
    if (Rb >= 0) {
1476
       if (disp < 0)
1477
           printf("load offset must be greater than zero.\r\n");
1478
       if (disp > 255LL)
1479
           printf("load offset too large.\r\n");
1480
       fixup = 11;
1481
       if (oc==0x87 || oc==0x6c) {  //LWS CAS
1482
          printf("Address mode not supported.\r\n");
1483
          return;
1484
       }
1485
       if (oc==0x9F) oc = 0x8F;  // LEA
1486
       else oc = oc + 8;
1487
        emit_insn(
1488
            ((disp & 0xff) << 24) |
1489
            (sc << 22) |
1490
            (Rb << 17) |
1491
            (Rt << 12) |
1492
            (Ra << 7) |
1493
            oc
1494
        );
1495
       return;
1496
    }
1497
    emitImm15(disp,lastsym!=(SYM*)NULL);
1498
    if (Ra < 0) Ra = 0;
1499
    // Convert LW Rn,D[BP] to short form
1500
    if (oc==0x46 && Ra==27 && ((disp & 0x7)==0) && ((disp >> 3) >= -8) && ((disp >> 3) <= 7)) {
1501
        emit2(
1502
           (((disp >> 3) & 0x0f) << 12) |
1503
           (Rt << 7) |
1504
           0x5F
1505
        );
1506
    }
1507
    else
1508
        emit_insn(
1509
            ((disp & 0x7ffff) << 17) |
1510
            (Rt << 12) |
1511
            (Ra << 7) |
1512
            oc
1513
        );
1514
    ScanToEOL();
1515
}
1516
 
1517
// ----------------------------------------------------------------------------
1518
// inc -8[bp],#1
1519
// ----------------------------------------------------------------------------
1520
 
1521
static void process_inc(int oc)
1522
{
1523
    int Ra;
1524
    int Rb;
1525
    int sc;
1526
    int sg;
1527
    int64_t incamt;
1528
    int64_t disp;
1529
    char *p;
1530
    int fixup = 5;
1531
    int neg = 0;
1532
 
1533
    NextToken();
1534
    p = inptr;
1535
    mem_operand(&disp, &Ra, &Rb, &sc, &sg);
1536
    incamt = 1;
1537
    if (token==']')
1538
       NextToken();
1539
    if (token==',') {
1540
        NextToken();
1541
        incamt = expr();
1542
        prevToken();
1543
    }
1544
    if (Rb >= 0) {
1545
       if (disp < 0)
1546
           printf("inc offset must be greater than zero.\r\n");
1547
       if (disp > 255LL)
1548
           printf("inc offset too large.\r\n");
1549
       oc = 0x6F;  // INCX
1550
       emit_insn(
1551
           ((disp & 0xFF) << 24) |
1552
           (sc << 22) |
1553
           (Rb << 17) |
1554
           ((incamt & 0x1F) << 12) |
1555
           (Ra << 7) |
1556
           oc
1557
       );
1558
       return;
1559
    }
1560
    if (oc==0x65) neg = 1;
1561
    oc = 0x64;        // INC
1562
    emitImm15(disp,lastsym!=(SYM*)NULL);
1563
    if (Ra < 0) Ra = 0;
1564
    if (neg) incamt = -incamt;
1565
    emit_insn(
1566
        ((disp & 0x7FFF) << 17) |
1567
        ((incamt & 0x1F) << 12) |
1568
        (Ra << 7) |
1569
        oc
1570
    );
1571
    ScanToEOL();
1572
}
1573
 
1574
// ----------------------------------------------------------------------------
1575
// pea disp[r2]
1576
// pea [r2+r3]
1577
// ----------------------------------------------------------------------------
1578
 
1579
static void process_pea()
1580
{
1581
    int oc;
1582
    int Ra;
1583
    int Rb;
1584
    int sc;
1585
    int sg;
1586
    char *p;
1587
    int64_t disp;
1588
    int fixup = 5;
1589
 
1590
    p = inptr;
1591
    NextToken();
1592
    mem_operand(&disp, &Ra, &Rb, &sc, &sg);
1593
    if (Rb >= 0) {
1594
       // For now PEAX isn't supported
1595
       printf("PEA: Illegal address mode.\r\n");
1596
       return;
1597
       fixup = 11;
1598
       oc = 0xB9;  // PEAX
1599
        if (bGen && lastsym && Ra != 249 && !use_gp)
1600
        if( lastsym->segment < 5)
1601
        sections[segment+7].AddRel(sections[segment].index,((int64_t)(lastsym->ord+1) << 32) | fixup | (lastsym->isExtern ? 128 : 0)|
1602
        (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
1603
       emitCode(Ra);
1604
       emitCode(Rb);
1605
       emitCode(0x00);
1606
       emitCode(sc | ((sg & 15) << 2));
1607
       return;
1608
    }
1609
    oc = 0x65;        // PEA
1610
    emitImm15(disp,lastsym!=(SYM*)NULL);
1611
    if (Ra < 0) Ra = 0;
1612
    emit_insn(
1613
        ((disp & 0x7FFFLL) << 17) |
1614
        (0x1E << 12) |
1615
        (Ra << 7) |
1616
        oc
1617
    );
1618
    ScanToEOL();
1619
}
1620
 
1621
 
1622
// ----------------------------------------------------------------------------
1623
// push r1
1624
// push #123
1625
// push -8[BP]
1626
// ----------------------------------------------------------------------------
1627
 
1628
static void process_pushpop(int oc)
1629
{
1630
    int Ra,Rb;
1631
    int64_t val;
1632
    int64_t disp;
1633
    int sc;
1634
    int sg;
1635
 
1636
    Ra = -1;
1637
    Rb = -1;
1638
    NextToken();
1639
    if (token=='#' && oc==0x67) {  // Filter to PUSH
1640
       val = expr();
1641
       emitImm15(val,(code_bits > 32 || data_bits > 32) && lastsym!=(SYM *)NULL);
1642
        emit_insn(
1643
            ((val & 0x7FFFLL) << 17) |
1644
            (0x1E << 12) |
1645
            (0x00 << 7) |
1646
            0x65   // PEA
1647
        );
1648
        return;
1649
    }
1650
    prevToken();
1651
    Ra = getRegisterX();
1652
    if (Ra == -1) {
1653
        NextToken();
1654
        mem_operand(&disp, &Ra, &Rb, &sc, &sg);
1655
        emitImm15(disp,(code_bits > 32 || data_bits > 32) && lastsym!=(SYM *)NULL);
1656
        if (Ra==-1) Ra = 0;
1657
        emit_insn(
1658
            ((disp & 0x7FFFLL) << 17) |
1659
            (0x1E << 12) |
1660
            (Ra << 7) |
1661
            0x66
1662
        );
1663
        ScanToEOL();
1664
        return;
1665
    }
1666
    if (oc==0x57) { // POP
1667
 
1668
        emit2(
1669
           (2 << 12) |
1670
           (Ra << 7) |
1671
           0x31
1672
        );
1673
/*
1674
 
1675
        emit_insn(
1676
            (8 << 17) |
1677
            (Ra << 12) |
1678
            (0x1E << 7) |
1679
            oc
1680
        );
1681
*/
1682
        prevToken();
1683
        return;
1684
    }
1685
    //PUSH
1686
 
1687
    emit2(
1688
       (Ra << 7) |
1689
       0x31
1690
    );
1691
/*
1692
    emit_insn(
1693
        (0x1E << 12) |
1694
        (Ra << 7)
1695
        | oc
1696
    );
1697
*/
1698
    prevToken();
1699
}
1700
 
1701
// ----------------------------------------------------------------------------
1702
// mov r1,r2
1703
// ----------------------------------------------------------------------------
1704
 
1705
static void process_mov()
1706
{
1707
     int Ra;
1708
     int Rt;
1709
 
1710
     Rt = getRegisterX();
1711
     need(',');
1712
     Ra = getRegisterX();
1713
     emit2(
1714
           ((Rt & 0xf) << 12) |
1715
           (Ra << 7) |
1716
           0x20 | ((Rt >> 4) & 1)
1717
     );
1718
/*
1719
     emit_insn(
1720
         (0x0D << 25) | // OR
1721
         (Rt << 12) |
1722
         (Ra << 7) |
1723
         0x02
1724
     );
1725
*/
1726
     prevToken();
1727
}
1728
 
1729
// ----------------------------------------------------------------------------
1730
// neg r1,r2
1731
// ----------------------------------------------------------------------------
1732
 
1733
static void process_neg(int oc)
1734
{
1735
     int Ra;
1736
     int Rb;
1737
     int Rt;
1738
 
1739
     Ra = 0;
1740
     Rt = getRegisterX();
1741
     need(',');
1742
     Rb = getRegisterX();
1743
     emit_insn(
1744
         (oc << 25) | // SUBU
1745
         (Rb << 17) |
1746
         (Rt << 12) |
1747
         (Ra << 7) |
1748
         0x02
1749
     );
1750
     prevToken();
1751
}
1752
 
1753
// ----------------------------------------------------------------------------
1754
// sei
1755
// cli
1756
// rtd
1757
// rte
1758
// rti
1759
// ----------------------------------------------------------------------------
1760
 
1761
static void process_pctrl(int oc)
1762
{
1763
     int Rt;
1764
 
1765
     if (oc==29 || oc==30 || oc==31)
1766
         Rt = 30;
1767
     else
1768
         Rt = 0;
1769
     emit_insn(
1770
         (0x37 << 25) |
1771
         (oc << 17) |
1772
         (Rt << 12) |
1773
         0x02
1774
     );
1775
}
1776
 
1777
// ----------------------------------------------------------------------------
1778
// rts
1779
// rts #24
1780
// rtl
1781
// ----------------------------------------------------------------------------
1782
 
1783
static void process_rts(int oc)
1784
{
1785
     int64_t val;
1786
 
1787
     val = oc==0x3B ? 8 :0;
1788
     NextToken();
1789
     if (token=='#') {
1790
        val = expr();
1791
     }
1792
     emitImm15(val,(code_bits > 32 || data_bits > 32) && lastsym!=(SYM *)NULL);
1793
     if (val < 4096)
1794
         emit2(
1795
             (((val>>3) & 0x1FFLL) << 7) |
1796
             ((oc==0x27) ? 0x37 : 0x30)
1797
         );
1798
     else
1799
         emit_insn(
1800
             ((val & 0x7FFFLL) << 17) |
1801
             (0x1F << 12) |
1802
             (0x1E << 7) |
1803
             oc
1804
         );
1805
}
1806
 
1807
// ----------------------------------------------------------------------------
1808
// asli r1,r2,#5
1809
// ----------------------------------------------------------------------------
1810
 
1811
static void process_shifti(int oc)
1812
{
1813
     int Ra;
1814
     int Rt;
1815
     int64_t val;
1816
 
1817
     Rt = getRegisterX();
1818
     need(',');
1819
     Ra = getRegisterX();
1820
     need(',');
1821
     NextToken();
1822
     val = expr();
1823
     emit_insn(
1824
         (oc << 25) |
1825
         ((val & 63) << 17) |
1826
         (Rt << 12) |
1827
         (Ra << 7) |
1828
         0x02
1829
     );
1830
}
1831
 
1832
// ----------------------------------------------------------------------------
1833
// gran r1
1834
// ----------------------------------------------------------------------------
1835
 
1836
static void process_gran(int oc)
1837
{
1838
    int Rt;
1839
 
1840
    Rt = getRegisterX();
1841
    emitAlignedCode(0x01);
1842
    emitCode(0x00);
1843
    emitCode(Rt);
1844
    emitCode(0x00);
1845
    emitCode(oc);
1846
    prevToken();
1847
}
1848
 
1849
// ----------------------------------------------------------------------------
1850
// ----------------------------------------------------------------------------
1851
 
1852
static void process_mtspr(int oc)
1853
{
1854
    int spr;
1855
    int Ra;
1856
    int Rc;
1857
 
1858
    Rc = getRegisterX();
1859
    if (Rc==-1) {
1860
        Rc = 0;
1861
        spr = FISA64_getSprRegister();
1862
        if (spr==-1) {
1863
            printf("Line %d: An SPR is needed.\r\n", lineno);
1864
            return;
1865
        }
1866
    }
1867
    else
1868
       spr = 0;
1869
    need(',');
1870
    Ra = getRegisterX();
1871
    emit_insn(
1872
        (oc << 25) |
1873
        (spr << 17) |
1874
        (Rc << 12) |
1875
        (Ra << 7) |
1876
        0x02
1877
    );
1878
    if (Ra >= 0)
1879
    prevToken();
1880
}
1881
 
1882
// ----------------------------------------------------------------------------
1883
// ----------------------------------------------------------------------------
1884
 
1885
static void process_mtfp(int oc)
1886
{
1887
    int fpr;
1888
    int Ra;
1889
 
1890
    fpr = getFPRegister();
1891
    need(',');
1892
    Ra = getRegisterX();
1893
    emitAlignedCode(0x01);
1894
    emitCode(Ra);
1895
    emitCode(fpr);
1896
    emitCode(0x00);
1897
    emitCode(oc);
1898
    if (Ra >= 0)
1899
    prevToken();
1900
}
1901
 
1902
// ----------------------------------------------------------------------------
1903
// ----------------------------------------------------------------------------
1904
 
1905
static void process_mfspr(int oc)
1906
{
1907
    int spr;
1908
    int Rt;
1909
    int Ra;
1910
 
1911
    Rt = getRegisterX();
1912
    need(',');
1913
    Ra = getRegisterX();
1914
    if (Ra==-1) {
1915
        Ra = 0;
1916
        spr = FISA64_getSprRegister();
1917
        if (spr==-1) {
1918
            printf("An SPR is needed.\r\n");
1919
            return;
1920
        }
1921
    }
1922
    else
1923
        spr = 0;
1924
    emit_insn(
1925
        (oc << 25) |
1926
        (spr << 17) |
1927
        (Rt << 12) |
1928
        (Ra << 7) |
1929
        0x02
1930
    );
1931
    if (spr >= 0)
1932
    prevToken();
1933
}
1934
 
1935
// ----------------------------------------------------------------------------
1936
// ----------------------------------------------------------------------------
1937
 
1938
static void process_mffp(int oc)
1939
{
1940
    int fpr;
1941
    int Rt;
1942
 
1943
    Rt = getRegisterX();
1944
    need(',');
1945
    fpr = getFPRegister();
1946
    emitAlignedCode(0x01);
1947
    emitCode(fpr);
1948
    emitCode(Rt);
1949
    emitCode(0x00);
1950
    emitCode(oc);
1951
    if (fpr >= 0)
1952
    prevToken();
1953
}
1954
 
1955
// ----------------------------------------------------------------------------
1956
// ----------------------------------------------------------------------------
1957
 
1958
static void process_fprdstat(int oc)
1959
{
1960
    int Rt;
1961
 
1962
    Rt = getRegisterX();
1963
    emitAlignedCode(0x01);
1964
    emitCode(0x00);
1965
    emitCode(Rt);
1966
    emitCode(0x00);
1967
    emitCode(oc);
1968
}
1969
 
1970
// ----------------------------------------------------------------------------
1971
// ----------------------------------------------------------------------------
1972
 
1973
static void ProcessEOL(int opt)
1974
{
1975
    int mm;
1976
    int first;
1977
    int cc;
1978
        int64_t nn;
1979
 
1980
     //printf("Line: %d\r", lineno);
1981
     segprefix = -1;
1982
     if (bGen && (segment==codeseg || segment==dataseg || segment==rodataseg)) {
1983
    nn = binstart;
1984
    cc = 8;
1985
    if (segment==codeseg) {
1986
       cc = 12;
1987
/*
1988
        if (sections[segment].bytes[binstart]==0x61) {
1989
            fprintf(ofp, "%06LLX ", ca);
1990
            for (nn = binstart; nn < binstart + 5 && nn < sections[segment].index; nn++) {
1991
                fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
1992
            }
1993
            fprintf(ofp, "   ; imm\n");
1994
             if (((ca+5) & 15)==15) {
1995
                 ca+=6;
1996
                 binstart+=6;
1997
                 nn++;
1998
             }
1999
             else {
2000
                  ca += 5;
2001
                  binstart += 5;
2002
             }
2003
        }
2004
*/
2005
/*
2006
        if (sections[segment].bytes[binstart]==0xfd) {
2007
            fprintf(ofp, "%06LLX ", ca);
2008
            for (nn = binstart; nn < binstart + 5 && nn < sections[segment].index; nn++) {
2009
                fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
2010
            }
2011
            fprintf(ofp, "   ; imm\n");
2012
             if (((ca+5) & 15)==15) {
2013
                 ca+=6;
2014
                 binstart+=6;
2015
                 nn++;
2016
             }
2017
             else {
2018
                  ca += 5;
2019
                  binstart += 5;
2020
             }
2021
        }
2022
         if (sections[segment].bytes[binstart]==0xfe) {
2023
            fprintf(ofp, "%06LLX ", ca);
2024
            for (nn = binstart; nn < binstart + 5 && nn < sections[segment].index; nn++) {
2025
                fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
2026
            }
2027
            fprintf(ofp, "   ; imm\n");
2028
             if (((ca+5) & 15)==15) {
2029
                 ca+=6;
2030
                 nn++;
2031
             }
2032
             else {
2033
                  ca += 5;
2034
             }
2035
        }
2036
*/
2037
    }
2038
 
2039
    first = 1;
2040
    while (nn < sections[segment].index) {
2041
        fprintf(ofp, "%06LLX ", ca);
2042
        for (mm = nn; nn < mm + cc && nn < sections[segment].index; nn++) {
2043
            fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
2044
        }
2045
        for (; nn < mm + cc; nn++)
2046
            fprintf(ofp, "   ");
2047
        if (first & opt) {
2048
            fprintf(ofp, "\t%.*s\n", inptr-stptr-1, stptr);
2049
            first = 0;
2050
        }
2051
        else
2052
            fprintf(ofp, opt ? "\n" : "; NOP Ramp\n");
2053
        ca += cc;
2054
    }
2055
    // empty (codeless) line
2056
    if (binstart==sections[segment].index) {
2057
        fprintf(ofp, "%41s\t%.*s", "", inptr-stptr, stptr);
2058
    }
2059
    } // bGen
2060
    if (opt) {
2061
       stptr = inptr;
2062
       lineno++;
2063
    }
2064
//    printf("line:%d\r",lineno);
2065
    binstart = sections[segment].index;
2066
    ca = sections[segment].address;
2067
}
2068
 
2069
// ----------------------------------------------------------------------------
2070
// ----------------------------------------------------------------------------
2071
 
2072
void FISA64_processMaster()
2073
{
2074
    int nn;
2075
    int64_t bs1, bs2;
2076
 
2077
    lineno = 1;
2078
    binndx = 0;
2079
    binstart = 0;
2080
    bs1 = 0;
2081
    bs2 = 0;
2082
    inptr = &masterFile[0];
2083
    stptr = inptr;
2084
    code_address = 0;
2085
    bss_address = 0;
2086
    start_address = 0;
2087
    data_address = 0;
2088
    first_org = 1;
2089
    first_rodata = 1;
2090
    first_data = 1;
2091
    first_bss = 1;
2092
    for (nn = 0; nn < 12; nn++) {
2093
        sections[nn].index = 0;
2094
        if (nn == 0)
2095
        sections[nn].address = 0;
2096
        else
2097
        sections[nn].address = 0;
2098
        sections[nn].start = 0;
2099
        sections[nn].end = 0;
2100
    }
2101
    ca = code_address;
2102
    segment = codeseg;
2103
    memset(current_label,0,sizeof(current_label));
2104
    NextToken();
2105
    while (token != tk_eof) {
2106
//        printf("\t%.*s\n", inptr-stptr-1, stptr);
2107
//        printf("token=%d\r", token);
2108
j_processToken:
2109
        switch(token) {
2110
        case tk_eol: ProcessEOL(1); break;
2111
        case tk_add:  process_rrop(0x04); break;
2112
        case tk_addi: process_riop(0x04); break;
2113
        case tk_addu:  process_rrop(0x14); break;
2114
        case tk_addui: process_riop(0x14); break;
2115
        case tk_align: process_align(); continue; break;
2116
        case tk_and:  process_rrop(12); break;
2117
        case tk_andi:  process_riop(12); break;
2118
        case tk_asl:  process_rrop(0x30); break;
2119
        case tk_asli: process_shifti(0x38); break;
2120
        case tk_asr:  process_rrop(0x34); break;
2121
        case tk_asri: process_shifti(0x3C); break;
2122
        case tk_beq: process_bcc(0); break;
2123
        case tk_bfextu: process_bitfield(6); break;
2124
        case tk_bge: process_bcc(3); break;
2125
        case tk_bgt: process_bcc(2); break;
2126
        case tk_ble: process_bcc(5); break;
2127
        case tk_blt: process_bcc(4); break;
2128
        case tk_bmi: process_bcc(4); break;
2129
        case tk_bne: process_bcc(1); break;
2130
        case tk_bpl: process_bcc(3); break;
2131
        case tk_bra: process_bra(0x3A); break;
2132
        case tk_bsr: process_bra(0x39); break;
2133
//        case tk_bsr: process_bra(0x56); break;
2134
        case tk_bss:
2135
            if (first_bss) {
2136
                while(sections[segment].address & 4095)
2137
                    emitByte(0x00);
2138
                sections[3].address = sections[segment].address;
2139
                first_bss = 0;
2140
                binstart = sections[3].index;
2141
                ca = sections[3].address;
2142
            }
2143
            segment = bssseg;
2144
            break;
2145
        case tk_byte:  process_db(); break;
2146
        case tk_cas: process_load(0x6C); break;
2147
        case tk_chk: process_chk(0x1A); break;
2148
        case tk_cli: process_pctrl(0); break;
2149
        case tk_cmp: process_rrop(0x06); break;
2150
        case tk_cmpu: process_rrop(0x16); break;
2151
        case tk_code: process_code(); break;
2152
        case tk_com: process_com(); break;
2153
        case tk_cpuid: process_cpuid(0x36); break;
2154
        case tk_data:
2155
             // Process data declarations as if we are in the rodata segment
2156
             // for initialization data.
2157
             if (isInitializationData) {
2158
                 token = tk_rodata;
2159
                 goto j_processToken;
2160
             }
2161
            if (first_data) {
2162
                while(sections[segment].address & 4095)
2163
                    emitByte(0x00);
2164
                sections[2].address = sections[segment].address;   // set starting address
2165
                first_data = 0;
2166
                binstart = sections[2].index;
2167
                ca = sections[2].address;
2168
            }
2169
            process_data(dataseg);
2170
            break;
2171
        case tk_db:  process_db(); break;
2172
        case tk_dc:  process_dc(); break;
2173
        case tk_dec: process_inc(0x65); break;
2174
        case tk_dh:  process_dh(); break;
2175
        case tk_div: process_rrop(0x08); break;
2176
        case tk_divu: process_rrop(0x18); break;
2177
        case tk_dw:  process_dw(); break;
2178
        case tk_end: goto j1;
2179
        case tk_endpublic: break;
2180
        case tk_eor: process_rrop(0x0E); break;
2181
        case tk_eori: process_riop(0x0E); break;
2182
        case tk_extern: process_extern(); break;
2183
 
2184
        case tk_fabs: process_fprop(0x64); break;
2185
        case tk_fadd: process_fprrop(0x28); break;
2186
        case tk_fcmp: process_fprrop(0x2A); break;
2187
        case tk_fdiv: process_fprrop(0x2C); break;
2188
        case tk_mffp: process_fprop(0x65); break;
2189
        case tk_mv2fix: process_fprop(0x66); break;
2190
        case tk_mv2flt: process_fprop(0x1D); break;
2191
        case tk_mtfp: process_fprop(0x1C); break;
2192
/*
2193
        case tk_fcx: process_fpstat(0x74); break;
2194
        case tk_fdx: process_fpstat(0x77); break;
2195
        case tk_fex: process_fpstat(0x76); break;
2196
*/
2197
        case tk_fill: process_fill(); break;
2198
        case tk_fix2flt: process_fprop(0x60); break;
2199
        case tk_flt2fix: process_fprop(0x61); break;
2200
        case tk_fmov: process_fprop(0x62); break;
2201
        case tk_fmul: process_fprrop(0x2B); break;
2202
/*
2203
        case tk_fnabs: process_fprop(0x89); break;
2204
        case tk_frm: process_fpstat(0x78); break;
2205
        case tk_fstat: process_fprdstat(0x86); break;
2206
        case tk_ftx: process_fpstat(0x75); break;
2207
*/
2208
        case tk_fneg: process_fprop(0x63); break;
2209
        case tk_fsub: process_fprrop(0x29); break;
2210
 
2211
        case tk_gran: process_gran(0x14); break;
2212
        case tk_inc: process_inc(0x64); break;
2213
        case tk_int: process_brk(2); break;
2214
 
2215
        case tk_jal: process_jal(0x3C,-1); break;
2216
        case tk_jmp: process_jal(0x3C,0); break;
2217
        case tk_jsr: process_jal(0x3C,31); break;
2218
 
2219
        case tk_lb:  process_load(0x40); break;
2220
        case tk_lbu: process_load(0x41); break;
2221
        case tk_lc:  process_load(0x42); break;
2222
        case tk_lcu: process_load(0x43); break;
2223
        case tk_ldi: process_ldi(0x0A); break;
2224
        case tk_lea: process_load(0x47); break;
2225
        case tk_lfd: process_load(0x51); break;
2226
        case tk_lh:  process_load(0x44); break;
2227
        case tk_lhu: process_load(0x45); break;
2228
        case tk_lsr: process_rrop(0x31); break;
2229
        case tk_lsri: process_shifti(0x39); break;
2230
        case tk_lw:  process_load(0x46); break;
2231
        case tk_lwar:  process_load(0x5C); break;
2232
        case tk_message: process_message(); break;
2233
        case tk_mfspr: process_mfspr(0x1F); break;
2234
        case tk_mod: process_rrop(0x09); break;
2235
        case tk_modu: process_rrop(0x19); break;
2236
        case tk_mov: process_mov(); break;
2237
        case tk_mtspr: process_mtspr(0x1E); break;
2238
        case tk_mul: process_rrop(0x07); break;
2239
        case tk_muli: process_riop(0x07); break;
2240
        case tk_mulu: process_rrop(0x17); break;
2241
        case tk_mului: process_riop(0x17); break;
2242
        case tk_neg: process_neg(0x15); break;
2243
        case tk_nop: emit_insn(0x0000003F); break;
2244
        case tk_not: process_rop(0x0A); break;
2245
        case tk_or:  process_rrop(0x0D); break;
2246
        case tk_ori: process_riop(0x0D); break;
2247
        case tk_org: process_org(); break;
2248
        case tk_pea: process_pea(); break;
2249
        case tk_pop:  process_pushpop(0x57); break;
2250
        case tk_public: process_public(); break;
2251
        case tk_push: process_pushpop(0x67); break;
2252
        case tk_rodata:
2253
            if (first_rodata) {
2254
                while(sections[segment].address & 4095)
2255
                    emitByte(0x00);
2256
                sections[1].address = sections[segment].address;
2257
                first_rodata = 0;
2258
                binstart = sections[1].index;
2259
                ca = sections[1].address;
2260
            }
2261
            segment = rodataseg;
2262
            break;
2263
        case tk_rol: process_rrop(0x32); break;
2264
        case tk_ror: process_rrop(0x33); break;
2265
        case tk_roli: process_shifti(0x3A); break;
2266
        case tk_rori: process_shifti(0x3B); break;
2267
        case tk_rtd: process_pctrl(29); break;
2268
        case tk_rte: process_pctrl(30); break;
2269
        case tk_rti: process_pctrl(31); break;
2270
        case tk_rtl: process_rts(0x27); break;
2271
        case tk_rts: process_rts(0x3B); break;
2272
        case tk_sb:  process_store(0x60); break;
2273
        case tk_sc:  process_store(0x61); break;
2274
        case tk_sei: process_pctrl(1); break;
2275
        case tk_seq:  process_rrop(0x20); break;
2276
        case tk_sfd: process_store(0x71); break;
2277
        case tk_sh:  process_store(0x62); break;
2278
        case tk_shl:  process_rrop(0x30); break;
2279
        case tk_shli: process_shifti(0x38); break;
2280
        case tk_sne:  process_rrop(0x21); break;
2281
        case tk_stp: process_pctrl(2); break;
2282
        case tk_sub:  process_rrop(0x05); break;
2283
        case tk_subi: process_riop(0x05); break;
2284
        case tk_subu:  process_rrop(0x15); break;
2285
        case tk_subui: process_riop(0x15); break;
2286
        case tk_sxb: process_rop(0x10); break;
2287
        case tk_sxc: process_rop(0x11); break;
2288
        case tk_sxh: process_rop(0x12); break;
2289
        case tk_sys: process_brk(0); break;
2290
        case tk_sw:  process_store(0x63); break;
2291
        case tk_swcr:  process_store(0x6E); break;
2292
        case tk_xor: process_rrop(0x0E); break;
2293
        case tk_xori: process_riop(0x0E); break;
2294
        case tk_wai: process_pctrl(3); break;
2295
        case tk_id:  process_label(); break;
2296
        }
2297
        NextToken();
2298
    }
2299
j1:
2300
    ;
2301
}
2302
 

powered by: WebSVN 2.1.0

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