ref: 1c7e58e75bc6b5620984f164d66354350b28dfe0
parent: 61c6a24d350a09f4a45b31b97ab91af6aea47958
author: mia soweli <inbox@tachibana-labs.org>
date: Sun May 19 10:54:06 EDT 2024
8[al]: support CMPXCHG and CMPXCHG8B
--- a/sys/src/cmd/8a/a.y
+++ b/sys/src/cmd/8a/a.y
@@ -20,7 +20,7 @@
%left '+' '-'
%left '*' '/' '%'
%token <lval> LTYPE0 LTYPE1 LTYPE2 LTYPE3 LTYPE4
-%token <lval> LTYPEC LTYPED LTYPEN LTYPER LTYPET LTYPES LTYPEM LTYPEI LTYPEG LTYPEXC LTYPEX
+%token <lval> LTYPEC LTYPED LTYPEN LTYPER LTYPET LTYPES LTYPEM LTYPEI LTYPEG LTYPEXC LTYPEX LTYPEXQ
%token <lval> LCONST LFP LPC LSB
%token <lval> LBREG LLREG LSREG LFREG LMREG LXREG
%token <dval> LFCONST
@@ -30,7 +30,7 @@
%type <con2> con2
%type <gen> mem imm imm2 reg nam rel rem rim rom omem nmem
%type <gen2> nonnon nonrel nonrem rimnon rimrem remrim
-%type <gen2> spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10
+%type <gen2> spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 spec11
%%
prog:
| prog line
@@ -81,6 +81,7 @@
| LTYPEG spec8 { outcode($1, &$2); }
| LTYPEXC spec9 { outcode($1, &$2); }
| LTYPEX spec10 { outcode($1, &$2); }
+| LTYPEXQ spec11 { outcode($1, &$2); }
nonnon:
{
@@ -255,6 +256,13 @@
if($1.type != D_CONST)
yyerror("illegal constant");
$$.to.offset = $1.offset;
+ }
+
+spec11: /* CMPXCHG8B */
+ mem
+ {
+ $$.from = nullgen;
+ $$.to = $1;
}
rem:
--- a/sys/src/cmd/8a/lex.c
+++ b/sys/src/cmd/8a/lex.c
@@ -290,6 +290,7 @@
"CMPXCHGB", LTYPE3, ACMPXCHGB,
"CMPXCHGL", LTYPE3, ACMPXCHGL,
"CMPXCHGW", LTYPE3, ACMPXCHGW,
+ "CMPXCHG8B", LTYPEXQ, ACMPXCHG8B,
"CPUID", LTYPE0, ACPUID,
"DAA", LTYPE0, ADAA,
"DAS", LTYPE0, ADAS,
--- a/sys/src/cmd/8c/8.out.h
+++ b/sys/src/cmd/8c/8.out.h
@@ -586,6 +586,7 @@
API2FL,
AJMPF,
+ ACMPXCHG8B,
/* add new operations here. nowhere else. here. */
ALAST
--- a/sys/src/cmd/8l/optab.c
+++ b/sys/src/cmd/8l/optab.c
@@ -439,6 +439,11 @@
Ymr, Yrl, Zm_r_xm, 1,
0
};
+uchar ycxq[] =
+{
+ Ynone, Ym, Zo_m, 2,
+ 0
+};
Optab optab[] =
/* as, ytab, andproto, opcode */
@@ -952,6 +957,11 @@
{ AFXTRACT, ynone, Px, 0xd9, 0xf4 },
{ AFYL2X, ynone, Px, 0xd9, 0xf1 },
{ AFYL2XP1, ynone, Px, 0xd9, 0xf9 },
+
+ { ACMPXCHGB, yml_mb, Pm, 0xb0, 0xb0 },
+ { ACMPXCHGL, yml_mb, Pm, 0xb1, 0xb1 },
+ { ACMPXCHGW, yml_mb, Pq, 0xb1, 0xb1 },
+ { ACMPXCHG8B, ycxq, Pm, 0xc7, (01) },
{ AEND },
0