2 * 16-bit and 32-bit mode stack frame layout
4 * Copyright 1995, 1998 Alexandre Julliard
7 #ifndef __WINE_STACKFRAME_H
8 #define __WINE_STACKFRAME_H
15 /* 32-bit stack layout after CallTo16() */
16 typedef struct _STACK32FRAME
18 SEGPTR frame16
; /* 00 16-bit frame from last CallFrom16() */
19 DWORD restore_addr
; /* 04 return address for restoring code selector */
20 DWORD codeselector
; /* 08 code selector to restore */
21 DWORD edi
; /* 0c saved registers */
26 DWORD ebp
; /* 20 saved 32-bit frame pointer */
27 DWORD relay
; /* 24 return address to relay stub */
28 DWORD retaddr
; /* 28 actual return address */
29 DWORD args
[1]; /* 2c arguments to 16-bit function */
32 /* 16-bit stack layout after CallFrom16() */
35 STACK32FRAME
*frame32
; /* 00 32-bit frame from last CallTo16() */
36 DWORD edx
; /* 04 saved registers */
43 DWORD relay
; /* 18 address of argument relay stub */
44 DWORD entry_ip
; /* 1c ip of entry point */
45 DWORD entry_cs
; /* 20 cs of entry point */
46 DWORD entry_point
; /* 24 API entry point to call, reused as mutex count */
47 WORD bp
; /* 28 16-bit stack frame chain */
48 WORD ip
; /* 2a return address */
54 #define THREAD_STACK16(teb) ((STACK16FRAME*)PTR_SEG_TO_LIN((teb)->cur_stack))
55 #define CURRENT_STACK16 (THREAD_STACK16(NtCurrentTeb()))
56 #define CURRENT_DS (CURRENT_STACK16->ds)
58 /* varargs lists on the 16-bit stack */
60 typedef void *VA_LIST16
;
62 #define __VA_ROUNDED16(type) \
63 ((sizeof(type) + sizeof(WORD) - 1) / sizeof(WORD) * sizeof(WORD))
64 #define VA_START16(list) ((list) = (VA_LIST16)(CURRENT_STACK16 + 1))
65 #define VA_ARG16(list,type) \
66 (((list) = (VA_LIST16)((char *)(list) + __VA_ROUNDED16(type))), \
67 *((type *)(void *)((char *)(list) - __VA_ROUNDED16(type))))
68 #define VA_END16(list) ((void)0)
70 /* Push bytes on the 16-bit stack of a thread;
71 * return a segptr to the first pushed byte
73 #define STACK16_PUSH(teb,size) \
74 (memmove((char*)THREAD_STACK16(teb)-(size),THREAD_STACK16(teb), \
75 sizeof(STACK16FRAME)), \
76 (teb)->cur_stack -= (size), \
77 (SEGPTR)((teb)->cur_stack + sizeof(STACK16FRAME)))
79 /* Pop bytes from the 16-bit stack of a thread */
80 #define STACK16_POP(teb,size) \
81 (memmove((char*)THREAD_STACK16(teb)+(size),THREAD_STACK16(teb), \
82 sizeof(STACK16FRAME)), \
83 (teb)->cur_stack += (size))
85 /* Push a DWORD on the 32-bit stack */
86 #define STACK32_PUSH(context,val) (*--(*(DWORD **)&ESP_reg(context)) = (val))
88 /* Pop a DWORD from the 32-bit stack */
89 #define STACK32_POP(context) (*(*(DWORD **)&ESP_reg(context))++)
91 /* Win32 register functions */
92 #define REGS_FUNC(name) __regs_##name
94 #endif /* __WINE_STACKFRAME_H */