wok annotate runcom/stuff/debug.S @ rev 23726

updated vlc packages (3.0.8 -> 3.0.10)
author Hans-G?nter Theisgen
date Thu Apr 30 17:32:34 2020 +0100 (2020-04-30)
parents 289a2f495cd6
children
rev   line source
pascal@11674 1 // Usage:
pascal@11674 2 //
pascal@11674 3 // f DX:CX load one CHS sector to 0000:7C00
pascal@11674 4 // t trace one step
pascal@11674 5 // g <address> go to adrs
pascal@11674 6 // d <address> display 16 bytes, CR for next 16 bytes...
pascal@11674 7 // e <address> <words>... enter memory byte/word/dword
pascal@11674 8 // m <segment> self move
pascal@11674 9 // + <segment> default segment offset
pascal@11674 10 //
pascal@11674 11 // Example:
pascal@11674 12 // m 0FC0 move debugger to 0FC0:0000 0FC0:01FF
pascal@11674 13 // f 1 read floppy boot sector to 0000:7C00
pascal@13055 14 // f 80:1 read hard disk master boot sector to 0000:7C00
pascal@11674 15 // g 7C0E ...
pascal@11674 16
pascal@11674 17 #define REGS32 28 bytes display FS, GS and 32 bits datas for AX..DI
pascal@11674 18 #define ADJESDI 16 bytes add segment overflow support for e and d
pascal@11674 19 #define ASCIIDUMP 20 bytes display hexa and ascii datas
pascal@11674 20 #define INPUTBUFFER 3 bytes overload init code with a 32+ bytes input buffer
pascal@11674 21
pascal@11674 22 .macro pushib val
pascal@11674 23 .byte 0x6A, \val-_start
pascal@11674 24 .endm
pascal@11674 25
pascal@11674 26 #ifdef REGS32
pascal@11674 27 #define SEGREGSZ 10
pascal@11674 28 #define REGSZ 32
pascal@11674 29 #define USER_SP REGSZ+SEGREGSZ-28(%bp)
pascal@11674 30 #define FIXSP 14
pascal@11674 31 #else
pascal@11674 32 #define SEGREGSZ 6
pascal@11674 33 #define REGSZ 16
pascal@11674 34 #define USER_SP REGSZ+SEGREGSZ-14(%bp)
pascal@11674 35 #define FIXSP 10
pascal@11674 36 #endif
pascal@11674 37 #define USER_FLAGS REGSZ+SEGREGSZ+4(%bp)
pascal@11674 38 #define USER_FLAGS_HIGH REGSZ+SEGREGSZ+5(%bp)
pascal@11674 39 #define USER_IP REGSZ+SEGREGSZ(%bp)
pascal@11674 40 #define USER_CS REGSZ+SEGREGSZ+2(%bp)
pascal@11674 41 #define USER_CSIP REGSZ+SEGREGSZ(%bp)
pascal@11674 42
pascal@11674 43 #ifdef INPUTBUFFER
pascal@11674 44 //#define ABS(x) (x-(setvectors-_start))
pascal@11674 45 #define ABS(x) (x-32)
pascal@11674 46 #else
pascal@11674 47 #define ABS(x) (x)
pascal@11674 48 #endif
pascal@11674 49 .macro initcode
pascal@11674 50 movw $0x0FC0, %di # move (and jump) to 0FC0:0000
pascal@11674 51 subw $_startz-_start, USER_IP
pascal@11674 52 movw USER_IP, %ax
pascal@11674 53 shrw $4, %ax # _start MUST be aligned on paragraph
pascal@11674 54 addw USER_CS, %ax # normalize %cs to have _start=0
pascal@11674 55 movw %ax, %ds
pascal@11674 56 .endm
pascal@11674 57
pascal@11674 58 .text
pascal@11674 59 .code16
pascal@11674 60 .org 0
pascal@11674 61
pascal@11674 62 .globl _start
pascal@11674 63 _start:
pascal@11674 64 pushf
pascal@11674 65 pushw %cs
pascal@11674 66 stc
pascal@11674 67 call init # the start code will be overwritten by the input buffer
pascal@11674 68 _startz:
pascal@11674 69
pascal@11674 70 #ifdef INPUTBUFFER
pascal@11674 71 isinit:
pascal@11674 72 initcode
pascal@11674 73 addw $FIXSP, USER_SP # adjust SP with [FLAGS CS IP DS ES [FS GS]] size
pascal@11674 74 pushib setvectors
pascal@11674 75 jmp moveself
pascal@11674 76 #endif
pascal@11674 77
pascal@11674 78 setvectors:
pascal@11674 79 xorw %si, %si # set interrupt vectors in 0 segment
pascal@11674 80 movw %si, %ds
pascal@11674 81 movb $0x7D, %cl # skip nmi
pascal@11674 82 hooklp: # interrupts: 0=div0 1=step 2=nmi 3=brk 4=ov 5=bound 6=invalid
pascal@11674 83 pushw %cs
pascal@11674 84 pushib ABS(dbgstart) # set %cs:dbgstart
pascal@11674 85 popl (%si) # to interrupt vector
pascal@11674 86 skiphook:
pascal@11674 87 lodsl # %si += 4
pascal@11674 88 shrb $1,%cl
pascal@11674 89 jnc skiphook
pascal@11674 90 jnz hooklp # note %cx will be cleared: SP will be untouched
pascal@11674 91 decw (3-7)*4(%si) # update int3 vector
pascal@11674 92 jmp dbgstartz # registers are already pushed by startup code
pascal@11674 93
pascal@11674 94 regs:
pascal@11674 95 .ascii "ss"
pascal@11674 96 .ascii "di"
pascal@11674 97 .ascii "si"
pascal@11674 98 .ascii "bp"
pascal@11674 99 .ascii "sp"
pascal@11674 100 .ascii "bx"
pascal@11674 101 .ascii "dx"
pascal@11674 102 .ascii "cx"
pascal@11674 103 .ascii "ax"
pascal@11674 104 #ifdef REGS32
pascal@11674 105 .ascii "gs"
pascal@11674 106 .ascii "fs"
pascal@11674 107 #endif
pascal@11674 108 .ascii "es"
pascal@11674 109 .ascii "ds"
pascal@11674 110 .ascii "ip"
pascal@11674 111 .ascii "cs"
pascal@11674 112 # Bit Label Desciption
pascal@11674 113 # ---------------------------
pascal@11674 114 # 0 CF Carry flag
pascal@11674 115 # 2 PF Parity flag
pascal@11674 116 # 4 AF Auxiliary carry flag
pascal@11674 117 # 6 ZF Zero flag
pascal@11674 118 # 7 SF Sign flag
pascal@11674 119 # 8 TF Trap flag
pascal@11674 120 # 9 IF Interrupt enable flag
pascal@11674 121 # 10 DF Direction flag
pascal@11674 122 # 11 OF Overflow flag
pascal@11674 123 #ifdef REGS32
pascal@11674 124 .ascii "odi|sz|a|p|c" # flags bits
pascal@11674 125 #else
pascal@11674 126 .ascii "oditsz?a?p c=" # flags bits
pascal@11674 127 #endif
pascal@11674 128 # 12-13 IOPL I/O Priviledge level
pascal@11674 129 # 14 NT Nested task flag
pascal@11674 130 # 16 RF Resume flag
pascal@11674 131 # 17 VM Virtual 8086 mode flag
pascal@11674 132 # 18 AC Alignment check flag (486+)
pascal@11674 133 # 19 VIF Virutal interrupt flag
pascal@11674 134 # 20 VIP Virtual interrupt pending flag
pascal@11674 135 # 21 ID ID flag
pascal@11674 136
pascal@11674 137 #ifdef INPUTBUFFER
pascal@11674 138 ismove:
pascal@11674 139 pushw %ax
pascal@11674 140 moveself:
pascal@11674 141 popw %si
pascal@11674 142 #else
pascal@11674 143 isinit:
pascal@11674 144 initcode
pascal@11674 145 ismove:
pascal@11674 146 xorw %si, %si
pascal@11674 147 #endif
pascal@11674 148 movw %di, %es # move code to %di:0
pascal@11674 149 pushw %di
pascal@11674 150 #ifdef INPUTBUFFER
pascal@11674 151 xorw %di, %di # and jmp into (%di:setvectors) with retf
pascal@11674 152 #else
pascal@11674 153 movw $setvectors, %di # and jmp into (%di:setvectors) with retf
pascal@11674 154 movw %di, %si
pascal@11674 155 #endif
pascal@11674 156 movw $_end-setvectors, %cx
pascal@11674 157 pushw %di
pascal@11674 158 rep movsb
pascal@11674 159 retf
pascal@11674 160
pascal@11674 161 int3:
pascal@11674 162 .byte 0x68 # push $0x086A OV UP DI NT PL ZR - NA - PO - NC
pascal@11674 163 # interrupt entry point: the registers [FLAGS CS IP] are already pushed
pascal@11674 164 dbgstart:
pascal@11674 165 .byte 0x6A, 0x08 # push $0x08 NV UP DI NT PL NZ - NA - PO - NC
pascal@11674 166 popf
pascal@11674 167 init:
pascal@11674 168 pushw %ds
pascal@11674 169 pushw %es
pascal@11674 170 #ifdef REGS32
pascal@11674 171 pushw %fs
pascal@11674 172 pushw %gs
pascal@11674 173 pushal # [FLAGS CS IP DS ES FS GS] EAX ECX EDX EBX ESP EBP ESI EDI [SS]
pascal@11674 174 #else
pascal@11674 175 pushaw # [FLAGS CS IP DS ES] AX CX DX BX SP BP SI DI [SS]
pascal@11674 176 #endif
pascal@11674 177 pushw %ss
pascal@11674 178 movw %sp, %bp
pascal@11674 179 #ifndef INPUTBUFFER
pascal@11674 180 pushf
pascal@11674 181 addw $FIXSP, USER_SP # adjust SP with [FLAGS CS IP DS ES [FS GS]] size
pascal@11674 182 popf
pascal@11674 183 #endif
pascal@11674 184 jc isinit
pascal@11674 185 jnz notint3
pascal@11674 186 decw USER_IP
pascal@11674 187 lesw USER_CSIP, %di
pascal@11674 188 #define OPCODE_BRK 0xCC
pascal@11674 189 .byte 0xB0 # movb $IM, %al
pascal@11674 190 break:
pascal@11674 191 .byte 0xCC
pascal@11674 192 stosb
pascal@11674 193 notint3:
pascal@11674 194 #ifdef INPUTBUFFER
pascal@11674 195 addw $FIXSP, USER_SP # adjust SP with [FLAGS CS IP DS ES [FS GS]] size
pascal@11674 196 #endif
pascal@11674 197 dbgstartz:
pascal@11674 198 dbgregslp:
pascal@11674 199 pushw %cs
pascal@11674 200 popw %ds
pascal@11674 201 movw $ABS(regs), %si
pascal@11674 202 #ifdef REGS32
pascal@11674 203 subw %si, %bp
pascal@11674 204 movw $15, %cx
pascal@11674 205 #else
pascal@11674 206 movw $13, %cx
pascal@11674 207 #endif
pascal@11674 208 regslp:
pascal@11674 209 call putreg # display register name and value
pascal@11674 210 loop regslp
pascal@11674 211 #ifdef REGS32
pascal@11674 212 movw (%bp,%si), %dx # get flags
pascal@11674 213 #else
pascal@11674 214 movw USER_FLAGS, %dx
pascal@11674 215 pushw %si
pascal@11674 216 stc # add trailing =
pascal@11674 217 #endif
pascal@11674 218 movb $13, %cl
pascal@11674 219 rcrw %cl, %dx
pascal@11674 220 nextbit:
pascal@11674 221 lodsb
pascal@11674 222 shlw $1, %dx
pascal@11674 223 #ifdef REGS32
pascal@11674 224 jnc skipflag
pascal@11674 225 cmpb $'|', %al # remove system flags
pascal@11674 226 je skipflag
pascal@11674 227 call dbgputc
pascal@11674 228 skipflag:
pascal@11674 229 #else
pascal@11674 230 call dbgputcbit # display active flags bits
pascal@11674 231 #endif
pascal@11674 232 loop nextbit
pascal@11674 233 #ifdef REGS32
pascal@11674 234 movw %sp, %bp
pascal@11674 235 #else
pascal@11674 236 popw %si
pascal@11674 237 movb $8, %cl
pascal@11674 238 stacklp:
pascal@11674 239 lodsw # si += 2
pascal@11674 240 call putr16 # display flags and the beginning of the stack
pascal@11674 241 loop stacklp
pascal@11674 242 #endif
pascal@11674 243 call getline
pascal@11674 244 lodsb
pascal@11674 245 xchgw %ax, %di
pascal@11674 246 call getval
pascal@11674 247 .byte 0x81, 0xC3 # addw $0, %bx
pascal@11674 248 offset_value:
pascal@11674 249 .word 0
pascal@11674 250 movw %bx, %es
pascal@11674 251 xchgw %ax, %di
pascal@11674 252 subb $'m', %al
pascal@11674 253 je ismove
pascal@11674 254 subb $'+'-'m', %al
pascal@11674 255 jne not_offset
pascal@11674 256 movw %di, ABS(offset_value)
pascal@11674 257 not_offset:
pascal@11674 258 orb $1, USER_FLAGS_HIGH # set TF
pascal@11674 259 subb $'t'-'+', %al
pascal@11674 260 je done
pascal@11674 261 subb $'d'-'t', %al
pascal@11674 262 xchgw %ax, %cx
pascal@11674 263 jcxz dump # 'd' ?
pascal@11674 264 loop noenter # 'e' ?
pascal@11674 265 nextval:
pascal@11674 266 call getval
pascal@11674 267 jcxz dbgregslp
pascal@11674 268 xchgb %dl, %dh
pascal@11674 269 mextmsb:
pascal@11674 270 stosb
pascal@11674 271 xchgw %ax, %dx
pascal@11674 272 xchgb %al, %dh
pascal@11674 273 #ifdef ADJESDI
pascal@11674 274 call adjustESDI
pascal@11674 275 #endif
pascal@11674 276 decw %cx
pascal@11674 277 loopne mextmsb
pascal@11674 278 jmp nextval
pascal@11674 279 noenter:
pascal@11674 280 loop not_floppy_load # f DX:CX ?
pascal@11674 281 movw %es, %dx
pascal@11674 282 movw %cx, %es
pascal@11674 283 movw %di, %cx
pascal@11674 284 movw $0x0201, %ax
pascal@11674 285 movw $0x7C00, %bx
pascal@11674 286 pushw %bx
pascal@11674 287 int $0x13
pascal@11674 288 popw %di
pascal@11674 289 godbgregslpifc:
pascal@11674 290 jc dbgregslp
pascal@11674 291 dump:
pascal@11674 292 movw %es, %ax
pascal@11674 293 call putax
pascal@11674 294 movw %di, %ax
pascal@11674 295 call putax
pascal@11674 296 movw $16, %cx
pascal@11674 297 dhex:
pascal@11674 298 movb %es:(%di), %ah
pascal@11674 299 #ifdef ASCIIDUMP
pascal@11674 300 movb %ah, (%si)
pascal@11674 301 incw %si
pascal@11674 302 #endif
pascal@11674 303 #ifdef ADJESDI
pascal@11674 304 call incESDI
pascal@11674 305 #else
pascal@11674 306 incw %di
pascal@11674 307 #endif
pascal@11674 308 #ifdef REGS32
pascal@11674 309 movb $0x30, %dh # the data has 2 digits
pascal@11674 310 #else
pascal@11674 311 movb $0x01, %dh # the data has 2 digits
pascal@11674 312 #endif
pascal@11674 313 call putx
pascal@11674 314 loop dhex
pascal@11674 315 #ifdef ASCIIDUMP
pascal@11674 316 movb $16, %cl
pascal@11674 317 subw %cx, %si
pascal@11674 318 dascii:
pascal@11674 319 lodsb
pascal@11674 320 cmpb $0x7F, %al
pascal@11674 321 jnc skipascii
pascal@11674 322 cmpb $0x20, %al
pascal@11674 323 cmc
pascal@11674 324 skipascii:
pascal@11674 325 call dbgputcbit
pascal@11674 326 loop dascii
pascal@11674 327 #endif
pascal@11674 328 call dbgputcr
pascal@11674 329 int $0x16
pascal@11674 330 cmpb $13, %al
pascal@11674 331 je dump
pascal@11674 332 notdump:
pascal@11674 333 not_floppy_load:
pascal@11674 334 stc
pascal@11674 335 loop godbgregslpifc # g ?
pascal@11674 336 isgo:
pascal@11674 337 andb $0xfe, USER_FLAGS_HIGH # clear TF
pascal@11674 338 xchgw %ax, %cx
pascal@11674 339 jcxz done
pascal@11674 340 setbreak:
pascal@11674 341 movb $OPCODE_BRK, %al
pascal@11674 342 xchgb %al, %es:(%di)
pascal@11674 343 movb %al, ABS(break)
pascal@11674 344 done:
pascal@11674 345 popw %ax # %ss
pascal@11674 346 #ifdef REGS32
pascal@11674 347 popal
pascal@11674 348 popw %gs
pascal@11674 349 popw %fs
pascal@11674 350 #else
pascal@11674 351 popaw
pascal@11674 352 #endif
pascal@11674 353 popw %es
pascal@11674 354 popw %ds
pascal@11674 355 iret
pascal@11674 356
pascal@11674 357 #ifdef ADJESDI
pascal@11674 358 adjustESDI:
pascal@11674 359 decw %di
pascal@11674 360 incESDI:
pascal@11674 361 incw %di
pascal@11674 362 jnz esok
pascal@11674 363 pushw %es
pascal@11674 364 addb $0x10,-3(%bp)
pascal@11674 365 popw %es
pascal@11674 366 esok:
pascal@11674 367 ret
pascal@11674 368 #endif
pascal@11674 369
pascal@11674 370 putreg:
pascal@11674 371 call dbgput2c
pascal@11674 372 movb $'=', %al
pascal@11674 373 call dbgputc
pascal@11674 374 putr16:
pascal@11674 375 #ifdef REGS32
pascal@11674 376 movl -2(%bp,%si), %eax
pascal@11674 377 movw $0x3FC0, %dx # check bits 7..14
pascal@11674 378 shrw %cl, %dx
pascal@11674 379 putax:
pascal@11674 380 movb $0xF0, %dh # the data has 4 digits
pascal@11674 381 jnc putx # 16 bits register ?
pascal@11674 382 incw %bp # a 32 bits register, not 16 bits
pascal@11674 383 incw %bp
pascal@11674 384 movb $0xFF, %dh # the data has 8 digits
pascal@11674 385 jmp putx
pascal@11674 386 putxlp:
pascal@11674 387 #else
pascal@11674 388 # movw _start-ABS(regs)-2(%bp,%si), %ax
pascal@11674 389 .byte 0x8b, 0x42, _start-ABS(regs)-2
pascal@11674 390 putax:
pascal@11674 391 movb $0x07, %dh # the data has 4 digits
pascal@11674 392 putx:
pascal@11674 393 putxlp:
pascal@11674 394 rolw $4, %ax
pascal@11674 395 #endif
pascal@11674 396 pushw %ax
pascal@11674 397 andb $0xf, %al
pascal@11674 398 addb $0x90, %al
pascal@11674 399 daa
pascal@11674 400 adcb $0x40, %al
pascal@11674 401 daa
pascal@11674 402 call dbgputc
pascal@11674 403 popw %ax
pascal@11674 404 #ifdef REGS32
pascal@11674 405 putx:
pascal@11674 406 roll $4, %eax
pascal@11674 407 #endif
pascal@11674 408 shrb $1, %dh
pascal@11674 409 jc putxlp
pascal@11674 410 #ifdef REGS32
pascal@11674 411 jnz putx
pascal@11674 412 #endif
pascal@11674 413 dbgputcbit:
pascal@11674 414 jc dbgputc
pascal@11674 415 mov $0x20, %al
pascal@11674 416 dbgputc:
pascal@11674 417 movw $7, %bx
pascal@11674 418 mov $0xE, %ah
pascal@11674 419 int $0x10
pascal@11674 420 xchgw %ax, %bx
pascal@11674 421 # clc # for putax
pascal@11674 422 ret
pascal@11674 423
pascal@11674 424 # get value in DX:AX, BX is segment CX is digits count.
pascal@11674 425 getval:
pascal@11674 426 xorw %ax, %ax
pascal@11674 427 xorw %bx, %bx
pascal@11674 428 xorw %cx, %cx
pascal@11674 429 getvalz:
pascal@11674 430 xchgw %ax, %bx
pascal@11674 431 cwd
pascal@11674 432 decw %cx
pascal@11674 433 isx:
pascal@11674 434 shll $4, %edx
pascal@11674 435 orb %al, %dl
pascal@11674 436 incw %cx
pascal@11674 437 gotspc:
pascal@11674 438 getvallp:
pascal@11674 439 lodsb
pascal@11674 440 cmpb $0x20, %al # heat heading spaces
pascal@11674 441 jne notspc
pascal@11674 442 jcxz gotspc
pascal@11674 443 notspc:
pascal@11674 444 subb $'0', %al
pascal@11674 445 cmpb $10, %al # in 0..9 ?
pascal@11674 446 jb isx
pascal@11674 447 subb $'a'-'0'-10, %al
pascal@11674 448 cmpb $16, %al # in a..f ?
pascal@11674 449 jb isx
pascal@11674 450 cmpb $':'-'a'+10, %al
pascal@11674 451 pushl %edx
pascal@11674 452 popw %ax
pascal@11674 453 popw %dx
pascal@11674 454 je getvalz # store segment in %bx
pascal@11674 455 pushw %dx
pascal@11674 456 shlw $12, %dx
pascal@11674 457 orw %dx, %bx
pascal@11674 458 popw %dx
pascal@11674 459 ret
pascal@11674 460
pascal@11674 461 getline:
pascal@11674 462 call dbgputcr
pascal@11674 463 getlinebs:
pascal@11674 464 cmpw $ABS(buffer), %si
pascal@11674 465 je getc
pascal@11674 466 decw %si
pascal@11674 467 getlinelp:
pascal@11674 468 call dbgputc
pascal@11674 469 getc:
pascal@11674 470 int $0x16
pascal@11674 471 cmpb $8, %al
pascal@11674 472 je getlinebs
pascal@11674 473 orb $0x20, %al
pascal@11674 474 movb %al, (%si)
pascal@11674 475 inc %si
pascal@11674 476 cmpb $0x2D, %al
pascal@11674 477 jne getlinelp
pascal@11674 478 dbgputcr:
pascal@11674 479 movw $ABS(crlf), %si
pascal@11674 480 dbgput2c:
pascal@11674 481 call dbgput1c
pascal@11674 482 dbgput1c:
pascal@11674 483 lodsb
pascal@11674 484 jmp dbgputc
pascal@11674 485
pascal@11674 486 crlf:
pascal@11674 487 .byte 13,10
pascal@11674 488 _end:
pascal@11674 489 buffer:
pascal@11674 490
pascal@11674 491 .org 510
pascal@11674 492 .byte 0x55, 0xAA
pascal@11674 493