Experiemnts with single stepping.

parent 718d7768
......@@ -227,10 +227,13 @@ single_step_handler_restart:
single_step_handler_disable:
popa
empty_handler:
iret
enable_single_step:
pusha
;; Remember single step is enabled
mov DWORD [SINGLE_STEP_ENABLED], 1
......@@ -239,6 +242,8 @@ enable_single_step:
mov edx, single_step_handler
call fill_idt_entry
popa
;; Actually set flag
pushf
or DWORD [esp], 0x100
......
......@@ -316,11 +316,21 @@ load_payload_loop:
payload_loaded:
;; The payload is finally loaded and we can jump into it!
mov esi, str_newline
call print_string
mov esi, str_newline
call print_string
mov esi, str_chainloading
call print_string
mov esi, str_chainloading
call print_string
;; Clear all registers
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor esp, esp
xor ebp, ebp
xor esi, esi
xor edi, edi
jmp 0x100000
......
......@@ -15,6 +15,7 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
section .text
;; filename in ECX
;; Destroys: ESI, EDI
......
......@@ -202,4 +202,143 @@ stdout_setup:
call serial_setup
ret
;; Input number in AL
;; Returns: AL (hex digit corresponding to input)
num2hex:
and al, 0xf
add al, '0'
cmp al, '9'
jbe ret_simple
add al, 'a' - '0' - 10
ret
;; Input in EDX
;; Destroys: EAX, ECX
write_hex:
push edx
mov eax, [esp]
shr eax, 28
call num2hex
mov cl, al
call write
mov eax, [esp]
shr eax, 24
call num2hex
mov cl, al
call write
mov eax, [esp]
shr eax, 20
call num2hex
mov cl, al
call write
mov eax, [esp]
shr eax, 16
call num2hex
mov cl, al
call write
mov eax, [esp]
shr eax, 12
call num2hex
mov cl, al
call write
mov eax, [esp]
shr eax, 8
call num2hex
mov cl, al
call write
mov eax, [esp]
shr eax, 4
call num2hex
mov cl, al
call write
mov eax, [esp]
shr eax, 0
call num2hex
mov cl, al
call write
pop edx
ret
single_stepping_handler:
;; cmp DWORD [instr_num], 0x3129
;; jne single_stepping_handler_end
mov ebx, [esp+4]
mov esi, str_instr_num
call log
mov edx, [instr_num]
call write_hex
mov esi, str_eip
call log
mov edx, [ebx+0x20]
call write_hex
mov esi, str_eax
call log
mov edx, [ebx+0x1c]
call write_hex
mov esi, str_ecx
call log
mov edx, [ebx+0x18]
call write_hex
mov esi, str_edx
call log
mov edx, [ebx+0x14]
call write_hex
mov esi, str_ebx
call log
mov edx, [ebx+0x10]
call write_hex
mov esi, str_esp
call log
mov edx, [ebx+0x0c]
call write_hex
mov esi, str_ebp
call log
mov edx, [ebx+0x08]
call write_hex
mov esi, str_esi
call log
mov edx, [ebx+0x04]
call write_hex
mov esi, str_edi
call log
mov edx, [ebx+0x00]
call write_hex
mov cl, NEWLINE
call write
single_stepping_handler_end:
inc DWORD [instr_num]
ret
enable_single_stepping:
mov DWORD [instr_num], 0x3126
mov DWORD [0x10010], single_stepping_handler
call [0x1001c]
cmp DWORD [term_row], 0
jne platform_panic
ret
section .bss
instr_num resd 1
section .data
str_instr_num db 'instr_num=', 0
str_eip db ' EIP=', 0
str_eax db ' EAX=', 0
str_ecx db ' ECX=', 0
str_edx db ' EDX=', 0
str_ebx db ' EBX=', 0
str_esp db ' ESP=', 0
str_ebp db ' EBP=', 0
str_esi db ' ESI=', 0
str_edi db ' EDI=', 0
%endif
......@@ -74,7 +74,6 @@ entry:
;; Use the multiboot header as temporary stack
mov esp, temp_stack_top
and esp, 0xfffffff0
;; Initialize the BSS
;; mov ecx, begin_bss
......@@ -100,6 +99,7 @@ entry:
%ifdef DEBUG
;; Initialize stdout
call stdout_setup
;; call enable_single_stepping
%endif
%ifdef DEBUG
......@@ -138,6 +138,7 @@ entry:
platform_panic:
panic:
jmp shutdown
%ifdef DEBUG
;; Write an exit string
mov esi, str_panic
......
......@@ -28,9 +28,6 @@
;; Manually jump to after_header, to avoid depending on instruction encoding length
db 0xeb, after_header - 2, 0x00, 0x00
dd begin_bss
dd end_bss
MBBEGIN equ $
;; Multiboot header
......@@ -47,6 +44,8 @@
after_header:
jmp entry
align 4
temp_stack_top:
section .bss
......
......@@ -15,6 +15,7 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
section .text
;; Try to shutdown a qemu host invoked with "-device isa-debug-exit"
qemu_shutdown:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment