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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [stdalone/] [twotasks-1/] [os/] [start.s] - Blame information for rev 48

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

Line No. Rev Author Line
1 18 hellwig
;
2
; start.s -- startup code
3
;
4
 
5
        .import main
6
        .import task0StkTop
7
        .import currentStkTop
8
        .import _ecode
9
        .import _edata
10
        .import _ebss
11
 
12
        .export _bcode
13
        .export _bdata
14
        .export _bbss
15
 
16
        .export enable
17
        .export disable
18
        .export orMask
19
        .export andMask
20
        .export getISR
21
        .export setISR
22
        .export startTask
23
        .export setTLB
24
 
25
        .code
26
_bcode:
27
 
28
        .data
29
_bdata:
30
 
31
        .bss
32
_bbss:
33
 
34
        .code
35
 
36
        ; reset arrives here
37
reset:
38
        j       start
39
 
40
        ; interrupts arrive here
41
intrpt:
42
        j       isr
43
 
44
        ; user TLB misses arrive here
45
userMiss:
46
        j       isr
47
 
48
isr:
49
        add     $26,$29,$0               ; sp -> $26
50
        add     $27,$1,$0                ; $1 -> $27
51
        ldw     $29,$0,currentStkTop     ; setup kernel mode stack
52
        sub     $29,$29,128             ; save registers
53
        stw     $2,$29,8
54
        stw     $3,$29,12
55
        stw     $4,$29,16
56
        stw     $5,$29,20
57
        stw     $6,$29,24
58
        stw     $7,$29,28
59
        stw     $8,$29,32
60
        stw     $9,$29,36
61
        stw     $10,$29,40
62
        stw     $11,$29,44
63
        stw     $12,$29,48
64
        stw     $13,$29,52
65
        stw     $14,$29,56
66
        stw     $15,$29,60
67
        stw     $16,$29,64
68
        stw     $17,$29,68
69
        stw     $18,$29,72
70
        stw     $19,$29,76
71
        stw     $20,$29,80
72
        stw     $21,$29,84
73
        stw     $22,$29,88
74
        stw     $23,$29,92
75
        stw     $24,$29,96
76
        stw     $25,$29,100
77
        stw     $26,$29,116             ; this is the task's sp
78
        stw     $27,$29,4               ; this is the task's $1
79
        stw     $30,$29,120             ; this is the task's resumption addr
80
        stw     $31,$29,124
81
        add     $5,$29,$0                ; $5 = pointer to register array
82
        mvfs    $4,0                     ; $4 = IRQ number
83
        slr     $4,$4,16
84
        and     $4,$4,0x1F
85
        sll     $26,$4,2                ; $26 = 4 * IRQ number
86
        ldw     $26,$26,irqsrv          ; get addr of service routine
87
        jalr    $26                     ; call service routine
88
        j       resume                  ; resume task if ISR returns
89
 
90
        ; resume a task
91
resume:
92
        ldw     $29,$0,currentStkTop     ; setup kernel mode stack
93
        sub     $29,$29,128             ; restore registers
94
        ldw     $2,$29,8
95
        ldw     $3,$29,12
96
        ldw     $4,$29,16
97
        ldw     $5,$29,20
98
        ldw     $6,$29,24
99
        ldw     $7,$29,28
100
        ldw     $8,$29,32
101
        ldw     $9,$29,36
102
        ldw     $10,$29,40
103
        ldw     $11,$29,44
104
        ldw     $12,$29,48
105
        ldw     $13,$29,52
106
        ldw     $14,$29,56
107
        ldw     $15,$29,60
108
        ldw     $16,$29,64
109
        ldw     $17,$29,68
110
        ldw     $18,$29,72
111
        ldw     $19,$29,76
112
        ldw     $20,$29,80
113
        ldw     $21,$29,84
114
        ldw     $22,$29,88
115
        ldw     $23,$29,92
116
        ldw     $24,$29,96
117
        ldw     $25,$29,100
118
        ldw     $26,$29,116             ; this is the task's sp
119
        ldw     $27,$29,4               ; this is the task's $1
120
        ldw     $30,$29,120             ; this is the task's resumption addr
121
        ldw     $31,$29,124
122
        add     $1,$27,$0                ; $27 -> $1
123
        add     $29,$26,$0               ; $26 -> sp
124
        rfx                             ; return from exception
125
 
126
start:
127
        mvfs    $8,0
128
        or      $8,$8,1 << 27           ; let vector point to RAM
129
        mvts    $8,0
130
        add     $10,$0,_bdata            ; copy data segment
131
        add     $8,$0,_edata
132
        sub     $9,$8,$10
133
        add     $9,$9,_ecode
134
        j       cpytest
135
cpyloop:
136
        ldw     $11,$9,0
137
        stw     $11,$8,0
138
cpytest:
139
        sub     $8,$8,4
140
        sub     $9,$9,4
141
        bgeu    $8,$10,cpyloop
142
        add     $8,$0,_bbss              ; clear bss
143
        add     $9,$0,_ebss
144
        j       clrtest
145
clrloop:
146
        stw     $0,$8,0
147
        add     $8,$8,4
148
clrtest:
149
        bltu    $8,$9,clrloop
150
        ldw     $29,$0,task0StkTop       ; setup kernel mode stack for task 0
151
        jal     main                    ; call 'main'
152
start1:
153
        j       start1                  ; loop
154
 
155
enable:
156
        mvfs    $8,0
157
        or      $8,$8,1 << 23
158
        mvts    $8,0
159
        jr      $31
160
 
161
disable:
162
        mvfs    $8,0
163
        and     $8,$8,~(1 << 23)
164
        mvts    $8,0
165
        jr      $31
166
 
167
orMask:
168
        mvfs    $8,0
169
        and     $4,$4,0x0000FFFF        ; use lower 16 bits only
170
        or      $8,$8,$4
171
        mvts    $8,0
172
        jr      $31
173
 
174
andMask:
175
        mvfs    $8,0
176
        or      $4,$4,0xFFFF0000        ; use lower 16 bits only
177
        and     $8,$8,$4
178
        mvts    $8,0
179
        jr      $31
180
 
181
getISR:
182
        sll     $4,$4,2
183
        ldw     $2,$4,irqsrv
184
        jr      $31
185
 
186
setISR:
187
        sll     $4,$4,2
188
        stw     $5,$4,irqsrv
189
        jr      $31
190
 
191
startTask:
192
        ldw     $29,$0,currentStkTop     ; setup kernel mode stack
193
        sub     $29,$29,128
194
        stw     $0,$29,0          ; preset registers
195
        stw     $0,$29,4
196
        stw     $0,$29,8
197
        stw     $0,$29,12
198
        stw     $0,$29,16
199
        stw     $0,$29,20
200
        stw     $0,$29,24
201
        stw     $0,$29,28
202
        stw     $0,$29,32
203
        stw     $0,$29,36
204
        stw     $0,$29,40
205
        stw     $0,$29,44
206
        stw     $0,$29,48
207
        stw     $0,$29,52
208
        stw     $0,$29,56
209
        stw     $0,$29,60
210
        stw     $0,$29,64
211
        stw     $0,$29,68
212
        stw     $0,$29,72
213
        stw     $0,$29,76
214
        stw     $0,$29,80
215
        stw     $0,$29,84
216
        stw     $0,$29,88
217
        stw     $0,$29,92
218
        stw     $0,$29,96
219
        stw     $0,$29,100
220
        stw     $0,$29,104
221
        stw     $0,$29,108
222
        stw     $0,$29,112
223
        add     $8,$0,0x80000000
224
        stw     $8,$29,116              ; sp
225
        stw     $0,$29,120               ; task starts at virtual addr 0
226
        stw     $0,$29,124
227
        mvfs    $8,0
228
        or      $8,$8,1 << 25           ; set previous mode to 'user'
229
        or      $8,$8,1 << 22           ; and enable interrupts
230
        mvts    $8,0
231
        j       resume
232
 
233
setTLB:
234
        mvts    $4,1                    ; set index
235
        mvts    $5,2                    ; set entryHi
236
        mvts    $6,3                    ; set entryLo
237
        tbwi                            ; write TLB entry at index
238
        jr      $31
239
 
240
        .data
241
 
242
; interrupt service routine table
243
 
244
        .align  4
245
 
246
irqsrv:
247
        .word   0                ; 00: terminal 0 transmitter interrupt
248
        .word   0                ; 01: terminal 0 receiver interrupt
249
        .word   0                ; 02: terminal 1 transmitter interrupt
250
        .word   0                ; 03: terminal 1 receiver interrupt
251
        .word   0                ; 04: keyboard interrupt
252
        .word   0                ; 05: unused
253
        .word   0                ; 06: unused
254
        .word   0                ; 07: unused
255
        .word   0                ; 08: disk interrupt
256
        .word   0                ; 09: unused
257
        .word   0                ; 10: unused
258
        .word   0                ; 11: unused
259
        .word   0                ; 12: unused
260
        .word   0                ; 13: unused
261 38 hellwig
        .word   0                ; 14: timer 0 interrupt
262
        .word   0                ; 15: timer 1 interrupt
263 18 hellwig
        .word   0                ; 16: bus timeout exception
264
        .word   0                ; 17: illegal instruction exception
265
        .word   0                ; 18: privileged instruction exception
266
        .word   0                ; 19: divide instruction exception
267
        .word   0                ; 20: trap instruction exception
268
        .word   0                ; 21: TLB miss exception
269
        .word   0                ; 22: TLB write exception
270
        .word   0                ; 23: TLB invalid exception
271
        .word   0                ; 24: illegal address exception
272
        .word   0                ; 25: privileged address exception
273
        .word   0                ; 26: unused
274
        .word   0                ; 27: unused
275
        .word   0                ; 28: unused
276
        .word   0                ; 29: unused
277
        .word   0                ; 30: unused
278
        .word   0                ; 31: unused

powered by: WebSVN 2.1.0

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