85a3ac69bc6704ceb594a3d78a7f81c7f222c9f4
[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 @ DEST
37 @ SRC
38 @_memcpy:
39 @       push rbp
40 @       mov rbp, rsp
41 @       
42 @       ; RDI - First Param
43 @       ; RSI - Second Param
44 @       mov rcx, rdx    ; RDX - Third
45 @       rep movsb
46 @       
47 @       pop rbp
48 @       ret
49 @
50 .globl _errno
51 _errno: .long   0       @ Placed in .text, to allow use of relative addressing
52
53 .macro syscall0 _name, _num     
54 .globl \_name
55 \_name:
56         svc #\_num
57         str r2, _errno
58         mov pc, lr
59 .endm
60
61 .macro syscall5 _name, _num
62 .globl \_name
63 \_name:
64         push {r4}
65         ldr r4, [sp,#4]
66         svc #\_num
67         str r2, _errno
68         pop {r4}
69         mov pc, lr
70 .endm
71
72 .macro syscall6 _name, _num
73 .globl \_name
74 \_name:
75         push {r4,r5}
76         ldr r4, [sp,#8]
77         ldr r5, [sp,#12]
78         svc #\_num
79         str r2, _errno
80         pop {r4,r5}
81         mov pc, lr
82 .endm
83
84 #define SYSCALL0(_name,_num)    syscall0 _name, _num
85 #define SYSCALL1(_name,_num)    SYSCALL0(_name, _num)
86 #define SYSCALL2(_name,_num)    SYSCALL0(_name, _num)
87 #define SYSCALL3(_name,_num)    SYSCALL0(_name, _num)
88 #define SYSCALL4(_name,_num)    SYSCALL0(_name, _num)
89 // TODO: 5/6 need special handling, because the args are on the stack
90 #define SYSCALL5(_name,_num)    syscall5 _name, _num
91 #define SYSCALL6(_name,_num)    syscall6 _name, _num
92
93 // Override the clone syscall
94 #define _exit   _exit_raw
95 #define _clone  _clone_raw
96 #include "syscalls.s.h"
97 #undef _exit
98 #undef _clone
99
100 .globl _clone
101 _clone:
102         push {r4}
103         mov r4, r1
104         svc #SYS_CLONE
105         str r2, _errno
106         tst r4, r4
107         beq _clone_ret
108         @ If in child, set SP
109         tst r0,r0
110         movne sp, r4
111 _clone_ret:
112         pop {r4}
113         mov pc, lr
114
115 .globl _exit
116 _exit:
117         svc #0
118         b .
119

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