Made stack manipulation macros into inline functions.
[wine] / include / stackframe.h
1 /*
2  * 16-bit and 32-bit mode stack frame layout
3  *
4  * Copyright 1995, 1998 Alexandre Julliard
5  */
6
7 #ifndef __WINE_STACKFRAME_H
8 #define __WINE_STACKFRAME_H
9
10 #include <string.h>
11 #include "ldt.h"
12 #include "thread.h"
13
14 #include "pshpack1.h"
15
16   /* 32-bit stack layout after CallTo16() */
17 typedef struct _STACK32FRAME
18 {
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 */
23     DWORD   esi;            /* 10 */
24     DWORD   edx;            /* 14 */
25     DWORD   ecx;            /* 18 */
26     DWORD   ebx;            /* 1c */
27     DWORD   ebp;            /* 20 saved 32-bit frame pointer */
28     DWORD   relay;          /* 24 return address to relay stub */
29     DWORD   retaddr;        /* 28 actual return address */
30     DWORD   args[1];        /* 2c arguments to 16-bit function */
31 } STACK32FRAME;
32
33   /* 16-bit stack layout after CallFrom16() */
34 typedef struct
35 {
36     STACK32FRAME *frame32;        /* 00 32-bit frame from last CallTo16() */
37     DWORD         edx;            /* 04 saved registers */
38     DWORD         ecx;            /* 08 */
39     DWORD         ebp;            /* 0c */
40     WORD          ds;             /* 10 */
41     WORD          es;             /* 12 */
42     WORD          fs;             /* 14 */
43     WORD          gs;             /* 16 */
44     DWORD         relay;          /* 18 address of argument relay stub */
45     DWORD         entry_ip;       /* 1c ip of entry point */
46     DWORD         entry_cs;       /* 20 cs of entry point */
47     DWORD         entry_point;    /* 24 API entry point to call, reused as mutex count */
48     WORD          bp;             /* 28 16-bit stack frame chain */
49     WORD          ip;             /* 2a return address */
50     WORD          cs;             /* 2c */
51 } STACK16FRAME;
52
53 #include "poppack.h"
54
55 #define THREAD_STACK16(teb)  ((STACK16FRAME*)PTR_SEG_TO_LIN((teb)->cur_stack))
56 #define CURRENT_STACK16      (THREAD_STACK16(NtCurrentTeb()))
57 #define CURRENT_DS           (CURRENT_STACK16->ds)
58
59 /* varargs lists on the 16-bit stack */
60
61 typedef void *VA_LIST16;
62
63 #define __VA_ROUNDED16(type) \
64     ((sizeof(type) + sizeof(WORD) - 1) / sizeof(WORD) * sizeof(WORD))
65 #define VA_START16(list) ((list) = (VA_LIST16)(CURRENT_STACK16 + 1))
66 #define VA_ARG16(list,type) \
67     (((list) = (VA_LIST16)((char *)(list) + __VA_ROUNDED16(type))), \
68      *((type *)(void *)((char *)(list) - __VA_ROUNDED16(type))))
69 #define VA_END16(list) ((void)0)
70
71
72 /* Push bytes on the 16-bit stack of a thread;
73  * return a segptr to the first pushed byte
74  */
75 static inline SEGPTR WINE_UNUSED stack16_push( int size )
76 {
77     TEB *teb = NtCurrentTeb();
78     STACK16FRAME *frame = THREAD_STACK16(teb);
79     memmove( (char*)frame - size, frame, sizeof(*frame) );
80     teb->cur_stack -= size;
81     return (SEGPTR)(teb->cur_stack + sizeof(*frame));
82 }
83
84 /* Pop bytes from the 16-bit stack of a thread */
85 static inline void WINE_UNUSED stack16_pop( int size )
86 {
87     TEB *teb = NtCurrentTeb();
88     STACK16FRAME *frame = THREAD_STACK16(teb);
89     memmove( (char*)frame + size, frame, sizeof(*frame) );
90     teb->cur_stack += size;
91 }
92
93 #ifdef __i386__
94 /* Push a DWORD on the 32-bit stack */
95 static inline void WINE_UNUSED stack32_push( CONTEXT *context, DWORD val )
96 {
97     ESP_reg(context) -= sizeof(DWORD);
98     *(DWORD *)ESP_reg(context) = val;
99 }
100
101 /* Pop a DWORD from the 32-bit stack */
102 static inline DWORD WINE_UNUSED stack32_pop( CONTEXT *context )
103 {
104     DWORD ret = *(DWORD *)ESP_reg(context);
105     ESP_reg(context) += sizeof(DWORD);
106     return ret;
107 }
108 #endif  /* __i386__ */
109
110 /* Win32 register functions */
111 #define REGS_FUNC(name) __regs_##name
112
113 #endif /* __WINE_STACKFRAME_H */