gdb-3.1
[deliverable/binutils-gdb.git] / gdb / m-i386.h
CommitLineData
e91b87a3 1/*
2 * Changes for 80386 by Pace Willisson (pace@prep.ai.mit.edu)
3 * July 1988
4 */
5
6/*
7 Copyright (C) 1986, 1987 Free Software Foundation, Inc.
8
9GDB is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY. No author or distributor accepts responsibility to anyone
11for the consequences of using it or for whether it serves any
12particular purpose or works at all, unless he says so in writing.
13Refer to the GDB General Public License for full details.
14
15Everyone is granted permission to copy, modify and redistribute GDB,
16but only under the conditions described in the GDB General Public
17License. A copy of this license is supposed to have been given to you
18along with GDB so you can know your rights and responsibilities. It
19should be in a file named COPYING. Among other things, the copyright
20notice and this notice must be preserved on all copies.
21
22In other words, go ahead and share GDB, but don't try to stop
23anyone else from sharing it farther. Help stamp out software hoarding!
24*/
25
26#ifndef i386
27#define i386
28#endif
29
30/* define USG if you are using sys5 /usr/include's */
31#define USG
32
33/* USG systems need these */
34#define vfork() fork()
35#define MAXPATHLEN 500
36
37/* define this if you don't have the extension to coff that allows
38 * file names to appear in the string table
39 * (aux.x_file.x_foff)
40 */
41#define COFF_NO_LONG_FILE_NAMES
42
43/* turn this on when rest of gdb is ready */
44/* #define IEEE_FLOAT */
45
46#define NBPG NBPC
47#define UPAGES USIZE
48
49#define HAVE_TERMIO
50
51/* Get rid of any system-imposed stack limit if possible. */
52
53/* #define SET_STACK_LIMIT_HUGE not in sys5 */
54
55/* Define this if the C compiler puts an underscore at the front
56 of external names before giving them to the linker. */
57
58/* #define NAMES_HAVE_UNDERSCORE */
59
60/* Specify debugger information format. */
61
62/* #define READ_DBX_FORMAT */
63#define COFF_FORMAT
64
65/* number of traps that happen between exec'ing the shell
66 * to run an inferior, and when we finally get to
67 * the inferior code. This is 2 on most implementations.
68 */
69#define START_INFERIOR_TRAPS_EXPECTED 4
70
71/* Offset from address of function to start of its code.
72 Zero on most machines. */
73
74#define FUNCTION_START_OFFSET 0
75
76/* Advance PC across any function entry prologue instructions
77 to reach some "real" code. */
78
79#define SKIP_PROLOGUE(frompc) {(frompc) = i386_skip_prologue((frompc));}
80
81/* Immediately after a function call, return the saved pc.
82 Can't always go through the frames for this because on some machines
83 the new frame is not set up until the new function executes
84 some instructions. */
85
86#define SAVED_PC_AFTER_CALL(frame) \
87 (read_memory_integer (read_register (SP_REGNUM), 4))
88
89/* This is the amount to subtract from u.u_ar0
90 to get the offset in the core file of the register values. */
91
92#define KERNEL_U_ADDR 0xe0000000
93
94/* Address of end of stack space. */
95
96#define STACK_END_ADDR 0x80000000
97
98/* Stack grows downward. */
99
100#define INNER_THAN <
101
102/* Sequence of bytes for breakpoint instruction. */
103
104#define BREAKPOINT {0xcc}
105
106/* Amount PC must be decremented by after a breakpoint.
107 This is often the number of bytes in BREAKPOINT
108 but not always. */
109
110#define DECR_PC_AFTER_BREAK 1
111
112/* Nonzero if instruction at PC is a return instruction. */
113
114#define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 1) == 0xc3)
115
116/* Return 1 if P points to an invalid floating point value.
117 LEN is the length in bytes -- not relevant on the 386. */
118
119#define INVALID_FLOAT(p, len) (0)
120
121/* code to execute to print interesting information about the
122 * floating point processor (if any)
123 * No need to define if there is nothing to do.
124 */
125#define FLOAT_INFO { i386_float_info (); }
126
127
128/* Largest integer type */
129#define LONGEST long
130
131/* Name of the builtin type for the LONGEST type above. */
132#define BUILTIN_TYPE_LONGEST builtin_type_long
133
134/* Say how long (ordinary) registers are. */
135
136#define REGISTER_TYPE long
137
138/* Number of machine registers */
139
140#define NUM_REGS 16
141
142/* Initializer for an array of names of registers.
143 There should be NUM_REGS strings in this initializer. */
144
145/* the order of the first 8 registers must match the compiler's
146 * numbering scheme (which is the same as the 386 scheme)
147 * also, this table must match regmap in i386-pinsn.c.
148 */
149#define REGISTER_NAMES { "eax", "ecx", "edx", "ebx", \
150 "esp", "ebp", "esi", "edi", \
151 "eip", "ps", "cs", "ss", \
152 "ds", "es", "fs", "gs", \
153 }
154
155/* Register numbers of various important registers.
156 Note that some of these values are "real" register numbers,
157 and correspond to the general registers of the machine,
158 and some are "phony" register numbers which are too large
159 to be actual register numbers as far as the user is concerned
160 but do serve to get the desired values when passed to read_register. */
161
162#define FP_REGNUM 5 /* Contains address of executing stack frame */
163#define SP_REGNUM 4 /* Contains address of top of stack */
164
165#define PC_REGNUM 8
166#define PS_REGNUM 9
167
168#define REGISTER_U_ADDR(addr, blockend, regno) \
169 (addr) = i386_register_u_addr ((blockend),(regno));
170
171/* Total amount of space needed to store our copies of the machine's
172 register state, the array `registers'. */
173#define REGISTER_BYTES (NUM_REGS * 4)
174
175/* Index within `registers' of the first byte of the space for
176 register N. */
177
178#define REGISTER_BYTE(N) ((N)*4)
179
180/* Number of bytes of storage in the actual machine representation
181 for register N. */
182
183#define REGISTER_RAW_SIZE(N) (4)
184
185/* Number of bytes of storage in the program's representation
186 for register N. */
187
188#define REGISTER_VIRTUAL_SIZE(N) (4)
189
190/* Largest value REGISTER_RAW_SIZE can have. */
191
192#define MAX_REGISTER_RAW_SIZE 4
193
194/* Largest value REGISTER_VIRTUAL_SIZE can have. */
195
196#define MAX_REGISTER_VIRTUAL_SIZE 4
197
198/* Nonzero if register N requires conversion
199 from raw format to virtual format. */
200
201#define REGISTER_CONVERTIBLE(N) (0)
202
203/* Convert data from raw format for register REGNUM
204 to virtual format for register REGNUM. */
205
206#define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) {bcopy ((FROM), (TO), 4);}
207
208/* Convert data from virtual format for register REGNUM
209 to raw format for register REGNUM. */
210
211#define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) {bcopy ((FROM), (TO), 4);}
212
213/* Return the GDB type object for the "standard" data type
214 of data in register N. */
215
216#define REGISTER_VIRTUAL_TYPE(N) (builtin_type_int)
217
218/* Store the address of the place in which to copy the structure the
219 subroutine will return. This is called from call_function. */
220
221#define STORE_STRUCT_RETURN(ADDR, SP) \
222 { (SP) -= sizeof (ADDR); \
223 write_memory ((SP), &(ADDR), sizeof (ADDR)); }
224
225/* Extract from an array REGBUF containing the (raw) register state
226 a function return value of type TYPE, and copy that, in virtual format,
227 into VALBUF. */
228
229#define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
230 bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE))
231
232/* Write into appropriate registers a function return value
233 of type TYPE, given in virtual format. */
234
235#define STORE_RETURN_VALUE(TYPE,VALBUF) \
236 write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
237
238/* Extract from an array REGBUF containing the (raw) register state
239 the address in which a function should return its structure value,
240 as a CORE_ADDR (or an expression that can be used as one). */
241
242#define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
243
244\f
245/* Describe the pointer in each stack frame to the previous stack frame
246 (its caller). */
247
248/* FRAME_CHAIN takes a frame's nominal address
249 and produces the frame's chain-pointer.
250
251 FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
252 and produces the nominal address of the caller frame.
253
254 However, if FRAME_CHAIN_VALID returns zero,
255 it means the given frame is the outermost one and has no caller.
256 In that case, FRAME_CHAIN_COMBINE is not used. */
257
258#define FRAME_CHAIN(thisframe) (read_memory_integer ((thisframe)->frame, 4))
259
260#define FRAME_CHAIN_VALID(chain, thisframe) \
261 (chain != 0 && (FRAME_SAVED_PC (thisframe) >= first_object_file_end))
262
263#define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
264
265/* Define other aspects of the stack frame. */
266
267#define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4))
268
269#define FRAME_ARGS_ADDRESS(fi) ((fi)->frame)
270
271#define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
272
273/* Return number of args passed to a frame.
274 Can return -1, meaning no way to tell. */
275
276/* on the 386, the instruction following the call could be:
277 * popl %ecx - one arg
278 * addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
279 * anything else - zero args
280 */
281#define FRAME_NUM_ARGS(numargs, fi) { \
282 int retpc; \
283 unsigned char op; \
284 struct frame_info *pfi; \
285 pfi = get_prev_frame_info ((fi)); \
286 retpc = pfi->pc; \
287 numargs = 0; \
288 op = read_memory_integer (retpc, 1); \
289 if (op == 0x59) \
290 /* pop %ecx */ \
291 (numargs) = 1; \
292 else if (op == 0x83) { \
293 op = read_memory_integer (retpc+1, 1); \
294 if (op == 0xc4) \
295 /* addl $<signed imm 8 bits>, %esp */ \
296 (numargs) = (read_memory_integer (retpc+2,1)&0xff)/4;\
297 } else if (op == 0x81) { /* add with 32 bit immediate */\
298 op = read_memory_integer (retpc+1, 1); \
299 if (op == 0xc4) \
300 /* addl $<imm 32>, %esp */ \
301 (numargs) = read_memory_integer (retpc+2, 4) / 4;\
302 } \
303}
304
305/* Return number of bytes at start of arglist that are not really args. */
306
307#define FRAME_ARGS_SKIP 8
308
309/* Put here the code to store, into a struct frame_saved_regs,
310 the addresses of the saved registers of frame described by FRAME_INFO.
311 This includes special registers such as pc and fp saved in special
312 ways in the stack frame. sp is even more special:
313 the address we return for it IS the sp for the next frame. */
314
315#define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
316{ i386_frame_find_saved_regs ((frame_info), &(frame_saved_regs)); }
317
318\f
319/* Things needed for making the inferior call functions. */
320
321/* Push an empty stack frame, to record the current PC, etc. */
322
323#define PUSH_DUMMY_FRAME { i386_push_dummy_frame (); }
324
325/* Discard from the stack the innermost frame, restoring all registers. */
326
327#define POP_FRAME { i386_pop_frame (); }
328
329/* this is
330 * call 11223344 (32 bit relative)
331 * int3
332 */
333
334#define CALL_DUMMY { 0x223344e8, 0xcc11 }
335
336#define CALL_DUMMY_LENGTH 8
337
338#define CALL_DUMMY_START_OFFSET 0 /* Start execution at beginning of dummy */
339
340/* Insert the specified number of args and function address
341 into a call sequence of the above form stored at DUMMYNAME. */
342
343#define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, type) \
344{ \
345 int from, to, delta, loc; \
346 loc = (int)(read_register (SP_REGNUM) - CALL_DUMMY_LENGTH); \
347 from = loc + 5; \
348 to = (int)(fun); \
349 delta = to - from; \
350 *(int *)((char *)(dummyname) + 1) = delta; \
351}
352
353\f
354#if 0
355/* Interface definitions for kernel debugger KDB. */
356
357/* Map machine fault codes into signal numbers.
358 First subtract 0, divide by 4, then index in a table.
359 Faults for which the entry in this table is 0
360 are not handled by KDB; the program's own trap handler
361 gets to handle then. */
362
363#define FAULT_CODE_ORIGIN 0
364#define FAULT_CODE_UNITS 4
365#define FAULT_TABLE \
366{ 0, 0, 0, 0, 0, 0, 0, 0, \
367 0, 0, 0, 0, 0, 0, 0, 0, \
368 0, 0, 0, 0, 0, 0, 0, 0}
369
370/* Start running with a stack stretching from BEG to END.
371 BEG and END should be symbols meaningful to the assembler.
372 This is used only for kdb. */
373
374#define INIT_STACK(beg, end) {}
375
376/* Push the frame pointer register on the stack. */
377#define PUSH_FRAME_PTR {}
378
379/* Copy the top-of-stack to the frame pointer register. */
380#define POP_FRAME_PTR {}
381
382/* After KDB is entered by a fault, push all registers
383 that GDB thinks about (all NUM_REGS of them),
384 so that they appear in order of ascending GDB register number.
385 The fault code will be on the stack beyond the last register. */
386
387#define PUSH_REGISTERS {}
388
389/* Assuming the registers (including processor status) have been
390 pushed on the stack in order of ascending GDB register number,
391 restore them and return to the address in the saved PC register. */
392
393#define POP_REGISTERS {}
394#endif
This page took 0.036922 seconds and 4 git commands to generate.