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

Subversion Repositories eco32

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

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

powered by: WebSVN 2.1.0

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