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
18 /* 32-bit stack layout after CallTo16() */
19 typedef struct _STACK32FRAME
21 SEGPTR frame16; /* 00 16-bit frame from last CallFrom16() */
22 DWORD restore_addr; /* 04 return address for restoring code selector */
23 DWORD codeselector; /* 08 code selector to restore */
24 DWORD edi; /* 0c saved registers */
29 DWORD ebp; /* 20 saved 32-bit frame pointer */
30 DWORD retaddr; /* 24 return address */
31 DWORD target; /* 28 target address / CONTEXT86 pointer */
32 DWORD nb_args; /* 2c number of 16-bit argument bytes */
35 /* 16-bit stack layout after CallFrom16() */
36 typedef struct _STACK16FRAME
38 STACK32FRAME *frame32; /* 00 32-bit frame from last CallTo16() */
39 DWORD edx; /* 04 saved registers */
46 DWORD callfrom_ip; /* 18 callfrom tail IP */
47 DWORD module_cs; /* 1c module code segment */
48 DWORD relay; /* 20 relay function address */
49 WORD entry_ip; /* 22 entry point IP */
50 DWORD entry_point; /* 26 API entry point to call, reused as mutex count */
51 WORD bp; /* 2a 16-bit stack frame chain */
52 WORD ip; /* 2c return address */
58 #define THREAD_STACK16(teb) ((STACK16FRAME*)PTR_SEG_TO_LIN((teb)->cur_stack))
59 #define CURRENT_STACK16 (THREAD_STACK16(NtCurrentTeb()))
60 #define CURRENT_DS (CURRENT_STACK16->ds)
62 /* varargs lists on the 16-bit stack */
64 typedef void *VA_LIST16;
66 #define __VA_ROUNDED16(type) \
67 ((sizeof(type) + sizeof(WORD) - 1) / sizeof(WORD) * sizeof(WORD))
68 #define VA_START16(list) ((list) = (VA_LIST16)(CURRENT_STACK16 + 1))
69 #define VA_ARG16(list,type) \
70 (((list) = (VA_LIST16)((char *)(list) + __VA_ROUNDED16(type))), \
71 *((type *)(void *)((char *)(list) - __VA_ROUNDED16(type))))
72 #define VA_END16(list) ((void)0)
75 /* Push bytes on the 16-bit stack of a thread;
76 * return a segptr to the first pushed byte
78 static inline SEGPTR WINE_UNUSED stack16_push( int size )
80 TEB *teb = NtCurrentTeb();
81 STACK16FRAME *frame = THREAD_STACK16(teb);
82 memmove( (char*)frame - size, frame, sizeof(*frame) );
83 teb->cur_stack -= size;
84 return (SEGPTR)(teb->cur_stack + sizeof(*frame));
87 /* Pop bytes from the 16-bit stack of a thread */
88 static inline void WINE_UNUSED stack16_pop( int size )
90 TEB *teb = NtCurrentTeb();
91 STACK16FRAME *frame = THREAD_STACK16(teb);
92 memmove( (char*)frame + size, frame, sizeof(*frame) );
93 teb->cur_stack += size;
96 /* Push a DWORD on the 32-bit stack */
97 static inline void WINE_UNUSED stack32_push( CONTEXT86 *context, DWORD val )
99 context->Esp -= sizeof(DWORD);
100 *(DWORD *)context->Esp = val;
103 /* Pop a DWORD from the 32-bit stack */
104 static inline DWORD WINE_UNUSED stack32_pop( CONTEXT86 *context )
106 DWORD ret = *(DWORD *)context->Esp;
107 context->Esp += sizeof(DWORD);
111 #endif /* __WINE_STACKFRAME_H */