forked from temisu/oneKpaq
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdebug32.asm
111 lines (93 loc) · 1.34 KB
/
debug32.asm
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
; Copyright (C) Teemu Suutari
%ifdef DEBUG_BUILD
; short loops wont be short anymore
%define short
; loop wont fit into byte
%macro loop 1
loop %%do_loop
jmp %%done
%%do_loop:
jmp %1
%%done:
%endm
%macro EXTCALL 1
; edi first param
; esi second param
; edx third param
; ecx fourth param
; return value in eax
%ifndef ONEKPAQ_NO_SECTIONS
[section .data.onekpaq.func_r_%1]
%endif
%%func_r_%1:
extern %1
dd %1
__SECT__
pushfd
push ebp ; osX mandates 16 byte stack alignment, does not harm others
mov ebp,esp ; .
and esp,byte ~15 ; .
push ecx
push edx
push esi
push edi
call [dword %%func_r_%1]
; call %1
pop edi
pop esi
pop edx
pop ecx
leave ; .
popfd
%endm
%macro DEBUG_PLAIN 1
%ifndef ONEKPAQ_NO_SECTIONS
[section .rodata.onekpaq.dbg_text]
%endif
%%dbg_text:
db %1
db 0
__SECT__
mov edi,%%dbg_text
%ifidn __OUTPUT_FORMAT__, elf32
EXTCALL DebugPrint
%else
EXTCALL _DebugPrint
%endif
%endm
%macro DEBUG 1
pushad
DEBUG_PLAIN {"D ",%1,10}
popad
%endm
%macro DEBUG 2
pushad
push dword %2
pop esi
DEBUG_PLAIN {"D ",%1,10}
popad
%endm
%macro DEBUG 3
pushad
push dword %2
push dword %3
pop edx
pop esi
DEBUG_PLAIN {"D ",%1,10}
popad
%endm
%macro DEBUG 4
pushad
push dword %2
push dword %3
push dword %4
pop ecx
pop edx
pop esi
DEBUG_PLAIN {"D ",%1,10}
popad
%endm
%else
%macro DEBUG 1+
%endm
%endif