Don't mess up the stack pointer, wtf is this calling convention

This commit is contained in:
Artemis Tosini 2023-10-21 22:13:38 +00:00
parent a08c65d942
commit f23416a40c
Signed by: artemist
GPG key ID: EE5227935FE3FF18
4 changed files with 128 additions and 32 deletions

View file

@ -42,8 +42,8 @@
#define SYS_fchmodat 53 #define SYS_fchmodat 53
// CONSTANT SYS_faccessat 48 // CONSTANT SYS_faccessat 48
#define SYS_faccessat 48 #define SYS_faccessat 48
// CONSTANT SYS_brk 234 // CONSTANT SYS_brk 214
#define SYS_brk 234 #define SYS_brk 214
// CONSTANT SYS_ioctl 29 // CONSTANT SYS_ioctl 29
#define SYS_ioctl 29 #define SYS_ioctl 29
// CONSTANT SYS_fsync 82 // CONSTANT SYS_fsync 82

View file

@ -22,9 +22,20 @@
void void
_write () _write ()
{ {
asm ("POP_X2"); asm ("SET_X0_FROM_BP");
asm ("POP_X1"); asm ("SUB_X0_24");
asm ("POP_X0"); asm ("DEREF_X0");
asm ("SET_X2_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SET_X1_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_TO_SYS_WRITE"); asm ("SET_X8_TO_SYS_WRITE");
asm ("SYSCALL"); asm ("SYSCALL");
} }

View file

@ -26,59 +26,148 @@ int errno;
int int
__sys_call (int sys_call) __sys_call (int sys_call)
{ {
asm ("POP_X8"); asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_FROM_X0");
asm ("SYSCALL"); asm ("SYSCALL");
} }
int int
__sys_call1 (int sys_call, int one) __sys_call1 (int sys_call, int one)
{ {
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X8_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("POP_X0");
asm ("POP_X8");
asm ("SYSCALL"); asm ("SYSCALL");
} }
int int
__sys_call2 (int sys_call, int one, int two) __sys_call2 (int sys_call, int one, int two)
{ {
asm ("POP_X1"); asm ("SET_X0_FROM_BP");
asm ("POP_X0"); asm ("SUB_X0_8");
asm ("POP_X8"); asm ("DEREF_X0");
asm ("SET_X8_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X1_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SYSCALL"); asm ("SYSCALL");
} }
int int
__sys_call3 (int sys_call, int one, int two, int three) __sys_call3 (int sys_call, int one, int two, int three)
{ {
asm ("POP_X2"); asm ("SET_X0_FROM_BP");
asm ("POP_X1"); asm ("SUB_X0_8");
asm ("POP_X0"); asm ("DEREF_X0");
asm ("POP_X8"); asm ("SET_X8_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X2_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X1_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SYSCALL"); asm ("SYSCALL");
} }
int int
__sys_call4 (int sys_call, int one, int two, int three, int four) __sys_call4 (int sys_call, int one, int two, int three, int four)
{ {
asm ("POP_X3"); asm ("SET_X0_FROM_BP");
asm ("POP_X2"); asm ("SUB_X0_8");
asm ("POP_X1"); asm ("DEREF_X0");
asm ("POP_X0"); asm ("SET_X8_FROM_X0");
asm ("POP_X8");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SET_X3_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X2_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X1_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SYSCALL"); asm ("SYSCALL");
} }
int int
__sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six) __sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
{ {
asm ("POP_X5"); asm ("SET_X0_FROM_BP");
asm ("POP_X4"); asm ("SUB_X0_8");
asm ("POP_X3"); asm ("DEREF_X0");
asm ("POP_X2"); asm ("SET_X8_FROM_X0");
asm ("POP_X1");
asm ("POP_X0"); asm ("SET_X0_FROM_BP");
asm ("POP_X8"); asm ("SUB_X0_24");
asm ("SUB_X0_24");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X5_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X4_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SET_X3_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("SUB_X0_8");
asm ("DEREF_X0");
asm ("SET_X2_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_24");
asm ("DEREF_X0");
asm ("SET_X1_FROM_X0");
asm ("SET_X0_FROM_BP");
asm ("SUB_X0_16");
asm ("DEREF_X0");
asm ("SYSCALL"); asm ("SYSCALL");
} }

View file

@ -26,11 +26,6 @@ DEFINE PUSH_LR 5e8e1ff8
DEFINE POP_X0 408640f8 DEFINE POP_X0 408640f8
DEFINE POP_X1 418640f8 DEFINE POP_X1 418640f8
DEFINE POP_X2 428640f8
DEFINE POP_X3 438640f8
DEFINE POP_X4 448640f8
DEFINE POP_X5 458640f8
DEFINE POP_X8 488640f8
DEFINE POP_X16 508640f8 DEFINE POP_X16 508640f8
DEFINE POP_BP 518640f8 DEFINE POP_BP 518640f8
DEFINE POP_LR 5e8640f8 DEFINE POP_LR 5e8640f8
@ -93,6 +88,7 @@ DEFINE SET_X3_FROM_X0 e30300aa
DEFINE SET_X4_FROM_X0 e40300aa DEFINE SET_X4_FROM_X0 e40300aa
DEFINE SET_X5_FROM_X0 e50300aa DEFINE SET_X5_FROM_X0 e50300aa
DEFINE SET_X6_FROM_X0 e60300aa DEFINE SET_X6_FROM_X0 e60300aa
DEFINE SET_X8_FROM_X0 e80300aa
DEFINE SET_X16_FROM_X0 f00300aa DEFINE SET_X16_FROM_X0 f00300aa
DEFINE SET_X16_FROM_SP f00312aa DEFINE SET_X16_FROM_SP f00312aa
DEFINE SET_BP_FROM_X16 f10310aa DEFINE SET_BP_FROM_X16 f10310aa