Merge remote-tracking branch 'nsz/math'
[musl] / src / thread / powerpc / syscall_cp.s
1 #r0: volatile. may be modified during linkage.
2 #r1: stack frame: 16 byte alignment.
3 #r2: tls/thread pointer on pp32
4 #r3,r4: return values, first args
5 #r5-r10: args
6 #r11-r12: volatile. may be modified during linkage
7 #r13: "small data area" pointer
8 #r14 - r30: local vars
9 #r31: local or environment pointer
10
11 #r1, r14-31: belong to the caller, must be saved and restored
12 #r0, r3-r12, ctr, xer: volatile, not preserved
13 #r0,r11,r12: may be altered by cross-module call, 
14 #"a func cannot depend on that these regs have the values placed by the caller"
15
16 #the fields CR2,CR2,CR4 of the cond reg must be preserved
17 #LR (link reg) shall contain the funcs return address
18         .text
19         .global __syscall_cp_asm
20         .type   __syscall_cp_asm,%function
21 __syscall_cp_asm:
22         # at enter: r3 = pointer to self->cancel, r4: syscall no, r5: first arg, r6: 2nd, r7: 3rd, r8: 4th, r9: 5th, r10: 6th
23         .global __cp_begin
24 __cp_begin:
25         # r3 holds first argument, its a pointer to self->cancel. 
26         # we must compare the dereferenced value with 0 and jump to __cancel if its not
27         
28         lwz 0, 0(3) #deref pointer into r0
29         
30         cmpwi cr7, 0, 0 #compare r0 with 0, store result in cr7. 
31         beq+ cr7, 1f #jump to label 1 if r0 was 0
32         
33         b __cancel #else call cancel 
34         # (the return address is not needed, since __cancel never returns)
35 1:
36         #ok, the cancel flag was not set
37         # syscall: number goes to r0, the rest 3-8
38         mr      0, 4                  # put the system call number into r0
39         mr      3, 5                  # Shift the arguments: arg1
40         mr      4, 6                  # arg2
41         mr      5, 7                  # arg3
42         mr      6, 8                  # arg4
43         mr      7, 9                  # arg5
44         mr      8, 10                  # arg6
45         sc
46         .global __cp_end
47 __cp_end:
48         bnslr+ # return if no summary overflow. 
49         #else negate result.
50         neg 3, 3
51         blr