From ac7d5ef06a6d6e8d84abbd1f0b82162725f98326 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 11 May 1995 17:39:37 +0000 Subject: Initial revision --- cpukit/sapi/src/debug.c | 62 +++++++++ cpukit/sapi/src/exinit.c | 245 ++++++++++++++++++++++++++++++++++ cpukit/sapi/src/extension.c | 156 ++++++++++++++++++++++ cpukit/sapi/src/fatal.c | 54 ++++++++ cpukit/sapi/src/io.c | 316 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 833 insertions(+) create mode 100644 cpukit/sapi/src/debug.c create mode 100644 cpukit/sapi/src/exinit.c create mode 100644 cpukit/sapi/src/extension.c create mode 100644 cpukit/sapi/src/fatal.c create mode 100644 cpukit/sapi/src/io.c (limited to 'cpukit/sapi/src') diff --git a/cpukit/sapi/src/debug.c b/cpukit/sapi/src/debug.c new file mode 100644 index 0000000000..5c42fa92f6 --- /dev/null +++ b/cpukit/sapi/src/debug.c @@ -0,0 +1,62 @@ +/* + * Debug Manager + * + * 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 +#include + +/*PAGE + * + * _Debug_Manager_initialization + */ + +void _Debug_Manager_initialization( void ) +{ + rtems_debug_disable( RTEMS_DEBUG_ALL_MASK ); +} + +/*PAGE + * + * rtems_debug_enable + */ + +void rtems_debug_enable ( + rtems_debug_control to_be_enabled +) +{ + _Debug_Level |= to_be_enabled; +} + +/*PAGE + * + * rtems_debug_disable + */ + +void rtems_debug_disable ( + rtems_debug_control to_be_disabled +) +{ + _Debug_Level &= ~to_be_disabled; +} + +/*PAGE + * + * _Debug_Is_enabled + */ + +boolean _Debug_Is_enabled( + rtems_debug_control level +) +{ + return (_Debug_Level & level); +} diff --git a/cpukit/sapi/src/exinit.c b/cpukit/sapi/src/exinit.c new file mode 100644 index 0000000000..cc45a11c94 --- /dev/null +++ b/cpukit/sapi/src/exinit.c @@ -0,0 +1,245 @@ +/* + * Initialization Manager + * + * 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$ + */ + +/* + * INIT is defined so all of the data will be included in this + * file. + */ + +#define INIT + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/*PAGE + * + * rtems_initialize_executive + * + * This directive initializes all the kernels data structures + * to the states necessary for the kernel to begin execution. All + * include files that contain global variable definitions should be + * included in this file. The system threads and initialization threads + * are created and started by this routine. This routine then + * initiates multithreading. + * + * Input parameters: + * configuration_table - pointer to the user's configuration table + * cpu_table - pointer to the user's CPU configuration table + * + * Output parameters: NONE + */ + +struct months { + unsigned32 months[2][13]; +}; + +void rtems_initialize_executive( + rtems_configuration_table *configuration_table, + rtems_cpu_table *cpu_table +) +{ + rtems_interrupt_level bsp_level; + + bsp_level = rtems_initialize_executive_early(configuration_table, cpu_table); + rtems_initialize_executive_late( bsp_level ); +} + +rtems_interrupt_level rtems_initialize_executive_early( + rtems_configuration_table *configuration_table, + rtems_cpu_table *cpu_table +) +{ + rtems_interrupt_level bsp_level; + rtems_multiprocessing_table *multiprocessing_table; + + /* + * Dispatching and interrupts are disabled until the end of the + * initialization sequence. This prevents an inadvertent context + * switch before the executive is initialized. + */ + + _ISR_Disable( bsp_level ); + + _System_state_Set( SYSTEM_STATE_BEFORE_INITIALIZATION ); + + _CPU_Initialize( cpu_table, _Thread_Dispatch ); + + multiprocessing_table = configuration_table->User_multiprocessing_table; + if ( multiprocessing_table == NULL ) + multiprocessing_table = + (void *) &_Configuration_Default_multiprocessing_table; + + _Configuration_Handler_initialization( + configuration_table, + multiprocessing_table, + multiprocessing_table->User_mpci_table + ); + + _Attributes_Handler_initialization(); + + _Thread_Dispatch_initialization(); + + _User_extensions_Handler_initialization( + configuration_table->User_extension_table + ); + + _Workspace_Handler_initialization( + (void *)configuration_table->work_space_start, + configuration_table->work_space_size + ); + + _ISR_Handler_initialization(); + + _Objects_Handler_initialization( + multiprocessing_table->node, + multiprocessing_table->maximum_global_objects + ); + + _Priority_Handler_initialization(); + + _Watchdog_Handler_initialization(); + + _TOD_Handler_initialization( configuration_table->microseconds_per_tick ); + + _Thread_Handler_initialization( + configuration_table->maximum_tasks, + configuration_table->ticks_per_timeslice, + multiprocessing_table->maximum_proxies + ); + + _MPCI_Handler_initialization(); + +/* MANAGERS */ + + _Interrupt_Manager_initialization(); + + _Multiprocessing_Manager_initialization(); + + _Timer_Manager_initialization( configuration_table->maximum_timers ); + + _Extension_Manager_initialization( configuration_table->maximum_extensions ); + + _IO_Manager_initialization( + configuration_table->Device_driver_table, + configuration_table->number_of_device_drivers + ); + + _Event_Manager_initialization(); + + _Message_queue_Manager_initialization( + configuration_table->maximum_message_queues, + configuration_table->maximum_messages + ); + + _Semaphore_Manager_initialization( + configuration_table->maximum_semaphores + ); + + _Partition_Manager_initialization( + configuration_table->maximum_partitions + ); + + _Region_Manager_initialization( configuration_table->maximum_regions ); + + _Dual_ported_memory_Manager_initialization( + configuration_table->maximum_ports + ); + + _Rate_monotonic_Manager_initialization( + configuration_table->maximum_periods + ); + + _Internal_threads_Initialization(); + + if ( cpu_table->pretasking_hook ) + (*cpu_table->pretasking_hook)(); + + _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING ); + + return bsp_level; +} + +void rtems_initialize_executive_late( + rtems_interrupt_level bsp_level +) +{ + + _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING ); + + _Thread_Start_multitasking( + _Internal_threads_System_initialization_thread, + _Internal_threads_Idle_thread + ); + + /* + * Restore the interrupt level to what the BSP had. Technically, + * this is unnecessary since the BSP should have all interrupts + * disabled when rtems_initialize_executive is invoked. But this keeps + * the ISR Disable/Enable calls paired. + */ + + _ISR_Enable( bsp_level ); +} + +/*PAGE + * + * rtems_shutdown_executive + * + * This kernel routine shutdowns the executive. It halts multitasking + * and returns control to the application execution "thread" which + * initialially invoked the rtems_initialize_executive directive. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void rtems_shutdown_executive( + unsigned32 result +) +{ + _Thread_Stop_multitasking(); +} diff --git a/cpukit/sapi/src/extension.c b/cpukit/sapi/src/extension.c new file mode 100644 index 0000000000..10c974ef8e --- /dev/null +++ b/cpukit/sapi/src/extension.c @@ -0,0 +1,156 @@ +/* + * Extension Manager + * + * + * 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 +#include +#include +#include + +/*PAGE + * + * _Extension_Manager_initialization + * + * This routine initializes all extension manager related data structures. + * + * Input parameters: + * maximum_extensions - number of extensions to initialize + * + * Output parameters: NONE + */ + +void _Extension_Manager_initialization( + unsigned32 maximum_extensions +) +{ + _Objects_Initialize_information( + &_Extension_Information, + FALSE, + maximum_extensions, + sizeof( Extension_Control ) + ); +} + +/*PAGE + * + * rtems_extension_create + * + * This directive creates a extension and performs some initialization. + * + * Input parameters: + * name - extension name + * extension_table - pointer to extension set information + * id - pointer to extension id + * + * Output parameters: + * id - extension id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_extension_create( + Objects_Name name, + rtems_extensions_table *extension_table, + Objects_Id *id +) +{ + Extension_Control *the_extension; + + if ( !_Objects_Is_name_valid( name ) ) + return ( RTEMS_INVALID_NAME ); + + _Thread_Disable_dispatch(); /* to prevent deletion */ + + the_extension = _Extension_Allocate(); + + if ( !the_extension ) { + _Thread_Enable_dispatch(); + return( RTEMS_TOO_MANY ); + } + + _User_extensions_Add_set( &the_extension->Extension, extension_table ); + + _Objects_Open( &_Extension_Information, &the_extension->Object, name ); + + *id = the_extension->Object.id; + _Thread_Enable_dispatch(); + return( RTEMS_SUCCESSFUL ); +} + +/*PAGE + * + * rtems_extension_ident + * + * This directive returns the system ID associated with + * the extension name. + * + * Input parameters: + * name - user defined message queue name + * id - pointer to extension id + * + * Output parameters: + * *id - message queue id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_extension_ident( + Objects_Name name, + Objects_Id *id +) +{ + return _Objects_Name_to_id( + &_Extension_Information, + name, + RTEMS_SEARCH_LOCAL_NODE, + id + ); +} + +/*PAGE + * + * rtems_extension_delete + * + * This directive allows a thread to delete a extension. + * + * Input parameters: + * id - extension id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_extension_delete( + Objects_Id id +) +{ + Extension_Control *the_extension; + Objects_Locations location; + + the_extension = _Extension_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + case OBJECTS_REMOTE: /* should never return this */ + return( RTEMS_INVALID_ID ); + case OBJECTS_LOCAL: + _User_extensions_Remove_set( &the_extension->Extension ); + _Objects_Close( &_Extension_Information, &the_extension->Object ); + _Extension_Free( the_extension ); + _Thread_Enable_dispatch(); + return( RTEMS_SUCCESSFUL ); + } + + return( RTEMS_INTERNAL_ERROR ); /* unreached - only to remove warnings */ +} diff --git a/cpukit/sapi/src/fatal.c b/cpukit/sapi/src/fatal.c new file mode 100644 index 0000000000..2ecc73ff3f --- /dev/null +++ b/cpukit/sapi/src/fatal.c @@ -0,0 +1,54 @@ +/* + * Fatal Error Manager + * + * 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 +#include +#include +#include +#include + +/*PAGE + * + * rtems_fatal_error_occurred + * + * This directive will invoke the fatal error handler supplied by the user + * followed by the the default one provided by the executive. The default + * error handler assumes no hardware is present to help inform the user + * of the problem. Halt stores the error code in a known register, + * disables interrupts, and halts the CPU. If the CPU does not have a + * halt instruction, it will loop to itself. + * + * Input parameters: + * the_error - fatal error status code + * + * Output parameters: + * the_error - on stack + * status register - on stack + * + * NOTE: The the_error is not necessarily a directive status code. + */ + +void volatile rtems_fatal_error_occurred( + unsigned32 the_error +) +{ + + _User_extensions_Fatal( the_error ); + + _System_state_Set( SYSTEM_STATE_FAILED ); + + _CPU_Fatal_halt( the_error ); + +/* will not return from this routine */ +} diff --git a/cpukit/sapi/src/io.c b/cpukit/sapi/src/io.c new file mode 100644 index 0000000000..cf78bb9f71 --- /dev/null +++ b/cpukit/sapi/src/io.c @@ -0,0 +1,316 @@ +/* + * Input/Output Manager + * + * + * 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 +#include +#include +#include +#include + +/*PAGE + * + * _IO_Initialize_all_drivers + * + * This routine initializes all device drivers + * + * Input Paramters: NONE + * + * Output Parameters: NONE + */ + +void _IO_Initialize_all_drivers( void ) +{ + rtems_device_major_number major; + unsigned32 ignored; + + for ( major=0 ; major < _IO_Number_of_drivers ; major ++ ) + (void) rtems_io_initialize( major, 0, _Configuration_Table, &ignored ); +} + +/*PAGE + * + * rtems_io_initialize + * + * This routine is the initialization directive of the IO manager. + * + * Input Paramters: + * major - device driver number + * minor - device number + * argument - pointer to argument(s) + * return_value - pointer to driver's return value + * + * Output Parameters: + * returns - return code + * *return_value - driver's return code + */ + +rtems_status_code rtems_io_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument, + unsigned32 *return_value +) +{ + return _IO_Handler_routine( + IO_INITIALIZE_OPERATION, + major, + minor, + argument, + return_value + ); +} + +/*PAGE + * + * rtems_io_open + * + * This routine is the open directive of the IO manager. + * + * Input Paramters: + * major - device driver number + * minor - device number + * argument - pointer to argument(s) + * return_value - pointer to driver's return value + * + * Output Parameters: + * returns - return code + * *return_value - driver's return code + */ + +rtems_status_code rtems_io_open( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument, + unsigned32 *return_value +) +{ + return _IO_Handler_routine( + IO_OPEN_OPERATION, + major, + minor, + argument, + return_value + ); +} + +/*PAGE + * + * rtems_io_close + * + * This routine is the close directive of the IO manager. + * + * Input Paramters: + * major - device driver number + * minor - device number + * argument - pointer to argument(s) + * return_value - pointer to driver's return value + * + * Output Parameters: + * returns - return code + * *return_value - driver's return code + */ + +rtems_status_code rtems_io_close( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument, + unsigned32 *return_value +) +{ + return _IO_Handler_routine( + IO_CLOSE_OPERATION, + major, + minor, + argument, + return_value + ); +} + +/*PAGE + * + * rtems_io_read + * + * This routine is the read directive of the IO manager. + * + * Input Paramters: + * major - device driver number + * minor - device number + * argument - pointer to argument(s) + * return_value - pointer to driver's return value + * + * Output Parameters: + * returns - return code + * *return_value - driver's return code + */ + +rtems_status_code rtems_io_read( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument, + unsigned32 *return_value +) +{ + return _IO_Handler_routine( + IO_READ_OPERATION, + major, + minor, + argument, + return_value + ); +} + +/*PAGE + * + * rtems_io_write + * + * This routine is the write directive of the IO manager. + * + * Input Paramters: + * major - device driver number + * minor - device number + * argument - pointer to argument(s) + * return_value - pointer to driver's return value + * + * Output Parameters: + * returns - return code + * *return_value - driver's return code + */ + +rtems_status_code rtems_io_write( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument, + unsigned32 *return_value +) +{ + return _IO_Handler_routine( + IO_WRITE_OPERATION, + major, + minor, + argument, + return_value + ); +} + +/*PAGE + * + * rtems_io_control + * + * This routine is the control directive of the IO manager. + * + * Input Paramters: + * major - device driver number + * minor - device number + * argument - pointer to argument(s) + * return_value - pointer to driver's return value + * + * Output Parameters: + * returns - return code + * *return_value - driver's return code + */ + +rtems_status_code rtems_io_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument, + unsigned32 *return_value +) +{ + return _IO_Handler_routine( + IO_CONTROL_OPERATION, + major, + minor, + argument, + return_value + ); +} + +/*PAGE + * + * _IO_Handler_routine + * + * This routine implements all IO manager directives. + * + * Input Paramters: + * operation - I/O operation to be performed + * major - device driver number + * minor - device number + * argument - pointer to argument(s) + * return_value - pointer to driver's return value + * + * Output Parameters: + * returns - return code + * *return_value - driver's return code + */ + +rtems_status_code _IO_Handler_routine( + IO_operations operation, + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument, + unsigned32 *return_value +) +{ + rtems_device_driver_entry io_callout; + + /* + * NOTE: There is no range checking as in Ada because: + * + arrays in Ada are not always zero based. + * + with zero based arrays, a comparison of an unsigned + * number being less than zero would be necessary to + * check it as a range. This would cause a warning for + * checking an unsigned number for being negative. + */ + + if ( major >= _IO_Number_of_drivers ) + return ( RTEMS_INVALID_NUMBER ); + + switch ( operation ) { + case IO_INITIALIZE_OPERATION: + io_callout = _IO_Driver_address_table[ major ].initialization; + break; + case IO_OPEN_OPERATION: + io_callout = _IO_Driver_address_table[ major ].open; + break; + case IO_CLOSE_OPERATION: + io_callout = _IO_Driver_address_table[ major ].close; + break; + case IO_READ_OPERATION: + io_callout = _IO_Driver_address_table[ major ].read; + break; + case IO_WRITE_OPERATION: + io_callout = _IO_Driver_address_table[ major ].write; + break; + case IO_CONTROL_OPERATION: + io_callout = _IO_Driver_address_table[ major ].control; + break; + default: /* unreached -- only to remove warnings */ + io_callout = NULL; + break; + } + + if ( io_callout != NULL ) + (*io_callout)( + major, + minor, + argument, + _Thread_Executing->Object.id, + return_value + ); + else + *return_value = 0; + + return( RTEMS_SUCCESSFUL ); +} -- cgit v1.2.3