-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathstacks.inc
More file actions
258 lines (229 loc) · 5.56 KB
/
Copy pathstacks.inc
File metadata and controls
258 lines (229 loc) · 5.56 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
;
; File:
; stacks.inc
; Description:
; Macro support for register stack frame
;
; Copyright (c) 1998
; Pasquale J. Villani
; All Rights Reserved
;
; This file is part of DOS-C.
;
; DOS-C 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
; 2, or (at your option) any later version.
;
; DOS-C 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 DOS-C; see the file COPYING. If not,
; write to the Free Software Foundation, 675 Mass Ave,
; Cambridge, MA 02139, USA.
;
; $Id: stacks.inc 1591 2011-05-06 01:46:55Z bartoldeman $
;
;
; Standard stack frame used throughout DOS-C
;
; MS-DOS specific
;
; +---------------+
; | irp hi | 26
; +---------------+
; | irp low | 24
; +---------------+
; | flags | 22
; +---------------+
; | cs | 20
; +---------------+
; | ip | 18
; +---------------+
; | es | 16
; +---------------+
; | ds | 14
; +---------------+
; | bp | 12
; +---------------+
; | di | 10
; +---------------+
; | si | 8
; +---------------+
; | dx | 6
; +---------------+
; | cx | 4
; +---------------+
; | bx | 2
; +---------------+
; | ax | 0
; +---------------+
;
;; Note: The order of the pushed registers _must_ match with the definition
;; of the "iregs" structure within PCB.H, because a pointer to the last
;; pushed register is used as a pointer to a "iregs" structure within the
;; called C sources! -- 2000/03/22 ska
; Don't use `struc RegFrame' etc. here because it interferes with segment
; definitions.
reg_ax equ 0
reg_bx equ 2
reg_cx equ 4
reg_dx equ 6
reg_si equ 8
reg_di equ 10
reg_bp equ 12
reg_ds equ 14
reg_es equ 16
reg_ip equ 18
reg_cs equ 20
reg_flags equ 22
irp_low equ 24
irp_hi equ 26
%macro PUSH$ALL 0
push es
push ds
push bp
push di
push si
push dx
push cx
push bx
push ax
%endmacro
%macro POP$ALL 0
pop ax
pop bx
pop cx
pop dx
pop si
pop di
pop bp
pop ds
pop es
%endmacro
; I386.inc - 10/25/01 by tom ehlert
;
; compiling the kernel for 386 will (sometimes) change the
; high part of (some) registers, which will be (sometimes) be used
; later
;
; assumption:
; we have never seen MSVC to use anything but eax, ecx, edx,
; nor have we seen Borland C to use anything but eax, ebx, edx,
; so we only protect eax, ebx or ecx, edx to conserve stack space
;
; to save even more stack space, we save only HIGH part of regs
; at some expense of slower execution. it's easier anyway :-)
;
; WATCOM only uses FS: and GS: (using -zff and -zgf) and never
; any high part of the 386 registers
;
%IF XCPU < 386
; no need to save/restore anything
; error 1 2 3
%macro Protect386Registers 0
%endmacro
%assign Size386Registers 0
%macro RestoreSP 0
mov sp, bp
%endmacro
%macro Restore386Registers 0
%endmacro
%ELSE
%ifdef WATCOM
%macro Protect386Registers 0
push fs
push gs
%endmacro
%assign Size386Registers 4
%macro RestoreSP 0
lea sp, [bp - Size386Registers]
%endmacro
%macro Restore386Registers 0
pop gs
pop fs
%endmacro
%else
%macro Protect386Registers 0
push eax
pop ax
%ifdef MSCL8
push ecx
pop cx
%else ;BC5
push ebx
pop bx
%endif
push edx
pop dx
%endmacro
%assign Size386Registers 6
%macro RestoreSP 0
lea sp, [bp - Size386Registers]
%endmacro
%macro Restore386Registers 0
push dx
pop edx
%ifdef MSCL8
push cx
pop ecx
%else ;BC5
push bx
pop ebx
%endif
push ax
pop eax
%endmacro
%endif
%ENDIF
; macros to define stack arguments
; arg a, {b,4}, c
; defines a and c as "word" arguments and b as a "dword" argument
; for STDCALL defines .a as [bp+4], .b as [bp+6] and .c as [bp+10]
; for PASCAL defines .a as [bp+10], .b as [bp+6] and .c as [bp+4]
;
; popargs bx, {dx,ax}, cx pops these arguments of the stack (for PASCAL
; in reverse order). Here dx,ax is a dword argument dx:ax where dx is
; the high word. The caller is responsible for dealing with instruction
; pointer (ip) on the stack.
%ifdef gcc
%define STDCALL
%else
%define PASCAL
%endif
%macro definearg 1-2 2
%xdefine .%1 bp+.argloc
%assign .argloc .argloc+%2
%endmacro
%macro arg 1-*
%assign .argloc 4
%rep %0
%ifdef PASCAL
%rotate -1
%endif
definearg %1
%ifdef STDCALL
%rotate 1
%endif
%endrep
%endmacro
%macro multipop 1-*
%rep %0
%rotate -1
pop %1
%endrep
%endmacro
%macro popargs 1-*
%rep %0
%ifdef PASCAL
%rotate -1
%endif
multipop %1
%ifdef STDCALL
%rotate 1
%endif
%endrep
%endmacro