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

Subversion Repositories thor

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

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

powered by: WebSVN 2.1.0

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