]> git.sur5r.net Git - cc65/blob - libsrc/dbg/dbgsupp.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / dbg / dbgsupp.s
1 ;
2 ; Ullrich von Bassewitz, 08.08.1998
3 ;
4 ; Support routines for the debugger
5 ;
6
7         .export         _DbgInit
8         .export         _DbgSP, _DbgCS, _DbgHI
9         .import         popax, return0, _DbgEntry, _set_brk, _end_brk
10         .import         _DbgBreaks
11         .import         _brk_pc
12         .importzp       sp, sreg, ptr1, tmp1, zpspace
13
14 ; C callable function, will install the debugger
15
16 _DbgInit:
17         lda     #<DbgBreak
18         ldx     #>DbgBreak
19         jmp     _set_brk
20
21
22 ; Entry for the break vector.
23
24 DbgBreak:
25         pla
26         sta     retsav
27         pla
28         sta     retsav+1
29
30         cli
31         tsx                     ; Stack pointer
32         stx     _DbgSP
33
34         jsr     DbgSwapZP       ; Swap stuff
35         lda     #<DbgStack      ; Set new stack
36         sta     sp
37         lda     #>DbgStack
38         sta     sp+1
39         jsr     ResetDbgBreaks  ; Reset temporary breakpoints
40         jsr     _DbgEntry       ; Call C code
41         jsr     SetDbgBreaks    ; Set temporary breakpoints
42         jsr     DbgSwapZP       ; Swap stuff back
43
44         lda     retsav+1
45         pha
46         lda     retsav
47         pha
48         rts
49
50
51
52 ; Stack used when in debugger mode
53
54 .bss
55         .res    256
56 DbgStack:
57
58 ; Swap space for the the C temporaries
59
60 CTemp:
61 _DbgCS: .res    2               ; sp
62 _DbgHI: .res    2               ; sreg
63         .res    22              ; Other stuff
64 _DbgSP: .res    1
65 retsav: .res    2               ; Save buffer for return address
66
67 .code
68
69 ; Swap the C temporaries
70
71 DbgSwapZP:
72         ldy     #zpspace-1
73 Swap1:  ldx     CTemp,y
74         lda     sp,y            ; ######
75         sta     CTemp,y
76         txa
77         sta     sp,y
78         dey
79         bpl     Swap1
80         rts
81
82 ; ----------------------------------------------------------------------------
83 ; Utility functions
84
85
86 ; Set/reset the breakpoints. We must do that here since the breakpoints
87 ; may be in the runtime stuff, causing the C part to fail before it has
88 ; reset the breakpoints. See declaration of struct breakpoint in the C
89 ; source
90
91 MaxBreaks       = 48            ; 4*12
92
93 ResetDbgBreaks:
94         ldy     #0
95         ldx     #0
96 L4:     lda     _DbgBreaks+3,x  ; Get bk_use
97         beq     L6              ; Jump if not set
98         bpl     L5              ; Jump if user breakpoint
99         lda     #0
100         sta     _DbgBreaks+3,x  ; Clear if temp breakpoint
101 L5:     lda     _DbgBreaks+1,x  ; PC hi
102         sta     ptr1+1
103         lda     _DbgBreaks,x    ; PC lo
104         sta     ptr1
105         lda     _DbgBreaks+2,x  ; Old OPC
106         sta     (ptr1),y        ; Reset the breakpoint
107 L6:     inx
108         inx
109         inx
110         inx
111         cpx     #MaxBreaks      ; Done?
112         bne     L4
113         rts
114
115 SetDbgBreaks:
116         ldx     #0
117         ldy     #0
118 L7:     lda     _DbgBreaks+3,x  ; Get bk_use
119         beq     L8              ; Jump if not set
120         lda     _DbgBreaks+1,x  ; PC hi
121         sta     ptr1+1
122         lda     _DbgBreaks,x    ; PC lo
123         sta     ptr1
124         lda     (ptr1),y        ; Get the breakpoint OPC...
125         sta     _DbgBreaks+2,x  ; ...and save it
126         lda     #$00            ; Load BRK opcode
127         sta     (ptr1),y
128 L8:     inx
129         inx
130         inx
131         inx
132         cpx     #MaxBreaks      ; Done?
133         bne     L7
134         rts
135
136 ; Get a free breakpoint slot or return 0
137
138         .export         _DbgGetBreakSlot
139
140 _DbgGetBreakSlot:
141         ldx     #0
142 L10:    lda     _DbgBreaks+3,x  ; Get bk_use
143         beq     L11             ; Jump if not set
144         inx
145         inx
146         inx
147         inx
148         cpx     #MaxBreaks      ; Done?
149         bne     L10
150         jmp     return0         ; No free slot
151
152 L11:    stx     tmp1
153         lda     #<_DbgBreaks
154         ldx     #>_DbgBreaks
155         clc
156         adc     tmp1
157         bcc     L12
158         inx
159 L12:    ldy     #1              ; Force != 0
160         rts
161
162
163 ; Check if a given address has a user breakpoint set, if found, return the
164 ; slot, otherwise return 0.
165
166         .export         _DbgIsBreak
167
168 _DbgIsBreak:
169         jsr     popax           ; Get address
170         sta     ptr1
171         stx     ptr1+1
172         ldx     #0
173 L20:    lda     _DbgBreaks+3,x  ; Get bk_use
174         beq     L21             ; Jump if not set
175         bmi     L21             ; Jump if temp breakpoint
176         lda     _DbgBreaks,x    ; Low byte of address
177         cmp     ptr1
178         bne     L21
179         lda     _DbgBreaks+1,x  ; High byte of address
180         cmp     ptr1+1
181         beq     L22
182 L21:    inx
183         inx
184         inx
185         inx
186         cpx     #MaxBreaks      ; Done?
187         bne     L20
188         jmp     return0         ; Not found
189
190 L22:    stx     tmp1
191         lda     #<_DbgBreaks
192         ldx     #>_DbgBreaks
193         clc
194         adc     tmp1
195         bcc     L23
196         inx
197 L23:    ldy     #1              ; Force != 0
198         rts
199
200
201