1 /* Sequent Symmetry target interface, for GDB when running under Unix.
2 Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* many 387-specific items of use taken from i386-dep.c */
30 #include <sys/param.h>
33 #include <sys/ioctl.h>
38 static long i386_get_frame_setup ();
39 static i386_follow_jump ();
42 #define TERMINAL struct sgttyb
44 exec_file_command (filename, from_tty)
50 /* Eliminate all traces of old exec file.
51 Mark text segment as empty. */
57 data_end -= exec_data_start;
66 /* Now open and digest the file the user requested, if any. */
70 filename = tilde_expand (filename);
71 make_cleanup (free, filename);
73 execchan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0,
76 perror_with_name (filename);
83 if (read_file_hdr (execchan, &file_hdr) < 0)
84 error ("\"%s\": not in executable format.", execfile);
86 aout_hdrsize = file_hdr.f_opthdr;
87 num_sections = file_hdr.f_nscns;
89 if (read_aout_hdr (execchan, &exec_aouthdr, aout_hdrsize) < 0)
90 error ("\"%s\": can't read optional aouthdr", execfile);
92 if (read_section_hdr (execchan, _TEXT, &text_hdr, num_sections,
94 error ("\"%s\": can't read text section header", execfile);
96 if (read_section_hdr (execchan, _DATA, &data_hdr, num_sections,
98 error ("\"%s\": can't read data section header", execfile);
100 text_start = exec_aouthdr.text_start;
101 text_end = text_start + exec_aouthdr.tsize;
102 text_offset = text_hdr.s_scnptr;
103 exec_data_start = exec_aouthdr.data_start;
104 exec_data_end = exec_data_start + exec_aouthdr.dsize;
105 exec_data_offset = data_hdr.s_scnptr;
106 data_start = exec_data_start;
107 data_end += exec_data_start;
108 exec_mtime = file_hdr.f_timdat;
110 #else /* not COFF_FORMAT */
114 val = myread (execchan, &exec_aouthdr, sizeof (AOUTHDR));
117 perror_with_name (filename);
119 text_start = N_ADDRADJ(exec_aouthdr);
120 exec_data_start = round(exec_aouthdr.a_text, NBPG*CLSIZE);
121 text_offset = N_TXTOFF (exec_aouthdr);
122 exec_data_offset = N_TXTOFF (exec_aouthdr) + exec_aouthdr.a_text;
123 text_end = exec_aouthdr.a_text;
124 exec_data_end = exec_data_start + exec_aouthdr.a_data;
125 data_start = exec_data_start;
126 data_end = data_start + exec_aouthdr.a_data;
127 exec_data_offset = N_TXTOFF(exec_aouthdr);
128 fstat (execchan, &st_exec);
129 exec_mtime = st_exec.st_mtime;
131 #endif /* not COFF_FORMAT */
136 printf ("No exec file now.\n");
138 /* Tell display code (if any) about the changed file name. */
139 if (exec_file_display_hook)
140 (*exec_file_display_hook) (filename);
143 /* rounds 'one' up to divide evenly by 'two' */
147 register int one, two;
151 temp = (one/two)*two;
159 static CORE_ADDR codestream_next_addr;
160 static CORE_ADDR codestream_addr;
161 static unsigned char codestream_buf[sizeof (int)];
162 static int codestream_off;
163 static int codestream_cnt;
165 #define codestream_tell() (codestream_addr + codestream_off)
166 #define codestream_peek() (codestream_cnt == 0 ? \
167 codestream_fill(1): codestream_buf[codestream_off])
168 #define codestream_get() (codestream_cnt-- == 0 ? \
169 codestream_fill(0) : codestream_buf[codestream_off++])
173 codestream_fill (peek_flag)
175 codestream_addr = codestream_next_addr;
176 codestream_next_addr += sizeof (int);
178 codestream_cnt = sizeof (int);
179 read_memory (codestream_addr,
180 (unsigned char *)codestream_buf,
184 return (codestream_peek());
186 return (codestream_get());
190 codestream_seek (place)
192 codestream_next_addr = place & -sizeof (int);
195 while (codestream_tell() != place)
200 codestream_read (buf, count)
206 for (i = 0; i < count; i++)
207 *p++ = codestream_get ();
211 * Following macro translates i386 opcode register numbers to Symmetry
212 * register numbers. This is used by FRAME_FIND_SAVED_REGS.
214 * %eax %ecx %edx %ebx %esp %ebp %esi %edi
215 * i386 0 1 2 3 4 5 6 7
216 * Symmetry 0 2 1 5 14 15 6 7
219 #define I386_REGNO_TO_SYMMETRY(n) \
220 ((n)==0?0 :(n)==1?2 :(n)==2?1 :(n)==3?5 :(n)==4?14 :(n)==5?15 :(n))
222 /* from i386-dep.c */
223 i386_frame_find_saved_regs (fip, fsrp)
224 struct frame_info *fip;
225 struct frame_saved_regs *fsrp;
227 unsigned long locals;
230 CORE_ADDR dummy_bottom;
234 bzero (fsrp, sizeof *fsrp);
236 /* if frame is the end of a dummy, compute where the
239 dummy_bottom = fip->frame - 4 - NUM_REGS*4 - CALL_DUMMY_LENGTH;
241 /* check if the PC is in the stack, in a dummy frame */
242 if (dummy_bottom <= fip->pc && fip->pc <= fip->frame)
244 /* all regs were saved by push_call_dummy () */
245 adr = fip->frame - 4;
246 for (i = 0; i < NUM_REGS; i++)
254 locals = i386_get_frame_setup (get_pc_function_start (fip->pc));
258 adr = fip->frame - 4 - locals;
259 for (i = 0; i < 8; i++)
261 op = codestream_get ();
262 if (op < 0x50 || op > 0x57)
264 fsrp->regs[I386_REGNO_TO_SYMMETRY(op - 0x50)] = adr;
269 fsrp->regs[PC_REGNUM] = fip->frame + 4;
270 fsrp->regs[FP_REGNUM] = fip->frame;
274 i386_get_frame_setup (pc)
278 codestream_seek (pc);
282 op = codestream_get ();
284 if (op == 0x58) /* popl %eax */
287 * this function must start with
290 * xchgl %eax, (%esp) 0x87 0x04 0x24
291 * or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
293 * (the system 5 compiler puts out the second xchg
294 * inst, and the assembler doesn't try to optimize it,
295 * so the 'sib' form gets generated)
297 * this sequence is used to get the address of the return
298 * buffer for a function that returns a structure
301 unsigned char buf[4];
302 static unsigned char proto1[3] = { 0x87,0x04,0x24 };
303 static unsigned char proto2[4] = { 0x87,0x44,0x24,0x00 };
304 pos = codestream_tell ();
305 codestream_read (buf, 4);
306 if (bcmp (buf, proto1, 3) == 0)
308 else if (bcmp (buf, proto2, 4) == 0)
311 codestream_seek (pos);
312 op = codestream_get (); /* update next opcode */
315 if (op == 0x55) /* pushl %esp */
317 if (codestream_get () != 0x8b) /* movl %esp, %ebp (2bytes) */
319 if (codestream_get () != 0xec)
322 * check for stack adjustment
326 * note: you can't subtract a 16 bit immediate
327 * from a 32 bit reg, so we don't have to worry
328 * about a data16 prefix
330 op = codestream_peek ();
331 if (op == 0x83) /* subl with 8 bit immed */
334 if (codestream_get () != 0xec)
336 /* subl with signed byte immediate
337 * (though it wouldn't make sense to be negative)
339 return (codestream_get());
341 else if (op == 0x81) /* subl with 32 bit immed */
344 if (codestream_get () != 0xec)
346 /* subl with 32 bit immediate */
347 codestream_read ((unsigned char *)&locals, 4);
357 /* enter instruction: arg is 16 unsigned immed */
358 unsigned short slocals;
359 codestream_read ((unsigned char *)&slocals, 2);
360 codestream_get (); /* flush final byte of enter instruction */
366 /* next instruction is a jump, move to target */
376 pos = codestream_tell ();
379 if (codestream_peek () == 0x66)
385 switch (codestream_get ())
388 /* relative jump: if data16 == 0, disp32, else disp16 */
391 codestream_read ((unsigned char *)&short_delta, 2);
392 pos += short_delta + 3; /* include size of jmp inst */
396 codestream_read ((unsigned char *)&long_delta, 4);
397 pos += long_delta + 5;
401 /* relative jump, disp8 (ignore data16) */
402 codestream_read ((unsigned char *)&byte_delta, 1);
403 pos += byte_delta + 2;
406 codestream_seek (pos + data16);
409 /* return pc of first real instruction */
410 /* from i386-dep.c */
412 i386_skip_prologue (pc)
417 if (i386_get_frame_setup (pc) < 0)
420 /* found valid frame setup - codestream now points to
421 * start of push instructions for saving registers
424 /* skip over register saves */
425 for (i = 0; i < 8; i++)
427 op = codestream_peek ();
428 /* break if not pushl inst */
429 if (op < 0x50 || op > 0x57)
436 return (codestream_tell ());
439 symmetry_extract_return_value(type, regbuf, valbuf)
451 if (TYPE_CODE_FLT == TYPE_CODE(type)) {
452 for (i = 0; i < misc_function_count; i++) {
453 if (!strcmp(misc_function_vector[i].name, "1167_flt"))
456 if (i < misc_function_count) {
457 /* found "1167_flt" means 1167, %fp2-%fp3 */
458 /* float & double; 19= %fp2, 20= %fp3 */
459 /* no single precision on 1167 */
460 xd.l[1] = *((int *)®buf[REGISTER_BYTE(19)]);
461 xd.l[0] = *((int *)®buf[REGISTER_BYTE(20)]);
462 switch (TYPE_LENGTH(type)) {
465 bcopy(&f, valbuf, TYPE_LENGTH(type));
468 bcopy(&xd.d, valbuf, TYPE_LENGTH(type));
471 error("Unknown floating point size");
475 /* 387 %st(0), gcc uses this */
476 i387_to_double(((int *)®buf[REGISTER_BYTE(3)]),
478 switch (TYPE_LENGTH(type)) {
481 bcopy(&f, valbuf, 4);
484 bcopy(&xd.d, valbuf, 8);
487 error("Unknown floating point size");
492 bcopy (regbuf, valbuf, TYPE_LENGTH (type));