More work on neatening code
[tpg/acess2.git] / Usermode / Libraries / ld-acess.so_src / arch / armv7.S.h
1 //
2 // Acess2 ARMv7 - System Calls
3 //
4
5 .globl _start
6 .extern SoMain
7 _start:
8         pop {r0}
9         ldm sp, {r1,r2,r3}
10         bl SoMain
11         
12         mov r4, r0
13
14         pop {r0,r1,r2}
15         blx r4
16         
17         b _exit
18
19 @ Stupid GCC
20 .globl __ucmpdi2
21 __ucmpdi2:
22         cmp r0, r2
23         movmi r0, #0
24         movmi pc, lr
25         movhi r0, #2
26         movhi pc, lr
27         cmp r1, r2
28         movmi r0, #0
29         movmi pc, lr
30         movhi r0, #2
31         movhi pc, lr
32         mov r0, #1
33         mov pc, lr
34
35 @ Well, can't blame it
36 @ - Clear the instruction cache
37 .globl __clear_cache
38 __clear_cache:
39         svc #0x1001
40         mov pc, lr
41
42 @ DEST
43 @ SRC
44 @_memcpy:
45 @       push rbp
46 @       mov rbp, rsp
47 @       
48 @       ; RDI - First Param
49 @       ; RSI - Second Param
50 @       mov rcx, rdx    ; RDX - Third
51 @       rep movsb
52 @       
53 @       pop rbp
54 @       ret
55 @
56 .globl _errno
57 _errno: .long   0       @ Placed in .text, to allow use of relative addressing
58
59 .macro syscall0 _name, _num     
60 .globl \_name
61 \_name:
62         push {lr}
63         svc #\_num
64         str r2, _errno
65         pop {pc}
66 .endm
67
68 .macro syscall5 _name, _num
69 .globl \_name
70 \_name:
71         push {r4, lr}
72         ldr r4, [sp,#8]
73         svc #\_num
74         str r2, _errno
75         pop {r4, pc}
76 .endm
77
78 .macro syscall6 _name, _num
79 .globl \_name
80 \_name:
81         push {r4,r5,lr}
82         ldr r4, [sp,#12]
83         ldr r5, [sp,#16]
84         svc #\_num
85         str r2, _errno
86         pop {r4,r5,pc}
87 .endm
88
89 #define SYSCALL0(_name,_num)    syscall0 _name, _num
90 #define SYSCALL1(_name,_num)    SYSCALL0(_name, _num)
91 #define SYSCALL2(_name,_num)    SYSCALL0(_name, _num)
92 #define SYSCALL3(_name,_num)    SYSCALL0(_name, _num)
93 #define SYSCALL4(_name,_num)    SYSCALL0(_name, _num)
94 // TODO: 5/6 need special handling, because the args are on the stack
95 #define SYSCALL5(_name,_num)    syscall5 _name, _num
96 #define SYSCALL6(_name,_num)    syscall6 _name, _num
97
98 // Override the clone syscall
99 #define _exit   _exit_raw
100 #define _clone  _clone_raw
101 #include "syscalls.s.h"
102 #undef _exit
103 #undef _clone
104
105 .globl _clone
106 _clone:
107         push {r4}
108         mov r4, r1
109         svc #SYS_CLONE
110         str r2, _errno
111         tst r4, r4
112         beq _clone_ret
113         @ If in child, set SP
114         tst r0,r0
115         movne sp, r4
116 _clone_ret:
117         pop {r4}
118         mov pc, lr
119
120 .globl _exit
121 _exit:
122         svc #0
123         b .
124

UCC git Repository :: git.ucc.asn.au