wok-4.x diff runcom/stuff/debug8086.S @ rev 12317

Add vkeybd
author Richard Dunbar <mojo@slitaz.org>
date Sat Aug 11 01:38:53 2012 +0000 (2012-08-11)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/runcom/stuff/debug8086.S	Sat Aug 11 01:38:53 2012 +0000
     1.3 @@ -0,0 +1,477 @@
     1.4 +// Usage:
     1.5 +//
     1.6 +// f DX:CX                 load one CHS sector to 0000:7C00
     1.7 +// t                       trace one step
     1.8 +// g <address>             go to adrs
     1.9 +// d <address>             display 16 bytes, CR for next 16 bytes...
    1.10 +// e <address> <words>...  enter memory byte/word/dword
    1.11 +// m <segment>             self move
    1.12 +// + <segment>             default segment offset
    1.13 +//
    1.14 +// Example:
    1.15 +// m 0FC0                  move debugger to 0FC0:0000 0FC0:01FF
    1.16 +// f 1			   read floppy boot sector to 0000:7C00
    1.17 +// f 80 1		   read hard disk master boot sector to 0000:7C00
    1.18 +// g 7C0E		   ...
    1.19 +
    1.20 +#define ADJESDI		16 bytes	add segment overflow support for e and d
    1.21 +#define ASCIIDUMP	20 bytes	display hexa and ascii datas
    1.22 +#define INPUTBUFFER	 2 bytes	overload init code with a 32+ bytes input buffer
    1.23 +//#define CPU186       -26 bytes	80186+ CPU
    1.24 +
    1.25 +.macro pusham
    1.26 +	pushw	%ax
    1.27 +	pushw	%cx
    1.28 +	pushw	%dx
    1.29 +	pushw	%bx
    1.30 +	movw	%sp, %bx
    1.31 +	leaw	14(%bx), %bx	# adjust SP with [FLAGS CS IP AX CX DX BX] size
    1.32 +	pushw	%bx	# %sp
    1.33 +	pushw	%bp
    1.34 +	pushw	%si
    1.35 +	pushw	%di
    1.36 +.endm
    1.37 +
    1.38 +.macro popam
    1.39 +	popw	%di
    1.40 +	popw	%si
    1.41 +	popw	%bp
    1.42 +	popw	%ax	# %sp
    1.43 +	popw	%bx
    1.44 +	popw	%dx
    1.45 +	popw	%cx
    1.46 +	popw	%ax
    1.47 +.endm
    1.48 +
    1.49 +#ifdef INPUTBUFFER
    1.50 +//#define ABS(x)		(x-(setvectors-_start))
    1.51 +#define ABS(x)		(x-30)
    1.52 +#else
    1.53 +#define ABS(x)		(x)
    1.54 +#endif
    1.55 +
    1.56 +#define SEGREGSZ	6
    1.57 +#define REGSZ	16
    1.58 +#define USER_SP		REGSZ+SEGREGSZ-10(%bp)
    1.59 +#define USER_FLAGS	REGSZ+SEGREGSZ+4(%bp)
    1.60 +#define USER_FLAGS_HIGH	REGSZ+SEGREGSZ+5(%bp)
    1.61 +#define USER_IP		REGSZ+SEGREGSZ(%bp)
    1.62 +#define USER_CS		REGSZ+SEGREGSZ+2(%bp)
    1.63 +#define USER_CSIP	REGSZ+SEGREGSZ(%bp)
    1.64 +
    1.65 +.macro initcode
    1.66 +	movw	$0x0FC0, %di	# move (and jump) to 0FC0:0000
    1.67 +	subw	$_startz-_start, USER_IP
    1.68 +	movw	USER_IP, %ax
    1.69 +#ifdef CPU186
    1.70 +	cld			# ensure movsb will work
    1.71 +	shrw	$4, %ax		# _start MUST be aligned on paragraph
    1.72 +#else
    1.73 +	movb	$4, %cl
    1.74 +	shrw	%cl, %ax	# _start MUST be aligned on paragraph
    1.75 +#endif
    1.76 +	addw	USER_CS, %ax	# normalize %cs to have _start=0
    1.77 +	movw	%ax, %ds
    1.78 +.endm
    1.79 +	.text
    1.80 +	.code16
    1.81 +#ifdef CPU186
    1.82 +	.arch	i186
    1.83 +#else
    1.84 +	.arch	i8086
    1.85 +#endif
    1.86 +	.org	0
    1.87 +
    1.88 +	.globl	_start
    1.89 +_start:
    1.90 +	pushf
    1.91 +	pushw	%cs
    1.92 +	stc
    1.93 +	call	init		# the start code will be overwritten by the input buffer
    1.94 +_startz:
    1.95 +
    1.96 +#ifdef INPUTBUFFER
    1.97 +isinit:
    1.98 +	initcode
    1.99 +	movw	$setvectors, %si
   1.100 +	jmp	moveself
   1.101 +#endif
   1.102 +
   1.103 +setvectors:
   1.104 +	xorw	%si, %si	# set interrupt vectors in 0 segment
   1.105 +	movw	%si, %ds
   1.106 +	movb	$0xF9, %ch	# skip nmi
   1.107 +hooklp:				# interrupts: 0=div0 1=step 2=nmi 3=brk 4=ov 5=bound 6=invalid
   1.108 +	movw	$ABS(dbgstart), (%si)	# set %cs:dbgstart
   1.109 +	lodsw			# %si += 2
   1.110 +	movw	%cs, (%si)	# to interrupt vector
   1.111 +skiphook:
   1.112 +	lodsw			# %si += 2
   1.113 +	shrb	$1,%ch
   1.114 +	jnc	skiphook
   1.115 +	jnz	hooklp		# note %cx will be cleared: SP will be untouched
   1.116 +#ifdef CPU186
   1.117 +	decw	(3-7)*4(%si)	# update int3 vector
   1.118 +#else
   1.119 +	movb	$ABS(int3), (3-7)*4(%si)	# update int3 vector
   1.120 +#endif
   1.121 +	jmp	dbgstartz	# registers are already pushed by startup code
   1.122 +
   1.123 +regs:
   1.124 +	.ascii	"ss"
   1.125 +	.ascii	"es"
   1.126 +	.ascii	"ds"  
   1.127 +	.ascii	"di"  
   1.128 +	.ascii	"si"  
   1.129 +	.ascii	"bp"  
   1.130 +	.ascii	"sp"  
   1.131 +	.ascii	"bx"  
   1.132 +	.ascii	"dx"  
   1.133 +	.ascii	"cx"  
   1.134 +	.ascii	"ax"  
   1.135 +	.ascii	"ip"  
   1.136 +	.ascii	"cs"  
   1.137 +# Bit   Label    Desciption
   1.138 +# ---------------------------
   1.139 +# 0      CF      Carry flag
   1.140 +# 2      PF      Parity flag
   1.141 +# 4      AF      Auxiliary carry flag
   1.142 +# 6      ZF      Zero flag
   1.143 +# 7      SF      Sign flag
   1.144 +# 8      TF      Trap flag
   1.145 +# 9      IF      Interrupt enable flag
   1.146 +# 10     DF      Direction flag
   1.147 +# 11     OF      Overflow flag
   1.148 +	.ascii	"oditsz?a?p c="	# flags bits
   1.149 +
   1.150 +int3:
   1.151 +#ifdef CPU186
   1.152 +	.byte	0x68		# push $0x086A	OV UP DI NT PL ZR - NA - PO - NC
   1.153 +# interrupt entry point: the registers [FLAGS CS IP] are already pushed
   1.154 +dbgstart:
   1.155 +	.byte	0x6A, 0x08	# push $0x08	NV UP DI NT PL NZ - NA - PO - NC
   1.156 +	popf
   1.157 +init:
   1.158 +	pushaw		#    [FLAGS CS IP] AX CX DX BX SP BP SI DI [DS ES SS]
   1.159 +#else
   1.160 +	stc
   1.161 +	.byte	0x73		# jnc
   1.162 +# interrupt entry point: the registers [FLAGS CS IP] are already pushed
   1.163 +dbgstart:
   1.164 +	clc
   1.165 +	pushw	%ax
   1.166 +	sbbw	%ax,%ax		# copy CF to SF
   1.167 +	clc
   1.168 +	popw	%ax
   1.169 +init:
   1.170 +	cld			# ensure movsb will work
   1.171 +	pusham		#    [FLAGS CS IP] AX CX DX BX SP BP SI DI [DS ES SS]
   1.172 +#endif
   1.173 +	pushw	%ds
   1.174 +	pushw	%es
   1.175 +	pushw	%ss
   1.176 +	movw	%sp, %bp
   1.177 +#ifdef CPU186
   1.178 +	pushf
   1.179 +	addw	$6, USER_SP	# adjust SP with [FLAGS CS IP] size
   1.180 +	popf
   1.181 +#endif
   1.182 +	jc	isinit
   1.183 +	jns	notint3
   1.184 +	decw	USER_IP
   1.185 +	lesw	USER_CSIP, %di
   1.186 +#define OPCODE_BRK     0xCC
   1.187 +	.byte	0xB0		# movb $IM, %al
   1.188 +break:
   1.189 +	.byte	0xCC
   1.190 +	stosb
   1.191 +notint3:
   1.192 +dbgstartz:
   1.193 +dbgregslp:
   1.194 +	call	getcmd
   1.195 +	.byte	0x81, 0xC3	# addw	$0, %bx
   1.196 +offset_value:
   1.197 +	.word	0
   1.198 +	movw	%bx, %es
   1.199 +	xchgw	%ax, %di
   1.200 +	subb	$'m', %al
   1.201 +	jne	isinotmove
   1.202 +#ifdef INPUTBUFFER
   1.203 +ismove:
   1.204 +	xchgw	%ax, %si
   1.205 +moveself:
   1.206 +#else
   1.207 +isinit:
   1.208 +	jmp	ismove
   1.209 +	initcode
   1.210 +ismove:
   1.211 +#endif
   1.212 +	movw	%di, %es	# move code to %di:0
   1.213 +	pushw	%di
   1.214 +#ifdef INPUTBUFFER
   1.215 +	xorw	%di, %di	# and jmp into (%di:setvectors) with retf
   1.216 +#else
   1.217 +	movw	$setvectors, %di	# and jmp into (%di:setvectors) with retf
   1.218 +	movw	%di, %si
   1.219 +#endif
   1.220 +	movw	$_end-setvectors, %cx
   1.221 +	pushw	%di
   1.222 +	rep	movsb
   1.223 +	retf
   1.224 +
   1.225 +isinotmove:
   1.226 +	subb	$'+'-'m', %al
   1.227 +	jne	not_offset
   1.228 +	movw	%di, ABS(offset_value)
   1.229 +not_offset:
   1.230 +	orb	$1, USER_FLAGS_HIGH	# set TF
   1.231 +	subb	$'t'-'+', %al
   1.232 +	je	done
   1.233 +	subb	$'d'-'t', %al
   1.234 +	xchgw	%ax, %cx
   1.235 +	jcxz	dump		# 'd' ?
   1.236 +	loop	noenter		# 'e' ?
   1.237 +nextval:
   1.238 +	call	getval
   1.239 +	jcxz	dbgregslp
   1.240 +	xchgb	%dl, %dh
   1.241 +mextmsb:
   1.242 +	stosb
   1.243 +	xchgw	%ax, %dx
   1.244 +	xchgb	%al, %dh
   1.245 +#ifdef ADJESDI
   1.246 +	call	adjustESDI
   1.247 +#endif
   1.248 +	decw	%cx
   1.249 +	loopne	mextmsb
   1.250 +	jmp	nextval
   1.251 +noenter:
   1.252 +	loop	not_floppy_load	# f DX:CX ?
   1.253 +	movw	%es, %dx
   1.254 +	movw	%cx, %es
   1.255 +	movw	%di, %cx
   1.256 +	movw	$0x0201, %ax
   1.257 +	movw	$0x7C00, %bx
   1.258 +	pushw	%bx
   1.259 +	int	$0x13
   1.260 +	popw	%di
   1.261 +godbgregslpifc:	
   1.262 +	jc	dbgregslp
   1.263 +dump:
   1.264 +	movw	%es, %ax
   1.265 +	call	putax
   1.266 +	movw	%di, %ax
   1.267 +	call	putax
   1.268 +	movw	$16, %cx
   1.269 +dhex:
   1.270 +	movb	%es:(%di), %ah
   1.271 +#ifdef ASCIIDUMP
   1.272 +	movb	%ah, (%si)
   1.273 +	incw	%si
   1.274 +#endif
   1.275 +#ifdef ADJESDI
   1.276 +	call	incESDI
   1.277 +#else
   1.278 +	incw	%di
   1.279 +#endif
   1.280 +	movb	$0x01, %dh	# the data has 2 digits
   1.281 +	call	putx
   1.282 +	loop	dhex
   1.283 +#ifdef ASCIIDUMP
   1.284 +	movb	$16, %cl
   1.285 +	subw	%cx, %si
   1.286 +dascii:
   1.287 +	lodsb
   1.288 +	cmpb	$0x7F, %al
   1.289 +	jnc	skipascii
   1.290 +	cmpb	$0x20, %al
   1.291 +	cmc
   1.292 +skipascii:
   1.293 +	call	dbgputcbit
   1.294 +	loop	dascii
   1.295 +#endif
   1.296 +	call	dbgputcr
   1.297 +	int	$0x16
   1.298 +	cmpb	$13, %al
   1.299 +	je	dump
   1.300 +notdump:
   1.301 +not_floppy_load:
   1.302 +	stc
   1.303 +	loop	godbgregslpifc	# g ?
   1.304 +isgo:
   1.305 +	andb	$0xfe, USER_FLAGS_HIGH	# clear TF
   1.306 +	xchgw	%ax, %cx
   1.307 +	jcxz	done
   1.308 +setbreak:
   1.309 +	movb	$OPCODE_BRK, %al
   1.310 +	xchgb	%al, %es:(%di)
   1.311 +	movb	%al, ABS(break)
   1.312 +done:
   1.313 +	popw	%ax  	# %ss
   1.314 +	popw	%es
   1.315 +	popw	%ds
   1.316 +#ifdef CPU186
   1.317 +	popaw
   1.318 +#else
   1.319 +	popam
   1.320 +#endif
   1.321 +	iret
   1.322 +
   1.323 +#ifdef ADJESDI
   1.324 +adjustESDI:
   1.325 +	decw	%di
   1.326 +incESDI:
   1.327 +	incw	%di
   1.328 +	jnz	esok
   1.329 +	pushw	%es
   1.330 +	addb	$0x10,-3(%bp)
   1.331 +	popw	%es
   1.332 +esok:
   1.333 +	ret
   1.334 +#endif
   1.335 +
   1.336 +putreg:
   1.337 +	call	dbgput2c
   1.338 +	movb	$'=', %al
   1.339 +	call	dbgputc
   1.340 +putr16:
   1.341 +#	movw	_start-ABS(regs)-2(%bp,%si), %ax
   1.342 +	.byte	0x8b, 0x42, _start-ABS(regs)-2
   1.343 +putax:
   1.344 +	movb	$0x07, %dh	# the data has 4 digits
   1.345 +putx:
   1.346 +putxlp:  
   1.347 +#ifdef CPU186
   1.348 +	rolw	$4, %ax
   1.349 +#else
   1.350 +	pushw	%cx
   1.351 +	movb	$4, %cl
   1.352 +	rolw	%cl, %ax
   1.353 +	popw	%cx
   1.354 +#endif
   1.355 +	pushw	%ax
   1.356 +	andb	$0xf, %al
   1.357 +	addb	$0x90, %al
   1.358 +	daa
   1.359 +	adcb	$0x40, %al
   1.360 +	daa
   1.361 +	call	dbgputc
   1.362 +	popw	%ax
   1.363 +	shrb	$1, %dh
   1.364 +	jc	putxlp
   1.365 +dbgputcbit:
   1.366 +	jc	dbgputc  
   1.367 +	mov	$0x20, %al
   1.368 +dbgputc:
   1.369 +	movw	$7, %bx
   1.370 +	mov	$0xE, %ah
   1.371 +	int	$0x10
   1.372 +	xchgw	%ax, %bx
   1.373 +	ret
   1.374 +
   1.375 +getline:
   1.376 +	movw	$ABS(regs), %si
   1.377 +	movw	$13, %cx
   1.378 +regslp:
   1.379 +	call	putreg		# display register name and value
   1.380 +	loop	regslp
   1.381 +	movw	USER_FLAGS, %dx
   1.382 +	pushw	%si
   1.383 +	movb	$13, %cl
   1.384 +	stc			# add trailing =
   1.385 +	rcrw	%cl, %dx
   1.386 +nextbit:
   1.387 +	lodsb
   1.388 +	shlw	$1, %dx
   1.389 +	call	dbgputcbit	# display active flags bits
   1.390 +	loop	nextbit
   1.391 +	popw	%si
   1.392 +	movb	$8, %cl
   1.393 +stacklp:
   1.394 +	lodsw			# si += 2
   1.395 +	call	putr16		# display flags and the beginning of the stack
   1.396 +	loop	stacklp
   1.397 +	call	dbgputcr
   1.398 +getlinebs:
   1.399 +	cmpw	$ABS(buffer), %si
   1.400 +	je	getc
   1.401 +	decw	%si
   1.402 +getlinelp:
   1.403 +	call	dbgputc
   1.404 +getc:
   1.405 +	int	$0x16
   1.406 +	cmpb	$8, %al
   1.407 +	je	getlinebs
   1.408 +	orb	$0x20, %al
   1.409 +	movb	%al, (%si)
   1.410 +	inc	%si
   1.411 +	cmpb	$0x2D, %al
   1.412 +	jne	getlinelp
   1.413 +dbgputcr:
   1.414 +	movw	$ABS(crlf), %si
   1.415 +dbgput2c:
   1.416 +	call	dbgput1c
   1.417 +dbgput1c:
   1.418 +	lodsb
   1.419 +	jmp	dbgputc
   1.420 +
   1.421 +getcmd:
   1.422 +	pushw	%cs
   1.423 +	popw	%ds
   1.424 +	call	getline
   1.425 +	lodsb
   1.426 +	xchgw	%ax, %di
   1.427 +# get value in DX:AX, BX is segment CX is digits count.
   1.428 +getval:
   1.429 +	xorw	%bx, %bx
   1.430 +	xorw	%cx, %cx
   1.431 +getvalz:
   1.432 +	pushw	%bx			# save segment
   1.433 +	xorw	%bx, %bx
   1.434 +	mul	%bx			# clear %dx:%ax
   1.435 +	decw	%cx
   1.436 +isx:
   1.437 +	incw	%cx
   1.438 +	orb	$0xE0, %dh
   1.439 +getvalbit:
   1.440 +	shlw	$1, %bx
   1.441 +	rclw	$1, %dx
   1.442 +	jc	getvalbit
   1.443 +	orb	%al, %bl
   1.444 +gotspc:
   1.445 +	lodsb
   1.446 +	cmpb	$0x20, %al		# space ?
   1.447 +	jne	notspc
   1.448 +	jcxz	gotspc
   1.449 +notspc:
   1.450 +	sub	$'0', %al
   1.451 +	cmpb	$10, %al		# in 0..9 ?
   1.452 +	jb	isx
   1.453 +	sub	$'a'-'0'-10, %al
   1.454 +	cmpb	$16, %al		# in a..f ?
   1.455 +	jb	isx
   1.456 +	cmpb	$':'-'a'+10, %al
   1.457 +	popw	%ax
   1.458 +	je	getvalz			# store segment in %bx
   1.459 +	xchgw	%ax, %bx
   1.460 +	pushw	%dx
   1.461 +#ifdef CPU186
   1.462 +	shlw	$12, %dx
   1.463 +#else
   1.464 +	pushw	%cx
   1.465 +	movb	$12, %cl
   1.466 +	shlw	%cl, %dx
   1.467 +	popw	%cx
   1.468 +#endif
   1.469 +	addw	%dx, %bx
   1.470 +	popw	%dx
   1.471 +	ret
   1.472 +
   1.473 +crlf:
   1.474 +	.byte	13,10
   1.475 +_end:
   1.476 +buffer:
   1.477 +
   1.478 +	.org	510
   1.479 +	.byte	0x55, 0xAA
   1.480 +