Commit | Line | Data |
---|---|---|
fcad29ce KH |
1 | /* Target machine description for VxWorks on the 29k, for GDB, the GNU debugger. |
2 | Copyright 1994 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Support. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
6c9638b4 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
fcad29ce KH |
20 | |
21 | #include "a29k/tm-a29k.h" | |
22 | ||
23 | #define GDBINIT_FILENAME ".vxgdbinit" | |
24 | ||
25 | #define DEFAULT_PROMPT "(vxgdb) " | |
26 | ||
27 | /* Number of registers in a ptrace_getregs call. */ | |
28 | ||
29 | #define VX_NUM_REGS (NUM_REGS) | |
30 | ||
31 | /* Number of registers in a ptrace_getfpregs call. */ | |
32 | ||
33 | /* #define VX_SIZE_FPREGS */ | |
34 | ||
35 | /* This is almost certainly the wrong place for this: */ | |
36 | #define LR2_REGNUM 34 | |
37 | \f | |
38 | ||
39 | /* Vxworks has its own CALL_DUMMY since it manages breakpoints in the kernel */ | |
40 | ||
41 | #undef CALL_DUMMY | |
42 | ||
43 | /* Replace the breakpoint instruction in the CALL_DUMMY with a nop. | |
44 | For Vxworks, the breakpoint is set and deleted by calls to | |
45 | CALL_DUMMY_BREAK_SET and CALL_DUMMY_BREAK_DELETE. */ | |
46 | ||
47 | #if TARGET_BYTE_ORDER == HOST_BYTE_ORDER | |
48 | #define CALL_DUMMY {0x0400870f,\ | |
49 | 0x36008200|(MSP_HW_REGNUM), \ | |
50 | 0x15000040|(MSP_HW_REGNUM<<8)|(MSP_HW_REGNUM<<16), \ | |
51 | 0x03ff80ff, 0x02ff80ff, 0xc8008080, 0x70400101, 0x70400101} | |
52 | #else /* Byte order differs. */ | |
53 | #define CALL_DUMMY {0x0f870004,\ | |
54 | 0x00820036|(MSP_HW_REGNUM << 24), \ | |
55 | 0x40000015|(MSP_HW_REGNUM<<8)|(MSP_HW_REGNUM<<16), \ | |
56 | 0xff80ff03, 0xff80ff02, 0x808000c8, 0x01014070, 0x01014070} | |
57 | #endif /* Byte order differs. */ | |
58 | ||
59 | ||
60 | /* For the basic CALL_DUMMY definitions, see "tm-29k.h." We use the | |
61 | same CALL_DUMMY code, but define FIX_CALL_DUMMY (and related macros) | |
62 | locally to handle remote debugging of VxWorks targets. The difference | |
63 | is in the setting and clearing of the breakpoint at the end of the | |
64 | CALL_DUMMY code fragment; under VxWorks, we can't simply insert a | |
65 | breakpoint instruction into the code, since that would interfere with | |
66 | the breakpoint management mechanism on the target. | |
67 | Note that CALL_DUMMY is a piece of code that is used to call any C function | |
68 | thru VxGDB */ | |
69 | ||
70 | /* The offset of the instruction within the CALL_DUMMY code where we | |
71 | want the inferior to stop after the function call has completed. | |
72 | call_function_by_hand () sets a breakpoint here (via CALL_DUMMY_BREAK_SET), | |
73 | which POP_FRAME later deletes (via CALL_DUMMY_BREAK_DELETE). */ | |
74 | ||
75 | #define CALL_DUMMY_STOP_OFFSET (7 * 4) | |
76 | ||
77 | /* The offset of the first instruction of the CALL_DUMMY code fragment | |
78 | relative to the frame pointer for a dummy frame. This is equal to | |
79 | the size of the CALL_DUMMY plus the arg_slop area size (see the diagram | |
80 | in "tm-29k.h"). */ | |
81 | /* PAD : the arg_slop area size doesn't appear to me to be useful since, the | |
82 | call dummy code no longer modify the msp. See below. This must be checked. */ | |
83 | ||
84 | #define CALL_DUMMY_OFFSET_IN_FRAME (CALL_DUMMY_LENGTH + 16 * 4) | |
85 | ||
86 | /* Insert the specified number of args and function address | |
87 | into a CALL_DUMMY sequence stored at DUMMYNAME, replace the third | |
88 | instruction (add msp, msp, 16*4) with a nop, and leave the final nop. | |
89 | We can't keep using a CALL_DUMMY that modify the msp since, for VxWorks, | |
90 | CALL_DUMMY is stored in the Memory Stack. Adding 16 words to the msp | |
91 | would then make possible for the inferior to overwrite the CALL_DUMMY code, | |
92 | thus creating a lot of trouble when exiting the inferior to come back in | |
93 | a CALL_DUMMY code that no longer exists... Furthermore, ESF are also stored | |
94 | from the msp in the memory stack. If msp is set higher than the dummy code, | |
95 | an ESF may clobber this code. */ | |
96 | ||
97 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
98 | #define NOP_INSTR 0x70400101 | |
99 | #else /* Target is little endian */ | |
100 | #define NOP_INSTR 0x01014070 | |
101 | #endif | |
102 | ||
103 | #undef FIX_CALL_DUMMY | |
104 | #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ | |
105 | { \ | |
106 | *(int *)((char *)dummyname + 8) = NOP_INSTR; \ | |
107 | STUFF_I16((char *)dummyname + CONST_INSN, fun); \ | |
108 | STUFF_I16((char *)dummyname + CONST_INSN + 4, fun >> 16); \ | |
109 | } | |
110 | ||
111 | /* For VxWorks, CALL_DUMMY must be stored in the stack of the task that is | |
112 | being debugged and executed "in the context of" this task */ | |
113 | ||
114 | #undef CALL_DUMMY_LOCATION | |
115 | #define CALL_DUMMY_LOCATION ON_STACK | |
116 | ||
117 | /* Set or delete a breakpoint at the location within a CALL_DUMMY code | |
118 | fragment where we want the target program to stop after the function | |
119 | call is complete. CALL_DUMMY_ADDR is the address of the first | |
120 | instruction in the CALL_DUMMY. DUMMY_FRAME_ADDR is the value of the | |
121 | frame pointer in the dummy frame. | |
122 | ||
123 | NOTE: in the both of the following definitions, we take advantage of | |
124 | knowledge of the implementation of the target breakpoint operation, | |
125 | in that we pass a null pointer as the second argument. It seems | |
126 | reasonable to assume that any target requiring the use of | |
127 | CALL_DUMMY_BREAK_{SET,DELETE} will not store the breakpoint | |
128 | shadow contents in GDB; in any case, this assumption is vaild | |
129 | for all VxWorks-related targets. */ | |
130 | ||
131 | #define CALL_DUMMY_BREAK_SET(call_dummy_addr) \ | |
132 | target_insert_breakpoint ((call_dummy_addr) + CALL_DUMMY_STOP_OFFSET, \ | |
133 | (char *) 0) | |
134 | ||
135 | #define CALL_DUMMY_BREAK_DELETE(dummy_frame_addr) \ | |
136 | target_remove_breakpoint ((dummy_frame_addr) - (CALL_DUMMY_OFFSET_IN_FRAME \ | |
137 | - CALL_DUMMY_STOP_OFFSET), \ | |
138 | (char *) 0) | |
139 | ||
140 | /* Return nonzero if the pc is executing within a CALL_DUMMY frame. */ | |
141 | ||
142 | #define PC_IN_CALL_DUMMY(pc, sp, frame_address) \ | |
143 | ((pc) >= (sp) \ | |
144 | && (pc) <= (sp) + CALL_DUMMY_OFFSET_IN_FRAME + CALL_DUMMY_LENGTH) | |
145 | ||
146 | /* Defining this prevents us from trying to pass a structure-valued argument | |
147 | to a function called via the CALL_DUMMY mechanism. This is not handled | |
148 | properly in call_function_by_hand (), and the fix might require re-writing | |
149 | the CALL_DUMMY handling for all targets (at least, a clean solution | |
150 | would probably require this). Arguably, this should go in "tm-29k.h" | |
151 | rather than here. */ | |
152 | ||
153 | #define STRUCT_VAL_ARGS_UNSUPPORTED | |
154 | ||
155 | #define BKPT_OFFSET (7 * 4) | |
156 | #define BKPT_INSTR 0x72500101 | |
157 | ||
158 | #undef FIX_CALL_DUMMY | |
159 | #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, args, type, gcc_p) \ | |
160 | {\ | |
161 | STUFF_I16((char *)dummyname + CONST_INSN, fun);\ | |
162 | STUFF_I16((char *)dummyname + CONST_INSN + 4, fun >> 16);\ | |
163 | *(int *)((char *)dummyname + BKPT_OFFSET) = BKPT_INSTR;\ | |
164 | } | |
165 | ||
166 | \f | |
167 | /* Offsets into jmp_buf. They are derived from VxWorks' REG_SET struct | |
168 | (see VxWorks' setjmp.h). Note that Sun2, Sun3 and SunOS4 and VxWorks have | |
169 | different REG_SET structs, hence different layouts for the jmp_buf struct. | |
170 | Only JB_PC is needed for getting the saved PC value. */ | |
171 | ||
172 | #define JB_ELEMENT_SIZE 4 /* size of each element in jmp_buf */ | |
173 | #define JB_PC 3 /* offset of pc (pc1) in jmp_buf */ | |
174 | ||
175 | /* Figure out where the longjmp will land. We expect that we have just entered | |
176 | longjmp and haven't yet setup the stack frame, so the args are still in the | |
177 | output regs. lr2 (LR2_REGNUM) points at the jmp_buf structure from which we | |
178 | extract the pc (JB_PC) that we will land at. The pc is copied into ADDR. | |
179 | This routine returns true on success */ | |
180 | ||
181 | #define GET_LONGJMP_TARGET(ADDR) get_longjmp_target(ADDR) | |
182 | extern int get_longjmp_target PARAMS ((CORE_ADDR *)); | |
183 | ||
184 | /* VxWorks adjusts the PC after a breakpoint has been hit. */ | |
185 | ||
186 | #undef DECR_PC_AFTER_BREAK | |
187 | #define DECR_PC_AFTER_BREAK 0 | |
188 | ||
189 | /* Do whatever promotions are appropriate on a value being returned | |
190 | from a function. VAL is the user-supplied value, and FUNC_TYPE | |
191 | is the return type of the function if known, else 0. | |
192 | ||
193 | For the Am29k, as far as I understand, if the function return type is known, | |
194 | cast the value to that type; otherwise, ensure that integer return values | |
195 | fill all of gr96. | |
196 | ||
197 | This definition really belongs in "tm-29k.h", since it applies | |
198 | to most Am29K-based systems; but once moved into that file, it might | |
199 | need to be redefined for all Am29K-based targets that also redefine | |
200 | STORE_RETURN_VALUE. For now, to be safe, we define it here. */ | |
201 | ||
202 | #define PROMOTE_RETURN_VALUE(val, func_type) \ | |
203 | do { \ | |
204 | if (func_type) \ | |
205 | val = value_cast (func_type, val); \ | |
206 | if ((TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT \ | |
207 | || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_ENUM) \ | |
208 | && TYPE_LENGTH (VALUE_TYPE (val)) < REGISTER_RAW_SIZE (0)) \ | |
209 | val = value_cast (builtin_type_int, val); \ | |
210 | } while (0) | |
211 | ||
212 | #define SPECIAL_FRAME_CHAIN_FP get_fp_contents | |
213 | #undef FRAME_CHAIN_VALID | |
214 | #define FRAME_CHAIN_VALID(chain, thisframe) \ | |
215 | (SPECIAL_FRAME_CHAIN_FP (chain, thisframe)) | |
216 | ||
217 | extern int SPECIAL_FRAME_CHAIN_FP (); | |
218 | ||
219 | extern CORE_ADDR frame_saved_call_site (); | |
220 | ||
221 | #undef PREPARE_TO_INIT_FRAME_INFO | |
222 | #define PREPARE_TO_INIT_FRAME_INFO(fci) do { \ | |
223 | long current_msp = read_register (MSP_REGNUM); \ | |
224 | if (PC_IN_CALL_DUMMY (fci->pc, current_msp, 0)) \ | |
225 | { \ | |
226 | fci->rsize = DUMMY_FRAME_RSIZE; \ | |
227 | fci->msize = 0; \ | |
228 | fci->saved_msp = \ | |
229 | read_register_stack_integer (fci->frame + DUMMY_FRAME_RSIZE - 4, 4); \ | |
230 | fci->flags |= (TRANSPARENT|MFP_USED); \ | |
231 | return; \ | |
232 | } \ | |
233 | } while (0) |