OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [tests/] [or1200/] [sim/] [or1200-ticksyscall.S] - Blame information for rev 425

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 349 julius
#include "spr-defs.h"
2
#include "board.h"
3
 
4
/*
5
 
6
        Tick timer and system call simultaneous interrupt test
7
 
8
        Within the test we'll use following global variables:
9
 
10
        r15 syscall interrupt counter
11
        r16 syscall function counter
12
        r17 timer interrupt counter
13
 
14
 
15
        The test do the following:
16
        Setup tick interrupts to occur regularly, and then do a bunch of l.sys
17
        systems calls, checking that they all occur OK
18
 
19
        Julius Baxter, julius@opencores.org
20
*/
21
//////////////////////////////////////////////////////////////////////
22
////                                                              ////
23
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
24
////                                                              ////
25
//// This source file may be used and distributed without         ////
26
//// restriction provided that this copyright statement is not    ////
27
//// removed from the file and that any derivative work contains  ////
28
//// the original copyright notice and the associated disclaimer. ////
29
////                                                              ////
30
//// This source file is free software; you can redistribute it   ////
31
//// and/or modify it under the terms of the GNU Lesser General   ////
32
//// Public License as published by the Free Software Foundation; ////
33
//// either version 2.1 of the License, or (at your option) any   ////
34
//// later version.                                               ////
35
////                                                              ////
36
//// This source is distributed in the hope that it will be       ////
37
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
38
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
39
//// PURPOSE.  See the GNU Lesser General Public License for more ////
40
//// details.                                                     ////
41
////                                                              ////
42
//// You should have received a copy of the GNU Lesser General    ////
43
//// Public License along with this source; if not, download it   ////
44
//// from http://www.opencores.org/lgpl.shtml                     ////
45
////                                                              ////
46
//////////////////////////////////////////////////////////////////////
47
 
48
#define TICK_COUNTER_VALUE 8
49
 
50
 
51
 
52
/* =================================================== [ exceptions ] === */
53
        .section .vectors, "ax"
54
 
55
 
56
/* ---[ 0x100: RESET exception ]----------------------------------------- */
57
        .org 0x100
58
        l.movhi r0, 0
59
        /* Clear status register */
60
        l.ori   r1, r0, SPR_SR_SM
61
        l.mtspr r0, r1, SPR_SR
62
        /* Clear timer  */
63
        l.mtspr r0, r0, SPR_TTMR
64
        /* Init the stack */
65
        .global _stack
66
        l.movhi r1, hi(_stack)
67
        l.ori   r1, r1, lo(_stack)
68
        l.addi  r2, r0, -3
69
        l.and   r1, r1, r2
70
        /* Jump to program initialisation code */
71
        .global _start
72
        l.movhi r4, hi(_start)
73
        l.ori   r4, r4, lo(_start)
74
        l.jr    r4
75
        l.nop
76
 
77
 
78
/* =================================================== [ tick interrupt ] === */
79
        .org 0x500
80
        .global _tick_handler
81
_tick_handler:
82
        l.addi r17, r17, 1
83
# Set r7 to hold value of TTMR, one-shot mode/single run (SR)
84
        l.addi r5, r0, TICK_COUNTER_VALUE /* Tick timer counter value */
85
        l.movhi r6,hi(SPR_TTMR_SR | SPR_TTMR_IE)
86
        l.add  r7,r5,r6
87
        /* Report values , 0x00000500 == tick timer report*/
88
        l.ori r3, r0, 0x0500
89
        l.nop 2
90
        l.or r3, r0, r17
91
        l.nop 2
92
# Init the tick timer
93
        l.mtspr r0,r0,SPR_TTCR          # clear TTCR
94
        l.mtspr r0,r7,SPR_TTMR          # set TTMR
95
        l.rfe
96
 
97
/* ========================================================= [ syscall ] === */
98
        .org 0xC00
99
        .extern _syscall_function
100
        .global _syscall_handler
101
_syscall_handler:
102
        l.addi r15, r15, 1
103
        l.mfspr r7, r0, SPR_ESR_BASE /* Put ESR in r7, set back to ESR later */
104
        l.mfspr r8, r0, SPR_EPCR_BASE/* Put EPCR in r8,set back to EPCR later*/
105
        /* Unset IEE and TEE bits of SR */
106
        l.ori r4, r0, SPR_SR_IEE|SPR_SR_TEE
107
        l.ori r5, r0, 0xffff
108
        l.xor r5, r5, r4
109
        l.and r5, r7, r5 /* New SR without interrupt bits set */
110
        l.mtspr r0, r5, SPR_ESR_BASE /* SR after l.rfe */
111
        /* Report values , 0x00000c00 == tick timer report*/
112
        l.ori r3, r0, 0x0c00
113
        l.nop 2
114
        /* Get syscall number */
115
        l.lwz r3, -4(r8) /* r8 = load(EPCR-4)= PC of l.sys that caused this */
116
        l.andi r3, r3, 0xffff /* get 16-bit immediate syscall number */
117
        l.nop 2
118
        l.movhi r4, hi(_syscall_function)
119
        l.ori r4, r4, lo(_syscall_function)
120
        l.mtspr r0, r4, SPR_EPCR_BASE
121
        l.rfe
122
 
123
 
124
 
125
/* =================================================== [ text section ] === */
126
        .section  .text
127
 
128
/* =================================================== [ start ] === */
129
 
130
        .global _start
131
_start:
132
 
133
        /* Instruction cache enable */
134
        /* Check if IC present and skip enabling otherwise */
135
        l.mfspr r24,r0,SPR_UPR
136
        l.andi  r26,r24,SPR_UPR_ICP
137
        l.sfeq  r26,r0
138
        l.bf    .L8
139
        l.nop
140
 
141
        /* Disable IC */
142
        l.mfspr r6,r0,SPR_SR
143
        l.addi  r5,r0,-1
144
        l.xori  r5,r5,SPR_SR_ICE
145
        l.and   r5,r6,r5
146
        l.mtspr r0,r5,SPR_SR
147
 
148
        /* Establish cache block size
149
        If BS=0, 16;
150
        If BS=1, 32;
151
        r14 contain block size
152
        */
153
        l.mfspr r24,r0,SPR_ICCFGR
154
        l.andi  r26,r24,SPR_ICCFGR_CBS
155
        l.srli  r28,r26,7
156
        l.ori   r30,r0,16
157
        l.sll   r14,r30,r28
158
 
159
        /* Establish number of cache sets
160
        r16 contains number of cache sets
161
        r28 contains log(# of cache sets)
162
        */
163
        l.andi  r26,r24,SPR_ICCFGR_NCS
164
        l.srli  r28,r26,3
165
        l.ori   r30,r0,1
166
        l.sll   r16,r30,r28
167
 
168
        /* Invalidate IC */
169
        l.addi  r6,r0,0
170
        l.sll   r5,r14,r28
171
 
172
.L7:
173
        l.mtspr r0,r6,SPR_ICBIR
174
        l.sfne  r6,r5
175
        l.bf    .L7
176
        l.add   r6,r6,r14
177
 
178
        /* Enable IC */
179
        l.mfspr r6,r0,SPR_SR
180
        l.ori   r6,r6,SPR_SR_ICE
181
        l.mtspr r0,r6,SPR_SR
182
        l.nop
183
        l.nop
184
        l.nop
185
        l.nop
186
        l.nop
187
        l.nop
188
        l.nop
189
        l.nop
190
 
191
.L8:
192
        /* Data cache enable */
193
        /* Check if DC present and skip enabling otherwise */
194
        l.mfspr r24,r0,SPR_UPR
195
        l.andi  r26,r24,SPR_UPR_DCP
196
        l.sfeq  r26,r0
197
        l.bf    .L10
198
        l.nop
199
        /* Disable DC */
200
        l.mfspr r6,r0,SPR_SR
201
        l.addi  r5,r0,-1
202
        l.xori  r5,r5,SPR_SR_DCE
203
        l.and   r5,r6,r5
204
        l.mtspr r0,r5,SPR_SR
205
        /* Establish cache block size
206
           If BS=0, 16;
207
           If BS=1, 32;
208
           r14 contain block size
209
        */
210
        l.mfspr r24,r0,SPR_DCCFGR
211
        l.andi  r26,r24,SPR_DCCFGR_CBS
212
        l.srli  r28,r26,7
213
        l.ori   r30,r0,16
214
        l.sll   r14,r30,r28
215
        /* Establish number of cache sets
216
           r16 contains number of cache sets
217
           r28 contains log(# of cache sets)
218
        */
219
        l.andi  r26,r24,SPR_DCCFGR_NCS
220
        l.srli  r28,r26,3
221
        l.ori   r30,r0,1
222
        l.sll   r16,r30,r28
223
        /* Invalidate DC */
224
        l.addi  r6,r0,0
225
        l.sll   r5,r14,r28
226
.L9:
227
        l.mtspr r0,r6,SPR_DCBIR
228
        l.sfne  r6,r5
229
        l.bf    .L9
230
        l.add   r6,r6,r14
231
        /* Enable DC */
232
        l.mfspr r6,r0,SPR_SR
233
        l.ori   r6,r6,SPR_SR_DCE
234
        l.mtspr r0,r6,SPR_SR
235
.L10:
236
 
237
        // Kick off test
238
        l.jal   _main
239
        l.nop
240
 
241
/* =================================================== [ main ] === */
242
.global _main
243
_main:
244
        l.movhi r15, 0
245
        l.movhi r16, 0
246
        l.movhi r17, 0
247
 
248
        #
249
        # unmask all ints
250
        #
251
        l.movhi r5,0xffff
252
        l.ori   r5,r5,0xffff
253
        l.mtspr r0,r5,SPR_PICMR         # set PICMR
254
 
255
        # Set r20 to hold enable exceptions and interrupts
256
        l.mfspr r20,r0,SPR_SR
257
        l.ori r20,r20,SPR_SR_SM|SPR_SR_TEE
258
 
259
        # Enable exceptions and interrupts
260
        l.mtspr r0,r20,SPR_SR   # set SR
261
 
262
        # Set r7 to hold value of TTMR, one-shot mode/single run (SR)
263
        l.addi r5, r0, TICK_COUNTER_VALUE /* Tick timer counter value */
264
        l.movhi r6,hi(SPR_TTMR_SR | SPR_TTMR_IE)
265
        l.add  r7,r5,r6
266
 
267
        # Init the tick timer
268
        l.mtspr r0,r0,SPR_TTCR          # clear TTCR
269
        l.mtspr r0,r7,SPR_TTMR          # set TTMR
270
 
271
_wait_loop:
272
        l.sfeqi r17, 0x10
273
        l.bnf _wait_loop
274
        l.nop
275
 
276
        /* Timer is working, let's start with some syscalls */
277
        /* These should occur before tick timer's cycle is up */
278
        l.nop
279
        l.sys 0x1
280
        l.nop
281
        l.sys 0x2
282
        l.nop
283
        l.sys 0x3
284
        l.nop
285
        l.sys 0x4
286
        l.nop
287
        l.sys 0x5
288
        l.nop
289
        l.sfnei r16, 0xf /* Should equal 15, 0xf */
290
        l.bf _fail
291
        l.nop
292
        /* Continue, hopefuly now intercept tick timer cycles */
293
        l.nop
294
        l.nop
295
        l.sys 0x6
296
        l.nop
297
        l.nop
298
        l.nop
299
        l.nop
300
        l.sys 0x7
301
        l.nop
302
        l.nop
303
        l.sys 0x8
304
        l.nop
305
        l.nop
306
        l.sys 0x9
307
        l.nop
308
        l.nop
309
        l.sys 0xa
310
        l.nop
311
        l.nop
312
        l.nop
313
        l.sys 0xb
314
        l.nop
315
        l.nop
316
        l.nop
317
        l.nop
318
        l.sys 0xc
319
        l.nop
320
        l.nop
321
        l.sys 0xd
322
        l.nop
323
        l.nop
324
        l.sys 0xe
325
        l.nop
326
        l.nop
327
        l.sys 0xf
328
        l.nop
329
        /* Now turn off tick timer */
330
        l.mtspr r0,r0,SPR_TTMR          # clear TTMR
331
        l.sfnei r16, 0x78 /* Should equal 120, 0x78 */
332
        l.bf _fail
333
        l.nop
334
        l.movhi r3, hi(0x8000000d)
335
        l.ori r3, r3, lo(0x8000000d)
336 425 julius
        l.nop 2
337
        l.ori r3, r0, 0
338 349 julius
        l.nop 1
339
 
340
_fail:
341
        l.movhi r3, hi(0xbaaaaaad)
342
        l.ori r3, r3, lo(0xbaaaaaad)
343
        l.nop 1
344
 
345
        .global _syscall_function
346
_syscall_function:
347
        /* r7 and r8 hold actual real ESR and EPCR, respectively */
348
        /* We'll restore them now */
349
        l.mtspr r0, r7, SPR_ESR_BASE /* SR before syscall */
350
        l.mtspr r0, r8, SPR_EPCR_BASE
351
        l.add r16, r16, r3 /* Add syscall number to our counter */
352
        l.movhi r4, hi(0x01000000) /* 16MB mark of memory */
353
        /* Ensure memory access OK */
354
        l.slli r3, r3, 2 /* Turn syscall number into a word address (<< 2) */
355
        l.add r4, r4, r3 /* Access this offset from 16MB mark */
356
        l.sw 0(r4), r16 /* Do a write to memory */
357
        l.lwz r16, 0(r4) /* Do a read from memory */
358
        /* Report running value of syscall counter */
359
        l.or r3, r0, r16
360
        l.nop 2
361
        l.rfe /* Now continue from where we had the l.sys */
362
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.