Added hi[] and lo[] functions to the assembler; fix things enough that we now

get to the point of failing to link programs.
This commit is contained in:
David Given 2018-09-08 22:42:06 +02:00
parent 379c1a4a3c
commit 75308901bc
6 changed files with 43 additions and 17 deletions

View file

@ -5,6 +5,9 @@
%token <y_word> OP_LI %token <y_word> OP_LI
%token <y_word> OP_LA %token <y_word> OP_LA
%token <y_word> HI
%token <y_word> LO
%type <y_word> gpr fpr %type <y_word> gpr fpr
%type <y_word> e16 e9 %type <y_word> e16 e9
%type <y_word> u25 u20 u16 u5 u3 %type <y_word> u25 u20 u16 u5 u3
@ -14,6 +17,8 @@
%type <y_word> fcond %type <y_word> fcond
%type <y_word> extmsblsb insmsblsb %type <y_word> extmsblsb insmsblsb
%type <y_word> hilo
%type <y_valu> extabsexp
#include "definitions.y" #include "definitions.y"

View file

@ -76,6 +76,8 @@
0, OP_LI, 0, "li", 0, OP_LI, 0, "li",
0, OP_LA, 0, "la", 0, OP_LA, 0, "la",
0, HI, RELOMIPSHI, "hi",
0, LO, RELOMIPS, "lo",
#include "tokens.y" #include "tokens.y"

View file

@ -31,6 +31,20 @@
emit4(0x34000000 | (reg<<16) | (reg<<21) | (val & 0xffff)); /* ori reg, reg, value */ 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 gpr: GPR
fpr: FPR fpr: FPR
@ -40,7 +54,11 @@ fmt3
| OP__DOT_W { $$ = 4; } | OP__DOT_W { $$ = 4; }
| OP__DOT_L { $$ = 5; } | OP__DOT_L { $$ = 5; }
| OP__DOT_PS { $$ = 6; } | OP__DOT_PS { $$ = 6; }
fmt: fmt3 { $$ = $1 + 16; } ;
fmt
: fmt3 { $$ = $1 + 16; }
;
fcond fcond
: OP__DOT_F { $$ = 0; } : OP__DOT_F { $$ = 0; }
@ -59,9 +77,10 @@ fcond
| OP__DOT_NGE { $$ = 13; } | OP__DOT_NGE { $$ = 13; }
| OP__DOT_LE { $$ = 14; } | OP__DOT_LE { $$ = 14; }
| OP__DOT_NGT { $$ = 15; } | OP__DOT_NGT { $$ = 15; }
;
e16 e16
: absexp : extabsexp
{ {
/* Allow signed or unsigned 16-bit values. */ /* Allow signed or unsigned 16-bit values. */
if (($1 < -0x8000) || ($1 > 0xffff)) if (($1 < -0x8000) || ($1 > 0xffff))
@ -99,7 +118,7 @@ u20
; ;
u16 u16
: absexp : extabsexp
{ {
if (($1 < 0) || ($1 > 0xffff)) if (($1 < 0) || ($1 > 0xffff))
serror("16-bit unsigned value out of range"); serror("16-bit unsigned value out of range");

View file

@ -4,16 +4,16 @@
.sect .data .sect .data
.sect .bss .sect .bss
.data .sect .text
.define .c_ud_i .define .c_ud_i
.c_ud_i: .c_ud_i:
/* Input: f0 /* Input: f0
* Output: r2 * Output: r2
* Only at and f31 may be used. * 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 c.le.d 0, f31, f0
bc1t toobig bc1t toobig
nop nop

View file

@ -4,28 +4,28 @@
.sect .data .sect .data
.sect .bss .sect .bss
.data .sect .text
.define .c_uf_i .define .c_uf_i
.c_uf_i: .c_uf_i:
/* Input: f0 /* Input: f0
* Output: r2 * Output: r2
* Only at and f31 may be used. * Only at and f31 may be used.
*/ */
li at, hi(.fd_80000000)
lwc1 f31, lo(.fd_800000000)(at) ori at, zero, hi[.ff_80000000]
c.le.f 0, f31, f0 lwc1 f31, lo[.ff_80000000] (at)
c.le.s 0, f31, f0
bc1t toobig bc1t toobig
nop nop
trunc.w.f f0, f0 trunc.w.s f0, f0
mfc1 r2, f0 mfc1 r2, f0
jr ra jr ra
nop nop
toobig: toobig:
sub.f f0, f0, f31 sub.s f0, f0, f31
trunc.w.f f0, f0 trunc.w.s f0, f0
mfc1 r2, f0 mfc1 r2, f0
addiu r2, r2, 0x8000 addiu r2, r2, 0x8000
jr ra jr ra

View file

@ -8,6 +8,6 @@
li r3, 20 ! ECASE = 20 in h/em_abs.h li r3, 20 ! ECASE = 20 in h/em_abs.h
! FALLTHROUGH to .trp ! FALLTHROUGH to .trp
.trap: .trp:
syscall syscall 0