From fd7c2d32cd764cc90e8a797b5e990204595d88d3 Mon Sep 17 00:00:00 2001 From: Danny Milosavljevic Date: Tue, 19 Feb 2019 13:02:47 +0100 Subject: [PATCH] ARM: Fix function calls. * lib/arm-mes/arm.M1: Delete "ret" macro. Fix "push___%ebp" macro. Add "pop____%lr" macro. Add "push___%lr" macro. Add "mov____%lr,%r9" macro. Add "mov____%r9,%pc" macro. * module/mescc/armv4/as.scm (armv4:function-preamble): Push lr, too. (armv4:ret): Pop lr, too. Return manually. --- lib/arm-mes/arm.M1 | 9 ++++++--- module/mescc/armv4/as.scm | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/arm-mes/arm.M1 b/lib/arm-mes/arm.M1 index f92eb463..ea72538d 100644 --- a/lib/arm-mes/arm.M1 +++ b/lib/arm-mes/arm.M1 @@ -84,6 +84,8 @@ DEFINE mov____%r0,(%r1) 000081e5 DEFINE mov____%r1,%r0 0100a0e1 DEFINE mov____%r1,%r2 0120a0e1 #DEFINE mov____%r1,0x32 xx +DEFINE mov____%lr,%r9 0e90a0e1 +DEFINE mov____%r9,%pc 09f0a0e1 # fp -> r0 DEFINE mov____%r11,%r0 0b00a0e1 @@ -126,6 +128,7 @@ DEFINE or_____%r1,%r0 010090e1 # orrs r0, r0, r1 DEFINE pop____%r0 04009de4 DEFINE pop____%r1 04109de4 DEFINE pop____%r3 04309de4 +DEFINE pop____%lr 04e09de4 # e59f9004 ldr r9, [pc, #4] ; c # e52d9004 push {r9} ; (str r9, [sp, #-4]!) @@ -136,14 +139,14 @@ DEFINE pop____%r3 04309de4 DEFINE push___$i32 04909fe504902de5000000ea DEFINE push___%r0 04002de5 # str r0, [sp, #-4]! -#DEFINE push___%ebp xx DEFINE push___%r1 04102de5 # str r1, [sp, #-4]! DEFINE push___%r2 04202de5 # str r2, [sp, #-4]! DEFINE push___%r3 04302de5 # str r3, [sp, #-4]! +DEFINE push___%lr 04e02de5 # str lr, [sp, #-4]! + #DEFINE push___(%r0) xx #DEFINE push___0x32(%ebp) xx #DEFINE push___0x8(%ebp) xx -DEFINE ret 4770 #e1a0f00e #DEFINE shl____$i8,%r0 xx # complicated encoding #DEFINE shl____$i8,%r1 xx # complicated encoding #DEFINE sub____$8,%r13 xx @@ -238,7 +241,7 @@ DEFINE SYS_getcwd b70090 DEFINE mov____%ebp,%r0 0b00a0e1 DEFINE mov____%ebp,%r1 0b10a0e1 -DEFINE push___%ebp 04002de5 # str r0, [sp, #-4]! +DEFINE push___%ebp 04b02de5 # str fp, [sp, #-4]! DEFINE pop____%ebp 04b09de4 # ldr fp, [sp], #4 DEFINE mov____%esp,%ebp 0db0a0e1 # mov fp, sp DEFINE mov____%ebp,%esp 0bd0a0e1 # mov sp, fp diff --git a/module/mescc/armv4/as.scm b/module/mescc/armv4/as.scm index 81cf6cbf..c7c7b92a 100644 --- a/module/mescc/armv4/as.scm +++ b/module/mescc/armv4/as.scm @@ -32,8 +32,9 @@ )) (define (armv4:function-preamble . rest) - "Note: Pretends to be on x86" - '(("push___%ebp") + "Note: Pretends to be on x86 a lot" + '(("push___%lr") + ("push___%ebp") ("mov____%esp,%ebp"))) (define (armv4:function-locals . rest) @@ -50,9 +51,12 @@ `(((#:immediate1 ,v) ,(string-append "mov____$i8,%" r))))) (define (armv4:ret . rest) + "Note: Pretends to be on x86 a lot" '(("mov____%ebp,%esp") ("pop____%ebp") - ("ret"))) + ("mov____%lr,%r9") + ("pop____%lr") + ("mov____%r9,%pc"))) (define (armv4:r-zero? info) (let ((r (get-r info)))