debug: Rework repl loop and implement help command '?'
This commit is contained in:
		
							parent
							
								
									31a72d594a
								
							
						
					
					
						commit
						9ce6ec5476
					
				
					 1 changed files with 92 additions and 68 deletions
				
			
		
							
								
								
									
										160
									
								
								rom/debug.asm
									
										
									
									
									
								
							
							
						
						
									
										160
									
								
								rom/debug.asm
									
										
									
									
									
								
							|  | @ -58,18 +58,30 @@ init:	push ds | ||||||
| 	pop ds | 	pop ds | ||||||
| 	retf | 	retf | ||||||
| 
 | 
 | ||||||
| crlf:	xor bx, bx | 	; Print AL | ||||||
| 	mov ax, 0x0e0a | space:	mov al, ' ' | ||||||
| 	int 0x10 | putc:	xor bx, bx | ||||||
| 	mov al, 0x0d | 	mov ah, 0x0e | ||||||
| 	int 0x10 | 	int 0x10 | ||||||
| 	ret | 	ret | ||||||
| 
 | 
 | ||||||
| space:	xor bx, bx | 	; Print CS:SI | ||||||
| 	mov ax, 0x0e20 | puts:	push ds | ||||||
| 	int 0x10 | 	push cs | ||||||
|  | 	pop ds | ||||||
|  | .loop:	lodsb | ||||||
|  | 	test al, al | ||||||
|  | 	jz .ret | ||||||
|  | 	call putc | ||||||
|  | 	jmp .loop | ||||||
|  | .ret:	pop ds | ||||||
| 	ret | 	ret | ||||||
| 
 | 
 | ||||||
|  | crlf:	mov al, 0x0A | ||||||
|  | 	call putc | ||||||
|  | 	mov al, 0x0D | ||||||
|  | 	jmp putc | ||||||
|  | 
 | ||||||
| print16: | print16: | ||||||
| 	; setup bx and ah for int 10h call | 	; setup bx and ah for int 10h call | ||||||
| 	xor bx, bx | 	xor bx, bx | ||||||
|  | @ -94,42 +106,6 @@ print16: | ||||||
| .noadj:	int 0x10 | .noadj:	int 0x10 | ||||||
| 	ret | 	ret | ||||||
| 
 | 
 | ||||||
| printregs: |  | ||||||
| 	mov cx, 13 |  | ||||||
| 	xor bx, bx |  | ||||||
| 	mov ah, 0x0e |  | ||||||
| 	mov si, reg_ax |  | ||||||
| .loop:	push cx |  | ||||||
| 	mov dx, [cs:si+names] |  | ||||||
| 	mov al, dl |  | ||||||
| 	int 0x10 |  | ||||||
| 	mov al, dh |  | ||||||
| 	int 0x10 |  | ||||||
| 	mov al, '=' |  | ||||||
| 	int 0x10 |  | ||||||
| 	lodsw |  | ||||||
| 	mov dx, ax |  | ||||||
| 	call print16 |  | ||||||
| 	call space |  | ||||||
| 	pop cx |  | ||||||
| 	loop .loop |  | ||||||
| 
 |  | ||||||
| 	mov dx, [reg_fl] |  | ||||||
| 	mov si, fnames |  | ||||||
| 	mov cx, 16 |  | ||||||
| .floop:	mov al, [cs:si] |  | ||||||
| 	inc si |  | ||||||
| 	cmp al, '+' |  | ||||||
| 	je .fskip |  | ||||||
| 	test dx, 0x8000 |  | ||||||
| 	jnz .fprnt |  | ||||||
| 	mov al, '-' |  | ||||||
| .fprnt: int 0x10 |  | ||||||
| .fskip: shl dx, 1 |  | ||||||
| 	loop .floop |  | ||||||
| 	call space |  | ||||||
| 	ret |  | ||||||
| 
 |  | ||||||
| int3entry: | int3entry: | ||||||
| 	; save DS and AX | 	; save DS and AX | ||||||
| 	push ds | 	push ds | ||||||
|  | @ -168,42 +144,21 @@ int3entry: | ||||||
| 	mov ss, ax | 	mov ss, ax | ||||||
| 	mov sp, stack | 	mov sp, stack | ||||||
| 	call crlf | 	call crlf | ||||||
| 
 |  | ||||||
| 	call printregs | 	call printregs | ||||||
| 
 | 
 | ||||||
| 	mov dx, ds | loop:	; show prompt | ||||||
| 	call print16 |  | ||||||
| 
 |  | ||||||
| loop:	; new line & show prompt |  | ||||||
| 	call crlf |  | ||||||
| 	mov al, '-' | 	mov al, '-' | ||||||
| 	int 0x10 | 	int 0x10 | ||||||
| 	; read data | 	; read data | ||||||
| 	call read | 	call read | ||||||
|  | 	pushf | ||||||
|  | 	call crlf | ||||||
|  | 	popf | ||||||
| 	jc loop | 	jc loop | ||||||
| 	; execute | 	; execute | ||||||
| 	call crlf |  | ||||||
| 	mov al, [cmdbuf] |  | ||||||
| 	call runcmd | 	call runcmd | ||||||
| 	jmp loop | 	jmp loop | ||||||
| 
 | 
 | ||||||
| runcmd:	cmp al, 'r' |  | ||||||
| 	je printregs |  | ||||||
| 	cmp al, 'g' |  | ||||||
| 	je go |  | ||||||
| 	cmp al, 't' |  | ||||||
| 	je step |  | ||||||
| 	; print a question mark |  | ||||||
| 	xor bx, bx |  | ||||||
| 	mov ax, 0x0e3F |  | ||||||
| 	int 0x10 |  | ||||||
| 	ret |  | ||||||
| 
 |  | ||||||
| go:	and word [reg_fl+1], 0xfe |  | ||||||
| 	jmp return |  | ||||||
| 
 |  | ||||||
| step:	or word [reg_fl+1], 0x03 |  | ||||||
| 
 |  | ||||||
| return:	; restore stack pointer | return:	; restore stack pointer | ||||||
| 	mov ss, [reg_ss] | 	mov ss, [reg_ss] | ||||||
| 	mov sp, [reg_sp] | 	mov sp, [reg_sp] | ||||||
|  | @ -276,6 +231,75 @@ read:	mov di, cmdbuf | ||||||
| .can:	stc | .can:	stc | ||||||
| .enter:	ret | .enter:	ret | ||||||
| 
 | 
 | ||||||
|  | runcmd:	mov al, [cmdbuf] | ||||||
|  | 	cmp al, 'g' | ||||||
|  | 	je cmd_g | ||||||
|  | 	cmp al, 'r' | ||||||
|  | 	je cmd_r | ||||||
|  | 	cmp al, 't' | ||||||
|  | 	je cmd_t | ||||||
|  | 	cmp al, '?' | ||||||
|  | 	je cmd_? | ||||||
|  | 	mov al, '?' | ||||||
|  | 	call putc | ||||||
|  | 	jmp crlf | ||||||
|  | 
 | ||||||
|  | cmd_?:	mov si, .txt | ||||||
|  | 	jmp puts | ||||||
|  | .txt:	db "g       Go", 0x0A, 0x0D | ||||||
|  | 	db "r       Print register values", 0x0A, 0x0D | ||||||
|  | 	db "t       Single-Step", 0x0A, 0x0D | ||||||
|  | 	db 0 | ||||||
|  | 
 | ||||||
|  | cmd_g:	and word [reg_fl+1], 0xfe | ||||||
|  | 	jmp return | ||||||
|  | 
 | ||||||
|  | cmd_r:	jmp printregs | ||||||
|  | 
 | ||||||
|  | cmd_t:	or word [reg_fl+1], 0x03 | ||||||
|  | 	jmp return | ||||||
|  | 
 | ||||||
|  | printregs: | ||||||
|  | 	mov cx, 13 | ||||||
|  | 	xor bx, bx | ||||||
|  | 	mov ah, 0x0e | ||||||
|  | 	mov si, reg_ax | ||||||
|  | .loop:	push cx | ||||||
|  | 	mov dx, [cs:si+names] | ||||||
|  | 	lodsw | ||||||
|  | 	call printreg | ||||||
|  | 	pop cx | ||||||
|  | 	loop .loop | ||||||
|  | 
 | ||||||
|  | 	mov dx, [reg_fl] | ||||||
|  | 	mov si, fnames | ||||||
|  | 	mov cx, 16 | ||||||
|  | .floop:	mov al, [cs:si] | ||||||
|  | 	inc si | ||||||
|  | 	cmp al, '+' | ||||||
|  | 	je .fskip | ||||||
|  | 	test dx, 0x8000 | ||||||
|  | 	jnz .fprnt | ||||||
|  | 	mov al, '-' | ||||||
|  | .fprnt: int 0x10 | ||||||
|  | .fskip: shl dx, 1 | ||||||
|  | 	loop .floop | ||||||
|  | 	call crlf | ||||||
|  | 	ret | ||||||
|  | 
 | ||||||
|  | printreg: | ||||||
|  | 	push ax | ||||||
|  | 	mov al, dl | ||||||
|  | 	call putc | ||||||
|  | 	mov al, dh | ||||||
|  | 	call putc | ||||||
|  | 	mov al, '=' | ||||||
|  | 	call putc | ||||||
|  | 	pop dx | ||||||
|  | 	call print16 | ||||||
|  | 	call space | ||||||
|  | 	ret | ||||||
|  | 
 | ||||||
| 	align 512 | 	align 512 | ||||||
| 
 | 
 | ||||||
| absolute 0 | absolute 0 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue