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
16 /* 32-bit stack layout after CallTo16() */
17 typedef struct _STACK32FRAME
19 SEGPTR frame16
; /* 00 16-bit frame from last CallFrom16() */
20 DWORD restore_addr
; /* 04 return address for restoring code selector */
21 DWORD codeselector
; /* 08 code selector to restore */
22 DWORD edi
; /* 0c saved registers */
27 DWORD ebp
; /* 20 saved 32-bit frame pointer */
28 DWORD retaddr
; /* 24 return address */
29 DWORD target
; /* 28 target address / CONTEXT86 pointer */
30 DWORD nb_args
; /* 2c number of 16-bit argument bytes */
33 /* 16-bit stack layout after CallFrom16() */
34 typedef struct _STACK16FRAME
36 STACK32FRAME
*frame32
; /* 00 32-bit frame from last CallTo16() */
37 DWORD edx
; /* 04 saved registers */
44 DWORD callfrom_ip
; /* 18 callfrom tail IP */
45 DWORD module_cs
; /* 1c module code segment */
46 DWORD relay
; /* 20 relay function address */
47 WORD entry_ip
; /* 22 entry point IP */
48 DWORD entry_point
; /* 26 API entry point to call, reused as mutex count */
49 WORD bp
; /* 2a 16-bit stack frame chain */
50 WORD ip
; /* 2c return address */
56 #define THREAD_STACK16(teb) ((STACK16FRAME*)PTR_SEG_TO_LIN((teb)->cur_stack))
57 #define CURRENT_STACK16 (THREAD_STACK16(NtCurrentTeb()))
58 #define CURRENT_DS (CURRENT_STACK16->ds)
60 /* varargs lists on the 16-bit stack */
62 typedef void *VA_LIST16
;
64 #define __VA_ROUNDED16(type) \
65 ((sizeof(type) + sizeof(WORD) - 1) / sizeof(WORD) * sizeof(WORD))
66 #define VA_START16(list) ((list) = (VA_LIST16)(CURRENT_STACK16 + 1))
67 #define VA_ARG16(list,type) \
68 (((list) = (VA_LIST16)((char *)(list) + __VA_ROUNDED16(type))), \
69 *((type *)(void *)((char *)(list) - __VA_ROUNDED16(type))))
70 #define VA_END16(list) ((void)0)
73 /* Push bytes on the 16-bit stack of a thread;
74 * return a segptr to the first pushed byte
76 static inline SEGPTR WINE_UNUSED
stack16_push( int size
)
78 TEB
*teb
= NtCurrentTeb();
79 STACK16FRAME
*frame
= THREAD_STACK16(teb
);
80 memmove( (char*)frame
- size
, frame
, sizeof(*frame
) );
81 teb
->cur_stack
-= size
;
82 return (SEGPTR
)(teb
->cur_stack
+ sizeof(*frame
));
85 /* Pop bytes from the 16-bit stack of a thread */
86 static inline void WINE_UNUSED
stack16_pop( int size
)
88 TEB
*teb
= NtCurrentTeb();
89 STACK16FRAME
*frame
= THREAD_STACK16(teb
);
90 memmove( (char*)frame
+ size
, frame
, sizeof(*frame
) );
91 teb
->cur_stack
+= size
;
94 /* Push a DWORD on the 32-bit stack */
95 static inline void WINE_UNUSED
stack32_push( CONTEXT86
*context
, DWORD val
)
97 ESP_reg(context
) -= sizeof(DWORD
);
98 *(DWORD
*)ESP_reg(context
) = val
;
101 /* Pop a DWORD from the 32-bit stack */
102 static inline DWORD WINE_UNUSED
stack32_pop( CONTEXT86
*context
)
104 DWORD ret
= *(DWORD
*)ESP_reg(context
);
105 ESP_reg(context
) += sizeof(DWORD
);
109 #endif /* __WINE_STACKFRAME_H */