source: trunk/libs/newlib/src/libgloss/or1k/sync-asm.S @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.9 KB
Line 
1#include "include/or1k-asm.h"
2#include "include/or1k-sprs.h"
3
4        .section .text
5
6
7        .global or1k_has_multicore_support
8        .type   or1k_has_multicore_support,@function
9or1k_has_multicore_support:
10#ifdef __OR1K_MULTICORE__
11        // Return 1
12        OR1K_DELAYED(
13                OR1K_INST(l.ori r11,r0,1),
14                OR1K_INST(l.jr  r9)
15        )
16#else
17        // Return 0
18        OR1K_DELAYED(
19                OR1K_INST(l.or r11,r0,r0),
20                OR1K_INST(l.jr r9)
21        )
22#endif
23
24        .global or1k_coreid
25        .type   or1k_coreid,@function
26or1k_coreid:
27#ifdef __OR1K_MULTICORE__
28        // Return SPR with core identifier
29        OR1K_DELAYED(
30                OR1K_INST(l.mfspr r11,r0,OR1K_SPR_SYS_COREID_ADDR),
31                OR1K_INST(l.jr    r9)
32        )
33#else
34        // Return 0
35        OR1K_DELAYED(
36                OR1K_INST(l.or r11,r0,r0),
37                OR1K_INST(l.jr r9)
38        )
39#endif
40
41        .global or1k_numcores
42        .type   or1k_numcores,@function
43or1k_numcores:
44#ifdef __OR1K_MULTICORE__
45        // Return SPR with number of cores
46        OR1K_DELAYED(
47                OR1K_INST(l.mfspr r11,r0,OR1K_SPR_SYS_NUMCORES_ADDR),
48                OR1K_INST(l.jr    r9)
49        )
50#else
51        // Return 1
52        OR1K_DELAYED(
53                OR1K_INST(l.ori r11,r0,1),
54                OR1K_INST(l.jr r9)
55        )
56#endif
57
58        .global or1k_sync_ll
59        .type   or1k_sync_ll,@function
60or1k_sync_ll:
61#ifdef __OR1K_MULTICORE__
62        // Load word atomic
63        OR1K_DELAYED(
64                OR1K_INST(l.lwa r11, 0(r3)),
65                OR1K_INST(l.jr  r9)
66        )
67#else
68        // Simply load word, TODO: throw exception? which?
69        OR1K_DELAYED(
70                OR1K_INST(l.lwz r11, 0(r3)),
71                OR1K_INST(l.jr  r9)
72        )
73#endif
74
75        .global or1k_sync_sc
76        .type   or1k_sync_sc,@function
77or1k_sync_sc:
78#ifdef __OR1K_MULTICORE__
79        // swa sets the flag if it was succesfull
80        // Store the value to address and set flag
81        l.swa 0(r3),r4
82        OR1K_DELAYED(
83                // Set return to success speculatively (may go to delay slot)
84                OR1K_INST(l.ori r11,r0,1),
85                // If the swa was successfull, jump to end
86                OR1K_INST(l.bf  .or1k_sync_sc_done)
87        )
88        // If the swa was not successfull, set
89        l.or r11,r0,r0
90.or1k_sync_sc_done:
91        OR1K_DELAYED_NOP(OR1K_INST(l.jr r9))
92#else
93        // Simply store word, TODO: throw exception? which?
94        OR1K_DELAYED(
95                OR1K_INST(l.sw 0(r3),r4),
96                OR1K_INST(l.jr r9)
97        )
98#endif
99
100
101        .global or1k_sync_cas
102        .type   or1k_sync_sc,@function
103or1k_sync_cas:
104#ifdef __OR1K_MULTICORE__
105        /* Load linked address value to return register */
106        l.lwa   r11,0(r3)
107        /* Compare value to parameter */
108        l.sfeq  r11,r4
109        /* If not equal: abort and return the read value */
110        OR1K_DELAYED_NOP(OR1K_INST(l.bnf .or1k_sync_cas_done))
111        /* If compare was successfull: try writing */
112        l.swa   0(r3),r5
113        /* If writing was not successful: restart */
114        OR1K_DELAYED_NOP(OR1K_INST(l.bnf or1k_sync_cas))
115.or1k_sync_cas_done:
116        /* Return value is the original read value */
117        OR1K_DELAYED_NOP(OR1K_INST(l.jr r9))
118#else
119        // Non-atomic CAS, TODO: throw exception? which?
120        l.lwz   r11,0(r3)
121        l.sfeq  r11,r4
122        OR1K_DELAYED_NOP(OR1K_INST(l.bnf .or1k_sync_cas_done))
123        l.sw    0(r3),r5
124.or1k_sync_cas_done:
125        OR1K_DELAYED_NOP(OR1K_INST(l.jr r9))
126#endif
127
128        .global or1k_sync_tsl
129        .type   or1k_sync_tsl,@function
130or1k_sync_tsl:
131        l.or    r4,r0,r0
132        OR1K_DELAYED(
133                OR1K_INST(l.addi r5,r0,1),
134                OR1K_INST(l.j    or1k_sync_cas)
135        )
Note: See TracBrowser for help on using the repository browser.