4 * Copyright Robert J. Amstadt, 1993
13 #include <linux/unistd.h>
14 #include <linux/head.h>
15 #include <linux/ldt.h>
16 #include <linux/segment.h>
20 #include "prototypes.h"
23 struct dll_name_table_entry_s dll_builtin_table[4] =
25 { "KERNEL", KERNEL_table, 256, 1 },
26 { "USER", USER_table, 256, 2 },
27 { "GDI", GDI_table, 256, 3 },
28 { "UNIXLIB", UNIXLIB_table, 256, 4 },
31 unsigned short *Stack16Frame;
33 /**********************************************************************
36 * We get a stack frame pointer to data that looks like this:
40 * +00 previous saved_16ss
41 * +02 previous saved_16ebp
42 * +06 previous saved_16esp
46 * +12 length of 16-bit arguments
52 DLLRelay(unsigned int func_num, unsigned int seg_off)
54 struct dll_table_entry_s *dll_p;
59 int arg_table[DLL_MAX_ARGS];
65 * Determine address of arguments.
67 Stack16Frame = (unsigned short *) seg_off;
68 arg_ptr = (void *) (seg_off + 0x18);
71 * Extract the DLL number and ordinal number.
73 dll_id = ((func_num >> 16) & 0xffff) - 1;
74 ordinal = func_num & 0xffff;
75 dll_p = &dll_builtin_table[dll_id].dll_table[ordinal];
79 unsigned int *ret_addr;
80 unsigned short *stack_p;
82 ret_addr = (unsigned int *) ((char *) seg_off + 0x14);
83 printf("RELAY: Calling %s.%d, 16-bit stack at %04x:%04x, ",
84 dll_builtin_table[dll_id].dll_name, ordinal,
85 seg_off >> 16, seg_off & 0xffff);
86 printf("return to %08x\n", *ret_addr);
89 stack_p = (unsigned short *) seg_off;
90 for (i = 0; i < 24; i++, stack_p++)
92 printf("%04x ", *stack_p);
97 #endif /* STACK_DEBUG */
99 #endif /* RELAY_DEBUG */
102 * Make sure we have a handler defined for this call.
104 if (dll_p->handler == NULL)
108 sprintf(buffer, "No handler for routine %s.%d",
109 dll_builtin_table[dll_id].dll_name, ordinal);
112 func_ptr = dll_p->handler;
115 * OK, special case. If the handler is define as taking no arguments
116 * then pass the address of the arguments on the 16-bit stack to the
117 * handler. It will just ignore the pointer if it really takes no
118 * arguments. This allows us to write slightly faster library routines
121 if (dll_p->n_args == 0)
122 return (*func_ptr)(arg_ptr);
125 * Getting this far means we need to convert the 16-bit argument stack.
127 for (i = 0; i < dll_p->n_args; i++)
132 offset = dll_p->args[i].dst_arg;
134 switch (dll_p->args[i].src_type)
136 case DLL_ARGTYPE_SIGNEDWORD:
137 sp = (short *) ((char *) arg_ptr + offset);
141 case DLL_ARGTYPE_WORD:
142 sp = (short *) ((char *) arg_ptr + offset);
143 arg_table[i] = (int) *sp & 0xffff;
146 case DLL_ARGTYPE_LONG:
147 case DLL_ARGTYPE_FARPTR:
148 ip = (int *) ((char *) arg_ptr + offset);
157 return (*func_ptr)(arg_table[0], arg_table[1], arg_table[2],
158 arg_table[3], arg_table[4], arg_table[5],
159 arg_table[6], arg_table[7], arg_table[8],
160 arg_table[9], arg_table[10], arg_table[11],
161 arg_table[12], arg_table[13], arg_table[14],
165 /**********************************************************************
168 struct dll_table_entry_s *
169 FindDLLTable(char *dll_name)
173 for (i = 0; i < 4; i++)
174 if (strcmp(dll_builtin_table[i].dll_name, dll_name) == 0)
175 return dll_builtin_table[i].dll_table;
180 /**********************************************************************
181 * FindOrdinalFromName
184 FindOrdinalFromName(struct dll_table_entry_s *dll_table, char *func_name)
188 for (i = 0; i < 4; i++)
189 if (dll_table == dll_builtin_table[i].dll_table)
195 limit = dll_builtin_table[i].dll_table_length;
196 for (i = 0; i < limit; i++)
197 if (strcasecmp(dll_table[i].export_name, func_name) == 0)