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

📄 armos.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
      break;    case SWI_Open:      if (swi_mask & SWI_MASK_DEMON)	SWIopen (state, state->Reg[0], state->Reg[1]);      else	unhandled = TRUE;      break;    case SWI_Clock:      if (swi_mask & SWI_MASK_DEMON)	{	  /* Return number of centi-seconds.  */	  state->Reg[0] =#ifdef CLOCKS_PER_SEC	    (CLOCKS_PER_SEC >= 100)	    ? (ARMword) (clock () / (CLOCKS_PER_SEC / 100))	    : (ARMword) ((clock () * 100) / CLOCKS_PER_SEC);#else	  /* Presume unix... clock() returns microseconds.  */	  (ARMword) (clock () / 10000);#endif	  OSptr->ErrorNo = errno;	}      else	unhandled = TRUE;      break;    case SWI_Time:      if (swi_mask & SWI_MASK_DEMON)	{	  state->Reg[0] = (ARMword) sim_callback->time (sim_callback, NULL);	  OSptr->ErrorNo = sim_callback->get_errno (sim_callback);	}      else	unhandled = TRUE;      break;    case SWI_Close:      if (swi_mask & SWI_MASK_DEMON)	{	  state->Reg[0] = sim_callback->close (sim_callback, state->Reg[0]);	  OSptr->ErrorNo = sim_callback->get_errno (sim_callback);	}      else	unhandled = TRUE;      break;    case SWI_Flen:      if (swi_mask & SWI_MASK_DEMON)	SWIflen (state, state->Reg[0]);      else	unhandled = TRUE;      break;    case SWI_Exit:      if (swi_mask & SWI_MASK_DEMON)	state->Emulate = FALSE;      else	unhandled = TRUE;      break;    case SWI_Seek:      if (swi_mask & SWI_MASK_DEMON)	{	  /* We must return non-zero for failure.  */	  state->Reg[0] = -1 >= sim_callback->lseek (sim_callback, state->Reg[0], state->Reg[1], SEEK_SET);	  OSptr->ErrorNo = sim_callback->get_errno (sim_callback);	}      else	unhandled = TRUE;      break;    case SWI_WriteC:      if (swi_mask & SWI_MASK_DEMON)	{	  char tmp = state->Reg[0];	  (void) sim_callback->write_stdout (sim_callback, &tmp, 1);	  OSptr->ErrorNo = sim_callback->get_errno (sim_callback);	}      else	unhandled = TRUE;      break;    case SWI_Write0:      if (swi_mask & SWI_MASK_DEMON)	SWIWrite0 (state, state->Reg[0]);      else	unhandled = TRUE;      break;    case SWI_GetErrno:      if (swi_mask & SWI_MASK_DEMON)	state->Reg[0] = OSptr->ErrorNo;      else	unhandled = TRUE;      break;    case SWI_GetEnv:      if (swi_mask & SWI_MASK_DEMON)	{	  state->Reg[0] = ADDRCMDLINE;	  if (state->MemSize)	    state->Reg[1] = state->MemSize;	  else	    state->Reg[1] = ADDRUSERSTACK;	  WriteCommandLineTo (state, state->Reg[0]);	}      else	unhandled = TRUE;      break;    case SWI_Breakpoint:      state->EndCondition = RDIError_BreakpointReached;      state->Emulate = FALSE;      break;      /* Handle Angel SWIs as well as Demon ones.  */    case AngelSWI_ARM:    case AngelSWI_Thumb:      if (swi_mask & SWI_MASK_ANGEL)	{	  ARMword addr;	  ARMword temp;	  /* R1 is almost always a parameter block.  */	  addr = state->Reg[1];	  /* R0 is a reason code.  */	  switch (state->Reg[0])	    {	    case -1:	      /* This can happen when a SWI is interrupted (eg receiving a		 ctrl-C whilst processing SWIRead()).  The SWI will complete		 returning -1 in r0 to the caller.  If GDB is then used to		 resume the system call the reason code will now be -1.  */	      return TRUE;	  	      /* Unimplemented reason codes.  */	    case AngelSWI_Reason_ReadC:	    case AngelSWI_Reason_IsTTY:	    case AngelSWI_Reason_TmpNam:	    case AngelSWI_Reason_Remove:	    case AngelSWI_Reason_Rename:	    case AngelSWI_Reason_System:	    case AngelSWI_Reason_EnterSVC:	    default:	      state->Emulate = FALSE;	      return FALSE;	    case AngelSWI_Reason_Clock:	      /* Return number of centi-seconds.  */	      state->Reg[0] =#ifdef CLOCKS_PER_SEC		(CLOCKS_PER_SEC >= 100)		? (ARMword) (clock () / (CLOCKS_PER_SEC / 100))		: (ARMword) ((clock () * 100) / CLOCKS_PER_SEC);#else	      /* Presume unix... clock() returns microseconds.  */	      (ARMword) (clock () / 10000);#endif	      OSptr->ErrorNo = errno;	      break;	    case AngelSWI_Reason_Time:	      state->Reg[0] = (ARMword) sim_callback->time (sim_callback, NULL);	      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);	      break;	    case AngelSWI_Reason_WriteC:	      {		char tmp = ARMul_SafeReadByte (state, addr);		(void) sim_callback->write_stdout (sim_callback, &tmp, 1);		OSptr->ErrorNo = sim_callback->get_errno (sim_callback);		break;	      }	    case AngelSWI_Reason_Write0:	      SWIWrite0 (state, addr);	      break;	    case AngelSWI_Reason_Close:	      state->Reg[0] = sim_callback->close (sim_callback, ARMul_ReadWord (state, addr));	      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);	      break;	    case AngelSWI_Reason_Seek:	      state->Reg[0] = -1 >= sim_callback->lseek (sim_callback, ARMul_ReadWord (state, addr),							 ARMul_ReadWord (state, addr + 4),							 SEEK_SET);	      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);	      break;	    case AngelSWI_Reason_FLen:	      SWIflen (state, ARMul_ReadWord (state, addr));	      break;	    case AngelSWI_Reason_GetCmdLine:	      WriteCommandLineTo (state, ARMul_ReadWord (state, addr));	      break;	    case AngelSWI_Reason_HeapInfo:	      /* R1 is a pointer to a pointer.  */	      addr = ARMul_ReadWord (state, addr);	      /* Pick up the right memory limit.  */	      if (state->MemSize)		temp = state->MemSize;	      else		temp = ADDRUSERSTACK;	      ARMul_WriteWord (state, addr, 0);		/* Heap base.  */	      ARMul_WriteWord (state, addr + 4, temp);	/* Heap limit.  */	      ARMul_WriteWord (state, addr + 8, temp);	/* Stack base.  */	      ARMul_WriteWord (state, addr + 12, temp);	/* Stack limit.  */	      break;	    case AngelSWI_Reason_ReportException:	      if (state->Reg[1] == ADP_Stopped_ApplicationExit)		state->Reg[0] = 0;	      else		state->Reg[0] = -1;	      state->Emulate = FALSE;	      break;	    case ADP_Stopped_ApplicationExit:	      state->Reg[0] = 0;	      state->Emulate = FALSE;	      break;	    case ADP_Stopped_RunTimeError:	      state->Reg[0] = -1;	      state->Emulate = FALSE;	      break;	    case AngelSWI_Reason_Errno:	      state->Reg[0] = OSptr->ErrorNo;	      break;	    case AngelSWI_Reason_Open:	      SWIopen (state,		       ARMul_ReadWord (state, addr),		       ARMul_ReadWord (state, addr + 4));	      break;	    case AngelSWI_Reason_Read:	      SWIread (state,		       ARMul_ReadWord (state, addr),		       ARMul_ReadWord (state, addr + 4),		       ARMul_ReadWord (state, addr + 8));	      break;	    case AngelSWI_Reason_Write:	      SWIwrite (state,			ARMul_ReadWord (state, addr),			ARMul_ReadWord (state, addr + 4),			ARMul_ReadWord (state, addr + 8));	      break;	    }	}      else	unhandled = TRUE;      break;      /* The following SWIs are generated by the softvectorcode[]	 installed by default by the simulator.  */    case 0x91: /* Undefined Instruction.  */      {	ARMword addr = state->RegBank[UNDEFBANK][14] - 4;		sim_callback->printf_filtered	  (sim_callback, "sim: exception: Unhandled Instruction '0x%08x' at 0x%08x.  Stopping.\n",	   ARMul_ReadWord (state, addr), addr);	state->EndCondition = RDIError_SoftwareInterrupt;	state->Emulate = FALSE;	return FALSE;      }          case 0x90: /* Reset.  */    case 0x92: /* SWI.  */      /* These two can be safely ignored.  */      break;    case 0x93: /* Prefetch Abort.  */    case 0x94: /* Data Abort.  */    case 0x95: /* Address Exception.  */    case 0x96: /* IRQ.  */    case 0x97: /* FIQ.  */    case 0x98: /* Error.  */      unhandled = TRUE;      break;    case -1:      /* This can happen when a SWI is interrupted (eg receiving a	 ctrl-C whilst processing SWIRead()).  The SWI will complete	 returning -1 in r0 to the caller.  If GDB is then used to	 resume the system call the reason code will now be -1.  */      return TRUE;	      case 0x180001: /* RedBoot's Syscall SWI in ARM mode.  */      if (swi_mask & SWI_MASK_REDBOOT)	{	  switch (state->Reg[0])	    {	      /* These numbers are defined in libgloss/syscall.h		 but the simulator should not be dependend upon		 libgloss being installed.  */	    case 1:  /* Exit.  */	      state->Emulate = FALSE;	      /* Copy exit code into r0.  */	      state->Reg[0] = state->Reg[1];	      break;	    case 2:  /* Open.  */	      SWIopen (state, state->Reg[1], state->Reg[2]);	      break;	    case 3:  /* Close.  */	      state->Reg[0] = sim_callback->close (sim_callback, state->Reg[1]);	      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);	      break;	    case 4:  /* Read.  */	      SWIread (state, state->Reg[1], state->Reg[2], state->Reg[3]);	      break;	    case 5:  /* Write.  */	      SWIwrite (state, state->Reg[1], state->Reg[2], state->Reg[3]);	      break;	    case 6:  /* Lseek.  */	      state->Reg[0] = sim_callback->lseek (sim_callback,						   state->Reg[1],						   state->Reg[2],						   state->Reg[3]);	      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);	      break;	    case 17: /* Utime.  */	      state->Reg[0] = (ARMword) sim_callback->time (sim_callback,							    (long *) state->Reg[1]);	      OSptr->ErrorNo = sim_callback->get_errno (sim_callback);	      break;	    case 7:  /* Unlink.  */	    case 8:  /* Getpid.  */	    case 9:  /* Kill.  */	    case 10: /* Fstat.  */	    case 11: /* Sbrk.  */	    case 12: /* Argvlen.  */	    case 13: /* Argv.  */	    case 14: /* ChDir.  */	    case 15: /* Stat.  */	    case 16: /* Chmod.  */	    case 18: /* Time.  */	      sim_callback->printf_filtered		(sim_callback,		 "sim: unhandled RedBoot syscall '%d' encountered - ignoring\n",		 state->Reg[0]);	      return FALSE;	    default:	      sim_callback->printf_filtered		(sim_callback,		 "sim: unknown RedBoot syscall '%d' encountered - ignoring\n",		 state->Reg[0]);	      return FALSE;	    }	  break;	}          default:      unhandled = TRUE;    }        if (unhandled)    {      if (SWI_vector_installed)	{	  ARMword cpsr;	  ARMword i_size;	  cpsr = ARMul_GetCPSR (state);	  i_size = INSN_SIZE;	  ARMul_SetSPSR (state, SVC32MODE, cpsr);	  cpsr &= ~0xbf;	  cpsr |= SVC32MODE | 0x80;	  ARMul_SetCPSR (state, cpsr);	  state->RegBank[SVCBANK][14] = state->Reg[14] = state->Reg[15] - i_size;	  state->NextInstr            = RESUME;	  state->Reg[15]              = state->pc = ARMSWIV;	  FLUSHPIPE;	}      else	{	  sim_callback->printf_filtered	    (sim_callback,	     "sim: unknown SWI encountered - %x - ignoring\n",	     number);	  return FALSE;	}    }  return TRUE;}#ifndef NOOS#ifndef ASIM/* The emulator calls this routine when an Exception occurs.  The second   parameter is the address of the relevant exception vector.  Returning   FALSE from this routine causes the trap to be taken, TRUE causes it to   be ignored (so set state->Emulate to FALSE!).  */unsignedARMul_OSException (ARMul_State * state  ATTRIBUTE_UNUSED,		   ARMword       vector ATTRIBUTE_UNUSED,		   ARMword       pc     ATTRIBUTE_UNUSED){  return FALSE;}#endif#endif /* NOOS */

⌨️ 快捷键说明

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