Usermode/ld-acess - Sorting and improvements to ld-acess
[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         svc #\_num
64         str r2, _errno
65         mov pc, lr
66 .endm
67
68 .macro syscall5 _name, _num
69 .globl \_name
70 \_name:
71         push {r4}
72         ldr r4, [sp,#4]
73         svc #\_num
74         str r2, _errno
75         pop {r4}
76         mov pc, lr
77 .endm
78
79 .macro syscall6 _name, _num
80 .globl \_name
81 \_name:
82         push {r4,r5}
83         ldr r4, [sp,#8]
84         ldr r5, [sp,#12]
85         svc #\_num
86         str r2, _errno
87         pop {r4,r5}
88         mov pc, lr
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