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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [zipos/] [resetdump.s] - Blame information for rev 22

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

Line No. Rev Author Line
1 22 dgisselq
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;//
2
;;
3
;; Filename:    resetdump.s
4
;;
5
;; Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
;;
7
;; Purpose:     While most of my ZipCPU programs to date have started with a
8
;;              simple assembly script to load the stack and call the program
9
;;      entry point, this is different.  This is a very complicated startup
10
;;      script designed to dump all of the internal information to the CPU
11
;;      to a UART output port.  This is on purpose.  Indeed, this may be my
12
;;      only means of debugging the device once it goes bad:
13
;;
14
;;      - To set a breakpoint
15
;;              at the location desired call kpanic(), the CPU will dump its
16
;;                      variables and restart.
17
;;              sometime before the desired clock, set the watchdog timer
18
;;                      (currently TIMER_B).  When the watchdog expires,
19
;;                      the CPU will restart.  Adjusting the watchdog will
20
;;                      adjust how long the CPU waits before restarting, and
21
;;                      may also adjust what instructions you find going on
22
;;
23
;;      - In hardware, you can set the scope.  On boot up, this resetdump
24
;;              startup will dump the value of the scope to the UART.
25
;;
26
;;      Of course, this all depends upon someone listening on the uart.  That's
27
;;      the purpose of the dumpuart.cpp program in the sw/host directory.
28
;;      That file will capture the dump so it can be examined later.
29
;;
30
;; Creator:     Dan Gisselquist, Ph.D.
31
;;              Gisselquist Technology, LLC
32
;;
33
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;//
34
;;
35
;; Copyright (C) 2015-2016, Gisselquist Technology, LLC
36
;;
37
;; This program is free software (firmware): you can redistribute it and/or
38
;; modify it under the terms of  the GNU General Public License as published
39
;; by the Free Software Foundation, either version 3 of the License, or (at
40
;; your option) any later version.
41
;;
42
;; This program is distributed in the hope that it will be useful, but WITHOUT
43
;; ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
44
;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
45
;; for more details.
46
;;
47
;; You should have received a copy of the GNU General Public License along
48
;; with this program.  (It's in the $(ROOT)/doc directory, run make with no
49
;; target there if the PDF file isn't present.)  If not, see
50
;; <http://www.gnu.org/licenses/> for a copy.
51
;;
52
;; License:     GPL, v3, as defined and found on www.gnu.org,
53
;;              http://www.gnu.org/licenses/gpl.html
54
;;
55
;;
56
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;//
57
;;
58
;;
59
        .section        .start
60
        .global         _start
61
        .type           _start,@function
62
_start:
63
; Upon reset, we must output our registers to the UART, lest we reset because
64
; of a crash
65
        STO     R0,(DBG)
66
        MOV     PC+1,R0
67
        BRA     internal_kpanic
68
        LDI     _top_of_stack,SP
69
        BRA     kernel_entry
70
 
71
        .global         kpanic
72
        .type           kpanic,@function
73
kpanic:
74
        STO     R0,(DBG)
75
        STO     R1,1(DBG)
76
        STO     R2,2(DBG)
77
        LDI     'P',R1
78
        MOV     PC+1,R0
79
        JMP     raw_put_uart
80
        LDI     'a',R1
81
        MOV     PC+1,R0
82
        JMP     raw_put_uart
83
        LDI     'n',R1
84
        MOV     PC+1,R0
85
        JMP     raw_put_uart
86
        LDI     'i',R1
87
        MOV     PC+1,R0
88
        JMP     raw_put_uart
89
        LDI     'c',R1
90
        MOV     PC+1,R0
91
        JMP     raw_put_uart
92
        LDI     ':',R1
93
        MOV     PC+1,R0
94
        JMP     raw_put_uart
95
        LDI     ' ',R1
96
        MOV     PC+1,R0
97
        JMP     raw_put_uart
98
        LDI     '\r',R1
99
        MOV     PC+1,R0
100
        JMP     raw_put_uart
101
        LDI     '\n',R1
102
        MOV     PC+1,R0
103
        JMP     raw_put_uart
104
        LOD     1(DBG),R1
105
        LOD     2(DBG),R2
106
        MOV     PC+1,R0
107
        JMP     internal_kpanic
108
        HALT
109
 
110
internal_kpanic:
111
        STO     R1,1(DBG)
112
        STO     R2,2(DBG)
113
        STO     R0,3(DBG)       ; Our return address
114
 
115
        ; R0
116
        LDI     0,R1
117
        LOD     (DBG),R2
118
        MOV     .Lcall0(PC),R0
119
        JMP     uart_put_reg_value
120
.Lcall0:
121
 
122
        ; R1
123
        LDI     1,R1
124
        LOD     1(DBG),R2
125
        MOV     .Lcall1(PC),R0
126
        JMP     uart_put_reg_value
127
.Lcall1:
128
        ; R2
129
        LDI     2,R1
130
        LOD     2(DBG),R2
131
        MOV     PC+1,R0
132
        JMP     uart_put_reg_value
133
        ; R3
134
        LDI     3,R1
135
        MOV     R3,R2
136
        MOV     PC+1,R0
137
        JMP     uart_put_reg_value
138
 
139
        ; R4
140
        LDI     4,R1
141
        MOV     R4,R2
142
        MOV     PC+1,R0
143
        JMP     uart_put_reg_value
144
 
145
        ; R5
146
        LDI     5,R1
147
        MOV     R5,R2
148
        MOV     PC+1,R0
149
        JMP     uart_put_reg_value
150
 
151
        ; R6
152
        LDI     6,R1
153
        MOV     R6,R2
154
        MOV     PC+1,R0
155
        JMP     uart_put_reg_value
156
 
157
        ; R7
158
        LDI     7,R1
159
        MOV     R7,R2
160
        MOV     PC+1,R0
161
        JMP     uart_put_reg_value
162
 
163
        ; R8
164
        LDI     8,R1
165
        MOV     R8,R2
166
        MOV     PC+1,R0
167
        JMP     uart_put_reg_value
168
 
169
        ; R9
170
        LDI     9,R1
171
        MOV     R9,R2
172
        MOV     PC+1,R0
173
        JMP     uart_put_reg_value
174
 
175
        ; R10
176
        LDI     10,R1
177
        MOV     R10,R2
178
        MOV     PC+1,R0
179
        JMP     uart_put_reg_value
180
 
181
        ; R11
182
        LDI     11,R1
183
        MOV     R11,R2
184
        MOV     PC+1,R0
185
        JMP     uart_put_reg_value
186
 
187
        ; R12
188
        LDI     12,R1
189
        MOV     R12,R2
190
        MOV     PC+1,R0
191
        JMP     uart_put_reg_value
192
 
193
        ; SP
194
        LDI     13,R1
195
        MOV     R13,R2
196
        MOV     PC+1,R0
197
        JMP     uart_put_reg_value
198
 
199
        ; uR0
200
        LDI     16,R1
201
        MOV     uR0,R2
202
        MOV     PC+1,R0
203
        JMP     uart_put_reg_value
204
 
205
        ; uR1
206
        LDI     17,R1
207
        MOV     uR1,R2
208
        MOV     PC+1,R0
209
        JMP     uart_put_reg_value
210
 
211
        LDI     18,R1
212
        MOV     uR2,R2
213
        MOV     PC+1,R0
214
        JMP     uart_put_reg_value
215
 
216
        LDI     19,R1
217
        MOV     uR3,R2
218
        MOV     PC+1,R0
219
        JMP     uart_put_reg_value
220
 
221
        LDI     20,R1
222
        MOV     uR4,R2
223
        MOV     PC+1,R0
224
        JMP     uart_put_reg_value
225
 
226
        LDI     21,R1
227
        MOV     uR5,R2
228
        MOV     PC+1,R0
229
        JMP     uart_put_reg_value
230
 
231
        LDI     22,R1
232
        MOV     uR6,R2
233
        MOV     PC+1,R0
234
        JMP     uart_put_reg_value
235
 
236
        LDI     23,R1
237
        MOV     uR7,R2
238
        MOV     PC+1,R0
239
        JMP     uart_put_reg_value
240
 
241
        LDI     24,R1
242
        MOV     uR8,R2
243
        MOV     PC+1,R0
244
        JMP     uart_put_reg_value
245
 
246
        LDI     25,R1
247
        MOV     uR9,R2
248
        MOV     PC+1,R0
249
        JMP     uart_put_reg_value
250
 
251
        LDI     26,R1
252
        MOV     uR10,R2
253
        MOV     PC+1,R0
254
        JMP     uart_put_reg_value
255
 
256
        LDI     27,R1
257
        MOV     uR11,R2
258
        MOV     PC+1,R0
259
        JMP     uart_put_reg_value
260
 
261
        LDI     28,R1
262
        MOV     uR12,R2
263
        MOV     PC+1,R0
264
        JMP     uart_put_reg_value
265
 
266
        ; uSP
267
        LDI     29,R1
268
        MOV     uSP,R2
269
        MOV     PC+1,R0
270
        JMP     uart_put_reg_value
271
 
272
        ; uCC
273
        LDI     30,R1
274
        MOV     uCC,R2
275
        MOV     PC+1,R0
276
        JMP     uart_put_reg_value
277
 
278
        ; uPC
279
        LDI     31,R1
280
        MOV     uPC,R2
281
        MOV     PC+1,R0
282
        JMP     uart_put_reg_value
283
 
284
;stack_mem_dump:
285
        ;LDI    0,R4
286
        ;LDI    _top_of_stack,R5
287
;stack_mem_dump_loop:
288
        ;MOV    R4,R1
289
        ;LOD    (R5),R2
290
        ;MOV    PC+1,R0
291
        ;JMP    uart_put_stack_value
292
        ;ADD    1,R4
293
        ;SUB    1,R5
294
        ;CMP    64,R4
295
        ;BLT    stack_mem_dump_loop
296
 
297
; Get prepared for a proper start by setting our stack register
298
        LDI     _top_of_stack,SP
299
 
300
        BRA     dump_scope
301
        ; BRA   end_internal_panic
302
 
303
; Now, do a full dump of all memory--all registers are available to us
304
dump_memory:
305
        LDI     RAM,R5
306
        LDI     0x1000,R6
307
        LDI     0x0f8,R7
308
        STO     R7,(SPIO)
309
full_mem_dump_loop:
310
        MOV     R5,R1
311
        LOD     (R5),R2
312
        MOV     PC+1,R0
313
        JMP     uart_dump_mem_value
314
        LDI     0x0f2,R7
315
        STO     R7,(SPIO)
316
 
317
        ADD     1,R5
318
        SUB     1,R6
319
        BGT     full_mem_dump_loop
320
 
321
        LDI     0x0f5,R7
322
        STO     R7,(SPIO)
323
 
324
dump_scope:
325
; Finally, do a full dump of the scope--if it had triggered
326
;   First, dump the scope control word
327
        LDI     SCOPE,R7        ; R7 = Debugging scope address
328
        MOV     R7,R1
329
        LOD     (R7),R2
330
        MOV     R2,R5           ; R5 will not be changed by a subroutine
331
        MOV     PC+1,R0
332
        BRA     uart_dump_mem_value
333
;   Then test whether or not the scope has stopped
334
        LDI     0x40000000,R1
335
        TEST    R1,R5
336
;   If not, start our kernel.
337
        BZ      dump_buserr
338
;   Otherwise, calculate the size of the scope
339
        LSR     20,R5
340
        AND     0x1f,R5
341
        LDI     1,R6
342
        LSL     R5,R6
343
;   And start dumping
344
        ADD     1,R7    ; Get the scope data address
345
dump_scope_loop:
346
        MOV     R7,R1
347
        LOD     (R7),R2
348
        MOV     PC+1,R0
349
        BRA     uart_dump_mem_value
350
        SUB     1,R6
351
        BGT     dump_scope_loop
352
 
353
dump_buserr:
354
; Dump a bus error address, if used
355
        LDI     'B',R1
356
        MOV     PC+1,R0
357
        BRA     raw_put_uart
358
        LDI     'u',R1
359
        MOV     PC+1,R0
360
        BRA     raw_put_uart
361
        LDI     's',R1
362
        MOV     PC+1,R0
363
        BRA     raw_put_uart
364
        LDI     'E',R1
365
        MOV     PC+1,R0
366
        BRA     raw_put_uart
367
        LDI     'r',R1
368
        MOV     PC+1,R0
369
        BRA     raw_put_uart
370
        LDI     'r',R1
371
        MOV     PC+1,R0
372
        BRA     raw_put_uart
373
        LDI     ':',R1
374
        MOV     PC+1,R0
375
        BRA     raw_put_uart
376
        LDI     ' ',R1
377
        MOV     PC+1,R0
378
        BRA     raw_put_uart
379
        LDI     BUSERR,R1
380
        LOD     (R1),R2
381
        MOV     PC+1,R0
382
        BRA     uart_dump_mem_value
383
 
384
end_internal_panic:
385
        LDI     '\r',R1
386
        MOV     PC+1,R0
387
        BRA     raw_put_uart
388
        LDI     '\n',R1
389
        MOV     PC+1,R0
390
        BRA     raw_put_uart
391
        LDI     '\r',R1
392
        MOV     PC+1,R0
393
        BRA     raw_put_uart
394
        LDI     '\n',R1
395
        MOV     PC+1,R0
396
        BRA     raw_put_uart
397
        LDI     0x0ff,R7
398
        STO     R7,(SPIO)
399
        LOD     3(DBG),PC
400
        JMP     R0
401
 
402
; R0 is return address
403
; R1 is register ID
404
; R2 is register to output
405
uart_put_reg_value:
406
        STO     R0,4(DBG)
407
        STO     R2,5(DBG)
408
        STO     R3,6(DBG)
409
        MOV     R1,R2
410
        LDI     'u',R1
411
        CMP     16,R2
412
        LDILO.LT 's',R1
413
        SUB.GE  16,R2
414
        MOV     PC+1,R0
415
        JMP     raw_put_uart
416
        LDI     '0',R1
417
        CMP     10,R2
418
        LDILO.GE '1',R1
419
        SUB.GE  10,R2
420
        MOV     PC+1,R0
421
        JMP     raw_put_uart
422
        MOV     R2,R1
423
        AND     15,R1
424
        MOV     PC+1,R0
425
        JMP     get_hex
426
        MOV     PC+1,R0
427
        JMP     raw_put_uart
428
        LDI     58,R1   ; A ':'
429
        MOV     PC+1,R0
430
        JMP     raw_put_uart
431
        LOD     5(DBG),R2
432
        LDI     8,R3
433
uart_put_loop:
434
        ROL     4,R2
435
        MOV     R2,R1
436
        AND     15,R1
437
        MOV     PC+1,R0
438
        JMP     get_hex
439
        MOV     PC+1,R0
440
        JMP     raw_put_uart
441
        SUB     1,R3
442
        BNZ     uart_put_loop
443
        LDI     '\r',R1
444
        MOV     PC+1,R0
445
        JMP     raw_put_uart
446
        LDI     '\n',R1
447
        MOV     PC+1,R0
448
        JMP     raw_put_uart
449
        LOD     4(DBG),R0
450
        LOD     5(DBG),R2
451
        LOD     6(DBG),R3
452
        JMP     R0
453
 
454
uart_dump_mem_value:
455
;       R0 = return address
456
;       R1 = Memory address
457
;       R2 = Memory Value
458
; Local: R3 = working value
459
        STO     R0,7(DBG)
460
        MOV     R1,R3           ; R3 = Memory address
461
        MOV     R2,R4           ; R4 = Memory Value
462
        LDI     77,R1           ; 77 = 'M'
463
        MOV     PC+1,R0
464
        JMP     raw_put_uart
465
        LDI     91,R1           ; 91 = '['
466
        MOV     PC+1,R0
467
        JMP     raw_put_uart
468
        LDI     48,R1           ; A '0'
469
        MOV     PC+1,R0
470
        JMP     raw_put_uart
471
        LDI     120,R1          ; An 'x'
472
        MOV     PC+1,R0
473
        JMP     raw_put_uart
474
        ; Set up a loop to dump things
475
        ROL     16,R3           ; Ignore the first 16 bits
476
        LDI     4,R2            ; We're going to do four hex digits here
477
        ;
478
uart_put_mem_address_loop:
479
        ROL     4,R3
480
        MOV     R3,R1
481
        AND     15,R1
482
        MOV     PC+1,R0
483
        JMP     get_hex
484
        MOV     PC+1,R0
485
        JMP     raw_put_uart
486
        SUB     1,R2
487
        BNZ     uart_put_mem_address_loop
488
        ; Put some transition characters
489
        LDI     93,R1           ; 93 = ']'
490
        MOV     PC+1,R0
491
        JMP     raw_put_uart
492
        LDI     58, R1          ; A semicolon
493
        MOV     PC+1,R0
494
        JMP     raw_put_uart
495
        LDI     32, R1          ; A space
496
        MOV     PC+1,R0
497
        JMP     raw_put_uart
498
 
499
        ; Set up a loop to dump the memory value now
500
        LDI     8,R2
501
uart_put_mem_value_loop:
502
        ROL     4,R4
503
        MOV     R4,R1
504
        AND     15,R1
505
        MOV     PC+1,R0
506
        JMP     get_hex
507
        MOV     PC+1,R0
508
        JMP     raw_put_uart
509
        SUB     1,R2
510
        BNZ     uart_put_mem_value_loop
511
        ; Clear the line
512
        LDI     '\r', R1
513
        MOV     PC+1,R0
514
        JMP     raw_put_uart
515
        LDI     '\n', R1
516
        MOV     PC+1,R0
517
        JMP     raw_put_uart
518
        ; And return from our subroutine
519
        LOD     7(DBG),R0
520
        JMP     R0
521
 
522
get_hex:
523
        ADD     0x30,R1
524
        CMP     0x39,R1
525
        ADD.GT  7,R1    ; Add 'A'-'0'-10
526
        JMP     R0
527
 
528
raw_put_uart:   ; R0 is return address, R1 is value to transmit
529
        STO     R2,8(DBG)
530
        LDI     INT_UARTTX,R2
531
        STO     R2,(PIC)        ; Clear the PIC, turn off interrupts, etc.
532
raw_put_uart_retest:
533
        LOD     (PIC),R2
534
        TEST    INT_UARTTX,R2
535
        BZ      raw_put_uart_retest
536
        STO     R1,(UART)
537
        LOD     8(DBG),R2
538
        JMP     R0
539
 
540
        .section        .fixdata
541
DBG:
542
.byte   0,0,0,0,0,0,0,0,0
543
 
544
.set    INT_UARTRX, 0x040
545
.set    INT_UARTTX, 0x080
546
.set    PIC,     0x0100
547
.set    BUSERR,  0x0101
548
.set    TMRA,    0x0102
549
.set    TMRB,    0x0103
550
.set    PWM,     0x0104
551
.set    SPIO,    0x0105
552
.set    GPIO,    0x0106
553
.set    UART,    0x0107
554
.set    VERSION, 0x0108
555
.set    SCOPE,   0x0200
556
.set    SCOPED,  0x0201
557
.set    CLOCK,   0x0800
558
.set    CONFIG,  0x0400
559
.set    TIMER,   0x0801
560
.set    STOPWATCH,0x802
561
.set    ALARM,   0x0803
562
.set    RAM,     0x2000

powered by: WebSVN 2.1.0

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