comparison level1/modules/wbug.asm @ 2185:c0bb67e4bd97

Start of WireBug
author boisy
date Mon, 09 Mar 2009 01:03:07 +0000
parents
children e10177e83238
comparison
equal deleted inserted replaced
2184:410d0f81ff00 2185:c0bb67e4bd97
1 ********************************************************************
2 * wbug - WireBug for 6809/6309
3 *
4 * $Id$
5 *
6 * For Level 1, wbug must be run from the command line in order for
7 * the debugger to be properly setup.
8 *
9 * For Level 2, this module is called by the kernel at boot time.
10 *
11 * A process can invoke the debugger by executing an os9 F$Debug instruction.
12 * SWI can also invoke the debugger but should be reserved for breakpoints only.
13 *
14 * Edt/Rev YYYY/MM/DD Modified by
15 * Comment
16 * ------------------------------------------------------------------
17 * 1 2005/04/03 Boisy G. Pitre
18 * Started.
19 *
20 * 2 2008/02/07 Boisy G. Pitre
21 * Revamped to use F$Debug for debugger entry and SWI for breakpoints.
22 * Confirmed working under Level 1, but under Level 2, system calls
23 * currently crash the CoCo 3.
24
25 NAM KrnP3
26 TTL WireBug for 6809/6309
27
28 IFP1
29 USE defsfile
30 USE dwdefs.d
31 ENDC
32
33 IFEQ LEVEL-1
34 tylg SET Prgrm+Objct
35 ELSE
36 tylg SET Systm+Objct
37 ENDC
38 atrv SET ReEnt+rev
39 rev SET $00
40 edition SET 2
41
42 cbsize EQU 24
43
44 * offsets into our on-stack storage
45 ORG 0
46 callregs RMB 2
47 IFEQ LEVEL-1
48 l1exitvct RMB 2
49 ENDC
50 combuff RMB cbsize
51 size EQU .
52
53
54 L0000 MOD eom,name,tylg,atrv,start,size
55
56 SvcTbl equ *
57 fcb F$Debug
58 fdb dbgent-*-2
59 fcb $80
60
61
62 name EQU *
63 IFEQ LEVEL-1
64 FCS /wbug/
65 ELSE
66 FCS /KrnP3/
67 FCB edition
68
69 nextname FCC /KrnP4/ next module name to link to
70 FCB C$CR
71 ENDC
72
73 subname FCS /dw3/
74
75 start
76 * attach to low level module
77 clra
78 leax subname,pcr
79 os9 F$Link
80 bcs ex@
81 IFGT Level-1
82 sty <D.DWSUB
83 ELSE
84 sty >D.DWSUB
85 ENDC
86 * install F$Debug system call
87 leay SvcTbl,pcr
88 os9 F$SSvc
89 bcs ex@
90 leax brkent,pcr get pointer to breakpoint entry
91 IFEQ LEVEL-1
92 stx >D.SWI store in D.SWI global
93 clrb clear carry
94 ex@ os9 F$Exit and exit
95 ELSE
96 stx <D.XSWI store in D.XSWI global
97 * get next KrnP module going
98 gol2 lda #tylg get next module type (same as this one!)
99 leax <nextname,pcr get address of next module name
100 os9 F$Link attempt to link to it
101 bcs ex@ no good...skip this
102 jsr ,y else go execute it
103 ex@ rts return
104 ENDC
105
106
107 * Breakpoint Entry
108 *
109 * We enter here when a process or the system executes an SWI instruction.
110 brkent
111 IFEQ LEVEL-1
112 * In Level 1, we get called right from the SWI vector, so we need to set U to point to the registers on the stack.
113 leau ,s point X to regs on stack
114 leay rtiexit,pc
115 ENDC
116 * This is a breakpoint; back up PC to point at SWI
117 ldd R$PC,u
118 subd #$01 length of SWI instruction
119 std R$PC,u
120 IFEQ LEVEL-1
121 bra cmn
122 ENDC
123
124 * Code common to both debugger and breakpoint entries
125 * Debugger Entry
126 *
127 * We enter here when a process or the system executes an os9 F$Debug instruction.
128 dbgent
129 IFEQ LEVEL-1
130 leay rtsexit,pc
131 ENDC
132 cmn pshs cc
133 orcc #IntMasks
134 leas -size,s make room on stack for temp statics
135 leax ,s point X to our temp statics
136 exg x,u exchange X and U
137 stx callregs,u save pointer to caller regs
138 IFEQ LEVEL-1
139 sty l1exitvct,u
140 ENDC
141 pshs u
142 IFGT Level-1
143 ldu <D.DWSUB
144 ELSE
145 ldu >D.DWSUB
146 ENDC
147 jsr ,u initialize I/O
148 puls u
149
150 lda #OP_WIREBUG_MODE
151 IFEQ LEVEL-1
152 ldb #$02 assume CoCo 2
153 ELSE
154 ldb #$03 assume CoCo 3
155 ENDC
156 std combuff,u
157 IFNE H6309
158 lda #$03 6309
159 ELSE
160 lda #$08 6809
161 ENDC
162 sta combuff+2,u
163 lbsr _sendtohost
164
165 * mainloop - processes requests from the server
166 mainloop
167 leax combuff,u point to comm buffer
168 pshs u
169 IFGT Level-1
170 ldu <D.DWSUB
171 ELSE
172 ldu >D.DWSUB
173 ENDC
174 l@
175 ldy #24
176 ldd #133
177 jsr 3,u get packet
178 cmpd #$0000 no data?
179 beq l@
180 puls u
181 * bcs
182 tfr y,d put checksum in D
183 subb 23,x
184 cmpb combuff+23,u does it match the checksum from the packet?
185 beq processmsg if not, send checksum error
186 bsr _sendcsumerror
187 bra mainloop
188
189 * Here we have a message with a valid checksum.
190 * Now we evaluate the command byte.
191 processmsg
192 lda combuff,u get command byte
193 cmpa #OP_WIREBUG_READMEM Read Memory?
194 lbeq _readmem branch if so
195 cmpa #OP_WIREBUG_READREGS Read Registers?
196 lbeq _readregs branch if so
197 cmpa #OP_WIREBUG_WRITEMEM Write Memory?
198 lbeq _writemem branch if so
199 cmpa #OP_WIREBUG_WRITEREGS Write Registers?
200 lbeq _writeregs branch if so
201 cmpa #OP_WIREBUG_GO Run Target?
202 bne mainloop
203
204 _go
205 * clr combuff,u
206 * bsr _sendtohost
207 leas size,s recover space on stack
208 IFEQ LEVEL-1
209 jmp [l1exitvct,u]
210 ENDC
211 rtsexit puls cc
212 clrb
213 rts
214 rtiexit puls cc
215 rti
216
217
218 * Destroys A
219 _sendcsumerror
220 lda #E$CRC
221 _senderror
222 sta combuff,u
223 bra _sendtohost
224
225 * Destroys A
226 _sendillnumerror
227 lda #16
228 bra _senderror
229
230 * This routine reads memory from the calling process' address space
231 * using F$Move.
232 _readmem
233 ldx combuff+1,u get source pointer
234 ldb combuff+3,u get count
235 cmpb #1
236 bge ok1@
237 bad1@ bsr _sendillnumerror
238 bra mainloop
239 ok1@ cmpb #22
240 bgt bad1@ if > 22, its illegal count
241
242 IFEQ LEVEL-1
243 * Level 1 copy
244 leay combuff+1,u point U to destination
245 l@ lda ,x+ get byte at Y and inc
246 sta ,y+ save byte at X and inc
247 decb done?
248 bne l@ branch if not
249 ELSE
250 * Level 2 copy
251 clra
252 tfr d,y put count in Y
253 pshs u,x save source pointer
254 leau combuff+1,u point U to destination
255 ldx D.Proc get current process pointer
256 lda P$Task,x get source task #
257 ldb D.SysTsk get destination task #
258 puls x restore source pointer
259 os9 F$Move move 'em out!
260 puls u restore statics pointer
261 ENDC
262
263 bsr _sendtohost
264 lbra mainloop
265
266
267 * This routine writes memory from the host to the calling process'
268 * address space using F$Move.
269 _writemem
270 leax combuff+4,u point X to source
271 IFEQ LEVEL-1
272 * Level 1 copy
273 ldb combuff+3,u get count of packet
274 ldy combuff+1,u get destination pointer
275 l@ lda ,x+ get byte at Y and inc
276 sta ,y+ save byte at X and inc
277 decb done?
278 bne l@ branch if not
279 ELSE
280 * Level 2
281 clra
282 ldb combuff+3,u get count of packet
283 tfr d,y put count in Y
284 pshs u,x save on stack
285 ldu combuff+1,u get destination pointer
286 ldx <D.Proc get current process pointer
287 lda <D.SysTsk get source task #
288 ldb P$Task,x get destination task #
289 puls x restore source pointer
290 os9 F$Move move 'em out!
291 puls u restore our static pointer
292 ENDC
293 ldd #$0100 assume successful write
294 bsr _sendtohost
295 lbra mainloop
296
297
298 * This routine sends the contents of combuff,u to the communications
299 * hardware.
300 *
301 * Also, we compute the checksum as we send the bytes out so that
302 * we do not have to call a separate routine.
303 *
304 * Entry:
305 * X = address of packet to send
306 _sendtohost
307 leax combuff,u
308 ldb #23 B = count of packet - 1
309 clra A = checksum
310 l@ adda ,x+ add up
311 decb until
312 bne l@ we've reached the end
313 sta ,x save computed checksum
314 leax -23,x
315 ldy #24
316 pshs u
317 IFGT Level-1
318 ldu <D.DWSUB
319 ELSE
320 ldu >D.DWSUB
321 ENDC
322 jsr 6,u write it out
323 puls u,pc
324
325
326 * Target registers: DO NOT CHANGE!
327 TASK_REGS
328 REG_STATE RMB 1
329 REG_PAGE RMB 1
330 REG_SP RMB 2
331 REG_U RMB 2
332 REG_Y RMB 2
333 REG_X RMB 2
334 REG_F RMB 1 F BEFORE E, SO W IS LEAST SIG. FIRST
335 REG_E RMB 1
336 REG_B RMB 1 B BEFORE A, SO D IS LEAST SIG. FIRST
337 REG_A RMB 1
338 REG_DP RMB 1
339 REG_CC RMB 1
340 REG_MD RMB 1
341 REG_V RMB 2
342 REG_PC RMB 2
343 TASK_REG_SZ EQU *-TASK_REGS
344
345
346 _readregs
347 ldy callregs,u get pointer to caller's regs
348 leax combuff+1,u
349 ldb R$DP,y
350 stb ,x+ DP
351 ldb R$CC,y
352 stb ,x+ CC
353 ldd R$D,y D
354 std ,x++
355 IFNE H6309
356 ldd R$W,y W
357 exg a,b
358 std ,x++
359 ELSE
360 leax 2,x
361 ENDC
362 ldd R$X,y X
363 exg a,b
364 std ,x++
365 ldd R$Y,y Y
366 exg a,b
367 std ,x++
368 ldd R$U,y U
369 exg a,b
370 std ,x++
371
372 IFNE H6309
373 * construct MD from shadow register in NitrOS-9 globals
374 lda >D.MDREG MD
375 sta ,x+
376 tfr v,d
377 std x++ V
378 ELSE
379 leax 3,x
380 ENDC
381
382 ldd R$PC,y
383 std 2,x PC
384 ldy >D.Proc get SP from proc desc
385 ldd P$SP,y
386 std ,x
387 bsr _sendtohost
388 lbra mainloop
389
390
391
392 _writeregs
393 ldy callregs,u get caller's reg ptr
394 ldd combuff+1,u
395 std R$DP,y
396 ldd combuff+3,u
397 std R$D,y
398 IFNE H6309
399 ldd combuff+5,u
400 std R$W,y
401 ENDC
402 ldd combuff+7,u
403 std R$X,y
404 ldd combuff+9,u
405 std R$Y,y
406 ldd combuff+11,u
407 std R$U,y
408
409 ldd combuff+17,u
410 std R$PC,y
411
412 ldy >D.Proc
413 std P$SP,y
414
415 lbra mainloop
416
417 EMOD
418 eom EQU *
419 END