Fix copyright comments and file comments.
[deliverable/binutils-gdb.git] / gdb / arm-linux-tdep.c
1 /* GNU/Linux on ARM target support.
2 Copyright 1999, 2000 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22 #include "target.h"
23 #include "value.h"
24 #include "gdbtypes.h"
25 #include "floatformat.h"
26
27 #ifdef GET_LONGJMP_TARGET
28
29 /* Figure out where the longjmp will land. We expect that we have
30 just entered longjmp and haven't yet altered r0, r1, so the
31 arguments are still in the registers. (A1_REGNUM) points at the
32 jmp_buf structure from which we extract the pc (JB_PC) that we will
33 land at. The pc is copied into ADDR. This routine returns true on
34 success. */
35
36 #define LONGJMP_TARGET_SIZE sizeof(int)
37 #define JB_ELEMENT_SIZE sizeof(int)
38 #define JB_SL 18
39 #define JB_FP 19
40 #define JB_SP 20
41 #define JB_PC 21
42
43 int
44 arm_get_longjmp_target (CORE_ADDR * pc)
45 {
46 CORE_ADDR jb_addr;
47 char buf[LONGJMP_TARGET_SIZE];
48
49 jb_addr = read_register (A1_REGNUM);
50
51 if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
52 LONGJMP_TARGET_SIZE))
53 return 0;
54
55 *pc = extract_address (buf, LONGJMP_TARGET_SIZE);
56 return 1;
57 }
58
59 #endif /* GET_LONGJMP_TARGET */
60
61 /* Extract from an array REGBUF containing the (raw) register state
62 a function return value of type TYPE, and copy that, in virtual format,
63 into VALBUF. */
64
65 void
66 arm_linux_extract_return_value (struct type *type,
67 char regbuf[REGISTER_BYTES],
68 char *valbuf)
69 {
70 /* ScottB: This needs to be looked at to handle the different
71 floating point emulators on ARM Linux. Right now the code
72 assumes that fetch inferior registers does the right thing for
73 GDB. I suspect this won't handle NWFPE registers correctly, nor
74 will the default ARM version (arm_extract_return_value()). */
75
76 int regnum = (TYPE_CODE_FLT == TYPE_CODE (type)) ? F0_REGNUM : A1_REGNUM;
77 memcpy (valbuf, &regbuf[REGISTER_BYTE (regnum)], TYPE_LENGTH (type));
78 }
79
80 /* Note: ScottB
81
82 This function does not support passing parameters using the FPA
83 variant of the APCS. It passes any floating point arguments in the
84 general registers and/or on the stack.
85
86 FIXME: This and arm_push_arguments should be merged. However this
87 function breaks on a little endian host, big endian target
88 using the COFF file format. ELF is ok.
89
90 ScottB. */
91
92 /* Addresses for calling Thumb functions have the bit 0 set.
93 Here are some macros to test, set, or clear bit 0 of addresses. */
94 #define IS_THUMB_ADDR(addr) ((addr) & 1)
95 #define MAKE_THUMB_ADDR(addr) ((addr) | 1)
96 #define UNMAKE_THUMB_ADDR(addr) ((addr) & ~1)
97
98 CORE_ADDR
99 arm_linux_push_arguments (int nargs, value_ptr * args, CORE_ADDR sp,
100 int struct_return, CORE_ADDR struct_addr)
101 {
102 char *fp;
103 int argnum, argreg, nstack_size;
104
105 /* Walk through the list of args and determine how large a temporary
106 stack is required. Need to take care here as structs may be
107 passed on the stack, and we have to to push them. */
108 nstack_size = -4 * REGISTER_SIZE; /* Some arguments go into A1-A4. */
109
110 if (struct_return) /* The struct address goes in A1. */
111 nstack_size += REGISTER_SIZE;
112
113 /* Walk through the arguments and add their size to nstack_size. */
114 for (argnum = 0; argnum < nargs; argnum++)
115 {
116 int len;
117 struct type *arg_type;
118
119 arg_type = check_typedef (VALUE_TYPE (args[argnum]));
120 len = TYPE_LENGTH (arg_type);
121
122 /* ANSI C code passes float arguments as integers, K&R code
123 passes float arguments as doubles. Correct for this here. */
124 if (TYPE_CODE_FLT == TYPE_CODE (arg_type) && REGISTER_SIZE == len)
125 nstack_size += FP_REGISTER_VIRTUAL_SIZE;
126 else
127 nstack_size += len;
128 }
129
130 /* Allocate room on the stack, and initialize our stack frame
131 pointer. */
132 fp = NULL;
133 if (nstack_size > 0)
134 {
135 sp -= nstack_size;
136 fp = (char *) sp;
137 }
138
139 /* Initialize the integer argument register pointer. */
140 argreg = A1_REGNUM;
141
142 /* The struct_return pointer occupies the first parameter passing
143 register. */
144 if (struct_return)
145 write_register (argreg++, struct_addr);
146
147 /* Process arguments from left to right. Store as many as allowed
148 in the parameter passing registers (A1-A4), and save the rest on
149 the temporary stack. */
150 for (argnum = 0; argnum < nargs; argnum++)
151 {
152 int len;
153 char *val;
154 double dbl_arg;
155 CORE_ADDR regval;
156 enum type_code typecode;
157 struct type *arg_type, *target_type;
158
159 arg_type = check_typedef (VALUE_TYPE (args[argnum]));
160 target_type = TYPE_TARGET_TYPE (arg_type);
161 len = TYPE_LENGTH (arg_type);
162 typecode = TYPE_CODE (arg_type);
163 val = (char *) VALUE_CONTENTS (args[argnum]);
164
165 /* ANSI C code passes float arguments as integers, K&R code
166 passes float arguments as doubles. The .stabs record for
167 for ANSI prototype floating point arguments records the
168 type as FP_INTEGER, while a K&R style (no prototype)
169 .stabs records the type as FP_FLOAT. In this latter case
170 the compiler converts the float arguments to double before
171 calling the function. */
172 if (TYPE_CODE_FLT == typecode && REGISTER_SIZE == len)
173 {
174 /* Float argument in buffer is in host format. Read it and
175 convert to DOUBLEST, and store it in target double. */
176 DOUBLEST dblval;
177
178 len = TARGET_DOUBLE_BIT / TARGET_CHAR_BIT;
179 floatformat_to_doublest (HOST_FLOAT_FORMAT, val, &dblval);
180 store_floating (&dbl_arg, len, dblval);
181 val = (char *) &dbl_arg;
182 }
183
184 /* If the argument is a pointer to a function, and it is a Thumb
185 function, set the low bit of the pointer. */
186 if (TYPE_CODE_PTR == typecode
187 && NULL != target_type
188 && TYPE_CODE_FUNC == TYPE_CODE (target_type))
189 {
190 CORE_ADDR regval = extract_address (val, len);
191 if (arm_pc_is_thumb (regval))
192 store_address (val, len, MAKE_THUMB_ADDR (regval));
193 }
194
195 /* Copy the argument to general registers or the stack in
196 register-sized pieces. Large arguments are split between
197 registers and stack. */
198 while (len > 0)
199 {
200 int partial_len = len < REGISTER_SIZE ? len : REGISTER_SIZE;
201
202 if (argreg <= ARM_LAST_ARG_REGNUM)
203 {
204 /* It's an argument being passed in a general register. */
205 regval = extract_address (val, partial_len);
206 write_register (argreg++, regval);
207 }
208 else
209 {
210 /* Push the arguments onto the stack. */
211 write_memory ((CORE_ADDR) fp, val, REGISTER_SIZE);
212 fp += REGISTER_SIZE;
213 }
214
215 len -= partial_len;
216 val += partial_len;
217 }
218 }
219
220 /* Return adjusted stack pointer. */
221 return sp;
222 }
223
224 void
225 _initialize_arm_linux_tdep (void)
226 {
227 }
This page took 0.036161 seconds and 4 git commands to generate.