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

Subversion Repositories thor

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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