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

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