Support the RedBoot SWI in ARM mode and some of its system calls.

This commit is contained in:
Nick Clifton 2002-05-09 10:14:12 +00:00
parent 412167cbaa
commit d8512e6afd
2 changed files with 109 additions and 30 deletions

View file

@ -1,3 +1,8 @@
2002-05-09 Nick Clifton <nickc@cambridge.redhat.com>
* armos.c (ARMul_OSHandleSWI): Support the RedBoot SWI in ARM
mode and some of its system calls.
2002-03-17 Anthony Green <green@redhat.com> 2002-03-17 Anthony Green <green@redhat.com>
* wrapper.c (mem_size): Increase the default target memory to 8MB. * wrapper.c (mem_size): Increase the default target memory to 8MB.

View file

@ -48,7 +48,7 @@
#endif #endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> /* For SEEK_SET etc */ #include <unistd.h> /* For SEEK_SET etc. */
#endif #endif
#ifdef __riscos #ifdef __riscos
@ -86,13 +86,12 @@ extern int _fisatty (FILE *);
#include "callback.h" #include "callback.h"
extern host_callback *sim_callback; extern host_callback *sim_callback;
extern unsigned ARMul_OSInit (ARMul_State * state); extern unsigned ARMul_OSInit (ARMul_State *);
extern void ARMul_OSExit (ARMul_State * state); extern void ARMul_OSExit (ARMul_State *);
extern unsigned ARMul_OSHandleSWI (ARMul_State * state, ARMword number); extern unsigned ARMul_OSHandleSWI (ARMul_State *, ARMword);
extern unsigned ARMul_OSException (ARMul_State * state, ARMword vector, extern unsigned ARMul_OSException (ARMul_State *, ARMword, ARMword);
ARMword pc); extern ARMword ARMul_OSLastErrorP (ARMul_State *);
extern ARMword ARMul_OSLastErrorP (ARMul_State * state); extern ARMword ARMul_Debug (ARMul_State *, ARMword, ARMword);
extern ARMword ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr);
#define BUFFERSIZE 4096 #define BUFFERSIZE 4096
#ifndef FOPEN_MAX #ifndef FOPEN_MAX
@ -164,15 +163,15 @@ ARMul_OSInit (ARMul_State * state)
OSptr = (struct OSblock *) state->OSptr; OSptr = (struct OSblock *) state->OSptr;
OSptr->ErrorP = 0; OSptr->ErrorP = 0;
state->Reg[13] = ADDRSUPERSTACK; /* set up a stack for the current mode */ state->Reg[13] = ADDRSUPERSTACK; /* Set up a stack for the current mode... */
ARMul_SetReg (state, SVC32MODE, 13, ADDRSUPERSTACK); /* and for supervisor mode */ ARMul_SetReg (state, SVC32MODE, 13, ADDRSUPERSTACK);/* ...and for supervisor mode... */
ARMul_SetReg (state, ABORT32MODE, 13, ADDRSUPERSTACK); /* and for abort 32 mode */ ARMul_SetReg (state, ABORT32MODE, 13, ADDRSUPERSTACK);/* ...and for abort 32 mode... */
ARMul_SetReg (state, UNDEF32MODE, 13, ADDRSUPERSTACK); /* and for undef 32 mode */ ARMul_SetReg (state, UNDEF32MODE, 13, ADDRSUPERSTACK);/* ...and for undef 32 mode... */
ARMul_SetReg (state, SYSTEMMODE, 13, ADDRSUPERSTACK); /* and for system mode */ ARMul_SetReg (state, SYSTEMMODE, 13, ADDRSUPERSTACK);/* ...and for system mode. */
instr = 0xe59ff000 | (ADDRSOFTVECTORS - 8); /* load pc from soft vector */ instr = 0xe59ff000 | (ADDRSOFTVECTORS - 8); /* Load pc from soft vector */
for (i = ARMul_ResetV; i <= ARMFIQV; i += 4) for (i = ARMul_ResetV; i <= ARMFIQV; i += 4)
ARMul_WriteWord (state, i, instr); /* write hardware vectors */ ARMul_WriteWord (state, i, instr); /* Write hardware vectors. */
SWI_vector_installed = 0; SWI_vector_installed = 0;
@ -196,16 +195,19 @@ ARMul_OSInit (ARMul_State * state)
/* #ifndef ASIM */ /* #ifndef ASIM */
/* install fpe */ /* Install FPE. */
for (i = 0; i < fpesize; i += 4) /* copy the code */ for (i = 0; i < fpesize; i += 4)
/* Copy the code. */
ARMul_WriteWord (state, FPESTART + i, fpecode[i >> 2]); ARMul_WriteWord (state, FPESTART + i, fpecode[i >> 2]);
for (i = FPESTART + fpesize;; i -= 4) for (i = FPESTART + fpesize;; i -= 4)
{ /* reverse the error strings */ {
/* Reverse the error strings. */
if ((j = ARMul_ReadWord (state, i)) == 0xffffffff) if ((j = ARMul_ReadWord (state, i)) == 0xffffffff)
break; break;
if (state->bigendSig && j < 0x80000000) if (state->bigendSig && j < 0x80000000)
{ /* it's part of the string so swap it */ {
/* It's part of the string so swap it. */
j = ((j >> 0x18) & 0x000000ff) | j = ((j >> 0x18) & 0x000000ff) |
((j >> 0x08) & 0x0000ff00) | ((j >> 0x08) & 0x0000ff00) |
((j << 0x08) & 0x00ff0000) | ((j << 0x18) & 0xff000000); ((j << 0x08) & 0x00ff0000) | ((j << 0x18) & 0xff000000);
@ -213,8 +215,10 @@ ARMul_OSInit (ARMul_State * state)
} }
} }
ARMul_WriteWord (state, FPEOLDVECT, ARMul_ReadWord (state, 4)); /* copy old illegal instr vector */ /* Copy old illegal instr vector. */
ARMul_WriteWord (state, 4, FPENEWVECT (ARMul_ReadWord (state, i - 4))); /* install new vector */ ARMul_WriteWord (state, FPEOLDVECT, ARMul_ReadWord (state, 4));
/* Install new vector. */
ARMul_WriteWord (state, 4, FPENEWVECT (ARMul_ReadWord (state, i - 4)));
ARMul_ConsolePrint (state, ", FPE"); ARMul_ConsolePrint (state, ", FPE");
/* #endif ASIM */ /* #endif ASIM */
@ -321,7 +325,9 @@ SWIread (ARMul_State * state, ARMword f, ARMword ptr, ARMword len)
if (local == NULL) if (local == NULL)
{ {
sim_callback->printf_filtered (sim_callback, "sim: Unable to read 0x%ulx bytes - out of memory\n", sim_callback->printf_filtered
(sim_callback,
"sim: Unable to read 0x%ulx bytes - out of memory\n",
len); len);
return; return;
} }
@ -346,7 +352,9 @@ SWIwrite (ARMul_State * state, ARMword f, ARMword ptr, ARMword len)
if (local == NULL) if (local == NULL)
{ {
sim_callback->printf_filtered (sim_callback, "sim: Unable to write 0x%lx bytes - out of memory\n", sim_callback->printf_filtered
(sim_callback,
"sim: Unable to write 0x%lx bytes - out of memory\n",
(long) len); (long) len);
return; return;
} }
@ -580,10 +588,10 @@ ARMul_OSHandleSWI (ARMul_State * state, ARMword number)
else else
temp = ADDRUSERSTACK; temp = ADDRUSERSTACK;
ARMul_WriteWord (state, addr, 0); /* Heap base */ ARMul_WriteWord (state, addr, 0); /* Heap base. */
ARMul_WriteWord (state, addr + 4, temp); /* Heap limit */ ARMul_WriteWord (state, addr + 4, temp); /* Heap limit. */
ARMul_WriteWord (state, addr + 8, temp); /* Stack base */ ARMul_WriteWord (state, addr + 8, temp); /* Stack base. */
ARMul_WriteWord (state, addr + 12, temp); /* Stack limit */ ARMul_WriteWord (state, addr + 12, temp); /* Stack limit. */
break; break;
case AngelSWI_Reason_ReportException: case AngelSWI_Reason_ReportException:
@ -635,6 +643,69 @@ ARMul_OSHandleSWI (ARMul_State * state, ARMword number)
/* These are used by the FPE code. */ /* These are used by the FPE code. */
break; break;
case 0x180001: /* RedBoot's Syscall SWI in ARM mode. */
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;
return TRUE;
case 2: /* Open. */
SWIopen (state, state->Reg[1], state->Reg[2]);
return TRUE;
case 3: /* Close. */
state->Reg[0] = close (state->Reg[1]);
OSptr->ErrorNo = errno;
return TRUE;
case 4: /* Read. */
SWIread (state, state->Reg[1], state->Reg[2], state->Reg[3]);
return TRUE;
case 5: /* Write. */
SWIwrite (state, state->Reg[1], state->Reg[2], state->Reg[3]);
return TRUE;
case 6: /* Lseek. */
state->Reg[0] = lseek (state->Reg[1], state->Reg[2], state->Reg[3]);
OSptr->ErrorNo = errno;
return TRUE;
case 17: /* Utime. */
state->Reg[0] = (ARMword) time (state->Reg[1]);
OSptr->ErrorNo = errno;
return (TRUE);
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;
}
return TRUE;
default: default:
/* If there is a SWI vector installed use it. */ /* If there is a SWI vector installed use it. */
if (state->is_XScale && saved_number != -1) if (state->is_XScale && saved_number != -1)
@ -661,7 +732,10 @@ ARMul_OSHandleSWI (ARMul_State * state, ARMword number)
} }
else else
{ {
sim_callback->printf_filtered (sim_callback, "sim: unknown SWI encountered - %x - ignoring\n", number); sim_callback->printf_filtered
(sim_callback,
"sim: unknown SWI encountered - %x - ignoring\n",
number);
return FALSE; return FALSE;
} }
} }