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

📄 armos.c

📁 skyeye的开源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	res = read (f, local, len);	if (res > 0)		for (i = 0; i < res; i++)			ARMul_WriteByte (state, ptr + i, local[i]);	free (local);	state->Reg[0] = res == -1 ? -1 : len - res;	OSptr->ErrorNo = errno;}static voidSWIwrite (ARMul_State * state, ARMword f, ARMword ptr, ARMword len){	struct OSblock *OSptr = (struct OSblock *) state->OSptr;	int res;	ARMword i;	char *local = malloc (len);	if (local == NULL) {		fprintf (stderr,			 "sim: Unable to write 0x%lx bytes - out of memory\n",			 (int) len);		return;	}	for (i = 0; i < len; i++)		local[i] = ARMul_ReadByte (state, ptr + i);	res = write (f, local, len);	state->Reg[0] = res == -1 ? -1 : len - res;	free (local);	OSptr->ErrorNo = errno;}static voidSWIflen (ARMul_State * state, ARMword fh){	struct OSblock *OSptr = (struct OSblock *) state->OSptr;	ARMword addr;	if (fh == 0 || fh > FOPEN_MAX) {		OSptr->ErrorNo = EBADF;		state->Reg[0] = -1L;		return;	}	addr = lseek (fh, 0, SEEK_CUR);	state->Reg[0] = lseek (fh, 0L, SEEK_END);	(void) lseek (fh, addr, SEEK_SET);	OSptr->ErrorNo = errno;}/***************************************************************************\* The emulator calls this routine when a SWI instruction is encuntered. The ** parameter passed is the SWI number (lower 24 bits of the instruction).    *\***************************************************************************/unsignedARMul_OSHandleSWI (ARMul_State * state, ARMword number){	ARMword addr, temp;	struct OSblock *OSptr = (struct OSblock *) state->OSptr;	switch (number) {	case SWI_Read:		SWIread (state, state->Reg[0], state->Reg[1], state->Reg[2]);		return TRUE;	case SWI_Write:		SWIwrite (state, state->Reg[0], state->Reg[1], state->Reg[2]);		return TRUE;	case SWI_Open:		SWIopen (state, state->Reg[0], state->Reg[1]);		return TRUE;	case SWI_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;		return (TRUE);	case SWI_Time:		state->Reg[0] = (ARMword) time (NULL);		OSptr->ErrorNo = errno;		return (TRUE);	case SWI_Close:		state->Reg[0] = close (state->Reg[0]);		OSptr->ErrorNo = errno;		return TRUE;	case SWI_Flen:		SWIflen (state, state->Reg[0]);		return (TRUE);	case SWI_Exit:		state->Emulate = FALSE;		return TRUE;	case SWI_Seek:		{			/* We must return non-zero for failure */			state->Reg[0] =				-1 >= lseek (state->Reg[0], state->Reg[1],					     SEEK_SET);			OSptr->ErrorNo = errno;			return TRUE;		}	case SWI_WriteC:		(void) fputc ((int) state->Reg[0], stdout);		OSptr->ErrorNo = errno;		return (TRUE);	case SWI_Write0:		SWIWrite0 (state, state->Reg[0]);		return (TRUE);	case SWI_GetErrno:		state->Reg[0] = OSptr->ErrorNo;		return (TRUE);	case SWI_Breakpoint:		//chy 2005-09-12 change below line		//state->EndCondition = RDIError_BreakpointReached;		//printf ("SKYEYE: in armos.c : should not come here!!!!\n");		state->EndCondition = 0;		/*modified by ksh to support breakpoiont*/		state->Emulate = STOP;		return (TRUE);	case SWI_GetEnv:		state->Reg[0] = ADDRCMDLINE;		if (state->MemSize)			state->Reg[1] = state->MemSize;		else			state->Reg[1] = ADDRUSERSTACK;		WriteCommandLineTo (state, state->Reg[0]);		return (TRUE);		/* Handle Angel SWIs as well as Demon ones */	case AngelSWI_ARM:	case AngelSWI_Thumb:		/* R1 is almost always a parameter block */		addr = state->Reg[1];		/* R0 is a reason code */		switch (state->Reg[0]) {			/* 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;			return (TRUE);		case AngelSWI_Reason_Time:			state->Reg[0] = (ARMword) time (NULL);			OSptr->ErrorNo = errno;			return (TRUE);		case AngelSWI_Reason_WriteC:			(void) fputc ((int) ARMul_ReadByte (state, addr),				      stdout);			OSptr->ErrorNo = errno;			return (TRUE);		case AngelSWI_Reason_Write0:			SWIWrite0 (state, addr);			return (TRUE);		case AngelSWI_Reason_Close:			state->Reg[0] = close (ARMul_ReadWord (state, addr));			OSptr->ErrorNo = errno;			return (TRUE);		case AngelSWI_Reason_Seek:			state->Reg[0] =				-1 >= lseek (ARMul_ReadWord (state, addr),					     ARMul_ReadWord (state, addr + 4),					     SEEK_SET);			OSptr->ErrorNo = errno;			return (TRUE);		case AngelSWI_Reason_FLen:			SWIflen (state, ARMul_ReadWord (state, addr));			return (TRUE);		case AngelSWI_Reason_GetCmdLine:			WriteCommandLineTo (state,					    ARMul_ReadWord (state, addr));			return (TRUE);		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 */			return (TRUE);		case AngelSWI_Reason_ReportException:			if (state->Reg[1] == ADP_Stopped_ApplicationExit)				state->Reg[0] = 0;			else				state->Reg[0] = -1;			state->Emulate = FALSE;			return TRUE;		case ADP_Stopped_ApplicationExit:			state->Reg[0] = 0;			state->Emulate = FALSE;			return (TRUE);		case ADP_Stopped_RunTimeError:			state->Reg[0] = -1;			state->Emulate = FALSE;			return (TRUE);		case AngelSWI_Reason_Errno:			state->Reg[0] = OSptr->ErrorNo;			return (TRUE);		case AngelSWI_Reason_Open:			SWIopen (state,				 ARMul_ReadWord (state, addr),				 ARMul_ReadWord (state, addr + 4));			return TRUE;		case AngelSWI_Reason_Read:			SWIread (state,				 ARMul_ReadWord (state, addr),				 ARMul_ReadWord (state, addr + 4),				 ARMul_ReadWord (state, addr + 8));			return TRUE;		case AngelSWI_Reason_Write:			SWIwrite (state,				  ARMul_ReadWord (state, addr),				  ARMul_ReadWord (state, addr + 4),				  ARMul_ReadWord (state, addr + 8));			return TRUE;		}	default:#if 0		state->Emulate = FALSE;#endif		return (FALSE);	}}#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){				/* don't use this here */	return (FALSE);}#endif#endif /* NOOS */

⌨️ 快捷键说明

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