| 1 | /*- |
| 2 | * This code is derived from software copyrighted by the Free Software |
| 3 | * Foundation. |
| 4 | * |
| 5 | * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. |
| 6 | * Modified 1991 by William Jolitz at UUNET Technologies, Inc. |
| 7 | * |
| 8 | * @(#)m-i386bsd.h 6.7 (Berkeley) 5/8/91 |
| 9 | */ |
| 10 | |
| 11 | /* Macro definitions for i386. |
| 12 | Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. |
| 13 | |
| 14 | This file is part of GDB. |
| 15 | |
| 16 | GDB is free software; you can redistribute it and/or modify |
| 17 | it under the terms of the GNU General Public License as published by |
| 18 | the Free Software Foundation; either version 1, or (at your option) |
| 19 | any later version. |
| 20 | |
| 21 | GDB is distributed in the hope that it will be useful, |
| 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | GNU General Public License for more details. |
| 25 | |
| 26 | You should have received a copy of the GNU General Public License |
| 27 | along with GDB; see the file COPYING. If not, write to |
| 28 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 29 | |
| 30 | /* Define the bit, byte, and word ordering of the machine. */ |
| 31 | /* #define BITS_BIG_ENDIAN */ |
| 32 | /* #define BYTES_BIG_ENDIAN */ |
| 33 | /* #define WORDS_BIG_ENDIAN */ |
| 34 | |
| 35 | /* |
| 36 | * Changes for 80386 by Pace Willisson (pace@prep.ai.mit.edu) |
| 37 | * July 1988 |
| 38 | * [ MODIFIED FOR 386BSD W. Jolitz ] |
| 39 | */ |
| 40 | |
| 41 | #ifndef i386 |
| 42 | #define i386 1 |
| 43 | #define i386b 1 |
| 44 | #endif |
| 45 | |
| 46 | #define IEEE_FLOAT |
| 47 | #define LONG_LONG |
| 48 | |
| 49 | /* Library stuff: POSIX tty (not supported yet), V7 tty (sigh), vprintf. */ |
| 50 | |
| 51 | #define HAVE_TERMIOS 1 |
| 52 | #define USE_OLD_TTY 1 |
| 53 | #define HAVE_VPRINTF 1 |
| 54 | |
| 55 | /* We support local and remote kernel debugging. */ |
| 56 | |
| 57 | #define KERNELDEBUG 1 |
| 58 | |
| 59 | /* Get rid of any system-imposed stack limit if possible. */ |
| 60 | |
| 61 | #define SET_STACK_LIMIT_HUGE |
| 62 | |
| 63 | /* Define this if the C compiler puts an underscore at the front |
| 64 | of external names before giving them to the linker. */ |
| 65 | |
| 66 | #define NAMES_HAVE_UNDERSCORE |
| 67 | |
| 68 | /* Specify debugger information format. */ |
| 69 | |
| 70 | #define READ_DBX_FORMAT |
| 71 | |
| 72 | /* number of traps that happen between exec'ing the shell |
| 73 | * to run an inferior, and when we finally get to |
| 74 | * the inferior code. This is 2 on most implementations. |
| 75 | */ |
| 76 | #define START_INFERIOR_TRAPS_EXPECTED 2 |
| 77 | |
| 78 | /* Offset from address of function to start of its code. |
| 79 | Zero on most machines. */ |
| 80 | |
| 81 | #define FUNCTION_START_OFFSET 0 |
| 82 | |
| 83 | /* Advance PC across any function entry prologue instructions |
| 84 | to reach some "real" code. */ |
| 85 | |
| 86 | #define SKIP_PROLOGUE(frompc) {(frompc) = i386_skip_prologue((frompc));} |
| 87 | |
| 88 | /* Immediately after a function call, return the saved pc. |
| 89 | Can't always go through the frames for this because on some machines |
| 90 | the new frame is not set up until the new function executes |
| 91 | some instructions. */ |
| 92 | |
| 93 | #define SAVED_PC_AFTER_CALL(frame) \ |
| 94 | (read_memory_integer (read_register (SP_REGNUM), 4)) |
| 95 | |
| 96 | /* This is the amount to subtract from u.u_ar0 |
| 97 | to get the offset in the core file of the register values. */ |
| 98 | |
| 99 | #ifdef NEWVM |
| 100 | #include <machine/vmparam.h> |
| 101 | #define KERNEL_U_ADDR USRSTACK |
| 102 | #else |
| 103 | #define KERNEL_U_ADDR 0xfdffd000 |
| 104 | #endif |
| 105 | |
| 106 | /* Address of end of stack space. */ |
| 107 | |
| 108 | #define STACK_END_ADDR KERNEL_U_ADDR |
| 109 | |
| 110 | /* Stack grows downward. */ |
| 111 | |
| 112 | #define INNER_THAN < |
| 113 | |
| 114 | /* Sequence of bytes for breakpoint instruction. */ |
| 115 | |
| 116 | #define BREAKPOINT {0xcc} |
| 117 | |
| 118 | /* Amount PC must be decremented by after a breakpoint. |
| 119 | This is often the number of bytes in BREAKPOINT |
| 120 | but not always. */ |
| 121 | |
| 122 | #define DECR_PC_AFTER_BREAK 1 |
| 123 | |
| 124 | /* Nonzero if instruction at PC is a return instruction. */ |
| 125 | |
| 126 | #define ABOUT_TO_RETURN(pc) \ |
| 127 | strchr("\302\303\312\313\317", read_memory_integer(pc, 1)) |
| 128 | |
| 129 | /* Return 1 if P points to an invalid floating point value. |
| 130 | LEN is the length in bytes -- not relevant on the 386. */ |
| 131 | |
| 132 | #define INVALID_FLOAT(p, len) (0) |
| 133 | |
| 134 | /* code to execute to print interesting information about the |
| 135 | * floating point processor (if any) |
| 136 | * No need to define if there is nothing to do. |
| 137 | */ |
| 138 | #define FLOAT_INFO { i386_float_info (); } |
| 139 | |
| 140 | |
| 141 | /* Largest integer type */ |
| 142 | #define LONGEST long long |
| 143 | |
| 144 | /* Name of the builtin type for the LONGEST type above. */ |
| 145 | #define BUILTIN_TYPE_LONGEST builtin_type_long_long |
| 146 | |
| 147 | /* Say how long (ordinary) registers are. */ |
| 148 | |
| 149 | #define REGISTER_TYPE long |
| 150 | |
| 151 | /* Number of machine registers */ |
| 152 | |
| 153 | #define NUM_REGS 16 |
| 154 | |
| 155 | /* Initializer for an array of names of registers. |
| 156 | There should be NUM_REGS strings in this initializer. */ |
| 157 | |
| 158 | /* the order of the first 8 registers must match the compiler's |
| 159 | * numbering scheme (which is the same as the 386 scheme) |
| 160 | * also, this table must match regmap in i386-pinsn.c. |
| 161 | */ |
| 162 | #define REGISTER_NAMES { "eax", "ecx", "edx", "ebx", \ |
| 163 | "esp", "ebp", "esi", "edi", \ |
| 164 | "eip", "ps", "cs", "ss", \ |
| 165 | "ds", "es", "fs", "gs", \ |
| 166 | } |
| 167 | |
| 168 | /* Register numbers of various important registers. |
| 169 | Note that some of these values are "real" register numbers, |
| 170 | and correspond to the general registers of the machine, |
| 171 | and some are "phony" register numbers which are too large |
| 172 | to be actual register numbers as far as the user is concerned |
| 173 | but do serve to get the desired values when passed to read_register. */ |
| 174 | |
| 175 | #define FP_REGNUM 5 /* Contains address of executing stack frame */ |
| 176 | #define SP_REGNUM 4 /* Contains address of top of stack */ |
| 177 | |
| 178 | #define PC_REGNUM 8 |
| 179 | #define PS_REGNUM 9 |
| 180 | |
| 181 | #define REGISTER_U_ADDR(addr, blockend, regno) \ |
| 182 | (addr) = i386_register_u_addr ((blockend),(regno)); |
| 183 | |
| 184 | /* Total amount of space needed to store our copies of the machine's |
| 185 | register state, the array `registers'. */ |
| 186 | #define REGISTER_BYTES (NUM_REGS * 4) |
| 187 | |
| 188 | /* Index within `registers' of the first byte of the space for |
| 189 | register N. */ |
| 190 | |
| 191 | #define REGISTER_BYTE(N) ((N)*4) |
| 192 | |
| 193 | /* Number of bytes of storage in the actual machine representation |
| 194 | for register N. */ |
| 195 | |
| 196 | #define REGISTER_RAW_SIZE(N) (4) |
| 197 | |
| 198 | /* Number of bytes of storage in the program's representation |
| 199 | for register N. */ |
| 200 | |
| 201 | #define REGISTER_VIRTUAL_SIZE(N) (4) |
| 202 | |
| 203 | /* Largest value REGISTER_RAW_SIZE can have. */ |
| 204 | |
| 205 | #define MAX_REGISTER_RAW_SIZE 4 |
| 206 | |
| 207 | /* Largest value REGISTER_VIRTUAL_SIZE can have. */ |
| 208 | |
| 209 | #define MAX_REGISTER_VIRTUAL_SIZE 4 |
| 210 | |
| 211 | /* Nonzero if register N requires conversion |
| 212 | from raw format to virtual format. */ |
| 213 | |
| 214 | #define REGISTER_CONVERTIBLE(N) (0) |
| 215 | |
| 216 | /* Convert data from raw format for register REGNUM |
| 217 | to virtual format for register REGNUM. */ |
| 218 | |
| 219 | #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) {bcopy ((FROM), (TO), 4);} |
| 220 | |
| 221 | /* Convert data from virtual format for register REGNUM |
| 222 | to raw format for register REGNUM. */ |
| 223 | |
| 224 | #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) {bcopy ((FROM), (TO), 4);} |
| 225 | |
| 226 | /* Return the GDB type object for the "standard" data type |
| 227 | of data in register N. */ |
| 228 | |
| 229 | #define REGISTER_VIRTUAL_TYPE(N) (builtin_type_int) |
| 230 | |
| 231 | /* Store the address of the place in which to copy the structure the |
| 232 | subroutine will return. This is called from call_function. */ |
| 233 | |
| 234 | #define STORE_STRUCT_RETURN(ADDR, SP) \ |
| 235 | { (SP) -= sizeof (ADDR); \ |
| 236 | write_memory ((SP), &(ADDR), sizeof (ADDR)); } |
| 237 | |
| 238 | /* Extract from an array REGBUF containing the (raw) register state |
| 239 | a function return value of type TYPE, and copy that, in virtual format, |
| 240 | into VALBUF. */ |
| 241 | |
| 242 | #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ |
| 243 | bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE)) |
| 244 | |
| 245 | /* Write into appropriate registers a function return value |
| 246 | of type TYPE, given in virtual format. */ |
| 247 | |
| 248 | #define STORE_RETURN_VALUE(TYPE,VALBUF) \ |
| 249 | write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE)) |
| 250 | |
| 251 | /* Extract from an array REGBUF containing the (raw) register state |
| 252 | the address in which a function should return its structure value, |
| 253 | as a CORE_ADDR (or an expression that can be used as one). */ |
| 254 | |
| 255 | #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF)) |
| 256 | |
| 257 | \f |
| 258 | /* Describe the pointer in each stack frame to the previous stack frame |
| 259 | (its caller). */ |
| 260 | |
| 261 | /* FRAME_CHAIN takes a frame's nominal address |
| 262 | and produces the frame's chain-pointer. |
| 263 | |
| 264 | FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address |
| 265 | and produces the nominal address of the caller frame. |
| 266 | |
| 267 | However, if FRAME_CHAIN_VALID returns zero, |
| 268 | it means the given frame is the outermost one and has no caller. |
| 269 | In that case, FRAME_CHAIN_COMBINE is not used. */ |
| 270 | |
| 271 | #define FRAME_CHAIN(thisframe) \ |
| 272 | (outside_startup_file ((thisframe)->pc) ? \ |
| 273 | read_memory_integer ((thisframe)->frame, 4) :\ |
| 274 | 0) |
| 275 | |
| 276 | #ifdef KERNELDEBUG |
| 277 | #define KERNTEXT_BASE 0xfe000000 |
| 278 | #ifdef NEWVM |
| 279 | #define KERNSTACK_TOP (read_register(SP_REGNUM) + 0x2000) /* approximate */ |
| 280 | #else |
| 281 | /* #define KERNSTACK_TOP (P1PAGES << PGSHIFT) */ |
| 282 | #define KERNSTACK_TOP 0xfe000000 |
| 283 | #endif |
| 284 | extern int kernel_debugging; |
| 285 | #define FRAME_CHAIN_VALID(chain, thisframe) \ |
| 286 | (chain != 0 && \ |
| 287 | !kernel_debugging ? outside_startup_file(FRAME_SAVED_PC(thisframe)) :\ |
| 288 | (chain >= read_register(SP_REGNUM) && chain < KERNSTACK_TOP)) |
| 289 | #else |
| 290 | #define FRAME_CHAIN_VALID(chain, thisframe) \ |
| 291 | (chain != 0 && (outside_startup_file (FRAME_SAVED_PC (thisframe)))) |
| 292 | #endif |
| 293 | |
| 294 | #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain) |
| 295 | |
| 296 | /* Define other aspects of the stack frame. */ |
| 297 | |
| 298 | /* A macro that tells us whether the function invocation represented |
| 299 | by FI does not have a frame on the stack associated with it. If it |
| 300 | does not, FRAMELESS is set to 1, else 0. */ |
| 301 | #define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \ |
| 302 | FRAMELESS_LOOK_FOR_PROLOGUE(FI, FRAMELESS) |
| 303 | |
| 304 | #define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4)) |
| 305 | |
| 306 | #define FRAME_ARGS_ADDRESS(fi) ((fi)->frame) |
| 307 | |
| 308 | #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame) |
| 309 | |
| 310 | /* Return number of args passed to a frame. |
| 311 | Can return -1, meaning no way to tell. */ |
| 312 | |
| 313 | #define FRAME_NUM_ARGS(numargs, fi) (numargs) = i386_frame_num_args(fi) |
| 314 | |
| 315 | /* Return number of bytes at start of arglist that are not really args. */ |
| 316 | |
| 317 | #define FRAME_ARGS_SKIP 8 |
| 318 | |
| 319 | /* Put here the code to store, into a struct frame_saved_regs, |
| 320 | the addresses of the saved registers of frame described by FRAME_INFO. |
| 321 | This includes special registers such as pc and fp saved in special |
| 322 | ways in the stack frame. sp is even more special: |
| 323 | the address we return for it IS the sp for the next frame. */ |
| 324 | |
| 325 | #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \ |
| 326 | { i386_frame_find_saved_regs ((frame_info), &(frame_saved_regs)); } |
| 327 | |
| 328 | \f |
| 329 | /* Discard from the stack the innermost frame, restoring all registers. */ |
| 330 | |
| 331 | #define POP_FRAME { i386_pop_frame (); } |
| 332 | |
| 333 | #define NEW_CALL_FUNCTION |
| 334 | \f |
| 335 | #if 0 |
| 336 | /* Interface definitions for kernel debugger KDB. */ |
| 337 | |
| 338 | /* Map machine fault codes into signal numbers. |
| 339 | First subtract 0, divide by 4, then index in a table. |
| 340 | Faults for which the entry in this table is 0 |
| 341 | are not handled by KDB; the program's own trap handler |
| 342 | gets to handle then. */ |
| 343 | |
| 344 | #define FAULT_CODE_ORIGIN 0 |
| 345 | #define FAULT_CODE_UNITS 4 |
| 346 | #define FAULT_TABLE \ |
| 347 | { 0, 0, 0, 0, 0, 0, 0, 0, \ |
| 348 | 0, 0, 0, 0, 0, 0, 0, 0, \ |
| 349 | 0, 0, 0, 0, 0, 0, 0, 0} |
| 350 | |
| 351 | /* Start running with a stack stretching from BEG to END. |
| 352 | BEG and END should be symbols meaningful to the assembler. |
| 353 | This is used only for kdb. */ |
| 354 | |
| 355 | #define INIT_STACK(beg, end) {} |
| 356 | |
| 357 | /* Push the frame pointer register on the stack. */ |
| 358 | #define PUSH_FRAME_PTR {} |
| 359 | |
| 360 | /* Copy the top-of-stack to the frame pointer register. */ |
| 361 | #define POP_FRAME_PTR {} |
| 362 | |
| 363 | /* After KDB is entered by a fault, push all registers |
| 364 | that GDB thinks about (all NUM_REGS of them), |
| 365 | so that they appear in order of ascending GDB register number. |
| 366 | The fault code will be on the stack beyond the last register. */ |
| 367 | |
| 368 | #define PUSH_REGISTERS {} |
| 369 | |
| 370 | /* Assuming the registers (including processor status) have been |
| 371 | pushed on the stack in order of ascending GDB register number, |
| 372 | restore them and return to the address in the saved PC register. */ |
| 373 | |
| 374 | #define POP_REGISTERS {} |
| 375 | #endif |