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

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