1/* Target-dependent code for Intel 386 running LynxOS.
2   Copyright 1993, 1996, 2000, 2001, 2002, 2003 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 "gdbcore.h"
23#include "inferior.h"
24#include "regcache.h"
25#include "target.h"
26#include "osabi.h"
27
28#include "i386-tdep.h"
29
30/* Return the PC of the caller from the call frame.  Assumes the subr
31   prologue has already been executed, and the frame pointer setup.
32   If this is the outermost frame, we check to see if we are in a
33   system call by examining the previous instruction.  If so, then the
34   return PC is actually at SP+4 because system calls use a different
35   calling sequence.  */
36
37static CORE_ADDR
38i386lynx_saved_pc_after_call (struct frame_info *frame)
39{
40  char opcode[7];
41  static const unsigned char call_inst[] =
42  { 0x9a, 0, 0, 0, 0, 8, 0 };	/* lcall 0x8,0x0 */
43
44  read_memory_nobpt (frame->pc - 7, opcode, 7);
45  if (memcmp (opcode, call_inst, 7) == 0)
46    return read_memory_unsigned_integer (read_register (SP_REGNUM) + 4, 4);
47
48  return read_memory_unsigned_integer (read_register (SP_REGNUM), 4);
49}
50
51
52/* LynxOS.  */
53static void
54i386lynx_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
55{
56  set_gdbarch_deprecated_saved_pc_after_call (gdbarch, i386lynx_saved_pc_after_call);
57}
58
59
60static enum gdb_osabi
61i386lynx_coff_osabi_sniffer (bfd *abfd)
62{
63  if (strcmp (bfd_get_target (abfd), "coff-i386-lynx") == 0)
64    return GDB_OSABI_LYNXOS;
65
66  return GDB_OSABI_UNKNOWN;
67}
68
69
70/* Provide a prototype to silence -Wmissing-prototypes.  */
71void _initialize_i386lynx_tdep (void);
72
73void
74_initialize_i386lynx_tdep (void)
75{
76  gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
77				  i386lynx_coff_osabi_sniffer);
78
79  gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LYNXOS,
80			  i386lynx_init_abi);
81}
82