-
Notifications
You must be signed in to change notification settings - Fork 4
/
func.mac
83 lines (77 loc) · 1.71 KB
/
func.mac
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
%macro func 1
extern %1
%1:
%push func
%stacksize small
%assign %$argsize 0
%assign %$localsize 0 ; for %local
%local saved_ds:word
; Standard function prologue
; See http://blogs.msdn.com/b/oldnewthing/archive/2011/03/16/10141735.aspx
; and http://jdebp.eu/FGA/function-perilogues.html#Win16Callbacks
; https://web.archive.org/web/20190127204706/https://blogs.msdn.microsoft.com/oldnewthing/?p=23533
; https://web.archive.org/web/20040824085710/http://www.geary.com/fixds.html
mov ax,ds
nop
inc bp
push bp
db 0x8b,0xec ; mov bp,sp
push ds
mov ds,ax
%endmacro
; Same as above, but with no save of ds to ax
%macro func_nods 1
extern %1
%1:
%push func
%stacksize small
%assign %$argsize 0
%assign %$localsize 0 ; for %local
%local saved_ds:word
inc bp
push bp
db 0x8b,0xec ; mov bp,sp
push ds
%endmacro
; Start of stub function without any prologue (usually because we jump
; here from other function prologues).
%macro stub 1
%1:
%push func
%stacksize small
%assign %$argsize 0
%assign %$localsize 0 ; for %local
%endmacro
%macro endfunc 0
lea sp,[bp-0x2]
pop ds
pop bp
dec bp
%if %$argsize
retf %$argsize
%else
retf
%endif
align 2
%pop func
%endmacro
; Some CRT functions have a slightly different epilogue...
%macro endfunc_crt 0
sub bp, byte 0x2
db 0x8b,0xe5 ; mov sp,bp
pop ds
pop bp
dec bp
%if %$argsize
retf %$argsize
%else
retf
%endif
%pop func
%endmacro
; End a stub function without any epilogue (usually because we jump
; to the rest of the shared implementation)
%macro endstub 0
%pop func
%endmacro
; vim: syntax=nasm