1130812Smarcel/* Target-dependent code for Intel 386 running LynxOS.
2130812Smarcel   Copyright 1993, 1996, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3130812Smarcel
4130812Smarcel   This file is part of GDB.
5130812Smarcel
6130812Smarcel   This program is free software; you can redistribute it and/or modify
7130812Smarcel   it under the terms of the GNU General Public License as published by
8130812Smarcel   the Free Software Foundation; either version 2 of the License, or
9130812Smarcel   (at your option) any later version.
10130812Smarcel
11130812Smarcel   This program is distributed in the hope that it will be useful,
12130812Smarcel   but WITHOUT ANY WARRANTY; without even the implied warranty of
13130812Smarcel   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14130812Smarcel   GNU General Public License for more details.
15130812Smarcel
16130812Smarcel   You should have received a copy of the GNU General Public License
17130812Smarcel   along with this program; if not, write to the Free Software
18130812Smarcel   Foundation, Inc., 59 Temple Place - Suite 330,
19130812Smarcel   Boston, MA 02111-1307, USA.  */
20130812Smarcel
21130812Smarcel#include "defs.h"
22130812Smarcel#include "gdbcore.h"
23130812Smarcel#include "inferior.h"
24130812Smarcel#include "regcache.h"
25130812Smarcel#include "target.h"
26130812Smarcel#include "osabi.h"
27130812Smarcel
28130812Smarcel#include "i386-tdep.h"
29130812Smarcel
30130812Smarcel/* Return the PC of the caller from the call frame.  Assumes the subr
31130812Smarcel   prologue has already been executed, and the frame pointer setup.
32130812Smarcel   If this is the outermost frame, we check to see if we are in a
33130812Smarcel   system call by examining the previous instruction.  If so, then the
34130812Smarcel   return PC is actually at SP+4 because system calls use a different
35130812Smarcel   calling sequence.  */
36130812Smarcel
37130812Smarcelstatic CORE_ADDR
38130812Smarceli386lynx_saved_pc_after_call (struct frame_info *frame)
39130812Smarcel{
40130812Smarcel  char opcode[7];
41130812Smarcel  static const unsigned char call_inst[] =
42130812Smarcel  { 0x9a, 0, 0, 0, 0, 8, 0 };	/* lcall 0x8,0x0 */
43130812Smarcel
44130812Smarcel  read_memory_nobpt (frame->pc - 7, opcode, 7);
45130812Smarcel  if (memcmp (opcode, call_inst, 7) == 0)
46130812Smarcel    return read_memory_unsigned_integer (read_register (SP_REGNUM) + 4, 4);
47130812Smarcel
48130812Smarcel  return read_memory_unsigned_integer (read_register (SP_REGNUM), 4);
49130812Smarcel}
50130812Smarcel
51130812Smarcel
52130812Smarcel/* LynxOS.  */
53130812Smarcelstatic void
54130812Smarceli386lynx_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
55130812Smarcel{
56130812Smarcel  set_gdbarch_deprecated_saved_pc_after_call (gdbarch, i386lynx_saved_pc_after_call);
57130812Smarcel}
58130812Smarcel
59130812Smarcel
60130812Smarcelstatic enum gdb_osabi
61130812Smarceli386lynx_coff_osabi_sniffer (bfd *abfd)
62130812Smarcel{
63130812Smarcel  if (strcmp (bfd_get_target (abfd), "coff-i386-lynx") == 0)
64130812Smarcel    return GDB_OSABI_LYNXOS;
65130812Smarcel
66130812Smarcel  return GDB_OSABI_UNKNOWN;
67130812Smarcel}
68130812Smarcel
69130812Smarcel
70130812Smarcel/* Provide a prototype to silence -Wmissing-prototypes.  */
71130812Smarcelvoid _initialize_i386lynx_tdep (void);
72130812Smarcel
73130812Smarcelvoid
74130812Smarcel_initialize_i386lynx_tdep (void)
75130812Smarcel{
76130812Smarcel  gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
77130812Smarcel				  i386lynx_coff_osabi_sniffer);
78130812Smarcel
79130812Smarcel  gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LYNXOS,
80130812Smarcel			  i386lynx_init_abi);
81130812Smarcel}
82