Release 980601
[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 "windows.h"
12 #include "ldt.h"
13 #include "thread.h"
14
15 #pragma pack(1)
16
17   /* 32-bit stack layout after CallTo16() */
18 typedef struct _STACK32FRAME
19 {
20     SEGPTR  frame16;        /* 00 16-bit frame from last CallFrom16() */
21     DWORD   edi;            /* 04 saved registers */
22     DWORD   esi;            /* 08 */
23     DWORD   edx;            /* 0c */
24     DWORD   ecx;            /* 10 */
25     DWORD   ebx;            /* 14 */
26     DWORD   restore_addr;   /* 18 return address for restoring code selector */
27     DWORD   codeselector;   /* 1c code selector to restore */
28     DWORD   ebp;            /* 20 saved 32-bit frame pointer */
29     DWORD   retaddr;        /* 24 actual return address */
30     DWORD   args[1];        /* 28 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         ebp;            /* 04 full 32-bit content of ebp */
38     WORD          entry_ip;       /* 08 ip of entry point */
39     WORD          ds;             /* 0a ds */
40     WORD          entry_cs;       /* 0c cs of entry point */
41     WORD          es;             /* 0e es */
42     DWORD         entry_point;    /* 10 32-bit entry point to call */
43     WORD          bp;             /* 14 16-bit bp */
44     WORD          ip;             /* 16 return address */
45     WORD          cs;             /* 18 */
46 } STACK16FRAME;
47
48 #pragma pack(4)
49
50 #define THREAD_STACK16(thdb) ((STACK16FRAME*)PTR_SEG_TO_LIN((thdb)->cur_stack))
51 #define CURRENT_STACK16      (THREAD_STACK16(THREAD_Current()))
52 #define CURRENT_DS           (CURRENT_STACK16->ds)
53
54 /* varargs lists on the 16-bit stack */
55
56 typedef void *VA_LIST16;
57
58 #define __VA_ROUNDED16(type) \
59     ((sizeof(type) + sizeof(WORD) - 1) / sizeof(WORD) * sizeof(WORD))
60 #define VA_START16(list) ((list) = (VA_LIST16)(CURRENT_STACK16 + 1))
61 #define VA_ARG16(list,type) \
62     (((list) = (VA_LIST16)((char *)(list) + __VA_ROUNDED16(type))), \
63      *((type *)(void *)((char *)(list) - __VA_ROUNDED16(type))))
64 #define VA_END16(list) ((void)0)
65
66 /* Push bytes on the 16-bit stack of a thread;
67  * return a segptr to the first pushed byte
68  */
69 #define STACK16_PUSH(thdb,size) \
70  (memmove((char*)THREAD_STACK16(thdb)-(size),THREAD_STACK16(thdb), \
71           sizeof(STACK16FRAME)), \
72   (thdb)->cur_stack -= (size), \
73   (SEGPTR)((thdb)->cur_stack + sizeof(STACK16FRAME)))
74
75 /* Pop bytes from the 16-bit stack of a thread */
76 #define STACK16_POP(thdb,size) \
77  (memmove((char*)THREAD_STACK16(thdb)+(size),THREAD_STACK16(thdb), \
78           sizeof(STACK16FRAME)), \
79   (thdb)->cur_stack += (size))
80
81 /* Push a DWORD on the 32-bit stack */
82 #define STACK32_PUSH(context,val) (*--((DWORD *)ESP_reg(context)) = (val))
83
84 /* Pop a DWORD from the 32-bit stack */
85 #define STACK32_POP(context) (*((DWORD *)ESP_reg(context))++)
86
87 /* Win32 register functions */
88 #define REGS_ENTRYPOINT(name) void WINAPI __regs_##name( CONTEXT *context )
89
90 #endif /* __WINE_STACKFRAME_H */