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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [AS64/] [source/] [friscv.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
static void emitAlignedCode(int cd);
29
static void process_shifti(int oc, int funct3, int funct7);
30
static void ProcessEOL(int opt);
31
 
32
extern int first_rodata;
33
extern int first_data;
34
extern int first_bss;
35
extern int htable[100000];
36
extern int htblcnt[100000];
37
extern int htblmax;
38
extern int pass;
39
 
40
static int64_t ca;
41
 
42
extern int use_gp;
43
 
44
#define OPT64     2
45
#define OPTX32    0
46
#define OPTLUI0   0
47
 
48
// ----------------------------------------------------------------------------
49
// Return the register number or -1 if not a register.
50
// Parses pretty register names like SP or BP in addition to r1,r2,etc.
51
// ----------------------------------------------------------------------------
52
 
53
static int getRegisterX()
54
{
55
    int reg;
56
 
57
    while(isspace(*inptr)) inptr++;
58
    switch(*inptr) {
59
    case 'x': case 'X':
60
         if (isdigit(inptr[1])) {
61
             reg = inptr[1]-'0';
62
             if (isdigit(inptr[2])) {
63
                 reg = 10 * reg + (inptr[2]-'0');
64
                 if (isdigit(inptr[3])) {
65
                     reg = 10 * reg + (inptr[3]-'0');
66
                     if (isIdentChar(inptr[4]))
67
                         return -1;
68
                     inptr += 4;
69
                     NextToken();
70
                     return reg;
71
                 }
72
                 else if (isIdentChar(inptr[3]))
73
                     return -1;
74
                 else {
75
                     inptr += 3;
76
                     NextToken();
77
                     return reg;
78
                 }
79
             }
80
             else if (isIdentChar(inptr[2]))
81
                 return -1;
82
             else {
83
                 inptr += 2;
84
                 NextToken();
85
                 return reg;
86
             }
87
         }
88
         else return -1;
89
    case 'a': case 'A':
90
         if (isdigit(inptr[1])) {
91
             reg = inptr[1]-'0' + 18;
92
             if (isIdentChar(inptr[2]))
93
                 return -1;
94
             else {
95
                 inptr += 2;
96
                 NextToken();
97
                 return reg;
98
             }
99
         }
100
         else return -1;
101
    case 'f': case 'F':
102
        if ((inptr[1]=='P' || inptr[1]=='p') && !isIdentChar(inptr[2])) {
103
            inptr += 2;
104
            NextToken();
105
            return 2;
106
        }
107
        break;
108
    case 'g': case 'G':
109
        if ((inptr[1]=='P' || inptr[1]=='p') && !isIdentChar(inptr[2])) {
110
            inptr += 2;
111
            NextToken();
112
            return 26;
113
        }
114
        break;
115
    case 's': case 'S':
116
        if ((inptr[1]=='P' || inptr[1]=='p') && !isIdentChar(inptr[2])) {
117
            inptr += 2;
118
            NextToken();
119
            return 14;
120
        }
121
        break;
122
    case 't': case 'T':
123
         if (isdigit(inptr[1])) {
124
             reg = inptr[1]-'0' + 26;
125
             if (isIdentChar(inptr[2]))
126
                 return -1;
127
             else {
128
                 inptr += 2;
129
                 NextToken();
130
                 return reg;
131
             }
132
         }
133
        if ((inptr[1]=='P' || inptr[1]=='p') && !isIdentChar(inptr[2])) {
134
            inptr += 2;
135
            NextToken();
136
            return 15;
137
        }
138
        /*
139
        if ((inptr[1]=='R' || inptr[1]=='r') && !isIdentChar(inptr[2])) {
140
            inptr += 2;
141
            NextToken();
142
            return 24;
143
        }
144
        */
145
        break;
146
    case 'p': case 'P':
147
        if ((inptr[1]=='c' || inptr[1]=='C') && !isIdentChar(inptr[2])) {
148
            inptr += 2;
149
            NextToken();
150
            return 29;
151
        }
152
        break;
153
    case 'l': case 'L':
154
        if ((inptr[1]=='R' || inptr[1]=='r') && !isIdentChar(inptr[2])) {
155
            inptr += 2;
156
            NextToken();
157
            return 31;
158
        }
159
        break;
160
    case 'r': case 'R':
161
        if ((inptr[1]=='a' || inptr[1]=='A') && !isIdentChar(inptr[2])) {
162
            inptr += 2;
163
            NextToken();
164
            return 1;
165
        }
166
        break;
167
    case 'v': case 'V':
168
         if (inptr[1]=='0' || inptr[1]=='1') {
169
             reg = inptr[1]-'0' + 16;
170
             if (isIdentChar(inptr[2]))
171
                 return -1;
172
             else {
173
                 inptr += 2;
174
                 NextToken();
175
                 return reg;
176
             }
177
         }
178
    default:
179
        return -1;
180
    }
181
    return -1;
182
}
183
 
184
 
185
// ---------------------------------------------------------------------------
186
// ---------------------------------------------------------------------------
187
 
188
static void emit_insn(int oc, int can_compress)
189
{
190
    int ndx;
191
 
192
    if (pass==3 && can_compress && 0) {
193
       for (ndx = 0; ndx < htblmax; ndx++) {
194
         if (oc == hTable[ndx].opcode) {
195
           printf("found opcode\n");
196
           hTable[ndx].count++;
197
           return;
198
         }
199
       }
200
       if (htblmax < 100000) {
201
           printf("inserting opcode %08X\n", oc);
202
          hTable[htblmax].opcode = oc;
203
          hTable[htblmax].count = 1;
204
          htblmax++;
205
          return;
206
       }
207
       printf("Too many instructions.\r\n");
208
       return;
209
    }
210
    if (pass > 3) {
211
     if (can_compress) {
212
       for (ndx = 0; ndx < htblmax; ndx++) {
213
         if (oc == hTable[ndx].opcode) {
214
           printf("found opcode\n");
215
           emitAlignedCode(((ndx & 8) << 4)|0x50|(ndx & 0x7));
216
           emitCode(ndx >> 4);
217
           return;
218
         }
219
       }
220
     }
221
     emitAlignedCode(oc & 255);
222
     emitCode((oc >> 8) & 255);
223
     emitCode((oc >> 16) & 255);
224
     emitCode((oc >> 24) & 255);
225
    }
226
    /*
227
    if (processOpt==2) {
228
       for (ndx = 0; ndx < htblmax; ndx++) {
229
         if (oc == hTable[ndx].opcode) {
230
           printf("found opcode\n");
231
           emitAlignedCode(((ndx & 8) << 4)|0x50|(ndx & 0x7));
232
           emitCode(ndx >> 4);
233
           return;
234
         }
235
       }
236
     emitAlignedCode(oc & 255);
237
     emitCode((oc >> 8) & 255);
238
     emitCode((oc >> 16) & 255);
239
     emitCode((oc >> 24) & 255);
240
    }
241
    else {
242
     emitAlignedCode(oc & 255);
243
     emitCode((oc >> 8) & 255);
244
     emitCode((oc >> 16) & 255);
245
     emitCode((oc >> 24) & 255);
246
    }
247
    */
248
        num_bytes += 4;
249
        if ((oc & 0x7F) != 0x3F)
250
        num_insns += 1;
251
}
252
 
253
// ---------------------------------------------------------------------------
254
// ---------------------------------------------------------------------------
255
 
256
static void emit_insn2(int64_t oc)
257
{
258
     emitCode(oc & 255);
259
     emitCode((oc >> 8) & 255);
260
     emitCode((oc >> 16) & 255);
261
     emitCode((oc >> 24) & 255);
262
}
263
 
264
 
265
// ---------------------------------------------------------------------------
266
// Emit code aligned to a code address.
267
// ---------------------------------------------------------------------------
268
 
269
static void emitAlignedCode(int cd)
270
{
271
     int64_t ad;
272
 
273
     ad = code_address & 15;
274
//     while (ad != 0 && ad != 4 && ad != 8 && ad != 12) {
275
       while (ad & 1) {
276
         emitByte(0x00);
277
         ad = code_address & 15;
278
     }
279
     emitByte(cd);
280
}
281
 
282
 
283
// ---------------------------------------------------------------------------
284
// Emit constant extension for memory operands.
285
// ---------------------------------------------------------------------------
286
 
287
static void emitImm0(int64_t v, int force)
288
{
289
     if (v != 0 || force) {
290
          emitAlignedCode(0xfd);
291
          emitCode(v & 255);
292
          emitCode((v >> 8) & 255);
293
          emitCode((v >> 16) & 255);
294
          emitCode((v >> 24) & 255);
295
     }
296
     if (((v < 0) && ((v >> 32) != -1L)) || ((v > 0) && ((v >> 32) != 0L)) || (force && data_bits > 32)) {
297
          emitAlignedCode(0xfe);
298
          emitCode((v >> 32) & 255);
299
          emitCode((v >> 40) & 255);
300
          emitCode((v >> 48) & 255);
301
          emitCode((v >> 56) & 255);
302
     }
303
}
304
 
305
// ---------------------------------------------------------------------------
306
// Emit constant extension for memory operands.
307
// ---------------------------------------------------------------------------
308
 
309
static void emitImm2(int64_t v, int force)
310
{
311
     if (v < 0L || v > 3L || force) {
312
          emitAlignedCode(0xfd);
313
          emitCode((v >> 2) & 255);
314
          emitCode((v >> 10) & 255);
315
          emitCode((v >> 18) & 255);
316
          emitCode((v >> 26) & 255);
317
     }
318
     if (((v < 0) && ((v >> 34) != -1L)) || ((v > 0) && ((v >> 34) != 0L)) || (force && data_bits > 34)) {
319
          emitAlignedCode(0xfe);
320
          emitCode((v >> 34) & 255);
321
          emitCode((v >> 42) & 255);
322
          emitCode((v >> 50) & 255);
323
          emitCode((v >> 58) & 255);
324
     }
325
}
326
 
327
// ---------------------------------------------------------------------------
328
// Emit constant extension for memory operands.
329
// ---------------------------------------------------------------------------
330
 
331
static void emitImm12(int64_t v, int force)
332
{
333
     if (v < -2048L || v > 2047L || force) {
334
          emitAlignedCode(0xfd);
335
          emitCode((v >> 12) & 255);
336
          emitCode((v >> 20) & 255);
337
          emitCode((v >> 28) & 255);
338
          emitCode((v >> 36) & 255);
339
     }
340
     if (((v < 0) && ((v >> 44) != -1L)) || ((v > 0) && ((v >> 44) != 0L)) || (force && data_bits > 44)) {
341
          emitAlignedCode(0xfe);
342
          emitCode((v >> 44) & 255);
343
          emitCode((v >> 52) & 255);
344
          emitCode((v >> 60) & 255);
345
          emitCode(0x00);
346
     }
347
}
348
 
349
// ---------------------------------------------------------------------------
350
// Emit constant extension for 16-bit operands.
351
// ---------------------------------------------------------------------------
352
 
353
static void emitImm16(int64_t v, int force)
354
{
355
     if (v < -32768L || v > 32767L || force) {
356
          emitAlignedCode(0xfd);
357
          emitCode((v >> 16) & 255);
358
          emitCode((v >> 24) & 255);
359
          emitCode((v >> 32) & 255);
360
          emitCode((v >> 40) & 255);
361
     }
362
     if (((v < 0) && ((v >> 48) != -1L)) || ((v > 0) && ((v >> 48) != 0L)) || (force && (code_bits > 48 || data_bits > 48))) {
363
          emitAlignedCode(0xfe);
364
          emitCode((v >> 48) & 255);
365
          emitCode((v >> 56) & 255);
366
          emitCode(0x00);
367
          emitCode(0x00);
368
     }
369
}
370
 
371
// ---------------------------------------------------------------------------
372
// Emit constant extension for 24-bit operands.
373
// ---------------------------------------------------------------------------
374
 
375
static void emitImm20(int64_t v, int force)
376
{
377
     if (v < -524288L || v > 524287L || force) {
378
          emitAlignedCode(0xfd);
379
          emitCode((v >> 20) & 255);
380
          emitCode((v >> 28) & 255);
381
          emitCode((v >> 36) & 255);
382
          emitCode((v >> 44) & 255);
383
     }
384
     if (((v < 0) && ((v >> 52) != -1L)) || ((v > 0) && ((v >> 52) != 0L)) || (force && (code_bits > 52 || data_bits > 52))) {
385
          emitAlignedCode(0xfe);
386
          emitCode((v >> 52) & 255);
387
          emitCode((v >> 60) & 255);
388
          emitCode(0x00);
389
          emitCode(0x00);
390
     }
391
}
392
 
393
// ---------------------------------------------------------------------------
394
// Emit constant extension for 24-bit operands.
395
// ---------------------------------------------------------------------------
396
 
397
static void emitImm24(int64_t v, int force)
398
{
399
     if (v < -8388608L || v > 8388607L || force) {
400
          emitAlignedCode(0xfd);
401
          emitCode((v >> 24) & 255);
402
          emitCode((v >> 32) & 255);
403
          emitCode((v >> 40) & 255);
404
          emitCode((v >> 48) & 255);
405
     }
406
     if (((v < 0) && ((v >> 56) != -1L)) || ((v > 0) && ((v >> 56) != 0L)) || (force && (code_bits > 56 || data_bits > 56))) {
407
          emitAlignedCode(0xfe);
408
          emitCode((v >> 56) & 255);
409
          emitCode(0x00);
410
          emitCode(0x00);
411
          emitCode(0x00);
412
     }
413
}
414
 
415
// ---------------------------------------------------------------------------
416
// Emit constant extension for 32-bit operands.
417
// ---------------------------------------------------------------------------
418
 
419
static void emitImm32(int64_t v, int force)
420
{
421
     if (v < -2147483648LL || v > 2147483647LL || force) {
422
          emitAlignedCode(0xfd);
423
          emitCode((v >> 32) & 255);
424
          emitCode((v >> 40) & 255);
425
          emitCode((v >> 48) & 255);
426
          emitCode((v >> 56) & 255);
427
     }
428
}
429
 
430
// ---------------------------------------------------------------------------
431
// addi r1,r2,#1234
432
// ---------------------------------------------------------------------------
433
 
434
static void process_addi(int funct3)
435
{
436
    int Ra;
437
    int Rt;
438
    char *p;
439
    int64_t val;
440
 
441
    p = inptr;
442
    Rt = getRegisterX();
443
    need(',');
444
    Ra = getRegisterX();
445
    need(',');
446
    NextToken();
447
    val = expr();
448
    if ((val < -2048 || val > 2047) && OPTLUI0) {
449
        emit_insn((val & 0xFFFFF000) | (0 << 7)|0x37,1);    // LUI
450
    }
451
    if ((val < -2048 || val > 2047)) {
452
      if (OPTX32) {
453
        emit_insn((0x800 << 20)|(Ra << 15)|(funct3<<12)|(Rt << 7)|0x13,1);
454
        emit_insn(val,0);
455
      }
456
      else if (OPT64) {
457
        emit_insn(((val & 0xFFF) << 20)|(Ra << 15)|(funct3<<12)|(Rt << 7)|0x3F,!expand_flag);
458
        emit_insn((val&0xFFFFF000)|0x13,0);
459
      }
460
    }
461
    else
462
      emit_insn(((val & 0xFFF) << 20)|(Ra << 15)|(funct3<<12)|(Rt << 7)|0x13,!expand_flag);
463
}
464
 
465
// ---------------------------------------------------------------------------
466
// ---------------------------------------------------------------------------
467
 
468
static void process_add()
469
{
470
    int Ra,Rb,Rt;
471
    char *p;
472
 
473
    p = inptr;
474
    Rt = getRegisterX();
475
    need(',');
476
    Ra = getRegisterX();
477
    need(',');
478
    NextToken();
479
    if (token=='#') {
480
        inptr = p;
481
        process_addi(0);
482
        return;
483
    }
484
    prevToken();
485
    Rb = getRegisterX();
486
    prevToken();
487
    emit_insn((Rb << 20)|(Ra<<15)|(0<<12)|(Rt<<7)|0x33,1);
488
}
489
 
490
// ---------------------------------------------------------------------------
491
// ---------------------------------------------------------------------------
492
 
493
static void process_riop(int oc, int funct3)
494
{
495
    int Ra,Rb,Rt;
496
    char *p;
497
    int tk = token;
498
    int val;
499
 
500
    p = inptr;
501
    Rt = getRegisterX();
502
    need(',');
503
    Ra = getRegisterX();
504
    need(',');
505
    NextToken();
506
    val = expr();
507
    if ((val < -2048 || val > 2047) && OPTLUI0) {
508
        emit_insn((val & 0xFFFFF000) | (0 << 7)|0x37,1);    // LUI
509
    }
510
    if ((val < -2048 || val > 2047)) {
511
       if (OPTX32) {
512
          emit_insn((0x800 << 20)|(Ra << 15)|(funct3<<12)|(Rt << 7)|oc,1);
513
          emit_insn(val,0);
514
       }
515
       else if (OPT64) {
516
        emit_insn(((val & 0xFFF) << 20)|(Ra << 15)|(funct3<<12)|(Rt << 7)|0x3F,!expand_flag);
517
        emit_insn((val&0xFFFFF000)|oc,0);
518
       }
519
    }
520
    else
521
      emit_insn(((val & 0xFFF) << 20)|(Ra << 15)|(funct3<<12)|(Rt << 7)|0x13,!expand_flag);
522
//    emit_insn((val << 20)|(Ra<<15)|(funct3<<12)|(Rt<<7)|oc);
523
}
524
 
525
// ---------------------------------------------------------------------------
526
// ---------------------------------------------------------------------------
527
 
528
static void process_rrop(int oc, int funct3, int funct7)
529
{
530
    int Ra,Rb,Rt;
531
    char *p;
532
    int tk = token;
533
 
534
    p = inptr;
535
    Rt = getRegisterX();
536
    need(',');
537
    Ra = getRegisterX();
538
    need(',');
539
    NextToken();
540
    if (token=='#') {
541
      inptr = p;
542
      switch(token) {
543
      case tk_add: process_riop(0x13,0x00); break;
544
      case tk_and: process_riop(0x13,0x07); break;
545
      default:
546
         printf("rrop: syntax error\n");
547
      }
548
//      process_addi(0);
549
        return;
550
    }
551
    prevToken();
552
    Rb = getRegisterX();
553
    prevToken();
554
    emit_insn((funct7 << 25)|(Rb << 20)|(Ra<<15)|(funct3<<12)|(Rt<<7)|oc,1);
555
}
556
 
557
// ---------------------------------------------------------------------------
558
// ---------------------------------------------------------------------------
559
 
560
static void process_mul()
561
{
562
    int Ra,Rb,Rt;
563
    char *p;
564
 
565
    p = inptr;
566
    Rt = getRegisterX();
567
    need(',');
568
    Ra = getRegisterX();
569
    need(',');
570
    Rb = getRegisterX();
571
    prevToken();
572
    emit_insn((1 << 25)|(Rb << 20)|(Ra<<15)|(0<<12)|(Rt<<7)|0x33,1);
573
}
574
 
575
// ---------------------------------------------------------------------------
576
// ---------------------------------------------------------------------------
577
 
578
static void process_sub()
579
{
580
    int Ra,Rb,Rt;
581
    char *p;
582
 
583
    p = inptr;
584
    Rt = getRegisterX();
585
    need(',');
586
    Ra = getRegisterX();
587
    need(',');
588
    NextToken();
589
    if (token=='#') {
590
        inptr = p;
591
        return;
592
    }
593
    prevToken();
594
    Rb = getRegisterX();
595
    prevToken();
596
    emit_insn(0x40000000|(Rb << 20)|(Ra<<15)|(0<<12)|(Rt<<7)|0x33,1);
597
}
598
 
599
// ---------------------------------------------------------------------------
600
// jmp main
601
// jsr [r19]
602
// jmp (tbl,r2)
603
// jsr [gp+r20]
604
// ---------------------------------------------------------------------------
605
 
606
static void process_jal()
607
{
608
    int64_t addr;
609
    int Ra, Rb;
610
    int Rt;
611
 
612
    Rt = 0;
613
    NextToken();
614
    if (token=='(' || token=='[') {
615
j1:
616
       Ra = getRegisterX();
617
       if (Ra==-1) {
618
           printf("Expecting a register\r\n");
619
           return;
620
       }
621
       // Simple jmp [Rn]
622
       else {
623
            if (token != ')' && token!=']')
624
                printf("Missing close bracket\r\n");
625
            emit_insn((Ra << 15)|(Rt<<7)|0x67,1);
626
            return;
627
       }
628
    }
629
    prevToken();
630
    Rt = getRegisterX();
631
    printf("Rt=%d ", Rt);
632
    if (Rt >= 0) {
633
        need(',');
634
        NextToken();
635
        // jal Rt,[Ra]
636
        if (token=='(' || token=='[')
637
           goto j1;
638
    }
639
    else
640
        Rt = 0;
641
    addr = expr() - code_address;
642
    printf("Addr=%ld ", addr);
643
    prevToken();
644
    // d(Rn)? 
645
    if (token=='(' || token=='[') {
646
        printf("a ");
647
        NextToken();
648
        Ra = getRegisterX();
649
        if (Ra==-1) {
650
            printf("Illegal jump address mode.\r\n");
651
            Ra = 0;
652
        }
653
j2:
654
        if (addr < -2048 || addr > 2047)
655
            emit_insn((addr & 0xFFFFF000)|0x37,1);
656
        emit_insn(((addr & 0xFFF) << 20)|(Ra<<15)|(Rt << 7)|0x67,1);
657
        return;
658
    }
659
    printf("b ");
660
    if (addr > 524287 || addr < -524288) {
661
        Ra = 0;
662
        goto j2;
663
    }
664
    printf("emit_insn \r\n");
665
    emit_insn(
666
        (((addr & 0x100000)>>20)<< 31) |
667
        (((addr & 0x7FE)>>1) << 21) |
668
        (((addr & 0x800)>>11) << 20) |
669
        (((addr & 0xFF000)>>12) << 12) |
670
        (Rt << 7) |
671
        0x6F, 0
672
    );
673
}
674
 
675
// ---------------------------------------------------------------------------
676
// subui r1,r2,#1234
677
// ---------------------------------------------------------------------------
678
/*
679
static void process_riop(int oc)
680
{
681
    int Ra;
682
    int Rt;
683
    char *p;
684
    int64_t val;
685
 
686
    p = inptr;
687
    Rt = getRegisterX();
688
    need(',');
689
    Ra = getRegisterX();
690
    need(',');
691
    NextToken();
692
    val = expr();
693
 
694
   if (lastsym != (SYM *)NULL)
695
       emitImm16(val,!lastsym->defined);
696
   else
697
       emitImm16(val,0);
698
 
699
    emitImm16(val,lastsym!=(SYM*)NULL);
700
    emitAlignedCode(oc);
701
    if (bGen)
702
    if (lastsym && !use_gp) {
703
        if( lastsym->segment < 5)
704
        sections[segment+7].AddRel(sections[segment].index,((lastsym->ord+1) << 32) | 3 | (lastsym->isExtern ? 128 : 0) |
705
        (lastsym->segment==codeseg ? code_bits << 8 : data_bits << 8));
706
    }
707
    emitCode(Ra);
708
    emitCode(Rt);
709
    emitCode(val & 255);
710
    emitCode((val >> 8) & 255);
711
}
712
*/
713
// ---------------------------------------------------------------------------
714
// fabs.d fp1,fp2[,rm]
715
// ---------------------------------------------------------------------------
716
 
717
static void process_fprop(int oc)
718
{
719
    int Ra;
720
    int Rt;
721
    char *p;
722
    int  sz;
723
    int fmt;
724
    int rm;
725
 
726
    rm = 0;
727
    sz = 'd';
728
    if (*inptr=='.') {
729
        inptr++;
730
        if (strchr("sdtqSDTQ",*inptr)) {
731
            sz = tolower(*inptr);
732
            inptr++;
733
        }
734
        else
735
            printf("Illegal float size.\r\n");
736
    }
737
    p = inptr;
738
    if (oc==0xF6)        // fcmp
739
        Rt = getRegisterX();
740
    else
741
        Rt = getFPRegister();
742
    need(',');
743
    Ra = getFPRegister();
744
    if (token==',')
745
       rm = getFPRoundMode();
746
    prevToken();
747
    emitAlignedCode(0x01);
748
    emitCode(Ra);
749
    emitCode(Rt);
750
    switch(sz) {
751
    case 's': fmt = 0; break;
752
    case 'd': fmt = 1; break;
753
    case 't': fmt = 2; break;
754
    case 'q': fmt = 3; break;
755
    }
756
    emitCode((fmt << 3)|rm);
757
    emitCode(oc);
758
}
759
 
760
// ---------------------------------------------------------------------------
761
// fadd.d fp1,fp2,fp12[,rm]
762
// fcmp.d r1,fp3,fp10[,rm]
763
// ---------------------------------------------------------------------------
764
 
765
static void process_fprrop(int oc)
766
{
767
    int Ra;
768
    int Rb;
769
    int Rt;
770
    char *p;
771
    int  sz;
772
    int fmt;
773
    int rm;
774
 
775
    rm = 0;
776
    sz = 'd';
777
    if (*inptr=='.') {
778
        inptr++;
779
        if (strchr("sdtqSDTQ",*inptr)) {
780
            sz = tolower(*inptr);
781
            inptr++;
782
        }
783
        else
784
            printf("Illegal float size.\r\n");
785
    }
786
    p = inptr;
787
    if (oc==0xF6)        // fcmp
788
        Rt = getRegisterX();
789
    else
790
        Rt = getFPRegister();
791
    need(',');
792
    Ra = getFPRegister();
793
    need(',');
794
    Rb = getFPRegister();
795
    if (token==',')
796
       rm = getFPRoundMode();
797
    prevToken();
798
    emitAlignedCode(oc);
799
    emitCode(Ra);
800
    emitCode(Rb);
801
    emitCode(Rt);
802
    switch(sz) {
803
    case 's': fmt = 0; break;
804
    case 'd': fmt = 1; break;
805
    case 't': fmt = 2; break;
806
    case 'q': fmt = 3; break;
807
    }
808
    emitCode((fmt << 3)|rm);
809
}
810
 
811
// ---------------------------------------------------------------------------
812
// fcx r0,#2
813
// fdx r1,#0
814
// ---------------------------------------------------------------------------
815
 
816
static void process_fpstat(int oc)
817
{
818
    int Ra;
819
    int64_t bits;
820
    char *p;
821
 
822
    p = inptr;
823
    bits = 0;
824
    Ra = getRegisterX();
825
    if (token==',') {
826
       NextToken();
827
       bits = expr();
828
    }
829
    prevToken();
830
    emitAlignedCode(0x01);
831
    emitCode(Ra);
832
    emitCode(bits & 0xff);
833
    emitCode(0x00);
834
    emitCode(oc);
835
}
836
 
837
// ---------------------------------------------------------------------------
838
// not r3,r3
839
// ---------------------------------------------------------------------------
840
 
841
static void process_rop(int oc)
842
{
843
    int Ra;
844
    int Rt;
845
 
846
    Rt = getRegisterX();
847
    need(',');
848
    Ra = getRegisterX();
849
    prevToken();
850
    emitAlignedCode(1);
851
    emitCode(Ra);
852
    emitCode(Rt);
853
    emitCode(0x00);
854
    emitCode(oc);
855
}
856
 
857
// ---------------------------------------------------------------------------
858
// brnz r1,label
859
// ---------------------------------------------------------------------------
860
 
861
static void process_bcc(int funct3)
862
{
863
    int Ra, Rb;
864
    int64_t val;
865
    int64_t disp;
866
 
867
    Ra = getRegisterX();
868
    need(',');
869
    Rb = getRegisterX();
870
    need(',');
871
    NextToken();
872
    val = expr();
873
    disp = val - code_address;
874
    printf("exmit branch\r\n");
875
    emit_insn(
876
        (((disp & 0x1000) >> 12) << 31) |
877
        (((disp & 0x7E0) >> 5) << 25) |
878
        (((disp & 0x1E) >> 1) << 8) |
879
        (((disp & 0x800) >> 11) << 7) |
880
        (Rb << 20) |
881
        (Ra << 15) |
882
        (funct3 << 12) |
883
        0x63,0
884
    );
885
}
886
 
887
// ---------------------------------------------------------------------------
888
// bra label
889
// ---------------------------------------------------------------------------
890
 
891
static void process_bra(int oc)
892
{
893
    int64_t val;
894
    int64_t disp;
895
    int64_t ad;
896
 
897
    NextToken();
898
    val = expr();
899
    ad = code_address + 5;
900
    if ((ad & 15)==15)
901
       ad++;
902
    disp = ((val & 0xFFFFFFFFFFFFF000L) - (ad & 0xFFFFFFFFFFFFF000L)) >> 12;
903
    emitAlignedCode(oc);
904
    emitCode(0x00);
905
    emitCode(val & 255);
906
    emitCode(((disp & 15) << 4)|((val >> 8) & 15));
907
    if (oc==0x56)   // BSR
908
        emitCode((disp >> 4) & 255);
909
    else
910
        emitCode((disp >> 4) & 31);
911
}
912
 
913
// ---------------------------------------------------------------------------
914
// expr
915
// expr[Reg]
916
// expr[Reg+Reg*sc]
917
// [Reg]
918
// [Reg+Reg*sc]
919
// ---------------------------------------------------------------------------
920
 
921
static void mem_operand(int64_t *disp, int *regA)
922
{
923
     int64_t val;
924
 
925
     // chech params
926
     if (disp == (int64_t *)NULL)
927
         return;
928
     if (regA == (int *)NULL)
929
         return;
930
 
931
     *disp = 0;
932
     *regA = -1;
933
     if (token!='[') {;
934
          val = expr();
935
          *disp = val;
936
     }
937
     if (token=='[') {
938
         *regA = getRegisterX();
939
         if (*regA == -1) {
940
             printf("expecting a register\r\n");
941
         }
942
         need(']');
943
     }
944
}
945
 
946
// ---------------------------------------------------------------------------
947
// sw disp[r1],r2
948
// sw [r1+r2],r3
949
// ----------------------------------------------------------------------------
950
 
951
static void process_store(int oc, int func3)
952
{
953
    int Ra;
954
    int Rs;
955
    int64_t disp;
956
 
957
    Rs = getRegisterX();
958
    if (Rs < 0) {
959
        printf("Expecting a source register.\r\n");
960
        ScanToEOL();
961
        return;
962
    }
963
    expect(',');
964
    mem_operand(&disp, &Ra);
965
    if (Ra < 0) Ra = 0;
966
    if ((disp < -2048 || disp > 2047) && OPTLUI0) {
967
        emit_insn((disp & 0xFFFFF000)|(0 << 7)|0x37,1); // LUI
968
    }
969
    if ((disp < -2048 || disp > 2047)) {
970
       if (OPTX32) {
971
        emit_insn((((0x800)>>5) << 25)|(Rs << 20)|(Ra << 15)|(func3<<12)|((disp & 0x1f) << 7)|oc,1);
972
        emit_insn(disp,0);
973
       }
974
       else if (OPT64) {
975
        emit_insn((((disp & 0xFFF)>>5) << 25)|(Rs << 20)|(Ra << 15)|(func3<<12)|((disp & 0x1f) << 7)|0x3F,!expand_flag);
976
        emit_insn((disp&0xFFFFF000)|oc,0);
977
       }
978
    }
979
    else
980
        emit_insn((((disp & 0xFFF)>>5) << 25)|(Rs << 20)|(Ra << 15)|(func3<<12)|((disp & 0x1f) << 7)|oc,!expand_flag);
981
    ScanToEOL();
982
}
983
 
984
// ----------------------------------------------------------------------------
985
// ----------------------------------------------------------------------------
986
 
987
static void process_ldi()
988
{
989
    int Rt;
990
    int64_t val;
991
 
992
    Rt = getRegisterX();
993
    expect(',');
994
    val = expr();
995
    if ((val < -2048 || val > 2047) && OPTLUI0)
996
       emit_insn((val & 0xFFFFF000) | 0x37,1);
997
    if ((val < -2048 || val > 2047)) {
998
       if (OPTX32) {
999
        emit_insn(((0x800) << 20)| (6 << 12) | (Rt << 7) | 0x13,1);  // ORI
1000
        emit_insn(val,0);
1001
      }
1002
      else if (OPT64) {
1003
        emit_insn(((val & 0xFFF) << 20)| (6 << 12) | (Rt << 7) | 0x3F,!expand_flag);  // ORI
1004
        emit_insn((val&0xFFFFF000)|0x13,0);
1005
      }
1006
    }
1007
    else
1008
        emit_insn(((val & 0xFFF) << 20)| (6 << 12) | (Rt << 7) | 0x13,!expand_flag);  // ORI
1009
}
1010
 
1011
// ----------------------------------------------------------------------------
1012
// lw r1,disp[r2]
1013
// lw r1,[r2+r3]
1014
// ----------------------------------------------------------------------------
1015
 
1016
static void process_load(int oc, int func3)
1017
{
1018
    int Ra;
1019
    int Rt;
1020
    char *p;
1021
    int64_t disp;
1022
    int fixup = 5;
1023
 
1024
    p = inptr;
1025
    Rt = getRegisterX();
1026
    if (Rt < 0) {
1027
        printf("Expecting a target register.\r\n");
1028
//        printf("Line:%.60s\r\n",p);
1029
        ScanToEOL();
1030
        inptr-=2;
1031
        return;
1032
    }
1033
    expect(',');
1034
    mem_operand(&disp, &Ra);
1035
    if (Ra < 0) Ra = 0;
1036
    if ((disp < -2048 || disp > 2047)&&OPTLUI0) {
1037
        emit_insn((disp & 0xFFFFF000)|(0 << 7)|0x37,1); // LUI
1038
    }
1039
    if ((disp < -2048 || disp > 2047)) {
1040
       if (OPTX32) {
1041
        emit_insn((0x800 << 20)|(Ra << 15)|(func3<<12)|(Rt<<7)|oc,1);
1042
        emit_insn(disp,0);
1043
       }
1044
       else if (OPT64) {
1045
        emit_insn(((disp&0x800) << 20)|(Ra << 15)|(func3<<12)|(Rt<<7)|0x3F,!expand_flag);
1046
        emit_insn((disp&0xFFFFF000)|oc,0);
1047
       }
1048
    }
1049
    else
1050
        emit_insn(((disp & 0xFFF) << 20)|(Ra << 15)|(func3<<12)|(Rt<<7)|oc,!expand_flag);
1051
    ScanToEOL();
1052
}
1053
 
1054
// ----------------------------------------------------------------------------
1055
// mov r1,r2
1056
// ----------------------------------------------------------------------------
1057
 
1058
static void process_mov(int oc)
1059
{
1060
     int Ra;
1061
     int Rt;
1062
 
1063
     Rt = getRegisterX();
1064
     need(',');
1065
     Ra = getRegisterX();
1066
     emitAlignedCode(0x01);
1067
     emitCode(Ra);
1068
     emitCode(Rt);
1069
     emitCode(0x00);
1070
     emitCode(oc);
1071
     prevToken();
1072
}
1073
 
1074
// ----------------------------------------------------------------------------
1075
// rts
1076
// rts #24
1077
// ----------------------------------------------------------------------------
1078
 
1079
static void process_rts(int oc)
1080
{
1081
     int64_t val;
1082
 
1083
     val = 0;
1084
     NextToken();
1085
     if (token=='#') {
1086
        val = expr();
1087
     }
1088
     emitAlignedCode(oc);
1089
     emitCode(0x00);
1090
     emitCode(val & 255);
1091
     emitCode((val >> 8) & 255);
1092
     emitCode(0x00);
1093
}
1094
 
1095
// ----------------------------------------------------------------------------
1096
// srli r1,r2,#5
1097
// ----------------------------------------------------------------------------
1098
 
1099
static void process_shifti(int oc, int funct3, int funct7)
1100
{
1101
     int Ra;
1102
     int Rt;
1103
     int64_t val;
1104
 
1105
     Rt = getRegisterX();
1106
     need(',');
1107
     Ra = getRegisterX();
1108
     need(',');
1109
     NextToken();
1110
     val = expr();
1111
     emit_insn((funct7 << 25) | ((val & 0x1F) << 20) | (Ra << 15)| (funct3 << 12) | (Rt << 7) | oc,1);  // ORI
1112
}
1113
 
1114
// ----------------------------------------------------------------------------
1115
// gran r1
1116
// ----------------------------------------------------------------------------
1117
 
1118
static void process_gran(int oc)
1119
{
1120
    int Rt;
1121
 
1122
    Rt = getRegisterX();
1123
    emitAlignedCode(0x01);
1124
    emitCode(0x00);
1125
    emitCode(Rt);
1126
    emitCode(0x00);
1127
    emitCode(oc);
1128
    prevToken();
1129
}
1130
 
1131
// ----------------------------------------------------------------------------
1132
// ----------------------------------------------------------------------------
1133
 
1134
static void process_mtspr(int oc)
1135
{
1136
    int spr;
1137
    int Ra;
1138
 
1139
    spr = getSprRegister();
1140
    need(',');
1141
    Ra = getRegisterX();
1142
    emitAlignedCode(0x01);
1143
    emitCode(Ra);
1144
    emitCode(spr);
1145
    emitCode(0x00);
1146
    emitCode(oc);
1147
    if (Ra >= 0)
1148
    prevToken();
1149
}
1150
 
1151
// ----------------------------------------------------------------------------
1152
// ----------------------------------------------------------------------------
1153
 
1154
static void process_mtfp(int oc)
1155
{
1156
    int fpr;
1157
    int Ra;
1158
 
1159
    fpr = getFPRegister();
1160
    need(',');
1161
    Ra = getRegisterX();
1162
    emitAlignedCode(0x01);
1163
    emitCode(Ra);
1164
    emitCode(fpr);
1165
    emitCode(0x00);
1166
    emitCode(oc);
1167
    if (Ra >= 0)
1168
    prevToken();
1169
}
1170
 
1171
// ----------------------------------------------------------------------------
1172
// ----------------------------------------------------------------------------
1173
 
1174
static void process_mfspr(int oc)
1175
{
1176
    int spr;
1177
    int Rt;
1178
 
1179
    Rt = getRegisterX();
1180
    need(',');
1181
    spr = getSprRegister();
1182
    emitAlignedCode(0x01);
1183
    emitCode(spr);
1184
    emitCode(Rt);
1185
    emitCode(0x00);
1186
    emitCode(oc);
1187
    if (spr >= 0)
1188
    prevToken();
1189
}
1190
 
1191
// ----------------------------------------------------------------------------
1192
// ----------------------------------------------------------------------------
1193
 
1194
static void process_mffp(int oc)
1195
{
1196
    int fpr;
1197
    int Rt;
1198
 
1199
    Rt = getRegisterX();
1200
    need(',');
1201
    fpr = getFPRegister();
1202
    emitAlignedCode(0x01);
1203
    emitCode(fpr);
1204
    emitCode(Rt);
1205
    emitCode(0x00);
1206
    emitCode(oc);
1207
    if (fpr >= 0)
1208
    prevToken();
1209
}
1210
 
1211
// ----------------------------------------------------------------------------
1212
// ----------------------------------------------------------------------------
1213
 
1214
static void process_fprdstat(int oc)
1215
{
1216
    int Rt;
1217
 
1218
    Rt = getRegisterX();
1219
    emitAlignedCode(0x01);
1220
    emitCode(0x00);
1221
    emitCode(Rt);
1222
    emitCode(0x00);
1223
    emitCode(oc);
1224
}
1225
 
1226
static void process_csrrw(int opcode3)
1227
{
1228
  int Rd;
1229
  int Rs = 0;
1230
  int64_t val;
1231
  int64_t val2 = 0;
1232
  int flag = 0;
1233
 
1234
  Rd = getRegisterX();
1235
  need(',');
1236
  NextToken();
1237
  val = expr();
1238
  prevToken();
1239
  need(',');
1240
  NextToken();
1241
  if (token=='#') {
1242
    val2 = expr();
1243
        flag = 4;
1244
  }
1245
  else {
1246
    Rs = getRegisterX();
1247
        prevToken();
1248
  }
1249
  emit_insn((val << 20) | ((Rs|val2) << 15) | ((opcode3|flag) << 12) | (Rd << 7) | 0x73,!expand_flag);
1250
}
1251
 
1252
// ----------------------------------------------------------------------------
1253
// ----------------------------------------------------------------------------
1254
 
1255
static void ProcessEOL(int opt)
1256
{
1257
    int nn,mm;
1258
    int first;
1259
    int cc;
1260
 
1261
     //printf("Line: %d\r", lineno);
1262
     expand_flag = 0;
1263
     compress_flag = 0;
1264
     segprefix = -1;
1265
     if (bGen && (segment==codeseg || segment==dataseg || segment==rodataseg)) {
1266
    nn = binstart;
1267
    cc = 8;
1268
    if (segment==codeseg) {
1269
       cc = 4;
1270
/*
1271
        if (sections[segment].bytes[binstart]==0x61) {
1272
            fprintf(ofp, "%06LLX ", ca);
1273
            for (nn = binstart; nn < binstart + 5 && nn < sections[segment].index; nn++) {
1274
                fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
1275
            }
1276
            fprintf(ofp, "   ; imm\n");
1277
             if (((ca+5) & 15)==15) {
1278
                 ca+=6;
1279
                 binstart+=6;
1280
                 nn++;
1281
             }
1282
             else {
1283
                  ca += 5;
1284
                  binstart += 5;
1285
             }
1286
        }
1287
*/
1288
/*
1289
        if (sections[segment].bytes[binstart]==0xfd) {
1290
            fprintf(ofp, "%06LLX ", ca);
1291
            for (nn = binstart; nn < binstart + 5 && nn < sections[segment].index; nn++) {
1292
                fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
1293
            }
1294
            fprintf(ofp, "   ; imm\n");
1295
             if (((ca+5) & 15)==15) {
1296
                 ca+=6;
1297
                 binstart+=6;
1298
                 nn++;
1299
             }
1300
             else {
1301
                  ca += 5;
1302
                  binstart += 5;
1303
             }
1304
        }
1305
         if (sections[segment].bytes[binstart]==0xfe) {
1306
            fprintf(ofp, "%06LLX ", ca);
1307
            for (nn = binstart; nn < binstart + 5 && nn < sections[segment].index; nn++) {
1308
                fprintf(ofp, "%02X ", sections[segment].bytes[nn]);
1309
            }
1310
            fprintf(ofp, "   ; imm\n");
1311
             if (((ca+5) & 15)==15) {
1312
                 ca+=6;
1313
                 nn++;
1314
             }
1315
             else {
1316
                  ca += 5;
1317
             }
1318
        }
1319
*/
1320
    }
1321
 
1322
    first = 1;
1323
    while (nn < sections[segment].index) {
1324
        fprintf(ofp, "%06LLX ", ca);
1325
        for (mm = nn; nn < mm + cc && nn < sections[segment].index; nn+=4) {
1326
            fprintf(ofp, "%02X", sections[segment].bytes[nn+3]);
1327
            fprintf(ofp, "%02X", sections[segment].bytes[nn+2]);
1328
            fprintf(ofp, "%02X", sections[segment].bytes[nn+1]);
1329
            fprintf(ofp, "%02X", sections[segment].bytes[nn]);
1330
        }
1331
        for (; nn < mm + cc; nn++)
1332
            fprintf(ofp, "   ");
1333
        if (first & opt) {
1334
            fprintf(ofp, "\t%.*s\n", inptr-stptr-1, stptr);
1335
            first = 0;
1336
        }
1337
        else
1338
            fprintf(ofp, opt ? "\n" : "; NOP Ramp\n");
1339
        ca += cc;
1340
    }
1341
    // empty (codeless) line
1342
    if (binstart==sections[segment].index) {
1343
        fprintf(ofp, "%24s\t%.*s", "", inptr-stptr, stptr);
1344
    }
1345
    } // bGen
1346
    if (opt) {
1347
       stptr = inptr;
1348
       lineno++;
1349
    }
1350
    binstart = sections[segment].index;
1351
    ca = sections[segment].address;
1352
}
1353
 
1354
// ----------------------------------------------------------------------------
1355
// ----------------------------------------------------------------------------
1356
 
1357
void Friscv_processMaster()
1358
{
1359
    int nn,mm;
1360
    int64_t bs1, bs2;
1361
 
1362
    lineno = 1;
1363
    binndx = 0;
1364
    binstart = 0;
1365
    bs1 = 0;
1366
    bs2 = 0;
1367
    inptr = &masterFile[0];
1368
    stptr = inptr;
1369
    code_address = 0;
1370
    bss_address = 0;
1371
    start_address = 0;
1372
    first_org = 1;
1373
    first_rodata = 1;
1374
    first_data = 1;
1375
    first_bss = 1;
1376
    if (pass<3) {
1377
    htblmax = 0;
1378
    for (nn = 0; nn < 100000; nn++) {
1379
      hTable[nn].count = 0;
1380
      hTable[nn].opcode = 0;
1381
    }
1382
    }
1383
    for (nn = 0; nn < 12; nn++) {
1384
        sections[nn].index = 0;
1385
        if (nn == 0)
1386
        sections[nn].address = 0;
1387
        else
1388
        sections[nn].address = 0;
1389
        sections[nn].start = 0;
1390
        sections[nn].end = 0;
1391
    }
1392
    ca = code_address;
1393
    segment = codeseg;
1394
    memset(current_label,0,sizeof(current_label));
1395
    NextToken();
1396
    while (token != tk_eof) {
1397
//        printf("\t%.*s\n", inptr-stptr-1, stptr);
1398
//        printf("token=%d\r", token);
1399
        switch(token) {
1400
        case tk_eol: ProcessEOL(1); break;
1401
//        case tk_add:  process_add(); break;
1402
        case tk_add:  process_rrop(0x33,0x00,0x00); break;
1403
        case tk_addi: process_addi(0); break;
1404
        case tk_align: process_align(); continue; break;
1405
        case tk_and:  process_rrop(0x33,0x07,0x00); break;
1406
        case tk_andi:  process_addi(7); break;
1407
        case tk_beq: process_bcc(0); break;
1408
        case tk_bge: process_bcc(5); break;
1409
        case tk_bgeu: process_bcc(7); break;
1410
        case tk_blt: process_bcc(4); break;
1411
        case tk_bltu: process_bcc(6); break;
1412
        case tk_bne: process_bcc(1); break;
1413
        case tk_bra: process_bra(0x46); break;
1414
        case tk_bsr: process_bra(0x56); break;
1415
        case tk_bss:
1416
            if (first_bss) {
1417
                while(sections[segment].address & 4095)
1418
                    emitByte(0x00);
1419
                sections[3].address = sections[segment].address;
1420
                first_bss = 0;
1421
                binstart = sections[3].index;
1422
                ca = sections[3].address;
1423
            }
1424
            segment = bssseg;
1425
            break;
1426
        case tk_cli: emit_insn(0x3100000001,1); break;
1427
        case tk_code: process_code(); break;
1428
        case tk_com: process_rop(0x06); break;
1429
        case tk_cs:  segprefix = 15; break;
1430
        case tk_csrrc: process_csrrw(3); break;
1431
        case tk_csrrs: process_csrrw(2); break;
1432
        case tk_csrrw: process_csrrw(1); break;
1433
        case tk_data:
1434
            if (first_data) {
1435
                while(sections[segment].address & 4095)
1436
                    emitByte(0x00);
1437
                sections[2].address = sections[segment].address;   // set starting address
1438
                first_data = 0;
1439
                binstart = sections[2].index;
1440
                ca = sections[2].address;
1441
            }
1442
            process_data(dataseg);
1443
            break;
1444
        case tk_db:  process_db(); break;
1445
        case tk_dc:  process_dc(); break;
1446
        case tk_dh:  process_dh(); break;
1447
//        case tk_div: process_rrop(0x08); break;
1448
//        case tk_divu: process_rrop(0x18); break;
1449
        case tk_dw:  process_dw(); break;
1450
        case tk_end: goto j1;
1451
        case tk_endpublic: break;
1452
        case tk_eor: process_rrop(0x33,0x04,0x00); break;
1453
        case tk_eori: process_riop(0x13,0x04); break;
1454
        case tk_extern: process_extern(); break;
1455
        case tk_fabs: process_fprop(0x88); break;
1456
        case tk_fadd: process_fprrop(0xF4); break;
1457
        case tk_fcmp: process_fprrop(0xF6); break;
1458
        case tk_fdiv: process_fprrop(0xF8); break;
1459
        case tk_fill: process_fill(); break;
1460
        case tk_fix2flt: process_fprop(0x84); break;
1461
        case tk_flt2fix: process_fprop(0x85); break;
1462
        case tk_fmov: process_fprop(0x87); break;
1463
        case tk_fmul: process_fprrop(0xF7); break;
1464
        case tk_fnabs: process_fprop(0x89); break;
1465
        case tk_fneg: process_fprop(0x8A); break;
1466
        case tk_frm: process_fpstat(0x78); break;
1467
        case tk_fstat: process_fprdstat(0x86); break;
1468
        case tk_fsub: process_fprrop(0xF5); break;
1469
        case tk_ftx: process_fpstat(0x75); break;
1470
        case tk_gran: process_gran(0x14); break;
1471
        case tk_jal: process_jal(); break;
1472
        case tk_jmp: process_jal(); break;
1473
        case tk_lb:  process_load(0x03,0); break;
1474
        case tk_lbu: process_load(0x03,4); break;
1475
        case tk_ld: process_ldi(); break;
1476
        case tk_ldi: process_ldi(); break;
1477
        case tk_lh:  process_load(0x03,1); break;
1478
        case tk_lhu: process_load(0x03,5); break;
1479
//        case tk_lui: process_lui(); break;
1480
        case tk_lw:  process_load(0x03,2); break;
1481
        case tk_mfspr: process_mfspr(0x49); break;
1482
        case tk_mov: process_mov(0x04); break;
1483
        case tk_mtspr: process_mtspr(0x48); break;
1484
        case tk_mul: process_rrop(0x33,0x00,0x01); break;
1485
        case tk_neg: process_rop(0x05); break;
1486
        case tk_nop: emit_insn(0xEAEAEAEAEA,1); break;
1487
        case tk_not: process_rop(0x07); break;
1488
        case tk_or:  process_rrop(0x33,0x06,0x00); break;
1489
        case tk_ori: process_addi(6); break;
1490
        case tk_org: process_org(); break;
1491
        case tk_php: emit_insn(0x3200000001,1); break;
1492
        case tk_plp: emit_insn(0x3300000001,1); break;
1493
        case tk_plus: expand_flag = 1; break;
1494
        case tk_public: process_public(); break;
1495
        case tk_rodata:
1496
            if (first_rodata) {
1497
                while(sections[segment].address & 4095)
1498
                    emitByte(0x00);
1499
                sections[1].address = sections[segment].address;
1500
                first_rodata = 0;
1501
                binstart = sections[1].index;
1502
                ca = sections[1].address;
1503
            }
1504
            segment = rodataseg;
1505
            break;
1506
        case tk_eret: emit_insn(0x10000073,1); break;
1507
        case tk_rts: process_rts(0x60); break;
1508
        case tk_sb:  process_store(0x23,0); break;
1509
        case tk_sei: emit_insn(0x3000000001,1); break;
1510
        case tk_slt:  process_rrop(0x33,0x02,0x00); break;
1511
        case tk_sltu:  process_rrop(0x33,0x03,0x00); break;
1512
        case tk_slti:  process_riop(0x13,0x02); break;
1513
        case tk_sltui:  process_riop(0x13,0x03); break;
1514
        case tk_sh:  process_store(0x23,1); break;
1515
        case tk_slli: process_shifti(0x13,0x01,0x00); break;
1516
        case tk_srai: process_shifti(0x13,0x05,0x20); break;
1517
        case tk_srli: process_shifti(0x13,0x05,0x00); break;
1518
        case tk_sub:  process_rrop(0x33,0x00,0x20); break;
1519
//        case tk_sub:  process_sub(); break;
1520
        case tk_sxb: process_rop(0x08); break;
1521
        case tk_sxc: process_rop(0x09); break;
1522
        case tk_sxh: process_rop(0x0A); break;
1523
        case tk_sw:  process_store(0x23,2); break;
1524
        case tk_swap: process_rop(0x03); break;
1525
        case tk_xor: process_rrop(0x33,0x04,0x00); break;
1526
        case tk_xori: process_riop(0x13,0x04); break;
1527
        case tk_id:  process_label(); break;
1528
        case '-': compress_flag = 1; break;
1529
        }
1530
        NextToken();
1531
    }
1532
j1:
1533
    ;
1534
}
1535
 

powered by: WebSVN 2.1.0

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