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

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