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