source: trunk/libs/newlib/src/libgloss/hp74x/debugger.s @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 10.9 KB
Line 
1/****************************************************************************
2
3                THIS SOFTWARE IS NOT COPYRIGHTED
4
5   HP offers the following for use in the public domain.  HP makes no
6   warranty with regard to the software or it's performance and the
7   user accepts the software "AS IS" with all faults.
8
9   HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
10   TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
11   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12
13****************************************************************************/
14        .space  $TEXT$
15        .subspa $CODE$,access=0x2c
16
17#if 1
18#include        "diagnose.h"
19#endif
20
21i13BREAK        .equ    0xa5a                   ; im13 field for specified functions
22i5REG           .equ    0x06                    ; Init registers
23i5BP            .equ    0x09                    ; GDB breakpoin
24i5PSW           .equ    0x0b                    ; Get PSW
25i5INLINE        .equ    0x0e                    ; Get INLINE
26R_gr0           .equ     0
27R_gr1           .equ     4
28R_gr2           .equ     8
29R_gr3           .equ    12
30R_gr4           .equ    16
31R_gr5           .equ    20
32R_gr6           .equ    24
33R_gr7           .equ    28
34R_gr8           .equ    32
35R_gr9           .equ    36
36R_gr10          .equ    40
37R_gr11          .equ    44
38R_gr12          .equ    48
39R_gr13          .equ    52
40R_gr14          .equ    56
41R_gr15          .equ    60
42R_gr16          .equ    64
43R_gr17          .equ    68
44R_gr18          .equ    72
45R_gr19          .equ    76
46R_gr20          .equ    80
47R_gr21          .equ    84
48R_gr22          .equ    88
49R_gr23          .equ    92
50R_gr24          .equ    96
51R_gr25          .equ    100
52R_gr26          .equ    104
53R_gr27          .equ    108
54R_gr28          .equ    112
55R_gr29          .equ    116
56R_gr30          .equ    120
57R_gr31          .equ    124
58
59R_sr0           .equ    128
60R_sr1           .equ    132
61R_sr2           .equ    136
62R_sr3           .equ    140
63R_sr4           .equ    144
64R_sr5           .equ    148
65R_sr6           .equ    152
66R_sr7           .equ    156
67
68R_cr0           .equ    160
69R_cr1           .equ    164
70R_cr2           .equ    168
71R_cr3           .equ    172
72R_cr4           .equ    176
73R_cr5           .equ    180
74R_cr6           .equ    184
75R_cr7           .equ    188
76R_cr8           .equ    192
77R_cr9           .equ    196
78R_cr10          .equ    200
79R_cr11          .equ    204
80R_cr12          .equ    208
81R_cr13          .equ    212
82R_cr14          .equ    216
83R_cr15          .equ    220
84R_cr16          .equ    224
85R_cr17H         .equ    228
86R_cr18H         .equ    232
87R_cr19          .equ    236
88R_cr20          .equ    240
89R_cr21          .equ    244
90R_cr22          .equ    248
91R_cr23          .equ    252
92R_cr24          .equ    256
93R_cr25          .equ    260
94R_cr26          .equ    264
95R_cr27          .equ    268
96R_cr28          .equ    272
97R_cr29          .equ    276
98R_cr30          .equ    280
99R_cr31          .equ    284
100
101R_cr17T         .equ    288
102R_cr18T         .equ    292
103
104R_cpu0          .equ    296
105
106R_SIZE          .equ    300
107
108min_stack       .equ     64
109
110        .import handle_exception
111        .import $global$, data
112        .IMPORT putnum, code
113        .IMPORT led_putnum, code
114        .IMPORT delay, code
115
116        .export FICE
117        .export DEBUG_GO
118        .export DEBUG_SS
119        .export STUB_RESTORE
120
121        .export save_regs
122        .export RegBlk
123        .export Exception_index
124
125;-------------------------------------------------------------------------------
126        .EXPORT breakpoint,ENTRY,ARGW0=GR,RTNVAL=GR
127breakpoint
128        .PROC
129        .CALLINFO CALLER,FRAME=128,SAVE_RP
130        .ENTRY
131
132        stw     %r2,-20(0,%r30)                 ; stash the return pointer
133        ldo     128(%r30),%r30                  ; push up the stack pointer
134
135;;; debug
136        ldi     6, %r26
137        bl,n    led_putnum,%r2
138        nop
139        ldil    L'900000,%r26
140        ldo     R'900000(%r26),%r26
141        bl,n    delay,%r2
142        nop
143;;; 
144        break   i5INLINE,i13BREAK
145;;; more debug
146        ldi     7, %r26
147        bl,n    led_putnum,%r2
148        nop
149        ldil    L'900000,%r26
150        ldo     R'900000(%r26),%r26
151        bl,n    delay,%r2
152        nop
153;;;
154       
155FICE    fice    0(0,%r26)                       ; Flush the i cache entry
156        sync
157
158        ldw     -148(0,%r30),%r2                ; retrieve the return pointer
159        ldo     -128(%r30),%r30                 ; reset the stack pointer
160        bv,n    0(%r2)                          ; return to caller
161        nop
162
163        .EXIT
164        .PROCEND
165
166;-------------------------------------------------------------------------------
167DEBUG_GO
168        or,tr   %r0,%r0,%r10    ; if go, do not set R-bit to 1
169
170DEBUG_SS
171        ldi     1,%r10          ; else set R-bit to 1
172
173DEBUG_EXEC
174
175        bl      DGO_0,%r8                       ; r8 points to register block
176        addil   L%RegBlk-DGO_0,%r8
177DGO_0
178        ldo     R%RegBlk-DGO_0(%r1),%r8
179
180; load space registers
181
182        ldw     R_sr0(%r8),%r1
183        mtsp    %r1,%sr0
184        ldw     R_sr1(%r8),%r1
185        mtsp    %r1,%sr1
186        ldw     R_sr2(%r8),%r1
187        mtsp    %r1,%sr2
188        ldw     R_sr3(%r8),%r1
189        mtsp    %r1,%sr3
190        ldw     R_sr4(%r8),%r1
191        mtsp    %r1,%sr4
192        ldw     R_sr5(%r8),%r1
193        mtsp    %r1,%sr5
194        ldw     R_sr6(%r8),%r1
195        mtsp    %r1,%sr6
196        ldw     R_sr7(%r8),%r1
197        mtsp    %r1,%sr7
198
199; clear Q-bit for rfi
200
201        rsm     0x08,%r0
202
203; load control registers
204
205        ldw     R_cr0(%r8),%r1
206        or,=    %r10,%r0,%r0            ; if single step
207        copy    %r0,%r1                 ;   set %cr0 to 0
208        mtctl   %r1,%cr0
209        ldw     R_cr8(%r8),%r1
210        mtctl   %r1,%cr8
211        ldw     R_cr9(%r8),%r1
212        mtctl   %r1,%cr9
213        ldw     R_cr10(%r8),%r1
214        mtctl   %r1,%cr10
215        ldw     R_cr11(%r8),%r1
216        mtctl   %r1,%cr11
217        ldw     R_cr12(%r8),%r1
218        mtctl   %r1,%cr12
219        ldw     R_cr13(%r8),%r1
220        mtctl   %r1,%cr13
221        ldw     R_cr14(%r8),%r1
222        mtctl   %r1,%cr14
223        ldw     R_cr15(%r8),%r1
224        mtctl   %r1,%cr15
225        ldw     R_cr16(%r8),%r1
226        mtctl   %r1,%cr16
227        ldw     R_cr17H(%r8),%r1        ; load iiasq.head
228        mtctl   %r1,%cr17
229        ldw     R_cr18H(%r8),%r1        ; load iiaoq.head
230        mtctl   %r1,%cr18
231        ldw     R_cr17T(%r8),%r1        ; load iiasq.tail
232        mtctl   %r1,%cr17
233        ldw     R_cr18T(%r8),%r1        ; load iiaoq.tail
234        mtctl   %r1,%cr18
235        ldw     R_cr19(%r8),%r1
236        mtctl   %r1,%cr19
237        ldw     R_cr20(%r8),%r1
238        mtctl   %r1,%cr20
239        ldw     R_cr21(%r8),%r1
240        mtctl   %r1,%cr21
241        ldw     R_cr22(%r8),%r1
242        dep     %r10,27,1,%r1           ; set R-bit if applicable
243        mtctl   %r1,%cr22
244        ldw     R_cr23(%r8),%r1
245        mtctl   %r1,%cr23
246        ldw     R_cr24(%r8),%r1
247        mtctl   %r1,%cr24
248        ldw     R_cr25(%r8),%r1
249        mtctl   %r1,%cr25
250        ldw     R_cr26(%r8),%r1
251        mtctl   %r1,%cr26
252        ldw     R_cr27(%r8),%r1
253        mtctl   %r1,%cr27
254        ldw     R_cr28(%r8),%r1
255        mtctl   %r1,%cr28
256        ldw     R_cr29(%r8),%r1
257        mtctl   %r1,%cr29
258        ldw     R_cr30(%r8),%r1
259        mtctl   %r1,%cr30
260        ldw     R_cr31(%r8),%r1
261        mtctl   %r1,%cr31
262
263; load diagnose registers
264
265        ldw     R_cpu0(%r8),%r1
266        ldil    L%CPU0_MASK,%r2
267        ldo     R%CPU0_MASK(%r2),%r2
268        xor     %r1,%r2,%r1             ; xor the read/clear bits
269        nop
270        mtcpu   %r1,0
271        mtcpu   %r1,0
272
273; load general registers
274
275        ldw     R_gr1(%r8),%r1
276        ldw     R_gr2(%r8),%r2
277        ldw     R_gr3(%r8),%r3
278        ldw     R_gr4(%r8),%r4
279        ldw     R_gr5(%r8),%r5
280        ldw     R_gr6(%r8),%r6
281        ldw     R_gr7(%r8),%r7
282        ldw     R_gr9(%r8),%r9
283        ldw     R_gr10(%r8),%r10
284        ldw     R_gr11(%r8),%r11
285        ldw     R_gr12(%r8),%r12
286        ldw     R_gr13(%r8),%r13
287        ldw     R_gr14(%r8),%r14
288        ldw     R_gr15(%r8),%r15
289        ldw     R_gr16(%r8),%r16
290        ldw     R_gr17(%r8),%r17
291        ldw     R_gr18(%r8),%r18
292        ldw     R_gr19(%r8),%r19
293        ldw     R_gr20(%r8),%r20
294        ldw     R_gr21(%r8),%r21
295        ldw     R_gr22(%r8),%r22
296        ldw     R_gr23(%r8),%r23
297        ldw     R_gr24(%r8),%r24
298        ldw     R_gr25(%r8),%r25
299        ldw     R_gr26(%r8),%r26
300        ldw     R_gr27(%r8),%r27
301        ldw     R_gr28(%r8),%r28
302        ldw     R_gr29(%r8),%r29
303        ldw     R_gr30(%r8),%r30
304        ldw     R_gr31(%r8),%r31
305        ldw     R_gr8(%r8),%r8
306
307; execute user program
308
309        nop
310        rfi             ; switch to user code
311        nop
312
313;-------------------------------------------------------------------------------
314
315STUB_RESTORE
316        copy    %r1,%r9 ; save exception index
317        bl      SR_00,%r8
318        addil   L%Exception_index-SR_00,%r8
319SR_00
320        ldo     R%Exception_index-SR_00(%r1),%r8
321        stw     %r9,(%r8)
322
323        bl      save_regs,%r25
324        nop
325       
326#ifdef  DEBUG_DEBUGGER1
327        stwm    %r1,8(%sp)
328        bl      putc,%rp
329        ldi     CR,%arg0
330        bl      putc,%rp
331        ldi     LF,%arg0
332        bl      printit,%mrp
333        mfctl   %pcoq,%arg0
334
335        mfctl   %pcoq,%r1
336        mtctl   %r1,%pcoq
337        mfctl   %pcoq,%arg0
338        bl      printit,%mrp
339        mtctl   %arg0,%pcoq
340
341        bl      printit,%mrp
342        ldw     -8(%sp),%arg0
343
344        ldwm    -8(%sp),%r1
345#endif
346
347#ifdef  DEBUG_DEBUGGER2
348        stwm    %r1,8(%sp)
349        bl      putc,%rp
350        ldi     LF,%arg0
351        ldwm    -8(%sp),%r1
352#endif
353
354#ifdef  DEBUG_DEBUGGER3
355        bl      printit,%mrp
356        copy    iptr,%arg0
357        bl      printit,%mrp
358        copy    rstack,%arg0
359        bl      printit,%mrp
360        copy    gspace,%arg0
361        bl      printit,%mrp
362        copy    dstack,%arg0
363        bl      printit,%mrp
364        copy    nextptr,%arg0
365        bl      printit,%mrp
366        copy    %dp,%arg0
367        bl      printit,%mrp
368        copy    %sp,%arg0
369        bl      printit,%mrp
370        mfctl   %rctr,%arg0
371        bl      printit,%mrp
372        mfctl   %iva,%arg0
373        bl      printit,%mrp
374        mfctl   %eiem,%arg0
375        bl      printit,%mrp
376        mfctl   %ipsw,%arg0
377        bl      printit,%mrp
378        copy    %r0,%arg0
379#endif
380        bl      SR_1,%sp
381        addil   L%Stub_stack-SR_1,%sp
382SR_1
383        ldo     R%Stub_stack-SR_1(%r1),%sp      ; set the stack pointer
384
385        bl      SR_2,%arg0
386        addil   L%RegBlk-SR_2,%arg0
387SR_2
388        ldo     R%RegBlk-SR_2(%r1),%arg0        ; set arg0 (save register area)
389
390        bl      SR_3,%arg1
391        addil   L%Exception_index-SR_3,%arg1    ; set arg1 address
392SR_3
393        ldo     R%Exception_index-SR_3(%r1),%arg1       ; set arg1 address
394
395        addi    min_stack,%sp,%sp               ; allocate min stack frame
396
397        bl      handle_exception,%r2
398        ldw     0(%arg1),%arg1                  ; load arg1
399        addi    -min_stack,%sp,%sp              ; de allocate min stack frame
400
401        b       DEBUG_EXEC                      ; 
402        copy    %r28,%r10       
403;-------------------------------------------------------------------------------
404
405save_regs       ; return address is in %r25
406
407        bl      SR_0,%r1                        ; r1 points to Register block
408        addil   L%RegBlk-SR_0,%r1
409SR_0
410        ldo     R%RegBlk-SR_0(%r1),%r1
411
412; save general registers
413
414        stw     %r0,R_gr0(%r1)
415        ; don't store %r1 yet
416        stw     %r2,R_gr2(%r1)
417        stw     %r3,R_gr3(%r1)
418        stw     %r4,R_gr4(%r1)
419        stw     %r5,R_gr5(%r1)
420        stw     %r6,R_gr6(%r1)
421        stw     %r7,R_gr7(%r1)
422        ; don't store %r8 yet
423        ; don't store %r9 yet
424        stw     %r10,R_gr10(%r1)
425        stw     %r11,R_gr11(%r1)
426        stw     %r12,R_gr12(%r1)
427        stw     %r13,R_gr13(%r1)
428        stw     %r14,R_gr14(%r1)
429        stw     %r15,R_gr15(%r1)
430        ; don't store %r16 yet
431        ; don't store %r17 yet
432        stw     %r18,R_gr18(%r1)
433        stw     %r19,R_gr19(%r1)
434        stw     %r20,R_gr20(%r1)
435        stw     %r21,R_gr21(%r1)
436        stw     %r22,R_gr22(%r1)
437        stw     %r23,R_gr23(%r1)
438        ; don't store %r24 yet
439        ; don't store %r25 yet
440        stw     %r26,R_gr26(%r1)
441        stw     %r27,R_gr27(%r1)
442        stw     %r28,R_gr28(%r1)
443        stw     %r29,R_gr29(%r1)
444        stw     %r30,R_gr30(%r1)
445        stw     %r31,R_gr31(%r1)
446
447; restore general registers from shadow registers and save them
448
449        copy    %r1,%r10        ; hold Register block pointer
450        copy    %r25,%rp        ; hold return pointer
451        shdw_gr
452        shdw_gr
453        stw     %r1,R_gr1(%r10)
454        stw     %r8,R_gr8(%r10)
455        stw     %r9,R_gr9(%r10)
456        stw     %r16,R_gr16(%r10)
457        stw     %r17,R_gr17(%r10)
458        stw     %r24,R_gr24(%r10)
459        stw     %r25,R_gr25(%r10)
460
461; save control registers
462
463        mfctl   %cr0,%r1
464        stw     %r1,R_cr0(%r10)
465        stw     %r0,R_cr1(%r10)
466        stw     %r0,R_cr2(%r10)
467        stw     %r0,R_cr3(%r10)
468        stw     %r0,R_cr4(%r10)
469        stw     %r0,R_cr5(%r10)
470        stw     %r0,R_cr6(%r10)
471        stw     %r0,R_cr7(%r10)
472        mfctl   %cr8,%r1
473        stw     %r1,R_cr8(%r10)
474        mfctl   %cr9,%r1
475        stw     %r1,R_cr9(%r10)
476        mfctl   %cr10,%r1
477        stw     %r1,R_cr10(%r10)
478        mfctl   %cr11,%r1
479        stw     %r1,R_cr11(%r10)
480        mfctl   %cr12,%r1
481        stw     %r1,R_cr12(%r10)
482        mfctl   %cr13,%r1
483        stw     %r1,R_cr13(%r10)
484        mfctl   %cr14,%r1
485        stw     %r1,R_cr14(%r10)
486        mfctl   %cr15,%r1
487        stw     %r1,R_cr15(%r10)
488        mfctl   %cr16,%r1
489        stw     %r1,R_cr16(%r10)
490        mfctl   %cr17,%r1
491        stw     %r1,R_cr17H(%r10)
492        mtctl   %r1,%cr17
493        mfctl   %cr17,%r1
494        stw     %r1,R_cr17T(%r10)
495        mtctl   %r1,%cr17
496        mfctl   %cr18,%r1
497        stw     %r1,R_cr18H(%r10)
498        mtctl   %r1,%cr18
499        mfctl   %cr18,%r1
500        stw     %r1,R_cr18T(%r10)
501        mtctl   %r1,%cr18
502        mfctl   %cr19,%r1
503        stw     %r1,R_cr19(%r10)
504        mfctl   %cr20,%r1
505        stw     %r1,R_cr20(%r10)
506        mfctl   %cr21,%r1
507        stw     %r1,R_cr21(%r10)
508        mfctl   %cr22,%r1
509        stw     %r1,R_cr22(%r10)
510        mfctl   %cr23,%r1
511        stw     %r1,R_cr23(%r10)
512        mfctl   %cr24,%r1
513        stw     %r1,R_cr24(%r10)
514        mfctl   %cr25,%r1
515        stw     %r1,R_cr25(%r10)
516        mfctl   %cr26,%r1
517        stw     %r1,R_cr26(%r10)
518        mfctl   %cr27,%r1
519        stw     %r1,R_cr27(%r10)
520        mfctl   %cr28,%r1
521        stw     %r1,R_cr28(%r10)
522        mfctl   %cr29,%r1
523        stw     %r1,R_cr29(%r10)
524        mfctl   %cr30,%r1
525        stw     %r1,R_cr30(%r10)
526        mfctl   %cr31,%r1
527        stw     %r1,R_cr31(%r10)
528
529; save diagnose registers
530
531        mfcpu_c 0,%r1
532        mfcpu_c 0,%r1
533        stw     %r1,R_cpu0(%r10)
534
535; save space registers
536
537        mfsp    %sr0,%r1
538        stw     %r1,R_sr0(%r10)
539        mfsp    %sr1,%r1
540        stw     %r1,R_sr1(%r10)
541        mfsp    %sr2,%r1
542        stw     %r1,R_sr2(%r10)
543        mfsp    %sr3,%r1
544        stw     %r1,R_sr3(%r10)
545        mfsp    %sr4,%r1
546        stw     %r1,R_sr4(%r10)
547        mfsp    %sr5,%r1
548        stw     %r1,R_sr5(%r10)
549        mfsp    %sr6,%r1
550        stw     %r1,R_sr6(%r10)
551        mfsp    %sr7,%r1
552        bv      (%rp)
553        stw     %r1,R_sr7(%r10)
554
555#ifdef  DEBUG_DEBUGGER
556;-------------------------------------------------------------------------------
557printit
558        mtctl   %rp,%tr0
559        mtctl   %r1,%tr1
560        bl      putnum,%rp
561        copy    %rp,%arg0
562
563        mtctl   %mrp,%tr2
564        bl      putc,%rp
565        ldi     CR,%arg0
566        bl      putc,%rp
567        ldi     LF,%arg0
568        mfctl   %tr2,%mrp
569        mfctl   %tr1,%r1
570        bv      (%mrp)
571        mfctl   %tr0,%rp
572#endif
573        .space  $PRIVATE$
574        .subspa $DATA$,align=4,access=0x1f
575
576Exception_index
577        .word   0
578       
579RegBlk
580        .block  R_SIZE          ; register block
581
582Stub_stack
583        .block  1024
584
585        .end
Note: See TracBrowser for help on using the repository browser.