plan9fox/sys/src/libc/amd64/main9p.s
cinap_lenrek 2c5c784255 prof: properly save and restore RARG for amd64
amd64 passes first argument in RARG (BP) register
which has the be preserved duing _profin() and
_profout() calls. to handle this we introduce
_saveret() and _savearg(). _saveret() returns
AX, _savearg() returns RARG (BP). for archs other
and amd64, _saveret() and _savearg() are the
same function, doing nothing.

restoing works with dummy function:

uintptr
_restore(uintptr, uintptr ret)
{
	return ret;
}

...

ret = _saveret();
arg = _savearg();
...
return _restore(arg, ret);

as we pass arg as the first argument, RARG (BP) is
restored.
2014-02-17 13:25:24 +01:00

39 lines
735 B
ArmAsm

#define NPRIVATES 16
TEXT _mainp(SB), 1, $(2*8+NPRIVATES*8)
MOVQ AX, _tos(SB) /* _tos = arg */
LEAQ 16(SP), AX
MOVQ AX, _privates(SB)
MOVL $NPRIVATES, _nprivates(SB)
CALL _profmain(SB) /* _profmain(); */
MOVQ _tos+0(SB), DX /* _tos->prof.pp = _tos->prof.next; */
MOVQ 8(DX), CX
MOVQ CX, (DX)
MOVL inargc-8(FP), RARG /* main(argc, argv); */
LEAQ inargv+0(FP), AX
MOVQ AX, 8(SP)
CALL main(SB)
loop:
MOVQ $_exits<>(SB), RARG
CALL exits(SB)
MOVQ $_profin(SB), AX /* force loading of profile */
JMP loop
TEXT _savearg(SB), 1, $0
MOVQ RARG, AX
RET
TEXT _saveret(SB), 1, $0
RET /* we want RARG in RARG */
TEXT _callpc(SB), 1, $0
MOVQ 8(RARG), AX
RET
DATA _exits<>+0(SB)/4, $"main"
GLOBL _exits<>+0(SB), $5