⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 support.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* support routines for interpreted instructions   Copyright (C) 1992, 1993 Free Software Foundation, Inc.This file is part of Z8KSIMZ8KSIM is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.Z8KSIM is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with Z8KZIM; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */#include "config.h"#include <ansidecl.h>#include <signal.h>#include <errno.h>#include "tm.h"#include "sim.h"#include "mem.h"#include <stdio.h>#ifdef HAVE_TIME_H#include <time.h>#endif#ifdef HAVE_SYS_TIMES_H#include <sys/times.h>#endif#include <sys/types.h>#include <sys/stat.h>#include <sys/param.h>#include "gdb/callback.h"#include "gdb/remote-sim.h"#include "syscall.h"static int get_now PARAMS ((void));static int now_persec PARAMS ((void));static int put_long PARAMS ((sim_state_type * context, int ptr, int value));static int put_short PARAMS ((sim_state_type * context, int ptr, int value));int sim_z8001_mode;static intget_now (){#ifdef HAVE_SYS_TIMES_H  struct tms b;  times (&b);  return b.tms_utime + b.tms_stime;#else  return time (0);#endif}static intnow_persec (){  return 50;}/* #define LOG /* define this to print instruction use counts */#ifdef __GNUC__#define INLINE __inline__#include "inlines.h"#else#include "inlines.h"#endif/* This holds the entire cpu context */static sim_state_type the_state;intfail (context, dummy)     sim_state_type *context;     int dummy;{  context->exception = SIM_BAD_INST;  return 1;}voidsfop_bad1 (context)     sim_state_type *context;{  context->exception    = SIM_BAD_INST;}voidbfop_bad1 (context)     sim_state_type *context;{  context->exception    = SIM_BAD_INST;}voidfop_bad (context)     sim_state_type *context;{  context->exception =    SIM_BAD_INST;}/* Table of bit counts for all byte values */char the_parity[256] ={  0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3,  4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4,  4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2,  3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5,  4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4,  5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3,  3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2,  3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,  4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5,  6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5,  5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6,  7, 7, 8};int read ();int write ();int open ();int close ();int open ();int close ();int link ();int fstat ();static intput_short (context, ptr, value)     sim_state_type *context;     int ptr;     int value;{  put_word_mem_da (context, ptr, value);  return ptr + 2;}static intput_long (context, ptr, value)     sim_state_type *context;     int       ptr;     int value;{  put_long_mem_da (context, ptr, value);  return ptr + 4;}#define aptr(x) ((sitoptr(x)) + (char *)(context->memory))static int args[3];static int arg_index;		/* Translate a z8k system call into a host system call */voidsupport_call (context, sc)     sim_state_type *context;     int sc;{  extern int errno;  int ret;  int retnext = 0;  int fd;  int olderrno = errno;  errno = 0;  switch (sc)    {    case SYS_ARG:      args[arg_index++] = context->regs[0].word << 16 | context->regs[1].word;      break;    case SYS_exit:      context->exception = SIM_DONE;      ret = args[0];      arg_index = 0;      break;    case SYS_close:      ret = close ((int) (args[0]));      arg_index = 0;      break;    case SYS_creat:      ret = creat (aptr (args[0]), args[1]);      arg_index = 0;      break;    case SYS_isatty:      ret = isatty (args[0]);      arg_index = 0;      break;    case SYS_open:      ret = open (aptr (args[0]), args[1], args[2]);      arg_index = 0;      break;    case SYS_lseek:      ret = lseek (args[0], (off_t) args[1], args[2]);      arg_index = 0;      break;    case SYS_read:      ret = read (args[0], aptr (args[1]), args[2]);      arg_index = 0;      break;    case SYS_write:      ret = write (args[0],aptr (args[1]), args[2]);      arg_index = 0;      break;    case SYS_time:      {	int dst = args[0];	ret = time (0);	if (dst)	  {	    put_long_mem_da (context,			     sitoptr (dst), ret);	  }	retnext = ret;	ret = retnext >> 16;	arg_index = 0;      }      break;    case SYS_fstat:      {	int buf;	struct stat host_stat;	fd = args[0];	buf = sitoptr (args[1]);	ret = fstat (fd, &host_stat);	buf = put_short (context, buf, host_stat.st_dev);	buf = put_short (context, buf, host_stat.st_ino);	/* FIXME: Isn't mode_t 4 bytes?  */	buf = put_short (context, buf, host_stat.st_mode);	buf = put_short (context, buf, host_stat.st_nlink);	buf = put_short (context, buf, host_stat.st_uid);	buf = put_short (context, buf, host_stat.st_uid);	buf = put_short (context, buf, host_stat.st_rdev);	buf = put_long (context, buf, host_stat.st_size);	buf = put_long (context, buf, host_stat.st_atime);	arg_index = 0;      } break;    default:    case SYS_link:      context->exception = SIM_BAD_SYSCALL;      arg_index = 0;      break;    }  context->regs[2].word = ret;  context->regs[3].word = retnext;  context->regs[5].word = errno;  /* support for the stdcall calling convention */  context->regs[6].word = retnext;  context->regs[7].word = ret;  errno = olderrno;}#undef get_word_mem_daintget_word_mem_da (context, addr)     sim_state_type *context;     int addr;{  return (get_byte_mem_da (context, addr) << 8) | (get_byte_mem_da (context, addr + 1));}#undef get_word_regint get_word_reg (context, reg) sim_state_type* context;     int reg;{  return context->regs[reg].word;}#ifdef LOGint log[64 * 1024];#endifvoidtm_store_register (regno, value)     int regno;     int value;{  switch    (regno)    {    case REG_PC:      the_state.sometimes_pc = value;      break;    default:      put_word_reg (&the_state, regno, value);    }}voidswap_long (buf, val)     char *buf;     int val;{  buf[0] = val >> 24;  buf[1] = val >> 16;  buf[2] = val >> 8;  buf[3] = val >> 0;}voidswap_word (buf, val)     char *buf;     int val;{  buf[0] = val >> 8;  buf[1] = val >> 0;}voidtm_fetch_register (regno, buf)     int regno;     char *buf;{  switch    (regno)    {    case REG_CYCLES:      swap_long (buf, the_state.cycles);      break;    case REG_INSTS:      swap_long (buf, the_state.insts);      break;      case    REG_TIME:      swap_long (buf, the_state.ticks);      break;    case REG_PC:      swap_long (buf, the_state.sometimes_pc);      break;    case REG_SP:      {	if (sim_z8001_mode)	  {	    swap_long (buf, get_long_reg (&the_state, 14));	  }	else	  {	    swap_long (buf, get_word_reg (&the_state, 15));	  }      }      break;      case    REG_FP:      {	if (sim_z8001_mode)	  {	    swap_long (buf, get_long_reg		       (&the_state, 10));	  }	else	  {	    swap_long (buf,		       get_word_reg (&the_state, 10));	  }      }      break;    default:      {	swap_word (buf,		   get_word_reg (&the_state, regno));      }    }}voidtm_resume (step)     int step;{  int now = get_now ();  struct op_info

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -