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 */
29 #include <sys/param.h>
32 #include <sys/ioctl.h>
37 static long i386_get_frame_setup ();
38 static i386_follow_jump ();
41 #define TERMINAL struct sgttyb
43 exec_file_command (filename, from_tty)
49 /* Eliminate all traces of old exec file.
50 Mark text segment as empty. */
56 data_end -= exec_data_start;
65 /* Now open and digest the file the user requested, if any. */
69 filename = tilde_expand (filename);
70 make_cleanup (free, filename);
72 execchan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0,
75 perror_with_name (filename);
82 if (read_file_hdr (execchan, &file_hdr) < 0)
83 error ("\"%s\": not in executable format.", execfile);
85 aout_hdrsize = file_hdr.f_opthdr;
86 num_sections = file_hdr.f_nscns;
88 if (read_aout_hdr (execchan, &exec_aouthdr, aout_hdrsize) < 0)
89 error ("\"%s\": can't read optional aouthdr", execfile);
91 if (read_section_hdr (execchan, _TEXT, &text_hdr, num_sections,
93 error ("\"%s\": can't read text section header", execfile);
95 if (read_section_hdr (execchan, _DATA, &data_hdr, num_sections,
97 error ("\"%s\": can't read data section header", execfile);
99 text_start = exec_aouthdr.text_start;
100 text_end = text_start + exec_aouthdr.tsize;
101 text_offset = text_hdr.s_scnptr;
102 exec_data_start = exec_aouthdr.data_start;
103 exec_data_end = exec_data_start + exec_aouthdr.dsize;
104 exec_data_offset = data_hdr.s_scnptr;
105 data_start = exec_data_start;
106 data_end += exec_data_start;
107 exec_mtime = file_hdr.f_timdat;
109 #else /* not COFF_FORMAT */
113 val = myread (execchan, &exec_aouthdr, sizeof (AOUTHDR));
116 perror_with_name (filename);
118 text_start = N_ADDRADJ(exec_aouthdr);
119 exec_data_start = round(exec_aouthdr.a_text, NBPG*CLSIZE);
120 text_offset = N_TXTOFF (exec_aouthdr);
121 exec_data_offset = N_TXTOFF (exec_aouthdr) + exec_aouthdr.a_text;
122 text_end = exec_aouthdr.a_text;
123 exec_data_end = exec_data_start + exec_aouthdr.a_data;
124 data_start = exec_data_start;
125 data_end = data_start + exec_aouthdr.a_data;
126 exec_data_offset = N_TXTOFF(exec_aouthdr);
127 fstat (execchan, &st_exec);
128 exec_mtime = st_exec.st_mtime;
130 #endif /* not COFF_FORMAT */
135 printf ("No exec file now.\n");
137 /* Tell display code (if any) about the changed file name. */
138 if (exec_file_display_hook)
139 (*exec_file_display_hook) (filename);
142 /* rounds 'one' up to divide evenly by 'two' */
146 register int one, two;
150 temp = (one/two)*two;
158 static CORE_ADDR codestream_next_addr;
159 static CORE_ADDR codestream_addr;
160 static unsigned char codestream_buf[sizeof (int)];
161 static int codestream_off;
162 static int codestream_cnt;
164 #define codestream_tell() (codestream_addr + codestream_off)
165 #define codestream_peek() (codestream_cnt == 0 ? \
166 codestream_fill(1): codestream_buf[codestream_off])
167 #define codestream_get() (codestream_cnt-- == 0 ? \
168 codestream_fill(0) : codestream_buf[codestream_off++])
172 codestream_fill (peek_flag)
174 codestream_addr = codestream_next_addr;
175 codestream_next_addr += sizeof (int);
177 codestream_cnt = sizeof (int);
178 read_memory (codestream_addr,
179 (unsigned char *)codestream_buf,
183 return (codestream_peek());
185 return (codestream_get());
189 codestream_seek (place)
191 codestream_next_addr = place & -sizeof (int);
194 while (codestream_tell() != place)
199 codestream_read (buf, count)
205 for (i = 0; i < count; i++)
206 *p++ = codestream_get ();
210 * Following macro translates i386 opcode register numbers to Symmetry
211 * register numbers. This is used by FRAME_FIND_SAVED_REGS.
213 * %eax %ecx %edx %ebx %esp %ebp %esi %edi
214 * i386 0 1 2 3 4 5 6 7
215 * Symmetry 0 2 1 5 14 15 6 7
218 #define I386_REGNO_TO_SYMMETRY(n) \
219 ((n)==0?0 :(n)==1?2 :(n)==2?1 :(n)==3?5 :(n)==4?14 :(n)==5?15 :(n))
221 /* from i386-dep.c */
222 i386_frame_find_saved_regs (fip, fsrp)
223 struct frame_info *fip;
224 struct frame_saved_regs *fsrp;
226 unsigned long locals;
229 CORE_ADDR dummy_bottom;
233 bzero (fsrp, sizeof *fsrp);
235 /* if frame is the end of a dummy, compute where the
238 dummy_bottom = fip->frame - 4 - NUM_REGS*4 - CALL_DUMMY_LENGTH;
240 /* check if the PC is in the stack, in a dummy frame */
241 if (dummy_bottom <= fip->pc && fip->pc <= fip->frame)
243 /* all regs were saved by push_call_dummy () */
244 adr = fip->frame - 4;
245 for (i = 0; i < NUM_REGS; i++)
253 locals = i386_get_frame_setup (get_pc_function_start (fip->pc));
257 adr = fip->frame - 4 - locals;
258 for (i = 0; i < 8; i++)
260 op = codestream_get ();
261 if (op < 0x50 || op > 0x57)
263 fsrp->regs[I386_REGNO_TO_SYMMETRY(op - 0x50)] = adr;
268 fsrp->regs[PC_REGNUM] = fip->frame + 4;
269 fsrp->regs[FP_REGNUM] = fip->frame;
273 i386_get_frame_setup (pc)
277 codestream_seek (pc);
281 op = codestream_get ();
283 if (op == 0x58) /* popl %eax */
286 * this function must start with
289 * xchgl %eax, (%esp) 0x87 0x04 0x24
290 * or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
292 * (the system 5 compiler puts out the second xchg
293 * inst, and the assembler doesn't try to optimize it,
294 * so the 'sib' form gets generated)
296 * this sequence is used to get the address of the return
297 * buffer for a function that returns a structure
300 unsigned char buf[4];
301 static unsigned char proto1[3] = { 0x87,0x04,0x24 };
302 static unsigned char proto2[4] = { 0x87,0x44,0x24,0x00 };
303 pos = codestream_tell ();
304 codestream_read (buf, 4);
305 if (bcmp (buf, proto1, 3) == 0)
307 else if (bcmp (buf, proto2, 4) == 0)
310 codestream_seek (pos);
311 op = codestream_get (); /* update next opcode */
314 if (op == 0x55) /* pushl %esp */
316 if (codestream_get () != 0x8b) /* movl %esp, %ebp (2bytes) */
318 if (codestream_get () != 0xec)
321 * check for stack adjustment
325 * note: you can't subtract a 16 bit immediate
326 * from a 32 bit reg, so we don't have to worry
327 * about a data16 prefix
329 op = codestream_peek ();
330 if (op == 0x83) /* subl with 8 bit immed */
333 if (codestream_get () != 0xec)
335 /* subl with signed byte immediate
336 * (though it wouldn't make sense to be negative)
338 return (codestream_get());
340 else if (op == 0x81) /* subl with 32 bit immed */
343 if (codestream_get () != 0xec)
345 /* subl with 32 bit immediate */
346 codestream_read ((unsigned char *)&locals, 4);
356 /* enter instruction: arg is 16 unsigned immed */
357 unsigned short slocals;
358 codestream_read ((unsigned char *)&slocals, 2);
359 codestream_get (); /* flush final byte of enter instruction */
365 /* next instruction is a jump, move to target */
375 pos = codestream_tell ();
378 if (codestream_peek () == 0x66)
384 switch (codestream_get ())
387 /* relative jump: if data16 == 0, disp32, else disp16 */
390 codestream_read ((unsigned char *)&short_delta, 2);
391 pos += short_delta + 3; /* include size of jmp inst */
395 codestream_read ((unsigned char *)&long_delta, 4);
396 pos += long_delta + 5;
400 /* relative jump, disp8 (ignore data16) */
401 codestream_read ((unsigned char *)&byte_delta, 1);
402 pos += byte_delta + 2;
405 codestream_seek (pos + data16);
408 /* return pc of first real instruction */
409 /* from i386-dep.c */
411 i386_skip_prologue (pc)
416 if (i386_get_frame_setup (pc) < 0)
419 /* found valid frame setup - codestream now points to
420 * start of push instructions for saving registers
423 /* skip over register saves */
424 for (i = 0; i < 8; i++)
426 op = codestream_peek ();
427 /* break if not pushl inst */
428 if (op < 0x50 || op > 0x57)
435 return (codestream_tell ());
438 symmetry_extract_return_value(type, regbuf, valbuf)
450 if (TYPE_CODE_FLT == TYPE_CODE(type)) {
451 for (i = 0; i < misc_function_count; i++) {
452 if (!strcmp(misc_function_vector[i].name, "1167_flt"))
455 if (i < misc_function_count) {
456 /* found "1167_flt" means 1167, %fp2-%fp3 */
457 /* float & double; 19= %fp2, 20= %fp3 */
458 /* no single precision on 1167 */
459 xd.l[1] = *((int *)®buf[REGISTER_BYTE(19)]);
460 xd.l[0] = *((int *)®buf[REGISTER_BYTE(20)]);
461 switch (TYPE_LENGTH(type)) {
464 bcopy(&f, valbuf, TYPE_LENGTH(type));
467 bcopy(&xd.d, valbuf, TYPE_LENGTH(type));
470 error("Unknown floating point size");
474 /* 387 %st(0), gcc uses this */
475 i387_to_double(((int *)®buf[REGISTER_BYTE(3)]),
477 switch (TYPE_LENGTH(type)) {
480 bcopy(&f, valbuf, 4);
483 bcopy(&xd.d, valbuf, 8);
486 error("Unknown floating point size");
491 bcopy (regbuf, valbuf, TYPE_LENGTH (type));