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 */
28 #include <sys/param.h>
31 #include <sys/ioctl.h>
36 static long i386_get_frame_setup ();
37 static i386_follow_jump ();
40 #define TERMINAL struct sgttyb
42 exec_file_command (filename
, from_tty
)
48 /* Eliminate all traces of old exec file.
49 Mark text segment as empty. */
55 data_end
-= exec_data_start
;
64 /* Now open and digest the file the user requested, if any. */
68 filename
= tilde_expand (filename
);
69 make_cleanup (free
, filename
);
71 execchan
= openp (getenv ("PATH"), 1, filename
, O_RDONLY
, 0,
74 perror_with_name (filename
);
81 if (read_file_hdr (execchan
, &file_hdr
) < 0)
82 error ("\"%s\": not in executable format.", execfile
);
84 aout_hdrsize
= file_hdr
.f_opthdr
;
85 num_sections
= file_hdr
.f_nscns
;
87 if (read_aout_hdr (execchan
, &exec_aouthdr
, aout_hdrsize
) < 0)
88 error ("\"%s\": can't read optional aouthdr", execfile
);
90 if (read_section_hdr (execchan
, _TEXT
, &text_hdr
, num_sections
,
92 error ("\"%s\": can't read text section header", execfile
);
94 if (read_section_hdr (execchan
, _DATA
, &data_hdr
, num_sections
,
96 error ("\"%s\": can't read data section header", execfile
);
98 text_start
= exec_aouthdr
.text_start
;
99 text_end
= text_start
+ exec_aouthdr
.tsize
;
100 text_offset
= text_hdr
.s_scnptr
;
101 exec_data_start
= exec_aouthdr
.data_start
;
102 exec_data_end
= exec_data_start
+ exec_aouthdr
.dsize
;
103 exec_data_offset
= data_hdr
.s_scnptr
;
104 data_start
= exec_data_start
;
105 data_end
+= exec_data_start
;
106 exec_mtime
= file_hdr
.f_timdat
;
108 #else /* not COFF_FORMAT */
112 val
= myread (execchan
, &exec_aouthdr
, sizeof (AOUTHDR
));
115 perror_with_name (filename
);
117 text_start
= N_ADDRADJ(exec_aouthdr
);
118 exec_data_start
= round(exec_aouthdr
.a_text
, NBPG
*CLSIZE
);
119 text_offset
= N_TXTOFF (exec_aouthdr
);
120 exec_data_offset
= N_TXTOFF (exec_aouthdr
) + exec_aouthdr
.a_text
;
121 text_end
= exec_aouthdr
.a_text
;
122 exec_data_end
= exec_data_start
+ exec_aouthdr
.a_data
;
123 data_start
= exec_data_start
;
124 data_end
= data_start
+ exec_aouthdr
.a_data
;
125 exec_data_offset
= N_TXTOFF(exec_aouthdr
);
126 fstat (execchan
, &st_exec
);
127 exec_mtime
= st_exec
.st_mtime
;
129 #endif /* not COFF_FORMAT */
134 printf ("No exec file now.\n");
136 /* Tell display code (if any) about the changed file name. */
137 if (exec_file_display_hook
)
138 (*exec_file_display_hook
) (filename
);
141 /* rounds 'one' up to divide evenly by 'two' */
145 register int one
, two
;
149 temp
= (one
/two
)*two
;
157 static CORE_ADDR codestream_next_addr
;
158 static CORE_ADDR codestream_addr
;
159 static unsigned char codestream_buf
[sizeof (int)];
160 static int codestream_off
;
161 static int codestream_cnt
;
163 #define codestream_tell() (codestream_addr + codestream_off)
164 #define codestream_peek() (codestream_cnt == 0 ? \
165 codestream_fill(1): codestream_buf[codestream_off])
166 #define codestream_get() (codestream_cnt-- == 0 ? \
167 codestream_fill(0) : codestream_buf[codestream_off++])
171 codestream_fill (peek_flag
)
173 codestream_addr
= codestream_next_addr
;
174 codestream_next_addr
+= sizeof (int);
176 codestream_cnt
= sizeof (int);
177 read_memory (codestream_addr
,
178 (unsigned char *)codestream_buf
,
182 return (codestream_peek());
184 return (codestream_get());
188 codestream_seek (place
)
190 codestream_next_addr
= place
& -sizeof (int);
193 while (codestream_tell() != place
)
198 codestream_read (buf
, count
)
204 for (i
= 0; i
< count
; i
++)
205 *p
++ = codestream_get ();
209 * Following macro translates i386 opcode register numbers to Symmetry
210 * register numbers. This is used by FRAME_FIND_SAVED_REGS.
212 * %eax %ecx %edx %ebx %esp %ebp %esi %edi
213 * i386 0 1 2 3 4 5 6 7
214 * Symmetry 0 2 1 5 14 15 6 7
217 #define I386_REGNO_TO_SYMMETRY(n) \
218 ((n)==0?0 :(n)==1?2 :(n)==2?1 :(n)==3?5 :(n)==4?14 :(n)==5?15 :(n))
220 /* from i386-dep.c */
221 i386_frame_find_saved_regs (fip
, fsrp
)
222 struct frame_info
*fip
;
223 struct frame_saved_regs
*fsrp
;
225 unsigned long locals
;
228 CORE_ADDR dummy_bottom
;
232 bzero (fsrp
, sizeof *fsrp
);
234 /* if frame is the end of a dummy, compute where the
237 dummy_bottom
= fip
->frame
- 4 - NUM_REGS
*4 - CALL_DUMMY_LENGTH
;
239 /* check if the PC is in the stack, in a dummy frame */
240 if (dummy_bottom
<= fip
->pc
&& fip
->pc
<= fip
->frame
)
242 /* all regs were saved by push_call_dummy () */
243 adr
= fip
->frame
- 4;
244 for (i
= 0; i
< NUM_REGS
; i
++)
252 locals
= i386_get_frame_setup (get_pc_function_start (fip
->pc
));
256 adr
= fip
->frame
- 4 - locals
;
257 for (i
= 0; i
< 8; i
++)
259 op
= codestream_get ();
260 if (op
< 0x50 || op
> 0x57)
262 fsrp
->regs
[I386_REGNO_TO_SYMMETRY(op
- 0x50)] = adr
;
267 fsrp
->regs
[PC_REGNUM
] = fip
->frame
+ 4;
268 fsrp
->regs
[FP_REGNUM
] = fip
->frame
;
272 i386_get_frame_setup (pc
)
276 codestream_seek (pc
);
280 op
= codestream_get ();
282 if (op
== 0x58) /* popl %eax */
285 * this function must start with
288 * xchgl %eax, (%esp) 0x87 0x04 0x24
289 * or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
291 * (the system 5 compiler puts out the second xchg
292 * inst, and the assembler doesn't try to optimize it,
293 * so the 'sib' form gets generated)
295 * this sequence is used to get the address of the return
296 * buffer for a function that returns a structure
299 unsigned char buf
[4];
300 static unsigned char proto1
[3] = { 0x87,0x04,0x24 };
301 static unsigned char proto2
[4] = { 0x87,0x44,0x24,0x00 };
302 pos
= codestream_tell ();
303 codestream_read (buf
, 4);
304 if (bcmp (buf
, proto1
, 3) == 0)
306 else if (bcmp (buf
, proto2
, 4) == 0)
309 codestream_seek (pos
);
310 op
= codestream_get (); /* update next opcode */
313 if (op
== 0x55) /* pushl %esp */
315 if (codestream_get () != 0x8b) /* movl %esp, %ebp (2bytes) */
317 if (codestream_get () != 0xec)
320 * check for stack adjustment
324 * note: you can't subtract a 16 bit immediate
325 * from a 32 bit reg, so we don't have to worry
326 * about a data16 prefix
328 op
= codestream_peek ();
329 if (op
== 0x83) /* subl with 8 bit immed */
332 if (codestream_get () != 0xec)
334 /* subl with signed byte immediate
335 * (though it wouldn't make sense to be negative)
337 return (codestream_get());
339 else if (op
== 0x81) /* subl with 32 bit immed */
342 if (codestream_get () != 0xec)
344 /* subl with 32 bit immediate */
345 codestream_read ((unsigned char *)&locals
, 4);
355 /* enter instruction: arg is 16 unsigned immed */
356 unsigned short slocals
;
357 codestream_read ((unsigned char *)&slocals
, 2);
358 codestream_get (); /* flush final byte of enter instruction */
364 /* next instruction is a jump, move to target */
374 pos
= codestream_tell ();
377 if (codestream_peek () == 0x66)
383 switch (codestream_get ())
386 /* relative jump: if data16 == 0, disp32, else disp16 */
389 codestream_read ((unsigned char *)&short_delta
, 2);
390 pos
+= short_delta
+ 3; /* include size of jmp inst */
394 codestream_read ((unsigned char *)&long_delta
, 4);
395 pos
+= long_delta
+ 5;
399 /* relative jump, disp8 (ignore data16) */
400 codestream_read ((unsigned char *)&byte_delta
, 1);
401 pos
+= byte_delta
+ 2;
404 codestream_seek (pos
+ data16
);
407 /* return pc of first real instruction */
408 /* from i386-dep.c */
410 i386_skip_prologue (pc
)
415 if (i386_get_frame_setup (pc
) < 0)
418 /* found valid frame setup - codestream now points to
419 * start of push instructions for saving registers
422 /* skip over register saves */
423 for (i
= 0; i
< 8; i
++)
425 op
= codestream_peek ();
426 /* break if not pushl inst */
427 if (op
< 0x50 || op
> 0x57)
434 return (codestream_tell ());
437 symmetry_extract_return_value(type
, regbuf
, valbuf
)
446 struct minimal_symbol
*msymbol
;
449 if (TYPE_CODE_FLT
== TYPE_CODE(type
)) {
450 msymbol
= lookup_minimal_symbol ("1167_flt", (struct objfile
*) NULL
);
451 if (msymbol
!= NULL
) {
452 /* found "1167_flt" means 1167, %fp2-%fp3 */
453 /* float & double; 19= %fp2, 20= %fp3 */
454 /* no single precision on 1167 */
455 xd
.l
[1] = *((int *)®buf
[REGISTER_BYTE(19)]);
456 xd
.l
[0] = *((int *)®buf
[REGISTER_BYTE(20)]);
457 switch (TYPE_LENGTH(type
)) {
460 bcopy(&f
, valbuf
, TYPE_LENGTH(type
));
463 bcopy(&xd
.d
, valbuf
, TYPE_LENGTH(type
));
466 error("Unknown floating point size");
470 /* 387 %st(0), gcc uses this */
471 i387_to_double(((int *)®buf
[REGISTER_BYTE(3)]),
473 switch (TYPE_LENGTH(type
)) {
476 bcopy(&f
, valbuf
, 4);
479 bcopy(&xd
.d
, valbuf
, 8);
482 error("Unknown floating point size");
487 bcopy (regbuf
, valbuf
, TYPE_LENGTH (type
));