summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/armulator/startup
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2000-07-31 18:29:37 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2000-07-31 18:29:37 +0000
commitcaf8869939b50ffc4e3e090b3572935e21327ae8 (patch)
treebd59aef32f9aeba0762726ca85aa95d54f6ce3ae /c/src/lib/libbsp/arm/armulator/startup
parentPatch rtems-rc-20000713-1-cvs.diff from Ralf Corsepius <corsepiu@faw.uni-ulm.de> (diff)
downloadrtems-caf8869939b50ffc4e3e090b3572935e21327ae8.tar.bz2
New bsp for simulator in gdb. Does not work yet.
Diffstat (limited to 'c/src/lib/libbsp/arm/armulator/startup')
-rw-r--r--c/src/lib/libbsp/arm/armulator/startup/.cvsignore2
-rw-r--r--c/src/lib/libbsp/arm/armulator/startup/Makefile.am50
-rw-r--r--c/src/lib/libbsp/arm/armulator/startup/bspstart.c95
-rw-r--r--c/src/lib/libbsp/arm/armulator/startup/libcfunc.c40
-rw-r--r--c/src/lib/libbsp/arm/armulator/startup/linkcmds61
-rw-r--r--c/src/lib/libbsp/arm/armulator/startup/swi.h65
-rw-r--r--c/src/lib/libbsp/arm/armulator/startup/syscalls.c172
-rw-r--r--c/src/lib/libbsp/arm/armulator/startup/trap.S93
8 files changed, 578 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/arm/armulator/startup/.cvsignore b/c/src/lib/libbsp/arm/armulator/startup/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/c/src/lib/libbsp/arm/armulator/startup/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/c/src/lib/libbsp/arm/armulator/startup/Makefile.am b/c/src/lib/libbsp/arm/armulator/startup/Makefile.am
new file mode 100644
index 0000000000..35d84913b7
--- /dev/null
+++ b/c/src/lib/libbsp/arm/armulator/startup/Makefile.am
@@ -0,0 +1,50 @@
+##
+## $Id$
+##
+
+AUTOMAKE_OPTIONS = foreign 1.4
+
+VPATH = @srcdir@:@srcdir@/../../../shared
+
+PGM = $(ARCH)/startup.rel
+
+C_FILES = bsplibc.c bsppost.c bspstart.c bootcard.c main.c sbrk.c \
+ gnatinstallhandler.c libcfunc.c syscalls.c
+C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
+
+S_FILES = trap.S
+S_O_FILES = $(S_FILES:%.S=$(ARCH)/%.o)
+
+OBJS = $(C_O_FILES) $(S_O_FILES)
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../../../../../../automake/lib.am
+
+#
+# (OPTIONAL) Add local stuff here using +=
+#
+
+# From newlib
+# Select which debug protocol is being used.
+# ARM_RDP_MONITOR selects the Demon monitor.
+# ARM_RDI_MONITOR selects the Angel monitor.
+# If neither are defined, then hard coded defaults will be used
+# to create the program's environment.
+AM_CPPFLAGS += -DARM_RDI_MONITOR
+
+$(PGM): $(OBJS)
+ $(make-rel)
+
+$(PROJECT_RELEASE)/lib/linkcmds: linkcmds
+ $(INSTALL_DATA) $< $@
+
+# the .rel file built here will be put into libbsp.a by ../wrapup/Makefile
+TMPINSTALL_FILES += $(PROJECT_RELEASE)/lib/linkcmds
+
+all-local: $(ARCH) $(OBJS) $(PGM) $(TMPINSTALL_FILES)
+
+.PRECIOUS: $(PGM)
+
+EXTRA_DIST = bspclean.c bspstart.c exit.c linkcmds setvec.c
+
+include $(top_srcdir)/../../../../../../automake/local.am
diff --git a/c/src/lib/libbsp/arm/armulator/startup/bspstart.c b/c/src/lib/libbsp/arm/armulator/startup/bspstart.c
new file mode 100644
index 0000000000..cf56f7e60d
--- /dev/null
+++ b/c/src/lib/libbsp/arm/armulator/startup/bspstart.c
@@ -0,0 +1,95 @@
+/*
+ * This routine starts the application. It includes application,
+ * board, and monitor specific initialization and configuration.
+ * The generic CPU dependent initialization has been performed
+ * before this routine is invoked.
+ *
+ * COPYRIGHT (c) 1989-1999.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+
+#include <bsp.h>
+#include <rtems/libio.h>
+
+#include <libcsupport.h>
+
+#include <string.h>
+
+/*
+ * The original table from the application and our copy of it with
+ * some changes.
+ */
+
+extern rtems_configuration_table Configuration;
+
+rtems_configuration_table BSP_Configuration;
+
+rtems_cpu_table Cpu_table;
+
+char *rtems_progname;
+
+/*
+ * Use the shared implementations of the following routines
+ */
+
+void bsp_postdriver_hook(void);
+void bsp_libc_init( void *, unsigned32, int );
+
+/*
+ * Function: bsp_pretasking_hook
+ * Created: 95/03/10
+ *
+ * Description:
+ * BSP pretasking hook. Called just before drivers are initialized.
+ * Used to setup libc and install any BSP extensions.
+ *
+ * NOTES:
+ * Must not use libc (to do io) from here, since drivers are
+ * not yet initialized.
+ *
+ */
+
+void bsp_pretasking_hook(void)
+{
+ extern int HeapBase;
+ extern int HeapSize;
+ void *heapStart = &HeapBase;
+ unsigned long heapSize = (unsigned long)&HeapSize;
+ unsigned long ramSpace;
+
+ bsp_libc_init(heapStart, heapSize, 0);
+
+#ifdef RTEMS_DEBUG
+ rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
+#endif
+
+}
+
+/*
+ * bsp_start
+ *
+ * This routine does the bulk of the system initialization.
+ */
+
+void bsp_start( void )
+{
+ extern int _end;
+ extern int WorkspaceBase;
+
+ initialize_monitor_handles();
+ Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */
+ Cpu_table.postdriver_hook = bsp_postdriver_hook;
+
+/*
+ if ( BSP_Configuration.work_space_size >(512*1024) )
+ abort_program( 1 );
+*/
+
+ BSP_Configuration.work_space_start = (void *) &WorkspaceBase;
+}
diff --git a/c/src/lib/libbsp/arm/armulator/startup/libcfunc.c b/c/src/lib/libbsp/arm/armulator/startup/libcfunc.c
new file mode 100644
index 0000000000..aec84d0f4c
--- /dev/null
+++ b/c/src/lib/libbsp/arm/armulator/startup/libcfunc.c
@@ -0,0 +1,40 @@
+/* Support files for GNU libc. Files in the C namespace go here.
+ Files in the system namespace (ie those that start with an underscore)
+ go in syscalls.c.
+
+ Note: These functions are in a seperate file so that OS providers can
+ overrride the system call stubs (defined in syscalls.c) without having
+ to provide libc funcitons as well. */
+#include "swi.h"
+
+#ifdef ARM_RDI_MONITOR
+
+static inline int
+do_AngelSWI (int reason, void * arg)
+{
+ int value;
+ asm volatile ("mov r0, %1; mov r1, %2; swi %a3; mov %0, r0"
+ : "=r" (value) /* Outputs */
+ : "r" (reason), "r" (arg), "i" (AngelSWI) /* Inputs */
+ : "r0", "r1", "lr"
+ /* Clobbers r0 and r1, and lr if in supervisor mode */);
+ return value;
+}
+#endif /* ARM_RDI_MONITOR */
+
+
+void
+abort_program (void)
+{
+#ifdef ARM_RDI_MONITOR
+ do_AngelSWI (AngelSWI_Reason_ReportException,
+ (void *) ADP_Stopped_RunTimeError);
+#else
+ asm ("mov r0,#17\nswi %a0" :: "i" (SWI_Exit));
+#endif
+}
+
+void
+alarm (void)
+{
+}
diff --git a/c/src/lib/libbsp/arm/armulator/startup/linkcmds b/c/src/lib/libbsp/arm/armulator/startup/linkcmds
new file mode 100644
index 0000000000..d6b6e5f6a5
--- /dev/null
+++ b/c/src/lib/libbsp/arm/armulator/startup/linkcmds
@@ -0,0 +1,61 @@
+/*
+ * $Id$
+ */
+
+/*
+ * Declare some sizes.
+ */
+_RamBase = DEFINED(_RamBase) ? _RamBase : 0x0;
+_RamSize = DEFINED(_RamSize) ? _RamSize : 1M;
+_HeapSize = DEFINED(_HeapSize) ? _HeapSize : 0x10000;
+_StackSize = DEFINED(_StackSize) ? _StackSize : 0x1000;
+
+SECTIONS
+{
+ . = 0x8000;
+ .text :
+ {
+ CREATE_OBJECT_SYMBOLS
+ *(.text)
+ _etext = .;
+
+ ___CTOR_LIST__ = .;
+ LONG((___CTOR_END__ - ___CTOR_LIST__) / 4 - 2)
+ *(.ctors)
+ LONG(0)
+ ___CTOR_END__ = .;
+ ___DTOR_LIST__ = .;
+ LONG((___DTOR_END__ - ___DTOR_LIST__) / 4 - 2)
+ *(.dtors)
+ LONG(0)
+ ___DTOR_END__ = .;
+ }
+ . = ALIGN(256) + (. & (256 - 1));
+ .data :
+ {
+ *(.data)
+ CONSTRUCTORS
+ _edata = .;
+ }
+ .bss SIZEOF(.data) + ADDR(.data):
+ {
+ _bss_start = .;
+ _clear_start = .;
+ *(.bss)
+ *(COMMON)
+ . = ALIGN (64);
+ _stack_init = .;
+ . += _StackSize;
+ _clear_end = .;
+ _WorkspaceBase = .;
+ . += 512K; /* reserve some memory for workspace */
+ _HeapBase = .;
+ . += _HeapSize; /* reserve some memory for heap */
+ _end = .;
+ __end = .;
+ }
+}
+
+HeapBase = _HeapBase;
+HeapSize = _HeapSize;
+WorkspaceBase = _WorkspaceBase;
diff --git a/c/src/lib/libbsp/arm/armulator/startup/swi.h b/c/src/lib/libbsp/arm/armulator/startup/swi.h
new file mode 100644
index 0000000000..91fad59121
--- /dev/null
+++ b/c/src/lib/libbsp/arm/armulator/startup/swi.h
@@ -0,0 +1,65 @@
+
+/***************************************************************************\
+* SWI numbers *
+\***************************************************************************/
+
+/* SWI numbers for RDP (Demon) monitor */
+#define SWI_WriteC 0x0
+#define SWI_Write0 0x2
+#define SWI_ReadC 0x4
+#define SWI_CLI 0x5
+#define SWI_GetEnv 0x10
+#define SWI_Exit 0x11
+#define SWI_EnterOS 0x16
+
+#define SWI_GetErrno 0x60
+#define SWI_Clock 0x61
+#define SWI_Time 0x63
+#define SWI_Remove 0x64
+#define SWI_Rename 0x65
+#define SWI_Open 0x66
+
+#define SWI_Close 0x68
+#define SWI_Write 0x69
+#define SWI_Read 0x6a
+#define SWI_Seek 0x6b
+#define SWI_Flen 0x6c
+
+#define SWI_IsTTY 0x6e
+#define SWI_TmpNam 0x6f
+#define SWI_InstallHandler 0x70
+#define SWI_GenerateError 0x71
+
+
+/* Now the SWI numbers and reason codes for RDI (Angel) monitors */
+#define AngelSWI_ARM (0x123456)
+#ifdef __thumb__
+#define AngelSWI (0xAB)
+#else
+#define AngelSWI AngelSWI_ARM
+#endif
+
+/* The reason codes: */
+#define AngelSWI_Reason_Open (0x01)
+#define AngelSWI_Reason_Close (0x02)
+#define AngelSWI_Reason_WriteC (0x03)
+#define AngelSWI_Reason_Write0 (0x04)
+#define AngelSWI_Reason_Write (0x05)
+#define AngelSWI_Reason_Read (0x06)
+#define AngelSWI_Reason_ReadC (0x07)
+#define AngelSWI_Reason_IsTTY (0x09)
+#define AngelSWI_Reason_Seek (0x0A)
+#define AngelSWI_Reason_FLen (0x0C)
+#define AngelSWI_Reason_TmpNam (0x0D)
+#define AngelSWI_Reason_Remove (0x0E)
+#define AngelSWI_Reason_Rename (0x0F)
+#define AngelSWI_Reason_Clock (0x10)
+#define AngelSWI_Reason_Time (0x11)
+#define AngelSWI_Reason_System (0x12)
+#define AngelSWI_Reason_Errno (0x13)
+#define AngelSWI_Reason_GetCmdLine (0x15)
+#define AngelSWI_Reason_HeapInfo (0x16)
+#define AngelSWI_Reason_EnterSVC (0x17)
+#define AngelSWI_Reason_ReportException (0x18)
+#define ADP_Stopped_ApplicationExit ((2 << 16) + 38)
+#define ADP_Stopped_RunTimeError ((2 << 16) + 34)
diff --git a/c/src/lib/libbsp/arm/armulator/startup/syscalls.c b/c/src/lib/libbsp/arm/armulator/startup/syscalls.c
new file mode 100644
index 0000000000..b0a3530739
--- /dev/null
+++ b/c/src/lib/libbsp/arm/armulator/startup/syscalls.c
@@ -0,0 +1,172 @@
+/* Support files for newlib/GDB simulator.
+ * $Id$
+ */
+
+#include <_ansi.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/fcntl.h>
+#include <stdio.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/times.h>
+#include <errno.h>
+#include <reent.h>
+#include "swi.h"
+
+int armulator_stdin;
+int armulator_stdout;
+int armulator_stderr;
+
+#ifdef ARM_RDI_MONITOR
+
+static inline int
+do_AngelSWI (int reason, void * arg)
+{
+ int value;
+ asm volatile ("mov r0, %1; mov r1, %2; swi %a3; mov %0, r0"
+ : "=r" (value) /* Outputs */
+ : "r" (reason), "r" (arg), "i" (AngelSWI) /* Inputs */
+ : "r0", "r1", "lr"
+ /* Clobbers r0 and r1, and lr if in supervisor mode */);
+ return value;
+}
+#endif /* ARM_RDI_MONITOR */
+
+void
+initialize_monitor_handles (void)
+{
+ int i;
+
+#ifdef ARM_RDI_MONITOR
+ int volatile block[3];
+
+ block[0] = (int) ":tt";
+ block[2] = 3; /* length of filename */
+ block[1] = 0; /* mode "r" */
+ armulator_stdin = do_AngelSWI (AngelSWI_Reason_Open, block);
+
+ block[0] = (int) ":tt";
+ block[2] = 3; /* length of filename */
+ block[1] = 4; /* mode "w" */
+ armulator_stdout = armulator_stderr = do_AngelSWI (AngelSWI_Reason_Open, block);
+#else
+ int fh;
+ const char * name;
+
+ name = ":tt";
+ asm ("mov r0,%2; mov r1, #0; swi %a1; mov %0, r0"
+ : "=r"(fh)
+ : "i" (SWI_Open),"r"(name)
+ : "r0","r1");
+ armulator_stdin = fh;
+
+ name = ":tt";
+ asm ("mov r0,%2; mov r1, #4; swi %a1; mov %0, r0"
+ : "=r"(fh)
+ : "i" (SWI_Open),"r"(name)
+ : "r0","r1");
+ armulator_stdout = armulator_stderr = fh;
+#endif
+}
+
+/* Returns # chars not! read */
+
+int
+_swiread (int file,
+ char * ptr,
+ int len)
+{
+ int fh = file;
+#ifdef ARM_RDI_MONITOR
+ int block[3];
+
+ block[0] = fh;
+ block[1] = (int) ptr;
+ block[2] = len;
+
+ return do_AngelSWI (AngelSWI_Reason_Read, block);
+#else
+ asm ("mov r0, %1; mov r1, %2;mov r2, %3; swi %a0"
+ : /* No outputs */
+ : "i"(SWI_Read), "r"(fh), "r"(ptr), "r"(len)
+ : "r0","r1","r2");
+#endif
+}
+
+/* Returns #chars not! written */
+int
+_swiwrite (
+ int file,
+ char * ptr,
+ int len)
+{
+ int fh = file;
+#ifdef ARM_RDI_MONITOR
+ int block[3];
+
+ block[0] = fh;
+ block[1] = (int) ptr;
+ block[2] = len;
+
+ return do_AngelSWI (AngelSWI_Reason_Write, block);
+#else
+ asm ("mov r0, %1; mov r1, %2;mov r2, %3; swi %a0"
+ : /* No outputs */
+ : "i"(SWI_Write), "r"(fh), "r"(ptr), "r"(len)
+ : "r0","r1","r2");
+#endif
+}
+
+/*
+ * Move me
+ */
+
+void
+bsp_cleanup (void )
+{
+ /* FIXME: return code is thrown away */
+
+#ifdef ARM_RDI_MONITOR
+ do_AngelSWI (AngelSWI_Reason_ReportException,
+ (void *) ADP_Stopped_ApplicationExit);
+#else
+ asm ("swi %a0" :: "i" (SWI_Exit));
+#endif
+}
+
+/*
+ * Technically could use this as guts of a "real-time clock driver"
+ */
+
+#if 0
+int
+_gettimeofday (struct timeval * tp, struct timezone * tzp)
+{
+
+ if (tp)
+ {
+ /* Ask the host for the seconds since the Unix epoch */
+#ifdef ARM_RDI_MONITOR
+ tp->tv_sec = do_AngelSWI (AngelSWI_Reason_Time,NULL);
+#else
+ {
+ int value;
+ asm ("swi %a1; mov %0, r0" : "=r" (value): "i" (SWI_Time) : "r0");
+ tp->tv_sec = value;
+ }
+#endif
+ tp->tv_usec = 0;
+ }
+
+ /* Return fixed data for the timezone */
+ if (tzp)
+ {
+ tzp->tz_minuteswest = 0;
+ tzp->tz_dsttime = 0;
+ }
+
+ return 0;
+}
+#endif
+
diff --git a/c/src/lib/libbsp/arm/armulator/startup/trap.S b/c/src/lib/libbsp/arm/armulator/startup/trap.S
new file mode 100644
index 0000000000..328fabca5c
--- /dev/null
+++ b/c/src/lib/libbsp/arm/armulator/startup/trap.S
@@ -0,0 +1,93 @@
+ /* Run-time exception support */
+#include "swi.h"
+
+/* .text is used instead of .section .text so it works with arm-aout too. */
+ .text
+ .align 0
+ .global __rt_stkovf_split_big
+ .global __rt_stkovf_split_small
+
+/* The following functions are provided for software stack checking.
+ If hardware stack-checking is being used then the code can be
+ compiled without the PCS entry checks, and simply rely on VM
+ management to extend the stack for a thread.
+
+ The stack extension event occurs when the PCS function entry code
+ would result in a stack-pointer beneath the stack-limit register
+ value. The system relies on the following map:
+
+ +-----------------------------------+ <-- end of stack block
+ | ... |
+ | ... |
+ | active stack |
+ | ... | <-- sp (stack-pointer) somewhere in here
+ | ... |
+ +-----------------------------------+ <-- sl (stack-limit)
+ | stack-extension handler workspace |
+ +-----------------------------------+ <-- base of stack block
+
+ The "stack-extension handler workspace" is an amount of memory in
+ which the stack overflow support code must execute. It must be
+ large enough to deal with the worst case path through the extension
+ code. At the moment the compiler expects this to be AT LEAST
+ 256bytes. It uses this fact to code functions with small local
+ data usage within the overflow space.
+
+ In a true target environment We may need to increase the space
+ between sl and the true limit to allow for the stack extension
+ code, SWI handlers and for undefined instruction handlers of the
+ target environment. */
+
+__rt_stkovf_split_small:
+ mov ip,sp @ Ensure we can calculate the stack required
+ @ and fall through to...
+__rt_stkovf_split_big:
+ @ in: sp = current stack-pointer (beneath stack-limit)
+ @ sl = current stack-limit
+ @ ip = low stack point we require for the current function
+ @ lr = return address into the current function
+ @ fp = frame-pointer
+ @ original sp --> +----------------------------------+
+ @ | pc (12 ahead of PCS entry store) |
+ @ current fp ---> +----------------------------------+
+ @ | lr (on entry) pc (on exit) |
+ @ +----------------------------------+
+ @ | sp ("original sp" on entry) |
+ @ +----------------------------------+
+ @ | fp (on entry to function) |
+ @ +----------------------------------+
+ @ | |
+ @ | ..argument and work registers.. |
+ @ | |
+ @ current sp ---> +----------------------------------+
+ @
+ @ The "current sl" is somewhere between "original sp" and "current sp"
+ @ but above "true sl". The "current sl" should be at least 256bytes
+ @ above the "true sl". The 256byte stack guard should be large enough
+ @ to deal with the worst case function entry stacking (160bytes) plus
+ @ the stack overflow handler stacking requirements, plus the stack
+ @ required for the memory allocation routines.
+ @
+ @ Normal PCS entry (before stack overflow check) can stack 16
+ @ standard registers (64bytes) and 8 floating point registers
+ @ (96bytes). This gives a minimum stack guard of 160bytes (excluding
+ @ the stack required for the code). (Actually only a maximum of
+ @ 14standard registers are ever stacked on entry to a function).
+ @
+ @ NOTE: Structure returns are performed by the caller allocating a
+ @ dummy space on the stack and passing in a "phantom" arg1 into
+ @ the function. This means that we do not need to worry about
+ @ preserving the stack under "sp" even on function return.
+ @
+ @ Code should never poke values beneath sp. The sp register
+ @ should always be "dropped" first to cover the data. This
+ @ protects the data against any events that may try and use
+ @ the stack.
+
+ SUB ip, sp, ip @ extra stack required for function
+ @ Add stack extension code here. If desired a new stack chunk
+ @ can be allocated, and the register state updated suitably.
+
+ @ We now know how much extra stack the function requires.
+ @ Terminate the program for the moment:
+ swi SWI_Exit