|
|
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 sun2
22: #define sun2
23: #endif
24:
25: /* Define this if the C compiler puts an underscore at the front
26: of external names before giving them to the linker. */
27:
28: #define NAMES_HAVE_UNDERSCORE
29:
30: /* Debugger information will be in DBX format. */
31:
32: #define READ_DBX_FORMAT
33:
34: /* Offset from address of function to start of its code.
35: Zero on most machines. */
36:
37: #define FUNCTION_START_OFFSET 0
38:
39: /* Advance PC across any function entry prologue instructions
40: to reach some "real" code. */
41:
42: #define SKIP_PROLOGUE(pc) \
43: { register int op = read_memory_integer (pc, 2); \
44: if (op == 0047126) \
45: pc += 4; /* Skip link #word */ \
46: else if (op == 0044016) \
47: pc += 6; /* Skip link #long */ \
48: }
49:
50: /* Immediately after a function call, return the saved pc.
51: Can't go through the frames for this because on some machines
52: the new frame is not set up until the new function executes
53: some instructions. */
54:
55: #define SAVED_PC_AFTER_CALL(frame) \
56: read_memory_integer (read_register (SP_REGNUM), 4)
57:
58: /* This is the amount to subtract from u.u_ar0
59: to get the offset in the core file of the register values. */
60:
61: #define KERNEL_U_ADDR 0x2800
62:
63: /* Address of end of stack space. */
64:
65: #define STACK_END_ADDR 0x1000000
66:
67: /* Stack grows downward. */
68:
69: #define INNER_THAN <
70:
71: /* Sequence of bytes for breakpoint instruction. */
72:
73: #define BREAKPOINT {0x4e, 0x4f}
74:
75: /* Amount PC must be decremented by after a breakpoint.
76: This is often the number of bytes in BREAKPOINT
77: but not always. */
78:
79: #define DECR_PC_AFTER_BREAK 2
80:
81: /* Nonzero if instruction at PC is a return instruction. */
82:
83: #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 2) == 0x4e75)
84:
85: /* Return 1 if P points to an invalid floating point value. */
86:
87: #define INVALID_FLOAT(p, len) 0 /* Just a first guess; not checked */
88:
89: /* Say how long registers are. */
90:
91: #define REGISTER_TYPE long
92:
93: /* Number of machine registers */
94:
95: #define NUM_REGS 18
96:
97: /* Number that are really general registers */
98:
99: #define NUM_GENERAL_REGS 16
100:
101: /* Initializer for an array of names of registers.
102: There should be NUM_REGS strings in this initializer. */
103:
104: #define REGISTER_NAMES {"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", "ps", "pc"}
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:
118: /* Total amount of space needed to store our copies of the machine's
119: register state, the array `registers'. */
120: #define REGISTER_BYTES (16*4+8)
121:
122: /* Index within `registers' of the first byte of the space for
123: register N. */
124:
125: #define REGISTER_BYTE(N) ((N) * 4)
126:
127: /* Number of bytes of storage in the actual machine representation
128: for register N. On the 68000, all regs are 4 bytes. */
129:
130: #define REGISTER_RAW_SIZE(N) 4
131:
132: /* Number of bytes of storage in the program's representation
133: for register N. On the 68000, all regs are 4 bytes. */
134:
135: #define REGISTER_VIRTUAL_SIZE(N) 4
136:
137: /* Largest value REGISTER_RAW_SIZE can have. */
138:
139: #define MAX_REGISTER_RAW_SIZE 4
140:
141: /* Largest value REGISTER_VIRTUAL_SIZE can have. */
142:
143: #define MAX_REGISTER_VIRTUAL_SIZE 4
144:
145: /* Nonzero if register N requires conversion
146: from raw format to virtual format. */
147:
148: #define REGISTER_CONVERTIBLE(N) 0
149:
150: /* Convert data from raw format for register REGNUM
151: to virtual format for register REGNUM. */
152:
153: #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) bcopy ((FROM), (TO), 4);
154:
155: /* Convert data from virtual format for register REGNUM
156: to raw format for register REGNUM. */
157:
158: #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) bcopy ((FROM), (TO), 4);
159:
160: /* Return the GDB type object for the "standard" data type
161: of data in register N. */
162:
163: #define REGISTER_VIRTUAL_TYPE(N) builtin_type_int
164:
165: /* Extract from an array REGBUF containing the (raw) register state
166: a function return value of type TYPE, and copy that, in virtual format,
167: into VALBUF. */
168:
169: #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
170: bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE))
171:
172: /* Write into appropriate registers a function return value
173: of type TYPE, given in virtual format. */
174:
175: #define STORE_RETURN_VALUE(TYPE,VALBUF) \
176: write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
177:
178: /* Extract from an array REGBUF containing the (raw) register state
179: the address in which a function should return its structure value,
180: as a CORE_ADDR (or an expression that can be used as one). */
181:
182: #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
183:
184: /* This is a piece of magic that is given a register number REGNO
185: and as BLOCKEND the address in the system of the end of the user structure
186: and stores in ADDR the address in the kernel or core dump
187: of that register. */
188:
189: #define REGISTER_U_ADDR(addr, blockend, regno) \
190: { addr = blockend + regno * 4; }
191:
192: /* Describe the pointer in each stack frame to the previous stack frame
193: (its caller). */
194:
195: /* FRAME_CHAIN takes a frame's nominal address
196: and produces the frame's chain-pointer.
197:
198: FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
199: and produces the nominal address of the caller frame.
200:
201: However, if FRAME_CHAIN_VALID returns zero,
202: it means the given frame is the outermost one and has no caller.
203: In that case, FRAME_CHAIN_COMBINE is not used. */
204:
205: /* In the case of the Sun, the frame's nominal address
206: is the address of a 4-byte word containing the calling frame's address. */
207:
208: #define FRAME_CHAIN(thisframe) (read_memory_integer (thisframe, 4))
209:
210: #define FRAME_CHAIN_VALID(chain, thisframe) \
211: (chain != 0 && (FRAME_SAVED_PC (thisframe) >= first_object_file_end))
212:
213: #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
214:
215: /* Define other aspects of the stack frame. */
216:
217: #define FRAME_SAVED_PC(frame) (read_memory_integer (frame + 4, 4))
218:
219: #define FRAME_ARGS_ADDRESS(fi) (fi.frame)
220:
221: #define FRAME_LOCALS_ADDRESS(fi) (fi.frame)
222:
223: /* Set VAL to the number of args passed to frame described by FI.
224: Can set VAL to -1, meaning no way to tell. */
225:
226: /* We can't tell how many args there are
227: now that the C compiler delays popping them. */
228: #define FRAME_NUM_ARGS(val,fi) (val = -1)
229:
230: #if 0
231: #define FRAME_NUM_ARGS(val, fi) \
232: { register CORE_ADDR pc = FRAME_SAVED_PC (fi.frame); \
233: register int insn = 0177777 & read_memory_integer (pc, 2); \
234: val = 0; \
235: if (insn == 0047757 || insn == 0157374) /* lea W(sp),sp or addaw #W,sp */ \
236: val = read_memory_integer (pc + 2, 2); \
237: else if ((insn & 0170777) == 0050217 /* addql #N, sp */ \
238: || (insn & 0170777) == 0050117) /* addqw */ \
239: { val = (insn >> 9) & 7; if (val == 0) val = 8; } \
240: else if (insn == 0157774) /* addal #WW, sp */ \
241: val = read_memory_integer (pc + 2, 4); \
242: val >>= 2; }
243: #endif
244:
245: /* Return number of bytes at start of arglist that are not really args. */
246:
247: #define FRAME_ARGS_SKIP 8
248:
249: /* Put here the code to store, into a struct frame_saved_regs,
250: the addresses of the saved registers of frame described by FRAME_INFO.
251: This includes special registers such as pc and fp saved in special
252: ways in the stack frame. sp is even more special:
253: the address we return for it IS the sp for the next frame. */
254:
255: #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \
256: { register int regnum; \
257: register int regmask; \
258: register CORE_ADDR next_addr; \
259: register CORE_ADDR pc; \
260: bzero (&frame_saved_regs, sizeof frame_saved_regs); \
261: if ((frame_info).pc >= (frame_info).frame - CALL_DUMMY_LENGTH - FP_REGNUM*4 - 4 \
262: && (frame_info).pc <= (frame_info).frame) \
263: { next_addr = (frame_info).frame; \
264: pc = (frame_info).frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 4; }\
265: else \
266: { pc = get_pc_function_start ((frame_info).pc); \
267: /* Verify we have a link a6 instruction next; \
268: if not we lose. If we win, find the address above the saved \
269: regs using the amount of storage from the link instruction. */\
270: if (044016 == read_memory_integer (pc, 2)) \
271: next_addr = (frame_info).frame + read_memory_integer (pc += 2, 4), pc+=4; \
272: else if (047126 == read_memory_integer (pc, 2)) \
273: next_addr = (frame_info).frame + read_memory_integer (pc += 2, 2), pc+=2; \
274: else goto lose; \
275: /* If have an addal #-n, sp next, adjust next_addr. */ \
276: if ((0177777 & read_memory_integer (pc, 2)) == 0157774) \
277: next_addr += read_memory_integer (pc += 2, 4), pc += 4; \
278: } \
279: /* next should be a moveml to (sp) or -(sp) or a movl r,-(sp) */ \
280: regmask = read_memory_integer (pc + 2, 2); \
281: if (0044327 == read_memory_integer (pc, 2)) \
282: { pc += 4; /* Regmask's low bit is for register 0, the first written */ \
283: for (regnum = 0; regnum < 16; regnum++, regmask >>= 1) \
284: if (regmask & 1) \
285: (frame_saved_regs).regs[regnum] = (next_addr += 4) - 4; } \
286: else if (0044347 == read_memory_integer (pc, 2)) \
287: { pc += 4; /* Regmask's low bit is for register 15, the first pushed */ \
288: for (regnum = 15; regnum >= 0; regnum--, regmask >>= 1) \
289: if (regmask & 1) \
290: (frame_saved_regs).regs[regnum] = (next_addr -= 4); } \
291: else if (0x2f00 == 0xfff0 & read_memory_integer (pc, 2)) \
292: { regnum = 0xf & read_memory_integer (pc, 2); pc += 2; \
293: (frame_saved_regs).regs[regnum] = (next_addr -= 4); } \
294: /* clrw -(sp); movw ccr,-(sp) may follow. */ \
295: if (0x426742e7 == read_memory_integer (pc, 4)) \
296: (frame_saved_regs).regs[PS_REGNUM] = (next_addr -= 4); \
297: lose: ; \
298: (frame_saved_regs).regs[SP_REGNUM] = (frame_info).frame + 8; \
299: (frame_saved_regs).regs[FP_REGNUM] = (frame_info).frame; \
300: (frame_saved_regs).regs[PC_REGNUM] = (frame_info).frame + 4; \
301: }
302:
303: /* Things needed for making the inferior call functions. */
304:
305: /* Push an empty stack frame, to record the current PC, etc. */
306:
307: #define PUSH_DUMMY_FRAME \
308: { register CORE_ADDR sp = read_register (SP_REGNUM);\
309: register int regnum; \
310: sp = push_word (sp, read_register (PC_REGNUM)); \
311: sp = push_word (sp, read_register (FP_REGNUM)); \
312: write_register (FP_REGNUM, sp); \
313: for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--) \
314: sp = push_word (sp, read_register (regnum)); \
315: sp = push_word (sp, read_register (PS_REGNUM)); \
316: write_register (SP_REGNUM, sp); }
317:
318: /* Discard from the stack the innermost frame, restoring all registers. */
319:
320: #define POP_FRAME \
321: { register CORE_ADDR fp = read_register (FP_REGNUM); \
322: register int regnum; \
323: struct frame_saved_regs fsr; \
324: struct frame_info fi; \
325: fi = get_frame_info (fp); \
326: get_frame_saved_regs (&fi, &fsr); \
327: for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--) \
328: if (fsr.regs[regnum]) \
329: write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \
330: if (fsr.regs[PS_REGNUM]) \
331: write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4)); \
332: write_register (FP_REGNUM, read_memory_integer (fp, 4)); \
333: write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); \
334: write_register (SP_REGNUM, fp + 8); \
335: }
336:
337: /* This sequence of words is the instructions
338: moveml 0xfffc,-(sp)
339: clrw -(sp)
340: movew ccr,-(sp)
341: /..* The arguments are pushed at this point by GDB;
342: no code is needed in the dummy for this.
343: The CALL_DUMMY_START_OFFSET gives the position of
344: the following jsr instruction. *../
345: jsr @#32323232
346: addl #69696969,sp
347: bpt
348: nop
349: Note this is 24 bytes.
350: We actually start executing at the jsr, since the pushing of the
351: registers is done by PUSH_DUMMY_FRAME. If this were real code,
352: the arguments for the function called by the jsr would be pushed
353: between the moveml and the jsr, and we could allow it to execute through.
354: But the arguments have to be pushed by GDB after the PUSH_DUMMY_FRAME is done,
355: and we cannot allow the moveml to push the registers again lest they be
356: taken for the arguments. */
357:
358: #define CALL_DUMMY {0x48e7fffc, 0x426742e7, 0x4eb93232, 0x3232dffc, 0x69696969, 0x4e4f4e71}
359:
360: #define CALL_DUMMY_LENGTH 24
361:
362: #define CALL_DUMMY_START_OFFSET 8
363:
364: /* Insert the specified number of args and function address
365: into a call sequence of the above form stored at DUMMYNAME. */
366:
367: #define FIX_CALL_DUMMY(dummyname, fun, nargs) \
368: { *(int *)((char *) dummyname + 16) = nargs * 4; \
369: *(int *)((char *) dummyname + 10) = fun; }
370:
371: /* Interface definitions for kernel debugger KDB. */
372:
373: /* Map machine fault codes into signal numbers.
374: First subtract 0, divide by 4, then index in a table.
375: Faults for which the entry in this table is 0
376: are not handled by KDB; the program's own trap handler
377: gets to handle then. */
378:
379: #define FAULT_CODE_ORIGIN 0
380: #define FAULT_CODE_UNITS 4
381: #define FAULT_TABLE \
382: { 0, 0, 0, 0, SIGTRAP, 0, 0, 0, \
383: 0, SIGTRAP, 0, 0, 0, 0, 0, SIGKILL, \
384: 0, 0, 0, 0, 0, 0, 0, 0, \
385: SIGILL }
386:
387: /* Start running with a stack stretching from BEG to END.
388: BEG and END should be symbols meaningful to the assembler.
389: This is used only for kdb. */
390:
391: #define INIT_STACK(beg, end) \
392: { asm (".globl end"); \
393: asm ("movel $ end, sp"); \
394: asm ("clrl fp"); }
395:
396: /* Push the frame pointer register on the stack. */
397: #define PUSH_FRAME_PTR \
398: asm ("movel fp, -(sp)");
399:
400: /* Copy the top-of-stack to the frame pointer register. */
401: #define POP_FRAME_PTR \
402: asm ("movl (sp), fp");
403:
404: /* After KDB is entered by a fault, push all registers
405: that GDB thinks about (all NUM_REGS of them),
406: so that they appear in order of ascending GDB register number.
407: The fault code will be on the stack beyond the last register. */
408:
409: #define PUSH_REGISTERS \
410: { asm ("clrw -(sp)"); \
411: asm ("pea 10(sp)"); \
412: asm ("movem $ 0xfffe,-(sp)"); }
413:
414: /* Assuming the registers (including processor status) have been
415: pushed on the stack in order of ascending GDB register number,
416: restore them and return to the address in the saved PC register. */
417:
418: #define POP_REGISTERS \
419: { asm ("subil $8,28(sp)"); \
420: asm ("movem (sp),$ 0xffff"); \
421: asm ("rte"); }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.