summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/unix/posix/startup
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1995-07-12 19:47:25 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1995-07-12 19:47:25 +0000
commit637df35f96d8023056369fcf2c9943419f1a1b74 (patch)
treea12bd461bf892ccaff6c67571432f0535eb03e96 /c/src/lib/libbsp/unix/posix/startup
parentadded David Glessner's 68302 work. (diff)
downloadrtems-637df35f96d8023056369fcf2c9943419f1a1b74.tar.bz2
Ada95, gnat, go32
Diffstat (limited to 'c/src/lib/libbsp/unix/posix/startup')
-rw-r--r--c/src/lib/libbsp/unix/posix/startup/bspclean.c37
-rw-r--r--c/src/lib/libbsp/unix/posix/startup/bspstart.c314
-rw-r--r--c/src/lib/libbsp/unix/posix/startup/exit.c28
-rw-r--r--c/src/lib/libbsp/unix/posix/startup/rtems-ctor.cc108
-rw-r--r--c/src/lib/libbsp/unix/posix/startup/setvec.c60
5 files changed, 547 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/unix/posix/startup/bspclean.c b/c/src/lib/libbsp/unix/posix/startup/bspclean.c
new file mode 100644
index 0000000000..22feedb7ad
--- /dev/null
+++ b/c/src/lib/libbsp/unix/posix/startup/bspclean.c
@@ -0,0 +1,37 @@
+/* bsp_cleanup()
+ *
+ * This routine normally is part of start.s and returns
+ * control to a monitor but on the UNIX simulator
+ * we do that directly from main.c.
+ *
+ * INPUT: NONE
+ *
+ * OUTPUT: NONE
+ *
+ * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
+ * On-Line Applications Research Corporation (OAR).
+ * All rights assigned to U.S. Government, 1994.
+ *
+ * This material may be reproduced by or for the U.S. Government pursuant
+ * to the copyright license under the clause at DFARS 252.227-7013. This
+ * notice must appear in all copies of this file and its derivatives.
+ *
+ * $Id$
+ */
+
+#include <rtems.h>
+#include <bsp.h>
+
+/*
+ * The app has "exited" (called rtems_shutdown_executive)
+ */
+
+void bsp_cleanup( void )
+{
+ /*
+ * Invoke any fatal error extension and "halt"
+ * By definition, rtems_fatal_error_occurred does not return.
+ */
+
+ rtems_fatal_error_occurred(0);
+}
diff --git a/c/src/lib/libbsp/unix/posix/startup/bspstart.c b/c/src/lib/libbsp/unix/posix/startup/bspstart.c
new file mode 100644
index 0000000000..a2ec1b1911
--- /dev/null
+++ b/c/src/lib/libbsp/unix/posix/startup/bspstart.c
@@ -0,0 +1,314 @@
+/*
+ * @(#)bspstart.c 1.7 - 95/04/07
+ *
+ */
+
+/* bsp_start()
+ *
+ * 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.
+ *
+ * Called by RTEMS::RTEMS constructor in startup-ctor.cc
+ *
+ * INPUT: NONE
+ *
+ * OUTPUT: NONE
+ *
+ * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
+ * On-Line Applications Research Corporation (OAR).
+ * All rights assigned to U.S. Government, 1994.
+ *
+ * This material may be reproduced by or for the U.S. Government pursuant
+ * to the copyright license under the clause at DFARS 252.227-7013. This
+ * notice must appear in all copies of this file and its derivatives.
+ *
+ * $Id$
+ */
+
+#include <rtems.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+#include <bsp.h>
+#include <libcsupport.h>
+
+#ifdef STACK_CHECKER_ON
+#include <stackchk.h>
+#endif
+
+extern rtems_configuration_table Configuration;
+
+/*
+ * A copy of the configuration table from the application
+ * with some changes applied to it.
+ */
+
+rtems_configuration_table BSP_Configuration;
+rtems_multiprocessing_table BSP_Multiprocessing;
+rtems_cpu_table Cpu_table;
+rtems_unsigned32 bsp_isr_level;
+rtems_unsigned32 Heap_size;
+int rtems_argc;
+char **rtems_argv;
+char **rtems_envp;
+
+
+#define WORKSPACE_SIZE (WORKSPACE_MB * (1024 * 1024))
+#define HEAPSPACE_SIZE (HEAPSPACE_MB * (1024 * 1024))
+
+rtems_unsigned8 MY_WORK_SPACE[ WORKSPACE_SIZE ] CPU_STRUCTURE_ALIGNMENT;
+
+/*
+ * Amount to increment itimer by each pass
+ * It is a variable instead of a #define to allow the 'looptest'
+ * script to bump it without recompiling rtems
+ */
+
+rtems_unsigned32 CPU_CLICKS_PER_TICK;
+
+/*
+ * Function: bsp_libc_init
+ * Created: 94/12/6
+ *
+ * Description:
+ * Initialize whatever libc we are using
+ * called from bsp_postdriver_hook
+ *
+ *
+ * Parameters:
+ * none
+ *
+ * Returns:
+ * none.
+ *
+ * Side Effects:
+ *
+ *
+ * Notes:
+ *
+ * Deficiencies/ToDo:
+ *
+ *
+ */
+
+void
+bsp_libc_init(void)
+{
+ void *heap_start;
+
+ Heap_size = HEAPSPACE_SIZE;
+ heap_start = 0;
+
+ RTEMS_Malloc_Initialize((void *)heap_start, Heap_size, 1024 * 1024);
+
+ libc_init(1);
+}
+
+
+/*
+ * 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.
+ *
+ * Parameters:
+ * none
+ *
+ * Returns:
+ * nada
+ *
+ * Side Effects:
+ * installs a few extensions
+ *
+ * Notes:
+ * Must not use libc (to do io) from here, since drivers are
+ * not yet initialized.
+ *
+ * Deficiencies/ToDo:
+ *
+ *
+ */
+
+void
+bsp_pretasking_hook(void)
+{
+ bsp_libc_init();
+
+#ifdef STACK_CHECKER_ON
+ /*
+ * Initialize the stack bounds checker
+ * We can either turn it on here or from the app.
+ */
+
+ Stack_check_Initialize();
+#endif
+
+#ifdef RTEMS_DEBUG
+ rtems_debug_enable( RTEMS_DEBUG_ALL_MASK );
+#endif
+}
+
+/*
+ * Function: bsp_start
+ * Created: 94/12/6
+ *
+ * Description:
+ * called by crt0 as our "main" equivalent
+ *
+ *
+ *
+ * Parameters:
+ *
+ *
+ * Returns:
+ *
+ *
+ * Side Effects:
+ *
+ *
+ * Notes:
+ *
+ *
+ * Deficiencies/ToDo:
+ *
+ *
+ */
+
+void
+bsp_start(void)
+{
+ struct stat stat_buf;
+ char buf[256];
+ char node[6];
+ char *home;
+ int fd;
+
+ /*
+ * Copy the table
+ */
+
+ BSP_Configuration = Configuration;
+
+ /*
+ * If the node number is -1 then the application better provide
+ * it through the file $HOME/rtems_node
+ */
+
+ BSP_Multiprocessing.node = -1;
+
+ if (BSP_Configuration.User_multiprocessing_table) {
+ if (BSP_Configuration.User_multiprocessing_table->node == -1) {
+ home = getenv("HOME");
+ sprintf(buf, "%s/%s", home, "rtems_node");
+ if ((stat(buf, &stat_buf)) == 0) {
+ fd = open(buf, O_RDONLY);
+ read(fd, node, 5);
+ close(fd);
+ unlink(buf);
+ BSP_Multiprocessing = *BSP_Configuration.User_multiprocessing_table;
+ BSP_Multiprocessing.node = atoi(node);
+ BSP_Configuration.User_multiprocessing_table = &BSP_Multiprocessing;
+ }
+ if (BSP_Configuration.User_multiprocessing_table->maximum_nodes == -1) {
+ home = getenv("HOME");
+ sprintf(buf, "%s/%s", home, "rtems_max_node");
+ if ((stat(buf, &stat_buf)) == 0) {
+ fd = open(buf, O_RDONLY);
+ read(fd, node, 5);
+ close(fd);
+ BSP_Multiprocessing.maximum_nodes = atoi(node);
+ }
+ }
+ }
+ }
+
+ /*
+ * Set cpu_number to accurately reflect our cpu number
+ */
+
+ if (BSP_Configuration.User_multiprocessing_table)
+ cpu_number = BSP_Configuration.User_multiprocessing_table->node - 1;
+ else
+ cpu_number = 0;
+
+ BSP_Configuration.work_space_start = (void *)MY_WORK_SPACE;
+ if (BSP_Configuration.work_space_size)
+ BSP_Configuration.work_space_size = WORKSPACE_SIZE;
+
+ /*
+ * Set up our hooks
+ * Make sure libc_init is done before drivers init'd so that
+ * they can use atexit()
+ */
+
+ Cpu_table.pretasking_hook = bsp_pretasking_hook; /* init libc, etc. */
+
+ Cpu_table.predriver_hook = NULL;
+
+ Cpu_table.postdriver_hook = NULL;
+
+ Cpu_table.idle_task = NULL; /* do not override system IDLE task */
+
+ /*
+ * Don't zero out the workspace since it is in the BSS under UNIX.
+ */
+
+ Cpu_table.do_zero_of_workspace = FALSE;
+
+ /*
+ * XXX; interrupt stack not currently used, so this doesn't matter
+ */
+
+ Cpu_table.interrupt_stack_size = (12 * 1024);
+
+ Cpu_table.extra_system_initialization_stack = 0;
+
+ /*
+ * Add 1 region for RTEMS Malloc
+ */
+
+ BSP_Configuration.maximum_regions++;
+
+#ifdef RTEMS_NEWLIB
+ /*
+ * Add 1 extension for newlib libc
+ */
+
+ BSP_Configuration.maximum_extensions++;
+#endif
+
+#ifdef STACK_CHECKER_ON
+ /*
+ * Add 1 extension for stack checker
+ */
+
+ BSP_Configuration.maximum_extensions++;
+#endif
+
+ /*
+ * Add 1 extension for MPCI_fatal
+ */
+
+ if (BSP_Configuration.User_multiprocessing_table)
+ BSP_Configuration.maximum_extensions++;
+
+ CPU_CLICKS_PER_TICK = 1;
+
+ /*
+ * Start most of RTEMS
+ * main() will start the rest
+ */
+
+ bsp_isr_level = rtems_initialize_executive_early(
+ &BSP_Configuration,
+ &Cpu_table
+ );
+}
diff --git a/c/src/lib/libbsp/unix/posix/startup/exit.c b/c/src/lib/libbsp/unix/posix/startup/exit.c
new file mode 100644
index 0000000000..ac3c840832
--- /dev/null
+++ b/c/src/lib/libbsp/unix/posix/startup/exit.c
@@ -0,0 +1,28 @@
+/*
+ * exit
+ *
+ * This routine returns control to "the pre-RTEMS environment".
+ *
+ * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
+ * On-Line Applications Research Corporation (OAR).
+ * All rights assigned to U.S. Government, 1994.
+ *
+ * This material may be reproduced by or for the U.S. Government pursuant
+ * to the copyright license under the clause at DFARS 252.227-7013. This
+ * notice must appear in all copies of this file and its derivatives.
+ *
+ * $Id$
+ */
+
+#include <rtems.h>
+#include <bsp.h>
+#include <clockdrv.h>
+
+void _exit( void )
+{
+ /* Clock or Timer cleanup is run by at_exit() */
+
+ Io_cleanup();
+
+ bsp_cleanup();
+}
diff --git a/c/src/lib/libbsp/unix/posix/startup/rtems-ctor.cc b/c/src/lib/libbsp/unix/posix/startup/rtems-ctor.cc
new file mode 100644
index 0000000000..4c55f3798f
--- /dev/null
+++ b/c/src/lib/libbsp/unix/posix/startup/rtems-ctor.cc
@@ -0,0 +1,108 @@
+// @(#)rtems-ctor.cc 1.6 - 95/04/25
+//
+//
+
+/*
+ * rtems-ctor.cc
+ *
+ * Description:
+ * This file exists solely to (try to) ensure RTEMS is initialized
+ * before any global constructors are run.
+ *
+ * The problem:
+ * Global constructors might reasonably expect that new() will
+ * work, but since new() uses malloc() which uses RTEMS regions,
+ * it can not be called until after initialize_executive().
+ *
+ * Global constructors are called in GNU systems one of 2 ways:
+ *
+ * an "invisible" call to __main() inserted by compiler
+ * This __main() calls __do_global_ctors() which
+ * walks thru the table and calls all global
+ * constructors.
+ *
+ * or -
+ * A special section is put into the linked binary. The
+ * system startup code knows to run the constructors in
+ * this special section before calling main().
+ *
+ * By making RTEMS initialization a constructor, we avoid having
+ * too much about all this. All we have to guarantee is that
+ * this constructor is the first one run.
+ *
+ *
+ * So for the first case above, this is what happens
+ *
+ * host crt0
+ * main()
+ * __main()
+ * __do_global_ctors()
+ * bsp_start()
+ * init_executive_early()
+ * <<any other constructors>>
+ *
+ * init_executive_late()
+ * bsp_cleanup()
+ *
+ * TODO:
+ *
+ */
+
+#include <bsp.h>
+
+/*
+ * RTEMS program name
+ * Probably not used by anyone, but it is nice to have it.
+ * Actually the UNIX version of CPU_INVOKE_DEBUGGER will probably
+ * need to use it
+ */
+
+char *rtems_progname;
+
+class RTEMS {
+ public:
+ RTEMS();
+ ~RTEMS();
+};
+
+RTEMS rtems_constructor;
+
+RTEMS::RTEMS()
+{
+ bsp_start();
+}
+
+RTEMS::~RTEMS()
+{
+ bsp_cleanup();
+}
+
+extern "C" {
+ int
+ main(int argc,
+ char **argv,
+ char **environp)
+ {
+ rtems_argc = argc;
+ rtems_argv = argv;
+ rtems_envp = environp;
+
+ if ((argc > 0) && argv && argv[0])
+ rtems_progname = argv[0];
+ else
+ rtems_progname = "RTEMS";
+
+ /*
+ * Start multitasking
+ */
+
+ rtems_initialize_executive_late( bsp_isr_level );
+
+ /*
+ * Returns when multitasking is stopped
+ * This allows our destructors to get run normally
+ */
+
+ return 0;
+ }
+}
diff --git a/c/src/lib/libbsp/unix/posix/startup/setvec.c b/c/src/lib/libbsp/unix/posix/startup/setvec.c
new file mode 100644
index 0000000000..fef64752d5
--- /dev/null
+++ b/c/src/lib/libbsp/unix/posix/startup/setvec.c
@@ -0,0 +1,60 @@
+/* set_vector
+ *
+ * This routine installs an interrupt vector on UNIX.
+ *
+ * INPUT:
+ * handler - interrupt handler entry point
+ * vector - vector number
+ * type - 0 indicates raw hardware connect
+ * 1 indicates RTEMS interrupt connect
+ *
+ * NOTE 'type' is ignored on hppa; all interrupts are owned by RTEMS
+ *
+ * RETURNS:
+ * address of previous interrupt handler
+ *
+ * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
+ * On-Line Applications Research Corporation (OAR).
+ * All rights assigned to U.S. Government, 1994.
+ *
+ * This material may be reproduced by or for the U.S. Government pursuant
+ * to the copyright license under the clause at DFARS 252.227-7013. This
+ * notice must appear in all copies of this file and its derivatives.
+ *
+ * $Id$
+ */
+
+#include <rtems.h>
+#include <bsp.h>
+
+/*
+ * Install an interrupt handler in the right place
+ * given its vector number from cpu/hppa.h
+ * There are 2 places an interrupt can be installed
+ * _ISR_Vector_table
+ * bsp interrupt XXX: nyi
+ *
+ * We decide which based on the vector number
+ */
+
+unix_isr_entry
+set_vector( /* returns old vector */
+ rtems_isr_entry handler, /* isr routine */
+ rtems_vector_number vector, /* vector number */
+ int type /* RTEMS or RAW intr */
+)
+{
+ rtems_isr_entry rtems_isr_ptr;
+ proc_ptr raw_isr_ptr;
+
+ if ( type ) {
+ rtems_interrupt_catch( handler, vector, &rtems_isr_ptr );
+ return (unix_isr_entry) rtems_isr_ptr;
+ } else {
+ _CPU_ISR_install_vector( vector, (proc_ptr) handler, &raw_isr_ptr );
+ return (unix_isr_entry) raw_isr_ptr;
+ }
+
+}
+
+