Commit a5b1baee authored by Russ Cox's avatar Russ Cox

cmd/8a, cmd/8g, cmd/8l, liblink: update for portable Prog, Addr

Change-Id: I19ed283962aa0221cf806307bde9ea0773a1bfd4
Reviewed-on: https://go-review.googlesource.com/3518Reviewed-by: default avatarAustin Clements <austin@google.com>
parent 604138e8
...@@ -222,8 +222,7 @@ spec3: /* JMP/CALL */ ...@@ -222,8 +222,7 @@ spec3: /* JMP/CALL */
{ {
$$.from = nullgen; $$.from = nullgen;
$$.to = $2; $$.to = $2;
$$.to.index = $2.type; $$.to.type = TYPE_INDIR;
$$.to.type = D_INDIR+D_ADDR;
} }
spec4: /* NOP */ spec4: /* NOP */
...@@ -240,7 +239,7 @@ spec5: /* SHL/SHR */ ...@@ -240,7 +239,7 @@ spec5: /* SHL/SHR */
{ {
$$.from = $1; $$.from = $1;
$$.to = $3; $$.to = $3;
if($$.from.index != D_NONE) if($$.from.index != TYPE_NONE)
yyerror("dp shift with lhs index"); yyerror("dp shift with lhs index");
$$.from.index = $5; $$.from.index = $5;
} }
...@@ -255,7 +254,7 @@ spec6: /* MOVW/MOVL */ ...@@ -255,7 +254,7 @@ spec6: /* MOVW/MOVL */
{ {
$$.from = $1; $$.from = $1;
$$.to = $3; $$.to = $3;
if($$.to.index != D_NONE) if($$.to.index != TYPE_NONE)
yyerror("dp move with lhs index"); yyerror("dp move with lhs index");
$$.to.index = $5; $$.to.index = $5;
} }
...@@ -303,7 +302,7 @@ spec10: /* PINSRD */ ...@@ -303,7 +302,7 @@ spec10: /* PINSRD */
{ {
$$.from = $3; $$.from = $3;
$$.to = $5; $$.to = $5;
if($1.type != D_CONST) if($1.type != TYPE_CONST)
yyerror("illegal constant"); yyerror("illegal constant");
$$.to.offset = $1.offset; $$.to.offset = $1.offset;
} }
...@@ -311,7 +310,7 @@ spec10: /* PINSRD */ ...@@ -311,7 +310,7 @@ spec10: /* PINSRD */
spec11: /* PCDATA */ spec11: /* PCDATA */
rim ',' rim rim ',' rim
{ {
if($1.type != D_CONST || $3.type != D_CONST) if($1.type != TYPE_CONST || $3.type != TYPE_CONST)
yyerror("arguments to PCDATA must be integer constants"); yyerror("arguments to PCDATA must be integer constants");
$$.from = $1; $$.from = $1;
$$.to = $3; $$.to = $3;
...@@ -320,9 +319,9 @@ spec11: /* PCDATA */ ...@@ -320,9 +319,9 @@ spec11: /* PCDATA */
spec12: /* FUNCDATA */ spec12: /* FUNCDATA */
rim ',' rim rim ',' rim
{ {
if($1.type != D_CONST) if($1.type != TYPE_CONST)
yyerror("index for FUNCDATA must be integer constant"); yyerror("index for FUNCDATA must be integer constant");
if($3.type != D_EXTERN && $3.type != D_STATIC) if($3.type != TYPE_MEM || ($3.name != NAME_EXTERN && $3.name != NAME_STATIC))
yyerror("value for FUNCDATA must be symbol reference"); yyerror("value for FUNCDATA must be symbol reference");
$$.from = $1; $$.from = $1;
$$.to = $3; $$.to = $3;
...@@ -355,7 +354,7 @@ rel: ...@@ -355,7 +354,7 @@ rel:
con '(' LPC ')' con '(' LPC ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_BRANCH; $$.type = TYPE_BRANCH;
$$.offset = $1 + pc; $$.offset = $1 + pc;
} }
| LNAME offset | LNAME offset
...@@ -364,7 +363,7 @@ rel: ...@@ -364,7 +363,7 @@ rel:
$$ = nullgen; $$ = nullgen;
if(pass == 2 && $1->type != LLAB) if(pass == 2 && $1->type != LLAB)
yyerror("undefined label: %s", $1->labelname); yyerror("undefined label: %s", $1->labelname);
$$.type = D_BRANCH; $$.type = TYPE_BRANCH;
$$.offset = $1->value + $2; $$.offset = $1->value + $2;
} }
...@@ -372,48 +371,53 @@ reg: ...@@ -372,48 +371,53 @@ reg:
LBREG LBREG
{ {
$$ = nullgen; $$ = nullgen;
$$.type = $1; $$.type = TYPE_REG;
$$.reg = $1;
} }
| LFREG | LFREG
{ {
$$ = nullgen; $$ = nullgen;
$$.type = $1; $$.type = TYPE_REG;
$$.reg = $1;
} }
| LLREG | LLREG
{ {
$$ = nullgen; $$ = nullgen;
$$.type = $1; $$.type = TYPE_REG;
$$.reg = $1;
} }
| LXREG | LXREG
{ {
$$ = nullgen; $$ = nullgen;
$$.type = $1; $$.type = TYPE_REG;
$$.reg = $1;
} }
| LSP | LSP
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_SP; $$.type = TYPE_REG;
$$.reg = REG_SP;
} }
| LSREG | LSREG
{ {
$$ = nullgen; $$ = nullgen;
$$.type = $1; $$.type = TYPE_REG;
$$.reg = $1;
} }
imm: imm:
'$' con '$' con
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_CONST; $$.type = TYPE_CONST;
$$.offset = $2; $$.offset = $2;
} }
| '$' nam | '$' nam
{ {
$$ = $2; $$ = $2;
$$.index = $2.type; $$.type = TYPE_ADDR;
$$.type = D_ADDR;
/* /*
if($2.type == D_AUTO || $2.type == D_PARAM) if($2.name == NAME_AUTO || $2.name == NAME_PARAM)
yyerror("constant cannot be automatic: %s", yyerror("constant cannot be automatic: %s",
$2.sym->name); $2.sym->name);
*/ */
...@@ -421,31 +425,31 @@ imm: ...@@ -421,31 +425,31 @@ imm:
| '$' LSCONST | '$' LSCONST
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_SCONST; $$.type = TYPE_SCONST;
memcpy($$.u.sval, $2, sizeof($$.u.sval)); memcpy($$.u.sval, $2, sizeof($$.u.sval));
} }
| '$' LFCONST | '$' LFCONST
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_FCONST; $$.type = TYPE_FCONST;
$$.u.dval = $2; $$.u.dval = $2;
} }
| '$' '(' LFCONST ')' | '$' '(' LFCONST ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_FCONST; $$.type = TYPE_FCONST;
$$.u.dval = $3; $$.u.dval = $3;
} }
| '$' '(' '-' LFCONST ')' | '$' '(' '-' LFCONST ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_FCONST; $$.type = TYPE_FCONST;
$$.u.dval = -$4; $$.u.dval = -$4;
} }
| '$' '-' LFCONST | '$' '-' LFCONST
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_FCONST; $$.type = TYPE_FCONST;
$$.u.dval = -$3; $$.u.dval = -$3;
} }
...@@ -453,9 +457,9 @@ imm2: ...@@ -453,9 +457,9 @@ imm2:
'$' con2 '$' con2
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_CONST2; $$.type = TYPE_TEXTSIZE;
$$.offset = $2.v1; $$.offset = $2.v1;
$$.offset2 = $2.v2; $$.u.argsize = $2.v2;
} }
con2: con2:
...@@ -488,25 +492,29 @@ omem: ...@@ -488,25 +492,29 @@ omem:
con con
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+D_NONE; $$.type = TYPE_MEM;
$$.reg = REG_NONE;
$$.offset = $1; $$.offset = $1;
} }
| con '(' LLREG ')' | con '(' LLREG ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+$3; $$.type = TYPE_MEM;
$$.reg = $3;
$$.offset = $1; $$.offset = $1;
} }
| con '(' LSP ')' | con '(' LSP ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+D_SP; $$.type = TYPE_MEM;
$$.reg = REG_SP;
$$.offset = $1; $$.offset = $1;
} }
| con '(' LLREG '*' con ')' | con '(' LLREG '*' con ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+D_NONE; $$.type = TYPE_MEM;
$$.reg = REG_NONE;
$$.offset = $1; $$.offset = $1;
$$.index = $3; $$.index = $3;
$$.scale = $5; $$.scale = $5;
...@@ -515,7 +523,8 @@ omem: ...@@ -515,7 +523,8 @@ omem:
| con '(' LLREG ')' '(' LLREG '*' con ')' | con '(' LLREG ')' '(' LLREG '*' con ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+$3; $$.type = TYPE_MEM;
$$.reg = $3;
$$.offset = $1; $$.offset = $1;
$$.index = $6; $$.index = $6;
$$.scale = $8; $$.scale = $8;
...@@ -524,7 +533,8 @@ omem: ...@@ -524,7 +533,8 @@ omem:
| con '(' LLREG ')' '(' LSREG '*' con ')' | con '(' LLREG ')' '(' LSREG '*' con ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+$3; $$.type = TYPE_MEM;
$$.reg = $3;
$$.offset = $1; $$.offset = $1;
$$.index = $6; $$.index = $6;
$$.scale = $8; $$.scale = $8;
...@@ -533,23 +543,27 @@ omem: ...@@ -533,23 +543,27 @@ omem:
| '(' LLREG ')' | '(' LLREG ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+$2; $$.type = TYPE_MEM;
$$.reg = $2;
} }
| '(' LSP ')' | '(' LSP ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+D_SP; $$.type = TYPE_MEM;
$$.reg = REG_SP;
} }
| con '(' LSREG ')' | con '(' LSREG ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+$3; $$.type = TYPE_MEM;
$$.reg = $3;
$$.offset = $1; $$.offset = $1;
} }
| '(' LLREG '*' con ')' | '(' LLREG '*' con ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+D_NONE; $$.type = TYPE_MEM;
$$.reg = REG_NONE;
$$.index = $2; $$.index = $2;
$$.scale = $4; $$.scale = $4;
checkscale($$.scale); checkscale($$.scale);
...@@ -557,7 +571,8 @@ omem: ...@@ -557,7 +571,8 @@ omem:
| '(' LLREG ')' '(' LLREG '*' con ')' | '(' LLREG ')' '(' LLREG '*' con ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_INDIR+$2; $$.type = TYPE_MEM;
$$.reg = $2;
$$.index = $5; $$.index = $5;
$$.scale = $7; $$.scale = $7;
checkscale($$.scale); checkscale($$.scale);
...@@ -580,14 +595,16 @@ nam: ...@@ -580,14 +595,16 @@ nam:
LNAME offset '(' pointer ')' LNAME offset '(' pointer ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = $4; $$.type = TYPE_MEM;
$$.name = $4;
$$.sym = linklookup(ctxt, $1->name, 0); $$.sym = linklookup(ctxt, $1->name, 0);
$$.offset = $2; $$.offset = $2;
} }
| LNAME '<' '>' offset '(' LSB ')' | LNAME '<' '>' offset '(' LSB ')'
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_STATIC; $$.type = TYPE_MEM;
$$.name = NAME_STATIC;
$$.sym = linklookup(ctxt, $1->name, 1); $$.sym = linklookup(ctxt, $1->name, 1);
$$.offset = $4; $$.offset = $4;
} }
...@@ -609,7 +626,7 @@ pointer: ...@@ -609,7 +626,7 @@ pointer:
LSB LSB
| LSP | LSP
{ {
$$ = D_AUTO; $$ = NAME_AUTO;
} }
| LFP | LFP
......
...@@ -192,87 +192,88 @@ struct ...@@ -192,87 +192,88 @@ struct
ushort value; ushort value;
} itab[] = } itab[] =
{ {
"SP", LSP, D_AUTO, "SP", LSP, NAME_AUTO,
"SB", LSB, D_EXTERN, "SB", LSB, NAME_EXTERN,
"FP", LFP, D_PARAM, "FP", LFP, NAME_PARAM,
"PC", LPC, D_BRANCH,
"PC", LPC, TYPE_BRANCH,
"AL", LBREG, D_AL,
"CL", LBREG, D_CL, "AL", LBREG, REG_AL,
"DL", LBREG, D_DL, "CL", LBREG, REG_CL,
"BL", LBREG, D_BL, "DL", LBREG, REG_DL,
"AH", LBREG, D_AH, "BL", LBREG, REG_BL,
"CH", LBREG, D_CH, "AH", LBREG, REG_AH,
"DH", LBREG, D_DH, "CH", LBREG, REG_CH,
"BH", LBREG, D_BH, "DH", LBREG, REG_DH,
"BH", LBREG, REG_BH,
"AX", LLREG, D_AX,
"CX", LLREG, D_CX, "AX", LLREG, REG_AX,
"DX", LLREG, D_DX, "CX", LLREG, REG_CX,
"BX", LLREG, D_BX, "DX", LLREG, REG_DX,
/* "SP", LLREG, D_SP, */ "BX", LLREG, REG_BX,
"BP", LLREG, D_BP, /* "SP", LLREG, REG_SP, */
"SI", LLREG, D_SI, "BP", LLREG, REG_BP,
"DI", LLREG, D_DI, "SI", LLREG, REG_SI,
"DI", LLREG, REG_DI,
"F0", LFREG, D_F0+0,
"F1", LFREG, D_F0+1, "F0", LFREG, REG_F0+0,
"F2", LFREG, D_F0+2, "F1", LFREG, REG_F0+1,
"F3", LFREG, D_F0+3, "F2", LFREG, REG_F0+2,
"F4", LFREG, D_F0+4, "F3", LFREG, REG_F0+3,
"F5", LFREG, D_F0+5, "F4", LFREG, REG_F0+4,
"F6", LFREG, D_F0+6, "F5", LFREG, REG_F0+5,
"F7", LFREG, D_F0+7, "F6", LFREG, REG_F0+6,
"F7", LFREG, REG_F0+7,
"X0", LXREG, D_X0+0,
"X1", LXREG, D_X0+1, "X0", LXREG, REG_X0+0,
"X2", LXREG, D_X0+2, "X1", LXREG, REG_X0+1,
"X3", LXREG, D_X0+3, "X2", LXREG, REG_X0+2,
"X4", LXREG, D_X0+4, "X3", LXREG, REG_X0+3,
"X5", LXREG, D_X0+5, "X4", LXREG, REG_X0+4,
"X6", LXREG, D_X0+6, "X5", LXREG, REG_X0+5,
"X7", LXREG, D_X0+7, "X6", LXREG, REG_X0+6,
"X7", LXREG, REG_X0+7,
"CS", LSREG, D_CS,
"SS", LSREG, D_SS, "CS", LSREG, REG_CS,
"DS", LSREG, D_DS, "SS", LSREG, REG_SS,
"ES", LSREG, D_ES, "DS", LSREG, REG_DS,
"FS", LSREG, D_FS, "ES", LSREG, REG_ES,
"GS", LSREG, D_GS, "FS", LSREG, REG_FS,
"TLS", LSREG, D_TLS, "GS", LSREG, REG_GS,
"TLS", LSREG, REG_TLS,
"GDTR", LBREG, D_GDTR,
"IDTR", LBREG, D_IDTR, "GDTR", LBREG, REG_GDTR,
"LDTR", LBREG, D_LDTR, "IDTR", LBREG, REG_IDTR,
"MSW", LBREG, D_MSW, "LDTR", LBREG, REG_LDTR,
"TASK", LBREG, D_TASK, "MSW", LBREG, REG_MSW,
"TASK", LBREG, REG_TASK,
"CR0", LBREG, D_CR+0,
"CR1", LBREG, D_CR+1, "CR0", LBREG, REG_CR+0,
"CR2", LBREG, D_CR+2, "CR1", LBREG, REG_CR+1,
"CR3", LBREG, D_CR+3, "CR2", LBREG, REG_CR+2,
"CR4", LBREG, D_CR+4, "CR3", LBREG, REG_CR+3,
"CR5", LBREG, D_CR+5, "CR4", LBREG, REG_CR+4,
"CR6", LBREG, D_CR+6, "CR5", LBREG, REG_CR+5,
"CR7", LBREG, D_CR+7, "CR6", LBREG, REG_CR+6,
"CR7", LBREG, REG_CR+7,
"DR0", LBREG, D_DR+0,
"DR1", LBREG, D_DR+1, "DR0", LBREG, REG_DR+0,
"DR2", LBREG, D_DR+2, "DR1", LBREG, REG_DR+1,
"DR3", LBREG, D_DR+3, "DR2", LBREG, REG_DR+2,
"DR4", LBREG, D_DR+4, "DR3", LBREG, REG_DR+3,
"DR5", LBREG, D_DR+5, "DR4", LBREG, REG_DR+4,
"DR6", LBREG, D_DR+6, "DR5", LBREG, REG_DR+5,
"DR7", LBREG, D_DR+7, "DR6", LBREG, REG_DR+6,
"DR7", LBREG, REG_DR+7,
"TR0", LBREG, D_TR+0,
"TR1", LBREG, D_TR+1, "TR0", LBREG, REG_TR+0,
"TR2", LBREG, D_TR+2, "TR1", LBREG, REG_TR+1,
"TR3", LBREG, D_TR+3, "TR2", LBREG, REG_TR+2,
"TR4", LBREG, D_TR+4, "TR3", LBREG, REG_TR+3,
"TR5", LBREG, D_TR+5, "TR4", LBREG, REG_TR+4,
"TR6", LBREG, D_TR+6, "TR5", LBREG, REG_TR+5,
"TR7", LBREG, D_TR+7, "TR6", LBREG, REG_TR+6,
"TR7", LBREG, REG_TR+7,
"AAA", LTYPE0, AAAA, "AAA", LTYPE0, AAAA,
"AAD", LTYPE0, AAAD, "AAD", LTYPE0, AAAD,
...@@ -829,8 +830,8 @@ cinit(void) ...@@ -829,8 +830,8 @@ cinit(void)
Sym *s; Sym *s;
int i; int i;
nullgen.type = D_NONE; nullgen.type = TYPE_NONE;
nullgen.index = D_NONE; nullgen.index = TYPE_NONE;
nerrors = 0; nerrors = 0;
iostack = I; iostack = I;
......
...@@ -543,16 +543,16 @@ static const yytype_uint16 yyrline[] = ...@@ -543,16 +543,16 @@ static const yytype_uint16 yyrline[] =
91, 96, 102, 103, 104, 105, 106, 107, 108, 109, 91, 96, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
122, 126, 133, 140, 147, 152, 159, 164, 171, 176, 122, 126, 133, 140, 147, 152, 159, 164, 171, 176,
181, 188, 196, 202, 211, 216, 221, 230, 231, 234, 181, 188, 196, 202, 211, 216, 221, 229, 230, 233,
239, 249, 254, 264, 269, 274, 281, 286, 294, 302, 238, 248, 253, 263, 268, 273, 280, 285, 293, 301,
312, 321, 332, 333, 336, 337, 338, 342, 346, 347, 311, 320, 331, 332, 335, 336, 337, 341, 345, 346,
348, 351, 352, 355, 361, 372, 377, 382, 387, 392, 347, 350, 351, 354, 360, 371, 377, 383, 389, 395,
397, 404, 410, 421, 427, 433, 439, 445, 453, 462, 401, 409, 415, 425, 431, 437, 443, 449, 457, 466,
467, 472, 477, 484, 485, 488, 494, 500, 506, 515, 471, 476, 481, 488, 489, 492, 499, 506, 513, 523,
524, 533, 538, 543, 549, 557, 567, 571, 580, 587, 533, 543, 549, 555, 562, 571, 582, 586, 595, 603,
596, 599, 603, 609, 610, 614, 617, 618, 622, 626, 613, 616, 620, 626, 627, 631, 634, 635, 639, 643,
630, 634, 640, 641, 645, 649, 653, 657, 661, 665, 647, 651, 657, 658, 662, 666, 670, 674, 678, 682,
669, 673, 677 686, 690, 694
}; };
#endif #endif
...@@ -1947,13 +1947,12 @@ yyreduce: ...@@ -1947,13 +1947,12 @@ yyreduce:
{ {
(yyval.addr2).from = nullgen; (yyval.addr2).from = nullgen;
(yyval.addr2).to = (yyvsp[(2) - (2)].addr); (yyval.addr2).to = (yyvsp[(2) - (2)].addr);
(yyval.addr2).to.index = (yyvsp[(2) - (2)].addr).type; (yyval.addr2).to.type = TYPE_INDIR;
(yyval.addr2).to.type = D_INDIR+D_ADDR;
} }
break; break;
case 49: case 49:
#line 235 "a.y" #line 234 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(1) - (3)].addr); (yyval.addr2).from = (yyvsp[(1) - (3)].addr);
(yyval.addr2).to = (yyvsp[(3) - (3)].addr); (yyval.addr2).to = (yyvsp[(3) - (3)].addr);
...@@ -1961,18 +1960,18 @@ yyreduce: ...@@ -1961,18 +1960,18 @@ yyreduce:
break; break;
case 50: case 50:
#line 240 "a.y" #line 239 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(1) - (5)].addr); (yyval.addr2).from = (yyvsp[(1) - (5)].addr);
(yyval.addr2).to = (yyvsp[(3) - (5)].addr); (yyval.addr2).to = (yyvsp[(3) - (5)].addr);
if((yyval.addr2).from.index != D_NONE) if((yyval.addr2).from.index != TYPE_NONE)
yyerror("dp shift with lhs index"); yyerror("dp shift with lhs index");
(yyval.addr2).from.index = (yyvsp[(5) - (5)].lval); (yyval.addr2).from.index = (yyvsp[(5) - (5)].lval);
} }
break; break;
case 51: case 51:
#line 250 "a.y" #line 249 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(1) - (3)].addr); (yyval.addr2).from = (yyvsp[(1) - (3)].addr);
(yyval.addr2).to = (yyvsp[(3) - (3)].addr); (yyval.addr2).to = (yyvsp[(3) - (3)].addr);
...@@ -1980,18 +1979,18 @@ yyreduce: ...@@ -1980,18 +1979,18 @@ yyreduce:
break; break;
case 52: case 52:
#line 255 "a.y" #line 254 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(1) - (5)].addr); (yyval.addr2).from = (yyvsp[(1) - (5)].addr);
(yyval.addr2).to = (yyvsp[(3) - (5)].addr); (yyval.addr2).to = (yyvsp[(3) - (5)].addr);
if((yyval.addr2).to.index != D_NONE) if((yyval.addr2).to.index != TYPE_NONE)
yyerror("dp move with lhs index"); yyerror("dp move with lhs index");
(yyval.addr2).to.index = (yyvsp[(5) - (5)].lval); (yyval.addr2).to.index = (yyvsp[(5) - (5)].lval);
} }
break; break;
case 53: case 53:
#line 265 "a.y" #line 264 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(1) - (2)].addr); (yyval.addr2).from = (yyvsp[(1) - (2)].addr);
(yyval.addr2).to = nullgen; (yyval.addr2).to = nullgen;
...@@ -1999,7 +1998,7 @@ yyreduce: ...@@ -1999,7 +1998,7 @@ yyreduce:
break; break;
case 54: case 54:
#line 270 "a.y" #line 269 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(1) - (1)].addr); (yyval.addr2).from = (yyvsp[(1) - (1)].addr);
(yyval.addr2).to = nullgen; (yyval.addr2).to = nullgen;
...@@ -2007,7 +2006,7 @@ yyreduce: ...@@ -2007,7 +2006,7 @@ yyreduce:
break; break;
case 55: case 55:
#line 275 "a.y" #line 274 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(1) - (3)].addr); (yyval.addr2).from = (yyvsp[(1) - (3)].addr);
(yyval.addr2).to = (yyvsp[(3) - (3)].addr); (yyval.addr2).to = (yyvsp[(3) - (3)].addr);
...@@ -2015,7 +2014,7 @@ yyreduce: ...@@ -2015,7 +2014,7 @@ yyreduce:
break; break;
case 56: case 56:
#line 282 "a.y" #line 281 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(1) - (3)].addr); (yyval.addr2).from = (yyvsp[(1) - (3)].addr);
(yyval.addr2).to = (yyvsp[(3) - (3)].addr); (yyval.addr2).to = (yyvsp[(3) - (3)].addr);
...@@ -2023,7 +2022,7 @@ yyreduce: ...@@ -2023,7 +2022,7 @@ yyreduce:
break; break;
case 57: case 57:
#line 287 "a.y" #line 286 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(1) - (5)].addr); (yyval.addr2).from = (yyvsp[(1) - (5)].addr);
(yyval.addr2).from.scale = (yyvsp[(3) - (5)].lval); (yyval.addr2).from.scale = (yyvsp[(3) - (5)].lval);
...@@ -2032,7 +2031,7 @@ yyreduce: ...@@ -2032,7 +2031,7 @@ yyreduce:
break; break;
case 58: case 58:
#line 295 "a.y" #line 294 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(1) - (5)].addr); (yyval.addr2).from = (yyvsp[(1) - (5)].addr);
(yyval.addr2).to = (yyvsp[(3) - (5)].addr); (yyval.addr2).to = (yyvsp[(3) - (5)].addr);
...@@ -2041,20 +2040,20 @@ yyreduce: ...@@ -2041,20 +2040,20 @@ yyreduce:
break; break;
case 59: case 59:
#line 303 "a.y" #line 302 "a.y"
{ {
(yyval.addr2).from = (yyvsp[(3) - (5)].addr); (yyval.addr2).from = (yyvsp[(3) - (5)].addr);
(yyval.addr2).to = (yyvsp[(5) - (5)].addr); (yyval.addr2).to = (yyvsp[(5) - (5)].addr);
if((yyvsp[(1) - (5)].addr).type != D_CONST) if((yyvsp[(1) - (5)].addr).type != TYPE_CONST)
yyerror("illegal constant"); yyerror("illegal constant");
(yyval.addr2).to.offset = (yyvsp[(1) - (5)].addr).offset; (yyval.addr2).to.offset = (yyvsp[(1) - (5)].addr).offset;
} }
break; break;
case 60: case 60:
#line 313 "a.y" #line 312 "a.y"
{ {
if((yyvsp[(1) - (3)].addr).type != D_CONST || (yyvsp[(3) - (3)].addr).type != D_CONST) if((yyvsp[(1) - (3)].addr).type != TYPE_CONST || (yyvsp[(3) - (3)].addr).type != TYPE_CONST)
yyerror("arguments to PCDATA must be integer constants"); yyerror("arguments to PCDATA must be integer constants");
(yyval.addr2).from = (yyvsp[(1) - (3)].addr); (yyval.addr2).from = (yyvsp[(1) - (3)].addr);
(yyval.addr2).to = (yyvsp[(3) - (3)].addr); (yyval.addr2).to = (yyvsp[(3) - (3)].addr);
...@@ -2062,11 +2061,11 @@ yyreduce: ...@@ -2062,11 +2061,11 @@ yyreduce:
break; break;
case 61: case 61:
#line 322 "a.y" #line 321 "a.y"
{ {
if((yyvsp[(1) - (3)].addr).type != D_CONST) if((yyvsp[(1) - (3)].addr).type != TYPE_CONST)
yyerror("index for FUNCDATA must be integer constant"); yyerror("index for FUNCDATA must be integer constant");
if((yyvsp[(3) - (3)].addr).type != D_EXTERN && (yyvsp[(3) - (3)].addr).type != D_STATIC) if((yyvsp[(3) - (3)].addr).type != TYPE_MEM || ((yyvsp[(3) - (3)].addr).name != NAME_EXTERN && (yyvsp[(3) - (3)].addr).name != NAME_STATIC))
yyerror("value for FUNCDATA must be symbol reference"); yyerror("value for FUNCDATA must be symbol reference");
(yyval.addr2).from = (yyvsp[(1) - (3)].addr); (yyval.addr2).from = (yyvsp[(1) - (3)].addr);
(yyval.addr2).to = (yyvsp[(3) - (3)].addr); (yyval.addr2).to = (yyvsp[(3) - (3)].addr);
...@@ -2074,45 +2073,46 @@ yyreduce: ...@@ -2074,45 +2073,46 @@ yyreduce:
break; break;
case 66: case 66:
#line 339 "a.y" #line 338 "a.y"
{ {
(yyval.addr) = (yyvsp[(2) - (2)].addr); (yyval.addr) = (yyvsp[(2) - (2)].addr);
} }
break; break;
case 67: case 67:
#line 343 "a.y" #line 342 "a.y"
{ {
(yyval.addr) = (yyvsp[(2) - (2)].addr); (yyval.addr) = (yyvsp[(2) - (2)].addr);
} }
break; break;
case 73: case 73:
#line 356 "a.y" #line 355 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_BRANCH; (yyval.addr).type = TYPE_BRANCH;
(yyval.addr).offset = (yyvsp[(1) - (4)].lval) + pc; (yyval.addr).offset = (yyvsp[(1) - (4)].lval) + pc;
} }
break; break;
case 74: case 74:
#line 362 "a.y" #line 361 "a.y"
{ {
(yyvsp[(1) - (2)].sym) = labellookup((yyvsp[(1) - (2)].sym)); (yyvsp[(1) - (2)].sym) = labellookup((yyvsp[(1) - (2)].sym));
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
if(pass == 2 && (yyvsp[(1) - (2)].sym)->type != LLAB) if(pass == 2 && (yyvsp[(1) - (2)].sym)->type != LLAB)
yyerror("undefined label: %s", (yyvsp[(1) - (2)].sym)->labelname); yyerror("undefined label: %s", (yyvsp[(1) - (2)].sym)->labelname);
(yyval.addr).type = D_BRANCH; (yyval.addr).type = TYPE_BRANCH;
(yyval.addr).offset = (yyvsp[(1) - (2)].sym)->value + (yyvsp[(2) - (2)].lval); (yyval.addr).offset = (yyvsp[(1) - (2)].sym)->value + (yyvsp[(2) - (2)].lval);
} }
break; break;
case 75: case 75:
#line 373 "a.y" #line 372 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = (yyvsp[(1) - (1)].lval); (yyval.addr).type = TYPE_REG;
(yyval.addr).reg = (yyvsp[(1) - (1)].lval);
} }
break; break;
...@@ -2120,59 +2120,63 @@ yyreduce: ...@@ -2120,59 +2120,63 @@ yyreduce:
#line 378 "a.y" #line 378 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = (yyvsp[(1) - (1)].lval); (yyval.addr).type = TYPE_REG;
(yyval.addr).reg = (yyvsp[(1) - (1)].lval);
} }
break; break;
case 77: case 77:
#line 383 "a.y" #line 384 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = (yyvsp[(1) - (1)].lval); (yyval.addr).type = TYPE_REG;
(yyval.addr).reg = (yyvsp[(1) - (1)].lval);
} }
break; break;
case 78: case 78:
#line 388 "a.y" #line 390 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = (yyvsp[(1) - (1)].lval); (yyval.addr).type = TYPE_REG;
(yyval.addr).reg = (yyvsp[(1) - (1)].lval);
} }
break; break;
case 79: case 79:
#line 393 "a.y" #line 396 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_SP; (yyval.addr).type = TYPE_REG;
(yyval.addr).reg = REG_SP;
} }
break; break;
case 80: case 80:
#line 398 "a.y" #line 402 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = (yyvsp[(1) - (1)].lval); (yyval.addr).type = TYPE_REG;
(yyval.addr).reg = (yyvsp[(1) - (1)].lval);
} }
break; break;
case 81: case 81:
#line 405 "a.y" #line 410 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_CONST; (yyval.addr).type = TYPE_CONST;
(yyval.addr).offset = (yyvsp[(2) - (2)].lval); (yyval.addr).offset = (yyvsp[(2) - (2)].lval);
} }
break; break;
case 82: case 82:
#line 411 "a.y" #line 416 "a.y"
{ {
(yyval.addr) = (yyvsp[(2) - (2)].addr); (yyval.addr) = (yyvsp[(2) - (2)].addr);
(yyval.addr).index = (yyvsp[(2) - (2)].addr).type; (yyval.addr).type = TYPE_ADDR;
(yyval.addr).type = D_ADDR;
/* /*
if($2.type == D_AUTO || $2.type == D_PARAM) if($2.name == D_AUTO || $2.name == D_PARAM)
yyerror("constant cannot be automatic: %s", yyerror("constant cannot be automatic: %s",
$2.sym->name); $2.sym->name);
*/ */
...@@ -2180,62 +2184,62 @@ yyreduce: ...@@ -2180,62 +2184,62 @@ yyreduce:
break; break;
case 83: case 83:
#line 422 "a.y" #line 426 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_SCONST; (yyval.addr).type = TYPE_SCONST;
memcpy((yyval.addr).u.sval, (yyvsp[(2) - (2)].sval), sizeof((yyval.addr).u.sval)); memcpy((yyval.addr).u.sval, (yyvsp[(2) - (2)].sval), sizeof((yyval.addr).u.sval));
} }
break; break;
case 84: case 84:
#line 428 "a.y" #line 432 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_FCONST; (yyval.addr).type = TYPE_FCONST;
(yyval.addr).u.dval = (yyvsp[(2) - (2)].dval); (yyval.addr).u.dval = (yyvsp[(2) - (2)].dval);
} }
break; break;
case 85: case 85:
#line 434 "a.y" #line 438 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_FCONST; (yyval.addr).type = TYPE_FCONST;
(yyval.addr).u.dval = (yyvsp[(3) - (4)].dval); (yyval.addr).u.dval = (yyvsp[(3) - (4)].dval);
} }
break; break;
case 86: case 86:
#line 440 "a.y" #line 444 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_FCONST; (yyval.addr).type = TYPE_FCONST;
(yyval.addr).u.dval = -(yyvsp[(4) - (5)].dval); (yyval.addr).u.dval = -(yyvsp[(4) - (5)].dval);
} }
break; break;
case 87: case 87:
#line 446 "a.y" #line 450 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_FCONST; (yyval.addr).type = TYPE_FCONST;
(yyval.addr).u.dval = -(yyvsp[(3) - (3)].dval); (yyval.addr).u.dval = -(yyvsp[(3) - (3)].dval);
} }
break; break;
case 88: case 88:
#line 454 "a.y" #line 458 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_CONST2; (yyval.addr).type = TYPE_TEXTSIZE;
(yyval.addr).offset = (yyvsp[(2) - (2)].con2).v1; (yyval.addr).offset = (yyvsp[(2) - (2)].con2).v1;
(yyval.addr).offset2 = (yyvsp[(2) - (2)].con2).v2; (yyval.addr).u.argsize = (yyvsp[(2) - (2)].con2).v2;
} }
break; break;
case 89: case 89:
#line 463 "a.y" #line 467 "a.y"
{ {
(yyval.con2).v1 = (yyvsp[(1) - (1)].lval); (yyval.con2).v1 = (yyvsp[(1) - (1)].lval);
(yyval.con2).v2 = ArgsSizeUnknown; (yyval.con2).v2 = ArgsSizeUnknown;
...@@ -2243,7 +2247,7 @@ yyreduce: ...@@ -2243,7 +2247,7 @@ yyreduce:
break; break;
case 90: case 90:
#line 468 "a.y" #line 472 "a.y"
{ {
(yyval.con2).v1 = -(yyvsp[(2) - (2)].lval); (yyval.con2).v1 = -(yyvsp[(2) - (2)].lval);
(yyval.con2).v2 = ArgsSizeUnknown; (yyval.con2).v2 = ArgsSizeUnknown;
...@@ -2251,7 +2255,7 @@ yyreduce: ...@@ -2251,7 +2255,7 @@ yyreduce:
break; break;
case 91: case 91:
#line 473 "a.y" #line 477 "a.y"
{ {
(yyval.con2).v1 = (yyvsp[(1) - (3)].lval); (yyval.con2).v1 = (yyvsp[(1) - (3)].lval);
(yyval.con2).v2 = (yyvsp[(3) - (3)].lval); (yyval.con2).v2 = (yyvsp[(3) - (3)].lval);
...@@ -2259,7 +2263,7 @@ yyreduce: ...@@ -2259,7 +2263,7 @@ yyreduce:
break; break;
case 92: case 92:
#line 478 "a.y" #line 482 "a.y"
{ {
(yyval.con2).v1 = -(yyvsp[(2) - (4)].lval); (yyval.con2).v1 = -(yyvsp[(2) - (4)].lval);
(yyval.con2).v2 = (yyvsp[(4) - (4)].lval); (yyval.con2).v2 = (yyvsp[(4) - (4)].lval);
...@@ -2267,37 +2271,41 @@ yyreduce: ...@@ -2267,37 +2271,41 @@ yyreduce:
break; break;
case 95: case 95:
#line 489 "a.y" #line 493 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+D_NONE; (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = REG_NONE;
(yyval.addr).offset = (yyvsp[(1) - (1)].lval); (yyval.addr).offset = (yyvsp[(1) - (1)].lval);
} }
break; break;
case 96: case 96:
#line 495 "a.y" #line 500 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+(yyvsp[(3) - (4)].lval); (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = (yyvsp[(3) - (4)].lval);
(yyval.addr).offset = (yyvsp[(1) - (4)].lval); (yyval.addr).offset = (yyvsp[(1) - (4)].lval);
} }
break; break;
case 97: case 97:
#line 501 "a.y" #line 507 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+D_SP; (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = REG_SP;
(yyval.addr).offset = (yyvsp[(1) - (4)].lval); (yyval.addr).offset = (yyvsp[(1) - (4)].lval);
} }
break; break;
case 98: case 98:
#line 507 "a.y" #line 514 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+D_NONE; (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = REG_NONE;
(yyval.addr).offset = (yyvsp[(1) - (6)].lval); (yyval.addr).offset = (yyvsp[(1) - (6)].lval);
(yyval.addr).index = (yyvsp[(3) - (6)].lval); (yyval.addr).index = (yyvsp[(3) - (6)].lval);
(yyval.addr).scale = (yyvsp[(5) - (6)].lval); (yyval.addr).scale = (yyvsp[(5) - (6)].lval);
...@@ -2306,10 +2314,11 @@ yyreduce: ...@@ -2306,10 +2314,11 @@ yyreduce:
break; break;
case 99: case 99:
#line 516 "a.y" #line 524 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+(yyvsp[(3) - (9)].lval); (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = (yyvsp[(3) - (9)].lval);
(yyval.addr).offset = (yyvsp[(1) - (9)].lval); (yyval.addr).offset = (yyvsp[(1) - (9)].lval);
(yyval.addr).index = (yyvsp[(6) - (9)].lval); (yyval.addr).index = (yyvsp[(6) - (9)].lval);
(yyval.addr).scale = (yyvsp[(8) - (9)].lval); (yyval.addr).scale = (yyvsp[(8) - (9)].lval);
...@@ -2318,10 +2327,11 @@ yyreduce: ...@@ -2318,10 +2327,11 @@ yyreduce:
break; break;
case 100: case 100:
#line 525 "a.y" #line 534 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+(yyvsp[(3) - (9)].lval); (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = (yyvsp[(3) - (9)].lval);
(yyval.addr).offset = (yyvsp[(1) - (9)].lval); (yyval.addr).offset = (yyvsp[(1) - (9)].lval);
(yyval.addr).index = (yyvsp[(6) - (9)].lval); (yyval.addr).index = (yyvsp[(6) - (9)].lval);
(yyval.addr).scale = (yyvsp[(8) - (9)].lval); (yyval.addr).scale = (yyvsp[(8) - (9)].lval);
...@@ -2330,35 +2340,39 @@ yyreduce: ...@@ -2330,35 +2340,39 @@ yyreduce:
break; break;
case 101: case 101:
#line 534 "a.y" #line 544 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+(yyvsp[(2) - (3)].lval); (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = (yyvsp[(2) - (3)].lval);
} }
break; break;
case 102: case 102:
#line 539 "a.y" #line 550 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+D_SP; (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = REG_SP;
} }
break; break;
case 103: case 103:
#line 544 "a.y" #line 556 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+(yyvsp[(3) - (4)].lval); (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = (yyvsp[(3) - (4)].lval);
(yyval.addr).offset = (yyvsp[(1) - (4)].lval); (yyval.addr).offset = (yyvsp[(1) - (4)].lval);
} }
break; break;
case 104: case 104:
#line 550 "a.y" #line 563 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+D_NONE; (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = REG_NONE;
(yyval.addr).index = (yyvsp[(2) - (5)].lval); (yyval.addr).index = (yyvsp[(2) - (5)].lval);
(yyval.addr).scale = (yyvsp[(4) - (5)].lval); (yyval.addr).scale = (yyvsp[(4) - (5)].lval);
checkscale((yyval.addr).scale); checkscale((yyval.addr).scale);
...@@ -2366,10 +2380,11 @@ yyreduce: ...@@ -2366,10 +2380,11 @@ yyreduce:
break; break;
case 105: case 105:
#line 558 "a.y" #line 572 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_INDIR+(yyvsp[(2) - (8)].lval); (yyval.addr).type = TYPE_MEM;
(yyval.addr).reg = (yyvsp[(2) - (8)].lval);
(yyval.addr).index = (yyvsp[(5) - (8)].lval); (yyval.addr).index = (yyvsp[(5) - (8)].lval);
(yyval.addr).scale = (yyvsp[(7) - (8)].lval); (yyval.addr).scale = (yyvsp[(7) - (8)].lval);
checkscale((yyval.addr).scale); checkscale((yyval.addr).scale);
...@@ -2377,14 +2392,14 @@ yyreduce: ...@@ -2377,14 +2392,14 @@ yyreduce:
break; break;
case 106: case 106:
#line 568 "a.y" #line 583 "a.y"
{ {
(yyval.addr) = (yyvsp[(1) - (1)].addr); (yyval.addr) = (yyvsp[(1) - (1)].addr);
} }
break; break;
case 107: case 107:
#line 572 "a.y" #line 587 "a.y"
{ {
(yyval.addr) = (yyvsp[(1) - (6)].addr); (yyval.addr) = (yyvsp[(1) - (6)].addr);
(yyval.addr).index = (yyvsp[(3) - (6)].lval); (yyval.addr).index = (yyvsp[(3) - (6)].lval);
...@@ -2394,153 +2409,155 @@ yyreduce: ...@@ -2394,153 +2409,155 @@ yyreduce:
break; break;
case 108: case 108:
#line 581 "a.y" #line 596 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = (yyvsp[(4) - (5)].lval); (yyval.addr).type = TYPE_MEM;
(yyval.addr).name = (yyvsp[(4) - (5)].lval);
(yyval.addr).sym = linklookup(ctxt, (yyvsp[(1) - (5)].sym)->name, 0); (yyval.addr).sym = linklookup(ctxt, (yyvsp[(1) - (5)].sym)->name, 0);
(yyval.addr).offset = (yyvsp[(2) - (5)].lval); (yyval.addr).offset = (yyvsp[(2) - (5)].lval);
} }
break; break;
case 109: case 109:
#line 588 "a.y" #line 604 "a.y"
{ {
(yyval.addr) = nullgen; (yyval.addr) = nullgen;
(yyval.addr).type = D_STATIC; (yyval.addr).type = TYPE_MEM;
(yyval.addr).name = NAME_STATIC;
(yyval.addr).sym = linklookup(ctxt, (yyvsp[(1) - (7)].sym)->name, 1); (yyval.addr).sym = linklookup(ctxt, (yyvsp[(1) - (7)].sym)->name, 1);
(yyval.addr).offset = (yyvsp[(4) - (7)].lval); (yyval.addr).offset = (yyvsp[(4) - (7)].lval);
} }
break; break;
case 110: case 110:
#line 596 "a.y" #line 613 "a.y"
{ {
(yyval.lval) = 0; (yyval.lval) = 0;
} }
break; break;
case 111: case 111:
#line 600 "a.y" #line 617 "a.y"
{ {
(yyval.lval) = (yyvsp[(2) - (2)].lval); (yyval.lval) = (yyvsp[(2) - (2)].lval);
} }
break; break;
case 112: case 112:
#line 604 "a.y" #line 621 "a.y"
{ {
(yyval.lval) = -(yyvsp[(2) - (2)].lval); (yyval.lval) = -(yyvsp[(2) - (2)].lval);
} }
break; break;
case 114: case 114:
#line 611 "a.y" #line 628 "a.y"
{ {
(yyval.lval) = D_AUTO; (yyval.lval) = NAME_AUTO;
} }
break; break;
case 117: case 117:
#line 619 "a.y" #line 636 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (1)].sym)->value; (yyval.lval) = (yyvsp[(1) - (1)].sym)->value;
} }
break; break;
case 118: case 118:
#line 623 "a.y" #line 640 "a.y"
{ {
(yyval.lval) = -(yyvsp[(2) - (2)].lval); (yyval.lval) = -(yyvsp[(2) - (2)].lval);
} }
break; break;
case 119: case 119:
#line 627 "a.y" #line 644 "a.y"
{ {
(yyval.lval) = (yyvsp[(2) - (2)].lval); (yyval.lval) = (yyvsp[(2) - (2)].lval);
} }
break; break;
case 120: case 120:
#line 631 "a.y" #line 648 "a.y"
{ {
(yyval.lval) = ~(yyvsp[(2) - (2)].lval); (yyval.lval) = ~(yyvsp[(2) - (2)].lval);
} }
break; break;
case 121: case 121:
#line 635 "a.y" #line 652 "a.y"
{ {
(yyval.lval) = (yyvsp[(2) - (3)].lval); (yyval.lval) = (yyvsp[(2) - (3)].lval);
} }
break; break;
case 123: case 123:
#line 642 "a.y" #line 659 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (3)].lval) + (yyvsp[(3) - (3)].lval); (yyval.lval) = (yyvsp[(1) - (3)].lval) + (yyvsp[(3) - (3)].lval);
} }
break; break;
case 124: case 124:
#line 646 "a.y" #line 663 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (3)].lval) - (yyvsp[(3) - (3)].lval); (yyval.lval) = (yyvsp[(1) - (3)].lval) - (yyvsp[(3) - (3)].lval);
} }
break; break;
case 125: case 125:
#line 650 "a.y" #line 667 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (3)].lval) * (yyvsp[(3) - (3)].lval); (yyval.lval) = (yyvsp[(1) - (3)].lval) * (yyvsp[(3) - (3)].lval);
} }
break; break;
case 126: case 126:
#line 654 "a.y" #line 671 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (3)].lval) / (yyvsp[(3) - (3)].lval); (yyval.lval) = (yyvsp[(1) - (3)].lval) / (yyvsp[(3) - (3)].lval);
} }
break; break;
case 127: case 127:
#line 658 "a.y" #line 675 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (3)].lval) % (yyvsp[(3) - (3)].lval); (yyval.lval) = (yyvsp[(1) - (3)].lval) % (yyvsp[(3) - (3)].lval);
} }
break; break;
case 128: case 128:
#line 662 "a.y" #line 679 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (4)].lval) << (yyvsp[(4) - (4)].lval); (yyval.lval) = (yyvsp[(1) - (4)].lval) << (yyvsp[(4) - (4)].lval);
} }
break; break;
case 129: case 129:
#line 666 "a.y" #line 683 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (4)].lval) >> (yyvsp[(4) - (4)].lval); (yyval.lval) = (yyvsp[(1) - (4)].lval) >> (yyvsp[(4) - (4)].lval);
} }
break; break;
case 130: case 130:
#line 670 "a.y" #line 687 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (3)].lval) & (yyvsp[(3) - (3)].lval); (yyval.lval) = (yyvsp[(1) - (3)].lval) & (yyvsp[(3) - (3)].lval);
} }
break; break;
case 131: case 131:
#line 674 "a.y" #line 691 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (3)].lval) ^ (yyvsp[(3) - (3)].lval); (yyval.lval) = (yyvsp[(1) - (3)].lval) ^ (yyvsp[(3) - (3)].lval);
} }
break; break;
case 132: case 132:
#line 678 "a.y" #line 695 "a.y"
{ {
(yyval.lval) = (yyvsp[(1) - (3)].lval) | (yyvsp[(3) - (3)].lval); (yyval.lval) = (yyvsp[(1) - (3)].lval) | (yyvsp[(3) - (3)].lval);
} }
...@@ -2548,7 +2565,7 @@ yyreduce: ...@@ -2548,7 +2565,7 @@ yyreduce:
/* Line 1267 of yacc.c. */ /* Line 1267 of yacc.c. */
#line 2552 "y.tab.c" #line 2569 "y.tab.c"
default: break; default: break;
} }
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
......
...@@ -715,8 +715,9 @@ agen(Node *n, Node *res) ...@@ -715,8 +715,9 @@ agen(Node *n, Node *res)
// LEAL (n3)(n2*w), n3 // LEAL (n3)(n2*w), n3
p1 = gins(ALEAL, &n2, &n3); p1 = gins(ALEAL, &n2, &n3);
p1->from.scale = w; p1->from.scale = w;
p1->from.index = p1->from.type; p1->from.type = TYPE_MEM;
p1->from.type = p1->to.type + D_INDIR; p1->from.index = p1->from.reg;
p1->from.reg = p1->to.reg;
} else { } else {
nodconst(&tmp, types[TUINT32], w); nodconst(&tmp, types[TUINT32], w);
gins(optoas(OMUL, types[TUINT32]), &tmp, &n2); gins(optoas(OMUL, types[TUINT32]), &tmp, &n2);
...@@ -805,7 +806,7 @@ igen(Node *n, Node *a, Node *res) ...@@ -805,7 +806,7 @@ igen(Node *n, Node *a, Node *res)
case OINDREG: case OINDREG:
// Increase the refcount of the register so that igen's caller // Increase the refcount of the register so that igen's caller
// has to call regfree. // has to call regfree.
if(n->val.u.reg != D_SP) if(n->val.u.reg != REG_SP)
reg[n->val.u.reg]++; reg[n->val.u.reg]++;
*a = *n; *a = *n;
return; return;
...@@ -856,7 +857,7 @@ igen(Node *n, Node *a, Node *res) ...@@ -856,7 +857,7 @@ igen(Node *n, Node *a, Node *res)
fp = structfirst(&flist, getoutarg(n->left->type)); fp = structfirst(&flist, getoutarg(n->left->type));
memset(a, 0, sizeof *a); memset(a, 0, sizeof *a);
a->op = OINDREG; a->op = OINDREG;
a->val.u.reg = D_SP; a->val.u.reg = REG_SP;
a->addable = 1; a->addable = 1;
a->xoffset = fp->width; a->xoffset = fp->width;
a->type = n->type; a->type = n->type;
...@@ -1262,8 +1263,8 @@ sgen(Node *n, Node *res, int64 w) ...@@ -1262,8 +1263,8 @@ sgen(Node *n, Node *res, int64 w)
return; return;
} }
nodreg(&dst, types[tptr], D_DI); nodreg(&dst, types[tptr], REG_DI);
nodreg(&src, types[tptr], D_SI); nodreg(&src, types[tptr], REG_SI);
tempname(&tsrc, types[tptr]); tempname(&tsrc, types[tptr]);
tempname(&tdst, types[tptr]); tempname(&tdst, types[tptr]);
...@@ -1293,23 +1294,23 @@ sgen(Node *n, Node *res, int64 w) ...@@ -1293,23 +1294,23 @@ sgen(Node *n, Node *res, int64 w)
// reverse direction // reverse direction
gins(ASTD, N, N); // set direction flag gins(ASTD, N, N); // set direction flag
if(c > 0) { if(c > 0) {
gconreg(AADDL, w-1, D_SI); gconreg(AADDL, w-1, REG_SI);
gconreg(AADDL, w-1, D_DI); gconreg(AADDL, w-1, REG_DI);
gconreg(AMOVL, c, D_CX); gconreg(AMOVL, c, REG_CX);
gins(AREP, N, N); // repeat gins(AREP, N, N); // repeat
gins(AMOVSB, N, N); // MOVB *(SI)-,*(DI)- gins(AMOVSB, N, N); // MOVB *(SI)-,*(DI)-
} }
if(q > 0) { if(q > 0) {
if(c > 0) { if(c > 0) {
gconreg(AADDL, -3, D_SI); gconreg(AADDL, -3, REG_SI);
gconreg(AADDL, -3, D_DI); gconreg(AADDL, -3, REG_DI);
} else { } else {
gconreg(AADDL, w-4, D_SI); gconreg(AADDL, w-4, REG_SI);
gconreg(AADDL, w-4, D_DI); gconreg(AADDL, w-4, REG_DI);
} }
gconreg(AMOVL, q, D_CX); gconreg(AMOVL, q, REG_CX);
gins(AREP, N, N); // repeat gins(AREP, N, N); // repeat
gins(AMOVSL, N, N); // MOVL *(SI)-,*(DI)- gins(AMOVSL, N, N); // MOVL *(SI)-,*(DI)-
} }
...@@ -1319,12 +1320,12 @@ sgen(Node *n, Node *res, int64 w) ...@@ -1319,12 +1320,12 @@ sgen(Node *n, Node *res, int64 w)
gins(ACLD, N, N); // paranoia. TODO(rsc): remove? gins(ACLD, N, N); // paranoia. TODO(rsc): remove?
// normal direction // normal direction
if(q > 128 || (q >= 4 && nacl)) { if(q > 128 || (q >= 4 && nacl)) {
gconreg(AMOVL, q, D_CX); gconreg(AMOVL, q, REG_CX);
gins(AREP, N, N); // repeat gins(AREP, N, N); // repeat
gins(AMOVSL, N, N); // MOVL *(SI)+,*(DI)+ gins(AMOVSL, N, N); // MOVL *(SI)+,*(DI)+
} else if(q >= 4) { } else if(q >= 4) {
p = gins(ADUFFCOPY, N, N); p = gins(ADUFFCOPY, N, N);
p->to.type = D_ADDR; p->to.type = TYPE_ADDR;
p->to.sym = linksym(pkglookup("duffcopy", runtimepkg)); p->to.sym = linksym(pkglookup("duffcopy", runtimepkg));
// 10 and 128 = magic constants: see ../../runtime/asm_386.s // 10 and 128 = magic constants: see ../../runtime/asm_386.s
p->to.offset = 10*(128-q); p->to.offset = 10*(128-q);
......
...@@ -73,9 +73,9 @@ cgen64(Node *n, Node *res) ...@@ -73,9 +73,9 @@ cgen64(Node *n, Node *res)
r = &t2; r = &t2;
} }
nodreg(&ax, types[TINT32], D_AX); nodreg(&ax, types[TINT32], REG_AX);
nodreg(&cx, types[TINT32], D_CX); nodreg(&cx, types[TINT32], REG_CX);
nodreg(&dx, types[TINT32], D_DX); nodreg(&dx, types[TINT32], REG_DX);
// Setup for binary operation. // Setup for binary operation.
split64(l, &lo1, &hi1); split64(l, &lo1, &hi1);
...@@ -159,10 +159,10 @@ cgen64(Node *n, Node *res) ...@@ -159,10 +159,10 @@ cgen64(Node *n, Node *res)
} else { } else {
gins(AMOVL, &dx, &cx); gins(AMOVL, &dx, &cx);
p1 = gins(ASHLL, ncon(v), &dx); p1 = gins(ASHLL, ncon(v), &dx);
p1->from.index = D_AX; // double-width shift p1->from.index = REG_AX; // double-width shift
p1->from.scale = 0; p1->from.scale = 0;
p1 = gins(ASHLL, ncon(v), &ax); p1 = gins(ASHLL, ncon(v), &ax);
p1->from.index = D_CX; // double-width shift p1->from.index = REG_CX; // double-width shift
p1->from.scale = 0; p1->from.scale = 0;
} }
break; break;
...@@ -198,7 +198,7 @@ cgen64(Node *n, Node *res) ...@@ -198,7 +198,7 @@ cgen64(Node *n, Node *res)
gins(AMOVL, &lo1, &ax); gins(AMOVL, &lo1, &ax);
gins(AMOVL, &hi1, &dx); gins(AMOVL, &hi1, &dx);
p1 = gins(ASHLL, ncon(v), &dx); p1 = gins(ASHLL, ncon(v), &dx);
p1->from.index = D_AX; // double-width shift p1->from.index = REG_AX; // double-width shift
p1->from.scale = 0; p1->from.scale = 0;
gins(ASHLL, ncon(v), &ax); gins(ASHLL, ncon(v), &ax);
break; break;
...@@ -240,7 +240,7 @@ cgen64(Node *n, Node *res) ...@@ -240,7 +240,7 @@ cgen64(Node *n, Node *res)
// general shift // general shift
p1 = gins(ASHLL, &cx, &dx); p1 = gins(ASHLL, &cx, &dx);
p1->from.index = D_AX; // double-width shift p1->from.index = REG_AX; // double-width shift
p1->from.scale = 0; p1->from.scale = 0;
gins(ASHLL, &cx, &ax); gins(ASHLL, &cx, &ax);
patch(p2, pc); patch(p2, pc);
...@@ -287,7 +287,7 @@ cgen64(Node *n, Node *res) ...@@ -287,7 +287,7 @@ cgen64(Node *n, Node *res)
gins(AMOVL, &lo1, &ax); gins(AMOVL, &lo1, &ax);
gins(AMOVL, &hi1, &dx); gins(AMOVL, &hi1, &dx);
p1 = gins(ASHRL, ncon(v), &ax); p1 = gins(ASHRL, ncon(v), &ax);
p1->from.index = D_DX; // double-width shift p1->from.index = REG_DX; // double-width shift
p1->from.scale = 0; p1->from.scale = 0;
gins(optoas(ORSH, hi1.type), ncon(v), &dx); gins(optoas(ORSH, hi1.type), ncon(v), &dx);
break; break;
...@@ -339,7 +339,7 @@ cgen64(Node *n, Node *res) ...@@ -339,7 +339,7 @@ cgen64(Node *n, Node *res)
// general shift // general shift
p1 = gins(ASHRL, &cx, &ax); p1 = gins(ASHRL, &cx, &ax);
p1->from.index = D_DX; // double-width shift p1->from.index = REG_DX; // double-width shift
p1->from.scale = 0; p1->from.scale = 0;
gins(optoas(ORSH, hi1.type), &cx, &dx); gins(optoas(ORSH, hi1.type), &cx, &dx);
patch(p2, pc); patch(p2, pc);
......
...@@ -38,8 +38,8 @@ betypeinit(void) ...@@ -38,8 +38,8 @@ betypeinit(void)
zprog.link = P; zprog.link = P;
zprog.as = AGOK; zprog.as = AGOK;
zprog.from.type = D_NONE; zprog.from.type = TYPE_NONE;
zprog.from.index = D_NONE; zprog.from.index = TYPE_NONE;
zprog.from.scale = 0; zprog.from.scale = 0;
zprog.to = zprog.from; zprog.to = zprog.from;
arch.zprog = zprog; arch.zprog = zprog;
...@@ -71,10 +71,6 @@ main(int argc, char **argv) ...@@ -71,10 +71,6 @@ main(int argc, char **argv)
arch.AUNDEF = AUNDEF; arch.AUNDEF = AUNDEF;
arch.AVARDEF = AVARDEF; arch.AVARDEF = AVARDEF;
arch.AVARKILL = AVARKILL; arch.AVARKILL = AVARKILL;
arch.D_AUTO = D_AUTO;
arch.D_BRANCH = D_BRANCH;
arch.D_NONE = D_NONE;
arch.D_PARAM = D_PARAM;
arch.MAXWIDTH = MAXWIDTH; arch.MAXWIDTH = MAXWIDTH;
arch.afunclit = afunclit; arch.afunclit = afunclit;
arch.anyregalloc = anyregalloc; arch.anyregalloc = anyregalloc;
......
...@@ -20,7 +20,7 @@ enum ...@@ -20,7 +20,7 @@ enum
}; };
EXTERN int32 dynloc; EXTERN int32 dynloc;
EXTERN uchar reg[D_NONE]; EXTERN uchar reg[MAXREG];
EXTERN int32 pcloc; // instruction counter EXTERN int32 pcloc; // instruction counter
EXTERN Strlit emptystring; EXTERN Strlit emptystring;
EXTERN Prog zprog; EXTERN Prog zprog;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "gg.h" #include "gg.h"
#include "opt.h" #include "opt.h"
static Prog *appendpp(Prog*, int, int, vlong, int, vlong); static Prog *appendpp(Prog*, int, int, int, vlong, int, int, vlong);
static Prog *zerorange(Prog *p, vlong frame, vlong lo, vlong hi, uint32 *ax); static Prog *zerorange(Prog *p, vlong frame, vlong lo, vlong hi, uint32 *ax);
void void
...@@ -22,7 +22,7 @@ defframe(Prog *ptxt) ...@@ -22,7 +22,7 @@ defframe(Prog *ptxt)
Node *n; Node *n;
// fill in argument size // fill in argument size
ptxt->to.offset2 = rnd(curfn->type->argwid, widthptr); ptxt->to.u.argsize = rnd(curfn->type->argwid, widthptr);
// fill in final stack size // fill in final stack size
frame = rnd(stksize+maxarg, widthptr); frame = rnd(stksize+maxarg, widthptr);
...@@ -68,28 +68,28 @@ zerorange(Prog *p, vlong frame, vlong lo, vlong hi, uint32 *ax) ...@@ -68,28 +68,28 @@ zerorange(Prog *p, vlong frame, vlong lo, vlong hi, uint32 *ax)
if(cnt == 0) if(cnt == 0)
return p; return p;
if(*ax == 0) { if(*ax == 0) {
p = appendpp(p, AMOVL, D_CONST, 0, D_AX, 0); p = appendpp(p, AMOVL, TYPE_CONST, 0, 0, TYPE_REG, REG_AX, 0);
*ax = 1; *ax = 1;
} }
if(cnt <= 4*widthreg) { if(cnt <= 4*widthreg) {
for(i = 0; i < cnt; i += widthreg) { for(i = 0; i < cnt; i += widthreg) {
p = appendpp(p, AMOVL, D_AX, 0, D_SP+D_INDIR, frame+lo+i); p = appendpp(p, AMOVL, TYPE_REG, REG_AX, 0, TYPE_MEM, REG_SP, frame+lo+i);
} }
} else if(!nacl && cnt <= 128*widthreg) { } else if(!nacl && cnt <= 128*widthreg) {
p = appendpp(p, ALEAL, D_SP+D_INDIR, frame+lo, D_DI, 0); p = appendpp(p, ALEAL, TYPE_MEM, REG_SP, frame+lo, TYPE_REG, REG_DI, 0);
p = appendpp(p, ADUFFZERO, D_NONE, 0, D_ADDR, 1*(128-cnt/widthreg)); p = appendpp(p, ADUFFZERO, TYPE_NONE, 0, 0, TYPE_ADDR, 0, 1*(128-cnt/widthreg));
p->to.sym = linksym(pkglookup("duffzero", runtimepkg)); p->to.sym = linksym(pkglookup("duffzero", runtimepkg));
} else { } else {
p = appendpp(p, AMOVL, D_CONST, cnt/widthreg, D_CX, 0); p = appendpp(p, AMOVL, TYPE_CONST, 0, cnt/widthreg, TYPE_REG, REG_CX, 0);
p = appendpp(p, ALEAL, D_SP+D_INDIR, frame+lo, D_DI, 0); p = appendpp(p, ALEAL, TYPE_MEM, REG_SP, frame+lo, TYPE_REG, REG_DI, 0);
p = appendpp(p, AREP, D_NONE, 0, D_NONE, 0); p = appendpp(p, AREP, TYPE_NONE, 0, 0, TYPE_NONE, 0, 0);
p = appendpp(p, ASTOSL, D_NONE, 0, D_NONE, 0); p = appendpp(p, ASTOSL, TYPE_NONE, 0, 0, TYPE_NONE, 0, 0);
} }
return p; return p;
} }
static Prog* static Prog*
appendpp(Prog *p, int as, int ftype, vlong foffset, int ttype, vlong toffset) appendpp(Prog *p, int as, int ftype, int freg, vlong foffset, int ttype, int treg, vlong toffset)
{ {
Prog *q; Prog *q;
q = mal(sizeof(*q)); q = mal(sizeof(*q));
...@@ -97,8 +97,10 @@ appendpp(Prog *p, int as, int ftype, vlong foffset, int ttype, vlong toffset) ...@@ -97,8 +97,10 @@ appendpp(Prog *p, int as, int ftype, vlong foffset, int ttype, vlong toffset)
q->as = as; q->as = as;
q->lineno = p->lineno; q->lineno = p->lineno;
q->from.type = ftype; q->from.type = ftype;
q->from.reg = freg;
q->from.offset = foffset; q->from.offset = foffset;
q->to.type = ttype; q->to.type = ttype;
q->to.reg = treg;
q->to.offset = toffset; q->to.offset = toffset;
q->link = p->link; q->link = p->link;
p->link = q; p->link = q;
...@@ -128,7 +130,7 @@ fixautoused(Prog* p) ...@@ -128,7 +130,7 @@ fixautoused(Prog* p)
Prog **lp; Prog **lp;
for (lp=&p; (p=*lp) != P; ) { for (lp=&p; (p=*lp) != P; ) {
if (p->as == ATYPE && p->from.node && p->from.type == D_AUTO && !((Node*)(p->from.node))->used) { if (p->as == ATYPE && p->from.node && p->from.name == NAME_AUTO && !((Node*)(p->from.node))->used) {
*lp = p->link; *lp = p->link;
continue; continue;
} }
...@@ -137,16 +139,14 @@ fixautoused(Prog* p) ...@@ -137,16 +139,14 @@ fixautoused(Prog* p)
// VARDEFs are interspersed with other code, and a jump might be using the // VARDEFs are interspersed with other code, and a jump might be using the
// VARDEF as a target. Replace with a no-op instead. A later pass will remove // VARDEF as a target. Replace with a no-op instead. A later pass will remove
// the no-ops. // the no-ops.
p->to.type = D_NONE; nopout(p);
p->to.node = N;
p->as = ANOP;
continue; continue;
} }
if (p->from.type == D_AUTO && p->from.node) if (p->from.type == TYPE_MEM && p->from.name == NAME_AUTO && p->from.node)
p->from.offset += ((Node*)(p->from.node))->stkdelta; p->from.offset += ((Node*)(p->from.node))->stkdelta;
if (p->to.type == D_AUTO && p->to.node) if (p->to.type == TYPE_MEM && p->to.name == NAME_AUTO && p->to.node)
p->to.offset += ((Node*)(p->to.node))->stkdelta; p->to.offset += ((Node*)(p->to.node))->stkdelta;
lp = &p->link; lp = &p->link;
...@@ -198,17 +198,17 @@ clearfat(Node *nl) ...@@ -198,17 +198,17 @@ clearfat(Node *nl)
return; return;
} }
nodreg(&n1, types[tptr], D_DI); nodreg(&n1, types[tptr], REG_DI);
agen(nl, &n1); agen(nl, &n1);
gconreg(AMOVL, 0, D_AX); gconreg(AMOVL, 0, REG_AX);
if(q > 128 || (q >= 4 && nacl)) { if(q > 128 || (q >= 4 && nacl)) {
gconreg(AMOVL, q, D_CX); gconreg(AMOVL, q, REG_CX);
gins(AREP, N, N); // repeat gins(AREP, N, N); // repeat
gins(ASTOSL, N, N); // STOL AL,*(DI)+ gins(ASTOSL, N, N); // STOL AL,*(DI)+
} else if(q >= 4) { } else if(q >= 4) {
p = gins(ADUFFZERO, N, N); p = gins(ADUFFZERO, N, N);
p->to.type = D_ADDR; p->to.type = TYPE_ADDR;
p->to.sym = linksym(pkglookup("duffzero", runtimepkg)); p->to.sym = linksym(pkglookup("duffzero", runtimepkg));
// 1 and 128 = magic constants: see ../../runtime/asm_386.s // 1 and 128 = magic constants: see ../../runtime/asm_386.s
p->to.offset = 1*(128-q); p->to.offset = 1*(128-q);
...@@ -265,7 +265,7 @@ ginscall(Node *f, int proc) ...@@ -265,7 +265,7 @@ ginscall(Node *f, int proc)
// x86 NOP 0x90 is really XCHG AX, AX; use that description // x86 NOP 0x90 is really XCHG AX, AX; use that description
// because the NOP pseudo-instruction will be removed by // because the NOP pseudo-instruction will be removed by
// the linker. // the linker.
nodreg(&reg, types[TINT], D_AX); nodreg(&reg, types[TINT], REG_AX);
gins(AXCHGL, &reg, &reg); gins(AXCHGL, &reg, &reg);
} }
p = gins(ACALL, N, f); p = gins(ACALL, N, f);
...@@ -274,8 +274,8 @@ ginscall(Node *f, int proc) ...@@ -274,8 +274,8 @@ ginscall(Node *f, int proc)
gins(AUNDEF, N, N); gins(AUNDEF, N, N);
break; break;
} }
nodreg(&reg, types[tptr], D_DX); nodreg(&reg, types[tptr], REG_DX);
nodreg(&r1, types[tptr], D_BX); nodreg(&r1, types[tptr], REG_BX);
gmove(f, &reg); gmove(f, &reg);
reg.op = OINDREG; reg.op = OINDREG;
gmove(&reg, &r1); gmove(&reg, &r1);
...@@ -291,7 +291,7 @@ ginscall(Node *f, int proc) ...@@ -291,7 +291,7 @@ ginscall(Node *f, int proc)
case 2: // deferred call (defer) case 2: // deferred call (defer)
memset(&stk, 0, sizeof(stk)); memset(&stk, 0, sizeof(stk));
stk.op = OINDREG; stk.op = OINDREG;
stk.val.u.reg = D_SP; stk.val.u.reg = REG_SP;
stk.xoffset = 0; stk.xoffset = 0;
// size of arguments at 0(SP) // size of arguments at 0(SP)
...@@ -307,7 +307,7 @@ ginscall(Node *f, int proc) ...@@ -307,7 +307,7 @@ ginscall(Node *f, int proc)
else else
ginscall(deferproc, 0); ginscall(deferproc, 0);
if(proc == 2) { if(proc == 2) {
nodreg(&reg, types[TINT32], D_AX); nodreg(&reg, types[TINT32], REG_AX);
gins(ATESTL, &reg, &reg); gins(ATESTL, &reg, &reg);
p = gbranch(AJEQ, T, +1); p = gbranch(AJEQ, T, +1);
cgen_ret(N); cgen_ret(N);
...@@ -349,7 +349,7 @@ cgen_callinter(Node *n, Node *res, int proc) ...@@ -349,7 +349,7 @@ cgen_callinter(Node *n, Node *res, int proc)
// register to hold its address. // register to hold its address.
igen(i, &nodi, res); // REG = &inter igen(i, &nodi, res); // REG = &inter
nodindreg(&nodsp, types[tptr], D_SP); nodindreg(&nodsp, types[tptr], REG_SP);
nodsp.xoffset = 0; nodsp.xoffset = 0;
if(proc != 0) if(proc != 0)
nodsp.xoffset += 2 * widthptr; // leave room for size & fn nodsp.xoffset += 2 * widthptr; // leave room for size & fn
...@@ -458,7 +458,7 @@ cgen_callret(Node *n, Node *res) ...@@ -458,7 +458,7 @@ cgen_callret(Node *n, Node *res)
memset(&nod, 0, sizeof(nod)); memset(&nod, 0, sizeof(nod));
nod.op = OINDREG; nod.op = OINDREG;
nod.val.u.reg = D_SP; nod.val.u.reg = REG_SP;
nod.addable = 1; nod.addable = 1;
nod.xoffset = fp->width; nod.xoffset = fp->width;
...@@ -488,7 +488,7 @@ cgen_aret(Node *n, Node *res) ...@@ -488,7 +488,7 @@ cgen_aret(Node *n, Node *res)
memset(&nod1, 0, sizeof(nod1)); memset(&nod1, 0, sizeof(nod1));
nod1.op = OINDREG; nod1.op = OINDREG;
nod1.val.u.reg = D_SP; nod1.val.u.reg = REG_SP;
nod1.addable = 1; nod1.addable = 1;
nod1.xoffset = fp->width; nod1.xoffset = fp->width;
...@@ -519,7 +519,8 @@ cgen_ret(Node *n) ...@@ -519,7 +519,8 @@ cgen_ret(Node *n)
genlist(curfn->exit); genlist(curfn->exit);
p = gins(ARET, N, N); p = gins(ARET, N, N);
if(n != N && n->op == ORETJMP) { if(n != N && n->op == ORETJMP) {
p->to.type = D_EXTERN; p->to.type = TYPE_MEM;
p->to.name = NAME_EXTERN;
p->to.sym = linksym(n->left->sym); p->to.sym = linksym(n->left->sym);
} }
} }
...@@ -830,8 +831,8 @@ cgen_div(int op, Node *nl, Node *nr, Node *res) ...@@ -830,8 +831,8 @@ cgen_div(int op, Node *nl, Node *nr, Node *res)
t = types[TINT32]; t = types[TINT32];
else else
t = types[TUINT32]; t = types[TUINT32];
savex(D_AX, &ax, &oldax, res, t); savex(REG_AX, &ax, &oldax, res, t);
savex(D_DX, &dx, &olddx, res, t); savex(REG_DX, &dx, &olddx, res, t);
dodiv(op, nl, nr, res, &ax, &dx); dodiv(op, nl, nr, res, &ax, &dx);
restx(&dx, &olddx); restx(&dx, &olddx);
restx(&ax, &oldax); restx(&ax, &oldax);
...@@ -875,8 +876,8 @@ cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res) ...@@ -875,8 +876,8 @@ cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res)
} }
memset(&oldcx, 0, sizeof oldcx); memset(&oldcx, 0, sizeof oldcx);
nodreg(&cx, types[TUINT32], D_CX); nodreg(&cx, types[TUINT32], REG_CX);
if(reg[D_CX] > 1 && !samereg(&cx, res)) { if(reg[REG_CX] > 1 && !samereg(&cx, res)) {
tempname(&oldcx, types[TUINT32]); tempname(&oldcx, types[TUINT32]);
gmove(&cx, &oldcx); gmove(&cx, &oldcx);
} }
...@@ -885,7 +886,7 @@ cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res) ...@@ -885,7 +886,7 @@ cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res)
tempname(&nt, nr->type); tempname(&nt, nr->type);
n1 = nt; n1 = nt;
} else { } else {
nodreg(&n1, types[TUINT32], D_CX); nodreg(&n1, types[TUINT32], REG_CX);
regalloc(&n1, nr->type, &n1); // to hold the shift type in CX regalloc(&n1, nr->type, &n1); // to hold the shift type in CX
} }
...@@ -905,7 +906,7 @@ cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res) ...@@ -905,7 +906,7 @@ cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res)
if(bounded) { if(bounded) {
if(nr->type->width > 4) { if(nr->type->width > 4) {
// delayed reg alloc // delayed reg alloc
nodreg(&n1, types[TUINT32], D_CX); nodreg(&n1, types[TUINT32], REG_CX);
regalloc(&n1, types[TUINT32], &n1); // to hold the shift type in CX regalloc(&n1, types[TUINT32], &n1); // to hold the shift type in CX
split64(&nt, &lo, &hi); split64(&nt, &lo, &hi);
gmove(&lo, &n1); gmove(&lo, &n1);
...@@ -914,7 +915,7 @@ cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res) ...@@ -914,7 +915,7 @@ cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res)
} else { } else {
if(nr->type->width > 4) { if(nr->type->width > 4) {
// delayed reg alloc // delayed reg alloc
nodreg(&n1, types[TUINT32], D_CX); nodreg(&n1, types[TUINT32], REG_CX);
regalloc(&n1, types[TUINT32], &n1); // to hold the shift type in CX regalloc(&n1, types[TUINT32], &n1); // to hold the shift type in CX
split64(&nt, &lo, &hi); split64(&nt, &lo, &hi);
gmove(&lo, &n1); gmove(&lo, &n1);
...@@ -1005,18 +1006,18 @@ cgen_hmul(Node *nl, Node *nr, Node *res) ...@@ -1005,18 +1006,18 @@ cgen_hmul(Node *nl, Node *nr, Node *res)
cgen(nr, &n2); cgen(nr, &n2);
// multiply. // multiply.
nodreg(&ax, t, D_AX); nodreg(&ax, t, REG_AX);
gmove(&n2, &ax); gmove(&n2, &ax);
gins(a, &n1, N); gins(a, &n1, N);
regfree(&n2); regfree(&n2);
if(t->width == 1) { if(t->width == 1) {
// byte multiply behaves differently. // byte multiply behaves differently.
nodreg(&ax, t, D_AH); nodreg(&ax, t, REG_AH);
nodreg(&dx, t, D_DX); nodreg(&dx, t, REG_DX);
gmove(&ax, &dx); gmove(&ax, &dx);
} }
nodreg(&dx, t, D_DX); nodreg(&dx, t, REG_DX);
gmove(&dx, res); gmove(&dx, res);
} }
...@@ -1083,8 +1084,8 @@ cgen_float387(Node *n, Node *res) ...@@ -1083,8 +1084,8 @@ cgen_float387(Node *n, Node *res)
nl = n->left; nl = n->left;
nr = n->right; nr = n->right;
nodreg(&f0, nl->type, D_F0); nodreg(&f0, nl->type, REG_F0);
nodreg(&f1, n->type, D_F0+1); nodreg(&f1, n->type, REG_F0+1);
if(nr != N) if(nr != N)
goto flt2; goto flt2;
...@@ -1223,9 +1224,9 @@ x87: ...@@ -1223,9 +1224,9 @@ x87:
a = brrev(a); a = brrev(a);
} }
nodreg(&tmp, nr->type, D_F0); nodreg(&tmp, nr->type, REG_F0);
nodreg(&n2, nr->type, D_F0 + 1); nodreg(&n2, nr->type, REG_F0 + 1);
nodreg(&ax, types[TUINT16], D_AX); nodreg(&ax, types[TUINT16], REG_AX);
et = simsimtype(nr->type); et = simsimtype(nr->type);
if(et == TFLOAT64) { if(et == TFLOAT64) {
if(nl->ullman > nr->ullman) { if(nl->ullman > nr->ullman) {
...@@ -1336,22 +1337,24 @@ expandchecks(Prog *firstp) ...@@ -1336,22 +1337,24 @@ expandchecks(Prog *firstp)
p1->pc = 9999; p1->pc = 9999;
p2->pc = 9999; p2->pc = 9999;
p->as = ACMPL; p->as = ACMPL;
p->to.type = D_CONST; p->to.type = TYPE_CONST;
p->to.offset = 0; p->to.offset = 0;
p1->as = AJNE; p1->as = AJNE;
p1->from.type = D_CONST; p1->from.type = TYPE_CONST;
p1->from.offset = 1; // likely p1->from.offset = 1; // likely
p1->to.type = D_BRANCH; p1->to.type = TYPE_BRANCH;
p1->to.u.branch = p2->link; p1->to.u.branch = p2->link;
// crash by write to memory address 0. // crash by write to memory address 0.
// if possible, since we know arg is 0, use 0(arg), // if possible, since we know arg is 0, use 0(arg),
// which will be shorter to encode than plain 0. // which will be shorter to encode than plain 0.
p2->as = AMOVL; p2->as = AMOVL;
p2->from.type = D_AX; p2->from.type = TYPE_REG;
if(regtyp(&p->from)) p2->from.reg = REG_AX;
p2->to.type = p->from.type + D_INDIR; if(regtyp(&p->from)) {
else p2->to.type = TYPE_MEM;
p2->to.type = D_INDIR+D_NONE; p2->to.reg = p->from.reg;
} else
p2->to.type = TYPE_MEM;
p2->to.offset = 0; p2->to.offset = 0;
} }
} }
...@@ -38,14 +38,13 @@ dsname(Sym *s, int off, char *t, int n) ...@@ -38,14 +38,13 @@ dsname(Sym *s, int off, char *t, int n)
Prog *p; Prog *p;
p = gins(ADATA, N, N); p = gins(ADATA, N, N);
p->from.type = D_EXTERN; p->from.type = TYPE_MEM;
p->from.index = D_NONE; p->from.name = NAME_EXTERN;
p->from.offset = off; p->from.offset = off;
p->from.scale = n; p->from.scale = n;
p->from.sym = linksym(s); p->from.sym = linksym(s);
p->to.type = D_SCONST; p->to.type = TYPE_SCONST;
p->to.index = D_NONE;
memmove(p->to.u.sval, t, n); memmove(p->to.u.sval, t, n);
return off + n; return off + n;
} }
...@@ -60,7 +59,8 @@ datastring(char *s, int len, Addr *a) ...@@ -60,7 +59,8 @@ datastring(char *s, int len, Addr *a)
Sym *sym; Sym *sym;
sym = stringsym(s, len); sym = stringsym(s, len);
a->type = D_EXTERN; a->type = TYPE_MEM;
a->name = NAME_EXTERN;
a->sym = linksym(sym); a->sym = linksym(sym);
a->node = sym->def; a->node = sym->def;
a->offset = widthptr+4; // skip header a->offset = widthptr+4; // skip header
...@@ -77,7 +77,8 @@ datagostring(Strlit *sval, Addr *a) ...@@ -77,7 +77,8 @@ datagostring(Strlit *sval, Addr *a)
Sym *sym; Sym *sym;
sym = stringsym(sval->s, sval->len); sym = stringsym(sval->s, sval->len);
a->type = D_EXTERN; a->type = TYPE_MEM;
a->name = NAME_EXTERN;
a->sym = linksym(sym); a->sym = linksym(sym);
a->node = sym->def; a->node = sym->def;
a->offset = 0; // header a->offset = 0; // header
...@@ -125,13 +126,13 @@ gdatacomplex(Node *nam, Mpcplx *cval) ...@@ -125,13 +126,13 @@ gdatacomplex(Node *nam, Mpcplx *cval)
p = gins(ADATA, nam, N); p = gins(ADATA, nam, N);
p->from.scale = w; p->from.scale = w;
p->to.type = D_FCONST; p->to.type = TYPE_FCONST;
p->to.u.dval = mpgetflt(&cval->real); p->to.u.dval = mpgetflt(&cval->real);
p = gins(ADATA, nam, N); p = gins(ADATA, nam, N);
p->from.scale = w; p->from.scale = w;
p->from.offset += w; p->from.offset += w;
p->to.type = D_FCONST; p->to.type = TYPE_FCONST;
p->to.u.dval = mpgetflt(&cval->imag); p->to.u.dval = mpgetflt(&cval->imag);
} }
...@@ -144,8 +145,7 @@ gdatastring(Node *nam, Strlit *sval) ...@@ -144,8 +145,7 @@ gdatastring(Node *nam, Strlit *sval)
p = gins(ADATA, nam, N); p = gins(ADATA, nam, N);
datastring(sval->s, sval->len, &p->to); datastring(sval->s, sval->len, &p->to);
p->from.scale = types[tptr]->width; p->from.scale = types[tptr]->width;
p->to.index = p->to.type; p->to.type = TYPE_ADDR;
p->to.type = D_ADDR;
//print("%P\n", p); //print("%P\n", p);
nodconst(&nod1, types[TINT32], sval->len); nodconst(&nod1, types[TINT32], sval->len);
...@@ -161,15 +161,14 @@ dstringptr(Sym *s, int off, char *str) ...@@ -161,15 +161,14 @@ dstringptr(Sym *s, int off, char *str)
off = rnd(off, widthptr); off = rnd(off, widthptr);
p = gins(ADATA, N, N); p = gins(ADATA, N, N);
p->from.type = D_EXTERN; p->from.type = TYPE_MEM;
p->from.index = D_NONE; p->from.name = NAME_EXTERN;
p->from.sym = linksym(s); p->from.sym = linksym(s);
p->from.offset = off; p->from.offset = off;
p->from.scale = widthptr; p->from.scale = widthptr;
datastring(str, strlen(str)+1, &p->to); datastring(str, strlen(str)+1, &p->to);
p->to.index = p->to.type; p->to.type = TYPE_ADDR;
p->to.type = D_ADDR;
p->to.etype = TINT32; p->to.etype = TINT32;
off += widthptr; off += widthptr;
...@@ -186,14 +185,13 @@ dgostrlitptr(Sym *s, int off, Strlit *lit) ...@@ -186,14 +185,13 @@ dgostrlitptr(Sym *s, int off, Strlit *lit)
off = rnd(off, widthptr); off = rnd(off, widthptr);
p = gins(ADATA, N, N); p = gins(ADATA, N, N);
p->from.type = D_EXTERN; p->from.type = TYPE_MEM;
p->from.index = D_NONE; p->from.name = NAME_EXTERN;
p->from.sym = linksym(s); p->from.sym = linksym(s);
p->from.offset = off; p->from.offset = off;
p->from.scale = widthptr; p->from.scale = widthptr;
datagostring(lit, &p->to); datagostring(lit, &p->to);
p->to.index = p->to.type; p->to.type = TYPE_ADDR;
p->to.type = D_ADDR;
p->to.etype = TINT32; p->to.etype = TINT32;
off += widthptr; off += widthptr;
...@@ -224,13 +222,13 @@ dsymptr(Sym *s, int off, Sym *x, int xoff) ...@@ -224,13 +222,13 @@ dsymptr(Sym *s, int off, Sym *x, int xoff)
off = rnd(off, widthptr); off = rnd(off, widthptr);
p = gins(ADATA, N, N); p = gins(ADATA, N, N);
p->from.type = D_EXTERN; p->from.type = TYPE_MEM;
p->from.index = D_NONE; p->from.name = NAME_EXTERN;
p->from.sym = linksym(s); p->from.sym = linksym(s);
p->from.offset = off; p->from.offset = off;
p->from.scale = widthptr; p->from.scale = widthptr;
p->to.type = D_ADDR; p->to.type = TYPE_ADDR;
p->to.index = D_EXTERN; p->to.name = NAME_EXTERN;
p->to.sym = linksym(x); p->to.sym = linksym(x);
p->to.offset = xoff; p->to.offset = xoff;
off += widthptr; off += widthptr;
...@@ -242,5 +240,7 @@ void ...@@ -242,5 +240,7 @@ void
nopout(Prog *p) nopout(Prog *p)
{ {
p->as = ANOP; p->as = ANOP;
p->from = zprog.from;
p->to = zprog.to;
} }
...@@ -45,10 +45,10 @@ void ...@@ -45,10 +45,10 @@ void
clearp(Prog *p) clearp(Prog *p)
{ {
p->as = AEND; p->as = AEND;
p->from.type = D_NONE; p->from.type = TYPE_NONE;
p->from.index = D_NONE; p->from.index = TYPE_NONE;
p->to.type = D_NONE; p->to.type = TYPE_NONE;
p->to.index = D_NONE; p->to.index = TYPE_NONE;
p->pc = pcloc; p->pc = pcloc;
pcloc++; pcloc++;
} }
...@@ -120,10 +120,10 @@ gbranch(int as, Type *t, int likely) ...@@ -120,10 +120,10 @@ gbranch(int as, Type *t, int likely)
USED(t); USED(t);
p = prog(as); p = prog(as);
p->to.type = D_BRANCH; p->to.type = TYPE_BRANCH;
p->to.u.branch = P; p->to.u.branch = P;
if(likely != 0) { if(likely != 0) {
p->from.type = D_CONST; p->from.type = TYPE_CONST;
p->from.offset = likely > 0; p->from.offset = likely > 0;
} }
return p; return p;
...@@ -135,7 +135,7 @@ gbranch(int as, Type *t, int likely) ...@@ -135,7 +135,7 @@ gbranch(int as, Type *t, int likely)
void void
patch(Prog *p, Prog *to) patch(Prog *p, Prog *to)
{ {
if(p->to.type != D_BRANCH) if(p->to.type != TYPE_BRANCH)
fatal("patch: not a branch"); fatal("patch: not a branch");
p->to.u.branch = to; p->to.u.branch = to;
p->to.offset = to->pc; p->to.offset = to->pc;
...@@ -146,7 +146,7 @@ unpatch(Prog *p) ...@@ -146,7 +146,7 @@ unpatch(Prog *p)
{ {
Prog *q; Prog *q;
if(p->to.type != D_BRANCH) if(p->to.type != TYPE_BRANCH)
fatal("unpatch: not a branch"); fatal("unpatch: not a branch");
q = p->to.u.branch; q = p->to.u.branch;
p->to.u.branch = P; p->to.u.branch = P;
...@@ -197,7 +197,7 @@ ggloblnod(Node *nam) ...@@ -197,7 +197,7 @@ ggloblnod(Node *nam)
p->lineno = nam->lineno; p->lineno = nam->lineno;
p->from.sym->gotype = linksym(ngotype(nam)); p->from.sym->gotype = linksym(ngotype(nam));
p->to.sym = nil; p->to.sym = nil;
p->to.type = D_CONST; p->to.type = TYPE_CONST;
p->to.offset = nam->type->width; p->to.offset = nam->type->width;
if(nam->readonly) if(nam->readonly)
p->from.scale = RODATA; p->from.scale = RODATA;
...@@ -211,11 +211,12 @@ ggloblsym(Sym *s, int32 width, int8 flags) ...@@ -211,11 +211,12 @@ ggloblsym(Sym *s, int32 width, int8 flags)
Prog *p; Prog *p;
p = gins(AGLOBL, N, N); p = gins(AGLOBL, N, N);
p->from.type = D_EXTERN; p->from.type = TYPE_MEM;
p->from.index = D_NONE; p->from.name = NAME_EXTERN;
p->from.index = REG_NONE;
p->from.sym = linksym(s); p->from.sym = linksym(s);
p->to.type = D_CONST; p->to.type = TYPE_CONST;
p->to.index = D_NONE; p->to.index = REG_NONE;
p->to.offset = width; p->to.offset = width;
p->from.scale = flags; p->from.scale = flags;
} }
...@@ -226,8 +227,8 @@ gtrack(Sym *s) ...@@ -226,8 +227,8 @@ gtrack(Sym *s)
Prog *p; Prog *p;
p = gins(AUSEFIELD, N, N); p = gins(AUSEFIELD, N, N);
p->from.type = D_EXTERN; p->from.type = TYPE_MEM;
p->from.index = D_NONE; p->from.name = NAME_EXTERN;
p->from.sym = linksym(s); p->from.sym = linksym(s);
} }
...@@ -253,9 +254,8 @@ isfat(Type *t) ...@@ -253,9 +254,8 @@ isfat(Type *t)
void void
afunclit(Addr *a, Node *n) afunclit(Addr *a, Node *n)
{ {
if(a->type == D_ADDR && a->index == D_EXTERN) { if(a->type == TYPE_ADDR && a->name == NAME_EXTERN) {
a->type = D_EXTERN; a->type = TYPE_MEM;
a->index = D_NONE;
a->sym = linksym(n->sym); a->sym = linksym(n->sym);
} }
} }
...@@ -833,16 +833,16 @@ sse: ...@@ -833,16 +833,16 @@ sse:
static int resvd[] = static int resvd[] =
{ {
// D_DI, // for movstring // REG_DI, // for movstring
// D_SI, // for movstring // REG_SI, // for movstring
D_AX, // for divide REG_AX, // for divide
D_CX, // for shift REG_CX, // for shift
D_DX, // for divide REG_DX, // for divide
D_SP, // for stack REG_SP, // for stack
D_BL, // because D_BX can be allocated REG_BL, // because REG_BX can be allocated
D_BH, REG_BH,
}; };
void void
...@@ -852,15 +852,15 @@ ginit(void) ...@@ -852,15 +852,15 @@ ginit(void)
for(i=0; i<nelem(reg); i++) for(i=0; i<nelem(reg); i++)
reg[i] = 1; reg[i] = 1;
for(i=D_AX; i<=D_DI; i++) for(i=REG_AX; i<=REG_DI; i++)
reg[i] = 0; reg[i] = 0;
for(i=D_X0; i<=D_X7; i++) for(i=REG_X0; i<=REG_X7; i++)
reg[i] = 0; reg[i] = 0;
for(i=0; i<nelem(resvd); i++) for(i=0; i<nelem(resvd); i++)
reg[resvd[i]]++; reg[resvd[i]]++;
} }
uintptr regpc[D_NONE]; uintptr regpc[MAXREG];
void void
gclean(void) gclean(void)
...@@ -870,10 +870,10 @@ gclean(void) ...@@ -870,10 +870,10 @@ gclean(void)
for(i=0; i<nelem(resvd); i++) for(i=0; i<nelem(resvd); i++)
reg[resvd[i]]--; reg[resvd[i]]--;
for(i=D_AX; i<=D_DI; i++) for(i=REG_AX; i<=REG_DI; i++)
if(reg[i]) if(reg[i])
yyerror("reg %R left allocated at %ux", i, regpc[i]); yyerror("reg %R left allocated at %ux", i, regpc[i]);
for(i=D_X0; i<=D_X7; i++) for(i=REG_X0; i<=REG_X7; i++)
if(reg[i]) if(reg[i])
yyerror("reg %R left allocated\n", i); yyerror("reg %R left allocated\n", i);
} }
...@@ -883,7 +883,7 @@ anyregalloc(void) ...@@ -883,7 +883,7 @@ anyregalloc(void)
{ {
int i, j; int i, j;
for(i=D_AX; i<=D_DI; i++) { for(i=REG_AX; i<=REG_DI; i++) {
if(reg[i] == 0) if(reg[i] == 0)
goto ok; goto ok;
for(j=0; j<nelem(resvd); j++) for(j=0; j<nelem(resvd); j++)
...@@ -892,7 +892,7 @@ anyregalloc(void) ...@@ -892,7 +892,7 @@ anyregalloc(void)
return 1; return 1;
ok:; ok:;
} }
for(i=D_X0; i<=D_X7; i++) for(i=REG_X0; i<=REG_X7; i++)
if(reg[i]) if(reg[i])
return 1; return 1;
return 0; return 0;
...@@ -928,15 +928,15 @@ regalloc(Node *n, Type *t, Node *o) ...@@ -928,15 +928,15 @@ regalloc(Node *n, Type *t, Node *o)
case TBOOL: case TBOOL:
if(o != N && o->op == OREGISTER) { if(o != N && o->op == OREGISTER) {
i = o->val.u.reg; i = o->val.u.reg;
if(i >= D_AX && i <= D_DI) if(i >= REG_AX && i <= REG_DI)
goto out; goto out;
} }
for(i=D_AX; i<=D_DI; i++) for(i=REG_AX; i<=REG_DI; i++)
if(reg[i] == 0) if(reg[i] == 0)
goto out; goto out;
fprint(2, "registers allocated at\n"); fprint(2, "registers allocated at\n");
for(i=D_AX; i<=D_DI; i++) for(i=REG_AX; i<=REG_DI; i++)
fprint(2, "\t%R\t%#lux\n", i, regpc[i]); fprint(2, "\t%R\t%#lux\n", i, regpc[i]);
fatal("out of fixed registers"); fatal("out of fixed registers");
goto err; goto err;
...@@ -944,19 +944,19 @@ regalloc(Node *n, Type *t, Node *o) ...@@ -944,19 +944,19 @@ regalloc(Node *n, Type *t, Node *o)
case TFLOAT32: case TFLOAT32:
case TFLOAT64: case TFLOAT64:
if(!use_sse) { if(!use_sse) {
i = D_F0; i = REG_F0;
goto out; goto out;
} }
if(o != N && o->op == OREGISTER) { if(o != N && o->op == OREGISTER) {
i = o->val.u.reg; i = o->val.u.reg;
if(i >= D_X0 && i <= D_X7) if(i >= REG_X0 && i <= REG_X7)
goto out; goto out;
} }
for(i=D_X0; i<=D_X7; i++) for(i=REG_X0; i<=REG_X7; i++)
if(reg[i] == 0) if(reg[i] == 0)
goto out; goto out;
fprint(2, "registers allocated at\n"); fprint(2, "registers allocated at\n");
for(i=D_X0; i<=D_X7; i++) for(i=REG_X0; i<=REG_X7; i++)
fprint(2, "\t%R\t%#lux\n", i, regpc[i]); fprint(2, "\t%R\t%#lux\n", i, regpc[i]);
fatal("out of floating registers"); fatal("out of floating registers");
} }
...@@ -967,11 +967,11 @@ err: ...@@ -967,11 +967,11 @@ err:
return; return;
out: out:
if (i == D_SP) if(i == REG_SP)
print("alloc SP\n"); print("alloc SP\n");
if(reg[i] == 0) { if(reg[i] == 0) {
regpc[i] = (uintptr)getcallerpc(&n); regpc[i] = (uintptr)getcallerpc(&n);
if(i == D_AX || i == D_CX || i == D_DX || i == D_SP) { if(i == REG_AX || i == REG_CX || i == REG_DX || i == REG_SP) {
dump("regalloc-o", o); dump("regalloc-o", o);
fatal("regalloc %R", i); fatal("regalloc %R", i);
} }
...@@ -990,14 +990,14 @@ regfree(Node *n) ...@@ -990,14 +990,14 @@ regfree(Node *n)
if(n->op != OREGISTER && n->op != OINDREG) if(n->op != OREGISTER && n->op != OINDREG)
fatal("regfree: not a register"); fatal("regfree: not a register");
i = n->val.u.reg; i = n->val.u.reg;
if(i == D_SP) if(i == REG_SP)
return; return;
if(i < 0 || i >= nelem(reg)) if(i < 0 || i >= nelem(reg))
fatal("regfree: reg out of range"); fatal("regfree: reg out of range");
if(reg[i] <= 0) if(reg[i] <= 0)
fatal("regfree: reg not allocated"); fatal("regfree: reg not allocated");
reg[i]--; reg[i]--;
if(reg[i] == 0 && (i == D_AX || i == D_CX || i == D_DX || i == D_SP)) if(reg[i] == 0 && (i == REG_AX || i == REG_CX || i == REG_DX || i == REG_SP))
fatal("regfree %R", i); fatal("regfree %R", i);
} }
...@@ -1088,7 +1088,7 @@ nodarg(Type *t, int fp) ...@@ -1088,7 +1088,7 @@ nodarg(Type *t, int fp)
case 0: // output arg case 0: // output arg
n->op = OINDREG; n->op = OINDREG;
n->val.u.reg = D_SP; n->val.u.reg = REG_SP;
break; break;
case 1: // input arg case 1: // input arg
...@@ -1349,7 +1349,7 @@ gmove(Node *f, Node *t) ...@@ -1349,7 +1349,7 @@ gmove(Node *f, Node *t)
case CASE(TINT64, TUINT8): case CASE(TINT64, TUINT8):
case CASE(TUINT64, TUINT8): case CASE(TUINT64, TUINT8):
split64(f, &flo, &fhi); split64(f, &flo, &fhi);
nodreg(&r1, t->type, D_AX); nodreg(&r1, t->type, REG_AX);
gmove(&flo, &r1); gmove(&flo, &r1);
gins(AMOVB, &r1, t); gins(AMOVB, &r1, t);
splitclean(); splitclean();
...@@ -1374,7 +1374,7 @@ gmove(Node *f, Node *t) ...@@ -1374,7 +1374,7 @@ gmove(Node *f, Node *t)
case CASE(TINT64, TUINT16): case CASE(TINT64, TUINT16):
case CASE(TUINT64, TUINT16): case CASE(TUINT64, TUINT16):
split64(f, &flo, &fhi); split64(f, &flo, &fhi);
nodreg(&r1, t->type, D_AX); nodreg(&r1, t->type, REG_AX);
gmove(&flo, &r1); gmove(&flo, &r1);
gins(AMOVW, &r1, t); gins(AMOVW, &r1, t);
splitclean(); splitclean();
...@@ -1392,7 +1392,7 @@ gmove(Node *f, Node *t) ...@@ -1392,7 +1392,7 @@ gmove(Node *f, Node *t)
case CASE(TINT64, TUINT32): case CASE(TINT64, TUINT32):
case CASE(TUINT64, TUINT32): case CASE(TUINT64, TUINT32):
split64(f, &flo, &fhi); split64(f, &flo, &fhi);
nodreg(&r1, t->type, D_AX); nodreg(&r1, t->type, REG_AX);
gmove(&flo, &r1); gmove(&flo, &r1);
gins(AMOVL, &r1, t); gins(AMOVL, &r1, t);
splitclean(); splitclean();
...@@ -1408,8 +1408,8 @@ gmove(Node *f, Node *t) ...@@ -1408,8 +1408,8 @@ gmove(Node *f, Node *t)
gins(AMOVL, &flo, &tlo); gins(AMOVL, &flo, &tlo);
gins(AMOVL, &fhi, &thi); gins(AMOVL, &fhi, &thi);
} else { } else {
nodreg(&r1, t->type, D_AX); nodreg(&r1, t->type, REG_AX);
nodreg(&r2, t->type, D_DX); nodreg(&r2, t->type, REG_DX);
gins(AMOVL, &flo, &r1); gins(AMOVL, &flo, &r1);
gins(AMOVL, &fhi, &r2); gins(AMOVL, &fhi, &r2);
gins(AMOVL, &r1, &tlo); gins(AMOVL, &r1, &tlo);
...@@ -1469,8 +1469,8 @@ gmove(Node *f, Node *t) ...@@ -1469,8 +1469,8 @@ gmove(Node *f, Node *t)
case CASE(TINT32, TINT64): // sign extend int32 case CASE(TINT32, TINT64): // sign extend int32
case CASE(TINT32, TUINT64): case CASE(TINT32, TUINT64):
split64(t, &tlo, &thi); split64(t, &tlo, &thi);
nodreg(&flo, tlo.type, D_AX); nodreg(&flo, tlo.type, REG_AX);
nodreg(&fhi, thi.type, D_DX); nodreg(&fhi, thi.type, REG_DX);
gmove(f, &flo); gmove(f, &flo);
gins(ACDQ, N, N); gins(ACDQ, N, N);
gins(AMOVL, &flo, &tlo); gins(AMOVL, &flo, &tlo);
...@@ -1571,7 +1571,7 @@ floatmove(Node *f, Node *t) ...@@ -1571,7 +1571,7 @@ floatmove(Node *f, Node *t)
cvt = f->type; cvt = f->type;
goto hardmem; goto hardmem;
} }
nodreg(&r1, types[ft], D_F0); nodreg(&r1, types[ft], REG_F0);
if(ft == TFLOAT32) if(ft == TFLOAT32)
gins(AFMOVF, f, &r1); gins(AFMOVF, f, &r1);
else else
...@@ -1599,9 +1599,9 @@ floatmove(Node *f, Node *t) ...@@ -1599,9 +1599,9 @@ floatmove(Node *f, Node *t)
goto hardmem; goto hardmem;
} }
bignodes(); bignodes();
nodreg(&f0, types[ft], D_F0); nodreg(&f0, types[ft], REG_F0);
nodreg(&f1, types[ft], D_F0 + 1); nodreg(&f1, types[ft], REG_F0 + 1);
nodreg(&ax, types[TUINT16], D_AX); nodreg(&ax, types[TUINT16], REG_AX);
if(ft == TFLOAT32) if(ft == TFLOAT32)
gins(AFMOVF, f, &f0); gins(AFMOVF, f, &f0);
...@@ -1663,7 +1663,7 @@ floatmove(Node *f, Node *t) ...@@ -1663,7 +1663,7 @@ floatmove(Node *f, Node *t)
case CASE(TINT64, TFLOAT64): case CASE(TINT64, TFLOAT64):
if(t->op == OREGISTER) if(t->op == OREGISTER)
goto hardmem; goto hardmem;
nodreg(&f0, t->type, D_F0); nodreg(&f0, t->type, REG_F0);
gins(AFMOVV, f, &f0); gins(AFMOVV, f, &f0);
if(tt == TFLOAT32) if(tt == TFLOAT32)
gins(AFMOVFP, &f0, t); gins(AFMOVFP, &f0, t);
...@@ -1676,16 +1676,16 @@ floatmove(Node *f, Node *t) ...@@ -1676,16 +1676,16 @@ floatmove(Node *f, Node *t)
// algorithm is: // algorithm is:
// if small enough, use native int64 -> float64 conversion. // if small enough, use native int64 -> float64 conversion.
// otherwise, halve (rounding to odd?), convert, and double. // otherwise, halve (rounding to odd?), convert, and double.
nodreg(&ax, types[TUINT32], D_AX); nodreg(&ax, types[TUINT32], REG_AX);
nodreg(&dx, types[TUINT32], D_DX); nodreg(&dx, types[TUINT32], REG_DX);
nodreg(&cx, types[TUINT32], D_CX); nodreg(&cx, types[TUINT32], REG_CX);
tempname(&t1, f->type); tempname(&t1, f->type);
split64(&t1, &tlo, &thi); split64(&t1, &tlo, &thi);
gmove(f, &t1); gmove(f, &t1);
gins(ACMPL, &thi, ncon(0)); gins(ACMPL, &thi, ncon(0));
p1 = gbranch(AJLT, T, 0); p1 = gbranch(AJLT, T, 0);
// native // native
nodreg(&r1, types[tt], D_F0); nodreg(&r1, types[tt], REG_F0);
gins(AFMOVV, &t1, &r1); gins(AFMOVV, &t1, &r1);
if(tt == TFLOAT32) if(tt == TFLOAT32)
gins(AFMOVFP, &r1, t); gins(AFMOVFP, &r1, t);
...@@ -1697,7 +1697,7 @@ floatmove(Node *f, Node *t) ...@@ -1697,7 +1697,7 @@ floatmove(Node *f, Node *t)
gmove(&tlo, &ax); gmove(&tlo, &ax);
gmove(&thi, &dx); gmove(&thi, &dx);
p1 = gins(ASHRL, ncon(1), &ax); p1 = gins(ASHRL, ncon(1), &ax);
p1->from.index = D_DX; // double-width shift DX -> AX p1->from.index = REG_DX; // double-width shift DX -> AX
p1->from.scale = 0; p1->from.scale = 0;
gins(AMOVL, ncon(0), &cx); gins(AMOVL, ncon(0), &cx);
gins(ASETCC, N, &cx); gins(ASETCC, N, &cx);
...@@ -1705,8 +1705,8 @@ floatmove(Node *f, Node *t) ...@@ -1705,8 +1705,8 @@ floatmove(Node *f, Node *t)
gins(ASHRL, ncon(1), &dx); gins(ASHRL, ncon(1), &dx);
gmove(&dx, &thi); gmove(&dx, &thi);
gmove(&ax, &tlo); gmove(&ax, &tlo);
nodreg(&r1, types[tt], D_F0); nodreg(&r1, types[tt], REG_F0);
nodreg(&r2, types[tt], D_F0 + 1); nodreg(&r2, types[tt], REG_F0 + 1);
gins(AFMOVV, &t1, &r1); gins(AFMOVV, &t1, &r1);
gins(AFMOVD, &r1, &r1); gins(AFMOVD, &r1, &r1);
gins(AFADDDP, &r1, &r2); gins(AFADDDP, &r1, &r2);
...@@ -1762,7 +1762,7 @@ floatmove_387(Node *f, Node *t) ...@@ -1762,7 +1762,7 @@ floatmove_387(Node *f, Node *t)
case CASE(TFLOAT64, TINT64): case CASE(TFLOAT64, TINT64):
if(t->op == OREGISTER) if(t->op == OREGISTER)
goto hardmem; goto hardmem;
nodreg(&r1, types[ft], D_F0); nodreg(&r1, types[ft], REG_F0);
if(f->op != OREGISTER) { if(f->op != OREGISTER) {
if(ft == TFLOAT32) if(ft == TFLOAT32)
gins(AFMOVF, f, &r1); gins(AFMOVF, f, &r1);
...@@ -1890,7 +1890,7 @@ floatmove_387(Node *f, Node *t) ...@@ -1890,7 +1890,7 @@ floatmove_387(Node *f, Node *t)
if(ismem(f) && ismem(t)) if(ismem(f) && ismem(t))
goto hard; goto hard;
if(f->op == OREGISTER && t->op == OREGISTER) { if(f->op == OREGISTER && t->op == OREGISTER) {
if(f->val.u.reg != D_F0 || t->val.u.reg != D_F0) if(f->val.u.reg != REG_F0 || t->val.u.reg != REG_F0)
goto fatal; goto fatal;
return; return;
} }
...@@ -1898,7 +1898,7 @@ floatmove_387(Node *f, Node *t) ...@@ -1898,7 +1898,7 @@ floatmove_387(Node *f, Node *t)
if(ft == TFLOAT64) if(ft == TFLOAT64)
a = AFMOVD; a = AFMOVD;
if(ismem(t)) { if(ismem(t)) {
if(f->op != OREGISTER || f->val.u.reg != D_F0) if(f->op != OREGISTER || f->val.u.reg != REG_F0)
fatal("gmove %N", f); fatal("gmove %N", f);
a = AFMOVFP; a = AFMOVFP;
if(ft == TFLOAT64) if(ft == TFLOAT64)
...@@ -1910,7 +1910,7 @@ floatmove_387(Node *f, Node *t) ...@@ -1910,7 +1910,7 @@ floatmove_387(Node *f, Node *t)
if(ismem(f) && ismem(t)) if(ismem(f) && ismem(t))
goto hard; goto hard;
if(f->op == OREGISTER && t->op == OREGISTER) { if(f->op == OREGISTER && t->op == OREGISTER) {
if(f->val.u.reg != D_F0 || t->val.u.reg != D_F0) if(f->val.u.reg != REG_F0 || t->val.u.reg != REG_F0)
goto fatal; goto fatal;
return; return;
} }
...@@ -2110,7 +2110,7 @@ gins(int as, Node *f, Node *t) ...@@ -2110,7 +2110,7 @@ gins(int as, Node *f, Node *t)
fatal("gins MOVF reg, reg"); fatal("gins MOVF reg, reg");
if(as == ACVTSD2SS && f && f->op == OLITERAL) if(as == ACVTSD2SS && f && f->op == OLITERAL)
fatal("gins CVTSD2SS const"); fatal("gins CVTSD2SS const");
if(as == AMOVSD && t && t->op == OREGISTER && t->val.u.reg == D_F0) if(as == AMOVSD && t && t->op == OREGISTER && t->val.u.reg == REG_F0)
fatal("gins MOVSD into F0"); fatal("gins MOVSD into F0");
switch(as) { switch(as) {
...@@ -2159,6 +2159,8 @@ gins(int as, Node *f, Node *t) ...@@ -2159,6 +2159,8 @@ gins(int as, Node *f, Node *t)
dump("bad width to:", t); dump("bad width to:", t);
fatal("bad width: %P (%d, %d)\n", p, af.width, at.width); fatal("bad width: %P (%d, %d)\n", p, af.width, at.width);
} }
if(p->to.type == TYPE_ADDR && w > 0)
fatal("bad use of addr: %P", p);
return p; return p;
} }
...@@ -2173,8 +2175,10 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -2173,8 +2175,10 @@ naddr(Node *n, Addr *a, int canemitcode)
Sym *s; Sym *s;
a->scale = 0; a->scale = 0;
a->index = D_NONE; a->reg = REG_NONE;
a->type = D_NONE; a->index = REG_NONE;
a->type = TYPE_NONE;
a->name = NAME_NONE;
a->gotype = nil; a->gotype = nil;
a->node = N; a->node = N;
if(n == N) if(n == N)
...@@ -2186,12 +2190,14 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -2186,12 +2190,14 @@ naddr(Node *n, Addr *a, int canemitcode)
break; break;
case OREGISTER: case OREGISTER:
a->type = n->val.u.reg; a->type = TYPE_REG;
a->reg = n->val.u.reg;
a->sym = nil; a->sym = nil;
break; break;
case OINDREG: case OINDREG:
a->type = n->val.u.reg+D_INDIR; a->type = TYPE_MEM;
a->reg = n->val.u.reg;
a->sym = linksym(n->sym); a->sym = linksym(n->sym);
a->offset = n->xoffset; a->offset = n->xoffset;
break; break;
...@@ -2203,14 +2209,16 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -2203,14 +2209,16 @@ naddr(Node *n, Addr *a, int canemitcode)
a->width = n->left->type->width; a->width = n->left->type->width;
a->offset = n->xoffset; a->offset = n->xoffset;
a->sym = linksym(n->left->sym); a->sym = linksym(n->left->sym);
a->type = D_PARAM; a->type = TYPE_MEM;
a->name = NAME_PARAM;
a->node = n->left->orig; a->node = n->left->orig;
break; break;
case OCLOSUREVAR: case OCLOSUREVAR:
if(!curfn->needctxt) if(!curfn->needctxt)
fatal("closurevar without needctxt"); fatal("closurevar without needctxt");
a->type = D_DX+D_INDIR; a->type = TYPE_MEM;
a->reg = REG_DX;
a->offset = n->xoffset; a->offset = n->xoffset;
a->sym = nil; a->sym = nil;
break; break;
...@@ -2246,18 +2254,21 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -2246,18 +2254,21 @@ naddr(Node *n, Addr *a, int canemitcode)
default: default:
fatal("naddr: ONAME class %S %d\n", n->sym, n->class); fatal("naddr: ONAME class %S %d\n", n->sym, n->class);
case PEXTERN: case PEXTERN:
a->type = D_EXTERN; a->type = TYPE_MEM;
a->name = NAME_EXTERN;
break; break;
case PAUTO: case PAUTO:
a->type = D_AUTO; a->type = TYPE_MEM;
a->name = NAME_AUTO;
break; break;
case PPARAM: case PPARAM:
case PPARAMOUT: case PPARAMOUT:
a->type = D_PARAM; a->type = TYPE_MEM;
a->name = NAME_PARAM;
break; break;
case PFUNC: case PFUNC:
a->index = D_EXTERN; a->type = TYPE_ADDR;
a->type = D_ADDR; a->name = NAME_EXTERN;
s = funcsym(s); s = funcsym(s);
break; break;
} }
...@@ -2270,13 +2281,13 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -2270,13 +2281,13 @@ naddr(Node *n, Addr *a, int canemitcode)
fatal("naddr: const %lT", n->type); fatal("naddr: const %lT", n->type);
break; break;
case CTFLT: case CTFLT:
a->type = D_FCONST; a->type = TYPE_FCONST;
a->u.dval = mpgetflt(n->val.u.fval); a->u.dval = mpgetflt(n->val.u.fval);
break; break;
case CTINT: case CTINT:
case CTRUNE: case CTRUNE:
a->sym = nil; a->sym = nil;
a->type = D_CONST; a->type = TYPE_CONST;
a->offset = mpgetfix(n->val.u.xval); a->offset = mpgetfix(n->val.u.xval);
break; break;
case CTSTR: case CTSTR:
...@@ -2284,12 +2295,12 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -2284,12 +2295,12 @@ naddr(Node *n, Addr *a, int canemitcode)
break; break;
case CTBOOL: case CTBOOL:
a->sym = nil; a->sym = nil;
a->type = D_CONST; a->type = TYPE_CONST;
a->offset = n->val.u.bval; a->offset = n->val.u.bval;
break; break;
case CTNIL: case CTNIL:
a->sym = nil; a->sym = nil;
a->type = D_CONST; a->type = TYPE_CONST;
a->offset = 0; a->offset = 0;
break; break;
} }
...@@ -2297,23 +2308,15 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -2297,23 +2308,15 @@ naddr(Node *n, Addr *a, int canemitcode)
case OADDR: case OADDR:
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type >= D_INDIR) { if(a->type != TYPE_MEM)
a->type -= D_INDIR; fatal("naddr: OADDR %D", a);
break; a->type = TYPE_ADDR;
} break;
if(a->type == D_EXTERN || a->type == D_STATIC ||
a->type == D_AUTO || a->type == D_PARAM)
if(a->index == D_NONE) {
a->index = a->type;
a->type = D_ADDR;
break;
}
fatal("naddr: OADDR\n");
case OITAB: case OITAB:
// itable of interface value // itable of interface value
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0) if(a->type == TYPE_CONST && a->offset == 0)
break; // len(nil) break; // len(nil)
a->etype = tptr; a->etype = tptr;
a->width = widthptr; a->width = widthptr;
...@@ -2322,7 +2325,7 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -2322,7 +2325,7 @@ naddr(Node *n, Addr *a, int canemitcode)
case OSPTR: case OSPTR:
// pointer in a string or slice // pointer in a string or slice
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0) if(a->type == TYPE_CONST && a->offset == 0)
break; // ptr(nil) break; // ptr(nil)
a->etype = simtype[tptr]; a->etype = simtype[tptr];
a->offset += Array_array; a->offset += Array_array;
...@@ -2332,7 +2335,7 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -2332,7 +2335,7 @@ naddr(Node *n, Addr *a, int canemitcode)
case OLEN: case OLEN:
// len of string or slice // len of string or slice
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0) if(a->type == TYPE_CONST && a->offset == 0)
break; // len(nil) break; // len(nil)
a->etype = TUINT32; a->etype = TUINT32;
a->offset += Array_nel; a->offset += Array_nel;
...@@ -2342,7 +2345,7 @@ naddr(Node *n, Addr *a, int canemitcode) ...@@ -2342,7 +2345,7 @@ naddr(Node *n, Addr *a, int canemitcode)
case OCAP: case OCAP:
// cap of string or slice // cap of string or slice
naddr(n->left, a, canemitcode); naddr(n->left, a, canemitcode);
if(a->type == D_CONST && a->offset == 0) if(a->type == TYPE_CONST && a->offset == 0)
break; // cap(nil) break; // cap(nil)
a->etype = TUINT32; a->etype = TUINT32;
a->offset += Array_cap; a->offset += Array_cap;
......
...@@ -32,9 +32,6 @@ ...@@ -32,9 +32,6 @@
#define Z N #define Z N
#define Adr Addr #define Adr Addr
#define D_HI D_NONE
#define D_LO D_NONE
#define BLOAD(r) band(bnot(r->refbehind), r->refahead) #define BLOAD(r) band(bnot(r->refbehind), r->refahead)
#define BSTORE(r) band(bnot(r->calbehind), r->calahead) #define BSTORE(r) band(bnot(r->calbehind), r->calahead)
#define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z]) #define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z])
...@@ -52,8 +49,6 @@ typedef struct Rgn Rgn; ...@@ -52,8 +49,6 @@ typedef struct Rgn Rgn;
extern Node *Z; extern Node *Z;
enum enum
{ {
D_HI = D_NONE,
D_LO = D_NONE,
CLOAD = 5, CLOAD = 5,
CREF = 5, CREF = 5,
CINF = 1000, CINF = 1000,
......
...@@ -74,7 +74,7 @@ rnops(Flow *r) ...@@ -74,7 +74,7 @@ rnops(Flow *r)
if(r != nil) if(r != nil)
for(;;) { for(;;) {
p = r->prog; p = r->prog;
if(p->as != ANOP || p->from.type != D_NONE || p->to.type != D_NONE) if(p->as != ANOP || p->from.type != TYPE_NONE || p->to.type != TYPE_NONE)
break; break;
r1 = uniqs(r); r1 = uniqs(r);
if(r1 == nil) if(r1 == nil)
...@@ -110,7 +110,7 @@ peep(Prog *firstp) ...@@ -110,7 +110,7 @@ peep(Prog *firstp)
case ALEAL: case ALEAL:
if(regtyp(&p->to)) if(regtyp(&p->to))
if(p->from.sym != nil) if(p->from.sym != nil)
if(p->from.index == D_NONE || p->from.index == D_CONST) if(p->from.index == REG_NONE)
conprop(r); conprop(r);
break; break;
...@@ -120,7 +120,7 @@ peep(Prog *firstp) ...@@ -120,7 +120,7 @@ peep(Prog *firstp)
case AMOVSS: case AMOVSS:
case AMOVSD: case AMOVSD:
if(regtyp(&p->to)) if(regtyp(&p->to))
if(p->from.type == D_CONST || p->from.type == D_FCONST) if(p->from.type == TYPE_CONST || p->from.type == TYPE_FCONST)
conprop(r); conprop(r);
break; break;
} }
...@@ -158,7 +158,7 @@ loop1: ...@@ -158,7 +158,7 @@ loop1:
r1 = rnops(uniqs(r)); r1 = rnops(uniqs(r));
if(r1 != nil) { if(r1 != nil) {
p1 = r1->prog; p1 = r1->prog;
if(p->as == p1->as && p->to.type == p1->from.type){ if(p->as == p1->as && p->to.type == p1->from.type && p->to.reg == p1->from.reg){
p1->as = AMOVL; p1->as = AMOVL;
t++; t++;
} }
...@@ -168,7 +168,7 @@ loop1: ...@@ -168,7 +168,7 @@ loop1:
case AADDL: case AADDL:
case AADDW: case AADDW:
if(p->from.type != D_CONST || needc(p->link)) if(p->from.type != TYPE_CONST || needc(p->link))
break; break;
if(p->from.offset == -1){ if(p->from.offset == -1){
if(p->as == AADDL) if(p->as == AADDL)
...@@ -190,7 +190,7 @@ loop1: ...@@ -190,7 +190,7 @@ loop1:
case ASUBL: case ASUBL:
case ASUBW: case ASUBW:
if(p->from.type != D_CONST || needc(p->link)) if(p->from.type != TYPE_CONST || needc(p->link))
break; break;
if(p->from.offset == -1) { if(p->from.offset == -1) {
if(p->as == ASUBL) if(p->as == ASUBL)
...@@ -239,9 +239,7 @@ excise(Flow *r) ...@@ -239,9 +239,7 @@ excise(Flow *r)
if(debug['P'] && debug['v']) if(debug['P'] && debug['v'])
print("%P ===delete===\n", p); print("%P ===delete===\n", p);
p->as = ANOP; nopout(p);
p->from = zprog.from;
p->to = zprog.to;
ostats.ndelmov++; ostats.ndelmov++;
} }
...@@ -249,14 +247,7 @@ excise(Flow *r) ...@@ -249,14 +247,7 @@ excise(Flow *r)
int int
regtyp(Adr *a) regtyp(Adr *a)
{ {
int t; return a->type == TYPE_REG && (REG_AX <= a->reg && a->reg <= REG_DI || REG_X0 <= a->reg && a->reg <= REG_X7);
t = a->type;
if(t >= D_AX && t <= D_DI)
return 1;
if(t >= D_X0 && t <= D_X7)
return 1;
return 0;
} }
// movb elimination. // movb elimination.
...@@ -293,7 +284,7 @@ elimshortmov(Graph *g) ...@@ -293,7 +284,7 @@ elimshortmov(Graph *g)
p->as = ANOTL; p->as = ANOTL;
break; break;
} }
if(regtyp(&p->from) || p->from.type == D_CONST) { if(regtyp(&p->from) || p->from.type == TYPE_CONST) {
// move or artihmetic into partial register. // move or artihmetic into partial register.
// from another register or constant can be movl. // from another register or constant can be movl.
// we don't switch to 32-bit arithmetic if it can // we don't switch to 32-bit arithmetic if it can
...@@ -398,7 +389,7 @@ subprop(Flow *r0) ...@@ -398,7 +389,7 @@ subprop(Flow *r0)
if(info.reguse | info.regset) if(info.reguse | info.regset)
return 0; return 0;
if((info.flags & Move) && (info.flags & (SizeL|SizeQ|SizeF|SizeD)) && p->to.type == v1->type) if((info.flags & Move) && (info.flags & (SizeL|SizeQ|SizeF|SizeD)) && p->to.type == v1->type && p->to.reg == v1->reg)
goto gotit; goto gotit;
if(copyau(&p->from, v2) || copyau(&p->to, v2)) if(copyau(&p->from, v2) || copyau(&p->to, v2))
...@@ -412,7 +403,7 @@ gotit: ...@@ -412,7 +403,7 @@ gotit:
copysub(&p->to, v1, v2, 1); copysub(&p->to, v1, v2, 1);
if(debug['P']) { if(debug['P']) {
print("gotit: %D->%D\n%P", v1, v2, r->prog); print("gotit: %D->%D\n%P", v1, v2, r->prog);
if(p->from.type == v2->type) if(p->from.type == v2->type && p->from.reg == v2->reg)
print(" excise"); print(" excise");
print("\n"); print("\n");
} }
...@@ -423,9 +414,9 @@ gotit: ...@@ -423,9 +414,9 @@ gotit:
if(debug['P']) if(debug['P'])
print("%P\n", r->prog); print("%P\n", r->prog);
} }
t = v1->type; t = v1->reg;
v1->type = v2->type; v1->reg = v2->reg;
v2->type = t; v2->reg = t;
if(debug['P']) if(debug['P'])
print("%P last\n", r->prog); print("%P last\n", r->prog);
return 1; return 1;
...@@ -566,11 +557,11 @@ copyu(Prog *p, Adr *v, Adr *s) ...@@ -566,11 +557,11 @@ copyu(Prog *p, Adr *v, Adr *s)
return 3; return 3;
case ACALL: case ACALL:
if(REGEXT && v->type <= REGEXT && v->type > exregoffset) if(REGEXT && v->type == TYPE_REG && v->reg <= REGEXT && v->reg > exregoffset)
return 2; return 2;
if(REGARG >= 0 && v->type == (uchar)REGARG) if(REGARG >= 0 && v->type == TYPE_REG && v->reg == (uchar)REGARG)
return 2; return 2;
if(v->type == p->from.type) if(v->type == p->from.type && v->reg == p->from.reg)
return 2; return 2;
if(s != nil) { if(s != nil) {
...@@ -583,7 +574,7 @@ copyu(Prog *p, Adr *v, Adr *s) ...@@ -583,7 +574,7 @@ copyu(Prog *p, Adr *v, Adr *s)
return 3; return 3;
case ATEXT: case ATEXT:
if(REGARG >= 0 && v->type == (uchar)REGARG) if(REGARG >= 0 && v->type == TYPE_REG && v->reg == (uchar)REGARG)
return 3; return 3;
return 0; return 0;
} }
...@@ -592,7 +583,7 @@ copyu(Prog *p, Adr *v, Adr *s) ...@@ -592,7 +583,7 @@ copyu(Prog *p, Adr *v, Adr *s)
return 0; return 0;
proginfo(&info, p); proginfo(&info, p);
if((info.reguse|info.regset) & RtoB(v->type)) if((info.reguse|info.regset) & RtoB(v->reg))
return 2; return 2;
if(info.flags & LeftAddr) if(info.flags & LeftAddr)
...@@ -636,16 +627,16 @@ copyu(Prog *p, Adr *v, Adr *s) ...@@ -636,16 +627,16 @@ copyu(Prog *p, Adr *v, Adr *s)
static int static int
copyas(Adr *a, Adr *v) copyas(Adr *a, Adr *v)
{ {
if(D_AL <= a->type && a->type <= D_BL) if(REG_AL <= a->reg && a->reg <= REG_BL)
fatal("use of byte register"); fatal("use of byte register");
if(D_AL <= v->type && v->type <= D_BL) if(REG_AL <= v->reg && v->reg <= REG_BL)
fatal("use of byte register"); fatal("use of byte register");
if(a->type != v->type) if(a->type != v->type || a->name != v->name || a->reg != v->reg)
return 0; return 0;
if(regtyp(v)) if(regtyp(v))
return 1; return 1;
if(v->type == D_AUTO || v->type == D_PARAM) if(v->type == TYPE_MEM && (v->name == NAME_AUTO || v->name == NAME_PARAM))
if(v->offset == a->offset) if(v->offset == a->offset)
return 1; return 1;
return 0; return 0;
...@@ -654,11 +645,11 @@ copyas(Adr *a, Adr *v) ...@@ -654,11 +645,11 @@ copyas(Adr *a, Adr *v)
int int
sameaddr(Addr *a, Addr *v) sameaddr(Addr *a, Addr *v)
{ {
if(a->type != v->type) if(a->type != v->type || a->name != v->name || a->reg != v->reg)
return 0; return 0;
if(regtyp(v)) if(regtyp(v))
return 1; return 1;
if(v->type == D_AUTO || v->type == D_PARAM) if(v->type == TYPE_MEM && (v->name == NAME_AUTO || v->name == NAME_PARAM))
if(v->offset == a->offset) if(v->offset == a->offset)
return 1; return 1;
return 0; return 0;
...@@ -674,9 +665,9 @@ copyau(Adr *a, Adr *v) ...@@ -674,9 +665,9 @@ copyau(Adr *a, Adr *v)
if(copyas(a, v)) if(copyas(a, v))
return 1; return 1;
if(regtyp(v)) { if(regtyp(v)) {
if(a->type-D_INDIR == v->type) if(a->type == TYPE_MEM && a->reg == v->reg)
return 1; return 1;
if(a->index == v->type) if(a->index == v->reg)
return 1; return 1;
} }
return 0; return 0;
...@@ -689,28 +680,28 @@ copyau(Adr *a, Adr *v) ...@@ -689,28 +680,28 @@ copyau(Adr *a, Adr *v)
static int static int
copysub(Adr *a, Adr *v, Adr *s, int f) copysub(Adr *a, Adr *v, Adr *s, int f)
{ {
int t; int reg;
if(copyas(a, v)) { if(copyas(a, v)) {
t = s->type; reg = s->reg;
if(t >= D_AX && t <= D_DI || t >= D_X0 && t <= D_X7) { if(reg >= REG_AX && reg <= REG_DI || reg >= REG_X0 && reg <= REG_X7) {
if(f) if(f)
a->type = t; a->reg = reg;
} }
return 0; return 0;
} }
if(regtyp(v)) { if(regtyp(v)) {
t = v->type; reg = v->reg;
if(a->type == t+D_INDIR) { if(a->type == TYPE_MEM && a->reg == reg) {
if((s->type == D_BP) && a->index != D_NONE) if((s->reg == REG_BP) && a->index != TYPE_NONE)
return 1; /* can't use BP-base with index */ return 1; /* can't use BP-base with index */
if(f) if(f)
a->type = s->type+D_INDIR; a->reg = s->reg;
// return 0; // return 0;
} }
if(a->index == t) { if(a->index == reg) {
if(f) if(f)
a->index = s->type; a->index = s->reg;
return 0; return 0;
} }
return 0; return 0;
...@@ -751,10 +742,11 @@ loop: ...@@ -751,10 +742,11 @@ loop:
case 3: // set case 3: // set
if(p->as == p0->as) if(p->as == p0->as)
if(p->from.type == p0->from.type) if(p->from.type == p0->from.type)
if(p->from.reg == p0->from.reg)
if(p->from.node == p0->from.node) if(p->from.node == p0->from.node)
if(p->from.offset == p0->from.offset) if(p->from.offset == p0->from.offset)
if(p->from.scale == p0->from.scale) if(p->from.scale == p0->from.scale)
if(p->from.type == D_FCONST && p->from.u.dval == p0->from.u.dval) if(p->from.type == TYPE_FCONST && p->from.u.dval == p0->from.u.dval)
if(p->from.index == p0->from.index) { if(p->from.index == p0->from.index) {
excise(r); excise(r);
goto loop; goto loop;
...@@ -767,13 +759,13 @@ int ...@@ -767,13 +759,13 @@ int
smallindir(Addr *a, Addr *reg) smallindir(Addr *a, Addr *reg)
{ {
return regtyp(reg) && return regtyp(reg) &&
a->type == D_INDIR + reg->type && a->type == TYPE_MEM && a->reg == reg->reg &&
a->index == D_NONE && a->index == REG_NONE &&
0 <= a->offset && a->offset < 4096; 0 <= a->offset && a->offset < 4096;
} }
int int
stackaddr(Addr *a) stackaddr(Addr *a)
{ {
return regtyp(a) && a->type == D_SP; return a->type == TYPE_REG && a->reg == REG_SP;
} }
...@@ -8,15 +8,15 @@ ...@@ -8,15 +8,15 @@
#include "opt.h" #include "opt.h"
// Matches real RtoB but can be used in global initializer. // Matches real RtoB but can be used in global initializer.
#define RtoB(r) (1<<((r)-D_AX)) #define RtoB(r) (1<<((r)-REG_AX))
enum { enum {
AX = RtoB(D_AX), AX = RtoB(REG_AX),
BX = RtoB(D_BX), BX = RtoB(REG_BX),
CX = RtoB(D_CX), CX = RtoB(REG_CX),
DX = RtoB(D_DX), DX = RtoB(REG_DX),
DI = RtoB(D_DI), DI = RtoB(REG_DI),
SI = RtoB(D_SI), SI = RtoB(REG_SI),
LeftRdwr = LeftRead | LeftWrite, LeftRdwr = LeftRead | LeftWrite,
RightRdwr = RightRead | RightWrite, RightRdwr = RightRead | RightWrite,
...@@ -325,11 +325,11 @@ proginfo(ProgInfo *info, Prog *p) ...@@ -325,11 +325,11 @@ proginfo(ProgInfo *info, Prog *p)
if(info->flags == 0) if(info->flags == 0)
fatal("unknown instruction %P", p); fatal("unknown instruction %P", p);
if((info->flags & ShiftCX) && p->from.type != D_CONST) if((info->flags & ShiftCX) && p->from.type != TYPE_CONST)
info->reguse |= CX; info->reguse |= CX;
if(info->flags & ImulAXDX) { if(info->flags & ImulAXDX) {
if(p->to.type == D_NONE) { if(p->to.type == TYPE_NONE) {
info->reguse |= AX; info->reguse |= AX;
info->regset |= AX | DX; info->regset |= AX | DX;
} else { } else {
...@@ -338,12 +338,12 @@ proginfo(ProgInfo *info, Prog *p) ...@@ -338,12 +338,12 @@ proginfo(ProgInfo *info, Prog *p)
} }
// Addressing makes some registers used. // Addressing makes some registers used.
if(p->from.type >= D_INDIR) if(p->from.type == TYPE_MEM && p->from.name == NAME_NONE)
info->regindex |= RtoB(p->from.type-D_INDIR); info->regindex |= RtoB(p->from.reg);
if(p->from.index != D_NONE) if(p->from.index != REG_NONE)
info->regindex |= RtoB(p->from.index); info->regindex |= RtoB(p->from.index);
if(p->to.type >= D_INDIR) if(p->to.type == TYPE_MEM && p->to.name == NAME_NONE)
info->regindex |= RtoB(p->to.type-D_INDIR); info->regindex |= RtoB(p->to.reg);
if(p->to.index != D_NONE) if(p->to.index != REG_NONE)
info->regindex |= RtoB(p->to.index); info->regindex |= RtoB(p->to.index);
} }
...@@ -104,7 +104,7 @@ regopt(Prog *firstp) ...@@ -104,7 +104,7 @@ regopt(Prog *firstp)
if(first) { if(first) {
fmtinstall('Q', Qconv); fmtinstall('Q', Qconv);
exregoffset = D_DI; // no externals exregoffset = REG_DI; // no externals
first = 0; first = 0;
} }
...@@ -123,7 +123,7 @@ regopt(Prog *firstp) ...@@ -123,7 +123,7 @@ regopt(Prog *firstp)
var[i].node = regnodes[i]; var[i].node = regnodes[i];
} }
regbits = RtoB(D_SP); regbits = RtoB(REG_SP);
for(z=0; z<BITS; z++) { for(z=0; z<BITS; z++) {
externs.b[z] = 0; externs.b[z] = 0;
params.b[z] = 0; params.b[z] = 0;
...@@ -155,7 +155,7 @@ regopt(Prog *firstp) ...@@ -155,7 +155,7 @@ regopt(Prog *firstp)
proginfo(&info, p); proginfo(&info, p);
// Avoid making variables for direct-called functions. // Avoid making variables for direct-called functions.
if(p->as == ACALL && p->to.type == D_EXTERN) if(p->as == ACALL && p->to.type == TYPE_MEM && p->to.name == NAME_EXTERN)
continue; continue;
r->use1.b[0] |= info.reguse | info.regindex; r->use1.b[0] |= info.reguse | info.regindex;
...@@ -401,17 +401,17 @@ brk: ...@@ -401,17 +401,17 @@ brk:
for(p=firstp; p!=P; p=p->link) { for(p=firstp; p!=P; p=p->link) {
while(p->link != P && p->link->as == ANOP) while(p->link != P && p->link->as == ANOP)
p->link = p->link->link; p->link = p->link->link;
if(p->to.type == D_BRANCH) if(p->to.type == TYPE_BRANCH)
while(p->to.u.branch != P && p->to.u.branch->as == ANOP) while(p->to.u.branch != P && p->to.u.branch->as == ANOP)
p->to.u.branch = p->to.u.branch->link; p->to.u.branch = p->to.u.branch->link;
} }
if(!use_sse) if(!use_sse)
for(p=firstp; p!=P; p=p->link) { for(p=firstp; p!=P; p=p->link) {
if(p->from.type >= D_X0 && p->from.type <= D_X7) if(p->from.reg >= REG_X0 && p->from.reg <= REG_X7)
fatal("invalid use of %R with GO386=387: %P", p->from.type, p); fatal("invalid use of %R with GO386=387: %P", p->from.reg, p);
if(p->to.type >= D_X0 && p->to.type <= D_X7) if(p->to.reg >= REG_X0 && p->to.reg <= REG_X7)
fatal("invalid use of %R with GO386=387: %P", p->to.type, p); fatal("invalid use of %R with GO386=387: %P", p->to.reg, p);
} }
if(debug['R']) { if(debug['R']) {
...@@ -492,7 +492,8 @@ addmove(Reg *r, int bn, int rn, int f) ...@@ -492,7 +492,8 @@ addmove(Reg *r, int bn, int rn, int f)
a = &p1->to; a = &p1->to;
a->offset = v->offset; a->offset = v->offset;
a->etype = v->etype; a->etype = v->etype;
a->type = v->name; a->type = TYPE_MEM;
a->name = v->name;
a->node = v->node; a->node = v->node;
a->sym = linksym(v->node->sym); a->sym = linksym(v->node->sym);
...@@ -525,11 +526,14 @@ addmove(Reg *r, int bn, int rn, int f) ...@@ -525,11 +526,14 @@ addmove(Reg *r, int bn, int rn, int f)
break; break;
} }
p1->from.type = rn; p1->from.type = TYPE_REG;
p1->from.reg = rn;
p1->from.name = 0;
if(!f) { if(!f) {
p1->from = *a; p1->from = *a;
*a = zprog.from; *a = zprog.from;
a->type = rn; a->type = TYPE_REG;
a->reg = rn;
if(v->etype == TUINT8) if(v->etype == TUINT8)
p1->as = AMOVB; p1->as = AMOVB;
if(v->etype == TUINT16) if(v->etype == TUINT16)
...@@ -546,18 +550,16 @@ doregbits(int r) ...@@ -546,18 +550,16 @@ doregbits(int r)
uint32 b; uint32 b;
b = 0; b = 0;
if(r >= D_INDIR) if(r >= REG_AX && r <= REG_DI)
r -= D_INDIR;
if(r >= D_AX && r <= D_DI)
b |= RtoB(r); b |= RtoB(r);
else else
if(r >= D_AL && r <= D_BL) if(r >= REG_AL && r <= REG_BL)
b |= RtoB(r-D_AL+D_AX); b |= RtoB(r-REG_AL+REG_AX);
else else
if(r >= D_AH && r <= D_BH) if(r >= REG_AH && r <= REG_BH)
b |= RtoB(r-D_AH+D_AX); b |= RtoB(r-REG_AH+REG_AX);
else else
if(r >= D_X0 && r <= D_X0+7) if(r >= REG_X0 && r <= REG_X0+7)
b |= FtoB(r); b |= FtoB(r);
return b; return b;
} }
...@@ -580,7 +582,7 @@ Bits ...@@ -580,7 +582,7 @@ Bits
mkvar(Reg *r, Adr *a) mkvar(Reg *r, Adr *a)
{ {
Var *v; Var *v;
int i, t, n, et, z, w, flag, regu; int i, n, et, z, w, flag, regu;
int32 o; int32 o;
Bits bit; Bits bit;
Node *node; Node *node;
...@@ -588,36 +590,38 @@ mkvar(Reg *r, Adr *a) ...@@ -588,36 +590,38 @@ mkvar(Reg *r, Adr *a)
/* /*
* mark registers used * mark registers used
*/ */
t = a->type; if(a->type == TYPE_NONE)
if(t == D_NONE)
goto none; goto none;
if(r != R) if(r != R)
r->use1.b[0] |= doregbits(a->index); r->use1.b[0] |= doregbits(a->index);
switch(t) { switch(a->type) {
default: default:
regu = doregbits(t); regu = doregbits(a->reg);
if(regu == 0) if(regu == 0)
goto none; goto none;
bit = zbits; bit = zbits;
bit.b[0] = regu; bit.b[0] = regu;
return bit; return bit;
case D_ADDR: case TYPE_ADDR:
a->type = a->index; a->type = TYPE_MEM;
bit = mkvar(r, a); bit = mkvar(r, a);
setaddrs(bit); setaddrs(bit);
a->type = t; a->type = TYPE_ADDR;
ostats.naddr++; ostats.naddr++;
goto none; goto none;
case D_EXTERN: case TYPE_MEM:
case D_STATIC: switch(a->name) {
case D_PARAM: case NAME_EXTERN:
case D_AUTO: case NAME_STATIC:
n = t; case NAME_PARAM:
break; case NAME_AUTO:
n = a->name;
break;
}
} }
node = a->node; node = a->node;
...@@ -693,10 +697,10 @@ mkvar(Reg *r, Adr *a) ...@@ -693,10 +697,10 @@ mkvar(Reg *r, Adr *a)
node->opt = v; node->opt = v;
bit = blsh(i); bit = blsh(i);
if(n == D_EXTERN || n == D_STATIC) if(n == NAME_EXTERN || n == NAME_STATIC)
for(z=0; z<BITS; z++) for(z=0; z<BITS; z++)
externs.b[z] |= bit.b[z]; externs.b[z] |= bit.b[z];
if(n == D_PARAM) if(n == NAME_PARAM)
for(z=0; z<BITS; z++) for(z=0; z<BITS; z++)
params.b[z] |= bit.b[z]; params.b[z] |= bit.b[z];
...@@ -967,13 +971,13 @@ paint1(Reg *r, int bn) ...@@ -967,13 +971,13 @@ paint1(Reg *r, int bn)
if(r->use1.b[z] & bb) { if(r->use1.b[z] & bb) {
change += CREF * r->f.loop; change += CREF * r->f.loop;
if(p->as == AFMOVL || p->as == AFMOVW) if(p->as == AFMOVL || p->as == AFMOVW)
if(BtoR(bb) != D_F0) if(BtoR(bb) != REG_F0)
change = -CINF; change = -CINF;
} }
if((r->use2.b[z]|r->set.b[z]) & bb) { if((r->use2.b[z]|r->set.b[z]) & bb) {
change += CREF * r->f.loop; change += CREF * r->f.loop;
if(p->as == AFMOVL || p->as == AFMOVW) if(p->as == AFMOVL || p->as == AFMOVW)
if(BtoR(bb) != D_F0) if(BtoR(bb) != REG_F0)
change = -CINF; change = -CINF;
} }
} }
...@@ -981,7 +985,7 @@ paint1(Reg *r, int bn) ...@@ -981,7 +985,7 @@ paint1(Reg *r, int bn)
if(STORE(r) & r->regdiff.b[z] & bb) { if(STORE(r) & r->regdiff.b[z] & bb) {
change -= CLOAD * r->f.loop; change -= CLOAD * r->f.loop;
if(p->as == AFMOVL || p->as == AFMOVW) if(p->as == AFMOVL || p->as == AFMOVW)
if(BtoR(bb) != D_F0) if(BtoR(bb) != REG_F0)
change = -CINF; change = -CINF;
} }
...@@ -1139,7 +1143,9 @@ addreg(Adr *a, int rn) ...@@ -1139,7 +1143,9 @@ addreg(Adr *a, int rn)
a->sym = nil; a->sym = nil;
a->node = nil; a->node = nil;
a->offset = 0; a->offset = 0;
a->type = rn; a->type = TYPE_REG;
a->reg = rn;
a->name = 0;
ostats.ncvtreg++; ostats.ncvtreg++;
} }
...@@ -1148,9 +1154,9 @@ uint32 ...@@ -1148,9 +1154,9 @@ uint32
RtoB(int r) RtoB(int r)
{ {
if(r < D_AX || r > D_DI) if(r < REG_AX || r > REG_DI)
return 0; return 0;
return 1L << (r-D_AX); return 1L << (r-REG_AX);
} }
int int
...@@ -1160,15 +1166,15 @@ BtoR(uint32 b) ...@@ -1160,15 +1166,15 @@ BtoR(uint32 b)
b &= 0xffL; b &= 0xffL;
if(b == 0) if(b == 0)
return 0; return 0;
return bitno(b) + D_AX; return bitno(b) + REG_AX;
} }
uint32 uint32
FtoB(int f) FtoB(int f)
{ {
if(f < D_X0 || f > D_X7) if(f < REG_X0 || f > REG_X7)
return 0; return 0;
return 1L << (f - D_X0 + 8); return 1L << (f - REG_X0 + 8);
} }
int int
...@@ -1177,7 +1183,7 @@ BtoF(uint32 b) ...@@ -1177,7 +1183,7 @@ BtoF(uint32 b)
b &= 0xFF00L; b &= 0xFF00L;
if(b == 0) if(b == 0)
return 0; return 0;
return bitno(b) - 8 + D_X0; return bitno(b) - 8 + REG_X0;
} }
void void
......
...@@ -592,72 +592,58 @@ enum ...@@ -592,72 +592,58 @@ enum
enum enum
{ {
D_AL = 0, REG_NONE = 0,
D_CL,
D_DL, REG_AL = 0+16,
D_BL, REG_CL,
REG_DL,
D_AH = 4, REG_BL,
D_CH,
D_DH, REG_AH = 4+16,
D_BH, REG_CH,
REG_DH,
D_AX = 8, REG_BH,
D_CX,
D_DX, REG_AX = 8+16,
D_BX, REG_CX,
D_SP, REG_DX,
D_BP, REG_BX,
D_SI, REG_SP,
D_DI, REG_BP,
REG_SI,
D_F0 = 16, REG_DI,
D_F7 = D_F0 + 7,
REG_F0 = 16+16,
D_CS = 24, REG_F7 = REG_F0 + 7+16,
D_SS,
D_DS, REG_CS = 24+16,
D_ES, REG_SS,
D_FS, REG_DS,
D_GS, REG_ES,
REG_FS,
D_GDTR, /* global descriptor table register */ REG_GS,
D_IDTR, /* interrupt descriptor table register */
D_LDTR, /* local descriptor table register */ REG_GDTR, /* global descriptor table register */
D_MSW, /* machine status word */ REG_IDTR, /* interrupt descriptor table register */
D_TASK, /* task register */ REG_LDTR, /* local descriptor table register */
REG_MSW, /* machine status word */
D_CR = 35, REG_TASK, /* task register */
D_DR = 43,
D_TR = 51, REG_CR = 35+16,
REG_DR = 43+16,
D_X0 = 59, REG_TR = 51+16,
D_X1,
D_X2, REG_X0 = 59+16,
D_X3, REG_X1,
D_X4, REG_X2,
D_X5, REG_X3,
D_X6, REG_X4,
D_X7, REG_X5,
REG_X6,
REG_X7,
D_TLS = 67, REG_TLS = 67+16,
D_NONE = 68, MAXREG = 68+16,
D_BRANCH = 69,
D_EXTERN = 70,
D_STATIC = 71,
D_AUTO = 72,
D_PARAM = 73,
D_CONST = 74,
D_FCONST = 75,
D_SCONST = 76,
D_ADDR = 77,
D_INDIR, /* additive */
D_CONST2 = D_INDIR+D_INDIR,
D_LAST,
T_TYPE = 1<<0, T_TYPE = 1<<0,
T_INDEX = 1<<1, T_INDEX = 1<<1,
...@@ -669,10 +655,10 @@ enum ...@@ -669,10 +655,10 @@ enum
T_GOTYPE = 1<<7, T_GOTYPE = 1<<7,
REGARG = -1, REGARG = -1,
REGRET = D_AX, REGRET = REG_AX,
FREGRET = D_F0, FREGRET = REG_F0,
REGSP = D_SP, REGSP = REG_SP,
REGTMP = D_DI, REGTMP = REG_DI,
}; };
/* /*
......
...@@ -140,7 +140,7 @@ enum ...@@ -140,7 +140,7 @@ enum
}; };
static uchar ycover[Ymax*Ymax]; static uchar ycover[Ymax*Ymax];
static int reg[D_NONE]; static int reg[MAXREG];
static void asmins(Link *ctxt, Prog *p); static void asmins(Link *ctxt, Prog *p);
static uchar ynone[] = static uchar ynone[] =
...@@ -750,12 +750,12 @@ static Optab optab[] = ...@@ -750,12 +750,12 @@ static Optab optab[] =
{ AMULW, ydivl, Pe, {0xf7,(04)} }, { AMULW, ydivl, Pe, {0xf7,(04)} },
{ ANAME }, { ANAME },
{ ANEGB, yscond, Px, {0xf6,(03)} }, { ANEGB, yscond, Px, {0xf6,(03)} },
{ ANEGL, yscond, Px, {0xf7,(03)} }, { ANEGL, yscond, Px, {0xf7,(03)} }, // TODO(rsc): yscond is wrong here.
{ ANEGW, yscond, Pe, {0xf7,(03)} }, { ANEGW, yscond, Pe, {0xf7,(03)} }, // TODO(rsc): yscond is wrong here.
{ ANOP, ynop, Px, {0,0} }, { ANOP, ynop, Px, {0,0} },
{ ANOTB, yscond, Px, {0xf6,(02)} }, { ANOTB, yscond, Px, {0xf6,(02)} },
{ ANOTL, yscond, Px, {0xf7,(02)} }, { ANOTL, yscond, Px, {0xf7,(02)} }, // TODO(rsc): yscond is wrong here.
{ ANOTW, yscond, Pe, {0xf7,(02)} }, { ANOTW, yscond, Pe, {0xf7,(02)} }, // TODO(rsc): yscond is wrong here.
{ AORB, yxorb, Pb, {0x0c,0x80,(01),0x08,0x0a} }, { AORB, yxorb, Pb, {0x0c,0x80,(01),0x08,0x0a} },
{ AORL, yxorl, Px, {0x83,(01),0x0d,0x81,(01),0x09,0x0b} }, { AORL, yxorl, Px, {0x83,(01),0x0d,0x81,(01),0x09,0x0b} },
{ AORW, yxorl, Pe, {0x83,(01),0x0d,0x81,(01),0x09,0x0b} }, { AORW, yxorl, Pe, {0x83,(01),0x0d,0x81,(01),0x09,0x0b} },
...@@ -973,7 +973,7 @@ static Optab optab[] = ...@@ -973,7 +973,7 @@ static Optab optab[] =
{ ACMPXCHGB, yrb_mb, Pm, {0xb0} }, { ACMPXCHGB, yrb_mb, Pm, {0xb0} },
{ ACMPXCHGL, yrl_ml, Pm, {0xb1} }, { ACMPXCHGL, yrl_ml, Pm, {0xb1} },
{ ACMPXCHGW, yrl_ml, Pm, {0xb1} }, { ACMPXCHGW, yrl_ml, Pm, {0xb1} },
{ ACMPXCHG8B, yscond, Pm, {0xc7,(01)} }, { ACMPXCHG8B, yscond, Pm, {0xc7,(01)} }, // TODO(rsc): yscond is wrong here.
{ ACPUID, ynone, Pm, {0xa2} }, { ACPUID, ynone, Pm, {0xa2} },
{ ARDTSC, ynone, Pm, {0x31} }, { ARDTSC, ynone, Pm, {0x31} },
...@@ -1231,7 +1231,7 @@ span8(Link *ctxt, LSym *s) ...@@ -1231,7 +1231,7 @@ span8(Link *ctxt, LSym *s)
for(p = s->text; p != nil; p = p->link) { for(p = s->text; p != nil; p = p->link) {
n = 0; n = 0;
if(p->to.type == D_BRANCH) if(p->to.type == TYPE_BRANCH)
if(p->pcond == nil) if(p->pcond == nil)
p->pcond = p; p->pcond = p;
if((q = p->pcond) != nil) if((q = p->pcond) != nil)
...@@ -1239,7 +1239,8 @@ span8(Link *ctxt, LSym *s) ...@@ -1239,7 +1239,8 @@ span8(Link *ctxt, LSym *s)
n = 1; n = 1;
p->back = n; p->back = n;
if(p->as == AADJSP) { if(p->as == AADJSP) {
p->to.type = D_SP; p->to.type = TYPE_REG;
p->to.reg = REG_SP;
v = -p->from.offset; v = -p->from.offset;
p->from.offset = v; p->from.offset = v;
p->as = AADDL; p->as = AADDL;
...@@ -1259,7 +1260,8 @@ span8(Link *ctxt, LSym *s) ...@@ -1259,7 +1260,8 @@ span8(Link *ctxt, LSym *s)
p->back |= 1; // backward jump p->back |= 1; // backward jump
if(p->as == AADJSP) { if(p->as == AADJSP) {
p->to.type = D_SP; p->to.type = TYPE_REG;
p->to.reg = REG_SP;
v = -p->from.offset; v = -p->from.offset;
p->from.offset = v; p->from.offset = v;
p->as = AADDL; p->as = AADDL;
...@@ -1437,196 +1439,216 @@ instinit(void) ...@@ -1437,196 +1439,216 @@ instinit(void)
ycover[Ym*Ymax + Yxm] = 1; ycover[Ym*Ymax + Yxm] = 1;
ycover[Yxr*Ymax + Yxm] = 1; ycover[Yxr*Ymax + Yxm] = 1;
for(i=0; i<D_NONE; i++) { for(i=0; i<MAXREG; i++) {
reg[i] = -1; reg[i] = -1;
if(i >= D_AL && i <= D_BH) if(i >= REG_AL && i <= REG_BH)
reg[i] = (i-D_AL) & 7; reg[i] = (i-REG_AL) & 7;
if(i >= D_AX && i <= D_DI) if(i >= REG_AX && i <= REG_DI)
reg[i] = (i-D_AX) & 7; reg[i] = (i-REG_AX) & 7;
if(i >= D_F0 && i <= D_F0+7) if(i >= REG_F0 && i <= REG_F0+7)
reg[i] = (i-D_F0) & 7; reg[i] = (i-REG_F0) & 7;
if(i >= D_X0 && i <= D_X0+7) if(i >= REG_X0 && i <= REG_X0+7)
reg[i] = (i-D_X0) & 7; reg[i] = (i-REG_X0) & 7;
} }
} }
static int static int
prefixof(Link *ctxt, Addr *a) prefixof(Link *ctxt, Addr *a)
{ {
switch(a->type) { if(a->type == TYPE_MEM && a->name == NAME_NONE) {
case D_INDIR+D_CS: switch(a->reg) {
return 0x2e; case REG_CS:
case D_INDIR+D_DS: return 0x2e;
return 0x3e; case REG_DS:
case D_INDIR+D_ES: return 0x3e;
return 0x26; case REG_ES:
case D_INDIR+D_FS: return 0x26;
return 0x64; case REG_FS:
case D_INDIR+D_GS: return 0x64;
return 0x65; case REG_GS:
case D_INDIR+D_TLS: return 0x65;
// NOTE: Systems listed here should be only systems that case REG_TLS:
// support direct TLS references like 8(TLS) implemented as // NOTE: Systems listed here should be only systems that
// direct references from FS or GS. Systems that require // support direct TLS references like 8(TLS) implemented as
// the initial-exec model, where you load the TLS base into // direct references from FS or GS. Systems that require
// a register and then index from that register, do not reach // the initial-exec model, where you load the TLS base into
// this code and should not be listed. // a register and then index from that register, do not reach
switch(ctxt->headtype) { // this code and should not be listed.
default: switch(ctxt->headtype) {
sysfatal("unknown TLS base register for %s", headstr(ctxt->headtype)); default:
case Hdarwin: sysfatal("unknown TLS base register for %s", headstr(ctxt->headtype));
case Hdragonfly: case Hdarwin:
case Hfreebsd: case Hdragonfly:
case Hnetbsd: case Hfreebsd:
case Hopenbsd: case Hnetbsd:
return 0x65; // GS case Hopenbsd:
return 0x65; // GS
}
} }
} }
return 0; return 0;
} }
static int static int
oclass(Addr *a) oclass(Link *ctxt, Addr *a)
{ {
int32 v; int32 v;
if((a->type >= D_INDIR && a->type < 2*D_INDIR) || a->index != D_NONE) { // TODO(rsc): This special case is for SHRQ $3, AX:DX,
if(a->index != D_NONE && a->scale == 0) { // which encodes as SHRQ $32(DX*0), AX.
if(a->type == D_ADDR) { // Similarly SHRQ CX, AX:DX is really SHRQ CX(DX*0), AX.
switch(a->index) { // Change encoding and remove.
case D_EXTERN: if((a->type == TYPE_CONST || a->type == TYPE_REG) && a->index != REG_NONE && a->scale == 0)
case D_STATIC: return Ycol;
return Yi32;
case D_AUTO: switch(a->type) {
case D_PARAM: case TYPE_NONE:
return Yiauto; return Ynone;
}
return Yxxx; case TYPE_BRANCH:
} return Ybr;
//if(a->type == D_INDIR+D_ADDR)
// print("*Ycol\n"); case TYPE_INDIR:
// TODO(rsc): Why this is also Ycol is a mystery. Should split the two meanings.
if(a->name != NAME_NONE && a->reg == REG_NONE && a->index == REG_NONE && a->scale == 0)
return Ycol; return Ycol;
} return Yxxx;
case TYPE_MEM:
return Ym; return Ym;
case TYPE_ADDR:
switch(a->name) {
case NAME_EXTERN:
case NAME_STATIC:
return Yi32;
case NAME_AUTO:
case NAME_PARAM:
return Yiauto;
}
// DUFFZERO/DUFFCOPY encoding forgot to set a->index
// and got Yi32 in an earlier version of this code.
// Keep doing that until we fix yduff etc.
if(a->sym != nil && strncmp(a->sym->name, "runtime.duff", 12) == 0)
return Yi32;
if(a->sym != nil || a->name != NAME_NONE)
ctxt->diag("unexpected addr: %D", a);
// fall through
case TYPE_CONST:
case TYPE_TEXTSIZE:
if(a->sym != nil)
ctxt->diag("TYPE_CONST with symbol: %D", a);
v = a->offset;
if(v == 0)
return Yi0;
if(v == 1)
return Yi1;
if(v >= -128 && v <= 127)
return Yi8;
return Yi32;
}
if(a->type != TYPE_REG) {
ctxt->diag("unexpected addr1: type=%d %D", a->type, a);
return Yxxx;
} }
switch(a->type)
{ switch(a->reg) {
case D_AL: case REG_AL:
return Yal; return Yal;
case D_AX: case REG_AX:
return Yax; return Yax;
case D_CL: case REG_CL:
case D_DL: case REG_DL:
case D_BL: case REG_BL:
case D_AH: case REG_AH:
case D_CH: case REG_CH:
case D_DH: case REG_DH:
case D_BH: case REG_BH:
return Yrb; return Yrb;
case D_CX: case REG_CX:
return Ycx; return Ycx;
case D_DX: case REG_DX:
case D_BX: case REG_BX:
return Yrx; return Yrx;
case D_SP: case REG_SP:
case D_BP: case REG_BP:
case D_SI: case REG_SI:
case D_DI: case REG_DI:
return Yrl; return Yrl;
case D_F0+0: case REG_F0+0:
return Yf0; return Yf0;
case D_F0+1: case REG_F0+1:
case D_F0+2: case REG_F0+2:
case D_F0+3: case REG_F0+3:
case D_F0+4: case REG_F0+4:
case D_F0+5: case REG_F0+5:
case D_F0+6: case REG_F0+6:
case D_F0+7: case REG_F0+7:
return Yrf; return Yrf;
case D_X0+0: case REG_X0+0:
case D_X0+1: case REG_X0+1:
case D_X0+2: case REG_X0+2:
case D_X0+3: case REG_X0+3:
case D_X0+4: case REG_X0+4:
case D_X0+5: case REG_X0+5:
case D_X0+6: case REG_X0+6:
case D_X0+7: case REG_X0+7:
return Yxr; return Yxr;
case D_NONE: case REG_CS: return Ycs;
return Ynone; case REG_SS: return Yss;
case REG_DS: return Yds;
case D_CS: return Ycs; case REG_ES: return Yes;
case D_SS: return Yss; case REG_FS: return Yfs;
case D_DS: return Yds; case REG_GS: return Ygs;
case D_ES: return Yes; case REG_TLS: return Ytls;
case D_FS: return Yfs;
case D_GS: return Ygs; case REG_GDTR: return Ygdtr;
case D_TLS: return Ytls; case REG_IDTR: return Yidtr;
case REG_LDTR: return Yldtr;
case D_GDTR: return Ygdtr; case REG_MSW: return Ymsw;
case D_IDTR: return Yidtr; case REG_TASK: return Ytask;
case D_LDTR: return Yldtr;
case D_MSW: return Ymsw; case REG_CR+0: return Ycr0;
case D_TASK: return Ytask; case REG_CR+1: return Ycr1;
case REG_CR+2: return Ycr2;
case D_CR+0: return Ycr0; case REG_CR+3: return Ycr3;
case D_CR+1: return Ycr1; case REG_CR+4: return Ycr4;
case D_CR+2: return Ycr2; case REG_CR+5: return Ycr5;
case D_CR+3: return Ycr3; case REG_CR+6: return Ycr6;
case D_CR+4: return Ycr4; case REG_CR+7: return Ycr7;
case D_CR+5: return Ycr5;
case D_CR+6: return Ycr6; case REG_DR+0: return Ydr0;
case D_CR+7: return Ycr7; case REG_DR+1: return Ydr1;
case REG_DR+2: return Ydr2;
case D_DR+0: return Ydr0; case REG_DR+3: return Ydr3;
case D_DR+1: return Ydr1; case REG_DR+4: return Ydr4;
case D_DR+2: return Ydr2; case REG_DR+5: return Ydr5;
case D_DR+3: return Ydr3; case REG_DR+6: return Ydr6;
case D_DR+4: return Ydr4; case REG_DR+7: return Ydr7;
case D_DR+5: return Ydr5;
case D_DR+6: return Ydr6; case REG_TR+0: return Ytr0;
case D_DR+7: return Ydr7; case REG_TR+1: return Ytr1;
case REG_TR+2: return Ytr2;
case D_TR+0: return Ytr0; case REG_TR+3: return Ytr3;
case D_TR+1: return Ytr1; case REG_TR+4: return Ytr4;
case D_TR+2: return Ytr2; case REG_TR+5: return Ytr5;
case D_TR+3: return Ytr3; case REG_TR+6: return Ytr6;
case D_TR+4: return Ytr4; case REG_TR+7: return Ytr7;
case D_TR+5: return Ytr5;
case D_TR+6: return Ytr6;
case D_TR+7: return Ytr7;
case D_EXTERN:
case D_STATIC:
case D_AUTO:
case D_PARAM:
return Ym;
case D_CONST:
case D_CONST2:
case D_ADDR:
if(a->sym == nil) {
v = a->offset;
if(v == 0)
return Yi0;
if(v == 1)
return Yi1;
if(v >= -128 && v <= 127)
return Yi8;
}
return Yi32;
case D_BRANCH:
return Ybr;
} }
return Yxxx; return Yxxx;
} }
...@@ -1640,17 +1662,17 @@ asmidx(Link *ctxt, int scale, int index, int base) ...@@ -1640,17 +1662,17 @@ asmidx(Link *ctxt, int scale, int index, int base)
default: default:
goto bad; goto bad;
case D_NONE: case TYPE_NONE:
i = 4 << 3; i = 4 << 3;
goto bas; goto bas;
case D_AX: case REG_AX:
case D_CX: case REG_CX:
case D_DX: case REG_DX:
case D_BX: case REG_BX:
case D_BP: case REG_BP:
case D_SI: case REG_SI:
case D_DI: case REG_DI:
i = reg[index] << 3; i = reg[index] << 3;
break; break;
} }
...@@ -1673,17 +1695,17 @@ bas: ...@@ -1673,17 +1695,17 @@ bas:
switch(base) { switch(base) {
default: default:
goto bad; goto bad;
case D_NONE: /* must be mod=00 */ case REG_NONE: /* must be mod=00 */
i |= 5; i |= 5;
break; break;
case D_AX: case REG_AX:
case D_CX: case REG_CX:
case D_DX: case REG_DX:
case D_BX: case REG_BX:
case D_SP: case REG_SP:
case D_BP: case REG_BP:
case D_SI: case REG_SI:
case D_DI: case REG_DI:
i |= reg[base]; i |= reg[base];
break; break;
} }
...@@ -1725,8 +1747,6 @@ relput4(Link *ctxt, Prog *p, Addr *a) ...@@ -1725,8 +1747,6 @@ relput4(Link *ctxt, Prog *p, Addr *a)
static int32 static int32
vaddr(Link *ctxt, Prog *p, Addr *a, Reloc *r) vaddr(Link *ctxt, Prog *p, Addr *a, Reloc *r)
{ {
int t;
int32 v;
LSym *s; LSym *s;
USED(p); USED(p);
...@@ -1734,13 +1754,9 @@ vaddr(Link *ctxt, Prog *p, Addr *a, Reloc *r) ...@@ -1734,13 +1754,9 @@ vaddr(Link *ctxt, Prog *p, Addr *a, Reloc *r)
if(r != nil) if(r != nil)
memset(r, 0, sizeof *r); memset(r, 0, sizeof *r);
t = a->type; switch(a->name) {
v = a->offset; case NAME_STATIC:
if(t == D_ADDR) case NAME_EXTERN:
t = a->index;
switch(t) {
case D_STATIC:
case D_EXTERN:
s = a->sym; s = a->sym;
if(s != nil) { if(s != nil) {
if(r == nil) { if(r == nil) {
...@@ -1751,12 +1767,13 @@ vaddr(Link *ctxt, Prog *p, Addr *a, Reloc *r) ...@@ -1751,12 +1767,13 @@ vaddr(Link *ctxt, Prog *p, Addr *a, Reloc *r)
r->siz = 4; r->siz = 4;
r->off = -1; r->off = -1;
r->sym = s; r->sym = s;
r->add = v; r->add = a->offset;
v = 0; return 0;
} }
break; return a->offset;
}
case D_INDIR+D_TLS: if((a->type == TYPE_MEM || a->type == TYPE_ADDR) && a->reg == REG_TLS) {
if(r == nil) { if(r == nil) {
ctxt->diag("need reloc for %D", a); ctxt->diag("need reloc for %D", a);
sysfatal("bad code"); sysfatal("bad code");
...@@ -1764,113 +1781,120 @@ vaddr(Link *ctxt, Prog *p, Addr *a, Reloc *r) ...@@ -1764,113 +1781,120 @@ vaddr(Link *ctxt, Prog *p, Addr *a, Reloc *r)
r->type = R_TLS_LE; r->type = R_TLS_LE;
r->siz = 4; r->siz = 4;
r->off = -1; // caller must fill in r->off = -1; // caller must fill in
r->add = v; r->add = a->offset;
v = 0; return 0;
break;
} }
return v;
return a->offset;
} }
static void static void
asmand(Link *ctxt, Prog *p, Addr *a, int r) asmand(Link *ctxt, Prog *p, Addr *a, int r)
{ {
int32 v; int32 v;
int t, scale; int base;
Reloc rel; Reloc rel;
USED(p); USED(p);
v = a->offset; v = a->offset;
t = a->type;
rel.siz = 0; rel.siz = 0;
if(a->index != D_NONE && a->index != D_TLS) {
if(t < D_INDIR || t >= 2*D_INDIR) {
switch(t) {
default:
goto bad;
case D_STATIC:
case D_EXTERN:
t = D_NONE;
v = vaddr(ctxt, p, a, &rel);
break;
case D_AUTO:
case D_PARAM:
t = D_SP;
break;
}
} else
t -= D_INDIR;
if(t == D_NONE) { switch(a->type) {
case TYPE_ADDR:
if(a->name == NAME_NONE)
ctxt->diag("unexpected TYPE_ADDR with NAME_NONE");
if(a->index == REG_TLS)
ctxt->diag("unexpected TYPE_ADDR with index==REG_TLS");
goto bad;
case TYPE_REG:
if((a->reg < REG_AL || REG_F7 < a->reg) && (a->reg < REG_X0 || REG_X0+7 < a->reg))
goto bad;
if(v)
goto bad;
*ctxt->andptr++ = (3 << 6) | (reg[a->reg] << 0) | (r << 3);
return;
}
if(a->type != TYPE_MEM)
goto bad;
if(a->index != REG_NONE && a->index != REG_TLS) {
base = a->reg;
switch(a->name) {
case NAME_EXTERN:
case NAME_STATIC:
base = REG_NONE;
v = vaddr(ctxt, p, a, &rel);
break;
case NAME_AUTO:
case NAME_PARAM:
base = REG_SP;
break;
}
if(base == REG_NONE) {
*ctxt->andptr++ = (0 << 6) | (4 << 0) | (r << 3); *ctxt->andptr++ = (0 << 6) | (4 << 0) | (r << 3);
asmidx(ctxt, a->scale, a->index, t); asmidx(ctxt, a->scale, a->index, base);
goto putrelv; goto putrelv;
} }
if(v == 0 && rel.siz == 0 && t != D_BP) { if(v == 0 && rel.siz == 0 && base != REG_BP) {
*ctxt->andptr++ = (0 << 6) | (4 << 0) | (r << 3); *ctxt->andptr++ = (0 << 6) | (4 << 0) | (r << 3);
asmidx(ctxt, a->scale, a->index, t); asmidx(ctxt, a->scale, a->index, base);
return; return;
} }
if(v >= -128 && v < 128 && rel.siz == 0) { if(v >= -128 && v < 128 && rel.siz == 0) {
*ctxt->andptr++ = (1 << 6) | (4 << 0) | (r << 3); *ctxt->andptr++ = (1 << 6) | (4 << 0) | (r << 3);
asmidx(ctxt, a->scale, a->index, t); asmidx(ctxt, a->scale, a->index, base);
*ctxt->andptr++ = v; *ctxt->andptr++ = v;
return; return;
} }
*ctxt->andptr++ = (2 << 6) | (4 << 0) | (r << 3); *ctxt->andptr++ = (2 << 6) | (4 << 0) | (r << 3);
asmidx(ctxt, a->scale, a->index, t); asmidx(ctxt, a->scale, a->index, base);
goto putrelv; goto putrelv;
} }
if(t >= D_AL && t <= D_F7 || t >= D_X0 && t <= D_X7) {
if(v) base = a->reg;
goto bad; switch(a->name) {
*ctxt->andptr++ = (3 << 6) | (reg[t] << 0) | (r << 3); case NAME_STATIC:
return; case NAME_EXTERN:
base = REG_NONE;
v = vaddr(ctxt, p, a, &rel);
break;
case NAME_AUTO:
case NAME_PARAM:
base = REG_SP;
break;
} }
scale = a->scale; if(base == REG_TLS)
if(t < D_INDIR || t >= 2*D_INDIR) {
switch(a->type) {
default:
goto bad;
case D_STATIC:
case D_EXTERN:
t = D_NONE;
v = vaddr(ctxt, p, a, &rel);
break;
case D_AUTO:
case D_PARAM:
t = D_SP;
break;
}
scale = 1;
} else
t -= D_INDIR;
if(t == D_TLS)
v = vaddr(ctxt, p, a, &rel); v = vaddr(ctxt, p, a, &rel);
if(t == D_NONE || (D_CS <= t && t <= D_GS) || t == D_TLS) { if(base == REG_NONE || (REG_CS <= base && base <= REG_GS) || base == REG_TLS) {
*ctxt->andptr++ = (0 << 6) | (5 << 0) | (r << 3); *ctxt->andptr++ = (0 << 6) | (5 << 0) | (r << 3);
goto putrelv; goto putrelv;
} }
if(t == D_SP) {
if(base == REG_SP) {
if(v == 0 && rel.siz == 0) { if(v == 0 && rel.siz == 0) {
*ctxt->andptr++ = (0 << 6) | (4 << 0) | (r << 3); *ctxt->andptr++ = (0 << 6) | (4 << 0) | (r << 3);
asmidx(ctxt, scale, D_NONE, t); asmidx(ctxt, a->scale, REG_NONE, base);
return; return;
} }
if(v >= -128 && v < 128 && rel.siz == 0) { if(v >= -128 && v < 128 && rel.siz == 0) {
*ctxt->andptr++ = (1 << 6) | (4 << 0) | (r << 3); *ctxt->andptr++ = (1 << 6) | (4 << 0) | (r << 3);
asmidx(ctxt, scale, D_NONE, t); asmidx(ctxt, a->scale, REG_NONE, base);
*ctxt->andptr++ = v; *ctxt->andptr++ = v;
return; return;
} }
*ctxt->andptr++ = (2 << 6) | (4 << 0) | (r << 3); *ctxt->andptr++ = (2 << 6) | (4 << 0) | (r << 3);
asmidx(ctxt, scale, D_NONE, t); asmidx(ctxt, a->scale, REG_NONE, base);
goto putrelv; goto putrelv;
} }
if(t >= D_AX && t <= D_DI) {
if(a->index == D_TLS) { if(REG_AX <= base && base <= REG_DI) {
if(a->index == REG_TLS) {
memset(&rel, 0, sizeof rel); memset(&rel, 0, sizeof rel);
rel.type = R_TLS_IE; rel.type = R_TLS_IE;
rel.siz = 4; rel.siz = 4;
...@@ -1878,17 +1902,17 @@ asmand(Link *ctxt, Prog *p, Addr *a, int r) ...@@ -1878,17 +1902,17 @@ asmand(Link *ctxt, Prog *p, Addr *a, int r)
rel.add = v; rel.add = v;
v = 0; v = 0;
} }
if(v == 0 && rel.siz == 0 && t != D_BP) { if(v == 0 && rel.siz == 0 && base != REG_BP) {
*ctxt->andptr++ = (0 << 6) | (reg[t] << 0) | (r << 3); *ctxt->andptr++ = (0 << 6) | (reg[base] << 0) | (r << 3);
return; return;
} }
if(v >= -128 && v < 128 && rel.siz == 0) { if(v >= -128 && v < 128 && rel.siz == 0) {
ctxt->andptr[0] = (1 << 6) | (reg[t] << 0) | (r << 3); ctxt->andptr[0] = (1 << 6) | (reg[base] << 0) | (r << 3);
ctxt->andptr[1] = v; ctxt->andptr[1] = v;
ctxt->andptr += 2; ctxt->andptr += 2;
return; return;
} }
*ctxt->andptr++ = (2 << 6) | (reg[t] << 0) | (r << 3); *ctxt->andptr++ = (2 << 6) | (reg[base] << 0) | (r << 3);
goto putrelv; goto putrelv;
} }
goto bad; goto bad;
...@@ -2028,7 +2052,7 @@ static uchar ymovtab[] = ...@@ -2028,7 +2052,7 @@ static uchar ymovtab[] =
}; };
// byteswapreg returns a byte-addressable register (AX, BX, CX, DX) // byteswapreg returns a byte-addressable register (AX, BX, CX, DX)
// which is not referenced in a->type. // which is not referenced in a.
// If a is empty, it returns BX to account for MULB-like instructions // If a is empty, it returns BX to account for MULB-like instructions
// that might use DX and AX. // that might use DX and AX.
static int static int
...@@ -2038,57 +2062,60 @@ byteswapreg(Link *ctxt, Addr *a) ...@@ -2038,57 +2062,60 @@ byteswapreg(Link *ctxt, Addr *a)
cana = canb = canc = cand = 1; cana = canb = canc = cand = 1;
switch(a->type) { if(a->type == TYPE_NONE)
case D_NONE:
cana = cand = 0; cana = cand = 0;
break;
case D_AX: if(a->type == TYPE_REG || ((a->type == TYPE_MEM || a->type == TYPE_ADDR) && a->name == NAME_NONE)) {
case D_AL: switch(a->reg) {
case D_AH: case REG_NONE:
case D_INDIR+D_AX: cana = cand = 0;
cana = 0; break;
break; case REG_AX:
case D_BX: case REG_AL:
case D_BL: case REG_AH:
case D_BH: cana = 0;
case D_INDIR+D_BX: break;
canb = 0; case REG_BX:
break; case REG_BL:
case D_CX: case REG_BH:
case D_CL: canb = 0;
case D_CH: break;
case D_INDIR+D_CX: case REG_CX:
canc = 0; case REG_CL:
break; case REG_CH:
case D_DX: canc = 0;
case D_DL: break;
case D_DH: case REG_DX:
case D_INDIR+D_DX: case REG_DL:
cand = 0; case REG_DH:
break; cand = 0;
break;
}
} }
switch(a->index) { if(a->type == TYPE_MEM || a->type == TYPE_ADDR) {
case D_AX: switch(a->index) {
cana = 0; case REG_AX:
break; cana = 0;
case D_BX: break;
canb = 0; case REG_BX:
break; canb = 0;
case D_CX: break;
canc = 0; case REG_CX:
break; canc = 0;
case D_DX: break;
cand = 0; case REG_DX:
break; cand = 0;
break;
}
} }
if(cana) if(cana)
return D_AX; return REG_AX;
if(canb) if(canb)
return D_BX; return REG_BX;
if(canc) if(canc)
return D_CX; return REG_CX;
if(cand) if(cand)
return D_DX; return REG_DX;
ctxt->diag("impossible byte register"); ctxt->diag("impossible byte register");
sysfatal("bad code"); sysfatal("bad code");
...@@ -2098,16 +2125,15 @@ byteswapreg(Link *ctxt, Addr *a) ...@@ -2098,16 +2125,15 @@ byteswapreg(Link *ctxt, Addr *a)
static void static void
subreg(Prog *p, int from, int to) subreg(Prog *p, int from, int to)
{ {
if(0 /* debug['Q'] */) if(0 /* debug['Q'] */)
print("\n%P s/%R/%R/\n", p, from, to); print("\n%P s/%R/%R/\n", p, from, to);
if(p->from.type == from) { if(p->from.reg == from) {
p->from.type = to; p->from.reg = to;
p->ft = 0; p->ft = 0;
} }
if(p->to.type == from) { if(p->to.reg == from) {
p->to.type = to; p->to.reg = to;
p->tt = 0; p->tt = 0;
} }
...@@ -2120,16 +2146,6 @@ subreg(Prog *p, int from, int to) ...@@ -2120,16 +2146,6 @@ subreg(Prog *p, int from, int to)
p->tt = 0; p->tt = 0;
} }
from += D_INDIR;
if(p->from.type == from) {
p->from.type = to+D_INDIR;
p->ft = 0;
}
if(p->to.type == from) {
p->to.type = to+D_INDIR;
p->tt = 0;
}
if(0 /* debug['Q'] */) if(0 /* debug['Q'] */)
print("%P\n", p); print("%P\n", p);
} }
...@@ -2179,9 +2195,9 @@ doasm(Link *ctxt, Prog *p) ...@@ -2179,9 +2195,9 @@ doasm(Link *ctxt, Prog *p)
*ctxt->andptr++ = pre; *ctxt->andptr++ = pre;
if(p->ft == 0) if(p->ft == 0)
p->ft = oclass(&p->from); p->ft = oclass(ctxt, &p->from);
if(p->tt == 0) if(p->tt == 0)
p->tt = oclass(&p->to); p->tt = oclass(ctxt, &p->to);
ft = p->ft * Ymax; ft = p->ft * Ymax;
tt = p->tt * Ymax; tt = p->tt * Ymax;
...@@ -2239,48 +2255,46 @@ found: ...@@ -2239,48 +2255,46 @@ found:
case Zlitm_r: case Zlitm_r:
for(; op = o->op[z]; z++) for(; op = o->op[z]; z++)
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, p, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.reg]);
break; break;
case Zm_r: case Zm_r:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, p, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.reg]);
break; break;
case Zm2_r: case Zm2_r:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
*ctxt->andptr++ = o->op[z+1]; *ctxt->andptr++ = o->op[z+1];
asmand(ctxt, p, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.reg]);
break; break;
case Zm_r_xm: case Zm_r_xm:
mediaop(ctxt, o, op, t[3], z); mediaop(ctxt, o, op, t[3], z);
asmand(ctxt, p, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.reg]);
break; break;
case Zm_r_i_xm: case Zm_r_i_xm:
mediaop(ctxt, o, op, t[3], z); mediaop(ctxt, o, op, t[3], z);
asmand(ctxt, p, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.reg]);
*ctxt->andptr++ = p->to.offset; *ctxt->andptr++ = p->to.offset;
break; break;
case Zibm_r: case Zibm_r:
while ((op = o->op[z++]) != 0) while ((op = o->op[z++]) != 0)
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, p, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.reg]);
*ctxt->andptr++ = p->to.offset; *ctxt->andptr++ = p->to.offset;
break; break;
case Zaut_r: case Zaut_r:
*ctxt->andptr++ = 0x8d; /* leal */ *ctxt->andptr++ = 0x8d; /* leal */
if(p->from.type != D_ADDR) if(p->from.type != TYPE_ADDR)
ctxt->diag("asmins: Zaut sb type ADDR"); ctxt->diag("asmins: Zaut sb type ADDR");
p->from.type = p->from.index; p->from.type = TYPE_MEM;
p->from.index = D_NONE;
p->ft = 0; p->ft = 0;
asmand(ctxt, p, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.reg]);
p->from.index = p->from.type; p->from.type = TYPE_ADDR;
p->from.type = D_ADDR;
p->ft = 0; p->ft = 0;
break; break;
...@@ -2291,17 +2305,17 @@ found: ...@@ -2291,17 +2305,17 @@ found:
case Zr_m: case Zr_m:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, p, &p->to, reg[p->from.type]); asmand(ctxt, p, &p->to, reg[p->from.reg]);
break; break;
case Zr_m_xm: case Zr_m_xm:
mediaop(ctxt, o, op, t[3], z); mediaop(ctxt, o, op, t[3], z);
asmand(ctxt, p, &p->to, reg[p->from.type]); asmand(ctxt, p, &p->to, reg[p->from.reg]);
break; break;
case Zr_m_i_xm: case Zr_m_i_xm:
mediaop(ctxt, o, op, t[3], z); mediaop(ctxt, o, op, t[3], z);
asmand(ctxt, p, &p->to, reg[p->from.type]); asmand(ctxt, p, &p->to, reg[p->from.reg]);
*ctxt->andptr++ = p->from.offset; *ctxt->andptr++ = p->from.offset;
break; break;
...@@ -2340,12 +2354,12 @@ found: ...@@ -2340,12 +2354,12 @@ found:
break; break;
case Zib_rp: case Zib_rp:
*ctxt->andptr++ = op + reg[p->to.type]; *ctxt->andptr++ = op + reg[p->to.reg];
*ctxt->andptr++ = vaddr(ctxt, p, &p->from, nil); *ctxt->andptr++ = vaddr(ctxt, p, &p->from, nil);
break; break;
case Zil_rp: case Zil_rp:
*ctxt->andptr++ = op + reg[p->to.type]; *ctxt->andptr++ = op + reg[p->to.reg];
if(o->prefix == Pe) { if(o->prefix == Pe) {
v = vaddr(ctxt, p, &p->from, nil); v = vaddr(ctxt, p, &p->from, nil);
*ctxt->andptr++ = v; *ctxt->andptr++ = v;
...@@ -2357,7 +2371,7 @@ found: ...@@ -2357,7 +2371,7 @@ found:
case Zib_rr: case Zib_rr:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, p, &p->to, reg[p->to.type]); asmand(ctxt, p, &p->to, reg[p->to.reg]);
*ctxt->andptr++ = vaddr(ctxt, p, &p->from, nil); *ctxt->andptr++ = vaddr(ctxt, p, &p->from, nil);
break; break;
...@@ -2398,7 +2412,7 @@ found: ...@@ -2398,7 +2412,7 @@ found:
case Zil_rr: case Zil_rr:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, p, &p->to, reg[p->to.type]); asmand(ctxt, p, &p->to, reg[p->to.reg]);
if(o->prefix == Pe) { if(o->prefix == Pe) {
v = vaddr(ctxt, p, &p->from, nil); v = vaddr(ctxt, p, &p->from, nil);
*ctxt->andptr++ = v; *ctxt->andptr++ = v;
...@@ -2409,16 +2423,16 @@ found: ...@@ -2409,16 +2423,16 @@ found:
break; break;
case Z_rp: case Z_rp:
*ctxt->andptr++ = op + reg[p->to.type]; *ctxt->andptr++ = op + reg[p->to.reg];
break; break;
case Zrp_: case Zrp_:
*ctxt->andptr++ = op + reg[p->from.type]; *ctxt->andptr++ = op + reg[p->from.reg];
break; break;
case Zclr: case Zclr:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, p, &p->to, reg[p->to.type]); asmand(ctxt, p, &p->to, reg[p->to.reg]);
break; break;
case Zcall: case Zcall:
...@@ -2570,9 +2584,9 @@ bad: ...@@ -2570,9 +2584,9 @@ bad:
* instruction with the operands renamed. * instruction with the operands renamed.
*/ */
pp = *p; pp = *p;
z = p->from.type; z = p->from.reg;
if(z >= D_BP && z <= D_DI) { if(p->from.type == TYPE_REG && z >= REG_BP && z <= REG_DI) {
if((breg = byteswapreg(ctxt, &p->to)) != D_AX) { if((breg = byteswapreg(ctxt, &p->to)) != REG_AX) {
*ctxt->andptr++ = 0x87; /* xchg lhs,bx */ *ctxt->andptr++ = 0x87; /* xchg lhs,bx */
asmand(ctxt, p, &p->from, reg[breg]); asmand(ctxt, p, &p->from, reg[breg]);
subreg(&pp, z, breg); subreg(&pp, z, breg);
...@@ -2581,15 +2595,15 @@ bad: ...@@ -2581,15 +2595,15 @@ bad:
asmand(ctxt, p, &p->from, reg[breg]); asmand(ctxt, p, &p->from, reg[breg]);
} else { } else {
*ctxt->andptr++ = 0x90 + reg[z]; /* xchg lsh,ax */ *ctxt->andptr++ = 0x90 + reg[z]; /* xchg lsh,ax */
subreg(&pp, z, D_AX); subreg(&pp, z, REG_AX);
doasm(ctxt, &pp); doasm(ctxt, &pp);
*ctxt->andptr++ = 0x90 + reg[z]; /* xchg lsh,ax */ *ctxt->andptr++ = 0x90 + reg[z]; /* xchg lsh,ax */
} }
return; return;
} }
z = p->to.type; z = p->to.reg;
if(z >= D_BP && z <= D_DI) { if(p->to.type == TYPE_REG && z >= REG_BP && z <= REG_DI) {
if((breg = byteswapreg(ctxt, &p->from)) != D_AX) { if((breg = byteswapreg(ctxt, &p->from)) != REG_AX) {
*ctxt->andptr++ = 0x87; /* xchg rhs,bx */ *ctxt->andptr++ = 0x87; /* xchg rhs,bx */
asmand(ctxt, p, &p->to, reg[breg]); asmand(ctxt, p, &p->to, reg[breg]);
subreg(&pp, z, breg); subreg(&pp, z, breg);
...@@ -2598,13 +2612,13 @@ bad: ...@@ -2598,13 +2612,13 @@ bad:
asmand(ctxt, p, &p->to, reg[breg]); asmand(ctxt, p, &p->to, reg[breg]);
} else { } else {
*ctxt->andptr++ = 0x90 + reg[z]; /* xchg rsh,ax */ *ctxt->andptr++ = 0x90 + reg[z]; /* xchg rsh,ax */
subreg(&pp, z, D_AX); subreg(&pp, z, REG_AX);
doasm(ctxt, &pp); doasm(ctxt, &pp);
*ctxt->andptr++ = 0x90 + reg[z]; /* xchg rsh,ax */ *ctxt->andptr++ = 0x90 + reg[z]; /* xchg rsh,ax */
} }
return; return;
} }
ctxt->diag("doasm: notfound t2=%ux from=%ux to=%ux %P", t[2], p->from.type, p->to.type, p); ctxt->diag("doasm: notfound t2=%d from=%d to=%d %P", t[2], p->ft, p->tt, p);
return; return;
mfound: mfound:
...@@ -2646,44 +2660,51 @@ mfound: ...@@ -2646,44 +2660,51 @@ mfound:
switch(p->to.index) { switch(p->to.index) {
default: default:
goto bad; goto bad;
case D_DS: case REG_DS:
*ctxt->andptr++ = 0xc5; *ctxt->andptr++ = 0xc5;
break; break;
case D_SS: case REG_SS:
*ctxt->andptr++ = 0x0f; *ctxt->andptr++ = 0x0f;
*ctxt->andptr++ = 0xb2; *ctxt->andptr++ = 0xb2;
break; break;
case D_ES: case REG_ES:
*ctxt->andptr++ = 0xc4; *ctxt->andptr++ = 0xc4;
break; break;
case D_FS: case REG_FS:
*ctxt->andptr++ = 0x0f; *ctxt->andptr++ = 0x0f;
*ctxt->andptr++ = 0xb4; *ctxt->andptr++ = 0xb4;
break; break;
case D_GS: case REG_GS:
*ctxt->andptr++ = 0x0f; *ctxt->andptr++ = 0x0f;
*ctxt->andptr++ = 0xb5; *ctxt->andptr++ = 0xb5;
break; break;
} }
asmand(ctxt, p, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.reg]);
break; break;
case 6: /* double shift */ case 6: /* double shift */
z = p->from.type; switch(p->from.type) {
switch(z) {
default: default:
goto bad; goto bad;
case D_CONST:
case TYPE_CONST:
*ctxt->andptr++ = 0x0f; *ctxt->andptr++ = 0x0f;
*ctxt->andptr++ = t[4]; *ctxt->andptr++ = t[4];
asmand(ctxt, p, &p->to, reg[p->from.index]); asmand(ctxt, p, &p->to, reg[p->from.index]);
*ctxt->andptr++ = p->from.offset; *ctxt->andptr++ = p->from.offset;
break; break;
case D_CL:
case D_CX: case TYPE_REG:
*ctxt->andptr++ = 0x0f; switch(p->from.reg) {
*ctxt->andptr++ = t[5]; default:
asmand(ctxt, p, &p->to, reg[p->from.index]); goto bad;
case REG_CL:
case REG_CX:
*ctxt->andptr++ = 0x0f;
*ctxt->andptr++ = t[5];
asmand(ctxt, p, &p->to, reg[p->from.index]);
break;
}
break; break;
} }
break; break;
...@@ -2695,7 +2716,7 @@ mfound: ...@@ -2695,7 +2716,7 @@ mfound:
} else } else
*ctxt->andptr++ = t[4]; *ctxt->andptr++ = t[4];
*ctxt->andptr++ = t[5]; *ctxt->andptr++ = t[5];
asmand(ctxt, p, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.reg]);
break; break;
case 8: /* mov tls, r */ case 8: /* mov tls, r */
...@@ -2711,37 +2732,40 @@ mfound: ...@@ -2711,37 +2732,40 @@ mfound:
case Hnacl: case Hnacl:
// ELF TLS base is 0(GS). // ELF TLS base is 0(GS).
pp.from = p->from; pp.from = p->from;
pp.from.type = D_INDIR+D_GS; pp.from.type = TYPE_MEM;
pp.from.reg = REG_GS;
pp.from.offset = 0; pp.from.offset = 0;
pp.from.index = D_NONE; pp.from.index = REG_NONE;
pp.from.scale = 0; pp.from.scale = 0;
*ctxt->andptr++ = 0x65; // GS *ctxt->andptr++ = 0x65; // GS
*ctxt->andptr++ = 0x8B; *ctxt->andptr++ = 0x8B;
asmand(ctxt, p, &pp.from, reg[p->to.type]); asmand(ctxt, p, &pp.from, reg[p->to.reg]);
break; break;
case Hplan9: case Hplan9:
if(ctxt->plan9privates == nil) if(ctxt->plan9privates == nil)
ctxt->plan9privates = linklookup(ctxt, "_privates", 0); ctxt->plan9privates = linklookup(ctxt, "_privates", 0);
memset(&pp.from, 0, sizeof pp.from); memset(&pp.from, 0, sizeof pp.from);
pp.from.type = D_EXTERN; pp.from.type = TYPE_MEM;
pp.from.name = NAME_EXTERN;
pp.from.sym = ctxt->plan9privates; pp.from.sym = ctxt->plan9privates;
pp.from.offset = 0; pp.from.offset = 0;
pp.from.index = D_NONE; pp.from.index = REG_NONE;
*ctxt->andptr++ = 0x8B; *ctxt->andptr++ = 0x8B;
asmand(ctxt, p, &pp.from, reg[p->to.type]); asmand(ctxt, p, &pp.from, reg[p->to.reg]);
break; break;
case Hwindows: case Hwindows:
// Windows TLS base is always 0x14(FS). // Windows TLS base is always 0x14(FS).
pp.from = p->from; pp.from = p->from;
pp.from.type = D_INDIR+D_FS; pp.from.type = TYPE_MEM;
pp.from.reg = REG_FS;
pp.from.offset = 0x14; pp.from.offset = 0x14;
pp.from.index = D_NONE; pp.from.index = REG_NONE;
pp.from.scale = 0; pp.from.scale = 0;
*ctxt->andptr++ = 0x64; // FS *ctxt->andptr++ = 0x64; // FS
*ctxt->andptr++ = 0x8B; *ctxt->andptr++ = 0x8B;
asmand(ctxt, p, &pp.from, reg[p->to.type]); asmand(ctxt, p, &pp.from, reg[p->to.reg]);
break; break;
} }
break; break;
...@@ -2779,9 +2803,9 @@ asmins(Link *ctxt, Prog *p) ...@@ -2779,9 +2803,9 @@ asmins(Link *ctxt, Prog *p)
return; return;
case ACALL: case ACALL:
case AJMP: case AJMP:
if(D_AX <= p->to.type && p->to.type <= D_DI) { if(p->to.type == TYPE_REG && REG_AX <= p->to.reg && p->to.reg <= REG_DI) {
*ctxt->andptr++ = 0x83; *ctxt->andptr++ = 0x83;
*ctxt->andptr++ = 0xe0 | (p->to.type - D_AX); *ctxt->andptr++ = 0xe0 | (p->to.reg - REG_AX);
*ctxt->andptr++ = 0xe0; *ctxt->andptr++ = 0xe0;
} }
break; break;
......
...@@ -108,41 +108,38 @@ Dconv(Fmt *fp) ...@@ -108,41 +108,38 @@ Dconv(Fmt *fp)
{ {
char str[STRINGSZ], s[STRINGSZ]; char str[STRINGSZ], s[STRINGSZ];
Addr *a; Addr *a;
int i;
a = va_arg(fp->args, Addr*); a = va_arg(fp->args, Addr*);
i = a->type;
switch(a->type) {
if(fp->flags & FmtLong) {
if(i == D_CONST2)
sprint(str, "$%lld-%d", a->offset, a->offset2);
else {
// ATEXT dst is not constant
sprint(str, "!!%D", a);
}
goto brk;
}
if(i >= D_INDIR) {
if(a->offset)
sprint(str, "%lld(%R)", a->offset, i-D_INDIR);
else
sprint(str, "(%R)", i-D_INDIR);
goto brk;
}
switch(i) {
default: default:
if(a->offset) sprint(str, "type=%d", a->type);
sprint(str, "$%lld,%R", a->offset, i);
else
sprint(str, "%R", i);
break; break;
case D_NONE: case TYPE_NONE:
str[0] = 0; str[0] = 0;
break; break;
case TYPE_REG:
// TODO(rsc): This special case is for instructions like
// PINSRQ CX,$1,X6
// where the $1 is included in the p->to Addr.
// Move into a new field.
if(a->offset != 0) {
sprint(str, "$%lld,%R", a->offset, a->reg);
break;
}
sprint(str, "%R", a->reg);
// TODO(rsc): This special case is for SHRQ $32, AX:DX, which encodes as
// SHRQ $32(DX*0), AX
// Remove.
if(a->index != REG_NONE) {
sprint(s, "(%R*%d)", (int)a->index, (int)a->scale);
strcat(str, s);
}
break;
case D_BRANCH: case TYPE_BRANCH:
if(a->sym != nil) if(a->sym != nil)
sprint(str, "%s(SB)", a->sym->name); sprint(str, "%s(SB)", a->sym->name);
else if(bigP != nil && bigP->pcond != nil) else if(bigP != nil && bigP->pcond != nil)
...@@ -153,67 +150,78 @@ Dconv(Fmt *fp) ...@@ -153,67 +150,78 @@ Dconv(Fmt *fp)
sprint(str, "%lld(PC)", a->offset); sprint(str, "%lld(PC)", a->offset);
break; break;
case D_EXTERN: case TYPE_MEM:
sprint(str, "%s+%lld(SB)", a->sym->name, a->offset); switch(a->name) {
break; default:
sprint(str, "name=%d", a->name);
case D_STATIC: break;
sprint(str, "%s<>+%lld(SB)", a->sym->name, a->offset); case NAME_NONE:
break; if(a->offset)
sprint(str, "%lld(%R)", a->offset, a->reg);
case D_AUTO: else
if(a->sym) sprint(str, "(%R)", a->reg);
sprint(str, "%s+%lld(SP)", a->sym->name, a->offset); break;
else case NAME_EXTERN:
sprint(str, "%lld(SP)", a->offset); sprint(str, "%s+%lld(SB)", a->sym->name, a->offset);
break; break;
case NAME_STATIC:
case D_PARAM: sprint(str, "%s<>+%lld(SB)", a->sym->name, a->offset);
if(a->sym) break;
sprint(str, "%s+%lld(FP)", a->sym->name, a->offset); case NAME_AUTO:
else if(a->sym)
sprint(str, "%lld(FP)", a->offset); sprint(str, "%s+%lld(SP)", a->sym->name, a->offset);
else
sprint(str, "%lld(SP)", a->offset);
break;
case NAME_PARAM:
if(a->sym)
sprint(str, "%s+%lld(FP)", a->sym->name, a->offset);
else
sprint(str, "%lld(FP)", a->offset);
break;
}
if(a->index != REG_NONE) {
sprint(s, "(%R*%d)", (int)a->index, (int)a->scale);
strcat(str, s);
}
break; break;
case D_CONST: case TYPE_CONST:
sprint(str, "$%lld", a->offset); sprint(str, "$%lld", a->offset);
// TODO(rsc): This special case is for SHRQ $32, AX:DX, which encodes as
// SHRQ $32(DX*0), AX
// Remove.
if(a->index != REG_NONE) {
sprint(s, "(%R*%d)", (int)a->index, (int)a->scale);
strcat(str, s);
}
break; break;
case D_CONST2: case TYPE_TEXTSIZE:
if(!(fp->flags & FmtLong)) { sprint(str, "$%lld-%d", a->offset, a->u.argsize);
// D_CONST2 outside of ATEXT should not happen
sprint(str, "!!$%lld-%d", a->offset, a->offset2);
}
break; break;
case D_FCONST: case TYPE_FCONST:
sprint(str, "$(%.17g)", a->u.dval); sprint(str, "$(%.17g)", a->u.dval);
break; break;
case D_SCONST: case TYPE_SCONST:
sprint(str, "$\"%$\"", a->u.sval); sprint(str, "$\"%$\"", a->u.sval);
break; break;
case D_ADDR: case TYPE_ADDR:
a->type = a->index; a->type = TYPE_MEM;
a->index = D_NONE;
sprint(str, "$%D", a); sprint(str, "$%D", a);
a->index = a->type; a->type = TYPE_ADDR;
a->type = D_ADDR; break;
goto conv;
}
brk:
if(a->index != D_NONE) {
sprint(s, "(%R*%d)", (int)a->index, (int)a->scale);
strcat(str, s);
} }
conv:
return fmtstrcpy(fp, str); return fmtstrcpy(fp, str);
} }
static char* regstr[] = static char* regstr[] =
{ {
"AL", /* [D_AL] */ "AL", /* [REG_AL] */
"CL", "CL",
"DL", "DL",
"BL", "BL",
...@@ -222,7 +230,7 @@ static char* regstr[] = ...@@ -222,7 +230,7 @@ static char* regstr[] =
"DH", "DH",
"BH", "BH",
"AX", /* [D_AX] */ "AX", /* [REG_AX] */
"CX", "CX",
"DX", "DX",
"BX", "BX",
...@@ -231,7 +239,7 @@ static char* regstr[] = ...@@ -231,7 +239,7 @@ static char* regstr[] =
"SI", "SI",
"DI", "DI",
"F0", /* [D_F0] */ "F0", /* [REG_F0] */
"F1", "F1",
"F2", "F2",
"F3", "F3",
...@@ -240,20 +248,20 @@ static char* regstr[] = ...@@ -240,20 +248,20 @@ static char* regstr[] =
"F6", "F6",
"F7", "F7",
"CS", /* [D_CS] */ "CS", /* [REG_CS] */
"SS", "SS",
"DS", "DS",
"ES", "ES",
"FS", "FS",
"GS", "GS",
"GDTR", /* [D_GDTR] */ "GDTR", /* [REG_GDTR] */
"IDTR", /* [D_IDTR] */ "IDTR", /* [REG_IDTR] */
"LDTR", /* [D_LDTR] */ "LDTR", /* [REG_LDTR] */
"MSW", /* [D_MSW] */ "MSW", /* [REG_MSW] */
"TASK", /* [D_TASK] */ "TASK", /* [REG_TASK] */
"CR0", /* [D_CR] */ "CR0", /* [REG_CR] */
"CR1", "CR1",
"CR2", "CR2",
"CR3", "CR3",
...@@ -262,7 +270,7 @@ static char* regstr[] = ...@@ -262,7 +270,7 @@ static char* regstr[] =
"CR6", "CR6",
"CR7", "CR7",
"DR0", /* [D_DR] */ "DR0", /* [REG_DR] */
"DR1", "DR1",
"DR2", "DR2",
"DR3", "DR3",
...@@ -271,7 +279,7 @@ static char* regstr[] = ...@@ -271,7 +279,7 @@ static char* regstr[] =
"DR6", "DR6",
"DR7", "DR7",
"TR0", /* [D_TR] */ "TR0", /* [REG_TR] */
"TR1", "TR1",
"TR2", "TR2",
"TR3", "TR3",
...@@ -280,7 +288,7 @@ static char* regstr[] = ...@@ -280,7 +288,7 @@ static char* regstr[] =
"TR6", "TR6",
"TR7", "TR7",
"X0", /* [D_X0] */ "X0", /* [REG_X0] */
"X1", "X1",
"X2", "X2",
"X3", "X3",
...@@ -289,8 +297,8 @@ static char* regstr[] = ...@@ -289,8 +297,8 @@ static char* regstr[] =
"X6", "X6",
"X7", "X7",
"TLS", /* [D_TLS] */ "TLS", /* [REG_TLS] */
"NONE", /* [D_NONE] */ "MAXREG", /* [MAXREG] */
}; };
static int static int
...@@ -300,8 +308,10 @@ Rconv(Fmt *fp) ...@@ -300,8 +308,10 @@ Rconv(Fmt *fp)
int r; int r;
r = va_arg(fp->args, int); r = va_arg(fp->args, int);
if(r >= D_AL && r <= D_NONE) if(r == REG_NONE)
sprint(str, "%s", regstr[r-D_AL]); return fmtstrcpy(fp, "NONE");
if(r >= REG_AL && r-REG_AL < nelem(regstr))
sprint(str, "%s", regstr[r-REG_AL]);
else else
sprint(str, "gok(%d)", r); sprint(str, "gok(%d)", r);
......
...@@ -39,28 +39,17 @@ static Prog zprg = { ...@@ -39,28 +39,17 @@ static Prog zprg = {
.back = 2, .back = 2,
.as = AGOK, .as = AGOK,
.from = { .from = {
.type = D_NONE, .type = TYPE_NONE,
.index = D_NONE, .index = REG_NONE,
.scale = 1, .scale = 1,
}, },
.to = { .to = {
.type = D_NONE, .type = TYPE_NONE,
.index = D_NONE, .index = REG_NONE,
.scale = 1, .scale = 1,
}, },
}; };
static int
symtype(Addr *a)
{
int t;
t = a->type;
if(t == D_ADDR)
t = a->index;
return t;
}
static int static int
isdata(Prog *p) isdata(Prog *p)
{ {
...@@ -120,20 +109,22 @@ progedit(Link *ctxt, Prog *p) ...@@ -120,20 +109,22 @@ progedit(Link *ctxt, Prog *p)
// become // become
// NOP // NOP
// ... off(TLS) ... // ... off(TLS) ...
if(p->as == AMOVL && p->from.type == D_TLS && D_AX <= p->to.type && p->to.type <= D_DI) { if(p->as == AMOVL && p->from.type == TYPE_REG && p->from.reg == REG_TLS && p->to.type == TYPE_REG && REG_AX <= p->to.reg && p->to.reg <= REG_DI) {
p->as = ANOP; p->as = ANOP;
p->from.type = D_NONE; p->from.type = TYPE_NONE;
p->to.type = D_NONE; p->to.type = TYPE_NONE;
} }
if(p->from.index == D_TLS && D_INDIR+D_AX <= p->from.type && p->from.type <= D_INDIR+D_DI) { if(p->from.type == TYPE_MEM && p->from.index == REG_TLS && REG_AX <= p->from.reg && p->from.reg <= REG_DI) {
p->from.type = D_INDIR+D_TLS; p->from.type = TYPE_MEM;
p->from.reg = REG_TLS;
p->from.scale = 0; p->from.scale = 0;
p->from.index = D_NONE; p->from.index = REG_NONE;
} }
if(p->to.index == D_TLS && D_INDIR+D_AX <= p->to.type && p->to.type <= D_INDIR+D_DI) { if(p->to.type == TYPE_MEM && p->to.index == REG_TLS && REG_AX <= p->to.reg && p->to.reg <= REG_DI) {
p->to.type = D_INDIR+D_TLS; p->to.type = TYPE_MEM;
p->to.reg = REG_TLS;
p->to.scale = 0; p->to.scale = 0;
p->to.index = D_NONE; p->to.index = REG_NONE;
} }
} else { } else {
// As a courtesy to the C compilers, rewrite TLS local exec load as TLS initial exec load. // As a courtesy to the C compilers, rewrite TLS local exec load as TLS initial exec load.
...@@ -143,35 +134,36 @@ progedit(Link *ctxt, Prog *p) ...@@ -143,35 +134,36 @@ progedit(Link *ctxt, Prog *p)
// MOVL TLS, BX // MOVL TLS, BX
// MOVL off(BX)(TLS*1), BX // MOVL off(BX)(TLS*1), BX
// This allows the C compilers to emit references to m and g using the direct off(TLS) form. // This allows the C compilers to emit references to m and g using the direct off(TLS) form.
if(p->as == AMOVL && p->from.type == D_INDIR+D_TLS && D_AX <= p->to.type && p->to.type <= D_DI) { if(p->as == AMOVL && p->from.type == TYPE_MEM && p->from.reg == REG_TLS && p->to.type == TYPE_REG && REG_AX <= p->to.reg && p->to.reg <= REG_DI) {
q = appendp(ctxt, p); q = appendp(ctxt, p);
q->as = p->as; q->as = p->as;
q->from = p->from; q->from.type = TYPE_MEM;
q->from.type = D_INDIR + p->to.type; q->from.reg = p->to.reg;
q->from.index = D_TLS; q->from.index = REG_TLS;
q->from.scale = 2; // TODO: use 1 q->from.scale = 2; // TODO: use 1
q->to = p->to; q->to = p->to;
p->from.type = D_TLS; p->from.type = TYPE_REG;
p->from.index = D_NONE; p->from.reg = REG_TLS;
p->from.index = REG_NONE;
p->from.offset = 0; p->from.offset = 0;
} }
} }
// TODO: Remove. // TODO: Remove.
if(ctxt->headtype == Hplan9) { if(ctxt->headtype == Hplan9) {
if(p->from.scale == 1 && p->from.index == D_TLS) if(p->from.scale == 1 && p->from.index == REG_TLS)
p->from.scale = 2; p->from.scale = 2;
if(p->to.scale == 1 && p->to.index == D_TLS) if(p->to.scale == 1 && p->to.index == REG_TLS)
p->to.scale = 2; p->to.scale = 2;
} }
// Rewrite CALL/JMP/RET to symbol as D_BRANCH. // Rewrite CALL/JMP/RET to symbol as TYPE_BRANCH.
switch(p->as) { switch(p->as) {
case ACALL: case ACALL:
case AJMP: case AJMP:
case ARET: case ARET:
if((p->to.type == D_EXTERN || p->to.type == D_STATIC) && p->to.sym != nil) if(p->to.type == TYPE_MEM && (p->to.name == NAME_EXTERN || p->to.name == NAME_STATIC) && p->to.sym != nil)
p->to.type = D_BRANCH; p->to.type = TYPE_BRANCH;
break; break;
} }
...@@ -179,13 +171,11 @@ progedit(Link *ctxt, Prog *p) ...@@ -179,13 +171,11 @@ progedit(Link *ctxt, Prog *p)
switch(p->as) { switch(p->as) {
case AMOVSS: case AMOVSS:
// Convert AMOVSS $(0), Xx to AXORPS Xx, Xx // Convert AMOVSS $(0), Xx to AXORPS Xx, Xx
if(p->from.type == D_FCONST) if(p->from.type == TYPE_FCONST)
if(p->from.u.dval == 0) if(p->from.u.dval == 0)
if(p->to.type >= D_X0) if(p->to.type == TYPE_REG && REG_X0 <= p->to.reg && p->to.reg <= REG_X7) {
if(p->to.type <= D_X7) {
p->as = AXORPS; p->as = AXORPS;
p->from.type = p->to.type; p->from = p->to;
p->from.index = p->to.index;
break; break;
} }
// fallthrough // fallthrough
...@@ -205,7 +195,7 @@ progedit(Link *ctxt, Prog *p) ...@@ -205,7 +195,7 @@ progedit(Link *ctxt, Prog *p)
case ADIVSS: case ADIVSS:
case ACOMISS: case ACOMISS:
case AUCOMISS: case AUCOMISS:
if(p->from.type == D_FCONST) { if(p->from.type == TYPE_FCONST) {
uint32 i32; uint32 i32;
float32 f32; float32 f32;
f32 = p->from.u.dval; f32 = p->from.u.dval;
...@@ -217,7 +207,8 @@ progedit(Link *ctxt, Prog *p) ...@@ -217,7 +207,8 @@ progedit(Link *ctxt, Prog *p)
adduint32(ctxt, s, i32); adduint32(ctxt, s, i32);
s->reachable = 0; s->reachable = 0;
} }
p->from.type = D_EXTERN; p->from.type = TYPE_MEM;
p->from.name = NAME_EXTERN;
p->from.sym = s; p->from.sym = s;
p->from.offset = 0; p->from.offset = 0;
} }
...@@ -225,13 +216,11 @@ progedit(Link *ctxt, Prog *p) ...@@ -225,13 +216,11 @@ progedit(Link *ctxt, Prog *p)
case AMOVSD: case AMOVSD:
// Convert AMOVSD $(0), Xx to AXORPS Xx, Xx // Convert AMOVSD $(0), Xx to AXORPS Xx, Xx
if(p->from.type == D_FCONST) if(p->from.type == TYPE_FCONST)
if(p->from.u.dval == 0) if(p->from.u.dval == 0)
if(p->to.type >= D_X0) if(p->to.type == TYPE_REG && REG_X0 <= p->to.reg && p->to.reg <= REG_X7) {
if(p->to.type <= D_X7) {
p->as = AXORPS; p->as = AXORPS;
p->from.type = p->to.type; p->from = p->to;
p->from.index = p->to.index;
break; break;
} }
// fallthrough // fallthrough
...@@ -251,7 +240,7 @@ progedit(Link *ctxt, Prog *p) ...@@ -251,7 +240,7 @@ progedit(Link *ctxt, Prog *p)
case ADIVSD: case ADIVSD:
case ACOMISD: case ACOMISD:
case AUCOMISD: case AUCOMISD:
if(p->from.type == D_FCONST) { if(p->from.type == TYPE_FCONST) {
uint64 i64; uint64 i64;
memmove(&i64, &p->from.u.dval, 8); memmove(&i64, &p->from.u.dval, 8);
sprint(literal, "$f64.%016llux", i64); sprint(literal, "$f64.%016llux", i64);
...@@ -261,7 +250,8 @@ progedit(Link *ctxt, Prog *p) ...@@ -261,7 +250,8 @@ progedit(Link *ctxt, Prog *p)
adduint64(ctxt, s, i64); adduint64(ctxt, s, i64);
s->reachable = 0; s->reachable = 0;
} }
p->from.type = D_EXTERN; p->from.type = TYPE_MEM;
p->from.name = NAME_EXTERN;
p->from.sym = s; p->from.sym = s;
p->from.offset = 0; p->from.offset = 0;
} }
...@@ -283,7 +273,7 @@ static Prog* load_g_cx(Link*, Prog*); ...@@ -283,7 +273,7 @@ static Prog* load_g_cx(Link*, Prog*);
static Prog* stacksplit(Link*, Prog*, int32, int, Prog**); static Prog* stacksplit(Link*, Prog*, int32, int, Prog**);
static void static void
addstacksplit(Link *ctxt, LSym *cursym) preprocess(Link *ctxt, LSym *cursym)
{ {
Prog *p, *q, *p1, *p2; Prog *p, *q, *p1, *p2;
int32 autoffset, deltasp; int32 autoffset, deltasp;
...@@ -308,7 +298,7 @@ addstacksplit(Link *ctxt, LSym *cursym) ...@@ -308,7 +298,7 @@ addstacksplit(Link *ctxt, LSym *cursym)
autoffset = 0; autoffset = 0;
cursym->locals = autoffset; cursym->locals = autoffset;
cursym->args = p->to.offset2; cursym->args = p->to.u.argsize;
q = nil; q = nil;
...@@ -322,7 +312,7 @@ addstacksplit(Link *ctxt, LSym *cursym) ...@@ -322,7 +312,7 @@ addstacksplit(Link *ctxt, LSym *cursym)
if(autoffset) { if(autoffset) {
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AADJSP; p->as = AADJSP;
p->from.type = D_CONST; p->from.type = TYPE_CONST;
p->from.offset = autoffset; p->from.offset = autoffset;
p->spadj = autoffset; p->spadj = autoffset;
} else { } else {
...@@ -358,41 +348,51 @@ addstacksplit(Link *ctxt, LSym *cursym) ...@@ -358,41 +348,51 @@ addstacksplit(Link *ctxt, LSym *cursym)
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_INDIR+D_CX; p->from.type = TYPE_MEM;
p->from.reg = REG_CX;
p->from.offset = 4*ctxt->arch->ptrsize; // G.panic p->from.offset = 4*ctxt->arch->ptrsize; // G.panic
p->to.type = D_BX; p->to.type = TYPE_REG;
p->to.reg = REG_BX;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ATESTL; p->as = ATESTL;
p->from.type = D_BX; p->from.type = TYPE_REG;
p->to.type = D_BX; p->from.reg = REG_BX;
p->to.type = TYPE_REG;
p->to.reg = REG_BX;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AJEQ; p->as = AJEQ;
p->to.type = D_BRANCH; p->to.type = TYPE_BRANCH;
p1 = p; p1 = p;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ALEAL; p->as = ALEAL;
p->from.type = D_INDIR+D_SP; p->from.type = TYPE_MEM;
p->from.reg = REG_SP;
p->from.offset = autoffset+4; p->from.offset = autoffset+4;
p->to.type = D_DI; p->to.type = TYPE_REG;
p->to.reg = REG_DI;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ACMPL; p->as = ACMPL;
p->from.type = D_INDIR+D_BX; p->from.type = TYPE_MEM;
p->from.reg = REG_BX;
p->from.offset = 0; // Panic.argp p->from.offset = 0; // Panic.argp
p->to.type = D_DI; p->to.type = TYPE_REG;
p->to.reg = REG_DI;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AJNE; p->as = AJNE;
p->to.type = D_BRANCH; p->to.type = TYPE_BRANCH;
p2 = p; p2 = p;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_SP; p->from.type = TYPE_REG;
p->to.type = D_INDIR+D_BX; p->from.reg = REG_SP;
p->to.type = TYPE_MEM;
p->to.reg = REG_BX;
p->to.offset = 0; // Panic.argp p->to.offset = 0; // Panic.argp
p = appendp(ctxt, p); p = appendp(ctxt, p);
...@@ -407,20 +407,24 @@ addstacksplit(Link *ctxt, LSym *cursym) ...@@ -407,20 +407,24 @@ addstacksplit(Link *ctxt, LSym *cursym)
// false positives in garbage collection. // false positives in garbage collection.
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_SP; p->from.type = TYPE_REG;
p->to.type = D_DI; p->from.reg = REG_SP;
p->to.type = TYPE_REG;
p->to.reg = REG_DI;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_CONST; p->from.type = TYPE_CONST;
p->from.offset = autoffset/4; p->from.offset = autoffset/4;
p->to.type = D_CX; p->to.type = TYPE_REG;
p->to.reg = REG_CX;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_CONST; p->from.type = TYPE_CONST;
p->from.offset = 0; p->from.offset = 0;
p->to.type = D_AX; p->to.type = TYPE_REG;
p->to.reg = REG_AX;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AREP; p->as = AREP;
...@@ -430,15 +434,15 @@ addstacksplit(Link *ctxt, LSym *cursym) ...@@ -430,15 +434,15 @@ addstacksplit(Link *ctxt, LSym *cursym)
} }
for(; p != nil; p = p->link) { for(; p != nil; p = p->link) {
a = p->from.type; a = p->from.name;
if(a == D_AUTO) if(a == NAME_AUTO)
p->from.offset += deltasp; p->from.offset += deltasp;
if(a == D_PARAM) if(a == NAME_PARAM)
p->from.offset += deltasp + 4; p->from.offset += deltasp + 4;
a = p->to.type; a = p->to.name;
if(a == D_AUTO) if(a == NAME_AUTO)
p->to.offset += deltasp; p->to.offset += deltasp;
if(a == D_PARAM) if(a == NAME_PARAM)
p->to.offset += deltasp + 4; p->to.offset += deltasp + 4;
switch(p->as) { switch(p->as) {
...@@ -473,7 +477,7 @@ addstacksplit(Link *ctxt, LSym *cursym) ...@@ -473,7 +477,7 @@ addstacksplit(Link *ctxt, LSym *cursym)
if(autoffset) { if(autoffset) {
p->as = AADJSP; p->as = AADJSP;
p->from.type = D_CONST; p->from.type = TYPE_CONST;
p->from.offset = -autoffset; p->from.offset = -autoffset;
p->spadj = -autoffset; p->spadj = -autoffset;
p = appendp(ctxt, p); p = appendp(ctxt, p);
...@@ -500,16 +504,18 @@ load_g_cx(Link *ctxt, Prog *p) ...@@ -500,16 +504,18 @@ load_g_cx(Link *ctxt, Prog *p)
Prog *next; Prog *next;
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_INDIR+D_TLS; p->from.type = TYPE_MEM;
p->from.reg = REG_TLS;
p->from.offset = 0; p->from.offset = 0;
p->to.type = D_CX; p->to.type = TYPE_REG;
p->to.reg = REG_CX;
next = p->link; next = p->link;
progedit(ctxt, p); progedit(ctxt, p);
while(p->link != next) while(p->link != next)
p = p->link; p = p->link;
if(p->from.index == D_TLS) if(p->from.index == REG_TLS)
p->from.scale = 2; p->from.scale = 2;
return p; return p;
...@@ -534,19 +540,21 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt, Prog **jmpok) ...@@ -534,19 +540,21 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt, Prog **jmpok)
// catches out-of-sync stack guard info. // catches out-of-sync stack guard info.
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ACMPL; p->as = ACMPL;
p->from.type = D_INDIR+D_CX; p->from.type = TYPE_MEM;
p->from.reg = REG_CX;
p->from.offset = 4; p->from.offset = 4;
p->to.type = D_SP; p->to.type = TYPE_REG;
p->to.reg = REG_SP;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AJCC; p->as = AJCC;
p->to.type = D_BRANCH; p->to.type = TYPE_BRANCH;
p->to.offset = 4; p->to.offset = 4;
q1 = p; q1 = p;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AINT; p->as = AINT;
p->from.type = D_CONST; p->from.type = TYPE_CONST;
p->from.offset = 3; p->from.offset = 3;
p = appendp(ctxt, p); p = appendp(ctxt, p);
...@@ -560,8 +568,10 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt, Prog **jmpok) ...@@ -560,8 +568,10 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt, Prog **jmpok)
// CMPL SP, stackguard // CMPL SP, stackguard
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ACMPL; p->as = ACMPL;
p->from.type = D_SP; p->from.type = TYPE_REG;
p->to.type = D_INDIR+D_CX; p->from.reg = REG_SP;
p->to.type = TYPE_MEM;
p->to.reg = REG_CX;
p->to.offset = 2*ctxt->arch->ptrsize; // G.stackguard0 p->to.offset = 2*ctxt->arch->ptrsize; // G.stackguard0
if(ctxt->cursym->cfunc) if(ctxt->cursym->cfunc)
p->to.offset = 3*ctxt->arch->ptrsize; // G.stackguard1 p->to.offset = 3*ctxt->arch->ptrsize; // G.stackguard1
...@@ -571,14 +581,18 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt, Prog **jmpok) ...@@ -571,14 +581,18 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt, Prog **jmpok)
// CMPL AX, stackguard // CMPL AX, stackguard
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ALEAL; p->as = ALEAL;
p->from.type = D_INDIR+D_SP; p->from.type = TYPE_MEM;
p->from.reg = REG_SP;
p->from.offset = -(framesize-StackSmall); p->from.offset = -(framesize-StackSmall);
p->to.type = D_AX; p->to.type = TYPE_REG;
p->to.reg = REG_AX;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ACMPL; p->as = ACMPL;
p->from.type = D_AX; p->from.type = TYPE_REG;
p->to.type = D_INDIR+D_CX; p->from.reg = REG_AX;
p->to.type = TYPE_MEM;
p->to.reg = REG_CX;
p->to.offset = 2*ctxt->arch->ptrsize; // G.stackguard0 p->to.offset = 2*ctxt->arch->ptrsize; // G.stackguard0
if(ctxt->cursym->cfunc) if(ctxt->cursym->cfunc)
p->to.offset = 3*ctxt->arch->ptrsize; // G.stackguard1 p->to.offset = 3*ctxt->arch->ptrsize; // G.stackguard1
...@@ -599,53 +613,61 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt, Prog **jmpok) ...@@ -599,53 +613,61 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt, Prog **jmpok)
// CMPL AX, $(framesize+(StackGuard-StackSmall)) // CMPL AX, $(framesize+(StackGuard-StackSmall))
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_INDIR+D_CX; p->from.type = TYPE_MEM;
p->from.reg = REG_CX;
p->from.offset = 0; p->from.offset = 0;
p->from.offset = 2*ctxt->arch->ptrsize; // G.stackguard0 p->from.offset = 2*ctxt->arch->ptrsize; // G.stackguard0
if(ctxt->cursym->cfunc) if(ctxt->cursym->cfunc)
p->from.offset = 3*ctxt->arch->ptrsize; // G.stackguard1 p->from.offset = 3*ctxt->arch->ptrsize; // G.stackguard1
p->to.type = D_SI; p->to.type = TYPE_REG;
p->to.reg = REG_SI;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ACMPL; p->as = ACMPL;
p->from.type = D_SI; p->from.type = TYPE_REG;
p->to.type = D_CONST; p->from.reg = REG_SI;
p->to.type = TYPE_CONST;
p->to.offset = (uint32)StackPreempt; p->to.offset = (uint32)StackPreempt;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AJEQ; p->as = AJEQ;
p->to.type = D_BRANCH; p->to.type = TYPE_BRANCH;
q1 = p; q1 = p;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ALEAL; p->as = ALEAL;
p->from.type = D_INDIR+D_SP; p->from.type = TYPE_MEM;
p->from.reg = REG_SP;
p->from.offset = StackGuard; p->from.offset = StackGuard;
p->to.type = D_AX; p->to.type = TYPE_REG;
p->to.reg = REG_AX;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ASUBL; p->as = ASUBL;
p->from.type = D_SI; p->from.type = TYPE_REG;
p->from.reg = REG_SI;
p->from.offset = 0; p->from.offset = 0;
p->to.type = D_AX; p->to.type = TYPE_REG;
p->to.reg = REG_AX;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ACMPL; p->as = ACMPL;
p->from.type = D_AX; p->from.type = TYPE_REG;
p->to.type = D_CONST; p->from.reg = REG_AX;
p->to.type = TYPE_CONST;
p->to.offset = framesize+(StackGuard-StackSmall); p->to.offset = framesize+(StackGuard-StackSmall);
} }
// common // common
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AJHI; p->as = AJHI;
p->to.type = D_BRANCH; p->to.type = TYPE_BRANCH;
p->to.offset = 4; p->to.offset = 4;
q = p; q = p;
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = ACALL; p->as = ACALL;
p->to.type = D_BRANCH; p->to.type = TYPE_BRANCH;
if(ctxt->cursym->cfunc) if(ctxt->cursym->cfunc)
p->to.sym = linklookup(ctxt, "runtime.morestackc", 0); p->to.sym = linklookup(ctxt, "runtime.morestackc", 0);
else else
...@@ -653,7 +675,7 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt, Prog **jmpok) ...@@ -653,7 +675,7 @@ stacksplit(Link *ctxt, Prog *p, int32 framesize, int noctxt, Prog **jmpok)
p = appendp(ctxt, p); p = appendp(ctxt, p);
p->as = AJMP; p->as = AJMP;
p->to.type = D_BRANCH; p->to.type = TYPE_BRANCH;
p->pcond = ctxt->cursym->text->link; p->pcond = ctxt->cursym->text->link;
if(q != nil) if(q != nil)
...@@ -804,7 +826,7 @@ loop: ...@@ -804,7 +826,7 @@ loop:
q = ctxt->arch->prg(); q = ctxt->arch->prg();
q->as = AJMP; q->as = AJMP;
q->lineno = p->lineno; q->lineno = p->lineno;
q->to.type = D_BRANCH; q->to.type = TYPE_BRANCH;
q->to.offset = p->pc; q->to.offset = p->pc;
q->pcond = p; q->pcond = p;
p = q; p = q;
...@@ -829,7 +851,7 @@ loop: ...@@ -829,7 +851,7 @@ loop:
p->pcond = q; p->pcond = q;
if((q = brchain(ctxt, p->link)) != nil) if((q = brchain(ctxt, p->link)) != nil)
p->link = q; p->link = q;
if(p->from.type == D_CONST) { if(p->from.type == TYPE_CONST) {
if(p->from.offset == 1) { if(p->from.offset == 1) {
/* /*
* expect conditional jump to be taken. * expect conditional jump to be taken.
...@@ -864,7 +886,7 @@ LinkArch link386 = { ...@@ -864,7 +886,7 @@ LinkArch link386 = {
.thechar = '8', .thechar = '8',
.endian = LittleEndian, .endian = LittleEndian,
.addstacksplit = addstacksplit, .preprocess = preprocess,
.assemble = span8, .assemble = span8,
.datasize = datasize, .datasize = datasize,
.follow = follow, .follow = follow,
...@@ -873,24 +895,12 @@ LinkArch link386 = { ...@@ -873,24 +895,12 @@ LinkArch link386 = {
.prg = prg, .prg = prg,
.progedit = progedit, .progedit = progedit,
.settextflag = settextflag, .settextflag = settextflag,
.symtype = symtype,
.textflag = textflag, .textflag = textflag,
.minlc = 1, .minlc = 1,
.ptrsize = 4, .ptrsize = 4,
.regsize = 4, .regsize = 4,
.D_ADDR = D_ADDR,
.D_AUTO = D_AUTO,
.D_BRANCH = D_BRANCH,
.D_CONST = D_CONST,
.D_EXTERN = D_EXTERN,
.D_FCONST = D_FCONST,
.D_NONE = D_NONE,
.D_PARAM = D_PARAM,
.D_SCONST = D_SCONST,
.D_STATIC = D_STATIC,
.ACALL = ACALL, .ACALL = ACALL,
.ADATA = ADATA, .ADATA = ADATA,
.AEND = AEND, .AEND = AEND,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment