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

📄 traps.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* frv trap support   Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.   Contributed by Red Hat.This file is part of the GNU simulators.This program 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.This program 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 License alongwith this program; if not, write to the Free Software Foundation, Inc.,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */#define WANT_CPU frvbf#define WANT_CPU_FRVBF#include "sim-main.h"#include "targ-vals.h"#include "cgen-engine.h"#include "cgen-par.h"#include "sim-fpu.h"#include "bfd.h"#include "libiberty.h"CGEN_ATTR_VALUE_TYPE frv_current_fm_slot;/* The semantic code invokes this for invalid (unrecognized) instructions.  */SEM_PCsim_engine_invalid_insn (SIM_CPU *current_cpu, IADDR cia, SEM_PC vpc){  frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);  return vpc;}/* Process an address exception.  */voidfrv_core_signal (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia,		  unsigned int map, int nr_bytes, address_word addr,		  transfer_type transfer, sim_core_signals sig){  if (sig == sim_core_unaligned_signal)    {      if (STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr400	  || STATE_ARCHITECTURE (sd)->mach == bfd_mach_fr450)	frv_queue_data_access_error_interrupt (current_cpu, addr);      else	frv_queue_mem_address_not_aligned_interrupt (current_cpu, addr);    }  frv_term (sd);  sim_core_signal (sd, current_cpu, cia, map, nr_bytes, addr, transfer, sig);}voidfrv_sim_engine_halt_hook (SIM_DESC sd, SIM_CPU *current_cpu, sim_cia cia){  int i;  if (current_cpu != NULL)    CIA_SET (current_cpu, cia);  /* Invalidate the insn and data caches of all cpus.  */  for (i = 0; i < MAX_NR_PROCESSORS; ++i)    {      current_cpu = STATE_CPU (sd, i);      frv_cache_invalidate_all (CPU_INSN_CACHE (current_cpu), 0);      frv_cache_invalidate_all (CPU_DATA_CACHE (current_cpu), 1);    }  frv_term (sd);}/* Read/write functions for system call interface.  */static intsyscall_read_mem (host_callback *cb, struct cb_syscall *sc,		  unsigned long taddr, char *buf, int bytes){  SIM_DESC sd = (SIM_DESC) sc->p1;  SIM_CPU *cpu = (SIM_CPU *) sc->p2;  frv_cache_invalidate_all (CPU_DATA_CACHE (cpu), 1);  return sim_core_read_buffer (sd, cpu, read_map, buf, taddr, bytes);}static intsyscall_write_mem (host_callback *cb, struct cb_syscall *sc,		   unsigned long taddr, const char *buf, int bytes){  SIM_DESC sd = (SIM_DESC) sc->p1;  SIM_CPU *cpu = (SIM_CPU *) sc->p2;  frv_cache_invalidate_all (CPU_INSN_CACHE (cpu), 0);  frv_cache_invalidate_all (CPU_DATA_CACHE (cpu), 1);  return sim_core_write_buffer (sd, cpu, write_map, buf, taddr, bytes);}/* Handle TRA and TIRA insns.  */voidfrv_itrap (SIM_CPU *current_cpu, PCADDR pc, USI base, SI offset){  SIM_DESC sd = CPU_STATE (current_cpu);  host_callback *cb = STATE_CALLBACK (sd);  USI num = ((base + offset) & 0x7f) + 0x80;#ifdef SIM_HAVE_BREAKPOINTS  /* Check for breakpoints "owned" by the simulator first, regardless     of --environment.  */  if (num == TRAP_BREAKPOINT)    {      /* First try sim-break.c.  If it's a breakpoint the simulator "owns"	 it doesn't return.  Otherwise it returns and let's us try.  */      sim_handle_breakpoint (sd, current_cpu, pc);      /* Fall through.  */    }#endif  if (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)    {      frv_queue_software_interrupt (current_cpu, num);      return;    }  switch (num)    {    case TRAP_SYSCALL :      {	CB_SYSCALL s;	CB_SYSCALL_INIT (&s);	s.func = GET_H_GR (7);	s.arg1 = GET_H_GR (8);	s.arg2 = GET_H_GR (9);	s.arg3 = GET_H_GR (10);	if (s.func == TARGET_SYS_exit)	  {	    sim_engine_halt (sd, current_cpu, NULL, pc, sim_exited, s.arg1);	  }	s.p1 = (PTR) sd;	s.p2 = (PTR) current_cpu;	s.read_mem = syscall_read_mem;	s.write_mem = syscall_write_mem;	cb_syscall (cb, &s);	SET_H_GR (8, s.result);	SET_H_GR (9, s.result2);	SET_H_GR (10, s.errcode);	break;      }    case TRAP_BREAKPOINT:      sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);      break;      /* Add support for dumping registers, either at fixed traps, or all	 unknown traps if configured with --enable-sim-trapdump.  */    default:#if !TRAPDUMP      frv_queue_software_interrupt (current_cpu, num);      return;#endif#ifdef TRAP_REGDUMP1    case TRAP_REGDUMP1:#endif#ifdef TRAP_REGDUMP2    case TRAP_REGDUMP2:#endif#if TRAPDUMP || (defined (TRAP_REGDUMP1)) || (defined (TRAP_REGDUMP2))      {	char buf[256];	int i, j;	buf[0] = 0;	if (STATE_TEXT_SECTION (sd)	    && pc >= STATE_TEXT_START (sd)	    && pc < STATE_TEXT_END (sd))	  {	    const char *pc_filename = (const char *)0;	    const char *pc_function = (const char *)0;	    unsigned int pc_linenum = 0;	    if (bfd_find_nearest_line (STATE_PROG_BFD (sd),				       STATE_TEXT_SECTION (sd),				       (struct bfd_symbol **) 0,				       pc - STATE_TEXT_START (sd),				       &pc_filename, &pc_function, &pc_linenum)		&& (pc_function || pc_filename))	      {		char *p = buf+2;		buf[0] = ' ';		buf[1] = '(';		if (pc_function)		  {		    strcpy (p, pc_function);		    p += strlen (p);		  }		else		  {		    char *q = (char *) strrchr (pc_filename, '/');		    strcpy (p, (q) ? q+1 : pc_filename);		    p += strlen (p);		  }		if (pc_linenum)		  {		    sprintf (p, " line %d", pc_linenum);		    p += strlen (p);		  }		p[0] = ')';		p[1] = '\0';		if ((p+1) - buf > sizeof (buf))		  abort ();	      }	  }	sim_io_printf (sd,		       "\nRegister dump,    pc = 0x%.8x%s, base = %u, offset = %d\n",		       (unsigned)pc, buf, (unsigned)base, (int)offset);	for (i = 0; i < 64; i += 8)	  {	    long g0 = (long)GET_H_GR (i);	    long g1 = (long)GET_H_GR (i+1);	    long g2 = (long)GET_H_GR (i+2);	    long g3 = (long)GET_H_GR (i+3);	    long g4 = (long)GET_H_GR (i+4);	    long g5 = (long)GET_H_GR (i+5);	    long g6 = (long)GET_H_GR (i+6);	    long g7 = (long)GET_H_GR (i+7);	    if ((g0 | g1 | g2 | g3 | g4 | g5 | g6 | g7) != 0)	      sim_io_printf (sd,			     "\tgr%02d - gr%02d:   0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx\n",			     i, i+7, g0, g1, g2, g3, g4, g5, g6, g7);	  }	for (i = 0; i < 64; i += 8)	  {	    long f0 = (long)GET_H_FR (i);	    long f1 = (long)GET_H_FR (i+1);	    long f2 = (long)GET_H_FR (i+2);	    long f3 = (long)GET_H_FR (i+3);	    long f4 = (long)GET_H_FR (i+4);	    long f5 = (long)GET_H_FR (i+5);	    long f6 = (long)GET_H_FR (i+6);	    long f7 = (long)GET_H_FR (i+7);	    if ((f0 | f1 | f2 | f3 | f4 | f5 | f6 | f7) != 0)	      sim_io_printf (sd,			     "\tfr%02d - fr%02d:   0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx\n",			     i, i+7, f0, f1, f2, f3, f4, f5, f6, f7);	  }	sim_io_printf (sd,		       "\tlr/lcr/cc/ccc: 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx\n",		       (long)GET_H_SPR (272),		       (long)GET_H_SPR (273),		       (long)GET_H_SPR (256),		       (long)GET_H_SPR (263));      }      break;#endif    }}/* Handle the MTRAP insn.  */voidfrv_mtrap (SIM_CPU *current_cpu){  SIM_DESC sd = CPU_STATE (current_cpu);  /* Check the status of media exceptions in MSR0.  */  SI msr = GET_MSR (0);  if (GET_MSR_AOVF (msr) || GET_MSR_MTT (msr) && STATE_ARCHITECTURE (sd)->mach != bfd_mach_fr550)    frv_queue_program_interrupt (current_cpu, FRV_MP_EXCEPTION);}/* Handle the BREAK insn.  */voidfrv_break (SIM_CPU *current_cpu){  IADDR pc;  SIM_DESC sd = CPU_STATE (current_cpu);#ifdef SIM_HAVE_BREAKPOINTS  /* First try sim-break.c.  If it's a breakpoint the simulator "owns"     it doesn't return.  Otherwise it returns and let's us try.  */  pc = GET_H_PC ();  sim_handle_breakpoint (sd, current_cpu, pc);  /* Fall through.  */#endif  if (STATE_ENVIRONMENT (sd) != OPERATING_ENVIRONMENT)    {      /* Invalidate the insn cache because the debugger will presumably	 replace the breakpoint insn with the real one.  */#ifndef SIM_HAVE_BREAKPOINTS      pc = GET_H_PC ();#endif      sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);    }  frv_queue_break_interrupt (current_cpu);}/* Return from trap.  */USIfrv_rett (SIM_CPU *current_cpu, PCADDR pc, BI debug_field){  USI new_pc;  /* if (normal running mode and debug_field==0       PC=PCSR       PSR.ET=1       PSR.S=PSR.PS     else if (debug running mode and debug_field==1)       PC=(BPCSR)       PSR.ET=BPSR.BET       PSR.S=BPSR.BS       change to normal running mode  */  int psr_s = GET_H_PSR_S ();  int psr_et = GET_H_PSR_ET ();  /* Check for exceptions in the priority order listed in the FRV Architecture     Volume 2.  */  if (! psr_s)    {      /* Halt if PSR.ET is not set.  See chapter 6 of the LSI.  */      if (! psr_et)	{	  SIM_DESC sd = CPU_STATE (current_cpu);	  sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);	}      /* privileged_instruction interrupt will have already been queued by	 frv_detect_insn_access_interrupts.  */      new_pc = pc + 4;    }  else if (psr_et)    {      /* Halt if PSR.S is set.  See chapter 6 of the LSI.  */      if (psr_s)	{	  SIM_DESC sd = CPU_STATE (current_cpu);	  sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);	}      frv_queue_program_interrupt (current_cpu, FRV_ILLEGAL_INSTRUCTION);      new_pc = pc + 4;    }  else if (! CPU_DEBUG_STATE (current_cpu) && debug_field == 0)    {      USI psr = GET_PSR ();      /* Return from normal running state.  */      new_pc = GET_H_SPR (H_SPR_PCSR);      SET_PSR_ET (psr, 1);      SET_PSR_S (psr, GET_PSR_PS (psr));      sim_queue_fn_si_write (current_cpu, frvbf_h_spr_set, H_SPR_PSR, psr);    }  else if (CPU_DEBUG_STATE (current_cpu) && debug_field == 1)    {      USI psr = GET_PSR ();      /* Return from debug state.  */      new_pc = GET_H_SPR (H_SPR_BPCSR);      SET_PSR_ET (psr, GET_H_BPSR_BET ());      SET_PSR_S (psr, GET_H_BPSR_BS ());      sim_queue_fn_si_write (current_cpu, frvbf_h_spr_set, H_SPR_PSR, psr);      CPU_DEBUG_STATE (current_cpu) = 0;    }  else    new_pc = pc + 4;  return new_pc;}/* Functions for handling non-excepting instruction side effects.  */static SI next_available_nesr (SIM_CPU *current_cpu, SI current_index){  FRV_REGISTER_CONTROL *control = CPU_REGISTER_CONTROL (current_cpu);  if (control->spr[H_SPR_NECR].implemented)    {      int limit;      USI necr = GET_NECR ();      /* See if any NESRs are implemented. First need to check the validity of	 the NECR.  */      if (! GET_NECR_VALID (necr))	return NO_NESR;      limit = GET_NECR_NEN (necr);      for (++current_index; current_index < limit; ++current_index)	{	  SI nesr = GET_NESR (current_index);	  if (! GET_NESR_VALID (nesr))	    return current_index;	}    }  return NO_NESR;}static SI next_valid_nesr (SIM_CPU *current_cpu, SI current_index){  FRV_REGISTER_CONTROL *control = CPU_REGISTER_CONTROL (current_cpu);  if (control->spr[H_SPR_NECR].implemented)    {      int limit;      USI necr = GET_NECR ();      /* See if any NESRs are implemented. First need to check the validity of	 the NECR.  */      if (! GET_NECR_VALID (necr))	return NO_NESR;      limit = GET_NECR_NEN (necr);      for (++current_index; current_index < limit; ++current_index)	{	  SI nesr = GET_NESR (current_index);	  if (GET_NESR_VALID (nesr))	    return current_index;	}    }  return NO_NESR;}BIfrvbf_check_non_excepting_load (  SIM_CPU *current_cpu, SI base_index, SI disp_index, SI target_index,  SI immediate_disp, QI data_size, BI is_float){  BI rc = 1; /* perform the load.  */  SIM_DESC sd = CPU_STATE (current_cpu);  int daec = 0;  int rec  = 0;  int ec   = 0;  USI necr;  int do_elos;  SI NE_flags[2];  SI NE_base;  SI nesr;  SI ne_index;  FRV_REGISTER_CONTROL *control;  SI address = GET_H_GR (base_index);  if (disp_index >= 0)    address += GET_H_GR (disp_index);  else    address += immediate_disp;  /* Check for interrupt factors.  */  switch (data_size)    {    case NESR_UQI_SIZE:    case NESR_QI_SIZE:      break;    case NESR_UHI_SIZE:    case NESR_HI_SIZE:      if (address & 1)	ec = 1;      break;    case NESR_SI_SIZE:      if (address & 3)	ec = 1;      break;    case NESR_DI_SIZE:      if (address & 7)	ec = 1;      if (target_index & 1)	rec = 1;      break;    case NESR_XI_SIZE:      if (address & 0xf)	ec = 1;      if (target_index & 3)	rec = 1;      break;    default:      {	IADDR pc = GET_H_PC ();	sim_engine_abort (sd, current_cpu, pc, 			  "check_non_excepting_load: Incorrect data_size\n");	break;      }    }  control = CPU_REGISTER_CONTROL (current_cpu);  if (control->spr[H_SPR_NECR].implemented)    {      necr = GET_NECR ();      do_elos = GET_NECR_VALID (necr) && GET_NECR_ELOS (necr);    }  else    do_elos = 0;

⌨️ 快捷键说明

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