Add new opcode for moving the stack pointer to a reg and use it to eliminate custom Linux startup code
Closed this issue · 1 comments
robertmuth commented
The startup code for a32 looks like this:
unit.FunStart("_start", 16, NOP_BYTES)
for mnemonic, ops in [
("ldr_imm_add", "al r0 sp 0"),
("add_imm", "al r1 sp 4"),
("bl", "al expr:call:main"),
("movw", "al r7 1"),
("svc", "al 0"),
("ud2", "al")]:
HandleOpcode(mnemonic, ops.split(), unit)
unit.FunEnd()
If we add an opcode get_sp
, we could express this directly in Cwerg IR:
get_sp sp:A32
ld argc:U32 sp 0
lea argv:A32 sp 4
push argv
push argc
bsr main
poparg res:S32
pusharg res
bsr exit
trap
robertmuth commented
GETFP and GETSP were added recently to address this