Separated stuff for shv background contextmenu to separate file.
[wine.git] / include / stackframe.h
blob5e6a8211bb9f801bdc84213826daa94b4d147adb
1 /*
2 * 16-bit and 32-bit mode stack frame layout
4 * Copyright 1995, 1998 Alexandre Julliard
5 */
7 #ifndef __WINE_STACKFRAME_H
8 #define __WINE_STACKFRAME_H
10 #include "ldt.h"
11 #include "thread.h"
13 #include "pshpack1.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 */
22 DWORD esi; /* 10 */
23 DWORD edx; /* 14 */
24 DWORD ecx; /* 18 */
25 DWORD ebx; /* 1c */
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 */
30 } STACK32FRAME;
32 /* 16-bit stack layout after CallFrom16() */
33 typedef struct
35 STACK32FRAME *frame32; /* 00 32-bit frame from last CallTo16() */
36 DWORD edx; /* 04 saved registers */
37 DWORD ecx; /* 08 */
38 DWORD ebp; /* 0c */
39 WORD ds; /* 10 */
40 WORD es; /* 12 */
41 WORD fs; /* 14 */
42 WORD gs; /* 16 */
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 */
49 WORD cs; /* 2c */
50 } STACK16FRAME;
52 #include "poppack.h"
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 */