selfhost/cmd/w6a: drop snake_case from lex/parse/asm/obj exports
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
// externals are queued in asm_.relocs.
|
||||
//
|
||||
// Encoding subset matches what w6c emits — see cmd/w6a/asm.c for the
|
||||
// authoritative list. Helpers (rcode/rhi/modrm/emit_rex etc.) are
|
||||
// fully ported; a_encode itself is still a stub pending the full
|
||||
// authoritative list. Helpers (rcode/rhi/modrm/emitrex etc.) are
|
||||
// fully ported; encode itself is still a stub pending the full
|
||||
// switch over A_*.
|
||||
|
||||
use os;
|
||||
@@ -15,7 +15,7 @@ use types;
|
||||
|
||||
// ---- text buffer growth ------------------------------------------------
|
||||
|
||||
export fn a_emit_byte(a: *asm_, b: u8) void = {
|
||||
export fn emitbyte(a: *asm_, b: u8) void = {
|
||||
if (a.textlen + 1u64 > a.textcap) {
|
||||
let nc: u64 = a.textcap;
|
||||
if (nc == 0u64) { nc = 4096u64; };
|
||||
@@ -30,14 +30,14 @@ export fn a_emit_byte(a: *asm_, b: u8) void = {
|
||||
a.textlen += 1u64;
|
||||
};
|
||||
|
||||
export fn a_emit_u32(a: *asm_, v: u32) void = {
|
||||
a_emit_byte(a, (v & 255u32): u8);
|
||||
a_emit_byte(a, ((v >> 8u32) & 255u32): u8);
|
||||
a_emit_byte(a, ((v >> 16u32) & 255u32): u8);
|
||||
a_emit_byte(a, ((v >> 24u32) & 255u32): u8);
|
||||
export fn emitu32(a: *asm_, v: u32) void = {
|
||||
emitbyte(a, (v & 255u32): u8);
|
||||
emitbyte(a, ((v >> 8u32) & 255u32): u8);
|
||||
emitbyte(a, ((v >> 16u32) & 255u32): u8);
|
||||
emitbyte(a, ((v >> 24u32) & 255u32): u8);
|
||||
};
|
||||
|
||||
export fn a_addreloc(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||
export fn addreloc(a: *asm_, off: u64, kind: i32, s: *asym, add: i64) void = {
|
||||
let r: *areloc = amalloc(a.a, 48u64): *areloc;
|
||||
r.off = off;
|
||||
r.kind = kind;
|
||||
@@ -77,29 +77,29 @@ fn rhi(r: i32) i32 = {
|
||||
return 0;
|
||||
};
|
||||
|
||||
fn is_xmm(r: i32) bool = {
|
||||
fn isxmm(r: i32) bool = {
|
||||
if (r >= D_X0) { if (r <= D_X15) { return true; }; };
|
||||
return false;
|
||||
};
|
||||
|
||||
// ModR/M byte builder.
|
||||
fn modrm_byte(mod: i32, reg: i32, rm: i32) u8 = {
|
||||
fn modrmbyte(mod: i32, reg: i32, rm: i32) u8 = {
|
||||
return (((mod & 3) << 6) | ((reg & 7) << 3) | (rm & 7)): u8;
|
||||
};
|
||||
|
||||
// REX prefix; W=1 for 64-bit operand size.
|
||||
fn emit_rex(a: *asm_, regbit: i32, rmbit: i32, w: i32) void = {
|
||||
fn emitrex(a: *asm_, regbit: i32, rmbit: i32, w: i32) void = {
|
||||
let b: u8 = 64u8; // 0x40
|
||||
if (w != 0) { b = b | 8u8; };
|
||||
if (regbit != 0) { b = b | 4u8; };
|
||||
if (rmbit != 0) { b = b | 1u8; };
|
||||
if (b != 64u8) { a_emit_byte(a, b); }
|
||||
else { if (w != 0) { a_emit_byte(a, b); }; };
|
||||
if (b != 64u8) { emitbyte(a, b); }
|
||||
else { if (w != 0) { emitbyte(a, b); }; };
|
||||
};
|
||||
|
||||
// ModR/M + (optional) SIB + displacement for [base+disp].
|
||||
// Special-cases SP (needs SIB) and BP (forces explicit disp).
|
||||
fn emit_modrm_mem(a: *asm_, reg_field: i32, base: i32, disp: i64) void = {
|
||||
fn emitmodrmmem(a: *asm_, reg_field: i32, base: i32, disp: i64) void = {
|
||||
let rm: i32 = rcode(base);
|
||||
let needsib: bool = (rm == 4);
|
||||
let forced_disp: bool = false;
|
||||
@@ -113,78 +113,78 @@ fn emit_modrm_mem(a: *asm_, reg_field: i32, base: i32, disp: i64) void = {
|
||||
if (disp >= -128i64) { if (disp <= 127i64) { mod = 1; }; };
|
||||
};
|
||||
|
||||
a_emit_byte(a, modrm_byte(mod, reg_field, rm));
|
||||
emitbyte(a, modrmbyte(mod, reg_field, rm));
|
||||
if (needsib) {
|
||||
a_emit_byte(a, 36u8); // 0x24: scale=0 idx=4(none) base=4
|
||||
emitbyte(a, 36u8); // 0x24: scale=0 idx=4(none) base=4
|
||||
};
|
||||
if (mod == 1) {
|
||||
a_emit_byte(a, (disp: u64 & 255u64): u8);
|
||||
emitbyte(a, (disp: u64 & 255u64): u8);
|
||||
} else { if (mod == 2) {
|
||||
a_emit_u32(a, disp: u32);
|
||||
emitu32(a, disp: u32);
|
||||
};};
|
||||
};
|
||||
|
||||
// reg→reg "src, dst" generic encoding (89 /r, 01 /r, etc.).
|
||||
fn encode_rr(a: *asm_, opcode: u8, src: i32, dst: i32) void = {
|
||||
emit_rex(a, rhi(src), rhi(dst), 1);
|
||||
a_emit_byte(a, opcode);
|
||||
a_emit_byte(a, modrm_byte(3, rcode(src), rcode(dst)));
|
||||
fn encoderr(a: *asm_, opcode: u8, src: i32, dst: i32) void = {
|
||||
emitrex(a, rhi(src), rhi(dst), 1);
|
||||
emitbyte(a, opcode);
|
||||
emitbyte(a, modrmbyte(3, rcode(src), rcode(dst)));
|
||||
};
|
||||
|
||||
// reg→mem(base, disp) (e.g. MOVQ src reg into mem; opcode = 0x89).
|
||||
fn encode_rm(a: *asm_, opcode: u8, src_reg: i32, base: i32, disp: i64) void = {
|
||||
emit_rex(a, rhi(src_reg), rhi(base), 1);
|
||||
a_emit_byte(a, opcode);
|
||||
emit_modrm_mem(a, rcode(src_reg), base, disp);
|
||||
fn encoderm(a: *asm_, opcode: u8, src_reg: i32, base: i32, disp: i64) void = {
|
||||
emitrex(a, rhi(src_reg), rhi(base), 1);
|
||||
emitbyte(a, opcode);
|
||||
emitmodrmmem(a, rcode(src_reg), base, disp);
|
||||
};
|
||||
|
||||
// mem(base, disp) → reg (e.g. MOVQ mem into reg; opcode = 0x8B).
|
||||
fn encode_mr(a: *asm_, opcode: u8, dst_reg: i32, base: i32, disp: i64) void = {
|
||||
emit_rex(a, rhi(dst_reg), rhi(base), 1);
|
||||
a_emit_byte(a, opcode);
|
||||
emit_modrm_mem(a, rcode(dst_reg), base, disp);
|
||||
fn encodemr(a: *asm_, opcode: u8, dst_reg: i32, base: i32, disp: i64) void = {
|
||||
emitrex(a, rhi(dst_reg), rhi(base), 1);
|
||||
emitbyte(a, opcode);
|
||||
emitmodrmmem(a, rcode(dst_reg), base, disp);
|
||||
};
|
||||
|
||||
// OPCODE /n imm32 reg form (e.g. ADDQ $imm, reg).
|
||||
fn encode_ri_imm32(a: *asm_, opcode: u8, subop: i32, dst: i32, imm: i32) void = {
|
||||
emit_rex(a, 0, rhi(dst), 1);
|
||||
a_emit_byte(a, opcode);
|
||||
a_emit_byte(a, modrm_byte(3, subop, rcode(dst)));
|
||||
a_emit_u32(a, imm: u32);
|
||||
fn encoderiimm32(a: *asm_, opcode: u8, subop: i32, dst: i32, imm: i32) void = {
|
||||
emitrex(a, 0, rhi(dst), 1);
|
||||
emitbyte(a, opcode);
|
||||
emitbyte(a, modrmbyte(3, subop, rcode(dst)));
|
||||
emitu32(a, imm: u32);
|
||||
};
|
||||
|
||||
// Unary on reg: F7 /n reg, etc.
|
||||
fn encode_unary(a: *asm_, opcode: u8, subop: i32, dst: i32) void = {
|
||||
emit_rex(a, 0, rhi(dst), 1);
|
||||
a_emit_byte(a, opcode);
|
||||
a_emit_byte(a, modrm_byte(3, subop, rcode(dst)));
|
||||
fn encodeunary(a: *asm_, opcode: u8, subop: i32, dst: i32) void = {
|
||||
emitrex(a, 0, rhi(dst), 1);
|
||||
emitbyte(a, opcode);
|
||||
emitbyte(a, modrmbyte(3, subop, rcode(dst)));
|
||||
};
|
||||
|
||||
// SSE2 helpers. Plan 9 syntax: source first, destination second.
|
||||
// For ADDSD-style ops we put dst in the reg field, src in r/m.
|
||||
fn sse_rr(a: *asm_, prefix: u8, op2: u8, reg_op: i32, rm_op: i32) void = {
|
||||
if (prefix != 0u8) { a_emit_byte(a, prefix); };
|
||||
emit_rex(a, rhi(reg_op), rhi(rm_op), 0);
|
||||
a_emit_byte(a, 15u8); // 0x0F
|
||||
a_emit_byte(a, op2);
|
||||
a_emit_byte(a, modrm_byte(3, rcode(reg_op), rcode(rm_op)));
|
||||
fn sserr(a: *asm_, prefix: u8, op2: u8, reg_op: i32, rm_op: i32) void = {
|
||||
if (prefix != 0u8) { emitbyte(a, prefix); };
|
||||
emitrex(a, rhi(reg_op), rhi(rm_op), 0);
|
||||
emitbyte(a, 15u8); // 0x0F
|
||||
emitbyte(a, op2);
|
||||
emitbyte(a, modrmbyte(3, rcode(reg_op), rcode(rm_op)));
|
||||
};
|
||||
|
||||
fn sse_mr_load(a: *asm_, prefix: u8, op2: u8, reg_op: i32, base: i32, disp: i64) void = {
|
||||
if (prefix != 0u8) { a_emit_byte(a, prefix); };
|
||||
emit_rex(a, rhi(reg_op), rhi(base), 0);
|
||||
a_emit_byte(a, 15u8);
|
||||
a_emit_byte(a, op2);
|
||||
emit_modrm_mem(a, rcode(reg_op), base, disp);
|
||||
fn ssemrload(a: *asm_, prefix: u8, op2: u8, reg_op: i32, base: i32, disp: i64) void = {
|
||||
if (prefix != 0u8) { emitbyte(a, prefix); };
|
||||
emitrex(a, rhi(reg_op), rhi(base), 0);
|
||||
emitbyte(a, 15u8);
|
||||
emitbyte(a, op2);
|
||||
emitmodrmmem(a, rcode(reg_op), base, disp);
|
||||
};
|
||||
|
||||
// REX.W variant of sse_rr (CVTTSD2SI / CVTSI2SD).
|
||||
fn sse_rr_w(a: *asm_, prefix: u8, op2: u8, reg_op: i32, rm_op: i32) void = {
|
||||
if (prefix != 0u8) { a_emit_byte(a, prefix); };
|
||||
emit_rex(a, rhi(reg_op), rhi(rm_op), 1);
|
||||
a_emit_byte(a, 15u8);
|
||||
a_emit_byte(a, op2);
|
||||
a_emit_byte(a, modrm_byte(3, rcode(reg_op), rcode(rm_op)));
|
||||
fn sserrw(a: *asm_, prefix: u8, op2: u8, reg_op: i32, rm_op: i32) void = {
|
||||
if (prefix != 0u8) { emitbyte(a, prefix); };
|
||||
emitrex(a, rhi(reg_op), rhi(rm_op), 1);
|
||||
emitbyte(a, 15u8);
|
||||
emitbyte(a, op2);
|
||||
emitbyte(a, modrmbyte(3, rcode(reg_op), rcode(rm_op)));
|
||||
};
|
||||
|
||||
// ---- label resolution / fixups ----------------------------------------
|
||||
@@ -199,7 +199,7 @@ fn streq(a: str, b: str) bool = {
|
||||
return true;
|
||||
};
|
||||
|
||||
fn resolve_label(a: *asm_, name: str) u64 = {
|
||||
fn resolvelabel(a: *asm_, name: str) u64 = {
|
||||
let s: *asym = a.syms;
|
||||
for (s != nil) {
|
||||
if (s.defined != 0) { if (streq(s.name, name)) { return s.addr; }; };
|
||||
@@ -208,7 +208,7 @@ fn resolve_label(a: *asm_, name: str) u64 = {
|
||||
return 0u64;
|
||||
};
|
||||
|
||||
fn label_defined(a: *asm_, name: str) bool = {
|
||||
fn labeldefined(a: *asm_, name: str) bool = {
|
||||
let s: *asym = a.syms;
|
||||
for (s != nil) {
|
||||
if (s.defined != 0) { if (streq(s.name, name)) { return true; }; };
|
||||
@@ -219,7 +219,7 @@ fn label_defined(a: *asm_, name: str) bool = {
|
||||
|
||||
// ---- fixup helper -----------------------------------------------------
|
||||
|
||||
fn add_fixup(a: *asm_, off: u64, label: str) void = {
|
||||
fn addfixup(a: *asm_, off: u64, label: str) void = {
|
||||
let f: *afixup = amalloc(a.a, 48u64): *afixup;
|
||||
f.off = off;
|
||||
f.label = label;
|
||||
@@ -227,24 +227,24 @@ fn add_fixup(a: *asm_, off: u64, label: str) void = {
|
||||
a.fixups = f;
|
||||
};
|
||||
|
||||
fn is_gpr(t: i32) bool = {
|
||||
fn isgpr(t: i32) bool = {
|
||||
if (t >= D_AX) { if (t <= D_R15) { return true; }; };
|
||||
return false;
|
||||
};
|
||||
|
||||
// `a_intern` lives in parse.ww — flat-scope concat lets us call it
|
||||
// `intern` lives in parse.ww — flat-scope concat lets us call it
|
||||
// directly without an @symbol declaration here.
|
||||
|
||||
// ---- a_encode ---------------------------------------------------------
|
||||
// ---- encode ----------------------------------------------------------
|
||||
|
||||
export fn a_encode(a: *asm_) i32 = {
|
||||
export fn encode(a: *asm_) i32 = {
|
||||
let p: *aprog = a.head;
|
||||
for (p != nil) {
|
||||
// Define any pending label at the current PC.
|
||||
if (p.label.len > 0) {
|
||||
let s: *asym = a_intern(a, p.label);
|
||||
let s: *asym = intern(a, p.label);
|
||||
s.defined = 1;
|
||||
s.is_text = 1;
|
||||
s.istext = 1;
|
||||
s.addr = a.textlen;
|
||||
};
|
||||
let op: i32 = p.as_;
|
||||
@@ -253,105 +253,105 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (op == A_TEXT) {
|
||||
let s: *asym = a_intern(a, p.to.asym);
|
||||
let s: *asym = intern(a, p.to.asym);
|
||||
s.defined = 1;
|
||||
s.is_text = 1;
|
||||
s.is_global = 1;
|
||||
s.istext = 1;
|
||||
s.isglobal = 1;
|
||||
s.addr = a.textlen;
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (op == A_DATA) {
|
||||
let s: *asym = a_intern(a, p.to.asym);
|
||||
let s: *asym = intern(a, p.to.asym);
|
||||
s.defined = 1;
|
||||
s.is_text = 1;
|
||||
s.is_global = 1;
|
||||
s.istext = 1;
|
||||
s.isglobal = 1;
|
||||
s.addr = a.textlen;
|
||||
let i: u64 = 0u64;
|
||||
for (i < p.nbytes) { a_emit_byte(a, p.bytes[i]); i += 1u64; };
|
||||
for (i < p.nbytes) { emitbyte(a, p.bytes[i]); i += 1u64; };
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (op == A_RET) {
|
||||
a_emit_byte(a, 195u8); // 0xC3
|
||||
emitbyte(a, 195u8); // 0xC3
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (op == A_SYSCALL) {
|
||||
a_emit_byte(a, 15u8);
|
||||
a_emit_byte(a, 5u8);
|
||||
emitbyte(a, 15u8);
|
||||
emitbyte(a, 5u8);
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (op == A_PUSHQ) {
|
||||
if (rhi(p.to.atype) != 0) { a_emit_byte(a, 65u8); }; // 0x41
|
||||
a_emit_byte(a, (80 + rcode(p.to.atype)): u8); // 0x50
|
||||
if (rhi(p.to.atype) != 0) { emitbyte(a, 65u8); }; // 0x41
|
||||
emitbyte(a, (80 + rcode(p.to.atype)): u8); // 0x50
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (op == A_POPQ) {
|
||||
if (rhi(p.to.atype) != 0) { a_emit_byte(a, 65u8); };
|
||||
a_emit_byte(a, (88 + rcode(p.to.atype)): u8); // 0x58
|
||||
if (rhi(p.to.atype) != 0) { emitbyte(a, 65u8); };
|
||||
emitbyte(a, (88 + rcode(p.to.atype)): u8); // 0x58
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (op == A_NEGQ) { encode_unary(a, 247u8, 3, p.to.atype); p = p.link; continue; };
|
||||
if (op == A_NOTQ) { encode_unary(a, 247u8, 2, p.to.atype); p = p.link; continue; };
|
||||
if (op == A_IDIVQ) { encode_unary(a, 247u8, 7, p.to.atype); p = p.link; continue; };
|
||||
if (op == A_DIVQ) { encode_unary(a, 247u8, 6, p.to.atype); p = p.link; continue; };
|
||||
if (op == A_NEGQ) { encodeunary(a, 247u8, 3, p.to.atype); p = p.link; continue; };
|
||||
if (op == A_NOTQ) { encodeunary(a, 247u8, 2, p.to.atype); p = p.link; continue; };
|
||||
if (op == A_IDIVQ) { encodeunary(a, 247u8, 7, p.to.atype); p = p.link; continue; };
|
||||
if (op == A_DIVQ) { encodeunary(a, 247u8, 6, p.to.atype); p = p.link; continue; };
|
||||
|
||||
if (op == A_MOVQ) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (ft == D_CONST) { if (is_gpr(tt)) {
|
||||
if (ft == D_CONST) { if (isgpr(tt)) {
|
||||
let v: i64 = p.from.offset;
|
||||
if (v >= -2147483648i64) { if (v <= 2147483647i64) {
|
||||
encode_ri_imm32(a, 199u8, 0, tt, v: i32);
|
||||
encoderiimm32(a, 199u8, 0, tt, v: i32);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
// movabs r64, imm64: REX.W B8+rd imm64
|
||||
emit_rex(a, 0, rhi(tt), 1);
|
||||
a_emit_byte(a, (184 + rcode(tt)): u8);
|
||||
emitrex(a, 0, rhi(tt), 1);
|
||||
emitbyte(a, (184 + rcode(tt)): u8);
|
||||
let k: i32 = 0;
|
||||
for (k < 8) {
|
||||
a_emit_byte(a, ((v: u64 >> (k: u64 * 8u64)) & 255u64): u8);
|
||||
emitbyte(a, ((v: u64 >> (k: u64 * 8u64)) & 255u64): u8);
|
||||
k += 1;
|
||||
};
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (is_gpr(ft)) { if (is_gpr(tt)) {
|
||||
encode_rr(a, 137u8, ft, tt); // 0x89
|
||||
if (isgpr(ft)) { if (isgpr(tt)) {
|
||||
encoderr(a, 137u8, ft, tt); // 0x89
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_INDIR) { if (is_gpr(tt)) {
|
||||
encode_mr(a, 139u8, tt, p.from.reg, p.from.offset); // 0x8B
|
||||
if (ft == D_INDIR) { if (isgpr(tt)) {
|
||||
encodemr(a, 139u8, tt, p.from.reg, p.from.offset); // 0x8B
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (is_gpr(ft)) { if (tt == D_INDIR) {
|
||||
encode_rm(a, 137u8, ft, p.to.reg, p.to.offset);
|
||||
if (isgpr(ft)) { if (tt == D_INDIR) {
|
||||
encoderm(a, 137u8, ft, p.to.reg, p.to.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_CONST) { if (tt == D_INDIR) {
|
||||
emit_rex(a, 0, rhi(p.to.reg), 1);
|
||||
a_emit_byte(a, 199u8);
|
||||
emit_modrm_mem(a, 0, p.to.reg, p.to.offset);
|
||||
a_emit_u32(a, p.from.offset: u32);
|
||||
emitrex(a, 0, rhi(p.to.reg), 1);
|
||||
emitbyte(a, 199u8);
|
||||
emitmodrmmem(a, 0, p.to.reg, p.to.offset);
|
||||
emitu32(a, p.from.offset: u32);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_EXTERN) { if (is_gpr(tt)) {
|
||||
if (ft == D_EXTERN) { if (isgpr(tt)) {
|
||||
// RIP-relative load: 48 8B /r mod=00 rm=5 disp32
|
||||
emit_rex(a, rhi(tt), 0, 1);
|
||||
a_emit_byte(a, 139u8);
|
||||
a_emit_byte(a, modrm_byte(0, rcode(tt), 5));
|
||||
emitrex(a, rhi(tt), 0, 1);
|
||||
emitbyte(a, 139u8);
|
||||
emitbyte(a, modrmbyte(0, rcode(tt), 5));
|
||||
let reloff: u64 = a.textlen;
|
||||
a_emit_u32(a, 0u32);
|
||||
let s: *asym = a_intern(a, p.from.asym);
|
||||
a_addreloc(a, reloff, 2, s, -4i64);
|
||||
emitu32(a, 0u32);
|
||||
let s: *asym = intern(a, p.from.asym);
|
||||
addreloc(a, reloff, 2, s, -4i64);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (is_gpr(ft)) { if (tt == D_EXTERN) {
|
||||
if (isgpr(ft)) { if (tt == D_EXTERN) {
|
||||
// RIP-relative store: 48 89 /r mod=00 rm=5 disp32
|
||||
emit_rex(a, rhi(ft), 0, 1);
|
||||
a_emit_byte(a, 137u8);
|
||||
a_emit_byte(a, modrm_byte(0, rcode(ft), 5));
|
||||
emitrex(a, rhi(ft), 0, 1);
|
||||
emitbyte(a, 137u8);
|
||||
emitbyte(a, modrmbyte(0, rcode(ft), 5));
|
||||
let reloff: u64 = a.textlen;
|
||||
a_emit_u32(a, 0u32);
|
||||
let s: *asym = a_intern(a, p.to.asym);
|
||||
a_addreloc(a, reloff, 2, s, -4i64);
|
||||
emitu32(a, 0u32);
|
||||
let s: *asym = intern(a, p.to.asym);
|
||||
addreloc(a, reloff, 2, s, -4i64);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
os.write(2, "w6a: unsupported MOVQ shape\n".ptr, 27u64);
|
||||
@@ -362,16 +362,16 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
if (op == A_MOVB) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (is_gpr(ft)) { if (tt == D_INDIR) {
|
||||
emit_rex(a, rhi(ft), rhi(p.to.reg), 0);
|
||||
a_emit_byte(a, 136u8); // 0x88
|
||||
emit_modrm_mem(a, rcode(ft), p.to.reg, p.to.offset);
|
||||
if (isgpr(ft)) { if (tt == D_INDIR) {
|
||||
emitrex(a, rhi(ft), rhi(p.to.reg), 0);
|
||||
emitbyte(a, 136u8); // 0x88
|
||||
emitmodrmmem(a, rcode(ft), p.to.reg, p.to.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_INDIR) { if (is_gpr(tt)) {
|
||||
emit_rex(a, rhi(tt), rhi(p.from.reg), 0);
|
||||
a_emit_byte(a, 138u8); // 0x8A
|
||||
emit_modrm_mem(a, rcode(tt), p.from.reg, p.from.offset);
|
||||
if (ft == D_INDIR) { if (isgpr(tt)) {
|
||||
emitrex(a, rhi(tt), rhi(p.from.reg), 0);
|
||||
emitbyte(a, 138u8); // 0x8A
|
||||
emitmodrmmem(a, rcode(tt), p.from.reg, p.from.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
os.write(2, "w6a: unsupported MOVB shape\n".ptr, 27u64);
|
||||
@@ -382,11 +382,11 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
if (op == A_MOVZBQ) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (ft == D_INDIR) { if (is_gpr(tt)) {
|
||||
emit_rex(a, rhi(tt), rhi(p.from.reg), 1);
|
||||
a_emit_byte(a, 15u8);
|
||||
a_emit_byte(a, 182u8); // 0xB6
|
||||
emit_modrm_mem(a, rcode(tt), p.from.reg, p.from.offset);
|
||||
if (ft == D_INDIR) { if (isgpr(tt)) {
|
||||
emitrex(a, rhi(tt), rhi(p.from.reg), 1);
|
||||
emitbyte(a, 15u8);
|
||||
emitbyte(a, 182u8); // 0xB6
|
||||
emitmodrmmem(a, rcode(tt), p.from.reg, p.from.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
os.write(2, "w6a: unsupported MOVZBQ shape\n".ptr, 29u64);
|
||||
@@ -397,22 +397,22 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
if (op == A_MOVL) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (is_gpr(ft)) { if (tt == D_INDIR) {
|
||||
emit_rex(a, rhi(ft), rhi(p.to.reg), 0);
|
||||
a_emit_byte(a, 137u8);
|
||||
emit_modrm_mem(a, rcode(ft), p.to.reg, p.to.offset);
|
||||
if (isgpr(ft)) { if (tt == D_INDIR) {
|
||||
emitrex(a, rhi(ft), rhi(p.to.reg), 0);
|
||||
emitbyte(a, 137u8);
|
||||
emitmodrmmem(a, rcode(ft), p.to.reg, p.to.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_INDIR) { if (is_gpr(tt)) {
|
||||
emit_rex(a, rhi(tt), rhi(p.from.reg), 0);
|
||||
a_emit_byte(a, 139u8);
|
||||
emit_modrm_mem(a, rcode(tt), p.from.reg, p.from.offset);
|
||||
if (ft == D_INDIR) { if (isgpr(tt)) {
|
||||
emitrex(a, rhi(tt), rhi(p.from.reg), 0);
|
||||
emitbyte(a, 139u8);
|
||||
emitmodrmmem(a, rcode(tt), p.from.reg, p.from.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (is_gpr(ft)) { if (is_gpr(tt)) {
|
||||
emit_rex(a, rhi(ft), rhi(tt), 0);
|
||||
a_emit_byte(a, 137u8);
|
||||
a_emit_byte(a, modrm_byte(3, rcode(ft), rcode(tt)));
|
||||
if (isgpr(ft)) { if (isgpr(tt)) {
|
||||
emitrex(a, rhi(ft), rhi(tt), 0);
|
||||
emitbyte(a, 137u8);
|
||||
emitbyte(a, modrmbyte(3, rcode(ft), rcode(tt)));
|
||||
p = p.link; continue;
|
||||
};};
|
||||
os.write(2, "w6a: unsupported MOVL shape\n".ptr, 27u64);
|
||||
@@ -423,10 +423,10 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
if (op == A_MOVSXD) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (ft == D_INDIR) { if (is_gpr(tt)) {
|
||||
emit_rex(a, rhi(tt), rhi(p.from.reg), 1);
|
||||
a_emit_byte(a, 99u8); // 0x63
|
||||
emit_modrm_mem(a, rcode(tt), p.from.reg, p.from.offset);
|
||||
if (ft == D_INDIR) { if (isgpr(tt)) {
|
||||
emitrex(a, rhi(tt), rhi(p.from.reg), 1);
|
||||
emitbyte(a, 99u8); // 0x63
|
||||
emitmodrmmem(a, rcode(tt), p.from.reg, p.from.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
os.write(2, "w6a: unsupported MOVSXD shape\n".ptr, 29u64);
|
||||
@@ -437,16 +437,16 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
if (op == A_MOVSD) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (is_xmm(ft)) { if (is_xmm(tt)) {
|
||||
sse_rr(a, 242u8, 16u8, tt, ft);
|
||||
if (isxmm(ft)) { if (isxmm(tt)) {
|
||||
sserr(a, 242u8, 16u8, tt, ft);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_INDIR) { if (is_xmm(tt)) {
|
||||
sse_mr_load(a, 242u8, 16u8, tt, p.from.reg, p.from.offset);
|
||||
if (ft == D_INDIR) { if (isxmm(tt)) {
|
||||
ssemrload(a, 242u8, 16u8, tt, p.from.reg, p.from.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (is_xmm(ft)) { if (tt == D_INDIR) {
|
||||
sse_mr_load(a, 242u8, 17u8, ft, p.to.reg, p.to.offset);
|
||||
if (isxmm(ft)) { if (tt == D_INDIR) {
|
||||
ssemrload(a, 242u8, 17u8, ft, p.to.reg, p.to.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
os.write(2, "w6a: unsupported MOVSD shape\n".ptr, 28u64);
|
||||
@@ -454,26 +454,26 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
p = p.link; continue;
|
||||
};
|
||||
|
||||
if (op == A_ADDSD) { sse_rr(a, 242u8, 88u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_SUBSD) { sse_rr(a, 242u8, 92u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_MULSD) { sse_rr(a, 242u8, 89u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_DIVSD) { sse_rr(a, 242u8, 94u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_UCOMISD) { sse_rr(a, 102u8, 46u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTTSD2SI) { sse_rr_w(a, 242u8, 44u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTSI2SD) { sse_rr_w(a, 242u8, 42u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_ADDSD) { sserr(a, 242u8, 88u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_SUBSD) { sserr(a, 242u8, 92u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_MULSD) { sserr(a, 242u8, 89u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_DIVSD) { sserr(a, 242u8, 94u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_UCOMISD) { sserr(a, 102u8, 46u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTTSD2SI) { sserrw(a, 242u8, 44u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTSI2SD) { sserrw(a, 242u8, 42u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
|
||||
if (op == A_MOVSS) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (is_xmm(ft)) { if (is_xmm(tt)) {
|
||||
sse_rr(a, 243u8, 16u8, tt, ft); p = p.link; continue;
|
||||
if (isxmm(ft)) { if (isxmm(tt)) {
|
||||
sserr(a, 243u8, 16u8, tt, ft); p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_INDIR) { if (is_xmm(tt)) {
|
||||
sse_mr_load(a, 243u8, 16u8, tt, p.from.reg, p.from.offset);
|
||||
if (ft == D_INDIR) { if (isxmm(tt)) {
|
||||
ssemrload(a, 243u8, 16u8, tt, p.from.reg, p.from.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (is_xmm(ft)) { if (tt == D_INDIR) {
|
||||
sse_mr_load(a, 243u8, 17u8, ft, p.to.reg, p.to.offset);
|
||||
if (isxmm(ft)) { if (tt == D_INDIR) {
|
||||
ssemrload(a, 243u8, 17u8, ft, p.to.reg, p.to.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
os.write(2, "w6a: unsupported MOVSS shape\n".ptr, 28u64);
|
||||
@@ -481,115 +481,115 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
p = p.link; continue;
|
||||
};
|
||||
|
||||
if (op == A_ADDSS) { sse_rr(a, 243u8, 88u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_SUBSS) { sse_rr(a, 243u8, 92u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_MULSS) { sse_rr(a, 243u8, 89u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_DIVSS) { sse_rr(a, 243u8, 94u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_UCOMISS) { sse_rr(a, 0u8, 46u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTTSS2SI) { sse_rr_w(a, 243u8, 44u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTSI2SS) { sse_rr_w(a, 243u8, 42u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTSD2SS) { sse_rr(a, 242u8, 90u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTSS2SD) { sse_rr(a, 243u8, 90u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_ADDSS) { sserr(a, 243u8, 88u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_SUBSS) { sserr(a, 243u8, 92u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_MULSS) { sserr(a, 243u8, 89u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_DIVSS) { sserr(a, 243u8, 94u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_UCOMISS) { sserr(a, 0u8, 46u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTTSS2SI) { sserrw(a, 243u8, 44u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTSI2SS) { sserrw(a, 243u8, 42u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTSD2SS) { sserr(a, 242u8, 90u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
if (op == A_CVTSS2SD) { sserr(a, 243u8, 90u8, p.to.atype, p.from.atype); p = p.link; continue; };
|
||||
|
||||
if (op == A_ADDQ) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (ft == D_CONST) { if (is_gpr(tt)) {
|
||||
encode_ri_imm32(a, 129u8, 0, tt, p.from.offset: i32); // 0x81
|
||||
if (ft == D_CONST) { if (isgpr(tt)) {
|
||||
encoderiimm32(a, 129u8, 0, tt, p.from.offset: i32); // 0x81
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_CONST) { if (tt == D_INDIR) {
|
||||
emit_rex(a, 0, rhi(p.to.reg), 1);
|
||||
a_emit_byte(a, 129u8);
|
||||
emit_modrm_mem(a, 0, p.to.reg, p.to.offset);
|
||||
a_emit_u32(a, p.from.offset: u32);
|
||||
emitrex(a, 0, rhi(p.to.reg), 1);
|
||||
emitbyte(a, 129u8);
|
||||
emitmodrmmem(a, 0, p.to.reg, p.to.offset);
|
||||
emitu32(a, p.from.offset: u32);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (is_gpr(ft)) { if (tt == D_INDIR) {
|
||||
encode_rm(a, 1u8, ft, p.to.reg, p.to.offset);
|
||||
if (isgpr(ft)) { if (tt == D_INDIR) {
|
||||
encoderm(a, 1u8, ft, p.to.reg, p.to.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_INDIR) { if (is_gpr(tt)) {
|
||||
encode_mr(a, 3u8, tt, p.from.reg, p.from.offset);
|
||||
if (ft == D_INDIR) { if (isgpr(tt)) {
|
||||
encodemr(a, 3u8, tt, p.from.reg, p.from.offset);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
encode_rr(a, 1u8, ft, tt);
|
||||
encoderr(a, 1u8, ft, tt);
|
||||
p = p.link; continue;
|
||||
};
|
||||
|
||||
if (op == A_SUBQ) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (ft == D_CONST) { if (is_gpr(tt)) {
|
||||
encode_ri_imm32(a, 129u8, 5, tt, p.from.offset: i32);
|
||||
if (ft == D_CONST) { if (isgpr(tt)) {
|
||||
encoderiimm32(a, 129u8, 5, tt, p.from.offset: i32);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_CONST) { if (tt == D_INDIR) {
|
||||
emit_rex(a, 0, rhi(p.to.reg), 1);
|
||||
a_emit_byte(a, 129u8);
|
||||
emit_modrm_mem(a, 5, p.to.reg, p.to.offset);
|
||||
a_emit_u32(a, p.from.offset: u32);
|
||||
emitrex(a, 0, rhi(p.to.reg), 1);
|
||||
emitbyte(a, 129u8);
|
||||
emitmodrmmem(a, 5, p.to.reg, p.to.offset);
|
||||
emitu32(a, p.from.offset: u32);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (is_gpr(ft)) { if (tt == D_INDIR) {
|
||||
encode_rm(a, 41u8, ft, p.to.reg, p.to.offset); // 0x29
|
||||
if (isgpr(ft)) { if (tt == D_INDIR) {
|
||||
encoderm(a, 41u8, ft, p.to.reg, p.to.offset); // 0x29
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_INDIR) { if (is_gpr(tt)) {
|
||||
encode_mr(a, 43u8, tt, p.from.reg, p.from.offset); // 0x2B
|
||||
if (ft == D_INDIR) { if (isgpr(tt)) {
|
||||
encodemr(a, 43u8, tt, p.from.reg, p.from.offset); // 0x2B
|
||||
p = p.link; continue;
|
||||
};};
|
||||
encode_rr(a, 41u8, ft, tt);
|
||||
encoderr(a, 41u8, ft, tt);
|
||||
p = p.link; continue;
|
||||
};
|
||||
|
||||
if (op == A_ANDQ) { encode_rr(a, 33u8, p.from.atype, p.to.atype); p = p.link; continue; }; // 0x21
|
||||
if (op == A_ORQ) { encode_rr(a, 9u8, p.from.atype, p.to.atype); p = p.link; continue; }; // 0x09
|
||||
if (op == A_ANDQ) { encoderr(a, 33u8, p.from.atype, p.to.atype); p = p.link; continue; }; // 0x21
|
||||
if (op == A_ORQ) { encoderr(a, 9u8, p.from.atype, p.to.atype); p = p.link; continue; }; // 0x09
|
||||
if (op == A_XORQ) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (ft == D_CONST) { if (is_gpr(tt)) {
|
||||
encode_ri_imm32(a, 129u8, 6, tt, p.from.offset: i32);
|
||||
if (ft == D_CONST) { if (isgpr(tt)) {
|
||||
encoderiimm32(a, 129u8, 6, tt, p.from.offset: i32);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
encode_rr(a, 49u8, ft, tt); // 0x31
|
||||
encoderr(a, 49u8, ft, tt); // 0x31
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (op == A_IMULQ) {
|
||||
emit_rex(a, rhi(p.to.atype), rhi(p.from.atype), 1);
|
||||
a_emit_byte(a, 15u8);
|
||||
a_emit_byte(a, 175u8); // 0xAF
|
||||
a_emit_byte(a, modrm_byte(3, rcode(p.to.atype), rcode(p.from.atype)));
|
||||
emitrex(a, rhi(p.to.atype), rhi(p.from.atype), 1);
|
||||
emitbyte(a, 15u8);
|
||||
emitbyte(a, 175u8); // 0xAF
|
||||
emitbyte(a, modrmbyte(3, rcode(p.to.atype), rcode(p.from.atype)));
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (op == A_SHLQ) { encode_unary(a, 211u8, 4, p.to.atype); p = p.link; continue; }; // 0xD3
|
||||
if (op == A_SHRQ) { encode_unary(a, 211u8, 5, p.to.atype); p = p.link; continue; };
|
||||
if (op == A_SHLQ) { encodeunary(a, 211u8, 4, p.to.atype); p = p.link; continue; }; // 0xD3
|
||||
if (op == A_SHRQ) { encodeunary(a, 211u8, 5, p.to.atype); p = p.link; continue; };
|
||||
if (op == A_CMPQ) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (ft == D_CONST) { if (is_gpr(tt)) {
|
||||
encode_ri_imm32(a, 129u8, 7, tt, p.from.offset: i32);
|
||||
if (ft == D_CONST) { if (isgpr(tt)) {
|
||||
encoderiimm32(a, 129u8, 7, tt, p.from.offset: i32);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
encode_rr(a, 57u8, ft, tt); // 0x39
|
||||
encoderr(a, 57u8, ft, tt); // 0x39
|
||||
p = p.link; continue;
|
||||
};
|
||||
|
||||
if (op == A_LEAQ) {
|
||||
let ft: i32 = p.from.atype;
|
||||
let tt: i32 = p.to.atype;
|
||||
if (ft == D_INDIR) { if (is_gpr(tt)) {
|
||||
encode_mr(a, 141u8, tt, p.from.reg, p.from.offset); // 0x8D
|
||||
if (ft == D_INDIR) { if (isgpr(tt)) {
|
||||
encodemr(a, 141u8, tt, p.from.reg, p.from.offset); // 0x8D
|
||||
p = p.link; continue;
|
||||
};};
|
||||
if (ft == D_EXTERN) { if (is_gpr(tt)) {
|
||||
emit_rex(a, rhi(tt), 0, 1);
|
||||
a_emit_byte(a, 141u8);
|
||||
a_emit_byte(a, modrm_byte(0, rcode(tt), 5));
|
||||
if (ft == D_EXTERN) { if (isgpr(tt)) {
|
||||
emitrex(a, rhi(tt), 0, 1);
|
||||
emitbyte(a, 141u8);
|
||||
emitbyte(a, modrmbyte(0, rcode(tt), 5));
|
||||
let reloff: u64 = a.textlen;
|
||||
a_emit_u32(a, 0u32);
|
||||
let s: *asym = a_intern(a, p.from.asym);
|
||||
a_addreloc(a, reloff, 2, s, -4i64);
|
||||
emitu32(a, 0u32);
|
||||
let s: *asym = intern(a, p.from.asym);
|
||||
addreloc(a, reloff, 2, s, -4i64);
|
||||
p = p.link; continue;
|
||||
};};
|
||||
p = p.link; continue;
|
||||
@@ -598,32 +598,32 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
if (op == A_CALL) {
|
||||
let tt: i32 = p.to.atype;
|
||||
if (tt == D_EXTERN) {
|
||||
a_emit_byte(a, 232u8); // 0xE8
|
||||
emitbyte(a, 232u8); // 0xE8
|
||||
let reloff: u64 = a.textlen;
|
||||
a_emit_u32(a, 0u32);
|
||||
let s: *asym = a_intern(a, p.to.asym);
|
||||
a_addreloc(a, reloff, 4, s, -4i64);
|
||||
emitu32(a, 0u32);
|
||||
let s: *asym = intern(a, p.to.asym);
|
||||
addreloc(a, reloff, 4, s, -4i64);
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (tt == D_BRANCH) {
|
||||
a_emit_byte(a, 232u8);
|
||||
add_fixup(a, a.textlen, p.to.asym);
|
||||
a_emit_u32(a, 0u32);
|
||||
emitbyte(a, 232u8);
|
||||
addfixup(a, a.textlen, p.to.asym);
|
||||
emitu32(a, 0u32);
|
||||
p = p.link; continue;
|
||||
};
|
||||
if (is_gpr(tt)) {
|
||||
if (rhi(tt) != 0) { a_emit_byte(a, 65u8); };
|
||||
a_emit_byte(a, 255u8); // 0xFF
|
||||
a_emit_byte(a, modrm_byte(3, 2, rcode(tt)));
|
||||
if (isgpr(tt)) {
|
||||
if (rhi(tt) != 0) { emitbyte(a, 65u8); };
|
||||
emitbyte(a, 255u8); // 0xFF
|
||||
emitbyte(a, modrmbyte(3, 2, rcode(tt)));
|
||||
p = p.link; continue;
|
||||
};
|
||||
p = p.link; continue;
|
||||
};
|
||||
|
||||
if (op == A_JMP) {
|
||||
a_emit_byte(a, 233u8); // 0xE9
|
||||
add_fixup(a, a.textlen, p.to.asym);
|
||||
a_emit_u32(a, 0u32);
|
||||
emitbyte(a, 233u8); // 0xE9
|
||||
addfixup(a, a.textlen, p.to.asym);
|
||||
emitu32(a, 0u32);
|
||||
p = p.link; continue;
|
||||
};
|
||||
|
||||
@@ -644,10 +644,10 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
else { if (op == A_JAE) { cc = 131u8; }
|
||||
else { is_jcc = false; };};};};};};};};};};};};
|
||||
if (is_jcc) {
|
||||
a_emit_byte(a, 15u8);
|
||||
a_emit_byte(a, cc);
|
||||
add_fixup(a, a.textlen, p.to.asym);
|
||||
a_emit_u32(a, 0u32);
|
||||
emitbyte(a, 15u8);
|
||||
emitbyte(a, cc);
|
||||
addfixup(a, a.textlen, p.to.asym);
|
||||
emitu32(a, 0u32);
|
||||
p = p.link; continue;
|
||||
};
|
||||
|
||||
@@ -659,7 +659,7 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
// Second pass: patch fixups (forward label refs).
|
||||
let f: *afixup = a.fixups;
|
||||
for (f != nil) {
|
||||
if (!label_defined(a, f.label)) {
|
||||
if (!labeldefined(a, f.label)) {
|
||||
os.write(2, "w6a: undefined label '".ptr, 21u64);
|
||||
let lbl: str = f.label;
|
||||
os.write(2, lbl.ptr, lbl.len: u64);
|
||||
@@ -668,7 +668,7 @@ export fn a_encode(a: *asm_) i32 = {
|
||||
f = f.fnext;
|
||||
continue;
|
||||
};
|
||||
let target: u64 = resolve_label(a, f.label);
|
||||
let target: u64 = resolvelabel(a, f.label);
|
||||
let rel: i64 = target: i64 - (f.off: i64 + 4i64);
|
||||
let rel32: u32 = rel: u32;
|
||||
a.text[f.off] = (rel32 & 255u32): u8;
|
||||
|
||||
Reference in New Issue
Block a user