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

Subversion Repositories thor

[/] [thor/] [trunk/] [software/] [boot_tb/] [boot.asm] - Blame information for rev 28

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 robfinch
 
2
; ============================================================================
3
;        __
4
;   \\__/ o\    (C) 2015  Robert Finch, Stratford
5
;    \  __ /    All rights reserved.
6
;     \/_//     robfinch@finitron.ca
7
;       ||
8
;
9
;
10
; This source file is free software: you can redistribute it and/or modify
11
; it under the terms of the GNU Lesser General Public License as published
12
; by the Free Software Foundation, either version 3 of the License, or
13
; (at your option) any later version.
14
;
15
; This source file is distributed in the hope that it will be useful,
16
; but WITHOUT ANY WARRANTY; without even the implied warranty of
17
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
; GNU General Public License for more details.
19
;
20
; You should have received a copy of the GNU General Public License
21
; along with this program.  If not, see .
22
;
23
; ============================================================================
24
;
25 28 robfinch
.include "C:\Cores4\Thor\trunk\software\FMTK\source\kernel\FMTK_Equates.inc"
26 12 robfinch
 
27
SCRSZ   EQU     2604
28 28 robfinch
_BS             EQU     0x07
29 5 robfinch
CR      EQU     0x0D            ;ASCII equates
30
LF      EQU     0x0A
31
TAB     EQU     0x09
32
CTRLC   EQU     0x03
33
CTRLH   EQU     0x08
34
CTRLI   EQU     0x09
35
CTRLJ   EQU     0x0A
36
CTRLK   EQU     0x0B
37
CTRLM   EQU 0x0D
38
CTRLS   EQU     0x13
39
CTRLX   EQU     0x18
40
XON             EQU     0x11
41
XOFF    EQU     0x13
42
ESC             EQU     0x1B
43
 
44 28 robfinch
SC_TAB          EQU             $0D
45 5 robfinch
SC_LSHIFT       EQU             $12
46
SC_RSHIFT       EQU             $59
47
SC_KEYUP        EQU             $F0
48
SC_EXTEND       EQU             $E0
49
SC_CTRL         EQU             $14
50
SC_ALT          EQU             $11
51
SC_DEL          EQU             $71             ; extend
52
SC_LCTRL        EQU             $58
53
SC_NUMLOCK      EQU             $77
54
SC_SCROLLLOCK   EQU     $7E
55
SC_CAPSLOCK     EQU             $58
56
 
57 12 robfinch
E_BadFuncno    EQU       1
58
BIOS_E_Timeout EQU       2
59
E_Unsupported  EQU       3
60
 
61
BIOS_STACKTOP           EQU             $3bf8
62
INT_STACK                       EQU             $37f8
63
VIDEO_BIOS_STACKTOP     EQU             $3ff8
64
 
65 5 robfinch
IOBASE_ADDR     EQU             0xFFD00000
66
IOLMT           EQU             0x100000
67
LEDS            EQU             0xC0600
68
TEXTSCR         EQU             0x00000
69
TEXTSCR2        EQU             0x10000
70
TEXTREG         EQU             0xA0000
71 12 robfinch
TEXTREG2        EQU             0xA0040
72 5 robfinch
TEXT_COLS       EQU             0x0
73
TEXT_ROWS       EQU             0x2
74
TEXT_CURPOS     EQU             0x16
75
KEYBD           EQU             0xC0000
76
 
77 16 robfinch
PIC_IS          EQU             0xC0FC0
78 5 robfinch
PIC_IE          EQU             0xC0FC8
79
PIC_ES          EQU             0xC0FE0
80
PIC_ESR         EQU             0xC0FE8         ; edge sense reset
81
 
82 16 robfinch
                bss
83
                org             $0000
84
                dw              0                                ; the first word is unused
85
Milliseconds    dw              0
86
m_w                             dh              0
87
m_z                             dh              0
88 28 robfinch
FMTK_SchedulerIRQ_vec   dw      0
89
Running_                dw              0
90
IOFocusNdx_             dw              0
91
iof_switch_             db              0
92
                align   8
93
NextRdy_                dw              0
94
PrevRdy_                dw              0
95
 
96 16 robfinch
KeyState1               db              0
97
KeyState2               db              0
98
KeybdLEDs               db              0
99
KeybdWaitFlag   db              0
100 28 robfinch
                align   2
101
KeybdHead               db              0
102
KeybdTail               db              0
103
KeybdBufSz              db              0
104
KeybdBuf                fill.b  128,0
105
                align   2
106 16 robfinch
CursorX                 dc              0
107
CursorY                 dc              0
108
VideoPos                dc              0
109
                align   4
110
NormAttr                dh              0
111
Vidregs                 dh              0
112
Vidptr                  dh              0
113
EscState                dc              0
114
Textrows                dc              0
115
Textcols                dc              0
116
                align   8
117
reg_save                fill.w  64,0
118
creg_save               fill.w  16,0
119
sreg_save               fill.w  16,0
120
preg_save               dw              0
121 5 robfinch
 
122 12 robfinch
                bss
123
                org             $4000
124
 
125
 
126
rxfull     EQU      1
127
Uart_ms         db      0
128
Uart_txxonoff   db      0
129
Uart_rxhead     dc      0
130
Uart_rxtail     dc      0
131
Uart_rxflow     db      0
132
Uart_rxrts      db      0
133
Uart_rxdtr      db      0
134
Uart_rxxon      db      0
135
Uart_foff       dc      0
136
Uart_fon        dc      0
137
Uart_txrts      db      0
138
Uart_txdtr      db      0
139
Uart_txxon      db      0
140
Uart_rxfifo     fill.b  512,0
141
 
142
NUMWKA          fill.b  64,0
143
 
144
        code 17 bits
145 5 robfinch
        org             $FFFF8000
146
 
147
cold_start:
148
                ; Initialize segment registers for flat model
149
                mtspr   zs,r0
150
                ldis    zs.lmt,#-1
151
                mtspr   ds,r0
152
                ldis    ds.lmt,#-1
153
                mtspr   es,r0
154
                ldis    es.lmt,#-1
155
                mtspr   fs,r0
156
                ldis    fs.lmt,#-1
157
                mtspr   gs,r0
158
                ldis    gs.lmt,#-1
159
                ldis    hs,#IOBASE_ADDR
160
                ldis    hs.lmt,#IOLMT
161
 
162
                ; set SS:SP
163
                mtspr   ss,r0
164
                ldis    ss.lmt,#$4000
165 12 robfinch
                ldi             r31,#$03ef8             ; initialize kernel SP
166
                ldi             r27,#$03bf8             ; initialize SP
167 5 robfinch
 
168
                ; switch processor to full speed
169
                stp             #$FFFF
170
 
171 16 robfinch
                ; set interrupt table at $1000
172
                ldis    c12,#$1000
173 5 robfinch
 
174
                ; set all vectors to the uninitialized interrupt vector
175 16 robfinch
                mov             r4,r0
176
                ldis    lc,#255         ; 256 vectors to set
177
su1:
178
                ldi             r1,#uii_jmp
179
                mov             r2,r4
180
                bsr             set_vector      ; trashes r2,r3
181
                addui   r4,r4,#1
182
                loop    su1
183 5 robfinch
 
184
                ; setup break vector
185 16 robfinch
                lla             r1,cs:brk_jmp
186 5 robfinch
                ldi             r2,#0
187
                bsr             set_vector
188
 
189 28 robfinch
                ; setup system scheduler vector
190
                ; points to an RTE at startup
191
                lla             r1,cs:tms_jmp
192
                ldi             r2,#2
193
                bsr             set_vector
194
                lla             r1,cs:rte_jmp
195
                ldi             r2,#3
196
                bsr             set_vector
197
 
198 12 robfinch
                ; setup Video BIOS vector
199 16 robfinch
                lla             r1,cs:vb_jmp
200 12 robfinch
                ldi             r2,#10
201
                bsr             set_vector
202
 
203 5 robfinch
                ; setup NMI vector
204 16 robfinch
                lla             r1,cs:nmi_jmp
205 5 robfinch
                ldi             r2,#254
206
                bsr             set_vector
207
 
208 16 robfinch
                lla             r1,cs:svc_jmp
209
                ldi             r2,#190
210
                bsr             set_vector
211
                lla             r1,cs:rsc_jmp
212
                ldi             r2,#191
213
                bsr             set_vector
214
 
215
                ; spurious interrupt
216
                ;
217
                lla             r1,cs:spur_jmp
218
                ldi             r2,#192
219
                bsr             set_vector
220
 
221 12 robfinch
                ; setup MSI vector
222
                sh              r0,Milliseconds
223 16 robfinch
                lla             r1,cs:msi_jmp
224 12 robfinch
                ldi             r2,#193
225
                bsr             set_vector
226
 
227 16 robfinch
                ; setup BTNU vector
228
                lla             r1,cs:btnu_jmp
229
                ldi             r2,#200
230
                bsr             set_vector
231
 
232
                ; setup KM vector
233
                lla             r1,cs:km_jmp
234
                ldi             r2,#245
235
                bsr             set_vector
236
 
237 12 robfinch
                ; setup data bus error vector
238 16 robfinch
                lla             r1,cs:dbe_jmp
239 12 robfinch
                ldi             r2,#251
240
                bsr             set_vector
241
 
242 28 robfinch
                ldi             r1,#JCB_Array
243
                sw              r1,zs:RunningJCB_
244
                sw              r1,zs:IOFocusNdx_       ; set I/O focus to BIOS
245
                ldi             r1,#TCB_Array
246
                sw              r1,zs:RunningTCB_
247
                sb              r0,zs:iof_switch_       ; reset switch flag
248
                mov             tr,r0
249
                bsr             KeybdInit
250
 
251
                jsr             FMTKInitialize_
252
 
253 5 robfinch
                ; Initialize PIC
254 28 robfinch
                ldi             r1,#%00000111           ; nmi, time slice interrupt is edge sensitive
255 5 robfinch
                sh              r1,hs:PIC_ES
256 28 robfinch
                ldi             r1,#%000001111          ; enable time slice interrupt, msi, nmi
257 5 robfinch
                sh              r1,hs:PIC_IE
258
 
259 16 robfinch
                ; Initialize random number generator
260
                ; m_z and m_w must not be zero
261
                ldi             r1,#$88888888
262
                sh              r1,m_w
263
                ldi             r1,#$77777777
264
                sh              r1,m_z
265
 
266 5 robfinch
                mov             r1,r0
267
                mov             r2,r0
268
                mov             r3,r0
269
                mov             r4,r0
270
                mov             r5,r0
271
 
272
                ldi             r1,#1
273 12 robfinch
                sc              r1,hs:LEDS
274 5 robfinch
 
275
                tlbwrreg DMA,r0                         ; clear TLB miss registers
276
                tlbwrreg IMA,r0
277
                ldi                     r1,#2                   ; 2 wired registers
278
                tlbwrreg        Wired,r1
279
                ldi                     r1,#$2                  ; 64kiB page size
280
                tlbwrreg        PageSize,r1
281
 
282
                ; setup the first translation
283
                ; virtual page $FFFF0000 maps to physical page $FFFF0000
284
                ; This places the BIOS ROM at $FFFFxxxx in the memory map
285
                ldi                     r1,#$80000101   ; ASID=zero, G=1,valid=1
286
                tlbwrreg        ASID,r1
287
                ldi                     r1,#$0FFFF
288
                tlbwrreg        VirtPage,r1
289
                tlbwrreg        PhysPage,r1
290
                tlbwrreg        Index,r0                ; select way #0
291
                tlbwi                                           ; write to TLB entry group #0 with hold registers
292
 
293
                ; setup second translation
294
                ; virtual page 0 maps to physical page 0
295
                ldi                     r1,#$80000101   ; ASID=zero, G=1,valid=1
296
                tlbwrreg        ASID,r1
297
                tlbwrreg        VirtPage,r0
298
                tlbwrreg        PhysPage,r0
299
                ldi                     r1,#8                   ; select way#1
300
                tlbwrreg        Index,r1
301
                tlbwi                                           ; write to TLB entry group #0 with hold registers
302
 
303
                ; turn on the TLB
304
;               tlben
305
 
306
                ; enable maskable interrupts
307
                ; Interrupts also are not enabled until an RTI instruction is executed.
308
                ; there will likely be a timer interrupt outstanding so this
309
                ; should go to the timer IRQ.
310
                cli
311
 
312
                ; now globally enable interrupts using the RTI instruction, this will also
313
                ; switch to core to application/user mode.
314
                ldis    c14,#j1                 ; c14 contains RTI return address
315 12 robfinch
                sync
316 16 robfinch
                rti
317 5 robfinch
j1:
318
                ldi             r1,#2
319 12 robfinch
                sc              r1,hs:LEDS
320 5 robfinch
                sb              r0,EscState
321 12 robfinch
                bsr             SerialInit
322 16 robfinch
;               bsr             Debugger
323 12 robfinch
                ldi             r2,#msgStartup
324
                ldis    lc,#msgStartupEnd-msgStartup-1
325
j3:
326
;               lbu             r1,[r2]
327
;               addui   r2,r2,#1
328
;               tst             p0,r1
329
;p0.eq  br              j2
330
;               bsr             SerialPutChar
331
;               loop    j3
332
j2:
333 5 robfinch
                bsr             VideoInit
334 12 robfinch
                bsr             VBClearScreen
335
;               bsr             VBClearScreen2
336 5 robfinch
                ldi             r1,#3
337 12 robfinch
                sc              r1,hs:LEDS
338
                mov             r1,r0
339
                mov             r2,r0
340
                ldi             r6,#2           ; Set Cursor Pos
341
                sys             #10
342 5 robfinch
                ldi             r1,#6
343 12 robfinch
                sc              r1,hs:LEDS
344
                bsr             alphabet
345 16 robfinch
                lla             r1,cs:msgStartup        ; convert to linear address
346 12 robfinch
                ldi             r6,#$14
347
                sys             #10
348 16 robfinch
 
349
;------------------------------------------------------------------------------
350
;------------------------------------------------------------------------------
351
; Monitor
352
;------------------------------------------------------------------------------
353
;------------------------------------------------------------------------------
354
 
355
Monitor:
356
                lla             r1,cs:msgMonitor
357
                bsr             VBDisplayString
358
 
359
                ; Display monitor prompt
360
.prompt:
361
                ldi             r1,#CR
362
                bsr             VBDisplayChar
363
                ldi             r1,#LF
364
                bsr             VBDisplayChar
365
                ldi             r1,#'$'
366
                bsr             VBDisplayChar
367
                bsr             CursorOn
368
.getkey:
369 5 robfinch
                bsr             KeybdGetCharWait
370 12 robfinch
                bsr             VBDisplayChar
371
                cmpi    p0,r1,#CR
372 16 robfinch
p0.ne   br              .getkey
373
                bsr             CursorOff
374
                lcu             r1,CursorY
375
                lcu             r7,Textcols
376
                mtspr   lc,r7                           ; use loop counter as safety
377
                mulu    r10,r1,r7                       ; pos = row * cols
378
                _4addu  r10,r10,r0                      ; pos *= 4
379
.0001:
380
                bsr             MonGetch1                       ; get character skipping spaces
381
                cmpi    p0,r1,#'$'                      ; skip over prompt
382
p0.eq   br              .0001
383
                cmpi    p0,r1,#'d'                      ; debug ?
384
p0.eq   bsr             Debugger
385 28 robfinch
p0.eq   br              .prompt
386 16 robfinch
                cmpi    p0,r1,#'g'
387
p0.eq   bsr             GoGraphics
388 28 robfinch
p0.eq   br              .prompt
389 16 robfinch
                cmpi    p0,r1,#'t'
390
p0.eq   bsr             MonGetch
391
p0.eq   cmpi    p0,r1,#'x'
392
p0.eq   bsr             GoText
393 28 robfinch
p0.eq   br              .prompt
394 16 robfinch
                cmpi    p0,r1,'r'
395
p0.eq   bsr             RandomDots
396 28 robfinch
p0.eq   br              .prompt
397 16 robfinch
                cmpi    p0,r1,#'c'
398
p0.eq   bsr             VBClearScreen
399
p0.eq   mov             r1,r0
400
p0.eq   mov             r2,r0
401
p0.eq   ldi             r6,#2
402
p0.eq   sys             #10
403
                br              .prompt
404 5 robfinch
 
405 16 robfinch
;------------------------------------------------------------------------------
406
; Returns:
407
;       r1  ascii code for character
408
;       r10 incremented
409
;   lc  decremented
410
;------------------------------------------------------------------------------
411
 
412
MonGetch:
413
                addui   r31,r31,#-8
414
                sws             c1,[r31]
415
                lhu             r1,hs:[r10]
416
                andi    r1,r1,#$3ff
417
                bsr             VBScreenToAscii
418
                addui   r10,r10,#4
419
                loop    .0001                   ; decrement loop counter
420
.0001:
421
                lws             c1,[r31]
422
                addui   r31,r31,#8
423
                rts
424
 
425
;------------------------------------------------------------------------------
426
; Returns:
427
;       r1  ascii code for character
428
;       r10 incremented by number of spaces + 1
429
;   lc  decremented by number of spaces + 1
430
;------------------------------------------------------------------------------
431
 
432
MonGetch1:
433
                addui   r31,r31,#-8
434
                sws             c1,[r31]
435
.0001:
436
                lhu             r1,hs:[r10]
437
                andi    r1,r1,#$3ff
438
                bsr             VBScreenToAscii
439
                addui   r10,r10,#4
440
                cmpi    p0,r1,#' '
441
p0.leu  loop    .0001
442
                lws             c1,[r31]
443
                addui   r31,r31,#8
444
                rts
445
 
446
;------------------------------------------------------------------------------
447 28 robfinch
; Go into graphics mode, four lines of text at bottom.
448 16 robfinch
;------------------------------------------------------------------------------
449
 
450
GoGraphics:
451
                lhu             r3,Vidregs
452
                ldi             r1,#4
453
                sc              r1,Textrows
454
                sh              r1,hs:4[r3]             ; # rows
455 28 robfinch
                ldi             r1,#240
456 16 robfinch
                sh              r1,hs:12[r3]    ; window top
457 28 robfinch
                mov             r1,r0                   ; reset cursor position
458
                mov             r2,r0
459
                ldi             r6,#2
460
                sys             #10
461 16 robfinch
                rts
462
 
463 28 robfinch
;------------------------------------------------------------------------------
464
; Go back to full text mode.
465
;------------------------------------------------------------------------------
466
 
467 16 robfinch
GoText:
468
                lhu             r3,Vidregs
469
                ldi             r1,#31
470
                sc              r1,Textrows
471
                sh              r1,hs:4[r3]             ; # rows
472
                ldi             r1,#17
473
                sh              r1,hs:12[r3]    ; window top
474 28 robfinch
                mov             r1,r0                   ; reset cursor position
475
                mov             r2,r0
476
                ldi             r6,#2
477
                sys             #10
478 16 robfinch
                rts
479
 
480
// ----------------------------------------------------------------------------
481
// Uses George Marsaglia's multiply method
482
//
483
// m_w = ;    /* must not be zero */
484
// m_z = ;    /* must not be zero */
485
//
486
// uint get_random()
487
// {
488
//     m_z = 36969 * (m_z & 65535) + (m_z >> 16);
489
//     m_w = 18000 * (m_w & 65535) + (m_w >> 16);
490
//     return (m_z << 16) + m_w;  /* 32-bit result */
491
// }
492
// ----------------------------------------------------------------------------
493
//
494
gen_rand:
495
                addui   r31,r31,#-8
496
                sw              r2,[r31]
497
                lhu             r1,m_z
498
                mului   r2,r1,#36969
499
                shrui   r1,r1,#16
500
                addu    r2,r2,r1
501
                sh              r2,m_z
502
 
503
                lhu             r1,m_w
504
                mului   r2,r1,#18000
505
                shrui   r1,r1,#16
506
                addu    r2,r2,r1
507
                sh              r2,m_w
508
rand:
509
                lhu             r1,m_z
510
                shli    r1,r1,#16
511
                addu    r1,r1,r2
512
                lw              r2,[r31]
513
                addui   r31,r31,#8
514
                rts
515
 
516
// ----------------------------------------------------------------------------
517
// Display random dots on the graphics screen.
518
// ----------------------------------------------------------------------------
519
 
520
RandomDots:
521
                addui   r31,r31,#-8
522 28 robfinch
                sws             c1,[r31]                ; stack the return address
523 16 robfinch
                mov             r4,r0
524
.0001:
525
                bsr             gen_rand                ; get random bitmap memory location
526 28 robfinch
                modui   r2,r1,#172032   ; mod the memory size
527
                _2addui r2,r2,#$FFA00000        ; *2 for 16 bit data, generate address
528 16 robfinch
                bsr             gen_rand                ; get random color
529
                modui   r3,r1,#$1000    ; limit to 12 bits
530 28 robfinch
                sc              r3,zs:[r2]              ; store color in memory
531 16 robfinch
                addui   r4,r4,#1                ; increment loop index
532
                andi    r4,r4,#$FFF             ;
533 28 robfinch
                tst             p1,r4                   ; check if time to check for keypress
534
p1.ne   br              .0001
535
                bsr             KeybdGetCharNoWait      ; try get a key, but don't wait
536
                tst             p1,r1                   ; branch if no key pressed
537
p1.lt   br              RandomDots.0001
538
                lws             c1,[r31]                ; restore return address
539 16 robfinch
                addui   r31,r31,#8
540
                rts
541
 
542
;------------------------------------------------------------------------------
543
 
544 5 robfinch
msgStartup:
545
                byte    "Thor Test System Starting...",CR,LF,0
546 12 robfinch
msgStartupEnd:
547 16 robfinch
msgMonitor:
548
                byte    CR,LF
549
                byte    "d  - run debugger",CR,LF
550
                byte    "g  - graphics mode",CR,LF
551
                byte    "tx - text mode",CR,LF
552
                byte    "r  - random dots",CR,LF
553
                byte    0
554 5 robfinch
 
555
bad_ram:
556
                ldi             r1,#'B'
557 12 robfinch
                bsr             VBAsciiToScreen
558 5 robfinch
                ori             r1,r1,#%011000000_111111111_00_00000000
559
                sh              r1,hs:TEXTSCR+16
560
.bram1: br              .bram1
561
 
562
;------------------------------------------------------------------------------
563 12 robfinch
; alphabet:
564
;
565
; Display the alphabet across the top of the screen.
566
;------------------------------------------------------------------------------
567
 
568
alphabet:
569
                addui   sp,sp,#-8
570
                sws             c1,[sp]                 ; store off return address
571
                ldi             r5,#'A'                 ; the first char
572
                ldi             r3,#TEXTSCR             ; screen address
573
                ldis    lc,#25                  ; 25 chars
574
.0001:
575
                mov             r1,r5                   ; r1 = ascii letter
576
                bsr             VBAsciiToScreen ; r1 = screen char
577
                lhu             r2,NormAttr             ; r2 = attribute
578
                or              r1,r1,r2                ; r1 = screen char + attribute
579
                sh              r1,hs:[r3]              ; store r1 to screen
580
                addui   r5,r5,#1                ; increment to next char
581
                addui   r3,r3,#4                ; increment to next screen loc
582
                loop    .0001                   ; loop back
583
                lws             c1,[sp]                 ; restore return address
584
                addui   sp,sp,#8
585
                rts
586
 
587
;------------------------------------------------------------------------------
588 5 robfinch
; Set interrupt vector
589
;
590
; Parameters:
591 16 robfinch
;       r1 = linear address of jump code
592 5 robfinch
;       r2 = vector number to set
593 16 robfinch
; Trashes: r2,r3,r5,p0
594 5 robfinch
;------------------------------------------------------------------------------
595
 
596
set_vector:
597
                mfspr   r3,c12                  ; get base address of interrupt table
598
                _16addu r2,r2,r3
599 16 robfinch
                lh              r3,zs:[r1]
600
                cmpi    p0,r3,#$003F6F01        ; unitialized interrupt number load
601
p0.eq   shli    r5,r2,#18
602
p0.eq   or              r3,r3,r5
603 5 robfinch
                sh              r3,zs:[r2]
604 16 robfinch
                lh              r3,zs:4[r1]
605 5 robfinch
                sh              r3,zs:4[r2]
606 16 robfinch
                lh              r3,zs:8[r1]
607 5 robfinch
                sh              r3,zs:8[r2]
608 16 robfinch
                lh              r3,zs:12[r1]
609 5 robfinch
                sh              r3,zs:12[r2]
610
                rts
611
 
612 16 robfinch
;------------------------------------------------------------------------------
613
; Save the register context.
614
;
615
; Parameters:
616 28 robfinch
;       tr points to app's TCB
617 16 robfinch
;
618
;------------------------------------------------------------------------------
619
 
620
save_context:
621 28 robfinch
                sw              r1,TCB_r1[tr]
622
                sw              r2,TCB_r2[tr]
623
                sw              r3,TCB_r3[tr]
624
                sw              r4,TCB_r4[tr]
625
                sw              r5,TCB_r5[tr]
626
                sw              r6,TCB_r6[tr]
627
                sw              r7,TCB_r7[tr]
628
                sw              r8,TCB_r8[tr]
629
                sw              r9,TCB_r9[tr]
630
                sw              r10,TCB_r10[tr]
631
                sw              r11,TCB_r11[tr]
632
                sw              r12,TCB_r12[tr]
633
                sw              r13,TCB_r13[tr]
634
                sw              r14,TCB_r14[tr]
635
                sw              r15,TCB_r15[tr]
636
                sw              r16,TCB_r16[tr]
637
                sw              r17,TCB_r17[tr]
638
                sw              r18,TCB_r18[tr]
639
                sw              r19,TCB_r19[tr]
640
                sw              r20,TCB_r20[tr]
641
                sw              r21,TCB_r21[tr]
642
                sw              r22,TCB_r22[tr]
643
                sw              r23,TCB_r23[tr]
644
                sw              r24,TCB_r24[tr]
645
                sw              r25,TCB_r25[tr]
646
                sw              r26,TCB_r26[tr]
647
                sw              r27,TCB_r27[tr]
648
                sws             ds,TCB_ds[tr]
649
                sws             es,TCB_es[tr]
650
                sws             fs,TCB_fs[tr]
651
                sws             gs,TCB_gs[tr]
652
                sws             hs,TCB_hs[tr]
653
                sws             ss,TCB_ss[tr]
654
                sws             cs,TCB_cs[tr]
655
                sws             ds.lmt,TCB_dslmt[tr]
656
                sws             es.lmt,TCB_eslmt[tr]
657
                sws             fs.lmt,TCB_fslmt[tr]
658
                sws             gs.lmt,TCB_gslmt[tr]
659
                sws             hs.lmt,TCB_hslmt[tr]
660
                sws             ss.lmt,TCB_sslmt[tr]
661
                sws             cs.lmt,TCB_cslmt[tr]
662
                sws             c1,TCB_c1[tr]
663
                sws             c2,TCB_c2[tr]
664
                sws             c3,TCB_c3[tr]
665
                sws             c4,TCB_c4[tr]
666
                sws             c5,TCB_c5[tr]
667
                sws             c6,TCB_c6[tr]
668
                sws             c7,TCB_c7[tr]
669
                sws             c8,TCB_c8[tr]
670
                sws             c9,TCB_c9[tr]
671
                sws             c10,TCB_c10[tr]
672
                sws             c11,TCB_c11[tr]
673
;               sws             c13,TCB_c13[tr]
674
;               sws             c14,TCB_c14[tr]
675
                sws             pregs,TCB_pregs[tr]
676 16 robfinch
                rte
677
 
678
;------------------------------------------------------------------------------
679
; Restore register context.
680
; Parameters:
681
;       DS points to app's data space.
682
;------------------------------------------------------------------------------
683
 
684
restore_context:
685 28 robfinch
                lw              r1,TCB_r1[tr]
686
                lw              r2,TCB_r2[tr]
687
                lw              r3,TCB_r3[tr]
688
                lw              r4,TCB_r4[tr]
689
                lw              r5,TCB_r5[tr]
690
                lw              r6,TCB_r6[tr]
691
                lw              r7,TCB_r7[tr]
692
                lw              r8,TCB_r8[tr]
693
                lw              r9,TCB_r9[tr]
694
                lw              r10,TCB_r10[tr]
695
                lw              r11,TCB_r11[tr]
696
                lw              r12,TCB_r12[tr]
697
                lw              r13,TCB_r13[tr]
698
                lw              r14,TCB_r14[tr]
699
                lw              r15,TCB_r15[tr]
700
                lw              r16,TCB_r16[tr]
701
                lw              r17,TCB_r17[tr]
702
                lw              r18,TCB_r18[tr]
703
                lw              r19,TCB_r19[tr]
704
                lw              r20,TCB_r20[tr]
705
                lw              r21,TCB_r21[tr]
706
                lw              r22,TCB_r22[tr]
707
                lw              r23,TCB_r23[tr]
708
                lw              r24,TCB_r24[tr]
709
                lw              r25,TCB_r25[tr]
710
                lw              r26,TCB_r26[tr]
711
                lw              r27,TCB_r27[tr]
712
                lws             ds,TCB_ds[tr]
713
                lws             es,TCB_es[tr]
714
                lws             fs,TCB_fs[tr]
715
                lws             gs,TCB_gs[tr]
716
                lws             hs,TCB_hs[tr]
717
                lws             ss,TCB_ss[tr]
718
                lws             cs,TCB_cs[tr]
719
                lws             ds.lmt,TCB_dslmt[tr]
720
                lws             es.lmt,TCB_eslmt[tr]
721
                lws             fs.lmt,TCB_fslmt[tr]
722
                lws             gs.lmt,TCB_gslmt[tr]
723
                lws             hs.lmt,TCB_hslmt[tr]
724
                lws             ss.lmt,TCB_sslmt[tr]
725
                lws             cs.lmt,TCB_cslmt[tr]
726
                lws             c1,TCB_c1[tr]
727
                lws             c2,TCB_c2[tr]
728
                lws             c3,TCB_c3[tr]
729
                lws             c4,TCB_c4[tr]
730
                lws             c5,TCB_c5[tr]
731
                lws             c6,TCB_c6[tr]
732
                lws             c7,TCB_c7[tr]
733
                lws             c8,TCB_c8[tr]
734
                lws             c9,TCB_c9[tr]
735
                lws             c10,TCB_c10[tr]
736
                lws             c11,TCB_c11[tr]
737
;               lws             c13,TCB_c13[tr]
738
;               lws             c14,TCB_c14[tr]
739
                lws             pregs,TCB_pregs[tr]
740 16 robfinch
                rte
741
 
742 28 robfinch
.include "c:\cores4\thor\trunk\software\FMTK\source\kernel\FMTKc.s"
743 12 robfinch
.include "video.asm"
744 28 robfinch
.include "serial.asm"
745 12 robfinch
.include "keyboard.asm"
746
.include "debugger.asm"
747 5 robfinch
 
748 16 robfinch
 
749 5 robfinch
;------------------------------------------------------------------------------
750 16 robfinch
; BTNU IRQ routine.
751
;
752
;------------------------------------------------------------------------------
753
;
754
btnu_rout:
755
                sync
756 28 robfinch
                addui   r31,r31,#-24
757 16 robfinch
                sw              r1,[r31]
758
                sws             hs,8[r31]
759 28 robfinch
                sws             hs.lmt,16[r31]
760 16 robfinch
 
761
                ; set I/O segment
762
                ldis    hs,#$FFD00000
763 28 robfinch
                ldis    hs.lmt,#$100000
764 16 robfinch
 
765
                ; update on-screen IRQ live indicator
766 28 robfinch
                inc.h   hs:TEXTSCR+312
767 16 robfinch
 
768
                ; restore regs and return
769
                lw              r1,[r31]
770
                lws             hs,8[r31]
771 28 robfinch
                lws             hs.lmt,16[r31]
772
                addui   r31,r31,#24
773 16 robfinch
                sync
774
                rti
775
 
776
;------------------------------------------------------------------------------
777
;------------------------------------------------------------------------------
778
 
779
spur_rout:
780
                sync
781 28 robfinch
                addui   r31,r31,#-24
782 16 robfinch
                sw              r1,[r31]
783
                sws             hs,8[r31]
784 28 robfinch
                sws             hs.lmt,16[r31]
785 16 robfinch
 
786
                ; set I/O segment
787
                ldis    hs,#$FFD00000
788 28 robfinch
                ldis    hs.lmt,#$100000
789 16 robfinch
 
790
;               ldi             r1,#18
791
;               sc              r1,hs:LEDS
792
 
793
                ; update on-screen IRQ live indicator
794 28 robfinch
                inc.h   hs:TEXTSCR+316
795 16 robfinch
 
796
                ; restore regs and return
797
                lw              r1,[r31]
798
                lws             hs,8[r31]
799 28 robfinch
                lws             hs.lmt,16[r31]
800
                addui   r31,r31,#24
801 16 robfinch
                sync
802
                rti
803
 
804
;------------------------------------------------------------------------------
805 12 robfinch
; Uninitialized interrupt
806 5 robfinch
;------------------------------------------------------------------------------
807 12 robfinch
uii_rout:
808 5 robfinch
                sync
809 28 robfinch
                addui   r31,r31,#-24
810 12 robfinch
                sw              r1,[r31]
811
                sws             hs,8[r31]
812 28 robfinch
                sws             hs.lmt,16[r31]
813 5 robfinch
 
814 12 robfinch
                ; set I/O segment
815
                ldis    hs,#$FFD00000
816 28 robfinch
                ldis    hs.lmt,#$100000
817 5 robfinch
 
818 12 robfinch
                ; update on-screen IRQ live indicator
819
                ldi             r1,#'U'|%011000000_111111111_00_00000000
820
                sh              r1,hs:TEXTSCR+320
821 5 robfinch
 
822 16 robfinch
                mov             r5,r63
823
                sc              r63,hs:LEDS
824
                bsr             DisplayAddr
825
 
826
                ldi             r6,#2
827
                ldi             r2,#0
828
                ldi             r7,#0
829
.0001:
830
                ldis    60,#18          ; set breakout index to 18
831
                sync
832
                mtspr   61,r7           ; select history reg #
833
                sync
834
                ldis    60,#16          ; set breakout index to 16
835
                sync
836
                mfspr   r5,61           ; get address
837
                bsr             DisplayAddr
838
                addui   r2,r2,#1
839
                ldis    60,#17          ; set breakout index to 17
840
                sync
841
                mfspr   r5,61           ; get address
842
                bsr             DisplayAddr
843
                addui   r2,r2,#1
844
                addui   r7,r7,#1
845
                cmpi    p0,r7,#63
846
p0.ltu  br              .0001
847
 
848
uii_hang:
849
                br              uii_hang
850 12 robfinch
                ; restore regs and return
851
                lw              r1,[r31]
852
                lws             hs,8[r31]
853 28 robfinch
                lws             hs.lmt,16[r31]
854
                addui   r31,r31,#24
855 12 robfinch
                sync
856
                rti
857 5 robfinch
 
858
;------------------------------------------------------------------------------
859 12 robfinch
; Non-maskable interrupt routine.
860 5 robfinch
;
861
;------------------------------------------------------------------------------
862
;
863 12 robfinch
nmi_rout:
864
                sync
865 28 robfinch
                addui   r31,r31,#-24
866 12 robfinch
                sw              r1,[r31]
867
                sws             hs,8[r31]
868 28 robfinch
                sws             hs.lmt,16[r31]
869 5 robfinch
 
870 12 robfinch
                ; set I/O segment
871
                ldis    hs,#$FFD00000
872 28 robfinch
                ldis    hs.lmt,#$100000
873 5 robfinch
 
874 12 robfinch
                ldi             r1,#16
875
                sc              r1,hs:LEDS
876 5 robfinch
 
877 12 robfinch
                ; reset the edge sense circuit to re-enable interrupts
878
                ldi             r1,#0
879
                sh              r1,hs:PIC_ESR
880 5 robfinch
 
881 12 robfinch
                ; update on-screen IRQ live indicator
882
                lh              r1,hs:TEXTSCR+324
883
                addui   r1,r1,#1
884
                sh              r1,hs:TEXTSCR+324
885 5 robfinch
 
886 12 robfinch
                ; restore regs and return
887
                lw              r1,[r31]
888
                lws             hs,8[r31]
889 28 robfinch
                lws             hs.lmt,16[r31]
890
                addui   r31,r31,#24
891 12 robfinch
                sync
892
                rti
893 5 robfinch
 
894
;------------------------------------------------------------------------------
895 12 robfinch
; Millisecond (1024 Hz) interrupt routine.
896 5 robfinch
;
897
;------------------------------------------------------------------------------
898
;
899 12 robfinch
msi_rout:
900
                sync
901 28 robfinch
                addui   sp,sp,#-32
902
                sw              r1,[sp]
903
                sws             hs,8[sp]
904
                sws             hs.lmt,16[sp]
905
                sws             c1,24[sp]
906 5 robfinch
 
907 12 robfinch
                ; set I/O segment
908
                ldis    hs,#$FFD00000
909 28 robfinch
                ldis    hs.lmt,#$100000
910 5 robfinch
 
911 12 robfinch
                ldi             r1,#24
912
                sc              r1,hs:LEDS
913 5 robfinch
 
914 12 robfinch
                ; reset the edge sense circuit to re-enable interrupts
915
                ldi             r1,#1
916
                sh              r1,hs:PIC_ESR
917 5 robfinch
 
918 12 robfinch
                ; update milliseconds
919 28 robfinch
                lw              r1,zs:Milliseconds
920 12 robfinch
                addui   r1,r1,#1
921 28 robfinch
                sw              r1,zs:Milliseconds
922 5 robfinch
 
923
                ; restore regs and return
924 28 robfinch
                lw              r1,[sp]
925
                lws             hs,8[sp]
926
                lws             hs.lmt,16[sp]
927
                lws             c1,24[sp]
928
                addui   sp,sp,#32
929 12 robfinch
                sync
930 5 robfinch
                rti
931
 
932
;------------------------------------------------------------------------------
933 12 robfinch
; Time Slice IRQ routine.
934 5 robfinch
;
935
;------------------------------------------------------------------------------
936
;
937 12 robfinch
tms_rout:
938
                sync
939 28 robfinch
                addui   r31,r31,#-24
940 12 robfinch
                sw              r1,[r31]
941
                sws             hs,8[r31]
942 28 robfinch
                sws             hs.lmt,16[r31]
943 5 robfinch
 
944
                ; set I/O segment
945
                ldis    hs,#$FFD00000
946 28 robfinch
                ldis    hs.lmt,#$100000
947 5 robfinch
 
948 12 robfinch
                ldi             r1,#32
949
                sc              r1,hs:LEDS
950
 
951 5 robfinch
                ; reset the edge sense circuit to re-enable interrupts
952 12 robfinch
                ldi             r1,#2
953 5 robfinch
                sh              r1,hs:PIC_ESR
954
 
955
                ; update on-screen IRQ live indicator
956 28 robfinch
                inc.h   hs:TEXTSCR+328
957 5 robfinch
 
958
                ; restore regs and return
959 12 robfinch
                lw              r1,[r31]
960
                lws             hs,8[r31]
961 28 robfinch
                lws             hs.lmt,16[r31]
962
                addui   r31,r31,#24
963 12 robfinch
                sync
964 28 robfinch
                rte
965 5 robfinch
 
966
;------------------------------------------------------------------------------
967 16 robfinch
; Data bus error routine.
968 5 robfinch
;
969
;
970
;------------------------------------------------------------------------------
971
;
972 12 robfinch
dbe_rout:
973
                sync
974
                ldi             r31,#INT_STACK-24
975
                sw              r1,[r31]
976
                sws             hs,8[r31]
977
                sw              r5,16[r31]
978 5 robfinch
 
979
                ; set I/O segment
980
                ldis    hs,#$FFD00000
981
 
982 12 robfinch
                ldi             r1,#64
983
                sc              r1,hs:LEDS
984 5 robfinch
 
985 12 robfinch
                ; reset the bus error circuit to re-enable interrupts
986
                sh              r0,hs:$CFFE0
987 5 robfinch
 
988 12 robfinch
                ; update on-screen DBE indicator
989
                ldi             r1,'D'|%011000000_000000110_0000000000
990
                sh              r1,hs:TEXTSCR+320
991
 
992
                ; Advance the program to the next address
993
                mfspr   r5,c14
994
                bsr             DBGGetInsnLength
995
                addu    r1,r5,r1
996
                mtspr   c14,r1
997
 
998 5 robfinch
                ; restore regs and return
999 12 robfinch
                lw              r1,[r31]
1000
                lws             hs,8[r31]
1001
                lw              r5,16[r31]
1002
                sync
1003 5 robfinch
                rti
1004
 
1005
;------------------------------------------------------------------------------
1006
; Break routine
1007
;
1008
; Currently uses only registers in case memory is bad, and sets an indicator
1009
; on-screen.
1010
;------------------------------------------------------------------------------
1011
;
1012
brk_rout:
1013 12 robfinch
                sync
1014 5 robfinch
                ldi             r1,#'B'
1015 12 robfinch
                bsr             VBAsciiToScreen
1016 5 robfinch
                ori             r1,r1,#|%011000000_111111111_00_00000000
1017 12 robfinch
                sh              r1,zs:$FFD10140
1018 5 robfinch
                ldi             r1,#'R'
1019 12 robfinch
                bsr             VBAsciiToScreen
1020 5 robfinch
                ori             r1,r1,#|%011000000_111111111_00_00000000
1021 12 robfinch
                sh              r1,zs:$FFD10144
1022 5 robfinch
                ldi             r1,#'K'
1023 12 robfinch
                bsr             VBAsciiToScreen
1024 5 robfinch
                ori             r1,r1,#|%011000000_111111111_00_00000000
1025 12 robfinch
                sh              r1,zs:$FFD10148
1026
                ldi             r2,#10
1027
                ldi             r6,#0
1028
                mfspr   r5,c13
1029
                bsr             DisplayAddr
1030 16 robfinch
                ldi             r2,#10
1031
                ldi             r6,#1
1032
                mfspr   r5,c14
1033
                bsr             DisplayAddr
1034
                ldi             r6,#2
1035
                ldi             r2,#0
1036
                ldi             r7,#0
1037
.0001:
1038
                ldis    60,#18          ; set breakout index to 18
1039
                sync
1040
                mtspr   61,r7           ; select history reg #
1041
                sync
1042
                ldis    60,#16          ; set breakout index to 16
1043
                sync
1044
                mfspr   r5,61           ; get address
1045
                bsr             DisplayAddr
1046
                addui   r2,r2,#1
1047
                ldis    60,#17          ; set breakout index to 17
1048
                sync
1049
                mfspr   r5,61           ; get address
1050
                bsr             DisplayAddr
1051
                addui   r2,r2,#1
1052
                addui   r7,r7,#1
1053
                cmpi    p0,r7,#63
1054
p0.ltu  br              .0001
1055
 
1056 5 robfinch
brk_lockup:
1057
                br              brk_lockup[c0]
1058
 
1059
; code snippet to jump to the break routine, copied to the break vector
1060
;
1061
; vector table jumps
1062
;
1063 16 robfinch
                align   8
1064
brk_jmp:
1065
                jmp             brk_rout[c0]
1066
                align   8
1067
tms_jmp:
1068
                jmp             tms_rout[c0]
1069
                align   8
1070
msi_jmp:
1071
                jmp             msi_rout[c0]
1072
                align   8
1073
nmi_jmp:
1074
                jmp             nmi_rout[c0]
1075
                align   8
1076
uii_jmp:
1077
                ldi             r63,#00
1078
                jmp             uii_rout[c0]
1079
                align   8
1080
vb_jmp:
1081
                jmp             VideoBIOSCall[c0]
1082
                align   8
1083
dbe_jmp:
1084
                jmp             dbe_rout[c0]
1085
                align   8
1086
svc_jmp:
1087
                jmp             save_context[c0]
1088
                align   8
1089
rsc_jmp:
1090
                jmp             restore_context[c0]
1091
                align   8
1092
spur_jmp:
1093
                jmp             spur_rout[c0]
1094
                align   8
1095
btnu_jmp:
1096
                jmp             btnu_rout[c0]
1097
                align   8
1098
rti_jmp:
1099
km_jmp:
1100
                rti
1101 28 robfinch
                align   8
1102
rte_jmp:
1103
                rte
1104 5 robfinch
 
1105
;------------------------------------------------------------------------------
1106
; Reset Point
1107
;------------------------------------------------------------------------------
1108
 
1109
                org             $FFFFEFF0
1110 16 robfinch
                jmp             cold_start[c15]
1111 5 robfinch
 
1112 12 robfinch
extern my_main : 24
1113
 

powered by: WebSVN 2.1.0

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