-
Notifications
You must be signed in to change notification settings - Fork 9
/
inttrace.inc
151 lines (140 loc) · 3.57 KB
/
inttrace.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
;========================================================================
; inttrace.asm -- Interrupt tracing
;------------------------------------------------------------------------
;
; Compiles with NASM 2.07, might work with other versions
;
; Copyright (C) 2010 Sergey Kiselev.
; Provided for hobbyist use on the N8VEM SBC-188 board.
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
; TODO:
;========================================================================
offset_BP equ 0
offset_ES equ offset_BP+2
offset_DS equ offset_ES+2
offset_SI equ offset_DS+2
offset_DX equ offset_SI+2
offset_CX equ offset_DX+2
offset_BX equ offset_CX+2
offset_AX equ offset_BX+2
offset_SFLAGS equ offset_AX+2
offset_RET equ offset_SFLAGS+2
offset_IP equ offset_RET+2
offset_CS equ offset_IP+2
offset_FLAGS equ offset_CS+2
original_SP equ offset_FLAGS+2
;========================================================================
; int_trace - print registers at interrupt service routine
;========================================================================
global int_trace
int_trace:
pushf
push ax
push bx
push cx
push dx
push si
push ds
push es
push bp
mov bp,sp
xor ax,ax ; AX = 0
lea si,[offset_IP+bp] ; SI = interrupt return CS:IP
.test_int:
ss lds bx,[si] ; DS:BX = caller's CS:IP
cmp byte [bx-2], 0CDh ; int opcode
jne .test_call_ptr ; not an int opcode
mov al,byte[bx-1] ; interrupt vector
jmp .print_regs
.test_call_ptr:
cmp word [bx-4], 1EFFh ; interupt emulation - call dword ptr
jne .print_regs
inc ah
.print_regs:
mov si,msg_regs
call print
call print_hex ; interrupt vector
call print_space
mov ax,word [offset_AX+bp]
call print_hex ; AX
call print_space
mov ax,word [offset_BX+bp]
call print_hex ; BX
call print_space
mov ax,cx
call print_hex ; CX
call print_space
mov ax,dx
call print_hex ; DX
call print_space
mov ax,word [offset_BP+bp]
call print_hex ; BP
call print_space
mov ax,word [offset_SI+bp]
call print_hex ; SI
call print_space
mov ax,di
call print_hex ; DI
call print_space
mov ax,word [offset_DS+bp]
call print_hex ; DS
call print_space
mov ax,es
call print_hex ; ES
call print_space
mov ax,word [offset_CS+bp]
call print_hex ; CS
call print_space
mov ax,word [offset_IP+bp]
call print_hex ; IP
call print_space
mov ax,ss
call print_hex ; SS
call print_space
mov ax,bp
add ax,original_SP
call print_hex
call print_space
mov ax,word [offset_FLAGS+bp]
call print_hex ; FLAGS
mov ax,0E0Dh
mov bl,07h
int 10h
mov ax,0E0Ah
mov bl,07h
int 10h
pop bp
pop es
pop ds
pop si
pop dx
pop cx
pop bx
pop ax
popf
ret
print_space:
push ax
push bx
mov ax,0E20h
mov bl,0Fh
int 10h
pop bx
pop ax
ret
;=========================================================================
msg_regs:
db 'INT AX BX CX DX BP SI DI DS ES CS IP SS SP Flags', 0Dh, 0Ah, 00h