|
|
1.1 root 1: /* Parameters for execution on a Sun, for GDB, the GNU debugger.
2: Copyright (C) 1986, 1987 Free Software Foundation, Inc.
3:
4: GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5: WARRANTY. No author or distributor accepts responsibility to anyone
6: for the consequences of using it or for whether it serves any
7: particular purpose or works at all, unless he says so in writing.
8: Refer to the GDB General Public License for full details.
9:
10: Everyone is granted permission to copy, modify and redistribute GDB,
11: but only under the conditions described in the GDB General Public
12: License. A copy of this license is supposed to have been given to you
13: along with GDB so you can know your rights and responsibilities. It
14: should be in a file named COPYING. Among other things, the copyright
15: notice and this notice must be preserved on all copies.
16:
17: In other words, go ahead and share GDB, but don't try to stop
18: anyone else from sharing it farther. Help stamp out software hoarding!
19: */
20:
21: #ifndef sun3
22: #define sun3
23: #endif
24:
25: /* Get rid of any system-imposed stack limit if possible. */
26:
27: #define SET_STACK_LIMIT_HUGE
28:
29: /* Define this if the C compiler puts an underscore at the front
30: of external names before giving them to the linker. */
31:
32: #define NAMES_HAVE_UNDERSCORE
33:
34: /* Debugger information will be in DBX format. */
35:
36: #define READ_DBX_FORMAT
37:
38: /* Offset from address of function to start of its code.
39: Zero on most machines. */
40:
41: #define FUNCTION_START_OFFSET 0
42:
43: /* Advance PC across any function entry prologue instructions
44: to reach some "real" code. */
45:
46: #define SKIP_PROLOGUE(pc) \
47: { register int op = read_memory_integer (pc, 2); \
48: if (op == 0047126) \
49: pc += 4; /* Skip link #word */ \
50: else if (op == 0044016) \
51: pc += 6; /* Skip link #long */ \
52: }
53:
54: /* Immediately after a function call, return the saved pc.
55: Can't go through the frames for this because on some machines
56: the new frame is not set up until the new function executes
57: some instructions. */
58:
59: #define SAVED_PC_AFTER_CALL(frame) \
60: read_memory_integer (read_register (SP_REGNUM), 4)
61:
62: /* Address of end of stack space. */
63:
64: #define STACK_END_ADDR 0xf000000
65:
66: /* Stack grows downward. */
67:
68: #define INNER_THAN <
69:
70: /* Sequence of bytes for breakpoint instruction. */
71:
72: #define BREAKPOINT {0x4e, 0x4f}
73:
74: /* Amount PC must be decremented by after a breakpoint.
75: This is often the number of bytes in BREAKPOINT
76: but not always. */
77:
78: #define DECR_PC_AFTER_BREAK 2
79:
80: /* Nonzero if instruction at PC is a return instruction. */
81:
82: #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 2) == 0x4e75)
83:
84: /* Return 1 if P points to an invalid floating point value. */
85:
86: #define INVALID_FLOAT(p, len) 0 /* Just a first guess; not checked */
87:
88: /* Say how long (ordinary) registers are. */
89:
90: #define REGISTER_TYPE long
91:
92: /* Number of machine registers */
93:
94: #define NUM_REGS 31
95:
96: /* Initializer for an array of names of registers.
97: There should be NUM_REGS strings in this initializer. */
98:
99: #define REGISTER_NAMES \
100: {"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", \
101: "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", \
102: "ps", "pc", \
103: "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7", \
104: "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags" }
105:
106: /* Register numbers of various important registers.
107: Note that some of these values are "real" register numbers,
108: and correspond to the general registers of the machine,
109: and some are "phony" register numbers which are too large
110: to be actual register numbers as far as the user is concerned
111: but do serve to get the desired values when passed to read_register. */
112:
113: #define FP_REGNUM 14 /* Contains address of executing stack frame */
114: #define SP_REGNUM 15 /* Contains address of top of stack */
115: #define PS_REGNUM 16 /* Contains processor status */
116: #define PC_REGNUM 17 /* Contains program counter */
117: #define FP0_REGNUM 18 /* Floating point register 0 */
118: #define FPC_REGNUM 26 /* 68881 control register */
119:
120: /* Total amount of space needed to store our copies of the machine's
121: register state, the array `registers'. */
122: #define REGISTER_BYTES (16*4+8*12+8+20)
123:
124: /* Index within `registers' of the first byte of the space for
125: register N. */
126:
127: #define REGISTER_BYTE(N) \
128: ((N) >= FPC_REGNUM ? (((N) - FPC_REGNUM) * 4) + 168 \
129: : (N) >= FP0_REGNUM ? (((N) - FP0_REGNUM) * 12) + 72 \
130: : (N) * 4)
131:
132: /* Number of bytes of storage in the actual machine representation
133: for register N. On the 68000, all regs are 4 bytes
134: except the floating point regs which are 12 bytes. */
135:
136: #define REGISTER_RAW_SIZE(N) (((unsigned)(N) - FP0_REGNUM) < 8 ? 12 : 4)
137:
138: /* Number of bytes of storage in the program's representation
139: for register N. On the 68000, all regs are 4 bytes
140: except the floating point regs which are 8-byte doubles. */
141:
142: #define REGISTER_VIRTUAL_SIZE(N) (((unsigned)(N) - FP0_REGNUM) < 8 ? 8 : 4)
143:
144: /* Largest value REGISTER_RAW_SIZE can have. */
145:
146: #define MAX_REGISTER_RAW_SIZE 12
147:
148: /* Largest value REGISTER_VIRTUAL_SIZE can have. */
149:
150: #define MAX_REGISTER_VIRTUAL_SIZE 8
151:
152: /* Nonzero if register N requires conversion
153: from raw format to virtual format. */
154:
155: #define REGISTER_CONVERTIBLE(N) (((unsigned)(N) - FP0_REGNUM) < 8)
156:
157: /* Convert data from raw format for register REGNUM
158: to virtual format for register REGNUM. */
159:
160: #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) \
161: { if ((REGNUM) >= FP0_REGNUM && (REGNUM) < FPC_REGNUM) \
162: convert_from_68881 ((FROM), (TO)); \
163: else \
164: bcopy ((FROM), (TO), 4); }
165:
166: /* Convert data from virtual format for register REGNUM
167: to raw format for register REGNUM. */
168:
169: #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) \
170: { if ((REGNUM) >= FP0_REGNUM && (REGNUM) < FPC_REGNUM) \
171: convert_to_68881 ((FROM), (TO)); \
172: else \
173: bcopy ((FROM), (TO), 4); }
174:
175: /* Return the GDB type object for the "standard" data type
176: of data in register N. */
177:
178: #define REGISTER_VIRTUAL_TYPE(N) \
179: (((unsigned)(N) - FP0_REGNUM) < 8 ? builtin_type_double : builtin_type_int)
180:
181: /* Extract from an array REGBUF containing the (raw) register state
182: a function return value of type TYPE, and copy that, in virtual format,
183: into VALBUF. */
184:
185: #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
186: bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE))
187:
188: /* Write into appropriate registers a function return value
189: of type TYPE, given in virtual format. */
190:
191: #define STORE_RETURN_VALUE(TYPE,VALBUF) \
192: write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
193:
194: /* Extract from an array REGBUF containing the (raw) register state
195: the address in which a function should return its structure value,
196: as a CORE_ADDR (or an expression that can be used as one). */
197:
198: #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
199:
200: /* Enable use of alternate code to read and write registers. */
201:
202: #define NEW_SUN_PTRACE
203:
204: /* Enable use of alternate code for Sun's format of core dump file. */
205:
206: #define NEW_SUN_CORE
207:
208: /* Do implement the attach and detach commands. */
209:
210: #define ATTACH_DETACH
211:
212: /* It is safe to look for symsegs on a Sun, because Sun's ld
213: does not screw up with random garbage at end of file. */
214:
215: #define READ_GDB_SYMSEGS
216:
217: /* Describe the pointer in each stack frame to the previous stack frame
218: (its caller). */
219:
220: /* FRAME_CHAIN takes a frame's nominal address
221: and produces the frame's chain-pointer.
222:
223: FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
224: and produces the nominal address of the caller frame.
225:
226: However, if FRAME_CHAIN_VALID returns zero,
227: it means the given frame is the outermost one and has no caller.
228: In that case, FRAME_CHAIN_COMBINE is not used. */
229:
230: /* In the case of the Sun, the frame's nominal address
231: is the address of a 4-byte word containing the calling frame's address. */
232:
233: #define FRAME_CHAIN(thisframe) (read_memory_integer (thisframe, 4))
234:
235: #define FRAME_CHAIN_VALID(chain, thisframe) \
236: (chain != 0 && (FRAME_SAVED_PC (thisframe) >= first_object_file_end))
237:
238: #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
239:
240: /* Define other aspects of the stack frame. */
241:
242: #define FRAME_SAVED_PC(frame) (read_memory_integer (frame + 4, 4))
243:
244: #define FRAME_ARGS_ADDRESS(fi) (fi.frame)
245:
246: #define FRAME_LOCALS_ADDRESS(fi) (fi.frame)
247:
248: /* Set VAL to the number of args passed to frame described by FI.
249: Can set VAL to -1, meaning no way to tell. */
250:
251: /* We can't tell how many args there are
252: now that the C compiler delays popping them. */
253: #define FRAME_NUM_ARGS(val,fi) (val = -1)
254:
255: #if 0
256: #define FRAME_NUM_ARGS(val, fi) \
257: { register CORE_ADDR pc = FRAME_SAVED_PC (fi.frame); \
258: register int insn = 0177777 & read_memory_integer (pc, 2); \
259: val = 0; \
260: if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */ \
261: val = read_memory_integer (pc + 2, 2); \
262: else if ((insn & 0170777) == 0050217 /* addql #N, sp */ \
263: || (insn & 0170777) == 0050117) /* addqw */ \
264: { val = (insn >> 9) & 7; if (val == 0) val = 8; } \
265: else if (insn == 0157774) /* addal #WW, sp */ \
266: val = read_memory_integer (pc + 2, 4); \
267: val >>= 2; }
268: #endif
269:
270: /* Return number of bytes at start of arglist that are not really args. */
271:
272: #define FRAME_ARGS_SKIP 8
273:
274: /* Put here the code to store, into a struct frame_saved_regs,
275: the addresses of the saved registers of frame described by FRAME_INFO.
276: This includes special registers such as pc and fp saved in special
277: ways in the stack frame. sp is even more special:
278: the address we return for it IS the sp for the next frame. */
279:
280: #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
281: { register int regnum; \
282: register int regmask; \
283: register CORE_ADDR next_addr; \
284: register CORE_ADDR pc; \
285: int nextinsn; \
286: bzero (&frame_saved_regs, sizeof frame_saved_regs); \
287: if ((frame_info).pc >= (frame_info).frame - CALL_DUMMY_LENGTH - FP_REGNUM*4 - 8*12 - 4 \
288: && (frame_info).pc <= (frame_info).frame) \
289: { next_addr = (frame_info).frame; \
290: pc = (frame_info).frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 8*12 - 4; }\
291: else \
292: { pc = get_pc_function_start ((frame_info).pc); \
293: /* Verify we have a link a6 instruction next; \
294: if not we lose. If we win, find the address above the saved \
295: regs using the amount of storage from the link instruction. */\
296: if (044016 == read_memory_integer (pc, 2)) \
297: next_addr = (frame_info).frame + read_memory_integer (pc += 2, 4), pc+=4; \
298: else if (047126 == read_memory_integer (pc, 2)) \
299: next_addr = (frame_info).frame + read_memory_integer (pc += 2, 2), pc+=2; \
300: else goto lose; \
301: /* If have an addal #-n, sp next, adjust next_addr. */ \
302: if ((0177777 & read_memory_integer (pc, 2)) == 0157774) \
303: next_addr += read_memory_integer (pc += 2, 4), pc += 4; \
304: } \
305: /* next should be a moveml to (sp) or -(sp) or a movl r,-(sp) */ \
306: regmask = read_memory_integer (pc + 2, 2); \
307: /* But before that can come an fmovem. Check for it. */ \
308: nextinsn = 0xffff & read_memory_integer (pc, 2); \
309: if (0xf227 == nextinsn \
310: && (regmask & 0xff00) == 0xe000) \
311: { pc += 4; /* Regmask's low bit is for register fp7, the first pushed */ \
312: for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--, regmask >>= 1) \
313: if (regmask & 1) \
314: (frame_saved_regs).regs[regnum] = (next_addr -= 12); \
315: regmask = read_memory_integer (pc + 2, 2); } \
316: if (0044327 == read_memory_integer (pc, 2)) \
317: { pc += 4; /* Regmask's low bit is for register 0, the first written */ \
318: for (regnum = 0; regnum < 16; regnum++, regmask >>= 1) \
319: if (regmask & 1) \
320: (frame_saved_regs).regs[regnum] = (next_addr += 4) - 4; } \
321: else if (0044347 == read_memory_integer (pc, 2)) \
322: { pc += 4; /* Regmask's low bit is for register 15, the first pushed */ \
323: for (regnum = 15; regnum >= 0; regnum--, regmask >>= 1) \
324: if (regmask & 1) \
325: (frame_saved_regs).regs[regnum] = (next_addr -= 4); } \
326: else if (0x2f00 == 0xfff0 & read_memory_integer (pc, 2)) \
327: { regnum = 0xf & read_memory_integer (pc, 2); pc += 2; \
328: (frame_saved_regs).regs[regnum] = (next_addr -= 4); } \
329: /* fmovemx to index of sp may follow. */ \
330: regmask = read_memory_integer (pc + 2, 2); \
331: nextinsn = 0xffff & read_memory_integer (pc, 2); \
332: if (0xf236 == nextinsn \
333: && (regmask & 0xff00) == 0xf000) \
334: { pc += 10; /* Regmask's low bit is for register fp0, the first written */ \
335: for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--, regmask >>= 1) \
336: if (regmask & 1) \
337: (frame_saved_regs).regs[regnum] = (next_addr += 12) - 12; \
338: regmask = read_memory_integer (pc + 2, 2); } \
339: /* clrw -(sp); movw ccr,-(sp) may follow. */ \
340: if (0x426742e7 == read_memory_integer (pc, 4)) \
341: (frame_saved_regs).regs[PS_REGNUM] = (next_addr -= 4); \
342: lose: ; \
343: (frame_saved_regs).regs[SP_REGNUM] = (frame_info).frame + 8; \
344: (frame_saved_regs).regs[FP_REGNUM] = (frame_info).frame; \
345: (frame_saved_regs).regs[PC_REGNUM] = (frame_info).frame + 4; \
346: }
347:
348: /* Things needed for making the inferior call functions. */
349:
350: /* Push an empty stack frame, to record the current PC, etc. */
351:
352: #define PUSH_DUMMY_FRAME \
353: { register CORE_ADDR sp = read_register (SP_REGNUM); \
354: register int regnum; \
355: char raw_buffer[12]; \
356: sp = push_word (sp, read_register (PC_REGNUM)); \
357: sp = push_word (sp, read_register (FP_REGNUM)); \
358: write_register (FP_REGNUM, sp); \
359: for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--) \
360: { read_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12); \
361: sp = push_bytes (sp, raw_buffer, 12); } \
362: for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--) \
363: sp = push_word (sp, read_register (regnum)); \
364: sp = push_word (sp, read_register (PS_REGNUM)); \
365: write_register (SP_REGNUM, sp); }
366:
367: /* Discard from the stack the innermost frame,
368: restoring all saved registers. */
369:
370: #define POP_FRAME \
371: { register CORE_ADDR fp = read_register (FP_REGNUM); \
372: register int regnum; \
373: struct frame_saved_regs fsr; \
374: struct frame_info fi; \
375: char raw_buffer[12]; \
376: fi = get_frame_info (fp); \
377: get_frame_saved_regs (&fi, &fsr); \
378: for (regnum = FP0_REGNUM + 7; regnum >= FP0_REGNUM; regnum--) \
379: if (fsr.regs[regnum]) \
380: { read_memory (fsr.regs[regnum], raw_buffer, 12); \
381: write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 12); }\
382: for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--) \
383: if (fsr.regs[regnum]) \
384: write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \
385: if (fsr.regs[PS_REGNUM]) \
386: write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4)); \
387: write_register (FP_REGNUM, read_memory_integer (fp, 4)); \
388: write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); \
389: write_register (SP_REGNUM, fp + 8); \
390: set_current_frame (read_register (FP_REGNUM)); }
391:
392: /* This sequence of words is the instructions
393: fmovem 0xff,-(sp)
394: moveml 0xfffc,-(sp)
395: clrw -(sp)
396: movew ccr,-(sp)
397: /..* The arguments are pushed at this point by GDB;
398: no code is needed in the dummy for this.
399: The CALL_DUMMY_START_OFFSET gives the position of
400: the following jsr instruction. *../
401: jsr @#32323232
402: addl #69696969,sp
403: trap #15
404: nop
405: Note this is 28 bytes.
406: We actually start executing at the jsr, since the pushing of the
407: registers is done by PUSH_DUMMY_FRAME. If this were real code,
408: the arguments for the function called by the jsr would be pushed
409: between the moveml and the jsr, and we could allow it to execute through.
410: But the arguments have to be pushed by GDB after the PUSH_DUMMY_FRAME is done,
411: and we cannot allow the moveml to push the registers again lest they be
412: taken for the arguments. */
413:
414: #define CALL_DUMMY {0xf227e0ff, 0x48e7fffc, 0x426742e7, 0x4eb93232, 0x3232dffc, 0x69696969, 0x4e4f4e71}
415:
416: #define CALL_DUMMY_LENGTH 28
417:
418: #define CALL_DUMMY_START_OFFSET 12
419:
420: /* Insert the specified number of args and function address
421: into a call sequence of the above form stored at DUMMYNAME. */
422:
423: #define FIX_CALL_DUMMY(dummyname, fun, nargs) \
424: { *(int *)((char *) dummyname + 20) = nargs * 4; \
425: *(int *)((char *) dummyname + 14) = fun; }
426:
427: /* Interface definitions for kernel debugger KDB. */
428:
429: /* Map machine fault codes into signal numbers.
430: First subtract 0, divide by 4, then index in a table.
431: Faults for which the entry in this table is 0
432: are not handled by KDB; the program's own trap handler
433: gets to handle then. */
434:
435: #define FAULT_CODE_ORIGIN 0
436: #define FAULT_CODE_UNITS 4
437: #define FAULT_TABLE \
438: { 0, 0, 0, 0, SIGTRAP, 0, 0, 0, \
439: 0, SIGTRAP, 0, 0, 0, 0, 0, SIGKILL, \
440: 0, 0, 0, 0, 0, 0, 0, 0, \
441: SIGILL }
442:
443: /* Start running with a stack stretching from BEG to END.
444: BEG and END should be symbols meaningful to the assembler.
445: This is used only for kdb. */
446:
447: #define INIT_STACK(beg, end) \
448: { asm (".globl end"); \
449: asm ("movel #end, sp"); \
450: asm ("movel #0,a6"); }
451:
452: /* Push the frame pointer register on the stack. */
453: #define PUSH_FRAME_PTR \
454: asm ("movel a6,sp@-");
455:
456: /* Copy the top-of-stack to the frame pointer register. */
457: #define POP_FRAME_PTR \
458: asm ("movl sp@,a6");
459:
460: /* After KDB is entered by a fault, push all registers
461: that GDB thinks about (all NUM_REGS of them),
462: so that they appear in order of ascending GDB register number.
463: The fault code will be on the stack beyond the last register. */
464:
465: #define PUSH_REGISTERS \
466: { asm ("clrw -(sp)"); \
467: asm ("pea sp@(10)"); \
468: asm ("movem #0xfffe,sp@-"); }
469:
470: /* Assuming the registers (including processor status) have been
471: pushed on the stack in order of ascending GDB register number,
472: restore them and return to the address in the saved PC register. */
473:
474: #define POP_REGISTERS \
475: { asm ("subil #8,sp@(28)"); \
476: asm ("movem sp@,#0xffff"); \
477: asm ("rte"); }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.