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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 506 julius
#include "spr-defs.h"
2
#include "board.h"
3
 
4
/*
5
 
6
        User IRQ 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 irq interrupt counter
13
        r18 intgen's base address
14
 
15
 
16
        The test does the following:
17
        Uses the intgen module to schedule interrupts to see if they clash
18
        with system calls.
19
 
20
        Julius Baxter, ORSoC AB, julius.baxter@orsoc.se
21
*/
22
//////////////////////////////////////////////////////////////////////
23
////                                                              ////
24
//// Copyright (C) 2011 Authors and OPENCORES.ORG                 ////
25
////                                                              ////
26
//// This source file may be used and distributed without         ////
27
//// restriction provided that this copyright statement is not    ////
28
//// removed from the file and that any derivative work contains  ////
29
//// the original copyright notice and the associated disclaimer. ////
30
////                                                              ////
31
//// This source file is free software; you can redistribute it   ////
32
//// and/or modify it under the terms of the GNU Lesser General   ////
33
//// Public License as published by the Free Software Foundation; ////
34
//// either version 2.1 of the License, or (at your option) any   ////
35
//// later version.                                               ////
36
////                                                              ////
37
//// This source is distributed in the hope that it will be       ////
38
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
39
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
40
//// PURPOSE.  See the GNU Lesser General Public License for more ////
41
//// details.                                                     ////
42
////                                                              ////
43
//// You should have received a copy of the GNU Lesser General    ////
44
//// Public License along with this source; if not, download it   ////
45
//// from http://www.opencores.org/lgpl.shtml                     ////
46
////                                                              ////
47
//////////////////////////////////////////////////////////////////////
48
 
49
 
50
/* =================================================== [ exceptions ] === */
51
        .section .vectors, "ax"
52
 
53
 
54
/* ---[ 0x100: RESET exception ]----------------------------------------- */
55
        .org 0x100
56
        l.movhi r0, 0
57
        /* Clear status register */
58
        l.ori   r1, r0, SPR_SR_SM
59
        l.mtspr r0, r1, SPR_SR
60
        /* Clear timer  */
61
        l.mtspr r0, r0, SPR_TTMR
62
        /* Init the stack */
63
        .global _stack
64
        l.movhi r1, hi(_stack)
65
        l.ori   r1, r1, lo(_stack)
66
        l.addi  r2, r0, -3
67
        l.and   r1, r1, r2
68
        /* Jump to program initialisation code */
69
        .global _start
70
        l.movhi r4, hi(_start)
71
        l.ori   r4, r4, lo(_start)
72
        l.jr    r4
73
        l.nop
74
 
75
 
76
/* =================================================== [ User interrupt ] === */
77
        .org 0x800
78
        .global _user_irq_handler
79
_user_irq_handler:
80
        l.addi r17, r17, 1
81
        /* Report values , 0x00000800 == user interrupt report*/
82
        l.ori r3, r0, 0x0800
83
        l.nop 2
84
        l.or r3, r0, r17
85
        l.nop 2
86
        /* TODO - propably confirm it was intgen's IRQ that caused this */
87
        /* Clear interrupt source */
88
        l.ori   r7, r18, 0x1    /* intgen IRQ clear address */
89
        l.sb    0(r7), r0       /* Any write clears the bit */
90
        /* Clear OR1200 PICSR */
91
        l.mfspr r7, r0, SPR_PICSR
92
        l.mtspr r0, r7, SPR_PICSR
93
 
94
        l.rfe
95
 
96
/* ========================================================= [ syscall ] === */
97
        .org 0xC00
98
        .extern _syscall_function
99
        .global _syscall_handler
100
_syscall_handler:
101
        l.addi r15, r15, 1
102
        l.mfspr r7, r0, SPR_ESR_BASE /* Put ESR in r7, set back to ESR later */
103
        l.mfspr r8, r0, SPR_EPCR_BASE/* Put EPCR in r8,set back to EPCR later*/
104
        /* Unset IEE and TEE bits of SR */
105
        l.ori r4, r0, SPR_SR_IEE|SPR_SR_TEE
106
        l.ori r5, r0, 0xffff
107
        l.xor r5, r5, r4
108
        l.and r5, r7, r5 /* New SR without interrupt bits set */
109
        l.mtspr r0, r5, SPR_ESR_BASE /* SR after l.rfe */
110
        /* Report values , 0x00000c00 == tick timer report*/
111
        l.ori r3, r0, 0x0c00
112
        l.nop 2
113
        /* Get syscall number */
114
        l.lwz r3, -4(r8) /* r8 = load(EPCR-4)= PC of l.sys that caused this */
115
        l.andi r3, r3, 0xffff /* get 16-bit immediate syscall number */
116
        l.nop 2
117
        l.movhi r4, hi(_syscall_function)
118
        l.ori r4, r4, lo(_syscall_function)
119
        l.mtspr r0, r4, SPR_EPCR_BASE
120
        l.rfe
121
 
122
 
123
 
124
/* =================================================== [ text section ] === */
125
        .section  .text
126
 
127
/* =================================================== [ start ] === */
128
 
129
        .global _start
130
_start:
131
        // Kick off test
132
        l.jal   _main
133
        l.nop
134
 
135
/* =================================================== [ main ] === */
136
.global _main
137
_main:
138
        l.movhi r15, 0
139
        l.movhi r16, 0
140
        l.movhi r17, 0
141
 
142
        #
143
        # unmask (enable) all ints
144
        #
145
        l.movhi r5,0xffff
146
        l.ori   r5,r5,0xffff
147
        l.mtspr r0,r5,SPR_PICMR         # set PICMR
148
 
149
        /* Enable Interrupts */
150
        l.mfspr r6,r0,SPR_SR
151
        l.ori   r6,r6,SPR_SR_IEE
152
        l.mtspr r0,r6,SPR_SR
153
 
154
 
155
        // Assumes r18 is intgen's base address
156
        l.movhi r18,hi(INTGEN_BASE)
157
 
158
#define INTGEN_LOAD(x)  \
159
        l.ori   r5,r0,lo(x)     ;\
160
        l.sb    0(r18),r5
161
 
162
 
163
        /* Test begin */
164
 
165
        l.nop
166
        INTGEN_LOAD(1)
167
        l.sys 0x1
168
        l.nop
169
        INTGEN_LOAD(1)
170
        l.nop
171
        l.sys 0x2
172
        l.nop
173
        INTGEN_LOAD(2)
174
        l.sys 0x3
175
        l.nop
176
        INTGEN_LOAD(2)
177
        l.nop
178
        l.sys 0x4
179
        l.nop
180
        l.ori   r5,r0,1
181
        l.sys 0x5
182
        l.sb    0(r18),r5
183
        l.nop
184
        l.nop
185
        l.nop
186
        l.sfnei r16, 0xf /* Should equal 15, 0xf */
187
        l.bf _fail
188
        l.nop
189
 
190
        l.movhi r3, hi(0x8000000d)
191
        l.ori r3, r3, lo(0x8000000d)
192
        l.nop 2
193
        l.ori r3, r0, 0
194
        l.nop 1
195
 
196
_fail:
197
        l.movhi r3, hi(0xbaaaaaad)
198
        l.ori r3, r3, lo(0xbaaaaaad)
199
        l.nop 1
200
 
201
        .global _syscall_function
202
_syscall_function:
203
        /* r7 and r8 hold actual real ESR and EPCR, respectively */
204
        /* We'll restore them now */
205
        l.mtspr r0, r7, SPR_ESR_BASE /* SR before syscall */
206
        l.mtspr r0, r8, SPR_EPCR_BASE
207
        l.add r16, r16, r3 /* Add syscall number to our counter */
208
        l.movhi r4, hi(0x00400000) /* 4MB mark of memory */
209
        /* Ensure memory access OK */
210
        l.slli r3, r3, 2 /* Turn syscall number into a word address (<< 2) */
211
        l.add r4, r4, r3 /* Access this offset from 4MB mark */
212
        l.sw 0(r4), r16 /* Do a write to memory */
213
        l.lwz r16, 0(r4) /* Do a read from memory */
214
        /* Report running value of syscall counter */
215
        l.or r3, r0, r16
216
        l.nop 2
217
        l.rfe /* Now continue from where we had the l.sys */
218
 

powered by: WebSVN 2.1.0

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