Release 960114
[wine/gsoc-2012-control.git] / if1632 / relay.c
blob6f6f7c89abc994cb878e129ce9478d0052737ac3
1 /*
2 * Copyright 1993 Robert J. Amstadt
3 * Copyright 1995 Alexandre Julliard
4 */
6 #include <stdio.h>
8 #include "dlls.h"
9 #include "global.h"
10 #include "module.h"
11 #include "registers.h"
12 #include "stackframe.h"
13 #include "stddebug.h"
14 /* #define DEBUG_RELAY */
15 #include "debug.h"
17 #if 0
18 /* Make make_debug think these were really used */
19 dprintf_relay
20 #endif
22 #define DLL_ENTRY(name) \
23 { #name, name##_Code_Start, name##_Data_Start, \
24 name##_Module_Start, name##_Module_End, TRUE, 0 }
25 #define DLL_ENTRY_NOTUSED(name) \
26 { #name, name##_Code_Start, name##_Data_Start, \
27 name##_Module_Start, name##_Module_End, FALSE, 0 }
29 struct dll_table_s dll_builtin_table[N_BUILTINS] =
31 DLL_ENTRY(KERNEL),
32 DLL_ENTRY(USER),
33 DLL_ENTRY(GDI),
34 DLL_ENTRY_NOTUSED(WIN87EM),
35 DLL_ENTRY_NOTUSED(SHELL),
36 DLL_ENTRY(SOUND),
37 DLL_ENTRY(KEYBOARD),
38 DLL_ENTRY(WINSOCK),
39 DLL_ENTRY(STRESS),
40 DLL_ENTRY(MMSYSTEM),
41 DLL_ENTRY(SYSTEM),
42 DLL_ENTRY(TOOLHELP),
43 DLL_ENTRY(MOUSE),
44 DLL_ENTRY_NOTUSED(COMMDLG),
45 DLL_ENTRY_NOTUSED(OLE2),
46 DLL_ENTRY_NOTUSED(OLE2CONV),
47 DLL_ENTRY_NOTUSED(OLE2DISP),
48 DLL_ENTRY_NOTUSED(OLE2NLS),
49 DLL_ENTRY_NOTUSED(OLE2PROX),
50 DLL_ENTRY_NOTUSED(OLECLI),
51 DLL_ENTRY_NOTUSED(OLESVR),
52 DLL_ENTRY_NOTUSED(COMPOBJ),
53 DLL_ENTRY_NOTUSED(STORAGE),
54 DLL_ENTRY(WINPROCS),
55 DLL_ENTRY_NOTUSED(DDEML)
58 /* don't forget to increase N_BUILTINS in dlls.h if you add a dll */
60 /* Saved 16-bit stack */
61 WORD IF1632_Saved16_ss = 0;
62 WORD IF1632_Saved16_sp = 0;
64 /* Saved 32-bit stack */
65 DWORD IF1632_Saved32_esp = 0;
66 SEGPTR IF1632_Stack32_base = 0;
67 DWORD IF1632_Original32_esp = 0;
69 /***********************************************************************
70 * RELAY_Init
72 BOOL RELAY_Init(void)
74 WORD codesel;
76 /* Allocate the code selector for CallTo16 routines */
78 extern void CALL16_Start(), CALL16_End();
79 extern void CALL16_Ret_word(), CALL16_Ret_long();
80 extern DWORD CALL16_RetAddr_word, CALL16_RetAddr_long;
82 codesel = GLOBAL_CreateBlock( GMEM_FIXED, (void *)CALL16_Start,
83 (int)CALL16_End - (int)CALL16_Start,
84 0, TRUE, TRUE, FALSE, NULL );
85 if (!codesel) return FALSE;
87 /* Patch the return addresses for CallTo16 routines */
89 CALL16_RetAddr_word = MAKELONG( (int)CALL16_Ret_word - (int)CALL16_Start,
90 codesel );
91 CALL16_RetAddr_long = MAKELONG( (int)CALL16_Ret_long - (int)CALL16_Start,
92 codesel );
94 return TRUE;
98 /***********************************************************************
99 * RELAY_DebugCall32
101 void RELAY_DebugCall32( int func_type, char *args,
102 void *entry_point, int args32 )
104 STACK16FRAME *frame;
105 struct dll_table_s *table;
106 char *args16, *name;
107 int i;
109 if (!debugging_relay) return;
111 frame = CURRENT_STACK16;
112 table = &dll_builtin_table[frame->dll_id-1];
113 name = MODULE_GetEntryPointName( table->hModule, frame->ordinal_number );
114 printf( "Call %s.%d: %*.*s(",
115 table->name, frame->ordinal_number, *name, *name, name + 1 );
117 args16 = (char *)frame->args;
118 for (i = 0; i < strlen(args); i++)
120 switch(args[i])
122 case 'w':
123 case 's':
124 args16 += 2;
125 break;
126 case 'l':
127 case 'p':
128 args16 += 4;
129 break;
133 while (*args)
135 switch(*args)
137 case 'w':
138 case 's':
139 args16 -= 2;
140 printf( "0x%04x", *(WORD *)args16 );
141 break;
142 case 'l':
143 args16 -= 4;
144 printf( "0x%08x", *(int *)args16 );
145 break;
146 case 'p':
147 args16 -= 4;
148 printf( "%04x:%04x", *(WORD *)(args16+2), *(WORD *)args16 );
149 break;
151 args++;
152 if (*args) printf( "," );
154 printf( ") ret=%04x:%04x ds=%04x\n", frame->cs, frame->ip, frame->ds );
156 if (func_type == 2) /* register function */
158 struct sigcontext_struct *context = (struct sigcontext_struct *)&args32;
159 printf( " AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
160 AX_reg(context), BX_reg(context), CX_reg(context),
161 DX_reg(context), SI_reg(context), DI_reg(context),
162 ES_reg(context), EFL_reg(context) );
167 /***********************************************************************
168 * RELAY_DebugReturn
170 void RELAY_DebugReturn( int func_type, int ret_val, int args32 )
172 STACK16FRAME *frame;
173 struct dll_table_s *table;
174 char *name;
176 if (*(DWORD *)PTR_SEG_TO_LIN(IF1632_Stack32_base) != 0xDEADBEEF)
178 fprintf(stderr, "Wine wrote past the end of the 32 bit stack. Please report this.\n");
179 exit(1); /* There's probably no point in going on */
181 if (!debugging_relay) return;
183 frame = CURRENT_STACK16;
184 table = &dll_builtin_table[frame->dll_id-1];
185 name = MODULE_GetEntryPointName( table->hModule, frame->ordinal_number );
186 printf( "Ret %s.%d: %*.*s() ",
187 table->name, frame->ordinal_number, *name, *name, name + 1 );
188 switch(func_type)
190 case 0: /* long */
191 printf( "retval=0x%08x ret=%04x:%04x ds=%04x\n",
192 ret_val, frame->cs, frame->ip, frame->ds );
193 break;
194 case 1: /* word */
195 printf( "retval=0x%04x ret=%04x:%04x ds=%04x\n",
196 ret_val & 0xffff, frame->cs, frame->ip, frame->ds );
197 break;
198 case 2: /* regs */
199 printf( "retval=none ret=%04x:%04x ds=%04x\n",
200 frame->cs, frame->ip, frame->ds );
202 struct sigcontext_struct *context = (struct sigcontext_struct *)&args32;
203 printf( " AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x ES=%04x EFL=%08lx\n",
204 AX_reg(context), BX_reg(context), CX_reg(context),
205 DX_reg(context), SI_reg(context), DI_reg(context),
206 ES_reg(context), EFL_reg(context) );
208 break;
213 /***********************************************************************
214 * RELAY_Unimplemented
216 * This function is called for unimplemented entry points (declared
217 * as 'stub' in the spec file).
219 void RELAY_Unimplemented(void)
221 STACK16FRAME *frame = CURRENT_STACK16;
222 struct dll_table_s *table = &dll_builtin_table[frame->dll_id-1];
223 char *name = MODULE_GetEntryPointName( table->hModule, frame->ordinal_number );
225 fprintf( stderr, "No handler for routine %s.%d (%*.*s)\n",
226 table->name, frame->ordinal_number, *name, *name, name + 1 );
227 exit(1);
231 /***********************************************************************
232 * RELAY_DebugCall16
234 * 'stack' points to the called function address on the 32-bit stack.
235 * Stack layout:
236 * ... ...
237 * (stack+12) arg2
238 * (stack+8) arg1
239 * (stack+4) 16-bit ds
240 * (stack) func to call
242 void RELAY_DebugCall16( int* stack, int nbargs )
244 if (!debugging_relay) return;
246 printf( "CallTo16(func=%04x:%04x,ds=%04x",
247 HIWORD(stack[0]), LOWORD(stack[0]), LOWORD(stack[1]) );
248 stack += 2;
249 while (nbargs--) printf( ",0x%x", *stack++ );
250 printf( ")\n" );