source: trunk/libs/newlib/src/libgloss/or1k/caches-asm.S @ 461

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

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

File size: 6.8 KB
Line 
1/* caches-asm.S -- cache manipulation for OpenRISC 1000.
2 *
3 * Copyright (c) 2011, 2014 Authors
4 *
5 * Contributor Julius Baxter <juliusbaxter@gmail.com>
6 * Contributor Stefan Wallentowitz <stefan.wallentowitz@tum.de>
7 *
8 * The authors hereby grant permission to use, copy, modify, distribute,
9 * and license this software and its documentation for any purpose, provided
10 * that existing copyright notices are retained in all copies and that this
11 * notice is included verbatim in any distributions. No written agreement,
12 * license, or royalty fee is required for any of the authorized uses.
13 * Modifications to this software may be copyrighted by their authors
14 * and need not follow the licensing terms described here, provided that
15 * the new terms are clearly indicated on the first page of each file where
16 * they apply.
17 */
18
19#include "include/or1k-asm.h"
20#include "include/or1k-sprs.h"
21
22/* -------------------------------------------------------------------------- */
23/*!Function used at reset to clear and enable all caches
24                                                                              */
25/* -------------------------------------------------------------------------- */
26        .global _or1k_cache_init
27        .type   _or1k_cache_init,@function
28
29_or1k_cache_init:
30        /* Instruction cache enable */
31        /* Check if IC present and skip enabling otherwise */
32        l.mfspr r3,r0,OR1K_SPR_SYS_UPR_ADDR
33        l.andi  r4,r3,OR1K_SPR_SYS_UPR_ICP_MASK
34        l.sfeq  r4,r0
35        OR1K_DELAYED_NOP(OR1K_INST(l.bf .Lnoic))
36
37        /* Disable IC */
38        l.mfspr r6,r0,OR1K_SPR_SYS_SR_ADDR
39        l.addi  r5,r0,-1
40        l.xori  r5,r5,OR1K_SPR_SYS_SR_ICE_MASK
41        l.and   r5,r6,r5
42        l.mtspr r0,r5,OR1K_SPR_SYS_SR_ADDR
43
44        /* Establish cache block size
45        If BS=0, 16;
46        If BS=1, 32;
47        r14 contain block size
48        */
49        l.mfspr r3,r0,OR1K_SPR_SYS_ICCFGR_ADDR
50        l.andi  r4,r3,OR1K_SPR_SYS_ICCFGR_CBS_MASK
51        l.srli  r7,r4,7
52        l.ori   r8,r0,16
53        l.sll   r14,r8,r7
54
55        /* Establish number of cache sets
56        r13 contains number of cache sets
57        r7 contains log(# of cache sets)
58        */
59        l.andi  r4,r3,OR1K_SPR_SYS_ICCFGR_NCS_MASK
60        l.srli  r7,r4,3
61        l.ori   r8,r0,1
62        l.sll   r13,r8,r7
63
64        /* Invalidate IC */
65        l.addi  r6,r0,0
66        l.sll   r5,r14,r7
67
68.Linvi: l.mtspr r0,r6,OR1K_SPR_ICACHE_ICBIR_ADDR
69        l.sfne  r6,r5
70        OR1K_DELAYED(
71                OR1K_INST(l.add r6,r6,r14),
72                OR1K_INST(l.bf  .Linvi)
73        )
74
75        /* Enable IC */
76        l.mfspr r6,r0,OR1K_SPR_SYS_SR_ADDR
77        l.ori   r6,r6,OR1K_SPR_SYS_SR_ICE_MASK
78        l.mtspr r0,r6,OR1K_SPR_SYS_SR_ADDR
79        l.nop
80        l.nop
81        l.nop
82        l.nop
83        l.nop
84        l.nop
85        l.nop
86        l.nop
87
88        /* Data cache enable */
89        /* Check if DC present and skip enabling otherwise */
90.Lnoic: l.mfspr r3,r0,OR1K_SPR_SYS_UPR_ADDR
91        l.andi  r4,r3,OR1K_SPR_SYS_UPR_DCP_MASK
92        l.sfeq  r4,r0
93        OR1K_DELAYED_NOP(OR1K_INST(l.bf .Lnodc))
94        /* Disable DC */
95        l.mfspr r6,r0,OR1K_SPR_SYS_SR_ADDR
96        l.addi  r5,r0,-1
97        l.xori  r5,r5,OR1K_SPR_SYS_SR_DCE_MASK
98        l.and   r5,r6,r5
99        l.mtspr r0,r5,OR1K_SPR_SYS_SR_ADDR
100        /* Establish cache block size
101           If BS=0, 16;
102           If BS=1, 32;
103           r14 contain block size */
104        l.mfspr r3,r0,OR1K_SPR_SYS_DCCFGR_ADDR
105        l.andi  r4,r3,OR1K_SPR_SYS_DCCFGR_CBS_MASK
106        l.srli  r7,r4,7
107        l.ori   r8,r0,16
108        l.sll   r14,r8,r7
109        /* Establish number of cache sets
110           r13 contains number of cache sets
111           r7 contains log(# of cache sets) */
112        l.andi  r4,r3,OR1K_SPR_SYS_ICCFGR_NCS_MASK
113        l.srli  r7,r4,3
114        l.ori   r8,r0,1
115        l.sll   r13,r8,r7
116        /* Invalidate DC */
117        l.addi  r6,r0,0
118        l.sll   r5,r14,r7
119
120.Linvd: l.mtspr r0,r6,OR1K_SPR_DCACHE_DCBIR_ADDR
121        l.sfne  r6,r5
122        OR1K_DELAYED(
123                OR1K_INST(l.add r6,r6,r14),
124                OR1K_INST(l.bf  .Linvd)
125        )
126        /* Enable DC */
127        l.mfspr r6,r0,OR1K_SPR_SYS_SR_ADDR
128        l.ori   r6,r6,OR1K_SPR_SYS_SR_DCE_MASK
129        l.mtspr r0,r6,OR1K_SPR_SYS_SR_ADDR
130
131.Lnodc:
132        /* Return */
133        OR1K_DELAYED_NOP(OR1K_INST(l.jr r9))
134
135/* -------------------------------------------------------------------------- */
136/*!Function to enable instruction cache
137                                                                              */
138/* -------------------------------------------------------------------------- */
139
140        .global or1k_icache_enable
141        .type   or1k_icache_enable,@function
142
143or1k_icache_enable:
144        /* Enable IC */
145        l.mfspr r13,r0,OR1K_SPR_SYS_SR_ADDR
146        l.ori   r13,r13,OR1K_SPR_SYS_SR_ICE_MASK
147        l.mtspr r0,r13,OR1K_SPR_SYS_SR_ADDR
148        l.nop
149        l.nop
150        l.nop
151        l.nop
152        l.nop
153        OR1K_DELAYED_NOP(OR1K_INST(l.jr r9))
154
155/* -------------------------------------------------------------------------- */
156/*!Function to disable instruction cache
157                                                                              */
158/* -------------------------------------------------------------------------- */
159        .global or1k_icache_disable
160        .type   or1k_icache_disable,@function
161
162or1k_icache_disable:
163        /* Disable IC */
164        l.mfspr r13,r0,OR1K_SPR_SYS_SR_ADDR
165        l.addi  r12,r0,-1
166        l.xori  r12,r12,OR1K_SPR_SYS_SR_ICE_MASK
167        l.and   r12,r13,r12
168        l.mtspr r0,r12,OR1K_SPR_SYS_SR_ADDR
169        OR1K_DELAYED_NOP(OR1K_INST(l.jr r9))
170
171/* -------------------------------------------------------------------------- */
172/*!Function to flush address of instruction cache
173                                                                              */
174/* -------------------------------------------------------------------------- */
175        .global or1k_icache_flush
176        .type   or1k_icache_flush,@function
177
178or1k_icache_flush:
179        OR1K_DELAYED(
180                OR1K_INST(l.mtspr r0,r3,OR1K_SPR_ICACHE_ICBIR_ADDR),
181                /* Push r3 into IC invalidate reg */
182                OR1K_INST(l.jr    r9)
183        )
184
185
186/* -------------------------------------------------------------------------- */
187/*!Function to enable data cache
188                                                                              */
189/* -------------------------------------------------------------------------- */
190        .global or1k_dcache_enable
191        .type   or1k_dcache_enable,@function
192
193or1k_dcache_enable:
194        /* Enable DC */
195        l.mfspr r13,r0,OR1K_SPR_SYS_SR_ADDR
196        l.ori   r13,r13,OR1K_SPR_SYS_SR_DCE_MASK
197        l.mtspr r0,r13,OR1K_SPR_SYS_SR_ADDR
198        l.nop
199        l.nop
200        l.nop
201        l.nop
202        l.nop
203        OR1K_DELAYED_NOP(OR1K_INST(l.jr r9))
204
205/* -------------------------------------------------------------------------- */
206/*!Function to disable data cache
207                                                                              */
208/* -------------------------------------------------------------------------- */
209        .global or1k_dcache_disable
210        .type   or1k_dcache_disable,@function
211
212or1k_dcache_disable:
213        /* Disable DC */
214        l.mfspr r13,r0,OR1K_SPR_SYS_SR_ADDR
215        l.addi  r12,r0,-1
216        l.xori  r12,r12,OR1K_SPR_SYS_SR_DCE_MASK
217        l.and   r12,r13,r12
218        l.mtspr r0,r12,OR1K_SPR_SYS_SR_ADDR
219        OR1K_DELAYED_NOP(OR1K_INST(l.jr r9))
220
221/* -------------------------------------------------------------------------- */
222/*!Function to flush address of data cache
223                                                                              */
224/* -------------------------------------------------------------------------- */
225        .global or1k_dcache_flush
226        .type   or1k_dcache_flush,@function
227
228or1k_dcache_flush:
229        OR1K_DELAYED(
230                OR1K_INST(l.mtspr r0,r3,OR1K_SPR_DCACHE_DCBIR_ADDR),
231                /* Push r3 into DC invalidate reg */
232                OR1K_INST(l.jr    r9)
233        )
Note: See TracBrowser for help on using the repository browser.