Added hi[] and lo[] functions to the assembler; fix things enough that we now
authorDavid Given <dg@cowlark.com>
Sat, 8 Sep 2018 20:42:06 +0000 (22:42 +0200)
committerDavid Given <dg@cowlark.com>
Sat, 8 Sep 2018 20:42:06 +0000 (22:42 +0200)
get to the point of failing to link programs.

mach/mips/as/mach2.c
mach/mips/as/mach3.c
mach/mips/as/mach4.c
mach/mips/libem/c_ud_i.s
mach/mips/libem/c_uf_i.s
mach/mips/libem/trp.s

index 9c81ed9..48fce77 100644 (file)
@@ -5,6 +5,9 @@
 %token <y_word> OP_LI
 %token <y_word> OP_LA
 
+%token <y_word> HI
+%token <y_word> LO
+
 %type <y_word> gpr fpr
 %type <y_word> e16 e9
 %type <y_word> u25 u20 u16 u5 u3
@@ -14,6 +17,8 @@
 %type <y_word> fcond
 
 %type <y_word> extmsblsb insmsblsb
+%type <y_word> hilo
+%type <y_valu> extabsexp
 
 #include "definitions.y"
 
index d75845e..519bb02 100644 (file)
@@ -76,6 +76,8 @@
 
 0,     OP_LI,      0,          "li",
 0,     OP_LA,      0,          "la",
+0,     HI,         RELOMIPSHI, "hi",
+0,     LO,         RELOMIPS,   "lo",
 
 #include "tokens.y"
 
index fddeb25..7b2e7e2 100644 (file)
                emit4(0x34000000 | (reg<<16) | (reg<<21) | (val & 0xffff)); /* ori reg, reg, value */
        }
 
+extabsexp
+       : absexp
+       | hilo ASC_LPAR expr ASC_RPAR
+       {
+               newrelo($3.typ, $1 | FIXUPFLAGS);
+               $$ = $3.val;
+       }
+       ;
+
+hilo
+       : HI { $$ = $1; }
+       | LO { $$ = $1; }
+       ;
+
 gpr: GPR
 fpr: FPR
 
@@ -40,7 +54,11 @@ fmt3
        | OP__DOT_W  { $$ = 4; }
        | OP__DOT_L  { $$ = 5; }
        | OP__DOT_PS { $$ = 6; }
-fmt: fmt3        { $$ = $1 + 16; }
+       ;
+
+fmt
+       : fmt3       { $$ = $1 + 16; }
+    ;
 
 fcond
        : OP__DOT_F    { $$ = 0; }
@@ -59,9 +77,10 @@ fcond
        | OP__DOT_NGE  { $$ = 13; }
        | OP__DOT_LE   { $$ = 14; }
        | OP__DOT_NGT  { $$ = 15; }
+       ;
 
 e16
-       : absexp
+       : extabsexp
        {
                /* Allow signed or unsigned 16-bit values. */
                if (($1 < -0x8000) || ($1 > 0xffff))
@@ -99,7 +118,7 @@ u20
        ;
 
 u16
-       : absexp
+       : extabsexp
        {
                if (($1 < 0) || ($1 > 0xffff))
                        serror("16-bit unsigned value out of range");
index e9c9dda..c0dc10b 100644 (file)
@@ -4,16 +4,16 @@
 .sect .data
 .sect .bss
 
-.data
-
+.sect .text
 .define .c_ud_i
 .c_ud_i:
        /* Input: f0
         * Output: r2
         * Only at and f31 may be used.
         */
-       li at, hi(.fd_80000000)
-       ldc1 f31, lo(.fd_800000000)(at)
+
+       ori at, zero, hi[.fd_80000000]
+       ldc1 f31, lo[.fd_80000000] (at)
        c.le.d 0, f31, f0
        bc1t toobig
        nop
index ac0642f..6dd9f23 100644 (file)
@@ -4,28 +4,28 @@
 .sect .data
 .sect .bss
 
-.data
-
+.sect .text
 .define .c_uf_i
 .c_uf_i:
        /* Input: f0
         * Output: r2
         * Only at and f31 may be used.
         */
-       li at, hi(.fd_80000000)
-       lwc1 f31, lo(.fd_800000000)(at)
-       c.le.f 0, f31, f0
+
+       ori at, zero, hi[.ff_80000000]
+       lwc1 f31, lo[.ff_80000000] (at)
+       c.le.s 0, f31, f0
        bc1t toobig
        nop
 
-       trunc.w.f f0, f0
+       trunc.w.s f0, f0
        mfc1 r2, f0
        jr ra
        nop
 
 toobig:
-       sub.f f0, f0, f31
-       trunc.w.f f0, f0
+       sub.s f0, f0, f31
+       trunc.w.s f0, f0
        mfc1 r2, f0
        addiu r2, r2, 0x8000
        jr ra
index 7801d47..5818707 100644 (file)
@@ -8,6 +8,6 @@
        li      r3, 20                  ! ECASE = 20 in h/em_abs.h
        ! FALLTHROUGH to .trp
 
-.trap:
-       syscall
+.trp:
+       syscall 0