source: cmedia/trunk/Include/stacktoflat.h@ 354

Last change on this file since 354 was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 2.8 KB
Line 
1/* $Id: stacktoflat.h,v 1.1 2000/04/23 14:55:27 ktk Exp $ */
2
3//******************************************************************************
4// Header for stack to flat macros
5//
6// Copyright 2000 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#ifndef __STACKTOFLAT_H__
25#define __STACKTOFLAT_H__
26
27extern ULONG TKSSBase;
28#pragma aux TKSSBase "TKSSBase"
29
30extern ULONG stacksel; //16 bits stack selector
31#pragma aux stacksel "stacksel"
32
33extern ULONG stackbase; //32 bits stackbase
34#pragma aux stackbase "stackbase"
35
36extern ULONG GetTKSSBase();
37#pragma aux GetTKSSBase "GetTKSSBase" \
38 value [eax];
39
40#ifdef KEE
41#define __StackToFlat(addr) (LINEAR)((unsigned long)(addr&0xffff) + stackbase)
42#else
43#define __StackToFlat(addr) (LINEAR)((unsigned long)(addr&0xffff) + *(unsigned long *)TKSSBase)
44#endif
45
46#define MAKE_FAR48(a) __Make48Pointer(a)
47
48// Convert 16:16 pointer to 16:32
49char __far *__Make48Pointer(unsigned long addr1616);
50#pragma aux __Make48Pointer = \
51 "movzx edx, ax" \
52 "shr eax, 16" \
53 "mov fs, ax" \
54 parm [eax] \
55 value [fs edx];
56
57#ifdef KEE
58//Only valid for stack based pointer!!
59#define __FlatToStack(addr32) ((stacksel << 16) | (((ULONG)addr32 - stackbase) & 0xffff))
60#else
61//Only valid for pointer previously constructed by __Make48Pointer!!
62//(upper 16 bits of 32 bits offset must be 0)
63FARPTR16 __Compress48Pointer(char FAR48 *addr1632);
64#pragma aux __Compress48Pointer = \
65 "mov ax, gs" \
66 "shl eax, 16" \
67 "mov ax, dx" \
68 parm [gs edx] \
69 value [eax];
70#endif
71
72#define MAKE_FAR16(a) __Compress48Pointer((char FAR48 *)a)
73
74USHORT GETFARSEL(char FAR48 *addr1632);
75#pragma aux GETFARSEL = \
76 "mov ax, gs" \
77 parm [gs edx] \
78 value [ax];
79
80ULONG GETFAROFFSET(char FAR48 *addr1632);
81#pragma aux GETFAROFFSET = \
82 "mov eax, edx" \
83 parm [gs edx] \
84 value [eax];
85
86//SvL: Only works for DS & SS ptrs!
87ULONG GETFLATPTR(char FAR48 *ptr);
88
89#define FLATPTR(a) GETFLATPTR((char FAR48 *)a)
90
91#endif
Note: See TracBrowser for help on using the repository browser.