1 | /* $Id: stacktoflat.h,v 1.1.1.1 2003/07/02 13:56:58 eleph Exp $ */
|
---|
2 | /*
|
---|
3 | * Header for SS / DS conversion routines
|
---|
4 | *
|
---|
5 | * (C) 2000-2002 InnoTek Systemberatung GmbH
|
---|
6 | * (C) 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | * This program is free software; you can redistribute it and/or
|
---|
9 | * modify it under the terms of the GNU General Public License as
|
---|
10 | * published by the Free Software Foundation; either version 2 of
|
---|
11 | * the License, or (at your option) any later version.
|
---|
12 | *
|
---|
13 | * This program is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU General Public
|
---|
19 | * License along with this program; if not, write to the Free
|
---|
20 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
---|
21 | * USA.
|
---|
22 | *
|
---|
23 | */
|
---|
24 |
|
---|
25 | #ifndef __STACKTOFLAT_H__
|
---|
26 | #define __STACKTOFLAT_H__
|
---|
27 |
|
---|
28 | extern ULONG TKSSBase;
|
---|
29 | #pragma aux TKSSBase "_TKSSBase"
|
---|
30 |
|
---|
31 | extern ULONG GetTKSSBase();
|
---|
32 | #pragma aux GetTKSSBase "GetTKSSBase" \
|
---|
33 | value [eax];
|
---|
34 |
|
---|
35 | #ifdef KEE
|
---|
36 | extern ULONG stacksel; //16 bits stack selector
|
---|
37 | #pragma aux stacksel "stacksel"
|
---|
38 |
|
---|
39 | extern ULONG stackbase; //32 bits stackbase
|
---|
40 | #pragma aux stackbase "stackbase"
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #ifdef FLATSTACK
|
---|
44 |
|
---|
45 | #ifdef KEE
|
---|
46 | //Convert 16:16 stack based address to 0:32 flat addresss
|
---|
47 | #define __Stack16ToFlat(addr) (LINEAR)((ULONG)(addr&0xffff) + stackbase)
|
---|
48 | #else
|
---|
49 | //Convert 16:16 stack based address to 0:32 flat addresss
|
---|
50 | #define __Stack16ToFlat(addr) (LINEAR)((((ULONG)addr)&0xffff) + *(ULONG *)TKSSBase)
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | //stack is already flat
|
---|
54 | #define __Stack32ToFlat(addr) (LINEAR)addr
|
---|
55 |
|
---|
56 | #else
|
---|
57 | //Convert 16:16 stack based address to 0:32 flat addresss
|
---|
58 | #define __Stack16ToFlat(addr) (LINEAR)((((ULONG)addr)&0xffff) + *(ULONG *)TKSSBase)
|
---|
59 |
|
---|
60 | //Convert 16:16 stack based address to 0:32 flat addresss
|
---|
61 | #define __Stack32ToFlat(addr) (LINEAR)((((ULONG)addr)&0xffff) + *(ULONG *)TKSSBase)
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | // Convert 16:16 pointer to 16:32
|
---|
65 | char FAR48 *MAKE_FARPTR32(FARPTR16 addr1616);
|
---|
66 | #pragma aux MAKE_FARPTR32 = \
|
---|
67 | "movzx edx, ax" \
|
---|
68 | "shr eax, 16" \
|
---|
69 | "mov fs, ax" \
|
---|
70 | parm [eax] \
|
---|
71 | value [fs edx];
|
---|
72 |
|
---|
73 | //Only valid for pointer previously constructed by __Make48Pointer!!
|
---|
74 | //(upper 16 bits of 32 bits offset must be 0)
|
---|
75 | FARPTR16 MAKE_FARPTR16(void FAR48 *addr1632);
|
---|
76 | #pragma aux MAKE_FARPTR16 = \
|
---|
77 | "mov ax, gs" \
|
---|
78 | "shl eax, 16" \
|
---|
79 | "mov ax, dx" \
|
---|
80 | parm [gs edx] \
|
---|
81 | value [eax];
|
---|
82 |
|
---|
83 | FARPTR16 MAKE_FARPTR16_STACK(LINEAR offset);
|
---|
84 | #pragma aux MAKE_FARPTR16_STACK = \
|
---|
85 | "mov ax, ss" \
|
---|
86 | "shl eax, 16" \
|
---|
87 | "mov ax, dx" \
|
---|
88 | parm [edx] \
|
---|
89 | value [eax];
|
---|
90 |
|
---|
91 | char FAR48 *MAKE_FARPTR32_STACK(LINEAR offset);
|
---|
92 | #pragma aux MAKE_FARPTR32_STACK = \
|
---|
93 | "push ss" \
|
---|
94 | "pop fs" \
|
---|
95 | parm [eax] \
|
---|
96 | value [fs eax];
|
---|
97 |
|
---|
98 | #define MAKE_FP16(sel, offset) ((sel << 16) | (offset & 0xffff) )
|
---|
99 |
|
---|
100 | USHORT GETFARSEL(char FAR48 *addr1632);
|
---|
101 | #pragma aux GETFARSEL = \
|
---|
102 | "mov ax, gs" \
|
---|
103 | parm [gs edx] \
|
---|
104 | value [ax];
|
---|
105 |
|
---|
106 | ULONG GETFAROFFSET(char FAR48 *addr1632);
|
---|
107 | #pragma aux GETFAROFFSET = \
|
---|
108 | "mov eax, edx" \
|
---|
109 | parm [gs edx] \
|
---|
110 | value [eax];
|
---|
111 |
|
---|
112 | //SvL: Only works for DS & SS ptrs!
|
---|
113 | ULONG GETFLATPTR(char FAR48 *ptr);
|
---|
114 |
|
---|
115 | #define FLATPTR(a) GETFLATPTR((char FAR48 *)a)
|
---|
116 |
|
---|
117 | #ifdef KEE
|
---|
118 | #define FlatToSel(addr32) ((stacksel << 16) | (((ULONG)addr32 - stackbase) & 0xffff))
|
---|
119 | #else
|
---|
120 | //Only valid for stack based pointer!!
|
---|
121 | ULONG FlatToSel(ULONG addr32);
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | #endif
|
---|