diff options
Diffstat (limited to 'cpukit')
307 files changed, 56008 insertions, 0 deletions
diff --git a/cpukit/libcsupport/include/clockdrv.h b/cpukit/libcsupport/include/clockdrv.h new file mode 100644 index 0000000000..258c590e0d --- /dev/null +++ b/cpukit/libcsupport/include/clockdrv.h @@ -0,0 +1,51 @@ +/* clock.h + * + * This file describes the Clock Driver for all boards. + * + * 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$ + */ + +#ifndef __CLOCK_DRIVER_h +#define __CLOCK_DRIVER_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* variables */ + +extern volatile rtems_unsigned32 Clock_driver_ticks; +extern rtems_device_major_number rtems_clock_major; +extern rtems_device_minor_number rtems_clock_minor; + +/* default clock driver entry */ + +#define CLOCK_DRIVER_TABLE_ENTRY \ + { Clock_initialize, NULL, NULL, NULL, NULL, Clock_control } + +rtems_device_driver Clock_initialize( + rtems_device_major_number, + rtems_device_minor_number, + void * +); + +rtems_device_driver Clock_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/libcsupport/include/console.h b/cpukit/libcsupport/include/console.h new file mode 100644 index 0000000000..02196de7a9 --- /dev/null +++ b/cpukit/libcsupport/include/console.h @@ -0,0 +1,69 @@ +/* console.h + * + * This file describes the Console Device Driver for all boards. + * This driver provides support for the standard C Library. + * + * 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$ + */ + +#ifndef _CONSOLE_DRIVER_h +#define _CONSOLE_DRIVER_h + +#ifdef __cplusplus +extern "C" { +#endif + +#define CONSOLE_DRIVER_TABLE_ENTRY \ + { console_initialize, console_open, console_close, \ + console_read, console_write, console_control } + +rtems_device_driver console_initialize( + rtems_device_major_number, + rtems_device_minor_number, + void * +); + +rtems_device_driver console_open( + rtems_device_major_number, + rtems_device_minor_number, + void * +); + +rtems_device_driver console_close( + rtems_device_major_number, + rtems_device_minor_number, + void * +); + +rtems_device_driver console_read( + rtems_device_major_number, + rtems_device_minor_number, + void * +); + +rtems_device_driver console_write( + rtems_device_major_number, + rtems_device_minor_number, + void * +); + +rtems_device_driver console_control( + rtems_device_major_number, + rtems_device_minor_number, + void * +); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/libcsupport/include/iosupp.h b/cpukit/libcsupport/include/iosupp.h new file mode 100644 index 0000000000..5f4a83b8ca --- /dev/null +++ b/cpukit/libcsupport/include/iosupp.h @@ -0,0 +1,44 @@ +/* iosupp.h + * + * 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$ + */ + +#ifndef __IOSUPP_h +#define __IOSUPP_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* character constants */ + +#define BS 0x08 /* backspace */ +#define LF 0x0a /* line feed */ +#define CR 0x0d /* carriage return */ +#define XON 0x11 /* control-Q */ +#define XOFF 0x13 /* control-S */ + +/* structures */ + +#ifdef IOSUPP_INIT +#define IOSUPP_EXTERN +#else +#undef IOSUPP_EXTERN +#define IOSUPP_EXTERN extern +#endif + +/* functions */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/cpukit/libcsupport/include/ringbuf.h b/cpukit/libcsupport/include/ringbuf.h new file mode 100644 index 0000000000..8c80aaf9c8 --- /dev/null +++ b/cpukit/libcsupport/include/ringbuf.h @@ -0,0 +1,53 @@ +/* + * ringbuf.h + * + * This file provides simple ring buffer functionality. + * + * $Id$ + */ + +#ifndef __RINGBUF_H__ +#define __RINGBUF_H__ + +#ifndef RINGBUF_QUEUE_LENGTH +#define RINGBUF_QUEUE_LENGTH 128 +#endif + +typedef struct { + char buffer[RINGBUF_QUEUE_LENGTH]; + volatile int head; + volatile int tail; +} Ring_buffer_t; + +#define Ring_buffer_Initialize( _buffer ) \ + do { \ + (_buffer)->head = (_buffer)->tail = 0; \ + } while ( 0 ) + +#define Ring_buffer_Is_empty( _buffer ) \ + ( (_buffer)->head == (_buffer)->tail ) + +#define Ring_buffer_Is_full( _buffer ) \ + ( (_buffer)->head == ((_buffer)->tail + 1) % RINGBUF_QUEUE_LENGTH ) + +#define Ring_buffer_Add_character( _buffer, _ch ) \ + do { \ + rtems_unsigned32 isrlevel; \ + \ + rtems_interrupt_disable( isrlevel ); \ + (_buffer)->tail = ((_buffer)->tail+1) % RINGBUF_QUEUE_LENGTH; \ + (_buffer)->buffer[ (_buffer)->tail ] = (_ch); \ + rtems_interrupt_enable( isrlevel ); \ + } while ( 0 ) + +#define Ring_buffer_Remove_character( _buffer, _ch ) \ + do { \ + rtems_unsigned32 isrlevel; \ + \ + rtems_interrupt_disable( isrlevel ); \ + (_buffer)->head = ((_buffer)->head+1) % RINGBUF_QUEUE_LENGTH; \ + (_ch) = (_buffer)->buffer[ (_buffer)->head ]; \ + rtems_interrupt_enable( isrlevel ); \ + } while ( 0 ) + +#endif diff --git a/cpukit/libcsupport/include/rtems/assoc.h b/cpukit/libcsupport/include/rtems/assoc.h new file mode 100644 index 0000000000..1982d654ac --- /dev/null +++ b/cpukit/libcsupport/include/rtems/assoc.h @@ -0,0 +1,42 @@ +/* + * + * Rtems associativity routines. Mainly used to convert a value from + * one space to another (eg: our errno's to host errno's and v.v) + * + * + * $Id$ + */ + +#ifndef _INCLUDE_ASSOC_H +#define _INCLUDE_ASSOC_H + +typedef struct { + const char *name; + unsigned32 local_value; + unsigned32 remote_value; +} rtems_assoc_t; + +/* + * Flag/marker for optional default value in each table + */ + +#define RTEMS_ASSOC_DEFAULT_NAME "(default)" + +const rtems_assoc_t *rtems_assoc_ptr_by_name(const rtems_assoc_t *, const char *); +const rtems_assoc_t *rtems_assoc_ptr_by_value(const rtems_assoc_t *, unsigned32); +const rtems_assoc_t *rtems_assoc_ptr_by_remote(const rtems_assoc_t *, unsigned32); + +unsigned32 rtems_assoc_remote_by_local(const rtems_assoc_t *, unsigned32); +unsigned32 rtems_assoc_local_by_remote(const rtems_assoc_t *, unsigned32); +unsigned32 rtems_assoc_remote_by_name(const rtems_assoc_t *, const char *); +unsigned32 rtems_assoc_local_by_name(const rtems_assoc_t *, const char *); +const char *rtems_assoc_name_by_local(const rtems_assoc_t *, unsigned32); +const char *rtems_assoc_name_by_remote(const rtems_assoc_t *, unsigned32); + +unsigned32 rtems_assoc_remote_by_local_bitfield(const rtems_assoc_t *, unsigned32); +char *rtems_assoc_name_by_local_bitfield(const rtems_assoc_t *, unsigned32, char *); +char *rtems_assoc_name_by_remote_bitfield(const rtems_assoc_t *, unsigned32, char *); +unsigned32 rtems_assoc_local_by_remote_bitfield(const rtems_assoc_t *, unsigned32); + + +#endif /* ! _INCLUDE_ASSOC_H */ diff --git a/cpukit/libcsupport/include/rtems/error.h b/cpukit/libcsupport/include/rtems/error.h new file mode 100644 index 0000000000..e4d8c77200 --- /dev/null +++ b/cpukit/libcsupport/include/rtems/error.h @@ -0,0 +1,33 @@ +/* + * Defines and externs for rtems error reporting + * + * $Id$ + */ + +#ifndef __RTEMS_ERROR_h +#define __RTEMS_ERROR_h + +/* + * rtems_error() and rtems_panic() support + */ + +#define RTEMS_ERROR_ERRNO (1<<((sizeof(int) * 8) - 2)) /* hi bit; use 'errno' */ +#define RTEMS_ERROR_PANIC (RTEMS_ERROR_ERRNO / 2) /* err fatal; no return */ +#define RTEMS_ERROR_ABORT (RTEMS_ERROR_ERRNO / 4) /* err is fatal; panic */ + +#define RTEMS_ERROR_MASK (RTEMS_ERROR_ERRNO | RTEMS_ERROR_ABORT | \ + RTEMS_ERROR_PANIC) /* all */ + +const char *rtems_status_text(rtems_status_code); +int rtems_error(int error_code, const char *printf_format, ...); +#ifdef __GNUC__ +void rtems_panic(const char *printf_format, ...) + __attribute__ ((__noreturn__)); +#else +void rtems_panic(const char *printf_format, ...); +#endif + +extern int rtems_panic_in_progress; + +#endif +/* end of include file */ diff --git a/cpukit/libcsupport/include/rtems/libcsupport.h b/cpukit/libcsupport/include/rtems/libcsupport.h new file mode 100644 index 0000000000..f43cd189e1 --- /dev/null +++ b/cpukit/libcsupport/include/rtems/libcsupport.h @@ -0,0 +1,42 @@ +/* libcsupport.h + * + * This include file contains the information regarding the + * RTEMS specific support for the standard C library. + * + * 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$ + */ + +#ifndef __LIBC_SUPPORT_h +#define __LIBC_SUPPORT_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <sys/types.h> + +void RTEMS_Malloc_Initialize( + void *start, + size_t length, + size_t sbrk_amount +); + +extern void malloc_dump(void); +extern void libc_init(int reentrant); +extern int host_errno(void); +extern void fix_syscall_errno(void); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/libcsupport/include/rtems/libio.h b/cpukit/libcsupport/include/rtems/libio.h new file mode 100644 index 0000000000..07d72620b1 --- /dev/null +++ b/cpukit/libcsupport/include/rtems/libio.h @@ -0,0 +1,98 @@ +/* + * General purpose communication channel for RTEMS to allow UNIX/POSIX + * system call behavior on top of RTEMS IO devices. + * + * TODO + * stat(2) + * unlink(2) + * rename(2) + * + * $Id$ + */ + +#ifndef _RTEMS_LIBIO_H +#define _RTEMS_LIBIO_H + +typedef unsigned32 rtems_libio_offset_t; + +/* + * An open file data structure, indexed by 'fd' + * TODO: + * should really have a separate per/file data structure that this + * points to (eg: size, offset, driver, pathname should be in that) + */ + +typedef struct { + rtems_driver_name_t *driver; + rtems_libio_offset_t size; /* size of file */ + rtems_libio_offset_t offset; /* current offset into the file */ + unsigned32 flags; + char *pathname; /* opened pathname */ + Objects_Id sem; + unsigned32 data0; /* private to "driver" */ + unsigned32 data1; /* ... */ +} rtems_libio_t; + + +/* + * param block for read/write + * Note: it must include 'offset' instead of using iop's offset since + * we can have multiple outstanding i/o's on a device. + */ + +typedef struct { + rtems_libio_t *iop; + rtems_libio_offset_t offset; + unsigned8 *buffer; + unsigned32 count; + unsigned32 flags; + unsigned32 bytes_moved; +} rtems_libio_rw_args_t; + +/* + * param block for open/close + */ + +typedef struct { + rtems_libio_t *iop; + unsigned32 flags; + unsigned32 mode; +} rtems_libio_open_close_args_t; + +/* + * param block for ioctl + */ + +typedef struct { + rtems_libio_t *iop; + unsigned32 command; + void *buffer; + unsigned32 ioctl_return; +} rtems_libio_ioctl_args_t; + + +/* + * Values for 'flag' + */ + +#define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */ +#define LIBIO_FLAGS_READ 0x0002 /* reading */ +#define LIBIO_FLAGS_WRITE 0x0004 /* writing */ +#define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */ +#define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ +#define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ +#define LIBIO_FLAGS_CREATE 0x0400 /* create file */ + +#define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) + +void rtems_libio_config(rtems_configuration_table *config, unsigned32 max_fds); +void rtems_libio_init(void); + +int __open(const char *pathname, unsigned32 flag, unsigned32 mode); +int __close(int fd); +int __read(int fd, void *buffer, unsigned32 count); +int __write(int fd, const void *buffer, unsigned32 count); +int __ioctl(int fd, unsigned32 command, void *buffer); +int __lseek(int fd, rtems_libio_offset_t offset, int whence); + +#endif /* _RTEMS_LIBIO_H */ diff --git a/cpukit/libcsupport/include/spurious.h b/cpukit/libcsupport/include/spurious.h new file mode 100644 index 0000000000..428e826164 --- /dev/null +++ b/cpukit/libcsupport/include/spurious.h @@ -0,0 +1,38 @@ +/* spurious.h + * + * This file describes the Spurious Interrupt Driver for all boards. + * + * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993. + * On-Line Applications Research Corporation (OAR). + * + * 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$ + */ + +#ifndef __SPURIOUS_h +#define __SPURIOUS_h + +#ifdef __cplusplus +extern "C" { +#endif + +#define SPURIOUS_DRIVER_TABLE_ENTRY \ + { Spurious_Initialize, NULL, NULL, NULL, NULL, NULL } + +rtems_device_driver Spurious_Initialize( + rtems_device_major_number, + rtems_device_minor_number, + void *, + rtems_id, + rtems_unsigned32 * +); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/libcsupport/include/sys/utsname.h b/cpukit/libcsupport/include/sys/utsname.h new file mode 100644 index 0000000000..ca15230d40 --- /dev/null +++ b/cpukit/libcsupport/include/sys/utsname.h @@ -0,0 +1,49 @@ +/* sys/utsname.h + * + * $Id$ + */ + +#ifndef __POSIX_SYS_UTSNAME_h +#define __POSIX_SYS_UTSNAME_h + +#include <sys/times.h> +#include <sys/types.h> + +/* + * 4.4.1 Get System Name (Table 4-1), P1003.1b-1993, p. 90 + * + * NOTE: The lengths of the strings in this structure are + * just long enough to reliably contain the RTEMS information. + * For example, the fields are not long enough to support + * Internet hostnames. + */ + +struct utsname { + char sysname[ 32 ]; /* Name of this implementation of the operating system */ + char nodename[ 32 ]; /* Name of this node within an implementation */ + /* specified communication network */ + char release[ 32 ]; /* Current release level of this implementation */ + char version[ 32 ]; /* Current version level of this release */ + char machine[ 32 ]; /* Name of the hardware type on which the system */ + /* is running */ +}; + +/* + * 4.4.1 Get System Name, P1003.1b-1993, p. 90 + */ + +int uname( + struct utsname *name +); + +/* + * 4.5.2 Get Process Times, P1003.1b-1993, p. 92 + */ + +clock_t times( + struct tms *buffer +); + +#endif +/* end of include file */ + diff --git a/cpukit/libcsupport/include/timerdrv.h b/cpukit/libcsupport/include/timerdrv.h new file mode 100644 index 0000000000..d091b62410 --- /dev/null +++ b/cpukit/libcsupport/include/timerdrv.h @@ -0,0 +1,40 @@ +/* timerdrv.h + * + * This file describes the Timer Driver for all boards. + * + * 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$ + */ + +#ifndef __TIMER_DRIVER_h +#define __TIMER_DRIVER_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* functions */ + +void Timer_initialize( void ); + +rtems_unsigned32 Read_timer( void ); + +rtems_status_code Empty_function( void ); + +void Set_find_average_overhead( + rtems_boolean find_flag +); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/libcsupport/include/vmeintr.h b/cpukit/libcsupport/include/vmeintr.h new file mode 100644 index 0000000000..6148114ce8 --- /dev/null +++ b/cpukit/libcsupport/include/vmeintr.h @@ -0,0 +1,58 @@ +/* + * vmeintr.h + * + * This file is the specification for the VMEbus interface library + * which should be provided by all BSPs for VMEbus Single Board + * Computers but currently only a few do so. + * + * 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$ + */ + +#ifndef __VME_INTERRUPT_h +#define __VME_INTERRUPT_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This defines the mask which is used to determine which + * interrupt levels are affected by a call to this package. + * The LSB corresponds to VME interrupt 0 and the MSB + * to VME interrupt 7. + * + */ + +typedef rtems_unsigned8 VME_interrupt_Mask; + +/* + * VME_interrupt_Disable + * + */ + +void VME_interrupt_Disable ( + VME_interrupt_Mask mask /* IN */ +); + +/* + * VME_interrupt_Disable + * + */ + +void VME_interrupt_Enable ( + VME_interrupt_Mask mask /* IN */ +); + +#ifdef __cplusplus +} +#endif + +#endif /* end of include file */ diff --git a/cpukit/libcsupport/src/README b/cpukit/libcsupport/src/README new file mode 100644 index 0000000000..ee7a90501e --- /dev/null +++ b/cpukit/libcsupport/src/README @@ -0,0 +1,37 @@ +-- +-- $Id$ +-- + +Overview of newlib support (newlib is from CYGNUS) + Each task can have its own libc state including: + open stdio files + strtok + multi precision arithmetic state + etc. + + This is implemented by a reentrancy data structure for each task. + + When a task is "started" (in RTEMS sense) the reentrancy structure + is allocated. Its address is stored in notepad[NOTEPAD_LAST]. + + When task is switched to, the value of global variable _impure_ptr + is changed to the value of the new tasks reentrancy structure. + + When a task is deleted + atexit() processing (for that task) happens + task's stdio buffers are flushed + + When exit(3) is called + calling task's atexit processing done + global libc state atexit processing done + (this will include any atexit routines installed by drivers) + executive is shutdown + causes a context switch back to bsp land + + +NOTE: + libc extension are installed by bsp_libc_init() + iff we are using clock interrupts. + This hack is necessary to allow the tmtests to avoid + timing the extensions. + diff --git a/cpukit/libcsupport/src/__brk.c b/cpukit/libcsupport/src/__brk.c new file mode 100644 index 0000000000..5f256cb072 --- /dev/null +++ b/cpukit/libcsupport/src/__brk.c @@ -0,0 +1,44 @@ +#if !defined(RTEMS_UNIX) + +/* + * RTEMS "Broken" __brk/__sbrk Implementation + * + * NOTE: sbrk is BSP provided. + * + * + * 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 <signal.h> +#include <errno.h> +#include <sys/types.h> +#ifdef RTEMS_NEWLIB +#include <reent.h> +#endif +#include <unistd.h> + +/* we use RTEMS for memory management. We don't need sbrk */ + +void * __sbrk(int incr) +{ + errno = EINVAL; + return (void *)0; +} + +int __brk( const void *endds ) +{ + errno = EINVAL; + return -1; +} + +#endif diff --git a/cpukit/libcsupport/src/__gettod.c b/cpukit/libcsupport/src/__gettod.c new file mode 100644 index 0000000000..6c9350d41c --- /dev/null +++ b/cpukit/libcsupport/src/__gettod.c @@ -0,0 +1,103 @@ +#if !defined(RTEMS_UNIX) +/* + * RTEMS gettimeofday Implementation + * + * + * 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> + +#ifdef RTEMS_NEWLIB +#include <sys/reent.h> +#endif + +#include <time.h> +#include <sys/time.h> + +#include <errno.h> +#include <assert.h> + +/* + * NOTE: The solaris gettimeofday does not have a second parameter. + */ + +int gettimeofday( + struct timeval *tp, + struct timezone *tzp +) +{ + rtems_status_code status; + rtems_clock_time_value time; + + if ( !tp ) { + errno = EFAULT; + return -1; + } + + /* "POSIX" does not seem to allow for not having a TOD */ + status = rtems_clock_get( RTEMS_CLOCK_GET_TIME_VALUE, &time ); + if ( status != RTEMS_SUCCESSFUL ) { + assert( 0 ); + return -1; + } + + tp->tv_sec = time.seconds; + tp->tv_usec = time.microseconds; + + /* + * newlib does not have timezone and daylight savings time + * yet. When it does this needs to be fixed. + */ + +#if 0 + if ( tzp ) { + tzp->tz_minuteswest = 0; /* at UTC */ + tzp->tz_dsttime = 0; /* no daylight savings */ + tzp->minuteswest = timezone / 60; /* from seconds to minutes */ + tzp->dsttime = daylight; + } +#endif + return 0; +} + +#if defined(RTEMS_NEWLIB) + +#if 0 +/* + * "Reentrant" version + */ + +int _gettimeofday_r( + struct _reent *ignored_reentrancy_stuff, + struct timeval *tp, + struct timezone *tzp +) +{ + return gettimeofday( tp, tzp ); +} +#endif + +/* + * "System call" version + */ + +int _gettimeofday( + struct timeval *tp, + struct timezone *tzp +) +{ + return gettimeofday( tp, tzp ); +} + +#endif /* defined(RTEMS_NEWLIB) */ + +#endif diff --git a/cpukit/libcsupport/src/__times.c b/cpukit/libcsupport/src/__times.c new file mode 100644 index 0000000000..12fd9241fe --- /dev/null +++ b/cpukit/libcsupport/src/__times.c @@ -0,0 +1,65 @@ +/* + * RTEMS _times Implementation + * + * + * 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 <sys/times.h> +#include <time.h> +#include <sys/time.h> +#include <errno.h> +#include <assert.h> + +clock_t _times( + struct tms *ptms +) +{ + rtems_status_code status; + rtems_interval ticks_since_boot; + + if ( !ptms ) { + errno = EFAULT; + return -1; + } + + /* "POSIX" does not seem to allow for not having a TOD */ + status = rtems_clock_get( + RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, + &ticks_since_boot + ); + if ( status != RTEMS_SUCCESSFUL ) { + assert( 0 ); + return -1; + } + + /* + * RTEMS has no notion of system versus user time and does + * not (as of 3.2.0) keep track of CPU usage on a per task basis. + */ + + ptms->tms_utime = ticks_since_boot; + ptms->tms_stime = 0; + ptms->tms_cutime = 0; + ptms->tms_cstime = 0; + + return 0; +} + +clock_t times( + struct tms *ptms +) +{ + return _times( ptms ); +} + diff --git a/cpukit/libcsupport/src/assoc.c b/cpukit/libcsupport/src/assoc.c new file mode 100644 index 0000000000..74387a8c5b --- /dev/null +++ b/cpukit/libcsupport/src/assoc.c @@ -0,0 +1,260 @@ +/* + * assoc.c + * rtems assoc routines + * + * $Id$ + */ + +#include <rtems.h> +#include "assoc.h" + +#include <stdio.h> /* sprintf */ +#include <string.h> /* strcat, strcmp */ + +#define STREQ(a,b) (strcmp((a), (b)) == 0) +#define rtems_assoc_is_default(ap) ((ap)->name && STREQ(ap->name, RTEMS_ASSOC_DEFAULT_NAME)) + +const rtems_assoc_t * +rtems_assoc_ptr_by_name( + const rtems_assoc_t *ap, + const char *name + ) +{ + const rtems_assoc_t *default_ap = 0; + + if (rtems_assoc_is_default(ap)) + default_ap = ap++; + + for ( ; ap->name; ap++) + if (strcmp(ap->name, name) == 0) + return ap; + + return default_ap; +} + +const rtems_assoc_t * +rtems_assoc_ptr_by_local( + const rtems_assoc_t *ap, + unsigned32 local_value + ) +{ + const rtems_assoc_t *default_ap = 0; + + if (rtems_assoc_is_default(ap)) + default_ap = ap++; + + for ( ; ap->name; ap++) + if (ap->local_value == local_value) + return ap; + + return default_ap; +} + + +const rtems_assoc_t * +rtems_assoc_ptr_by_remote( + const rtems_assoc_t *ap, + unsigned32 remote_value + ) +{ + const rtems_assoc_t *default_ap = 0; + + if (rtems_assoc_is_default(ap)) + default_ap = ap++; + + for ( ; ap->name; ap++) + if (ap->remote_value == remote_value) + return ap; + + return default_ap; +} + + +/* + * Get values + */ + +unsigned32 +rtems_assoc_remote_by_local( + const rtems_assoc_t *ap, + unsigned32 local_value + ) +{ + const rtems_assoc_t *nap; + nap = rtems_assoc_ptr_by_local(ap, local_value); + if (nap) + return nap->remote_value; + + return 0; +} + +unsigned32 +rtems_assoc_local_by_remote( + const rtems_assoc_t *ap, + unsigned32 remote_value + ) +{ + const rtems_assoc_t *nap; + nap = rtems_assoc_ptr_by_remote(ap, remote_value); + if (nap) + return nap->local_value; + + return 0; +} + +unsigned32 +rtems_assoc_remote_by_name( + const rtems_assoc_t *ap, + const char *name + ) +{ + const rtems_assoc_t *nap; + nap = rtems_assoc_ptr_by_name(ap, name); + if (nap) + return nap->remote_value; + + return 0; +} + +unsigned32 +rtems_assoc_local_by_name( + const rtems_assoc_t *ap, + const char *name + ) +{ + const rtems_assoc_t *nap; + nap = rtems_assoc_ptr_by_name(ap, name); + if (nap) + return nap->local_value; + + return 0; +} + +/* + * what to return if a value is not found + * this is not reentrant, but it really shouldn't be invoked anyway + */ + +const char * +rtems_assoc_name_bad( + unsigned32 bad_value +) +{ +#ifdef RTEMS_DEBUG + static char bad_buffer[32]; + + sprintf(bad_buffer, "< %d [0x%x] >", bad_value, bad_value); +#else + static char bad_buffer[32] = "<assoc.c: BAD NAME>"; +#endif + return bad_buffer; +} + + +const char * +rtems_assoc_name_by_local( + const rtems_assoc_t *ap, + unsigned32 local_value + ) +{ + const rtems_assoc_t *nap; + nap = rtems_assoc_ptr_by_local(ap, local_value); + if (nap) + return nap->name; + + return rtems_assoc_name_bad(local_value); +} + +const char * +rtems_assoc_name_by_remote( + const rtems_assoc_t *ap, + unsigned32 remote_value + ) +{ + const rtems_assoc_t *nap; + nap = rtems_assoc_ptr_by_remote(ap, remote_value); + if (nap) + return nap->name; + + return rtems_assoc_name_bad(remote_value); +} + +/* + * Bitfield functions assume just 1 bit set in each of remote and local + * entries; they do not check for this. + */ + +unsigned32 rtems_assoc_remote_by_local_bitfield( + const rtems_assoc_t *ap, + unsigned32 local_value + ) +{ + unsigned32 b; + unsigned32 remote_value = 0; + + for (b = 1; b; b <<= 1) + if (b & local_value) + remote_value |= rtems_assoc_remote_by_local(ap, b); + + return remote_value; +} + + +unsigned32 rtems_assoc_local_by_remote_bitfield( + const rtems_assoc_t *ap, + unsigned32 remote_value + ) +{ + unsigned32 b; + unsigned32 local_value = 0; + + for (b = 1; b; b <<= 1) + if (b & remote_value) + local_value |= rtems_assoc_local_by_remote(ap, b); + + return local_value; +} + +char * +rtems_assoc_name_by_remote_bitfield( + const rtems_assoc_t *ap, + unsigned32 value, + char *buffer + ) +{ + unsigned32 b; + + *buffer = 0; + + for (b = 1; b; b <<= 1) + if (b & value) + { + if (*buffer) + strcat(buffer, " "); + strcat(buffer, rtems_assoc_name_by_remote(ap, b)); + } + + return buffer; +} + +char * +rtems_assoc_name_by_local_bitfield( + const rtems_assoc_t *ap, + unsigned32 value, + char *buffer + ) +{ + unsigned32 b; + + *buffer = 0; + + for (b = 1; b; b <<= 1) + if (b & value) + { + if (*buffer) + strcat(buffer, " "); + strcat(buffer, rtems_assoc_name_by_local(ap, b)); + } + + return buffer; +} diff --git a/cpukit/libcsupport/src/error.c b/cpukit/libcsupport/src/error.c new file mode 100644 index 0000000000..5bd481c3e6 --- /dev/null +++ b/cpukit/libcsupport/src/error.c @@ -0,0 +1,209 @@ +/* + * report errors and panics to RTEMS' stderr. + * Currently just used by RTEMS monitor. + * + * $Id$ + */ + + +/* + * These routines provide general purpose error reporting. + * rtems_error reports an error to stderr and allows use of + * printf style formatting. A newline is appended to all messages. + * + * error_flag can be specified as any of the following: + * + * RTEMS_ERROR_ERRNO -- include errno text in output + * RTEMS_ERROR_PANIC -- halts local system after output + * RTEMS_ERROR_ABORT -- abort after output + * + * It can also include a rtems_status value which can be OR'd + * with the above flags. * + * + * EXAMPLE + * #include <rtems.h> + * #include <rtems/error.h> + * rtems_error(0, "stray interrupt %d", intr); + * + * EXAMPLE + * if ((status = rtems_task_create(...)) != RTEMS_SUCCCESSFUL) + * { + * rtems_error(status | RTEMS_ERROR_ABORT, + * "could not create task"); + * } + * + * EXAMPLE + * if ((fd = open(pathname, O_RDNLY)) < 0) + * { + * rtems_error(RTEMS_ERROR_ERRNO, "open of '%s' failed", pathname); + * goto failed; + * } + */ + +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#include <rtems.h> + +#include "error.h" +#include <rtems/assoc.h> + +#include <stdio.h> +#include <stdarg.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> /* _exit() */ + +/* bug in hpux <errno.h>: no prototypes unless you are C++ */ +#ifdef hpux9 +char *strerror(int); +#endif + +extern char *rtems_progname; +int rtems_panic_in_progress; + +rtems_assoc_t rtems_status_assoc[] = { + { "successful completion", RTEMS_SUCCESSFUL, }, + { "returned from a thread", RTEMS_TASK_EXITTED, }, + { "multiprocessing not configured", RTEMS_MP_NOT_CONFIGURED, }, + { "invalid object name", RTEMS_INVALID_NAME, }, + { "invalid object id", RTEMS_INVALID_ID, }, + { "too many", RTEMS_TOO_MANY, }, + { "timed out waiting", RTEMS_TIMEOUT, }, + { "object deleted while waiting", RTEMS_OBJECT_WAS_DELETED, }, + { "specified size was invalid", RTEMS_INVALID_SIZE, }, + { "address specified is invalid", RTEMS_INVALID_ADDRESS, }, + { "number was invalid", RTEMS_INVALID_NUMBER, }, + { "item has not been initialized", RTEMS_NOT_DEFINED, }, + { "resources still outstanding", RTEMS_RESOURCE_IN_USE, }, + { "request not satisfied", RTEMS_UNSATISFIED, }, + { "thread is in wrong state", RTEMS_INCORRECT_STATE, }, + { "thread already in state", RTEMS_ALREADY_SUSPENDED, }, + { "illegal on calling thread", RTEMS_ILLEGAL_ON_SELF, }, + { "illegal for remote object", RTEMS_ILLEGAL_ON_REMOTE_OBJECT, }, + { "called from wrong environment", RTEMS_CALLED_FROM_ISR, }, + { "invalid thread priority", RTEMS_INVALID_PRIORITY, }, + { "invalid date/time", RTEMS_INVALID_CLOCK, }, + { "invalid node id", RTEMS_INVALID_NODE, }, + { "directive not configured", RTEMS_NOT_CONFIGURED, }, + { "not owner of resource", RTEMS_NOT_OWNER_OF_RESOURCE , }, + { "directive not implemented", RTEMS_NOT_IMPLEMENTED, }, + { "RTEMS inconsistency detected", RTEMS_INTERNAL_ERROR, }, + { "could not get enough memory", RTEMS_NO_MEMORY, }, + { "internal multiprocessing only", THREAD_STATUS_PROXY_BLOCKING, }, + { 0, 0, 0 }, +}; + + +const char * +rtems_status_text( + rtems_status_code status +) +{ + return rtems_assoc_name_by_local(rtems_status_assoc, status); +} + + +static int rtems_verror( + unsigned32 error_flag, + const char *printf_format, + va_list arglist +) +{ + int local_errno = 0; + int chars_written = 0; + rtems_status_code status; + + if (error_flag & RTEMS_ERROR_PANIC) + { + rtems_panic_in_progress++; + + /* disable task switches */ + _Thread_Disable_dispatch(); + + /* don't aggravate things */ + if (rtems_panic_in_progress > 2) + return 0; + } + + (void) fflush(stdout); /* in case stdout/stderr same */ + + status = error_flag & ~RTEMS_ERROR_MASK; + if (error_flag & RTEMS_ERROR_ERRNO) /* include errno? */ + local_errno = errno; + + if (_System_state_Is_multiprocessing) + fprintf(stderr, "[%d] ", _Configuration_MP_table->node); + + if (rtems_progname && *rtems_progname) + chars_written += fprintf(stderr, "%s: ", rtems_progname); + chars_written += vfprintf(stderr, printf_format, arglist); + + if (status) + chars_written += fprintf(stderr, " (status: %s)", rtems_status_text(status)); + + if (local_errno) + if ((local_errno > 0) && *strerror(local_errno)) + chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno)); + else + chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno); + + chars_written += fprintf(stderr, "\n"); + + (void) fflush(stderr); + + if (error_flag & (RTEMS_ERROR_PANIC | RTEMS_ERROR_ABORT)) + { + if (error_flag & RTEMS_ERROR_PANIC) + { + rtems_error(0, "fatal error, exiting"); + _exit(local_errno); + } + else + { + rtems_error(0, "fatal error, aborting"); + abort(); + } + } + return chars_written; +} + + +/* + * Report an error. + * error_flag is as above; printf_format is a normal + * printf(3) format string, with its concommitant arguments. + * + * Returns the number of characters written. + */ + +int rtems_error( + int error_flag, + const char *printf_format, + ... + ) +{ + va_list arglist; + int chars_written; + + va_start(arglist, printf_format); + chars_written = rtems_verror(error_flag, printf_format, arglist); + va_end(arglist); + + return chars_written; +} + +/* + * rtems_panic is shorthand for rtems_error(RTEMS_ERROR_PANIC, ...) + */ + +void rtems_panic( + const char *printf_format, + ... + ) +{ + va_list arglist; + + va_start(arglist, printf_format); + (void) rtems_verror(RTEMS_ERROR_PANIC, printf_format, arglist); + va_end(arglist); +} diff --git a/cpukit/libcsupport/src/hosterr.c b/cpukit/libcsupport/src/hosterr.c new file mode 100644 index 0000000000..7fc2ca966e --- /dev/null +++ b/cpukit/libcsupport/src/hosterr.c @@ -0,0 +1,43 @@ +/* + * Routines to access a host errno + * + * 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 <errno.h> + +int host_errno(void); + +/* + * copy host errno, if any to thread aware errno, if any + */ + +void fix_syscall_errno(void) +{ + errno = host_errno(); +} + +/* + * Get the host system errno, if any + * When using newlib (or possibly other libc's) on top of UNIX + * the errno returned by system calls may be unavailable due + * to trickery of making errno thread aware. + * This provides a kludge of getting at it. + */ + +#undef errno +extern int errno; +int host_errno(void) +{ + return errno; +} + diff --git a/cpukit/libcsupport/src/libio.c b/cpukit/libcsupport/src/libio.c new file mode 100644 index 0000000000..a01dea7b8a --- /dev/null +++ b/cpukit/libcsupport/src/libio.c @@ -0,0 +1,442 @@ +/* + * Provide UNIX/POSIX-like io system calls for RTEMS using the + * RTEMS IO manager + * + * TODO + * + * $Id$ + */ + +#include <rtems.h> +#include <rtems/assoc.h> /* assoc.h not included by rtems.h */ + +#include <stdio.h> /* O_RDONLY, et.al. */ +#include <fcntl.h> /* O_RDONLY, et.al. */ + +#if defined(solaris2) +#define O_NDELAY O_NONBLOCK +#elif defined(RTEMS_NEWLIB) +#define O_NDELAY _FNBIO +#endif + +#include <errno.h> +#include <string.h> /* strcmp */ +#include <unistd.h> +#include <stdlib.h> /* calloc() */ + +#include "libio.h" /* libio.h not pulled in by rtems */ + +/* + * Semaphore to protect the io table + */ + +Objects_Id rtems_libio_semaphore; + +#define RTEMS_LIBIO_SEM rtems_build_name('L', 'B', 'I', 'O') +#define RTEMS_LIBIO_IOP_SEM(n) rtems_build_name('L', 'B', 'I', n) + +unsigned32 rtems_libio_number_iops; +rtems_libio_t *rtems_libio_iops; +rtems_libio_t *rtems_libio_last_iop; + +#define rtems_libio_iop(fd) ((((unsigned32)(fd)) < rtems_libio_number_iops) ? \ + &rtems_libio_iops[fd] : 0) + +#define rtems_libio_check_fd(fd) \ + do { \ + if ((fd) >= rtems_libio_number_iops) \ + { \ + errno = EBADF; \ + return -1; \ + } \ + } while (0) + +#define rtems_libio_check_buffer(buffer) \ + do { \ + if ((buffer) == 0) \ + { \ + errno = EINVAL; \ + return -1; \ + } \ + } while (0) + +#define rtems_libio_check_count(count) \ + do { \ + if ((count) == 0) \ + { \ + return 0; \ + } \ + } while (0) + +#define rtems_libio_check_permissions(iop, flag) \ + do { \ + if (((iop)->flags & (flag)) == 0) \ + { \ + errno = EINVAL; \ + return -1; \ + } \ + } while (0) + + +void +rtems_libio_config( + rtems_configuration_table *config, + unsigned32 max_fds + ) +{ + rtems_libio_number_iops = max_fds; + + /* + * tweak config to reflect # of semaphores we will need + */ + + config->maximum_semaphores += 1; /* one for iop table */ + config->maximum_semaphores += max_fds; +} + +/* + * Called by bsp startup code to init the libio area. + */ + +void +rtems_libio_init(void) +{ + rtems_status_code rc; + + if (rtems_libio_number_iops > 0) + { + rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops, + sizeof(rtems_libio_t)); + if (rtems_libio_iops == NULL) + rtems_fatal_error_occurred(RTEMS_NO_MEMORY); + + rtems_libio_last_iop = rtems_libio_iops + (rtems_libio_number_iops - 1); + } + + rc = rtems_semaphore_create( + RTEMS_LIBIO_SEM, + 1, + RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, + RTEMS_NO_PRIORITY, + &rtems_libio_semaphore + ); + if (rc != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(rc); +} + +/* + * Convert RTEMS status to a UNIX errno + */ + +rtems_assoc_t errno_assoc[] = { + { "OK", RTEMS_SUCCESSFUL, 0 }, + { "TIMEOUT", RTEMS_TIMEOUT, ETIME }, + { "NO MEMORY", RTEMS_NO_MEMORY, ENOMEM }, + { 0, 0, 0 }, +}; + +static unsigned32 +rtems_libio_errno(rtems_status_code code) +{ + int rc; + + if ((rc = rtems_assoc_remote_by_local(errno_assoc, (unsigned32) code))) + { + errno = rc; + return -1; + } + return 0; +} + +/* + * Convert UNIX fnctl(2) flags to ones that RTEMS drivers understand + */ + +rtems_assoc_t access_modes_assoc[] = { + { "READ", LIBIO_FLAGS_READ, O_RDONLY }, + { "WRITE", LIBIO_FLAGS_WRITE, O_WRONLY }, + { "READ/WRITE", LIBIO_FLAGS_READ_WRITE, O_RDWR }, + { 0, 0, 0 }, +}; + +rtems_assoc_t status_flags_assoc[] = { + { "NO DELAY", LIBIO_FLAGS_NO_DELAY, O_NDELAY }, + { "APPEND", LIBIO_FLAGS_APPEND, O_APPEND }, + { "CREATE", LIBIO_FLAGS_CREATE, O_CREAT }, + { 0, 0, 0 }, +}; + +static unsigned32 +rtems_libio_fcntl_flags(unsigned32 fcntl_flags) +{ + unsigned32 flags = 0; + unsigned32 access_modes; + + /* + * Access mode is a small integer + */ + + access_modes = fcntl_flags & O_ACCMODE; + fcntl_flags &= ~O_ACCMODE; + flags = rtems_assoc_local_by_remote(access_modes_assoc, access_modes); + + /* + * Everything else is single bits + */ + + flags |= rtems_assoc_local_by_remote_bitfield(status_flags_assoc, fcntl_flags); + return flags; +} + + +static rtems_libio_t * +rtems_libio_allocate(void) +{ + rtems_libio_t *iop; + rtems_status_code rc; + + rtems_semaphore_obtain(rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + + for (iop = rtems_libio_iops; iop <= rtems_libio_last_iop; iop++) + if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) + { + /* + * Got one; create a semaphore for it + */ + + rc = rtems_semaphore_create( + RTEMS_LIBIO_IOP_SEM(iop - rtems_libio_iops), + 1, + RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, + RTEMS_NO_PRIORITY, + &iop->sem + ); + if (rc != RTEMS_SUCCESSFUL) + goto failed; + + iop->flags = LIBIO_FLAGS_OPEN; + goto done; + } + +failed: + iop = 0; + +done: + rtems_semaphore_release(rtems_libio_semaphore); + return iop; +} + +static void +rtems_libio_free(rtems_libio_t *iop) +{ + rtems_semaphore_obtain(rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + + if (iop->sem) + rtems_semaphore_delete(iop->sem); + (void) memset(iop, 0, sizeof(*iop)); + + rtems_semaphore_release(rtems_libio_semaphore); +} + +int +__open( + const char *pathname, + unsigned32 flag, + unsigned32 mode) +{ + rtems_status_code rc; + rtems_libio_t *iop = 0; + rtems_driver_name_t *np; + rtems_libio_open_close_args_t args; + + if ((rc = rtems_io_lookup_name(pathname, &np)) != RTEMS_SUCCESSFUL) + goto done; + + iop = rtems_libio_allocate(); + if (iop == 0) + { + rc = RTEMS_TOO_MANY; + goto done; + } + + iop->driver = np; + iop->pathname = (char *) pathname; + iop->flags |= rtems_libio_fcntl_flags(flag); + + args.iop = iop; + args.flags = iop->flags; + args.mode = mode; + + rc = rtems_io_open(np->major, np->minor, (void *) &args); + +done: + if (rc != RTEMS_SUCCESSFUL) + { + if (iop) + rtems_libio_free(iop); + return rtems_libio_errno(rc); + } + + return iop - rtems_libio_iops; +} + +int +__close( + int fd + ) +{ + rtems_status_code rc; + rtems_driver_name_t *np; + rtems_libio_t *iop = rtems_libio_iop(fd); + rtems_libio_open_close_args_t args; + + rtems_libio_check_fd(fd); + + np = iop->driver; + + args.iop = iop; + args.flags = 0; + args.mode = 0; + + rc = rtems_io_close(np->major, np->minor, (void *) &args); + + if (rc != RTEMS_SUCCESSFUL) + return rtems_libio_errno(rc); + return 0; +} + +int +__read( + int fd, + void * buffer, + unsigned32 count + ) +{ + rtems_status_code rc; + rtems_driver_name_t *np; + rtems_libio_t *iop = rtems_libio_iop(fd); + rtems_libio_rw_args_t args; + + rtems_libio_check_fd(fd); + rtems_libio_check_buffer(buffer); + rtems_libio_check_count(count); + rtems_libio_check_permissions(iop, LIBIO_FLAGS_READ); + + np = iop->driver; + + args.iop = iop; + args.offset = iop->offset; + args.buffer = buffer; + args.count = count; + args.flags = iop->flags; + args.bytes_moved = 0; + + rc = rtems_io_read(np->major, np->minor, (void *) &args); + + iop->offset += args.bytes_moved; + + if (rc != RTEMS_SUCCESSFUL) + return rtems_libio_errno(rc); + + return args.bytes_moved; +} + +int +__write( + int fd, + const void *buffer, + unsigned32 count + ) +{ + rtems_status_code rc; + rtems_driver_name_t *np; + rtems_libio_t *iop = rtems_libio_iop(fd); + rtems_libio_rw_args_t args; + + rtems_libio_check_fd(fd); + rtems_libio_check_buffer(buffer); + rtems_libio_check_count(count); + rtems_libio_check_permissions(iop, LIBIO_FLAGS_WRITE); + + np = iop->driver; + + args.iop = iop; + args.offset = iop->offset; + args.buffer = (void *) buffer; + args.count = count; + args.flags = iop->flags; + args.bytes_moved = 0; + + rc = rtems_io_write(np->major, np->minor, (void *) &args); + + iop->offset += args.bytes_moved; + + if (rc != RTEMS_SUCCESSFUL) + return rtems_libio_errno(rc); + + return args.bytes_moved; +} + +int +__ioctl( + int fd, + unsigned32 command, + void * buffer) +{ + rtems_status_code rc; + rtems_driver_name_t *np; + rtems_libio_t *iop = rtems_libio_iop(fd); + rtems_libio_ioctl_args_t args; + + rtems_libio_check_fd(fd); + + np = iop->driver; + + args.iop = iop; + args.command = command; + args.buffer = buffer; + + rc = rtems_io_control(np->major, np->minor, (void *) &args); + + if (rc != RTEMS_SUCCESSFUL) + return rtems_libio_errno(rc); + + return args.ioctl_return; +} + +/* + * internal only?? + */ + + +int +__lseek( + int fd, + rtems_libio_offset_t offset, + int whence + ) +{ + rtems_libio_t *iop = rtems_libio_iop(fd); + + rtems_libio_check_fd(fd); + + switch (whence) + { + case SEEK_SET: + iop->offset = offset; + break; + + case SEEK_CUR: + iop->offset += offset; + break; + + case SEEK_END: + iop->offset = iop->size - offset; + break; + + default: + errno = EINVAL; + return -1; + } + return 0; +} diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c new file mode 100644 index 0000000000..de63df6ea0 --- /dev/null +++ b/cpukit/libcsupport/src/malloc.c @@ -0,0 +1,366 @@ +/* + * RTEMS Malloc Family Implementation + * + * + * 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 "libcsupport.h" +#ifdef RTEMS_NEWLIB +#include <sys/reent.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <assert.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> /* sbrk(2) */ + +rtems_id RTEMS_Malloc_Heap; +size_t RTEMS_Malloc_Sbrk_amount; + +#ifdef RTEMS_DEBUG +#define MALLOC_STATS +#define MALLOC_DIRTY +#endif + +#ifdef MALLOC_STATS +#define MSBUMP(f,n) malloc_stats.f += (n) + +struct { + unsigned32 space_available; /* current size of malloc area */ + unsigned32 malloc_calls; /* # calls to malloc */ + unsigned32 free_calls; + unsigned32 realloc_calls; + unsigned32 calloc_calls; + unsigned32 max_depth; /* most ever malloc'd at 1 time */ + unsigned64 lifetime_allocated; + unsigned64 lifetime_freed; +} malloc_stats; + +#else /* No malloc_stats */ +#define MSBUMP(f,n) +#endif + +void RTEMS_Malloc_Initialize( + void *start, + size_t length, + size_t sbrk_amount +) +{ + rtems_status_code status; + void *starting_address; + rtems_unsigned32 old_address; + rtems_unsigned32 u32_address; + + /* + * If the starting address is 0 then we are to attempt to + * get length worth of memory using sbrk. Make sure we + * align the address that we get back. + */ + + starting_address = start; + RTEMS_Malloc_Sbrk_amount = sbrk_amount; + + if (!starting_address) { + u32_address = (unsigned int)sbrk(length); + + if (u32_address == -1) { + rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); + /* DOES NOT RETURN!!! */ + } + + if (u32_address & (CPU_ALIGNMENT-1)) { + old_address = u32_address; + u32_address = (u32_address + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); + + /* + * adjust the length by whatever we aligned by + */ + + length -= u32_address - old_address; + } + + starting_address = (void *)u32_address; + } + + /* + * Unfortunately we cannot use assert if this fails because if this + * has failed we do not have a heap and if we do not have a heap + * STDIO cannot work because there will be no buffers. + */ + + status = rtems_region_create( + rtems_build_name( 'H', 'E', 'A', 'P' ), + starting_address, + length, + CPU_ALIGNMENT, + RTEMS_DEFAULT_ATTRIBUTES, + &RTEMS_Malloc_Heap + ); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred( status ); + +#ifdef MALLOC_STATS + /* zero all the stats */ + (void) memset(&malloc_stats, 0, sizeof(malloc_stats)); +#endif + + MSBUMP(space_available, length); +} + +void *malloc( + size_t size +) +{ + void *return_this; + void *starting_address; + rtems_unsigned32 the_size; + rtems_unsigned32 sbrk_amount; + rtems_status_code status; + + MSBUMP(malloc_calls, 1); + + if ( !size ) + return (void *) 0; + + /* + * Try to give a segment in the current region if there is not + * enough space then try to grow the region using rtems_region_extend(). + * If this fails then return a NULL pointer. + */ + + status = rtems_region_get_segment( + RTEMS_Malloc_Heap, + size, + RTEMS_NO_WAIT, + RTEMS_NO_TIMEOUT, + &return_this + ); + + if ( status != RTEMS_SUCCESSFUL ) { + /* + * Round to the "requested sbrk amount" so hopefully we won't have + * to grow again for a while. This effectively does sbrk() calls + * in "page" amounts. + */ + + sbrk_amount = RTEMS_Malloc_Sbrk_amount; + + if ( sbrk_amount == 0 ) + return (void *) 0; + + the_size = ((size + sbrk_amount) / sbrk_amount * sbrk_amount); + + if (((rtems_unsigned32)starting_address = sbrk(the_size)) == -1) + return (void *) 0; + + status = rtems_region_extend( + RTEMS_Malloc_Heap, + starting_address, + the_size + ); + if ( status != RTEMS_SUCCESSFUL ) { + sbrk(-the_size); + errno = ENOMEM; + return (void *) 0; + } + + MSBUMP(space_available, the_size); + + status = rtems_region_get_segment( + RTEMS_Malloc_Heap, + size, + RTEMS_NO_WAIT, + RTEMS_NO_TIMEOUT, + &return_this + ); + if ( status != RTEMS_SUCCESSFUL ) { + errno = ENOMEM; + return (void *) 0; + } + } + +#ifdef MALLOC_STATS + if (return_this) + { + unsigned32 actual_size; + unsigned32 current_depth; + status = rtems_region_get_segment_size(RTEMS_Malloc_Heap, return_this, &actual_size); + MSBUMP(lifetime_allocated, actual_size); + current_depth = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed; + if (current_depth > malloc_stats.max_depth) + malloc_stats.max_depth = current_depth; + } +#endif + +#ifdef MALLOC_DIRTY + (void) memset(return_this, 0xCF, size); +#endif + + return return_this; +} + +void *calloc( + size_t nelem, + size_t elsize +) +{ + register char *cptr; + int length; + + MSBUMP(calloc_calls, 1); + + length = nelem * elsize; + cptr = malloc( length ); + if ( cptr ) + memset( cptr, '\0', length ); + + MSBUMP(malloc_calls, -1); /* subtract off the malloc */ + + return cptr; +} + +void *realloc( + void *ptr, + size_t size +) +{ + rtems_unsigned32 old_size; + rtems_status_code status; + char *new_area; + + MSBUMP(realloc_calls, 1); + + if ( !ptr ) + return malloc( size ); + + if ( !size ) { + free( ptr ); + return (void *) 0; + } + + new_area = malloc( size ); + if ( !new_area ) { + free( ptr ); + return (void *) 0; + } + + status = rtems_region_get_segment_size( RTEMS_Malloc_Heap, ptr, &old_size ); + if ( status != RTEMS_SUCCESSFUL ) { + errno = EINVAL; + return (void *) 0; + } + + memcpy( new_area, ptr, (size < old_size) ? size : old_size ); + free( ptr ); + + return new_area; + +} + +void free( + void *ptr +) +{ + rtems_status_code status; + + MSBUMP(free_calls, 1); + + if ( !ptr ) + return; + +#ifdef MALLOC_STATS + { + unsigned32 size; + status = rtems_region_get_segment_size( RTEMS_Malloc_Heap, ptr, &size ); + if ( status == RTEMS_SUCCESSFUL ) { + MSBUMP(lifetime_freed, size); + } + } +#endif + + status = rtems_region_return_segment( RTEMS_Malloc_Heap, ptr ); + if ( status != RTEMS_SUCCESSFUL ) { + errno = EINVAL; + assert( 0 ); + } +} + +#ifdef MALLOC_STATS +/* + * Dump the malloc statistics + * May be called via atexit() (installable by our bsp) or + * at any time by user + */ + +void malloc_dump(void) +{ + unsigned32 allocated = malloc_stats.lifetime_allocated - malloc_stats.lifetime_freed; + + printf("Malloc stats\n"); + printf(" avail:%uk allocated:%uk (%d%%) max:%uk (%d%%) lifetime:%Luk freed:%Luk\n", + (unsigned int) malloc_stats.space_available / 1024, + (unsigned int) allocated / 1024, + /* avoid float! */ + (allocated * 100) / malloc_stats.space_available, + (unsigned int) malloc_stats.max_depth / 1024, + (malloc_stats.max_depth * 100) / malloc_stats.space_available, + (unsigned long long) malloc_stats.lifetime_allocated / 1024, + (unsigned long long) malloc_stats.lifetime_freed / 1024); + printf(" Call counts: malloc:%d free:%d realloc:%d calloc:%d\n", + malloc_stats.malloc_calls, + malloc_stats.free_calls, + malloc_stats.realloc_calls, + malloc_stats.calloc_calls); +} +#endif + +/* + * "Reentrant" versions of the above routines implemented above. + */ + +#ifdef RTEMS_NEWLIB +void *malloc_r( + struct _reent *ignored, + size_t size +) +{ + return malloc( size ); +} + +void *calloc_r( + size_t nelem, + size_t elsize +) +{ + return calloc( nelem, elsize ); +} + +void *realloc_r( + void *ptr, + size_t size +) +{ + return realloc_r( ptr, size ); +} + +void free_r( + void *ptr +) +{ + free( ptr ); +} +#endif + diff --git a/cpukit/libcsupport/src/newlibc.c b/cpukit/libcsupport/src/newlibc.c new file mode 100644 index 0000000000..8c9ed2e1a8 --- /dev/null +++ b/cpukit/libcsupport/src/newlibc.c @@ -0,0 +1,336 @@ +#if defined(RTEMS_NEWLIB) + +/* + * COPYRIGHT (c) 1994 by Division Incorporated + * + * To anyone who acknowledges that this file is provided "AS IS" + * without any express or implied warranty: + * permission to use, copy, modify, and distribute this file + * for any purpose is hereby granted without fee, provided that + * the above copyright notice and this notice appears in all + * copies, and that the name of Division Incorporated not be + * used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * Division Incorporated makes no representations about the + * suitability of this software for any purpose. + * + * Description: + * Implementation of hooks for the CYGNUS newlib libc + * These hooks set things up so that: + * '_REENT' is switched at task switch time. + * + * + * TODO: + * + * NOTE: + * + * $Id$ + * + */ + +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#include <rtems.h> +#include <libcsupport.h> +#include <stdlib.h> /* for free() */ +#include <string.h> /* for memset() */ + +#include <sys/reent.h> /* for extern of _REENT (aka _impure_ptr) */ + +/* + * NOTE: When using RTEMS fake stat, fstat, and isatty, all output + * is line buffered so this setvbuf is not necessary. This + * setvbuf insures that we can redirect the output of a test + * on the UNIX simulator and it is in the same order as for a + * real target. + * NOTE: + * There is some problem with doing this on the hpux version + * of the UNIX simulator (symptom is printf core dumps), so + * we just don't for now. + * Not sure if this is a problem with hpux, newlib, or something else. + */ + +#if defined(RTEMS_UNIX) && !defined(hpux) +#define NEED_SETVBUF +#endif + +#ifdef NEED_SETVBUF +#include <stdio.h> +#endif + +#include "internal.h" + +#define LIBC_NOTEPAD RTEMS_NOTEPAD_LAST + + +int libc_reentrant; /* do we think we are reentrant? */ +struct _reent libc_global_reent = _REENT_INIT(libc_global_reent);; + +/* + * CYGNUS newlib routine that does atexit() processing and flushes + * stdio streams + * undocumented + */ + +extern void _wrapup_reent(struct _reent *); +extern void _reclaim_reent(struct _reent *); + +void +libc_wrapup(void) +{ + _wrapup_reent(0); + if (_REENT != &libc_global_reent) + { + _wrapup_reent(&libc_global_reent); +#if 0 + /* don't reclaim this one, just in case we do printfs */ + /* on our way out to ROM */ + _reclaim_reent(&libc_global_reent); +#endif + _REENT = &libc_global_reent; + } +} + + +rtems_boolean +libc_create_hook(rtems_tcb *current_task, + rtems_tcb *creating_task) +{ + MY_task_set_note(creating_task, LIBC_NOTEPAD, 0); + return TRUE; +} + +/* + * Called for all user TASKS (system tasks are MPCI Receive Server and IDLE) + */ + +rtems_extension +libc_start_hook(rtems_tcb *current_task, + rtems_tcb *starting_task) +{ + struct _reent *ptr; + + /* NOTE: our malloc is reentrant without a reent ptr since + * it is based on region manager + */ + + ptr = (struct _reent *) malloc(sizeof(struct _reent)); + + /* GCC extension: structure constants */ + *ptr = (struct _reent) _REENT_INIT((*ptr)); + + MY_task_set_note(starting_task, LIBC_NOTEPAD, (rtems_unsigned32) ptr); +} + +/* + * Called for all user TASKS (system tasks are MPCI Receive Server and IDLE) + * + * NOTE: When using RTEMS fake stat, fstat, and isatty, all output + * is line buffered so this setvbuf is not necessary. This + * setvbuf insures that we can redirect the output of a test + * on the UNIX simulator and it is in the same order as for a + * real target. + */ + +#ifdef RTEMS_UNIX +rtems_extension +libc_begin_hook(rtems_tcb *current_task) +{ + setvbuf( stdout, NULL, _IOLBF, BUFSIZ ); +} +#endif + +rtems_extension +libc_switch_hook(rtems_tcb *current_task, + rtems_tcb *heir_task) +{ + rtems_unsigned32 impure_value; + + /* XXX We can't use rtems_task_set_note() here since SYSI task has a + * tid of 0, which is treated specially (optimized, actually) + * by rtems_task_set_note + * + * NOTE: The above comment is no longer true and we need to use + * the extension data areas added about the same time. + */ + + /* + * Don't touch the outgoing task if it has been deleted. + */ + + if ( !_States_Is_transient( current_task->current_state ) ) { + impure_value = (rtems_unsigned32) _REENT; + MY_task_set_note(current_task, LIBC_NOTEPAD, impure_value); + } + + _REENT = (struct _reent *) MY_task_get_note(heir_task, LIBC_NOTEPAD); + +} + +/* + * Function: libc_delete_hook + * Created: 94/12/10 + * + * Description: + * Called when a task is deleted. + * Must restore the new lib reentrancy state for the new current + * task. + * + * Parameters: + * + * + * Returns: + * + * + * Side Effects: + * + * Notes: + * + * + * Deficiencies/ToDo: + * + * + */ +rtems_extension +libc_delete_hook(rtems_tcb *current_task, + rtems_tcb *deleted_task) +{ + struct _reent *ptr; + + /* + * The reentrancy structure was allocated by newlib using malloc() + */ + + if (current_task == deleted_task) + { + ptr = _REENT; + } + else + { + ptr = (struct _reent *) MY_task_get_note(deleted_task, LIBC_NOTEPAD); + } + + /* if (ptr) */ + if (ptr && ptr != &libc_global_reent) + { + _wrapup_reent(ptr); + _reclaim_reent(ptr); + free(ptr); + } + + MY_task_set_note(deleted_task, LIBC_NOTEPAD, 0); + + /* + * Require the switch back to another task to install its own + */ + + if (current_task == deleted_task) + { + _REENT = 0; + } +} + +/* + * Function: libc_init + * Created: 94/12/10 + * + * Description: + * Init libc for CYGNUS newlib + * Set up _REENT to use our global libc_global_reent. + * (newlib provides a global of its own, but we prefer our + * own name for it) + * + * If reentrancy is desired (which it should be), then + * we install the task extension hooks to maintain the + * newlib reentrancy global variable _REENT on task + * create, delete, switch, exit, etc. + * + * Parameters: + * reentrant non-zero if reentrant library desired. + * + * Returns: + * + * Side Effects: + * installs libc extensions if reentrant. + * + * Notes: + * + * + * Deficiencies/ToDo: + * + */ + +void +libc_init(int reentrant) +{ + rtems_extensions_table libc_extension; + rtems_id extension_id; + rtems_status_code rc; + + _REENT = &libc_global_reent; + + if (reentrant) + { + memset(&libc_extension, 0, sizeof(libc_extension)); + + libc_extension.thread_create = libc_create_hook; + libc_extension.thread_start = libc_start_hook; +#ifdef RTEMS_UNIX + libc_extension.thread_begin = libc_begin_hook; +#endif + libc_extension.thread_switch = libc_switch_hook; + libc_extension.thread_delete = libc_delete_hook; + + rc = rtems_extension_create(rtems_build_name('L', 'I', 'B', 'C'), + &libc_extension, &extension_id); + if (rc != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(rc); + + libc_reentrant = reentrant; + } +} + + +void +exit(int status) +{ + libc_wrapup(); + rtems_shutdown_executive(status); +} + + +/* + * Function: _exit + * Created: 94/12/10 + * + * Description: + * Called from exit() after it does atexit() processing and stdio fflush's + * + * called from bottom of exit() to really delete the task. + * If we are using reentrant libc, then let the delete extension + * do all the work, otherwise if a shutdown is in progress, + * then just do it. + * + * Parameters: + * exit status + * + * Returns: + * does not return + * + * Side Effects: + * + * Notes: + * + * + * Deficiencies/ToDo: + * + * + */ + +#if !defined(RTEMS_UNIX) && !defined(__GO32__) +void _exit(int status) +{ + rtems_shutdown_executive(status); +} +#endif + +#endif diff --git a/cpukit/libcsupport/src/no_libc.c b/cpukit/libcsupport/src/no_libc.c new file mode 100644 index 0000000000..9bb65f4df6 --- /dev/null +++ b/cpukit/libcsupport/src/no_libc.c @@ -0,0 +1,45 @@ +#if !defined(RTEMS_NEWLIB) && !defined(RTEMS_UNIX) + +/* no_libc.h + * + * This file contains stubs for the reentrancy hooks when + * an unknown C library is used. + * + * 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 "libcsupport.h" +#include "internal.h" + +#include <stdlib.h> /* for free() */ + +void +libc_init(int reentrant) +{ +} + +void libc_suspend_main(void) +{ +} + + +void libc_global_exit(rtems_unsigned32 code) +{ +} + +void _exit(int status) +{ +} + +#endif diff --git a/cpukit/libcsupport/src/unixlibc.c b/cpukit/libcsupport/src/unixlibc.c new file mode 100644 index 0000000000..2acd4fba8e --- /dev/null +++ b/cpukit/libcsupport/src/unixlibc.c @@ -0,0 +1,11 @@ +/* + * $Id$ + */ + +#if defined(RTEMS_UNIXLIB) + +void libc_init(int reentrant) +{ +} + +#endif diff --git a/cpukit/libcsupport/src/utsname.c b/cpukit/libcsupport/src/utsname.c new file mode 100644 index 0000000000..98b105023e --- /dev/null +++ b/cpukit/libcsupport/src/utsname.c @@ -0,0 +1,61 @@ +/* utsname.c + * + * $Id$ + */ + +#include <stdio.h> +#include <string.h> + +#include <sys/utsname.h> + +#include <rtems/score/system.h> +#include <rtems/score/object.h> + +/*PAGE + * + * 4.4.1 Get System Name, P1003.1b-1993, p. 90 + */ + +int uname( + struct utsname *name +) +{ + /* XXX: Here is what Solaris returns... + sysname = SunOS + nodename = node_name + release = 5.3 + version = Generic_101318-12 + machine = sun4m + */ + + strcpy( name->sysname, "RTEMS" ); + + sprintf( name->nodename, "Node %d\n", _Objects_Local_node ); + + /* XXX release string is in BAD format for this routine!!! */ + strcpy( name->release, "3.2.0" ); + + /* XXX does this have any meaning for RTEMS */ + + strcpy( name->release, "" ); + + sprintf( name->machine, "%s/%s", CPU_NAME, CPU_MODEL_NAME ); + + return 0; +} + +#ifdef NOT_IMPLEMENTED_YET + +/*PAGE + * + * 4.5.2 Get Process Times, P1003.1b-1993, p. 92 + */ + +clock_t times( + struct tms *buffer +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +#endif diff --git a/cpukit/libmisc/README b/cpukit/libmisc/README new file mode 100644 index 0000000000..6825898121 --- /dev/null +++ b/cpukit/libmisc/README @@ -0,0 +1,16 @@ +# +# $Id$ +# + +This directory contains for the "miscellaneous" library. Currently +the only item in this library is a user extension set which checks +for a task "blowing" it's stack. + +The following ideas have been mentioned for items which could go +in this library, but this list is not all inclusive: + + + Workspace Consistency Checker + + Task Execution Time Monitor + +The intent of this library is to provide a home for useful utility routines +which are dependent upon RTEMS. diff --git a/cpukit/libmisc/monitor/README b/cpukit/libmisc/monitor/README new file mode 100644 index 0000000000..d5a73da140 --- /dev/null +++ b/cpukit/libmisc/monitor/README @@ -0,0 +1,97 @@ +# +# $Id$ +# + +monitor task + +The monitor task is an optional task that knows about RTEMS +data structures and can print out information about them. +It is a work-in-progress and needs many more commands, but +is useful now. + +The monitor works best when it is the highest priority task, +so all your other tasks should ideally be at some priority +greater than 1. + +To use the monitor: +------------------- + + #include <rtems/monitor.h> + + ... + + rtems_monitor_init(0); + + The parameter to rtems_monitor_init() tells the monitor whether + to suspend itself on startup. A value of 0 causes the monitor + to immediately enter command mode; a non-zero value causes the + monitor to suspend itself after creation and wait for explicit + wakeup. + + + rtems_monitor_wakeup(); + + wakes up a suspended monitor and causes it to reenter command mode. + +Monitor commands +---------------- + + The monitor prompt is 'rtems> '. + Can abbreviate commands to "uniquity" + There is a 'help' command. Here is the output from various + help commands: + + Commands (may be abbreviated) + + help -- get this message or command specific help + task -- show task information + queue -- show message queue information + symbol -- show entries from symbol table + pause -- pause monitor for a specified number of ticks + fatal -- invoke a fatal RTEMS error + + task [id [id ...] ] + display information about the specified tasks. + Default is to display information about all tasks on this node + + queue [id [id ... ] ] + display information about the specified message queues + Default is to display information about all queues on this node + + symbol [ symbolname [symbolname ... ] ] + display value associated with specified symbol. + Defaults to displaying all known symbols. + + pause [ticks] + monitor goes to "sleep" for specified ticks (default is 1) + monitor will resume at end of period or if explicitly awakened + + fatal [status] + Invoke 'rtems_fatal_error_occurred' with 'status' + (default is RTEMS_INTERNAL_ERROR) + + continue + put the monitor to sleep waiting for an explicit wakeup from the + program running. + + +Sample output from 'task' command +--------------------------------- + + rtems> task + ID NAME PRIO STAT MODES EVENTS WAITID WAITARG NOTES + ------------------------------------------------------------------------ + 00010001 UI1 2 READY P:T:nA NONE15: 0x40606348 + 00010002 RMON 1 READY nP NONE15: 0x40604110 + + 'RMON' is the monitor itself, so we have 1 "user" task. + Its modes are P:T:nA which translate to: + + preemptable + timesliced + no ASRS + + It has no events. + It has a notepad value for notepad 15 which is 0x40606348 + (this is the libc thread state) + diff --git a/cpukit/libmisc/monitor/mon-command.c b/cpukit/libmisc/monitor/mon-command.c new file mode 100644 index 0000000000..87d31dfa2a --- /dev/null +++ b/cpukit/libmisc/monitor/mon-command.c @@ -0,0 +1,187 @@ +/* + * Command parsing routines for RTEMS monitor + * + * TODO: + * + * $Id$ + */ + +#include <rtems.h> + +#include "monitor.h" + +#include <stdio.h> +#include <string.h> + +/* + * make_argv(cp): token-count + * Break up the command line in 'cp' into global argv[] and argc (return + * value). + */ + +int +rtems_monitor_make_argv( + char *cp, + int *argc_p, + char **argv) +{ + int argc = 0; + + while ((cp = strtok(cp, " \t\n\r"))) + { + argv[argc++] = cp; + cp = (char *) NULL; + } + argv[argc] = (char *) NULL; /* end of argv */ + + return *argc_p = argc; +} + + +/* + * Read and break up a monitor command + * + * We have to loop on the gets call, since it will return NULL under UNIX + * RTEMS when we get a signal (eg: SIGALRM). + */ + +int +rtems_monitor_command_read(char *command, + int *argc, + char **argv) +{ + extern rtems_configuration_table BSP_Configuration; + static char monitor_prompt[32]; + + /* + * put node number in the prompt if we are multiprocessing + */ + + if (BSP_Configuration.User_multiprocessing_table == 0) + sprintf(monitor_prompt, "%s", MONITOR_PROMPT); + else if (rtems_monitor_default_node != rtems_monitor_node) + sprintf(monitor_prompt, "%d-%s-%d", rtems_monitor_node, MONITOR_PROMPT, rtems_monitor_default_node); + else + sprintf(monitor_prompt, "%d-%s", rtems_monitor_node, MONITOR_PROMPT); + +#ifdef RTEMS_UNIX + /* RTEMS on unix gets so many interrupt system calls this is hosed */ + printf("%s> ", monitor_prompt); + fflush(stdout); + while (gets(command) == (char *) 0) + ; +#else + do + { + printf("%s> ", monitor_prompt); + fflush(stdout); + } while (gets(command) == (char *) 0); +#endif + + return rtems_monitor_make_argv(command, argc, argv); +} + +/* + * Look up a command in a command table + * + */ + +rtems_monitor_command_entry_t * +rtems_monitor_command_lookup( + rtems_monitor_command_entry_t *table, + int argc, + char **argv +) +{ + rtems_monitor_command_entry_t *p; + rtems_monitor_command_entry_t *abbreviated_match = 0; + int abbreviated_matches = 0; + char *command; + int command_length; + + command = argv[0]; + + if ((table == 0) || (command == 0)) + goto failed; + + command_length = strlen(command); + + for (p = table; p->command; p++) + if (STREQ(command, p->command)) /* exact match */ + goto done; + else if (STRNEQ(command, p->command, command_length)) + { + abbreviated_matches++; + abbreviated_match = p; + } + + /* no perfect match; is there a non-ambigous abbreviated match? */ + if ( ! abbreviated_match) + { + printf("Unrecognized command '%s'; try 'help'\n", command); + goto failed; + } + + if (abbreviated_matches > 1) + { + printf("Command '%s' is ambiguous; try 'help'\n", command); + goto failed; + } + + p = abbreviated_match; + +done: + if (p->command_function == 0) + goto failed; + return p; + +failed: + return 0; +} + +void +rtems_monitor_command_usage(rtems_monitor_command_entry_t *table, + char *command_string) +{ + rtems_monitor_command_entry_t *help = 0; + char *help_command_argv[2]; + + /* if first entry in table is a usage, then print it out */ + if (command_string == 0) + { + if (STREQ(table->command, "--usage--") && table->usage) + help = table; + } + else + { + help_command_argv[0] = command_string; + help_command_argv[1] = 0; + help = rtems_monitor_command_lookup(table, 1, help_command_argv); + } + + if (help) + printf("%s\n", help->usage); +} + + +void +rtems_monitor_help_cmd( + int argc, + char **argv, + unsigned32 command_arg, + boolean verbose +) +{ + int arg; + rtems_monitor_command_entry_t *command; + + command = (rtems_monitor_command_entry_t *) command_arg; + + if (argc == 1) + rtems_monitor_command_usage(command, 0); + else + { + for (arg=1; argv[arg]; arg++) + rtems_monitor_command_usage(command, argv[arg]); + } +} diff --git a/cpukit/libmisc/monitor/mon-config.c b/cpukit/libmisc/monitor/mon-config.c new file mode 100644 index 0000000000..f5c9f6f093 --- /dev/null +++ b/cpukit/libmisc/monitor/mon-config.c @@ -0,0 +1,130 @@ +/* + * RTEMS Config display support + * + * TODO + * + * $Id$ + */ + + +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#include <rtems.h> +#include "monitor.h" + +#include <stdio.h> +#include <stdlib.h> /* strtoul() */ + +#define DATACOL 15 +#define CONTCOL DATACOL /* continued col */ + +/* + * Fill in entire monitor config table + * for sending to a remote monitor or printing on the local system + */ + +void +rtems_monitor_config_canonical( + rtems_monitor_config_t *canonical_config, + void *config_void +) +{ + rtems_configuration_table *c = (rtems_configuration_table *) config_void; + + canonical_config->work_space_start = c->work_space_start; + canonical_config->work_space_size = c->work_space_size; + canonical_config->maximum_tasks = c->maximum_tasks; + canonical_config->maximum_timers = c->maximum_timers; + canonical_config->maximum_semaphores = c->maximum_semaphores; + canonical_config->maximum_message_queues = c->maximum_message_queues; + canonical_config->maximum_partitions = c->maximum_partitions; + canonical_config->maximum_regions = c->maximum_regions; + canonical_config->maximum_ports = c->maximum_ports; + canonical_config->maximum_periods = c->maximum_periods; + canonical_config->maximum_extensions = c->maximum_extensions; + canonical_config->microseconds_per_tick = c->microseconds_per_tick; + canonical_config->ticks_per_timeslice = c->ticks_per_timeslice; + canonical_config->number_of_initialization_tasks = c->number_of_initialization_tasks; +} + +/* + * This is easy, since there is only 1 (altho we could get them from + * other nodes...) + */ + +void * +rtems_monitor_config_next( + void *object_info, + rtems_monitor_config_t *canonical_config, + rtems_id *next_id +) +{ + rtems_configuration_table *c = _Configuration_Table; + int n = rtems_get_index(*next_id); + + if (n >= 1) + goto failed; + + _Thread_Disable_dispatch(); + + *next_id += 1; + return (void *) c; + +failed: + *next_id = RTEMS_OBJECT_ID_FINAL; + return 0; +} + + +void +rtems_monitor_config_dump_header( + boolean verbose +) +{ + printf("\ +INITIAL (startup) Configuration Info\n"); +/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 +0 1 2 3 4 5 6 7 */ + rtems_monitor_separator(); +} + + +void +rtems_monitor_config_dump( + rtems_monitor_config_t *monitor_config, + boolean verbose +) +{ + unsigned32 length = 0; + + length = 0; + length += printf("WORKSPACE"); + length += rtems_monitor_pad(DATACOL, length); + length += printf("start: 0x%x; size: 0x%x\n", + (unsigned32) monitor_config->work_space_start, + monitor_config->work_space_size); + + length = 0; + length += printf("TIME"); + length += rtems_monitor_pad(DATACOL, length); + length += printf("usec/tick: %d; tick/timeslice: %d; tick/sec: %d\n", + monitor_config->microseconds_per_tick, + monitor_config->ticks_per_timeslice, + 1000000 / monitor_config->microseconds_per_tick); + + length = 0; + length += printf("MAXIMUMS"); + length += rtems_monitor_pad(DATACOL, length); + length += printf("tasks: %d; timers: %d; sems: %d; que's: %d; ext's: %d\n", + monitor_config->maximum_tasks, + monitor_config->maximum_timers, + monitor_config->maximum_semaphores, + monitor_config->maximum_message_queues, + monitor_config->maximum_extensions); + length = 0; + length += rtems_monitor_pad(CONTCOL, length); + length += printf("partitions: %d; regions: %d; ports: %d; periods: %d\n", + monitor_config->maximum_partitions, + monitor_config->maximum_regions, + monitor_config->maximum_ports, + monitor_config->maximum_periods); +} diff --git a/cpukit/libmisc/monitor/mon-dname.c b/cpukit/libmisc/monitor/mon-dname.c new file mode 100644 index 0000000000..e6993e18f7 --- /dev/null +++ b/cpukit/libmisc/monitor/mon-dname.c @@ -0,0 +1,112 @@ +/* + * RTEMS monitor driver names support. + * + * There are 2 "driver" things the monitor knows about. + * + * 1. Regular RTEMS drivers. + * This is a table indexed by major device number and + * containing driver entry points only. + * + * 2. Driver name table. + * A separate table of names for drivers. + * The table converts driver names to a major number + * as index into the driver table and a minor number + * for an argument to driver. + * + * Drivers are displayed with 'driver' command. + * Names are displayed with 'dname' command. + * + * $Id$ + */ + +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#include <rtems.h> + +#include "monitor.h" + +#include <stdio.h> +#include <stdlib.h> /* strtoul() */ +#include <string.h> /* strncpy() */ + +#define DATACOL 15 +#define CONTCOL DATACOL /* continued col */ + +void +rtems_monitor_dname_canonical( + rtems_monitor_dname_t *canonical_dname, + void *dname_void +) +{ + rtems_driver_name_t *np = (rtems_driver_name_t *) dname_void; + + (void) strncpy(canonical_dname->name_string, np->device_name, sizeof(canonical_dname->name_string)); + canonical_dname->major = np->major; + canonical_dname->minor = np->minor; +} + +void * +rtems_monitor_dname_next( + void *object_information, + rtems_monitor_dname_t *canonical_dname, + rtems_id *next_id +) +{ + int n = rtems_get_index(*next_id); + rtems_driver_name_t *table = _IO_Driver_name_table; + rtems_driver_name_t *np = 0; + +/* XXX should we be using _IO_Number_of_devices */ + for (np = table + n ; n<_IO_Number_of_devices; n++, np++) + if (np->device_name) + goto done; + + *next_id = RTEMS_OBJECT_ID_FINAL; + return 0; + +done: + _Thread_Disable_dispatch(); + + /* + * dummy up a fake id and name for this item + */ + + canonical_dname->id = n; + canonical_dname->name = rtems_build_name('-', '-', '-', '-'); + + *next_id += 1; + return np; +} + +void +rtems_monitor_dname_dump_header( + boolean verbose +) +{ + printf("\ + Major:Minor Name\n"); +/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 +0 1 2 3 4 5 6 7 */ + rtems_monitor_separator(); +} + +void +rtems_monitor_dname_dump( + rtems_monitor_dname_t *monitor_dname, + boolean verbose +) +{ + unsigned32 length = 0; + + length += rtems_monitor_pad(6, length); + length += rtems_monitor_dump_hex(monitor_dname->major); + length += printf(":"); + length += rtems_monitor_dump_hex(monitor_dname->minor); + + length += rtems_monitor_pad(16, length); + length += printf("%.*s", + (int) sizeof(monitor_dname->name_string), + (char *) monitor_dname->name_string); + + length += printf("\n"); + length = 0; +} diff --git a/cpukit/libmisc/monitor/mon-driver.c b/cpukit/libmisc/monitor/mon-driver.c new file mode 100644 index 0000000000..d5cff24a19 --- /dev/null +++ b/cpukit/libmisc/monitor/mon-driver.c @@ -0,0 +1,136 @@ +/* + * RTEMS monitor IO (device drivers) support + * + * There are 2 "driver" things the monitor knows about. + * + * 1. Regular RTEMS drivers. + * This is a table indexed by major device number and + * containing driver entry points only. + * + * 2. Driver name table. + * A separate table of names for drivers. + * The table converts driver names to a major number + * as index into the driver table and a minor number + * for an argument to driver. + * + * Drivers are displayed with 'driver' command. + * Names are displayed with 'name' command. + * + * $Id$ + */ + +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#include <rtems.h> + +#include "monitor.h" + +#include <stdio.h> +#include <stdlib.h> /* strtoul() */ + +#define DATACOL 15 +#define CONTCOL DATACOL /* continued col */ + + +void +rtems_monitor_driver_canonical( + rtems_monitor_driver_t *canonical_driver, + void *driver_void +) +{ + rtems_driver_address_table *d = (rtems_driver_address_table *) driver_void; + + rtems_monitor_symbol_canonical_by_value(&canonical_driver->initialization, + d->initialization); + + rtems_monitor_symbol_canonical_by_value(&canonical_driver->open, + d->open); + rtems_monitor_symbol_canonical_by_value(&canonical_driver->close, + d->close); + rtems_monitor_symbol_canonical_by_value(&canonical_driver->read, + d->read); + rtems_monitor_symbol_canonical_by_value(&canonical_driver->write, + d->write); + rtems_monitor_symbol_canonical_by_value(&canonical_driver->control, + d->control); +} + + +void * +rtems_monitor_driver_next( + void *object_info, + rtems_monitor_driver_t *canonical_driver, + rtems_id *next_id +) +{ + rtems_configuration_table *c = _Configuration_Table; + int n = rtems_get_index(*next_id); + + if (n >= c->number_of_device_drivers) + goto failed; + + _Thread_Disable_dispatch(); + + /* + * dummy up a fake id and name for this item + */ + + canonical_driver->id = n; + canonical_driver->name = rtems_build_name('-', '-', '-', '-'); + + *next_id += 1; + return (void *) (c->Device_driver_table + n); + +failed: + *next_id = RTEMS_OBJECT_ID_FINAL; + return 0; +} + + +void +rtems_monitor_driver_dump_header( + boolean verbose +) +{ + printf("\ + Major Entry points\n"); +/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 +0 1 2 3 4 5 6 7 */ + rtems_monitor_separator(); +} + +void +rtems_monitor_driver_dump( + rtems_monitor_driver_t *monitor_driver, + boolean verbose +) +{ + unsigned32 length = 0; + + length += printf(" %d", monitor_driver->id); + + length += rtems_monitor_pad(13, length); + length += printf("init: "); + length += rtems_monitor_symbol_dump(&monitor_driver->initialization, verbose); + length += printf("; control: "); + length += rtems_monitor_symbol_dump(&monitor_driver->control, verbose); + length += printf("\n"); + length = 0; + + length += rtems_monitor_pad(13, length); + + length += printf("open: "); + length += rtems_monitor_symbol_dump(&monitor_driver->open, verbose); + length += printf("; close: "); + length += rtems_monitor_symbol_dump(&monitor_driver->close, verbose); + length += printf("\n"); + length = 0; + + length += rtems_monitor_pad(13, length); + + length += printf("read: "); + length += rtems_monitor_symbol_dump(&monitor_driver->read, verbose); + length += printf("; write: "); + length += rtems_monitor_symbol_dump(&monitor_driver->write, verbose); + length += printf("\n"); + length = 0; +} diff --git a/cpukit/libmisc/monitor/mon-extension.c b/cpukit/libmisc/monitor/mon-extension.c new file mode 100644 index 0000000000..4afecaa617 --- /dev/null +++ b/cpukit/libmisc/monitor/mon-extension.c @@ -0,0 +1,98 @@ +/* + * RTEMS Monitor extension support + * + * $Id$ + */ + +#include <rtems.h> +#include "monitor.h" + +#include <stdio.h> + +void +rtems_monitor_extension_canonical( + rtems_monitor_extension_t *canonical_extension, + void *extension_void +) +{ + Extension_Control *rtems_extension = (Extension_Control *) extension_void; + rtems_extensions_table *e = &rtems_extension->Extension.Callouts; + + rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_create, + e->thread_create); + + rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_start, + e->thread_start); + rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_restart, + e->thread_restart); + rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_delete, + e->thread_delete); + rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_tswitch, + e->thread_switch); + rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_begin, + e->thread_begin); + rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_exitted, + e->thread_exitted); + rtems_monitor_symbol_canonical_by_value(&canonical_extension->e_fatal, + e->fatal); +} + +void +rtems_monitor_extension_dump_header( + boolean verbose +) +{ + printf("\ + ID NAME\n"); +/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 +0 1 2 3 4 5 6 7 */ + + rtems_monitor_separator(); +} + + +/* + * Dump out the canonical form + */ + +void +rtems_monitor_extension_dump( + rtems_monitor_extension_t *monitor_extension, + boolean verbose +) +{ + unsigned32 length = 0; + + length += rtems_monitor_dump_id(monitor_extension->id); + length += rtems_monitor_pad(11, length); + length += rtems_monitor_dump_name(monitor_extension->name); + + length += rtems_monitor_pad(18, length); + length += printf("create: "); + length += rtems_monitor_symbol_dump(&monitor_extension->e_create, verbose); + length += printf("; start: "); + length += rtems_monitor_symbol_dump(&monitor_extension->e_start, verbose); + length += printf("; restart: "); + length += rtems_monitor_symbol_dump(&monitor_extension->e_restart, verbose); + length += printf("\n"); + length = 0; + + length += rtems_monitor_pad(18, length); + length += printf("delete: "); + length += rtems_monitor_symbol_dump(&monitor_extension->e_delete, verbose); + length += printf("; switch: "); + length += rtems_monitor_symbol_dump(&monitor_extension->e_tswitch, verbose); + length += printf("; begin: "); + length += rtems_monitor_symbol_dump(&monitor_extension->e_begin, verbose); + length += printf("\n"); + length = 0; + + length += rtems_monitor_pad(18, length); + length += printf("exitted: "); + length += rtems_monitor_symbol_dump(&monitor_extension->e_exitted, verbose); + length += printf("; fatal: "); + length += rtems_monitor_symbol_dump(&monitor_extension->e_fatal, verbose); + length += printf("\n"); + length = 0; + printf("\n"); +} diff --git a/cpukit/libmisc/monitor/mon-itask.c b/cpukit/libmisc/monitor/mon-itask.c new file mode 100644 index 0000000000..5ce4b55270 --- /dev/null +++ b/cpukit/libmisc/monitor/mon-itask.c @@ -0,0 +1,115 @@ +/* + * RTEMS Monitor init task support + * + * $Id$ + */ + +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#include <rtems.h> +#include "monitor.h" + +#include <stdio.h> + +/* + * As above, but just for init tasks + */ +void +rtems_monitor_init_task_canonical( + rtems_monitor_init_task_t *canonical_itask, + void *itask_void +) +{ + rtems_initialization_tasks_table *rtems_itask = itask_void; + + rtems_monitor_symbol_canonical_by_value(&canonical_itask->entry, + rtems_itask->entry_point); + + canonical_itask->argument = rtems_itask->argument; + canonical_itask->stack_size = rtems_itask->stack_size; + canonical_itask->priority = rtems_itask->initial_priority; + canonical_itask->modes = rtems_itask->mode_set; + canonical_itask->attributes = rtems_itask->attribute_set; +} + +void * +rtems_monitor_init_task_next( + void *object_info, + rtems_monitor_init_task_t *canonical_init_task, + rtems_id *next_id +) +{ + rtems_configuration_table *c = _Configuration_Table; + rtems_initialization_tasks_table *itask; + int n = rtems_get_index(*next_id); + + if (n >= c->number_of_initialization_tasks) + goto failed; + + _Thread_Disable_dispatch(); + + itask = c->User_initialization_tasks_table + n; + + /* + * dummy up a fake id and name for this item + */ + + canonical_init_task->id = n; + canonical_init_task->name = itask->name; + + *next_id += 1; + return (void *) itask; + +failed: + *next_id = RTEMS_OBJECT_ID_FINAL; + return 0; +} + + +void +rtems_monitor_init_task_dump_header( + boolean verbose +) +{ + printf("\ + # NAME ENTRY ARGUMENT PRIO MODES ATTRIBUTES STACK SIZE\n"); +/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 +0 1 2 3 4 5 6 7 */ + rtems_monitor_separator(); +} + +/* + */ + +void +rtems_monitor_init_task_dump( + rtems_monitor_init_task_t *monitor_itask, + boolean verbose +) +{ + int length = 0; + + length += rtems_monitor_dump_decimal(monitor_itask->id); + + length += rtems_monitor_pad(7, length); + length += rtems_monitor_dump_name(monitor_itask->name); + + length += rtems_monitor_pad(14, length); + length += rtems_monitor_symbol_dump(&monitor_itask->entry, verbose); + + length += rtems_monitor_pad(25, length); + length += printf("%d [0x%x]", monitor_itask->argument, monitor_itask->argument); + + length += rtems_monitor_pad(39, length); + length += rtems_monitor_dump_priority(monitor_itask->priority); + + length += rtems_monitor_pad(46, length); + length += rtems_monitor_dump_modes(monitor_itask->modes); + + length += rtems_monitor_pad(54, length); + length += rtems_monitor_dump_attributes(monitor_itask->attributes); + + length += rtems_monitor_pad(66, length); + length += printf("%d [0x%x]", monitor_itask->stack_size, monitor_itask->stack_size); + + printf("\n"); +} diff --git a/cpukit/libmisc/monitor/mon-manager.c b/cpukit/libmisc/monitor/mon-manager.c new file mode 100644 index 0000000000..af8d530d3b --- /dev/null +++ b/cpukit/libmisc/monitor/mon-manager.c @@ -0,0 +1,50 @@ +/* + * RTEMS Monitor "manager" support. + * Used to traverse object (chain) lists and print them out. + * + * $Id$ + */ + +#include <rtems.h> +#include "monitor.h" + +#include <stdio.h> + +#include <monitor.h> + +/* + * "next" routine for all objects that are RTEMS manager objects + */ + +void * +rtems_monitor_manager_next( + void *table_void, + void *canonical, + rtems_id *next_id +) +{ + Objects_Information *table = table_void; + rtems_monitor_generic_t *copy; + Objects_Control *object = 0; + unsigned32 location; + + /* + * When we are called, it must be local + */ + + if ( ! _Objects_Is_local_id(*next_id)) + goto done; + + object = _Objects_Get_next(table, *next_id, &location, next_id); + + if (object) + { + copy = (rtems_monitor_generic_t *) canonical; + copy->id = object->id; + _Objects_Copy_name_raw(object->name, ©->name, sizeof(copy->name)); + } + +done: + return object; +} + diff --git a/cpukit/libmisc/monitor/mon-monitor.c b/cpukit/libmisc/monitor/mon-monitor.c new file mode 100644 index 0000000000..a5a3fab131 --- /dev/null +++ b/cpukit/libmisc/monitor/mon-monitor.c @@ -0,0 +1,517 @@ +/* + * RTEMS monitor main body + * + * TODO: + * add stuff to RTEMS api + * rtems_get_name(id) + * rtems_get_type(id) + * rtems_build_id(node, type, num) + * Add a command to dump out info about an arbitrary id when + * types are added to id's + * rtems> id idnum + * idnum: node n, object: whatever, id: whatever + * allow id's to be specified as n:t:id, where 'n:t' is optional + * should have a separate monitor FILE stream (ala the debugger) + * remote request/response stuff should be cleaned up + * maybe we can use real rpc?? + * 'info' command to print out: + * interrupt stack location, direction and size + * floating point config stuff + * interrupt config stuff + * + * $Id$ + */ + +#include <rtems.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#include "monitor.h" + +/* set by trap handler */ +extern rtems_tcb *debugger_interrupted_task; +extern rtems_context *debugger_interrupted_task_context; +extern rtems_unsigned32 debugger_trap; + +/* + * Various id's for the monitor + * They need to be public variables for access by other agencies + * such as debugger and remote servers' + */ + +rtems_id rtems_monitor_task_id; + +unsigned32 rtems_monitor_node; /* our node number */ +unsigned32 rtems_monitor_default_node; /* current default for commands */ + +/* + * The rtems symbol table + */ + +rtems_symbol_table_t *rtems_monitor_symbols; + +/* + * The top-level commands + */ + +rtems_monitor_command_entry_t rtems_monitor_commands[] = { + { "--usage--", + "\n" + "RTEMS monitor\n" + "\n" + "Commands (may be abbreviated)\n" + "\n" + " help -- get this message or command specific help\n" + " pause -- pause monitor for a specified number of ticks\n" + " exit -- invoke a fatal RTEMS error\n" + " symbol -- show entries from symbol table\n" + " continue -- put monitor to sleep waiting for explicit wakeup\n" + " config -- show system configuration\n" + " itask -- list init tasks\n" + " mpci -- list mpci config\n" + " task -- show task information\n" + " queue -- show message queue information\n" + " extension -- user extensions\n" + " driver -- show information about named drivers\n" + " dname -- show information about named drivers\n" + " object -- generic object information\n" + " node -- specify default node for commands that take id's\n" +#ifdef CPU_INVOKE_DEBUGGER + " debugger -- invoke system debugger\n" +#endif + , + 0, + 0, + (unsigned32) rtems_monitor_commands, + }, + { "config", + "config\n" + " Show the system configuration.\n", + 0, + rtems_monitor_object_cmd, + RTEMS_MONITOR_OBJECT_CONFIG, + }, + { "itask", + "itask\n" + " List init tasks for the system\n", + 0, + rtems_monitor_object_cmd, + RTEMS_MONITOR_OBJECT_INIT_TASK, + }, + { "mpci", + "mpci\n" + " Show the MPCI system configuration, if configured.\n", + 0, + rtems_monitor_object_cmd, + RTEMS_MONITOR_OBJECT_MPCI, + }, + { "pause", + "pause [ticks]\n" + " monitor goes to \"sleep\" for specified ticks (default is 1)\n" + " monitor will resume at end of period or if explicitly awakened\n", + 0, + rtems_monitor_pause_cmd, + 0, + }, + { "continue", + "continue\n" + " put the monitor to sleep waiting for an explicit wakeup from the\n" + " program running.\n", + 0, + rtems_monitor_continue_cmd, + 0, + }, + { "go", + "go\n" + " Alias for 'continue'\n", + 0, + rtems_monitor_continue_cmd, + 0, + }, + { "node", + "node [ node number ]\n" + " Specify default node number for commands that take id's\n", + 0, + rtems_monitor_node_cmd, + 0, + }, + { "symbol", + "symbol [ symbolname [symbolname ... ] ]\n" + " display value associated with specified symbol.\n" + " Defaults to displaying all known symbols.\n", + 0, + rtems_monitor_symbol_cmd, + (unsigned32) &rtems_monitor_symbols, + }, + { "extension", + "extension [id [id ...] ]\n" + " display information about specified extensions.\n" + " Default is to display information about all extensions on this node\n", + 0, + rtems_monitor_object_cmd, + RTEMS_MONITOR_OBJECT_EXTENSION, + }, + { "task", + "task [id [id ...] ]\n" + " display information about the specified tasks.\n" + " Default is to display information about all tasks on this node\n", + 0, + rtems_monitor_object_cmd, + RTEMS_MONITOR_OBJECT_TASK, + }, + { "queue", + "queue [id [id ... ] ]\n" + " display information about the specified message queues\n" + " Default is to display information about all queues on this node\n", + 0, + rtems_monitor_object_cmd, + RTEMS_MONITOR_OBJECT_QUEUE, + }, + { "object", + "object [id [id ...] ]\n" + " display information about specified RTEMS objects.\n" + " Object id's must include 'type' information.\n" + " (which may normally be defaulted)\n", + 0, + rtems_monitor_object_cmd, + RTEMS_MONITOR_OBJECT_INVALID, + }, + { "driver", + "driver [ major [ major ... ] ]\n" + " Display the RTEMS device driver table.\n", + 0, + rtems_monitor_object_cmd, + RTEMS_MONITOR_OBJECT_DRIVER, + }, + { "dname", + "dname\n" + " Displays information about named drivers.\n", + 0, + rtems_monitor_object_cmd, + RTEMS_MONITOR_OBJECT_DNAME, + }, + { "exit", + "exit [status]\n" + " Invoke 'rtems_fatal_error_occurred' with 'status'\n" + " (default is RTEMS_SUCCESSFUL)\n", + 0, + rtems_monitor_fatal_cmd, + RTEMS_SUCCESSFUL, + }, + { "fatal", + "fatal [status]\n" + " 'exit' with fatal error; default error is RTEMS_TASK_EXITTED\n", + 0, + rtems_monitor_fatal_cmd, + RTEMS_TASK_EXITTED, /* exit value */ + }, + { "quit", + "quit [status]\n" + " Alias for 'exit'\n", + 0, + rtems_monitor_fatal_cmd, + RTEMS_SUCCESSFUL, /* exit value */ + }, + { "help", + "help [ command [ command ] ]\n" + " provide information about commands\n" + " Default is show basic command summary.\n", + 0, + rtems_monitor_help_cmd, + (unsigned32) rtems_monitor_commands, + }, +#ifdef CPU_INVOKE_DEBUGGER + { "debugger", + "debugger\n" + " Enter the debugger, if possible.\n" + " A continue from the debugger will return to the monitor.\n", + 0, + rtems_monitor_debugger_cmd, + 0, + }, +#endif + { 0, 0, 0, 0, 0 }, +}; + + +rtems_status_code +rtems_monitor_suspend(rtems_interval timeout) +{ + rtems_event_set event_set; + rtems_status_code status; + + status = rtems_event_receive(MONITOR_WAKEUP_EVENT, + RTEMS_DEFAULT_OPTIONS, + timeout, + &event_set); + return status; +} + +void +rtems_monitor_wakeup(void) +{ + rtems_status_code status; + + status = rtems_event_send(rtems_monitor_task_id, MONITOR_WAKEUP_EVENT); +} + +void +rtems_monitor_debugger_cmd( + int argc, + char **argv, + unsigned32 command_arg, + boolean verbose +) +{ +#ifdef CPU_INVOKE_DEBUGGER + CPU_INVOKE_DEBUGGER; +#endif +} + +void +rtems_monitor_pause_cmd( + int argc, + char **argv, + unsigned32 command_arg, + boolean verbose +) +{ + if (argc == 1) + rtems_monitor_suspend(1); + else + rtems_monitor_suspend(strtoul(argv[1], 0, 0)); +} + +void +rtems_monitor_fatal_cmd( + int argc, + char **argv, + unsigned32 command_arg, + boolean verbose +) +{ + if (argc == 1) + rtems_fatal_error_occurred(command_arg); + else + rtems_fatal_error_occurred(strtoul(argv[1], 0, 0)); +} + +void +rtems_monitor_continue_cmd( + int argc, + char **argv, + unsigned32 command_arg, + boolean verbose +) +{ + rtems_monitor_suspend(RTEMS_NO_TIMEOUT); +} + +void +rtems_monitor_node_cmd( + int argc, + char **argv, + unsigned32 command_arg, + boolean verbose +) +{ + unsigned32 new_node = rtems_monitor_default_node; + + switch (argc) + { + case 1: /* no node, just set back to ours */ + new_node = rtems_monitor_node; + break; + + case 2: + new_node = strtoul(argv[1], 0, 0); + break; + + default: + printf("invalid syntax, try 'help node'\n"); + break; + } + + if ((new_node >= 1) && + _Configuration_MP_table && + (new_node <= _Configuration_MP_table->maximum_nodes)) + rtems_monitor_default_node = new_node; +} + + +/* + * Function: rtems_monitor_symbols_loadup + * + * Description: + * Create and load the monitor's symbol table. + * We are reading the output format of 'gnm' which looks like this: + * + * 400a7068 ? _Rate_monotonic_Information + * 400a708c ? _Thread_Dispatch_disable_level + * 400a7090 ? _Configuration_Table + * + * We ignore the type field. + * + * Side Effects: + * Creates and fills in 'rtems_monitor_symbols' table + * + * TODO + * there should be a BSP #define or something like that + * to do this; Assuming stdio is crazy. + * Someday this should know BFD + * Maybe we could get objcopy to just copy the symbol areas + * and copy that down. + * + */ + +void +rtems_monitor_symbols_loadup(void) +{ + FILE *fp; + char buffer[128]; + + if (rtems_monitor_symbols) + rtems_symbol_table_destroy(rtems_monitor_symbols); + + rtems_monitor_symbols = rtems_symbol_table_create(10); + if (rtems_monitor_symbols == 0) + return; + + fp = fopen("symbols", "r"); + + if (fp == 0) + return; + + while (fgets(buffer, sizeof(buffer) - 1, fp)) + { + char *symbol; + char *value; + char *ignored_type; + + value = strtok(buffer, " \t\n"); + ignored_type = strtok(0, " \t\n"); + symbol = strtok(0, " \t\n"); + + if (symbol && ignored_type && value) + { + rtems_symbol_t *sp; + sp = rtems_symbol_create(rtems_monitor_symbols, + symbol, + (rtems_unsigned32) strtoul(value, 0, 16)); + if (sp == 0) + { + printf("could not define symbol '%s'\n", symbol); + goto done; + } + } + else + { + printf("parsing error on '%s'\n", buffer); + goto done; + } + } + +done: +} + + +/* + * Main monitor command loop + */ + +void +rtems_monitor_task( + rtems_task_argument monitor_flags +) +{ + rtems_tcb *debugee = 0; + rtems_context *rp; + rtems_context_fp *fp; + char command_buffer[513]; + int argc; + char *argv[64]; + boolean verbose = FALSE; + + if (monitor_flags & RTEMS_MONITOR_SUSPEND) + (void) rtems_monitor_suspend(RTEMS_NO_TIMEOUT); + + for (;;) + { + extern rtems_tcb * _Thread_Executing; + rtems_monitor_command_entry_t *command; + + debugee = _Thread_Executing; + rp = &debugee->Registers; + fp = (rtems_context_fp *) debugee->fp_context; /* possibly 0 */ + + if (0 == rtems_monitor_command_read(command_buffer, &argc, argv)) + continue; + if ((command = rtems_monitor_command_lookup(rtems_monitor_commands, + argc, + argv)) == 0) + continue; + + command->command_function(argc, argv, command->command_arg, verbose); + + fflush(stdout); + } +} + + +void +rtems_monitor_kill(void) +{ + if (rtems_monitor_task_id) + rtems_task_delete(rtems_monitor_task_id); + rtems_monitor_task_id = 0; + + rtems_monitor_server_kill(); +} + +void +rtems_monitor_init( + unsigned32 monitor_flags +) +{ + rtems_status_code status; + + rtems_monitor_kill(); + + status = rtems_task_create(RTEMS_MONITOR_NAME, + 1, + 0 /* default stack */, + RTEMS_INTERRUPT_LEVEL(0), + RTEMS_DEFAULT_ATTRIBUTES, + &rtems_monitor_task_id); + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "could not create monitor task"); + goto done; + } + + rtems_monitor_node = rtems_get_node(rtems_monitor_task_id); + rtems_monitor_default_node = rtems_monitor_node; + + rtems_monitor_symbols_loadup(); + + if (monitor_flags & RTEMS_MONITOR_GLOBAL) + rtems_monitor_server_init(monitor_flags); + + /* + * Start the monitor task itself + */ + + status = rtems_task_start(rtems_monitor_task_id, + rtems_monitor_task, + monitor_flags); + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "could not start monitor"); + goto done; + } + +done: +} diff --git a/cpukit/libmisc/monitor/mon-mpci.c b/cpukit/libmisc/monitor/mon-mpci.c new file mode 100644 index 0000000000..5c4d2c2cb3 --- /dev/null +++ b/cpukit/libmisc/monitor/mon-mpci.c @@ -0,0 +1,159 @@ +/* + * RTEMS MPCI Config display support + * + * TODO + * + * $Id$ + */ + + +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#include <rtems.h> +#include "monitor.h" + +#include <stdio.h> +#include <stdlib.h> /* strtoul() */ + +#define DATACOL 15 + +/* + * Fill in entire monitor config table + * for sending to a remote monitor or printing on the local system + */ + +void +rtems_monitor_mpci_canonical( + rtems_monitor_mpci_t *canonical_mpci, + void *config_void +) +{ + rtems_configuration_table *c = _Configuration_Table; + rtems_multiprocessing_table *m; + rtems_mpci_table *mt; + + m = c->User_multiprocessing_table; + if (m == 0) + return; + mt = m->User_mpci_table; + + canonical_mpci->node = m->node; + canonical_mpci->maximum_nodes = m->maximum_nodes; + canonical_mpci->maximum_global_objects = m->maximum_global_objects; + canonical_mpci->maximum_proxies = m->maximum_proxies; + + canonical_mpci->default_timeout = mt->default_timeout; + canonical_mpci->maximum_packet_size = mt->maximum_packet_size; + + rtems_monitor_symbol_canonical_by_value(&canonical_mpci->initialization, + mt->initialization); + + rtems_monitor_symbol_canonical_by_value(&canonical_mpci->get_packet, + mt->get_packet); + rtems_monitor_symbol_canonical_by_value(&canonical_mpci->return_packet, + mt->return_packet); + rtems_monitor_symbol_canonical_by_value(&canonical_mpci->send_packet, + mt->send_packet); + rtems_monitor_symbol_canonical_by_value(&canonical_mpci->receive_packet, + mt->receive_packet); +} + +/* + * This is easy, since there is only 1 (altho we could get them from + * other nodes...) + */ + +void * +rtems_monitor_mpci_next( + void *object_info, + rtems_monitor_mpci_t *canonical_mpci, + rtems_id *next_id +) +{ + rtems_configuration_table *c = _Configuration_Table; + int n = rtems_get_index(*next_id); + + if (n >= 1) + goto failed; + + if ( ! c->User_multiprocessing_table) + goto failed; + + _Thread_Disable_dispatch(); + + *next_id += 1; + return (void *) c; + +failed: + *next_id = RTEMS_OBJECT_ID_FINAL; + return 0; +} + + +void +rtems_monitor_mpci_dump_header( + boolean verbose +) +{ + printf("\ + max max max default max\n\ + node nodes globals proxies timeout pktsize\n"); +/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 +0 1 2 3 4 5 6 7 */ + + rtems_monitor_separator(); +} + + +void +rtems_monitor_mpci_dump( + rtems_monitor_mpci_t *monitor_mpci, + boolean verbose +) +{ + unsigned32 length = 0; + + length += rtems_monitor_pad(2, length); + length += printf(" %d", monitor_mpci->node); + length += rtems_monitor_pad(11, length); + length += printf("%d", monitor_mpci->maximum_nodes); + + length += rtems_monitor_pad(18, length); + length += rtems_monitor_dump_decimal(monitor_mpci->maximum_global_objects); + + length += rtems_monitor_pad(28, length); + length += rtems_monitor_dump_decimal(monitor_mpci->maximum_proxies); + + length += rtems_monitor_pad(37, length); + length += rtems_monitor_dump_decimal(monitor_mpci->default_timeout); + + length += rtems_monitor_pad(46, length); + length += rtems_monitor_dump_decimal(monitor_mpci->maximum_packet_size); + + printf("\n"); + length = 0; + length += rtems_monitor_pad(DATACOL, length); + + length += printf("init: "); + length += rtems_monitor_symbol_dump(&monitor_mpci->initialization, verbose); + + printf("\n"); + length = 0; + length += rtems_monitor_pad(DATACOL, length); + + length += printf("get: "); + length += rtems_monitor_symbol_dump(&monitor_mpci->get_packet, verbose); + length += printf("; return: "); + length += rtems_monitor_symbol_dump(&monitor_mpci->return_packet, verbose); + + printf("\n"); + length = 0; + length += rtems_monitor_pad(DATACOL, length); + + length += printf("send: "); + length += rtems_monitor_symbol_dump(&monitor_mpci->send_packet, verbose); + length += printf("; receive: "); + length += rtems_monitor_symbol_dump(&monitor_mpci->receive_packet, verbose); + + printf("\n"); + length = 0; +} diff --git a/cpukit/libmisc/monitor/mon-object.c b/cpukit/libmisc/monitor/mon-object.c new file mode 100644 index 0000000000..0dfc6513d2 --- /dev/null +++ b/cpukit/libmisc/monitor/mon-object.c @@ -0,0 +1,374 @@ +/* + * RTEMS Monitor "object" support. + * + * Used to traverse object lists and print them out. + * An object can be an RTEMS object (chain based stuff) or + * a "misc" object such as a device driver. + * + * Each object has its own file in this directory (eg: extension.c) + * That file provides routines to convert a "native" structure + * to its canonical form, print a canonical structure, etc. + * + * TODO: + * should allow for non-numeric id's??? + * + * $Id$ + */ + +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#include <rtems.h> +#include "monitor.h" + +#include <stdio.h> +#include <stdlib.h> /* strtoul() */ + +#include <monitor.h> + +#define NUMELEMS(arr) (sizeof(arr) / sizeof(arr[0])) + +/* + * add: + * next + */ + +rtems_monitor_object_info_t rtems_monitor_object_info[] = +{ + { RTEMS_MONITOR_OBJECT_CONFIG, + (void *) 0, + sizeof(rtems_monitor_config_t), + (rtems_monitor_object_next_fn) rtems_monitor_config_next, + (rtems_monitor_object_canonical_fn) rtems_monitor_config_canonical, + (rtems_monitor_object_dump_header_fn) rtems_monitor_config_dump_header, + (rtems_monitor_object_dump_fn) rtems_monitor_config_dump, + }, + { RTEMS_MONITOR_OBJECT_MPCI, + (void *) 0, + sizeof(rtems_monitor_mpci_t), + (rtems_monitor_object_next_fn) rtems_monitor_mpci_next, + (rtems_monitor_object_canonical_fn) rtems_monitor_mpci_canonical, + (rtems_monitor_object_dump_header_fn) rtems_monitor_mpci_dump_header, + (rtems_monitor_object_dump_fn) rtems_monitor_mpci_dump, + }, + { RTEMS_MONITOR_OBJECT_INIT_TASK, + (void *) 0, + sizeof(rtems_monitor_init_task_t), + (rtems_monitor_object_next_fn) rtems_monitor_init_task_next, + (rtems_monitor_object_canonical_fn) rtems_monitor_init_task_canonical, + (rtems_monitor_object_dump_header_fn) rtems_monitor_init_task_dump_header, + (rtems_monitor_object_dump_fn) rtems_monitor_init_task_dump, + }, + { RTEMS_MONITOR_OBJECT_TASK, + (void *) &_RTEMS_tasks_Information, + sizeof(rtems_monitor_task_t), + (rtems_monitor_object_next_fn) rtems_monitor_manager_next, + (rtems_monitor_object_canonical_fn) rtems_monitor_task_canonical, + (rtems_monitor_object_dump_header_fn) rtems_monitor_task_dump_header, + (rtems_monitor_object_dump_fn) rtems_monitor_task_dump, + }, + { RTEMS_MONITOR_OBJECT_QUEUE, + (void *) &_Message_queue_Information, + sizeof(rtems_monitor_queue_t), + (rtems_monitor_object_next_fn) rtems_monitor_manager_next, + (rtems_monitor_object_canonical_fn) rtems_monitor_queue_canonical, + (rtems_monitor_object_dump_header_fn) rtems_monitor_queue_dump_header, + (rtems_monitor_object_dump_fn) rtems_monitor_queue_dump, + }, + { RTEMS_MONITOR_OBJECT_EXTENSION, + (void *) &_Extension_Information, + sizeof(rtems_monitor_extension_t), + (rtems_monitor_object_next_fn) rtems_monitor_manager_next, + (rtems_monitor_object_canonical_fn) rtems_monitor_extension_canonical, + (rtems_monitor_object_dump_header_fn) rtems_monitor_extension_dump_header, + (rtems_monitor_object_dump_fn) rtems_monitor_extension_dump, + }, + { RTEMS_MONITOR_OBJECT_DRIVER, + (void *) 0, + sizeof(rtems_monitor_driver_t), + (rtems_monitor_object_next_fn) rtems_monitor_driver_next, + (rtems_monitor_object_canonical_fn) rtems_monitor_driver_canonical, + (rtems_monitor_object_dump_header_fn) rtems_monitor_driver_dump_header, + (rtems_monitor_object_dump_fn) rtems_monitor_driver_dump, + }, + { RTEMS_MONITOR_OBJECT_DNAME, + /* XXX now that the driver name table is allocated from the */ + /* XXX Workspace, this does not work */ + (void *) 0, + /* (void *) _IO_Driver_name_table, */ + sizeof(rtems_monitor_dname_t), + (rtems_monitor_object_next_fn) rtems_monitor_dname_next, + (rtems_monitor_object_canonical_fn) rtems_monitor_dname_canonical, + (rtems_monitor_object_dump_header_fn) rtems_monitor_dname_dump_header, + (rtems_monitor_object_dump_fn) rtems_monitor_dname_dump, + }, +}; + +/* + * Allow id's to be specified without the node number or + * type for convenience. + */ + +rtems_id +rtems_monitor_id_fixup( + rtems_id id, + unsigned32 default_node, + rtems_monitor_object_type_t type +) +{ + unsigned32 node; + + node = rtems_get_node(id); + if (node == 0) + { + if (rtems_get_class(id) != OBJECTS_NO_CLASS) + type = rtems_get_class(id); + + id = _Objects_Build_id(type, default_node, rtems_get_index(id)); + } + return id; +} + + +rtems_monitor_object_info_t * +rtems_monitor_object_lookup( + rtems_monitor_object_type_t type +) +{ + rtems_monitor_object_info_t *p; + for (p = &rtems_monitor_object_info[0]; + p < &rtems_monitor_object_info[NUMELEMS(rtems_monitor_object_info)]; + p++) + { + if (p->type == type) + return p; + } + return 0; +} + +rtems_id +rtems_monitor_object_canonical_next_remote( + rtems_monitor_object_type_t type, + rtems_id id, + void *canonical +) +{ + rtems_id next_id; + rtems_status_code status; + rtems_monitor_server_request_t request; + rtems_monitor_server_response_t response; + + /* + * Send request + */ + + request.command = RTEMS_MONITOR_SERVER_CANONICAL; + request.argument0 = (unsigned32) type; + request.argument1 = (unsigned32) id; + + status = rtems_monitor_server_request(rtems_get_node(id), &request, &response); + if (status != RTEMS_SUCCESSFUL) + goto failed; + + /* + * process response + */ + + next_id = (rtems_id) response.result0; + if (next_id != RTEMS_OBJECT_ID_FINAL) + (void) memcpy(canonical, &response.payload, response.result1); + + return next_id; + +failed: + return RTEMS_OBJECT_ID_FINAL; + +} + + +rtems_id +rtems_monitor_object_canonical_next( + rtems_monitor_object_info_t *info, + rtems_id id, + void *canonical +) +{ + rtems_id next_id; + void *raw_item; + + if ( ! _Objects_Is_local_id(id)) + next_id = rtems_monitor_object_canonical_next_remote(info->type, + id, + canonical); + else + { + next_id = id; + + raw_item = (void *) info->next(info->object_information, + canonical, + &next_id); + + if (raw_item) + { + info->canonical(canonical, raw_item); + _Thread_Enable_dispatch(); + } + } + return next_id; +} + + +/* + * this is routine server invokes locally to get the type + */ + +rtems_id +rtems_monitor_object_canonical_get( + rtems_monitor_object_type_t type, + rtems_id id, + void *canonical, + unsigned32 *size_p +) +{ + rtems_monitor_object_info_t *info; + rtems_id next_id; + + *size_p = 0; + + info = rtems_monitor_object_lookup(type); + + if (info == 0) + return RTEMS_OBJECT_ID_FINAL; + + next_id = rtems_monitor_object_canonical_next(info, id, canonical); + *size_p = info->size; + + return next_id; +} + + +void +rtems_monitor_object_dump_1( + rtems_monitor_object_info_t *info, + rtems_id id, + boolean verbose +) +{ + rtems_id next_id; + rtems_monitor_union_t canonical; + + if ((next_id = rtems_monitor_object_canonical_next( + info, + id, + &canonical)) != RTEMS_OBJECT_ID_FINAL) + { + /* + * If the one we actually got is the one we wanted, then + * print it out. + * For ones that have an id field, this works fine, + * for all others, always dump it out. + * + * HACK: the way we determine whether there is an id is a hack. + * + * by the way: the reason we try to not have an id, is that some + * of the canonical structures are almost too big for shared + * memory driver (eg: mpci) + */ + + if ((info->next != rtems_monitor_manager_next) || + (id == canonical.generic.id)) + info->dump(&canonical, verbose); + } +} + +void +rtems_monitor_object_dump_all( + rtems_monitor_object_info_t *info, + boolean verbose +) +{ + rtems_id next_id; + rtems_monitor_union_t canonical; + + next_id = RTEMS_OBJECT_ID_INITIAL(info->type, rtems_monitor_default_node); + + while ((next_id = rtems_monitor_object_canonical_next( + info, + next_id, + &canonical)) != RTEMS_OBJECT_ID_FINAL) + { + info->dump(&canonical, verbose); + } +} + +void +rtems_monitor_object_cmd( + int argc, + char **argv, + unsigned32 command_arg, + boolean verbose +) +{ + int arg; + rtems_monitor_object_info_t *info = 0; + rtems_monitor_object_type_t type = (rtems_monitor_object_type_t) command_arg; + + /* what is the default type? */ + type = (rtems_monitor_object_type_t) command_arg; + + if (argc == 1) + { + if (type == RTEMS_MONITOR_OBJECT_INVALID) + { + printf("A type must be specified to \"dump all\"\n"); + goto done; + } + + info = rtems_monitor_object_lookup(type); + if (info == 0) + goto not_found; + + if (info->dump_header) + info->dump_header(verbose); + rtems_monitor_object_dump_all(info, verbose); + } + else + { + unsigned32 default_node = rtems_monitor_default_node; + rtems_monitor_object_type_t last_type = RTEMS_MONITOR_OBJECT_INVALID; + rtems_id id; + + for (arg=1; argv[arg]; arg++) + { + id = (rtems_id) strtoul(argv[arg], 0, 16); + id = rtems_monitor_id_fixup(id, default_node, type); + type = (rtems_monitor_object_type_t) rtems_get_class(id); + + /* + * Allow the item type to change in the middle + * of the command. If the type changes, then + * just dump out a new header and keep on going. + */ + if (type != last_type) + { + info = rtems_monitor_object_lookup(type); + if (info == 0) + goto not_found; + + if (info->dump_header) + info->dump_header(verbose); + } + + if (info == 0) + { +not_found: printf("Invalid or unsupported type %d\n", type); + goto done; + } + + rtems_monitor_object_dump_1(info, id, verbose); + + default_node = rtems_get_node(id); + + last_type = type; + } + } +done: +} diff --git a/cpukit/libmisc/monitor/mon-prmisc.c b/cpukit/libmisc/monitor/mon-prmisc.c new file mode 100644 index 0000000000..030bd020da --- /dev/null +++ b/cpukit/libmisc/monitor/mon-prmisc.c @@ -0,0 +1,254 @@ +/* + * Print misc stuff for the monitor dump routines + * Each routine returns the number of characters it output. + * + * TODO: + * + * $Id$ + */ + +#include <rtems.h> +#include "monitor.h" + +#include <rtems/assoc.h> + +#include <stdio.h> +#include <ctype.h> + +void +rtems_monitor_separator(void) +{ + printf("------------------------------------------------------------------------------\n"); +} + +unsigned32 +rtems_monitor_pad( + unsigned32 destination_column, + unsigned32 current_column +) +{ + int pad_length; + + if (destination_column <= current_column) + pad_length = 1; + else + pad_length = destination_column - current_column; + + return printf("%*s", pad_length, ""); +} + +unsigned32 +rtems_monitor_dump_char(rtems_unsigned8 ch) +{ + if (isprint(ch)) + return printf("%c", ch); + else + return printf("%02x", ch); +} + +unsigned32 +rtems_monitor_dump_decimal(unsigned32 num) +{ + return printf("%4d", num); +} + +unsigned32 +rtems_monitor_dump_hex(unsigned32 num) +{ + return printf("0x%x", num); +} + +unsigned32 +rtems_monitor_dump_assoc_bitfield( + rtems_assoc_t *ap, + char *separator, + unsigned32 value + ) +{ + unsigned32 b; + unsigned32 length = 0; + const char *name; + + for (b = 1; b; b <<= 1) + if (b & value) + { + if (length) + length += printf("%s", separator); + + name = rtems_assoc_name_by_local(ap, b); + + if (name) + length += printf("%s", name); + else + length += printf("0x%x", b); + } + + return length; +} + +unsigned32 +rtems_monitor_dump_id(rtems_id id) +{ + return printf("%08x", id); +} + +unsigned32 +rtems_monitor_dump_name(rtems_name name) +{ + int i; + unsigned32 length = 0; + union { + unsigned32 ui; + char c[4]; + } u; + + u.ui = (rtems_unsigned32) name; + + for (i=0; i<sizeof(u.c); i++) + length += rtems_monitor_dump_char(u.c[i]); + return length; +} + +unsigned32 +rtems_monitor_dump_priority(rtems_task_priority priority) +{ + return printf("%3d", priority); +} + + +rtems_assoc_t rtems_monitor_state_assoc[] = { + { "DORM", STATES_DORMANT }, + { "SUSP", STATES_SUSPENDED }, + { "TRANS", STATES_TRANSIENT }, + { "DELAY", STATES_DELAYING }, + { "Wbuf", STATES_WAITING_FOR_BUFFER }, + { "Wseg", STATES_WAITING_FOR_SEGMENT }, + { "Wmsg" , STATES_WAITING_FOR_MESSAGE }, + { "Wevnt", STATES_WAITING_FOR_EVENT }, + { "Wsem", STATES_WAITING_FOR_SEMAPHORE }, + { "Wtime", STATES_WAITING_FOR_TIME }, + { "Wrpc", STATES_WAITING_FOR_RPC_REPLY }, + { "WRATE", STATES_WAITING_FOR_PERIOD }, + { 0, 0, 0 }, +}; + +unsigned32 +rtems_monitor_dump_state(States_Control state) +{ + unsigned32 length = 0; + + if (state == STATES_READY) /* assoc doesn't deal with this as it is 0 */ + length += printf("READY"); + + length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_state_assoc, + ":", + state); + return length; +} + +rtems_assoc_t rtems_monitor_attribute_assoc[] = { + { "FL", RTEMS_FLOATING_POINT }, + { "GL", RTEMS_GLOBAL }, + { "PR", RTEMS_PRIORITY }, + { "BI", RTEMS_BINARY_SEMAPHORE }, + { "IN", RTEMS_INHERIT_PRIORITY }, + { 0, 0, 0 }, +}; + +unsigned32 +rtems_monitor_dump_attributes(rtems_attribute attributes) +{ + unsigned32 length = 0; + + if (attributes == RTEMS_DEFAULT_ATTRIBUTES) /* value is 0 */ + length += printf("DEFAULT"); + + length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_attribute_assoc, + ":", + attributes); + return length; +} + +rtems_assoc_t rtems_monitor_modes_assoc[] = { + { "nP", RTEMS_NO_PREEMPT }, + { "T", RTEMS_TIMESLICE }, + { "nA", RTEMS_NO_ASR }, + { 0, 0, 0 }, +}; + +unsigned32 +rtems_monitor_dump_modes(rtems_mode modes) +{ + unsigned32 length = 0; + + if (modes == RTEMS_DEFAULT_MODES) /* value is 0 */ + length += printf("P:T:nA"); + + length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_modes_assoc, + ":", + modes); + return length; +} + +rtems_assoc_t rtems_monitor_events_assoc[] = { + { "0", RTEMS_EVENT_0 }, + { "1", RTEMS_EVENT_1 }, + { "2", RTEMS_EVENT_2 }, + { "3", RTEMS_EVENT_3 }, + { "4", RTEMS_EVENT_4 }, + { "5", RTEMS_EVENT_5 }, + { "6", RTEMS_EVENT_6 }, + { "7", RTEMS_EVENT_7 }, + { "8", RTEMS_EVENT_8 }, + { "9", RTEMS_EVENT_9 }, + { "10", RTEMS_EVENT_10 }, + { "11", RTEMS_EVENT_11 }, + { "12", RTEMS_EVENT_12 }, + { "13", RTEMS_EVENT_13 }, + { "14", RTEMS_EVENT_14 }, + { "15", RTEMS_EVENT_15 }, + { "16", RTEMS_EVENT_16 }, + { "17", RTEMS_EVENT_17 }, + { "18", RTEMS_EVENT_18 }, + { "19", RTEMS_EVENT_19 }, + { "20", RTEMS_EVENT_20 }, + { "21", RTEMS_EVENT_21 }, + { "22", RTEMS_EVENT_22 }, + { "23", RTEMS_EVENT_23 }, + { "24", RTEMS_EVENT_24 }, + { "25", RTEMS_EVENT_25 }, + { "26", RTEMS_EVENT_26 }, + { "27", RTEMS_EVENT_27 }, + { "28", RTEMS_EVENT_28 }, + { "29", RTEMS_EVENT_29 }, + { "30", RTEMS_EVENT_30 }, + { "31", RTEMS_EVENT_31 }, + { 0, 0, 0 }, +}; + +unsigned32 +rtems_monitor_dump_events(rtems_event_set events) +{ + unsigned32 length = 0; + + if (events == EVENT_SETS_NONE_PENDING) /* value is 0 */ + length += printf("NONE"); + + length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_events_assoc, + ":", + events); + return length; +} + +unsigned32 +rtems_monitor_dump_notepad(unsigned32 *notepad) +{ + unsigned32 length = 0; + int i; + + for (i=0; i < RTEMS_NUMBER_NOTEPADS; i++) + if (notepad[i]) + length += printf("%d: 0x%x ", i, notepad[i]); + + return length; +} diff --git a/cpukit/libmisc/monitor/mon-queue.c b/cpukit/libmisc/monitor/mon-queue.c new file mode 100644 index 0000000000..08c1d9474e --- /dev/null +++ b/cpukit/libmisc/monitor/mon-queue.c @@ -0,0 +1,64 @@ +/* + * $Id$ + */ + +#include <rtems.h> +#include "monitor.h" + +#include <stdio.h> + +void +rtems_monitor_queue_canonical( + rtems_monitor_queue_t *canonical_queue, + void *queue_void +) +{ + Message_queue_Control *rtems_queue = (Message_queue_Control *) queue_void; + + canonical_queue->attributes = rtems_queue->attribute_set; + canonical_queue->maximum_message_size = rtems_queue->message_queue.maximum_message_size; + canonical_queue->maximum_pending_messages = rtems_queue->message_queue.maximum_pending_messages; + canonical_queue->number_of_pending_messages = rtems_queue->message_queue.number_of_pending_messages; +} + +void +rtems_monitor_queue_dump_header( + boolean verbose +) +{ + printf("\ + ID NAME ATTRIBUTES PEND MAXPEND MAXSIZE\n"); +/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 +0 1 2 3 4 5 6 7 */ + rtems_monitor_separator(); +} + + +/* + * Dump out the "next" queue indicated by 'id'. + * Returns next one to check. + * Returns RTEMS_OBJECT_ID_FINAL when all done + */ + +void +rtems_monitor_queue_dump( + rtems_monitor_queue_t *monitor_queue, + boolean verbose +) +{ + unsigned32 length = 0; + + length += rtems_monitor_dump_id(monitor_queue->id); + length += rtems_monitor_pad(11, length); + length += rtems_monitor_dump_name(monitor_queue->name); + length += rtems_monitor_pad(19, length); + length += rtems_monitor_dump_attributes(monitor_queue->attributes); + length += rtems_monitor_pad(31, length); + length += rtems_monitor_dump_decimal(monitor_queue->number_of_pending_messages); + length += rtems_monitor_pad(39, length); + length += rtems_monitor_dump_decimal(monitor_queue->maximum_pending_messages); + length += rtems_monitor_pad(48, length); + length += rtems_monitor_dump_decimal(monitor_queue->maximum_message_size); + + printf("\n"); +} diff --git a/cpukit/libmisc/monitor/mon-server.c b/cpukit/libmisc/monitor/mon-server.c new file mode 100644 index 0000000000..cc26718c27 --- /dev/null +++ b/cpukit/libmisc/monitor/mon-server.c @@ -0,0 +1,302 @@ +/* + * RTEMS monitor server (handles requests for info from RTEMS monitors + * running on other nodes) + * + * $Id$ + */ + +#include <rtems.h> + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#include "monitor.h" + +/* + * Various id's for the server + */ + +rtems_id rtems_monitor_server_task_id; +rtems_id rtems_monitor_server_request_queue_id; /* our server */ +rtems_id *rtems_monitor_server_request_queue_ids; /* all servers */ +rtems_id rtems_monitor_server_response_queue_id; /* our server */ + + +/* + * Send a request to a server task + */ + +rtems_status_code +rtems_monitor_server_request( + unsigned32 server_node, + rtems_monitor_server_request_t *request, + rtems_monitor_server_response_t *response +) +{ + rtems_id server_id; + rtems_status_code status; + unsigned32 size; + + /* + * What is id of monitor on target node? + * Look it up if we don't know it yet. + */ + + server_id = rtems_monitor_server_request_queue_ids[server_node]; + if (server_id == 0) + { + status = rtems_message_queue_ident(RTEMS_MONITOR_QUEUE_NAME, + server_node, + &server_id); + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "ident of remote server failed"); + goto done; + } + + rtems_monitor_server_request_queue_ids[server_node] = server_id; + } + + request->return_id = rtems_monitor_server_response_queue_id; + + status = rtems_message_queue_send(server_id, request, sizeof(*request)); + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "monitor server request send failed"); + goto done; + } + + /* + * Await response, if requested + */ + + if (response) + { + status = rtems_message_queue_receive(rtems_monitor_server_response_queue_id, + response, + &size, + RTEMS_WAIT, + 100); + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "server did not respond"); + + /* maybe server task was restarted; look it up again next time */ + rtems_monitor_server_request_queue_ids[server_node] = 0; + + goto done; + } + + if (response->command != RTEMS_MONITOR_SERVER_RESPONSE) + { + status = RTEMS_INCORRECT_STATE; + goto done; + } + } + +done: + return status; +} + + + +/* + * monitor server task + */ + +void +rtems_monitor_server_task( + rtems_task_argument monitor_flags +) +{ + rtems_monitor_server_request_t request; + rtems_monitor_server_response_t response; + rtems_status_code status; + unsigned32 size; + + for (;;) + { + status = rtems_message_queue_receive( + rtems_monitor_server_request_queue_id, + &request, + &size, + RTEMS_WAIT, + (rtems_interval) 0); + + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "monitor server msg queue receive error"); + goto failed; + } + + if (size != sizeof(request)) + { + rtems_error(0, "monitor server bad size on receive"); + goto failed; + } + + switch (request.command) + { + case RTEMS_MONITOR_SERVER_CANONICAL: + { + rtems_monitor_object_type_t object_type; + rtems_id id; + rtems_id next_id; + + object_type = (rtems_monitor_object_type_t) request.argument0; + id = (rtems_id) request.argument1; + next_id = rtems_monitor_object_canonical_get(object_type, + id, + &response.payload, + &size); + + response.command = RTEMS_MONITOR_SERVER_RESPONSE; + response.result0 = next_id; + response.result1 = size; + +#define SERVER_OVERHEAD (RTEMS_offsetof(rtems_monitor_server_response_t, \ + payload)) + + status = rtems_message_queue_send(request.return_id, + &response, + size + SERVER_OVERHEAD); + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "response send failed"); + goto failed; + } + break; + } + + default: + { + rtems_error(0, "invalid command to monitor server: %d", request.command); + goto failed; + } + } + } + +failed: + rtems_task_delete(RTEMS_SELF); +} + + +/* + * Kill off any old server + * Not sure if this is useful, but it doesn't help + */ + +void +rtems_monitor_server_kill(void) +{ + if (rtems_monitor_server_task_id) + rtems_task_delete(rtems_monitor_server_task_id); + rtems_monitor_task_id = 0; + + if (rtems_monitor_server_request_queue_id) + rtems_message_queue_delete(rtems_monitor_server_request_queue_id); + rtems_monitor_server_response_queue_id = 0; + + if (rtems_monitor_server_response_queue_id) + rtems_message_queue_delete(rtems_monitor_server_response_queue_id); + rtems_monitor_server_request_queue_ids = 0; + + if (rtems_monitor_server_request_queue_ids) + free(rtems_monitor_server_request_queue_ids); + rtems_monitor_server_request_queue_ids = 0; +} + + +void +rtems_monitor_server_init( + unsigned32 monitor_flags +) +{ + rtems_status_code status; + + if (_System_state_Is_multiprocessing && + (_Configuration_MP_table->maximum_nodes > 1)) + { + unsigned32 maximum_nodes = _Configuration_MP_table->maximum_nodes; + + /* + * create the msg que our server will listen + * Since we only get msgs from other RTEMS monitors, we just + * need reserve space for 1 msg from each node. + */ + + status = rtems_message_queue_create( + RTEMS_MONITOR_QUEUE_NAME, + maximum_nodes, + sizeof(rtems_monitor_server_request_t), + RTEMS_GLOBAL, + &rtems_monitor_server_request_queue_id); + + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "could not create monitor server message queue"); + goto done; + } + + /* + * create the msg que our responses will come on + * Since monitor just does one thing at a time, we only need 1 item + * message queue. + */ + + status = rtems_message_queue_create( + RTEMS_MONITOR_RESPONSE_QUEUE_NAME, + 1, /* depth */ + sizeof(rtems_monitor_server_response_t), + RTEMS_GLOBAL, + &rtems_monitor_server_response_queue_id); + + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "could not create monitor response message queue"); + goto done; + } + + /* need an id for queue of each other server we might talk to */ + /* indexed by node, so add 1 to maximum_nodes */ + rtems_monitor_server_request_queue_ids = + (rtems_id *) malloc((maximum_nodes + 1) * sizeof(rtems_id)); + (void) memset(rtems_monitor_server_request_queue_ids, + 0, + (maximum_nodes + 1) * sizeof(rtems_id)); + + rtems_monitor_server_request_queue_ids[rtems_monitor_node] = + rtems_monitor_server_request_queue_id; + + /* + * create the server task + */ + status = rtems_task_create(RTEMS_MONITOR_SERVER_NAME, + 1, + 0 /* default stack */, + RTEMS_INTERRUPT_LEVEL(0), + RTEMS_DEFAULT_ATTRIBUTES, + &rtems_monitor_server_task_id); + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "could not create monitor server task"); + goto done; + } + + /* + * Start the server task + */ + status = rtems_task_start(rtems_monitor_server_task_id, + rtems_monitor_server_task, + monitor_flags); + if (status != RTEMS_SUCCESSFUL) + { + rtems_error(status, "could not start monitor server"); + goto done; + } + } + +done: +} diff --git a/cpukit/libmisc/monitor/mon-symbols.c b/cpukit/libmisc/monitor/mon-symbols.c new file mode 100644 index 0000000000..6c6589d38f --- /dev/null +++ b/cpukit/libmisc/monitor/mon-symbols.c @@ -0,0 +1,481 @@ +/* + * File: symbols.c + * + * Description: + * Symbol table manager for the RTEMS monitor. + * These routines may be used by other system resources also. + * + * + * TODO: + * + * $Id$ + */ + +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#include <rtems.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "monitor.h" +#include "symbols.h" + + +rtems_symbol_table_t * +rtems_symbol_table_create() +{ + rtems_symbol_table_t *table; + + table = (rtems_symbol_table_t *) malloc(sizeof(rtems_symbol_table_t)); + memset((void *) table, 0, sizeof(*table)); + + table->growth_factor = 30; /* 30 percent */ + + return table; +} + +void +rtems_symbol_table_destroy(rtems_symbol_table_t *table) +{ + rtems_symbol_string_block_t *p, *pnext; + + if (table) + { + if (table->addresses) + (void) free(table->addresses); + table->addresses = 0; + p = table->string_buffer_head; + while (p) + { + pnext = p->next; + free(p); + p = pnext; + } + table->string_buffer_head = 0; + table->string_buffer_current = 0; + + free(table); + } +} + +rtems_symbol_t * +rtems_symbol_create( + rtems_symbol_table_t *table, + char *name, + rtems_unsigned32 value + ) +{ + int symbol_length; + size_t newsize; + rtems_symbol_t *sp; + + symbol_length = strlen(name) + 1; /* include '\000' in length */ + + /* need to grow the table? */ + if (table->next >= table->size) + { + if (table->size == 0) + newsize = 100; + else + newsize = table->size + (table->size / (100 / table->growth_factor)); + + table->addresses = (rtems_symbol_t *) realloc((void *) table->addresses, newsize * sizeof(rtems_symbol_t)); + if (table->addresses == 0) /* blew it; lost orig */ + goto failed; + table->size = newsize; + } + + sp = &table->addresses[table->next]; + sp->value = value; + + /* Have to add it to string pool */ + /* need to grow pool? */ + + if ((table->string_buffer_head == 0) || + (table->strings_next + symbol_length) >= SYMBOL_STRING_BLOCK_SIZE) + { + rtems_symbol_string_block_t *p; + + p = (rtems_symbol_string_block_t *) malloc(sizeof(rtems_symbol_string_block_t)); + if (p == 0) + goto failed; + p->next = 0; + if (table->string_buffer_head == 0) + table->string_buffer_head = p; + else + table->string_buffer_current->next = p; + table->string_buffer_current = p; + + table->strings_next = 0; + } + + sp->name = table->string_buffer_current->buffer + table->strings_next; + (void) strcpy(sp->name, name); + + table->strings_next += symbol_length; + table->sorted = 0; + table->next++; + + return sp; + +/* XXX Not sure what to do here. We've possibly destroyed the initial + symbol table due to realloc failure */ +failed: + return 0; +} + +/* + * Qsort entry point for compare by address + */ + +static int +rtems_symbol_compare(const void *e1, + const void *e2) +{ + rtems_symbol_t *s1, *s2; + s1 = (rtems_symbol_t *) e1; + s2 = (rtems_symbol_t *) e2; + + if (s1->value < s2->value) + return -1; + if (s1->value > s2->value) + return 1; + return 0; +} + + +/* + * Sort the symbol table using qsort + */ + +static void +rtems_symbol_sort(rtems_symbol_table_t *table) +{ + qsort((void *) table->addresses, (size_t) table->next, + sizeof(rtems_symbol_t), rtems_symbol_compare); + table->sorted = 1; +} + + +/* + * Search the symbol table by address + * This code based on CYGNUS newlib bsearch, but changed + * to allow for finding closest symbol <= key + */ + +rtems_symbol_t * +rtems_symbol_value_lookup( + rtems_symbol_table_t *table, + rtems_unsigned32 value + ) +{ + rtems_symbol_t *sp; + rtems_symbol_t *base; + rtems_symbol_t *best = 0; + rtems_unsigned32 distance; + rtems_unsigned32 best_distance = ~0; + rtems_unsigned32 elements; + + if (table == 0) + table = rtems_monitor_symbols; + + if ((table == 0) || (table->size == 0)) + return 0; + + if (table->sorted == 0) + rtems_symbol_sort(table); + + base = table->addresses; + elements = table->next; + + while (elements) + { + sp = base + (elements / 2); + if (value < sp->value) + elements /= 2; + else if (value > sp->value) + { + distance = value - sp->value; + if (distance < best_distance) + { + best_distance = distance; + best = sp; + } + base = sp + 1; + elements = (elements / 2) - (elements % 2 ? 0 : 1); + } + else + return sp; + } + + if (value == base->value) + return base; + + return best; +} + +/* + * Search the symbol table for the exact matching address. + * If the symbol table has already been sorted, then + * call the regular symbol value lookup, however, it it + * has not yet been sorted, search it sequentially. + * This routine is primarily used for low level symbol + * lookups (eg. from exception handler and interrupt routines) + * where the penality of sorted is not wanted and where + * an exact match is needed such that symbol table order + * is not important. + */ +const rtems_symbol_t * +rtems_symbol_value_lookup_exact( + rtems_symbol_table_t *table, + rtems_unsigned32 value + ) +{ + int s; + rtems_symbol_t *sp; + + if (table == 0) + { + table = rtems_monitor_symbols; + if (table == 0) + return NULL; + } + + if (table->sorted) + { + sp = rtems_symbol_value_lookup(table, value); + if ( rtems_symbol_value(sp) == value ) + return sp; + else + return NULL; /* not an exact match */ + } + + for (s = 0, sp = table->addresses; s < table->next; s++, sp++) + { + if ( sp->value == value ) + return sp; + } + + return NULL; + +} + + +/* + * Search the symbol table by string name (case independent) + */ + +rtems_symbol_t * +rtems_symbol_name_lookup( + rtems_symbol_table_t *table, + char *name + ) +{ + int s; + rtems_symbol_t *sp; + + if (table == 0) + { + table = rtems_monitor_symbols; + if (table == 0) + return NULL; + } + + for (s = 0, sp = table->addresses; s < table->next; s++, sp++) + { + if ( strcasecmp(sp->name, name) == 0 ) + return sp; + } + + return NULL; +} + +void * +rtems_monitor_symbol_next( + void *object_info, + rtems_monitor_symbol_t *canonical, + rtems_id *next_id +) +{ + rtems_symbol_table_t *table; + int n = rtems_get_index(*next_id); + + table = *(rtems_symbol_table_t **) object_info; + if (table == 0) + goto failed; + + if (n >= table->next) + goto failed; + + /* NOTE: symbols do not have id and name fields */ + + if (table->sorted == 0) + rtems_symbol_sort(table); + + _Thread_Disable_dispatch(); + + *next_id += 1; + return (void *) (table->addresses + n); + +failed: + *next_id = RTEMS_OBJECT_ID_FINAL; + return 0; +} + +void +rtems_monitor_symbol_canonical( + rtems_monitor_symbol_t *canonical_symbol, + rtems_symbol_t *sp +) +{ + canonical_symbol->value = sp->value; + canonical_symbol->offset = 0; + strncpy(canonical_symbol->name, sp->name, sizeof(canonical_symbol->name)); +} + + +void +rtems_monitor_symbol_canonical_by_name( + rtems_monitor_symbol_t *canonical_symbol, + char *name +) +{ + rtems_symbol_t *sp; + + sp = rtems_symbol_name_lookup(0, name); + + canonical_symbol->value = sp ? sp->value : 0; + + strncpy(canonical_symbol->name, name, sizeof(canonical_symbol->name)); + canonical_symbol->offset = 0; +} + +void +rtems_monitor_symbol_canonical_by_value( + rtems_monitor_symbol_t *canonical_symbol, + void *value_void_p +) +{ + unsigned32 value = (unsigned32) value_void_p; + rtems_symbol_t *sp; + + sp = rtems_symbol_value_lookup(0, value); + if (sp) + { + canonical_symbol->value = sp->value; + canonical_symbol->offset = value - sp->value; + strncpy(canonical_symbol->name, sp->name, sizeof(canonical_symbol->name)); + } + else + { + canonical_symbol->value = value; + canonical_symbol->offset = 0; + canonical_symbol->name[0] = '\0'; + } +} + + +unsigned32 +rtems_monitor_symbol_dump( + rtems_monitor_symbol_t *canonical_symbol, + boolean verbose +) +{ + unsigned32 length = 0; + + /* + * print the name if it exists AND if value is non-zero + * Ie: don't print some garbage symbol for address 0 + */ + + if (canonical_symbol->name[0] && (canonical_symbol->value != 0)) + { + if (canonical_symbol->offset == 0) + length += printf("%.*s", + (int) sizeof(canonical_symbol->name), + canonical_symbol->name); + else + length += printf("<%.*s+0x%x>", + (int) sizeof(canonical_symbol->name), + canonical_symbol->name, + canonical_symbol->offset); + if (verbose) + length += printf(" [0x%x]", canonical_symbol->value); + } + else + length += printf("[0x%x]", canonical_symbol->value); + + return length; +} + + +void +rtems_monitor_symbol_dump_all( + rtems_symbol_table_t *table, + boolean verbose +) +{ + int s; + rtems_symbol_t *sp; + + if (table == 0) + { + table = rtems_monitor_symbols; + if (table == 0) + return; + } + + if (table->sorted == 0) + rtems_symbol_sort(table); + + for (s = 0, sp = table->addresses; s < table->next; s++, sp++) + { + rtems_monitor_symbol_t canonical_symbol; + + rtems_monitor_symbol_canonical(&canonical_symbol, sp); + rtems_monitor_symbol_dump(&canonical_symbol, TRUE); + printf("\n"); + } +} + + +/* + * 'symbol' command + */ + +void +rtems_monitor_symbol_cmd( + int argc, + char **argv, + unsigned32 command_arg, + boolean verbose +) +{ + int arg; + rtems_symbol_table_t *table; + + table = *(rtems_symbol_table_t **) command_arg; + if (table == 0) + { + table = rtems_monitor_symbols; + if (table == 0) + return; + } + + /* + * Use object command to dump out whole symbol table + */ + if (argc == 1) + rtems_monitor_symbol_dump_all(table, verbose); + else + { + rtems_monitor_symbol_t canonical_symbol; + + for (arg=1; argv[arg]; arg++) + { + rtems_monitor_symbol_canonical_by_name(&canonical_symbol, argv[arg]); + rtems_monitor_symbol_dump(&canonical_symbol, verbose); + printf("\n"); + } + } +} diff --git a/cpukit/libmisc/monitor/mon-task.c b/cpukit/libmisc/monitor/mon-task.c new file mode 100644 index 0000000000..b1a7938eb5 --- /dev/null +++ b/cpukit/libmisc/monitor/mon-task.c @@ -0,0 +1,92 @@ +/* + * RTEMS Monitor task support + * + * $Id$ + */ + +#include <rtems.h> +#include "monitor.h" + +#include <stdio.h> + +void +rtems_monitor_task_canonical( + rtems_monitor_task_t *canonical_task, + void *thread_void +) +{ + Thread_Control *rtems_thread = (Thread_Control *) thread_void; + RTEMS_API_Control *api; + + api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ]; + + canonical_task->entry = rtems_thread->Start.entry_point; + canonical_task->argument = rtems_thread->Start.numeric_argument; + canonical_task->stack = rtems_thread->Start.Initial_stack.area; + canonical_task->stack_size = rtems_thread->Start.Initial_stack.size; + canonical_task->priority = rtems_thread->current_priority; + canonical_task->state = rtems_thread->current_state; + canonical_task->wait_id = rtems_thread->Wait.id; + canonical_task->events = api->pending_events; + +/* XXX modes and attributes only exist in the RTEMS API .. */ +/* XXX not directly in the core thread.. they will have to be derived */ +/* XXX if they are important enough to include anymore. */ + canonical_task->modes = 0; /* XXX FIX ME.... rtems_thread->current_modes; */ + canonical_task->attributes = 0 /* XXX FIX ME rtems_thread->API_Extensions[ THREAD_API_RTEMS ]->attribute_set */; + (void) memcpy(canonical_task->notepad, api ->Notepads, sizeof(canonical_task->notepad)); +/* XXX more to fix */ +/* + (void) memcpy(&canonical_task->wait_args, &rtems_thread->Wait.Extra, sizeof(canonical_task->wait_args)); +*/ +} + + +void +rtems_monitor_task_dump_header( + boolean verbose +) +{ + printf("\ + ID NAME PRIO STAT MODES EVENTS WAITID WAITARG NOTES\n"); +/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 +0 1 2 3 4 5 6 7 */ + + rtems_monitor_separator(); +} + +/* + */ + +void +rtems_monitor_task_dump( + rtems_monitor_task_t *monitor_task, + boolean verbose +) +{ + int length = 0; + + length += rtems_monitor_dump_id(monitor_task->id); + length += rtems_monitor_pad(11, length); + length += rtems_monitor_dump_name(monitor_task->name); + length += rtems_monitor_pad(18, length); + length += rtems_monitor_dump_priority(monitor_task->priority); + length += rtems_monitor_pad(24, length); + length += rtems_monitor_dump_state(monitor_task->state); + length += rtems_monitor_pad(31, length); + length += rtems_monitor_dump_modes(monitor_task->modes); + length += rtems_monitor_pad(39, length); + length += rtems_monitor_dump_events(monitor_task->events); + if (monitor_task->wait_id) + { + length += rtems_monitor_pad(47, length); + length += rtems_monitor_dump_id(monitor_task->wait_id); + length += rtems_monitor_pad(57, length); + length += rtems_monitor_dump_hex(monitor_task->wait_args); + } + + length += rtems_monitor_pad(65, length); + length += rtems_monitor_dump_notepad(monitor_task->notepad); + printf("\n"); +} + diff --git a/cpukit/libmisc/monitor/monitor.h b/cpukit/libmisc/monitor/monitor.h new file mode 100644 index 0000000000..8a86b2c7d0 --- /dev/null +++ b/cpukit/libmisc/monitor/monitor.h @@ -0,0 +1,443 @@ +/* + * File: monitor.h + * + * Description: + * The RTEMS monitor task include file. + * + * TODO: + * + * $Id$ + */ + +#ifndef __MONITOR_H +#define __MONITOR_H + +#include "symbols.h" +#include <rtems/error.h> /* rtems_error() */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Monitor types are derived from rtems object classes + */ + +typedef enum { + RTEMS_MONITOR_OBJECT_INVALID = OBJECTS_NO_CLASS, + RTEMS_MONITOR_OBJECT_TASK = OBJECTS_RTEMS_TASKS, + RTEMS_MONITOR_OBJECT_EXTENSION = OBJECTS_RTEMS_EXTENSIONS, + RTEMS_MONITOR_OBJECT_QUEUE = OBJECTS_RTEMS_MESSAGE_QUEUES, + RTEMS_MONITOR_OBJECT_SEMAPHORE = OBJECTS_RTEMS_SEMAPHORES, + RTEMS_MONITOR_OBJECT_PARTITION = OBJECTS_RTEMS_PARTITIONS, + RTEMS_MONITOR_OBJECT_REGION = OBJECTS_RTEMS_REGIONS, + RTEMS_MONITOR_OBJECT_PORT = OBJECTS_RTEMS_PORTS, + + /* following monitor objects are not known to RTEMS, but + * we like to have "types" for them anyway */ + + RTEMS_MONITOR_OBJECT_DRIVER = OBJECTS_CLASSES_LAST+1, + RTEMS_MONITOR_OBJECT_DNAME, + RTEMS_MONITOR_OBJECT_CONFIG, + RTEMS_MONITOR_OBJECT_INIT_TASK, + RTEMS_MONITOR_OBJECT_MPCI, + RTEMS_MONITOR_OBJECT_SYMBOL, +} rtems_monitor_object_type_t; + +/* + * rtems_monitor_init() flags + */ + +#define RTEMS_MONITOR_SUSPEND 0x0001 /* suspend monitor on startup */ +#define RTEMS_MONITOR_GLOBAL 0x0002 /* monitor should be global */ + + +/* + * Public interfaces for RTEMS data structures monitor is aware of. + * These are only used by the monitor. + * + * NOTE: + * All the canonical objects that correspond to RTEMS managed "objects" + * must have an identical first portion with 'id' and 'name' fields. + * + * Others do not have that restriction, even tho we would like them to. + * This is because some of the canonical structures are almost too big + * for shared memory driver (eg: mpci) and we are nickel and diming it. + */ + +/* + * Type of a pointer that may be a symbol + */ + +#define MONITOR_SYMBOL_LEN 20 +typedef struct { + char name[MONITOR_SYMBOL_LEN]; + unsigned32 value; + unsigned32 offset; +} rtems_monitor_symbol_t; + +typedef struct { + rtems_id id; + rtems_name name; + /* end of common portion */ +} rtems_monitor_generic_t; + +/* + * Task + */ +typedef struct { + rtems_id id; + rtems_name name; + /* end of common portion */ + Thread_Entry entry; + unsigned32 argument; + void *stack; + unsigned32 stack_size; + rtems_task_priority priority; + States_Control state; + rtems_event_set events; + rtems_mode modes; + rtems_attribute attributes; + unsigned32 notepad[RTEMS_NUMBER_NOTEPADS]; + rtems_id wait_id; + unsigned32 wait_args; +} rtems_monitor_task_t; + +/* + * Init task + */ + +typedef struct { + rtems_id id; /* not really an id */ + rtems_name name; + /* end of common portion */ + rtems_monitor_symbol_t entry; + unsigned32 argument; + unsigned32 stack_size; + rtems_task_priority priority; + rtems_mode modes; + rtems_attribute attributes; +} rtems_monitor_init_task_t; + + +/* + * Message queue + */ +typedef struct { + rtems_id id; + rtems_name name; + /* end of common portion */ + rtems_attribute attributes; + unsigned32 number_of_pending_messages; + unsigned32 maximum_pending_messages; + unsigned32 maximum_message_size; +} rtems_monitor_queue_t; + +/* + * Extension + */ +typedef struct { + rtems_id id; + rtems_name name; + /* end of common portion */ + rtems_monitor_symbol_t e_create; + rtems_monitor_symbol_t e_start; + rtems_monitor_symbol_t e_restart; + rtems_monitor_symbol_t e_delete; + rtems_monitor_symbol_t e_tswitch; + rtems_monitor_symbol_t e_begin; + rtems_monitor_symbol_t e_exitted; + rtems_monitor_symbol_t e_fatal; +} rtems_monitor_extension_t; + +/* + * Device driver + */ + +typedef struct { + rtems_id id; /* not really an id (should be tho) */ + rtems_name name; /* ditto */ + /* end of common portion */ + rtems_monitor_symbol_t initialization; /* initialization procedure */ + rtems_monitor_symbol_t open; /* open request procedure */ + rtems_monitor_symbol_t close; /* close request procedure */ + rtems_monitor_symbol_t read; /* read request procedure */ + rtems_monitor_symbol_t write; /* write request procedure */ + rtems_monitor_symbol_t control; /* special functions procedure */ +} rtems_monitor_driver_t; + +typedef struct { + rtems_id id; /* not used for drivers (yet) */ + rtems_name name; /* not used for drivers (yet) */ + /* end of common portion */ + unsigned32 major; + unsigned32 minor; + char name_string[64]; +} rtems_monitor_dname_t; + +/* + * System config + */ + +typedef struct { + void *work_space_start; + unsigned32 work_space_size; + unsigned32 maximum_tasks; + unsigned32 maximum_timers; + unsigned32 maximum_semaphores; + unsigned32 maximum_message_queues; + unsigned32 maximum_partitions; + unsigned32 maximum_regions; + unsigned32 maximum_ports; + unsigned32 maximum_periods; + unsigned32 maximum_extensions; + unsigned32 microseconds_per_tick; + unsigned32 ticks_per_timeslice; + unsigned32 number_of_initialization_tasks; +} rtems_monitor_config_t; + +/* + * MPCI config + */ + +typedef struct { + unsigned32 node; /* local node number */ + unsigned32 maximum_nodes; /* maximum # nodes in system */ + unsigned32 maximum_global_objects; /* maximum # global objects */ + unsigned32 maximum_proxies; /* maximum # proxies */ + + unsigned32 default_timeout; /* in ticks */ + unsigned32 maximum_packet_size; + rtems_monitor_symbol_t initialization; + rtems_monitor_symbol_t get_packet; + rtems_monitor_symbol_t return_packet; + rtems_monitor_symbol_t send_packet; + rtems_monitor_symbol_t receive_packet; +} rtems_monitor_mpci_t; + +/* + * The generic canonical information union + */ + +typedef union { + rtems_monitor_generic_t generic; + rtems_monitor_task_t task; + rtems_monitor_queue_t queue; + rtems_monitor_extension_t extension; + rtems_monitor_driver_t driver; + rtems_monitor_dname_t dname; + rtems_monitor_config_t config; + rtems_monitor_mpci_t mpci; + rtems_monitor_init_task_t itask; +} rtems_monitor_union_t; + +/* + * Support for talking to other monitors + */ + +/* + * Names of other monitors + */ + +#define RTEMS_MONITOR_NAME (rtems_build_name('R', 'M', 'O', 'N')) +#define RTEMS_MONITOR_SERVER_NAME (rtems_build_name('R', 'M', 'S', 'V')) +#define RTEMS_MONITOR_QUEUE_NAME (rtems_build_name('R', 'M', 'S', 'Q')) +#define RTEMS_MONITOR_RESPONSE_QUEUE_NAME (rtems_build_name('R', 'M', 'R', 'Q')) + +#define RTEMS_MONITOR_SERVER_RESPONSE 0x0001 +#define RTEMS_MONITOR_SERVER_CANONICAL 0x0002 + +typedef struct +{ + unsigned32 command; + rtems_id return_id; + unsigned32 argument0; + unsigned32 argument1; + unsigned32 argument2; + unsigned32 argument3; + unsigned32 argument4; + unsigned32 argument5; +} rtems_monitor_server_request_t; + +typedef struct +{ + unsigned32 command; + unsigned32 result0; + unsigned32 result1; + rtems_monitor_union_t payload; +} rtems_monitor_server_response_t; + +extern rtems_id rtems_monitor_task_id; + +extern unsigned32 rtems_monitor_node; /* our node number */ +extern unsigned32 rtems_monitor_default_node; /* current default for commands */ + +/* + * Monitor command function and table entry + */ + +typedef struct rtems_monitor_command_entry_s rtems_monitor_command_entry_t; + +typedef void ( *rtems_monitor_command_function_t )( + int argc, + char **argv, + unsigned32 command_arg, + boolean verbose + ); + +struct rtems_monitor_command_entry_s { + char *command; /* command name */ + char *usage; /* usage string for the command */ + unsigned32 arguments_required; /* # of required args */ + rtems_monitor_command_function_t command_function; + + /* Some argument for the command */ + unsigned32 command_arg; +}; + +typedef void *(*rtems_monitor_object_next_fn)(void *, void *, rtems_id *); +typedef void (*rtems_monitor_object_canonical_fn)(void *, void *); +typedef void (*rtems_monitor_object_dump_header_fn)(boolean); +typedef void (*rtems_monitor_object_dump_fn)(void *, boolean); + +typedef struct { + rtems_monitor_object_type_t type; + void *object_information; + int size; /* of canonical object */ + rtems_monitor_object_next_fn next; + rtems_monitor_object_canonical_fn canonical; + rtems_monitor_object_dump_header_fn dump_header; + rtems_monitor_object_dump_fn dump; +} rtems_monitor_object_info_t; + + +/* monitor.c */ +void rtems_monitor_kill(void); +void rtems_monitor_init(rtems_boolean); +void rtems_monitor_wakeup(void); +void rtems_monitor_pause_cmd(int, char **, unsigned32, boolean); +void rtems_monitor_fatal_cmd(int, char **, unsigned32, boolean); +void rtems_monitor_continue_cmd(int, char **, unsigned32, boolean); +void rtems_monitor_debugger_cmd(int, char **, unsigned32, boolean); +void rtems_monitor_node_cmd(int, char **, unsigned32, boolean); +void rtems_monitor_symbols_loadup(void); +void rtems_monitor_task(rtems_task_argument); + +/* server.c */ +void rtems_monitor_server_kill(void); +rtems_status_code rtems_monitor_server_request(unsigned32, rtems_monitor_server_request_t *, rtems_monitor_server_response_t *); +void rtems_monitor_server_task(rtems_task_argument); +void rtems_monitor_server_init(unsigned32); + +/* command.c */ +int rtems_monitor_make_argv(char *, int *, char **); +int rtems_monitor_command_read(char *, int *, char **); +rtems_monitor_command_entry_t *rtems_monitor_command_lookup( + rtems_monitor_command_entry_t * table, int argc, char **argv); +void rtems_monitor_command_usage(rtems_monitor_command_entry_t *, char *); +void rtems_monitor_help_cmd(int, char **, unsigned32, boolean); + +/* prmisc.c */ +void rtems_monitor_separator(void); +unsigned32 rtems_monitor_pad(unsigned32 dest_col, unsigned32 curr_col); +unsigned32 rtems_monitor_dump_char(unsigned8 ch); +unsigned32 rtems_monitor_dump_decimal(unsigned32 num); +unsigned32 rtems_monitor_dump_hex(unsigned32 num); +unsigned32 rtems_monitor_dump_id(rtems_id id); +unsigned32 rtems_monitor_dump_name(rtems_name name); +unsigned32 rtems_monitor_dump_priority(rtems_task_priority priority); +unsigned32 rtems_monitor_dump_state(States_Control state); +unsigned32 rtems_monitor_dump_modes(rtems_mode modes); +unsigned32 rtems_monitor_dump_attributes(rtems_attribute attributes); +unsigned32 rtems_monitor_dump_events(rtems_event_set events); +unsigned32 rtems_monitor_dump_notepad(unsigned32 *notepad); + +/* object.c */ +rtems_id rtems_monitor_id_fixup(rtems_id, unsigned32, rtems_monitor_object_type_t); +rtems_id rtems_monitor_object_canonical_get(rtems_monitor_object_type_t, rtems_id, void *, unsigned32 *size_p); +rtems_id rtems_monitor_object_canonical_next(rtems_monitor_object_info_t *, rtems_id, void *); +void *rtems_monitor_object_next(void *, void *, rtems_id, rtems_id *); +rtems_id rtems_monitor_object_canonical(rtems_id, void *); +void rtems_monitor_object_cmd(int, char **, unsigned32, boolean); + +/* manager.c */ +void *rtems_monitor_manager_next(void *, void *, rtems_id *); + +/* config.c */ +void rtems_monitor_config_canonical(rtems_monitor_config_t *, void *); +void *rtems_monitor_config_next(void *, rtems_monitor_config_t *, rtems_id *); +void rtems_monitor_config_dump_header(boolean); +void rtems_monitor_config_dump(rtems_monitor_config_t *, boolean verbose); + +/* mpci.c */ +void rtems_monitor_mpci_canonical(rtems_monitor_mpci_t *, void *); +void *rtems_monitor_mpci_next(void *, rtems_monitor_mpci_t *, rtems_id *); +void rtems_monitor_mpci_dump_header(boolean); +void rtems_monitor_mpci_dump(rtems_monitor_mpci_t *, boolean verbose); + +/* itask.c */ +void rtems_monitor_init_task_canonical(rtems_monitor_init_task_t *, void *); +void *rtems_monitor_init_task_next(void *, rtems_monitor_init_task_t *, rtems_id *); +void rtems_monitor_init_task_dump_header(boolean); +void rtems_monitor_init_task_dump(rtems_monitor_init_task_t *, boolean verbose); + +/* extension.c */ +void rtems_monitor_extension_canonical(rtems_monitor_extension_t *, void *); +void rtems_monitor_extension_dump_header(boolean verbose); +void rtems_monitor_extension_dump(rtems_monitor_extension_t *, boolean); + +/* task.c */ +void rtems_monitor_task_canonical(rtems_monitor_task_t *, void *); +void rtems_monitor_task_dump_header(boolean verbose); +void rtems_monitor_task_dump(rtems_monitor_task_t *, boolean); + +/* queue.c */ +void rtems_monitor_queue_canonical(rtems_monitor_queue_t *, void *); +void rtems_monitor_queue_dump_header(boolean verbose); +void rtems_monitor_queue_dump(rtems_monitor_queue_t *, boolean); + +/* driver.c */ +void *rtems_monitor_driver_next(void *, rtems_monitor_driver_t *, rtems_id *); +void rtems_monitor_driver_canonical(rtems_monitor_driver_t *, void *); +void rtems_monitor_driver_dump_header(boolean); +void rtems_monitor_driver_dump(rtems_monitor_driver_t *, boolean); + +/* dname.c */ +void *rtems_monitor_dname_next(void *, rtems_monitor_dname_t *, rtems_id *); +void rtems_monitor_dname_canonical(rtems_monitor_dname_t *, void *); +void rtems_monitor_dname_dump_header(boolean); +void rtems_monitor_dname_dump(rtems_monitor_dname_t *, boolean); + +/* symbols.c */ +rtems_symbol_table_t *rtems_symbol_table_create(); +void rtems_symbol_table_destroy(rtems_symbol_table_t *table); + +rtems_symbol_t *rtems_symbol_create(rtems_symbol_table_t *, char *, unsigned32); +rtems_symbol_t *rtems_symbol_value_lookup(rtems_symbol_table_t *, unsigned32); +const rtems_symbol_t *rtems_symbol_value_lookup_exact(rtems_symbol_table_t *, unsigned32); +rtems_symbol_t *rtems_symbol_name_lookup(rtems_symbol_table_t *, char *); +void *rtems_monitor_symbol_next(void *object_info, rtems_monitor_symbol_t *, rtems_id *); +void rtems_monitor_symbol_canonical(rtems_monitor_symbol_t *, rtems_symbol_t *); +void rtems_monitor_symbol_canonical_by_name(rtems_monitor_symbol_t *, char *); +void rtems_monitor_symbol_canonical_by_value(rtems_monitor_symbol_t *, void *); +unsigned32 rtems_monitor_symbol_dump(rtems_monitor_symbol_t *, boolean); +void rtems_monitor_symbol_cmd(int, char **, unsigned32, boolean); + + +extern rtems_symbol_table_t *rtems_monitor_symbols; + +#ifndef MONITOR_PROMPT +#define MONITOR_PROMPT "rtems" /* will have '> ' appended */ +#endif + +#define MONITOR_WAKEUP_EVENT RTEMS_EVENT_0 + + +#define STREQ(a,b) (strcmp(a,b) == 0) +#define STRNEQ(a,b,n) (strncmp(a,b,n) == 0) + +#ifdef __cplusplus +} +#endif + +#endif /* ! __MONITOR_H */ diff --git a/cpukit/libmisc/monitor/symbols.h b/cpukit/libmisc/monitor/symbols.h new file mode 100644 index 0000000000..061ccdd952 --- /dev/null +++ b/cpukit/libmisc/monitor/symbols.h @@ -0,0 +1,64 @@ +/* + * RTEMS monitor symbol table functions + * + * Description: + * Entry points for symbol table routines. + * + * + * + * TODO: + * + * $Id$ + */ + +#ifndef _INCLUDE_SYMBOLS_H +#define _INCLUDE_SYMBOLS_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + rtems_unsigned32 value; + char *name; +} rtems_symbol_t; + +#define SYMBOL_STRING_BLOCK_SIZE 4080 +typedef struct rtems_symbol_string_block_s { + struct rtems_symbol_string_block_s *next; + char buffer[SYMBOL_STRING_BLOCK_SIZE]; +} rtems_symbol_string_block_t; + +typedef struct { + + rtems_unsigned32 sorted; /* are symbols sorted right now? */ + + rtems_unsigned32 growth_factor; /* % to grow by when needed */ + + rtems_unsigned32 next; /* next symbol slot to use when adding */ + rtems_unsigned32 size; /* max # of symbols */ + + /* + * Symbol list -- sorted by address (when we do a lookup) + */ + + rtems_symbol_t *addresses; /* symbol array by address */ + + /* + * String pool, unsorted, a list of blocks of string data + */ + + rtems_symbol_string_block_t *string_buffer_head; + rtems_symbol_string_block_t *string_buffer_current; + rtems_unsigned32 strings_next; /* next byte to use in this block */ + +} rtems_symbol_table_t; + +#define rtems_symbol_name(sp) ((sp)->name) +#define rtems_symbol_value(sp) ((sp)->value) + +#ifdef __cplusplus +} +#endif + +#endif /* ! _INCLUDE_SYMBOLS_H */ diff --git a/cpukit/libmisc/stackchk/README b/cpukit/libmisc/stackchk/README new file mode 100644 index 0000000000..20e76f07bc --- /dev/null +++ b/cpukit/libmisc/stackchk/README @@ -0,0 +1,41 @@ +# +# $Id$ +# + +This directory contains a stack bounds checker. It provides two +primary features: + + + check for stack overflow at each context switch + + provides an educated guess at each task's stack usage + +The stack overflow check at context switch works by looking for +a 16 byte pattern at the logical end of the stack to be corrupted. +The "guesser" assumes that the entire stack was prefilled with a known +pattern and assumes that the pattern is still in place if the memory +has not been used as a stack. + +Both of these can be fooled by pushing large holes onto the stack +and not writing to them... or (much more unlikely) writing the +magic patterns into memory. + +This code has not been extensively tested. It is provided as a tool +for RTEMS users to catch the most common mistake in multitasking +systems ... too little stack space. Suggestions and comments are appreciated. + +NOTES: + +1. Stack usage information is questionable on CPUs which push + large holes on stack. + +2. The stack checker has a tendency to generate a fault when + trying to print the helpful diagnostic message. If it comes + out, congratulations. If not, then the variable Stack_check_Blown_task + contains a pointer to the TCB of the offending task. This + is usually enough to go on. + +FUTURE: + +1. Determine how/if gcc will generate stack probe calls and support that. + +2. Get accurate stack usage numbers on i960.. it pushes very large + holes on the stack. diff --git a/cpukit/libmisc/stackchk/check.c b/cpukit/libmisc/stackchk/check.c new file mode 100644 index 0000000000..3d06d1dd12 --- /dev/null +++ b/cpukit/libmisc/stackchk/check.c @@ -0,0 +1,512 @@ +/* + * Stack Overflow Check User Extension Set + * + * NOTE: This extension set automatically determines at + * initialization time whether the stack for this + * CPU grows up or down and installs the correct + * extension routines for that direction. + * + * 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> + +/* + * HACK + * the stack dump information should be printed by a "fatal" extension. + * Fatal extensions only get called via rtems_fatal_error_occurred() + * and not when rtems_shutdown_executive() is called. + * I hope/think this is changing so that fatal extensions are renamed + * to "shutdown" extensions. + * When that happens, this #define should be deleted and all the code + * it marks. + */ +#define DONT_USE_FATAL_EXTENSION + + +extern rtems_configuration_table BSP_Configuration; + +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include "stackchk.h" +#include "internal.h" + +/* + * This variable contains the name of the task which "blew" the stack. + * It is NULL if the system is all right. + */ + +Thread_Control *Stack_check_Blown_task; + +/* + * The extension table for the stack checker. + */ + +rtems_extensions_table Stack_check_Extension_table = { + Stack_check_Create_extension, /* rtems_task_create */ + 0, /* rtems_task_start */ + 0, /* rtems_task_restart */ + 0, /* rtems_task_delete */ + Stack_check_Switch_extension, /* task_switch */ + Stack_check_Begin_extension, /* task_begin */ + 0, /* task_exitted */ +#ifdef DONT_USE_FATAL_EXTENSION + 0, /* fatal */ +#else + Stack_check_Fatal_extension, /* fatal */ +#endif +}; + +/* + * The "magic pattern" used to mark the end of the stack. + */ + +Stack_check_Control Stack_check_Pattern; + +/* + * Where the pattern goes in the stack area is dependent upon + * whether the stack grow to the high or low area of the memory. + * + */ + +#if ( CPU_STACK_GROWS_UP == TRUE ) + +#define Stack_check_Get_pattern_area( _the_stack ) \ + ((Stack_check_Control *) \ + ((_the_stack)->area + (_the_stack)->size - sizeof( Stack_check_Control ) )) + +#define Stack_check_Calculate_used( _low, _size, _high_water ) \ + ((_high_water) - (_low)) + +#define Stack_check_usable_stack_start(_the_stack) \ + ((_the_stack)->area) + +#else + +#define Stack_check_Get_pattern_area( _the_stack ) \ + ((Stack_check_Control *) ((_the_stack)->area + HEAP_OVERHEAD)) + +#define Stack_check_Calculate_used( _low, _size, _high_water) \ + ( ((_low) + (_size)) - (_high_water) ) + +#define Stack_check_usable_stack_start(_the_stack) \ + ((_the_stack)->area + sizeof(Stack_check_Control)) + +#endif + +#define Stack_check_usable_stack_size(_the_stack) \ + ((_the_stack)->size - sizeof(Stack_check_Control)) + + +/* + * Do we have an interrupt stack? + * XXX it would sure be nice if the interrupt stack were also + * stored in a "stack" structure! + */ + + +Stack_Control stack_check_interrupt_stack; + +/* + * Prototypes necessary for forward references + */ + +void Stack_check_Dump_usage( void ); + +/* + * Fill an entire stack area with BYTE_PATTERN. + * This will be used by a Fatal extension to check for + * amount of actual stack used + */ + +void +stack_check_dope_stack(Stack_Control *stack) +{ + memset(stack->area, BYTE_PATTERN, stack->size); +} + + +/*PAGE + * + * Stack_check_Initialize + */ + +unsigned32 stack_check_initialized = 0; + +void Stack_check_Initialize( void ) +{ + rtems_status_code status; + Objects_Id id_ignored; + unsigned32 *p; +#if 0 + unsigned32 i; + unsigned32 class_index; + Thread_Control *the_thread; + Objects_Information *information; +#endif + + if (stack_check_initialized) + return; + + /* + * Dope the pattern and fill areas + */ + + for ( p = Stack_check_Pattern.pattern; + p < &Stack_check_Pattern.pattern[PATTERN_SIZE_WORDS]; + p += 4 + ) + { + p[0] = 0xFEEDF00D; /* FEED FOOD to BAD DOG */ + p[1] = 0x0BAD0D06; + p[2] = 0xDEADF00D; /* DEAD FOOD GOOD DOG */ + p[3] = 0x600D0D06; + }; + + status = rtems_extension_create( + rtems_build_name( 'S', 'T', 'C', 'K' ), + &Stack_check_Extension_table, + &id_ignored + ); + assert ( status == RTEMS_SUCCESSFUL ); + + Stack_check_Blown_task = 0; + + /* + * If installed by a task, that task will not get setup properly + * since it missed out on the create hook. This will cause a + * failure on first switch out of that task. + * So pretend here that we actually ran create and begin extensions. + */ + + /* XXX + * + * Technically this has not been done for any task created before this + * happened. So just run through them and fix the situation. + */ +#if 0 + if (_Thread_Executing) + { + Stack_check_Create_extension(_Thread_Executing, _Thread_Executing); + } +#endif + +#if 0 + for ( class_index = OBJECTS_CLASSES_FIRST ; + class_index <= OBJECTS_CLASSES_LAST ; + class_index++ ) { + information = _Objects_Information_table[ class_index ]; + if ( information && information->is_thread ) { + for ( i=1 ; i <= information->maximum ; i++ ) { + the_thread = (Thread_Control *)information->local_table[ i ]; + Stack_check_Create_extension( the_thread, the_thread ); + } + } + } +#endif + + /* + * If appropriate, setup the interrupt stack for high water testing + * also. + */ + if (_CPU_Interrupt_stack_low && _CPU_Interrupt_stack_high) + { + stack_check_interrupt_stack.area = _CPU_Interrupt_stack_low; + stack_check_interrupt_stack.size = _CPU_Interrupt_stack_high - + _CPU_Interrupt_stack_low; + + stack_check_dope_stack(&stack_check_interrupt_stack); + } + +#ifdef DONT_USE_FATAL_EXTENSION +#ifdef RTEMS_DEBUG + /* + * this would normally be called by a fatal extension + * handler, but we don't run fatal extensions unless + * we fatal error. + */ + atexit(Stack_check_Dump_usage); +#endif +#endif + + stack_check_initialized = 1; +} + +/*PAGE + * + * Stack_check_Create_extension + */ + +boolean Stack_check_Create_extension( + Thread_Control *running, + Thread_Control *the_thread +) +{ + if (the_thread /* XXX && (the_thread != _Thread_Executing) */ ) + stack_check_dope_stack(&the_thread->Start.Initial_stack); + + return TRUE; +} + +/*PAGE + * + * Stack_check_Begin_extension + */ + +void Stack_check_Begin_extension( + Thread_Control *the_thread +) +{ + Stack_check_Control *the_pattern; + + if ( the_thread->Object.id == 0 ) /* skip system tasks */ + return; + + the_pattern = Stack_check_Get_pattern_area(&the_thread->Start.Initial_stack); + + *the_pattern = Stack_check_Pattern; +} + +/*PAGE + * + * Stack_check_report_blown_task + * Report a blown stack. Needs to be a separate routine + * so that interrupt handlers can use this too. + * + * Caller must have set the Stack_check_Blown_task. + * + * NOTE: The system is in a questionable state... we may not get + * the following message out. + */ + +void Stack_check_report_blown_task(void) +{ + Stack_Control *stack; + Thread_Control *running; + + running = Stack_check_Blown_task; + stack = &running->Start.Initial_stack; + + fprintf( + stderr, + "BLOWN STACK!!! Offending task(%p): id=0x%08x; name=0x%08x", + running, + running->Object.id, + *(unsigned32 *)running->Object.name + ); + fflush(stderr); + + if (BSP_Configuration.User_multiprocessing_table) + fprintf( + stderr, + "; node=%d\n", + BSP_Configuration.User_multiprocessing_table->node + ); + else + fprintf(stderr, "\n"); + fflush(stderr); + + fprintf( + stderr, + " stack covers range 0x%08x - 0x%08x (%d bytes)\n", + (unsigned32) stack->area, + (unsigned32) stack->area + stack->size - 1, + (unsigned32) stack->size); + fflush(stderr); + + fprintf( + stderr, + " Damaged pattern begins at 0x%08x and is %d bytes long\n", + (unsigned32) Stack_check_Get_pattern_area(stack), PATTERN_SIZE_BYTES); + fflush(stderr); + + rtems_fatal_error_occurred( (unsigned32) "STACK BLOWN" ); +} + +/*PAGE + * + * Stack_check_Switch_extension + */ + +void Stack_check_Switch_extension( + Thread_Control *running, + Thread_Control *heir +) +{ + if ( running->Object.id == 0 ) /* skip system tasks */ + return; + + if (0 != memcmp( (void *) Stack_check_Get_pattern_area( &running->Start.Initial_stack)->pattern, + (void *) Stack_check_Pattern.pattern, + PATTERN_SIZE_BYTES)) + { + Stack_check_Blown_task = running; + Stack_check_report_blown_task(); + } +} + +void *Stack_check_find_high_water_mark( + const void *s, + size_t n +) +{ + const unsigned32 *base, *ebase; + unsigned32 length; + + base = s; + length = n/4; + +#if ( CPU_STACK_GROWS_UP == TRUE ) + /* + * start at higher memory and find first word that does not + * match pattern + */ + + base += length - 1; + for (ebase = s; base > ebase; base--) + if (*base != U32_PATTERN) + return (void *) base; +#else + /* + * start at lower memory and find first word that does not + * match pattern + */ + + base += PATTERN_SIZE_WORDS; + for (ebase = base + length; base < ebase; base++) + if (*base != U32_PATTERN) + return (void *) base; +#endif + + return (void *)0; +} + +/*PAGE + * + * Stack_check_Dump_threads_usage + * Try to print out how much stack was actually used by the task. + * + */ + +void Stack_check_Dump_threads_usage( + Thread_Control *the_thread +) +{ + unsigned32 size, used; + void *low; + void *high_water_mark; + Stack_Control *stack; + + if ( !the_thread ) + return; + + /* + * XXX HACK to get to interrupt stack + */ + + if (the_thread == (Thread_Control *) -1) + { + if (stack_check_interrupt_stack.area) + { + stack = &stack_check_interrupt_stack; + the_thread = 0; + } + else + return; + } + else + stack = &the_thread->Start.Initial_stack; + + low = Stack_check_usable_stack_start(stack); + size = Stack_check_usable_stack_size(stack); + + high_water_mark = Stack_check_find_high_water_mark(low, size); + + if ( high_water_mark ) + used = Stack_check_Calculate_used( low, size, high_water_mark ); + else + used = 0; + + printf( "0x%08x 0x%08x 0x%08x 0x%08x %8d %8d\n", + the_thread ? the_thread->Object.id : ~0, + the_thread ? *(unsigned32 *)the_thread->Object.name : + rtems_build_name('I', 'N', 'T', 'R'), + (unsigned32) stack->area, + (unsigned32) stack->area + (unsigned32) stack->size - 1, + size, + used + ); +} + +/*PAGE + * + * Stack_check_Fatal_extension + */ + +void Stack_check_Fatal_extension( + Internal_errors_Source source, + boolean is_internal, + unsigned32 status +) +{ +#ifndef DONT_USE_FATAL_EXTENSION + if (status == 0) + Stack_check_Dump_usage(); +#endif +} + + +/*PAGE + * + * Stack_check_Dump_usage + */ + +void Stack_check_Dump_usage( void ) +{ + unsigned32 i; + unsigned32 class_index; + Thread_Control *the_thread; + unsigned32 hit_running = 0; + Objects_Information *information; + + if (stack_check_initialized == 0) + return; + + printf("Stack usage by thread\n"); + printf( + " ID NAME LOW HIGH AVAILABLE USED\n" + ); + + for ( class_index = OBJECTS_CLASSES_FIRST ; + class_index <= OBJECTS_CLASSES_LAST ; + class_index++ ) { + information = _Objects_Information_table[ class_index ]; + if ( information && information->is_thread ) { + for ( i=1 ; i <= information->maximum ; i++ ) { + the_thread = (Thread_Control *)information->local_table[ i ]; + Stack_check_Dump_threads_usage( the_thread ); + if ( the_thread == _Thread_Executing ) + hit_running = 1; + } + } + } + + if ( !hit_running ) + Stack_check_Dump_threads_usage( _Thread_Executing ); + + /* dump interrupt stack info if any */ + Stack_check_Dump_threads_usage((Thread_Control *) -1); +} + diff --git a/cpukit/libmisc/stackchk/internal.h b/cpukit/libmisc/stackchk/internal.h new file mode 100644 index 0000000000..e98ec7e92e --- /dev/null +++ b/cpukit/libmisc/stackchk/internal.h @@ -0,0 +1,96 @@ +/* internal.h + * + * This include file contains internal information + * for the RTEMS stack checker. + * + * 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$ + */ + +#ifndef __INTERNAL_STACK_CHECK_h +#define __INTERNAL_STACK_CHECK_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This structure is used to fill in and compare the "end of stack" + * marker pattern. + * pattern area must be a multiple of 4 words. + */ + +#ifdef CPU_STACK_CHECK_SIZE +#define PATTERN_SIZE_WORDS (((CPU_STACK_CHECK_SIZE / 4) + 3) & ~0x3) +#else +#define PATTERN_SIZE_WORDS 4 +#endif + +#define PATTERN_SIZE_BYTES (PATTERN_SIZE_WORDS * 4) + +typedef struct { + unsigned32 pattern[ PATTERN_SIZE_WORDS ]; +} Stack_check_Control; + +/* + * The pattern used to fill the entire stack. + */ + +#define BYTE_PATTERN 0xA5 +#define U32_PATTERN 0xA5A5A5A5 + +/* + * Stack_check_Create_extension + */ + +boolean Stack_check_Create_extension( + Thread_Control *running, + Thread_Control *the_thread +); + +/* + * Stack_check_Begin_extension + */ + +void Stack_check_Begin_extension( + Thread_Control *the_thread +); + +/* + * Stack_check_Switch_extension + */ + +void Stack_check_Switch_extension( + Thread_Control *running, + Thread_Control *heir +); + +/* + * Stack_check_Fatal_extension + */ + +void Stack_check_Fatal_extension( + Internal_errors_Source source, + boolean is_internal, + unsigned32 status +); + +/* + * Stack_check_Dump_usage + */ + +void Stack_check_Dump_usage( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/libmisc/stackchk/stackchk.h b/cpukit/libmisc/stackchk/stackchk.h new file mode 100644 index 0000000000..f3281c63fe --- /dev/null +++ b/cpukit/libmisc/stackchk/stackchk.h @@ -0,0 +1,41 @@ +/* stackchk.h + * + * This include file contains information necessary to utilize + * and install the stack checker mechanism. + * + * 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$ + */ + +#ifndef __STACK_CHECK_h +#define __STACK_CHECK_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Stack_check_Initialize + */ + +void Stack_check_Initialize( void ); + +/* + * Stack_check_Dump_usage + */ + +void Stack_check_Dump_usage( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/posix/include/aio.h b/cpukit/posix/include/aio.h new file mode 100644 index 0000000000..504559c857 --- /dev/null +++ b/cpukit/posix/include/aio.h @@ -0,0 +1,137 @@ +/* aio.h + * + * $Id$ + */ + +#ifndef __POSIX_ASYNCHRONOUS_IO_h +#define __POSIX_ASYNCHRONOUS_IO_h + +#include <rtems/posix/features.h> + +#if defined(_POSIX_ASYNCHRONOUS_IO) + +/* + * 6.7.1 Data Definitions for Asynchronous Input and Output, + * P1003.1b-1993, p. 151 + */ + +#include <sys/types.h> +#include <signal.h> +#include <time.h> +#include <fcntl.h> + +/* + * 6.7.1.2 Manifest Constants, P1003.1b-1993, p. 153 + */ + +#define AIO_CANCELED 0 /* all requested operations have been canceled */ +#define AIO_NOTCANCELED 0 /* some of the operations could not be canceled */ + /* since they are in progress */ +#define AIO_ALLDONE 0 /* none of the requested operations could be */ + /* canceled since they are already complete */ + +/* lio_listio() options */ + +#define LIO_WAIT 0 /* calling process is to suspend until the */ + /* operation is complete */ +#define LIO_NOWAIT 0 /* calling process is to continue execution while */ + /* the operation is performed and no notification */ + /* shall be given when the operation is completed */ +#define LIO_READ 0 /* request a read() */ +#define LIO_WRITE 0 /* request a write() */ +#define LIO_NOP 0 /* no transfer is requested */ + +/* + * 6.7.1.1 Asynchronous I/O Control Block, P1003.1b-1993, p. 151 + */ + +struct aiocb { + int aio_fildes; /* File descriptor */ + off_t aio_offset; /* File offset */ + volatile void *aio_buf; /* Location of buffer */ + size_t aio_nbytes; /* Length of transfer */ + int aio_reqprio; /* Request priority offset */ + struct sigevent aio_sigevent; /* Signal number and value */ + int aoi_lio_opcode; /* Operation to be performed */ +}; + +/* + * 6.7.2 Asynchronous Read, P1003.1b-1993, p. 154 + */ + +int aio_read( + struct aiocb *aiocbp +); + +/* + * 6.7.3 Asynchronous Write, P1003.1b-1993, p. 155 + */ + +int aio_write( + struct aiocb *aiocbp +); + +/* + * 6.7.4 List Directed I/O, P1003.1b-1993, p. 158 + */ + +int lio_listio( + int mode, + struct aiocb * const list[], + int nent, + struct sigevent *sig +); + +/* + * 6.7.5 Retrieve Error of Asynchronous I/O Operation, P1003.1b-1993, p. 161 + */ + +int aio_error( + const struct aiocb *aiocbp +); + +/* + * 6.7.6 Retrieve Return Status of Asynchronous I/O Operation, + * P1003.1b-1993, p. 162 + */ + +int aio_return( + const struct aiocb *aiocbp +); + +/* + * 6.7.7 Cancel Asynchronous I/O Operation, P1003.1b-1993, p. 163 + */ + +int aio_cancel( + int filedes, + struct aiocb *aiocbp +); + +/* + * 6.7.7 Wait for Asynchronous I/O Request, P1003.1b-1993, p. 164 + */ + +int aio_suspend( + struct aiocb * const list[], + int nent, + const struct timespec *timeout +); + +#if defined(_POSIX_SYNCHRONIZED_IO) + +/* + * 6.7.9 Asynchronous File Synchronization, P1003.1b-1993, p. 166 + */ + +int aio_fsync( + int op, + struct aiocb *aiocbp +); + +#endif /* _POSIX_SYNCHRONIZED_IO */ + +#endif /* _POSIX_ASYNCHRONOUS_IO */ + +#endif +/* end of include file */ diff --git a/cpukit/posix/include/devctl.h b/cpukit/posix/include/devctl.h new file mode 100644 index 0000000000..5073b475ee --- /dev/null +++ b/cpukit/posix/include/devctl.h @@ -0,0 +1,30 @@ +/* devctl.h + * + * $Id$ + */ + +#ifndef __POSIX_DEVICE_CONTROL_h +#define __POSIX_DEVICE_CONTROL_h + +#include <rtems/posix/features.h> + +#if defined(_POSIX_DEVICE_CONTROL) + +#include <sys/types.h> +#include <unistd.h> + +/* + * 21.2.1 Control a Device, P1003.4b/D8, p. 65 + */ + +int devctl( + int filedes, + void *dev_data_ptr, + size_t nbyte, + int *dev_info_ptr +); + +#endif + +#endif +/* end of include file */ diff --git a/cpukit/posix/include/intr.h b/cpukit/posix/include/intr.h new file mode 100644 index 0000000000..f07d1f9552 --- /dev/null +++ b/cpukit/posix/include/intr.h @@ -0,0 +1,72 @@ +/* intr.h + * + * XXX: It is unclear if the type "intr_t" should be defined when + * _POSIX_INTERRUPT_CONTROL is not. + * + * $Id$ + */ + +#ifndef __POSIX_INTERRUPTS_h +#define __POSIX_INTERRUPTS_h + +#include <rtems/posix/features.h> +#include <sys/types.h> +#include <sys/time.h> + +#if defined(_POSIX_INTERRUPT_CONTROL) + +/* + * 22.2 Concepts, P1003.4b/D8, p. 73 + */ + +typedef int intr_t; + +/* + * 22.3.1 Associate a User-Written ISR with an Interrupt, P1003.4b/D8, p. 74 + */ + +/* + * Return codes from an interrupt handler + */ + +#define INTR_HANDLED_NOTIFY 0 /* ISR handled this interrupt, notify */ + /* the thread that registered the */ + /* ISR that the interrupt occurred. */ +#define INTR_HANDLED_DO_NOT_NOTIFY 1 /* ISR handled this interrupt, but */ + /* do NOT perform notification. */ +#define INTR_NOT_HANDLED 2 /* ISR did not handle this interrupt, */ + /* let the next handler try. */ + +int intr_capture( + intr_t intr, + int (*intr_handler)( void *area ), + volatile void *area, + size_t areasize +); + +int intr_release( + intr_t intr, + int (*intr_handler)( void *area ) +); + +int intr_lock( + intr_t intr +); + +int intr_unlock( + intr_t intr +); + +/* + * 22.3.2 Await Interrupt Notification, P1003.4b/D8, p. 76 + */ + +int intr_timed_wait( + int flags, + const struct timespec *timeout +); + +#endif + +#endif +/* end of include file */ diff --git a/cpukit/posix/include/mqueue.h b/cpukit/posix/include/mqueue.h new file mode 100644 index 0000000000..f1b2250e5c --- /dev/null +++ b/cpukit/posix/include/mqueue.h @@ -0,0 +1,145 @@ +/* mqueue.h + * + * $Id$ + */ + +#ifndef __POSIX_MESSAGE_QUEUE_h +#define __POSIX_MESSAGE_QUEUE_h + +#include <rtems/posix/features.h> + +#if defined(_POSIX_MESSAGE_PASSING) + +#include <sys/types.h> + +#include <rtems/system.h> +#include <rtems/score/object.h> + +/* + * 15.1.1 Data Structures, P1003.1b-1993, p. 271 + */ + +typedef Objects_Id mqd_t; + +struct mq_attr { + long mq_flags; /* Message queue flags */ + long mq_maxmsg; /* Maximum number of messages */ + long mq_msgsize; /* Maximum message size */ + long mq_curmsgs; /* Number of messages currently queued */ +}; + +/* + * 15.2.2 Open a Message Queue, P1003.1b-1993, p. 272 + */ + +mqd_t mq_open( + const char *name, + int oflag, + ... +); + +/* + * 15.2.2 Close a Message Queue, P1003.1b-1993, p. 275 + */ + +int mq_close( + mqd_t mqdes +); + +/* + * 15.2.2 Remove a Message Queue, P1003.1b-1993, p. 276 + */ + +int mq_unlink( + const char *name +); + +/* + * 15.2.4 Send a Message to a Message Queue, P1003.1b-1993, p. 277 + * + * NOTE: P1003.4b/D8, p. 45 adds mq_timedsend(). + */ + +int mq_send( + mqd_t mqdes, + const char *msg_ptr, + size_t msg_len, + unsigned int msg_prio +); + +#if defined(_POSIX_TIMEOUTS) + +#include <time.h> + +int mq_timedsend( + mqd_t mqdes, + const char *msg_ptr, + size_t msg_len, + unsigned int msg_prio, + const struct timespec *timeout +); + +#endif /* _POSIX_TIMEOUTS */ + +/* + * 15.2.5 Receive a Message From a Message Queue, P1003.1b-1993, p. 279 + * + * NOTE: P1003.4b/D8, p. 45 adds mq_timedreceive(). + */ + +ssize_t mq_receive( + mqd_t mqdes, + char *msg_ptr, + size_t msg_len, + unsigned int *msg_prio +); + +#if defined(_POSIX_TIMEOUTS) + +int mq_timedreceive( /* XXX: should this be ssize_t */ + mqd_t mqdes, + char *msg_ptr, + size_t msg_len, + unsigned int *msg_prio, + const struct timespec *timeout +); + +#endif /* _POSIX_TIMEOUTS */ + +#if defined(_POSIX_REALTIME_SIGNALS) + +/* + * 15.2.6 Notify Process that a Message is Available on a Queue, + * P1003.1b-1993, p. 280 + */ + +int mq_notify( + mqd_t mqdes, + const struct sigevent *notification +); + +#endif /* _POSIX_REALTIME_SIGNALS */ + +/* + * 15.2.7 Set Message Queue Attributes, P1003.1b-1993, p. 281 + */ + +int mq_setattr( + mqd_t mqdes, + const struct mq_attr *mqstat, + struct mq_attr *omqstat +); + +/* + * 15.2.8 Get Message Queue Attributes, P1003.1b-1993, p. 283 + */ + +int mq_getattr( + mqd_t mqdes, + struct mq_attr *mqstat +); + +#endif /* _POSIX_MESSAGE_PASSING */ + +#endif +/* end of include file */ diff --git a/cpukit/posix/include/rtems/posix/cancel.h b/cpukit/posix/include/rtems/posix/cancel.h new file mode 100644 index 0000000000..e6d80275f4 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/cancel.h @@ -0,0 +1,16 @@ +/* rtems/posix/cancel.h + * + * $Id$ + */ + +#ifndef __RTEMS_POSIX_CANCEL_h +#define __RTEMS_POSIX_CANCEL_h + +typedef struct { + Chain_Node Node; + void (*routine)( void * ); + void *arg; +} POSIX_Cancel_Handler_control; + +#endif +/* end of include file */ diff --git a/cpukit/posix/include/rtems/posix/cond.h b/cpukit/posix/include/rtems/posix/cond.h new file mode 100644 index 0000000000..4448e38b6c --- /dev/null +++ b/cpukit/posix/include/rtems/posix/cond.h @@ -0,0 +1,123 @@ +/* rtems/posix/cond.h + * + * This include file contains all the private support information for + * POSIX condition variables. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_CONDITION_VARIABLES_h +#define __RTEMS_POSIX_CONDITION_VARIABLES_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> +#include <rtems/score/threadq.h> + +/* + * Data Structure used to manage a POSIX condition variable + */ + +typedef struct { + Objects_Control Object; + int process_shared; + pthread_mutex_t Mutex; + Thread_queue_Control Wait_queue; +} POSIX_Condition_variables_Control; + +/* + * The following defines the information control block used to manage + * this class of objects. + */ + +EXTERN Objects_Information _POSIX_Condition_variables_Information; + +/* + * _POSIX_Condition_variables_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _POSIX_Condition_variables_Manager_initialization( + unsigned32 maximum_condition_variables +); + +/* + * _POSIX_Condition_variables_Allocate + * + * DESCRIPTION: + * + * This function allocates a condition variable control block from + * the inactive chain of free condition variable control blocks. + */ + +STATIC INLINE POSIX_Condition_variables_Control * + _POSIX_Condition_variables_Allocate( void ); + +/* + * _POSIX_Condition_variables_Free + * + * DESCRIPTION: + * + * This routine frees a condition variable control block to the + * inactive chain of free condition variable control blocks. + */ + +STATIC INLINE void _POSIX_Condition_variables_Free ( + POSIX_Condition_variables_Control *the_condition_variable +); + +/* + * _POSIX_Condition_variables_Get + * + * DESCRIPTION: + * + * This function maps condition variable IDs to condition variable control + * blocks. If ID corresponds to a local condition variable, then it returns + * the_condition variable control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. if the condition variable ID is global and + * resides on a remote node, then location is set to OBJECTS_REMOTE, + * and the_condition variable is undefined. Otherwise, location is set + * to OBJECTS_ERROR and the_condition variable is undefined. + */ + +STATIC INLINE POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get ( + Objects_Id *id, + Objects_Locations *location +); + +/* + * _POSIX_Condition_variables_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_condition variable is NULL + * and FALSE otherwise. + */ + +STATIC INLINE boolean _POSIX_Condition_variables_Is_null ( + POSIX_Condition_variables_Control *the_condition_variable +); + +#include <rtems/posix/cond.inl> +#include <rtems/posix/condmp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ + diff --git a/cpukit/posix/include/rtems/posix/condmp.h b/cpukit/posix/include/rtems/posix/condmp.h new file mode 100644 index 0000000000..12997b68f4 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/condmp.h @@ -0,0 +1,162 @@ +/* condmp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the POSIX Condition Variable 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$ + */ + +#ifndef __RTEMS_POSIX_CONDITION_VARIABLES_MP_h +#define __RTEMS_POSIX_CONDITION_VARIABLES_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the list of + * remote condition variable operations. + */ + +typedef enum { + POSIX_CONDITION_VARIABLES_MP_ANNOUNCE_CREATE = 0, + POSIX_CONDITION_VARIABLES_MP_ANNOUNCE_DELETE = 1, + POSIX_CONDITION_VARIABLES_MP_EXTRACT_PROXY = 2, + POSIX_CONDITION_VARIABLES_MP_OBTAIN_REQUEST = 3, + POSIX_CONDITION_VARIABLES_MP_OBTAIN_RESPONSE = 4, + POSIX_CONDITION_VARIABLES_MP_RELEASE_REQUEST = 5, + POSIX_CONDITION_VARIABLES_MP_RELEASE_RESPONSE = 6, +} POSIX_Condition_variables_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote condition variable operations. + */ + +typedef struct { + MP_packet_Prefix Prefix; + POSIX_Condition_variables_MP_Remote_operations operation; + Objects_Name name; + boolean wait; /* XXX options */ + Objects_Id proxy_id; +} POSIX_Condition_variables_MP_Packet; + +/* + * _POSIX_Condition_variables_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _POSIX_Condition_variables_MP_Send_process_packet ( + POSIX_Condition_variables_MP_Remote_operations operation, + Objects_Id condition_variables_id, + Objects_Name name, + Objects_Id proxy_id +); + +/* + * _POSIX_Condition_variables_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +int _POSIX_Condition_variables_MP_Send_request_packet ( + POSIX_Condition_variables_MP_Remote_operations operation, + Objects_Id condition_variables_id, + boolean wait, /* XXX options */ + Watchdog_Interval timeout +); + +/* + * _POSIX_Condition_variables_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _POSIX_Condition_variables_MP_Send_response_packet ( + POSIX_Condition_variables_MP_Remote_operations operation, + Objects_Id condition_variables_id, + Thread_Control *the_thread +); + +/* + * + * _POSIX_Condition_variables_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _POSIX_Condition_variables_MP_Process_packet ( + MP_packet_Prefix *the_packet_prefix +); + +/* + * _POSIX_Condition_variables_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + */ + +void _POSIX_Condition_variables_MP_Send_object_was_deleted ( + Thread_Control *the_proxy +); + +/* + * _POSIX_Condition_variables_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + */ + +void _POSIX_Condition_variables_MP_Send_extract_proxy ( + Thread_Control *the_thread +); + +/* + * _POSIX_Condition_variables_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a condition variable mp packet. + */ + +POSIX_Condition_variables_MP_Packet + *_POSIX_Condition_variables_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/posix/include/rtems/posix/intr.h b/cpukit/posix/include/rtems/posix/intr.h new file mode 100644 index 0000000000..ae1690f676 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/intr.h @@ -0,0 +1,153 @@ +/* rtems/posix/intr.h + * + * This include file contains all the private support information for + * POSIX Interrupt 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$ + */ + +#ifndef __RTEMS_POSIX_KEY_h +#define __RTEMS_POSIX_KEY_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/isr.h> +#include <rtems/score/object.h> + +/* + * Data Structure used to manage each POSIX Interrupt Vector + */ + +typedef struct { + int number_installed; + int lock_count; + int deferred_count; + Chain_Control Handlers; +} POSIX_Interrupt_Control; + +/* + * Data Structure used to manage a POSIX Interrupt Handler + */ + +typedef struct { + Objects_Control Object; + int is_active; + intr_t vector; + Thread_Control *server; + int (*handler)( void *area ); + volatile void *user_data_area; +} POSIX_Interrupt_Handler_control; + +/* + * The following defines the information control block used to manage + * this class of objects. + */ + +EXTERN Objects_Information _POSIX_Interrupt_Handlers_Information; + +/* + * The following is an array which is used to manage the set of + * interrupt handlers installed on each vector. + */ + +EXTERN POSIX_Interrupt_Control _POSIX_Interrupt_Information[ ISR_NUMBER_OF_VECTORS ]; + +/* + * _POSIX_Interrupt_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _POSIX_Interrupt_Manager_initialization( + unsigned32 maximum_interrupt_handlers +); + +/* + * _POSIX_Interrupt_Allocate + * + * DESCRIPTION: + * + * This function allocates a interrupt handler control block from + * the inactive chain of free interrupt handler control blocks. + */ + +STATIC INLINE POSIX_Interrupt_Handler_control * + _POSIX_Interrupt_Allocate( void ); + +/* + * _POSIX_Interrupt_Free + * + * DESCRIPTION: + * + * This routine frees a interrupt handler control block to the + * inactive chain of free interrupt handler control blocks. + */ + +STATIC INLINE void _POSIX_Interrupt_Free ( + POSIX_Interrupt_Handler_control *the_intr +); + +/* + * _POSIX_Interrupt_Get + * + * DESCRIPTION: + * + * This function maps interrupt handler IDs to interrupt handler control + * blocks. If ID corresponds to a local interrupt handler, then it returns + * the_intr control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. if the interrupt handler ID is global and + * resides on a remote node, then location is set to OBJECTS_REMOTE, + * and the_intr is undefined. Otherwise, location is set + * to OBJECTS_ERROR and the_intr is undefined. + */ + +STATIC INLINE POSIX_Interrupt_Control *_POSIX_Interrupt_Get ( + Objects_Id id, + Objects_Locations *location +); + +/* + * _POSIX_Interrupt_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_intr is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _POSIX_Interrupt_Is_null ( + POSIX_Interrupt_Handler_control *the_intr +); + +/* + * _POSIX_Interrupt_Handler + * + * DESCRIPTION: + * + * This function XXX. + */ + +void _POSIX_Interrupt_Handler( + ISR_Vector_number vector +); + +#include <rtems/posix/intr.inl> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ + diff --git a/cpukit/posix/include/rtems/posix/key.h b/cpukit/posix/include/rtems/posix/key.h new file mode 100644 index 0000000000..0e690161b8 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/key.h @@ -0,0 +1,136 @@ +/* rtems/posix/key.h + * + * This include file contains all the private support information for + * POSIX key. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_KEY_h +#define __RTEMS_POSIX_KEY_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Data Structure used to manage a POSIX key + * + * NOTE: The Values is a table indexed by the index portion of the + * ID of the currently executing thread. + */ + +typedef struct { + Objects_Control Object; + boolean is_active; + void (*destructor)( void * ); + void **Values[ OBJECTS_CLASSES_LAST_THREAD_CLASS + 1 ]; +} POSIX_Keys_Control; + +/* + * The following defines the information control block used to manage + * this class of objects. + */ + +EXTERN Objects_Information _POSIX_Keys_Information; + +/* + * _POSIX_Keys_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _POSIX_Key_Manager_initialization( + unsigned32 maximum_keys +); + +/* + * _POSIX_Keys_Run_destructors + * + * DESCRIPTION: + * + * This function executes all the destructors associated with the thread's + * keys. This function will execute until all values have been set to NULL. + * + * NOTE: This is the routine executed when a thread exits to + * run through all the keys and do the destructor action. + */ + +void _POSIX_Keys_Run_destructors( + Thread_Control *thread +); + +/* + * _POSIX_Keys_Allocate + * + * DESCRIPTION: + * + * This function allocates a keys control block from + * the inactive chain of free keys control blocks. + */ + +STATIC INLINE POSIX_Keys_Control *_POSIX_Keys_Allocate( void ); + +/* + * _POSIX_Keys_Free + * + * DESCRIPTION: + * + * This routine frees a keys control block to the + * inactive chain of free keys control blocks. + */ + +STATIC INLINE void _POSIX_Keys_Free ( + POSIX_Keys_Control *the_key +); + +/* + * _POSIX_Keys_Get + * + * DESCRIPTION: + * + * This function maps key IDs to key control blocks. + * If ID corresponds to a local keys, then it returns + * the_key control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. if the keys ID is global and + * resides on a remote node, then location is set to OBJECTS_REMOTE, + * and the_key is undefined. Otherwise, location is set + * to OBJECTS_ERROR and the_key is undefined. + */ + +STATIC INLINE POSIX_Keys_Control *_POSIX_Keys_Get ( + Objects_Id id, + Objects_Locations *location +); + +/* + * _POSIX_Keys_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_key is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _POSIX_Keys_Is_null ( + POSIX_Keys_Control *the_key +); + +#include <rtems/posix/key.inl> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ + diff --git a/cpukit/posix/include/rtems/posix/mqueue.h b/cpukit/posix/include/rtems/posix/mqueue.h new file mode 100644 index 0000000000..5d5cfee61b --- /dev/null +++ b/cpukit/posix/include/rtems/posix/mqueue.h @@ -0,0 +1,186 @@ +/* rtems/posix/mqueue.h + * + * This include file contains all the private support information for + * POSIX Message Queues. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_MESSAGE_QUEUE_h +#define __RTEMS_POSIX_MESSAGE_QUEUE_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/coremsg.h> +#include <rtems/score/object.h> + +/* + * Data Structure used to manage a POSIX message queue + */ + +typedef struct { + Objects_Control Object; + int process_shared; + int flags; + boolean named; + boolean linked; + boolean blocking; + unsigned32 open_count; + CORE_message_queue_Control Message_queue; + struct sigevent notification; +} POSIX_Message_queue_Control; + +/* + * The following defines the information control block used to manage + * this class of objects. + */ + +EXTERN Objects_Information _POSIX_Message_queue_Information; + +/* + * _POSIX_Message_queue_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _POSIX_Message_queue_Manager_initialization( + unsigned32 maximum_message_queues +); + +/* + * + * _POSIX_Message_queue_Create_support + * + * DESCRIPTION: + * + * This routine performs the creation of a message queue utilizing the + * core message queue. + */ + +int _POSIX_Message_queue_Create_support( + const char *name, + int pshared, + unsigned int oflag, + struct mq_attr *attr, + POSIX_Message_queue_Control **message_queue +); + +/* + * + * _POSIX_Message_queue_Send_support + * + * DESCRIPTION: + * + * This routine posts a message to a specified message queue. + */ + +int _POSIX_Message_queue_Send_support( + mqd_t mqdes, + const char *msg_ptr, + unsigned32 msg_len, + Priority_Control msg_prio, + Watchdog_Interval timeout +); + +/* + * _POSIX_Message_queue_Allocate + * + * DESCRIPTION: + * + * This function allocates a message queue control block from + * the inactive chain of free message queue control blocks. + */ + +STATIC INLINE POSIX_Message_queue_Control *_POSIX_Message_queue_Allocate( void ); + +/* + * _POSIX_Message_queue_Free + * + * DESCRIPTION: + * + * This routine frees a message queue control block to the + * inactive chain of free message queue control blocks. + */ + +STATIC INLINE void _POSIX_Message_queue_Free ( + POSIX_Message_queue_Control *the_mq +); + +/* + * _POSIX_Message_queue_Get + * + * DESCRIPTION: + * + * This function maps message queue IDs to message queue control blocks. + * If ID corresponds to a local message queue, then it returns + * the_mq control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. if the message queue ID is global and + * resides on a remote node, then location is set to OBJECTS_REMOTE, + * and the_message queue is undefined. Otherwise, location is set + * to OBJECTS_ERROR and the_mq is undefined. + */ + +STATIC INLINE POSIX_Message_queue_Control *_POSIX_Message_queue_Get ( + Objects_Id id, + Objects_Locations *location +); + +/* + * _POSIX_Message_queue_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_message_queue is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _POSIX_Message_queue_Is_null ( + POSIX_Message_queue_Control *the_mq +); + +/* + * _POSIX_Message_queue_Name_to_id + * + * DESCRIPTION: + * + * XXX + */ + +int _POSIX_Message_queue_Name_to_id( + const char *name, + Objects_Id *id +); + +/* + * _POSIX_Message_queue_Priority_to_core + * + * DESCRIPTION: + * + * XXX + */ + +STATIC INLINE Priority_Control _POSIX_Message_queue_Priority_to_core( + unsigned int priority +); + +#include <rtems/posix/mqueue.inl> +#include <rtems/posix/mqueuemp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ + diff --git a/cpukit/posix/include/rtems/posix/mqueuemp.h b/cpukit/posix/include/rtems/posix/mqueuemp.h new file mode 100644 index 0000000000..ae23f6af56 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/mqueuemp.h @@ -0,0 +1,161 @@ +/* mqueuemp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the POSIX Message Queue 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$ + */ + +#ifndef __RTEMS_POSIX_MESSAGE_QUEUE_MP_h +#define __RTEMS_POSIX_MESSAGE_QUEUE_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the list of + * remote message queue operations. + */ + +typedef enum { + POSIX_MESSAGE_QUEUE_MP_ANNOUNCE_CREATE = 0, + POSIX_MESSAGE_QUEUE_MP_ANNOUNCE_DELETE = 1, + POSIX_MESSAGE_QUEUE_MP_EXTRACT_PROXY = 2, + POSIX_MESSAGE_QUEUE_MP_OBTAIN_REQUEST = 3, + POSIX_MESSAGE_QUEUE_MP_OBTAIN_RESPONSE = 4, + POSIX_MESSAGE_QUEUE_MP_RELEASE_REQUEST = 5, + POSIX_MESSAGE_QUEUE_MP_RELEASE_RESPONSE = 6, +} POSIX_Message_queue_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote message queue operations. + */ + +typedef struct { + MP_packet_Prefix Prefix; + POSIX_Message_queue_MP_Remote_operations operation; + Objects_Name name; + boolean wait; /* XXX options */ + Objects_Id proxy_id; +} POSIX_Message_queue_MP_Packet; + +/* + * _POSIX_Message_queue_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _POSIX_Message_queue_MP_Send_process_packet ( + POSIX_Message_queue_MP_Remote_operations operation, + Objects_Id mq_id, + Objects_Name name, + Objects_Id proxy_id +); + +/* + * _POSIX_Message_queue_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +int _POSIX_Message_queue_MP_Send_request_packet ( + POSIX_Message_queue_MP_Remote_operations operation, + Objects_Id mq_id, + boolean wait, /* XXX options */ + Watchdog_Interval timeout +); + +/* + * _POSIX_Message_queue_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _POSIX_Message_queue_MP_Send_response_packet ( + POSIX_Message_queue_MP_Remote_operations operation, + Objects_Id mq_id, + Thread_Control *the_thread +); + +/* + * + * _POSIX_Message_queue_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _POSIX_Message_queue_MP_Process_packet ( + MP_packet_Prefix *the_packet_prefix +); + +/* + * _POSIX_Message_queue_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + */ + +void _POSIX_Message_queue_MP_Send_object_was_deleted ( + Thread_Control *the_proxy +); + +/* + * _POSIX_Message_queue_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + */ + +void _POSIX_Message_queue_MP_Send_extract_proxy ( + Thread_Control *the_thread +); + +/* + * _POSIX_Message_queue_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a message queue mp packet. + */ + +POSIX_Message_queue_MP_Packet *_POSIX_Message_queue_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/posix/include/rtems/posix/mutex.h b/cpukit/posix/include/rtems/posix/mutex.h new file mode 100644 index 0000000000..5639d908d2 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/mutex.h @@ -0,0 +1,117 @@ +/* rtems/posix/mutex.h + * + * This include file contains all the private support information for + * POSIX mutex's. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_MUTEX_h +#define __RTEMS_POSIX_MUTEX_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Data Structure used to manage a POSIX mutex + */ + +typedef struct { + Objects_Control Object; + int process_shared; + CORE_mutex_Control Mutex; +} POSIX_Mutex_Control; + +/* + * The following defines the information control block used to manage + * this class of objects. + */ + +EXTERN Objects_Information _POSIX_Mutex_Information; + +/* + * _POSIX_Mutex_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _POSIX_Mutex_Manager_initialization( + unsigned32 maximum_mutexes +); + +/* + * _POSIX_Mutex_Allocate + * + * DESCRIPTION: + * + * This function allocates a mutexes control block from + * the inactive chain of free mutexes control blocks. + */ + +STATIC INLINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void ); + +/* + * _POSIX_Mutex_Free + * + * DESCRIPTION: + * + * This routine frees a mutexes control block to the + * inactive chain of free mutexes control blocks. + */ + +STATIC INLINE void _POSIX_Mutex_Free ( + POSIX_Mutex_Control *the_mutex +); + +/* + * _POSIX_Mutex_Get + * + * DESCRIPTION: + * + * This function maps mutexes IDs to mutexes control blocks. + * If ID corresponds to a local mutexes, then it returns + * the_mutex control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. if the mutexes ID is global and + * resides on a remote node, then location is set to OBJECTS_REMOTE, + * and the_mutex is undefined. Otherwise, location is set + * to OBJECTS_ERROR and the_mutex is undefined. + */ + +STATIC INLINE POSIX_Mutex_Control *_POSIX_Mutex_Get ( + Objects_Id *id, + Objects_Locations *location +); + +/* + * _POSIX_Mutex_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_mutex is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _POSIX_Mutex_Is_null ( + POSIX_Mutex_Control *the_mutex +); + +#include <rtems/posix/mutex.inl> +#include <rtems/posix/mutexmp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ + diff --git a/cpukit/posix/include/rtems/posix/mutexmp.h b/cpukit/posix/include/rtems/posix/mutexmp.h new file mode 100644 index 0000000000..15ac5371e8 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/mutexmp.h @@ -0,0 +1,161 @@ +/* mutexmp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the POSIX Mutex 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$ + */ + +#ifndef __RTEMS_POSIX_MUTEX_MP_h +#define __RTEMS_POSIX_MUTEX_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the list of + * remote mutex operations. + */ + +typedef enum { + POSIX_MUTEX_MP_ANNOUNCE_CREATE = 0, + POSIX_MUTEX_MP_ANNOUNCE_DELETE = 1, + POSIX_MUTEX_MP_EXTRACT_PROXY = 2, + POSIX_MUTEX_MP_OBTAIN_REQUEST = 3, + POSIX_MUTEX_MP_OBTAIN_RESPONSE = 4, + POSIX_MUTEX_MP_RELEASE_REQUEST = 5, + POSIX_MUTEX_MP_RELEASE_RESPONSE = 6, +} POSIX_Mutex_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote mutex operations. + */ + +typedef struct { + MP_packet_Prefix Prefix; + POSIX_Mutex_MP_Remote_operations operation; + Objects_Name name; + boolean wait; /* XXX options */ + Objects_Id proxy_id; +} POSIX_Mutex_MP_Packet; + +/* + * _POSIX_Mutex_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _POSIX_Mutex_MP_Send_process_packet ( + POSIX_Mutex_MP_Remote_operations operation, + Objects_Id mutex_id, + Objects_Name name, + Objects_Id proxy_id +); + +/* + * _POSIX_Mutex_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +int _POSIX_Mutex_MP_Send_request_packet ( + POSIX_Mutex_MP_Remote_operations operation, + Objects_Id mutex_id, + boolean wait, /* XXX options */ + Watchdog_Interval timeout +); + +/* + * _POSIX_Mutex_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _POSIX_Mutex_MP_Send_response_packet ( + POSIX_Mutex_MP_Remote_operations operation, + Objects_Id mutex_id, + Thread_Control *the_thread +); + +/* + * + * _POSIX_Mutex_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _POSIX_Mutex_MP_Process_packet ( + MP_packet_Prefix *the_packet_prefix +); + +/* + * _POSIX_Mutex_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + */ + +void _POSIX_Mutex_MP_Send_object_was_deleted ( + Thread_Control *the_proxy +); + +/* + * _POSIX_Mutex_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + */ + +void _POSIX_Mutex_MP_Send_extract_proxy ( + Thread_Control *the_thread +); + +/* + * _POSIX_Mutex_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a mutex mp packet. + */ + +POSIX_Mutex_MP_Packet *_POSIX_Mutex_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/posix/include/rtems/posix/priority.h b/cpukit/posix/include/rtems/posix/priority.h new file mode 100644 index 0000000000..f4cb717b7c --- /dev/null +++ b/cpukit/posix/include/rtems/posix/priority.h @@ -0,0 +1,34 @@ +/* + * + * + * $Id$ + */ + +#ifndef __RTEMS_POSIX_PRIORITY_h +#define __RTEMS_POSIX_PRIORITY_h + +#include <rtems/score/priority.h> + +/* + * RTEMS Core has priorities run in the opposite sense of the POSIX API. + */ + +#define POSIX_SCHEDULER_MAXIMUM_PRIORITY (255) + +#define POSIX_SCHEDULER_MINIMUM_PRIORITY (1) + +STATIC INLINE boolean _POSIX_Priority_Is_valid( + int priority +); + +STATIC INLINE Priority_Control _POSIX_Priority_To_core( + int priority +); + +STATIC INLINE int _POSIX_Priority_From_core( + Priority_Control priority +); + +#include <rtems/posix/priority.inl> + +#endif diff --git a/cpukit/posix/include/rtems/posix/pthread.h b/cpukit/posix/include/rtems/posix/pthread.h new file mode 100644 index 0000000000..538e737268 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/pthread.h @@ -0,0 +1,113 @@ +/* rtems/posix/pthread.h + * + * This include file contains all the private support information for + * POSIX threads. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_THREADS_h +#define __RTEMS_POSIX_THREADS_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Data Structure used to manage a POSIX thread + */ + +typedef Thread_Control POSIX_Threads_Control; + +/* + * The following defines the information control block used to manage + * this class of objects. + */ + +EXTERN Objects_Information _POSIX_Threads_Information; + +/* + * _POSIX_Threads_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _POSIX_Threads_Manager_initialization( + unsigned32 maximum_pthreads +); + +/* + * _POSIX_Threads_Allocate + * + * DESCRIPTION: + * + * This function allocates a pthread control block from + * the inactive chain of free pthread control blocks. + */ + +STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Allocate( void ); + +/* + * _POSIX_Threads_Free + * + * DESCRIPTION: + * + * This routine frees a pthread control block to the + * inactive chain of free pthread control blocks. + */ + +STATIC INLINE void _POSIX_Threads_Free ( + POSIX_Threads_Control *the_pthread +); + +/* + * _POSIX_Threads_Get + * + * DESCRIPTION: + * + * This function maps pthread IDs to pthread control blocks. + * If ID corresponds to a local pthread, then it returns + * the_pthread control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. if the pthread ID is global and + * resides on a remote node, then location is set to OBJECTS_REMOTE, + * and the_pthread is undefined. Otherwise, location is set + * to OBJECTS_ERROR and the_pthread is undefined. + */ + +STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Get ( + Objects_Id *id, + Objects_Locations *location +); + +/* + * _POSIX_Threads_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_pthread is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _POSIX_Threads_Is_null ( + POSIX_Threads_Control *the_pthread +); + +#include <rtems/posix/pthread.inl> +#include <rtems/posix/pthreadmp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ + diff --git a/cpukit/posix/include/rtems/posix/pthreadmp.h b/cpukit/posix/include/rtems/posix/pthreadmp.h new file mode 100644 index 0000000000..e15534136b --- /dev/null +++ b/cpukit/posix/include/rtems/posix/pthreadmp.h @@ -0,0 +1,161 @@ +/* pthreadmp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the POSIX Threads 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$ + */ + +#ifndef __RTEMS_POSIX_THREADS_MP_h +#define __RTEMS_POSIX_THREADS_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the list of + * remote pthread operations. + */ + +typedef enum { + POSIX_THREADS_MP_ANNOUNCE_CREATE = 0, + POSIX_THREADS_MP_ANNOUNCE_DELETE = 1, + POSIX_THREADS_MP_EXTRACT_PROXY = 2, + POSIX_THREADS_MP_OBTAIN_REQUEST = 3, + POSIX_THREADS_MP_OBTAIN_RESPONSE = 4, + POSIX_THREADS_MP_RELEASE_REQUEST = 5, + POSIX_THREADS_MP_RELEASE_RESPONSE = 6 +} POSIX_Threads_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote pthread operations. + */ + +typedef struct { + MP_packet_Prefix Prefix; + POSIX_Threads_MP_Remote_operations operation; + Objects_Name name; + boolean wait; + Objects_Id proxy_id; +} POSIX_Threads_MP_Packet; + +/* + * _POSIX_Threads_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _POSIX_Threads_MP_Send_process_packet ( + POSIX_Threads_MP_Remote_operations operation, + Objects_Id pthread_id, + Objects_Name name, + Objects_Id proxy_id +); + +/* + * _POSIX_Threads_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +int _POSIX_Threads_MP_Send_request_packet ( + POSIX_Threads_MP_Remote_operations operation, + Objects_Id pthread_id, + boolean wait, + Watchdog_Interval timeout +); + +/* + * _POSIX_Threads_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _POSIX_Threads_MP_Send_response_packet ( + POSIX_Threads_MP_Remote_operations operation, + Objects_Id pthread_id, + Thread_Control *the_thread +); + +/* + * + * _POSIX_Threads_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _POSIX_Threads_MP_Process_packet ( + MP_packet_Prefix *the_packet_prefix +); + +/* + * _POSIX_Threads_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + */ + +void _POSIX_Threads_MP_Send_object_was_deleted ( + Thread_Control *the_proxy +); + +/* + * _POSIX_Threads_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + */ + +void _POSIX_Threads_MP_Send_extract_proxy ( + Thread_Control *the_thread +); + +/* + * _POSIX_Threads_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a pthread mp packet. + */ + +POSIX_Threads_MP_Packet *_POSIX_Threads_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/posix/include/rtems/posix/semaphore.h b/cpukit/posix/include/rtems/posix/semaphore.h new file mode 100644 index 0000000000..a538663989 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/semaphore.h @@ -0,0 +1,135 @@ +/* rtems/posix/semaphore.h + * + * This include file contains all the private support information for + * POSIX Semaphores. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_SEMAPHORE_h +#define __RTEMS_POSIX_SEMAPHORE_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/coresem.h> + +/* + * Data Structure used to manage a POSIX semaphore + */ + +typedef struct { + Objects_Control Object; + int process_shared; + boolean named; + boolean linked; + unsigned32 open_count; + CORE_semaphore_Control Semaphore; +} POSIX_Semaphore_Control; + +/* + * The following defines the information control block used to manage + * this class of objects. + */ + +EXTERN Objects_Information _POSIX_Semaphore_Information; + +/* + * _POSIX_Semaphore_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _POSIX_Semaphore_Manager_initialization( + unsigned32 maximum_semaphorees +); + +/* + * _POSIX_Semaphore_Allocate + * + * DESCRIPTION: + * + * This function allocates a semaphore control block from + * the inactive chain of free semaphore control blocks. + */ + +STATIC INLINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void ); + +/* + * _POSIX_Semaphore_Free + * + * DESCRIPTION: + * + * This routine frees a semaphore control block to the + * inactive chain of free semaphore control blocks. + */ + +STATIC INLINE void _POSIX_Semaphore_Free ( + POSIX_Semaphore_Control *the_semaphore +); + +/* + * _POSIX_Semaphore_Get + * + * DESCRIPTION: + * + * This function maps semaphore IDs to semaphore control blocks. + * If ID corresponds to a local semaphore, then it returns + * the_semaphore control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. if the semaphore ID is global and + * resides on a remote node, then location is set to OBJECTS_REMOTE, + * and the_semaphore is undefined. Otherwise, location is set + * to OBJECTS_ERROR and the_semaphore is undefined. + */ + +STATIC INLINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get ( + Objects_Id *id, + Objects_Locations *location +); + +/* + * _POSIX_Semaphore_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_semaphore is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _POSIX_Semaphore_Is_null ( + POSIX_Semaphore_Control *the_semaphore +); + +/* + * _POSIX_Semaphore_Name_to_id + * + * DESCRIPTION: + * + * XXX + */ + +int _POSIX_Semaphore_Name_to_id( + const char *name, + Objects_Id *id +); + +#include <rtems/posix/semaphore.inl> +#include <rtems/posix/semaphoremp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ + diff --git a/cpukit/posix/include/rtems/posix/semaphoremp.h b/cpukit/posix/include/rtems/posix/semaphoremp.h new file mode 100644 index 0000000000..102b3d08a6 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/semaphoremp.h @@ -0,0 +1,161 @@ +/* semaphoremp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the POSIX Semaphore 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$ + */ + +#ifndef __RTEMS_POSIX_SEMAPHORE_MP_h +#define __RTEMS_POSIX_SEMAPHORE_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the list of + * remote semaphore operations. + */ + +typedef enum { + POSIX_SEMAPHORE_MP_ANNOUNCE_CREATE = 0, + POSIX_SEMAPHORE_MP_ANNOUNCE_DELETE = 1, + POSIX_SEMAPHORE_MP_EXTRACT_PROXY = 2, + POSIX_SEMAPHORE_MP_OBTAIN_REQUEST = 3, + POSIX_SEMAPHORE_MP_OBTAIN_RESPONSE = 4, + POSIX_SEMAPHORE_MP_RELEASE_REQUEST = 5, + POSIX_SEMAPHORE_MP_RELEASE_RESPONSE = 6, +} POSIX_Semaphore_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote semaphore operations. + */ + +typedef struct { + MP_packet_Prefix Prefix; + POSIX_Semaphore_MP_Remote_operations operation; + Objects_Name name; + boolean wait; /* XXX options */ + Objects_Id proxy_id; +} POSIX_Semaphore_MP_Packet; + +/* + * _POSIX_Semaphore_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _POSIX_Semaphore_MP_Send_process_packet ( + POSIX_Semaphore_MP_Remote_operations operation, + Objects_Id semaphore_id, + Objects_Name name, + Objects_Id proxy_id +); + +/* + * _POSIX_Semaphore_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +int _POSIX_Semaphore_MP_Send_request_packet ( + POSIX_Semaphore_MP_Remote_operations operation, + Objects_Id semaphore_id, + boolean wait, /* XXX options */ + Watchdog_Interval timeout +); + +/* + * _POSIX_Semaphore_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _POSIX_Semaphore_MP_Send_response_packet ( + POSIX_Semaphore_MP_Remote_operations operation, + Objects_Id semaphore_id, + Thread_Control *the_thread +); + +/* + * + * _POSIX_Semaphore_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _POSIX_Semaphore_MP_Process_packet ( + MP_packet_Prefix *the_packet_prefix +); + +/* + * _POSIX_Semaphore_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + */ + +void _POSIX_Semaphore_MP_Send_object_was_deleted ( + Thread_Control *the_proxy +); + +/* + * _POSIX_Semaphore_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + */ + +void _POSIX_Semaphore_MP_Send_extract_proxy ( + Thread_Control *the_thread +); + +/* + * _POSIX_Semaphore_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a semaphore mp packet. + */ + +POSIX_Semaphore_MP_Packet *_POSIX_Semaphore_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/posix/include/rtems/posix/threadsup.h b/cpukit/posix/include/rtems/posix/threadsup.h new file mode 100644 index 0000000000..26643445b4 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/threadsup.h @@ -0,0 +1,30 @@ +/* threadsup.h + * + * $Id$ + */ + +#ifndef __RTEMS_POSIX_THREAD_SUPPORT_h +#define __RTEMS_POSIX_THREAD_SUPPORT_h + +#include <rtems/score/coresem.h> + +typedef struct { + /* + * POSIX Interrupts + */ + unsigned32 interrupts_installed; + CORE_semaphore_Control Interrupt_Semaphore; + + /* + * POSIX Cancelability + */ + int cancelability_state; + int cancelability_type; + int cancelation_requested; + Chain_Control Cancellation_Handlers; + +} POSIX_API_Thread_Support_Control; + +#endif +/* end of include file */ + diff --git a/cpukit/posix/include/rtems/posix/time.h b/cpukit/posix/include/rtems/posix/time.h new file mode 100644 index 0000000000..0b11f2fa54 --- /dev/null +++ b/cpukit/posix/include/rtems/posix/time.h @@ -0,0 +1,14 @@ +/* + * + * + * $Id$ + */ + +#ifndef __RTEMS_POSIX_TIME_h +#define __RTEMS_POSIX_TIME_h + +Watchdog_Interval _POSIX_Time_Spec_to_interval( + const struct timespec *time +); + +#endif diff --git a/cpukit/posix/include/sched.h b/cpukit/posix/include/sched.h new file mode 100644 index 0000000000..1ea27a1634 --- /dev/null +++ b/cpukit/posix/include/sched.h @@ -0,0 +1,88 @@ +/* sched.h + * + * $Id$ + */ + + +#ifndef __POSIX_SCHEDULING_h +#define __POSIX_SCHEDULING_h + +#include <rtems/posix/features.h> + +#if defined(_POSIX_PRIORITY_SCHEDULING) + +#include <sys/types.h> +#include <time.h> +#include <sys/sched.h> +#include <pthread.h> + +/* + * 13.3.1 Set Scheduling Parameters, P1003.1b-1993, p. 252 + * + */ + +int sched_setparam( + pid_t pid, + const struct sched_param *param +); + +/* + * 13.3.2 Set Scheduling Parameters, P1003.1b-1993, p. 253 + */ + +int sched_getparam( + pid_t pid, + const struct sched_param *param +); + +/* + * 13.3.3 Set Scheduling Policy and Scheduling Parameters, + * P1003.1b-1993, p. 254 + */ + +int sched_setscheduler( + pid_t pid, + int policy, + const struct sched_param *param +); + +/* + * 13.3.4 Get Scheduling Policy, P1003.1b-1993, p. 256 + */ + +int sched_getscheduler( + pid_t pid +); + +/* + * 13.3.6 Get Scheduling Parameter Limits, P1003.1b-1993, p. 258 + */ + +int sched_get_priority_max( + int policy +); + +int sched_get_priority_min( + int policy +); + +int sched_rr_get_interval( + pid_t pid, + struct timespec *interval +); + +#endif /* _POSIX_PRIORITY_SCHEDULING */ + +#if defined(_POSIX_THREADS) || defined(_POSIX_PRIORITY_SCHEDULING) + +/* + * 13.3.5 Yield Processor, P1003.1b-1993, p. 257 + */ + +int sched_yield( void ); + +#endif /* _POSIX_THREADS or _POSIX_PRIORITY_SCHEDULING */ + +#endif +/* end of include file */ + diff --git a/cpukit/posix/include/semaphore.h b/cpukit/posix/include/semaphore.h new file mode 100644 index 0000000000..0388f91ad9 --- /dev/null +++ b/cpukit/posix/include/semaphore.h @@ -0,0 +1,108 @@ +/* semaphore.h + * + * $Id$ + */ + +#ifndef __POSIX_SEMAPHORE_h +#define __POSIX_SEMAPHORE_h + +#include <rtems/posix/features.h> + +#if defined(_POSIX_SEMAPHORES) + +#include <sys/time.h> + +/* + * 11.1 Semaphore Characteristics, P1003.1b-1993, p.219 + */ + +typedef int sem_t; + +/* + * 11.2.1 Initialize an Unnamed Semaphore, P1003.1b-1993, p.219 + */ + +int sem_init( + sem_t *sem, + int pshared, + unsigned int value +); + +/* + * 11.2.2 Destroy an Unnamed Semaphore, P1003.1b-1993, p.220 + */ + +int sem_destroy( + sem_t *sem +); + +/* + * 11.2.3 Initialize/Open a Named Semaphore, P1003.1b-1993, p.221 + * + * NOTE: Follows open() calling conventions. + */ + +sem_t *sem_open( + const char *name, + int oflag, + ... +); + +/* + * 11.2.4 Close a Named Semaphore, P1003.1b-1993, p.224 + */ + +int sem_close( + sem_t *sem +); + +/* + * 11.2.5 Remove a Named Semaphore, P1003.1b-1993, p.225 + */ + +int sem_unlink( + const char *name +); + +/* + * 11.2.6 Lock a Semaphore, P1003.1b-1993, p.226 + * + * NOTE: P1003.4b/D8 adds sem_timedwait(), p. 27 + */ + +int sem_wait( + sem_t *sem +); + +int sem_trywait( + sem_t *sem +); + +#if defined(_POSIX_TIMEOUTS) +int sem_timedwait( + sem_t *sem, + const struct timespec *timeout +); +#endif + +/* + * 11.2.7 Unlock a Semaphore, P1003.1b-1993, p.227 + */ + +int sem_post( + sem_t *sem +); + +/* + * 11.2.8 Get the Value of a Semaphore, P1003.1b-1993, p.229 + */ + +int sem_getvalue( + sem_t *sem, + int *sval +); + +#endif /* _POSIX_SEMAPHORES */ + +#endif +/* end of include file */ diff --git a/cpukit/posix/inline/rtems/posix/cond.inl b/cpukit/posix/inline/rtems/posix/cond.inl new file mode 100644 index 0000000000..f6d55af7c6 --- /dev/null +++ b/cpukit/posix/inline/rtems/posix/cond.inl @@ -0,0 +1,76 @@ +/* rtems/posix/cond.inl + * + * This include file contains the static inline implementation of the private + * inlined routines for POSIX condition variables. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_CONDITION_VARIABLES_inl +#define __RTEMS_POSIX_CONDITION_VARIABLES_inl + +/*PAGE + * + * _POSIX_Condition_variables_Allocate + */ + +STATIC INLINE POSIX_Condition_variables_Control + *_POSIX_Condition_variables_Allocate( void ) +{ + return (POSIX_Condition_variables_Control *) + _Objects_Allocate( &_POSIX_Condition_variables_Information ); +} + +/*PAGE + * + * _POSIX_Condition_variables_Free + */ + +STATIC INLINE void _POSIX_Condition_variables_Free ( + POSIX_Condition_variables_Control *the_condition_variable +) +{ + _Objects_Free( + &_POSIX_Condition_variables_Information, + &the_condition_variable->Object + ); +} + +/*PAGE + * + * _POSIX_Condition_variables_Get + */ + +STATIC INLINE POSIX_Condition_variables_Control *_POSIX_Condition_variables_Get ( + Objects_Id *id, + Objects_Locations *location +) +{ +/* XXX really should validate pointer */ + return (POSIX_Condition_variables_Control *) + _Objects_Get( &_POSIX_Condition_variables_Information, *id, location ); +} + +/*PAGE + * + * _POSIX_Condition_variables_Is_null + */ + +STATIC INLINE boolean _POSIX_Condition_variables_Is_null ( + POSIX_Condition_variables_Control *the_condition_variable +) +{ + return !the_condition_variable; +} + +#endif +/* end of include file */ + diff --git a/cpukit/posix/inline/rtems/posix/intr.inl b/cpukit/posix/inline/rtems/posix/intr.inl new file mode 100644 index 0000000000..56b1c9dd0b --- /dev/null +++ b/cpukit/posix/inline/rtems/posix/intr.inl @@ -0,0 +1,72 @@ +/* rtems/posix/intr.inl + * + * This include file contains the static inline implementation of the private + * inlined routines for POSIX Interrupt 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$ + */ + +#ifndef __RTEMS_POSIX_INTERRUPT_inl +#define __RTEMS_POSIX_INTERRUPT_inl + +/*PAGE + * + * _POSIX_Interrupt_Allocate + */ + +STATIC INLINE POSIX_Interrupt_Handler_control * + _POSIX_Interrupt_Allocate( void ) +{ + return (POSIX_Interrupt_Handler_control *) + _Objects_Allocate( &_POSIX_Interrupt_Handlers_Information ); +} + +/*PAGE + * + * _POSIX_Interrupt_Free + */ + +STATIC INLINE void _POSIX_Interrupt_Free ( + POSIX_Interrupt_Handler_control *the_intr +) +{ + _Objects_Free( &_POSIX_Interrupt_Handlers_Information, &the_intr->Object ); +} + +/*PAGE + * + * _POSIX_Interrupt_Get + */ + +STATIC INLINE POSIX_Interrupt_Control *_POSIX_Interrupt_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (POSIX_Interrupt_Control *) + _Objects_Get( &_POSIX_Interrupt_Handlers_Information, id, location ); +} + +/*PAGE + * + * _POSIX_Interrupt_Is_null + */ + +STATIC INLINE boolean _POSIX_Interrupt_Is_null ( + POSIX_Interrupt_Handler_control *the_intr +) +{ + return !the_intr; +} + +#endif +/* end of include file */ + diff --git a/cpukit/posix/inline/rtems/posix/key.inl b/cpukit/posix/inline/rtems/posix/key.inl new file mode 100644 index 0000000000..3b9c1e9e3c --- /dev/null +++ b/cpukit/posix/inline/rtems/posix/key.inl @@ -0,0 +1,70 @@ +/* rtems/posix/key.inl + * + * This include file contains the static inline implementation of the private + * inlined routines for POSIX key's. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_KEY_inl +#define __RTEMS_POSIX_KEY_inl + +/*PAGE + * + * _POSIX_Keys_Allocate + */ + +STATIC INLINE POSIX_Keys_Control *_POSIX_Keys_Allocate( void ) +{ + return (POSIX_Keys_Control *) _Objects_Allocate( &_POSIX_Keys_Information ); +} + +/*PAGE + * + * _POSIX_Keys_Free + */ + +STATIC INLINE void _POSIX_Keys_Free ( + POSIX_Keys_Control *the_key +) +{ + _Objects_Free( &_POSIX_Keys_Information, &the_key->Object ); +} + +/*PAGE + * + * _POSIX_Keys_Get + */ + +STATIC INLINE POSIX_Keys_Control *_POSIX_Keys_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (POSIX_Keys_Control *) + _Objects_Get( &_POSIX_Keys_Information, id, location ); +} + +/*PAGE + * + * _POSIX_Keys_Is_null + */ + +STATIC INLINE boolean _POSIX_Keys_Is_null ( + POSIX_Keys_Control *the_key +) +{ + return !the_key; +} + +#endif +/* end of include file */ + diff --git a/cpukit/posix/inline/rtems/posix/mqueue.inl b/cpukit/posix/inline/rtems/posix/mqueue.inl new file mode 100644 index 0000000000..140a37a6a6 --- /dev/null +++ b/cpukit/posix/inline/rtems/posix/mqueue.inl @@ -0,0 +1,83 @@ +/* rtems/posix/mqueue.inl + * + * This include file contains the static inline implementation of the private + * inlined routines for POSIX Message Queue. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_MESSAGE_QUEUE_inl +#define __RTEMS_POSIX_MESSAGE_QUEUE_inl + +/*PAGE + * + * _POSIX_Message_queue_Allocate + */ + +STATIC INLINE POSIX_Message_queue_Control *_POSIX_Message_queue_Allocate( void ) +{ + return (POSIX_Message_queue_Control *) + _Objects_Allocate( &_POSIX_Message_queue_Information ); +} + +/*PAGE + * + * _POSIX_Message_queue_Free + */ + +STATIC INLINE void _POSIX_Message_queue_Free ( + POSIX_Message_queue_Control *the_mq +) +{ + _Objects_Free( &_POSIX_Message_queue_Information, &the_mq->Object ); +} + +/*PAGE + * + * _POSIX_Message_queue_Get + */ + +STATIC INLINE POSIX_Message_queue_Control *_POSIX_Message_queue_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (POSIX_Message_queue_Control *) + _Objects_Get( &_POSIX_Message_queue_Information, id, location ); +} + +/*PAGE + * + * _POSIX_Message_queue_Is_null + */ + +STATIC INLINE boolean _POSIX_Message_queue_Is_null ( + POSIX_Message_queue_Control *the_mq +) +{ + return !the_mq; +} + +/*PAGE + * + * _POSIX_Message_queue_Priority_to_core + */ + +STATIC INLINE Priority_Control _POSIX_Message_queue_Priority_to_core( + unsigned int priority +) +{ + return priority; +} + +#endif +/* end of include file */ + diff --git a/cpukit/posix/inline/rtems/posix/mutex.inl b/cpukit/posix/inline/rtems/posix/mutex.inl new file mode 100644 index 0000000000..f663eb3c7d --- /dev/null +++ b/cpukit/posix/inline/rtems/posix/mutex.inl @@ -0,0 +1,88 @@ +/* rtems/posix/mutex.inl + * + * This include file contains the static inline implementation of the private + * inlined routines for POSIX mutex's. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_MUTEX_inl +#define __RTEMS_POSIX_MUTEX_inl + +/*PAGE + * + * _POSIX_Mutex_Allocate + */ + +STATIC INLINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void ) +{ + return (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information ); +} + +/*PAGE + * + * _POSIX_Mutex_Free + */ + +STATIC INLINE void _POSIX_Mutex_Free ( + POSIX_Mutex_Control *the_mutex +) +{ + _Objects_Free( &_POSIX_Mutex_Information, &the_mutex->Object ); +} + +/*PAGE + * + * _POSIX_Mutex_Get + */ + +STATIC INLINE POSIX_Mutex_Control *_POSIX_Mutex_Get ( + Objects_Id *id, + Objects_Locations *location +) +{ + int status; + + if ( *id == PTHREAD_MUTEX_INITIALIZER ) { + /* + * Do an "auto-create" here. + */ + + status = pthread_mutex_init( id, 0 ); + if ( status ) { + *location = OBJECTS_ERROR; + return (POSIX_Mutex_Control *) 0; + } + } + + /* + * Now call Objects_Get() + */ + + return (POSIX_Mutex_Control *) + _Objects_Get( &_POSIX_Mutex_Information, *id, location ); +} + +/*PAGE + * + * _POSIX_Mutex_Is_null + */ + +STATIC INLINE boolean _POSIX_Mutex_Is_null ( + POSIX_Mutex_Control *the_mutex +) +{ + return !the_mutex; +} + +#endif +/* end of include file */ + diff --git a/cpukit/posix/inline/rtems/posix/priority.inl b/cpukit/posix/inline/rtems/posix/priority.inl new file mode 100644 index 0000000000..90dfaead02 --- /dev/null +++ b/cpukit/posix/inline/rtems/posix/priority.inl @@ -0,0 +1,29 @@ +/* + * $Id$ + */ + +#ifndef __RTEMS_POSIX_PRIORITY_inl +#define __RTEMS_POSIX_PRIORITY_inl + +STATIC INLINE boolean _POSIX_Priority_Is_valid( + int priority +) +{ + return (boolean) priority >= 1 && priority <= 255; +} + +STATIC INLINE Priority_Control _POSIX_Priority_To_core( + int priority +) +{ + return (Priority_Control) 256 - priority; +} + +STATIC INLINE int _POSIX_Priority_From_core( + Priority_Control priority +) +{ + return 256 - priority; +} + +#endif diff --git a/cpukit/posix/inline/rtems/posix/pthread.inl b/cpukit/posix/inline/rtems/posix/pthread.inl new file mode 100644 index 0000000000..256372d326 --- /dev/null +++ b/cpukit/posix/inline/rtems/posix/pthread.inl @@ -0,0 +1,71 @@ +/* rtems/posix/pthread.inl + * + * This include file contains the static inline implementation of the private + * inlined routines for POSIX threads. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_THREADS_inl +#define __RTEMS_POSIX_THREADS_inl + +/*PAGE + * + * _POSIX_Threads_Allocate + */ + +STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Allocate( void ) +{ + return (POSIX_Threads_Control *) + _Objects_Allocate( &_POSIX_Threads_Information ); +} + +/*PAGE + * + * _POSIX_Threads_Free + */ + +STATIC INLINE void _POSIX_Threads_Free ( + POSIX_Threads_Control *the_pthread +) +{ + _Objects_Free( &_POSIX_Threads_Information, &the_pthread->Object ); +} + +/*PAGE + * + * _POSIX_Threads_Get + */ + +STATIC INLINE POSIX_Threads_Control *_POSIX_Threads_Get ( + Objects_Id *id, + Objects_Locations *location +) +{ + return (POSIX_Threads_Control *) + _Objects_Get( &_POSIX_Threads_Information, *id, location ); +} + +/*PAGE + * + * _POSIX_Threads_Is_null + */ + +STATIC INLINE boolean _POSIX_Threads_Is_null ( + POSIX_Threads_Control *the_pthread +) +{ + return !the_pthread; +} + +#endif +/* end of include file */ + diff --git a/cpukit/posix/inline/rtems/posix/semaphore.inl b/cpukit/posix/inline/rtems/posix/semaphore.inl new file mode 100644 index 0000000000..33af0bd000 --- /dev/null +++ b/cpukit/posix/inline/rtems/posix/semaphore.inl @@ -0,0 +1,71 @@ +/* rtems/posix/semaphore.inl + * + * This include file contains the static inline implementation of the private + * inlined routines for POSIX Semaphores. + * + * 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$ + */ + +#ifndef __RTEMS_POSIX_SEMAPHORE_inl +#define __RTEMS_POSIX_SEMAPHORE_inl + +/*PAGE + * + * _POSIX_Semaphore_Allocate + */ + +STATIC INLINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void ) +{ + return (POSIX_Semaphore_Control *) + _Objects_Allocate( &_POSIX_Semaphore_Information ); +} + +/*PAGE + * + * _POSIX_Semaphore_Free + */ + +STATIC INLINE void _POSIX_Semaphore_Free ( + POSIX_Semaphore_Control *the_semaphore +) +{ + _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object ); +} + +/*PAGE + * + * _POSIX_Semaphore_Get + */ + +STATIC INLINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get ( + Objects_Id *id, + Objects_Locations *location +) +{ + return (POSIX_Semaphore_Control *) + _Objects_Get( &_POSIX_Semaphore_Information, *id, location ); +} + +/*PAGE + * + * _POSIX_Semaphore_Is_null + */ + +STATIC INLINE boolean _POSIX_Semaphore_Is_null ( + POSIX_Semaphore_Control *the_semaphore +) +{ + return !the_semaphore; +} + +#endif +/* end of include file */ + diff --git a/cpukit/posix/src/aio.c b/cpukit/posix/src/aio.c new file mode 100644 index 0000000000..491c2772cf --- /dev/null +++ b/cpukit/posix/src/aio.c @@ -0,0 +1,113 @@ +/* aio.c + * + * $Id$ + */ + +#include <aio.h> + +#ifdef NOT_IMPLEMENTED_YET + +/*PAGE + * + * 6.7.2 Asynchronous Read, P1003.1b-1993, p. 154 + */ + +int aio_read( + struct aiocb *aiocbp +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 6.7.3 Asynchronous Write, P1003.1b-1993, p. 155 + */ + +int aio_write( + struct aiocb *aiocbp +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 6.7.4 List Directed I/O, P1003.1b-1993, p. 158 + */ + +int lio_listio( + int mode, + struct aiocb * const list[], + int nent, + struct sigevent *sig +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 6.7.5 Retrieve Error of Asynchronous I/O Operation, P1003.1b-1993, p. 161 + */ + +int aio_error( + const struct aiocb *aiocbp +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 6.7.6 Retrieve Return Status of Asynchronous I/O Operation, + * P1003.1b-1993, p. 162 + */ + +int aio_return( + const struct aiocb *aiocbp +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 6.7.7 Cancel Asynchronous I/O Operation, P1003.1b-1993, p. 163 + */ + +int aio_cancel( + int filedes, + struct aiocb *aiocbp +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 6.7.7 Wait for Asynchronous I/O Request, P1003.1b-1993, p. 164 + */ + +int aio_suspend( + struct aiocb * const list[], + int nent, + const struct timespec *timeout +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 6.7.9 Asynchronous File Synchronization, P1003.1b-1993, p. 166 + */ + +int aio_fsync( + int op, + struct aiocb *aiocbp +) +{ + return POSIX_NOT_IMPLEMENTED(); +} +#endif diff --git a/cpukit/posix/src/cancel.c b/cpukit/posix/src/cancel.c new file mode 100644 index 0000000000..2ad972c626 --- /dev/null +++ b/cpukit/posix/src/cancel.c @@ -0,0 +1,227 @@ +/* cancel.c + * + * $Id$ + */ + +#include <pthread.h> +#include <errno.h> +#include <rtems/score/chain.h> +#include <rtems/score/isr.h> +#include <rtems/score/thread.h> +#include <rtems/score/wkspace.h> +#include <rtems/posix/cancel.h> +#include <rtems/posix/pthread.h> +#include <rtems/posix/threadsup.h> + +/*PAGE + * + * POSIX_Thread_cancel_run + * + */ + +void POSIX_Thread_cancel_run( + Thread_Control *the_thread +) +{ + int old_cancel_state; + POSIX_Cancel_Handler_control *handler; + Chain_Control *handler_stack; + POSIX_API_Thread_Support_Control *thread_support; + ISR_Level level; + + thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ]; + + handler_stack = &thread_support->Cancellation_Handlers; + + old_cancel_state = thread_support->cancelability_state; + + thread_support->cancelability_state = PTHREAD_CANCEL_DISABLE; + + while ( !_Chain_Is_empty( handler_stack ) ) { + _ISR_Disable( level ); + handler = (POSIX_Cancel_Handler_control *) _Chain_Tail( handler_stack ); + _Chain_Extract_unprotected( &handler->Node ); + _ISR_Enable( level ); + + (*handler->routine)( handler->arg ); + + _Workspace_Free( handler ); + } + + thread_support->cancelation_requested = 0; + + thread_support->cancelability_state = old_cancel_state; +} + +/*PAGE + * + * 18.2.1 Canceling Execution of a Thread, P1003.1c/Draft 10, p. 181 + */ + +int pthread_cancel( + pthread_t thread +) +{ + Thread_Control *the_thread; + POSIX_API_Thread_Support_Control *thread_support; + Objects_Locations location; + + the_thread = _POSIX_Threads_Get( &thread, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + return POSIX_MP_NOT_IMPLEMENTED(); + case OBJECTS_LOCAL: + thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ]; + + thread_support->cancelation_requested = 1; + + _Thread_Enable_dispatch(); + return 0; + } + + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183 + */ + +int pthread_setcancelstate( + int state, + int *oldstate +) +{ + POSIX_API_Thread_Support_Control *thread_support; + + if ( !oldstate ) + return EINVAL; + + if ( state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE ) + return EINVAL; + + thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + + *oldstate = thread_support->cancelability_state; + thread_support->cancelability_state = state; + + if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE && + thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS && + thread_support->cancelation_requested ) + POSIX_Thread_cancel_run( _Thread_Executing ); + + return 0; +} + +/*PAGE + * + * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183 + */ + +int pthread_setcanceltype( + int type, + int *oldtype +) +{ + POSIX_API_Thread_Support_Control *thread_support; + + if ( !oldtype ) + return EINVAL; + + if ( type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS ) + return EINVAL; + + thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + + *oldtype = thread_support->cancelability_type; + thread_support->cancelability_type = type; + + if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE && + thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS && + thread_support->cancelation_requested ) + POSIX_Thread_cancel_run( _Thread_Executing ); + + return 0; +} + +/*PAGE + * + * 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183 + */ + +void pthread_testcancel( void ) +{ + POSIX_API_Thread_Support_Control *thread_support; + + thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + + if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE && + thread_support->cancelation_requested ) + POSIX_Thread_cancel_run( _Thread_Executing ); +} + +/*PAGE + * + * 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184 + */ + +void pthread_cleanup_push( + void (*routine)( void * ), + void *arg +) +{ + POSIX_Cancel_Handler_control *handler; + Chain_Control *handler_stack; + POSIX_API_Thread_Support_Control *thread_support; + + if ( !routine ) + return; /* XXX what to do really? */ + + handler = _Workspace_Allocate( sizeof( POSIX_Cancel_Handler_control ) ); + + if ( !handler ) + return; /* XXX what to do really? */ + + thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + + handler_stack = &thread_support->Cancellation_Handlers; + + handler->routine = routine; + handler->arg = arg; + + _Chain_Append( handler_stack, &handler->Node ); +} + +/*PAGE + * + * 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184 + */ + +void pthread_cleanup_pop( + int execute +) +{ + POSIX_Cancel_Handler_control *handler; + Chain_Control *handler_stack; + POSIX_API_Thread_Support_Control *thread_support; + ISR_Level level; + + thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + + handler_stack = &thread_support->Cancellation_Handlers; + + if ( _Chain_Is_empty( handler_stack ) ) + return; + + _ISR_Disable( level ); + handler = (POSIX_Cancel_Handler_control *) _Chain_Tail( handler_stack ); + _Chain_Extract_unprotected( &handler->Node ); + _ISR_Enable( level ); + + if ( execute ) + (*handler->routine)( handler->arg ); + + _Workspace_Free( handler ); +} diff --git a/cpukit/posix/src/cond.c b/cpukit/posix/src/cond.c new file mode 100644 index 0000000000..e20cfe5359 --- /dev/null +++ b/cpukit/posix/src/cond.c @@ -0,0 +1,400 @@ +/* cond.c + * + * $Id$ + */ + +#include <pthread.h> +#include <errno.h> + +#include <rtems/score/object.h> +#include <rtems/score/states.h> +#include <rtems/score/watchdog.h> +#include <rtems/posix/cond.h> +#include <rtems/posix/time.h> + +/*PAGE + * + * The default condition variable attributes structure. + */ + +const pthread_condattr_t _POSIX_Condition_variables_Default_attributes = { + TRUE, /* is_initialized */ + PTHREAD_PROCESS_PRIVATE /* process_shared */ +}; + +/*PAGE + * + * _POSIX_Condition_variables_Manager_initialization + * + * This routine initializes all condition variable manager related data + * structures. + * + * Input parameters: + * maximum_condition_variables - maximum configured condition_variables + * + * Output parameters: NONE + */ + +void _POSIX_Condition_variables_Manager_initialization( + unsigned32 maximum_condition_variables +) +{ + _Objects_Initialize_information( + &_POSIX_Condition_variables_Information, + OBJECTS_POSIX_CONDITION_VARIABLES, + TRUE, + maximum_condition_variables, + sizeof( POSIX_Condition_variables_Control ), + FALSE, + 0, + FALSE + ); +} + +/*PAGE + * + * 11.4.1 Condition Variable Initialization Attributes, + * P1003.1c/Draft 10, p. 96 + */ + +int pthread_condattr_init( + pthread_condattr_t *attr +) +{ + if ( !attr ) + return EINVAL; + + *attr = _POSIX_Condition_variables_Default_attributes; + return 0; +} + +/*PAGE + * + * 11.4.1 Condition Variable Initialization Attributes, + * P1003.1c/Draft 10, p. 96 + */ + +int pthread_condattr_destroy( + pthread_condattr_t *attr +) +{ + if ( !attr || attr->is_initialized == FALSE ) + return EINVAL; + + attr->is_initialized = FALSE; + return 0; +} + +/*PAGE + * + * 11.4.1 Condition Variable Initialization Attributes, + * P1003.1c/Draft 10, p. 96 + */ + +int pthread_condattr_getpshared( + const pthread_condattr_t *attr, + int *pshared +) +{ + if ( !attr ) + return EINVAL; + + *pshared = attr->process_shared; + return 0; +} + +/*PAGE + * + * 11.4.1 Condition Variable Initialization Attributes, + * P1003.1c/Draft 10, p. 96 + */ + +int pthread_condattr_setpshared( + pthread_condattr_t *attr, + int pshared +) +{ + if ( !attr ) + return EINVAL; + + attr->process_shared = pshared; + return 0; +} + +/*PAGE + * + * 11.4.2 Initializing and Destroying a Condition Variable, + * P1003.1c/Draft 10, p. 87 + */ + +int pthread_cond_init( + pthread_cond_t *cond, + const pthread_condattr_t *attr +) +{ + POSIX_Condition_variables_Control *the_cond; + const pthread_condattr_t *the_attr; + + if ( attr ) the_attr = attr; + else the_attr = &_POSIX_Condition_variables_Default_attributes; + + /* + * XXX: Be careful about attributes when global!!! + */ + + if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED ) + return POSIX_MP_NOT_IMPLEMENTED(); + + if ( !the_attr->is_initialized ) + return EINVAL; + + _Thread_Disable_dispatch(); + + the_cond = _POSIX_Condition_variables_Allocate(); + + if ( !the_cond ) { + _Thread_Enable_dispatch(); + return ENOMEM; + } + + if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED && + !( _Objects_MP_Allocate_and_open( &_POSIX_Condition_variables_Information, + 0, the_cond->Object.id, FALSE ) ) ) { + _POSIX_Condition_variables_Free( the_cond ); + _Thread_Enable_dispatch(); + return EAGAIN; + } + + the_cond->process_shared = the_attr->process_shared; + + the_cond->Mutex = 0; + +/* XXX some more initialization might need to go here */ + _Thread_queue_Initialize( + &the_cond->Wait_queue, + OBJECTS_POSIX_CONDITION_VARIABLES, + THREAD_QUEUE_DISCIPLINE_FIFO, + STATES_WAITING_FOR_CONDITION_VARIABLE, + _POSIX_Condition_variables_MP_Send_extract_proxy, + ETIMEDOUT + ); + + _Objects_Open( + &_POSIX_Condition_variables_Information, + &the_cond->Object, + 0 + ); + + *cond = the_cond->Object.id; + + if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED ) + _POSIX_Condition_variables_MP_Send_process_packet( + POSIX_CONDITION_VARIABLES_MP_ANNOUNCE_CREATE, + the_cond->Object.id, + 0, /* Name not used */ + 0 /* Not used */ + ); + + _Thread_Enable_dispatch(); + + return 0; +} + +/*PAGE + * + * 11.4.2 Initializing and Destroying a Condition Variable, + * P1003.1c/Draft 10, p. 87 + */ + +int pthread_cond_destroy( + pthread_cond_t *cond +) +{ + register POSIX_Condition_variables_Control *the_cond; + Objects_Locations location; + + the_cond = _POSIX_Condition_variables_Get( cond, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + return EINVAL; + case OBJECTS_LOCAL: + + _Objects_Close( + &_POSIX_Condition_variables_Information, + &the_cond->Object + ); + + if ( _Thread_queue_Get_number_waiting( &the_cond->Wait_queue ) ) + return EBUSY; + + _POSIX_Condition_variables_Free( the_cond ); + + if ( the_cond->process_shared == PTHREAD_PROCESS_SHARED ) { + + _Objects_MP_Close( + &_POSIX_Condition_variables_Information, + the_cond->Object.id + ); + + _POSIX_Condition_variables_MP_Send_process_packet( + POSIX_CONDITION_VARIABLES_MP_ANNOUNCE_DELETE, + the_cond->Object.id, + 0, /* Not used */ + 0 /* Not used */ + ); + } + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * _POSIX_Condition_variables_Signal_support + * + * A support routine which implements guts of the broadcast and single task + * wake up version of the "signal" operation. + */ + +int _POSIX_Condition_variables_Signal_support( + pthread_cond_t *cond, + boolean is_broadcast +) +{ + register POSIX_Condition_variables_Control *the_cond; + Objects_Locations location; + Thread_Control *the_thread; + + the_cond = _POSIX_Condition_variables_Get( cond, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + return EINVAL; + case OBJECTS_LOCAL: + + do { + the_thread = _Thread_queue_Dequeue( &the_cond->Wait_queue ); + } while ( is_broadcast && the_thread ); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 11.4.3 Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 + */ + +int pthread_cond_signal( + pthread_cond_t *cond +) +{ + return _POSIX_Condition_variables_Signal_support( cond, FALSE ); +} + +/*PAGE + * + * 11.4.3 Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 + */ + +int pthread_cond_broadcast( + pthread_cond_t *cond +) +{ + return _POSIX_Condition_variables_Signal_support( cond, TRUE ); +} + +/*PAGE + * + * _POSIX_Condition_variables_Wait_support + * + * A support routine which implements guts of the blocking, non-blocking, and + * timed wait version of condition variable wait routines. + */ + +int _POSIX_Condition_variables_Wait_support( + pthread_cond_t *cond, + pthread_mutex_t *mutex, + Watchdog_Interval timeout +) +{ + register POSIX_Condition_variables_Control *the_cond; + Objects_Locations location; + int status; + + the_cond = _POSIX_Condition_variables_Get( cond, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + return EINVAL; + case OBJECTS_LOCAL: + + /* + * XXX: should be an error if cond->Mutex != mutex + */ + + status = pthread_mutex_unlock( mutex ); + if ( !status ) + return status; + + the_cond->Mutex = *mutex; + +/* XXX .. enter critical section .. */ + _Thread_queue_Enqueue( &the_cond->Wait_queue, 0 ); + + _Thread_Enable_dispatch(); + + status = pthread_mutex_lock( mutex ); + if ( !status ) + return status; + + return _Thread_Executing->Wait.return_code; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 + */ + +int pthread_cond_wait( + pthread_cond_t *cond, + pthread_mutex_t *mutex +) +{ + return _POSIX_Condition_variables_Wait_support( + cond, + mutex, + THREAD_QUEUE_WAIT_FOREVER + ); +} + +/*PAGE + * + * 11.4.4 Waiting on a Condition, P1003.1c/Draft 10, p. 105 + */ + +int pthread_cond_timedwait( + pthread_cond_t *cond, + pthread_mutex_t *mutex, + const struct timespec *abstime +) +{ + return _POSIX_Condition_variables_Wait_support( + cond, + mutex, + _POSIX_Time_Spec_to_interval( abstime ) + ); +} diff --git a/cpukit/posix/src/devctl.c b/cpukit/posix/src/devctl.c new file mode 100644 index 0000000000..6581e0296c --- /dev/null +++ b/cpukit/posix/src/devctl.c @@ -0,0 +1,25 @@ +/* devctl.c + * + * $Id$ + */ + +#include <devctl.h> + +#ifdef NOT_IMPLEMENTED_YET + +/*PAGE + * + * 21.2.1 Control a Device, P1003.4b/D8, p. 65 + */ + +int devctl( + int filedes, + void *dev_data_ptr, + size_t nbyte, + int *dev_info_ptr +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +#endif diff --git a/cpukit/posix/src/intr.c b/cpukit/posix/src/intr.c new file mode 100644 index 0000000000..11fbe6969a --- /dev/null +++ b/cpukit/posix/src/intr.c @@ -0,0 +1,338 @@ +/* intr.c + * + * NOTE: Each task has an interrupt semaphore associated with it. + * No matter which interrupt occurs that it has registered, + * the same semaphore is used. + * + * $Id$ + */ + +#include <errno.h> +#include <intr.h> + +#include <pthread.h> +#include <rtems/score/isr.h> +#include <rtems/score/coresem.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> +#include <rtems/posix/intr.h> +#include <rtems/posix/time.h> +#include <rtems/posix/threadsup.h> + +/* + * _POSIX_Interrupt_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _POSIX_Interrupt_Manager_initialization( + unsigned32 maximum_interrupt_handlers +) +{ + unsigned32 index; + POSIX_Interrupt_Control *the_vector; + + _Objects_Initialize_information( + &_POSIX_Interrupt_Handlers_Information, + OBJECTS_POSIX_INTERRUPTS, + FALSE, + maximum_interrupt_handlers, + sizeof( POSIX_Interrupt_Handler_control ), + FALSE, + 0, + FALSE + ); + + for ( index=0 ; index < CPU_INTERRUPT_NUMBER_OF_VECTORS ; index++ ) { + the_vector = &_POSIX_Interrupt_Information[ index ]; + + the_vector->number_installed = 0; + the_vector->lock_count = 0; + the_vector->deferred_count = 0; + _Chain_Initialize_empty( &the_vector->Handlers ); + } +} + +/*PAGE + * + * 22.3.1 Associate a User-Written ISR with an Interrupt, P1003.4b/D8, p. 74 + */ + +int intr_capture( + intr_t intr, + int (*intr_handler)( void *area ), + volatile void *area, + size_t areasize +) +{ + POSIX_Interrupt_Handler_control *the_intr; + POSIX_Interrupt_Control *the_vector; + POSIX_API_Thread_Support_Control *thread_support; + proc_ptr old_handler; + + if ( !_ISR_Is_vector_number_valid( intr ) || + !_ISR_Is_valid_user_handler( intr_handler ) ) + return EINVAL; + + _Thread_Disable_dispatch(); + + the_intr = _POSIX_Interrupt_Allocate(); + + if ( !the_intr ) { + _Thread_Enable_dispatch(); + return ENOMEM; + } + + the_vector = &_POSIX_Interrupt_Information[ intr ]; + + the_intr->vector = intr; + the_intr->handler = intr_handler; + the_intr->user_data_area = area; + the_intr->server = _Thread_Executing; + the_intr->is_active = TRUE; + + thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + thread_support->interrupts_installed++; + +/* XXX should we malloc the semaphore on the fly??? if so we probably need to + release it when the thread has released all interrupts and keep + a count of how many it has installed. CURRENTLY NO.. ALLOCATED w/TCB +*/ + + /* + * This is sufficient to have the handlers invoked in the opposite + * order of installation. The loop invoking them can then go from + * the front of the list to the end. + */ + + _Chain_Prepend( &the_vector->Handlers, &the_intr->Object.Node ); + + if ( !the_vector->number_installed++ ) + _ISR_Install_vector( + intr, + (proc_ptr) _POSIX_Interrupt_Handler, + &old_handler + ); + + _Objects_Open( &_POSIX_Interrupt_Handlers_Information, &the_intr->Object, 0 ); + + /* + * Normally, an Id would be returned here. + */ + + _Thread_Enable_dispatch(); + + return 0; +} + +/*PAGE + * + * 22.3.1 Associate a User-Written ISR with an Interrupt, P1003.4b/D8, p. 74 + */ + +int intr_release( + intr_t intr, + int (*intr_handler)( void *area ) +) +{ + boolean found; + POSIX_Interrupt_Handler_control *the_intr; + POSIX_Interrupt_Control *the_vector; + POSIX_API_Thread_Support_Control *thread_support; + Chain_Node *the_node; + + if ( !_ISR_Is_valid_user_handler( intr_handler ) ) + return EINVAL; + + _Thread_Disable_dispatch(); + + /* + * Since interrupt handlers do not have a user visible id, there is + * no choice but to search the entire set of active interrupt handlers + * to find this one. + */ + + found = FALSE; + + the_vector = &_POSIX_Interrupt_Information[ intr ]; + + the_node = _Chain_Head( &the_vector->Handlers ); + + for ( ; !_Chain_Is_tail( &the_vector->Handlers, the_node ) ; ) { + the_intr = (POSIX_Interrupt_Handler_control *) the_node; + + if ( the_intr->handler == intr_handler ) { + found = TRUE; + break; + } + the_node = the_node->next; + } + + if ( !found ) { + _Thread_Enable_dispatch(); + return EINVAL; + } + + if ( !_Thread_Is_executing( the_intr->server ) ) { + _Thread_Enable_dispatch(); + return EINVAL; /* XXX should be ENOISR; */ + } + + /* + * OK now we have found the interrupt handler and can do some work. + */ + + _Chain_Extract( &the_intr->Object.Node ); + + the_intr->is_active = FALSE; + + the_vector->number_installed -= 1; + + thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + thread_support->interrupts_installed--; + + /* + * It is unnecessary to flush the semaphore since the handler can only + * be "removed" by the thread which installed it. Thus it cannot be + * blocked on the semaphore or it would not be executing this routine. + */ + + _Objects_Close( &_POSIX_Interrupt_Handlers_Information, &the_intr->Object ); + + _POSIX_Interrupt_Free( the_intr ); + + _Thread_Enable_dispatch(); + + return 0; +} + +/*PAGE + * + * 22.3.1 Associate a User-Written ISR with an Interrupt, P1003.4b/D8, p. 74 + */ + +int intr_lock( + intr_t intr +) +{ + POSIX_Interrupt_Control *the_vector; + + _Thread_Disable_dispatch(); + + the_vector = &_POSIX_Interrupt_Information[ intr ]; + + the_vector->lock_count++; + + _Thread_Enable_dispatch(); + + return 0; +} + +/*PAGE + * + * 22.3.1 Associate a User-Written ISR with an Interrupt, P1003.4b/D8, p. 74 + */ + +int intr_unlock( + intr_t intr +) +{ + POSIX_Interrupt_Control *the_vector; + + _Thread_Disable_dispatch(); + + the_vector = &_POSIX_Interrupt_Information[ intr ]; + + if ( !--the_vector->lock_count ) { + while ( --the_vector->deferred_count ) { + _POSIX_Interrupt_Handler( intr ); + } + } + + _Thread_Enable_dispatch(); + + return 0; +} + +/* + * 22.3.2 Await Interrupt Notification, P1003.4b/D8, p. 76 + */ + +int intr_timed_wait( + int flags, + const struct timespec *timeout +) +{ + Watchdog_Interval ticks; + POSIX_API_Thread_Support_Control *thread_support; + + ticks = _POSIX_Time_Spec_to_interval( timeout ); + + thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + + _Thread_Disable_dispatch(); + + _CORE_semaphore_Seize( + &thread_support->Interrupt_Semaphore, + 0, /* XXX does id=0 hurt in this case? */ + TRUE, + ticks + ); + _Thread_Enable_dispatch(); + + return _Thread_Executing->Wait.return_code; /* XXX should be POSIX */ +} + +/*PAGE + * + * _POSIX_Interrupt_Handler + * + */ + +void _POSIX_Interrupt_Handler( + ISR_Vector_number vector +) +{ + POSIX_Interrupt_Handler_control *the_intr; + POSIX_Interrupt_Control *the_vector; + POSIX_API_Thread_Support_Control *thread_support; + Chain_Node *the_node; + int status; + + the_vector = &_POSIX_Interrupt_Information[ vector ]; + + the_node = _Chain_Head( &the_vector->Handlers ); + + for ( ; !_Chain_Is_tail( &the_vector->Handlers, the_node ) ; ) { + the_intr = (POSIX_Interrupt_Handler_control *) the_node; + + status = (*the_intr->handler)( (void *) the_intr->user_data_area ); + + switch ( status ) { + case INTR_HANDLED_NOTIFY: + thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + + _CORE_semaphore_Surrender( + &thread_support->Interrupt_Semaphore, + 0, /* XXX is id=0 a problem */ + 0 /* XXX is this a problem (mp support)*/ + ); + return; + + case INTR_HANDLED_DO_NOT_NOTIFY: + return; + + case INTR_NOT_HANDLED: + default: /* this should not happen */ + break; + } + the_node = the_node->next; + } + + /* XXX + * + * This is an unhandled interrupt!!! + */ +} diff --git a/cpukit/posix/src/key.c b/cpukit/posix/src/key.c new file mode 100644 index 0000000000..3bcc1b5170 --- /dev/null +++ b/cpukit/posix/src/key.c @@ -0,0 +1,260 @@ +/* key.c + * + * $Id$ + */ + +#include <errno.h> +#include <limits.h> +#include <pthread.h> +#include <string.h> + +#include <rtems/score/thread.h> +#include <rtems/score/wkspace.h> +#include <rtems/posix/key.h> + +/* + * _POSIX_Key_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _POSIX_Key_Manager_initialization( + unsigned32 maximum_keys +) +{ + _Objects_Initialize_information( + &_POSIX_Keys_Information, + OBJECTS_POSIX_KEYS, + FALSE, + maximum_keys, + sizeof( POSIX_Keys_Control ), + FALSE, + 0, + FALSE + ); +} + +/*PAGE + * + * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 + */ + +int pthread_key_create( + pthread_key_t *key, + void (*destructor)( void * ) +) +{ + POSIX_Keys_Control *the_key; + void *table; + unsigned32 the_class; + unsigned32 bytes_to_allocate; + + + _Thread_Disable_dispatch(); + + the_key = _POSIX_Keys_Allocate(); + + if ( !the_key ) { + _Thread_Enable_dispatch(); + return EAGAIN; + } + + the_key->destructor = destructor; + + for ( the_class = OBJECTS_CLASSES_FIRST_THREAD_CLASS; + the_class <= OBJECTS_CLASSES_LAST_THREAD_CLASS; + the_class++ ) { + + bytes_to_allocate = + (_Objects_Information_table[ the_class ]->maximum + 1) * sizeof( void * ); + + table = _Workspace_Allocate( bytes_to_allocate ); + + if ( !table ) { + for ( --the_class; + the_class >= OBJECTS_CLASSES_FIRST_THREAD_CLASS; + the_class-- ) + _Workspace_Free( the_key->Values[ the_class ] ); + + _POSIX_Keys_Free( the_key ); + _Thread_Enable_dispatch(); + return ENOMEM; + } + + the_key->Values[ the_class ] = table; + memset( table, '\0', bytes_to_allocate ); + } + + the_key->is_active = TRUE; + + _Objects_Open( &_POSIX_Keys_Information, &the_key->Object, 0 ); + + *key = the_key->Object.id; + + _Thread_Enable_dispatch(); + + return 0; +} + +/*PAGE + * + * 17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165 + */ + +int pthread_setspecific( + pthread_key_t key, + const void *value +) +{ + register POSIX_Keys_Control *the_key; + unsigned32 index; + unsigned32 class; + Objects_Locations location; + + the_key = _POSIX_Keys_Get( key, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + return EINVAL; /* should never happen */ + case OBJECTS_LOCAL: + index = _Objects_Get_index( _Thread_Executing->Object.id ); + class = _Objects_Get_class( _Thread_Executing->Object.id ); + the_key->Values[ class ][ index ] = (void *) value; + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 17.1.2 Thread-Specific Data Management, P1003.1c/Draft 10, p. 165 + */ + +void *pthread_getspecific( + pthread_key_t key +) +{ + register POSIX_Keys_Control *the_key; + unsigned32 index; + unsigned32 class; + Objects_Locations location; + + the_key = _POSIX_Keys_Get( key, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return NULL; + case OBJECTS_REMOTE: + return 0; /* should never happen */ + case OBJECTS_LOCAL: + index = _Objects_Get_index( _Thread_Executing->Object.id ); + class = _Objects_Get_class( _Thread_Executing->Object.id ); + return (void *) the_key->Values[ class ][ index ]; + } + return (void *) POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 17.1.3 Thread-Specific Data Key Deletion, P1003.1c/Draft 10, p. 167 + */ + +int pthread_key_delete( + pthread_key_t key +) +{ + register POSIX_Keys_Control *the_key; + Objects_Locations location; + unsigned32 the_class; + + the_key = _POSIX_Keys_Get( key, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + return 0; /* should never happen */ + case OBJECTS_LOCAL: + _Objects_Close( &_POSIX_Keys_Information, &the_key->Object ); + + the_key->is_active = FALSE; + + for ( the_class = OBJECTS_CLASSES_FIRST_THREAD_CLASS; + the_class <= OBJECTS_CLASSES_LAST_THREAD_CLASS; + the_class++ ) + _Workspace_Free( the_key->Values[ the_class ] ); + + /* + * NOTE: The destructor is not called and it is the responsibility + * of the application to free the memory. + */ + + _POSIX_Keys_Free( the_key ); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * _POSIX_Keys_Run_destructors + * + * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 + * + * NOTE: This is the routine executed when a thread exits to + * run through all the keys and do the destructor action. + * + * XXX: This needs to be hooked to the thread exitting -- SOMEHOW. + */ + +void _POSIX_Keys_Run_destructors( + Thread_Control *thread +) +{ + unsigned32 index; + unsigned32 pthread_index; + unsigned32 pthread_class; + unsigned32 iterations; + boolean are_all_null; + POSIX_Keys_Control *the_key; + void *value; + + pthread_index = _Objects_Get_index( thread->Object.id ); + pthread_class = _Objects_Get_class( thread->Object.id ); + + iterations = 0; + + for ( ; ; ) { + + are_all_null = TRUE; + + for ( index=1 ; index <= _POSIX_Keys_Information.maximum ; index++ ) { + + the_key = (POSIX_Keys_Control *) + _POSIX_Keys_Information.local_table[ index ]; + + if ( the_key && the_key->is_active && the_key->destructor ) { + value = the_key->Values[ pthread_class ][ pthread_index ]; + if ( value ) { + (*the_key->destructor)( value ); + if ( the_key->Values[ pthread_class ][ pthread_index ] ) + are_all_null = FALSE; + } + } + } + + if ( are_all_null == TRUE ) + return; + + iterations++; + + /* + * The standard allows one to not do this and thus go into an infinite + * loop. It seems rude to unnecessarily lock up a system. + */ + + if ( iterations >= PTHREAD_DESTRUCTOR_ITERATIONS ) + return; + } +} diff --git a/cpukit/posix/src/mqueue.c b/cpukit/posix/src/mqueue.c new file mode 100644 index 0000000000..e175300355 --- /dev/null +++ b/cpukit/posix/src/mqueue.c @@ -0,0 +1,715 @@ +/* mqueue.c + * + * NOTE: The structure of the routines is identical to that of POSIX + * Message_queues to leave the option of having unnamed message + * queues at a future date. They are currently not part of the + * POSIX standard but unnamed message_queues are. This is also + * the reason for the apparently unnecessary tracking of + * the process_shared attribute. [In addition to the fact that + * it would be trivial to add pshared to the mq_attr structure + * and have process private message queues.] + * + * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open + * time. + * + * $Id$ + */ + +#include <stdarg.h> + +#include <pthread.h> +#include <limits.h> +#include <errno.h> +#include <fcntl.h> + +#include <mqueue.h> +#include <rtems/system.h> +#include <rtems/score/watchdog.h> +#include <rtems/posix/mqueue.h> +#include <rtems/posix/time.h> + +/*PAGE + * + * _POSIX_Message_queue_Manager_initialization + * + * This routine initializes all message_queue manager related data structures. + * + * Input parameters: + * maximum_message_queues - maximum configured message_queues + * + * Output parameters: NONE + */ + +void _POSIX_Message_queue_Manager_initialization( + unsigned32 maximum_message_queues +) +{ + _Objects_Initialize_information( + &_POSIX_Message_queue_Information, + OBJECTS_POSIX_MESSAGE_QUEUES, + TRUE, + maximum_message_queues, + sizeof( POSIX_Message_queue_Control ), + TRUE, + _POSIX_PATH_MAX, + FALSE + ); +} + +/*PAGE + * + * _POSIX_Message_queue_Create_support + */ + +int _POSIX_Message_queue_Create_support( + const char *name, + int pshared, + unsigned int oflag, + struct mq_attr *attr, + POSIX_Message_queue_Control **message_queue +) +{ + POSIX_Message_queue_Control *the_mq; + + _Thread_Disable_dispatch(); + + the_mq = _POSIX_Message_queue_Allocate(); + + if ( !the_mq ) { + _Thread_Enable_dispatch(); + seterrno( ENFILE ); + return -1; + } + + if ( pshared == PTHREAD_PROCESS_SHARED && + !( _Objects_MP_Allocate_and_open( &_POSIX_Message_queue_Information, 0, + the_mq->Object.id, FALSE ) ) ) { + _POSIX_Message_queue_Free( the_mq ); + _Thread_Enable_dispatch(); + seterrno( ENFILE ); + return -1; + } + + the_mq->process_shared = pshared; + + if ( name ) { + the_mq->named = TRUE; + the_mq->open_count = 1; + the_mq->linked = TRUE; + } + else + the_mq->named = FALSE; + + if ( oflag & O_NONBLOCK ) + the_mq->blocking = FALSE; + else + the_mq->blocking = TRUE; + + /* XXX + * + * Note that this should be based on the current scheduling policy. + */ + + /* XXX + * + * Message and waiting disciplines are not distinguished. + */ +/* + the_mq_attr->message_discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; + the_mq_attr->waiting_discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; + */ + + the_mq->Message_queue.Attributes.discipline = + CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; + + if ( ! _CORE_message_queue_Initialize( + &the_mq->Message_queue, + OBJECTS_POSIX_MESSAGE_QUEUES, + &the_mq->Message_queue.Attributes, + attr->mq_maxmsg, + attr->mq_msgsize, + _POSIX_Message_queue_MP_Send_extract_proxy ) ) { + + if ( pshared == PTHREAD_PROCESS_SHARED ) + _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq->Object.id ); + + _POSIX_Message_queue_Free( the_mq ); + _Thread_Enable_dispatch(); + seterrno( ENOSPC ); + return -1; + } + + + /* XXX - need Names to be a string!!! */ + _Objects_Open( + &_POSIX_Message_queue_Information, + &the_mq->Object, + (char *) name + ); + + *message_queue = the_mq; + + if ( pshared == PTHREAD_PROCESS_SHARED ) + _POSIX_Message_queue_MP_Send_process_packet( + POSIX_MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, + the_mq->Object.id, + (char *) name, + 0 /* Not used */ + ); + + _Thread_Enable_dispatch(); + return 0; +} + +/*PAGE + * + * 15.2.2 Open a Message Queue, P1003.1b-1993, p. 272 + */ + +mqd_t mq_open( + const char *name, + int oflag, + ... + /* mode_t mode, */ + /* struct mq_attr attr */ +) +{ + va_list arg; + mode_t mode; + struct mq_attr *attr; + int status; + Objects_Id the_mq_id; + POSIX_Message_queue_Control *the_mq; + + if ( oflag & O_CREAT ) { + va_start(arg, oflag); + mode = (mode_t) va_arg( arg, mode_t * ); + attr = (struct mq_attr *) va_arg( arg, struct mq_attr ** ); + va_end(arg); + } + + status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id ); + + /* + * If the name to id translation worked, then the message queue exists + * and we can just return a pointer to the id. Otherwise we may + * need to check to see if this is a "message queue does not exist" + * or some other miscellaneous error on the name. + */ + + if ( status ) { + + if ( status == EINVAL ) { /* name -> ID translation failed */ + if ( !(oflag & O_CREAT) ) { /* willing to create it? */ + seterrno( ENOENT ); + return (mqd_t) -1; + } + /* we are willing to create it */ + } + seterrno( status ); /* some type of error */ + return (mqd_t) -1; + + } else { /* name -> ID translation succeeded */ + + if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) { + seterrno( EEXIST ); + return (mqd_t) -1; + } + + /* + * XXX In this case we need to do an ID->pointer conversion to + * check the mode. This is probably a good place for a subroutine. + */ + + the_mq->open_count += 1; + + return (mqd_t)&the_mq->Object.id; + + } + + /* XXX verify this comment... + * + * At this point, the message queue does not exist and everything has been + * checked. We should go ahead and create a message queue. + */ + + status = _POSIX_Message_queue_Create_support( + name, + TRUE, /* shared across processes */ + oflag, + attr, + &the_mq + ); + + if ( status == -1 ) + return (mqd_t) -1; + + return (mqd_t) &the_mq->Object.id; +} + +/*PAGE + * + * _POSIX_Message_queue_Delete + */ + +void _POSIX_Message_queue_Delete( + POSIX_Message_queue_Control *the_mq +) +{ + if ( !the_mq->linked && !the_mq->open_count ) { + _POSIX_Message_queue_Free( the_mq ); + + if ( the_mq->process_shared == PTHREAD_PROCESS_SHARED ) { + + _Objects_MP_Close( + &_POSIX_Message_queue_Information, + the_mq->Object.id + ); + + _POSIX_Message_queue_MP_Send_process_packet( + POSIX_MESSAGE_QUEUE_MP_ANNOUNCE_DELETE, + the_mq->Object.id, + 0, /* Not used */ + 0 /* Not used */ + ); + } + + } +} + +/*PAGE + * + * 15.2.2 Close a Message Queue, P1003.1b-1993, p. 275 + */ + +int mq_close( + mqd_t mqdes +) +{ + register POSIX_Message_queue_Control *the_mq; + Objects_Locations location; + + the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + the_mq->open_count -= 1; + _POSIX_Message_queue_Delete( the_mq ); + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 15.2.2 Remove a Message Queue, P1003.1b-1993, p. 276 + */ + +int mq_unlink( + const char *name +) +{ + int status; + register POSIX_Message_queue_Control *the_mq; + Objects_Id the_mq_id; + Objects_Locations location; + + status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id ); + + if ( !status ) { + seterrno( status ); + return -1; + } + + the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + + _Objects_MP_Close( + &_POSIX_Message_queue_Information, + the_mq->Object.id + ); + + the_mq->linked = FALSE; + + _POSIX_Message_queue_Delete( the_mq ); + + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * _POSIX_Message_queue_Send_support + */ + +int _POSIX_Message_queue_Send_support( + mqd_t mqdes, + const char *msg_ptr, + unsigned32 msg_len, + Priority_Control msg_prio, + Watchdog_Interval timeout +) +{ + register POSIX_Message_queue_Control *the_mq; + Objects_Locations location; + + the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + /* XXX must add support for timeout and priority */ + _CORE_message_queue_Send( + &the_mq->Message_queue, + (void *) msg_ptr, + msg_len, + mqdes, + NULL /* XXX _POSIX_Message_queue_Core_message_queue_mp_support*/ + ); + _Thread_Enable_dispatch(); + return _Thread_Executing->Wait.return_code; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 15.2.4 Send a Message to a Message Queue, P1003.1b-1993, p. 277 + * + * NOTE: P1003.4b/D8, p. 45 adds mq_timedsend(). + */ + +int mq_send( + mqd_t mqdes, + const char *msg_ptr, + size_t msg_len, + unsigned int msg_prio +) +{ + return _POSIX_Message_queue_Send_support( + mqdes, + msg_ptr, + msg_len, + msg_prio, + THREAD_QUEUE_WAIT_FOREVER + ); +} + +/*PAGE + * + * 15.2.4 Send a Message to a Message Queue, P1003.1b-1993, p. 277 + * + * NOTE: P1003.4b/D8, p. 45 adds mq_timedsend(). + */ + +int mq_timedsend( + mqd_t mqdes, + const char *msg_ptr, + size_t msg_len, + unsigned int msg_prio, + const struct timespec *timeout +) +{ + return _POSIX_Message_queue_Send_support( + mqdes, + msg_ptr, + msg_len, + msg_prio, + _POSIX_Time_Spec_to_interval( timeout ) + ); +} + +/*PAGE + * + * _POSIX_Message_queue_Receive_support + */ + +/* XXX be careful ... watch the size going through all the layers ... */ + +ssize_t _POSIX_Message_queue_Receive_support( + mqd_t mqdes, + char *msg_ptr, + size_t msg_len, + unsigned int *msg_prio, + Watchdog_Interval timeout +) +{ + register POSIX_Message_queue_Control *the_mq; + Objects_Locations location; + unsigned32 status = 0; + unsigned32 length_out; + + the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + /* XXX need to define the options argument to this */ + length_out = msg_len; + _CORE_message_queue_Seize( + &the_mq->Message_queue, + mqdes, + msg_ptr, + &length_out, + /* msg_prio, XXXX */ + the_mq->blocking, + timeout + ); + _Thread_Enable_dispatch(); + if ( !status ) + return length_out; + /* XXX --- the return codes gotta be looked at .. fix this */ + return _Thread_Executing->Wait.return_code; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 15.2.5 Receive a Message From a Message Queue, P1003.1b-1993, p. 279 + * + * NOTE: P1003.4b/D8, p. 45 adds mq_timedreceive(). + */ + +ssize_t mq_receive( + mqd_t mqdes, + char *msg_ptr, + size_t msg_len, + unsigned int *msg_prio +) +{ + return _POSIX_Message_queue_Receive_support( + mqdes, + msg_ptr, + msg_len, + msg_prio, + THREAD_QUEUE_WAIT_FOREVER + ); +} + +/*PAGE + * + * 15.2.5 Receive a Message From a Message Queue, P1003.1b-1993, p. 279 + * + * NOTE: P1003.4b/D8, p. 45 adds mq_timedreceive(). + */ + +int mq_timedreceive( /* XXX: should this be ssize_t */ + mqd_t mqdes, + char *msg_ptr, + size_t msg_len, + unsigned int *msg_prio, + const struct timespec *timeout +) +{ + return _POSIX_Message_queue_Receive_support( + mqdes, + msg_ptr, + msg_len, + msg_prio, + _POSIX_Time_Spec_to_interval( timeout ) + ); +} + +/*PAGE + * + * _POSIX_Message_queue_Notify_handler + * + */ + +void _POSIX_Message_queue_Notify_handler( + void *user_data +) +{ + POSIX_Message_queue_Control *the_mq; + + the_mq = user_data; + + /* XXX do something with signals here!!!! */ +} + +/*PAGE + * + * 15.2.6 Notify Process that a Message is Available on a Queue, + * P1003.1b-1993, p. 280 + */ + +int mq_notify( + mqd_t mqdes, + const struct sigevent *notification +) +{ + register POSIX_Message_queue_Control *the_mq; + Objects_Locations location; + + the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EBADF ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + if ( notification ) { + if ( _CORE_message_queue_Is_notify_enabled( &the_mq->Message_queue ) ) { + _Thread_Enable_dispatch(); + seterrno( EBUSY ); + return( -1 ); + } + + _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL ); + + the_mq->notification = *notification; + + _CORE_message_queue_Set_notify( + &the_mq->Message_queue, + _POSIX_Message_queue_Notify_handler, + the_mq + ); + } else { + + _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL ); + + } + + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 15.2.7 Set Message Queue Attributes, P1003.1b-1993, p. 281 + */ + +int mq_setattr( + mqd_t mqdes, + const struct mq_attr *mqstat, + struct mq_attr *omqstat +) +{ + register POSIX_Message_queue_Control *the_mq; + Objects_Locations location; + CORE_message_queue_Attributes *the_mq_attr; + + the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + /* + * Return the old values. + */ + + /* XXX this is the same stuff as is in mq_getattr... and probably */ + /* XXX should be in an inlined private routine */ + + the_mq_attr = &the_mq->Message_queue.Attributes; + + omqstat->mq_flags = the_mq->flags; + omqstat->mq_msgsize = the_mq->Message_queue.maximum_message_size; + omqstat->mq_maxmsg = the_mq->Message_queue.maximum_pending_messages; + omqstat->mq_curmsgs = the_mq->Message_queue.number_of_pending_messages; + + /* + * Ignore everything except the O_NONBLOCK bit. + */ + + if ( mqstat->mq_flags & O_NONBLOCK ) + the_mq->blocking = FALSE; + else + the_mq->blocking = TRUE; + + the_mq->flags = mqstat->mq_flags; + + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 15.2.8 Get Message Queue Attributes, P1003.1b-1993, p. 283 + */ + +int mq_getattr( + mqd_t mqdes, + struct mq_attr *mqstat +) +{ + register POSIX_Message_queue_Control *the_mq; + Objects_Locations location; + CORE_message_queue_Attributes *the_mq_attr; + + the_mq = _POSIX_Message_queue_Get( mqdes, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + /* + * Return the old values. + */ + + /* XXX this is the same stuff as is in mq_setattr... and probably */ + /* XXX should be in an inlined private routine */ + + the_mq_attr = &the_mq->Message_queue.Attributes; + + mqstat->mq_flags = the_mq->flags; + mqstat->mq_msgsize = the_mq->Message_queue.maximum_message_size; + mqstat->mq_maxmsg = the_mq->Message_queue.maximum_pending_messages; + mqstat->mq_curmsgs = the_mq->Message_queue.number_of_pending_messages; + + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} diff --git a/cpukit/posix/src/mutex.c b/cpukit/posix/src/mutex.c new file mode 100644 index 0000000000..9ff4acff99 --- /dev/null +++ b/cpukit/posix/src/mutex.c @@ -0,0 +1,570 @@ +/* mutex.c + * + * $Id$ + */ + +#include <errno.h> +#include <pthread.h> + +#include <rtems/score/system.h> +#include <rtems/score/coremutex.h> +#include <rtems/score/watchdog.h> +#include <rtems/score/mpci.h> + +#include <rtems/posix/mutex.h> +#include <rtems/posix/priority.h> +#include <rtems/posix/time.h> + +/*PAGE + * + * The default mutex attributes structure. + */ + +const pthread_mutexattr_t _POSIX_Mutex_Default_attributes = { + TRUE, /* is_initialized */ + PTHREAD_PROCESS_PRIVATE, /* process_shared */ + POSIX_SCHEDULER_MINIMUM_PRIORITY, /* prio_ceiling */ + PTHREAD_PRIO_NONE, /* protocol */ + FALSE /* recursive */ +}; + +/*PAGE + * + * _POSIX_Mutex_Manager_initialization + * + * This routine initializes all mutex manager related data structures. + * + * Input parameters: + * maximum_mutexes - maximum configured mutexes + * + * Output parameters: NONE + */ + +void _POSIX_Mutex_Manager_initialization( + unsigned32 maximum_mutexes +) +{ + _Objects_Initialize_information( + &_POSIX_Mutex_Information, + OBJECTS_POSIX_MUTEXES, + TRUE, + maximum_mutexes, + sizeof( POSIX_Mutex_Control ), + FALSE, + 0, + FALSE + ); +} + +/*PAGE + * + * 11.3.1 Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81 + */ + +int pthread_mutexattr_init( + pthread_mutexattr_t *attr +) +{ + if ( !attr ) + return EINVAL; + + *attr = _POSIX_Mutex_Default_attributes; + return 0; +} + +/*PAGE + * + * 11.3.1 Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81 + */ + +int pthread_mutexattr_destroy( + pthread_mutexattr_t *attr +) +{ + if ( !attr || attr->is_initialized == FALSE ) + return EINVAL; + + attr->is_initialized = FALSE; + return 0; +} + +/*PAGE + * + * 11.3.1 Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81 + */ + +int pthread_mutexattr_getpshared( + const pthread_mutexattr_t *attr, + int *pshared +) +{ + if ( !attr ) + return EINVAL; + + *pshared = attr->process_shared; + return 0; +} + +/*PAGE + * + * 11.3.1 Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81 + */ + +int pthread_mutexattr_setpshared( + pthread_mutexattr_t *attr, + int pshared +) +{ + if ( !attr ) + return EINVAL; + + attr->process_shared = pshared; + return 0; +} + +/*PAGE + * + * 11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87 + * + * NOTE: XXX Could be optimized so all the attribute error checking + * is not performed when attr is NULL. + */ + +int pthread_mutex_init( + pthread_mutex_t *mutex, + const pthread_mutexattr_t *attr +) +{ + POSIX_Mutex_Control *the_mutex; + CORE_mutex_Attributes *the_mutex_attr; + const pthread_mutexattr_t *the_attr; + CORE_mutex_Disciplines the_discipline; + + if ( attr ) the_attr = attr; + else the_attr = &_POSIX_Mutex_Default_attributes; + + /* + * XXX: Be careful about attributes when global!!! + */ + + if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED ) + return POSIX_MP_NOT_IMPLEMENTED(); + + if ( !the_attr->is_initialized ) + return EINVAL; + + /* + * Determine the discipline of the mutex + */ + + switch ( the_attr->protocol ) { + case PTHREAD_PRIO_NONE: + the_discipline = CORE_MUTEX_DISCIPLINES_FIFO; + break; + case PTHREAD_PRIO_INHERIT: + the_discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT; + break; + case PTHREAD_PRIO_PROTECT: + the_discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING; + break; + default: + return EINVAL; + } + + if ( !_POSIX_Priority_Is_valid( the_attr->prio_ceiling ) ) + return EINVAL; + + _Thread_Disable_dispatch(); + + the_mutex = _POSIX_Mutex_Allocate(); + + if ( !the_mutex ) { + _Thread_Enable_dispatch(); + return ENOMEM; + } + + if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED && + !( _Objects_MP_Allocate_and_open( &_POSIX_Mutex_Information, 0, + the_mutex->Object.id, FALSE ) ) ) { + _POSIX_Mutex_Free( the_mutex ); + _Thread_Enable_dispatch(); + return EAGAIN; + } + + the_mutex->process_shared = the_attr->process_shared; + + the_mutex_attr = &the_mutex->Mutex.Attributes; + + the_mutex_attr->allow_nesting = the_attr->recursive; + the_mutex_attr->priority_ceiling = + _POSIX_Priority_To_core( the_attr->prio_ceiling ); + the_mutex_attr->discipline = the_discipline; + + /* + * Must be initialized to unlocked. + */ + + _CORE_mutex_Initialize( + &the_mutex->Mutex, + OBJECTS_POSIX_MUTEXES, + the_mutex_attr, + CORE_MUTEX_UNLOCKED, + 0 /* XXX proxy_extract_callout */ + ); + + _Objects_Open( &_POSIX_Mutex_Information, &the_mutex->Object, 0 ); + + *mutex = the_mutex->Object.id; + + if ( the_attr->process_shared == PTHREAD_PROCESS_SHARED ) + _POSIX_Mutex_MP_Send_process_packet( + POSIX_MUTEX_MP_ANNOUNCE_CREATE, + the_mutex->Object.id, + 0, /* Name not used */ + 0 /* Not used */ + ); + + _Thread_Enable_dispatch(); + return 0; +} + +/*PAGE + * + * 11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87 + */ + +int pthread_mutex_destroy( + pthread_mutex_t *mutex +) +{ + register POSIX_Mutex_Control *the_mutex; + Objects_Locations location; + + the_mutex = _POSIX_Mutex_Get( mutex, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + return EINVAL; + case OBJECTS_LOCAL: + /* + * XXX: There is an error for the mutex being locked + * or being in use by a condition variable. + */ + + if ( _CORE_mutex_Is_locked( &the_mutex->Mutex ) ) { + _Thread_Enable_dispatch(); + return EBUSY; + } + + _Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object ); + + _CORE_mutex_Flush( + &the_mutex->Mutex, + _POSIX_Mutex_MP_Send_object_was_deleted, + EINVAL + ); + + _POSIX_Mutex_Free( the_mutex ); + + if ( the_mutex->process_shared == PTHREAD_PROCESS_SHARED ) { + + _Objects_MP_Close( &_POSIX_Mutex_Information, the_mutex->Object.id ); + + _POSIX_Mutex_MP_Send_process_packet( + POSIX_MUTEX_MP_ANNOUNCE_DELETE, + the_mutex->Object.id, + 0, /* Not used */ + 0 /* Not used */ + ); + } + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/* + * _POSIX_Mutex_Lock_support + * + * A support routine which implements guts of the blocking, non-blocking, and + * timed wait version of mutex lock. + */ + +int _POSIX_Mutex_Lock_support( + pthread_mutex_t *mutex, + boolean blocking, + Watchdog_Interval timeout +) +{ + register POSIX_Mutex_Control *the_mutex; + Objects_Locations location; + + the_mutex = _POSIX_Mutex_Get( mutex, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + return _POSIX_Mutex_MP_Send_request_packet( + POSIX_MUTEX_MP_OBTAIN_REQUEST, + *mutex, + 0, /* must define the option set */ + WATCHDOG_NO_TIMEOUT + ); + case OBJECTS_LOCAL: + _CORE_mutex_Seize( + &the_mutex->Mutex, + the_mutex->Object.id, + blocking, + timeout + ); + _Thread_Enable_dispatch(); + return _Thread_Executing->Wait.return_code; + break; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93 + * + * NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29 + */ + +int pthread_mutex_lock( + pthread_mutex_t *mutex +) +{ + return _POSIX_Mutex_Lock_support( mutex, TRUE, THREAD_QUEUE_WAIT_FOREVER ); +} + +/*PAGE + * + * 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93 + * + * NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29 + */ + +int pthread_mutex_trylock( + pthread_mutex_t *mutex +) +{ + return _POSIX_Mutex_Lock_support( mutex, FALSE, THREAD_QUEUE_WAIT_FOREVER ); +} + +/*PAGE + * + * 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93 + * + * NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29 + */ + +void POSIX_Threads_mutex_MP_support( + Thread_Control *the_thread, + Objects_Id id +) +{ + (void) POSIX_MP_NOT_IMPLEMENTED(); /* XXX: should never get here */ +} + +int pthread_mutex_unlock( + pthread_mutex_t *mutex +) +{ + register POSIX_Mutex_Control *the_mutex; + Objects_Locations location; + + the_mutex = _POSIX_Mutex_Get( mutex, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + return _POSIX_Mutex_MP_Send_request_packet( + POSIX_MUTEX_MP_RELEASE_REQUEST, + *mutex, + 0, /* Not used */ + MPCI_DEFAULT_TIMEOUT + ); + case OBJECTS_LOCAL: + _CORE_mutex_Surrender( + &the_mutex->Mutex, + the_mutex->Object.id, + POSIX_Threads_mutex_MP_support + ); + _Thread_Enable_dispatch(); + return _Thread_Executing->Wait.return_code; /* XXX return status */ + break; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 11.3.3 Locking and Unlocking a Mutex, P1003.1c/Draft 10, p. 93 + * + * NOTE: P1003.4b/D8 adds pthread_mutex_timedlock(), p. 29 + */ + +int pthread_mutex_timedlock( + pthread_mutex_t *mutex, + const struct timespec *timeout +) +{ + return _POSIX_Mutex_Lock_support( + mutex, + TRUE, + _POSIX_Time_Spec_to_interval( timeout ) + ); +} + +/*PAGE + * + * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 + */ + +int pthread_mutexattr_setprotocol( + pthread_mutexattr_t *attr, + int protocol +) +{ + if ( !attr ) + return EINVAL; + + attr->protocol = protocol; + return 0; +} + +/*PAGE + * + * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 + */ + +int pthread_mutexattr_getprotocol( + const pthread_mutexattr_t *attr, + int *protocol +) +{ + if ( !attr ) + return EINVAL; + + *protocol = attr->protocol; + return 0; +} + +/*PAGE + * + * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 + */ + +int pthread_mutexattr_setprioceiling( + pthread_mutexattr_t *attr, + int prioceiling +) +{ + if ( !attr ) + return EINVAL; + + if ( !_POSIX_Priority_Is_valid( attr->prio_ceiling ) ) + return EINVAL; + + attr->prio_ceiling = prioceiling; + return 0; +} + +/*PAGE + * + * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 + */ + +int pthread_mutexattr_getprioceiling( + const pthread_mutexattr_t *attr, + int *prioceiling +) +{ + if ( !attr ) + return EINVAL; + + *prioceiling = attr->prio_ceiling; + return 0; +} + +/*PAGE + * + * 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 + */ + +int pthread_mutex_setprioceiling( + pthread_mutex_t *mutex, + int prioceiling, + int *old_ceiling +) +{ + register POSIX_Mutex_Control *the_mutex; + Objects_Locations location; + Priority_Control the_priority; + int status; + + if ( !_POSIX_Priority_Is_valid( prioceiling ) ) + return EINVAL; + + the_priority = _POSIX_Priority_To_core( prioceiling ); + + /* + * Must acquire the mutex before we can change it's ceiling + */ + + status = pthread_mutex_lock( mutex ); + if ( status ) + return status; + + the_mutex = _POSIX_Mutex_Get( mutex, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + return POSIX_MP_NOT_IMPLEMENTED(); /* XXX feels questionable */ + return EINVAL; + case OBJECTS_LOCAL: + the_mutex->Mutex.Attributes.priority_ceiling = the_priority; + _CORE_mutex_Surrender( + &the_mutex->Mutex, + the_mutex->Object.id, + POSIX_Threads_mutex_MP_support + ); + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 + */ + +int pthread_mutex_getprioceiling( + pthread_mutex_t *mutex, + int *prioceiling +) +{ + register POSIX_Mutex_Control *the_mutex; + Objects_Locations location; + + the_mutex = _POSIX_Mutex_Get( mutex, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_REMOTE: + return POSIX_MP_NOT_IMPLEMENTED(); /* XXX feels questionable */ + case OBJECTS_LOCAL: + *prioceiling = _POSIX_Priority_From_core( + the_mutex->Mutex.Attributes.priority_ceiling + ); + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} diff --git a/cpukit/posix/src/psignal.c b/cpukit/posix/src/psignal.c new file mode 100644 index 0000000000..9ad7406e21 --- /dev/null +++ b/cpukit/posix/src/psignal.c @@ -0,0 +1,258 @@ +/* signal.c + * + * $Id$ + */ + +#include <signal.h> + +#include <rtems/score/thread.h> + +#ifdef NOT_IMPLEMENTED_YET + +/* + * 3.3.2 Send a Signal to a Process, P1003.1b-1993, p. 68 + * + * NOTE: Behavior of kill() depends on _POSIX_SAVED_IDS. + */ + +int kill( + int pid_t, + int sig +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69 + */ + +int sigemptyset( + sigset_t *set +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69 + */ + +int sigfillset( + sigset_t *set +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69 + */ + +int sigaddset( + sigset_t *set, + int signo +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69 + */ + +int sigdelset( + sigset_t *set, + int signo +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.3 Manipulate Signal Sets, P1003.1b-1993, p. 69 + */ + +int sigismember( + const sigset_t *set, + int signo +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.4 Examine and Change Signal Action, P1003.1b-1993, p. 70 + */ + +int sigaction( + int sig, + const struct sigaction *act, + struct sigaction *oact +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.5 Examine and Change Blocked Signals, P1003.1b-1993, p. 73 + * + * NOTE: P1003.1c/D10, p. 37 adds pthread_sigmask(). + */ + +int sigprocmask( + int how, + const sigset_t *set, + sigset_t *oset +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.5 Examine and Change Blocked Signals, P1003.1b-1993, p. 73 + * + * NOTE: P1003.1c/D10, p. 37 adds pthread_sigmask(). + */ + +int pthread_sigmask( + int how, + const sigset_t *set, + sigset_t *oset +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.6 Examine Pending Signals, P1003.1b-1993, p. 75 + */ + +int sigpending( + sigset_t *set +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.7 Wait for a Signal, P1003.1b-1993, p. 75 + */ + +int sigsuspend( + const sigset_t *sigmask +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 + * + * NOTE: P1003.1c/D10, p. 39 adds sigwait(). + */ + +int sigwaitinfo( + const sigset_t *set, + siginfo_t *info +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 + * + * NOTE: P1003.1c/D10, p. 39 adds sigwait(). + */ + +int sigtimedwait( + const sigset_t *set, + siginfo_t *info, + const struct timespec *timeout +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 + * + * NOTE: P1003.1c/D10, p. 39 adds sigwait(). + */ + +int sigwait( + const sigset_t *set, + int *sig +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.9 Queue a Signal to a Process, P1003.1b-1993, p. 78 + */ + +int sigqueue( + pid_t pid, + int signo, + const union sigval value +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.3.10 Send a Signal to a Thread, P1003.1c/D10, p. 43 + */ + +int pthread_kill( + pthread_t thread, + int sig +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.4.1 Schedule Alarm, P1003.1b-1993, p. 79 + */ + +unsigned int alarm( + unsigned int seconds +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 3.4.2 Suspend Process Execution, P1003.1b-1993, p. 80 + */ + +int pause( void ) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +#endif + +/* + * 3.4.3 Delay Process Execution, P1003.1b-1993, p. 73 + */ + +unsigned int sleep( + unsigned int seconds +) +{ + _Thread_Disable_dispatch(); + _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_TIME ); + _Watchdog_Initialize( + &_Thread_Executing->Timer, + _Thread_Delay_ended, /* XXX may need to be POSIX specific */ + _Thread_Executing->Object.id, + NULL + ); + _Watchdog_Insert_seconds( &_Thread_Executing->Timer, seconds ); + _Thread_Enable_dispatch(); + return 0; /* XXX should account for signal */ +} diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c new file mode 100644 index 0000000000..7247586685 --- /dev/null +++ b/cpukit/posix/src/pthread.c @@ -0,0 +1,553 @@ +/* pthread.c + * + * $Id$ + */ + +#include <errno.h> +#include <pthread.h> +#include <limits.h> + +#include <rtems/score/stack.h> +#include <rtems/score/thread.h> +#include <rtems/posix/pthread.h> + +/*PAGE + * + * The default pthreads attributes structure. + */ + +const pthread_attr_t _POSIX_Threads_Default_attributes = { + TRUE, /* is_initialized */ + 0, /* stackaddr */ + STACK_MINIMUM_SIZE, /* stacksize */ + PTHREAD_SCOPE_PROCESS, /* contentionscope */ + PTHREAD_INHERIT_SCHED, /* inheritsched */ + SCHED_FIFO, /* schedpolicy */ + { /* schedparam */ + 128, /* sched_priority */ + 0, /* ss_low_priority */ + { 0L, 0 }, /* ss_replenish_period */ + { 0L, 0 } /* ss_initial_budget */ + }, + PTHREAD_CREATE_DETACHED, /* detachstate */ + 1 /* cputime_clock_allowed */ +}; + +/*PAGE + * + * _POSIX_Threads_Manager_initialization + * + * This routine initializes all threads manager related data structures. + * + * Input parameters: + * maximum_pthreads - maximum configured pthreads + * + * Output parameters: NONE + */ + +void _POSIX_Threads_Manager_initialization( + unsigned32 maximum_pthreads +) +{ + _Objects_Initialize_information( + &_POSIX_Threads_Information, + OBJECTS_POSIX_THREADS, + TRUE, + maximum_pthreads, + sizeof( POSIX_Threads_Control ), + TRUE, + _POSIX_PATH_MAX, + TRUE + ); +} + +#ifdef NOT_IMPLEMENTED_YET + +/*PAGE + * + * 3.1.3 Register Fork Handlers, P1003.1c/Draft 10, P1003.1c/Draft 10, p. 27 + */ + +int pthread_atfork( + void (*prepare)(void), + void (*parent)(void), + void (*child)(void) +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +#endif + +/*PAGE + * + * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 + */ + +int pthread_attr_setscope( + pthread_attr_t *attr, + int contentionscope +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + attr->contentionscope = contentionscope; + return 0; +} + +/*PAGE + * + * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 + */ + +int pthread_attr_getscope( + const pthread_attr_t *attr, + int *contentionscope +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + *contentionscope = attr->contentionscope; + return 0; +} + +/*PAGE + * + * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 + */ + +int pthread_attr_setinheritsched( + pthread_attr_t *attr, + int inheritsched +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + attr->inheritsched = inheritsched; + return 0; +} + +/*PAGE + * + * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 + */ + +int pthread_attr_getinheritsched( + const pthread_attr_t *attr, + int *inheritsched +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + *inheritsched = attr->inheritsched; + return 0; +} + +/*PAGE + * + * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 + */ + +int pthread_attr_setschedpolicy( + pthread_attr_t *attr, + int policy +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + attr->schedpolicy = policy; + return 0; +} + +/*PAGE + * + * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 + */ + +int pthread_attr_getschedpolicy( + const pthread_attr_t *attr, + int *policy +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + *policy = attr->schedpolicy; + return 0; +} + +/*PAGE + * + * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 + */ + +int pthread_attr_setschedparam( + pthread_attr_t *attr, + const struct sched_param param +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + attr->schedparam = param; + return 0; +} + +/*PAGE + * + * 13.5.1 Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 + */ + +int pthread_attr_getschedparam( + const pthread_attr_t *attr, + struct sched_param *param +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + *param = attr->schedparam; + return 0; +} + +/*PAGE + * + * 13.5.2 Dynamic Thread Scheduling Parameters Access, + * P1003.1c/Draft 10, p. 124 + */ + +int pthread_getschedparam( + pthread_t thread, + int *policy, + struct sched_param *param +) +{ + pthread_attr_t *attr; /* XXX: really need to get this from the thread */ + + if ( !policy || !param ) + return EINVAL; + + *policy = attr->schedpolicy; + *param = attr->schedparam; + return 0; +} + +/*PAGE + * + * 13.5.2 Dynamic Thread Scheduling Parameters Access, + * P1003.1c/Draft 10, p. 124 + */ + +int pthread_setschedparam( + pthread_t thread, + int policy, + struct sched_param *param +) +{ + /* XXX need to reschedule after doing this to the thread */ + pthread_attr_t *attr; /* XXX: really need to get this from the thread */ + + if ( !param ) + return EINVAL; + + attr->schedpolicy = policy; + attr->schedparam = *param; + return 0; +} + +/*PAGE + * + * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140 + */ + +int pthread_attr_init( + pthread_attr_t *attr +) +{ + if ( !attr ) + return EINVAL; + + *attr = _POSIX_Threads_Default_attributes; + return 0; +} + +/*PAGE + * + * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140 + */ + +int pthread_attr_destroy( + pthread_attr_t *attr +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + attr->is_initialized = FALSE; + return 0; +} + +/*PAGE + * + * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140 + */ + +int pthread_attr_getstacksize( + const pthread_attr_t *attr, + size_t *stacksize +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + *stacksize = attr->stacksize; + return 0; +} + +/*PAGE + * + * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140 + */ + +int pthread_attr_setstacksize( + pthread_attr_t *attr, + size_t stacksize +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + attr->stacksize = stacksize; + return 0; +} + +/*PAGE + * + * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140 + */ + +int pthread_attr_getstackaddr( + const pthread_attr_t *attr, + void **stackaddr +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + *stackaddr = attr->stackaddr; + return 0; +} + +/*PAGE + * + * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140 + */ + +int pthread_attr_setstackaddr( + pthread_attr_t *attr, + void *stackaddr +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + attr->stackaddr = stackaddr; + return 0; +} + +/*PAGE + * + * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140 + */ + +int pthread_attr_getdetachstate( + const pthread_attr_t *attr, + int *detachstate +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + *detachstate = attr->detachstate; + return 0; +} + +/*PAGE + * + * 16.1.1 Thread Creation Attributes, P1003.1c/Draft 10, p, 140 + */ + +int pthread_attr_setdetachstate( + pthread_attr_t *attr, + int detachstate +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + attr->detachstate = detachstate; + return 0; +} + +#ifdef NOT_IMPLEMENTED_YET + +/*PAGE + * + * 16.1.2 Thread Creation, P1003.1c/Draft 10, p. 144 + */ + +int pthread_create( + pthread_t *thread, + const pthread_attr_t *attr, + void (*start_routine)( void * ), + void *arg +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 16.1.3 Wait for Thread Termination, P1003.1c/Draft 10, p. 147 + */ + +int pthread_join( + pthread_t thread, + void **value_ptr +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 16.1.4 Detaching a Thread, P1003.1c/Draft 10, p. 149 + */ + +int pthread_detach( + pthread_t thread +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +#endif + +/*PAGE + * + * 16.1.6 Get Calling Thread's ID, p1003.1c/Draft 10, p. XXX + */ + +pthread_t pthread_self( void ) +{ + return _Thread_Executing->Object.id; +} + +/*PAGE + * + * 16.1.7 Compare Thread IDs, p1003.1c/Draft 10, p. 153 + */ + +int pthread_equal( + pthread_t t1, + pthread_t t2 +) +{ +#ifdef RTEMS_DEBUG + /* XXX may want to do a "get" to make sure both are valid. */ + /* XXX behavior is undefined if not valid pthread_t's */ +#endif + return _Objects_Are_ids_equal( t1, t1 ); +} + +/*PAGE + * + * 16.1.8 Dynamic Package Initialization + */ + +int pthread_once( + pthread_once_t *once_control, + void (*init_routine)(void) +) +{ + /* XXX: Should we implement this routine this way or make it a full */ + /* XXX: fledged object? */ + + if ( !once_control || !init_routine ) + return EINVAL; + + _Thread_Disable_dispatch(); + + if ( !once_control->is_initialized ) { + + once_control->is_initialized = TRUE; + once_control->init_executed = TRUE; + (*init_routine)(); + + } if ( !once_control->init_executed ) { + + once_control->init_executed = TRUE; + (*init_routine)(); + + } + + _Thread_Enable_dispatch(); + + return 0; +} + +#ifdef NOT_IMPLEMENTED_YET + +/*PAGE + * + * 20.1.6 Accessing a Thread CPU-time Clock, P1003.4b/D8, p. 58 + */ + +int pthread_getcpuclockid( + pthread_t pid, + clockid_t *clock_id +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +#endif + +/*PAGE + * + * 20.1.7 CPU-time Clock Thread Creation Attribute, P1003.4b/D8, p. 59 + */ + +int pthread_attr_setcputime( + pthread_attr_t *attr, + int clock_allowed +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + attr->cputime_clock_allowed = clock_allowed; + return 0; +} + +/*PAGE + * + * 20.1.7 CPU-time Clock Thread Creation Attribute, P1003.4b/D8, p. 59 + */ + +int pthread_attr_getcputime( + pthread_attr_t *attr, + int *clock_allowed +) +{ + if ( !attr || !attr->is_initialized ) + return EINVAL; + + *clock_allowed = attr->cputime_clock_allowed; + return 0; +} diff --git a/cpukit/posix/src/sched.c b/cpukit/posix/src/sched.c new file mode 100644 index 0000000000..b131b52397 --- /dev/null +++ b/cpukit/posix/src/sched.c @@ -0,0 +1,127 @@ +/* sched.c + * + * $Id$ + */ + +#include <sched.h> +#include <rtems/score/tod.h> +#include <rtems/score/thread.h> +#include <rtems/posix/priority.h> + +#ifdef NOT_IMPLEMENTED_YET + +/*PAGE + * + * 13.3.1 Set Scheduling Parameters, P1003.1b-1993, p. 252 + * + */ + +int sched_setparam( + pid_t pid, + const struct sched_param *param +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 13.3.2 Set Scheduling Parameters, P1003.1b-1993, p. 253 + */ + +int sched_getparam( + pid_t pid, + const struct sched_param *param +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 13.3.3 Set Scheduling Policy and Scheduling Parameters, + * P1003.1b-1993, p. 254 + */ + +int sched_setscheduler( + pid_t pid, + int policy, + const struct sched_param *param +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 13.3.4 Get Scheduling Policy, P1003.1b-1993, p. 256 + */ + +int sched_getscheduler( + pid_t pid +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +#endif + +/*PAGE + * + * 13.3.6 Get Scheduling Parameter Limits, P1003.1b-1993, p. 258 + */ + +int sched_get_priority_max( + int policy +) +{ + /* XXX error check the policy */ + return POSIX_SCHEDULER_MAXIMUM_PRIORITY; +} + +/*PAGE + * + * 13.3.6 Get Scheduling Parameter Limits, P1003.1b-1993, p. 258 + */ + +int sched_get_priority_min( + int policy +) +{ + /* XXX error check the policy */ + return POSIX_SCHEDULER_MINIMUM_PRIORITY; +} + +/*PAGE + * + * 13.3.6 Get Scheduling Parameter Limits, P1003.1b-1993, p. 258 + */ + +int sched_rr_get_interval( + pid_t pid, + struct timespec *interval +) +{ + time_t us_per_quantum; + + /* XXX eventually should support different time quantums per thread */ + + /* XXX should get for errors? (bad pid) */ + + us_per_quantum = _TOD_Microseconds_per_tick * _Thread_Ticks_per_timeslice; + + interval->tv_sec = us_per_quantum / TOD_MICROSECONDS_PER_SECOND; + interval->tv_nsec = (us_per_quantum % TOD_MICROSECONDS_PER_SECOND) * 1000; + return 0; +} + +/*PAGE + * + * 13.3.5 Yield Processor, P1003.1b-1993, p. 257 + */ + +int sched_yield( void ) +{ + _Thread_Yield_processor(); + return 0; +} diff --git a/cpukit/posix/src/semaphore.c b/cpukit/posix/src/semaphore.c new file mode 100644 index 0000000000..e17124152c --- /dev/null +++ b/cpukit/posix/src/semaphore.c @@ -0,0 +1,576 @@ +/* semaphore.c + * + * $Id$ + */ + +#include <stdarg.h> + +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <semaphore.h> +#include <limits.h> + +#include <rtems/system.h> +#include <rtems/score/object.h> +#include <rtems/posix/semaphore.h> +#include <rtems/posix/time.h> + +/*PAGE + * + * _POSIX_Semaphore_Manager_initialization + * + * This routine initializes all semaphore manager related data structures. + * + * Input parameters: + * maximum_semaphores - maximum configured semaphores + * + * Output parameters: NONE + */ + +void _POSIX_Semaphore_Manager_initialization( + unsigned32 maximum_semaphores +) +{ + _Objects_Initialize_information( + &_POSIX_Semaphore_Information, + OBJECTS_POSIX_SEMAPHORES, + TRUE, + maximum_semaphores, + sizeof( POSIX_Semaphore_Control ), + TRUE, + _POSIX_PATH_MAX, + FALSE + ); +} + +/*PAGE + * + * _POSIX_Semaphore_Create_support + */ + +int _POSIX_Semaphore_Create_support( + const char *name, + int pshared, + unsigned int value, + POSIX_Semaphore_Control **the_sem +) +{ + POSIX_Semaphore_Control *the_semaphore; + CORE_semaphore_Attributes *the_sem_attr; + + _Thread_Disable_dispatch(); + + the_semaphore = _POSIX_Semaphore_Allocate(); + + if ( !the_semaphore ) { + _Thread_Enable_dispatch(); + seterrno( ENOMEM ); + return -1; + } + + if ( pshared == PTHREAD_PROCESS_SHARED && + !( _Objects_MP_Allocate_and_open( &_POSIX_Semaphore_Information, 0, + the_semaphore->Object.id, FALSE ) ) ) { + _POSIX_Semaphore_Free( the_semaphore ); + _Thread_Enable_dispatch(); + seterrno( EAGAIN ); + return -1; + } + + the_semaphore->process_shared = pshared; + + if ( name ) { + the_semaphore->named = TRUE; + the_semaphore->open_count = 1; + the_semaphore->linked = TRUE; + } + else + the_semaphore->named = FALSE; + + the_sem_attr = &the_semaphore->Semaphore.Attributes; + + /* XXX + * + * Note should this be based on the current scheduling policy? + */ + + the_sem_attr->discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO; + + _CORE_semaphore_Initialize( + &the_semaphore->Semaphore, + OBJECTS_POSIX_SEMAPHORES, + the_sem_attr, + value, + 0 /* XXX - proxy_extract_callout is unused */ + ); + + /* XXX - need Names to be a string!!! */ + _Objects_Open( + &_POSIX_Semaphore_Information, + &the_semaphore->Object, + (char *) name + ); + + *the_sem = the_semaphore; + + if ( pshared == PTHREAD_PROCESS_SHARED ) + _POSIX_Semaphore_MP_Send_process_packet( + POSIX_SEMAPHORE_MP_ANNOUNCE_CREATE, + the_semaphore->Object.id, + (char *) name, + 0 /* proxy id - Not used */ + ); + + _Thread_Enable_dispatch(); + return 0; +} + + +/*PAGE + * + * 11.2.1 Initialize an Unnamed Semaphore, P1003.1b-1993, p.219 + */ + +int sem_init( + sem_t *sem, + int pshared, + unsigned int value +) +{ + int status; + POSIX_Semaphore_Control *the_semaphore; + + status = _POSIX_Semaphore_Create_support( + NULL, + pshared, + value, + &the_semaphore + ); + + if ( status != -1 ) + *sem = the_semaphore->Object.id; + + return status; +} + +/*PAGE + * + * 11.2.2 Destroy an Unnamed Semaphore, P1003.1b-1993, p.220 + */ + +int sem_destroy( + sem_t *sem +) +{ + register POSIX_Semaphore_Control *the_semaphore; + Objects_Locations location; + + the_semaphore = _POSIX_Semaphore_Get( sem, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + /* + * Undefined operation on a named semaphore. + */ + + if ( the_semaphore->named == TRUE ) { + seterrno( EINVAL ); + return( -1 ); + } + + _Objects_Close( &_POSIX_Semaphore_Information, &the_semaphore->Object ); + + _CORE_semaphore_Flush( + &the_semaphore->Semaphore, + _POSIX_Semaphore_MP_Send_object_was_deleted, + -1 /* XXX should also seterrno -> EINVAL */ + ); + + _POSIX_Semaphore_Free( the_semaphore ); + + if ( the_semaphore->process_shared == PTHREAD_PROCESS_SHARED ) { + + _Objects_MP_Close( + &_POSIX_Semaphore_Information, + the_semaphore->Object.id + ); + + _POSIX_Semaphore_MP_Send_process_packet( + POSIX_SEMAPHORE_MP_ANNOUNCE_DELETE, + the_semaphore->Object.id, + 0, /* Not used */ + 0 /* Not used */ + ); + } + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 11.2.3 Initialize/Open a Named Semaphore, P1003.1b-1993, p.221 + * + * NOTE: When oflag is O_CREAT, then optional third and fourth + * parameters must be present. + */ + +sem_t *sem_open( + const char *name, + int oflag, + ... + /* mode_t mode, */ + /* unsigned int value */ +) +{ + va_list arg; + mode_t mode; + unsigned int value; + int status; + Objects_Id the_semaphore_id; + POSIX_Semaphore_Control *the_semaphore; + + + if ( oflag & O_CREAT ) { + va_start(arg, oflag); + mode = (mode_t) va_arg( arg, mode_t * ); + value = (unsigned int) va_arg( arg, unsigned int * ); + va_end(arg); + } + + status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id ); + + /* + * If the name to id translation worked, then the semaphore exists + * and we can just return a pointer to the id. Otherwise we may + * need to check to see if this is a "semaphore does not exist" + * or some other miscellaneous error on the name. + */ + + if ( status ) { + + if ( status == EINVAL ) { /* name -> ID translation failed */ + if ( !(oflag & O_CREAT) ) { /* willing to create it? */ + seterrno( ENOENT ); + return (sem_t *) -1; + } + /* we are willing to create it */ + } + seterrno( status ); /* some type of error */ + return (sem_t *) -1; + + } else { /* name -> ID translation succeeded */ + + if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) { + seterrno( EEXIST ); + return (sem_t *) -1; + } + + /* + * XXX In this case we need to do an ID->pointer conversion to + * check the mode. This is probably a good place for a subroutine. + */ + + the_semaphore->open_count += 1; + + return (sem_t *)&the_semaphore->Object.id; + + } + + /* XXX verify this comment... + * + * At this point, the semaphore does not exist and everything has been + * checked. We should go ahead and create a semaphore. + */ + + status = _POSIX_Semaphore_Create_support( + name, + TRUE, /* shared across processes */ + value, + &the_semaphore + ); + + if ( status == -1 ) + return (sem_t *) -1; + + return (sem_t *) &the_semaphore->Object.id; + +} + +/*PAGE + * + * _POSIX_Semaphore_Delete + */ + +void _POSIX_Semaphore_Delete( + POSIX_Semaphore_Control *the_semaphore +) +{ + if ( !the_semaphore->linked && !the_semaphore->open_count ) { + _POSIX_Semaphore_Free( the_semaphore ); + + if ( the_semaphore->process_shared == PTHREAD_PROCESS_SHARED ) { + + _Objects_MP_Close( + &_POSIX_Semaphore_Information, + the_semaphore->Object.id + ); + + _POSIX_Semaphore_MP_Send_process_packet( + POSIX_SEMAPHORE_MP_ANNOUNCE_DELETE, + the_semaphore->Object.id, + 0, /* Not used */ + 0 /* Not used */ + ); + } + + } +} + +/*PAGE + * + * 11.2.4 Close a Named Semaphore, P1003.1b-1993, p.224 + */ + +int sem_close( + sem_t *sem +) +{ + register POSIX_Semaphore_Control *the_semaphore; + Objects_Locations location; + + the_semaphore = _POSIX_Semaphore_Get( sem, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + the_semaphore->open_count -= 1; + _POSIX_Semaphore_Delete( the_semaphore ); + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 11.2.5 Remove a Named Semaphore, P1003.1b-1993, p.225 + */ + +int sem_unlink( + const char *name +) +{ + int status; + register POSIX_Semaphore_Control *the_semaphore; + Objects_Id the_semaphore_id; + Objects_Locations location; + + status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id ); + + if ( !status ) { + seterrno( status ); + return -1; + } + + the_semaphore = _POSIX_Semaphore_Get( &the_semaphore_id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + + if ( the_semaphore->process_shared == PTHREAD_PROCESS_SHARED ) { + _Objects_MP_Close( + &_POSIX_Semaphore_Information, + the_semaphore->Object.id + ); + } + + the_semaphore->linked = FALSE; + + _POSIX_Semaphore_Delete( the_semaphore ); + + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * _POSIX_Semaphore_Wait_support + */ + +int _POSIX_Semaphore_Wait_support( + sem_t *sem, + boolean blocking, + Watchdog_Interval timeout +) +{ + register POSIX_Semaphore_Control *the_semaphore; + Objects_Locations location; + + the_semaphore = _POSIX_Semaphore_Get( sem, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + _CORE_semaphore_Seize( + &the_semaphore->Semaphore, + the_semaphore->Object.id, + blocking, + timeout + ); + _Thread_Enable_dispatch(); + return _Thread_Executing->Wait.return_code; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 11.2.6 Lock a Semaphore, P1003.1b-1993, p.226 + * + * NOTE: P1003.4b/D8 adds sem_timedwait(), p. 27 + */ + +int sem_wait( + sem_t *sem +) +{ + return _POSIX_Semaphore_Wait_support( sem, TRUE, THREAD_QUEUE_WAIT_FOREVER ); +} + +/*PAGE + * + * 11.2.6 Lock a Semaphore, P1003.1b-1993, p.226 + * + * NOTE: P1003.4b/D8 adds sem_timedwait(), p. 27 + */ + +int sem_trywait( + sem_t *sem +) +{ + return _POSIX_Semaphore_Wait_support( sem, FALSE, THREAD_QUEUE_WAIT_FOREVER ); +} + +/*PAGE + * + * 11.2.6 Lock a Semaphore, P1003.1b-1993, p.226 + * + * NOTE: P1003.4b/D8 adds sem_timedwait(), p. 27 + */ + +int sem_timedwait( + sem_t *sem, + const struct timespec *timeout +) +{ + return _POSIX_Semaphore_Wait_support( + sem, + TRUE, + _POSIX_Time_Spec_to_interval( timeout ) + ); +} + +/*PAGE + * + * 11.2.7 Unlock a Semaphore, P1003.1b-1993, p.227 + */ + +void POSIX_Semaphore_MP_support( + Thread_Control *the_thread, + Objects_Id id +) +{ + (void) POSIX_MP_NOT_IMPLEMENTED(); +} + + +int sem_post( + sem_t *sem +) +{ + register POSIX_Semaphore_Control *the_semaphore; + Objects_Locations location; + + the_semaphore = _POSIX_Semaphore_Get( sem, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + _CORE_semaphore_Surrender( + &the_semaphore->Semaphore, + the_semaphore->Object.id, + POSIX_Semaphore_MP_support + ); + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} + +/*PAGE + * + * 11.2.8 Get the Value of a Semaphore, P1003.1b-1993, p.229 + */ + +int sem_getvalue( + sem_t *sem, + int *sval +) +{ + register POSIX_Semaphore_Control *the_semaphore; + Objects_Locations location; + + the_semaphore = _POSIX_Semaphore_Get( sem, &location ); + switch ( location ) { + case OBJECTS_ERROR: + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return POSIX_MP_NOT_IMPLEMENTED(); + seterrno( EINVAL ); + return( -1 ); + case OBJECTS_LOCAL: + *sval = _CORE_semaphore_Get_count( &the_semaphore->Semaphore ); + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); +} diff --git a/cpukit/posix/src/time.c b/cpukit/posix/src/time.c new file mode 100644 index 0000000000..cfe980793a --- /dev/null +++ b/cpukit/posix/src/time.c @@ -0,0 +1,193 @@ +/* time.c + * + * $Id$ + */ + +#include <time.h> +#include <rtems/score/tod.h> + +/* + * Seconds from January 1, 1970 to January 1, 1988. Used to account for + * differences between POSIX API and RTEMS core. + */ + +#define POSIX_TIME_SECONDS_1970_THROUGH_1988 \ + (((1987 - 1970 + 1) * TOD_SECONDS_PER_NON_LEAP_YEAR) + \ + (4 * TOD_SECONDS_PER_DAY)) + +/* + * 4.5.1 Get System Time, P1003.1b-1993, p. 91 + */ + +time_t time( + time_t *tloc +) +{ + time_t seconds_since_epoch; + + if ( !_TOD_Is_set() ) { + /* XXX set errno */ + return -1; + } + + /* + * Internally the RTEMS epoch is 1988. This must be taken into account. + */ + + seconds_since_epoch = _TOD_Seconds_since_epoch; + + seconds_since_epoch += POSIX_TIME_SECONDS_1970_THROUGH_1988; + + if ( tloc ) + *tloc = seconds_since_epoch; + + return seconds_since_epoch; +} + +#ifdef NOT_IMPLEMENTED_YET +/* + * 14.2.1 Clocks, P1003.1b-1993, p. 263 + */ + +int clock_settime( + clockid_t clock_id, + const struct timespec *tp +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 14.2.1 Clocks, P1003.1b-1993, p. 263 + */ + +int clock_gettime( + clockid_t clock_id, + struct timespec *tp +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 14.2.1 Clocks, P1003.1b-1993, p. 263 + */ + +int clock_getres( + clockid_t clock_id, + struct timespec *res +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 14.2.2 Create a Per-Process Timer, P1003.1b-1993, p. 264 + */ + +int timer_create( + clockid_t clock_id, + struct sigevent *evp, + timer_t *timerid +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 14.2.3 Delete a Per_process Timer, P1003.1b-1993, p. 266 + */ + +int timer_delete( + timer_t timerid +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267 + */ + +int timer_settime( + timer_t timerid, + int flags, + const struct itimerspec *value, + struct itimerspec *ovalue +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267 + */ + +int timer_gettime( + timer_t timerid, + struct itimerspec *value +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 14.2.4 Per-Process Timers, P1003.1b-1993, p. 267 + */ + +int timer_getoverrun( + timer_t timerid +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 14.2.5 High Resolution Sleep, P1003.1b-1993, p. 269 + */ + +int nanosleep( + const struct timespec *rqtp, + struct timespec *rmtp +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 20.1.3 Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55 + */ + +int clock_getcpuclockid( + pid_t pid, + clockid_t *clock_id +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 20.1.5 CPU-time Clock Attribute Access, P1003.4b/D8, p. 58 + */ + +int clock_setenable_attr( + clockid_t clock_id, + int attr +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/* + * 20.1.5 CPU-time Clock Attribute Access, P1003.4b/D8, p. 58 + */ + +int clock_getenable_attr( + clockid_t clock_id, + int *attr +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +#endif diff --git a/cpukit/posix/src/types.c b/cpukit/posix/src/types.c new file mode 100644 index 0000000000..e6e743ade5 --- /dev/null +++ b/cpukit/posix/src/types.c @@ -0,0 +1,168 @@ +/* types.c + * + * $Id$ + */ + +#include <sys/types.h> + +#ifdef NOT_IMPLEMENTED_YET + +/*PAGE + * + * 4.1.1 Get Process and Parent Process IDs, P1003.1b-1993, p. 83 + */ + +pid_t getpid( void ) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.1.1 Get Process and Parent Process IDs, P1003.1b-1993, p. 83 + */ + +pid_t getppid( void ) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.2.1 Get Real User, Effective User, Ral Group, and Effective Group IDs, + * P1003.1b-1993, p. 84 + */ + +uid_t getuid( void ) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.2.1 Get Real User, Effective User, Ral Group, and Effective Group IDs, + * P1003.1b-1993, p. 84 + */ + +uid_t geteuid( void ) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.2.1 Get Real User, Effective User, Ral Group, and Effective Group IDs, + * P1003.1b-1993, p. 84 + */ + +gid_t getgid( void ) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.2.1 Get Real User, Effective User, Ral Group, and Effective Group IDs, + * P1003.1b-1993, p. 84 + */ + +gid_t getegid( void ) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.2.2 Set User and Group IDs, P1003.1b-1993, p. 84 + */ + +int setuid( + uid_t uid +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.2.2 Set User and Group IDs, P1003.1b-1993, p. 84 + */ + +int setgid( + gid_t gid +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.2.3 Get Supplementary IDs, P1003.1b-1993, p. 86 + */ + +int getgroups( + int gidsetsize, + gid_t grouplist[] +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.2.4 Get User Name, P1003.1b-1993, p. 87 + * + * NOTE: P1003.1c/D10, p. 49 adds getlogin_r(). + */ + +char *getlogin( void ) +{ + return (char *)POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.2.4 Get User Name, P1003.1b-1993, p. 87 + * + * NOTE: P1003.1c/D10, p. 49 adds getlogin_r(). + */ + +char *getlogin_r( void ) +{ + return (char *)POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.3.1 Get Process Group IDs, P1003.1b-1993, p. 89 + */ + +pid_t getpgrp( void ) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.3.2 Create Session and Set Process Group ID, P1003.1b-1993, p. 88 + */ + +pid_t setsid( void ) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +/*PAGE + * + * 4.3.3 Set Process Group ID for Job Control, P1003.1b-1993, p. 89 + */ + +int setpgid( + pid_t pid, + pid_t pgid +) +{ + return POSIX_NOT_IMPLEMENTED(); +} + +#endif diff --git a/cpukit/rtems/include/rtems.h b/cpukit/rtems/include/rtems.h new file mode 100644 index 0000000000..e8826079b9 --- /dev/null +++ b/cpukit/rtems/include/rtems.h @@ -0,0 +1,121 @@ +/* rtems.h + * + * This include file contains information about RTEMS executive that + * is required by the application and is CPU independent. It includes + * two (2) CPU dependent files to tailor its data structures for a + * particular processor. + * + * 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$ + */ + +#ifndef __RTEMS_RTEMS_GENERIC_h +#define __RTEMS_RTEMS_GENERIC_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Unless told otherwise, the RTEMS include files will hide some stuff + * from normal application code. Defining this crosses a boundary which + * is undesirable since it means your application is using RTEMS features + * which are not included in the formally defined and supported API. + * Define this at your own risk. + */ + +#ifndef __RTEMS_VIOLATE_KERNEL_VISIBILITY__ +#define __RTEMS_APPLICATION__ +#endif + +#include <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/types.h> + +#include <rtems/config.h> +#include <rtems/init.h> +#include <rtems/rtems/tasks.h> +#include <rtems/rtems/intr.h> +#include <rtems/rtems/clock.h> +#include <rtems/extension.h> +#include <rtems/rtems/timer.h> +#include <rtems/rtems/sem.h> +#include <rtems/rtems/message.h> +#include <rtems/rtems/event.h> +#include <rtems/rtems/signal.h> +#include <rtems/rtems/event.h> +#include <rtems/rtems/part.h> +#include <rtems/rtems/region.h> +#include <rtems/rtems/dpmem.h> +#include <rtems/io.h> +#include <rtems/fatal.h> +#include <rtems/rtems/ratemon.h> +#include <rtems/rtems/mp.h> + +#include <rtems/rtems/support.h> +#include <rtems/score/sysstate.h> + +#define RTEMS_HAS_HARDWARE_FP CPU_HARDWARE_FP + +/* + * The following define the constants which may be used in name searches. + */ + +#define RTEMS_SEARCH_ALL_NODES OBJECTS_SEARCH_ALL_NODES +#define RTEMS_SEARCH_OTHER_NODES OBJECTS_SEARCH_OTHER_NODES +#define RTEMS_SEARCH_LOCAL_NODE OBJECTS_SEARCH_LOCAL_NODE +#define RTEMS_WHO_AM_I OBJECTS_WHO_AM_I + +/* + * Parameters and return id's for _Objects_Get_next + */ + +#define RTEMS_OBJECT_ID_INITIAL_INDEX OBJECTS_ID_INITIAL_INDEX +#define RTEMS_OBJECT_ID_FINAL_INDEX OBJECTS_ID_FINAL_INDEX + +#define RTEMS_OBJECT_ID_INITIAL(class, node) OBJECTS_ID_INITIAL(class, node) +#define RTEMS_OBJECT_ID_FINAL OBJECTS_ID_FINAL + +/* + * The following constant defines the minimum stack size which every + * thread must exceed. + */ + +#define RTEMS_MINIMUM_STACK_SIZE STACK_MINIMUM_SIZE + +/* + * Constant for indefinite wait. (actually an illegal interval) + */ + +#define RTEMS_NO_TIMEOUT WATCHDOG_NO_TIMEOUT + +/* + * An MPCI must support packets of at least this size. + */ + +#define RTEMS_MINIMUM_PACKET_SIZE MP_PACKET_MINIMUM_PACKET_SIZE + +/* + * The following constant defines the number of unsigned32's + * in a packet which must be converted to native format in a + * heterogeneous system. In packets longer than + * MP_PACKET_MINIMUN_HETERO_CONVERSION unsigned32's, some of the "extra" data + * may a user message buffer which is not automatically endian swapped. + */ + +#define RTEMS_MINIMUN_HETERO_CONVERSION MP_PACKET_MINIMUN_HETERO_CONVERSION + + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/asr.h b/cpukit/rtems/include/rtems/rtems/asr.h new file mode 100644 index 0000000000..31758fc06b --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/asr.h @@ -0,0 +1,112 @@ +/* asr.h + * + * This include file contains all the constants and structures associated + * with the Asynchronous Signal Handler. This Handler provides the low-level + * support required by the Signal 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$ + */ + +#ifndef __RTEMS_ASR_h +#define __RTEMS_ASR_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/modes.h> + +/* + * + * The following type defines the control block used to manage + * each signal set. + */ + +typedef unsigned32 rtems_signal_set; + +/* + * Return type for ASR Handler + */ + +typedef void rtems_asr; + +/* + * The following type corresponds to the applications asynchronous + * signal processing routine. + */ + +typedef rtems_asr ( *rtems_asr_entry )( + rtems_signal_set + ); + +/* + * + * The following defines the control structure used to manage + * signals. Each thread has a copy of this record. + */ + +typedef struct { + boolean is_enabled; /* are ASRs enabled currently? */ + rtems_asr_entry handler; /* address of RTEMS_ASR */ + Modes_Control mode_set; /* RTEMS_ASR mode */ + rtems_signal_set signals_posted; /* signal set */ + rtems_signal_set signals_pending; /* pending signal set */ + unsigned32 nest_level; /* nest level of RTEMS_ASR */ +} ASR_Information; + +/* + * The following constants define the individual signals which may + * be used to compose a signal set. + */ + +#define RTEMS_SIGNAL_0 0x00000001 +#define RTEMS_SIGNAL_1 0x00000002 +#define RTEMS_SIGNAL_2 0x00000004 +#define RTEMS_SIGNAL_3 0x00000008 +#define RTEMS_SIGNAL_4 0x00000010 +#define RTEMS_SIGNAL_5 0x00000020 +#define RTEMS_SIGNAL_6 0x00000040 +#define RTEMS_SIGNAL_7 0x00000080 +#define RTEMS_SIGNAL_8 0x00000100 +#define RTEMS_SIGNAL_9 0x00000200 +#define RTEMS_SIGNAL_10 0x00000400 +#define RTEMS_SIGNAL_11 0x00000800 +#define RTEMS_SIGNAL_12 0x00001000 +#define RTEMS_SIGNAL_13 0x00002000 +#define RTEMS_SIGNAL_14 0x00004000 +#define RTEMS_SIGNAL_15 0x00008000 +#define RTEMS_SIGNAL_16 0x00010000 +#define RTEMS_SIGNAL_17 0x00020000 +#define RTEMS_SIGNAL_18 0x00040000 +#define RTEMS_SIGNAL_19 0x00080000 +#define RTEMS_SIGNAL_20 0x00100000 +#define RTEMS_SIGNAL_21 0x00200000 +#define RTEMS_SIGNAL_22 0x00400000 +#define RTEMS_SIGNAL_23 0x00800000 +#define RTEMS_SIGNAL_24 0x01000000 +#define RTEMS_SIGNAL_25 0x02000000 +#define RTEMS_SIGNAL_26 0x04000000 +#define RTEMS_SIGNAL_27 0x08000000 +#define RTEMS_SIGNAL_28 0x10000000 +#define RTEMS_SIGNAL_29 0x20000000 +#define RTEMS_SIGNAL_30 0x40000000 +#define RTEMS_SIGNAL_31 0x80000000 + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/asr.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/attr.h b/cpukit/rtems/include/rtems/rtems/attr.h new file mode 100644 index 0000000000..8262a3a381 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/attr.h @@ -0,0 +1,84 @@ +/* attr.h + * + * This include file contains all information about the Object Attributes + * 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$ + */ + +#ifndef __RTEMS_ATTRIBUTES_h +#define __RTEMS_ATTRIBUTES_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* types */ + +typedef unsigned32 rtems_attribute; + +/* constants */ + +#define RTEMS_DEFAULT_ATTRIBUTES 0x00000000 + +#define RTEMS_NO_FLOATING_POINT 0x00000000 /* don't use FP HW */ +#define RTEMS_FLOATING_POINT 0x00000001 /* utilize coprocessor */ + +#define RTEMS_LOCAL 0x00000000 /* local resource */ +#define RTEMS_GLOBAL 0x00000002 /* global resource */ + +#define RTEMS_FIFO 0x00000000 /* process RTEMS_FIFO */ +#define RTEMS_PRIORITY 0x00000004 /* process by priority */ + +#define RTEMS_COUNTING_SEMAPHORE 0x00000000 +#define RTEMS_BINARY_SEMAPHORE 0x00000010 + +#define RTEMS_NO_INHERIT_PRIORITY 0x00000000 +#define RTEMS_INHERIT_PRIORITY 0x00000020 + +#define RTEMS_NO_PRIORITY_CEILING 0x00000000 +#define RTEMS_PRIORITY_CEILING 0x00000040 + +#if ( CPU_HARDWARE_FP == TRUE ) +#define ATTRIBUTES_NOT_SUPPORTED 0 +#else +#define ATTRIBUTES_NOT_SUPPORTED RTEMS_FLOATING_POINT +#endif + +#if ( CPU_ALL_TASKS_ARE_FP == TRUE ) +#define ATTRIBUTES_REQUIRED RTEMS_FLOATING_POINT +#else +#define ATTRIBUTES_REQUIRED 0 +#endif + +/* + * _Attributes_Handler_initialization + * + * DESCRIPTION: + * + * This routine performs initialization for this handler. + * + * NOTE: There is no initialization required in C. Conditional compilation + * takes care of this in C. + */ + +#define _Attributes_Handler_initialization() + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/attr.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/clock.h b/cpukit/rtems/include/rtems/rtems/clock.h new file mode 100644 index 0000000000..d7c032a282 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/clock.h @@ -0,0 +1,103 @@ +/* clock.h + * + * This include file contains all the constants and structures associated + * with the Clock Manager. This manager provides facilities to set, obtain, + * and continually update the current date and time. + * + * This manager provides directives to: + * + * + set the current date and time + * + obtain the current date and time + * + announce a clock tick + * + * + * 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$ + */ + +#ifndef __RTEMS_CLOCK_h +#define __RTEMS_CLOCK_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/tod.h> +#include <rtems/rtems/types.h> + +/* + * List of things which can be returned by the rtems_clock_get directive. + */ + +typedef enum { + RTEMS_CLOCK_GET_TOD, + RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH, + RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, + RTEMS_CLOCK_GET_TICKS_PER_SECOND, + RTEMS_CLOCK_GET_TIME_VALUE +} rtems_clock_get_options; + +/* + * Standard flavor style to return TOD in for a rtems_clock_get option. + */ + +typedef struct { + unsigned32 seconds; + unsigned32 microseconds; +} rtems_clock_time_value; + +/* + * rtems_clock_get + * + * DESCRIPTION: + * + * This routine implements the rtems_clock_get directive. It returns + * one of the following: + * + current time of day + * + seconds since epoch + * + ticks since boot + * + ticks per second + */ + +rtems_status_code rtems_clock_get( + rtems_clock_get_options option, + void *time_buffer +); + +/* + * rtems_clock_set + * + * DESCRIPTION: + * + * This routine implements the rtems_clock_set directive. It sets + * the current time of day to that in the time_buffer record. + */ + +rtems_status_code rtems_clock_set( + rtems_time_of_day *time_buffer +); + +/* + * rtems_clock_tick + * + * DESCRIPTION: + * + * This routine implements the rtems_clock_tick directive. It is invoked + * to inform RTEMS of the occurrence of a clock tick. + */ + +rtems_status_code rtems_clock_tick( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/dpmem.h b/cpukit/rtems/include/rtems/rtems/dpmem.h new file mode 100644 index 0000000000..fc580c1a8a --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/dpmem.h @@ -0,0 +1,157 @@ +/* dpmem.h + * + * This include file contains all the constants and structures associated + * with the Dual Ported Memory Manager. This manager provides a mechanism + * for converting addresses between internal and external representations + * for multiple dual-ported memory areas. + * + * Directives provided are: + * + * + create a port + * + get ID of a port + * + delete a port + * + convert external to internal address + * + convert internal to external address + * + * + * 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$ + */ + +#ifndef __RTEMS_DUAL_PORTED_MEMORY_h +#define __RTEMS_DUAL_PORTED_MEMORY_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> + +/* + * The following structure defines the port control block. Each port + * has a control block associated with it. This control block contains + * all information required to support the port related operations. + */ + +typedef struct { + Objects_Control Object; + void *internal_base; /* base internal address */ + void *external_base; /* base external address */ + unsigned32 length; /* length of dual-ported area */ +} Dual_ported_memory_Control; + +/* + * The following define the internal Dual Ported Memory information. + */ + +EXTERN Objects_Information _Dual_ported_memory_Information; + +/* + * _Dual_ported_memory_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Dual_ported_memory_Manager_initialization( + unsigned32 maximum_ports +); + +/* + * rtems_port_create + * + * DESCRIPTION: + * + * This routine implements the rtems_port_create directive. The port + * will have the name name. The port maps onto an area of dual ported + * memory of length bytes which has internal_start and external_start + * as the internal and external starting addresses, respectively. + * It returns the id of the created port in ID. + */ + +rtems_status_code rtems_port_create( + rtems_name name, + void *internal_start, + void *external_start, + unsigned32 length, + Objects_Id *id +); + +/* + * rtems_port_ident + * + * DESCRIPTION: + * + * This routine implements the rtems_port_ident directive. This directive + * returns the port ID associated with name. If more than one port is + * named name, then the port to which the ID belongs is arbitrary. + */ + +rtems_status_code rtems_port_ident( + rtems_name name, + Objects_Id *id +); + +/* + * rtems_port_delete + * + * DESCRIPTION: + * + * This routine implements the rtems_port_delete directive. It deletes + * the port associated with ID. + */ + +rtems_status_code rtems_port_delete( + Objects_Id id +); + +/* + * rtems_port_external_to_internal + * + * DESCRIPTION: + * + * This routine implements the rtems_port_external_to_internal directive. + * It returns the internal port address which maps to the provided + * external port address for the specified port ID. + */ + +rtems_status_code rtems_port_external_to_internal( + Objects_Id id, + void *external, + void **internal +); + +/* + * rtems_port_internal_to_external + * + * DESCRIPTION: + * + * This routine implements the Port_internal_to_external directive. + * It returns the external port address which maps to the provided + * internal port address for the specified port ID. + */ + +rtems_status_code rtems_port_internal_to_external( + Objects_Id id, + void *internal, + void **external +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/dpmem.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/event.h b/cpukit/rtems/include/rtems/rtems/event.h new file mode 100644 index 0000000000..4cd3b1cbea --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/event.h @@ -0,0 +1,174 @@ +/* event.h + * + * This include file contains the information pertaining to the Event + * Manager. This manager provides a high performance method of communication + * and synchronization. + * + * Directives provided are: + * + * + send an event set to a task + * + receive event condition + * + * + * 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$ + */ + +#ifndef __RTEMS_EVENT_h +#define __RTEMS_EVENT_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> +#include <rtems/rtems/types.h> +#include <rtems/rtems/options.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> +#include <rtems/rtems/eventset.h> + +/* + * This constant is passed as the event_in to the + * rtems_event_receive directive to determine which events are pending. + */ + +#define EVENT_CURRENT 0 + +/* + * The following enumerated types indicate what happened while the event + * manager was in the synchronization window. + */ + +typedef enum { + EVENT_SYNC_SYNCHRONIZED, + EVENT_SYNC_NOTHING_HAPPENED, + EVENT_SYNC_TIMEOUT, + EVENT_SYNC_SATISFIED +} Event_Sync_states; + +/* + * Event_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Event_Manager_initialization( void ); + +/* + * rtems_event_send + * + * DESCRIPTION: + * + * This routine implements the rtems_event_send directive. It sends + * event_in to the task specified by ID. If the task is blocked + * waiting to receive events and the posting of event_in satisfies + * the task's event condition, then it is unblocked. + */ + +rtems_status_code rtems_event_send ( + Objects_Id id, + rtems_event_set event_in +); + +/* + * rtems_event_receive + * + * DESCRIPTION: + * + * This routine implements the rtems_event_receive directive. This + * directive is invoked when the calling task wishes to receive + * the event_in event condition. One of the fields in the option_set + * parameter determines whether the receive request is satisfied if + * any or all of the events are pending. If the event condition + * is not satisfied immediately, then the task may block with an + * optional timeout of TICKS clock ticks or return immediately. + * This determination is based on another field in the option_set + * parameter. This directive returns the events received in the + * event_out parameter. + */ + +rtems_status_code rtems_event_receive ( + rtems_event_set event_in, + rtems_option option_set, + rtems_interval ticks, + rtems_event_set *event_out +); + +/* + * _Event_Seize + * + * DESCRIPTION: + * + * This routine determines if the event condition event_in is + * satisfied. If so or if the no_wait option is enabled in option_set, + * then the procedure returns immediately. If neither of these + * conditions is true, then the calling task is blocked with an + * optional timeout of ticks clock ticks. + */ + +void _Event_Seize ( + rtems_event_set event_in, + rtems_option option_set, + rtems_interval ticks, + rtems_event_set *event_out +); + +/* + * _Event_Surrender + * + * DESCRIPTION: + * + * This routine determines if the event condition of the_thread + * has been satisfied. If so, it unblocks the_thread. + */ + +void _Event_Surrender ( + Thread_Control *the_thread +); + +/* + * _Event_Timeout + * + * DESCRIPTION: + * + * This routine is invoked when a task's event receive request + * has not been satisfied after the specified timeout interval. + * The task represented by ID will be unblocked and its status + * code will be set in it's control block to indicate that a timeout + * has occurred. + */ + +void _Event_Timeout ( + Objects_Id id, + void *ignored +); + +/* + * The following defines the synchronization flag used by the + * Event Manager to insure that signals sent to the currently + * executing thread are received properly. + */ + +EXTERN volatile Event_Sync_states _Event_Sync_state; + +#include <rtems/rtems/eventmp.h> +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/event.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/eventmp.h b/cpukit/rtems/include/rtems/rtems/eventmp.h new file mode 100644 index 0000000000..a6f5b912b0 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/eventmp.h @@ -0,0 +1,147 @@ +/* eventmp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the Event 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$ + */ + +#ifndef __RTEMS_EVENT_MP_h +#define __RTEMS_EVENT_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/event.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the list of + * remote event operations. + */ + +typedef enum { + EVENT_MP_SEND_REQUEST = 0, + EVENT_MP_SEND_RESPONSE = 1 +} Event_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote event operations. + */ + +typedef struct { + rtems_packet_prefix Prefix; + Event_MP_Remote_operations operation; + rtems_event_set event_in; +} Event_MP_Packet; + +/* + * _Event_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + * + * This routine is not needed since there are no process + * packets to be sent by this manager. + */ + +/* + * _Event_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +rtems_status_code _Event_MP_Send_request_packet ( + Event_MP_Remote_operations operation, + Objects_Id event_id, + rtems_event_set event_in +); + +/* + * _Event_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _Event_MP_Send_response_packet ( + Event_MP_Remote_operations operation, + Thread_Control *the_thread +); + +/* + * + * _Event_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _Event_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +); + +/* + * _Event_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + * + * This routine is not needed since there are no objects + * deleted by this manager. + */ + +/* + * _Event_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + * + * This routine is not needed since there are no objects + * deleted by this manager. + */ + +/* + * _Event_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a event mp packet. + */ + +Event_MP_Packet *_Event_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/rtems/include/rtems/rtems/eventset.h b/cpukit/rtems/include/rtems/rtems/eventset.h new file mode 100644 index 0000000000..0f3e122e5f --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/eventset.h @@ -0,0 +1,89 @@ +/* eventset.h + * + * This include file contains the information pertaining to the + * Event Sets Handler. This handler provides methods for the manipulation + * of event sets which will be sent and received by tasks. + * + * 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$ + */ + +#ifndef __RTEMS_EVENT_SET_h +#define __RTEMS_EVENT_SET_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The following defines the type used to control event sets. + */ + +typedef unsigned32 rtems_event_set; + +/* + * The following constants define the individual events which may + * be used to compose an event set. + */ + +#define RTEMS_PENDING_EVENTS 0 /* receive pending events */ +#define RTEMS_ALL_EVENTS 0xFFFFFFFF + +#define RTEMS_EVENT_0 0x00000001 +#define RTEMS_EVENT_1 0x00000002 +#define RTEMS_EVENT_2 0x00000004 +#define RTEMS_EVENT_3 0x00000008 +#define RTEMS_EVENT_4 0x00000010 +#define RTEMS_EVENT_5 0x00000020 +#define RTEMS_EVENT_6 0x00000040 +#define RTEMS_EVENT_7 0x00000080 +#define RTEMS_EVENT_8 0x00000100 +#define RTEMS_EVENT_9 0x00000200 +#define RTEMS_EVENT_10 0x00000400 +#define RTEMS_EVENT_11 0x00000800 +#define RTEMS_EVENT_12 0x00001000 +#define RTEMS_EVENT_13 0x00002000 +#define RTEMS_EVENT_14 0x00004000 +#define RTEMS_EVENT_15 0x00008000 +#define RTEMS_EVENT_16 0x00010000 +#define RTEMS_EVENT_17 0x00020000 +#define RTEMS_EVENT_18 0x00040000 +#define RTEMS_EVENT_19 0x00080000 +#define RTEMS_EVENT_20 0x00100000 +#define RTEMS_EVENT_21 0x00200000 +#define RTEMS_EVENT_22 0x00400000 +#define RTEMS_EVENT_23 0x00800000 +#define RTEMS_EVENT_24 0x01000000 +#define RTEMS_EVENT_25 0x02000000 +#define RTEMS_EVENT_26 0x04000000 +#define RTEMS_EVENT_27 0x08000000 +#define RTEMS_EVENT_28 0x10000000 +#define RTEMS_EVENT_29 0x20000000 +#define RTEMS_EVENT_30 0x40000000 +#define RTEMS_EVENT_31 0x80000000 + + +/* + * The following constant is the value of an event set which + * has no events pending. + */ + +#define EVENT_SETS_NONE_PENDING 0 + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/eventset.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/intr.h b/cpukit/rtems/include/rtems/rtems/intr.h new file mode 100644 index 0000000000..8681ccf9e0 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/intr.h @@ -0,0 +1,160 @@ +/* intr.h + * + * This include file contains all the constants and structures associated + * with the Interrupt 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$ + */ + +#ifndef __RTEMS_INTERRUPT_h +#define __RTEMS_INTERRUPT_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/isr.h> + +/* + * Interrupt level type + */ + +typedef ISR_Level rtems_interrupt_level; + +/* + * The following type defines the control block used to manage + * the vectors. + */ + +typedef ISR_Vector_number rtems_vector_number; + +/* + * Return type for ISR Handler + */ + +typedef void rtems_isr; + +/* + * Pointer to an ISR Handler + */ + +typedef rtems_isr ( *rtems_isr_entry )( + rtems_vector_number + ); + +/* + * _Interrupt_Manager_initialization + * + * DESCRIPTION: + * + * This routine initializes the interrupt manager. + * + */ + +void _Interrupt_Manager_initialization( void ); + +/* + * rtems_interrupt_catch + * + * DESCRIPTION: + * + * This routine implements the rtems_interrupt_catch directive. This + * directive installs new_isr_handler as the RTEMS interrupt service + * routine for vector. The previous RTEMS interrupt service + * routine is returned in old_isr_handler. + */ + +rtems_status_code rtems_interrupt_catch( + rtems_isr_entry new_isr_handler, + rtems_vector_number vector, + rtems_isr_entry *old_isr_handler +); + +/* + * rtems_interrupt_disable + * + * DESCRIPTION: + * + * This routine disables all maskable interrupts and returns the + * previous level in _isr_cookie. + */ + +#define rtems_interrupt_disable( _isr_cookie ) \ + _ISR_Disable(_isr_cookie) + +/* + * rtems_interrupt_enable + * + * DESCRIPTION: + * + * This routine enables maskable interrupts to the level indicated + * _isr_cookie. + */ + +#define rtems_interrupt_enable( _isr_cookie ) \ + _ISR_Enable(_isr_cookie) + +/* + * rtems_interrupt_flash + * + * DESCRIPTION: + * + * This routine temporarily enables maskable interrupts to the + * level in _isr_cookie before redisabling them. + */ + +#define rtems_interrupt_flash( _isr_cookie ) \ + _ISR_Flash(_isr_cookie) + +/* + * rtems_interrupt_is_in_progress + * + * DESCRIPTION: + * + * This function returns TRUE if the processor is currently servicing + * and interrupt and FALSE otherwise. A return value of TRUE indicates + * that the caller is an interrupt service routine, NOT a thread. The + * directives available to an interrupt service routine are restricted. + */ + +#define rtems_interrupt_is_in_progress() \ + _ISR_Is_in_progress() + +/* + * rtems_interrupt_cause + * + * DESCRIPTION: + * + * This routine generates an interrupt. + * + * NOTE: No implementation. + */ + +#define rtems_interrupt_cause( _interrupt_to_cause ) + +/* + * rtems_interrupt_cause + * + * DESCRIPTION: + * + * This routine clears the specified interrupt. + * + * NOTE: No implementation. + */ + +#define rtems_interrupt_clear( _interrupt_to_clear ) + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/message.h b/cpukit/rtems/include/rtems/rtems/message.h new file mode 100644 index 0000000000..0469f8ddbf --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/message.h @@ -0,0 +1,317 @@ +/* message.h + * + * This include file contains all the constants and structures associated + * with the Message Queue Manager. This manager provides a mechanism for + * communication and synchronization between tasks using messages. + * + * Directives provided are: + * + * + create a queue + * + get ID of a queue + * + delete a queue + * + put a message at the rear of a queue + * + put a message at the front of a queue + * + broadcast N messages to a queue + * + receive message from a queue + * + flush all messages on a queue + * + * + * 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$ + */ + +#ifndef __RTEMS_MESSAGE_QUEUE_h +#define __RTEMS_MESSAGE_QUEUE_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/types.h> +#include <rtems/score/chain.h> +#include <rtems/score/object.h> +#include <rtems/rtems/attr.h> +#include <rtems/score/threadq.h> +#include <rtems/score/coremsg.h> + +/* + * The following enumerated type details the modes in which a message + * may be submitted to a message queue. The message may be posted + * in a send or urgent fashion. + */ + +typedef enum { + MESSAGE_QUEUE_SEND_REQUEST = 0, + MESSAGE_QUEUE_URGENT_REQUEST = 1 +} Message_queue_Submit_types; + +/* + * The following records define the control block used to manage + * each message queue. + */ + +typedef struct { + Objects_Control Object; + rtems_attribute attribute_set; + CORE_message_queue_Control message_queue; +} Message_queue_Control; + +/* + * The following defines the information control block used to + * manage this class of objects. + */ + +EXTERN Objects_Information _Message_queue_Information; + +/* + * _Message_queue_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Message_queue_Manager_initialization( + unsigned32 maximum_message_queues +); + +/* + * rtems_message_queue_create + * + * DESCRIPTION: + * + * This routine implements the rtems_message_queue_create directive. The + * message queue will have the name name. If the attribute_set indicates + * that the message queue is to be limited in the number of messages + * that can be outstanding, then count indicates the maximum number of + * messages that will be held. It returns the id of the created + * message queue in ID. + */ + +rtems_status_code rtems_message_queue_create( + rtems_name name, + unsigned32 count, + unsigned32 max_message_size, + rtems_attribute attribute_set, + Objects_Id *id +); + +/* + * rtems_message_queue_ident + * + * DESCRIPTION: + * + * This routine implements the rtems_message_queue_ident directive. + * This directive returns the message queue ID associated with NAME. + * If more than one message queue is named name, then the message + * queue to which the ID belongs is arbitrary. node indicates the + * extent of the search for the ID of the message queue named name. + * The search can be limited to a particular node or allowed to + * encompass all nodes. + */ + +rtems_status_code rtems_message_queue_ident( + rtems_name name, + unsigned32 node, + Objects_Id *id +); + +/* + * rtems_message_queue_delete + * + * DESCRIPTION: + * + * This routine implements the rtems_message_queue_delete directive. The + * message queue indicated by ID is deleted. + */ + +rtems_status_code rtems_message_queue_delete( + Objects_Id id +); + +/* + * rtems_message_queue_send + * + * DESCRIPTION: + * + * This routine implements the rtems_message_queue_send directive. + * This directive sends the message buffer to the message queue + * indicated by ID. If one or more tasks is blocked waiting + * to receive a message from this message queue, then one will + * receive the message. The task selected to receive the + * message is based on the task queue discipline algorithm in + * use by this particular message queue. If no tasks are waiting, + * then the message buffer will be placed at the rear of the + * chain of pending messages for this message queue. + */ + +rtems_status_code rtems_message_queue_send( + Objects_Id id, + void *buffer, + unsigned32 size +); + +/* + * rtems_message_queue_urgent + * + * DESCRIPTION: + * + * This routine implements the rtems_message_queue_send directive. + * This directive sends the message buffer to the message queue + * indicated by ID. If one or more tasks is blocked waiting + * to receive a message from this message queue, then one will + * receive the message. The task selected to receive the + * message is based on the task queue discipline algorithm in + * use by this particular message queue. If no tasks are waiting, + * then the message buffer will be placed at the rear of the + * chain of pending messages for this message queue. + */ + +rtems_status_code rtems_message_queue_urgent( + Objects_Id id, + void *buffer, + unsigned32 size +); + +/* + * rtems_message_queue_broadcast + * + * DESCRIPTION: + * + * This routine implements the rtems_message_queue_send directive. + * This directive sends the message buffer to the message queue + * indicated by ID. If one or more tasks is blocked waiting + * to receive a message from this message queue, then one will + * receive the message. The task selected to receive the + * message is based on the task queue discipline algorithm in + * use by this particular message queue. If no tasks are waiting, + * then the message buffer will be placed at the rear of the + * chain of pending messages for this message queue. + */ + +rtems_status_code rtems_message_queue_broadcast( + Objects_Id id, + void *buffer, + unsigned32 size, + unsigned32 *count +); + +/* + * rtems_message_queue_receive + * + * DESCRIPTION: + * + * This routine implements the rtems_message_queue_receive directive. + * This directive is invoked when the calling task wishes to receive + * a message from the message queue indicated by ID. The received + * message is to be placed in buffer. If no messages are outstanding + * and the option_set indicates that the task is willing to block, + * then the task will be blocked until a message arrives or until, + * optionally, timeout clock ticks have passed. + */ + +rtems_status_code rtems_message_queue_receive( + Objects_Id id, + void *buffer, + unsigned32 *size, + unsigned32 option_set, + rtems_interval timeout +); + +/* + * rtems_message_queue_flush + * + * DESCRIPTION: + * + * This routine implements the rtems_message_queue_flush directive. + * This directive takes all outstanding messages for the message + * queue indicated by ID and returns them to the inactive message + * chain. The number of messages flushed is returned in COUNT. + */ + +rtems_status_code rtems_message_queue_flush( + Objects_Id id, + unsigned32 *count +); + +/* + * _Message_queue_Submit + * + * DESCRIPTION: + * + * This routine implements the directives rtems_message_queue_send + * and rtems_message_queue_urgent. It processes a message that is + * to be submitted to the designated message queue. The message will + * either be processed as a send send message which it will be inserted + * at the rear of the queue or it will be processed as an urgent message + * which will be inserted at the front of the queue. + */ + +rtems_status_code _Message_queue_Submit( + Objects_Id id, + void *buffer, + unsigned32 size, + Message_queue_Submit_types submit_type +); + +/* + * _Message_queue_Allocate + * + * DESCRIPTION: + * + * This function allocates a message queue control block from + * the inactive chain of free message queue control blocks. + */ + +Message_queue_Control *_Message_queue_Allocate ( + unsigned32 count, + unsigned32 max_message_size +); + +/* + * _Message_queue_Translate_core_message_queue_return_code + * + * DESCRIPTION: + * + * This function returns a RTEMS status code based on the core message queue + * status code specified. + */ + +rtems_status_code _Message_queue_Translate_core_message_queue_return_code ( + unsigned32 the_message_queue_status +); + +/* + * + * _Message_queue_Core_message_queue_mp_support + * + * Input parameters: + * the_thread - the remote thread the message was submitted to + * id - id of the message queue + * + * Output parameters: NONE + */ + +void _Message_queue_Core_message_queue_mp_support ( + Thread_Control *the_thread, + Objects_Id id +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/message.inl> +#endif +#include <rtems/rtems/msgmp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/modes.h b/cpukit/rtems/include/rtems/rtems/modes.h new file mode 100644 index 0000000000..34a23c7b20 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/modes.h @@ -0,0 +1,89 @@ +/* modes.h + * + * This include file contains all constants and structures associated + * with the RTEMS thread and RTEMS_ASR modes. + * + * 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$ + */ + +#ifndef __RTEMS_MODES_h +#define __RTEMS_MODES_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/isr.h> + +/* + * The following type defines the control block used to manage + * each a mode set. + */ + +typedef unsigned32 Modes_Control; + +/* + * The following constants define the individual modes and masks + * which may be used to compose a mode set and to alter modes. + */ + +#define RTEMS_ALL_MODE_MASKS 0x0000ffff + +#define RTEMS_DEFAULT_MODES 0x00000000 +#define RTEMS_CURRENT_MODE 0 + +#define RTEMS_PREEMPT_MASK 0x00000100 /* preemption bit */ +#define RTEMS_TIMESLICE_MASK 0x00000200 /* timeslice bit */ +#define RTEMS_ASR_MASK 0x00000400 /* RTEMS_ASR enable bit */ +#define RTEMS_INTERRUPT_MASK CPU_MODES_INTERRUPT_MASK + +#define RTEMS_PREEMPT 0x00000000 /* enable preemption */ +#define RTEMS_NO_PREEMPT 0x00000100 /* disable preemption */ + +#define RTEMS_NO_TIMESLICE 0x00000000 /* disable timeslicing */ +#define RTEMS_TIMESLICE 0x00000200 /* enable timeslicing */ + +#define RTEMS_ASR 0x00000000 /* enable RTEMS_ASR */ +#define RTEMS_NO_ASR 0x00000400 /* disable RTEMS_ASR */ + +/* + * The number of bits for interrupt levels is CPU dependent. + * RTEMS supports 0 to 256 levels in bits 0-7 of the mode. + */ + +/*PAGE + * + * RTEMS_INTERRUPT_LEVEL + * + * DESCRIPTION: + * + * This function returns the processor dependent interrupt + * level which corresponds to the requested interrupt level. + * + * NOTE: RTEMS supports 256 interrupt levels using the least + * significant eight bits of MODES.CONTROL. On any + * particular CPU, fewer than 256 levels may be supported. + */ + +#define RTEMS_INTERRUPT_LEVEL( _mode_set ) \ + ( (_mode_set) & RTEMS_INTERRUPT_MASK ) + + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/modes.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/mp.h b/cpukit/rtems/include/rtems/rtems/mp.h new file mode 100644 index 0000000000..079f55b093 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/mp.h @@ -0,0 +1,53 @@ +/* mp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing 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$ + */ + +#ifndef __RTEMS_MP_h +#define __RTEMS_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * + * _Multiprocessing_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Multiprocessing_Manager_initialization ( void ); + +/* + * + * rtems_multiprocessing_announce + * + * DESCRIPTION: + * + * This routine implements the MULTIPROCESSING_ANNOUNCE directive. + * It is invoked by the MPCI layer to indicate that an MPCI packet + * has been received. + */ + +void rtems_multiprocessing_announce ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/msgmp.h b/cpukit/rtems/include/rtems/rtems/msgmp.h new file mode 100644 index 0000000000..070ed6fcaa --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/msgmp.h @@ -0,0 +1,175 @@ +/* msgmp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the Message 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$ + */ + +#ifndef __RTEMS_MESSAGE_QUEUE_MP_h +#define __RTEMS_MESSAGE_QUEUE_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/message.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the list of + * remote message queue operations. + */ + +typedef enum { + MESSAGE_QUEUE_MP_ANNOUNCE_CREATE = 0, + MESSAGE_QUEUE_MP_ANNOUNCE_DELETE = 1, + MESSAGE_QUEUE_MP_EXTRACT_PROXY = 2, + MESSAGE_QUEUE_MP_RECEIVE_REQUEST = 3, + MESSAGE_QUEUE_MP_RECEIVE_RESPONSE = 4, + MESSAGE_QUEUE_MP_SEND_REQUEST = 5, + MESSAGE_QUEUE_MP_SEND_RESPONSE = 6, + MESSAGE_QUEUE_MP_URGENT_REQUEST = 7, + MESSAGE_QUEUE_MP_URGENT_RESPONSE = 8, + MESSAGE_QUEUE_MP_BROADCAST_REQUEST = 9, + MESSAGE_QUEUE_MP_BROADCAST_RESPONSE = 10, + MESSAGE_QUEUE_MP_FLUSH_REQUEST = 11, + MESSAGE_QUEUE_MP_FLUSH_RESPONSE = 12 +} Message_queue_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote message queue operations. + */ + +typedef struct { + rtems_packet_prefix Prefix; + Message_queue_MP_Remote_operations operation; + rtems_name name; + rtems_option option_set; + Objects_Id proxy_id; + unsigned32 count; + unsigned32 size; + unsigned32 pad0; + CORE_message_queue_Buffer Buffer; +} Message_queue_MP_Packet; + +/* + * _Message_queue_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _Message_queue_MP_Send_process_packet ( + Message_queue_MP_Remote_operations operation, + Objects_Id message_queue_id, + rtems_name name, + Objects_Id proxy_id +); + +/* + * _Message_queue_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +rtems_status_code _Message_queue_MP_Send_request_packet ( + Message_queue_MP_Remote_operations operation, + Objects_Id message_queue_id, + void *buffer, + unsigned32 *size_p, + rtems_option option_set, + Watchdog_Interval timeout +); + +/* + * _Message_queue_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _Message_queue_MP_Send_response_packet ( + Message_queue_MP_Remote_operations operation, + Objects_Id message_queue_id, + Thread_Control *the_thread +); + +/* + * + * _Message_queue_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _Message_queue_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +); + +/* + * _Message_queue_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + */ + +void _Message_queue_MP_Send_object_was_deleted ( + Thread_Control *the_proxy +); + +/* + * _Message_queue_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + */ + +void _Message_queue_MP_Send_extract_proxy ( + Thread_Control *the_thread +); + +/* + * _Message_queue_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a message queue mp packet. + */ + +Message_queue_MP_Packet *_Message_queue_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/rtems/include/rtems/rtems/options.h b/cpukit/rtems/include/rtems/rtems/options.h new file mode 100644 index 0000000000..069d7721b3 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/options.h @@ -0,0 +1,53 @@ +/* options.h + * + * This include file contains information which defines the + * options available on many directives. + * + * 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$ + */ + +#ifndef __RTEMS_OPTIONS_h +#define __RTEMS_OPTIONS_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The following type defines the control block used to manage + * option sets. + */ + +typedef unsigned32 rtems_option; + +/* + * The following constants define the individual options which may + * be used to compose an option set. + */ + +#define RTEMS_DEFAULT_OPTIONS 0x00000000 + +#define RTEMS_WAIT 0x00000000 /* wait on resource */ +#define RTEMS_NO_WAIT 0x00000001 /* do not wait on resource */ + +#define RTEMS_EVENT_ALL 0x00000000 /* wait for all events */ +#define RTEMS_EVENT_ANY 0x00000002 /* wait on any event */ + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/options.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/part.h b/cpukit/rtems/include/rtems/rtems/part.h new file mode 100644 index 0000000000..e06a2e4b86 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/part.h @@ -0,0 +1,168 @@ +/* partition.h + * + * This include file contains all the constants and structures associated + * with the Partition Manager. This manager provides facilities to + * dynamically allocate memory in fixed-sized units which are returned + * as buffers. + * + * Directives provided are: + * + * + create a partition + * + get an ID of a partition + * + delete a partition + * + get a buffer from a partition + * + return a buffer to a partition + * + * 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$ + */ + +#ifndef __RTEMS_PARTITION_h +#define __RTEMS_PARTITION_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/address.h> +#include <rtems/score/object.h> +#include <rtems/rtems/attr.h> +#include <rtems/rtems/types.h> + +/* + * The following defines the control block used to manage each partition. + */ + +typedef struct { + Objects_Control Object; + void *starting_address; /* physical address */ + unsigned32 length; /* in bytes */ + unsigned32 buffer_size; /* in bytes */ + rtems_attribute attribute_set; /* attributes */ + unsigned32 number_of_used_blocks; /* or allocated buffers */ + Chain_Control Memory; /* buffer chain */ +} Partition_Control; + +/* + * The following defines the information control block used to + * manage this class of objects. + */ + +EXTERN Objects_Information _Partition_Information; + +/* + * _Partition_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Partition_Manager_initialization( + unsigned32 maximum_partitions +); + +/* + * rtems_partition_create + * + * DESCRIPTION: + * + * This routine implements the rtems_partition_create directive. The + * partition will have the name name. The memory area managed by + * the partition is of length bytes and starts at starting_address. + * The memory area will be divided into as many buffers of + * buffer_size bytes as possible. The attribute_set determines if + * the partition is global or local. It returns the id of the + * created partition in ID. + */ + +rtems_status_code rtems_partition_create( + rtems_name name, + void *starting_address, + unsigned32 length, + unsigned32 buffer_size, + rtems_attribute attribute_set, + Objects_Id *id +); + +/* + * rtems_partition_ident + * + * DESCRIPTION: + * + * This routine implements the rtems_partition_ident directive. + * This directive returns the partition ID associated with name. + * If more than one partition is named name, then the partition + * to which the ID belongs is arbitrary. node indicates the + * extent of the search for the ID of the partition named name. + * The search can be limited to a particular node or allowed to + * encompass all nodes. + */ + +rtems_status_code rtems_partition_ident( + rtems_name name, + unsigned32 node, + Objects_Id *id +); + +/* + * rtems_partition_delete + * + * DESCRIPTION: + * + * This routine implements the rtems_partition_delete directive. The + * partition indicated by ID is deleted. + */ + +rtems_status_code rtems_partition_delete( + Objects_Id id +); + +/* + * rtems_partition_get_buffer + * + * DESCRIPTION: + * + * This routine implements the rtems_partition_get_buffer directive. It + * attempts to allocate a buffer from the partition associated with ID. + * If a buffer is allocated, its address is returned in buffer. + */ + +rtems_status_code rtems_partition_get_buffer( + Objects_Id id, + void **buffer +); + +/* + * rtems_partition_return_buffer + * + * DESCRIPTION: + * + * This routine implements the rtems_partition_return_buffer directive. It + * frees the buffer to the partition associated with ID. The buffer must + * have been previously allocated from the same partition. + */ + +rtems_status_code rtems_partition_return_buffer( + Objects_Id id, + void *buffer +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/part.inl> +#endif +#include <rtems/rtems/partmp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/partmp.h b/cpukit/rtems/include/rtems/rtems/partmp.h new file mode 100644 index 0000000000..fd7d442dd3 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/partmp.h @@ -0,0 +1,161 @@ +/* partmp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the Partition 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$ + */ + +#ifndef __RTEMS_PARTITION_MP_h +#define __RTEMS_PARTITION_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/score/thread.h> + +#include <rtems/rtems/part.h> + +/* + * The following enumerated type defines the list of + * remote partition operations. + */ + +typedef enum { + PARTITION_MP_ANNOUNCE_CREATE = 0, + PARTITION_MP_ANNOUNCE_DELETE = 1, + PARTITION_MP_EXTRACT_PROXY = 2, + PARTITION_MP_GET_BUFFER_REQUEST = 3, + PARTITION_MP_GET_BUFFER_RESPONSE = 4, + PARTITION_MP_RETURN_BUFFER_REQUEST = 5, + PARTITION_MP_RETURN_BUFFER_RESPONSE = 6 +} Partition_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote partition operations. + */ + +typedef struct { + rtems_packet_prefix Prefix; + Partition_MP_Remote_operations operation; + rtems_name name; + void *buffer; + Objects_Id proxy_id; +} Partition_MP_Packet; + +/* + * _Partition_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _Partition_MP_Send_process_packet ( + Partition_MP_Remote_operations operation, + Objects_Id partition_id, + rtems_name name, + Objects_Id proxy_id +); + +/* + * _Partition_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +rtems_status_code _Partition_MP_Send_request_packet ( + Partition_MP_Remote_operations operation, + Objects_Id partition_id, + void *buffer +); + +/* + * _Partition_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _Partition_MP_Send_response_packet ( + Partition_MP_Remote_operations operation, + Objects_Id partition_id, + Thread_Control *the_thread +); + +/* + * + * _Partition_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _Partition_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +); + +/* + * _Partition_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + * + * This routine is not needed by the Partition since a partition + * cannot be deleted when buffers are in use. + */ + +/* + * _Partition_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + */ + +void _Partition_MP_Send_extract_proxy ( + Thread_Control *the_thread +); + +/* + * _Partition_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a partition mp packet. + */ + +Partition_MP_Packet *_Partition_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/rtems/include/rtems/rtems/ratemon.h b/cpukit/rtems/include/rtems/rtems/ratemon.h new file mode 100644 index 0000000000..a85bbcdc09 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/ratemon.h @@ -0,0 +1,185 @@ +/* ratemon.h + * + * This include file contains all the constants, structures, and + * prototypes associated with the Rate Monotonic Manager. This manager + * provides facilities to implement tasks which execute in a periodic fashion. + * + * Directives provided are: + * + * + create a rate monotonic timer + * + cancel a period + * + delete a rate monotonic timer + * + conclude current and start the next period + * + * 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$ + */ + +#ifndef __RTEMS_RATE_MONOTONIC_h +#define __RTEMS_RATE_MONOTONIC_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the states in which a + * period may be. + */ + +typedef enum { + RATE_MONOTONIC_INACTIVE, /* off chain, never initialized */ + RATE_MONOTONIC_OWNER_IS_BLOCKING, /* on chain, owner is blocking on it */ + RATE_MONOTONIC_ACTIVE, /* on chain, running continuously */ + RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING, /* on chain, expired while owner was */ + /* was blocking on it */ + RATE_MONOTONIC_EXPIRED /* off chain, will be reset by next */ + /* rtems_rate_monotonic_period */ +} Rate_Monotonic_Period_states; + +/* + * The following constant is the interval passed to the rate_monontonic_period + * directive to obtain status information. + */ + +#define RTEMS_PERIOD_STATUS WATCHDOG_NO_TIMEOUT + +/* + * The following structure defines the control block used to manage + * each period. + */ + +typedef struct { + Objects_Control Object; + Watchdog_Control Timer; + Rate_Monotonic_Period_states state; + Thread_Control *owner; +} Rate_monotonic_Control; + +EXTERN Objects_Information _Rate_monotonic_Information; + +/* + * _Rate_monotonic_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Rate_monotonic_Manager_initialization( + unsigned32 maximum_periods +); + +/* + * rtems_rate_monotonic_create + * + * DESCRIPTION: + * + * This routine implements the rate_monotonic_create directive. The + * period will have the name name. It returns the id of the + * created period in ID. + */ + +rtems_status_code rtems_rate_monotonic_create( + rtems_name name, + Objects_Id *id +); + +/* + * rtems_rate_monotonic_ident + * + * DESCRIPTION: + * + * This routine implements the rtems_rate_monotonic_ident directive. + * This directive returns the period ID associated with name. + * If more than one period is named name, then the period + * to which the ID belongs is arbitrary. + */ + +rtems_status_code rtems_rate_monotonic_ident( + rtems_name name, + Objects_Id *id +); + +/* + * rtems_rate_monotonic_cancel + * + * DESCRIPTION: + * + * This routine implements the rtems_rate_monotonic_cancel directive. This + * directive stops the period associated with ID from continuing to + * run. + */ + +rtems_status_code rtems_rate_monotonic_cancel( + Objects_Id id +); + +/* + * rtems_rate_monotonic_delete + * + * DESCRIPTION: + * + * This routine implements the rtems_rate_monotonic_delete directive. The + * period indicated by ID is deleted. + */ + +rtems_status_code rtems_rate_monotonic_delete( + Objects_Id id +); + +/* + * rtems_rate_monotonic_period + * + * DESCRIPTION: + * + * This routine implements the rtems_rate_monotonic_period directive. When + * length is non-zero, this directive initiates the period associated with + * ID from continuing for a period of length. If length is zero, then + * result is set to indicate the current state of the period. + */ + +rtems_status_code rtems_rate_monotonic_period( + Objects_Id id, + rtems_interval length +); + +/* + * _Rate_monotonic_Timeout + * + * DESCRIPTION: + * + * This routine is invoked when the period represented + * by ID expires. If the task which owns this period is blocked + * waiting for the period to expire, then it is readied and the + * period is restarted. If the owning task is not waiting for the + * period to expire, then the period is placed in the EXPIRED + * state and not restarted. + */ + +void _Rate_monotonic_Timeout ( + Objects_Id id, + void *ignored +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/ratemon.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/region.h b/cpukit/rtems/include/rtems/rtems/region.h new file mode 100644 index 0000000000..7ee2658cd2 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/region.h @@ -0,0 +1,234 @@ +/* region.h + * + * This include file contains all the constants and structures associated + * with the Region Manager. This manager provides facilities to dynamically + * allocate memory in variable sized units which are returned as segments. + * + * Directives provided are: + * + * + create a region + * + get an ID of a region + * + delete a region + * + get a segment from a region + * + return a segment to a region + * + * 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$ + */ + +#ifndef __RTEMS_REGION_h +#define __RTEMS_REGION_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> +#include <rtems/score/threadq.h> +#include <rtems/score/heap.h> +#include <rtems/debug.h> +#include <rtems/rtems/attr.h> +#include <rtems/rtems/types.h> + +/* + * The following records define the control block used to manage + * each region. + */ + +typedef struct { + Objects_Control Object; + Thread_queue_Control Wait_queue; /* waiting threads */ + void *starting_address; /* physical start addr */ + unsigned32 length; /* physical length(bytes) */ + unsigned32 page_size; /* in bytes */ + unsigned32 maximum_segment_size; /* in bytes */ + rtems_attribute attribute_set; + unsigned32 number_of_used_blocks; /* blocks allocated */ + Heap_Control Memory; +} Region_Control; + +/* + * The following defines the information control block used to + * manage this class of objects. + */ + +EXTERN Objects_Information _Region_Information; + +/* + * _Region_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Region_Manager_initialization( + unsigned32 maximum_regions +); + +/* + * rtems_region_create + * + * DESCRIPTION: + * + * This routine implements the rtems_region_create directive. The + * region will have the name name. The memory area managed by + * the region is of length bytes and starts at starting_address. + * The memory area will be divided into as many allocatable units of + * page_size bytes as possible. The attribute_set determines which + * thread queue discipline is used by the region. It returns the + * id of the created region in ID. + */ + +rtems_status_code rtems_region_create( + rtems_name name, + void *starting_address, + unsigned32 length, + unsigned32 page_size, + rtems_attribute attribute_set, + Objects_Id *id +); + +/* + * rtems_region_extend + * + * DESCRIPTION: + * + * This routine implements the rtems_region_extend directive. The + * region will have the name name. The memory area managed by + * the region will be attempted to be grown by length bytes using + * the memory starting at starting_address. + */ + +rtems_status_code rtems_region_extend( + Objects_Id id, + void *starting_address, + unsigned32 length +); + +/* + * rtems_region_ident + * + * DESCRIPTION: + * + * This routine implements the rtems_region_ident directive. + * This directive returns the region ID associated with name. + * If more than one region is named name, then the region + * to which the ID belongs is arbitrary. + */ + +rtems_status_code rtems_region_ident( + rtems_name name, + Objects_Id *id +); + +/* + * rtems_region_delete + * + * DESCRIPTION: + * + * This routine implements the rtems_region_delete directive. The + * region indicated by ID is deleted. + */ + +rtems_status_code rtems_region_delete( + Objects_Id id +); + +/* + * rtems_region_get_segment + * + * DESCRIPTION: + * + * This routine implements the rtems_region_get_segment directive. It + * attempts to allocate a segment from the region associated with ID. + * If a segment of the requested size can be allocated, its address + * is returned in segment. If no segment is available, then the task + * may return immediately or block waiting for a segment with an optional + * timeout of timeout clock ticks. Whether the task blocks or returns + * immediately is based on the no_wait option in the option_set. + */ + +rtems_status_code rtems_region_get_segment( + Objects_Id id, + unsigned32 size, + rtems_option option_set, + rtems_interval timeout, + void **segment +); + +/* + * rtems_region_get_segment_size + * + * DESCRIPTION: + * + * This routine implements the rtems_region_get_segment_size directive. It + * returns the size in bytes of the specified user memory area. + */ + +rtems_status_code rtems_region_get_segment_size( + Objects_Id id, + void *segment, + unsigned32 *size +); + +/* + * rtems_region_return_segment + * + * DESCRIPTION: + * + * This routine implements the rtems_region_return_segment directive. It + * frees the segment to the region associated with ID. The segment must + * have been previously allocated from the same region. If freeing the + * segment results in enough memory being available to satisfy the + * rtems_region_get_segment of the first blocked task, then that task and as + * many subsequent tasks as possible will be unblocked with their requests + * satisfied. + */ + +rtems_status_code rtems_region_return_segment( + Objects_Id id, + void *segment +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/region.inl> +#endif +#include <rtems/rtems/regionmp.h> + +/* + * _Region_Debug_Walk + * + * DESCRIPTION: + * + * This routine is invoked to verify the integrity of a heap associated + * with the_region. + */ + +#ifdef RTEMS_DEBUG + +#define _Region_Debug_Walk( _the_region, _source ) \ + do { \ + if ( _Debug_Is_enabled( RTEMS_DEBUG_REGION ) ) \ + _Heap_Walk( &(_the_region)->Memory, _source, FALSE ); \ + } while ( 0 ) + +#else + +#define _Region_Debug_Walk( _the_region, _source ) + +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/regionmp.h b/cpukit/rtems/include/rtems/rtems/regionmp.h new file mode 100644 index 0000000000..b59fe9235e --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/regionmp.h @@ -0,0 +1,166 @@ +/* regionmp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the Region 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$ + */ + +#ifndef __RTEMS_REGION_MP_h +#define __RTEMS_REGION_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> + +#include <rtems/rtems/options.h> +#include <rtems/rtems/region.h> + +/* + * The following enumerated type defines the list of + * remote region operations. + */ + +typedef enum { + REGION_MP_ANNOUNCE_CREATE = 0, + REGION_MP_ANNOUNCE_DELETE = 1, + REGION_MP_EXTRACT_PROXY = 2, + REGION_MP_GET_SEGMENT_REQUEST = 3, + REGION_MP_GET_SEGMENT_RESPONSE = 4, + REGION_MP_RETURN_SEGMENT_REQUEST = 5, + REGION_MP_RETURN_SEGMENT_RESPONSE = 6 +} Region_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote region operations. + */ + +typedef struct { + rtems_packet_prefix Prefix; + Region_MP_Remote_operations operation; + rtems_name name; + rtems_option option_set; + unsigned32 size; + Objects_Id proxy_id; + void *segment; +} Region_MP_Packet; + +/* + * _Region_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _Region_MP_Send_process_packet ( + Region_MP_Remote_operations operation, + Objects_Id region_id, + rtems_name name, + Objects_Id proxy_id +); + +/* + * _Region_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +rtems_status_code _Region_MP_Send_request_packet ( + Region_MP_Remote_operations operation, + Objects_Id region_id, + void *segment, + unsigned32 size, + rtems_option option_set, + rtems_interval timeout +); + +/* + * _Region_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _Region_MP_Send_response_packet ( + Region_MP_Remote_operations operation, + Objects_Id region_id, + Thread_Control *the_thread +); + +/* + * + * _Region_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _Region_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +); + +/* + * _Region_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + * + * This routine is not needed by the Region since a region + * cannot be deleted when segments are in use. + */ + +/* + * _Region_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + */ + +void _Region_MP_Send_extract_proxy ( + Thread_Control *the_thread +); + +/* + * _Region_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a region mp packet. + */ + +Region_MP_Packet *_Region_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/rtems/include/rtems/rtems/rtemsapi.h b/cpukit/rtems/include/rtems/rtems/rtemsapi.h new file mode 100644 index 0000000000..e43de773fd --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/rtemsapi.h @@ -0,0 +1,34 @@ +/* + * RTEMS API Support + * + * NOTE: + * + * 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$ + */ + +#ifndef __RTEMS_API_h +#define __RTEMS_API_h + +#include <rtems/config.h> + +/*PAGE + * + * _RTEMS_API_Initialize + * + * XXX + */ + +void _RTEMS_API_Initialize( + rtems_configuration_table *configuration_table +); + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/sem.h b/cpukit/rtems/include/rtems/rtems/sem.h new file mode 100644 index 0000000000..c4f8574b17 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/sem.h @@ -0,0 +1,248 @@ +/* semaphore.h + * + * This include file contains all the constants and structures associated + * with the Semaphore Manager. This manager utilizes standard Dijkstra + * counting semaphores to provide synchronization and mutual exclusion + * capabilities. + * + * Directives provided are: + * + * + create a semaphore + * + get an ID of a semaphore + * + delete a semaphore + * + acquire a semaphore + * + release a semaphore + * + * 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$ + */ + +#ifndef __RTEMS_SEMAPHORE_h +#define __RTEMS_SEMAPHORE_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/types.h> +#include <rtems/rtems/support.h> +#include <rtems/rtems/tasks.h> +#include <rtems/rtems/attr.h> +#include <rtems/score/coremutex.h> +#include <rtems/score/object.h> +#include <rtems/score/coresem.h> +#include <rtems/score/threadq.h> + +/* + * The following defines the control block used to manage each semaphore. + */ + +typedef struct { + Objects_Control Object; + rtems_attribute attribute_set; + union { + CORE_mutex_Control mutex; + CORE_semaphore_Control semaphore; + } Core_control; +} Semaphore_Control; + +/* + * The following defines the information control block used to manage + * this class of objects. + */ + +EXTERN Objects_Information _Semaphore_Information; + +/* + * _Semaphore_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Semaphore_Manager_initialization( + unsigned32 maximum_semaphores +); + +/* + * rtems_semaphore_create + * + * DESCRIPTION: + * + * This routine implements the rtems_semaphore_create directive. The + * semaphore will have the name name. The starting count for + * the semaphore is count. The attribute_set determines if + * the semaphore is global or local and the thread queue + * discipline. It returns the id of the created semaphore in ID. + */ + +rtems_status_code rtems_semaphore_create( + rtems_name name, + unsigned32 count, + rtems_attribute attribute_set, + rtems_task_priority priority_ceiling, + rtems_id *id +); + +/* + * rtems_semaphore_ident + * + * DESCRIPTION: + * + * This routine implements the rtems_semaphore_ident directive. + * This directive returns the semaphore ID associated with name. + * If more than one semaphore is named name, then the semaphore + * to which the ID belongs is arbitrary. node indicates the + * extent of the search for the ID of the semaphore named name. + * The search can be limited to a particular node or allowed to + * encompass all nodes. + */ + +rtems_status_code rtems_semaphore_ident( + rtems_name name, + unsigned32 node, + rtems_id *id +); + +/* + * rtems_semaphore_delete + * + * DESCRIPTION: + * + * This routine implements the rtems_semaphore_delete directive. The + * semaphore indicated by ID is deleted. + */ + +rtems_status_code rtems_semaphore_delete( + rtems_id id +); + +/* + * rtems_semaphore_obtain + * + * DESCRIPTION: + * + * This routine implements the rtems_semaphore_obtain directive. It + * attempts to obtain a unit from the semaphore associated with ID. + * If a unit can be allocated, the calling task will return immediately. + * If no unit is available, then the task may return immediately or + * block waiting for a unit with an optional timeout of timeout + * clock ticks. Whether the task blocks or returns immediately + * is based on the RTEMS_NO_WAIT option in the option_set. + */ + +rtems_status_code rtems_semaphore_obtain( + rtems_id id, + unsigned32 option_set, + rtems_interval timeout +); + +/* + * rtems_semaphore_release + * + * DESCRIPTION: + * + * This routine implements the rtems_semaphore_release directive. It + * frees a unit to the semaphore associated with ID. If a task was + * blocked waiting for a unit from this semaphore, then that task will + * be readied and the unit given to that task. Otherwise, the unit + * will be returned to the semaphore. + */ + +rtems_status_code rtems_semaphore_release( + rtems_id id +); + +/* + * _Semaphore_Seize + * + * DESCRIPTION: + * + * This routine attempts to receive a unit from the_semaphore. + * If a unit is available or if the RTEMS_NO_WAIT option is enabled in + * option_set, then the routine returns. Otherwise, the calling task + * is blocked until a unit becomes available. + */ + +boolean _Semaphore_Seize( + Semaphore_Control *the_semaphore, + unsigned32 option_set +); + +/* + * _Semaphore_Translate_core_mutex_return_code + * + * DESCRIPTION: + * + * This function returns a RTEMS status code based on the mutex + * status code specified. + */ + +rtems_status_code _Semaphore_Translate_core_mutex_return_code ( + unsigned32 the_mutex_status +); + +/* + * _Semaphore_Translate_core_semaphore_return_code + * + * DESCRIPTION: + * + * This function returns a RTEMS status code based on the semaphore + * status code specified. + */ + +rtems_status_code _Semaphore_Translate_core_semaphore_return_code ( + unsigned32 the_mutex_status +); + +/*PAGE + * + * _Semaphore_Core_mutex_mp_support + * + * DESCRIPTION: + * + * This function processes the global actions necessary for remote + * accesses to a global semaphore based on a core mutex. This function + * is called by the core. + */ + +void _Semaphore_Core_mutex_mp_support ( + Thread_Control *the_thread, + rtems_id id +); + +/*PAGE + * + * _Semaphore_Core_mp_support + * + * DESCRIPTION: + * + * This function processes the global actions necessary for remote + * accesses to a global semaphore based on a core semaphore. This function + * is called by the core. + */ + +void _Semaphore_Core_semaphore_mp_support ( + Thread_Control *the_thread, + rtems_id id +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/sem.inl> +#endif +#include <rtems/rtems/semmp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/semmp.h b/cpukit/rtems/include/rtems/rtems/semmp.h new file mode 100644 index 0000000000..4d9618256d --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/semmp.h @@ -0,0 +1,163 @@ +/* semmp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the Semaphore 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$ + */ + +#ifndef __RTEMS_SEMAPHORE_MP_h +#define __RTEMS_SEMAPHORE_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/rtems/sem.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the list of + * remote semaphore operations. + */ + +typedef enum { + SEMAPHORE_MP_ANNOUNCE_CREATE = 0, + SEMAPHORE_MP_ANNOUNCE_DELETE = 1, + SEMAPHORE_MP_EXTRACT_PROXY = 2, + SEMAPHORE_MP_OBTAIN_REQUEST = 3, + SEMAPHORE_MP_OBTAIN_RESPONSE = 4, + SEMAPHORE_MP_RELEASE_REQUEST = 5, + SEMAPHORE_MP_RELEASE_RESPONSE = 6 +} Semaphore_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote semaphore operations. + */ + +typedef struct { + rtems_packet_prefix Prefix; + Semaphore_MP_Remote_operations operation; + rtems_name name; + rtems_option option_set; + Objects_Id proxy_id; +} Semaphore_MP_Packet; + +/* + * _Semaphore_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _Semaphore_MP_Send_process_packet ( + Semaphore_MP_Remote_operations operation, + Objects_Id semaphore_id, + rtems_name name, + Objects_Id proxy_id +); + +/* + * _Semaphore_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +rtems_status_code _Semaphore_MP_Send_request_packet ( + Semaphore_MP_Remote_operations operation, + Objects_Id semaphore_id, + rtems_option option_set, + rtems_interval timeout +); + +/* + * _Semaphore_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _Semaphore_MP_Send_response_packet ( + Semaphore_MP_Remote_operations operation, + Objects_Id semaphore_id, + Thread_Control *the_thread +); + +/* + * + * _Semaphore_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _Semaphore_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +); + +/* + * _Semaphore_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + */ + +void _Semaphore_MP_Send_object_was_deleted ( + Thread_Control *the_proxy +); + +/* + * _Semaphore_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + */ + +void _Semaphore_MP_Send_extract_proxy ( + Thread_Control *the_thread +); + +/* + * _Semaphore_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a semaphore mp packet. + */ + +Semaphore_MP_Packet *_Semaphore_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/rtems/include/rtems/rtems/signal.h b/cpukit/rtems/include/rtems/rtems/signal.h new file mode 100644 index 0000000000..e72bcb2dbc --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/signal.h @@ -0,0 +1,83 @@ +/* signal.h + * + * This include file contains all the constants and structures associated + * with the Signal Manager. This manager provides capabilities required + * for asynchronous communication between tasks via signal sets. + * + * Directives provided are: + * + * + establish an asynchronous signal routine + * + send a signal set to a task + * + * 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$ + */ + +#ifndef __RTEMS_SIGNAL_h +#define __RTEMS_SIGNAL_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/asr.h> +#include <rtems/rtems/modes.h> +#include <rtems/score/object.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/types.h> + +/* + * _Signal_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Signal_Manager_initialization( void ); + +/* + * rtems_signal_catch + * + * DESCRIPTION: + * + * This routine implements the rtems_signal_catch directive. This directive + * is used to establish asr_handler as the Asynchronous Signal Routine + * (RTEMS_ASR) for the calling task. The asr_handler will execute with a + * mode of mode_set. + */ + +rtems_status_code rtems_signal_catch( + rtems_asr_entry asr_handler, + rtems_mode mode_set +); + +/* + * rtems_signal_send + * + * DESCRIPTION: + * + * This routine implements the rtems_signal_send directive. This directive + * sends the signal_set to the task specified by ID. + */ + +rtems_status_code rtems_signal_send( + Objects_Id id, + rtems_signal_set signal_set +); + +#include <rtems/rtems/signalmp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/signalmp.h b/cpukit/rtems/include/rtems/rtems/signalmp.h new file mode 100644 index 0000000000..91d36b729f --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/signalmp.h @@ -0,0 +1,147 @@ +/* signalmp.h + * + * This include file contains all the constants and structures associated + * with the Multiprocessing Support in the Signal 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$ + */ + +#ifndef __RTEMS_SIGNAL_MP_h +#define __RTEMS_SIGNAL_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/asr.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the list of + * remote signal operations. + */ + +typedef enum { + SIGNAL_MP_SEND_REQUEST = 0, + SIGNAL_MP_SEND_RESPONSE = 1 +} Signal_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote signal operations. + */ + +typedef struct { + rtems_packet_prefix Prefix; + Signal_MP_Remote_operations operation; + rtems_signal_set signal_in; +} Signal_MP_Packet; + +/* + * _Signal_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + * + * This routine is not needed since there are no process + * packets to be sent by this manager. + */ + +/* + * _Signal_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +rtems_status_code _Signal_MP_Send_request_packet ( + Signal_MP_Remote_operations operation, + Objects_Id task_id, + rtems_signal_set signal_in +); + +/* + * _Signal_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _Signal_MP_Send_response_packet ( + Signal_MP_Remote_operations operation, + Thread_Control *the_thread +); + +/* + * + * _Signal_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _Signal_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +); + +/* + * _Signal_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + * + * This routine is not needed since there are no objects + * deleted by this manager. + */ + +/* + * _Signal_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + * + * This routine is not needed since there are no objects + * deleted by this manager. + */ + +/* + * _Signal_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a signal mp packet. + */ + +Signal_MP_Packet *_Signal_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/rtems/include/rtems/rtems/status.h b/cpukit/rtems/include/rtems/rtems/status.h new file mode 100644 index 0000000000..23c1c830c6 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/status.h @@ -0,0 +1,82 @@ +/* status.h + * + * This include file contains the status codes returned from the + * executive directives. + * + * 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$ + */ + +#ifndef __RTEMS_STATUS_h +#define __RTEMS_STATUS_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* types */ + +/* enumerated constants */ + +typedef enum { + RTEMS_SUCCESSFUL = 0, /* successful completion */ + RTEMS_TASK_EXITTED = 1, /* returned from a thread */ + RTEMS_MP_NOT_CONFIGURED = 2, /* multiprocessing not configured */ + RTEMS_INVALID_NAME = 3, /* invalid object name */ + RTEMS_INVALID_ID = 4, /* invalid object id */ + RTEMS_TOO_MANY = 5, /* too many */ + RTEMS_TIMEOUT = 6, /* timed out waiting */ + RTEMS_OBJECT_WAS_DELETED = 7, /* object deleted while waiting */ + RTEMS_INVALID_SIZE = 8, /* specified size was invalid */ + RTEMS_INVALID_ADDRESS = 9, /* address specified is invalid */ + RTEMS_INVALID_NUMBER = 10, /* number was invalid */ + RTEMS_NOT_DEFINED = 11, /* item has not been initialized */ + RTEMS_RESOURCE_IN_USE = 12, /* resources still outstanding */ + RTEMS_UNSATISFIED = 13, /* request not satisfied */ + RTEMS_INCORRECT_STATE = 14, /* thread is in wrong state */ + RTEMS_ALREADY_SUSPENDED = 15, /* thread already in state */ + RTEMS_ILLEGAL_ON_SELF = 16, /* illegal on calling thread */ + RTEMS_ILLEGAL_ON_REMOTE_OBJECT = 17, /* illegal for remote object */ + RTEMS_CALLED_FROM_ISR = 18, /* called from wrong environment */ + RTEMS_INVALID_PRIORITY = 19, /* invalid thread priority */ + RTEMS_INVALID_CLOCK = 20, /* invalid date/time */ + RTEMS_INVALID_NODE = 21, /* invalid node id */ + RTEMS_NOT_CONFIGURED = 22, /* directive not configured */ + RTEMS_NOT_OWNER_OF_RESOURCE = 23, /* not owner of resource */ + RTEMS_NOT_IMPLEMENTED = 24, /* directive not implemented */ + RTEMS_INTERNAL_ERROR = 25, /* RTEMS inconsistency detected */ + RTEMS_NO_MEMORY = 26 /* could not get enough memory */ +} rtems_status_code; + +#define RTEMS_STATUS_CODES_FIRST RTEMS_SUCCESSFUL +#define RTEMS_STATUS_CODES_LAST RTEMS_NO_MEMORY + +extern rtems_status_code _Status_Object_name_errors_to_status[]; + +#ifdef INIT +rtems_status_code _Status_Object_name_errors_to_status[] = { + RTEMS_SUCCESSFUL, /* OBJECTS_SUCCESSFUL */ + RTEMS_INVALID_NAME, /* OBJECTS_INVALID_NAME */ + RTEMS_INVALID_NODE /* OBJECTS_INVALID_NODE */ +}; +#endif + +/* + * Applications are allowed to use the macros to compare status codes. + */ + +#include <rtems/rtems/status.inl> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/support.h b/cpukit/rtems/include/rtems/rtems/support.h new file mode 100644 index 0000000000..3305ffd4d3 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/support.h @@ -0,0 +1,97 @@ +/* support.h + * + * This include file contains information about support functions for + * the RTEMS API. + * + * 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$ + */ + +#ifndef __RTEMS_RTEMS_SUPPORT_h +#define __RTEMS_RTEMS_SUPPORT_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/types.h> + +/* + * rtems_build_name + * + * DESCRIPTION: + * + * This function returns an object name composed of the four characters + * C1, C2, C3, and C4. + * + * NOTE: + * + * This must be implemented as a macro for use in Configuration Tables. + * + */ + +#define rtems_build_name( _C1, _C2, _C3, _C4 ) \ + ( (_C1) << 24 | (_C2) << 16 | (_C3) << 8 | (_C4) ) + +/* + * rtems_get_class + * + * DESCRIPTION: + * + * This function returns the class portion of the ID. + * + */ + +#define rtems_get_class( _id ) \ + _Objects_Get_class( _id ) + +/* + * rtems_get_node + * + * DESCRIPTION: + * + * This function returns the node portion of the ID. + * + */ + +#define rtems_get_node( _id ) \ + _Objects_Get_node( _id ) + +/* + * rtems_get_index + * + * DESCRIPTION: + * + * This function returns the index portion of the ID. + * + */ + +#define rtems_get_index( _id ) \ + _Objects_Get_index( _id ) + +/* + * Time related + */ + +#define RTEMS_MILLISECONDS_TO_MICROSECONDS(_ms) \ + TOD_MILLISECONDS_TO_MICROSECONDS(_ms) +#define RTEMS_MILLISECONDS_TO_TICKS(_ms) \ + TOD_MILLISECONDS_TO_TICKS(_ms) + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/support.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/taskmp.h b/cpukit/rtems/include/rtems/rtems/taskmp.h new file mode 100644 index 0000000000..032d5645d1 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/taskmp.h @@ -0,0 +1,167 @@ +/* taskmp.h + * + * This include file contains all the constants and structures associated + * with the multiprocessing support in the task 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$ + */ + +#ifndef __RTEMS_RTEMS_TASKS_MP_h +#define __RTEMS_RTEMS_TASKS_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/score/priority.h> +#include <rtems/rtems/tasks.h> +#include <rtems/score/thread.h> + +/* + * The following enumerated type defines the list of + * remote task operations. + */ + +typedef enum { + RTEMS_TASKS_MP_ANNOUNCE_CREATE = 0, + RTEMS_TASKS_MP_ANNOUNCE_DELETE = 1, + RTEMS_TASKS_MP_SUSPEND_REQUEST = 2, + RTEMS_TASKS_MP_SUSPEND_RESPONSE = 3, + RTEMS_TASKS_MP_RESUME_REQUEST = 4, + RTEMS_TASKS_MP_RESUME_RESPONSE = 5, + RTEMS_TASKS_MP_SET_PRIORITY_REQUEST = 6, + RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE = 7, + RTEMS_TASKS_MP_GET_NOTE_REQUEST = 8, + RTEMS_TASKS_MP_GET_NOTE_RESPONSE = 9, + RTEMS_TASKS_MP_SET_NOTE_REQUEST = 10, + RTEMS_TASKS_MP_SET_NOTE_RESPONSE = 11 +} RTEMS_tasks_MP_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote task operations. + */ + +typedef struct { + rtems_packet_prefix Prefix; + RTEMS_tasks_MP_Remote_operations operation; + rtems_name name; + rtems_task_priority the_priority; + unsigned32 notepad; + unsigned32 note; +} RTEMS_tasks_MP_Packet; + +/* + * _RTEMS_tasks_MP_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _RTEMS_tasks_MP_Send_process_packet ( + RTEMS_tasks_MP_Remote_operations operation, + Objects_Id task_id, + rtems_name name +); + +/* + * _RTEMS_tasks_MP_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + */ + +rtems_status_code _RTEMS_tasks_MP_Send_request_packet ( + RTEMS_tasks_MP_Remote_operations operation, + Objects_Id task_id, + rtems_task_priority the_priority, + unsigned32 notepad, + unsigned32 note +); + +/* + * _RTEMS_tasks_MP_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + */ + +void _RTEMS_tasks_MP_Send_response_packet ( + RTEMS_tasks_MP_Remote_operations operation, + Thread_Control *the_thread +); + +/* + * + * _RTEMS_tasks_MP_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _RTEMS_tasks_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +); + +/* + * _RTEMS_tasks_MP_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + * + * This routine is not needed by RTEMS_tasks since a task + * cannot be deleted when segments are in use. + */ + +/* + * _RTEMS_tasks_MP_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + * + * This routine is not needed since there are no objects + * deleted by this manager. + * + */ + +/* + * _RTEMS_tasks_MP_Get_packet + * + * DESCRIPTION: + * + * This function is used to obtain a task mp packet. + */ + +RTEMS_tasks_MP_Packet *_RTEMS_tasks_MP_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of file */ diff --git a/cpukit/rtems/include/rtems/rtems/tasks.h b/cpukit/rtems/include/rtems/rtems/tasks.h new file mode 100644 index 0000000000..b86d85a562 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/tasks.h @@ -0,0 +1,419 @@ +/* tasks.h + * + * This include file contains all constants and structures associated + * with RTEMS tasks. This manager provides a comprehensive set of directives + * to create, delete, and administer tasks. + * + * Directives provided are: + * + * + create a task + * + get an ID of a task + * + start a task + * + restart a task + * + delete a task + * + suspend a task + * + resume a task + * + set a task's priority + * + change the current task's mode + * + get a task notepad entry + * + set a task notepad entry + * + wake up after interval + * + wake up when specified + * + * 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$ + */ + +#ifndef __RTEMS_RTEMS_TASKS_h +#define __RTEMS_RTEMS_TASKS_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/rtems/types.h> +#include <rtems/rtems/eventset.h> +#include <rtems/rtems/asr.h> +#include <rtems/rtems/attr.h> + +/* + * Constant to be used as the ID of current task + */ + +#define RTEMS_SELF OBJECTS_ID_OF_SELF + +/* + * This constant is passed to the rtems_task_wake_after directive as the + * interval when a task wishes to yield the CPU. + */ + +#define RTEMS_YIELD_PROCESSOR WATCHDOG_NO_TIMEOUT + +/* + * Define the type for an RTEMS API task priority. + */ + +typedef Priority_Control rtems_task_priority; + +#define RTEMS_NO_PRIORITY RTEMS_CURRENT_PRIORITY + +#define RTEMS_MINIMUM_PRIORITY (PRIORITY_MINIMUM + 1) +#define RTEMS_MAXIMUM_PRIORITY PRIORITY_MAXIMUM + +/* + * The following constant is passed to rtems_task_set_priority when the + * caller wants to obtain the current priority. + */ + +#define RTEMS_CURRENT_PRIORITY PRIORITY_MINIMUM + +/* + * Notepads constants (indices into notepad array) + */ + +#define RTEMS_NOTEPAD_FIRST 0 /* lowest numbered notepad */ +#define RTEMS_NOTEPAD_0 0 /* notepad location 0 */ +#define RTEMS_NOTEPAD_1 1 /* notepad location 1 */ +#define RTEMS_NOTEPAD_2 2 /* notepad location 2 */ +#define RTEMS_NOTEPAD_3 3 /* notepad location 3 */ +#define RTEMS_NOTEPAD_4 4 /* notepad location 4 */ +#define RTEMS_NOTEPAD_5 5 /* notepad location 5 */ +#define RTEMS_NOTEPAD_6 6 /* notepad location 6 */ +#define RTEMS_NOTEPAD_7 7 /* notepad location 7 */ +#define RTEMS_NOTEPAD_8 8 /* notepad location 8 */ +#define RTEMS_NOTEPAD_9 9 /* notepad location 9 */ +#define RTEMS_NOTEPAD_10 10 /* notepad location 10 */ +#define RTEMS_NOTEPAD_11 11 /* notepad location 11 */ +#define RTEMS_NOTEPAD_12 12 /* notepad location 12 */ +#define RTEMS_NOTEPAD_13 13 /* notepad location 13 */ +#define RTEMS_NOTEPAD_14 14 /* notepad location 14 */ +#define RTEMS_NOTEPAD_15 15 /* notepad location 15 */ +#define RTEMS_NOTEPAD_LAST RTEMS_NOTEPAD_15 /* highest numbered notepad */ + +#define RTEMS_NUMBER_NOTEPADS (RTEMS_NOTEPAD_LAST+1) + +/* + * External API name for Thread_Control + */ + +typedef Thread_Control rtems_tcb; + +/* + * The following defines the "return type" of an RTEMS task. + */ + +typedef void rtems_task; + +/* + * The following defines the argument to an RTEMS task. + */ + +typedef unsigned32 rtems_task_argument; + +/* + * The following defines the type for the entry point of an RTEMS task. + */ + +typedef rtems_task ( *rtems_task_entry )( + rtems_task_argument + ); + +/* + * The following records define the Initialization Tasks Table. + * Each entry contains the information required by RTEMS to + * create and start a user task automatically at executive + * initialization time. + */ + +typedef struct { + rtems_name name; /* task name */ + unsigned32 stack_size; /* task stack size */ + rtems_task_priority initial_priority; /* task priority */ + rtems_attribute attribute_set; /* task attributes */ + rtems_task_entry entry_point; /* task entry point */ + rtems_mode mode_set; /* task initial mode */ + unsigned32 argument; /* task argument */ +} rtems_initialization_tasks_table; + +/* + * This is the API specific information required by each thread for + * the RTEMS API to function correctly. + */ + + +typedef struct { + unsigned32 Notepads[ RTEMS_NUMBER_NOTEPADS ]; + rtems_event_set pending_events; + rtems_event_set event_condition; + ASR_Information Signal; +} RTEMS_API_Control; + +/* + * The following defines the information control block used to + * manage this class of objects. + */ + +EXTERN Objects_Information _RTEMS_tasks_Information; + +/* + * These are used to manage the user initialization tasks. + */ + +EXTERN rtems_initialization_tasks_table *_RTEMS_tasks_User_initialization_tasks; +EXTERN unsigned32 _RTEMS_tasks_Number_of_initialization_tasks; + +/* + * _RTEMS_tasks_Manager_initialization + * + * DESCRIPTION: + * + * This routine initializes all Task Manager related data structures. + */ + +void _RTEMS_tasks_Manager_initialization( + unsigned32 maximum_tasks, + unsigned32 number_of_initialization_tasks, + rtems_initialization_tasks_table *user_tasks +); + +/* + * rtems_task_create + * + * DESCRIPTION: + * + * This routine implements the rtems_task_create directive. The task + * will have the name name. The attribute_set can be used to indicate + * that the task will be globally accessible or utilize floating point. + * The task's stack will be stack_size bytes. The task will begin + * execution with initial_priority and initial_modes. It returns the + * id of the created task in ID. + */ + +rtems_status_code rtems_task_create( + rtems_name name, + rtems_task_priority initial_priority, + unsigned32 stack_size, + rtems_mode initial_modes, + rtems_attribute attribute_set, + Objects_Id *id +); + +/* + * rtems_task_ident + * + * DESCRIPTION: + * + * This routine implements the rtems_task_ident directive. + * This directive returns the task ID associated with name. + * If more than one task is named name, then the task to + * which the ID belongs is arbitrary. node indicates the + * extent of the search for the ID of the task named name. + * The search can be limited to a particular node or allowed to + * encompass all nodes. + */ + +rtems_status_code rtems_task_ident( + rtems_name name, + unsigned32 node, + Objects_Id *id +); + +/* + * rtems_task_delete + * + * DESCRIPTION: + * + * This routine implements the rtems_task_delete directive. The + * task indicated by ID is deleted. + */ + +rtems_status_code rtems_task_delete( + Objects_Id id +); + +/* + * rtems_task_get_note + * + * DESCRIPTION: + * + * This routine implements the rtems_task_get_note directive. The + * value of the indicated notepad for the task associated with ID + * is returned in note. + */ + +rtems_status_code rtems_task_get_note( + Objects_Id id, + unsigned32 notepad, + unsigned32 *note +); + +/* + * rtems_task_set_note + * + * DESCRIPTION: + * + * This routine implements the rtems_task_set_note directive. The + * value of the indicated notepad for the task associated with ID + * is returned in note. + */ + +rtems_status_code rtems_task_set_note( + Objects_Id id, + unsigned32 notepad, + unsigned32 note +); + +/* + * rtems_task_mode + * + * DESCRIPTION: + * + * This routine implements the rtems_task_mode directive. The current + * values of the modes indicated by mask of the calling task are changed + * to that indicated in mode_set. The former mode of the task is + * returned in mode_set. + */ + +rtems_status_code rtems_task_mode( + rtems_mode mode_set, + rtems_mode mask, + rtems_mode *previous_mode_set +); + +/* + * rtems_task_restart + * + * DESCRIPTION: + * + * This routine implements the rtems_task_restart directive. The + * task associated with ID is restarted at its initial entry + * point with the new argument. + */ + +rtems_status_code rtems_task_restart( + Objects_Id id, + unsigned32 arg +); + +/* + * rtems_task_suspend + * + * DESCRIPTION: + * + * This routine implements the rtems_task_suspend directive. The + * SUSPENDED state is set for task associated with ID. + */ + +rtems_status_code rtems_task_suspend( + Objects_Id id +); + +/* + * rtems_task_resume + * + * DESCRIPTION: + * + * This routine implements the rtems_task_resume Directive. The + * SUSPENDED state is cleared for task associated with ID. + */ + +rtems_status_code rtems_task_resume( + Objects_Id id +); + +/* + * rtems_task_set_priority + * + * DESCRIPTION: + * + * This routine implements the rtems_task_set_priority directive. The + * current priority of the task associated with ID is set to + * new_priority. The former priority of that task is returned + * in old_priority. + */ + +rtems_status_code rtems_task_set_priority( + Objects_Id id, + rtems_task_priority new_priority, + rtems_task_priority *old_priority +); + +/* + * rtems_task_start + * + * DESCRIPTION: + * + * This routine implements the rtems_task_start directive. The + * starting execution point of the task associated with ID is + * set to entry_point with the initial argument. + */ + +rtems_status_code rtems_task_start( + Objects_Id id, + rtems_task_entry entry_point, + unsigned32 argument +); + +/* + * rtems_task_wake_when + * + * DESCRIPTION: + * + * This routine implements the rtems_task_wake_when directive. The + * calling task is blocked until the current time of day is + * equal to that indicated by time_buffer. + */ + +rtems_status_code rtems_task_wake_when( + rtems_time_of_day *time_buffer +); + +/* + * rtems_task_wake_after + * + * DESCRIPTION: + * + * This routine implements the rtems_task_wake_after directive. The + * calling task is blocked until the indicated number of clock + * ticks have occurred. + */ + +rtems_status_code rtems_task_wake_after( + rtems_interval ticks +); + +/*PAGE + * + * _RTEMS_tasks_Initialize_user_tasks + * + * This routine creates and starts all configured user + * initialzation threads. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _RTEMS_tasks_Initialize_user_tasks( void ); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/tasks.inl> +#endif +#include <rtems/rtems/taskmp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/timer.h b/cpukit/rtems/include/rtems/rtems/timer.h new file mode 100644 index 0000000000..d09b80d5ff --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/timer.h @@ -0,0 +1,207 @@ +/* timer.h + * + * This include file contains all the constants, structures, and + * prototypes associated with the Timer Manager. This manager provides + * facilities to configure, initiate, cancel, and delete timers which will + * fire at specified intervals of time. + * + * Directives provided are: + * + * + create a timer + * + get an ID of a timer + * + delete a timer + * + set a timer to fire after a number of ticks have passed + * + set a timer to fire when a specified date and time has been reached + * + reset a timer + * + cancel a time + * + * 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$ + */ + +#ifndef __RTEMS_TIMER_h +#define __RTEMS_TIMER_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> +#include <rtems/score/tod.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type details the classes to which a timer + * may belong. + */ + +typedef enum { + TIMER_INTERVAL, + TIMER_TIME_OF_DAY, + TIMER_DORMANT +} Timer_Classes; + +/* + * The following types define a pointer to a timer service routine. + */ + +typedef void rtems_timer_service_routine; + +typedef rtems_timer_service_routine ( *rtems_timer_service_routine_entry )( + rtems_id, + void * + ); + +/* + * The following defines the information control block used to manage + * this class of objects. + */ + +EXTERN Objects_Information _Timer_Information; + +/* + * The following records define the control block used to manage + * each timer. + */ + +typedef struct { + Objects_Control Object; + Watchdog_Control Ticker; + Timer_Classes the_class; +} Timer_Control; + +/* + * _Timer_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Timer_Manager_initialization( + unsigned32 maximum_timers +); + +/* + * rtems_timer_create + * + * DESCRIPTION: + * + * This routine implements the rtems_timer_create directive. The + * timer will have the name name. It returns the id of the + * created timer in ID. + */ + +rtems_status_code rtems_timer_create( + rtems_name name, + Objects_Id *id +); + +/* + * rtems_timer_ident + * + * DESCRIPTION: + * + * This routine implements the rtems_timer_ident directive. + * This directive returns the timer ID associated with name. + * If more than one timer is named name, then the timer + * to which the ID belongs is arbitrary. + */ + +rtems_status_code rtems_timer_ident( + rtems_name name, + Objects_Id *id +); + +/* + * rtems_timer_cancel + * + * DESCRIPTION: + * + * This routine implements the rtems_timer_cancel directive. It is used + * to stop the timer associated with ID from firing. + */ + +rtems_status_code rtems_timer_cancel( + Objects_Id id +); + +/* + * rtems_timer_delete + * + * DESCRIPTION: + * + * This routine implements the rtems_timer_delete directive. The + * timer indicated by ID is deleted. + */ + +rtems_status_code rtems_timer_delete( + Objects_Id id +); + +/* + * rtems_timer_fire_after + * + * DESCRIPTION: + * + * This routine implements the rtems_timer_fire_after directive. It + * initiates the timer associated with ID to fire in ticks clock + * ticks. When the timer fires, the routine will be invoked. + */ + +rtems_status_code rtems_timer_fire_after( + Objects_Id id, + rtems_interval ticks, + rtems_timer_service_routine_entry routine, + void *user_data +); + +/* + * rtems_timer_fire_when + * + * DESCRIPTION: + * + * This routine implements the rtems_timer_fire_when directive. It + * initiates the timer associated with ID to fire at wall_time + * When the timer fires, the routine will be invoked. + */ + +rtems_status_code rtems_timer_fire_when( + Objects_Id id, + rtems_time_of_day *wall_time, + rtems_timer_service_routine_entry routine, + void *user_data +); + +/* + * rtems_timer_reset + * + * DESCRIPTION: + * + * This routine implements the rtems_timer_reset directive. It is used + * to reinitialize the interval timer associated with ID just as if + * rtems_timer_fire_after were re-invoked with the same arguments that + * were used to initiate this timer. + */ + +rtems_status_code rtems_timer_reset( + Objects_Id id +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/rtems/timer.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/include/rtems/rtems/types.h b/cpukit/rtems/include/rtems/rtems/types.h new file mode 100644 index 0000000000..1dc8cd5373 --- /dev/null +++ b/cpukit/rtems/include/rtems/rtems/types.h @@ -0,0 +1,96 @@ +/* types.h + * + * This include file defines the types used by the RTEMS API. + * + * 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$ + */ + +#ifndef __RTEMS_RTEMS_TYPES_h +#define __RTEMS_RTEMS_TYPES_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> +#include <rtems/score/priority.h> +#include <rtems/rtems/modes.h> +#include <rtems/score/mpci.h> +#include <rtems/score/mppkt.h> + +/* + * RTEMS basic type definitions + */ + +typedef unsigned8 rtems_unsigned8; /* unsigned 8-bit value */ +typedef unsigned16 rtems_unsigned16; /* unsigned 16-bit value */ +typedef unsigned32 rtems_unsigned32; /* unsigned 32-bit value */ + +typedef signed8 rtems_signed8; /* signed 8-bit value */ +typedef signed16 rtems_signed16; /* signed 16-bit value */ +typedef signed32 rtems_signed32; /* signed 32-bit value */ + +/* + * some C++ compilers (eg: HP's) don't do 'long long' + */ +#if defined(__GNUC__) +typedef unsigned64 rtems_unsigned64; /* unsigned 64-bit value */ +typedef signed64 rtems_signed64; /* signed 64-bit value */ +#endif + +typedef single_precision rtems_single; /* single precision float */ +typedef double_precision rtems_double; /* double precision float */ + +typedef boolean rtems_boolean; + +typedef unsigned32 rtems_name; +typedef Objects_Id rtems_id; + +typedef Context_Control rtems_context; +typedef Context_Control_fp rtems_context_fp; +typedef CPU_Interrupt_frame rtems_interrupt_frame; + +/* + * Time related + */ + +typedef Watchdog_Interval rtems_interval; +typedef TOD_Control rtems_time_of_day; + +/* + * Define the type for an RTEMS API task mode. + */ + +typedef Modes_Control rtems_mode; + +/* + * MPCI related entries + */ + +typedef MP_packet_Classes rtems_mp_packet_classes; +typedef MP_packet_Prefix rtems_packet_prefix; + +typedef MPCI_initialization_entry rtems_mpci_initialization_entry; +typedef MPCI_get_packet_entry rtems_mpci_get_packet_entry; +typedef MPCI_return_packet_entry rtems_mpci_return_packet_entry; +typedef MPCI_send_entry rtems_mpci_send_packet_entry; +typedef MPCI_receive_entry rtems_mpci_receive_packet_entry; + +typedef MPCI_Entry rtems_mpci_entry; + +typedef MPCI_Control rtems_mpci_table; + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/asr.inl b/cpukit/rtems/inline/rtems/rtems/asr.inl new file mode 100644 index 0000000000..fc52778875 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/asr.inl @@ -0,0 +1,128 @@ +/* inline/asr.inl + * + * This include file contains the implemenation of all routines + * associated with the asynchronous signal handler which are inlined. + * + * 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$ + */ + +#ifndef __INLINE_ASR_inl +#define __INLINE_ASR_inl + +#include <rtems/score/isr.h> + +/*PAGE + * + * _ASR_Initialize + * + * DESCRIPTION: + * + * This routine initializes the given RTEMS_ASR information record. + */ + +STATIC INLINE void _ASR_Initialize ( + ASR_Information *information +) +{ + information->is_enabled = TRUE; + information->handler = NULL; + information->mode_set = RTEMS_DEFAULT_MODES; + information->signals_posted = 0; + information->signals_pending = 0; + information->nest_level = 0; +} + +/*PAGE + * + * _ASR_Swap_signals + * + * DESCRIPTION: + * + * This routine atomically swaps the pending and posted signal + * sets. This is done when the thread alters its mode in such a + * way that the RTEMS_ASR disable/enable flag changes. + */ + +STATIC INLINE void _ASR_Swap_signals ( + ASR_Information *information +) +{ + rtems_signal_set _signals; + ISR_Level _level; + + _ISR_Disable( _level ); + _signals = information->signals_pending; + information->signals_pending = information->signals_posted; + information->signals_posted = _signals; + _ISR_Enable( _level ); +} + +/*PAGE + * + * _ASR_Is_null_handler + * + * DESCRIPTION: + * + * This function returns TRUE if the given asr_handler is NULL and + * FALSE otherwise. + */ + +STATIC INLINE boolean _ASR_Is_null_handler ( + rtems_asr_entry asr_handler +) +{ + return asr_handler == NULL; +} + +/*PAGE + * + * _ASR_Are_signals_pending + * + * DESCRIPTION: + * + * This function returns TRUE if there are signals pending in the + * given RTEMS_ASR information record and FALSE otherwise. + */ + +STATIC INLINE boolean _ASR_Are_signals_pending ( + ASR_Information *information +) +{ + return information->signals_posted != 0; +} + +/*PAGE + * + * _ASR_Post_signals + * + * DESCRIPTION: + * + * This routine posts the given signals into the signal_set + * passed in. The result is returned to the user in signal_set. + * + * NOTE: This must be implemented as a macro. + */ + +STATIC INLINE void _ASR_Post_signals( + rtems_signal_set signals, + rtems_signal_set *signal_set +) +{ + ISR_Level _level; + + _ISR_Disable( _level ); + *signal_set |= signals; + _ISR_Enable( _level ); +} + + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/attr.inl b/cpukit/rtems/inline/rtems/rtems/attr.inl new file mode 100644 index 0000000000..53c613382f --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/attr.inl @@ -0,0 +1,159 @@ +/* inline/attr.inl + * + * This include file contains all of the inlined routines associated + * with attributes. + * + * 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$ + */ + +#ifndef __INLINE_ATTRIBUTES_inl +#define __INLINE_ATTRIBUTES_inl + +/*PAGE + * + * _Attributes_Set + * + * DESCRIPTION: + * + * This function sets the requested new_attributes in the attribute_set + * passed in. The result is returned to the user. + */ + +STATIC INLINE rtems_attribute _Attributes_Set ( + rtems_attribute new_attributes, + rtems_attribute attribute_set +) +{ + return attribute_set | new_attributes; +} + +/*PAGE + * + * _Attributes_Clear + * + * DESCRIPTION: + * + * This function clears the requested new_attributes in the attribute_set + * passed in. The result is returned to the user. + */ + +STATIC INLINE rtems_attribute _Attributes_Clear ( + rtems_attribute attribute_set, + rtems_attribute mask +) +{ + return attribute_set & ~mask; +} + +/*PAGE + * + * _Attributes_Is_floating_point + * + * DESCRIPTION: + * + * This function returns TRUE if the floating point attribute is + * enabled in the attribute_set and FALSE otherwise. + */ + +STATIC INLINE boolean _Attributes_Is_floating_point( + rtems_attribute attribute_set +) +{ + return ( attribute_set & RTEMS_FLOATING_POINT ); +} + +/*PAGE + * + * _Attributes_Is_global + * + * DESCRIPTION: + * + * This function returns TRUE if the global object attribute is + * enabled in the attribute_set and FALSE otherwise. + */ + +STATIC INLINE boolean _Attributes_Is_global( + rtems_attribute attribute_set +) +{ + return ( attribute_set & RTEMS_GLOBAL ); +} + +/*PAGE + * + * _Attributes_Is_priority + * + * DESCRIPTION: + * + * This function returns TRUE if the priority attribute is + * enabled in the attribute_set and FALSE otherwise. + */ + +STATIC INLINE boolean _Attributes_Is_priority( + rtems_attribute attribute_set +) +{ + return ( attribute_set & RTEMS_PRIORITY ); +} + +/*PAGE + * + * _Attributes_Is_binary_semaphore + * + * DESCRIPTION: + * + * This function returns TRUE if the binary semaphore attribute is + * enabled in the attribute_set and FALSE otherwise. + */ + +STATIC INLINE boolean _Attributes_Is_binary_semaphore( + rtems_attribute attribute_set +) +{ + return ( attribute_set & RTEMS_BINARY_SEMAPHORE ); +} + +/*PAGE + * + * _Attributes_Is_inherit_priority + * + * DESCRIPTION: + * + * This function returns TRUE if the priority inheritance attribute + * is enabled in the attribute_set and FALSE otherwise. + */ + +STATIC INLINE boolean _Attributes_Is_inherit_priority( + rtems_attribute attribute_set +) +{ + return ( attribute_set & RTEMS_INHERIT_PRIORITY ); +} + +/*PAGE + * + * _Attributes_Is_priority_ceiling + * + * DESCRIPTION: + * + * This function returns TRUE if the priority ceiling attribute + * is enabled in the attribute_set and FALSE otherwise. + */ + +STATIC INLINE boolean _Attributes_Is_priority_ceiling( + rtems_attribute attribute_set +) +{ + return ( attribute_set & RTEMS_PRIORITY_CEILING ); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/dpmem.inl b/cpukit/rtems/inline/rtems/rtems/dpmem.inl new file mode 100644 index 0000000000..4bd13bcd80 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/dpmem.inl @@ -0,0 +1,95 @@ +/* inline/dpmem.inl + * + * This include file contains the inline routine used in conjunction + * with the Dual Ported Memory 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$ + */ + +#ifndef __INLINE_DPMEM_inl +#define __INLINE_DPMEM_inl + + +/*PAGE + * + * _Dual_ported_memory_Allocate + * + * DESCRIPTION: + * + * This routine allocates a port control block from the inactive chain + * of free port control blocks. + */ + +STATIC INLINE Dual_ported_memory_Control + *_Dual_ported_memory_Allocate ( void ) +{ + return (Dual_ported_memory_Control *) + _Objects_Allocate( &_Dual_ported_memory_Information ); +} + +/*PAGE + * + * _Dual_ported_memory_Free + * + * DESCRIPTION: + * + * This routine frees a port control block to the inactive chain + * of free port control blocks. + */ + +STATIC INLINE void _Dual_ported_memory_Free ( + Dual_ported_memory_Control *the_port +) +{ + _Objects_Free( &_Dual_ported_memory_Information, &the_port->Object ); +} + +/*PAGE + * + * _Dual_ported_memory_Get + * + * DESCRIPTION: + * + * This function maps port IDs to port control blocks. If ID + * corresponds to a local port, then it returns the_port control + * pointer which maps to ID and location is set to OBJECTS_LOCAL. + * Global ports are not supported, thus if ID does not map to a + * local port, location is set to OBJECTS_ERROR and the_port is + * undefined. + */ + +STATIC INLINE Dual_ported_memory_Control *_Dual_ported_memory_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (Dual_ported_memory_Control *) + _Objects_Get( &_Dual_ported_memory_Information, id, location ); +} + +/*PAGE + * + * _Dual_ported_memory_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_port is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _Dual_ported_memory_Is_null( + Dual_ported_memory_Control *the_port +) +{ + return ( the_port == NULL ); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/event.inl b/cpukit/rtems/inline/rtems/rtems/event.inl new file mode 100644 index 0000000000..1f41e0a5fc --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/event.inl @@ -0,0 +1,21 @@ +/* inline/event.inl + * + * This include file contains the static inline implementation of + * macros for the Event 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$ + */ + +#ifndef __MACROS_EVENT_inl +#define __MACROS_EVENT_inl + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/eventset.inl b/cpukit/rtems/inline/rtems/rtems/eventset.inl new file mode 100644 index 0000000000..ec0789b207 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/eventset.inl @@ -0,0 +1,91 @@ +/* inline/eventset.inl + * + * This include file contains the information pertaining to event sets. + * + * 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$ + */ + +#ifndef __INLINE_EVENT_SET_inl +#define __INLINE_EVENT_SET_inl + +/*PAGE + * + * _Event_sets_Is_empty + * + * DESCRIPTION: + * + * This function returns TRUE if on events are posted in the event_set, + * and FALSE otherwise. + */ + +STATIC INLINE boolean _Event_sets_Is_empty( + rtems_event_set the_event_set +) +{ + return ( the_event_set == 0 ); +} + +/*PAGE + * + * _Event_sets_Post + * + * DESCRIPTION: + * + * This routine posts the given new_events into the event_set + * passed in. The result is returned to the user in event_set. + */ + +STATIC INLINE void _Event_sets_Post( + rtems_event_set the_new_events, + rtems_event_set *the_event_set +) +{ + *the_event_set |= the_new_events; +} + +/*PAGE + * + * _Event_sets_Get + * + * DESCRIPTION: + * + * This function returns the events in event_condition which are + * set in event_set. + */ + +STATIC INLINE rtems_event_set _Event_sets_Get( + rtems_event_set the_event_set, + rtems_event_set the_event_condition +) +{ + return ( the_event_set & the_event_condition ); +} + +/*PAGE + * + * _Event_sets_Clear + * + * DESCRIPTION: + * + * This function removes the events in mask from the event_set + * passed in. The result is returned to the user in event_set. + */ + +STATIC INLINE rtems_event_set _Event_sets_Clear( + rtems_event_set the_event_set, + rtems_event_set the_mask +) +{ + return ( the_event_set & ~(the_mask) ); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/message.inl b/cpukit/rtems/inline/rtems/rtems/message.inl new file mode 100644 index 0000000000..c34ad5082a --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/message.inl @@ -0,0 +1,83 @@ +/* message.inl + * + * This include file contains the static inline implementation of all + * inlined routines in the Message 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$ + */ + +#ifndef __MESSAGE_QUEUE_inl +#define __MESSAGE_QUEUE_inl + +#include <rtems/score/wkspace.h> + +/*PAGE + * + * _Message_queue_Is_null + * + * DESCRIPTION: + * + * This function places the_message at the rear of the outstanding + * messages on the_message_queue. + */ + +STATIC INLINE boolean _Message_queue_Is_null ( + Message_queue_Control *the_message_queue +) +{ + return ( the_message_queue == NULL ); +} + + +/*PAGE + * + * _Message_queue_Free + * + * DESCRIPTION: + * + * This routine deallocates a message queue control block into + * the inactive chain of free message queue control blocks. + */ + +STATIC INLINE void _Message_queue_Free ( + Message_queue_Control *the_message_queue +) +{ + _Objects_Free( &_Message_queue_Information, &the_message_queue->Object ); +} + +/*PAGE + * + * _Message_queue_Get + * + * DESCRIPTION: + * + * This function maps message queue IDs to message queue control + * blocks. If ID corresponds to a local message queue, then it + * returns the_message_queue control pointer which maps to ID + * and location is set to OBJECTS_LOCAL. If the message queue ID is + * global and resides on a remote node, then location is set + * to OBJECTS_REMOTE, and the_message_queue is undefined. + * Otherwise, location is set to OBJECTS_ERROR and + * the_message_queue is undefined. + */ + +STATIC INLINE Message_queue_Control *_Message_queue_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (Message_queue_Control *) + _Objects_Get( &_Message_queue_Information, id, location ); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/modes.inl b/cpukit/rtems/inline/rtems/rtems/modes.inl new file mode 100644 index 0000000000..803febd49a --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/modes.inl @@ -0,0 +1,152 @@ +/* modes.inl + * + * This include file contains the static inline implementation of the + * inlined routines in the Mode 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$ + */ + +#ifndef __MODES_inl +#define __MODES_inl + +/*PAGE + * + * _Modes_Mask_changed + * + * DESCRIPTION: + * + * This function returns TRUE if any of the mode flags in mask + * are set in mode_set, and FALSE otherwise. + */ + +STATIC INLINE boolean _Modes_Mask_changed ( + Modes_Control mode_set, + Modes_Control masks +) +{ + return ( mode_set & masks ); +} + +/*PAGE + * + * _Modes_Is_asr_disabled + * + * DESCRIPTION: + * + * This function returns TRUE if mode_set indicates that Asynchronous + * Signal Processing is disabled, and FALSE otherwise. + */ + +STATIC INLINE boolean _Modes_Is_asr_disabled ( + Modes_Control mode_set +) +{ + return (mode_set & RTEMS_ASR_MASK) == RTEMS_NO_ASR; +} + +/*PAGE + * + * _Modes_Is_preempt + * + * DESCRIPTION: + * + * This function returns TRUE if mode_set indicates that preemption + * is enabled, and FALSE otherwise. + */ + +STATIC INLINE boolean _Modes_Is_preempt ( + Modes_Control mode_set +) +{ + return (mode_set & RTEMS_PREEMPT_MASK) == RTEMS_PREEMPT; +} + +/*PAGE + * + * _Modes_Is_timeslice + * + * DESCRIPTION: + * + * This function returns TRUE if mode_set indicates that timeslicing + * is enabled, and FALSE otherwise. + */ + +STATIC INLINE boolean _Modes_Is_timeslice ( + Modes_Control mode_set +) +{ + return (mode_set & RTEMS_TIMESLICE_MASK) == RTEMS_TIMESLICE; +} + +/*PAGE + * + * _Modes_Get_interrupt_level + * + * DESCRIPTION: + * + * This function returns the interrupt level portion of the mode_set. + */ + +STATIC INLINE ISR_Level _Modes_Get_interrupt_level ( + Modes_Control mode_set +) +{ + return ( mode_set & RTEMS_INTERRUPT_MASK ); +} + +/*PAGE + * + * _Modes_Set_interrupt_level + * + * DESCRIPTION: + * + * This routine sets the current interrupt level to that specified + * in the mode_set. + */ + +STATIC INLINE void _Modes_Set_interrupt_level ( + Modes_Control mode_set +) +{ + _ISR_Set_level( _Modes_Get_interrupt_level( mode_set ) ); +} + +/*PAGE + * + * _Modes_Change + * + * DESCRIPTION: + * + * This routine changes the modes in old_mode_set indicated by + * mask to the requested values in new_mode_set. The resulting + * mode set is returned in out_mode_set and the modes that changed + * is returned in changed. + */ + +STATIC INLINE void _Modes_Change ( + Modes_Control old_mode_set, + Modes_Control new_mode_set, + Modes_Control mask, + Modes_Control *out_mode_set, + Modes_Control *changed +) +{ + Modes_Control _out_mode; + + _out_mode = old_mode_set; + _out_mode &= ~mask; + _out_mode |= new_mode_set & mask; + *changed = _out_mode ^ old_mode_set; + *out_mode_set = _out_mode; +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/options.inl b/cpukit/rtems/inline/rtems/rtems/options.inl new file mode 100644 index 0000000000..9dba30e895 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/options.inl @@ -0,0 +1,55 @@ +/* options.inl + * + * This file contains the static inline implementation of the inlined + * routines from the Options 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$ + */ + +#ifndef __OPTIONS_inl +#define __OPTIONS_inl + +/*PAGE + * + * _Options_Is_no_wait + * + * DESCRIPTION: + * + * This function returns TRUE if the RTEMS_NO_WAIT option is enabled in + * option_set, and FALSE otherwise. + */ + +STATIC INLINE boolean _Options_Is_no_wait ( + rtems_option option_set +) +{ + return (option_set & RTEMS_NO_WAIT); +} + +/*PAGE + * + * _Options_Is_any + * + * DESCRIPTION: + * + * This function returns TRUE if the RTEMS_EVENT_ANY option is enabled in + * OPTION_SET, and FALSE otherwise. + */ + +STATIC INLINE boolean _Options_Is_any ( + rtems_option option_set +) +{ + return (option_set & RTEMS_EVENT_ANY); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/part.inl b/cpukit/rtems/inline/rtems/rtems/part.inl new file mode 100644 index 0000000000..9088755aa7 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/part.inl @@ -0,0 +1,199 @@ +/* part.inl + * + * This file contains the macro implementation of all inlined routines + * in the Partition 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$ + */ + +#ifndef __PARTITION_inl +#define __PARTITION_inl + +/*PAGE + * + * _Partition_Allocate_buffer + * + * DESCRIPTION: + * + * This function attempts to allocate a buffer from the_partition. + * If successful, it returns the address of the allocated buffer. + * Otherwise, it returns NULL. + */ + +STATIC INLINE void *_Partition_Allocate_buffer ( + Partition_Control *the_partition +) +{ + return _Chain_Get( &the_partition->Memory ); +} + +/*PAGE + * + * _Partition_Free_buffer + * + * DESCRIPTION: + * + * This routine frees the_buffer to the_partition. + */ + +STATIC INLINE void _Partition_Free_buffer ( + Partition_Control *the_partition, + Chain_Node *the_buffer +) +{ + _Chain_Append( &the_partition->Memory, the_buffer ); +} + +/*PAGE + * + * _Partition_Is_buffer_on_boundary + * + * DESCRIPTION: + * + * This function returns TRUE if the_buffer is on a valid buffer + * boundary for the_partition, and FALSE otherwise. + */ + +STATIC INLINE boolean _Partition_Is_buffer_on_boundary ( + void *the_buffer, + Partition_Control *the_partition +) +{ + unsigned32 offset; + + offset = (unsigned32) _Addresses_Subtract( + the_buffer, + the_partition->starting_address + ); + + return ((offset % the_partition->buffer_size) == 0); +} + +/*PAGE + * + * _Partition_Is_buffer_valid + * + * DESCRIPTION: + * + * This function returns TRUE if the_buffer is a valid buffer from + * the_partition, otherwise FALSE is returned. + */ + +STATIC INLINE boolean _Partition_Is_buffer_valid ( + Chain_Node *the_buffer, + Partition_Control *the_partition +) +{ + void *starting; + void *ending; + + starting = the_partition->starting_address; + ending = _Addresses_Add_offset( starting, the_partition->length ); + + return ( + _Addresses_Is_in_range( the_buffer, starting, ending ) && + _Partition_Is_buffer_on_boundary( the_buffer, the_partition ) + ); +} + +/*PAGE + * + * _Partition_Is_buffer_size_aligned + * + * DESCRIPTION: + * + * This function returns TRUE if the use of the specified buffer_size + * will result in the allocation of buffers whose first byte is + * properly aligned, and FALSE otherwise. + */ + +STATIC INLINE boolean _Partition_Is_buffer_size_aligned ( + unsigned32 buffer_size +) +{ + return ((buffer_size % CPU_PARTITION_ALIGNMENT) == 0); +} + +/*PAGE + * + * _Partition_Allocate + * + * DESCRIPTION: + * + * This function allocates a partition control block from + * the inactive chain of free partition control blocks. + */ + +STATIC INLINE Partition_Control *_Partition_Allocate ( void ) +{ + return (Partition_Control *) _Objects_Allocate( &_Partition_Information ); +} + +/*PAGE + * + * _Partition_Free + * + * DESCRIPTION: + * + * This routine frees a partition control block to the + * inactive chain of free partition control blocks. + */ + +STATIC INLINE void _Partition_Free ( + Partition_Control *the_partition +) +{ + _Objects_Free( &_Partition_Information, &the_partition->Object ); +} + +/*PAGE + * + * _Partition_Get + * + * DESCRIPTION: + * + * This function maps partition IDs to partition control blocks. + * If ID corresponds to a local partition, then it returns + * the_partition control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. If the partition ID is global and + * resides on a remote node, then location is set to OBJECTS_REMOTE, + * and the_partition is undefined. Otherwise, location is set + * to OBJECTS_ERROR and the_partition is undefined. + */ + +STATIC INLINE Partition_Control *_Partition_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (Partition_Control *) + _Objects_Get( &_Partition_Information, id, location ); +} + +/*PAGE + * + * _Partition_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_partition is NULL + * and FALSE otherwise. + */ + +STATIC INLINE boolean _Partition_Is_null ( + Partition_Control *the_partition +) +{ + return ( the_partition == NULL ); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/ratemon.inl b/cpukit/rtems/inline/rtems/rtems/ratemon.inl new file mode 100644 index 0000000000..0450988329 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/ratemon.inl @@ -0,0 +1,143 @@ +/* ratemon.inl + * + * This file contains the static inline implementation of the inlined + * routines in the Rate Monotonic 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$ + */ + +#ifndef __RATE_MONOTONIC_inl +#define __RATE_MONOTONIC_inl + +/*PAGE + * + * _Rate_monotonic_Allocate + * + * DESCRIPTION: + * + * This function allocates a period control block from + * the inactive chain of free period control blocks. + */ + +STATIC INLINE Rate_monotonic_Control *_Rate_monotonic_Allocate( void ) +{ + return (Rate_monotonic_Control *) + _Objects_Allocate( &_Rate_monotonic_Information ); +} + +/*PAGE + * + * _Rate_monotonic_Free + * + * DESCRIPTION: + * + * This routine allocates a period control block from + * the inactive chain of free period control blocks. + */ + +STATIC INLINE void _Rate_monotonic_Free ( + Rate_monotonic_Control *the_period +) +{ + _Objects_Free( &_Rate_monotonic_Information, &the_period->Object ); +} + +/*PAGE + * + * _Rate_monotonic_Get + * + * DESCRIPTION: + * + * This function maps period IDs to period control blocks. + * If ID corresponds to a local period, then it returns + * the_period control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. Otherwise, location is set + * to OBJECTS_ERROR and the_period is undefined. + */ + +STATIC INLINE Rate_monotonic_Control *_Rate_monotonic_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (Rate_monotonic_Control *) + _Objects_Get( &_Rate_monotonic_Information, id, location ); +} + +/*PAGE + * + * _Rate_monotonic_Is_active + * + * DESCRIPTION: + * + * This function returns TRUE if the_period is in the ACTIVE state, + * and FALSE otherwise. + */ + +STATIC INLINE boolean _Rate_monotonic_Is_active ( + Rate_monotonic_Control *the_period +) +{ + return (the_period->state == RATE_MONOTONIC_ACTIVE); +} + +/*PAGE + * + * _Rate_monotonic_Is_inactive + * + * DESCRIPTION: + * + * This function returns TRUE if the_period is in the ACTIVE state, + * and FALSE otherwise. + */ + +STATIC INLINE boolean _Rate_monotonic_Is_inactive ( + Rate_monotonic_Control *the_period +) +{ + return (the_period->state == RATE_MONOTONIC_INACTIVE); +} + +/*PAGE + * + * _Rate_monotonic_Is_expired + * + * DESCRIPTION: + * + * This function returns TRUE if the_period is in the EXPIRED state, + * and FALSE otherwise. + */ + +STATIC INLINE boolean _Rate_monotonic_Is_expired ( + Rate_monotonic_Control *the_period +) +{ + return (the_period->state == RATE_MONOTONIC_EXPIRED); +} + +/*PAGE + * + * _Rate_monotonic_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_period is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _Rate_monotonic_Is_null ( + Rate_monotonic_Control *the_period +) +{ + return (the_period == NULL); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/region.inl b/cpukit/rtems/inline/rtems/rtems/region.inl new file mode 100644 index 0000000000..aae042bed4 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/region.inl @@ -0,0 +1,127 @@ +/* region.inl + * + * This file contains the macro implementation of the inlined + * routines from the Region 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$ + */ + +#ifndef __REGION_inl +#define __REGION_inl + +/*PAGE + * + * _Region_Allocate + * + * DESCRIPTION: + * + * This function allocates a region control block from + * the inactive chain of free region control blocks. + */ + +STATIC INLINE Region_Control *_Region_Allocate( void ) +{ + return (Region_Control *) _Objects_Allocate( &_Region_Information ); +} + +/*PAGE + * + * _Region_Free + * + * DESCRIPTION: + * + * This routine frees a region control block to the + * inactive chain of free region control blocks. + */ + +STATIC INLINE void _Region_Free ( + Region_Control *the_region +) +{ + _Objects_Free( &_Region_Information, &the_region->Object ); +} + +/*PAGE + * + * _Region_Get + * + * DESCRIPTION: + * + * This function maps region IDs to region control blocks. + * If ID corresponds to a local region, then it returns + * the_region control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. Otherwise, location is set + * to OBJECTS_ERROR and the_region is undefined. + */ + +STATIC INLINE Region_Control *_Region_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (Region_Control *) + _Objects_Get( &_Region_Information, id, location ); +} + +/*PAGE + * + * _Region_Allocate_segment + * + * DESCRIPTION: + * + * This function attempts to allocate a segment from the_region. + * If successful, it returns the address of the allocated segment. + * Otherwise, it returns NULL. + */ + +STATIC INLINE void *_Region_Allocate_segment ( + Region_Control *the_region, + unsigned32 size +) +{ + return _Heap_Allocate( &the_region->Memory, size ); +} + +/*PAGE + * + * _Region_Free_segment + * + * DESCRIPTION: + * + * This function frees the_segment to the_region. + */ + +STATIC INLINE boolean _Region_Free_segment ( + Region_Control *the_region, + void *the_segment +) +{ + return _Heap_Free( &the_region->Memory, the_segment ); +} + +/*PAGE + * + * _Region_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_region is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _Region_Is_null ( + Region_Control *the_region +) +{ + return ( the_region == NULL ); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/sem.inl b/cpukit/rtems/inline/rtems/rtems/sem.inl new file mode 100644 index 0000000000..c80431f9b1 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/sem.inl @@ -0,0 +1,93 @@ +/* sem.inl + * + * This file contains the static inlin implementation of the inlined + * routines from the Semaphore 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$ + */ + +#ifndef __SEMAPHORE_inl +#define __SEMAPHORE_inl + +/*PAGE + * + * _Semaphore_Allocate + * + * DESCRIPTION: + * + * This function allocates a semaphore control block from + * the inactive chain of free semaphore control blocks. + */ + +STATIC INLINE Semaphore_Control *_Semaphore_Allocate( void ) +{ + return (Semaphore_Control *) _Objects_Allocate( &_Semaphore_Information ); +} + +/*PAGE + * + * _Semaphore_Free + * + * DESCRIPTION: + * + * This routine frees a semaphore control block to the + * inactive chain of free semaphore control blocks. + */ + +STATIC INLINE void _Semaphore_Free ( + Semaphore_Control *the_semaphore +) +{ + _Objects_Free( &_Semaphore_Information, &the_semaphore->Object ); +} + +/*PAGE + * + * _Semaphore_Get + * + * DESCRIPTION: + * + * This function maps semaphore IDs to semaphore control blocks. + * If ID corresponds to a local semaphore, then it returns + * the_semaphore control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. if the semaphore ID is global and + * resides on a remote node, then location is set to OBJECTS_REMOTE, + * and the_semaphore is undefined. Otherwise, location is set + * to OBJECTS_ERROR and the_semaphore is undefined. + */ + +STATIC INLINE Semaphore_Control *_Semaphore_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (Semaphore_Control *) + _Objects_Get( &_Semaphore_Information, id, location ); +} + +/*PAGE + * + * _Semaphore_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_semaphore is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _Semaphore_Is_null ( + Semaphore_Control *the_semaphore +) +{ + return ( the_semaphore == NULL ); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/status.inl b/cpukit/rtems/inline/rtems/rtems/status.inl new file mode 100644 index 0000000000..f85b4c6d0b --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/status.inl @@ -0,0 +1,56 @@ +/* inline/status.inl + * + * This include file contains the implementations of the inlined + * routines for the status package. + * + * 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$ + */ + +#ifndef __INLINE_STATUS_inl +#define __INLINE_STATUS_inl + +/*PAGE + * + * rtems_is_status_successful + * + * DESCRIPTION: + * + * This function returns TRUE if the status code is equal to RTEMS_SUCCESSFUL, + * and FALSE otherwise. + */ + +STATIC INLINE boolean rtems_is_status_successful( + rtems_status_code code +) +{ + return (code == RTEMS_SUCCESSFUL); +} + +/*PAGE + * + * rtems_are_statuses_equal + * + * DESCRIPTION: + * + * This function returns TRUE if the status code1 is equal to code2, + * and FALSE otherwise. + */ + +STATIC INLINE boolean rtems_are_statuses_equal( + rtems_status_code code1, + rtems_status_code code2 +) +{ + return (code1 == code2); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/support.inl b/cpukit/rtems/inline/rtems/rtems/support.inl new file mode 100644 index 0000000000..856b24e7f9 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/support.inl @@ -0,0 +1,61 @@ +/* support.inl + * + * This include file contains the static inline implementation of all + * of the inlined routines specific to the RTEMS API. + * + * 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$ + */ + +#ifndef __RTEMS_SUPPORT_inl +#define __RTEMS_SUPPORT_inl + +/*PAGE + * + * rtems_is_name_valid + * + * DESCRIPTION: + * + * This function returns TRUE if the name is valid, and FALSE otherwise. + */ + +STATIC INLINE rtems_boolean rtems_is_name_valid ( + rtems_name name +) +{ + return ( name != 0 ); +} + +/*PAGE + * + * rtems_name_to_characters + * + * DESCRIPTION: + * + * This function breaks the object name into the four component + * characters C1, C2, C3, and C4. + */ + +STATIC INLINE void rtems_name_to_characters( + rtems_name name, + char *c1, + char *c2, + char *c3, + char *c4 +) +{ + *c1 = (name >> 24) & 0xff; + *c2 = (name >> 16) & 0xff; + *c3 = (name >> 8) & 0xff; + *c4 = name & 0xff; +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/tasks.inl b/cpukit/rtems/inline/rtems/rtems/tasks.inl new file mode 100644 index 0000000000..6caa34ea80 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/tasks.inl @@ -0,0 +1,90 @@ +/* tasks.inl + * + * This file contains the static inline implementation of all inlined + * routines in the with RTEMS Tasks 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$ + */ + +#ifndef __RTEMS_TASKS_inl +#define __RTEMS_TASKS_inl + +/*PAGE + * + * _RTEMS_tasks_Allocate + * + * DESCRIPTION: + * + * This function allocates a task control block from + * the inactive chain of free task control blocks. + */ + +STATIC INLINE Thread_Control *_RTEMS_tasks_Allocate( void ) +{ + return (Thread_Control *) _Objects_Allocate( &_RTEMS_tasks_Information ); +} + +/*PAGE + * + * _RTEMS_tasks_Free + * + * DESCRIPTION: + * + * This routine frees a task control block to the + * inactive chain of free task control blocks. + */ + +STATIC INLINE void _RTEMS_tasks_Free ( + Thread_Control *the_task +) +{ + _Objects_Free( + _Objects_Get_information( the_task->Object.id ), + &the_task->Object + ); +} + +/*PAGE + * + * _RTEMS_tasks_Priority_to_Core + * + * DESCRIPTION: + * + * This function converts an RTEMS API priority into a core priority. + */ + +STATIC INLINE Priority_Control _RTEMS_tasks_Priority_to_Core( + rtems_task_priority priority +) +{ + return (Priority_Control) priority; +} + +/*PAGE + * + * _RTEMS_tasks_Priority_is_valid + * + * DESCRIPTION: + * + * This function returns TRUE if the_priority is a valid user task priority + * and FALSE otherwise. + */ + +STATIC INLINE boolean _RTEMS_tasks_Priority_is_valid ( + rtems_task_priority the_priority +) +{ + return ( ( the_priority >= RTEMS_MINIMUM_PRIORITY ) && + ( the_priority <= RTEMS_MAXIMUM_PRIORITY ) ); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/inline/rtems/rtems/timer.inl b/cpukit/rtems/inline/rtems/rtems/timer.inl new file mode 100644 index 0000000000..dedcdffa36 --- /dev/null +++ b/cpukit/rtems/inline/rtems/rtems/timer.inl @@ -0,0 +1,142 @@ +/* timer.inl + * + * This file contains the static inline implementation of the inlined routines + * from the Timer 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$ + */ + +#ifndef __TIMER_inl +#define __TIMER_inl + +/*PAGE + * + * _Timer_Allocate + * + * DESCRIPTION: + * + * This function allocates a timer control block from + * the inactive chain of free timer control blocks. + */ + +STATIC INLINE Timer_Control *_Timer_Allocate( void ) +{ + return (Timer_Control *) _Objects_Allocate( &_Timer_Information ); +} + +/*PAGE + * + * _Timer_Free + * + * DESCRIPTION: + * + * This routine frees a timer control block to the + * inactive chain of free timer control blocks. + */ + +STATIC INLINE void _Timer_Free ( + Timer_Control *the_timer +) +{ + _Objects_Free( &_Timer_Information, &the_timer->Object ); +} + +/*PAGE + * + * _Timer_Get + * + * DESCRIPTION: + * + * This function maps timer IDs to timer control blocks. + * If ID corresponds to a local timer, then it returns + * the timer control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. Otherwise, location is set + * to OBJECTS_ERROR and the returned value is undefined. + */ + +STATIC INLINE Timer_Control *_Timer_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (Timer_Control *) + _Objects_Get( &_Timer_Information, id, location ); +} + +/*PAGE + * + * _Timer_Is_interval_class + * + * DESCRIPTION: + * + * This function returns TRUE if the class is that of an INTERVAL + * timer, and FALSE otherwise. + */ + +STATIC INLINE boolean _Timer_Is_interval_class ( + Timer_Classes the_class +) +{ + return ( the_class == TIMER_INTERVAL ); +} + +/*PAGE + * + * _Timer_Is_time_of_day_class + * + * DESCRIPTION: + * + * This function returns TRUE if the class is that of an INTERVAL + * timer, and FALSE otherwise. + */ + +STATIC INLINE boolean _Timer_Is_timer_of_day_class ( + Timer_Classes the_class +) +{ + return ( the_class == TIMER_TIME_OF_DAY ); +} + +/*PAGE + * + * _Timer_Is_dormant_class + * + * DESCRIPTION: + * + * This function returns TRUE if the class is that of a DORMANT + * timer, and FALSE otherwise. + */ + +STATIC INLINE boolean _Timer_Is_dormant_class ( + Timer_Classes the_class +) +{ + return ( the_class == TIMER_DORMANT ); +} + +/*PAGE + * + * _Timer_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_timer is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _Timer_Is_null ( + Timer_Control *the_timer +) +{ + return ( the_timer == NULL ); +} + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/asr.inl b/cpukit/rtems/macros/rtems/rtems/asr.inl new file mode 100644 index 0000000000..d6806b00f6 --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/asr.inl @@ -0,0 +1,90 @@ +/* macros/asr.h + * + * This include file contains the implemenation of all routines + * associated with the asynchronous signal handler which are inlined. + * + * 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$ + */ + +#ifndef __INLINE_ASR_h +#define __INLINE_ASR_h + +#include <rtems/score/isr.h> + +/*PAGE + * + * _ASR_Initialize + * + */ + +#define _ASR_Initialize( _information ) \ +{ \ + (_information)->is_enabled = TRUE; \ + (_information)->handler = NULL; \ + (_information)->mode_set = RTEMS_DEFAULT_MODES; \ + (_information)->signals_posted = 0; \ + (_information)->signals_pending = 0; \ + (_information)->nest_level = 0; \ +} + +/*PAGE + * + * _ASR_Swap_signals + * + */ + +#define _ASR_Swap_signals( _information ) \ +{ \ + rtems_signal_set _signals; \ + ISR_Level _level; \ + \ + _ISR_Disable( _level ); \ + _signals = (_information)->signals_pending; \ + (_information)->signals_pending = (_information)->signals_posted; \ + (_information)->signals_posted = _signals; \ + _ISR_Enable( _level ); \ +} + +/*PAGE + * + * _ASR_Is_null_handler + * + */ + +#define _ASR_Is_null_handler( _asr_handler ) \ + ( (_asr_handler) == NULL ) + +/*PAGE + * + * _ASR_Are_signals_pending + * + */ + +#define _ASR_Are_signals_pending( _information ) \ + ( (_information)->signals_posted != 0 ) + +/*PAGE + * + * _ASR_Post_signals + * + */ + +#define _ASR_Post_signals( _signals, _signal_set ) \ + do { \ + ISR_Level _level; \ + \ + _ISR_Disable( _level ); \ + *(_signal_set) |= (_signals); \ + _ISR_Enable( _level ); \ + } while ( 0 ) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/attr.inl b/cpukit/rtems/macros/rtems/rtems/attr.inl new file mode 100644 index 0000000000..27231871ba --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/attr.inl @@ -0,0 +1,91 @@ +/* macros/attr.h + * + * This include file contains all of the inlined routines associated + * with attributes. + * + * 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$ + */ + +#ifndef __MACROS_ATTRIBUTES_h +#define __MACROS_ATTRIBUTES_h + +/*PAGE + * + * _Attributes_Set + */ + +#define _Attributes_Set( _new_attributes, _attribute_set ) \ + ( (_attribute_set) | (_new_attributes) ) + +/*PAGE + * + * _Attributes_Clear + */ + +#define _Attributes_Clear( _attribute_set, _mask ) \ + ( (_attribute_set) & ~(_mask) ) + +/*PAGE + * + * _Attributes_Is_floating_point + * + */ + +#define _Attributes_Is_floating_point( _attribute_set ) \ + ( (_attribute_set) & RTEMS_FLOATING_POINT ) + +/*PAGE + * + * _Attributes_Is_global + * + */ + +#define _Attributes_Is_global( _attribute_set ) \ + ( (_attribute_set) & RTEMS_GLOBAL ) + +/*PAGE + * + * _Attributes_Is_priority + * + */ + +#define _Attributes_Is_priority( _attribute_set ) \ + ( (_attribute_set) & RTEMS_PRIORITY ) + +/*PAGE + * + * _Attributes_Is_binary_semaphore + * + */ + +#define _Attributes_Is_binary_semaphore( _attribute_set ) \ + ( (_attribute_set) & RTEMS_BINARY_SEMAPHORE ) + +/*PAGE + * + * _Attributes_Is_inherit_priority + * + */ + +#define _Attributes_Is_inherit_priority( _attribute_set ) \ + ( (_attribute_set) & RTEMS_INHERIT_PRIORITY ) + +/*PAGE + * + * _Attributes_Is_priority_ceiling + * + */ + +#define _Attributes_Is_priority_ceiling( _attribute_set ) \ + ( (_attribute_set) & RTEMS_PRIORITY_CEILING ) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/dpmem.inl b/cpukit/rtems/macros/rtems/rtems/dpmem.inl new file mode 100644 index 0000000000..3e1d7bce95 --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/dpmem.inl @@ -0,0 +1,59 @@ +/* macros/dpmem.h + * + * This include file contains the inline routine used in conjunction + * with the Dual Ported Memory 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$ + */ + +#ifndef __MACROS_DPMEM_h +#define __MACROS_DPMEM_h + +/*PAGE + * + * _Dual_ported_memory_Allocate + * + */ + +#define _Dual_ported_memory_Allocate() \ + (Dual_ported_memory_Control *) \ + _Objects_Allocate( &_Dual_ported_memory_Information ) + +/*PAGE + * + * _Dual_ported_memory_Free + * + */ + +#define _Dual_ported_memory_Free( _the_port ) \ + _Objects_Free( &_Dual_ported_memory_Information, &(_the_port)->Object ) + +/*PAGE + * + * _Dual_ported_memory_Get + * + */ + +#define _Dual_ported_memory_Get( _id, _location ) \ + (Dual_ported_memory_Control *) \ + _Objects_Get( &_Dual_ported_memory_Information, (_id), (_location) ) + + +/*PAGE + * + * _Dual_ported_memory_Is_null + */ + +#define _Dual_ported_memory_Is_null( _the_port ) \ + ( (_the_port) == NULL ) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/event.inl b/cpukit/rtems/macros/rtems/rtems/event.inl new file mode 100644 index 0000000000..e37f6813bf --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/event.inl @@ -0,0 +1,21 @@ +/* macros/event.h + * + * This include file contains the implementation of macros for + * the Event 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$ + */ + +#ifndef __MACROS_EVENT_h +#define __MACROS_EVENT_h + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/eventset.inl b/cpukit/rtems/macros/rtems/rtems/eventset.inl new file mode 100644 index 0000000000..1803d18637 --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/eventset.inl @@ -0,0 +1,53 @@ +/* eventset.inl + * + * This include file contains the macro implementation of inlined + * routines in the event set object. + * + * 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$ + */ + +#ifndef __EVENT_SET_inl +#define __EVENT_SET_inl + +/*PAGE + * + * _Event_sets_Is_empty + */ + +#define _Event_sets_Is_empty( _the_event_set ) \ + ((_the_event_set) == 0 ) + +/*PAGE + * + * _Event_sets_Is_empty + */ + +#define _Event_sets_Post( _the_new_events, _the_event_set ) \ + *(_the_event_set) |= (_the_new_events) + +/*PAGE + * + * _Event_sets_Is_empty + */ + +#define _Event_sets_Get( _the_event_set, _the_event_condition ) \ + ((_the_event_set) & (_the_event_condition)) + +/*PAGE + * + * _Event_sets_Clear + */ + +#define _Event_sets_Clear( _the_event_set, _the_mask ) \ + ((_the_event_set) & ~(_the_mask)) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/message.inl b/cpukit/rtems/macros/rtems/rtems/message.inl new file mode 100644 index 0000000000..62b6ac0ceb --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/message.inl @@ -0,0 +1,49 @@ +/* message.inl + * + * This include file contains the macro implementation of all + * inlined routines in the Message 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$ + */ + +#ifndef __MESSAGE_QUEUE_inl +#define __MESSAGE_QUEUE_inl + +/*PAGE + * + * _Message_queue_Is_null + * + */ + +#define _Message_queue_Is_null( _the_message_queue ) \ + ( (_the_message_queue) == NULL ) + +/*PAGE + * + * _Message_queue_Free + * + */ + +#define _Message_queue_Free( _the_message_queue ) \ + _Objects_Free( &_Message_queue_Information, &(_the_message_queue)->Object ) + +/*PAGE + * + * _Message_queue_Get + * + */ + +#define _Message_queue_Get( _id, _location ) \ + (Message_queue_Control *) \ + _Objects_Get( &_Message_queue_Information, (_id), (_location) ) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/modes.inl b/cpukit/rtems/macros/rtems/rtems/modes.inl new file mode 100644 index 0000000000..a7dea6516d --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/modes.inl @@ -0,0 +1,92 @@ +/* modes.inl + * + * This include file contains the macro implementation of the + * inlined routines in the Mode 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$ + */ + +#ifndef __MODES_inl +#define __MODES_inl + +/*PAGE + * + * _Modes_Mask_changed + * + */ + +#define _Modes_Mask_changed( _mode_set, _masks ) \ + ( (_mode_set) & (_masks) ) + +/*PAGE + * + * _Modes_Is_asr_disabled + * + */ + +#define _Modes_Is_asr_disabled( _mode_set ) \ + (((_mode_set) & RTEMS_ASR_MASK) == RTEMS_NO_ASR) + +/*PAGE + * + * _Modes_Is_preempt + * + */ + +#define _Modes_Is_preempt( _mode_set ) \ + ( ( (_mode_set) & RTEMS_PREEMPT_MASK ) == RTEMS_PREEMPT ) + +/*PAGE + * + * _Modes_Is_timeslice + * + */ + +#define _Modes_Is_timeslice( _mode_set ) \ + (((_mode_set) & RTEMS_TIMESLICE_MASK) == RTEMS_TIMESLICE) + +/*PAGE + * + * _Modes_Get_interrupt_level + * + */ + +#define _Modes_Get_interrupt_level( _mode_set ) \ + ( (_mode_set) & RTEMS_INTERRUPT_MASK ) + +/*PAGE + * + * _Modes_Set_interrupt_level + * + */ + +#define _Modes_Set_interrupt_level( _mode_set ) \ + _ISR_Set_level( _Modes_Get_interrupt_level( (_mode_set) ) ) + +/*PAGE + * + * _Modes_Change + * + */ + +#define _Modes_Change( _old_mode_set, _new_mode_set, \ + _mask, _out_mode_set, _changed ) \ + { Modes_Control _out_mode; \ + \ + _out_mode = (_old_mode_set); \ + _out_mode &= ~(_mask); \ + _out_mode |= (_new_mode_set) & (_mask); \ + *(_changed) = _out_mode ^ (_old_mode_set); \ + *(_out_mode_set) = _out_mode; \ + } + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/options.inl b/cpukit/rtems/macros/rtems/rtems/options.inl new file mode 100644 index 0000000000..7c14e4fe4f --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/options.inl @@ -0,0 +1,39 @@ +/* options.inl + * + * This file contains the macro implementation of the inlined + * routines from the Options 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$ + */ + +#ifndef __OPTIONS_inl +#define __OPTIONS_inl + +/*PAGE + * + * _Options_Is_no_wait + * + */ + +#define _Options_Is_no_wait( _option_set ) \ + ( (_option_set) & RTEMS_NO_WAIT ) + +/*PAGE + * + * _Options_Is_any + * + */ + +#define _Options_Is_any( _option_set ) \ + ( (_option_set) & RTEMS_EVENT_ANY ) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/part.inl b/cpukit/rtems/macros/rtems/rtems/part.inl new file mode 100644 index 0000000000..55c188b210 --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/part.inl @@ -0,0 +1,117 @@ +/* part.inl + * + * This file contains the macro implementation of all inlined routines + * in the Partition 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$ + */ + +#ifndef __PARTITION_inl +#define __PARTITION_inl + +/*PAGE + * + * _Partition_Allocate_buffer + * + */ + +#define _Partition_Allocate_buffer( _the_partition ) \ + _Chain_Get( &(_the_partition)->Memory ) + +/*PAGE + * + * _Partition_Free_buffer + * + */ + +#define _Partition_Free_buffer( _the_partition, _the_buffer ) \ + _Chain_Append( &(_the_partition)->Memory, (_the_buffer) ) + +/*PAGE + * + * _Partition_Is_buffer_on_boundary + * + */ + +#define _Partition_Is_buffer_on_boundary( _the_buffer, _the_partition ) \ + ((((unsigned32) _Addresses_Subtract( \ + (_the_buffer), \ + (_the_partition)->starting_address ) \ + ) % \ + (_the_partition)->buffer_size) == 0) + +/*PAGE + * + * _Partition_Is_buffer_valid + * + */ + +#define _Partition_Is_buffer_valid( _the_buffer, _the_partition ) \ + ( \ + _Addresses_Is_in_range( \ + (_the_buffer), \ + (_the_partition)->starting_address, \ + _Addresses_Add_offset( \ + (_the_partition)->starting_address, \ + (_the_partition)->length \ + ) \ + ) && \ + _Partition_Is_buffer_on_boundary( (_the_buffer), (_the_partition) ) \ + ) + +/*PAGE + * + * _Partition_Is_buffer_size_aligned + * + */ + +#define _Partition_Is_buffer_size_aligned( _buffer_size ) \ + ((_buffer_size) % CPU_PARTITION_ALIGNMENT == 0) + +/*PAGE + * + * _Partition_Allocate + * + */ + +#define _Partition_Allocate() \ + (Partition_Control *) _Objects_Allocate( &_Partition_Information ) + +/*PAGE + * + * _Partition_Free + * + */ + +#define _Partition_Free( _the_partition ) \ + _Objects_Free( &_Partition_Information, &(_the_partition)->Object ) + +/*PAGE + * + * _Partition_Get + * + */ + +#define _Partition_Get( _id, _location ) \ + (Partition_Control *) \ + _Objects_Get( &_Partition_Information, (_id), (_location) ) + +/*PAGE + * + * _Partition_Is_null + * + */ + +#define _Partition_Is_null( _the_partition ) \ + ( (_the_partition) == NULL ) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/ratemon.inl b/cpukit/rtems/macros/rtems/rtems/ratemon.inl new file mode 100644 index 0000000000..ebb182e6f1 --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/ratemon.inl @@ -0,0 +1,85 @@ +/* ratemon.inl + * + * This file contains the macro implementation of the inlined + * routines in the Rate Monotonic 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$ + */ + +#ifndef __RATE_MONOTONIC_inl +#define __RATE_MONOTONIC_inl + +/*PAGE + * + * _Rate_monotonic_Allocate + * + */ + +#define _Rate_monotonic_Allocate() \ + (Rate_monotonic_Control *) \ + _Objects_Allocate( &_Rate_monotonic_Information ) + +/*PAGE + * + * _Rate_monotonic_Free + * + */ + +#define _Rate_monotonic_Free( _the_period ) \ + _Objects_Free( &_Rate_monotonic_Information, &(_the_period)->Object ) + +/*PAGE + * + * _Rate_monotonic_Get + * + */ + +#define _Rate_monotonic_Get( _id, _location ) \ + (Rate_monotonic_Control *) \ + _Objects_Get( &_Rate_monotonic_Information, (_id), (_location) ) + +/*PAGE + * + * _Rate_monotonic_Is_active + * + */ + +#define _Rate_monotonic_Is_active( _the_period ) \ + ((_the_period)->state == RATE_MONOTONIC_ACTIVE) + +/*PAGE + * + * _Rate_monotonic_Is_inactive + * + */ + +#define _Rate_monotonic_Is_inactive( _the_period ) \ + ((_the_period)->state == RATE_MONOTONIC_INACTIVE) + +/*PAGE + * + * _Rate_monotonic_Is_expired + * + */ + +#define _Rate_monotonic_Is_expired( _the_period ) \ + ((_the_period)->state == RATE_MONOTONIC_EXPIRED) + +/*PAGE + * + * _Rate_monotonic_Is_null + * + */ + +#define _Rate_monotonic_Is_null( _the_period ) ( (_the_period) == NULL ) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/region.inl b/cpukit/rtems/macros/rtems/rtems/region.inl new file mode 100644 index 0000000000..667d77e307 --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/region.inl @@ -0,0 +1,75 @@ +/* region.inl + * + * This file contains the macro implementation of the inlined + * routines from the Region 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$ + */ + +#ifndef __REGION_inl +#define __REGION_inl + +/*PAGE + * + * _Region_Allocate + * + */ + +#define _Region_Allocate() \ + (Region_Control *) _Objects_Allocate( &_Region_Information ) + +/*PAGE + * + * _Region_Free + * + */ + +#define _Region_Free( _the_region ) \ + _Objects_Free( &_Region_Information, &(_the_region)->Object ) + +/*PAGE + * + * _Region_Get + * + */ + +#define _Region_Get( _id, _location ) \ + (Region_Control *) \ + _Objects_Get( &_Region_Information, (_id), (_location) ) + +/*PAGE + * + * _Region_Allocate_segment + * + */ + +#define _Region_Allocate_segment( _the_region, _size ) \ + _Heap_Allocate( &(_the_region)->Memory, (_size) ) + +/*PAGE + * + * _Region_Free_segment + * + */ + +#define _Region_Free_segment( _the_region, _the_segment ) \ + _Heap_Free( &(_the_region)->Memory, (_the_segment) ) + +/*PAGE + * + * _Region_Is_null + * + */ + +#define _Region_Is_null( _the_region ) ( (_the_region) == NULL ) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/sem.inl b/cpukit/rtems/macros/rtems/rtems/sem.inl new file mode 100644 index 0000000000..7e94069009 --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/sem.inl @@ -0,0 +1,58 @@ +/* sem.inl + * + * This file contains the macro implementation of the inlined + * routines from the Semaphore 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$ + */ + +#ifndef __SEMAPHORE_inl +#define __SEMAPHORE_inl + +/*PAGE + * + * _Semaphore_Allocate + * + */ + +#define _Semaphore_Allocate() \ + (Semaphore_Control *) _Objects_Allocate( &_Semaphore_Information ) + +/*PAGE + * + * _Semaphore_Free + * + */ + +#define _Semaphore_Free( _the_semaphore ) \ + _Objects_Free( &_Semaphore_Information, &(_the_semaphore)->Object ) + +/*PAGE + * + * _Semaphore_Get + * + */ + +#define _Semaphore_Get( _id, _location ) \ + (Semaphore_Control *) \ + _Objects_Get( &_Semaphore_Information, (_id), (_location) ) + +/*PAGE + * + * _Semaphore_Is_null + * + */ + +#define _Semaphore_Is_null( _the_semaphore ) \ + ( (_the_semaphore) == NULL ) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/status.inl b/cpukit/rtems/macros/rtems/rtems/status.inl new file mode 100644 index 0000000000..408cb816d1 --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/status.inl @@ -0,0 +1,39 @@ +/* macros/status.h + * + * This include file contains the implementations of the inlined + * routines for the status package. + * + * 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$ + */ + +#ifndef __MACROS_STATUS_h +#define __MACROS_STATUS_h + +/*PAGE + * + * rtems_is_status_successful + * + */ + +#define rtems_is_status_successful( _code ) \ + ( (_code) == RTEMS_SUCCESSFUL ) + +/*PAGE + * + * rtems_are_statuses_equal + * + */ + +#define rtems_are_statuses_equal( _code1, _code2 ) \ + ((_code1) == (_code2)) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/support.inl b/cpukit/rtems/macros/rtems/rtems/support.inl new file mode 100644 index 0000000000..a25b445aff --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/support.inl @@ -0,0 +1,44 @@ +/* support.inl + * + * This include file contains the macros implementation of all + * of the inlined routines specific to the RTEMS API. + * + * 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$ + */ + +#ifndef __RTEMS_SUPPORT_inl +#define __RTEMS_SUPPORT_inl + +/*PAGE + * + * rtems_is_name_valid + * + */ + +#define rtems_is_name_valid( _name ) \ + ( (_name) != 0 ) + +/*PAGE + * + * rtems_name_to_characters + * + */ + +#define rtems_name_to_characters( _name, _c1, _c2, _c3, _c4 ) \ + { \ + (*(_c1) = ((_name) >> 24) & 0xff; \ + (*(_c2) = ((_name) >> 16) & 0xff; \ + (*(_c3) = ((_name) >> 8) & 0xff; \ + (*(_c4) = ((_name)) & 0xff; \ + } + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/tasks.inl b/cpukit/rtems/macros/rtems/rtems/tasks.inl new file mode 100644 index 0000000000..8dd6ff351b --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/tasks.inl @@ -0,0 +1,58 @@ +/* tasks.inl + * + * This file contains the macro implementation of all inlined + * routines in the with RTEMS Tasks 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$ + */ + +#ifndef __RTEMS_TASKS_inl +#define __RTEMS_TASKS_inl + +/*PAGE + * + * _RTEMS_tasks_Allocate + * + */ + +#define _RTEMS_tasks_Allocate() \ + (Thread_Control *) _Objects_Allocate( &_RTEMS_tasks_Information ) + +/*PAGE + * + * _RTEMS_tasks_Free + * + */ + +#define _RTEMS_tasks_Free( _the_task ) \ + _Objects_Free( &_RTEMS_tasks_Information, &(_the_task)->Object ) + +/*PAGE + * + * _RTEMS_tasks_Priority_to_Core + */ + +#define _RTEMS_tasks_Priority_to_Core( _priority ) \ + ((Priority_Control) (_priority)) + +/*PAGE + * + * _RTEMS_tasks_Priority_is_valid + * + */ + +#define _RTEMS_tasks_Priority_is_valid( _the_priority ) \ + ( ((_the_priority) >= RTEMS_MINIMUM_PRIORITY) && \ + ((_the_priority) <= RTEMS_MAXIMUM_PRIORITY) ) + + +#endif +/* end of include file */ diff --git a/cpukit/rtems/macros/rtems/rtems/timer.inl b/cpukit/rtems/macros/rtems/rtems/timer.inl new file mode 100644 index 0000000000..9026bed570 --- /dev/null +++ b/cpukit/rtems/macros/rtems/rtems/timer.inl @@ -0,0 +1,85 @@ +/* timer.inl + * + * This file contains the macro implementation of the inlined routines + * from the Timer 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$ + */ + +#ifndef __TIMER_inl +#define __TIMER_inl + +/*PAGE + * + * _Timer_Allocate + * + */ + +#define _Timer_Allocate() \ + (Timer_Control *) _Objects_Allocate( &_Timer_Information ) + +/*PAGE + * + * _Timer_Free + * + */ + +#define _Timer_Free( _the_timer ) \ + _Objects_Free( &_Timer_Information, &(_the_timer)->Object ) + +/*PAGE + * + * _Timer_Get + * + */ + +#define _Timer_Get( _id, _location ) \ + (Timer_Control *) \ + _Objects_Get( &_Timer_Information, (_id), (_location) ) + +/*PAGE + * + * _Timer_Is_interval_class + * + */ + +#define _Timer_Is_interval_class( _the_class ) \ + ( (_the_class) == TIMER_INTERVAL ) + +/*PAGE + * + * _Timer_Is_time_of_day_class + * + */ + +#define _Timer_Is_time_of_day_class( _the_class ) \ + ( (_the_class) == TIMER_TIME_OF_DAY ) + +/*PAGE + * + * _Timer_Is_dormant_class + * + */ + +#define _Timer_Is_dormant_class( _the_class ) \ + ( (_the_class) == TIMER_DORMANT ) + +/*PAGE + * + * _Timer_Is_null + * + */ + +#define _Timer_Is_null( _the_timer ) \ + ( (_the_timer) == NULL ) + +#endif +/* end of include file */ diff --git a/cpukit/rtems/src/dpmem.c b/cpukit/rtems/src/dpmem.c new file mode 100644 index 0000000000..982116d859 --- /dev/null +++ b/cpukit/rtems/src/dpmem.c @@ -0,0 +1,281 @@ +/* + * Dual Port Memory 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/support.h> +#include <rtems/score/address.h> +#include <rtems/rtems/dpmem.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/rtems/dpmem.h> + +/*PAGE + * + * _Dual_ported_memory_Manager_initialization + * + * This routine initializes all dual-ported memory manager related + * data structures. + * + * Input parameters: + * maximum_ports - number of ports to initialize + * + * Output parameters: NONE + */ + +void _Dual_ported_memory_Manager_initialization( + unsigned32 maximum_ports +) +{ + _Objects_Initialize_information( + &_Dual_ported_memory_Information, + OBJECTS_RTEMS_PORTS, + FALSE, + maximum_ports, + sizeof( Dual_ported_memory_Control ), + FALSE, + RTEMS_MAXIMUM_NAME_LENGTH, + FALSE + ); +} + +/*PAGE + * + * rtems_port_create + * + * This directive creates a port into a dual-ported memory area. + * + * Input parameters: + * name - user defined port name + * internal_start - internal start address of port + * external_start - external start address of port + * length - physical length in bytes + * id - address of port id to set + * + * Output parameters: + * id - port id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_port_create( + rtems_name name, + void *internal_start, + void *external_start, + unsigned32 length, + Objects_Id *id +) +{ + register Dual_ported_memory_Control *the_port; + + if ( !rtems_is_name_valid( name) ) + return RTEMS_INVALID_NAME; + + if ( !_Addresses_Is_aligned( internal_start ) || + !_Addresses_Is_aligned( external_start ) ) + return RTEMS_INVALID_ADDRESS; + + _Thread_Disable_dispatch(); /* to prevent deletion */ + + the_port = _Dual_ported_memory_Allocate(); + + if ( !the_port ) { + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + the_port->internal_base = internal_start; + the_port->external_base = external_start; + the_port->length = length - 1; + + _Objects_Open( + &_Dual_ported_memory_Information, + &the_port->Object, + &name + ); + + *id = the_port->Object.id; + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_port_ident + * + * This directive returns the system ID associated with + * the port name. + * + * Input parameters: + * name - user defined port name + * id - pointer to port id + * + * Output parameters: + * *id - port id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_port_ident( + rtems_name name, + Objects_Id *id +) +{ + Objects_Name_to_id_errors status; + + status = _Objects_Name_to_id( + &_Dual_ported_memory_Information, + &name, + OBJECTS_SEARCH_ALL_NODES, + id + ); + + return _Status_Object_name_errors_to_status[ status ]; +} + +/*PAGE + * + * rtems_port_delete + * + * This directive allows a thread to delete a dual-ported memory area + * specified by the dual-ported memory identifier. + * + * Input parameters: + * id - dual-ported memory area id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_port_delete( + Objects_Id id +) +{ + register Dual_ported_memory_Control *the_port; + Objects_Locations location; + + the_port = _Dual_ported_memory_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* this error cannot be returned */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + _Objects_Close( &_Dual_ported_memory_Information, &the_port->Object ); + _Dual_ported_memory_Free( the_port ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_port_internal_to_external + * + * This directive converts an internal dual-ported memory address to an + * external dual-ported memory address. If the given internal address + * is an invalid dual-ported address, then the external address is set + * to the given internal address. + * + * Input parameters: + * id - id of dual-ported memory object + * internal - internal address to set + * external - pointer to external address + * + * Output parameters: + * external - external address + * RTEMS_SUCCESSFUL - always succeeds + */ + +rtems_status_code rtems_port_internal_to_external( + Objects_Id id, + void *internal, + void **external +) +{ + register Dual_ported_memory_Control *the_port; + Objects_Locations location; + unsigned32 ending; + + the_port = _Dual_ported_memory_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* this error cannot be returned */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + ending = _Addresses_Subtract( internal, the_port->internal_base ); + if ( ending > the_port->length ) + *external = internal; + else + *external = _Addresses_Add_offset( the_port->external_base, + ending ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_port_external_to_internal + * + * This directive converts an external dual-ported memory address to an + * internal dual-ported memory address. If the given external address + * is an invalid dual-ported address, then the internal address is set + * to the given external address. + * + * Input parameters: + * id - id of dp memory object + * external - external address + * internal - pointer of internal address to set + * + * Output parameters: + * internal - internal address + * RTEMS_SUCCESSFUL - always succeeds + */ + +rtems_status_code rtems_port_external_to_internal( + Objects_Id id, + void *external, + void **internal +) +{ + register Dual_ported_memory_Control *the_port; + Objects_Locations location; + unsigned32 ending; + + the_port = _Dual_ported_memory_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* this error cannot be returned */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + ending = _Addresses_Subtract( external, the_port->external_base ); + if ( ending > the_port->length ) + *internal = external; + else + *internal = _Addresses_Add_offset( the_port->internal_base, + ending ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} diff --git a/cpukit/rtems/src/event.c b/cpukit/rtems/src/event.c new file mode 100644 index 0000000000..ab00bc757e --- /dev/null +++ b/cpukit/rtems/src/event.c @@ -0,0 +1,383 @@ +/* + * Event 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/event.h> +#include <rtems/score/isr.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/rtems/tasks.h> + +/*PAGE + * + * _Event_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Event_Manager_initialization( void ) +{ + _Event_Sync_state = EVENT_SYNC_SYNCHRONIZED; + + /* + * Register the MP Process Packet routine. + */ + + _MPCI_Register_packet_processor( MP_PACKET_EVENT, _Event_MP_Process_packet ); +} + +/*PAGE + * + * rtems_event_send + * + * This directive allows a thread send an event set to another thread. + * + * Input parameters: + * id - thread id + * event - event set + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_event_send( + Objects_Id id, + rtems_event_set event_in +) +{ + register Thread_Control *the_thread; + Objects_Locations location; + RTEMS_API_Control *api; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + return( + _Event_MP_Send_request_packet( + EVENT_MP_SEND_REQUEST, + id, + event_in + ) + ); + case OBJECTS_LOCAL: + api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; + _Event_sets_Post( event_in, &api->pending_events ); + _Event_Surrender( the_thread ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_event_receive + * + * This directive allows a thread to receive a set of events. + * + * Input parameters: + * event_in - input event condition + * option_set - options + * ticks - number of ticks to wait (0 means wait forever) + * event_out - pointer to output event set + * + * Output parameters: + * event out - event set + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_event_receive( + rtems_event_set event_in, + rtems_option option_set, + rtems_interval ticks, + rtems_event_set *event_out +) +{ + RTEMS_API_Control *api; + + api = _Thread_Executing->API_Extensions[ THREAD_API_RTEMS ]; + + if ( _Event_sets_Is_empty( event_in ) ) { + *event_out = api->pending_events; + return RTEMS_SUCCESSFUL; + } + + _Thread_Disable_dispatch(); + _Event_Seize( event_in, option_set, ticks, event_out ); + _Thread_Enable_dispatch(); + return( _Thread_Executing->Wait.return_code ); +} + + +/*PAGE + * + * _Event_Seize + * + * This routine attempts to satisfy the requested event condition + * for the running thread. + * + * Input parameters: + * event_in - the event condition to satisfy + * option_set - acquire event options + * ticks - interval to wait + * event_out - pointer to event set output area + * + * Output parameters: NONE + * *event_out - event set output area filled in + * + * INTERRUPT LATENCY: + * available + * wait + * check sync + */ + +void _Event_Seize( + rtems_event_set event_in, + rtems_option option_set, + rtems_interval ticks, + rtems_event_set *event_out +) +{ + Thread_Control *executing; + rtems_event_set seized_events; + rtems_event_set pending_events; + ISR_Level level; + RTEMS_API_Control *api; + Event_Sync_states sync_state; + + executing = _Thread_Executing; + executing->Wait.return_code = RTEMS_SUCCESSFUL; + + api = executing->API_Extensions[ THREAD_API_RTEMS ]; + + _ISR_Disable( level ); + pending_events = api->pending_events; + seized_events = _Event_sets_Get( pending_events, event_in ); + + if ( !_Event_sets_Is_empty( seized_events ) && + (seized_events == event_in || _Options_Is_any( option_set )) ) { + api->pending_events = + _Event_sets_Clear( pending_events, seized_events ); + _ISR_Enable( level ); + *event_out = seized_events; + return; + } + + if ( _Options_Is_no_wait( option_set ) ) { + _ISR_Enable( level ); + executing->Wait.return_code = RTEMS_UNSATISFIED; + *event_out = seized_events; + return; + } + + _Event_Sync_state = EVENT_SYNC_NOTHING_HAPPENED; + + executing->Wait.option = (unsigned32) option_set; + executing->Wait.count = (unsigned32) event_in; + executing->Wait.return_argument = event_out; + + _ISR_Enable( level ); + + if ( ticks ) { + _Watchdog_Initialize( + &executing->Timer, + _Event_Timeout, + executing->Object.id, + NULL + ); + _Watchdog_Insert_ticks( &executing->Timer, ticks ); + } + + _Thread_Set_state( executing, STATES_WAITING_FOR_EVENT ); + + _ISR_Disable( level ); + + sync_state = _Event_Sync_state; + _Event_Sync_state = EVENT_SYNC_SYNCHRONIZED; + + switch ( sync_state ) { + case EVENT_SYNC_SYNCHRONIZED: + /* + * This cannot happen. It indicates that this routine did not + * enter the synchronization states above. + */ + return; + + case EVENT_SYNC_NOTHING_HAPPENED: + _ISR_Enable( level ); + return; + + case EVENT_SYNC_TIMEOUT: + executing->Wait.return_code = RTEMS_TIMEOUT; + _ISR_Enable( level ); + _Thread_Unblock( executing ); + return; + + case EVENT_SYNC_SATISFIED: + if ( _Watchdog_Is_active( &executing->Timer ) ) { + _Watchdog_Deactivate( &executing->Timer ); + _ISR_Enable( level ); + (void) _Watchdog_Remove( &executing->Timer ); + } else + _ISR_Enable( level ); + _Thread_Unblock( executing ); + return; + } +} + +/*PAGE + * + * _Event_Surrender + * + * This routines remove a thread from the specified threadq. + * + * Input parameters: + * the_thread - pointer to thread to be dequeued + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * before flash + * after flash + * check sync + */ + +void _Event_Surrender( + Thread_Control *the_thread +) +{ + ISR_Level level; + rtems_event_set pending_events; + rtems_event_set event_condition; + rtems_event_set seized_events; + rtems_option option_set; + RTEMS_API_Control *api; + + api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; + + option_set = (rtems_option) the_thread->Wait.option; + + _ISR_Disable( level ); + pending_events = api->pending_events; + event_condition = (rtems_event_set) the_thread->Wait.count; + + seized_events = _Event_sets_Get( pending_events, event_condition ); + + if ( !_Event_sets_Is_empty( seized_events ) ) { + if ( _States_Is_waiting_for_event( the_thread->current_state ) ) { + if ( seized_events == event_condition || _Options_Is_any( option_set ) ) { + api->pending_events = + _Event_sets_Clear( pending_events, seized_events ); + *(rtems_event_set *)the_thread->Wait.return_argument = seized_events; + + _ISR_Flash( level ); + + if ( !_Watchdog_Is_active( &the_thread->Timer ) ) { + _ISR_Enable( level ); + _Thread_Unblock( the_thread ); + } + else { + _Watchdog_Deactivate( &the_thread->Timer ); + _ISR_Enable( level ); + (void) _Watchdog_Remove( &the_thread->Timer ); + _Thread_Unblock( the_thread ); + } + return; + } + } + + switch ( _Event_Sync_state ) { + case EVENT_SYNC_SYNCHRONIZED: + case EVENT_SYNC_SATISFIED: + break; + + case EVENT_SYNC_NOTHING_HAPPENED: + case EVENT_SYNC_TIMEOUT: + if ( !_Thread_Is_executing( the_thread ) ) + break; + + if ( seized_events == event_condition || _Options_Is_any(option_set) ) { + api->pending_events = + _Event_sets_Clear( pending_events,seized_events ); + *(rtems_event_set *)the_thread->Wait.return_argument = seized_events; + _Event_Sync_state = EVENT_SYNC_SATISFIED; + } + break; + } + } + _ISR_Enable( level ); +} + +/*PAGE + * + * _Event_Timeout + * + * This routine processes a thread which timeouts while waiting to + * receive an event_set. It is called by the watchdog handler. + * + * Input parameters: + * id - thread id + * + * Output parameters: NONE + */ + +void _Event_Timeout( + Objects_Id id, + void *ignored +) +{ + Thread_Control *the_thread; + Objects_Locations location; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + case OBJECTS_REMOTE: /* impossible */ + break; + case OBJECTS_LOCAL: + + /* + * If the event manager is not synchronized, then it is either + * "nothing happened", "timeout", or "satisfied". If the_thread + * is the executing thread, then it is in the process of blocking + * and it is the thread which is responsible for the synchronization + * process. + * + * If it is not satisfied, then it is "nothing happened" and + * this is the "timeout" transition. After a request is satisfied, + * a timeout is not allowed to occur. + */ + + if ( _Event_Sync_state != EVENT_SYNC_SYNCHRONIZED && + _Thread_Is_executing( the_thread ) ) { + if ( _Event_Sync_state != EVENT_SYNC_SATISFIED ) + _Event_Sync_state = EVENT_SYNC_TIMEOUT; + } else { + the_thread->Wait.return_code = RTEMS_TIMEOUT; + _Thread_Unblock( the_thread ); + } + _Thread_Unnest_dispatch(); + break; + } +} diff --git a/cpukit/rtems/src/eventmp.c b/cpukit/rtems/src/eventmp.c new file mode 100644 index 0000000000..30cd1166c6 --- /dev/null +++ b/cpukit/rtems/src/eventmp.c @@ -0,0 +1,190 @@ +/* + * Multiprocessing Support for the Event 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/event.h> +#include <rtems/score/mpci.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/rtems/support.h> + +/*PAGE + * + * _Event_MP_Send_process_packet + * + * This subprogram is not needed since there are no process + * packets to be sent by this manager. + * + */ + +/*PAGE + * + * _Event_MP_Send_request_packet + * + */ + +rtems_status_code _Event_MP_Send_request_packet ( + Event_MP_Remote_operations operation, + Objects_Id event_id, + rtems_event_set event_in +) +{ + Event_MP_Packet *the_packet; + + switch ( operation ) { + + case EVENT_MP_SEND_REQUEST: + + the_packet = _Event_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_EVENT; + the_packet->Prefix.length = sizeof ( Event_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( Event_MP_Packet ); + the_packet->operation = operation; + the_packet->Prefix.id = event_id; + the_packet->event_in = event_in; + + return + _MPCI_Send_request_packet( + rtems_get_node( event_id ), + &the_packet->Prefix, + STATES_READY + ); + + break; + + case EVENT_MP_SEND_RESPONSE: + break; + + } + /* + * The following line is included to satisfy compilers which + * produce warnings when a function does not end with a return. + */ + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * _Event_MP_Send_response_packet + * + */ + +void _Event_MP_Send_response_packet ( + Event_MP_Remote_operations operation, + Thread_Control *the_thread +) +{ + Event_MP_Packet *the_packet; + + switch ( operation ) { + + case EVENT_MP_SEND_RESPONSE: + + the_packet = ( Event_MP_Packet *) the_thread->receive_packet; + +/* + * The packet being returned already contains the class, length, and + * to_convert fields, therefore they are not set in this routine. + */ + the_packet->operation = operation; + the_packet->Prefix.id = the_packet->Prefix.source_tid; + + _MPCI_Send_response_packet( + rtems_get_node( the_packet->Prefix.source_tid ), + &the_packet->Prefix + ); + break; + + case EVENT_MP_SEND_REQUEST: + break; + + } +} + +/*PAGE + * + * + * _Event_MP_Process_packet + * + */ + +void _Event_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +) +{ + Event_MP_Packet *the_packet; + Thread_Control *the_thread; + + the_packet = (Event_MP_Packet *) the_packet_prefix; + + switch ( the_packet->operation ) { + + case EVENT_MP_SEND_REQUEST: + + the_packet->Prefix.return_code = rtems_event_send( + the_packet->Prefix.id, + the_packet->event_in + ); + + _Event_MP_Send_response_packet( + EVENT_MP_SEND_RESPONSE, + _Thread_Executing + ); + break; + + case EVENT_MP_SEND_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + _MPCI_Return_packet( the_packet_prefix ); + + break; + + } +} + +/*PAGE + * + * _Event_MP_Send_object_was_deleted + * + * This subprogram is not needed since there are no objects + * deleted by this manager. + * + */ + +/*PAGE + * + * _Event_MP_Send_extract_proxy + * + * This subprogram is not needed since there are no objects + * deleted by this manager. + * + */ + +/*PAGE + * + * _Event_MP_Get_packet + * + */ + +Event_MP_Packet *_Event_MP_Get_packet ( void ) +{ + return ( (Event_MP_Packet *) _MPCI_Get_packet() ); +} + +/* end of file */ diff --git a/cpukit/rtems/src/intr.c b/cpukit/rtems/src/intr.c new file mode 100644 index 0000000000..8ec880ee99 --- /dev/null +++ b/cpukit/rtems/src/intr.c @@ -0,0 +1,65 @@ +/* + * Interrupt 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/score/isr.h> +#include <rtems/rtems/intr.h> + +/* _Interrupt_Manager_initialization + * + * This routine initializes the interrupt manager. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _Interrupt_Manager_initialization( void ) +{ +} + +/* rtems_interrupt_catch + * + * This directive allows a thread to specify what action to take when + * catching signals. + * + * Input parameters: + * new_isr_handler - address of interrupt service routine (isr) + * vector - interrupt vector number + * old_isr_handler - address at which to store previous ISR address + * + * Output parameters: + * RTEMS_SUCCESSFUL - always succeeds + * *old_isr_handler - previous ISR address + */ + +rtems_status_code rtems_interrupt_catch( + rtems_isr_entry new_isr_handler, + rtems_vector_number vector, + rtems_isr_entry *old_isr_handler +) +{ + if ( !_ISR_Is_vector_number_valid( vector ) ) + return RTEMS_INVALID_NUMBER; + + if ( !_ISR_Is_valid_user_handler( new_isr_handler ) ) + return RTEMS_INVALID_ADDRESS; + + _ISR_Install_vector( + vector, (proc_ptr)new_isr_handler, (proc_ptr *)old_isr_handler ); + + return RTEMS_SUCCESSFUL; +} diff --git a/cpukit/rtems/src/mp.c b/cpukit/rtems/src/mp.c new file mode 100644 index 0000000000..7bc39074c6 --- /dev/null +++ b/cpukit/rtems/src/mp.c @@ -0,0 +1,42 @@ +/* + * Multiprocessing 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/mp.h> +#include <rtems/score/mpci.h> + +/*PAGE + * + * _Multiprocessing_Manager_initialization + * + */ + +void _Multiprocessing_Manager_initialization ( void ) +{ +} + +/*PAGE + * + * rtems_multiprocessing_announce + * + */ + +void rtems_multiprocessing_announce ( void ) +{ + _MPCI_Announce(); +} + +/* end of file */ diff --git a/cpukit/rtems/src/msg.c b/cpukit/rtems/src/msg.c new file mode 100644 index 0000000000..7d7c6e3025 --- /dev/null +++ b/cpukit/rtems/src/msg.c @@ -0,0 +1,714 @@ +/* + * Message Queue 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 <rtems/system.h> +#include <rtems/score/sysstate.h> +#include <rtems/score/chain.h> +#include <rtems/score/isr.h> +#include <rtems/score/coremsg.h> +#include <rtems/score/object.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/score/wkspace.h> +#include <rtems/score/mpci.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/attr.h> +#include <rtems/rtems/message.h> +#include <rtems/rtems/options.h> +#include <rtems/rtems/support.h> + +/*PAGE + * + * _Message_queue_Manager_initialization + * + * This routine initializes all message queue manager related + * data structures. + * + * Input parameters: + * maximum_message_queues - number of message queues to initialize + * + * Output parameters: NONE + */ + +void _Message_queue_Manager_initialization( + unsigned32 maximum_message_queues +) +{ + _Objects_Initialize_information( + &_Message_queue_Information, + OBJECTS_RTEMS_MESSAGE_QUEUES, + TRUE, + maximum_message_queues, + sizeof( Message_queue_Control ), + FALSE, + RTEMS_MAXIMUM_NAME_LENGTH, + FALSE + ); + + /* + * Register the MP Process Packet routine. + */ + + _MPCI_Register_packet_processor( + MP_PACKET_MESSAGE_QUEUE, + _Message_queue_MP_Process_packet + ); + +} + +/*PAGE + * + * _Message_queue_Allocate + * + * Allocate a message queue and the space for its messages + * + * Input parameters: + * the_message_queue - the message queue to allocate message buffers + * count - maximum message and reserved buffer count + * max_message_size - maximum size of each message + * + * Output parameters: + * the_message_queue - set if successful, NULL otherwise + */ + +Message_queue_Control *_Message_queue_Allocate ( + unsigned32 count, + unsigned32 max_message_size +) +{ + return + (Message_queue_Control *)_Objects_Allocate(&_Message_queue_Information); + +} + +/*PAGE + * + * rtems_message_queue_create + * + * This directive creates a message queue by allocating and initializing + * a message queue data structure. + * + * Input parameters: + * name - user defined queue name + * count - maximum message and reserved buffer count + * max_message_size - maximum size of each message + * attribute_set - process method + * id - pointer to queue + * + * Output parameters: + * id - queue id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_message_queue_create( + rtems_name name, + unsigned32 count, + unsigned32 max_message_size, + rtems_attribute attribute_set, + Objects_Id *id +) +{ + register Message_queue_Control *the_message_queue; + CORE_message_queue_Attributes the_message_queue_attributes; + boolean is_global; + + if ( !rtems_is_name_valid( name ) ) + return RTEMS_INVALID_NAME; + + if ( (is_global = _Attributes_Is_global( attribute_set ) ) && + !_System_state_Is_multiprocessing ) + return RTEMS_MP_NOT_CONFIGURED; + + if (count == 0) + return RTEMS_INVALID_NUMBER; + + if (max_message_size == 0) + return RTEMS_INVALID_SIZE; + +#if 1 + /* + * I am not 100% sure this should be an error. + * It seems reasonable to create a que with a large max size, + * and then just send smaller msgs from remote (or all) nodes. + */ + + if ( is_global && (_MPCI_table->maximum_packet_size < max_message_size) ) + return RTEMS_INVALID_SIZE; + +#endif + + _Thread_Disable_dispatch(); /* protects object pointer */ + + the_message_queue = _Message_queue_Allocate( count, max_message_size ); + + if ( !the_message_queue ) { + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + if ( is_global && + !( _Objects_MP_Allocate_and_open( &_Message_queue_Information, + name, the_message_queue->Object.id, FALSE ) ) ) { + _Message_queue_Free( the_message_queue ); + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + the_message_queue->attribute_set = attribute_set; + + if (_Attributes_Is_priority( attribute_set ) ) + the_message_queue_attributes.discipline = + CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY; + else + the_message_queue_attributes.discipline = + CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; + + if ( ! _CORE_message_queue_Initialize( + &the_message_queue->message_queue, + OBJECTS_RTEMS_MESSAGE_QUEUES, + &the_message_queue_attributes, + count, + max_message_size, + _Message_queue_MP_Send_extract_proxy ) ) { + if ( is_global ) + _Objects_MP_Close( + &_Message_queue_Information, the_message_queue->Object.id); + + _Message_queue_Free( the_message_queue ); + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + _Objects_Open( + &_Message_queue_Information, + &the_message_queue->Object, + &name + ); + + *id = the_message_queue->Object.id; + + if ( is_global ) + _Message_queue_MP_Send_process_packet( + MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, + the_message_queue->Object.id, + name, + 0 + ); + + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_message_queue_ident + * + * This directive returns the system ID associated with + * the message queue name. + * + * Input parameters: + * name - user defined message queue name + * node - node(s) to be searched + * id - pointer to message queue id + * + * Output parameters: + * *id - message queue id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_message_queue_ident( + rtems_name name, + unsigned32 node, + Objects_Id *id +) +{ + Objects_Name_to_id_errors status; + + status = _Objects_Name_to_id( + &_Message_queue_Information, + &name, + node, + id + ); + + return _Status_Object_name_errors_to_status[ status ]; +} + +/*PAGE + * + * rtems_message_queue_delete + * + * This directive allows a thread to delete the message queue specified + * by the given queue identifier. + * + * Input parameters: + * id - queue id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_message_queue_delete( + Objects_Id id +) +{ + register Message_queue_Control *the_message_queue; + Objects_Locations location; + + the_message_queue = _Message_queue_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; + case OBJECTS_LOCAL: + _Objects_Close( &_Message_queue_Information, + &the_message_queue->Object ); + + _CORE_message_queue_Close( + &the_message_queue->message_queue, + _Message_queue_MP_Send_object_was_deleted, + CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED + ); + + _Message_queue_Free( the_message_queue ); + + if ( _Attributes_Is_global( the_message_queue->attribute_set ) ) { + _Objects_MP_Close( + &_Message_queue_Information, + the_message_queue->Object.id + ); + + _Message_queue_MP_Send_process_packet( + MESSAGE_QUEUE_MP_ANNOUNCE_DELETE, + the_message_queue->Object.id, + 0, /* Not used */ + 0 + ); + } + + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_message_queue_send + * + * This routine implements the directives q_send. It sends a + * message to the specified message queue. + * + * Input parameters: + * id - pointer to message queue + * buffer - pointer to message buffer + * size - size of message to sent urgently + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_message_queue_send( + Objects_Id id, + void *buffer, + unsigned32 size +) +{ + return( _Message_queue_Submit(id, buffer, size, MESSAGE_QUEUE_SEND_REQUEST) ); +} + +/*PAGE + * + * rtems_message_queue_urgent + * + * This routine implements the directives q_urgent. It urgents a + * message to the specified message queue. + * + * Input parameters: + * id - pointer to message queue + * buffer - pointer to message buffer + * size - size of message to sent urgently + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_message_queue_urgent( + Objects_Id id, + void *buffer, + unsigned32 size +) +{ + return(_Message_queue_Submit(id, buffer, size, MESSAGE_QUEUE_URGENT_REQUEST)); +} + +/*PAGE + * + * rtems_message_queue_broadcast + * + * This directive sends a message for every thread waiting on the queue + * designated by id. + * + * Input parameters: + * id - pointer to message queue + * buffer - pointer to message buffer + * size - size of message to broadcast + * count - pointer to area to store number of threads made ready + * + * Output parameters: + * count - number of threads made ready + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_message_queue_broadcast( + Objects_Id id, + void *buffer, + unsigned32 size, + unsigned32 *count +) +{ + register Message_queue_Control *the_message_queue; + Objects_Locations location; + CORE_message_queue_Status core_status; + + the_message_queue = _Message_queue_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Executing->Wait.return_argument = count; + + return + _Message_queue_MP_Send_request_packet( + MESSAGE_QUEUE_MP_BROADCAST_REQUEST, + id, + buffer, + &size, + 0, /* option_set not used */ + MPCI_DEFAULT_TIMEOUT + ); + + case OBJECTS_LOCAL: + core_status = _CORE_message_queue_Broadcast( + &the_message_queue->message_queue, + buffer, + size, + id, + _Message_queue_Core_message_queue_mp_support, + count + ); + + _Thread_Enable_dispatch(); + return + _Message_queue_Translate_core_message_queue_return_code( core_status ); + + } + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_message_queue_receive + * + * This directive dequeues a message from the designated message queue + * and copies it into the requesting thread's buffer. + * + * Input parameters: + * id - queue id + * buffer - pointer to message buffer + * size - size of message receive + * option_set - options on receive + * timeout - number of ticks to wait + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_message_queue_receive( + Objects_Id id, + void *buffer, + unsigned32 *size, + unsigned32 option_set, + rtems_interval timeout +) +{ + register Message_queue_Control *the_message_queue; + Objects_Locations location; + boolean wait; + + the_message_queue = _Message_queue_Get( id, &location ); + switch ( location ) { + + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + + case OBJECTS_REMOTE: + return _Message_queue_MP_Send_request_packet( + MESSAGE_QUEUE_MP_RECEIVE_REQUEST, + id, + buffer, + size, + option_set, + timeout + ); + + case OBJECTS_LOCAL: + if ( _Options_Is_no_wait( option_set ) ) + wait = FALSE; + else + wait = TRUE; + + _CORE_message_queue_Seize( + &the_message_queue->message_queue, + the_message_queue->Object.id, + buffer, + size, + wait, + timeout + ); + _Thread_Enable_dispatch(); + return( _Message_queue_Translate_core_message_queue_return_code( + _Thread_Executing->Wait.return_code ) ); + + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_message_queue_flush + * + * This directive removes all pending messages from a queue and returns + * the number of messages removed. If no messages were present then + * a count of zero is returned. + * + * Input parameters: + * id - queue id + * count - return area for count + * + * Output parameters: + * count - number of messages removed ( 0 = empty queue ) + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_message_queue_flush( + Objects_Id id, + unsigned32 *count +) +{ + register Message_queue_Control *the_message_queue; + Objects_Locations location; + + the_message_queue = _Message_queue_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Executing->Wait.return_argument = count; + + return + _Message_queue_MP_Send_request_packet( + MESSAGE_QUEUE_MP_FLUSH_REQUEST, + id, + 0, /* buffer not used */ + 0, /* size */ + 0, /* option_set not used */ + MPCI_DEFAULT_TIMEOUT + ); + + case OBJECTS_LOCAL: + *count = _CORE_message_queue_Flush( &the_message_queue->message_queue ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * _Message_queue_Submit + * + * This routine implements the directives rtems_message_queue_send + * and rtems_message_queue_urgent. It processes a message that is + * to be submitted to the designated message queue. The message will + * either be processed as a send send message which it will be inserted + * at the rear of the queue or it will be processed as an urgent message + * which will be inserted at the front of the queue. + * + * Input parameters: + * id - pointer to message queue + * buffer - pointer to message buffer + * size - size in bytes of message to send + * submit_type - send or urgent message + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code _Message_queue_Submit( + Objects_Id id, + void *buffer, + unsigned32 size, + Message_queue_Submit_types submit_type +) +{ + register Message_queue_Control *the_message_queue; + Objects_Locations location; + CORE_message_queue_Status core_status; + + the_message_queue = _Message_queue_Get( id, &location ); + switch ( location ) + { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + + case OBJECTS_REMOTE: + switch ( submit_type ) { + case MESSAGE_QUEUE_SEND_REQUEST: + return + _Message_queue_MP_Send_request_packet( + MESSAGE_QUEUE_MP_SEND_REQUEST, + id, + buffer, + &size, + 0, /* option_set */ + MPCI_DEFAULT_TIMEOUT + ); + + case MESSAGE_QUEUE_URGENT_REQUEST: + return + _Message_queue_MP_Send_request_packet( + MESSAGE_QUEUE_MP_URGENT_REQUEST, + id, + buffer, + &size, + 0, /* option_set */ + MPCI_DEFAULT_TIMEOUT + ); + } + + case OBJECTS_LOCAL: + switch ( submit_type ) { + case MESSAGE_QUEUE_SEND_REQUEST: + core_status = _CORE_message_queue_Send( + &the_message_queue->message_queue, + buffer, + size, + id, + _Message_queue_Core_message_queue_mp_support + ); + break; + case MESSAGE_QUEUE_URGENT_REQUEST: + core_status = _CORE_message_queue_Urgent( + &the_message_queue->message_queue, + buffer, + size, + id, + _Message_queue_Core_message_queue_mp_support + ); + break; + default: + core_status = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; + return RTEMS_INTERNAL_ERROR; /* should never get here */ + } + + _Thread_Enable_dispatch(); + return _Message_queue_Translate_core_message_queue_return_code( + core_status ); + + } + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * _Message_queue_Translate_core_message_queue_return_code + * + * Input parameters: + * the_message_queue_status - message_queue status code to translate + * + * Output parameters: + * rtems status code - translated RTEMS status code + * + */ + +rtems_status_code _Message_queue_Translate_core_message_queue_return_code ( + unsigned32 the_message_queue_status +) +{ + switch ( the_message_queue_status ) { + case CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL: + return RTEMS_SUCCESSFUL; + case CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE: + return RTEMS_INVALID_SIZE; + case CORE_MESSAGE_QUEUE_STATUS_TOO_MANY: + return RTEMS_TOO_MANY; + case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED: + return RTEMS_UNSATISFIED; + case CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT: + return RTEMS_UNSATISFIED; + case CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED: + return RTEMS_OBJECT_WAS_DELETED; + case CORE_MESSAGE_QUEUE_STATUS_TIMEOUT: + return RTEMS_TIMEOUT; + case THREAD_STATUS_PROXY_BLOCKING: + return THREAD_STATUS_PROXY_BLOCKING; + } + _Internal_error_Occurred( /* XXX */ + INTERNAL_ERROR_RTEMS_API, + TRUE, + the_message_queue_status + ); + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * _Message_queue_Core_message_queue_mp_support + * + * Input parameters: + * the_thread - the remote thread the message was submitted to + * id - id of the message queue + * + * Output parameters: NONE + */ + +void _Message_queue_Core_message_queue_mp_support ( + Thread_Control *the_thread, + Objects_Id id +) +{ + the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; + + _Message_queue_MP_Send_response_packet( + MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, + id, + the_thread + ); +} diff --git a/cpukit/rtems/src/msgmp.c b/cpukit/rtems/src/msgmp.c new file mode 100644 index 0000000000..e43fc28aef --- /dev/null +++ b/cpukit/rtems/src/msgmp.c @@ -0,0 +1,454 @@ +/* + * Multiprocessing Support for the Message Queue 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/message.h> +#include <rtems/score/mpci.h> +#include <rtems/rtems/msgmp.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> +#include <rtems/rtems/support.h> + +/*PAGE + * + * _Message_queue_MP_Send_process_packet + * + */ + +void _Message_queue_MP_Send_process_packet ( + Message_queue_MP_Remote_operations operation, + Objects_Id message_queue_id, + rtems_name name, + Objects_Id proxy_id +) +{ + Message_queue_MP_Packet *the_packet; + unsigned32 node; + + switch ( operation ) { + + case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE: + case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE: + case MESSAGE_QUEUE_MP_EXTRACT_PROXY: + + the_packet = _Message_queue_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE; + the_packet->Prefix.length = sizeof ( Message_queue_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( Message_queue_MP_Packet ); + the_packet->operation = operation; + the_packet->Prefix.id = message_queue_id; + the_packet->name = name; + the_packet->proxy_id = proxy_id; + + if ( operation == MESSAGE_QUEUE_MP_EXTRACT_PROXY ) + node = rtems_get_node( message_queue_id ); + else + node = MPCI_ALL_NODES; + + _MPCI_Send_process_packet( node, &the_packet->Prefix ); + break; + + case MESSAGE_QUEUE_MP_RECEIVE_REQUEST: + case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE: + case MESSAGE_QUEUE_MP_SEND_REQUEST: + case MESSAGE_QUEUE_MP_SEND_RESPONSE: + case MESSAGE_QUEUE_MP_URGENT_REQUEST: + case MESSAGE_QUEUE_MP_URGENT_RESPONSE: + case MESSAGE_QUEUE_MP_BROADCAST_REQUEST: + case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE: + case MESSAGE_QUEUE_MP_FLUSH_REQUEST: + case MESSAGE_QUEUE_MP_FLUSH_RESPONSE: + break; + + } +} + +/*PAGE + * + * _Message_queue_MP_Send_request_packet + * + */ + +rtems_status_code _Message_queue_MP_Send_request_packet ( + Message_queue_MP_Remote_operations operation, + Objects_Id message_queue_id, + void *buffer, + unsigned32 *size_p, + rtems_option option_set, + rtems_interval timeout +) +{ + Message_queue_MP_Packet *the_packet; + + switch ( operation ) { + + case MESSAGE_QUEUE_MP_SEND_REQUEST: + case MESSAGE_QUEUE_MP_URGENT_REQUEST: + case MESSAGE_QUEUE_MP_BROADCAST_REQUEST: + case MESSAGE_QUEUE_MP_FLUSH_REQUEST: + + the_packet = _Message_queue_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE; + the_packet->Prefix.length = sizeof(Message_queue_MP_Packet); + if ( size_p ) + the_packet->Prefix.length += *size_p; + the_packet->Prefix.to_convert = sizeof(Message_queue_MP_Packet); + + /* + * make sure message is not too big for our MPCI driver + * We have to check it here instead of waiting for MPCI because + * we are about to slam in the payload + */ + + if (the_packet->Prefix.length > _MPCI_table->maximum_packet_size) { + _Thread_Enable_dispatch(); + return RTEMS_INVALID_SIZE; + } + + if ( ! _Options_Is_no_wait(option_set)) + the_packet->Prefix.timeout = timeout; + + the_packet->operation = operation; + the_packet->Prefix.id = message_queue_id; + the_packet->option_set = option_set; + + /* + * Copy the data into place if needed + */ + + if (buffer) { + the_packet->Buffer.size = *size_p; + _CORE_message_queue_Copy_buffer( + buffer, + the_packet->Buffer.buffer, + *size_p + ); + } + + return _MPCI_Send_request_packet(rtems_get_node(message_queue_id), + &the_packet->Prefix, + STATES_WAITING_FOR_MESSAGE); + break; + + case MESSAGE_QUEUE_MP_RECEIVE_REQUEST: + + the_packet = _Message_queue_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE; + the_packet->Prefix.length = sizeof(Message_queue_MP_Packet); + the_packet->Prefix.to_convert = sizeof(Message_queue_MP_Packet); + + if ( ! _Options_Is_no_wait(option_set)) + the_packet->Prefix.timeout = timeout; + + the_packet->operation = MESSAGE_QUEUE_MP_RECEIVE_REQUEST; + the_packet->Prefix.id = message_queue_id; + the_packet->option_set = option_set; + the_packet->size = 0; /* just in case of an error */ + + _Thread_Executing->Wait.return_argument = (unsigned32 *)buffer; + _Thread_Executing->Wait.return_argument_1 = size_p; + + return _MPCI_Send_request_packet(rtems_get_node(message_queue_id), + &the_packet->Prefix, + STATES_WAITING_FOR_MESSAGE); + break; + + case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE: + case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE: + case MESSAGE_QUEUE_MP_EXTRACT_PROXY: + case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE: + case MESSAGE_QUEUE_MP_SEND_RESPONSE: + case MESSAGE_QUEUE_MP_URGENT_RESPONSE: + case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE: + case MESSAGE_QUEUE_MP_FLUSH_RESPONSE: + break; + } + + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * _Message_queue_MP_Send_response_packet + * + */ + +void _Message_queue_MP_Send_response_packet ( + Message_queue_MP_Remote_operations operation, + Objects_Id message_queue_id, + Thread_Control *the_thread +) +{ + Message_queue_MP_Packet *the_packet; + + switch ( operation ) { + + case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE: + case MESSAGE_QUEUE_MP_SEND_RESPONSE: + case MESSAGE_QUEUE_MP_URGENT_RESPONSE: + case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE: + case MESSAGE_QUEUE_MP_FLUSH_RESPONSE: + + the_packet = ( Message_queue_MP_Packet *) the_thread->receive_packet; + +/* + * The packet being returned already contains the class, length, and + * to_convert fields, therefore they are not set in this routine. + * + * Exception: MESSAGE_QUEUE_MP_RECEIVE_RESPONSE needs payload length + * added to 'length' + */ + the_packet->operation = operation; + the_packet->Prefix.id = the_packet->Prefix.source_tid; + + if (operation == MESSAGE_QUEUE_MP_RECEIVE_RESPONSE) + the_packet->Prefix.length += the_packet->size; + + _MPCI_Send_response_packet( + rtems_get_node( the_packet->Prefix.source_tid ), + &the_packet->Prefix + ); + break; + + case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE: + case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE: + case MESSAGE_QUEUE_MP_EXTRACT_PROXY: + case MESSAGE_QUEUE_MP_RECEIVE_REQUEST: + case MESSAGE_QUEUE_MP_SEND_REQUEST: + case MESSAGE_QUEUE_MP_URGENT_REQUEST: + case MESSAGE_QUEUE_MP_BROADCAST_REQUEST: + case MESSAGE_QUEUE_MP_FLUSH_REQUEST: + break; + + } +} + +/*PAGE + * + * + * _Message_queue_MP_Process_packet + * + */ + +void _Message_queue_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +) +{ + Message_queue_MP_Packet *the_packet; + Thread_Control *the_thread; + boolean ignored; + + the_packet = (Message_queue_MP_Packet *) the_packet_prefix; + + switch ( the_packet->operation ) { + + case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE: + + ignored = _Objects_MP_Allocate_and_open( + &_Message_queue_Information, + the_packet->name, + the_packet->Prefix.id, + TRUE + ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE: + + _Objects_MP_Close( &_Message_queue_Information, the_packet->Prefix.id ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case MESSAGE_QUEUE_MP_EXTRACT_PROXY: + + the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id ); + + if ( ! _Thread_Is_null( the_thread ) ) + _Thread_queue_Extract( the_thread->Wait.queue, the_thread ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case MESSAGE_QUEUE_MP_RECEIVE_REQUEST: + + the_packet->Prefix.return_code = rtems_message_queue_receive( + the_packet->Prefix.id, + the_packet->Buffer.buffer, + &the_packet->size, + the_packet->option_set, + the_packet->Prefix.timeout + ); + + if ( ! _Thread_Is_proxy_blocking( the_packet->Prefix.return_code ) ) + _Message_queue_MP_Send_response_packet( + MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + + case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + if (the_packet->Prefix.return_code == RTEMS_SUCCESSFUL) { + *(rtems_unsigned32 *)the_thread->Wait.return_argument_1 = + the_packet->size; + + _CORE_message_queue_Copy_buffer( + the_packet->Buffer.buffer, + the_thread->Wait.return_argument, + the_packet->size + ); + } + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case MESSAGE_QUEUE_MP_SEND_REQUEST: + + the_packet->Prefix.return_code = rtems_message_queue_send( + the_packet->Prefix.id, + the_packet->Buffer.buffer, + the_packet->Buffer.size + ); + + _Message_queue_MP_Send_response_packet( + MESSAGE_QUEUE_MP_SEND_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + + case MESSAGE_QUEUE_MP_SEND_RESPONSE: + case MESSAGE_QUEUE_MP_URGENT_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case MESSAGE_QUEUE_MP_URGENT_REQUEST: + + the_packet->Prefix.return_code = rtems_message_queue_urgent( + the_packet->Prefix.id, + the_packet->Buffer.buffer, + the_packet->Buffer.size + ); + + _Message_queue_MP_Send_response_packet( + MESSAGE_QUEUE_MP_URGENT_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + + case MESSAGE_QUEUE_MP_BROADCAST_REQUEST: + + the_packet->Prefix.return_code = rtems_message_queue_broadcast( + the_packet->Prefix.id, + the_packet->Buffer.buffer, + the_packet->Buffer.size, + &the_packet->count + ); + + _Message_queue_MP_Send_response_packet( + MESSAGE_QUEUE_MP_BROADCAST_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + + case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE: + case MESSAGE_QUEUE_MP_FLUSH_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + *(unsigned32 *)the_thread->Wait.return_argument = the_packet->count; + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case MESSAGE_QUEUE_MP_FLUSH_REQUEST: + + the_packet->Prefix.return_code = rtems_message_queue_flush( + the_packet->Prefix.id, + &the_packet->count + ); + + _Message_queue_MP_Send_response_packet( + MESSAGE_QUEUE_MP_FLUSH_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + + } +} + +/*PAGE + * + * _Message_queue_MP_Send_object_was_deleted + * + */ + +void _Message_queue_MP_Send_object_was_deleted ( + Thread_Control *the_proxy +) +{ + the_proxy->receive_packet->return_code = RTEMS_OBJECT_WAS_DELETED; + + _Message_queue_MP_Send_response_packet( + MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, + the_proxy->Wait.id, + the_proxy + ); +} + +/*PAGE + * + * _Message_queue_MP_Send_extract_proxy + * + */ + +void _Message_queue_MP_Send_extract_proxy ( + Thread_Control *the_thread +) +{ + _Message_queue_MP_Send_process_packet( + MESSAGE_QUEUE_MP_EXTRACT_PROXY, + the_thread->Wait.id, + (rtems_name) 0, + the_thread->Object.id + ); +} + +/*PAGE + * + * _Message_queue_MP_Get_packet + * + */ + +Message_queue_MP_Packet *_Message_queue_MP_Get_packet ( void ) +{ + return ( (Message_queue_MP_Packet *) _MPCI_Get_packet() ); +} + +/* end of file */ diff --git a/cpukit/rtems/src/part.c b/cpukit/rtems/src/part.c new file mode 100644 index 0000000000..f63ab693f1 --- /dev/null +++ b/cpukit/rtems/src/part.c @@ -0,0 +1,341 @@ +/* + * Partition 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/support.h> +#include <rtems/score/address.h> +#include <rtems/score/object.h> +#include <rtems/rtems/part.h> +#include <rtems/score/thread.h> +#include <rtems/score/sysstate.h> + +/*PAGE + * + * _Partition_Manager_initialization + * + * This routine initializes all partition manager related + * data structures. + * + * Input parameters: + * maximum_partitions - number of partitions to initialize + * + * Output parameters: NONE + */ + +void _Partition_Manager_initialization( + unsigned32 maximum_partitions +) +{ + _Objects_Initialize_information( + &_Partition_Information, + OBJECTS_RTEMS_PARTITIONS, + TRUE, + maximum_partitions, + sizeof( Partition_Control ), + FALSE, + RTEMS_MAXIMUM_NAME_LENGTH, + FALSE + ); + + /* + * Register the MP Process Packet routine. + */ + + _MPCI_Register_packet_processor( + MP_PACKET_PARTITION, + _Partition_MP_Process_packet + ); + +} + +/*PAGE + * + * rtems_partition_create + * + * This directive creates a partiton of fixed sized buffers from the + * given contiguous memory area. + * + * Input parameters: + * name - user defined partition name + * starting_address - physical start address of partition + * length - physical length in bytes + * buffer_size - size of buffers in bytes + * attribute_set - partition attributes + * id - pointer to partition id + * + * Output parameters: + * id - partition id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_partition_create( + rtems_name name, + void *starting_address, + unsigned32 length, + unsigned32 buffer_size, + rtems_attribute attribute_set, + Objects_Id *id +) +{ + register Partition_Control *the_partition; + + if ( !rtems_is_name_valid( name ) ) + return RTEMS_INVALID_NAME; + + if ( length == 0 || buffer_size == 0 || length < buffer_size || + !_Partition_Is_buffer_size_aligned( buffer_size ) ) + return RTEMS_INVALID_SIZE; + + if ( !_Addresses_Is_aligned( starting_address ) ) + return RTEMS_INVALID_ADDRESS; + + if ( _Attributes_Is_global( attribute_set ) && + !_System_state_Is_multiprocessing ) + return RTEMS_MP_NOT_CONFIGURED; + + _Thread_Disable_dispatch(); /* prevents deletion */ + + the_partition = _Partition_Allocate(); + + if ( !the_partition ) { + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + if ( _Attributes_Is_global( attribute_set ) && + !( _Objects_MP_Allocate_and_open( &_Partition_Information, name, + the_partition->Object.id, FALSE ) ) ) { + _Partition_Free( the_partition ); + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + the_partition->starting_address = starting_address; + the_partition->length = length; + the_partition->buffer_size = buffer_size; + the_partition->attribute_set = attribute_set; + the_partition->number_of_used_blocks = 0; + + _Chain_Initialize( &the_partition->Memory, starting_address, + length / buffer_size, buffer_size ); + + _Objects_Open( &_Partition_Information, &the_partition->Object, &name ); + + *id = the_partition->Object.id; + if ( _Attributes_Is_global( attribute_set ) ) + _Partition_MP_Send_process_packet( + PARTITION_MP_ANNOUNCE_CREATE, + the_partition->Object.id, + name, + 0 /* Not used */ + ); + + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_partition_ident + * + * This directive returns the system ID associated with + * the partition name. + * + * Input parameters: + * name - user defined partition name + * node - node(s) to be searched + * id - pointer to partition id + * + * Output parameters: + * *id - partition id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_partition_ident( + rtems_name name, + unsigned32 node, + Objects_Id *id +) +{ + Objects_Name_to_id_errors status; + + status = _Objects_Name_to_id( &_Partition_Information, &name, node, id ); + + return _Status_Object_name_errors_to_status[ status ]; +} + +/*PAGE + * + * rtems_partition_delete + * + * This directive allows a thread to delete a partition specified by + * the partition identifier, provided that none of its buffers are + * still allocated. + * + * Input parameters: + * id - partition id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_partition_delete( + Objects_Id id +) +{ + register Partition_Control *the_partition; + Objects_Locations location; + + the_partition = _Partition_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; + case OBJECTS_LOCAL: + if ( the_partition->number_of_used_blocks == 0 ) { + _Objects_Close( &_Partition_Information, &the_partition->Object ); + _Partition_Free( the_partition ); + if ( _Attributes_Is_global( the_partition->attribute_set ) ) { + + _Objects_MP_Close( + &_Partition_Information, + the_partition->Object.id + ); + + _Partition_MP_Send_process_packet( + PARTITION_MP_ANNOUNCE_DELETE, + the_partition->Object.id, + 0, /* Not used */ + 0 /* Not used */ + ); + } + + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_RESOURCE_IN_USE; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_partition_get_buffer + * + * This directive will obtain a buffer from a buffer partition. + * + * Input parameters: + * id - partition id + * buffer - pointer to buffer address + * + * Output parameters: + * buffer - pointer to buffer address filled in + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_partition_get_buffer( + Objects_Id id, + void **buffer +) +{ + register Partition_Control *the_partition; + Objects_Locations location; + void *the_buffer; + + the_partition = _Partition_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Executing->Wait.return_argument = buffer; + return( + _Partition_MP_Send_request_packet( + PARTITION_MP_GET_BUFFER_REQUEST, + id, + 0 /* Not used */ + ) + ); + case OBJECTS_LOCAL: + the_buffer = _Partition_Allocate_buffer( the_partition ); + if ( the_buffer ) { + the_partition->number_of_used_blocks += 1; + _Thread_Enable_dispatch(); + *buffer = the_buffer; + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_UNSATISFIED; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_partition_return_buffer + * + * This directive will return the given buffer to the specified + * buffer partition. + * + * Input parameters: + * id - partition id + * buffer - pointer to buffer address + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_partition_return_buffer( + Objects_Id id, + void *buffer +) +{ + register Partition_Control *the_partition; + Objects_Locations location; + + the_partition = _Partition_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + return( + _Partition_MP_Send_request_packet( + PARTITION_MP_RETURN_BUFFER_REQUEST, + id, + buffer + ) + ); + case OBJECTS_LOCAL: + if ( _Partition_Is_buffer_valid( buffer, the_partition ) ) { + _Partition_Free_buffer( the_partition, buffer ); + the_partition->number_of_used_blocks -= 1; + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_INVALID_ADDRESS; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} diff --git a/cpukit/rtems/src/partmp.c b/cpukit/rtems/src/partmp.c new file mode 100644 index 0000000000..969bf314b5 --- /dev/null +++ b/cpukit/rtems/src/partmp.c @@ -0,0 +1,302 @@ +/* + * Multiprocessing Support for the Partition 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/score/mpci.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/rtems/part.h> +#include <rtems/score/thread.h> +#include <rtems/rtems/support.h> + +/*PAGE + * + * _Partition_MP_Send_process_packet + * + */ + +void _Partition_MP_Send_process_packet ( + Partition_MP_Remote_operations operation, + Objects_Id partition_id, + rtems_name name, + Objects_Id proxy_id +) +{ + Partition_MP_Packet *the_packet; + unsigned32 node; + + switch ( operation ) { + + case PARTITION_MP_ANNOUNCE_CREATE: + case PARTITION_MP_ANNOUNCE_DELETE: + case PARTITION_MP_EXTRACT_PROXY: + + the_packet = _Partition_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_PARTITION; + the_packet->Prefix.length = sizeof ( Partition_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( Partition_MP_Packet ); + the_packet->operation = operation; + the_packet->Prefix.id = partition_id; + the_packet->name = name; + the_packet->proxy_id = proxy_id; + + if ( operation == PARTITION_MP_EXTRACT_PROXY ) + node = rtems_get_node( partition_id ); + else + node = MPCI_ALL_NODES; + + _MPCI_Send_process_packet( node, &the_packet->Prefix ); + break; + + case PARTITION_MP_GET_BUFFER_REQUEST: + case PARTITION_MP_GET_BUFFER_RESPONSE: + case PARTITION_MP_RETURN_BUFFER_REQUEST: + case PARTITION_MP_RETURN_BUFFER_RESPONSE: + break; + } +} + +/*PAGE + * + * _Partition_MP_Send_request_packet + * + */ + +rtems_status_code _Partition_MP_Send_request_packet ( + Partition_MP_Remote_operations operation, + Objects_Id partition_id, + void *buffer +) +{ + Partition_MP_Packet *the_packet; + + switch ( operation ) { + + case PARTITION_MP_GET_BUFFER_REQUEST: + case PARTITION_MP_RETURN_BUFFER_REQUEST: + + the_packet = _Partition_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_PARTITION; + the_packet->Prefix.length = sizeof ( Partition_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( Partition_MP_Packet ); + the_packet->operation = operation; + the_packet->Prefix.id = partition_id; + the_packet->buffer = buffer; + + return + _MPCI_Send_request_packet( + rtems_get_node( partition_id ), + &the_packet->Prefix, + STATES_READY /* Not used */ + ); + + break; + + case PARTITION_MP_ANNOUNCE_CREATE: + case PARTITION_MP_ANNOUNCE_DELETE: + case PARTITION_MP_EXTRACT_PROXY: + case PARTITION_MP_GET_BUFFER_RESPONSE: + case PARTITION_MP_RETURN_BUFFER_RESPONSE: + break; + + } + /* + * The following line is included to satisfy compilers which + * produce warnings when a function does not end with a return. + */ + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * _Partition_MP_Send_response_packet + * + */ + +void _Partition_MP_Send_response_packet ( + Partition_MP_Remote_operations operation, + Objects_Id partition_id, + Thread_Control *the_thread +) +{ + Partition_MP_Packet *the_packet; + + switch ( operation ) { + + case PARTITION_MP_GET_BUFFER_RESPONSE: + case PARTITION_MP_RETURN_BUFFER_RESPONSE: + + the_packet = ( Partition_MP_Packet *) the_thread->receive_packet; + +/* + * The packet being returned already contains the class, length, and + * to_convert fields, therefore they are not set in this routine. + */ + the_packet->operation = operation; + the_packet->Prefix.id = the_packet->Prefix.source_tid; + + _MPCI_Send_response_packet( + rtems_get_node( the_packet->Prefix.source_tid ), + &the_packet->Prefix + ); + break; + + case PARTITION_MP_ANNOUNCE_CREATE: + case PARTITION_MP_ANNOUNCE_DELETE: + case PARTITION_MP_EXTRACT_PROXY: + case PARTITION_MP_GET_BUFFER_REQUEST: + case PARTITION_MP_RETURN_BUFFER_REQUEST: + break; + + } +} + +/*PAGE + * + * + * _Partition_MP_Process_packet + * + */ + +void _Partition_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +) +{ + Partition_MP_Packet *the_packet; + Thread_Control *the_thread; + boolean ignored; + + the_packet = (Partition_MP_Packet *) the_packet_prefix; + + switch ( the_packet->operation ) { + + case PARTITION_MP_ANNOUNCE_CREATE: + + ignored = _Objects_MP_Allocate_and_open( + &_Partition_Information, + the_packet->name, + the_packet->Prefix.id, + TRUE + ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case PARTITION_MP_ANNOUNCE_DELETE: + + _Objects_MP_Close( &_Partition_Information, the_packet->Prefix.id ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case PARTITION_MP_EXTRACT_PROXY: + + the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id ); + + if ( ! _Thread_Is_null( the_thread ) ) + _Thread_queue_Extract( the_thread->Wait.queue, the_thread ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case PARTITION_MP_GET_BUFFER_REQUEST: + + the_packet->Prefix.return_code = rtems_partition_get_buffer( + the_packet->Prefix.id, + &the_packet->buffer + ); + + _Partition_MP_Send_response_packet( + PARTITION_MP_GET_BUFFER_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + + case PARTITION_MP_GET_BUFFER_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + *(void **)the_thread->Wait.return_argument = the_packet->buffer; + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case PARTITION_MP_RETURN_BUFFER_REQUEST: + + the_packet->Prefix.return_code = rtems_partition_return_buffer( + the_packet->Prefix.id, + the_packet->buffer + ); + + _Partition_MP_Send_response_packet( + PARTITION_MP_RETURN_BUFFER_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + + case PARTITION_MP_RETURN_BUFFER_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + } +} + +/*PAGE + * + * _Partition_MP_Send_object_was_deleted + * + * This routine is not needed by the Partition since a partition + * cannot be deleted when buffers are in use. + * + */ + +/*PAGE + * + * _Partition_MP_Send_extract_proxy + * + */ + +void _Partition_MP_Send_extract_proxy ( + Thread_Control *the_thread +) +{ + _Partition_MP_Send_process_packet( + PARTITION_MP_EXTRACT_PROXY, + the_thread->Wait.id, + (rtems_name) 0, + the_thread->Object.id + ); + +} + +/*PAGE + * + * _Partition_MP_Get_packet + * + */ + +Partition_MP_Packet *_Partition_MP_Get_packet ( void ) +{ + return ( (Partition_MP_Packet *) _MPCI_Get_packet() ); +} + +/* end of file */ diff --git a/cpukit/rtems/src/ratemon.c b/cpukit/rtems/src/ratemon.c new file mode 100644 index 0000000000..d3524b02d6 --- /dev/null +++ b/cpukit/rtems/src/ratemon.c @@ -0,0 +1,385 @@ +/* + * Rate Monotonic 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/support.h> +#include <rtems/score/isr.h> +#include <rtems/score/object.h> +#include <rtems/rtems/ratemon.h> +#include <rtems/score/thread.h> + +/*PAGE + * + * _Rate_monotonic_Manager_initialization + * + * This routine initializes all Rate Monotonic Manager related + * data structures. + * + * Input parameters: + * maximum_periods - number of periods timers to initialize + * + * Output parameters: NONE + * + * NOTE: The Rate Monotonic Manager is built on top of the Watchdog + * Handler. + */ + +void _Rate_monotonic_Manager_initialization( + unsigned32 maximum_periods +) +{ + _Objects_Initialize_information( + &_Rate_monotonic_Information, + OBJECTS_RTEMS_PERIODS, + FALSE, + maximum_periods, + sizeof( Rate_monotonic_Control ), + FALSE, + RTEMS_MAXIMUM_NAME_LENGTH, + FALSE + ); +} + +/*PAGE + * + * rtems_rate_monotonic_create + * + * This directive creates a rate monotonic timer and performs + * some initialization. + * + * Input parameters: + * name - name of period + * id - pointer to rate monotonic id + * + * Output parameters: + * id - rate monotonic id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_rate_monotonic_create( + rtems_name name, + Objects_Id *id +) +{ + Rate_monotonic_Control *the_period; + + if ( !rtems_is_name_valid( name ) ) + return RTEMS_INVALID_NAME; + + _Thread_Disable_dispatch(); /* to prevent deletion */ + + the_period = _Rate_monotonic_Allocate(); + + if ( !the_period ) { + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + the_period->owner = _Thread_Executing; + the_period->state = RATE_MONOTONIC_INACTIVE; + + _Objects_Open( &_Rate_monotonic_Information, &the_period->Object, &name ); + + *id = the_period->Object.id; + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_rate_monotonic_ident + * + * This directive returns the system ID associated with + * the rate monotonic period name. + * + * Input parameters: + * name - user defined period name + * id - pointer to period id + * + * Output parameters: + * *id - region id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_rate_monotonic_ident( + rtems_name name, + Objects_Id *id +) +{ + Objects_Name_to_id_errors status; + + status = _Objects_Name_to_id( + &_Rate_monotonic_Information, + &name, + OBJECTS_SEARCH_LOCAL_NODE, + id + ); + + return _Status_Object_name_errors_to_status[ status ]; +} + +/*PAGE + * + * rtems_rate_monotonic_cancel + * + * This directive allows a thread to cancel a rate monotonic timer. + * + * Input parameters: + * id - rate monotonic id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful and caller is not the owning thread + * error code - if unsuccessful + */ + +rtems_status_code rtems_rate_monotonic_cancel( + Objects_Id id +) +{ + Rate_monotonic_Control *the_period; + Objects_Locations location; + + the_period = _Rate_monotonic_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + return RTEMS_INTERNAL_ERROR; /* should never return this */ + case OBJECTS_LOCAL: + if ( !_Thread_Is_executing( the_period->owner ) ) { + _Thread_Enable_dispatch(); + return RTEMS_NOT_OWNER_OF_RESOURCE; + } + (void) _Watchdog_Remove( &the_period->Timer ); + the_period->state = RATE_MONOTONIC_INACTIVE; + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_rate_monotonic_delete + * + * This directive allows a thread to delete a rate monotonic timer. + * + * Input parameters: + * id - rate monotonic id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_rate_monotonic_delete( + Objects_Id id +) +{ + Rate_monotonic_Control *the_period; + Objects_Locations location; + + the_period = _Rate_monotonic_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + _Objects_Close( &_Rate_monotonic_Information, &the_period->Object ); + (void) _Watchdog_Remove( &the_period->Timer ); + the_period->state = RATE_MONOTONIC_INACTIVE; + _Rate_monotonic_Free( the_period ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_rate_monotonic_period + * + * This directive allows a thread to manipulate a rate monotonic timer. + * + * Input parameters: + * id - rate monotonic id + * length - length of period (in ticks) + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_rate_monotonic_period( + Objects_Id id, + rtems_interval length +) +{ + Rate_monotonic_Control *the_period; + Objects_Locations location; + rtems_status_code return_value; + Rate_Monotonic_Period_states local_state; + ISR_Level level; + + the_period = _Rate_monotonic_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + if ( !_Thread_Is_executing( the_period->owner ) ) { + _Thread_Enable_dispatch(); + return RTEMS_NOT_OWNER_OF_RESOURCE; + } + + if ( length == RTEMS_PERIOD_STATUS ) { + switch ( the_period->state ) { + case RATE_MONOTONIC_INACTIVE: + return_value = RTEMS_NOT_DEFINED; + break; + case RATE_MONOTONIC_ACTIVE: + return_value = RTEMS_SUCCESSFUL; + break; + case RATE_MONOTONIC_EXPIRED: + return_value = RTEMS_TIMEOUT; + break; + default: /* unreached -- only to remove warnings */ + return_value = RTEMS_INTERNAL_ERROR; + break; + } + _Thread_Enable_dispatch(); + return( return_value ); + } + + _ISR_Disable( level ); + switch ( the_period->state ) { + case RATE_MONOTONIC_INACTIVE: + _ISR_Enable( level ); + the_period->state = RATE_MONOTONIC_ACTIVE; + _Watchdog_Initialize( + &the_period->Timer, + _Rate_monotonic_Timeout, + id, + NULL + ); + _Watchdog_Insert_ticks( &the_period->Timer, length ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + + case RATE_MONOTONIC_ACTIVE: + /* + * This tells the _Rate_monotonic_Timeout that this task is + * in the process of blocking on the period. + */ + + the_period->state = RATE_MONOTONIC_OWNER_IS_BLOCKING; + _ISR_Enable( level ); + + _Thread_Executing->Wait.id = the_period->Object.id; + _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD ); + + /* + * Did the watchdog timer expire while we were actually blocking + * on it? + */ + + _ISR_Disable( level ); + local_state = the_period->state; + the_period->state = RATE_MONOTONIC_ACTIVE; + _ISR_Enable( level ); + + /* + * If it did, then we want to unblock ourself and continue as + * if nothing happen. The period was reset in the timeout routine. + */ + + if ( local_state == RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING ) + _Thread_Clear_state( _Thread_Executing, STATES_WAITING_FOR_PERIOD ); + + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + break; + + case RATE_MONOTONIC_EXPIRED: + _ISR_Enable( level ); + the_period->state = RATE_MONOTONIC_ACTIVE; + _Watchdog_Insert_ticks( &the_period->Timer, length ); + _Thread_Enable_dispatch(); + return RTEMS_TIMEOUT; + + case RATE_MONOTONIC_OWNER_IS_BLOCKING: + case RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING: + /* + * These should never happen. + */ + break; + } + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * _Rate_monotonic_Timeout + * + * This routine processes a period ending. If the owning thread + * is waiting for the period, that thread is unblocked and the + * period reinitiated. Otherwise, the period is expired. + * This routine is called by the watchdog handler. + * + * Input parameters: + * id - period id + * + * Output parameters: NONE + */ + +void _Rate_monotonic_Timeout( + Objects_Id id, + void *ignored +) +{ + Rate_monotonic_Control *the_period; + Objects_Locations location; + Thread_Control *the_thread; + + the_period = _Rate_monotonic_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + case OBJECTS_REMOTE: /* impossible */ + break; + case OBJECTS_LOCAL: + the_thread = the_period->owner; + if ( _States_Is_waiting_for_period( the_thread->current_state ) && + the_thread->Wait.id == the_period->Object.id ) { + _Thread_Unblock( the_thread ); + _Watchdog_Reset( &the_period->Timer ); + } else if ( the_period->state == RATE_MONOTONIC_OWNER_IS_BLOCKING ) { + the_period->state = RATE_MONOTONIC_EXPIRED_WHILE_BLOCKING; + _Watchdog_Reset( &the_period->Timer ); + } else + the_period->state = RATE_MONOTONIC_EXPIRED; + _Thread_Unnest_dispatch(); + break; + } +} + diff --git a/cpukit/rtems/src/region.c b/cpukit/rtems/src/region.c new file mode 100644 index 0000000000..5a8ad26797 --- /dev/null +++ b/cpukit/rtems/src/region.c @@ -0,0 +1,486 @@ +/* + * Region 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/support.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/rtems/region.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> + +/*PAGE + * + * _Region_Manager_initialization + * + * This routine initializes all region manager related data structures. + * + * Input parameters: + * maximum_regions - number of regions to initialize + * + * Output parameters: NONE + */ + +void _Region_Manager_initialization( + unsigned32 maximum_regions +) +{ + _Objects_Initialize_information( + &_Region_Information, + OBJECTS_RTEMS_REGIONS, + FALSE, + maximum_regions, + sizeof( Region_Control ), + FALSE, + RTEMS_MAXIMUM_NAME_LENGTH, + FALSE + ); + + /* + * Register the MP Process Packet routine. + */ + + _MPCI_Register_packet_processor( + MP_PACKET_REGION, + 0 /* XXX _Region_MP_Process_packet */ + ); + +} + +/*PAGE + * + * rtems_region_create + * + * This directive creates a region of physical contiguous memory area + * from which variable sized segments can be allocated. + * + * Input parameters: + * name - user defined region name + * starting_address - physical start address of region + * length - physical length in bytes + * page_size - page size in bytes + * attribute_set - region attributes + * id - address of region id to set + * + * Output parameters: + * id - region id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_region_create( + rtems_name name, + void *starting_address, + unsigned32 length, + unsigned32 page_size, + rtems_attribute attribute_set, + Objects_Id *id +) +{ + Region_Control *the_region; + + if ( !rtems_is_name_valid( name ) ) + return RTEMS_INVALID_NAME; + + if ( !_Addresses_Is_aligned( starting_address ) ) + return RTEMS_INVALID_ADDRESS; + + _Thread_Disable_dispatch(); /* to prevent deletion */ + + the_region = _Region_Allocate(); + + if ( !the_region ) { + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + the_region->maximum_segment_size = + _Heap_Initialize(&the_region->Memory, starting_address, length, page_size); + + if ( !the_region->maximum_segment_size ) { + _Region_Free( the_region ); + _Thread_Enable_dispatch(); + return RTEMS_INVALID_SIZE; + } + + the_region->starting_address = starting_address; + the_region->length = length; + the_region->page_size = page_size; + the_region->attribute_set = attribute_set; + the_region->number_of_used_blocks = 0; + + _Thread_queue_Initialize( + &the_region->Wait_queue, + OBJECTS_RTEMS_REGIONS, + _Attributes_Is_priority( attribute_set ) ? + THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, + STATES_WAITING_FOR_SEGMENT, + _Region_MP_Send_extract_proxy, + RTEMS_TIMEOUT + ); + + _Objects_Open( &_Region_Information, &the_region->Object, &name ); + + *id = the_region->Object.id; + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_region_ident + * + * This directive returns the system ID associated with + * the region name. + * + * Input parameters: + * name - user defined region name + * id - pointer to region id + * + * Output parameters: + * *id - region id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_region_ident( + rtems_name name, + Objects_Id *id +) +{ + Objects_Name_to_id_errors status; + + status = _Objects_Name_to_id( + &_Region_Information, + &name, + OBJECTS_SEARCH_LOCAL_NODE, + id + ); + + return _Status_Object_name_errors_to_status[ status ]; +} + +/*PAGE + * + * rtems_region_delete + * + * This directive allows a thread to delete a region specified by + * the region identifier, provided that none of its segments are + * still allocated. + * + * Input parameters: + * id - region id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_region_delete( + Objects_Id id +) +{ + register Region_Control *the_region; + Objects_Locations location; + + the_region = _Region_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* this error cannot be returned */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + _Region_Debug_Walk( the_region, 5 ); + if ( the_region->number_of_used_blocks == 0 ) { + _Objects_Close( &_Region_Information, &the_region->Object ); + _Region_Free( the_region ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_RESOURCE_IN_USE; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_region_extend + * + * This directive attempts to grow a region of physical contiguous memory area + * from which variable sized segments can be allocated. + * + * Input parameters: + * id - id of region to grow + * start - starting address of memory area for extension + * length - physical length in bytes to grow the region + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_region_extend( + Objects_Id id, + void *starting_address, + unsigned32 length +) +{ + Region_Control *the_region; + Objects_Locations location; + unsigned32 amount_extended; + Heap_Extend_status heap_status; + rtems_status_code status; + + status = RTEMS_SUCCESSFUL; + + the_region = _Region_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* this error cannot be returned */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + + heap_status = _Heap_Extend( + &the_region->Memory, + starting_address, + length, + &amount_extended + ); + + switch ( heap_status ) { + case HEAP_EXTEND_SUCCESSFUL: + the_region->length += amount_extended; + the_region->maximum_segment_size += amount_extended; + break; + case HEAP_EXTEND_ERROR: + status = RTEMS_INVALID_ADDRESS; + break; + case HEAP_EXTEND_NOT_IMPLEMENTED: + status = RTEMS_NOT_IMPLEMENTED; + break; + } + _Thread_Enable_dispatch(); + return( status ); + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_region_get_segment + * + * This directive will obtain a segment from the given region. + * + * Input parameters: + * id - region id + * size - segment size in bytes + * option_set - wait option + * timeout - number of ticks to wait (0 means wait forever) + * segment - pointer to segment address + * + * Output parameters: + * segment - pointer to segment address filled in + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_region_get_segment( + Objects_Id id, + unsigned32 size, + rtems_option option_set, + rtems_interval timeout, + void **segment +) +{ + register Region_Control *the_region; + Objects_Locations location; + Thread_Control *executing; + void *the_segment; + + *segment = NULL; + + if ( size == 0 ) + return RTEMS_INVALID_SIZE; + + executing = _Thread_Executing; + the_region = _Region_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* this error cannot be returned */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + if ( size > the_region->maximum_segment_size ) { + _Thread_Enable_dispatch(); + return RTEMS_INVALID_SIZE; + } + + _Region_Debug_Walk( the_region, 1 ); + + the_segment = _Region_Allocate_segment( the_region, size ); + + _Region_Debug_Walk( the_region, 2 ); + + if ( the_segment ) { + the_region->number_of_used_blocks += 1; + _Thread_Enable_dispatch(); + *segment = the_segment; + return RTEMS_SUCCESSFUL; + } + + if ( _Options_Is_no_wait( option_set ) ) { + _Thread_Enable_dispatch(); + return RTEMS_UNSATISFIED; + } + + executing->Wait.queue = &the_region->Wait_queue; + executing->Wait.id = id; + executing->Wait.count = size; + executing->Wait.return_argument = (unsigned32 *) segment; + + _Thread_queue_Enter_critical_section( &the_region->Wait_queue ); + + _Thread_queue_Enqueue( &the_region->Wait_queue, timeout ); + + _Thread_Enable_dispatch(); + return( executing->Wait.return_code ); + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} +/*PAGE + * + * rtems_region_get_segment_size + * + * This directive will return the size of the segment indicated + * + * Input parameters: + * id - region id + * segment - segment address + * size - pointer to segment size in bytes + * + * Output parameters: + * size - segment size in bytes filled in + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_region_get_segment_size( + Objects_Id id, + void *segment, + unsigned32 *size +) +{ + register Region_Control *the_region; + Objects_Locations location; + Thread_Control *executing; + + executing = _Thread_Executing; + the_region = _Region_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* this error cannot be returned */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + + if ( _Heap_Size_of_user_area( &the_region->Memory, segment, size ) ) { + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_INVALID_ADDRESS; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_region_return_segment + * + * This directive will return a segment to its region. + * + * Input parameters: + * id - region id + * segment - pointer to segment address + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_region_return_segment( + Objects_Id id, + void *segment +) +{ + register Region_Control *the_region; + Thread_Control *the_thread; + Objects_Locations location; + void **the_segment; + int status; + + the_region = _Region_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* this error cannot be returned */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + + _Region_Debug_Walk( the_region, 3 ); + + status = _Region_Free_segment( the_region, segment ); + + _Region_Debug_Walk( the_region, 4 ); + + if ( !status ) { + _Thread_Enable_dispatch(); + return RTEMS_INVALID_ADDRESS; + } + + the_region->number_of_used_blocks -= 1; + for ( ; ; ) { + the_thread = _Thread_queue_First( &the_region->Wait_queue ); + + if ( the_thread == NULL ) + break; + + the_segment = _Region_Allocate_segment( + the_region, + the_thread->Wait.count + ); + + if ( the_segment == NULL ) + break; + + *(void **)the_thread->Wait.return_argument = the_segment; + the_region->number_of_used_blocks += 1; + _Thread_queue_Extract( &the_region->Wait_queue, the_thread ); + the_thread->Wait.return_code = RTEMS_SUCCESSFUL; + } + + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} diff --git a/cpukit/rtems/src/regionmp.c b/cpukit/rtems/src/regionmp.c new file mode 100644 index 0000000000..57f307f826 --- /dev/null +++ b/cpukit/rtems/src/regionmp.c @@ -0,0 +1,310 @@ +/* + * Multiprocessing Support for the Region 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/score/mpci.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/rtems/region.h> +#include <rtems/score/thread.h> +#include <rtems/rtems/support.h> + +/*PAGE + * + * _Region_MP_Send_process_packet + * + */ + +void _Region_MP_Send_process_packet ( + Region_MP_Remote_operations operation, + Objects_Id region_id, + rtems_name name, + Objects_Id proxy_id +) +{ + Region_MP_Packet *the_packet; + unsigned32 node; + + switch ( operation ) { + + case REGION_MP_ANNOUNCE_CREATE: + case REGION_MP_ANNOUNCE_DELETE: + case REGION_MP_EXTRACT_PROXY: + + the_packet = _Region_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_REGION; + the_packet->Prefix.length = sizeof ( Region_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( Region_MP_Packet ); + the_packet->operation = operation; + the_packet->Prefix.id = region_id; + the_packet->name = name; + the_packet->proxy_id = proxy_id; + + if ( operation == REGION_MP_EXTRACT_PROXY ) + node = rtems_get_node( region_id ); + else + node = MPCI_ALL_NODES; + + _MPCI_Send_process_packet( node, &the_packet->Prefix ); + break; + + case REGION_MP_GET_SEGMENT_REQUEST: + case REGION_MP_GET_SEGMENT_RESPONSE: + case REGION_MP_RETURN_SEGMENT_REQUEST: + case REGION_MP_RETURN_SEGMENT_RESPONSE: + break; + } +} + +/*PAGE + * + * _Region_MP_Send_request_packet + * + */ + +rtems_status_code _Region_MP_Send_request_packet ( + Region_MP_Remote_operations operation, + Objects_Id region_id, + void *segment, + unsigned32 size, + rtems_option option_set, + rtems_interval timeout +) +{ + Region_MP_Packet *the_packet; + + switch ( operation ) { + + case REGION_MP_GET_SEGMENT_REQUEST: + case REGION_MP_RETURN_SEGMENT_REQUEST: + + the_packet = _Region_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_REGION; + the_packet->Prefix.length = sizeof ( Region_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( Region_MP_Packet ); + if ( ! _Options_Is_no_wait(option_set)) + the_packet->Prefix.timeout = timeout; + + the_packet->operation = operation; + the_packet->Prefix.id = region_id; + the_packet->segment = segment; + the_packet->size = size; + the_packet->option_set = option_set; + + return _MPCI_Send_request_packet( + rtems_get_node( region_id ), + &the_packet->Prefix, + STATES_READY /* Not used */ + ); + break; + + case REGION_MP_ANNOUNCE_CREATE: + case REGION_MP_ANNOUNCE_DELETE: + case REGION_MP_EXTRACT_PROXY: + case REGION_MP_GET_SEGMENT_RESPONSE: + case REGION_MP_RETURN_SEGMENT_RESPONSE: + break; + + } + /* + * The following line is included to satisfy compilers which + * produce warnings when a function does not end with a return. + */ + return RTEMS_INTERNAL_ERROR; +} + +/*PAGE + * + * _Region_MP_Send_response_packet + * + */ + +void _Region_MP_Send_response_packet ( + Region_MP_Remote_operations operation, + Objects_Id region_id, + Thread_Control *the_thread +) +{ + Region_MP_Packet *the_packet; + + switch ( operation ) { + + case REGION_MP_GET_SEGMENT_RESPONSE: + case REGION_MP_RETURN_SEGMENT_RESPONSE: + + the_packet = ( Region_MP_Packet *) the_thread->receive_packet; + +/* + * The packet being returned already contains the class, length, and + * to_convert fields, therefore they are not set in this routine. + */ + the_packet->operation = operation; + the_packet->Prefix.id = the_packet->Prefix.source_tid; + + _MPCI_Send_response_packet( + rtems_get_node( the_packet->Prefix.source_tid ), + &the_packet->Prefix + ); + break; + + case REGION_MP_ANNOUNCE_CREATE: + case REGION_MP_ANNOUNCE_DELETE: + case REGION_MP_EXTRACT_PROXY: + case REGION_MP_GET_SEGMENT_REQUEST: + case REGION_MP_RETURN_SEGMENT_REQUEST: + break; + + } +} + +/*PAGE + * + * + * _Region_MP_Process_packet + * + */ + +void _Region_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +) +{ + Region_MP_Packet *the_packet; + Thread_Control *the_thread; + boolean ignored; + + the_packet = (Region_MP_Packet *) the_packet_prefix; + + switch ( the_packet->operation ) { + + case REGION_MP_ANNOUNCE_CREATE: + + ignored = _Objects_MP_Allocate_and_open( + &_Region_Information, + the_packet->name, + the_packet->Prefix.id, + TRUE + ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case REGION_MP_ANNOUNCE_DELETE: + + _Objects_MP_Close( &_Region_Information, the_packet->Prefix.id ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case REGION_MP_EXTRACT_PROXY: + + the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id ); + + if ( ! _Thread_Is_null( the_thread ) ) + _Thread_queue_Extract( the_thread->Wait.queue, the_thread ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case REGION_MP_GET_SEGMENT_REQUEST: + + the_packet->Prefix.return_code = rtems_region_get_segment( + the_packet->Prefix.id, + the_packet->size, + the_packet->option_set, + the_packet->Prefix.timeout, + &the_packet->segment + ); + + _Region_MP_Send_response_packet( + REGION_MP_GET_SEGMENT_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + + case REGION_MP_GET_SEGMENT_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + *(void **)the_thread->Wait.return_argument = the_packet->segment; + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case REGION_MP_RETURN_SEGMENT_REQUEST: + + the_packet->Prefix.return_code = rtems_region_return_segment( + the_packet->Prefix.id, + the_packet->segment + ); + + _Region_MP_Send_response_packet( + REGION_MP_RETURN_SEGMENT_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + + case REGION_MP_RETURN_SEGMENT_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + } +} + +/*PAGE + * + * _Region_MP_Send_object_was_deleted + * + * This routine is not needed by the Region since a region + * cannot be deleted when segments are in use. + * + */ + +/*PAGE + * + * _Region_MP_Send_extract_proxy + * + */ + +void _Region_MP_Send_extract_proxy ( + Thread_Control *the_thread +) +{ + _Region_MP_Send_process_packet( + REGION_MP_EXTRACT_PROXY, + the_thread->Wait.id, + (rtems_name) 0, + the_thread->Object.id + ); +} + +/*PAGE + * + * _Region_MP_Get_packet + * + */ + +Region_MP_Packet *_Region_MP_Get_packet ( void ) +{ + return ( (Region_MP_Packet *) _MPCI_Get_packet() ); +} + +/* end of file */ diff --git a/cpukit/rtems/src/rtclock.c b/cpukit/rtems/src/rtclock.c new file mode 100644 index 0000000000..ea340ae5f4 --- /dev/null +++ b/cpukit/rtems/src/rtclock.c @@ -0,0 +1,151 @@ +/* + * Clock 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/clock.h> +#include <rtems/score/isr.h> +#include <rtems/score/thread.h> +#include <rtems/score/tod.h> +#include <rtems/score/watchdog.h> + +/*PAGE + * + * rtems_clock_get + * + * This directive returns the current date and time. If the time has + * not been set by a tm_set then an error is returned. + * + * Input parameters: + * option - which value to return + * time_buffer - pointer to output buffer (a time and date structure + * or an interval) + * + * Output parameters: + * time_buffer - output filled in + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_clock_get( + rtems_clock_get_options option, + void *time_buffer +) +{ + ISR_Level level; + rtems_interval tmp; + + switch ( option ) { + case RTEMS_CLOCK_GET_TOD: + if ( !_TOD_Is_set() ) + return RTEMS_NOT_DEFINED; + + *(rtems_time_of_day *)time_buffer = _TOD_Current; + return RTEMS_SUCCESSFUL; + + case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH: + if ( !_TOD_Is_set() ) + return RTEMS_NOT_DEFINED; + + *(rtems_interval *)time_buffer = _TOD_Seconds_since_epoch; + return RTEMS_SUCCESSFUL; + + case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT: + *(rtems_interval *)time_buffer = _TOD_Ticks_since_boot; + return RTEMS_SUCCESSFUL; + + case RTEMS_CLOCK_GET_TICKS_PER_SECOND: + *(rtems_interval *)time_buffer = _TOD_Ticks_per_second; + return RTEMS_SUCCESSFUL; + + case RTEMS_CLOCK_GET_TIME_VALUE: + if ( !_TOD_Is_set() ) + return RTEMS_NOT_DEFINED; + + _ISR_Disable( level ); + ((rtems_clock_time_value *)time_buffer)->seconds = + _TOD_Seconds_since_epoch; + tmp = _TOD_Current.ticks; + _ISR_Enable( level ); + + tmp *= _TOD_Microseconds_per_tick; + ((rtems_clock_time_value *)time_buffer)->microseconds = tmp; + + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* should never get here */ + +} + +/*PAGE + * + * rtems_clock_set + * + * This directive sets the date and time for this node. + * + * Input parameters: + * time_buffer - pointer to the time and date structure + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_clock_set( + rtems_time_of_day *time_buffer +) +{ + rtems_interval seconds; + + if ( _TOD_Validate( time_buffer ) ) { + seconds = _TOD_To_seconds( time_buffer ); + _Thread_Disable_dispatch(); + _TOD_Set( time_buffer, seconds ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + return RTEMS_INVALID_CLOCK; +} + +/*PAGE + * + * rtems_clock_tick + * + * This directive notifies the executve that a tick has occurred. + * When the tick occurs the time manager updates and maintains + * the calendar time, timeslicing, and any timeout delays. + * + * Input parameters: NONE + * + * Output parameters: + * RTEMS_SUCCESSFUL - always succeeds + * + * NOTE: This routine only works for leap-years through 2099. + */ + +rtems_status_code rtems_clock_tick( void ) +{ + _TOD_Tickle_ticks(); + + _Watchdog_Tickle_ticks(); + + _Thread_Tickle_timeslice(); + + if ( _Thread_Is_context_switch_necessary() && + _Thread_Is_dispatching_enabled() ) + _Thread_Dispatch(); + + return RTEMS_SUCCESSFUL; +} diff --git a/cpukit/rtems/src/rtemstimer.c b/cpukit/rtems/src/rtemstimer.c new file mode 100644 index 0000000000..6c3005ffbe --- /dev/null +++ b/cpukit/rtems/src/rtemstimer.c @@ -0,0 +1,349 @@ +/* + * Timer 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/support.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/rtems/timer.h> +#include <rtems/score/tod.h> +#include <rtems/score/watchdog.h> + +/*PAGE + * + * _Timer_Manager_initialization + * + * This routine initializes all timer manager related data structures. + * + * Input parameters: + * maximum_timers - number of timers to initialize + * + * Output parameters: NONE + */ + +void _Timer_Manager_initialization( + unsigned32 maximum_timers +) +{ + _Objects_Initialize_information( + &_Timer_Information, + OBJECTS_RTEMS_TIMERS, + FALSE, + maximum_timers, + sizeof( Timer_Control ), + FALSE, + RTEMS_MAXIMUM_NAME_LENGTH, + FALSE + ); +} + +/*PAGE + * + * rtems_timer_create + * + * This directive creates a timer and performs some initialization. + * + * Input parameters: + * name - timer name + * id - pointer to timer id + * + * Output parameters: + * id - timer id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_timer_create( + rtems_name name, + Objects_Id *id +) +{ + Timer_Control *the_timer; + + if ( !rtems_is_name_valid( name ) ) + return RTEMS_INVALID_NAME; + + _Thread_Disable_dispatch(); /* to prevent deletion */ + + the_timer = _Timer_Allocate(); + + if ( !the_timer ) { + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + the_timer->the_class = TIMER_DORMANT; + + _Objects_Open( &_Timer_Information, &the_timer->Object, &name ); + + *id = the_timer->Object.id; + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_timer_ident + * + * This directive returns the system ID associated with + * the timer name. + * + * Input parameters: + * name - user defined message queue name + * id - pointer to timer id + * + * Output parameters: + * *id - message queue id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_timer_ident( + rtems_name name, + Objects_Id *id +) +{ + Objects_Name_to_id_errors status; + + status = _Objects_Name_to_id( + &_Timer_Information, + &name, + OBJECTS_SEARCH_LOCAL_NODE, + id + ); + + return _Status_Object_name_errors_to_status[ status ]; +} + +/*PAGE + * + * rtems_timer_cancel + * + * This directive allows a thread to cancel a timer. + * + * Input parameters: + * id - timer id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_timer_cancel( + Objects_Id id +) +{ + Timer_Control *the_timer; + Objects_Locations location; + + the_timer = _Timer_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + if ( !_Timer_Is_dormant_class( the_timer->the_class ) ) + (void) _Watchdog_Remove( &the_timer->Ticker ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_timer_delete + * + * This directive allows a thread to delete a timer. + * + * Input parameters: + * id - timer id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_timer_delete( + Objects_Id id +) +{ + Timer_Control *the_timer; + Objects_Locations location; + + the_timer = _Timer_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + _Objects_Close( &_Timer_Information, &the_timer->Object ); + (void) _Watchdog_Remove( &the_timer->Ticker ); + _Timer_Free( the_timer ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_timer_fire_after + * + * This directive allows a thread to start a timer. + * + * Input parameters: + * id - timer id + * ticks - interval until routine is fired + * routine - routine to schedule + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_timer_fire_after( + Objects_Id id, + rtems_interval ticks, + rtems_timer_service_routine_entry routine, + void *user_data +) +{ + Timer_Control *the_timer; + Objects_Locations location; + + if ( ticks == 0 ) + return RTEMS_INVALID_NUMBER; + + the_timer = _Timer_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + (void) _Watchdog_Remove( &the_timer->Ticker ); + the_timer->the_class = TIMER_INTERVAL; + _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data ); + _Watchdog_Insert_ticks( &the_timer->Ticker, ticks ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_timer_fire_when + * + * This directive allows a thread to start a timer. + * + * Input parameters: + * id - timer id + * wall_time - time of day to fire timer + * routine - routine to schedule + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_timer_fire_when( + Objects_Id id, + rtems_time_of_day *wall_time, + rtems_timer_service_routine_entry routine, + void *user_data +) +{ + Timer_Control *the_timer; + Objects_Locations location; + rtems_interval seconds; + + if ( !_TOD_Is_set() ) + return RTEMS_NOT_DEFINED; + + if ( !_TOD_Validate( wall_time ) ) + return RTEMS_INVALID_CLOCK; + + seconds = _TOD_To_seconds( wall_time ); + if ( seconds <= _TOD_Seconds_since_epoch ) + return RTEMS_INVALID_CLOCK; + + the_timer = _Timer_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + (void) _Watchdog_Remove( &the_timer->Ticker ); + the_timer->the_class = TIMER_TIME_OF_DAY; + _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data ); + _Watchdog_Insert_seconds( + &the_timer->Ticker, + seconds - _TOD_Seconds_since_epoch + ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_timer_reset + * + * This directive allows a thread to reset a timer. + * + * Input parameters: + * id - timer id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_timer_reset( + Objects_Id id +) +{ + Timer_Control *the_timer; + Objects_Locations location; + + the_timer = _Timer_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + case OBJECTS_LOCAL: + if ( _Timer_Is_interval_class( the_timer->the_class ) ) { + _Watchdog_Reset( &the_timer->Ticker ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_NOT_DEFINED; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} diff --git a/cpukit/rtems/src/sem.c b/cpukit/rtems/src/sem.c new file mode 100644 index 0000000000..004176f4fb --- /dev/null +++ b/cpukit/rtems/src/sem.c @@ -0,0 +1,570 @@ +/* + * Semaphore Manager + * + * DESCRIPTION: + * + * This package is the implementation of the Semaphore Manager. + * This manager utilizes standard Dijkstra counting semaphores to provide + * synchronization and mutual exclusion capabilities. + * + * Directives provided are: + * + * + create a semaphore + * + get an ID of a semaphore + * + delete a semaphore + * + acquire a semaphore + * + release a semaphore + * + * 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/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/support.h> +#include <rtems/rtems/attr.h> +#include <rtems/score/isr.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/rtems/sem.h> +#include <rtems/score/coremutex.h> +#include <rtems/score/coresem.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> +#include <rtems/score/mpci.h> +#include <rtems/score/sysstate.h> + +#include <rtems/score/interr.h> + +/*PAGE + * + * _Semaphore_Manager_initialization + * + * This routine initializes all semaphore manager related data structures. + * + * Input parameters: + * maximum_semaphores - maximum configured semaphores + * + * Output parameters: NONE + */ + +void _Semaphore_Manager_initialization( + unsigned32 maximum_semaphores +) +{ + _Objects_Initialize_information( + &_Semaphore_Information, + OBJECTS_RTEMS_SEMAPHORES, + TRUE, + maximum_semaphores, + sizeof( Semaphore_Control ), + FALSE, + RTEMS_MAXIMUM_NAME_LENGTH, + FALSE + ); + + /* + * Register the MP Process Packet routine. + */ + + _MPCI_Register_packet_processor( + MP_PACKET_SEMAPHORE, + _Semaphore_MP_Process_packet + ); + +} + +/*PAGE + * + * rtems_semaphore_create + * + * This directive creates a semaphore and sets the initial value based + * on the given count. A semaphore id is returned. + * + * Input parameters: + * name - user defined semaphore name + * count - initial count of semaphore + * attribute_set - semaphore attributes + * priority_ceiling - semaphore's ceiling priority + * id - pointer to semaphore id + * + * Output parameters: + * id - semaphore id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_semaphore_create( + rtems_name name, + unsigned32 count, + rtems_attribute attribute_set, + rtems_task_priority priority_ceiling, + Objects_Id *id +) +{ + register Semaphore_Control *the_semaphore; + CORE_mutex_Attributes the_mutex_attributes; + CORE_semaphore_Attributes the_semaphore_attributes; + unsigned32 lock; + + if ( !rtems_is_name_valid( name ) ) + return RTEMS_INVALID_NAME; + + if ( _Attributes_Is_global( attribute_set ) ) { + + if ( !_System_state_Is_multiprocessing ) + return RTEMS_MP_NOT_CONFIGURED; + + if ( _Attributes_Is_inherit_priority( attribute_set ) ) + return RTEMS_NOT_DEFINED; + + } else if ( _Attributes_Is_inherit_priority( attribute_set ) ) { + + if ( ! ( _Attributes_Is_binary_semaphore( attribute_set ) && + _Attributes_Is_priority( attribute_set ) ) ) + return RTEMS_NOT_DEFINED; + + } + + if ( _Attributes_Is_binary_semaphore( attribute_set ) && ( count > 1 ) ) + return RTEMS_INVALID_NUMBER; + + _Thread_Disable_dispatch(); /* prevents deletion */ + + the_semaphore = _Semaphore_Allocate(); + + if ( !the_semaphore ) { + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + if ( _Attributes_Is_global( attribute_set ) && + ! ( _Objects_MP_Allocate_and_open( &_Semaphore_Information, name, + the_semaphore->Object.id, FALSE ) ) ) { + _Semaphore_Free( the_semaphore ); + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + the_semaphore->attribute_set = attribute_set; + + if ( _Attributes_Is_binary_semaphore( attribute_set ) ) { + if ( _Attributes_Is_inherit_priority( attribute_set ) ) + the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT; + else if (_Attributes_Is_priority_ceiling( attribute_set ) ) + the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING; + else if (_Attributes_Is_priority( attribute_set ) ) + the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY; + else + the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_FIFO; + + the_mutex_attributes.allow_nesting = TRUE; + + /* Add priority ceiling code here ????? */ + + the_mutex_attributes.priority_ceiling = priority_ceiling; + + if ( count == 1 ) + lock = CORE_MUTEX_UNLOCKED; + else + lock = CORE_MUTEX_LOCKED; + + _CORE_mutex_Initialize( + &the_semaphore->Core_control.mutex, + OBJECTS_RTEMS_SEMAPHORES, + &the_mutex_attributes, + lock, + _Semaphore_MP_Send_extract_proxy + ); + } + else { + if ( _Attributes_Is_priority( attribute_set ) ) + the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_PRIORITY; + else + the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO; + + /* + * The following are just to make Purify happy. + */ + + the_mutex_attributes.allow_nesting = TRUE; + the_mutex_attributes.priority_ceiling = PRIORITY_MINIMUM; + + _CORE_semaphore_Initialize( + &the_semaphore->Core_control.semaphore, + OBJECTS_RTEMS_SEMAPHORES, + &the_semaphore_attributes, + count, + _Semaphore_MP_Send_extract_proxy + ); + } + + _Objects_Open( &_Semaphore_Information, &the_semaphore->Object, &name ); + + *id = the_semaphore->Object.id; + + if ( _Attributes_Is_global( attribute_set ) ) + _Semaphore_MP_Send_process_packet( + SEMAPHORE_MP_ANNOUNCE_CREATE, + the_semaphore->Object.id, + name, + 0 /* Not used */ + ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_semaphore_ident + * + * This directive returns the system ID associated with + * the semaphore name. + * + * Input parameters: + * name - user defined semaphore name + * node - node(s) to be searched + * id - pointer to semaphore id + * + * Output parameters: + * *id - semaphore id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_semaphore_ident( + rtems_name name, + unsigned32 node, + Objects_Id *id +) +{ + Objects_Name_to_id_errors status; + + status = _Objects_Name_to_id( &_Semaphore_Information, &name, node, id ); + + return _Status_Object_name_errors_to_status[ status ]; +} + +/*PAGE + * + * rtems_semaphore_delete + * + * This directive allows a thread to delete a semaphore specified by + * the semaphore id. The semaphore is freed back to the inactive + * semaphore chain. + * + * Input parameters: + * id - semaphore id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_semaphore_delete( + Objects_Id id +) +{ + register Semaphore_Control *the_semaphore; + Objects_Locations location; + + the_semaphore = _Semaphore_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; + case OBJECTS_LOCAL: + if ( _Attributes_Is_binary_semaphore( the_semaphore->attribute_set) ) { + if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) ) { + _Thread_Enable_dispatch(); + return RTEMS_RESOURCE_IN_USE; + } + else + _CORE_mutex_Flush( + &the_semaphore->Core_control.mutex, + _Semaphore_MP_Send_object_was_deleted, + CORE_MUTEX_WAS_DELETED + ); + } + else + _CORE_semaphore_Flush( + &the_semaphore->Core_control.semaphore, + _Semaphore_MP_Send_object_was_deleted, + CORE_SEMAPHORE_WAS_DELETED + ); + + _Objects_Close( &_Semaphore_Information, &the_semaphore->Object ); + + _Semaphore_Free( the_semaphore ); + + if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) { + + _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id ); + + _Semaphore_MP_Send_process_packet( + SEMAPHORE_MP_ANNOUNCE_DELETE, + the_semaphore->Object.id, + 0, /* Not used */ + 0 /* Not used */ + ); + } + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_semaphore_obtain + * + * This directive allows a thread to acquire a semaphore. + * + * Input parameters: + * id - semaphore id + * option_set - wait option + * timeout - number of ticks to wait (0 means wait forever) + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_semaphore_obtain( + Objects_Id id, + unsigned32 option_set, + rtems_interval timeout +) +{ + register Semaphore_Control *the_semaphore; + Objects_Locations location; + boolean wait; + + the_semaphore = _Semaphore_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + return _Semaphore_MP_Send_request_packet( + SEMAPHORE_MP_OBTAIN_REQUEST, + id, + option_set, + timeout + ); + case OBJECTS_LOCAL: + if ( _Options_Is_no_wait( option_set ) ) + wait = FALSE; + else + wait = TRUE; + + if ( _Attributes_Is_binary_semaphore( the_semaphore->attribute_set ) ) { + _CORE_mutex_Seize( + &the_semaphore->Core_control.mutex, + id, + wait, + timeout + ); + _Thread_Enable_dispatch(); + return _Semaphore_Translate_core_mutex_return_code( + _Thread_Executing->Wait.return_code ); + } else { + _CORE_semaphore_Seize( + &the_semaphore->Core_control.semaphore, + id, + wait, + timeout + ); + _Thread_Enable_dispatch(); + return _Semaphore_Translate_core_semaphore_return_code( + _Thread_Executing->Wait.return_code ); + } + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_semaphore_release + * + * This directive allows a thread to release a semaphore. + * + * Input parameters: + * id - semaphore id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_semaphore_release( + Objects_Id id +) +{ + register Semaphore_Control *the_semaphore; + Objects_Locations location; + CORE_mutex_Status mutex_status; + CORE_semaphore_Status semaphore_status; + + the_semaphore = _Semaphore_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + return _Semaphore_MP_Send_request_packet( + SEMAPHORE_MP_RELEASE_REQUEST, + id, + 0, /* Not used */ + MPCI_DEFAULT_TIMEOUT + ); + case OBJECTS_LOCAL: + if ( _Attributes_Is_binary_semaphore( the_semaphore->attribute_set ) ) { + mutex_status = _CORE_mutex_Surrender( + &the_semaphore->Core_control.mutex, + id, + _Semaphore_Core_mutex_mp_support + ); + _Thread_Enable_dispatch(); + return _Semaphore_Translate_core_mutex_return_code( mutex_status ); + } + else + semaphore_status = _CORE_semaphore_Surrender( + &the_semaphore->Core_control.semaphore, + id, + _Semaphore_Core_semaphore_mp_support + ); + _Thread_Enable_dispatch(); + return + _Semaphore_Translate_core_semaphore_return_code( semaphore_status ); + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * _Semaphore_Translate_core_mutex_return_code + * + * Input parameters: + * the_mutex_status - mutex status code to translate + * + * Output parameters: + * rtems status code - translated RTEMS status code + * + */ + +rtems_status_code _Semaphore_Translate_core_mutex_return_code ( + unsigned32 the_mutex_status +) +{ + switch ( the_mutex_status ) { + case CORE_MUTEX_STATUS_SUCCESSFUL: + return RTEMS_SUCCESSFUL; + case CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT: + return RTEMS_UNSATISFIED; + case CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED: + return RTEMS_INTERNAL_ERROR; + case CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE: + return RTEMS_NOT_OWNER_OF_RESOURCE; + case CORE_MUTEX_WAS_DELETED: + return RTEMS_OBJECT_WAS_DELETED; + case CORE_MUTEX_TIMEOUT: + return RTEMS_TIMEOUT; + case THREAD_STATUS_PROXY_BLOCKING: + return THREAD_STATUS_PROXY_BLOCKING; + } + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * _Semaphore_Translate_core_semaphore_return_code + * + * Input parameters: + * the_semaphore_status - semaphore status code to translate + * + * Output parameters: + * rtems status code - translated RTEMS status code + * + */ + +rtems_status_code _Semaphore_Translate_core_semaphore_return_code ( + unsigned32 the_semaphore_status +) +{ + switch ( the_semaphore_status ) { + case CORE_SEMAPHORE_STATUS_SUCCESSFUL: + return RTEMS_SUCCESSFUL; + case CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT: + return RTEMS_UNSATISFIED; + case CORE_SEMAPHORE_WAS_DELETED: + return RTEMS_OBJECT_WAS_DELETED; + case CORE_SEMAPHORE_TIMEOUT: + return RTEMS_TIMEOUT; + case THREAD_STATUS_PROXY_BLOCKING: + return THREAD_STATUS_PROXY_BLOCKING; + } + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * _Semaphore_Core_mutex_mp_support + * + * Input parameters: + * the_thread - the remote thread the semaphore was surrendered to + * id - id of the surrendered semaphore + * + * Output parameters: NONE + */ + +void _Semaphore_Core_mutex_mp_support ( + Thread_Control *the_thread, + Objects_Id id +) +{ + the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; + + _Semaphore_MP_Send_response_packet( + SEMAPHORE_MP_OBTAIN_RESPONSE, + id, + the_thread + ); +} + + +/*PAGE + * + * _Semaphore_Core_semaphore_mp_support + * + * Input parameters: + * the_thread - the remote thread the semaphore was surrendered to + * id - id of the surrendered semaphore + * + * Output parameters: NONE + */ + +void _Semaphore_Core_semaphore_mp_support ( + Thread_Control *the_thread, + Objects_Id id +) +{ + the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; + + _Semaphore_MP_Send_response_packet( + SEMAPHORE_MP_OBTAIN_RESPONSE, + id, + the_thread + ); +} diff --git a/cpukit/rtems/src/semmp.c b/cpukit/rtems/src/semmp.c new file mode 100644 index 0000000000..7e7d59ba8e --- /dev/null +++ b/cpukit/rtems/src/semmp.c @@ -0,0 +1,308 @@ +/* + * Multiprocessing Support for the Semaphore 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/score/mpci.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/rtems/sem.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> +#include <rtems/rtems/support.h> + +/*PAGE + * + * _Semaphore_MP_Send_process_packet + * + */ + +void _Semaphore_MP_Send_process_packet ( + Semaphore_MP_Remote_operations operation, + Objects_Id semaphore_id, + rtems_name name, + Objects_Id proxy_id +) +{ + Semaphore_MP_Packet *the_packet; + unsigned32 node; + + switch ( operation ) { + + case SEMAPHORE_MP_ANNOUNCE_CREATE: + case SEMAPHORE_MP_ANNOUNCE_DELETE: + case SEMAPHORE_MP_EXTRACT_PROXY: + + the_packet = _Semaphore_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_SEMAPHORE; + the_packet->Prefix.length = sizeof ( Semaphore_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( Semaphore_MP_Packet ); + the_packet->operation = operation; + the_packet->Prefix.id = semaphore_id; + the_packet->name = name; + the_packet->proxy_id = proxy_id; + + if ( operation == SEMAPHORE_MP_EXTRACT_PROXY ) + node = rtems_get_node( semaphore_id ); + else + node = MPCI_ALL_NODES; + + _MPCI_Send_process_packet( node, &the_packet->Prefix ); + break; + + case SEMAPHORE_MP_OBTAIN_REQUEST: + case SEMAPHORE_MP_OBTAIN_RESPONSE: + case SEMAPHORE_MP_RELEASE_REQUEST: + case SEMAPHORE_MP_RELEASE_RESPONSE: + break; + } +} + +/*PAGE + * + * _Semaphore_MP_Send_request_packet + * + */ + +rtems_status_code _Semaphore_MP_Send_request_packet ( + Semaphore_MP_Remote_operations operation, + Objects_Id semaphore_id, + rtems_option option_set, + rtems_interval timeout +) +{ + Semaphore_MP_Packet *the_packet; + + switch ( operation ) { + + case SEMAPHORE_MP_OBTAIN_REQUEST: + case SEMAPHORE_MP_RELEASE_REQUEST: + + the_packet = _Semaphore_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_SEMAPHORE; + the_packet->Prefix.length = sizeof ( Semaphore_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( Semaphore_MP_Packet ); + if ( ! _Options_Is_no_wait(option_set)) + the_packet->Prefix.timeout = timeout; + + the_packet->operation = operation; + the_packet->Prefix.id = semaphore_id; + the_packet->option_set = option_set; + + return _MPCI_Send_request_packet( + rtems_get_node( semaphore_id ), + &the_packet->Prefix, + STATES_WAITING_FOR_SEMAPHORE + ); + break; + + case SEMAPHORE_MP_ANNOUNCE_CREATE: + case SEMAPHORE_MP_ANNOUNCE_DELETE: + case SEMAPHORE_MP_EXTRACT_PROXY: + case SEMAPHORE_MP_OBTAIN_RESPONSE: + case SEMAPHORE_MP_RELEASE_RESPONSE: + break; + + } + /* + * The following line is included to satisfy compilers which + * produce warnings when a function does not end with a return. + */ + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * _Semaphore_MP_Send_response_packet + * + */ + +void _Semaphore_MP_Send_response_packet ( + Semaphore_MP_Remote_operations operation, + Objects_Id semaphore_id, + Thread_Control *the_thread +) +{ + Semaphore_MP_Packet *the_packet; + + switch ( operation ) { + + case SEMAPHORE_MP_OBTAIN_RESPONSE: + case SEMAPHORE_MP_RELEASE_RESPONSE: + + the_packet = ( Semaphore_MP_Packet *) the_thread->receive_packet; + +/* + * The packet being returned already contains the class, length, and + * to_convert fields, therefore they are not set in this routine. + */ + the_packet->operation = operation; + the_packet->Prefix.id = the_packet->Prefix.source_tid; + + _MPCI_Send_response_packet( + rtems_get_node( the_packet->Prefix.source_tid ), + &the_packet->Prefix + ); + break; + + case SEMAPHORE_MP_ANNOUNCE_CREATE: + case SEMAPHORE_MP_ANNOUNCE_DELETE: + case SEMAPHORE_MP_EXTRACT_PROXY: + case SEMAPHORE_MP_OBTAIN_REQUEST: + case SEMAPHORE_MP_RELEASE_REQUEST: + break; + + } +} + +/*PAGE + * + * + * _Semaphore_MP_Process_packet + * + */ + +void _Semaphore_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +) +{ + Semaphore_MP_Packet *the_packet; + Thread_Control *the_thread; + boolean ignored; + + the_packet = (Semaphore_MP_Packet *) the_packet_prefix; + + switch ( the_packet->operation ) { + + case SEMAPHORE_MP_ANNOUNCE_CREATE: + + ignored = _Objects_MP_Allocate_and_open( + &_Semaphore_Information, + the_packet->name, + the_packet->Prefix.id, + TRUE + ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case SEMAPHORE_MP_ANNOUNCE_DELETE: + + _Objects_MP_Close( &_Semaphore_Information, the_packet->Prefix.id ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case SEMAPHORE_MP_EXTRACT_PROXY: + + the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id ); + + if ( ! _Thread_Is_null( the_thread ) ) + _Thread_queue_Extract( the_thread->Wait.queue, the_thread ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case SEMAPHORE_MP_OBTAIN_REQUEST: + + the_packet->Prefix.return_code = rtems_semaphore_obtain( + the_packet->Prefix.id, + the_packet->option_set, + the_packet->Prefix.timeout + ); + + if ( ! _Thread_Is_proxy_blocking( the_packet->Prefix.return_code ) ) + _Semaphore_MP_Send_response_packet( + SEMAPHORE_MP_OBTAIN_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + + case SEMAPHORE_MP_OBTAIN_RESPONSE: + case SEMAPHORE_MP_RELEASE_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case SEMAPHORE_MP_RELEASE_REQUEST: + + the_packet->Prefix.return_code = rtems_semaphore_release( + the_packet->Prefix.id + ); + + _Semaphore_MP_Send_response_packet( + SEMAPHORE_MP_RELEASE_RESPONSE, + the_packet->Prefix.id, + _Thread_Executing + ); + break; + } +} + +/*PAGE + * + * _Semaphore_MP_Send_object_was_deleted + * + */ + +void _Semaphore_MP_Send_object_was_deleted ( + Thread_Control *the_proxy +) +{ + the_proxy->receive_packet->return_code = RTEMS_OBJECT_WAS_DELETED; + + _Semaphore_MP_Send_response_packet( + SEMAPHORE_MP_OBTAIN_RESPONSE, + the_proxy->Wait.id, + the_proxy + ); + +} + +/*PAGE + * + * _Semaphore_MP_Send_extract_proxy + * + */ + +void _Semaphore_MP_Send_extract_proxy ( + Thread_Control *the_thread +) +{ + _Semaphore_MP_Send_process_packet( + SEMAPHORE_MP_EXTRACT_PROXY, + the_thread->Wait.id, + (rtems_name) 0, + the_thread->Object.id + ); + +} + +/*PAGE + * + * _Semaphore_MP_Get_packet + * + */ + +Semaphore_MP_Packet *_Semaphore_MP_Get_packet ( void ) +{ + return ( (Semaphore_MP_Packet *) _MPCI_Get_packet() ); +} + +/* end of file */ diff --git a/cpukit/rtems/src/signal.c b/cpukit/rtems/src/signal.c new file mode 100644 index 0000000000..10aefa391c --- /dev/null +++ b/cpukit/rtems/src/signal.c @@ -0,0 +1,149 @@ +/* + * Signal 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/asr.h> +#include <rtems/score/isr.h> +#include <rtems/rtems/modes.h> +#include <rtems/rtems/signal.h> +#include <rtems/score/thread.h> +#include <rtems/rtems/tasks.h> + +/*PAGE + * + * _Signal_Manager_initialization + * + * This routine initializes all signal manager related data structures. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _Signal_Manager_initialization( void ) +{ + /* + * Register the MP Process Packet routine. + */ + + _MPCI_Register_packet_processor( + MP_PACKET_SIGNAL, + _Signal_MP_Process_packet + ); +} + +/*PAGE + * + * rtems_signal_catch + * + * This directive allows a thread to specify what action to take when + * catching signals. + * + * Input parameters: + * handler - address of asynchronous signal routine (asr) + * ( NULL indicates asr is invalid ) + * mode_set - mode value for asr + * + * Output parameters: + * RTEMS_SUCCESSFUL - always succeeds + */ + +rtems_status_code rtems_signal_catch( + rtems_asr_entry asr_handler, + rtems_mode mode_set +) +{ + Thread_Control *executing; + RTEMS_API_Control *api; + ASR_Information *asr; + +/* XXX normalize mode */ + executing = _Thread_Executing; + api = executing->API_Extensions[ THREAD_API_RTEMS ]; + asr = &api->Signal; + + _Thread_Disable_dispatch(); /* cannot reschedule while */ + /* the thread is inconsistent */ + + if ( !_ASR_Is_null_handler( asr_handler ) ) { + asr->mode_set = mode_set; + asr->handler = asr_handler; + } + else + _ASR_Initialize( asr ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_signal_send + * + * This directive allows a thread to send signals to a thread. + * + * Input parameters: + * id - thread id + * signal_set - signal set + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_signal_send( + Objects_Id id, + rtems_signal_set signal_set +) +{ + register Thread_Control *the_thread; + Objects_Locations location; + RTEMS_API_Control *api; + ASR_Information *asr; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + return _Signal_MP_Send_request_packet( + SIGNAL_MP_SEND_REQUEST, + id, + signal_set + ); + case OBJECTS_LOCAL: + api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; + asr = &api->Signal; + + if ( ! _ASR_Is_null_handler( asr->handler ) ) { + if ( asr->is_enabled ) { + _ASR_Post_signals( signal_set, &asr->signals_posted ); + + the_thread->do_post_task_switch_extension = TRUE; + + if ( _ISR_Is_in_progress() && _Thread_Is_executing( the_thread ) ) + _ISR_Signals_to_thread_executing = TRUE; + } else { + _ASR_Post_signals( signal_set, &asr->signals_pending ); + } + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_NOT_DEFINED; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} diff --git a/cpukit/rtems/src/signalmp.c b/cpukit/rtems/src/signalmp.c new file mode 100644 index 0000000000..b3a6ecf18c --- /dev/null +++ b/cpukit/rtems/src/signalmp.c @@ -0,0 +1,189 @@ +/* + * Multiprocessing Support for the Signal 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/score/mpci.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/rtems/signal.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> +#include <rtems/rtems/support.h> + +/*PAGE + * + * _Signal_MP_Send_process_packet + * + * This subprogram is not needed since there are no process + * packets to be sent by this manager. + * + */ + +/*PAGE + * + * _Signal_MP_Send_request_packet + * + */ + +rtems_status_code _Signal_MP_Send_request_packet ( + Signal_MP_Remote_operations operation, + Objects_Id task_id, + rtems_signal_set signal_in +) +{ + Signal_MP_Packet *the_packet; + + switch ( operation ) { + + case SIGNAL_MP_SEND_REQUEST: + + the_packet = _Signal_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_SIGNAL; + the_packet->Prefix.length = sizeof ( Signal_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( Signal_MP_Packet ); + the_packet->operation = operation; + the_packet->Prefix.id = task_id; + the_packet->signal_in = signal_in; + + return _MPCI_Send_request_packet( + rtems_get_node( task_id ), + &the_packet->Prefix, + STATES_READY /* Not used */ + ); + break; + + case SIGNAL_MP_SEND_RESPONSE: + break; + + } + /* + * The following line is included to satisfy compilers which + * produce warnings when a function does not end with a return. + */ + return RTEMS_INTERNAL_ERROR; +} + +/*PAGE + * + * _Signal_MP_Send_response_packet + * + */ + +void _Signal_MP_Send_response_packet ( + Signal_MP_Remote_operations operation, + Thread_Control *the_thread +) +{ + Signal_MP_Packet *the_packet; + + switch ( operation ) { + + case SIGNAL_MP_SEND_RESPONSE: + + the_packet = ( Signal_MP_Packet *) the_thread->receive_packet; + +/* + * The packet being returned already contains the class, length, and + * to_convert fields, therefore they are not set in this routine. + */ + the_packet->operation = operation; + the_packet->Prefix.id = the_packet->Prefix.source_tid; + + _MPCI_Send_response_packet( + rtems_get_node( the_packet->Prefix.source_tid ), + &the_packet->Prefix + ); + break; + + case SIGNAL_MP_SEND_REQUEST: + break; + + } +} + +/*PAGE + * + * + * _Signal_MP_Process_packet + * + */ + +void _Signal_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +) +{ + Signal_MP_Packet *the_packet; + Thread_Control *the_thread; + + the_packet = (Signal_MP_Packet *) the_packet_prefix; + + switch ( the_packet->operation ) { + + case SIGNAL_MP_SEND_REQUEST: + + the_packet->Prefix.return_code = rtems_signal_send( + the_packet->Prefix.id, + the_packet->signal_in + ); + + _Signal_MP_Send_response_packet( + SIGNAL_MP_SEND_RESPONSE, + _Thread_Executing + ); + break; + + case SIGNAL_MP_SEND_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + } +} + +/*PAGE + * + * _Signal_MP_Send_object_was_deleted + * + * This subprogram is not needed since there are no objects + * deleted by this manager. + * + */ + +/*PAGE + * + * _Signal_MP_Send_extract_proxy + * + * This subprogram is not needed since there are no objects + * deleted by this manager. + * + */ + +/*PAGE + * + * _Signal_MP_Get_packet + * + */ + +Signal_MP_Packet *_Signal_MP_Get_packet ( void ) +{ + return ( (Signal_MP_Packet *) _MPCI_Get_packet() ); +} + +/* end of file */ diff --git a/cpukit/rtems/src/taskmp.c b/cpukit/rtems/src/taskmp.c new file mode 100644 index 0000000000..8edccb05e9 --- /dev/null +++ b/cpukit/rtems/src/taskmp.c @@ -0,0 +1,340 @@ +/* + * Multiprocessing Support for the RTEMS Task 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/score/mpci.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/rtems/options.h> +#include <rtems/rtems/tasks.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> +#include <rtems/rtems/support.h> + +/*PAGE + * + * _RTEMS_tasks_MP_Send_process_packet + * + */ + +void _RTEMS_tasks_MP_Send_process_packet ( + RTEMS_tasks_MP_Remote_operations operation, + Objects_Id task_id, + rtems_name name +) +{ + RTEMS_tasks_MP_Packet *the_packet; + + switch ( operation ) { + + case RTEMS_TASKS_MP_ANNOUNCE_CREATE: + case RTEMS_TASKS_MP_ANNOUNCE_DELETE: + + the_packet = _RTEMS_tasks_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_TASKS; + the_packet->Prefix.length = sizeof ( RTEMS_tasks_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( RTEMS_tasks_MP_Packet ); + the_packet->operation = operation; + the_packet->Prefix.id = task_id; + the_packet->name = name; + + _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix ); + break; + + case RTEMS_TASKS_MP_SUSPEND_REQUEST: + case RTEMS_TASKS_MP_SUSPEND_RESPONSE: + case RTEMS_TASKS_MP_RESUME_REQUEST: + case RTEMS_TASKS_MP_RESUME_RESPONSE: + case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST: + case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE: + case RTEMS_TASKS_MP_GET_NOTE_REQUEST: + case RTEMS_TASKS_MP_GET_NOTE_RESPONSE: + case RTEMS_TASKS_MP_SET_NOTE_REQUEST: + case RTEMS_TASKS_MP_SET_NOTE_RESPONSE: + break; + } +} + +/*PAGE + * + * _RTEMS_tasks_MP_Send_request_packet + * + */ + +rtems_status_code _RTEMS_tasks_MP_Send_request_packet ( + RTEMS_tasks_MP_Remote_operations operation, + Objects_Id task_id, + rtems_task_priority new_priority, + unsigned32 notepad, + unsigned32 note +) +{ + RTEMS_tasks_MP_Packet *the_packet; + + switch ( operation ) { + + case RTEMS_TASKS_MP_SUSPEND_REQUEST: + case RTEMS_TASKS_MP_RESUME_REQUEST: + case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST: + case RTEMS_TASKS_MP_GET_NOTE_REQUEST: + case RTEMS_TASKS_MP_SET_NOTE_REQUEST: + + the_packet = _RTEMS_tasks_MP_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_TASKS; + the_packet->Prefix.length = sizeof ( RTEMS_tasks_MP_Packet ); + the_packet->Prefix.to_convert = sizeof ( RTEMS_tasks_MP_Packet ); + the_packet->operation = operation; + the_packet->Prefix.id = task_id; + the_packet->the_priority = new_priority; + the_packet->notepad = notepad; + the_packet->note = note; + + return _MPCI_Send_request_packet( + rtems_get_node( task_id ), + &the_packet->Prefix, + STATES_READY /* Not used */ + ); + break; + + case RTEMS_TASKS_MP_ANNOUNCE_CREATE: + case RTEMS_TASKS_MP_ANNOUNCE_DELETE: + case RTEMS_TASKS_MP_SUSPEND_RESPONSE: + case RTEMS_TASKS_MP_RESUME_RESPONSE: + case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE: + case RTEMS_TASKS_MP_GET_NOTE_RESPONSE: + case RTEMS_TASKS_MP_SET_NOTE_RESPONSE: + break; + + } + /* + * The following line is included to satisfy compilers which + * produce warnings when a function does not end with a return. + */ + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * _RTEMS_tasks_MP_Send_response_packet + * + */ + +void _RTEMS_tasks_MP_Send_response_packet ( + RTEMS_tasks_MP_Remote_operations operation, + Thread_Control *the_thread +) +{ + RTEMS_tasks_MP_Packet *the_packet; + + switch ( operation ) { + + case RTEMS_TASKS_MP_SUSPEND_RESPONSE: + case RTEMS_TASKS_MP_RESUME_RESPONSE: + case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE: + case RTEMS_TASKS_MP_GET_NOTE_RESPONSE: + case RTEMS_TASKS_MP_SET_NOTE_RESPONSE: + + the_packet = (RTEMS_tasks_MP_Packet *) the_thread->receive_packet; + +/* + * The packet being returned already contains the class, length, and + * to_convert fields, therefore they are not set in this routine. + */ + the_packet->operation = operation; + the_packet->Prefix.id = the_packet->Prefix.source_tid; + + _MPCI_Send_response_packet( + rtems_get_node( the_packet->Prefix.source_tid ), + &the_packet->Prefix + ); + break; + + case RTEMS_TASKS_MP_ANNOUNCE_CREATE: + case RTEMS_TASKS_MP_ANNOUNCE_DELETE: + case RTEMS_TASKS_MP_SUSPEND_REQUEST: + case RTEMS_TASKS_MP_RESUME_REQUEST: + case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST: + case RTEMS_TASKS_MP_GET_NOTE_REQUEST: + case RTEMS_TASKS_MP_SET_NOTE_REQUEST: + break; + + } +} + +/*PAGE + * + * + * _RTEMS_tasks_MP_Process_packet + * + */ + +void _RTEMS_tasks_MP_Process_packet ( + rtems_packet_prefix *the_packet_prefix +) +{ + RTEMS_tasks_MP_Packet *the_packet; + Thread_Control *the_thread; + boolean ignored; + + the_packet = (RTEMS_tasks_MP_Packet *) the_packet_prefix; + + switch ( the_packet->operation ) { + + case RTEMS_TASKS_MP_ANNOUNCE_CREATE: + + ignored = _Objects_MP_Allocate_and_open( + &_RTEMS_tasks_Information, + the_packet->name, + the_packet->Prefix.id, + TRUE + ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case RTEMS_TASKS_MP_ANNOUNCE_DELETE: + + _Objects_MP_Close( &_RTEMS_tasks_Information, the_packet->Prefix.id ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case RTEMS_TASKS_MP_SUSPEND_REQUEST: + + the_packet->Prefix.return_code = rtems_task_suspend( + the_packet->Prefix.id + ); + + _RTEMS_tasks_MP_Send_response_packet( + RTEMS_TASKS_MP_SUSPEND_RESPONSE, + _Thread_Executing + ); + break; + + case RTEMS_TASKS_MP_SUSPEND_RESPONSE: + case RTEMS_TASKS_MP_RESUME_RESPONSE: + case RTEMS_TASKS_MP_SET_NOTE_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case RTEMS_TASKS_MP_RESUME_REQUEST: + + the_packet->Prefix.return_code = rtems_task_resume( + the_packet->Prefix.id + ); + + _RTEMS_tasks_MP_Send_response_packet( + RTEMS_TASKS_MP_RESUME_RESPONSE, + _Thread_Executing + ); + break; + + case RTEMS_TASKS_MP_SET_PRIORITY_REQUEST: + + the_packet->Prefix.return_code = rtems_task_set_priority( + the_packet->Prefix.id, + the_packet->the_priority, + &the_packet->the_priority + ); + + _RTEMS_tasks_MP_Send_response_packet( + RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE, + _Thread_Executing + ); + break; + + case RTEMS_TASKS_MP_SET_PRIORITY_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + *(rtems_task_priority *)the_thread->Wait.return_argument = + the_packet->the_priority; + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case RTEMS_TASKS_MP_GET_NOTE_REQUEST: + + the_packet->Prefix.return_code = rtems_task_get_note( + the_packet->Prefix.id, + the_packet->notepad, + &the_packet->note + ); + + _RTEMS_tasks_MP_Send_response_packet( + RTEMS_TASKS_MP_GET_NOTE_RESPONSE, + _Thread_Executing + ); + break; + + case RTEMS_TASKS_MP_GET_NOTE_RESPONSE: + + the_thread = _MPCI_Process_response( the_packet_prefix ); + + *(unsigned32 *)the_thread->Wait.return_argument = the_packet->note; + + _MPCI_Return_packet( the_packet_prefix ); + break; + + case RTEMS_TASKS_MP_SET_NOTE_REQUEST: + + the_packet->Prefix.return_code = rtems_task_set_note( + the_packet->Prefix.id, + the_packet->notepad, + the_packet->note + ); + + _RTEMS_tasks_MP_Send_response_packet( + RTEMS_TASKS_MP_SET_NOTE_RESPONSE, + _Thread_Executing + ); + break; + } +} + +/*PAGE + * + * _RTEMS_tasks_MP_Send_object_was_deleted + * + * This routine is not neededby the Tasks since a task + * cannot be globally deleted. + * + */ + +/*PAGE + * + * _RTEMS_tasks_MP_Send_extract_proxy + * + * This routine is not neededby the Tasks since a task + * cannot be globally deleted. + * + */ + +/*PAGE + * + * _RTEMS_tasks_MP_Get_packet + * + */ + +RTEMS_tasks_MP_Packet *_RTEMS_tasks_MP_Get_packet ( void ) +{ + return (RTEMS_tasks_MP_Packet *) _MPCI_Get_packet(); +} + +/* end of file */ diff --git a/cpukit/rtems/src/tasks.c b/cpukit/rtems/src/tasks.c new file mode 100644 index 0000000000..0b30fcce69 --- /dev/null +++ b/cpukit/rtems/src/tasks.c @@ -0,0 +1,1098 @@ +/* + * RTEMS Task 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 <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/support.h> +#include <rtems/rtems/modes.h> +#include <rtems/score/object.h> +#include <rtems/score/stack.h> +#include <rtems/score/states.h> +#include <rtems/rtems/tasks.h> +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> +#include <rtems/score/tod.h> +#include <rtems/score/userext.h> +#include <rtems/score/wkspace.h> +#include <rtems/score/apiext.h> +#include <rtems/score/sysstate.h> + +/*PAGE + * + * _RTEMS_tasks_Create_extension + * + * XXX + */ + +boolean _RTEMS_tasks_Create_extension( + Thread_Control *executing, + Thread_Control *created +) +{ + RTEMS_API_Control *api; + + api = _Workspace_Allocate( sizeof( RTEMS_API_Control ) ); + + if ( !api ) + return FALSE; + + created->API_Extensions[ THREAD_API_RTEMS ] = api; + + api->pending_events = EVENT_SETS_NONE_PENDING; + _ASR_Initialize( &api->Signal ); + return TRUE; +} + +/*PAGE + * + * _RTEMS_tasks_Start_extension + * + * XXX + */ + +User_extensions_routine _RTEMS_tasks_Start_extension( + Thread_Control *executing, + Thread_Control *started +) +{ + RTEMS_API_Control *api; + + api = started->API_Extensions[ THREAD_API_RTEMS ]; + + api->pending_events = EVENT_SETS_NONE_PENDING; + + _ASR_Initialize( &api->Signal ); +} + +/*PAGE + * + * _RTEMS_tasks_Delete_extension + * + * XXX + */ + +User_extensions_routine _RTEMS_tasks_Delete_extension( + Thread_Control *executing, + Thread_Control *deleted +) +{ + (void) _Workspace_Free( deleted->API_Extensions[ THREAD_API_RTEMS ] ); + + deleted->API_Extensions[ THREAD_API_RTEMS ] = NULL; +} + +/*PAGE + * + * _RTEMS_tasks_Switch_extension + * + * XXX + */ + +void _RTEMS_tasks_Switch_extension( + Thread_Control *executing +) +{ + ISR_Level level; + RTEMS_API_Control *api; + ASR_Information *asr; + rtems_signal_set signal_set; + Modes_Control prev_mode; + + api = executing->API_Extensions[ THREAD_API_RTEMS ]; + asr = &api->Signal; + + _ISR_Disable( level ); + signal_set = asr->signals_posted; + asr->signals_posted = 0; + _ISR_Enable( level ); + + + if ( !signal_set ) /* similar to _ASR_Are_signals_pending( asr ) */ + return; + + asr->nest_level += 1; + rtems_task_mode( asr->mode_set, RTEMS_ALL_MODE_MASKS, &prev_mode ); + + (*asr->handler)( signal_set ); + + asr->nest_level -= 1; + rtems_task_mode( prev_mode, RTEMS_ALL_MODE_MASKS, &prev_mode ); + +} + +API_extensions_Control _RTEMS_tasks_API_extensions = { + { NULL, NULL }, + NULL, /* predriver */ + _RTEMS_tasks_Initialize_user_tasks, /* postdriver */ + _RTEMS_tasks_Switch_extension /* post switch */ +}; + +User_extensions_Control _RTEMS_tasks_User_extensions = { + { NULL, NULL }, + { _RTEMS_tasks_Create_extension, /* create */ + _RTEMS_tasks_Start_extension, /* start */ + _RTEMS_tasks_Start_extension, /* restart */ + _RTEMS_tasks_Delete_extension, /* delete */ + NULL, /* switch */ + NULL, /* begin */ + NULL, /* exitted */ + NULL /* fatal */ + } +}; + +/*PAGE + * + * _RTEMS_tasks_Manager_initialization + * + * This routine initializes all Task Manager related data structures. + * + * Input parameters: + * maximum_tasks - number of tasks to initialize + * + * Output parameters: NONE + */ + +void _RTEMS_tasks_Manager_initialization( + unsigned32 maximum_tasks, + unsigned32 number_of_initialization_tasks, + rtems_initialization_tasks_table *user_tasks +) +{ + + _RTEMS_tasks_Number_of_initialization_tasks = number_of_initialization_tasks; + _RTEMS_tasks_User_initialization_tasks = user_tasks; + + if ( user_tasks == NULL || number_of_initialization_tasks == 0 ) + _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, RTEMS_TOO_MANY ); + + _Objects_Initialize_information( + &_RTEMS_tasks_Information, + OBJECTS_RTEMS_TASKS, + TRUE, + maximum_tasks, + sizeof( Thread_Control ), + FALSE, + RTEMS_MAXIMUM_NAME_LENGTH, + TRUE + ); + + /* + * Add all the extensions for this API + */ + + _User_extensions_Add_API_set( &_RTEMS_tasks_User_extensions ); + + _API_extensions_Add( &_RTEMS_tasks_API_extensions ); + + /* + * Register the MP Process Packet routine. + */ + + _MPCI_Register_packet_processor( + MP_PACKET_TASKS, + _RTEMS_tasks_MP_Process_packet + ); + +} + +/*PAGE + * + * rtems_task_create + * + * This directive creates a thread by allocating and initializing a + * thread control block and a stack. The newly created thread is + * placed in the dormant state. + * + * Input parameters: + * name - user defined thread name + * initial_priority - thread priority + * stack_size - stack size in bytes + * initial_modes - initial thread mode + * attribute_set - thread attributes + * id - pointer to thread id + * + * Output parameters: + * id - thread id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_create( + rtems_name name, + rtems_task_priority initial_priority, + unsigned32 stack_size, + rtems_mode initial_modes, + rtems_attribute attribute_set, + Objects_Id *id +) +{ + register Thread_Control *the_thread; + Objects_MP_Control *the_global_object = NULL; + boolean is_fp; + boolean is_global; + boolean status; + rtems_attribute the_attribute_set; + Priority_Control core_priority; + RTEMS_API_Control *api; + ASR_Information *asr; + + + if ( !rtems_is_name_valid( name ) ) + return RTEMS_INVALID_NAME; + + /* + * Core Thread Initialize insures we get the minimum amount of + * stack space. + */ + +#if 0 + if ( !_Stack_Is_enough( stack_size ) ) + return RTEMS_INVALID_SIZE; +#endif + + /* + * Validate the RTEMS API priority and convert it to the core priority range. + */ + + if ( !_RTEMS_tasks_Priority_is_valid( initial_priority ) ) + return RTEMS_INVALID_PRIORITY; + + core_priority = _RTEMS_tasks_Priority_to_Core( initial_priority ); + + /* + * Fix the attribute set to match the attributes which + * this processor (1) requires and (2) is able to support. + * First add in the required flags for attribute_set + * Typically this might include FP if the platform + * or application required all tasks to be fp aware. + * Then turn off the requested bits which are not supported. + */ + + the_attribute_set = _Attributes_Set( attribute_set, ATTRIBUTES_REQUIRED ); + the_attribute_set = + _Attributes_Clear( the_attribute_set, ATTRIBUTES_NOT_SUPPORTED ); + + if ( _Attributes_Is_floating_point( the_attribute_set ) ) + is_fp = TRUE; + else + is_fp = FALSE; + + if ( _Attributes_Is_global( the_attribute_set ) ) { + + is_global = TRUE; + + if ( !_System_state_Is_multiprocessing ) + return RTEMS_MP_NOT_CONFIGURED; + + } else + is_global = FALSE; + + /* + * Make sure system is MP if this task is global + */ + + /* + * Disable dispatch for protection + */ + + _Thread_Disable_dispatch(); + + /* + * Allocate the thread control block and -- if the task is global -- + * allocate a global object control block. + * + * NOTE: This routine does not use the combined allocate and open + * global object routine because this results in a lack of + * control over when memory is allocated and can be freed in + * the event of an error. + */ + + the_thread = _RTEMS_tasks_Allocate(); + + if ( !the_thread ) { + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + + if ( is_global ) { + the_global_object = _Objects_MP_Allocate_global_object(); + + if ( _Objects_MP_Is_null_global_object( the_global_object ) ) { + _RTEMS_tasks_Free( the_thread ); + _Thread_Enable_dispatch(); + return RTEMS_TOO_MANY; + } + } + + /* + * Initialize the core thread for this task. + */ + + status = _Thread_Initialize( + &_RTEMS_tasks_Information, + the_thread, + NULL, + stack_size, + is_fp, + core_priority, + _Modes_Is_preempt(initial_modes) ? TRUE : FALSE, + _Modes_Is_timeslice(initial_modes) ? TRUE : FALSE, + _Modes_Get_interrupt_level(initial_modes), + &name + ); + + if ( !status ) { + if ( is_global ) + _Objects_MP_Free_global_object( the_global_object ); + _RTEMS_tasks_Free( the_thread ); + _Thread_Enable_dispatch(); + return RTEMS_UNSATISFIED; + } + + api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; + asr = &api->Signal; + + asr->is_enabled = _Modes_Is_asr_disabled(initial_modes) ? FALSE : TRUE; + + *id = the_thread->Object.id; + + if ( is_global ) { + + the_thread->is_global = TRUE; + + _Objects_MP_Open( + &_RTEMS_tasks_Information, + the_global_object, + name, + the_thread->Object.id + ); + + _RTEMS_tasks_MP_Send_process_packet( + RTEMS_TASKS_MP_ANNOUNCE_CREATE, + the_thread->Object.id, + name + ); + + } + + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_task_ident + * + * This directive returns the system ID associated with + * the thread name. + * + * Input parameters: + * name - user defined thread name + * node - node(s) to be searched + * id - pointer to thread id + * + * Output parameters: + * *id - thread id + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_ident( + rtems_name name, + unsigned32 node, + Objects_Id *id +) +{ + Objects_Name_to_id_errors status; + + if ( name == OBJECTS_ID_OF_SELF ) { + *id = _Thread_Executing->Object.id; + return RTEMS_SUCCESSFUL; + } + + status = _Objects_Name_to_id( &_RTEMS_tasks_Information, &name, node, id ); + + return _Status_Object_name_errors_to_status[ status ]; +} + +/*PAGE + * + * rtems_task_start + * + * This directive readies the thread identified by the "id" + * based on its current priorty, to await execution. A thread + * can be started only from the dormant state. + * + * Input parameters: + * id - thread id + * entry_point - start execution address of thread + * argument - thread argument + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_start( + rtems_id id, + rtems_task_entry entry_point, + unsigned32 argument +) +{ + register Thread_Control *the_thread; + Objects_Locations location; + + if ( entry_point == NULL ) + return RTEMS_INVALID_ADDRESS; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; + case OBJECTS_LOCAL: + if ( _Thread_Start( + the_thread, THREAD_START_NUMERIC, entry_point, NULL, argument ) ) { + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_INCORRECT_STATE; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_task_restart + * + * This directive readies the specified thread. It restores + * the thread environment to the original values established + * at thread creation and start time. A thread can be restarted + * from any state except the dormant state. + * + * Input parameters: + * id - thread id + * argument - thread argument + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_restart( + Objects_Id id, + unsigned32 argument +) +{ + register Thread_Control *the_thread; + Objects_Locations location; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; + case OBJECTS_LOCAL: + if ( _Thread_Restart( the_thread, NULL, argument ) ) { + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_INCORRECT_STATE; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_task_delete + * + * This directive allows a thread to delete itself or the thread + * identified in the id field. The executive halts execution + * of the thread and frees the thread control block. + * + * Input parameters: + * id - thread id + * + * Output parameters: + * nothing - if id is the requesting thread (always succeeds) + * RTEMS_SUCCESSFUL - if successful and id is + * not the requesting thread + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_delete( + Objects_Id id +) +{ + register Thread_Control *the_thread; + Objects_Locations location; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Dispatch(); + return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; + case OBJECTS_LOCAL: + _Thread_Close( &_RTEMS_tasks_Information, the_thread ); + + _RTEMS_tasks_Free( the_thread ); + + if ( the_thread->is_global ) { + + _Objects_MP_Close( &_RTEMS_tasks_Information, the_thread->Object.id ); + + _RTEMS_tasks_MP_Send_process_packet( + RTEMS_TASKS_MP_ANNOUNCE_DELETE, + the_thread->Object.id, + 0 /* Not used */ + ); + } + + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_task_suspend + * + * This directive will place the specified thread in the "suspended" + * state. Note that the suspended state can be in addition to + * other waiting states. + * + * Input parameters: + * id - thread id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_suspend( + Objects_Id id +) +{ + register Thread_Control *the_thread; + Objects_Locations location; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + return _RTEMS_tasks_MP_Send_request_packet( + RTEMS_TASKS_MP_SUSPEND_REQUEST, + id, + 0, /* Not used */ + 0, /* Not used */ + 0 /* Not used */ + ); + case OBJECTS_LOCAL: + if ( !_States_Is_suspended( the_thread->current_state ) ) { + _Thread_Set_state( the_thread, STATES_SUSPENDED ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_ALREADY_SUSPENDED; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_task_resume + * + * This directive will remove the specified thread + * from the suspended state. + * + * Input parameters: + * id - thread id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_resume( + Objects_Id id +) +{ + register Thread_Control *the_thread; + Objects_Locations location; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + return( + _RTEMS_tasks_MP_Send_request_packet( + RTEMS_TASKS_MP_RESUME_REQUEST, + id, + 0, /* Not used */ + 0, /* Not used */ + 0 /* Not used */ + ) + ); + case OBJECTS_LOCAL: + if ( _States_Is_suspended( the_thread->current_state ) ) { + _Thread_Resume( the_thread ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + _Thread_Enable_dispatch(); + return RTEMS_INCORRECT_STATE; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_task_set_priority + * + * This directive changes the priority of the specified thread. + * The specified thread can be any thread in the system including + * the requesting thread. + * + * Input parameters: + * id - thread id (0 indicates requesting thread) + * new_priority - thread priority (0 indicates current priority) + * old_priority - pointer to previous priority + * + * Output parameters: + * old_priority - previous priority + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_set_priority( + Objects_Id id, + rtems_task_priority new_priority, + rtems_task_priority *old_priority +) +{ + register Thread_Control *the_thread; + Objects_Locations location; + + if ( new_priority != RTEMS_CURRENT_PRIORITY && + !_RTEMS_tasks_Priority_is_valid( new_priority ) ) + return RTEMS_INVALID_PRIORITY; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Executing->Wait.return_argument = old_priority; + return( + _RTEMS_tasks_MP_Send_request_packet( + RTEMS_TASKS_MP_SET_PRIORITY_REQUEST, + id, + new_priority, + 0, /* Not used */ + 0 /* Not used */ + ) + ); + case OBJECTS_LOCAL: + *old_priority = the_thread->current_priority; + if ( new_priority != RTEMS_CURRENT_PRIORITY ) { + the_thread->real_priority = new_priority; + if ( the_thread->resource_count == 0 || + the_thread->current_priority > new_priority ) + _Thread_Change_priority( the_thread, new_priority ); + } + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_task_mode + * + * This directive enables and disables several modes of + * execution for the requesting thread. + * + * Input parameters: + * mode_set - new mode + * mask - mask + * previous_mode_set - address of previous mode set + * + * Output: + * *previous_mode_set - previous mode set + * always return RTEMS_SUCCESSFUL; + */ + +rtems_status_code rtems_task_mode( + rtems_mode mode_set, + rtems_mode mask, + rtems_mode *previous_mode_set +) +{ + Thread_Control *executing; + RTEMS_API_Control *api; + ASR_Information *asr; + boolean is_asr_enabled = FALSE; + boolean needs_asr_dispatching = FALSE; + rtems_mode old_mode; + + executing = _Thread_Executing; + api = executing->API_Extensions[ THREAD_API_RTEMS ]; + asr = &api->Signal; + + old_mode = (executing->is_preemptible) ? RTEMS_PREEMPT : RTEMS_NO_PREEMPT; + old_mode |= (executing->is_timeslice) ? RTEMS_TIMESLICE : RTEMS_NO_TIMESLICE; + old_mode |= (asr->is_enabled) ? RTEMS_ASR : RTEMS_NO_ASR; + old_mode |= _ISR_Get_level(); + + *previous_mode_set = old_mode; + + /* + * These are generic thread scheduling characteristics. + */ + + if ( mask & RTEMS_PREEMPT_MASK ) + executing->is_preemptible = _Modes_Is_preempt(mode_set) ? TRUE : FALSE; + + if ( mask & RTEMS_TIMESLICE_MASK ) + executing->is_timeslice = _Modes_Is_timeslice(mode_set) ? TRUE : FALSE; + + /* + * Set the new interrupt level + */ + + if ( mask & RTEMS_INTERRUPT_MASK ) + _Modes_Set_interrupt_level( mode_set ); + + /* + * This is specific to the RTEMS API + */ + + is_asr_enabled = FALSE; + needs_asr_dispatching = FALSE; + + if ( mask & RTEMS_ASR_MASK ) { + is_asr_enabled = _Modes_Is_asr_disabled( mode_set ) ? FALSE : TRUE; + if ( is_asr_enabled != asr->is_enabled ) { + asr->is_enabled = is_asr_enabled; + _ASR_Swap_signals( asr ); + if ( _ASR_Are_signals_pending( asr ) ) { + needs_asr_dispatching = TRUE; + executing->do_post_task_switch_extension = TRUE; + } + } + } + + if ( _Thread_Evaluate_mode() || needs_asr_dispatching ) + _Thread_Dispatch(); + + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_task_get_note + * + * This directive obtains the note from the specified notepad + * of the specified thread. + * + * Input parameters: + * id - thread id + * notepad - notepad number + * note - pointer to note + * + * Output parameters: + * note - filled in if successful + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_get_note( + Objects_Id id, + unsigned32 notepad, + unsigned32 *note +) +{ + register Thread_Control *the_thread; + Objects_Locations location; + RTEMS_API_Control *api; + + /* + * NOTE: There is no check for < RTEMS_NOTEPAD_FIRST because that would + * be checking an unsigned number for being negative. + */ + + if ( notepad > RTEMS_NOTEPAD_LAST ) + return RTEMS_INVALID_NUMBER; + + /* + * Optimize the most likely case to avoid the Thread_Dispatch. + */ + + if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) || + _Objects_Are_ids_equal( id, _Thread_Executing->Object.id ) ) { + api = _Thread_Executing->API_Extensions[ THREAD_API_RTEMS ]; + *note = api->Notepads[ notepad ]; + return RTEMS_SUCCESSFUL; + } + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + _Thread_Executing->Wait.return_argument = note; + + return _RTEMS_tasks_MP_Send_request_packet( + RTEMS_TASKS_MP_GET_NOTE_REQUEST, + id, + 0, /* Not used */ + notepad, + 0 /* Not used */ + ); + case OBJECTS_LOCAL: + api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; + *note = api->Notepads[ notepad ]; + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_task_set_note + * + * This directive sets the specified notepad contents to the given + * note. + * + * Input parameters: + * id - thread id + * notepad - notepad number + * note - note value + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_set_note( + Objects_Id id, + unsigned32 notepad, + unsigned32 note +) +{ + register Thread_Control *the_thread; + Objects_Locations location; + RTEMS_API_Control *api; + + /* + * NOTE: There is no check for < RTEMS_NOTEPAD_FIRST because that would + * be checking an unsigned number for being negative. + */ + + if ( notepad > RTEMS_NOTEPAD_LAST ) + return RTEMS_INVALID_NUMBER; + + /* + * Optimize the most likely case to avoid the Thread_Dispatch. + */ + + if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) || + _Objects_Are_ids_equal( id, _Thread_Executing->Object.id ) ) { + api = _Thread_Executing->API_Extensions[ THREAD_API_RTEMS ]; + api->Notepads[ notepad ] = note; + return RTEMS_SUCCESSFUL; + } + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + case OBJECTS_REMOTE: + return _RTEMS_tasks_MP_Send_request_packet( + RTEMS_TASKS_MP_SET_NOTE_REQUEST, + id, + 0, /* Not used */ + notepad, + note + ); + + case OBJECTS_LOCAL: + api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; + api->Notepads[ notepad ] = note; + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} + +/*PAGE + * + * rtems_task_wake_after + * + * This directive suspends the requesting thread for the given amount + * of ticks. + * + * Input parameters: + * ticks - number of ticks to wait + * + * Output parameters: + * RTEMS_SUCCESSFUL - always successful + */ + +rtems_status_code rtems_task_wake_after( + rtems_interval ticks +) +{ + if ( ticks == 0 ) { + _Thread_Yield_processor(); + _Thread_Dispatch(); + } else { + _Thread_Disable_dispatch(); + _Thread_Set_state( _Thread_Executing, STATES_DELAYING ); + _Watchdog_Initialize( + &_Thread_Executing->Timer, + _Thread_Delay_ended, + _Thread_Executing->Object.id, + NULL + ); + _Watchdog_Insert_ticks( &_Thread_Executing->Timer, ticks ); + _Thread_Enable_dispatch(); + } + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * rtems_task_wake_when + * + * This directive blocks the requesting thread until the given date and + * time is reached. + * + * Input parameters: + * time_buffer - pointer to the time and date structure + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_task_wake_when( +rtems_time_of_day *time_buffer +) +{ + Watchdog_Interval seconds; + + if ( !_TOD_Is_set() ) + return RTEMS_NOT_DEFINED; + + time_buffer->ticks = 0; + + if ( !_TOD_Validate( time_buffer ) ) + return RTEMS_INVALID_CLOCK; + + seconds = _TOD_To_seconds( time_buffer ); + + if ( seconds <= _TOD_Seconds_since_epoch ) + return RTEMS_INVALID_CLOCK; + + _Thread_Disable_dispatch(); + _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_TIME ); + _Watchdog_Initialize( + &_Thread_Executing->Timer, + _Thread_Delay_ended, + _Thread_Executing->Object.id, + NULL + ); + _Watchdog_Insert_seconds( + &_Thread_Executing->Timer, + seconds - _TOD_Seconds_since_epoch + ); + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; +} + +/*PAGE + * + * _RTEMS_tasks_Initialize_user_tasks + * + * This routine creates and starts all configured user + * initialzation threads. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _RTEMS_tasks_Initialize_user_tasks( void ) +{ + unsigned32 index; + unsigned32 maximum; + rtems_id id; + rtems_status_code return_value; + rtems_initialization_tasks_table *user_tasks; + + /* + * NOTE: This is slightly different from the Ada implementation. + */ + + user_tasks = _RTEMS_tasks_User_initialization_tasks; + maximum = _RTEMS_tasks_Number_of_initialization_tasks; + + for ( index=0 ; index < maximum ; index++ ) { + return_value = rtems_task_create( + user_tasks[ index ].name, + user_tasks[ index ].initial_priority, + user_tasks[ index ].stack_size, + user_tasks[ index ].mode_set, + user_tasks[ index ].attribute_set, + &id + ); + + if ( !rtems_is_status_successful( return_value ) ) + _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, return_value ); + + return_value = rtems_task_start( + id, + user_tasks[ index ].entry_point, + user_tasks[ index ].argument + ); + + if ( !rtems_is_status_successful( return_value ) ) + _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, TRUE, return_value ); + } +} + diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h new file mode 100644 index 0000000000..83f6c3ccd1 --- /dev/null +++ b/cpukit/sapi/include/confdefs.h @@ -0,0 +1,377 @@ +/* confdefs.h + * + * This include file contains the configuration table template that will + * be used by the single processor tests to define its default configuration + * parameters. + * + * 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$ + */ + +#ifndef __CONFIGURATION_TEMPLATE_h +#define __CONFIGURATION_TEMPLATE_h + +#ifdef __cplusplus +extern "C" { +#endif + + +extern rtems_initialization_tasks_table Initialization_tasks[]; +extern rtems_driver_address_table Device_drivers[]; +extern rtems_configuration_table Configuration; +extern rtems_multiprocessing_table Multiprocessing_configuration; + +/* + * Default User Initialization Task Table. This table guarantees that + * one user initialization table is defined. + */ + +#ifndef CONFIGURE_HAS_OWN_INIT_TASK_TABLE + +#ifndef CONFIGURE_INIT_TASK_NAME +#define CONFIGURE_INIT_TASK_NAME rtems_build_name( 'U', 'I', '1', ' ' ) +#endif + +#ifndef CONFIGURE_INIT_TASK_STACK_SIZE +#define CONFIGURE_INIT_TASK_STACK_SIZE RTEMS_MINIMUM_STACK_SIZE +#endif + +#ifndef CONFIGURE_INIT_TASK_PRIORITY +#define CONFIGURE_INIT_TASK_PRIORITY 1 +#endif + +#ifndef CONFIGURE_INIT_TASK_ATTRIBUTES +#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES +#endif + +#ifndef CONFIGURE_INIT_TASK_ENTRY_POINT +#define CONFIGURE_INIT_TASK_ENTRY_POINT Init +#endif + +#ifndef CONFIGURE_INIT_TASK_INITIAL_MODES +#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_NO_PREEMPT +#endif + +#ifndef CONFIGURE_INIT_TASK_ARGUMENTS +#define CONFIGURE_INIT_TASK_ARGUMENTS 0 +#endif + +#ifdef CONFIGURE_INIT +rtems_initialization_tasks_table Initialization_tasks[] = { + { CONFIGURE_INIT_TASK_NAME, + CONFIGURE_INIT_TASK_STACK_SIZE, + CONFIGURE_INIT_TASK_PRIORITY, + CONFIGURE_INIT_TASK_ATTRIBUTES, + CONFIGURE_INIT_TASK_ENTRY_POINT, + CONFIGURE_INIT_TASK_INITIAL_MODES, + CONFIGURE_INIT_TASK_ARGUMENTS + } +}; +#endif + +#endif + +/* + * Default Device Driver Table. Each driver needed by the test is explicitly + * choosen by that test. There is always a null driver entry. + */ + +#define NULL_DRIVER_TABLE_ENTRY \ + { NULL, NULL, NULL, NULL, NULL, NULL } + +#ifdef CONFIGURE_TEST_NEEDS_TIMER_DRIVER +#include <timerdrv.h> +#endif + +#ifdef CONFIGURE_TEST_NEEDS_STUB_DRIVER +#include <stubdrv.h> +#endif + +#ifndef CONFIGURE_HAS_OWN_DEVICE_DRIVER_TABLE + +#ifdef CONFIGURE_INIT +rtems_driver_address_table Device_drivers[] = { +#ifdef CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER + CONSOLE_DRIVER_TABLE_ENTRY, +#endif +#ifdef CONFIGURE_TEST_NEEDS_CLOCK_DRIVER + CLOCK_DRIVER_TABLE_ENTRY, +#endif +#ifdef CONFIGURE_TEST_NEEDS_STUB_DRIVER + STUB_DRIVER_TABLE_ENTRY, +#endif + NULL_DRIVER_TABLE_ENTRY +}; +#endif + +#endif /* CONFIGURE_HAS_OWN_DEVICE_DRIVER_TABLE */ + +/* + * Default the number of devices per device driver. This value may be + * overridden by the user. + */ + +#ifndef CONFIGURE_HAS_OWN_NUMBER_OF_DEVICES + +#ifndef CONFIGURE_MAXIMUM_DEVICES +#define CONFIGURE_MAXIMUM_DEVICES 20 +#endif + +#endif /* CONFIGURE_HAS_OWN_NUMBER_OF_DEVICES */ + +/* + * Default Configuration Table. This table contains the most values set in + * the RTEMS Test Suite. Each value may be overridden within each test to + * customize the environment. + */ + +#ifdef CONFIGURE_MPTEST +#ifndef CONFIGURE_HAS_OWN_MULTIPROCESING_TABLE + +#ifndef CONFIGURE_MP_NODE_NUMBER +#define CONFIGURE_MP_NODE_NUMBER NODE_NUMBER +#endif + +#ifndef CONFIGURE_MP_MAXIMUM_NODES +#define CONFIGURE_MP_MAXIMUM_NODES 2 +#endif + +#ifndef CONFIGURE_MP_MAXIMUM_GLOBAL_OBJECTS +#define CONFIGURE_MP_MAXIMUM_GLOBAL_OBJECTS 32 +#endif + +#ifndef CONFIGURE_MP_MAXIMUM_PROXIES +#define CONFIGURE_MP_MAXIMUM_PROXIES 32 +#endif + +#ifndef CONFIGURE_MP_MPCI_TABLE_POINTER +#include <mpci.h> +#define CONFIGURE_MP_MPCI_TABLE_POINTER &MPCI_table +#endif + +#ifdef CONFIGURE_INIT +rtems_multiprocessing_table Multiprocessing_configuration = { + CONFIGURE_MP_NODE_NUMBER, /* local node number */ + CONFIGURE_MP_MAXIMUM_NODES, /* maximum # nodes in system */ + CONFIGURE_MP_MAXIMUM_GLOBAL_OBJECTS, /* maximum # global objects */ + CONFIGURE_MP_MAXIMUM_PROXIES, /* maximum # proxies */ + CONFIGURE_MP_MPCI_TABLE_POINTER /* pointer to MPCI config table */ +}; +#endif + +#define CONFIGURE_MULTIPROCESSING_TABLE &Multiprocessing_configuration + +#endif /* CONFIGURE_HAS_OWN_MULTIPROCESING_TABLE */ + +#else + +#define CONFIGURE_MULTIPROCESSING_TABLE NULL + +#endif /* CONFIGURE_MPTEST */ + +/* + * Default Configuration Table. This table contains the most values set in + * the RTEMS Test Suite. Each value may be overridden within each test to + * customize the environment. + */ + +#ifndef CONFIGURE_HAS_OWN_CONFIGURATION_TABLE + +#ifndef CONFIGURE_EXECUTIVE_RAM_WORK_AREA +#define CONFIGURE_EXECUTIVE_RAM_WORK_AREA NULL +#endif + +#ifndef CONFIGURE_MAXIMUM_TASKS +#define CONFIGURE_MAXIMUM_TASKS 10 +#endif + +#ifndef CONFIGURE_MAXIMUM_TIMERS +#define CONFIGURE_MAXIMUM_TIMERS 0 +#endif + +#ifndef CONFIGURE_MAXIMUM_SEMAPHORES +#define CONFIGURE_MAXIMUM_SEMAPHORES 0 +#endif + +#ifndef CONFIGURE_MAXIMUM_MESSAGE_QUEUES +#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 0 +#endif + +#ifndef CONFIGURE_MAXIMUM_PARTITIONS +#define CONFIGURE_MAXIMUM_PARTITIONS 0 +#endif + +#ifndef CONFIGURE_MAXIMUM_REGIONS +#define CONFIGURE_MAXIMUM_REGIONS 0 +#endif + +#ifndef CONFIGURE_MAXIMUM_PORTS +#define CONFIGURE_MAXIMUM_PORTS 0 +#endif + +#ifndef CONFIGURE_MAXIMUM_PERIODS +#define CONFIGURE_MAXIMUM_PERIODS 0 +#endif + +#ifndef CONFIGURE_MAXIMUM_USER_EXTENSIONS +#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 0 +#endif + +#ifndef CONFIGURE_MICROSECONDS_PER_TICK +#define CONFIGURE_MICROSECONDS_PER_TICK RTEMS_MILLISECONDS_TO_MICROSECONDS(10) +#endif + +#ifndef CONFIGURE_TICKS_PER_TIMESLICE +#define CONFIGURE_TICKS_PER_TIMESLICE 50 +#endif + +#ifndef CONFIGURE_INITIAL_EXTENSIONS +#define CONFIGURE_INITIAL_EXTENSIONS NULL +#endif + +/* + * Calculate the RAM size based on the maximum number of objects configured. + * The model is to estimate the memory required for each configured item, + * sum the memory requirements and insure that there is at least 32K greater + * than that for things not directly addressed such as: + * + * + stacks greater than minimum size + * + FP contexts + * + API areas (should be optional) + * + messages + * + object name and local pointer table overhead + * + per node memory requirements + * + executive fixed requirements (including at least internal threads + * and the Ready chains) + * + * NOTE: Eventually this should take into account some of the above. + * Basically, this is a "back of the envelope" estimate for + * memory requirements. It could be more accurate. + */ + +#ifndef CONFIGURE_EXECUTIVE_RAM_SIZE + +#define CONFIGURE_OBJECT_TABLE_STUFF \ + ( sizeof(Objects_Control *) + sizeof(rtems_name *) + sizeof(rtems_name) ) + +#define CONFIGURE_MEMORY_FOR_TASKS(_tasks) \ + ((_tasks) * \ + ((sizeof(Thread_Control) + CONTEXT_FP_SIZE + \ + STACK_MINIMUM_SIZE + sizeof( RTEMS_API_Control ) + \ + CONFIGURE_OBJECT_TABLE_STUFF)) \ + ) + +#define CONFIGURE_MEMORY_FOR_TIMERS(_timers) \ + ((_timers) * ( sizeof(Timer_Control) + CONFIGURE_OBJECT_TABLE_STUFF ) ) + +#define CONFIGURE_MEMORY_FOR_SEMAPHORES(_semaphores) \ + ((_semaphores) * \ + ( sizeof(Semaphore_Control) + CONFIGURE_OBJECT_TABLE_STUFF ) ) + +#define CONFIGURE_MEMORY_FOR_MESSAGE_QUEUES(_queues) \ + ( (_queues) * \ + ( sizeof(Message_queue_Control) + CONFIGURE_OBJECT_TABLE_STUFF ) ) + +#define CONFIGURE_MEMORY_FOR_PARTITIONS(_partitions) \ + ( (_partitions) * \ + ( sizeof(Partition_Control) + CONFIGURE_OBJECT_TABLE_STUFF ) ) + +#define CONFIGURE_MEMORY_FOR_REGIONS(_regions) \ + ( (_regions) * \ + ( sizeof(Region_Control) + CONFIGURE_OBJECT_TABLE_STUFF ) ) + +#define CONFIGURE_MEMORY_FOR_PORTS(_ports) \ + ( (_ports) * \ + ( sizeof(Dual_ported_memory_Control) + CONFIGURE_OBJECT_TABLE_STUFF ) ) + +#define CONFIGURE_MEMORY_FOR_PERIODS(_periods) \ + ( (_periods) * \ + ( sizeof(Rate_monotonic_Control) + CONFIGURE_OBJECT_TABLE_STUFF ) ) + +#define CONFIGURE_MEMORY_FOR_USER_EXTENSIONS(_extensions) \ + ( (_extensions) * \ + ( sizeof(Extension_Control) + CONFIGURE_OBJECT_TABLE_STUFF ) ) + +#define CONFIGURE_MEMORY_FOR_DEVICES(_devices) \ + (((_devices) + 1) * ( sizeof(rtems_driver_name_t) ) ) + +#ifdef CONFIGURE_MPTEST + +#ifndef CONFIGURE_HAS_OWN_MULTIPROCESING_TABLE + +#define CONFIGURE_MEMORY_FOR_PROXIES(_proxies) \ + ( ((_proxies) + 1) * ( sizeof(Thread_Proxy_control) ) ) + +#define CONFIGURE_MEMORY_FOR_GLOBAL_OBJECTS(_global_objects) \ + ((_global_objects) * ( sizeof(Objects_MP_Control) ) ) + +#define CONFIGURE_MEMORY_FOR_MP \ + ( CONFIGURE_MEMORY_FOR_PROXIES(CONFIGURE_MP_MAXIMUM_PROXIES) + \ + CONFIGURE_MEMORY_FOR_GLOBAL_OBJECTS(CONFIGURE_MP_MAXIMUM_GLOBAL_OBJECTS) \ + ) + +#endif /* CONFIGURE_HAS_OWN_MULTIPROCESING_TABLE */ + +#else + +#define CONFIGURE_MEMORY_FOR_MP 0 + +#endif +#define CONFIGURE_EXECUTIVE_RAM_SIZE \ +(( CONFIGURE_MEMORY_FOR_TASKS(CONFIGURE_MAXIMUM_TASKS) + \ + CONFIGURE_MEMORY_FOR_TIMERS(CONFIGURE_MAXIMUM_TIMERS) + \ + CONFIGURE_MEMORY_FOR_SEMAPHORES(CONFIGURE_MAXIMUM_SEMAPHORES) + \ + CONFIGURE_MEMORY_FOR_MESSAGE_QUEUES(CONFIGURE_MAXIMUM_MESSAGE_QUEUES) + \ + CONFIGURE_MEMORY_FOR_PARTITIONS(CONFIGURE_MAXIMUM_PARTITIONS) + \ + CONFIGURE_MEMORY_FOR_REGIONS(CONFIGURE_MAXIMUM_REGIONS) + \ + CONFIGURE_MEMORY_FOR_PORTS(CONFIGURE_MAXIMUM_PORTS) + \ + CONFIGURE_MEMORY_FOR_PERIODS(CONFIGURE_MAXIMUM_PERIODS) + \ + CONFIGURE_MEMORY_FOR_USER_EXTENSIONS(CONFIGURE_MAXIMUM_USER_EXTENSIONS) + \ + CONFIGURE_MEMORY_FOR_DEVICES(CONFIGURE_MAXIMUM_DEVICES) + \ + CONFIGURE_MEMORY_FOR_MP + \ + (96*1024) \ +) & 0xffff8000) +#endif + +#ifdef CONFIGURE_INIT +rtems_configuration_table Configuration = { + CONFIGURE_EXECUTIVE_RAM_WORK_AREA, + CONFIGURE_EXECUTIVE_RAM_SIZE, + CONFIGURE_MAXIMUM_TASKS, + CONFIGURE_MAXIMUM_TIMERS, + CONFIGURE_MAXIMUM_SEMAPHORES, + CONFIGURE_MAXIMUM_MESSAGE_QUEUES, + CONFIGURE_MAXIMUM_PARTITIONS, + CONFIGURE_MAXIMUM_REGIONS, + CONFIGURE_MAXIMUM_PORTS, + CONFIGURE_MAXIMUM_PERIODS, + CONFIGURE_MAXIMUM_USER_EXTENSIONS, + CONFIGURE_MICROSECONDS_PER_TICK, + CONFIGURE_TICKS_PER_TIMESLICE, + sizeof (Initialization_tasks)/ + sizeof(rtems_initialization_tasks_table), /* number of init tasks */ + Initialization_tasks, /* init task(s) table */ + sizeof (Device_drivers)/ + sizeof(rtems_driver_address_table), /* number of device drivers */ + CONFIGURE_MAXIMUM_DEVICES, + Device_drivers, /* pointer to driver table */ + CONFIGURE_INITIAL_EXTENSIONS, /* pointer to initial extensions */ + CONFIGURE_MULTIPROCESSING_TABLE /* ptr to MP config table */ +}; +#endif + +#endif /* CONFIGURE_HAS_OWN_CONFIGURATION_TABLE */ + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/sapi/include/rtems/config.h b/cpukit/sapi/include/rtems/config.h new file mode 100644 index 0000000000..29f6005f58 --- /dev/null +++ b/cpukit/sapi/include/rtems/config.h @@ -0,0 +1,94 @@ +/* config.h + * + * This include file contains the table of user defined configuration + * parameters. + * + * 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$ + */ + +#ifndef __RTEMS_CONFIGURATION_h +#define __RTEMS_CONFIGURATION_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/status.h> +#include <rtems/extension.h> +#include <rtems/io.h> +#include <rtems/score/mpci.h> +#include <rtems/rtems/types.h> +#include <rtems/rtems/tasks.h> + +/* + * The following records define the Multiprocessor Configuration + * Table. This table defines the multiprocessor system + * characteristics which must be known by RTEMS in a multiprocessor + * system. + */ + +typedef struct { + unsigned32 node; /* local node number */ + unsigned32 maximum_nodes; /* maximum # nodes in system */ + unsigned32 maximum_global_objects; /* maximum # global objects */ + unsigned32 maximum_proxies; /* maximum # proxies */ + MPCI_Control *User_mpci_table; /* pointer to MPCI table */ +} rtems_multiprocessing_table; + +/* + * The following records define the Configuration Table. The + * information contained in this table is required in all + * RTEMS systems, whether single or multiprocessor. This + * table primarily defines the following: + * + * + location and size of the RTEMS Workspace + * + required number of each object type + * + microseconds per clock tick + * + clock ticks per task timeslice + */ + +typedef struct { + void *work_space_start; + unsigned32 work_space_size; + unsigned32 maximum_tasks; + unsigned32 maximum_timers; + unsigned32 maximum_semaphores; + unsigned32 maximum_message_queues; + unsigned32 maximum_partitions; + unsigned32 maximum_regions; + unsigned32 maximum_ports; + unsigned32 maximum_periods; + unsigned32 maximum_extensions; + unsigned32 microseconds_per_tick; + unsigned32 ticks_per_timeslice; + unsigned32 number_of_initialization_tasks; + rtems_initialization_tasks_table *User_initialization_tasks_table; + unsigned32 number_of_device_drivers; + unsigned32 maximum_devices; + rtems_driver_address_table *Device_driver_table; + rtems_extensions_table *User_extension_table; + rtems_multiprocessing_table *User_multiprocessing_table; +} rtems_configuration_table; + +/* + * The following are provided strictly for the convenience of + * the user. They are not used in RTEMS itself. + */ + +EXTERN rtems_configuration_table *_Configuration_Table; +EXTERN rtems_multiprocessing_table *_Configuration_MP_table; + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/sapi/include/rtems/extension.h b/cpukit/sapi/include/rtems/extension.h new file mode 100644 index 0000000000..8f46ed80dd --- /dev/null +++ b/cpukit/sapi/include/rtems/extension.h @@ -0,0 +1,136 @@ +/* extension.h + * + * This include file contains all the constants, structures, and + * prototypes associated with the User Extension Manager. This manager + * provides a mechanism for manipulating sets of user-defined extensions. + * + * Directives provided are: + * + * + create user extension set + * + get ID of user extension set + * + delete user extension set + * + * 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$ + */ + +#ifndef __RTEMS_EXTENSION_MANAGER_h +#define __RTEMS_EXTENSION_MANAGER_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> +#include <rtems/score/userext.h> +#include <rtems/rtems/status.h> /* XXX */ +#include <rtems/rtems/types.h> /* XXX */ + +/* + * Extension related types + */ + +typedef User_extensions_routine rtems_extension; +typedef User_extensions_thread_create_extension rtems_task_create_extension; +typedef User_extensions_thread_delete_extension rtems_task_delete_extension; +typedef User_extensions_thread_start_extension rtems_task_start_extension; +typedef User_extensions_thread_restart_extension rtems_task_restart_extension; +typedef User_extensions_thread_switch_extension rtems_task_switch_extension; +typedef User_extensions_thread_begin_extension rtems_task_begin_extension; +typedef User_extensions_thread_exitted_extension rtems_task_exitted_extension; +typedef User_extensions_fatal_extension rtems_fatal_extension; + +typedef User_extensions_Table rtems_extensions_table; + +/* + * The following defines the information control block used to manage + * this class of objects. + */ + +EXTERN Objects_Information _Extension_Information; + +/* + * The following records define the control block used to manage + * each extension. + */ + +typedef struct { + Objects_Control Object; + User_extensions_Control Extension; +} Extension_Control; + +/* + * _Extension_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Extension_Manager_initialization( + unsigned32 maximum_extensions +); + +/* + * rtems_extension_create + * + * DESCRIPTION: + * + * This routine implements the rtems_extension_create directive. The + * extension will have the name name. The entry points of the + * routines which constitute this extension set are in EXTENSION_TABLE. + * It returns the id of the created extension in ID. + */ + +rtems_status_code rtems_extension_create( + rtems_name name, + rtems_extensions_table *extension_table, + Objects_Id *id +); + +/* + * rtems_extension_ident + * + * DESCRIPTION: + * + * This routine implements the rtems_extension_ident directive. + * This directive returns the extension ID associated with name. + * If more than one extension is named name, then the extension + * to which the ID belongs is arbitrary. + */ + +rtems_status_code rtems_extension_ident( + rtems_name name, + Objects_Id *id +); + +/* + * rtems_extension_delete + * + * DESCRIPTION: + * + * This routine implements the rtems_extension_delete directive. The + * extension indicated by ID is deleted. + */ + +rtems_status_code rtems_extension_delete( + Objects_Id id +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/extension.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/sapi/include/rtems/fatal.h b/cpukit/sapi/include/rtems/fatal.h new file mode 100644 index 0000000000..f61b4183f3 --- /dev/null +++ b/cpukit/sapi/include/rtems/fatal.h @@ -0,0 +1,49 @@ +/* fatal.h + * + * This include file contains constants and prototypes related + * to the Fatal Error Manager. This manager processes all fatal or + * irrecoverable errors. + * + * This manager provides directives to: + * + * + announce a fatal error has occurred + * + * + * 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$ + */ + +#ifndef __RTEMS_FATAL_h +#define __RTEMS_FATAL_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * rtems_fatal_error_occurred + * + * DESCRIPTION: + * + * This is the routine which implements the rtems_fatal_error_occurred + * directive. It is invoked when the application or RTEMS + * determines that a fatal error has occurred. + */ + +void volatile rtems_fatal_error_occurred( + unsigned32 the_error +); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/sapi/include/rtems/init.h b/cpukit/sapi/include/rtems/init.h new file mode 100644 index 0000000000..e008c45ebc --- /dev/null +++ b/cpukit/sapi/include/rtems/init.h @@ -0,0 +1,110 @@ +/* init.h + * + * This include file contains all the constants and structures associated + * with the Initialization Manager. This manager is responsible for + * initializing RTEMS, creating and starting all configured initialization + * tasks, invoking the initialization routine for each user-supplied device + * driver, and initializing the optional multiprocessor layer. + * + * This manager provides directives to: + * + * + initialize the RTEMS executive + * + shutdown the RTEMS executive + * + * + * 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$ + */ + +#ifndef __RTEMS_INIT_h +#define __RTEMS_INIT_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/types.h> +#include <rtems/config.h> +#include <rtems/rtems/intr.h> + +/* + * The following defines the default Multiprocessing Configuration + * Table. This table is used in a single processor system. + */ + +extern const rtems_multiprocessing_table + _Initialization_Default_multiprocessing_table; + +/* + * rtems_initialize_executive + * + * DESCRIPTION: + * + * This routine implements the rtems_initialize_executive directive. This + * directive is invoked at system startup to initialize the RTEMS + * multitasking environment. + */ + +void rtems_initialize_executive( + rtems_configuration_table *configuration_table, + rtems_cpu_table *cpu_table +); + +/* + * rtems_initialize_executive_early + * + * DESCRIPTION: + * + * This routine implements the early portion of rtems_initialize_executive + * directive up to the pretasking hook. This directive is invoked at system + * startup to initialize the RTEMS multitasking environment. + */ + +rtems_interrupt_level rtems_initialize_executive_early( + rtems_configuration_table *configuration_table, + rtems_cpu_table *cpu_table +); + +/* + * rtems_initialize_executive_late + * + * DESCRIPTION: + * + * This routine implements the early portion of rtems_initialize_executive + * directive up to the pretasking hook. This directive is invoked at system + * startup to initialize the RTEMS multitasking environment. + */ + +void rtems_initialize_executive_late( + rtems_interrupt_level bsp_level +); + +/* + * rtems_shutdown_executive + * + * DESCRIPTION: + * + * This routine implements the rtems_shutdown_executive directive. The + * invocation of this directive results in the RTEMS environment being + * shutdown and multitasking halted. From the application's perspective, + * invocation of this directive results in the rtems_initialize_executive + * directive exitting to the startup code which invoked it. + */ + +void rtems_shutdown_executive( + unsigned32 result +); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/sapi/include/rtems/io.h b/cpukit/sapi/include/rtems/io.h new file mode 100644 index 0000000000..a7af4df792 --- /dev/null +++ b/cpukit/sapi/include/rtems/io.h @@ -0,0 +1,244 @@ +/* io.h + * + * This include file contains all the constants and structures associated + * with the Input/Output Manager. This manager provides a well defined + * mechanism for accessing device drivers and a structured methodology for + * organizing device drivers. + * + * Directives provided are: + * + * + initialize a device driver + * + open a device driver + * + close a device driver + * + read from a device driver + * + write to a device driver + * + special device services + * + * 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$ + */ + +#ifndef __RTEMS_IO_h +#define __RTEMS_IO_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/rtems/status.h> + +/* + * + * The following defines the types for: + * + * + major and minor numbers + * + the return type of a device driver entry + * + a pointer to a device driver entry + * + an entry in the the Device Driver Address Table. Each entry in this + * table corresponds to an application provided device driver and + * defines the entry points for that device driver. + */ + +typedef unsigned32 rtems_device_major_number; +typedef unsigned32 rtems_device_minor_number; + +typedef rtems_status_code rtems_device_driver; + +typedef rtems_device_driver ( *rtems_device_driver_entry )( + rtems_device_major_number, + rtems_device_minor_number, + void * + ); + +typedef struct { + rtems_device_driver_entry initialization; /* initialization procedure */ + rtems_device_driver_entry open; /* open request procedure */ + rtems_device_driver_entry close; /* close request procedure */ + rtems_device_driver_entry read; /* read request procedure */ + rtems_device_driver_entry write; /* write request procedure */ + rtems_device_driver_entry control; /* special functions procedure */ +} rtems_driver_address_table; + +/* + * Table for the io device names + */ + +typedef struct { + char *device_name; + unsigned32 device_name_length; + rtems_device_major_number major; + rtems_device_minor_number minor; +} rtems_driver_name_t; + +/* + * This is the table of device names. + */ + +/* + * The following declare the data required to manage the Driver + * Address Table and Device Name Table. + */ + +EXTERN unsigned32 _IO_Number_of_drivers; +EXTERN rtems_driver_address_table *_IO_Driver_address_table; +EXTERN unsigned32 _IO_Number_of_devices; +EXTERN rtems_driver_name_t *_IO_Driver_name_table; + +/* + * _IO_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _IO_Manager_initialization( + rtems_driver_address_table *driver_table, + unsigned32 number_of_drivers, + unsigned32 number_of_devices +); + +/* + * rtems_io_register_name + * + * DESCRIPTION: + * + * Associate a name with a driver. + * + */ + +rtems_status_code rtems_io_register_name( + char *device_name, + rtems_device_major_number major, + rtems_device_minor_number minor +); + + +/* + * rtems_io_lookup_name + * + * DESCRIPTION: + * + * Find what driver "owns" this name + */ + +rtems_status_code rtems_io_lookup_name( + const char *name, + rtems_driver_name_t **device_info +); + + +/* + * rtems_io_initialize + * + * DESCRIPTION: + * + * This routine implements the rtems_io_initialize directive. It is invoked + * to initialize a device driver or an individual device. + */ + +rtems_status_code rtems_io_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +); + +/* + * rtems_io_open + * + * DESCRIPTION: + * + * This routine implements the rtems_io_open directive. It is invoked + * to open a device. + */ + +rtems_status_code rtems_io_open( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +); + +/* + * rtems_io_close + * + * DESCRIPTION: + * + * This routine implements the rtems_io_close directive. It is invoked + * to close a device. + */ + +rtems_status_code rtems_io_close( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +); + +/* + * rtems_io_read + * + * DESCRIPTION: + * + * This routine implements the rtems_io_read directive. It is invoked + * to read from a device. + */ + +rtems_status_code rtems_io_read( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +); + +/* + * rtems_io_write + * + * DESCRIPTION: + * + * This routine implements the rtems_io_write directive. It is invoked + * to write to a device. + */ + +rtems_status_code rtems_io_write( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +); + +/* + * rtems_io_control + * + * DESCRIPTION: + * + * This routine implements the rtems_io_control directive. It is invoked + * to perform a device specific operation on a device. + */ + +rtems_status_code rtems_io_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +); + +/* + * _IO_Initialize_all_drivers + * + * DESCRIPTION: + * + * This routine initializes all of the device drivers configured + * in the Device Driver Address Table. + */ + +void _IO_Initialize_all_drivers( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/sapi/include/rtems/mptables.h b/cpukit/sapi/include/rtems/mptables.h new file mode 100644 index 0000000000..b8e4c6de43 --- /dev/null +++ b/cpukit/sapi/include/rtems/mptables.h @@ -0,0 +1,29 @@ +/* mptables.h + * + * This include file contains the executive's pre-initialized tables + * used in a multiprocessor configuration. + * + * 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$ + */ + +#ifndef __RTEMS_MPTABLES_h +#define __RTEMS_MPTABLES_h + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/sapi/inline/rtems/extension.inl b/cpukit/sapi/inline/rtems/extension.inl new file mode 100644 index 0000000000..c7757ff280 --- /dev/null +++ b/cpukit/sapi/inline/rtems/extension.inl @@ -0,0 +1,91 @@ +/* extension.inl + * + * This file contains the static inline implementation of the inlined routines + * from the 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$ + */ + +#ifndef __EXTENSION_MANAGER_inl +#define __EXTENSION_MANAGER_inl + +/*PAGE + * + * _Extension_Allocate + * + * DESCRIPTION: + * + * This function allocates a extension control block from + * the inactive chain of free extension control blocks. + */ + +STATIC INLINE Extension_Control *_Extension_Allocate( void ) +{ + return (Extension_Control *) _Objects_Allocate( &_Extension_Information ); +} + +/*PAGE + * + * _Extension_Free + * + * DESCRIPTION: + * + * This routine frees a extension control block to the + * inactive chain of free extension control blocks. + */ + +STATIC INLINE void _Extension_Free ( + Extension_Control *the_extension +) +{ + _Objects_Free( &_Extension_Information, &the_extension->Object ); +} + +/*PAGE + * + * _Extension_Get + * + * DESCRIPTION: + * + * This function maps extension IDs to extension control blocks. + * If ID corresponds to a local extension, then it returns + * the extension control pointer which maps to ID and location + * is set to OBJECTS_LOCAL. Otherwise, location is set + * to OBJECTS_ERROR and the returned value is undefined. + */ + +STATIC INLINE Extension_Control *_Extension_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + return (Extension_Control *) + _Objects_Get( &_Extension_Information, id, location ); +} + +/*PAGE + * + * _Extension_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_extension is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _Extension_Is_null ( + Extension_Control *the_extension +) +{ + return ( the_extension == NULL ); +} + +#endif +/* end of include file */ diff --git a/cpukit/sapi/macros/rtems/extension.inl b/cpukit/sapi/macros/rtems/extension.inl new file mode 100644 index 0000000000..96fb9d1b3e --- /dev/null +++ b/cpukit/sapi/macros/rtems/extension.inl @@ -0,0 +1,58 @@ +/* extension.inl + * + * This file contains the macro implementation of the inlined routines + * from the 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$ + */ + +#ifndef __EXTENSION_inl +#define __EXTENSION_inl + +/*PAGE + * + * _Extension_Allocate + * + */ + +#define _Extension_Allocate() \ + (Extension_Control *) _Objects_Allocate( &_Extension_Information ) + +/*PAGE + * + * _Extension_Free + * + */ + +#define _Extension_Free( _the_extension ) \ + _Objects_Free( &_Extension_Information, &(_the_extension)->Object ) + +/*PAGE + * + * _Extension_Get + * + */ + +#define _Extension_Get( _id, _location ) \ + (Extension_Control *) \ + _Objects_Get( &_Extension_Information, (_id), (_location) ) + +/*PAGE + * + * _Extension_Is_null + * + */ + +#define _Extension_Is_null( _the_extension ) \ + ( (_the_extension) == NULL ) + +#endif +/* end of include file */ 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 <rtems/system.h> +#include <rtems/debug.h> + +/*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..2ffd9f4839 --- /dev/null +++ b/cpukit/sapi/src/exinit.c @@ -0,0 +1,285 @@ +/* + * 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 <rtems/system.h> +#include <rtems/config.h> +#include <rtems/debug.h> +#include <rtems/extension.h> +#include <rtems/fatal.h> +#include <rtems/init.h> +#include <rtems/io.h> +#include <rtems/score/sysstate.h> + +#include <rtems/score/apiext.h> +#include <rtems/score/copyrt.h> +#include <rtems/score/heap.h> +#include <rtems/score/interr.h> +#include <rtems/score/isr.h> +#include <rtems/score/mpci.h> +#include <rtems/score/priority.h> +#include <rtems/score/thread.h> +#include <rtems/score/tod.h> +#include <rtems/score/userext.h> +#include <rtems/score/watchdog.h> +#include <rtems/score/wkspace.h> + +#include <rtems/directives.h> +#include <rtems/sptables.h> + +#include <rtems/rtems/rtemsapi.h> + +/*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 + */ + +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 ); + + if ( cpu_table == NULL ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_NO_CONFIGURATION_TABLE + ); + + /* + * Initialize the system state based on whether this is an MP system. + */ + + multiprocessing_table = configuration_table->User_multiprocessing_table; + + _System_state_Handler_initialization( + (multiprocessing_table) ? TRUE : FALSE + ); + + /* + * Provided just for user convenience. + */ + + _Configuration_Table = configuration_table; + _Configuration_MP_table = multiprocessing_table; + + /* + * Internally we view single processor systems as a very restricted + * multiprocessor system. + */ + + if ( multiprocessing_table == NULL ) + multiprocessing_table = + (void *)&_Initialization_Default_multiprocessing_table; + + if ( cpu_table == NULL ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_NO_CPU_TABLE + ); + + _CPU_Initialize( cpu_table, _Thread_Dispatch ); + + /* + * Do this as early as possible to insure no debugging output + * is even attempted to be printed. + */ + + _Debug_Manager_initialization(); + + _API_extensions_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_nodes, + multiprocessing_table->maximum_global_objects + ); + + _Priority_Handler_initialization(); + + _Watchdog_Handler_initialization(); + + _TOD_Handler_initialization( configuration_table->microseconds_per_tick ); + + _Thread_Handler_initialization( + configuration_table->ticks_per_timeslice, + configuration_table->maximum_extensions, + multiprocessing_table->maximum_proxies + ); + + _MPCI_Handler_initialization( + multiprocessing_table->User_mpci_table, + RTEMS_TIMEOUT + ); + +/* MANAGERS */ + + _Extension_Manager_initialization( configuration_table->maximum_extensions ); + + _IO_Manager_initialization( + configuration_table->Device_driver_table, + configuration_table->number_of_device_drivers, + configuration_table->maximum_devices + ); + + _RTEMS_API_Initialize( configuration_table ); + + _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING ); + + if ( cpu_table->pretasking_hook ) + (*cpu_table->pretasking_hook)(); + + /* + * No threads should be created before this point!!! + * + * At this point all API extensions are in place. After the call to + * _Thread_Create_idle() _Thread_Executing will be set. + * and _Thread_Heir are not set yet. + */ + + _Thread_Create_idle(); + + _MPCI_Create_server(); + + /* + * Run the API and BSPs predriver hook. + */ + + _API_extensions_Run_predriver(); + + if ( _CPU_Table.predriver_hook ) + (*_CPU_Table.predriver_hook)(); + + /* + * Initialize all the device drivers and initialize the MPCI layer. + * + * NOTE: The MPCI may be build upon a device driver. + */ + + _IO_Initialize_all_drivers(); + + if ( _System_state_Is_multiprocessing ) { + _MPCI_Initialization(); + _MPCI_Internal_packets_Send_process_packet( + MPCI_PACKETS_SYSTEM_VERIFY + ); + } + + /* + * Run the APIs and BSPs postdriver hooks. + * + * The API extensions are supposed to create user initialization tasks. + */ + + _API_extensions_Run_postdriver(); + + if ( _CPU_Table.postdriver_hook ) + (*_CPU_Table.postdriver_hook)(); + + return bsp_level; +} + +void rtems_initialize_executive_late( + rtems_interrupt_level bsp_level +) +{ + + _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING ); + + _Thread_Start_multitasking(); + + /* + * 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..6df116bc69 --- /dev/null +++ b/cpukit/sapi/src/extension.c @@ -0,0 +1,165 @@ +/* + * 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 <rtems/system.h> +#include <rtems/rtems/support.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/extension.h> + +/*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, + OBJECTS_RTEMS_EXTENSIONS, + FALSE, + maximum_extensions, + sizeof( Extension_Control ), + FALSE, + RTEMS_MAXIMUM_NAME_LENGTH, + FALSE + ); +} + +/*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( + rtems_name name, + rtems_extensions_table *extension_table, + Objects_Id *id +) +{ + Extension_Control *the_extension; + + if ( !rtems_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( + rtems_name name, + Objects_Id *id +) +{ + Objects_Name_to_id_errors status; + + status = _Objects_Name_to_id( + &_Extension_Information, + &name, + OBJECTS_SEARCH_LOCAL_NODE, + id + ); + + return _Status_Object_name_errors_to_status[ status ]; +} + +/*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..b2599e3ae2 --- /dev/null +++ b/cpukit/sapi/src/fatal.c @@ -0,0 +1,38 @@ +/* + * 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 <rtems/system.h> +#include <rtems/fatal.h> +#include <rtems/score/interr.h> + +/*PAGE + * + * rtems_fatal_error_occurred + * + * This directive will invoke the internal fatal error handler. + * + * Input parameters: + * the_error - fatal error status code + * + * Output parameters: NONE + */ + +void volatile rtems_fatal_error_occurred( + unsigned32 the_error +) +{ + _Internal_error_Occurred( INTERNAL_ERROR_RTEMS_API, FALSE, 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..b326a96987 --- /dev/null +++ b/cpukit/sapi/src/io.c @@ -0,0 +1,345 @@ +/* + * 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 <rtems/system.h> +#include <rtems/io.h> +#include <rtems/score/isr.h> +#include <rtems/score/thread.h> +#include <rtems/score/wkspace.h> + +#include <string.h> + +/*PAGE + * + * _IO_Manager_initialization + * + */ + +void _IO_Manager_initialization( + rtems_driver_address_table *driver_table, + unsigned32 number_of_drivers, + unsigned32 number_of_devices +) +{ + void *tmp; + unsigned32 index; + rtems_driver_name_t *np; + + _IO_Driver_address_table = driver_table; + _IO_Number_of_drivers = number_of_drivers; + _IO_Number_of_devices = number_of_devices; + + tmp = _Workspace_Allocate_or_fatal_error( + sizeof( rtems_driver_name_t ) * ( number_of_devices + 1 ) + ); + + _IO_Driver_name_table = (rtems_driver_name_t *) tmp; + + for( index=0, np = _IO_Driver_name_table ; + index < _IO_Number_of_devices ; + index++, np++ ) { + np->device_name = 0; + np->device_name_length = 0; + np->major = 0; + np->minor = 0; + } +} + +/*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; + + for ( major=0 ; major < _IO_Number_of_drivers ; major ++ ) + (void) rtems_io_initialize( major, 0, NULL); +} + +/*PAGE + * + * rtems_io_register_name + * + * Associate a name with a driver + * + * Input Paramters: + * device_name - pointer to name string to associate with device + * major - device major number to receive name + * minor - device minor number to receive name + * + * Output Parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_io_register_name( + char *device_name, + rtems_device_major_number major, + rtems_device_minor_number minor + ) +{ + rtems_driver_name_t *np; + unsigned32 level; + unsigned32 index; + + /* find an empty slot */ + for( index=0, np = _IO_Driver_name_table ; + index < _IO_Number_of_devices ; + index++, np++ ) + { + + _ISR_Disable(level); + if (np->device_name == 0) + { + np->device_name = device_name; + np->device_name_length = strlen(device_name); + np->major = major; + np->minor = minor; + _ISR_Enable(level); + + return RTEMS_SUCCESSFUL; + } + _ISR_Enable(level); + } + + return RTEMS_TOO_MANY; +} + +/*PAGE + * + * rtems_io_lookup_name + * + * Find what driver "owns" this name + * + * Input Paramters: + * name - name to lookup the associated device + * + * Output Parameters: + * device_info - device associate with name + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +rtems_status_code rtems_io_lookup_name( + const char *name, + rtems_driver_name_t **device_info +) +{ + rtems_driver_name_t *np; + unsigned32 index; + + for( index=0, np = _IO_Driver_name_table ; + index < _IO_Number_of_devices ; + index++, np++ ) + if (np->device_name) + if (strncmp(np->device_name, name, np->device_name_length) == 0) + { + *device_info = np; + return RTEMS_SUCCESSFUL; + } + + *device_info = 0; + return RTEMS_UNSATISFIED; +} + + +/*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) + * + * Output Parameters: + * returns - return code + */ + +rtems_status_code rtems_io_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +) +{ + rtems_device_driver_entry callout; + + if ( major >= _IO_Number_of_drivers ) + return RTEMS_INVALID_NUMBER; + + callout = _IO_Driver_address_table[major].initialization; + return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL; +} + +/*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) + * + * Output Parameters: + * returns - return code + */ + +rtems_status_code rtems_io_open( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +) +{ + rtems_device_driver_entry callout; + + if ( major >= _IO_Number_of_drivers ) + return RTEMS_INVALID_NUMBER; + + callout = _IO_Driver_address_table[major].open; + return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL; +} + +/*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) + * + * Output Parameters: + * returns - return code + */ + +rtems_status_code rtems_io_close( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +) +{ + rtems_device_driver_entry callout; + + if ( major >= _IO_Number_of_drivers ) + return RTEMS_INVALID_NUMBER; + + callout = _IO_Driver_address_table[major].close; + return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL; +} + +/*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) + * + * Output Parameters: + * returns - return code + */ + +rtems_status_code rtems_io_read( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +) +{ + rtems_device_driver_entry callout; + + if ( major >= _IO_Number_of_drivers ) + return RTEMS_INVALID_NUMBER; + + callout = _IO_Driver_address_table[major].read; + return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL; +} + +/*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) + * + * Output Parameters: + * returns - return code + */ + +rtems_status_code rtems_io_write( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +) +{ + rtems_device_driver_entry callout; + + if ( major >= _IO_Number_of_drivers ) + return RTEMS_INVALID_NUMBER; + + callout = _IO_Driver_address_table[major].write; + return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL; +} + +/*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) + * + * Output Parameters: + * returns - return code + */ + +rtems_status_code rtems_io_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *argument +) +{ + rtems_device_driver_entry callout; + + if ( major >= _IO_Number_of_drivers ) + return RTEMS_INVALID_NUMBER; + + callout = _IO_Driver_address_table[major].control; + return callout ? callout(major, minor, argument) : RTEMS_SUCCESSFUL; +} + diff --git a/cpukit/sapi/src/rtemsapi.c b/cpukit/sapi/src/rtemsapi.c new file mode 100644 index 0000000000..b6ecb6c37c --- /dev/null +++ b/cpukit/sapi/src/rtemsapi.c @@ -0,0 +1,89 @@ +/* + * RTEMS API Support + * + * NOTE: + * + * 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/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/rtemsapi.h> + +#define INIT + +#include <rtems/rtems/intr.h> +#include <rtems/rtems/clock.h> +#include <rtems/rtems/tasks.h> +#include <rtems/rtems/dpmem.h> +#include <rtems/rtems/event.h> +#include <rtems/rtems/message.h> +#include <rtems/rtems/mp.h> +#include <rtems/rtems/part.h> +#include <rtems/rtems/ratemon.h> +#include <rtems/rtems/region.h> +#include <rtems/rtems/sem.h> +#include <rtems/rtems/signal.h> +#include <rtems/rtems/timer.h> + +/*PAGE + * + * _RTEMS_API_Initialize + * + * XXX + */ + +void _RTEMS_API_Initialize( + rtems_configuration_table *configuration_table +) +{ + _Attributes_Handler_initialization(); + + _Interrupt_Manager_initialization(); + + _Multiprocessing_Manager_initialization(); + + _RTEMS_tasks_Manager_initialization( + configuration_table->maximum_tasks, + configuration_table->number_of_initialization_tasks, + configuration_table->User_initialization_tasks_table + ); + + _Timer_Manager_initialization( configuration_table->maximum_timers ); + + _Signal_Manager_initialization(); + + _Event_Manager_initialization(); + + _Message_queue_Manager_initialization( + configuration_table->maximum_message_queues + ); + + _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 + ); +} + +/* end of file */ diff --git a/cpukit/score/cpu/hppa1.1/cpu.c b/cpukit/score/cpu/hppa1.1/cpu.c new file mode 100644 index 0000000000..89bb8a8447 --- /dev/null +++ b/cpukit/score/cpu/hppa1.1/cpu.c @@ -0,0 +1,189 @@ +/* + * HP PA-RISC Dependent Source + * + * COPYRIGHT (c) 1994 by Division Incorporated + * + * To anyone who acknowledges that this file is provided "AS IS" + * without any express or implied warranty: + * permission to use, copy, modify, and distribute this file + * for any purpose is hereby granted without fee, provided that + * the above copyright notice and this notice appears in all + * copies, and that the name of Division Incorporated not be + * used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * Division Incorporated makes no representations about the + * suitability of this software for any purpose. + * + * $Id$ + */ + +#include <rtems/system.h> +#include <rtems/score/isr.h> +void hppa_cpu_halt(unsigned32 the_error); + + +/*PAGE + * + * _CPU_ISR_install_raw_handler + */ + +void _CPU_ISR_install_raw_handler( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + /* + * This is unsupported. For HPPA this function is handled by BSP + */ + + _CPU_Fatal_halt( 0xdeaddead ); +} + + + +/* + * This is the default handler which is called if + * _CPU_ISR_install_vector() has not been called for the + * specified vector. It simply forwards onto the spurious + * handler defined in the cpu-table. + */ + +static ISR_Handler +hppa_interrupt_report_spurious(ISR_Vector_number vector, + void* rtems_isr_frame) /* HPPA extension */ +{ + + /* + * If the CPU table defines a spurious_handler, then + * call it. If the handler returns halt. + */ + if ( _CPU_Table.spurious_handler ) + _CPU_Table.spurious_handler(vector, rtems_isr_frame); + + hppa_cpu_halt(vector); +} + + +/*PAGE + * + * _CPU_ISR_Get_level + */ + +unsigned32 _CPU_ISR_Get_level(void) +{ + int level; + HPPA_ASM_SSM(0, level); /* change no bits; just get copy */ + if (level & HPPA_PSW_I) + return 0; + return 1; +} + +/*PAGE + * + * _CPU_ISR_install_vector + * + * This kernel routine installs the RTEMS handler for the + * specified vector. The handler is a C callable routine. + * + * Input parameters: + * vector - interrupt vector number + * old_handler - former ISR for this vector number + * new_handler - replacement ISR for this vector number + * + * Output parameters: NONE + * + */ + +void _CPU_ISR_install_vector( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + *old_handler = _ISR_Vector_table[vector]; + + _ISR_Vector_table[vector] = new_handler; +} + +/* _CPU_Initialize + * + * This routine performs processor dependent initialization. + * + * INPUT PARAMETERS: + * cpu_table - CPU table to initialize + * thread_dispatch - address of disptaching routine + * + */ + +void _CPU_Initialize( + rtems_cpu_table *cpu_table, + void (*thread_dispatch) /* ignored on this CPU */ +) +{ + register unsigned8 *fp_context; + int i; + proc_ptr old_handler; + + /* + * XXX; need to setup fpsr smarter perhaps + */ + + fp_context = (unsigned8*) &_CPU_Null_fp_context; + for (i=0 ; i<sizeof(Context_Control_fp); i++) + *fp_context++ = 0; + + /* + * Set _CPU_Default_gr27 here so it will hopefully be the correct + * global data pointer for the entire system. + */ + + asm volatile( "stw %%r27,%0" : "=m" (_CPU_Default_gr27): ); + + /* + * Init the 2nd level interrupt handlers + */ + + for (i=0; i < CPU_INTERRUPT_NUMBER_OF_VECTORS; i++) + _CPU_ISR_install_vector(i, + hppa_interrupt_report_spurious, + &old_handler); + + _CPU_Table = *cpu_table; + +} + + +/* + * Halt the system. + * Called by the _CPU_Fatal_halt macro + * + * XXX + * Later on, this will allow us to return to the prom. + * For now, we just ignore 'type_of_halt' + * + * XXX + * NOTE: for gcc, this function must be at the bottom + * of the file, that is because if it is at the top + * of the file, gcc will inline it's calls. Since + * the function uses the HPPA_ASM_LABEL() macro, when + * gcc inlines it, you get two definitions of the same + * label name, which is an assembly error. + */ + + +void +hppa_cpu_halt(unsigned32 the_error) +{ + unsigned32 isrlevel; + + _CPU_ISR_Disable(isrlevel); + + /* + * XXXXX NOTE: This label is only needed that that when + * the simulator stops, it shows the label name specified + */ + HPPA_ASM_LABEL("_hppa_cpu_halt"); + HPPA_ASM_BREAK(0, 0); +} + diff --git a/cpukit/score/cpu/i386/asm.h b/cpukit/score/cpu/i386/asm.h new file mode 100644 index 0000000000..e317161043 --- /dev/null +++ b/cpukit/score/cpu/i386/asm.h @@ -0,0 +1,140 @@ +/* asm.h + * + * This include file attempts to address the problems + * caused by incompatible flavors of assemblers and + * toolsets. It primarily addresses variations in the + * use of leading underscores on symbols and the requirement + * that register names be preceded by a %. + * + * + * NOTE: The spacing in the use of these macros + * is critical to them working as advertised. + * + * COPYRIGHT: + * + * This file is based on similar code found in newlib available + * from ftp.cygnus.com. The file which was used had no copyright + * notice. This file is freely distributable as long as the source + * of the file is noted. This file is: + * + * COPYRIGHT (c) 1994. + * On-Line Applications Research Corporation (OAR). + * + * $Id$ + */ + +#ifndef __i386_ASM_h +#define __i386_ASM_h + +/* + * Indicate we are in an assembly file and get the basic CPU definitions. + */ + +#define ASM +#include <rtems/score/i386.h> + +/* + * Recent versions of GNU cpp define variables which indicate the + * need for underscores and percents. If not using GNU cpp or + * the version does not support this, then you will obviously + * have to define these as appropriate. + */ + +/* + * Go32 suffers the same bug as __REGISTER_PREFIX__ + */ + +#if __GO32__ +#undef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +/* + * Looks like there is a bug in gcc 2.6.2 where this is not + * defined correctly when configured as i386-coff and + * i386-aout. + */ + +#undef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ % + +/* +#ifndef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ +#endif +*/ + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a ## b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) + +#define eax REG (eax) +#define ebx REG (ebx) +#define ecx REG (ecx) +#define edx REG (edx) +#define esi REG (esi) +#define edi REG (edi) +#define esp REG (esp) +#define ebp REG (ebp) + +#define ax REG (ax) +#define bx REG (bx) +#define cx REG (cx) +#define dx REG (dx) +#define si REG (si) +#define di REG (di) +#define sp REG (sp) +#define bp REG (bp) + +#define ah REG (ah) +#define al REG (al) + +#define cs REG (cs) +#define ds REG (ds) +#define es REG (es) +#define fs REG (fs) +#define gs REG (gs) +#define ss REG (ss) + +/* + * Define macros to handle section beginning and ends. + */ + + +#define BEGIN_CODE_DCL .text +#define END_CODE_DCL +#define BEGIN_DATA_DCL .data +#define END_DATA_DCL +#define BEGIN_CODE .text +#define END_CODE +#define BEGIN_DATA +#define END_DATA +#define BEGIN_BSS +#define END_BSS +#define END + +/* + * Following must be tailor for a particular flavor of the C compiler. + * They may need to put underscores in front of the symbols. + */ + +#define PUBLIC(sym) .globl SYM (sym) +#define EXTERN(sym) .globl SYM (sym) + +#endif +/* end of include file */ + + diff --git a/cpukit/score/cpu/i386/cpu.c b/cpukit/score/cpu/i386/cpu.c new file mode 100644 index 0000000000..ad9c56e20a --- /dev/null +++ b/cpukit/score/cpu/i386/cpu.c @@ -0,0 +1,177 @@ +/* + * Intel i386 Dependent Source + * + * + * 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/system.h> +#include <rtems/score/isr.h> + +/* _CPU_Initialize + * + * This routine performs processor dependent initialization. + * + * INPUT PARAMETERS: + * cpu_table - CPU table to initialize + * thread_dispatch - address of disptaching routine + */ + + +void _CPU_Initialize( + rtems_cpu_table *cpu_table, + void (*thread_dispatch) /* ignored on this CPU */ +) +{ + register unsigned16 fp_status asm ("ax"); + register void *fp_context; + + _CPU_Table = *cpu_table; + + /* + * The following code saves a NULL i387 context which is given + * to each task at start and restart time. The following code + * is based upon that provided in the i386 Programmer's + * Manual and should work on any coprocessor greater than + * the i80287. + * + * NOTE: The NO RTEMS_WAIT form of the coprocessor instructions + * MUST be used in case there is not a coprocessor + * to wait for. + */ + + fp_status = 0xa5a5; + asm volatile( "fninit" ); + asm volatile( "fnstsw %0" : "=a" (fp_status) : "0" (fp_status) ); + + if ( fp_status == 0 ) { + + fp_context = &_CPU_Null_fp_context; + + asm volatile( "fsave (%0)" : "=r" (fp_context) + : "0" (fp_context) + ); + } +} + +/*PAGE + * + * _CPU_ISR_Get_level + */ + +unsigned32 _CPU_ISR_Get_level( void ) +{ + unsigned32 level; + + i386_get_interrupt_level( level ); + + return level; +} + +/*PAGE + * + * _CPU_ISR_install_raw_handler + */ + +#if __GO32__ +#include <go32.h> +#include <dpmi.h> +#endif /* __GO32__ */ + +void _CPU_ISR_install_raw_handler( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ +#if __GO32__ + _go32_dpmi_seginfo handler_info; + + /* get the address of the old handler */ + _go32_dpmi_get_protected_mode_interrupt_vector( vector, &handler_info); + + /* Notice how we're failing to save the pm_segment portion of the */ + /* structure here? That means we might crash the system if we */ + /* try to restore the ISR. Can't fix this until i386_isr is */ + /* redefined. XXX [BHC]. */ + *old_handler = (proc_ptr *) handler_info.pm_offset; + + handler_info.pm_offset = (u_long) new_handler; + handler_info.pm_selector = _go32_my_cs(); + + /* install the IDT entry */ + _go32_dpmi_set_protected_mode_interrupt_vector( vector, &handler_info ); +#else + i386_IDT_slot idt; + unsigned32 handler; + + *old_handler = 0; /* XXX not supported */ + + handler = (unsigned32) new_handler; + + /* build the IDT entry */ + idt.offset_0_15 = handler & 0xffff; + idt.segment_selector = i386_get_cs(); + idt.reserved = 0x00; + idt.p_dpl = 0x8e; /* present, ISR */ + idt.offset_16_31 = handler >> 16; + + /* install the IDT entry */ + i386_Install_idt( + (unsigned32) &idt, + _CPU_Table.interrupt_table_segment, + (unsigned32) _CPU_Table.interrupt_table_offset + (8 * vector) + ); +#endif +} + +/*PAGE + * + * _CPU_ISR_install_vector + * + * This kernel routine installs the RTEMS handler for the + * specified vector. + * + * Input parameters: + * vector - interrupt vector number + * old_handler - former ISR for this vector number + * new_handler - replacement ISR for this vector number + * + * Output parameters: NONE + * + */ + +void _ISR_Handler_0(), _ISR_Handler_1(); + +#define PER_ISR_ENTRY \ + (((unsigned32) _ISR_Handler_1 - (unsigned32) _ISR_Handler_0)) + +#define _Interrupt_Handler_entry( _vector ) \ + (((unsigned32)_ISR_Handler_0) + ((_vector) * PER_ISR_ENTRY)) + +void _CPU_ISR_install_vector( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + proc_ptr ignored; + unsigned32 unique_handler; + + *old_handler = _ISR_Vector_table[ vector ]; + + /* calculate the unique entry point for this vector */ + unique_handler = _Interrupt_Handler_entry( vector ); + + _CPU_ISR_install_raw_handler( vector, (void *)unique_handler, &ignored ); + + _ISR_Vector_table[ vector ] = new_handler; +} diff --git a/cpukit/score/cpu/i386/rtems/asm.h b/cpukit/score/cpu/i386/rtems/asm.h new file mode 100644 index 0000000000..e317161043 --- /dev/null +++ b/cpukit/score/cpu/i386/rtems/asm.h @@ -0,0 +1,140 @@ +/* asm.h + * + * This include file attempts to address the problems + * caused by incompatible flavors of assemblers and + * toolsets. It primarily addresses variations in the + * use of leading underscores on symbols and the requirement + * that register names be preceded by a %. + * + * + * NOTE: The spacing in the use of these macros + * is critical to them working as advertised. + * + * COPYRIGHT: + * + * This file is based on similar code found in newlib available + * from ftp.cygnus.com. The file which was used had no copyright + * notice. This file is freely distributable as long as the source + * of the file is noted. This file is: + * + * COPYRIGHT (c) 1994. + * On-Line Applications Research Corporation (OAR). + * + * $Id$ + */ + +#ifndef __i386_ASM_h +#define __i386_ASM_h + +/* + * Indicate we are in an assembly file and get the basic CPU definitions. + */ + +#define ASM +#include <rtems/score/i386.h> + +/* + * Recent versions of GNU cpp define variables which indicate the + * need for underscores and percents. If not using GNU cpp or + * the version does not support this, then you will obviously + * have to define these as appropriate. + */ + +/* + * Go32 suffers the same bug as __REGISTER_PREFIX__ + */ + +#if __GO32__ +#undef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +/* + * Looks like there is a bug in gcc 2.6.2 where this is not + * defined correctly when configured as i386-coff and + * i386-aout. + */ + +#undef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ % + +/* +#ifndef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ +#endif +*/ + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a ## b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) + +#define eax REG (eax) +#define ebx REG (ebx) +#define ecx REG (ecx) +#define edx REG (edx) +#define esi REG (esi) +#define edi REG (edi) +#define esp REG (esp) +#define ebp REG (ebp) + +#define ax REG (ax) +#define bx REG (bx) +#define cx REG (cx) +#define dx REG (dx) +#define si REG (si) +#define di REG (di) +#define sp REG (sp) +#define bp REG (bp) + +#define ah REG (ah) +#define al REG (al) + +#define cs REG (cs) +#define ds REG (ds) +#define es REG (es) +#define fs REG (fs) +#define gs REG (gs) +#define ss REG (ss) + +/* + * Define macros to handle section beginning and ends. + */ + + +#define BEGIN_CODE_DCL .text +#define END_CODE_DCL +#define BEGIN_DATA_DCL .data +#define END_DATA_DCL +#define BEGIN_CODE .text +#define END_CODE +#define BEGIN_DATA +#define END_DATA +#define BEGIN_BSS +#define END_BSS +#define END + +/* + * Following must be tailor for a particular flavor of the C compiler. + * They may need to put underscores in front of the symbols. + */ + +#define PUBLIC(sym) .globl SYM (sym) +#define EXTERN(sym) .globl SYM (sym) + +#endif +/* end of include file */ + + diff --git a/cpukit/score/cpu/i960/asm.h b/cpukit/score/cpu/i960/asm.h new file mode 100644 index 0000000000..803f42f649 --- /dev/null +++ b/cpukit/score/cpu/i960/asm.h @@ -0,0 +1,107 @@ +/* asm.h + * + * This include file attempts to address the problems + * caused by incompatible flavors of assemblers and + * toolsets. It primarily addresses variations in the + * use of leading underscores on symbols and the requirement + * that register names be preceded by a %. + * + * + * NOTE: The spacing in the use of these macros + * is critical to them working as advertised. + * + * COPYRIGHT: + * + * This file is based on similar code found in newlib available + * from ftp.cygnus.com. The file which was used had no copyright + * notice. This file is freely distributable as long as the source + * of the file is noted. This file is: + * + * COPYRIGHT (c) 1994. + * On-Line Applications Research Corporation (OAR). + * + * $Id$ + */ + +#ifndef __i960_ASM_h +#define __i960_ASM_h + +/* + * Indicate we are in an assembly file and get the basic CPU definitions. + */ + +#define ASM +#include <rtems/score/i960.h> + +/* + * Recent versions of GNU cpp define variables which indicate the + * need for underscores and percents. If not using GNU cpp or + * the version does not support this, then you will obviously + * have to define these as appropriate. + */ + +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#ifndef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ +#endif + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a ## b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) + +#define g0 REG (g0) +#define g1 REG (g1) +#define g2 REG (g2) +#define g3 REG (g3) +#define g4 REG (g4) +#define g5 REG (g5) +#define g6 REG (g6) +#define g7 REG (g7) +#define g8 REG (g8) +#define g9 REG (g9) +#define g10 REG (g10) +#define g11 REG (g11) +#define g12 REG (g12) +#define g13 REG (g13) +#define g14 REG (g14) +#define g15 REG (g15) + +/* + * Define macros to handle section beginning and ends. + */ + + +#define BEGIN_CODE_DCL .text +#define END_CODE_DCL +#define BEGIN_DATA_DCL .data +#define END_DATA_DCL +#define BEGIN_CODE .text +#define END_CODE +#define BEGIN_DATA +#define END_DATA +#define BEGIN_BSS +#define END_BSS +#define END + +/* + * Following must be tailor for a particular flavor of the C compiler. + * They may need to put underscores in front of the symbols. + */ + +#define PUBLIC(sym) .globl SYM (sym) +#define EXTERN(sym) .globl SYM (sym) + +#endif +/* end of include file */ diff --git a/cpukit/score/cpu/i960/cpu.c b/cpukit/score/cpu/i960/cpu.c new file mode 100644 index 0000000000..e55a400c40 --- /dev/null +++ b/cpukit/score/cpu/i960/cpu.c @@ -0,0 +1,155 @@ +/* + * Intel i960CA Dependent Source + * + * + * 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$ + */ + +#if defined(__i960CA__) || defined(__i960_CA__) || defined(__i960CA) +#else +#warning "*** ENTIRE FILE IMPLEMENTED & TESTED FOR CA ONLY ***" +#warning "*** THIS FILE WILL NOT COMPILE ON ANOTHER FAMILY MEMBER ***" +#endif + +#include <rtems/system.h> +#include <rtems/score/isr.h> + +/* _CPU_Initialize + * + * This routine performs processor dependent initialization. + * + * INPUT PARAMETERS: + * cpu_table - CPU table to initialize + * thread_dispatch - address of disptaching routine + * + * OUTPUT PARAMETERS: NONE + */ + +void _CPU_Initialize( + rtems_cpu_table *cpu_table, + void (*thread_dispatch) /* ignored on this CPU */ +) +{ + + _CPU_Table = *cpu_table; + +} + +/*PAGE + * + * _CPU_ISR_Get_level + */ + +unsigned32 _CPU_ISR_Get_level( void ) +{ + unsigned32 level; + + i960_get_interrupt_level( level ); + + return level; +} + +/*PAGE + * + * _CPU_ISR_install_raw_handler + */ + +#define _Is_vector_caching_enabled( _prcb ) \ + ((_prcb)->control_tbl->icon & 0x2000) + +void _CPU_ISR_install_raw_handler( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + i960ca_PRCB *prcb = _CPU_Table.Prcb; + proc_ptr *cached_intr_tbl = NULL; + + /* The i80960CA does not support vectors 0-7. The first 9 entries + * in the Interrupt Table are used to manage pending interrupts. + * Thus vector 8, the first valid vector number, is actually in + * slot 9 in the table. + */ + + *old_handler = prcb->intr_tbl[ vector + 1 ]; + + prcb->intr_tbl[ vector + 1 ] = new_handler; + + if ( _Is_vector_caching_enabled( prcb ) ) + if ( (vector & 0xf) == 0x2 ) /* cacheable? */ + cached_intr_tbl[ vector >> 4 ] = new_handler; +} + +/*PAGE + * + * _CPU__ISR_install_vector + * + * Install the RTEMS vector wrapper in the CPU's interrupt table. + * + * Input parameters: + * vector - interrupt vector number + * old_handler - former ISR for this vector number + * new_handler - replacement ISR for this vector number + * + * Output parameters: NONE + * + */ + +void _CPU_ISR_install_vector( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + proc_ptr ignored; + + *old_handler = _ISR_Vector_table[ vector ]; + + _CPU_ISR_install_raw_handler( vector, _ISR_Handler, &ignored ); + + _ISR_Vector_table[ vector ] = new_handler; +} + +/*PAGE + * + * _CPU_Install_interrupt_stack + */ + +#define soft_reset( prcb ) \ + { register i960ca_PRCB *_prcb = (prcb); \ + register unsigned32 *_next=0; \ + register unsigned32 _cmd = 0x30000; \ + asm volatile( "lda next,%1; \ + sysctl %0,%1,%2; \ + next: mov g0,g0" \ + : "=d" (_cmd), "=d" (_next), "=d" (_prcb) \ + : "0" (_cmd), "1" (_next), "2" (_prcb) ); \ + } + +void _CPU_Install_interrupt_stack( void ) +{ + i960ca_PRCB *prcb = _CPU_Table.Prcb; + unsigned32 level; + + /* + * Set the Interrupt Stack in the PRCB and force a reload of it. + * Interrupts are disabled for safety. + */ + + _CPU_ISR_Disable( level ); + + prcb->intr_stack = _CPU_Interrupt_stack_low; + + soft_reset( prcb ); + + _CPU_ISR_Enable( level ); +} diff --git a/cpukit/score/cpu/m68k/asm.h b/cpukit/score/cpu/m68k/asm.h new file mode 100644 index 0000000000..4c53980d51 --- /dev/null +++ b/cpukit/score/cpu/m68k/asm.h @@ -0,0 +1,129 @@ +/* asm.h + * + * This include file attempts to address the problems + * caused by incompatible flavors of assemblers and + * toolsets. It primarily addresses variations in the + * use of leading underscores on symbols and the requirement + * that register names be preceded by a %. + * + * + * NOTE: The spacing in the use of these macros + * is critical to them working as advertised. + * + * COPYRIGHT: + * + * This file is based on similar code found in newlib available + * from ftp.cygnus.com. The file which was used had no copyright + * notice. This file is freely distributable as long as the source + * of the file is noted. This file is: + * + * COPYRIGHT (c) 1994. + * On-Line Applications Research Corporation (OAR). + * + * $Id$ + */ + +#ifndef __M68k_ASM_h +#define __M68k_ASM_h + +/* + * Indicate we are in an assembly file and get the basic CPU definitions. + */ + +#define ASM +#include <rtems/score/m68k.h> + +/* + * Recent versions of GNU cpp define variables which indicate the + * need for underscores and percents. If not using GNU cpp or + * the version does not support this, then you will obviously + * have to define these as appropriate. + */ + +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#ifndef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ +#endif + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a ## b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) + +#define d0 REG (d0) +#define d1 REG (d1) +#define d2 REG (d2) +#define d3 REG (d3) +#define d4 REG (d4) +#define d5 REG (d5) +#define d6 REG (d6) +#define d7 REG (d7) +#define a0 REG (a0) +#define a1 REG (a1) +#define a2 REG (a2) +#define a3 REG (a3) +#define a4 REG (a4) +#define a5 REG (a5) +#define a6 REG (a6) +#define a7 REG (a7) + +#define msp REG (msp) +#define usp REG (usp) +#define isp REG (isp) +#define sr REG (sr) +#define vbr REG (vbr) +#define dfc REG (dfc) + +#define fp0 REG (fp0) +#define fp1 REG (fp1) +#define fp2 REG (fp2) +#define fp3 REG (fp3) +#define fp4 REG (fp4) +#define fp5 REG (fp5) +#define fp6 REG (fp6) +#define fp7 REG (fp7) + +#define fpc REG (fpc) +#define fpi REG (fpi) +#define fps REG (fps) + +/* + * Define macros to handle section beginning and ends. + */ + + +#define BEGIN_CODE_DCL .text +#define END_CODE_DCL +#define BEGIN_DATA_DCL .data +#define END_DATA_DCL +#define BEGIN_CODE .text +#define END_CODE +#define BEGIN_DATA +#define END_DATA +#define BEGIN_BSS +#define END_BSS +#define END + +/* + * Following must be tailor for a particular flavor of the C compiler. + * They may need to put underscores in front of the symbols. + */ + +#define PUBLIC(sym) .globl SYM (sym) +#define EXTERN(sym) .globl SYM (sym) + +#endif +/* end of include file */ + + diff --git a/cpukit/score/cpu/m68k/cpu.c b/cpukit/score/cpu/m68k/cpu.c new file mode 100644 index 0000000000..f57fae6685 --- /dev/null +++ b/cpukit/score/cpu/m68k/cpu.c @@ -0,0 +1,144 @@ +/* + * Motorola MC68xxx Dependent Source + * + * 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/system.h> +#include <rtems/score/isr.h> + +/* _CPU_Initialize + * + * This routine performs processor dependent initialization. + * + * INPUT PARAMETERS: + * cpu_table - CPU table to initialize + * thread_dispatch - entry pointer to thread dispatcher + * + * OUTPUT PARAMETERS: NONE + */ + +void _CPU_Initialize( + rtems_cpu_table *cpu_table, + void (*thread_dispatch) /* ignored on this CPU */ +) +{ + _CPU_Table = *cpu_table; +} + +/*PAGE + * + * _CPU_ISR_Get_level + */ + +unsigned32 _CPU_ISR_Get_level( void ) +{ + unsigned32 level; + + m68k_get_interrupt_level( level ); + + return level; +} + +/*PAGE + * + * _CPU_ISR_install_raw_handler + */ + +void _CPU_ISR_install_raw_handler( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + proc_ptr *interrupt_table = NULL; + + m68k_get_vbr( interrupt_table ); + +#if ( M68K_HAS_VBR == 1) + *old_handler = interrupt_table[ vector ]; + interrupt_table[ vector ] = new_handler; +#else + *old_handler = *(proc_ptr *)( (int)interrupt_table+ (int)vector*6-10); + *(proc_ptr *)( (int)interrupt_table+ (int)vector*6-10) = new_handler; +#endif /* M68K_HAS_VBR */ +} + +/*PAGE + * + * _CPU_ISR_install_vector + * + * This kernel routine installs the RTEMS handler for the + * specified vector. + * + * Input parameters: + * vector - interrupt vector number + * new_handler - replacement ISR for this vector number + * old_handler - former ISR for this vector number + * + * Output parameters: NONE + */ + +void _CPU_ISR_install_vector( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + proc_ptr ignored; + + *old_handler = _ISR_Vector_table[ vector ]; + + _CPU_ISR_install_raw_handler( vector, _ISR_Handler, &ignored ); + + _ISR_Vector_table[ vector ] = new_handler; +} + + +/*PAGE + * + * _CPU_Install_interrupt_stack + */ + +void _CPU_Install_interrupt_stack( void ) +{ +#if ( M68K_HAS_SEPARATE_STACKS == 1 ) + void *isp = _CPU_Interrupt_stack_high; + + asm volatile ( "movec %0,%%isp" : "=r" (isp) : "0" (isp) ); +#else +#warning "FIX ME... HOW DO I INSTALL THE INTERRUPT STACK!!!" +#endif +} + +#if ( M68K_HAS_BFFFO != 1 ) +/* + * Returns table for duplication of the BFFFO instruction (16 bits only) + */ +const unsigned char __BFFFOtable[256] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; +#endif diff --git a/cpukit/score/cpu/m68k/m68302.h b/cpukit/score/cpu/m68k/m68302.h new file mode 100644 index 0000000000..da96478cf3 --- /dev/null +++ b/cpukit/score/cpu/m68k/m68302.h @@ -0,0 +1,608 @@ +/* + *------------------------------------------------------------------ + * + * m68302.h - Definitions for Motorola MC68302 processor. + * + * Section references in this file refer to revision 2 of Motorola's + * "MC68302 Integrated Multiprotocol Processor User's Manual". + * (Motorola document MC68302UM/AD REV 2.) + * + * Based on Don Meyer's cpu68302.h that was posted in comp.sys.m68k + * on 17 February, 1993. + * + * Copyright 1995 David W. Glessner. + * + * Redistribution and use in source and binary forms are permitted + * provided that the following conditions are met: + * 1. Redistribution of source code and documentation must retain + * the above copyright notice, this list of conditions and the + * following disclaimer. + * 2. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * This software is provided "AS IS" without warranty of any kind, + * either expressed or implied, including, but not limited to, the + * implied warranties of merchantability, title and fitness for a + * particular purpose. + * + * + * $Id$ + * + *------------------------------------------------------------------ + */ + +#ifndef __MOTOROLA_MC68302_DEFINITIONS_h +#define __MOTOROLA_MC68302_DEFINITIONS_h + +/* + * BAR - Base Address Register + * Section 2.7 + */ +#define M302_BAR (*((volatile rtems_unsigned16 *) 0xf2)) + +/* + * SCR - System Control Register + * Section 3.8.1 + */ +#define M302_SCR (*((volatile rtems_unsigned32 *) 0xf4)) +/* + * SCR bits + */ +#define RBIT_SCR_IPA 0x08000000 +#define RBIT_SCR_HWT 0x04000000 +#define RBIT_SCR_WPV 0x02000000 +#define RBIT_SCR_ADC 0x01000000 + +#define RBIT_SCR_ERRE 0x00400000 +#define RBIT_SCR_VGE 0x00200000 +#define RBIT_SCR_WPVE 0x00100000 +#define RBIT_SCR_RMCST 0x00080000 +#define RBIT_SCR_EMWS 0x00040000 +#define RBIT_SCR_ADCE 0x00020000 +#define RBIT_SCR_BCLM 0x00010000 + +#define RBIT_SCR_FRZW 0x00008000 +#define RBIT_SCR_FRZ2 0x00004000 +#define RBIT_SCR_FRZ1 0x00002000 +#define RBIT_SCR_SAM 0x00001000 +#define RBIT_SCR_HWDEN 0x00000800 +#define RBIT_SCR_HWDCN2 0x00000400 +#define RBIT_SCR_HWDCN1 0x00000200 +#define RBIT_SCR_HWDCN0 0x00000100 + +#define RBIT_SCR_LPREC 0x00000080 +#define RBIT_SCR_LPP16 0x00000040 +#define RBIT_SCR_LPEN 0x00000020 +#define RBIT_SCR_LPCLKDIV 0x0000001f + + +/* + * 68000 interrupt and trap vector numbers + */ +#define M68K_IVEC_BUS_ERROR 2 +#define M68K_IVEC_ADDRESS_ERROR 3 +#define M68K_IVEC_ILLEGAL_OPCODE 4 +#define M68K_IVEC_ZERO_DIVIDE 5 +#define M68K_IVEC_CHK 6 +#define M68K_IVEC_TRAPV 7 +#define M68K_IVEC_PRIVILEGE 8 +#define M68K_IVEC_TRACE 9 +#define M68K_IVEC_LINE_A 10 +#define M68K_IVEC_LINE_F 11 +/* Unassigned, Reserved 12-14 */ +#define M68K_IVEC_UNINITIALIZED_INT 15 +/* Unassigned, Reserved 16-23 */ +#define M68K_IVEC_SPURIOUS_INT 24 + +#define M68K_IVEC_LEVEL1_AUTOVECTOR 25 +#define M68K_IVEC_LEVEL2_AUTOVECTOR 26 +#define M68K_IVEC_LEVEL3_AUTOVECTOR 27 +#define M68K_IVEC_LEVEL4_AUTOVECTOR 28 +#define M68K_IVEC_LEVEL5_AUTOVECTOR 29 +#define M68K_IVEC_LEVEL6_AUTOVECTOR 30 +#define M68K_IVEC_LEVEL7_AUTOVECTOR 31 + +#define M68K_IVEC_TRAP0 32 +#define M68K_IVEC_TRAP1 33 +#define M68K_IVEC_TRAP2 34 +#define M68K_IVEC_TRAP3 35 +#define M68K_IVEC_TRAP4 36 +#define M68K_IVEC_TRAP5 37 +#define M68K_IVEC_TRAP6 38 +#define M68K_IVEC_TRAP7 39 +#define M68K_IVEC_TRAP8 40 +#define M68K_IVEC_TRAP9 41 +#define M68K_IVEC_TRAP10 42 +#define M68K_IVEC_TRAP11 43 +#define M68K_IVEC_TRAP12 44 +#define M68K_IVEC_TRAP13 45 +#define M68K_IVEC_TRAP14 46 +#define M68K_IVEC_TRAP15 47 +/* + * Unassigned, Reserved 48-59 + * + * Note: Vectors 60-63 are used by the MC68302 (e.g. BAR, SCR). + */ + +/* + * MC68302 Interrupt Vectors + * Section 3.2 + */ +enum m68302_ivec_e { + M302_IVEC_ERR =0, + M302_IVEC_PB8 =1, /* General-Purpose Interrupt 0 */ + M302_IVEC_SMC2 =2, + M302_IVEC_SMC1 =3, + M302_IVEC_TIMER3 =4, + M302_IVEC_SCP =5, + M302_IVEC_TIMER2 =6, + M302_IVEC_PB9 =7, /* General-Purpose Interrupt 1 */ + M302_IVEC_SCC3 =8, + M302_IVEC_TIMER1 =9, + M302_IVEC_SCC2 =10, + M302_IVEC_IDMA =11, + M302_IVEC_SDMA =12, /* SDMA Channels Bus Error */ + M302_IVEC_SCC1 =13, + M302_IVEC_PB10 =14, /* General-Purpose Interrupt 2 */ + M302_IVEC_PB11 =15, /* General-Purpose Interrupt 3 */ + M302_IVEC_IRQ1 =17, /* External Device */ + M302_IVEC_IRQ6 =22, /* External Device */ + M302_IVEC_IRQ7 =23 /* External Device */ +}; + + +/* + * GIMR - Global Interrupt Mode Register + * Section 3.2.5.1 + */ +#define RBIT_GIMR_MOD (1<<15) +#define RBIT_GIMR_IV7 (1<<14) +#define RBIT_GIMR_IV6 (1<<13) +#define RBIT_GIMR_IV1 (1<<12) +#define RBIT_GIMR_ET7 (1<<10) +#define RBIT_GIMR_ET6 (1<<9) +#define RBIT_GIMR_ET1 (1<<8) +#define RBIT_GIMR_VECTOR (7<<5) + +/* + * IPR - Interrupt Pending Register (Section 3.2.5.2) + * IMR - Interrupt Mask Register (Section 3.2.5.3) + * ISR - Interrupt In-Service Register (Section 3.2.5.4) + */ +#define RBIT_IPR_PB11 (1<<15) +#define RBIT_IPR_PB10 (1<<14) +#define RBIT_IPR_SCC1 (1<<13) +#define RBIT_IPR_SDMA (1<<12) +#define RBIT_IPR_IDMA (1<<11) +#define RBIT_IPR_SCC2 (1<<10) +#define RBIT_IPR_TIMER1 (1<<9) +#define RBIT_IPR_SCC3 (1<<8) +#define RBIT_IPR_PB9 (1<<7) +#define RBIT_IPR_TIMER2 (1<<6) +#define RBIT_IPR_SCP (1<<5) +#define RBIT_IPR_TIMER3 (1<<4) +#define RBIT_IPR_SMC1 (1<<3) +#define RBIT_IPR_SMC2 (1<<2) +#define RBIT_IPR_PB8 (1<<1) +#define RBIT_IPR_ERR (1<<0) + +#define RBIT_ISR_PB11 (1<<15) +#define RBIT_ISR_PB10 (1<<14) +#define RBIT_ISR_SCC1 (1<<13) +#define RBIT_ISR_SDMA (1<<12) +#define RBIT_ISR_IDMA (1<<11) +#define RBIT_ISR_SCC2 (1<<10) +#define RBIT_ISR_TIMER1 (1<<9) +#define RBIT_ISR_SCC3 (1<<8) +#define RBIT_ISR_PB9 (1<<7) +#define RBIT_ISR_TIMER2 (1<<6) +#define RBIT_ISR_SCP (1<<5) +#define RBIT_ISR_TIMER3 (1<<4) +#define RBIT_ISR_SMC1 (1<<3) +#define RBIT_ISR_SMC2 (1<<2) +#define RBIT_ISR_PB8 (1<<1) + +#define RBIT_IMR_PB11 (1<<15) /* PB11 Interrupt Mask */ +#define RBIT_IMR_PB10 (1<<14) /* PB10 Interrupt Mask */ +#define RBIT_IMR_SCC1 (1<<13) /* SCC1 Interrupt Mask */ +#define RBIT_IMR_SDMA (1<<12) /* SDMA Interrupt Mask */ +#define RBIT_IMR_IDMA (1<<11) /* IDMA Interrupt Mask */ +#define RBIT_IMR_SCC2 (1<<10) /* SCC2 Interrupt Mask */ +#define RBIT_IMR_TIMER1 (1<<9) /* TIMER1 Interrupt Mask */ +#define RBIT_IMR_SCC3 (1<<8) /* SCC3 Interrupt Mask */ +#define RBIT_IMR_PB9 (1<<7) /* PB9 Interrupt Mask */ +#define RBIT_IMR_TIMER2 (1<<6) /* TIMER2 Interrupt Mask */ +#define RBIT_IMR_SCP (1<<5) /* SCP Interrupt Mask */ +#define RBIT_IMR_TIMER3 (1<<4) /* TIMER3 Interrupt Mask */ +#define RBIT_IMR_SMC1 (1<<3) /* SMC1 Interrupt Mask */ +#define RBIT_IMR_SMC2 (1<<2) /* SMC2 Interrupt Mask */ +#define RBIT_IMR_PB8 (1<<1) /* PB8 Interrupt Mask */ + + +/* + * DRAM Refresh + * Section 3.9 + * + * The DRAM refresh memory map replaces the SCC2 Tx BD 6 and Tx BD 7 + * structures in the parameter RAM. + * + * Access to the DRAM registers can be accomplished by + * the following approach: + * + * volatile m302_DRAM_refresh_t *dram; + * dram = (volatile m302_DRAM_refresh_t *) &m302.scc2.bd.tx[6]; + * + * Then simply use pointer references (e.g. dram->count = 3). + */ +typedef struct { + rtems_unsigned16 dram_high; /* DRAM high address and FC */ + rtems_unsigned16 dram_low; /* DRAM low address */ + rtems_unsigned16 increment; /* increment step (bytes/row) */ + rtems_unsigned16 count; /* RAM refresh cycle count (#rows) */ + rtems_unsigned16 t_ptr_h; /* temporary refresh high addr & FC */ + rtems_unsigned16 t_ptr_l; /* temporary refresh low address */ + rtems_unsigned16 t_count; /* temporary refresh cycles count */ + rtems_unsigned16 res; /* reserved */ +} m302_DRAM_refresh_t; + + +/* + * TMR - Timer Mode Register (for timers 1 and 2) + * Section 3.5.2.1 + */ +#define RBIT_TMR_ICLK_STOP (0<<1) +#define RBIT_TMR_ICLK_MASTER (1<<1) +#define RBIT_TMR_ICLK_MASTER16 (2<<1) +#define RBIT_TMR_ICLK_TIN (3<<1) + +#define RBIT_TMR_OM (1<<5) +#define RBIT_TMR_ORI (1<<4) +#define RBIT_TMR_FRR (1<<3) +#define RBIT_TMR_RST (1<<0) + + +/* + * TER - Timer Event Register (for timers 1 and 2) + * Section 3.5.2.5 + */ +#define RBIT_TER_REF (1<<1) /* Output Reference Event */ +#define RBIT_TER_CAP (1<<0) /* Capture Event */ + + +/* + * SCC Buffer Descriptors and Buffer Descriptors Table + * Section 4.5.5 + */ +typedef struct m302_SCC_bd { + rtems_unsigned16 status; /* status and control */ + rtems_unsigned16 length; /* data length */ + rtems_unsigned8 *buffer; /* data buffer pointer */ +} m302_SCC_bd_t; + +typedef struct { + m302_SCC_bd_t rx[8]; /* receive buffer descriptors */ + m302_SCC_bd_t tx[8]; /* transmit buffer descriptors */ +} m302_SCC_bd_table_t; + + +/* + * SCC Parameter RAM (offset 0x080 from an SCC Base) + * Section 4.5.6 + * + * Each SCC parameter RAM area begins at offset 0x80 from each SCC base + * area (0x400, 0x500, or 0x600 from the dual-port RAM base). + * + * Offsets 0x9c-0xbf from each SCC base area compose the protocol-specific + * portion of the SCC parameter RAM. + */ +typedef struct { + rtems_unsigned8 rfcr; /* Rx Function Code */ + rtems_unsigned8 tfcr; /* Tx Function Code */ + rtems_unsigned16 mrblr; /* Maximum Rx Buffer Length */ + rtems_unsigned16 _rstate; /* Rx Internal State */ + rtems_unsigned8 res2; + rtems_unsigned8 rbd; /* Rx Internal Buffer Number */ + rtems_unsigned32 _rdptr; /* Rx Internal Data Pointer */ + rtems_unsigned16 _rcount; /* Rx Internal Byte Count */ + rtems_unsigned16 _rtmp; /* Rx Temp */ + rtems_unsigned16 _tstate; /* Tx Internal State */ + rtems_unsigned8 res7; + rtems_unsigned8 tbd; /* Tx Internal Buffer Number */ + rtems_unsigned32 _tdptr; /* Tx Internal Data Pointer */ + rtems_unsigned16 _tcount; /* Tx Internal Byte Count */ + rtems_unsigned16 _ttmp; /* Tx Temp */ +} m302_SCC_parameters_t; + +/* + * UART-Specific SCC Parameter RAM + * Section 4.5.11.3 + */ +typedef struct { + rtems_unsigned16 max_idl; /* Maximum IDLE Characters (rx) */ + rtems_unsigned16 idlc; /* Temporary rx IDLE counter */ + rtems_unsigned16 brkcr; /* Break Count Register (tx) */ + rtems_unsigned16 parec; /* Receive Parity Error Counter */ + rtems_unsigned16 frmec; /* Receive Framing Error Counter */ + rtems_unsigned16 nosec; /* Receive Noise Counter */ + rtems_unsigned16 brkec; /* Receive Break Condition Counter */ + rtems_unsigned16 uaddr1; /* UART ADDRESS Character 1 */ + rtems_unsigned16 uaddr2; /* UART ADDRESS Character 2 */ + rtems_unsigned16 rccr; /* Receive Control Character Register */ + rtems_unsigned16 character[8]; /* Control Characters 1 through 8*/ +} m302_SCC_UartSpecific_t; +/* + * This definition allows for the checking of receive buffers + * for errors. + */ + +#define RCV_ERR 0x003F + +/* + * UART receive buffer descriptor bit definitions. + * Section 4.5.11.14 + */ +#define RBIT_UART_CTRL (1<<11) /* buffer contains a control char */ +#define RBIT_UART_ADDR (1<<10) /* first byte contains an address */ +#define RBIT_UART_MATCH (1<<9) /* indicates which addr char matched */ +#define RBIT_UART_IDLE (1<<8) /* buffer closed due to IDLE sequence */ +#define RBIT_UART_BR (1<<5) /* break sequence was received */ +#define RBIT_UART_FR (1<<4) /* framing error was received */ +#define RBIT_UART_PR (1<<3) /* parity error was received */ +#define RBIT_UART_OV (1<<1) /* receiver overrun occurred */ +#define RBIT_UART_CD (1<<0) /* carrier detect lost */ +#define RBIT_UART_STATUS 0x003B /* all status bits */ + +/* + * UART transmit buffer descriptor bit definitions. + * Section 4.5.11.15 + */ +#define RBIT_UART_CR (1<<11) /* clear-to-send report + * this results in two idle bits + * between back-to-back frames + */ +#define RBIT_UART_A (1<<10) /* buffer contains address characters + * only valid in multidrop mode (UM0=1) + */ +#define RBIT_UART_PREAMBLE (1<<9) /* send preamble before data */ +#define RBIT_UART_CTS_LOST (1<<0) /* CTS lost */ + +/* + * UART event register + * Section 4.5.11.16 + */ +#define M302_UART_EV_CTS (1<<7) /* CTS status changed */ +#define M302_UART_EV_CD (1<<6) /* carrier detect status changed */ +#define M302_UART_EV_IDL (1<<5) /* IDLE sequence status changed */ +#define M302_UART_EV_BRK (1<<4) /* break character was received */ +#define M302_UART_EV_CCR (1<<3) /* control character received */ +#define M302_UART_EV_TX (1<<1) /* buffer has been transmitted */ +#define M302_UART_EV_RX (1<<0) /* buffer has been received */ + + +/* + * HDLC-Specific SCC Parameter RAM + * Section 4.5.12.3 + * + * c_mask_l should be 0xF0B8 for 16-bit CRC, 0xdebb for 32-bit CRC + * c_mask_h is a don't care for 16-bit CRC, 0x20E2 for 32-bit CRC + */ +typedef struct { + rtems_unsigned16 rcrc_l; /* Temp Receive CRC Low */ + rtems_unsigned16 rcrc_h; /* Temp Receive CRC High */ + rtems_unsigned16 c_mask_l; /* CRC Mask Low */ + rtems_unsigned16 c_mask_h; /* CRC Mask High */ + rtems_unsigned16 tcrc_l; /* Temp Transmit CRC Low */ + rtems_unsigned16 tcrc_h; /* Temp Transmit CRC High */ + + rtems_unsigned16 disfc; /* Discard Frame Counter */ + rtems_unsigned16 crcec; /* CRC Error Counter */ + rtems_unsigned16 abtsc; /* Abort Sequence Counter */ + rtems_unsigned16 nmarc; /* Nonmatching Address Received Cntr */ + rtems_unsigned16 retrc; /* Frame Retransmission Counter */ + + rtems_unsigned16 mflr; /* Maximum Frame Length Register */ + rtems_unsigned16 max_cnt; /* Maximum_Length Counter */ + + rtems_unsigned16 hmask; /* User Defined Frame Address Mask */ + rtems_unsigned16 haddr1; /* User Defined Frame Address */ + rtems_unsigned16 haddr2; /* " */ + rtems_unsigned16 haddr3; /* " */ + rtems_unsigned16 haddr4; /* " */ +} m302_SCC_HdlcSpecific_t; +/* + * HDLC receiver buffer descriptor bit definitions + * Section 4.5.12.10 + */ +#define RBIT_HDLC_EMPTY_BIT 0x8000 /* buffer associated with BD is empty */ +#define RBIT_HDLC_LAST_BIT 0x0800 /* buffer is last in a frame */ +#define RBIT_HDLC_FIRST_BIT 0x0400 /* buffer is first in a frame */ +#define RBIT_HDLC_FRAME_LEN 0x0020 /* receiver frame length violation */ +#define RBIT_HDLC_NONOCT_Rx 0x0010 /* received non-octet aligned frame */ +#define RBIT_HDLC_ABORT_SEQ 0x0008 /* received abort sequence */ +#define RBIT_HDLC_CRC_ERROR 0x0004 /* frame contains a CRC error */ +#define RBIT_HDLC_OVERRUN 0x0002 /* receiver overrun occurred */ +#define RBIT_HDLC_CD_LOST 0x0001 /* carrier detect lost */ + +/* + * HDLC transmit buffer descriptor bit definitions + * Section 4.5.12.11 + */ +#define RBIT_HDLC_READY_BIT 0x8000 /* buffer is ready to transmit */ +#define RBIT_HDLC_EXT_BUFFER 0x4000 /* buffer is in external memory */ +#define RBIT_HDLC_WRAP_BIT 0x2000 /* last buffer in bd table, so wrap */ +#define RBIT_HDLC_WAKE_UP 0x1000 /* interrupt when buffer serviced */ +#define RBIT_HDLC_LAST_BIT 0x0800 /* buffer is last in the frame */ +#define RBIT_HDLC_TxCRC_BIT 0x0400 /* transmit a CRC sequence */ +#define RBIT_HDLC_UNDERRUN 0x0002 /* transmitter underrun */ +#define RBIT_HDLC_CTS_LOST 0x0001 /* CTS lost */ + +/* + * HDLC event register bit definitions + * Section 4.5.12.12 + */ +#define RBIT_HDLC_CTS 0x80 /* CTS status changed */ +#define RBIT_HDLC_CD 0x40 /* carrier detect status changed */ +#define RBIT_HDLC_IDL 0x20 /* IDLE sequence status changed */ +#define RBIT_HDLC_TXE 0x10 /* transmit error */ +#define RBIT_HDLC_RXF 0x08 /* received frame */ +#define RBIT_HDLC_BSY 0x04 /* frame rcvd and discarded due to + * lack of buffers + */ +#define RBIT_HDLC_TXB 0x02 /* buffer has been transmitted */ +#define RBIT_HDLC_RXB 0x01 /* received buffer */ + + + +typedef struct { + m302_SCC_bd_table_t bd; /* +000 Buffer Descriptor Table */ + m302_SCC_parameters_t parm; /* +080 Common Parameter RAM */ + union { /* +09C Protocol-Specific Parm RAM */ + m302_SCC_UartSpecific_t uart; + m302_SCC_HdlcSpecific_t hdlc; + } prot; + rtems_unsigned8 res[0x040]; /* +0C0 reserved, (not implemented) */ +} m302_SCC_t; + + +/* + * Common SCC Registers + */ +typedef struct { + rtems_unsigned16 res1; + rtems_unsigned16 scon; /* SCC Configuration Register 4.5.2 */ + rtems_unsigned16 scm; /* SCC Mode Register 4.5.3 */ + rtems_unsigned16 dsr; /* SCC Data Synchronization Register 4.5.4 */ + rtems_unsigned8 scce; /* SCC Event Register 4.5.8.1 */ + rtems_unsigned8 res2; + rtems_unsigned8 sccm; /* SCC Mask Register 4.5.8.2 */ + rtems_unsigned8 res3; + rtems_unsigned8 sccs; /* SCC Status Register 4.5.8.3 */ + rtems_unsigned8 res4; + rtems_unsigned16 res5; +} m302_SCC_Registers_t; + +/* + * SCON - SCC Configuration Register + * Section 4.5.2 + */ +#define RBIT_SCON_WOMS (1<<15) /* Wired-OR Mode Select (NMSI mode only) + * When set, the TXD driver is an + * open-drain output */ +#define RBIT_SCON_EXTC (1<<14) /* External Clock Source */ +#define RBIT_SCON_TCS (1<<13) /* Transmit Clock Source */ +#define RBIT_SCON_RCS (1<<12) /* Receive Clock Source */ + +/* + * SCM - SCC Mode Register bit definitions + * Section 4.5.3 + * The parameter-specific mode bits occupy bits 15 through 6. + */ +#define RBIT_SCM_ENR (1<<3) /* Enable receiver */ +#define RBIT_SCM_ENT (1<<2) /* Enable transmitter */ + + +/* + * Internal MC68302 Registers + * starts at offset 0x800 from dual-port RAM base + * Section 2.8 + */ +typedef struct { + /* offset +800 */ + rtems_unsigned16 res0; + rtems_unsigned16 cmr; /* IDMA Channel Mode Register */ + rtems_unsigned32 sapr; /* IDMA Source Address Pointer */ + rtems_unsigned32 dapr; /* IDMA Destination Address Pointer */ + rtems_unsigned16 bcr; /* IDMA Byte Count Register */ + rtems_unsigned8 csr; /* IDMA Channel Status Register */ + rtems_unsigned8 res1; + rtems_unsigned8 fcr; /* IDMA Function Code Register */ + rtems_unsigned8 res2; + + /* offset +812 */ + rtems_unsigned16 gimr; /* Global Interrupt Mode Register */ + rtems_unsigned16 ipr; /* Interrupt Pending Register */ + rtems_unsigned16 imr; /* Interrupt Mask Register */ + rtems_unsigned16 isr; /* Interrupt In-Service Register */ + rtems_unsigned16 res3; + rtems_unsigned16 res4; + + /* offset +81e */ + rtems_unsigned16 pacnt; /* Port A Control Register */ + rtems_unsigned16 paddr; /* Port A Data Direction Register */ + rtems_unsigned16 padat; /* Port A Data Register */ + rtems_unsigned16 pbcnt; /* Port B Control Register */ + rtems_unsigned16 pbddr; /* Port B Data Direction Register */ + rtems_unsigned16 pbdat; /* Port B Data Register */ + rtems_unsigned16 res5; + + /* offset +82c */ + rtems_unsigned16 res6; + rtems_unsigned16 res7; + rtems_unsigned16 br0; /* Base Register (CS0) */ + rtems_unsigned16 or0; /* Option Register (CS0) */ + rtems_unsigned16 br1; /* Base Register (CS1) */ + rtems_unsigned16 or1; /* Option Register (CS1) */ + rtems_unsigned16 br2; /* Base Register (CS2) */ + rtems_unsigned16 or2; /* Option Register (CS2) */ + rtems_unsigned16 br3; /* Base Register (CS3) */ + rtems_unsigned16 or3; /* Option Register (CS3) */ + + /* offset +840 */ + rtems_unsigned16 tmr1; /* Timer Unit 1 Mode Register */ + rtems_unsigned16 trr1; /* Timer Unit 1 Reference Register */ + rtems_unsigned16 tcr1; /* Timer Unit 1 Capture Register */ + rtems_unsigned16 tcn1; /* Timer Unit 1 Counter */ + rtems_unsigned8 res8; + rtems_unsigned8 ter1; /* Timer Unit 1 Event Register */ + rtems_unsigned16 wrr; /* Watchdog Reference Register */ + rtems_unsigned16 wcn; /* Watchdog Counter */ + rtems_unsigned16 res9; + rtems_unsigned16 tmr2; /* Timer Unit 2 Mode Register */ + rtems_unsigned16 trr2; /* Timer Unit 2 Reference Register */ + rtems_unsigned16 tcr2; /* Timer Unit 2 Capture Register */ + rtems_unsigned16 tcn2; /* Timer Unit 2 Counter */ + rtems_unsigned8 resa; + rtems_unsigned8 ter2; /* Timer Unit 2 Event Register */ + rtems_unsigned16 resb; + rtems_unsigned16 resc; + rtems_unsigned16 resd; + + /* offset +860 */ + rtems_unsigned8 cr; /* Command Register */ + rtems_unsigned8 rese[0x1f]; + + /* offset +880, +890, +8a0 */ + m302_SCC_Registers_t scc[3]; /* SCC1, SCC2, SCC3 Registers */ + + /* offset +8b0 */ + rtems_unsigned16 spmode; /* SCP,SMC Mode and Clock Cntrl Reg */ + rtems_unsigned16 simask; /* Serial Interface Mask Register */ + rtems_unsigned16 simode; /* Serial Interface Mode Register */ +} m302_internalReg_t ; + + +/* + * MC68302 dual-port RAM structure. + * (Includes System RAM, Parameter RAM, and Internal Registers). + * Section 2.8 + */ +typedef struct { + rtems_unsigned8 mem[0x240]; /* +000 User Data Memory */ + rtems_unsigned8 res1[0x1c0]; /* +240 reserved, (not implemented) */ + m302_SCC_t scc1; /* +400 SCC1 */ + m302_SCC_t scc2; /* +500 SCC2 */ + m302_SCC_t scc3; /* +600 SCC3 */ + rtems_unsigned8 res2[0x100]; /* +700 reserved, (not implemented) */ + m302_internalReg_t reg; /* +800 68302 Internal Registers */ +} m302_dualPortRAM_t; + + +/* + * Declare the variable that's used to reference the variables in + * the dual-port RAM. + */ +extern volatile m302_dualPortRAM_t m302; + +#endif +/* end of include file */ diff --git a/cpukit/score/cpu/m68k/m68360.h b/cpukit/score/cpu/m68k/m68360.h new file mode 100644 index 0000000000..84687c49fa --- /dev/null +++ b/cpukit/score/cpu/m68k/m68360.h @@ -0,0 +1,880 @@ +/* + ************************************************************************** + ************************************************************************** + ** ** + ** MOTOROLA MC68360 QUAD INTEGRATED COMMUNICATIONS CONTROLLER (QUICC) ** + ** ** + ** HARDWARE DECLARATIONS ** + ** ** + ** ** + ** Submitted By: ** + ** ** + ** W. Eric Norum ** + ** Saskatchewan Accelerator Laboratory ** + ** University of Saskatchewan ** + ** 107 North Road ** + ** Saskatoon, Saskatchewan, CANADA ** + ** S7N 5C6 ** + ** ** + ** eric@skatter.usask.ca ** + ** ** + ** $Id$ ** + ** ** + ************************************************************************** + ************************************************************************** + */ + +#ifndef __MC68360_h +#define __MC68360_h + +/* + ************************************************************************* + * REGISTER SUBBLOCKS * + ************************************************************************* + */ + +/* + * Memory controller registers + */ +typedef struct m360MEMCRegisters_ { + rtems_unsigned32 br; + rtems_unsigned32 or; + rtems_unsigned32 _pad[2]; +} m360MEMCRegisters_t; + +/* + * Serial Communications Controller registers + */ +typedef struct m360SCCRegisters_ { + rtems_unsigned32 gsmr_l; + rtems_unsigned32 gsmr_h; + rtems_unsigned16 psmr; + rtems_unsigned16 _pad0; + rtems_unsigned16 todr; + rtems_unsigned16 dsr; + rtems_unsigned16 scce; + rtems_unsigned16 _pad1; + rtems_unsigned16 sccm; + rtems_unsigned8 _pad2; + rtems_unsigned8 sccs; + rtems_unsigned32 _pad3[2]; +} m360SCCRegisters_t; + +/* + * Serial Management Controller registers + */ +typedef struct m360SMCRegisters_ { + rtems_unsigned16 _pad0; + rtems_unsigned16 smcmr; + rtems_unsigned16 _pad1; + rtems_unsigned8 smce; + rtems_unsigned8 _pad2; + rtems_unsigned16 _pad3; + rtems_unsigned8 smcm; + rtems_unsigned8 _pad4; + rtems_unsigned32 _pad5; +} m360SMCRegisters_t; + + +/* + ************************************************************************* + * Miscellaneous Parameters * + ************************************************************************* + */ +typedef struct m360MiscParms_ { + rtems_unsigned16 rev_num; + rtems_unsigned16 _res1; + rtems_unsigned32 _res2; + rtems_unsigned32 _res3; +} m360MiscParms_t; + +/* + ************************************************************************* + * RISC Timers * + ************************************************************************* + */ +typedef struct m360TimerParms_ { + rtems_unsigned16 tm_base; + rtems_unsigned16 _tm_ptr; + rtems_unsigned16 _r_tmr; + rtems_unsigned16 _r_tmv; + rtems_unsigned32 tm_cmd; + rtems_unsigned32 tm_cnt; +} m360TimerParms_t; + +/* + * RISC Controller Configuration Register (RCCR) + * All other bits in this register are either reserved or + * used only with a Motorola-supplied RAM microcode packge. + */ +#define M360_RCCR_TIME (1<<15) /* Enable timer */ +#define M360_RCCR_TIMEP(x) ((x)<<8) /* Timer period */ + +/* + * Command register + * Set up this register before issuing a M360_CR_OP_SET_TIMER command. + */ +#define M360_TM_CMD_V (1<<31) /* Set to enable timer */ +#define M360_TM_CMD_R (1<<30) /* Set for automatic restart */ +#define M360_TM_CMD_TIMER(x) ((x)<<16) /* Select timer */ +#define M360_TM_CMD_PERIOD(x) (x) /* Timer period (16 bits) */ + +/* + ************************************************************************* + * DMA Controllers * + ************************************************************************* + */ +typedef struct m360IDMAparms_ { + rtems_unsigned16 ibase; + rtems_unsigned16 ibptr; + rtems_unsigned32 _istate; + rtems_unsigned32 _itemp; +} m360IDMAparms_t; + +/* + ************************************************************************* + * Serial Communication Controllers * + ************************************************************************* + */ +typedef struct m360SCCparms_ { + rtems_unsigned16 rbase; + rtems_unsigned16 tbase; + rtems_unsigned8 rfcr; + rtems_unsigned8 tfcr; + rtems_unsigned16 mrblr; + rtems_unsigned32 _rstate; + rtems_unsigned32 _pad0; + rtems_unsigned16 _rbptr; + rtems_unsigned16 _pad1; + rtems_unsigned32 _pad2; + rtems_unsigned32 _tstate; + rtems_unsigned32 _pad3; + rtems_unsigned16 _tbptr; + rtems_unsigned16 _pad4; + rtems_unsigned32 _pad5; + rtems_unsigned32 _rcrc; + rtems_unsigned32 _tcrc; + union { + struct { + rtems_unsigned32 _res0; + rtems_unsigned32 _res1; + rtems_unsigned16 max_idl; + rtems_unsigned16 _idlc; + rtems_unsigned16 brkcr; + rtems_unsigned16 parec; + rtems_unsigned16 frmec; + rtems_unsigned16 nosec; + rtems_unsigned16 brkec; + rtems_unsigned16 brklen; + rtems_unsigned16 uaddr[2]; + rtems_unsigned16 _rtemp; + rtems_unsigned16 toseq; + rtems_unsigned16 character[8]; + rtems_unsigned16 rccm; + rtems_unsigned16 rccr; + rtems_unsigned16 rlbc; + } uart; + } un; +} m360SCCparms_t; + +typedef struct m360SCCENparms_ { + rtems_unsigned16 rbase; + rtems_unsigned16 tbase; + rtems_unsigned8 rfcr; + rtems_unsigned8 tfcr; + rtems_unsigned16 mrblr; + rtems_unsigned32 _rstate; + rtems_unsigned32 _pad0; + rtems_unsigned16 _rbptr; + rtems_unsigned16 _pad1; + rtems_unsigned32 _pad2; + rtems_unsigned32 _tstate; + rtems_unsigned32 _pad3; + rtems_unsigned16 _tbptr; + rtems_unsigned16 _pad4; + rtems_unsigned32 _pad5; + rtems_unsigned32 _rcrc; + rtems_unsigned32 _tcrc; + union { + struct { + rtems_unsigned32 _res0; + rtems_unsigned32 _res1; + rtems_unsigned16 max_idl; + rtems_unsigned16 _idlc; + rtems_unsigned16 brkcr; + rtems_unsigned16 parec; + rtems_unsigned16 frmec; + rtems_unsigned16 nosec; + rtems_unsigned16 brkec; + rtems_unsigned16 brklen; + rtems_unsigned16 uaddr[2]; + rtems_unsigned16 _rtemp; + rtems_unsigned16 toseq; + rtems_unsigned16 character[8]; + rtems_unsigned16 rccm; + rtems_unsigned16 rccr; + rtems_unsigned16 rlbc; + } uart; + struct { + rtems_unsigned32 c_pres; + rtems_unsigned32 c_mask; + rtems_unsigned32 crcec; + rtems_unsigned32 alec; + rtems_unsigned32 disfc; + rtems_unsigned16 pads; + rtems_unsigned16 ret_lim; + rtems_unsigned16 _ret_cnt; + rtems_unsigned16 mflr; + rtems_unsigned16 minflr; + rtems_unsigned16 maxd1; + rtems_unsigned16 maxd2; + rtems_unsigned16 _maxd; + rtems_unsigned16 dma_cnt; + rtems_unsigned16 _max_b; + rtems_unsigned16 gaddr1; + rtems_unsigned16 gaddr2; + rtems_unsigned16 gaddr3; + rtems_unsigned16 gaddr4; + rtems_unsigned32 _tbuf0data0; + rtems_unsigned32 _tbuf0data1; + rtems_unsigned32 _tbuf0rba0; + rtems_unsigned32 _tbuf0crc; + rtems_unsigned16 _tbuf0bcnt; + rtems_unsigned16 paddr_h; + rtems_unsigned16 paddr_m; + rtems_unsigned16 paddr_l; + rtems_unsigned16 p_per; + rtems_unsigned16 _rfbd_ptr; + rtems_unsigned16 _tfbd_ptr; + rtems_unsigned16 _tlbd_ptr; + rtems_unsigned32 _tbuf1data0; + rtems_unsigned32 _tbuf1data1; + rtems_unsigned32 _tbuf1rba0; + rtems_unsigned32 _tbuf1crc; + rtems_unsigned16 _tbuf1bcnt; + rtems_unsigned16 _tx_len; + rtems_unsigned16 iaddr1; + rtems_unsigned16 iaddr2; + rtems_unsigned16 iaddr3; + rtems_unsigned16 iaddr4; + rtems_unsigned16 _boff_cnt; + rtems_unsigned16 taddr_l; + rtems_unsigned16 taddr_m; + rtems_unsigned16 taddr_h; + } ethernet; + } un; +} m360SCCENparms_t; + +/* + * Receive and transmit function code register bits + * These apply to the function code registers of all devices, not just SCC. + */ +#define M360_RFCR_MOT (1<<4) +#define M360_RFCR_DMA_SPACE 0x8 +#define M360_TFCR_MOT (1<<4) +#define M360_TFCR_DMA_SPACE 0x8 + +/* + ************************************************************************* + * Serial Management Controllers * + ************************************************************************* + */ +typedef struct m360SMCparms_ { + rtems_unsigned16 rbase; + rtems_unsigned16 tbase; + rtems_unsigned8 rfcr; + rtems_unsigned8 tfcr; + rtems_unsigned16 mrblr; + rtems_unsigned32 _rstate; + rtems_unsigned32 _pad0; + rtems_unsigned16 _rbptr; + rtems_unsigned16 _pad1; + rtems_unsigned32 _pad2; + rtems_unsigned32 _tstate; + rtems_unsigned32 _pad3; + rtems_unsigned16 _tbptr; + rtems_unsigned16 _pad4; + rtems_unsigned32 _pad5; + union { + struct { + rtems_unsigned16 max_idl; + rtems_unsigned16 _pad0; + rtems_unsigned16 brklen; + rtems_unsigned16 brkec; + rtems_unsigned16 brkcr; + rtems_unsigned16 _r_mask; + } uart; + struct { + rtems_unsigned16 _pad0[5]; + } transparent; + } un; +} m360SMCparms_t; + +/* + * Mode register + */ +#define M360_SMCMR_CLEN(x) ((x)<<11) /* Character length */ +#define M360_SMCMR_2STOP (1<<10) /* 2 stop bits */ +#define M360_SMCMR_PARITY (1<<9) /* Enable parity */ +#define M360_SMCMR_EVEN (1<<8) /* Even parity */ +#define M360_SMCMR_SM_GCI (0<<4) /* GCI Mode */ +#define M360_SMCMR_SM_UART (2<<4) /* UART Mode */ +#define M360_SMCMR_SM_TRANSPARENT (3<<4) /* Transparent Mode */ +#define M360_SMCMR_DM_LOOPBACK (1<<2) /* Local loopback mode */ +#define M360_SMCMR_DM_ECHO (2<<2) /* Echo mode */ +#define M360_SMCMR_TEN (1<<1) /* Enable transmitter */ +#define M360_SMCMR_REN (1<<0) /* Enable receiver */ + +/* + * Event and mask registers (SMCE, SMCM) + */ +#define M360_SMCE_BRK (1<<4) +#define M360_SMCE_BSY (1<<2) +#define M360_SMCE_TX (1<<1) +#define M360_SMCE_RX (1<<0) + +/* + ************************************************************************* + * Serial Peripheral Interface * + ************************************************************************* + */ +typedef struct m360SPIparms_ { + rtems_unsigned16 rbase; + rtems_unsigned16 tbase; + rtems_unsigned8 rfcr; + rtems_unsigned8 tfcr; + rtems_unsigned16 mrblr; + rtems_unsigned32 _rstate; + rtems_unsigned32 _pad0; + rtems_unsigned16 _rbptr; + rtems_unsigned16 _pad1; + rtems_unsigned32 _pad2; + rtems_unsigned32 _tstate; + rtems_unsigned32 _pad3; + rtems_unsigned16 _tbptr; + rtems_unsigned16 _pad4; + rtems_unsigned32 _pad5; +} m360SPIparms_t; + +/* + * Mode register (SPMODE) + */ +#define M360_SPMODE_LOOP (1<<14) /* Local loopback mode */ +#define M360_SPMODE_CI (1<<13) /* Clock invert */ +#define M360_SPMODE_CP (1<<12) /* Clock phase */ +#define M360_SPMODE_DIV16 (1<<11) /* Divide BRGCLK by 16 */ +#define M360_SPMODE_REV (1<<10) /* Reverse data */ +#define M360_SPMODE_MASTER (1<<9) /* SPI is master */ +#define M360_SPMODE_EN (1<<8) /* Enable SPI */ +#define M360_SPMODE_CLEN(x) ((x)<<4) /* Character length */ +#define M360_SPMODE_PM(x) (x) /* Prescaler modulus */ + +/* + * Mode register (SPCOM) + */ +#define M360_SPCOM_STR (1<<7) /* Start transmit */ + +/* + * Event and mask registers (SPIE, SPIM) + */ +#define M360_SPIE_MME (1<<5) /* Multi-master error */ +#define M360_SPIE_TXE (1<<4) /* Tx error */ +#define M360_SPIE_BSY (1<<2) /* Busy condition*/ +#define M360_SPIE_TXB (1<<1) /* Tx buffer */ +#define M360_SPIE_RXB (1<<0) /* Rx buffer */ + +/* + ************************************************************************* + * SDMA (SCC, SMC, SPI) Buffer Descriptors * + ************************************************************************* + */ +typedef struct m360BufferDescriptor_ { + rtems_unsigned16 status; + rtems_unsigned16 length; + volatile void *buffer; +} m360BufferDescriptor_t; + +/* + * Bits in receive buffer descriptor status word + */ +#define M360_BD_EMPTY (1<<15) /* Ethernet, SCC UART, SMC UART, SPI */ +#define M360_BD_WRAP (1<<13) /* Ethernet, SCC UART, SMC UART, SPI */ +#define M360_BD_INTERRUPT (1<<12) /* Ethernet, SCC UART, SMC UART, SPI */ +#define M360_BD_LAST (1<<11) /* Ethernet, SPI */ +#define M360_BD_CONTROL_CHAR (1<<11) /* SCC UART */ +#define M360_BD_FIRST_IN_FRAME (1<<10) /* Ethernet */ +#define M360_BD_ADDRESS (1<<10) /* SCC UART */ +#define M360_BD_CONTINUOUS (1<<9) /* SCC UART, SMC UART, SPI */ +#define M360_BD_MISS (1<<8) /* Ethernet */ +#define M360_BD_IDLE (1<<8) /* SCC UART, SMC UART */ +#define M360_BD_ADDRSS_MATCH (1<<7) /* SCC UART */ +#define M360_BD_LONG (1<<5) /* Ethernet */ +#define M360_BD_BREAK (1<<5) /* SCC UART, SMC UART */ +#define M360_BD_NONALIGNED (1<<4) /* Ethernet */ +#define M360_BD_FRAMING_ERROR (1<<4) /* SCC UART, SMC UART */ +#define M360_BD_SHORT (1<<3) /* Ethernet */ +#define M360_BD_PARITY_ERROR (1<<3) /* SCC UART, SMC UART */ +#define M360_BD_CRC_ERROR (1<<2) /* Ethernet */ +#define M360_BD_OVERRUN (1<<1) /* Ethernet, SCC UART, SMC UART, SPI */ +#define M360_BD_COLLISION (1<<0) /* Ethernet */ +#define M360_BD_CARRIER_LOST (1<<0) /* SCC UART */ +#define M360_BD_MASTER_ERROR (1<<0) /* SPI */ + +/* + * Bits in transmit buffer descriptor status word + * Many bits have the same meaning as those in receiver buffer descriptors. + */ +#define M360_BD_READY (1<<15) /* Ethernet, SCC UART, SMC UART, SPI */ +#define M360_BD_PAD (1<<14) /* Ethernet */ +#define M360_BD_CTS_REPORT (1<<11) /* SCC UART */ +#define M360_BD_TX_CRC (1<<10) /* Ethernet */ +#define M360_BD_DEFER (1<<9) /* Ethernet */ +#define M360_BD_HEARTBEAT (1<<8) /* Ethernet */ +#define M360_BD_PREAMBLE (1<<8) /* SCC UART, SMC UART */ +#define M360_BD_LATE_COLLISION (1<<7) /* Ethernet */ +#define M360_BD_NO_STOP_BIT (1<<7) /* SCC UART */ +#define M360_BD_RETRY_LIMIT (1<<6) /* Ethernet */ +#define M360_BD_RETRY_COUNT(x) (((x)&0x3C)>>2) /* Ethernet */ +#define M360_BD_UNDERRUN (1<<1) /* Ethernet, SPI */ +#define M360_BD_CARRIER_LOST (1<<0) /* Ethernet */ +#define M360_BD_CTS_LOST (1<<0) /* SCC UART */ + +/* + ************************************************************************* + * IDMA Buffer Descriptors * + ************************************************************************* + */ +typedef struct m360IDMABufferDescriptor_ { + rtems_unsigned16 status; + rtems_unsigned16 _pad; + rtems_unsigned32 length; + void *source; + void *destination; +} m360IDMABufferDescriptor_t; + +/* + ************************************************************************* + * RISC Communication Processor Module Command Register (CR) * + ************************************************************************* + */ +#define M360_CR_RST (1<<15) /* Reset communication processor */ +#define M360_CR_OP_INIT_RX_TX (0<<8) /* SCC, SMC UART, SMC GCI, SPI */ +#define M360_CR_OP_INIT_RX (1<<8) /* SCC, SMC UART, SPI */ +#define M360_CR_OP_INIT_TX (2<<8) /* SCC, SMC UART, SPI */ +#define M360_CR_OP_INIT_HUNT (3<<8) /* SCC, SMC UART */ +#define M360_CR_OP_STOP_TX (4<<8) /* SCC, SMC UART */ +#define M360_CR_OP_GR_STOP_TX (5<<8) /* SCC */ +#define M360_CR_OP_INIT_IDMA (5<<8) /* IDMA */ +#define M360_CR_OP_RESTART_TX (6<<8) /* SCC, SMC UART */ +#define M360_CR_OP_CLOSE_RX_BD (7<<8) /* SCC, SMC UART, SPI */ +#define M360_CR_OP_SET_GRP_ADDR (8<<8) /* SCC */ +#define M360_CR_OP_SET_TIMER (8<<8) /* Timer */ +#define M360_CR_OP_GCI_TIMEOUT (9<<8) /* SMC GCI */ +#define M360_CR_OP_RESERT_BCS (10<<8) /* SCC */ +#define M360_CR_OP_GCI_ABORT (10<<8) /* SMC GCI */ +#define M360_CR_CHAN_SCC1 (0<<4) /* Channel selection */ +#define M360_CR_CHAN_SCC2 (4<<4) +#define M360_CR_CHAN_SPI (5<<4) +#define M360_CR_CHAN_TIMER (5<<4) +#define M360_CR_CHAN_SCC3 (8<<4) +#define M360_CR_CHAN_SMC1 (9<<4) +#define M360_CR_CHAN_IDMA1 (9<<4) +#define M360_CR_CHAN_SCC4 (12<<4) +#define M360_CR_CHAN_SMC2 (13<<4) +#define M360_CR_CHAN_IDMA2 (13<<4) +#define M360_CR_FLG (1<<0) /* Command flag */ + +/* + ************************************************************************* + * System Protection Control Register (SYPCR) * + ************************************************************************* + */ +#define M360_SYPCR_SWE (1<<7) /* Software watchdog enable */ +#define M360_SYPCR_SWRI (1<<6) /* Software watchdog reset select */ +#define M360_SYPCR_SWT1 (1<<5) /* Software watchdog timing bit 1 */ +#define M360_SYPCR_SWT0 (1<<4) /* Software watchdog timing bit 0 */ +#define M360_SYPCR_DBFE (1<<3) /* Double bus fault monitor enable */ +#define M360_SYPCR_BME (1<<2) /* Bus monitor external enable */ +#define M360_SYPCR_BMT1 (1<<1) /* Bus monitor timing bit 1 */ +#define M360_SYPCR_BMT0 (1<<0) /* Bus monitor timing bit 0 */ + +/* + ************************************************************************* + * Memory Control Registers * + ************************************************************************* + */ +#define M360_GMR_RCNT(x) ((x)<<24) /* Refresh count */ +#define M360_GMR_RFEN (1<<23) /* Refresh enable */ +#define M360_GMR_RCYC(x) ((x)<<21) /* Refresh cycle length */ +#define M360_GMR_PGS(x) ((x)<<18) /* Page size */ +#define M360_GMR_DPS_32BIT (0<<16) /* DRAM port size */ +#define M360_GMR_DPS_16BIT (1<<16) +#define M360_GMR_DPS_8BIT (2<<16) +#define M360_GMR_DPS_DSACK (3<<16) +#define M360_GMR_WBT40 (1<<15) /* Wait between 040 transfers */ +#define M360_GMR_WBTQ (1<<14) /* Wait between 360 transfers */ +#define M360_GMR_SYNC (1<<13) /* Synchronous external access */ +#define M360_GMR_EMWS (1<<12) /* External master wait state */ +#define M360_GMR_OPAR (1<<11) /* Odd parity */ +#define M360_GMR_PBEE (1<<10) /* Parity bus error enable */ +#define M360_GMR_TSS40 (1<<9) /* TS* sample for 040 */ +#define M360_GMR_NCS (1<<8) /* No CPU space */ +#define M360_GMR_DWQ (1<<7) /* Delay write for 360 */ +#define M360_GMR_DW40 (1<<6) /* Delay write for 040 */ +#define M360_GMR_GAMX (1<<5) /* Global address mux enable */ + +#define M360_MEMC_BR_FC(x) ((x)<<7) /* Function code limit */ +#define M360_MEMC_BR_TRLXQ (1<<6) /* Relax timing requirements */ +#define M360_MEMC_BR_BACK40 (1<<5) /* Burst acknowledge to 040 */ +#define M360_MEMC_BR_CSNT40 (1<<4) /* CS* negate timing for 040 */ +#define M360_MEMC_BR_CSNTQ (1<<3) /* CS* negate timing for 360 */ +#define M360_MEMC_BR_PAREN (1<<2) /* Enable parity checking */ +#define M360_MEMC_BR_WP (1<<1) /* Write Protect */ +#define M360_MEMC_BR_V (1<<0) /* Base/Option register are valid */ + +#define M360_MEMC_OR_TCYC(x) ((x)<<28) /* Cycle length (clocks) */ +#define M360_MEMC_OR_WAITS(x) M360_MEMC_OR_TCYC((x)+1) +#define M360_MEMC_OR_2KB 0x0FFFF800 /* Address range */ +#define M360_MEMC_OR_4KB 0x0FFFF000 +#define M360_MEMC_OR_8KB 0x0FFFE000 +#define M360_MEMC_OR_16KB 0x0FFFC000 +#define M360_MEMC_OR_32KB 0x0FFF8000 +#define M360_MEMC_OR_64KB 0x0FFF0000 +#define M360_MEMC_OR_128KB 0x0FFE0000 +#define M360_MEMC_OR_256KB 0x0FFC0000 +#define M360_MEMC_OR_512KB 0x0FF80000 +#define M360_MEMC_OR_1MB 0x0FF00000 +#define M360_MEMC_OR_2MB 0x0FE00000 +#define M360_MEMC_OR_4MB 0x0FC00000 +#define M360_MEMC_OR_8MB 0x0F800000 +#define M360_MEMC_OR_16MB 0x0F000000 +#define M360_MEMC_OR_32MB 0x0E000000 +#define M360_MEMC_OR_64MB 0x0C000000 +#define M360_MEMC_OR_128MB 0x08000000 +#define M360_MEMC_OR_256MB 0x00000000 +#define M360_MEMC_OR_FCMC(x) ((x)<<7) /* Function code mask */ +#define M360_MEMC_OR_BCYC(x) ((x)<<5) /* Burst cycle length (clocks) */ +#define M360_MEMC_OR_PGME (1<<3) /* Page mode enable */ +#define M360_MEMC_OR_32BIT (0<<1) /* Port size */ +#define M360_MEMC_OR_16BIT (1<<1) +#define M360_MEMC_OR_8BIT (2<<1) +#define M360_MEMC_OR_DSACK (3<<1) +#define M360_MEMC_OR_DRAM (1<<0) /* Dynamic RAM select */ + +/* + ************************************************************************* + * SI Mode Register (SIMODE) * + ************************************************************************* + */ +#define M360_SI_SMC2_BITS 0xFFFF0000 /* All SMC2 bits */ +#define M360_SI_SMC2_TDM (1<<31) /* Multiplexed SMC2 */ +#define M360_SI_SMC2_BRG1 (0<<28) /* SMC2 clock souce */ +#define M360_SI_SMC2_BRG2 (1<<28) +#define M360_SI_SMC2_BRG3 (2<<28) +#define M360_SI_SMC2_BRG4 (3<<28) +#define M360_SI_SMC2_CLK5 (0<<28) +#define M360_SI_SMC2_CLK6 (1<<28) +#define M360_SI_SMC2_CLK7 (2<<28) +#define M360_SI_SMC2_CLK8 (3<<28) +#define M360_SI_SMC1_BITS 0x0000FFFF /* All SMC1 bits */ +#define M360_SI_SMC1_TDM (1<<15) /* Multiplexed SMC1 */ +#define M360_SI_SMC1_BRG1 (0<<12) /* SMC1 clock souce */ +#define M360_SI_SMC1_BRG2 (1<<12) +#define M360_SI_SMC1_BRG3 (2<<12) +#define M360_SI_SMC1_BRG4 (3<<12) +#define M360_SI_SMC1_CLK1 (0<<12) +#define M360_SI_SMC1_CLK2 (1<<12) +#define M360_SI_SMC1_CLK3 (2<<12) +#define M360_SI_SMC1_CLK4 (3<<12) + +/* + ************************************************************************* + * SDMA Configuration Register (SDMA) * + ************************************************************************* + */ +#define M360_SDMA_FREEZE (2<<13) /* Freeze on next bus cycle */ +#define M360_SDMA_SISM_7 (7<<8) /* Normal interrupt service mask */ +#define M360_SDMA_SAID_4 (4<<4) /* Normal arbitration ID */ +#define M360_SDMA_INTE (1<<1) /* SBER interrupt enable */ +#define M360_SDMA_INTB (1<<0) /* SBKP interrupt enable */ + +/* + ************************************************************************* + * Baud (sic) Rate Generators * + ************************************************************************* + */ +#define M360_BRG_RST (1<<17) /* Reset generator */ +#define M360_BRG_EN (1<<16) /* Enable generator */ +#define M360_BRG_EXTC_BRGCLK (0<<14) /* Source is BRGCLK */ +#define M360_BRG_EXTC_CLK2 (1<<14) /* Source is CLK2 pin */ +#define M360_BRG_EXTC_CLK6 (2<<14) /* Source is CLK6 pin */ +#define M360_BRG_ATB (1<<13) /* Autobaud */ +#define M360_BRG_115200 (13<<1) /* Assume 25 MHz clock */ +#define M360_BRG_57600 (26<<1) +#define M360_BRG_38400 (40<<1) +#define M360_BRG_19200 (80<<1) +#define M360_BRG_9600 (162<<1) +#define M360_BRG_4800 (324<<1) +#define M360_BRG_2400 (650<<1) +#define M360_BRG_1200 (1301<<1) +#define M360_BRG_600 (2603<<1) +#define M360_BRG_300 ((324<<1) | 1) +#define M360_BRG_150 ((650<<1) | 1) +#define M360_BRG_75 ((1301<<1) | 1) + +/* + ************************************************************************* + * MC68360 DUAL-PORT RAM AND REGISTERS * + ************************************************************************* + */ +typedef struct m360_ { + /* + * Dual-port RAM + */ + rtems_unsigned8 dpram0[0x400]; /* Microcode program */ + rtems_unsigned8 dpram1[0x200]; + rtems_unsigned8 dpram2[0x100]; /* Microcode scratch */ + rtems_unsigned8 dpram3[0x100]; /* Not on REV A or B masks */ + rtems_unsigned8 _rsv0[0xC00-0x800]; + m360SCCENparms_t scc1p; + rtems_unsigned8 _rsv1[0xCB0-0xC00-sizeof(m360SCCENparms_t)]; + m360MiscParms_t miscp; + rtems_unsigned8 _rsv2[0xD00-0xCB0-sizeof(m360MiscParms_t)]; + m360SCCparms_t scc2p; + rtems_unsigned8 _rsv3[0xD80-0xD00-sizeof(m360SCCparms_t)]; + m360SPIparms_t spip; + rtems_unsigned8 _rsv4[0xDB0-0xD80-sizeof(m360SPIparms_t)]; + m360TimerParms_t tmp; + rtems_unsigned8 _rsv5[0xE00-0xDB0-sizeof(m360TimerParms_t)]; + m360SCCparms_t scc3p; + rtems_unsigned8 _rsv6[0xE70-0xE00-sizeof(m360SCCparms_t)]; + m360IDMAparms_t idma1p; + rtems_unsigned8 _rsv7[0xE80-0xE70-sizeof(m360IDMAparms_t)]; + m360SMCparms_t smc1p; + rtems_unsigned8 _rsv8[0xF00-0xE80-sizeof(m360SMCparms_t)]; + m360SCCparms_t scc4p; + rtems_unsigned8 _rsv9[0xF70-0xF00-sizeof(m360SCCparms_t)]; + m360IDMAparms_t idma2p; + rtems_unsigned8 _rsv10[0xF80-0xF70-sizeof(m360IDMAparms_t)]; + m360SMCparms_t smc2p; + rtems_unsigned8 _rsv11[0x1000-0xF80-sizeof(m360SMCparms_t)]; + + /* + * SIM Block + */ + rtems_unsigned32 mcr; + rtems_unsigned32 _pad00; + rtems_unsigned8 avr; + rtems_unsigned8 rsr; + rtems_unsigned16 _pad01; + rtems_unsigned8 clkocr; + rtems_unsigned8 _pad02; + rtems_unsigned16 _pad03; + rtems_unsigned16 pllcr; + rtems_unsigned16 _pad04; + rtems_unsigned16 cdvcr; + rtems_unsigned16 pepar; + rtems_unsigned32 _pad05[2]; + rtems_unsigned16 _pad06; + rtems_unsigned8 sypcr; + rtems_unsigned8 swiv; + rtems_unsigned16 _pad07; + rtems_unsigned16 picr; + rtems_unsigned16 _pad08; + rtems_unsigned16 pitr; + rtems_unsigned16 _pad09; + rtems_unsigned8 _pad10; + rtems_unsigned8 swsr; + rtems_unsigned32 bkar; + rtems_unsigned32 bcar; + rtems_unsigned32 _pad11[2]; + + /* + * MEMC Block + */ + rtems_unsigned32 gmr; + rtems_unsigned16 mstat; + rtems_unsigned16 _pad12; + rtems_unsigned32 _pad13[2]; + m360MEMCRegisters_t memc[8]; + rtems_unsigned8 _pad14[0xF0-0xD0]; + rtems_unsigned8 _pad15[0x100-0xF0]; + rtems_unsigned8 _pad16[0x500-0x100]; + + /* + * IDMA1 Block + */ + rtems_unsigned16 iccr; + rtems_unsigned16 _pad17; + rtems_unsigned16 cmr1; + rtems_unsigned16 _pad18; + rtems_unsigned32 sapr1; + rtems_unsigned32 dapr1; + rtems_unsigned32 bcr1; + rtems_unsigned8 fcr1; + rtems_unsigned8 _pad19; + rtems_unsigned8 cmar1; + rtems_unsigned8 _pad20; + rtems_unsigned8 csr1; + rtems_unsigned8 _pad21; + rtems_unsigned16 _pad22; + + /* + * SDMA Block + */ + rtems_unsigned8 sdsr; + rtems_unsigned8 _pad23; + rtems_unsigned16 sdcr; + rtems_unsigned32 sdar; + + /* + * IDMA2 Block + */ + rtems_unsigned16 _pad24; + rtems_unsigned16 cmr2; + rtems_unsigned32 sapr2; + rtems_unsigned32 dapr2; + rtems_unsigned32 bcr2; + rtems_unsigned8 fcr2; + rtems_unsigned8 _pad26; + rtems_unsigned8 cmar2; + rtems_unsigned8 _pad27; + rtems_unsigned8 csr2; + rtems_unsigned8 _pad28; + rtems_unsigned16 _pad29; + rtems_unsigned32 _pad30; + + /* + * CPIC Block + */ + rtems_unsigned32 cicr; + rtems_unsigned32 cipr; + rtems_unsigned32 cimr; + rtems_unsigned32 cisr; + + /* + * Parallel I/O Block + */ + rtems_unsigned16 padir; + rtems_unsigned16 papar; + rtems_unsigned16 paodr; + rtems_unsigned16 padat; + rtems_unsigned32 _pad31[2]; + rtems_unsigned16 pcdir; + rtems_unsigned16 pcpar; + rtems_unsigned16 pcso; + rtems_unsigned16 pcdat; + rtems_unsigned16 pcint; + rtems_unsigned16 _pad32; + rtems_unsigned32 _pad33[5]; + + /* + * TIMER Block + */ + rtems_unsigned16 tgcr; + rtems_unsigned16 _pad34; + rtems_unsigned32 _pad35[3]; + rtems_unsigned16 tmr1; + rtems_unsigned16 tmr2; + rtems_unsigned16 trr1; + rtems_unsigned16 trr2; + rtems_unsigned16 tcr1; + rtems_unsigned16 tcr2; + rtems_unsigned16 tcn1; + rtems_unsigned16 tcn2; + rtems_unsigned16 tmr3; + rtems_unsigned16 tmr4; + rtems_unsigned16 trr3; + rtems_unsigned16 trr4; + rtems_unsigned16 tcr3; + rtems_unsigned16 tcr4; + rtems_unsigned16 tcn3; + rtems_unsigned16 tcn4; + rtems_unsigned16 ter1; + rtems_unsigned16 ter2; + rtems_unsigned16 ter3; + rtems_unsigned16 ter4; + rtems_unsigned32 _pad36[2]; + + /* + * CP Block + */ + rtems_unsigned16 cr; + rtems_unsigned16 _pad37; + rtems_unsigned16 rccr; + rtems_unsigned16 _pad38; + rtems_unsigned32 _pad39[3]; + rtems_unsigned16 _pad40; + rtems_unsigned16 rter; + rtems_unsigned16 _pad41; + rtems_unsigned16 rtmr; + rtems_unsigned32 _pad42[5]; + + /* + * BRG Block + */ + rtems_unsigned32 brgc1; + rtems_unsigned32 brgc2; + rtems_unsigned32 brgc3; + rtems_unsigned32 brgc4; + + /* + * SCC Block + */ + m360SCCRegisters_t scc1; + m360SCCRegisters_t scc2; + m360SCCRegisters_t scc3; + m360SCCRegisters_t scc4; + + /* + * SMC Block + */ + m360SMCRegisters_t smc1; + m360SMCRegisters_t smc2; + + /* + * SPI Block + */ + rtems_unsigned16 spmode; + rtems_unsigned16 _pad43[2]; + rtems_unsigned8 spie; + rtems_unsigned8 _pad44; + rtems_unsigned16 _pad45; + rtems_unsigned8 spim; + rtems_unsigned8 _pad46[2]; + rtems_unsigned8 spcom; + rtems_unsigned16 _pad47[2]; + + /* + * PIP Block + */ + rtems_unsigned16 pipc; + rtems_unsigned16 _pad48; + rtems_unsigned16 ptpr; + rtems_unsigned32 pbdir; + rtems_unsigned32 pbpar; + rtems_unsigned16 _pad49; + rtems_unsigned16 pbodr; + rtems_unsigned32 pbdat; + rtems_unsigned32 _pad50[6]; + + /* + * SI Block + */ + rtems_unsigned32 simode; + rtems_unsigned8 sigmr; + rtems_unsigned8 _pad51; + rtems_unsigned8 sistr; + rtems_unsigned8 sicmr; + rtems_unsigned32 _pad52; + rtems_unsigned32 sicr; + rtems_unsigned16 _pad53; + rtems_unsigned16 sirp[2]; + rtems_unsigned16 _pad54; + rtems_unsigned32 _pad55[2]; + rtems_unsigned8 siram[256]; +} m360_t; + +extern volatile m360_t m360; + +#endif /* __MC68360_h */ diff --git a/cpukit/score/cpu/m68k/qsm.h b/cpukit/score/cpu/m68k/qsm.h new file mode 100644 index 0000000000..e1bf33bc12 --- /dev/null +++ b/cpukit/score/cpu/m68k/qsm.h @@ -0,0 +1,209 @@ +/* + *------------------------------------------------------------------- + * + * QSM -- Queued Serial Module + * + * The QSM contains two serial interfaces: (a) the queued serial + * peripheral interface (QSPI) and the serial communication interface + * (SCI). The QSPI provides peripheral expansion and/or interprocessor + * communication through a full-duplex, synchronous, three-wire bus. A + * self contained RAM queue permits serial data transfers without CPU + * intervention and automatic continuous sampling. The SCI provides a + * standard non-return to zero mark/space format with wakeup functions + * to allow the CPU to run uninterrupted until woken + * + * For more information, refer to Motorola's "Modular Microcontroller + * Family Queued Serial Module Reference Manual" (Motorola document + * QSMRM/AD). + * + * This file has been created by John S. Gwynne for support of + * Motorola's 68332 MCU in the efi332 project. + * + * Redistribution and use in source and binary forms are permitted + * provided that the following conditions are met: + * 1. Redistribution of source code and documentation must retain + * the above authorship, this list of conditions and the + * following disclaimer. + * 2. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * This software is provided "AS IS" without warranty of any kind, + * either expressed or implied, including, but not limited to, the + * implied warranties of merchantability, title and fitness for a + * particular purpose. + * + *------------------------------------------------------------------ + * + * $Id$ + */ + +#ifndef _QSM_H_ +#define _QSM_H_ + + +#include <efi332.h> + + +/* SAM-- shift and mask */ +#undef SAM +#define SAM(a,b,c) ((a << b) & c) + + +/* QSM_CRB (QSM Control Register Block) base address of the QSM + control registers */ +#if SIM_MM == 0 +#define QSM_CRB 0x7ffc00 +#else +#undef SIM_MM +#define SIM_MM 1 +#define QSM_CRB 0xfffc00 +#endif + + +#define QSMCR (volatile unsigned short int * const)(0x00 + QSM_CRB) + /* QSM Configuration Register */ +#define STOP 0x8000 /* Stop Enable */ +#define FRZ 0x6000 /* Freeze Control */ +#define SUPV 0x0080 /* Supervisor/Unrestricted */ +#define IARB 0x000f /* Inerrupt Arbitration */ + + +#define QTEST (volatile unsigned short int * const)(0x02 + QSM_CRB) + /* QSM Test Register */ +/* Used only for factor testing */ + + +#define QILR (volatile unsigned char * const)(0x04 + QSM_CRB) + /* QSM Interrupt Level Register */ +#define ILQSPI 0x38 /* Interrupt Level for QSPI */ +#define ILSCI 0x07 /* Interrupt Level for SCI */ + + +#define QIVR (volatile unsigned char * const)(0x05 + QSM_CRB) + /* QSM Interrupt Vector Register */ +#define INTV 0xff /* Interrupt Vector Number */ + + +#define SCCR0 (volatile unsigned short int * const)(0x08 + QSM_CRB) + /* SCI Control Register 0 */ +#define SCBR 0x1fff /* SCI Baud Rate */ + + +#define SCCR1 (volatile unsigned short int * const)(0x0a + QSM_CRB) + /* SCI Control Register 1 */ +#define LOOPS 0x4000 /* Loop Mode */ +#define WOMS 0x2000 /* Wired-OR Mode for SCI Pins */ +#define ILT 0x1000 /* Idle-Line Detect Type */ +#define PT 0x0800 /* Parity Type */ +#define PE 0x0400 /* Parity Enable */ +#define M 0x0200 /* Mode Select */ +#define WAKE 0x0100 /* Wakeup by Address Mark */ +#define TIE 0x0080 /* Transmit Complete Interrupt Enable */ +#define TCIE 0x0040 /* Transmit Complete Interrupt Enable */ +#define RIE 0x0020 /* Receiver Interrupt Enable */ +#define ILIE 0x0010 /* Idle-Line Interrupt Enable */ +#define TE 0x0008 /* Transmitter Enable */ +#define RE 0x0004 /* Receiver Enable */ +#define RWU 0x0002 /* Receiver Wakeup */ +#define SBK 0x0001 /* Send Break */ + + +#define SCSR (volatile unsigned short int * const)(0x0c + QSM_CRB) + /* SCI Status Register */ +#define TDRE 0x0100 /* Transmit Data Register Empty */ +#define TC 0x0080 /* Transmit Complete */ +#define RDRF 0x0040 /* Receive Data Register Full */ +#define RAF 0x0020 /* Receiver Active */ +#define IDLE 0x0010 /* Idle-Line Detected */ +#define OR 0x0008 /* Overrun Error */ +#define NF 0x0004 /* Noise Error Flag */ +#define FE 0x0002 /* Framing Error */ +#define PF 0x0001 /* Parity Error */ + + +#define SCDR (volatile unsigned short int * const)(0x0e + QSM_CRB) + /* SCI Data Register */ + + +#define PORTQS (volatile unsigned char * const)(0x15 + QSM_CRB) + /* Port QS Data Register */ + +#define PQSPAR (volatile unsigned char * const)(0x16 + QSM_CRB) + /* PORT QS Pin Assignment Rgister */ +/* Any bit cleared (zero) defines the corresponding pin to be an I/O + pin. Any bit set defines the corresponding pin to be a QSPI + signal. */ +/* note: PQS2 is a digital I/O pin unless the SPI is enabled in which + case it becomes the SPI serial clock SCK. */ +/* note: PQS7 is a digital I/O pin unless the SCI transmitter is + enabled in which case it becomes the SCI serial output TxD. */ +#define QSMFun 0x0 +#define QSMDis 0x1 +/* + * PQSPAR Field | QSM Function | Discrete I/O pin + *------------------+--------------+------------------ */ +#define PQSPA0 0 /* MISO | PQS0 */ +#define PQSPA1 1 /* MOSI | PQS1 */ +#define PQSPA2 2 /* SCK | PQS2 (see note)*/ +#define PQSPA3 3 /* PCSO/!SS | PQS3 */ +#define PQSPA4 4 /* PCS1 | PQS4 */ +#define PQSPA5 5 /* PCS2 | PQS5 */ +#define PQSPA6 6 /* PCS3 | PQS6 */ +#define PQSPA7 7 /* TxD | PQS7 (see note)*/ + + +#define DDRQS (volatile unsigned char * const)(0x17 + QSM_CRB) + /* PORT QS Data Direction Register */ +/* Clearing a bit makes the corresponding pin an input; setting a bit + makes the pin an output. */ + + +#define SPCR0 (volatile unsigned short int * const)(0x18 + QSM_CRB) + /* QSPI Control Register 0 */ +#define MSTR 0x8000 /* Master/Slave Mode Select */ +#define WOMQ 0x4000 /* Wired-OR Mode for QSPI Pins */ +#define BITS 0x3c00 /* Bits Per Transfer */ +#define CPOL 0x0200 /* Clock Polarity */ +#define CPHA 0x0100 /* Clock Phase */ +#define SPBR 0x00ff /* Serial Clock Baud Rate */ + + +#define SPCR1 (volatile unsigned short int * const)(0x1a + QSM_CRB) + /* QSPI Control Register 1 */ +#define SPE 0x8000 /* QSPI Enable */ +#define DSCKL 0x7f00 /* Delay before SCK */ +#define DTL 0x00ff /* Length of Delay after Transfer */ + + +#define SPCR2 (volatile unsigned short int * const)(0x1c + QSM_CRB) + /* QSPI Control Register 2 */ +#define SPIFIE 0x8000 /* SPI Finished Interrupt Enable */ +#define WREN 0x4000 /* Wrap Enable */ +#define WRTO 0x2000 /* Wrap To */ +#define ENDQP 0x0f00 /* Ending Queue Pointer */ +#define NEWQP 0x000f /* New Queue Pointer Value */ + + +#define SPCR3 (volatile unsigned char * const)(0x1e + QSM_CRB) + /* QSPI Control Register 3 */ +#define LOOPQ 0x0400 /* QSPI Loop Mode */ +#define HMIE 0x0200 /* HALTA and MODF Interrupt Enable */ +#define HALT 0x0100 /* Halt */ + + +#define SPSR (volatile unsigned char * const)(0x1f + QSM_CRB) + /* QSPI Status Register */ +#define SPIF 0x0080 /* QSPI Finished Flag */ +#define MODF 0x0040 /* Mode Fault Flag */ +#define HALTA 0x0020 /* Halt Acknowlwdge Flag */ +#define CPTQP x0000f /* Completed Queue Pointer */ + +#define QSPIRR (volatile unsigned char * const)(0x100 + QSM_CRB) + /* QSPI Receive Data RAM */ +#define QSPITR (volatile unsigned char * const)(0x120 + QSM_CRB) + /* QSPI Transmit Data RAM */ +#define QSPIcR (volatile unsigned char * const)(0x140 + QSM_CRB) + /* QSPI Command RAM */ + +#endif /* _QSM_H_ */ diff --git a/cpukit/score/cpu/m68k/rtems/asm.h b/cpukit/score/cpu/m68k/rtems/asm.h new file mode 100644 index 0000000000..4c53980d51 --- /dev/null +++ b/cpukit/score/cpu/m68k/rtems/asm.h @@ -0,0 +1,129 @@ +/* asm.h + * + * This include file attempts to address the problems + * caused by incompatible flavors of assemblers and + * toolsets. It primarily addresses variations in the + * use of leading underscores on symbols and the requirement + * that register names be preceded by a %. + * + * + * NOTE: The spacing in the use of these macros + * is critical to them working as advertised. + * + * COPYRIGHT: + * + * This file is based on similar code found in newlib available + * from ftp.cygnus.com. The file which was used had no copyright + * notice. This file is freely distributable as long as the source + * of the file is noted. This file is: + * + * COPYRIGHT (c) 1994. + * On-Line Applications Research Corporation (OAR). + * + * $Id$ + */ + +#ifndef __M68k_ASM_h +#define __M68k_ASM_h + +/* + * Indicate we are in an assembly file and get the basic CPU definitions. + */ + +#define ASM +#include <rtems/score/m68k.h> + +/* + * Recent versions of GNU cpp define variables which indicate the + * need for underscores and percents. If not using GNU cpp or + * the version does not support this, then you will obviously + * have to define these as appropriate. + */ + +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#ifndef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ +#endif + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a ## b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) + +#define d0 REG (d0) +#define d1 REG (d1) +#define d2 REG (d2) +#define d3 REG (d3) +#define d4 REG (d4) +#define d5 REG (d5) +#define d6 REG (d6) +#define d7 REG (d7) +#define a0 REG (a0) +#define a1 REG (a1) +#define a2 REG (a2) +#define a3 REG (a3) +#define a4 REG (a4) +#define a5 REG (a5) +#define a6 REG (a6) +#define a7 REG (a7) + +#define msp REG (msp) +#define usp REG (usp) +#define isp REG (isp) +#define sr REG (sr) +#define vbr REG (vbr) +#define dfc REG (dfc) + +#define fp0 REG (fp0) +#define fp1 REG (fp1) +#define fp2 REG (fp2) +#define fp3 REG (fp3) +#define fp4 REG (fp4) +#define fp5 REG (fp5) +#define fp6 REG (fp6) +#define fp7 REG (fp7) + +#define fpc REG (fpc) +#define fpi REG (fpi) +#define fps REG (fps) + +/* + * Define macros to handle section beginning and ends. + */ + + +#define BEGIN_CODE_DCL .text +#define END_CODE_DCL +#define BEGIN_DATA_DCL .data +#define END_DATA_DCL +#define BEGIN_CODE .text +#define END_CODE +#define BEGIN_DATA +#define END_DATA +#define BEGIN_BSS +#define END_BSS +#define END + +/* + * Following must be tailor for a particular flavor of the C compiler. + * They may need to put underscores in front of the symbols. + */ + +#define PUBLIC(sym) .globl SYM (sym) +#define EXTERN(sym) .globl SYM (sym) + +#endif +/* end of include file */ + + diff --git a/cpukit/score/cpu/m68k/rtems/m68k/m68302.h b/cpukit/score/cpu/m68k/rtems/m68k/m68302.h new file mode 100644 index 0000000000..da96478cf3 --- /dev/null +++ b/cpukit/score/cpu/m68k/rtems/m68k/m68302.h @@ -0,0 +1,608 @@ +/* + *------------------------------------------------------------------ + * + * m68302.h - Definitions for Motorola MC68302 processor. + * + * Section references in this file refer to revision 2 of Motorola's + * "MC68302 Integrated Multiprotocol Processor User's Manual". + * (Motorola document MC68302UM/AD REV 2.) + * + * Based on Don Meyer's cpu68302.h that was posted in comp.sys.m68k + * on 17 February, 1993. + * + * Copyright 1995 David W. Glessner. + * + * Redistribution and use in source and binary forms are permitted + * provided that the following conditions are met: + * 1. Redistribution of source code and documentation must retain + * the above copyright notice, this list of conditions and the + * following disclaimer. + * 2. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * This software is provided "AS IS" without warranty of any kind, + * either expressed or implied, including, but not limited to, the + * implied warranties of merchantability, title and fitness for a + * particular purpose. + * + * + * $Id$ + * + *------------------------------------------------------------------ + */ + +#ifndef __MOTOROLA_MC68302_DEFINITIONS_h +#define __MOTOROLA_MC68302_DEFINITIONS_h + +/* + * BAR - Base Address Register + * Section 2.7 + */ +#define M302_BAR (*((volatile rtems_unsigned16 *) 0xf2)) + +/* + * SCR - System Control Register + * Section 3.8.1 + */ +#define M302_SCR (*((volatile rtems_unsigned32 *) 0xf4)) +/* + * SCR bits + */ +#define RBIT_SCR_IPA 0x08000000 +#define RBIT_SCR_HWT 0x04000000 +#define RBIT_SCR_WPV 0x02000000 +#define RBIT_SCR_ADC 0x01000000 + +#define RBIT_SCR_ERRE 0x00400000 +#define RBIT_SCR_VGE 0x00200000 +#define RBIT_SCR_WPVE 0x00100000 +#define RBIT_SCR_RMCST 0x00080000 +#define RBIT_SCR_EMWS 0x00040000 +#define RBIT_SCR_ADCE 0x00020000 +#define RBIT_SCR_BCLM 0x00010000 + +#define RBIT_SCR_FRZW 0x00008000 +#define RBIT_SCR_FRZ2 0x00004000 +#define RBIT_SCR_FRZ1 0x00002000 +#define RBIT_SCR_SAM 0x00001000 +#define RBIT_SCR_HWDEN 0x00000800 +#define RBIT_SCR_HWDCN2 0x00000400 +#define RBIT_SCR_HWDCN1 0x00000200 +#define RBIT_SCR_HWDCN0 0x00000100 + +#define RBIT_SCR_LPREC 0x00000080 +#define RBIT_SCR_LPP16 0x00000040 +#define RBIT_SCR_LPEN 0x00000020 +#define RBIT_SCR_LPCLKDIV 0x0000001f + + +/* + * 68000 interrupt and trap vector numbers + */ +#define M68K_IVEC_BUS_ERROR 2 +#define M68K_IVEC_ADDRESS_ERROR 3 +#define M68K_IVEC_ILLEGAL_OPCODE 4 +#define M68K_IVEC_ZERO_DIVIDE 5 +#define M68K_IVEC_CHK 6 +#define M68K_IVEC_TRAPV 7 +#define M68K_IVEC_PRIVILEGE 8 +#define M68K_IVEC_TRACE 9 +#define M68K_IVEC_LINE_A 10 +#define M68K_IVEC_LINE_F 11 +/* Unassigned, Reserved 12-14 */ +#define M68K_IVEC_UNINITIALIZED_INT 15 +/* Unassigned, Reserved 16-23 */ +#define M68K_IVEC_SPURIOUS_INT 24 + +#define M68K_IVEC_LEVEL1_AUTOVECTOR 25 +#define M68K_IVEC_LEVEL2_AUTOVECTOR 26 +#define M68K_IVEC_LEVEL3_AUTOVECTOR 27 +#define M68K_IVEC_LEVEL4_AUTOVECTOR 28 +#define M68K_IVEC_LEVEL5_AUTOVECTOR 29 +#define M68K_IVEC_LEVEL6_AUTOVECTOR 30 +#define M68K_IVEC_LEVEL7_AUTOVECTOR 31 + +#define M68K_IVEC_TRAP0 32 +#define M68K_IVEC_TRAP1 33 +#define M68K_IVEC_TRAP2 34 +#define M68K_IVEC_TRAP3 35 +#define M68K_IVEC_TRAP4 36 +#define M68K_IVEC_TRAP5 37 +#define M68K_IVEC_TRAP6 38 +#define M68K_IVEC_TRAP7 39 +#define M68K_IVEC_TRAP8 40 +#define M68K_IVEC_TRAP9 41 +#define M68K_IVEC_TRAP10 42 +#define M68K_IVEC_TRAP11 43 +#define M68K_IVEC_TRAP12 44 +#define M68K_IVEC_TRAP13 45 +#define M68K_IVEC_TRAP14 46 +#define M68K_IVEC_TRAP15 47 +/* + * Unassigned, Reserved 48-59 + * + * Note: Vectors 60-63 are used by the MC68302 (e.g. BAR, SCR). + */ + +/* + * MC68302 Interrupt Vectors + * Section 3.2 + */ +enum m68302_ivec_e { + M302_IVEC_ERR =0, + M302_IVEC_PB8 =1, /* General-Purpose Interrupt 0 */ + M302_IVEC_SMC2 =2, + M302_IVEC_SMC1 =3, + M302_IVEC_TIMER3 =4, + M302_IVEC_SCP =5, + M302_IVEC_TIMER2 =6, + M302_IVEC_PB9 =7, /* General-Purpose Interrupt 1 */ + M302_IVEC_SCC3 =8, + M302_IVEC_TIMER1 =9, + M302_IVEC_SCC2 =10, + M302_IVEC_IDMA =11, + M302_IVEC_SDMA =12, /* SDMA Channels Bus Error */ + M302_IVEC_SCC1 =13, + M302_IVEC_PB10 =14, /* General-Purpose Interrupt 2 */ + M302_IVEC_PB11 =15, /* General-Purpose Interrupt 3 */ + M302_IVEC_IRQ1 =17, /* External Device */ + M302_IVEC_IRQ6 =22, /* External Device */ + M302_IVEC_IRQ7 =23 /* External Device */ +}; + + +/* + * GIMR - Global Interrupt Mode Register + * Section 3.2.5.1 + */ +#define RBIT_GIMR_MOD (1<<15) +#define RBIT_GIMR_IV7 (1<<14) +#define RBIT_GIMR_IV6 (1<<13) +#define RBIT_GIMR_IV1 (1<<12) +#define RBIT_GIMR_ET7 (1<<10) +#define RBIT_GIMR_ET6 (1<<9) +#define RBIT_GIMR_ET1 (1<<8) +#define RBIT_GIMR_VECTOR (7<<5) + +/* + * IPR - Interrupt Pending Register (Section 3.2.5.2) + * IMR - Interrupt Mask Register (Section 3.2.5.3) + * ISR - Interrupt In-Service Register (Section 3.2.5.4) + */ +#define RBIT_IPR_PB11 (1<<15) +#define RBIT_IPR_PB10 (1<<14) +#define RBIT_IPR_SCC1 (1<<13) +#define RBIT_IPR_SDMA (1<<12) +#define RBIT_IPR_IDMA (1<<11) +#define RBIT_IPR_SCC2 (1<<10) +#define RBIT_IPR_TIMER1 (1<<9) +#define RBIT_IPR_SCC3 (1<<8) +#define RBIT_IPR_PB9 (1<<7) +#define RBIT_IPR_TIMER2 (1<<6) +#define RBIT_IPR_SCP (1<<5) +#define RBIT_IPR_TIMER3 (1<<4) +#define RBIT_IPR_SMC1 (1<<3) +#define RBIT_IPR_SMC2 (1<<2) +#define RBIT_IPR_PB8 (1<<1) +#define RBIT_IPR_ERR (1<<0) + +#define RBIT_ISR_PB11 (1<<15) +#define RBIT_ISR_PB10 (1<<14) +#define RBIT_ISR_SCC1 (1<<13) +#define RBIT_ISR_SDMA (1<<12) +#define RBIT_ISR_IDMA (1<<11) +#define RBIT_ISR_SCC2 (1<<10) +#define RBIT_ISR_TIMER1 (1<<9) +#define RBIT_ISR_SCC3 (1<<8) +#define RBIT_ISR_PB9 (1<<7) +#define RBIT_ISR_TIMER2 (1<<6) +#define RBIT_ISR_SCP (1<<5) +#define RBIT_ISR_TIMER3 (1<<4) +#define RBIT_ISR_SMC1 (1<<3) +#define RBIT_ISR_SMC2 (1<<2) +#define RBIT_ISR_PB8 (1<<1) + +#define RBIT_IMR_PB11 (1<<15) /* PB11 Interrupt Mask */ +#define RBIT_IMR_PB10 (1<<14) /* PB10 Interrupt Mask */ +#define RBIT_IMR_SCC1 (1<<13) /* SCC1 Interrupt Mask */ +#define RBIT_IMR_SDMA (1<<12) /* SDMA Interrupt Mask */ +#define RBIT_IMR_IDMA (1<<11) /* IDMA Interrupt Mask */ +#define RBIT_IMR_SCC2 (1<<10) /* SCC2 Interrupt Mask */ +#define RBIT_IMR_TIMER1 (1<<9) /* TIMER1 Interrupt Mask */ +#define RBIT_IMR_SCC3 (1<<8) /* SCC3 Interrupt Mask */ +#define RBIT_IMR_PB9 (1<<7) /* PB9 Interrupt Mask */ +#define RBIT_IMR_TIMER2 (1<<6) /* TIMER2 Interrupt Mask */ +#define RBIT_IMR_SCP (1<<5) /* SCP Interrupt Mask */ +#define RBIT_IMR_TIMER3 (1<<4) /* TIMER3 Interrupt Mask */ +#define RBIT_IMR_SMC1 (1<<3) /* SMC1 Interrupt Mask */ +#define RBIT_IMR_SMC2 (1<<2) /* SMC2 Interrupt Mask */ +#define RBIT_IMR_PB8 (1<<1) /* PB8 Interrupt Mask */ + + +/* + * DRAM Refresh + * Section 3.9 + * + * The DRAM refresh memory map replaces the SCC2 Tx BD 6 and Tx BD 7 + * structures in the parameter RAM. + * + * Access to the DRAM registers can be accomplished by + * the following approach: + * + * volatile m302_DRAM_refresh_t *dram; + * dram = (volatile m302_DRAM_refresh_t *) &m302.scc2.bd.tx[6]; + * + * Then simply use pointer references (e.g. dram->count = 3). + */ +typedef struct { + rtems_unsigned16 dram_high; /* DRAM high address and FC */ + rtems_unsigned16 dram_low; /* DRAM low address */ + rtems_unsigned16 increment; /* increment step (bytes/row) */ + rtems_unsigned16 count; /* RAM refresh cycle count (#rows) */ + rtems_unsigned16 t_ptr_h; /* temporary refresh high addr & FC */ + rtems_unsigned16 t_ptr_l; /* temporary refresh low address */ + rtems_unsigned16 t_count; /* temporary refresh cycles count */ + rtems_unsigned16 res; /* reserved */ +} m302_DRAM_refresh_t; + + +/* + * TMR - Timer Mode Register (for timers 1 and 2) + * Section 3.5.2.1 + */ +#define RBIT_TMR_ICLK_STOP (0<<1) +#define RBIT_TMR_ICLK_MASTER (1<<1) +#define RBIT_TMR_ICLK_MASTER16 (2<<1) +#define RBIT_TMR_ICLK_TIN (3<<1) + +#define RBIT_TMR_OM (1<<5) +#define RBIT_TMR_ORI (1<<4) +#define RBIT_TMR_FRR (1<<3) +#define RBIT_TMR_RST (1<<0) + + +/* + * TER - Timer Event Register (for timers 1 and 2) + * Section 3.5.2.5 + */ +#define RBIT_TER_REF (1<<1) /* Output Reference Event */ +#define RBIT_TER_CAP (1<<0) /* Capture Event */ + + +/* + * SCC Buffer Descriptors and Buffer Descriptors Table + * Section 4.5.5 + */ +typedef struct m302_SCC_bd { + rtems_unsigned16 status; /* status and control */ + rtems_unsigned16 length; /* data length */ + rtems_unsigned8 *buffer; /* data buffer pointer */ +} m302_SCC_bd_t; + +typedef struct { + m302_SCC_bd_t rx[8]; /* receive buffer descriptors */ + m302_SCC_bd_t tx[8]; /* transmit buffer descriptors */ +} m302_SCC_bd_table_t; + + +/* + * SCC Parameter RAM (offset 0x080 from an SCC Base) + * Section 4.5.6 + * + * Each SCC parameter RAM area begins at offset 0x80 from each SCC base + * area (0x400, 0x500, or 0x600 from the dual-port RAM base). + * + * Offsets 0x9c-0xbf from each SCC base area compose the protocol-specific + * portion of the SCC parameter RAM. + */ +typedef struct { + rtems_unsigned8 rfcr; /* Rx Function Code */ + rtems_unsigned8 tfcr; /* Tx Function Code */ + rtems_unsigned16 mrblr; /* Maximum Rx Buffer Length */ + rtems_unsigned16 _rstate; /* Rx Internal State */ + rtems_unsigned8 res2; + rtems_unsigned8 rbd; /* Rx Internal Buffer Number */ + rtems_unsigned32 _rdptr; /* Rx Internal Data Pointer */ + rtems_unsigned16 _rcount; /* Rx Internal Byte Count */ + rtems_unsigned16 _rtmp; /* Rx Temp */ + rtems_unsigned16 _tstate; /* Tx Internal State */ + rtems_unsigned8 res7; + rtems_unsigned8 tbd; /* Tx Internal Buffer Number */ + rtems_unsigned32 _tdptr; /* Tx Internal Data Pointer */ + rtems_unsigned16 _tcount; /* Tx Internal Byte Count */ + rtems_unsigned16 _ttmp; /* Tx Temp */ +} m302_SCC_parameters_t; + +/* + * UART-Specific SCC Parameter RAM + * Section 4.5.11.3 + */ +typedef struct { + rtems_unsigned16 max_idl; /* Maximum IDLE Characters (rx) */ + rtems_unsigned16 idlc; /* Temporary rx IDLE counter */ + rtems_unsigned16 brkcr; /* Break Count Register (tx) */ + rtems_unsigned16 parec; /* Receive Parity Error Counter */ + rtems_unsigned16 frmec; /* Receive Framing Error Counter */ + rtems_unsigned16 nosec; /* Receive Noise Counter */ + rtems_unsigned16 brkec; /* Receive Break Condition Counter */ + rtems_unsigned16 uaddr1; /* UART ADDRESS Character 1 */ + rtems_unsigned16 uaddr2; /* UART ADDRESS Character 2 */ + rtems_unsigned16 rccr; /* Receive Control Character Register */ + rtems_unsigned16 character[8]; /* Control Characters 1 through 8*/ +} m302_SCC_UartSpecific_t; +/* + * This definition allows for the checking of receive buffers + * for errors. + */ + +#define RCV_ERR 0x003F + +/* + * UART receive buffer descriptor bit definitions. + * Section 4.5.11.14 + */ +#define RBIT_UART_CTRL (1<<11) /* buffer contains a control char */ +#define RBIT_UART_ADDR (1<<10) /* first byte contains an address */ +#define RBIT_UART_MATCH (1<<9) /* indicates which addr char matched */ +#define RBIT_UART_IDLE (1<<8) /* buffer closed due to IDLE sequence */ +#define RBIT_UART_BR (1<<5) /* break sequence was received */ +#define RBIT_UART_FR (1<<4) /* framing error was received */ +#define RBIT_UART_PR (1<<3) /* parity error was received */ +#define RBIT_UART_OV (1<<1) /* receiver overrun occurred */ +#define RBIT_UART_CD (1<<0) /* carrier detect lost */ +#define RBIT_UART_STATUS 0x003B /* all status bits */ + +/* + * UART transmit buffer descriptor bit definitions. + * Section 4.5.11.15 + */ +#define RBIT_UART_CR (1<<11) /* clear-to-send report + * this results in two idle bits + * between back-to-back frames + */ +#define RBIT_UART_A (1<<10) /* buffer contains address characters + * only valid in multidrop mode (UM0=1) + */ +#define RBIT_UART_PREAMBLE (1<<9) /* send preamble before data */ +#define RBIT_UART_CTS_LOST (1<<0) /* CTS lost */ + +/* + * UART event register + * Section 4.5.11.16 + */ +#define M302_UART_EV_CTS (1<<7) /* CTS status changed */ +#define M302_UART_EV_CD (1<<6) /* carrier detect status changed */ +#define M302_UART_EV_IDL (1<<5) /* IDLE sequence status changed */ +#define M302_UART_EV_BRK (1<<4) /* break character was received */ +#define M302_UART_EV_CCR (1<<3) /* control character received */ +#define M302_UART_EV_TX (1<<1) /* buffer has been transmitted */ +#define M302_UART_EV_RX (1<<0) /* buffer has been received */ + + +/* + * HDLC-Specific SCC Parameter RAM + * Section 4.5.12.3 + * + * c_mask_l should be 0xF0B8 for 16-bit CRC, 0xdebb for 32-bit CRC + * c_mask_h is a don't care for 16-bit CRC, 0x20E2 for 32-bit CRC + */ +typedef struct { + rtems_unsigned16 rcrc_l; /* Temp Receive CRC Low */ + rtems_unsigned16 rcrc_h; /* Temp Receive CRC High */ + rtems_unsigned16 c_mask_l; /* CRC Mask Low */ + rtems_unsigned16 c_mask_h; /* CRC Mask High */ + rtems_unsigned16 tcrc_l; /* Temp Transmit CRC Low */ + rtems_unsigned16 tcrc_h; /* Temp Transmit CRC High */ + + rtems_unsigned16 disfc; /* Discard Frame Counter */ + rtems_unsigned16 crcec; /* CRC Error Counter */ + rtems_unsigned16 abtsc; /* Abort Sequence Counter */ + rtems_unsigned16 nmarc; /* Nonmatching Address Received Cntr */ + rtems_unsigned16 retrc; /* Frame Retransmission Counter */ + + rtems_unsigned16 mflr; /* Maximum Frame Length Register */ + rtems_unsigned16 max_cnt; /* Maximum_Length Counter */ + + rtems_unsigned16 hmask; /* User Defined Frame Address Mask */ + rtems_unsigned16 haddr1; /* User Defined Frame Address */ + rtems_unsigned16 haddr2; /* " */ + rtems_unsigned16 haddr3; /* " */ + rtems_unsigned16 haddr4; /* " */ +} m302_SCC_HdlcSpecific_t; +/* + * HDLC receiver buffer descriptor bit definitions + * Section 4.5.12.10 + */ +#define RBIT_HDLC_EMPTY_BIT 0x8000 /* buffer associated with BD is empty */ +#define RBIT_HDLC_LAST_BIT 0x0800 /* buffer is last in a frame */ +#define RBIT_HDLC_FIRST_BIT 0x0400 /* buffer is first in a frame */ +#define RBIT_HDLC_FRAME_LEN 0x0020 /* receiver frame length violation */ +#define RBIT_HDLC_NONOCT_Rx 0x0010 /* received non-octet aligned frame */ +#define RBIT_HDLC_ABORT_SEQ 0x0008 /* received abort sequence */ +#define RBIT_HDLC_CRC_ERROR 0x0004 /* frame contains a CRC error */ +#define RBIT_HDLC_OVERRUN 0x0002 /* receiver overrun occurred */ +#define RBIT_HDLC_CD_LOST 0x0001 /* carrier detect lost */ + +/* + * HDLC transmit buffer descriptor bit definitions + * Section 4.5.12.11 + */ +#define RBIT_HDLC_READY_BIT 0x8000 /* buffer is ready to transmit */ +#define RBIT_HDLC_EXT_BUFFER 0x4000 /* buffer is in external memory */ +#define RBIT_HDLC_WRAP_BIT 0x2000 /* last buffer in bd table, so wrap */ +#define RBIT_HDLC_WAKE_UP 0x1000 /* interrupt when buffer serviced */ +#define RBIT_HDLC_LAST_BIT 0x0800 /* buffer is last in the frame */ +#define RBIT_HDLC_TxCRC_BIT 0x0400 /* transmit a CRC sequence */ +#define RBIT_HDLC_UNDERRUN 0x0002 /* transmitter underrun */ +#define RBIT_HDLC_CTS_LOST 0x0001 /* CTS lost */ + +/* + * HDLC event register bit definitions + * Section 4.5.12.12 + */ +#define RBIT_HDLC_CTS 0x80 /* CTS status changed */ +#define RBIT_HDLC_CD 0x40 /* carrier detect status changed */ +#define RBIT_HDLC_IDL 0x20 /* IDLE sequence status changed */ +#define RBIT_HDLC_TXE 0x10 /* transmit error */ +#define RBIT_HDLC_RXF 0x08 /* received frame */ +#define RBIT_HDLC_BSY 0x04 /* frame rcvd and discarded due to + * lack of buffers + */ +#define RBIT_HDLC_TXB 0x02 /* buffer has been transmitted */ +#define RBIT_HDLC_RXB 0x01 /* received buffer */ + + + +typedef struct { + m302_SCC_bd_table_t bd; /* +000 Buffer Descriptor Table */ + m302_SCC_parameters_t parm; /* +080 Common Parameter RAM */ + union { /* +09C Protocol-Specific Parm RAM */ + m302_SCC_UartSpecific_t uart; + m302_SCC_HdlcSpecific_t hdlc; + } prot; + rtems_unsigned8 res[0x040]; /* +0C0 reserved, (not implemented) */ +} m302_SCC_t; + + +/* + * Common SCC Registers + */ +typedef struct { + rtems_unsigned16 res1; + rtems_unsigned16 scon; /* SCC Configuration Register 4.5.2 */ + rtems_unsigned16 scm; /* SCC Mode Register 4.5.3 */ + rtems_unsigned16 dsr; /* SCC Data Synchronization Register 4.5.4 */ + rtems_unsigned8 scce; /* SCC Event Register 4.5.8.1 */ + rtems_unsigned8 res2; + rtems_unsigned8 sccm; /* SCC Mask Register 4.5.8.2 */ + rtems_unsigned8 res3; + rtems_unsigned8 sccs; /* SCC Status Register 4.5.8.3 */ + rtems_unsigned8 res4; + rtems_unsigned16 res5; +} m302_SCC_Registers_t; + +/* + * SCON - SCC Configuration Register + * Section 4.5.2 + */ +#define RBIT_SCON_WOMS (1<<15) /* Wired-OR Mode Select (NMSI mode only) + * When set, the TXD driver is an + * open-drain output */ +#define RBIT_SCON_EXTC (1<<14) /* External Clock Source */ +#define RBIT_SCON_TCS (1<<13) /* Transmit Clock Source */ +#define RBIT_SCON_RCS (1<<12) /* Receive Clock Source */ + +/* + * SCM - SCC Mode Register bit definitions + * Section 4.5.3 + * The parameter-specific mode bits occupy bits 15 through 6. + */ +#define RBIT_SCM_ENR (1<<3) /* Enable receiver */ +#define RBIT_SCM_ENT (1<<2) /* Enable transmitter */ + + +/* + * Internal MC68302 Registers + * starts at offset 0x800 from dual-port RAM base + * Section 2.8 + */ +typedef struct { + /* offset +800 */ + rtems_unsigned16 res0; + rtems_unsigned16 cmr; /* IDMA Channel Mode Register */ + rtems_unsigned32 sapr; /* IDMA Source Address Pointer */ + rtems_unsigned32 dapr; /* IDMA Destination Address Pointer */ + rtems_unsigned16 bcr; /* IDMA Byte Count Register */ + rtems_unsigned8 csr; /* IDMA Channel Status Register */ + rtems_unsigned8 res1; + rtems_unsigned8 fcr; /* IDMA Function Code Register */ + rtems_unsigned8 res2; + + /* offset +812 */ + rtems_unsigned16 gimr; /* Global Interrupt Mode Register */ + rtems_unsigned16 ipr; /* Interrupt Pending Register */ + rtems_unsigned16 imr; /* Interrupt Mask Register */ + rtems_unsigned16 isr; /* Interrupt In-Service Register */ + rtems_unsigned16 res3; + rtems_unsigned16 res4; + + /* offset +81e */ + rtems_unsigned16 pacnt; /* Port A Control Register */ + rtems_unsigned16 paddr; /* Port A Data Direction Register */ + rtems_unsigned16 padat; /* Port A Data Register */ + rtems_unsigned16 pbcnt; /* Port B Control Register */ + rtems_unsigned16 pbddr; /* Port B Data Direction Register */ + rtems_unsigned16 pbdat; /* Port B Data Register */ + rtems_unsigned16 res5; + + /* offset +82c */ + rtems_unsigned16 res6; + rtems_unsigned16 res7; + rtems_unsigned16 br0; /* Base Register (CS0) */ + rtems_unsigned16 or0; /* Option Register (CS0) */ + rtems_unsigned16 br1; /* Base Register (CS1) */ + rtems_unsigned16 or1; /* Option Register (CS1) */ + rtems_unsigned16 br2; /* Base Register (CS2) */ + rtems_unsigned16 or2; /* Option Register (CS2) */ + rtems_unsigned16 br3; /* Base Register (CS3) */ + rtems_unsigned16 or3; /* Option Register (CS3) */ + + /* offset +840 */ + rtems_unsigned16 tmr1; /* Timer Unit 1 Mode Register */ + rtems_unsigned16 trr1; /* Timer Unit 1 Reference Register */ + rtems_unsigned16 tcr1; /* Timer Unit 1 Capture Register */ + rtems_unsigned16 tcn1; /* Timer Unit 1 Counter */ + rtems_unsigned8 res8; + rtems_unsigned8 ter1; /* Timer Unit 1 Event Register */ + rtems_unsigned16 wrr; /* Watchdog Reference Register */ + rtems_unsigned16 wcn; /* Watchdog Counter */ + rtems_unsigned16 res9; + rtems_unsigned16 tmr2; /* Timer Unit 2 Mode Register */ + rtems_unsigned16 trr2; /* Timer Unit 2 Reference Register */ + rtems_unsigned16 tcr2; /* Timer Unit 2 Capture Register */ + rtems_unsigned16 tcn2; /* Timer Unit 2 Counter */ + rtems_unsigned8 resa; + rtems_unsigned8 ter2; /* Timer Unit 2 Event Register */ + rtems_unsigned16 resb; + rtems_unsigned16 resc; + rtems_unsigned16 resd; + + /* offset +860 */ + rtems_unsigned8 cr; /* Command Register */ + rtems_unsigned8 rese[0x1f]; + + /* offset +880, +890, +8a0 */ + m302_SCC_Registers_t scc[3]; /* SCC1, SCC2, SCC3 Registers */ + + /* offset +8b0 */ + rtems_unsigned16 spmode; /* SCP,SMC Mode and Clock Cntrl Reg */ + rtems_unsigned16 simask; /* Serial Interface Mask Register */ + rtems_unsigned16 simode; /* Serial Interface Mode Register */ +} m302_internalReg_t ; + + +/* + * MC68302 dual-port RAM structure. + * (Includes System RAM, Parameter RAM, and Internal Registers). + * Section 2.8 + */ +typedef struct { + rtems_unsigned8 mem[0x240]; /* +000 User Data Memory */ + rtems_unsigned8 res1[0x1c0]; /* +240 reserved, (not implemented) */ + m302_SCC_t scc1; /* +400 SCC1 */ + m302_SCC_t scc2; /* +500 SCC2 */ + m302_SCC_t scc3; /* +600 SCC3 */ + rtems_unsigned8 res2[0x100]; /* +700 reserved, (not implemented) */ + m302_internalReg_t reg; /* +800 68302 Internal Registers */ +} m302_dualPortRAM_t; + + +/* + * Declare the variable that's used to reference the variables in + * the dual-port RAM. + */ +extern volatile m302_dualPortRAM_t m302; + +#endif +/* end of include file */ diff --git a/cpukit/score/cpu/m68k/rtems/m68k/m68360.h b/cpukit/score/cpu/m68k/rtems/m68k/m68360.h new file mode 100644 index 0000000000..84687c49fa --- /dev/null +++ b/cpukit/score/cpu/m68k/rtems/m68k/m68360.h @@ -0,0 +1,880 @@ +/* + ************************************************************************** + ************************************************************************** + ** ** + ** MOTOROLA MC68360 QUAD INTEGRATED COMMUNICATIONS CONTROLLER (QUICC) ** + ** ** + ** HARDWARE DECLARATIONS ** + ** ** + ** ** + ** Submitted By: ** + ** ** + ** W. Eric Norum ** + ** Saskatchewan Accelerator Laboratory ** + ** University of Saskatchewan ** + ** 107 North Road ** + ** Saskatoon, Saskatchewan, CANADA ** + ** S7N 5C6 ** + ** ** + ** eric@skatter.usask.ca ** + ** ** + ** $Id$ ** + ** ** + ************************************************************************** + ************************************************************************** + */ + +#ifndef __MC68360_h +#define __MC68360_h + +/* + ************************************************************************* + * REGISTER SUBBLOCKS * + ************************************************************************* + */ + +/* + * Memory controller registers + */ +typedef struct m360MEMCRegisters_ { + rtems_unsigned32 br; + rtems_unsigned32 or; + rtems_unsigned32 _pad[2]; +} m360MEMCRegisters_t; + +/* + * Serial Communications Controller registers + */ +typedef struct m360SCCRegisters_ { + rtems_unsigned32 gsmr_l; + rtems_unsigned32 gsmr_h; + rtems_unsigned16 psmr; + rtems_unsigned16 _pad0; + rtems_unsigned16 todr; + rtems_unsigned16 dsr; + rtems_unsigned16 scce; + rtems_unsigned16 _pad1; + rtems_unsigned16 sccm; + rtems_unsigned8 _pad2; + rtems_unsigned8 sccs; + rtems_unsigned32 _pad3[2]; +} m360SCCRegisters_t; + +/* + * Serial Management Controller registers + */ +typedef struct m360SMCRegisters_ { + rtems_unsigned16 _pad0; + rtems_unsigned16 smcmr; + rtems_unsigned16 _pad1; + rtems_unsigned8 smce; + rtems_unsigned8 _pad2; + rtems_unsigned16 _pad3; + rtems_unsigned8 smcm; + rtems_unsigned8 _pad4; + rtems_unsigned32 _pad5; +} m360SMCRegisters_t; + + +/* + ************************************************************************* + * Miscellaneous Parameters * + ************************************************************************* + */ +typedef struct m360MiscParms_ { + rtems_unsigned16 rev_num; + rtems_unsigned16 _res1; + rtems_unsigned32 _res2; + rtems_unsigned32 _res3; +} m360MiscParms_t; + +/* + ************************************************************************* + * RISC Timers * + ************************************************************************* + */ +typedef struct m360TimerParms_ { + rtems_unsigned16 tm_base; + rtems_unsigned16 _tm_ptr; + rtems_unsigned16 _r_tmr; + rtems_unsigned16 _r_tmv; + rtems_unsigned32 tm_cmd; + rtems_unsigned32 tm_cnt; +} m360TimerParms_t; + +/* + * RISC Controller Configuration Register (RCCR) + * All other bits in this register are either reserved or + * used only with a Motorola-supplied RAM microcode packge. + */ +#define M360_RCCR_TIME (1<<15) /* Enable timer */ +#define M360_RCCR_TIMEP(x) ((x)<<8) /* Timer period */ + +/* + * Command register + * Set up this register before issuing a M360_CR_OP_SET_TIMER command. + */ +#define M360_TM_CMD_V (1<<31) /* Set to enable timer */ +#define M360_TM_CMD_R (1<<30) /* Set for automatic restart */ +#define M360_TM_CMD_TIMER(x) ((x)<<16) /* Select timer */ +#define M360_TM_CMD_PERIOD(x) (x) /* Timer period (16 bits) */ + +/* + ************************************************************************* + * DMA Controllers * + ************************************************************************* + */ +typedef struct m360IDMAparms_ { + rtems_unsigned16 ibase; + rtems_unsigned16 ibptr; + rtems_unsigned32 _istate; + rtems_unsigned32 _itemp; +} m360IDMAparms_t; + +/* + ************************************************************************* + * Serial Communication Controllers * + ************************************************************************* + */ +typedef struct m360SCCparms_ { + rtems_unsigned16 rbase; + rtems_unsigned16 tbase; + rtems_unsigned8 rfcr; + rtems_unsigned8 tfcr; + rtems_unsigned16 mrblr; + rtems_unsigned32 _rstate; + rtems_unsigned32 _pad0; + rtems_unsigned16 _rbptr; + rtems_unsigned16 _pad1; + rtems_unsigned32 _pad2; + rtems_unsigned32 _tstate; + rtems_unsigned32 _pad3; + rtems_unsigned16 _tbptr; + rtems_unsigned16 _pad4; + rtems_unsigned32 _pad5; + rtems_unsigned32 _rcrc; + rtems_unsigned32 _tcrc; + union { + struct { + rtems_unsigned32 _res0; + rtems_unsigned32 _res1; + rtems_unsigned16 max_idl; + rtems_unsigned16 _idlc; + rtems_unsigned16 brkcr; + rtems_unsigned16 parec; + rtems_unsigned16 frmec; + rtems_unsigned16 nosec; + rtems_unsigned16 brkec; + rtems_unsigned16 brklen; + rtems_unsigned16 uaddr[2]; + rtems_unsigned16 _rtemp; + rtems_unsigned16 toseq; + rtems_unsigned16 character[8]; + rtems_unsigned16 rccm; + rtems_unsigned16 rccr; + rtems_unsigned16 rlbc; + } uart; + } un; +} m360SCCparms_t; + +typedef struct m360SCCENparms_ { + rtems_unsigned16 rbase; + rtems_unsigned16 tbase; + rtems_unsigned8 rfcr; + rtems_unsigned8 tfcr; + rtems_unsigned16 mrblr; + rtems_unsigned32 _rstate; + rtems_unsigned32 _pad0; + rtems_unsigned16 _rbptr; + rtems_unsigned16 _pad1; + rtems_unsigned32 _pad2; + rtems_unsigned32 _tstate; + rtems_unsigned32 _pad3; + rtems_unsigned16 _tbptr; + rtems_unsigned16 _pad4; + rtems_unsigned32 _pad5; + rtems_unsigned32 _rcrc; + rtems_unsigned32 _tcrc; + union { + struct { + rtems_unsigned32 _res0; + rtems_unsigned32 _res1; + rtems_unsigned16 max_idl; + rtems_unsigned16 _idlc; + rtems_unsigned16 brkcr; + rtems_unsigned16 parec; + rtems_unsigned16 frmec; + rtems_unsigned16 nosec; + rtems_unsigned16 brkec; + rtems_unsigned16 brklen; + rtems_unsigned16 uaddr[2]; + rtems_unsigned16 _rtemp; + rtems_unsigned16 toseq; + rtems_unsigned16 character[8]; + rtems_unsigned16 rccm; + rtems_unsigned16 rccr; + rtems_unsigned16 rlbc; + } uart; + struct { + rtems_unsigned32 c_pres; + rtems_unsigned32 c_mask; + rtems_unsigned32 crcec; + rtems_unsigned32 alec; + rtems_unsigned32 disfc; + rtems_unsigned16 pads; + rtems_unsigned16 ret_lim; + rtems_unsigned16 _ret_cnt; + rtems_unsigned16 mflr; + rtems_unsigned16 minflr; + rtems_unsigned16 maxd1; + rtems_unsigned16 maxd2; + rtems_unsigned16 _maxd; + rtems_unsigned16 dma_cnt; + rtems_unsigned16 _max_b; + rtems_unsigned16 gaddr1; + rtems_unsigned16 gaddr2; + rtems_unsigned16 gaddr3; + rtems_unsigned16 gaddr4; + rtems_unsigned32 _tbuf0data0; + rtems_unsigned32 _tbuf0data1; + rtems_unsigned32 _tbuf0rba0; + rtems_unsigned32 _tbuf0crc; + rtems_unsigned16 _tbuf0bcnt; + rtems_unsigned16 paddr_h; + rtems_unsigned16 paddr_m; + rtems_unsigned16 paddr_l; + rtems_unsigned16 p_per; + rtems_unsigned16 _rfbd_ptr; + rtems_unsigned16 _tfbd_ptr; + rtems_unsigned16 _tlbd_ptr; + rtems_unsigned32 _tbuf1data0; + rtems_unsigned32 _tbuf1data1; + rtems_unsigned32 _tbuf1rba0; + rtems_unsigned32 _tbuf1crc; + rtems_unsigned16 _tbuf1bcnt; + rtems_unsigned16 _tx_len; + rtems_unsigned16 iaddr1; + rtems_unsigned16 iaddr2; + rtems_unsigned16 iaddr3; + rtems_unsigned16 iaddr4; + rtems_unsigned16 _boff_cnt; + rtems_unsigned16 taddr_l; + rtems_unsigned16 taddr_m; + rtems_unsigned16 taddr_h; + } ethernet; + } un; +} m360SCCENparms_t; + +/* + * Receive and transmit function code register bits + * These apply to the function code registers of all devices, not just SCC. + */ +#define M360_RFCR_MOT (1<<4) +#define M360_RFCR_DMA_SPACE 0x8 +#define M360_TFCR_MOT (1<<4) +#define M360_TFCR_DMA_SPACE 0x8 + +/* + ************************************************************************* + * Serial Management Controllers * + ************************************************************************* + */ +typedef struct m360SMCparms_ { + rtems_unsigned16 rbase; + rtems_unsigned16 tbase; + rtems_unsigned8 rfcr; + rtems_unsigned8 tfcr; + rtems_unsigned16 mrblr; + rtems_unsigned32 _rstate; + rtems_unsigned32 _pad0; + rtems_unsigned16 _rbptr; + rtems_unsigned16 _pad1; + rtems_unsigned32 _pad2; + rtems_unsigned32 _tstate; + rtems_unsigned32 _pad3; + rtems_unsigned16 _tbptr; + rtems_unsigned16 _pad4; + rtems_unsigned32 _pad5; + union { + struct { + rtems_unsigned16 max_idl; + rtems_unsigned16 _pad0; + rtems_unsigned16 brklen; + rtems_unsigned16 brkec; + rtems_unsigned16 brkcr; + rtems_unsigned16 _r_mask; + } uart; + struct { + rtems_unsigned16 _pad0[5]; + } transparent; + } un; +} m360SMCparms_t; + +/* + * Mode register + */ +#define M360_SMCMR_CLEN(x) ((x)<<11) /* Character length */ +#define M360_SMCMR_2STOP (1<<10) /* 2 stop bits */ +#define M360_SMCMR_PARITY (1<<9) /* Enable parity */ +#define M360_SMCMR_EVEN (1<<8) /* Even parity */ +#define M360_SMCMR_SM_GCI (0<<4) /* GCI Mode */ +#define M360_SMCMR_SM_UART (2<<4) /* UART Mode */ +#define M360_SMCMR_SM_TRANSPARENT (3<<4) /* Transparent Mode */ +#define M360_SMCMR_DM_LOOPBACK (1<<2) /* Local loopback mode */ +#define M360_SMCMR_DM_ECHO (2<<2) /* Echo mode */ +#define M360_SMCMR_TEN (1<<1) /* Enable transmitter */ +#define M360_SMCMR_REN (1<<0) /* Enable receiver */ + +/* + * Event and mask registers (SMCE, SMCM) + */ +#define M360_SMCE_BRK (1<<4) +#define M360_SMCE_BSY (1<<2) +#define M360_SMCE_TX (1<<1) +#define M360_SMCE_RX (1<<0) + +/* + ************************************************************************* + * Serial Peripheral Interface * + ************************************************************************* + */ +typedef struct m360SPIparms_ { + rtems_unsigned16 rbase; + rtems_unsigned16 tbase; + rtems_unsigned8 rfcr; + rtems_unsigned8 tfcr; + rtems_unsigned16 mrblr; + rtems_unsigned32 _rstate; + rtems_unsigned32 _pad0; + rtems_unsigned16 _rbptr; + rtems_unsigned16 _pad1; + rtems_unsigned32 _pad2; + rtems_unsigned32 _tstate; + rtems_unsigned32 _pad3; + rtems_unsigned16 _tbptr; + rtems_unsigned16 _pad4; + rtems_unsigned32 _pad5; +} m360SPIparms_t; + +/* + * Mode register (SPMODE) + */ +#define M360_SPMODE_LOOP (1<<14) /* Local loopback mode */ +#define M360_SPMODE_CI (1<<13) /* Clock invert */ +#define M360_SPMODE_CP (1<<12) /* Clock phase */ +#define M360_SPMODE_DIV16 (1<<11) /* Divide BRGCLK by 16 */ +#define M360_SPMODE_REV (1<<10) /* Reverse data */ +#define M360_SPMODE_MASTER (1<<9) /* SPI is master */ +#define M360_SPMODE_EN (1<<8) /* Enable SPI */ +#define M360_SPMODE_CLEN(x) ((x)<<4) /* Character length */ +#define M360_SPMODE_PM(x) (x) /* Prescaler modulus */ + +/* + * Mode register (SPCOM) + */ +#define M360_SPCOM_STR (1<<7) /* Start transmit */ + +/* + * Event and mask registers (SPIE, SPIM) + */ +#define M360_SPIE_MME (1<<5) /* Multi-master error */ +#define M360_SPIE_TXE (1<<4) /* Tx error */ +#define M360_SPIE_BSY (1<<2) /* Busy condition*/ +#define M360_SPIE_TXB (1<<1) /* Tx buffer */ +#define M360_SPIE_RXB (1<<0) /* Rx buffer */ + +/* + ************************************************************************* + * SDMA (SCC, SMC, SPI) Buffer Descriptors * + ************************************************************************* + */ +typedef struct m360BufferDescriptor_ { + rtems_unsigned16 status; + rtems_unsigned16 length; + volatile void *buffer; +} m360BufferDescriptor_t; + +/* + * Bits in receive buffer descriptor status word + */ +#define M360_BD_EMPTY (1<<15) /* Ethernet, SCC UART, SMC UART, SPI */ +#define M360_BD_WRAP (1<<13) /* Ethernet, SCC UART, SMC UART, SPI */ +#define M360_BD_INTERRUPT (1<<12) /* Ethernet, SCC UART, SMC UART, SPI */ +#define M360_BD_LAST (1<<11) /* Ethernet, SPI */ +#define M360_BD_CONTROL_CHAR (1<<11) /* SCC UART */ +#define M360_BD_FIRST_IN_FRAME (1<<10) /* Ethernet */ +#define M360_BD_ADDRESS (1<<10) /* SCC UART */ +#define M360_BD_CONTINUOUS (1<<9) /* SCC UART, SMC UART, SPI */ +#define M360_BD_MISS (1<<8) /* Ethernet */ +#define M360_BD_IDLE (1<<8) /* SCC UART, SMC UART */ +#define M360_BD_ADDRSS_MATCH (1<<7) /* SCC UART */ +#define M360_BD_LONG (1<<5) /* Ethernet */ +#define M360_BD_BREAK (1<<5) /* SCC UART, SMC UART */ +#define M360_BD_NONALIGNED (1<<4) /* Ethernet */ +#define M360_BD_FRAMING_ERROR (1<<4) /* SCC UART, SMC UART */ +#define M360_BD_SHORT (1<<3) /* Ethernet */ +#define M360_BD_PARITY_ERROR (1<<3) /* SCC UART, SMC UART */ +#define M360_BD_CRC_ERROR (1<<2) /* Ethernet */ +#define M360_BD_OVERRUN (1<<1) /* Ethernet, SCC UART, SMC UART, SPI */ +#define M360_BD_COLLISION (1<<0) /* Ethernet */ +#define M360_BD_CARRIER_LOST (1<<0) /* SCC UART */ +#define M360_BD_MASTER_ERROR (1<<0) /* SPI */ + +/* + * Bits in transmit buffer descriptor status word + * Many bits have the same meaning as those in receiver buffer descriptors. + */ +#define M360_BD_READY (1<<15) /* Ethernet, SCC UART, SMC UART, SPI */ +#define M360_BD_PAD (1<<14) /* Ethernet */ +#define M360_BD_CTS_REPORT (1<<11) /* SCC UART */ +#define M360_BD_TX_CRC (1<<10) /* Ethernet */ +#define M360_BD_DEFER (1<<9) /* Ethernet */ +#define M360_BD_HEARTBEAT (1<<8) /* Ethernet */ +#define M360_BD_PREAMBLE (1<<8) /* SCC UART, SMC UART */ +#define M360_BD_LATE_COLLISION (1<<7) /* Ethernet */ +#define M360_BD_NO_STOP_BIT (1<<7) /* SCC UART */ +#define M360_BD_RETRY_LIMIT (1<<6) /* Ethernet */ +#define M360_BD_RETRY_COUNT(x) (((x)&0x3C)>>2) /* Ethernet */ +#define M360_BD_UNDERRUN (1<<1) /* Ethernet, SPI */ +#define M360_BD_CARRIER_LOST (1<<0) /* Ethernet */ +#define M360_BD_CTS_LOST (1<<0) /* SCC UART */ + +/* + ************************************************************************* + * IDMA Buffer Descriptors * + ************************************************************************* + */ +typedef struct m360IDMABufferDescriptor_ { + rtems_unsigned16 status; + rtems_unsigned16 _pad; + rtems_unsigned32 length; + void *source; + void *destination; +} m360IDMABufferDescriptor_t; + +/* + ************************************************************************* + * RISC Communication Processor Module Command Register (CR) * + ************************************************************************* + */ +#define M360_CR_RST (1<<15) /* Reset communication processor */ +#define M360_CR_OP_INIT_RX_TX (0<<8) /* SCC, SMC UART, SMC GCI, SPI */ +#define M360_CR_OP_INIT_RX (1<<8) /* SCC, SMC UART, SPI */ +#define M360_CR_OP_INIT_TX (2<<8) /* SCC, SMC UART, SPI */ +#define M360_CR_OP_INIT_HUNT (3<<8) /* SCC, SMC UART */ +#define M360_CR_OP_STOP_TX (4<<8) /* SCC, SMC UART */ +#define M360_CR_OP_GR_STOP_TX (5<<8) /* SCC */ +#define M360_CR_OP_INIT_IDMA (5<<8) /* IDMA */ +#define M360_CR_OP_RESTART_TX (6<<8) /* SCC, SMC UART */ +#define M360_CR_OP_CLOSE_RX_BD (7<<8) /* SCC, SMC UART, SPI */ +#define M360_CR_OP_SET_GRP_ADDR (8<<8) /* SCC */ +#define M360_CR_OP_SET_TIMER (8<<8) /* Timer */ +#define M360_CR_OP_GCI_TIMEOUT (9<<8) /* SMC GCI */ +#define M360_CR_OP_RESERT_BCS (10<<8) /* SCC */ +#define M360_CR_OP_GCI_ABORT (10<<8) /* SMC GCI */ +#define M360_CR_CHAN_SCC1 (0<<4) /* Channel selection */ +#define M360_CR_CHAN_SCC2 (4<<4) +#define M360_CR_CHAN_SPI (5<<4) +#define M360_CR_CHAN_TIMER (5<<4) +#define M360_CR_CHAN_SCC3 (8<<4) +#define M360_CR_CHAN_SMC1 (9<<4) +#define M360_CR_CHAN_IDMA1 (9<<4) +#define M360_CR_CHAN_SCC4 (12<<4) +#define M360_CR_CHAN_SMC2 (13<<4) +#define M360_CR_CHAN_IDMA2 (13<<4) +#define M360_CR_FLG (1<<0) /* Command flag */ + +/* + ************************************************************************* + * System Protection Control Register (SYPCR) * + ************************************************************************* + */ +#define M360_SYPCR_SWE (1<<7) /* Software watchdog enable */ +#define M360_SYPCR_SWRI (1<<6) /* Software watchdog reset select */ +#define M360_SYPCR_SWT1 (1<<5) /* Software watchdog timing bit 1 */ +#define M360_SYPCR_SWT0 (1<<4) /* Software watchdog timing bit 0 */ +#define M360_SYPCR_DBFE (1<<3) /* Double bus fault monitor enable */ +#define M360_SYPCR_BME (1<<2) /* Bus monitor external enable */ +#define M360_SYPCR_BMT1 (1<<1) /* Bus monitor timing bit 1 */ +#define M360_SYPCR_BMT0 (1<<0) /* Bus monitor timing bit 0 */ + +/* + ************************************************************************* + * Memory Control Registers * + ************************************************************************* + */ +#define M360_GMR_RCNT(x) ((x)<<24) /* Refresh count */ +#define M360_GMR_RFEN (1<<23) /* Refresh enable */ +#define M360_GMR_RCYC(x) ((x)<<21) /* Refresh cycle length */ +#define M360_GMR_PGS(x) ((x)<<18) /* Page size */ +#define M360_GMR_DPS_32BIT (0<<16) /* DRAM port size */ +#define M360_GMR_DPS_16BIT (1<<16) +#define M360_GMR_DPS_8BIT (2<<16) +#define M360_GMR_DPS_DSACK (3<<16) +#define M360_GMR_WBT40 (1<<15) /* Wait between 040 transfers */ +#define M360_GMR_WBTQ (1<<14) /* Wait between 360 transfers */ +#define M360_GMR_SYNC (1<<13) /* Synchronous external access */ +#define M360_GMR_EMWS (1<<12) /* External master wait state */ +#define M360_GMR_OPAR (1<<11) /* Odd parity */ +#define M360_GMR_PBEE (1<<10) /* Parity bus error enable */ +#define M360_GMR_TSS40 (1<<9) /* TS* sample for 040 */ +#define M360_GMR_NCS (1<<8) /* No CPU space */ +#define M360_GMR_DWQ (1<<7) /* Delay write for 360 */ +#define M360_GMR_DW40 (1<<6) /* Delay write for 040 */ +#define M360_GMR_GAMX (1<<5) /* Global address mux enable */ + +#define M360_MEMC_BR_FC(x) ((x)<<7) /* Function code limit */ +#define M360_MEMC_BR_TRLXQ (1<<6) /* Relax timing requirements */ +#define M360_MEMC_BR_BACK40 (1<<5) /* Burst acknowledge to 040 */ +#define M360_MEMC_BR_CSNT40 (1<<4) /* CS* negate timing for 040 */ +#define M360_MEMC_BR_CSNTQ (1<<3) /* CS* negate timing for 360 */ +#define M360_MEMC_BR_PAREN (1<<2) /* Enable parity checking */ +#define M360_MEMC_BR_WP (1<<1) /* Write Protect */ +#define M360_MEMC_BR_V (1<<0) /* Base/Option register are valid */ + +#define M360_MEMC_OR_TCYC(x) ((x)<<28) /* Cycle length (clocks) */ +#define M360_MEMC_OR_WAITS(x) M360_MEMC_OR_TCYC((x)+1) +#define M360_MEMC_OR_2KB 0x0FFFF800 /* Address range */ +#define M360_MEMC_OR_4KB 0x0FFFF000 +#define M360_MEMC_OR_8KB 0x0FFFE000 +#define M360_MEMC_OR_16KB 0x0FFFC000 +#define M360_MEMC_OR_32KB 0x0FFF8000 +#define M360_MEMC_OR_64KB 0x0FFF0000 +#define M360_MEMC_OR_128KB 0x0FFE0000 +#define M360_MEMC_OR_256KB 0x0FFC0000 +#define M360_MEMC_OR_512KB 0x0FF80000 +#define M360_MEMC_OR_1MB 0x0FF00000 +#define M360_MEMC_OR_2MB 0x0FE00000 +#define M360_MEMC_OR_4MB 0x0FC00000 +#define M360_MEMC_OR_8MB 0x0F800000 +#define M360_MEMC_OR_16MB 0x0F000000 +#define M360_MEMC_OR_32MB 0x0E000000 +#define M360_MEMC_OR_64MB 0x0C000000 +#define M360_MEMC_OR_128MB 0x08000000 +#define M360_MEMC_OR_256MB 0x00000000 +#define M360_MEMC_OR_FCMC(x) ((x)<<7) /* Function code mask */ +#define M360_MEMC_OR_BCYC(x) ((x)<<5) /* Burst cycle length (clocks) */ +#define M360_MEMC_OR_PGME (1<<3) /* Page mode enable */ +#define M360_MEMC_OR_32BIT (0<<1) /* Port size */ +#define M360_MEMC_OR_16BIT (1<<1) +#define M360_MEMC_OR_8BIT (2<<1) +#define M360_MEMC_OR_DSACK (3<<1) +#define M360_MEMC_OR_DRAM (1<<0) /* Dynamic RAM select */ + +/* + ************************************************************************* + * SI Mode Register (SIMODE) * + ************************************************************************* + */ +#define M360_SI_SMC2_BITS 0xFFFF0000 /* All SMC2 bits */ +#define M360_SI_SMC2_TDM (1<<31) /* Multiplexed SMC2 */ +#define M360_SI_SMC2_BRG1 (0<<28) /* SMC2 clock souce */ +#define M360_SI_SMC2_BRG2 (1<<28) +#define M360_SI_SMC2_BRG3 (2<<28) +#define M360_SI_SMC2_BRG4 (3<<28) +#define M360_SI_SMC2_CLK5 (0<<28) +#define M360_SI_SMC2_CLK6 (1<<28) +#define M360_SI_SMC2_CLK7 (2<<28) +#define M360_SI_SMC2_CLK8 (3<<28) +#define M360_SI_SMC1_BITS 0x0000FFFF /* All SMC1 bits */ +#define M360_SI_SMC1_TDM (1<<15) /* Multiplexed SMC1 */ +#define M360_SI_SMC1_BRG1 (0<<12) /* SMC1 clock souce */ +#define M360_SI_SMC1_BRG2 (1<<12) +#define M360_SI_SMC1_BRG3 (2<<12) +#define M360_SI_SMC1_BRG4 (3<<12) +#define M360_SI_SMC1_CLK1 (0<<12) +#define M360_SI_SMC1_CLK2 (1<<12) +#define M360_SI_SMC1_CLK3 (2<<12) +#define M360_SI_SMC1_CLK4 (3<<12) + +/* + ************************************************************************* + * SDMA Configuration Register (SDMA) * + ************************************************************************* + */ +#define M360_SDMA_FREEZE (2<<13) /* Freeze on next bus cycle */ +#define M360_SDMA_SISM_7 (7<<8) /* Normal interrupt service mask */ +#define M360_SDMA_SAID_4 (4<<4) /* Normal arbitration ID */ +#define M360_SDMA_INTE (1<<1) /* SBER interrupt enable */ +#define M360_SDMA_INTB (1<<0) /* SBKP interrupt enable */ + +/* + ************************************************************************* + * Baud (sic) Rate Generators * + ************************************************************************* + */ +#define M360_BRG_RST (1<<17) /* Reset generator */ +#define M360_BRG_EN (1<<16) /* Enable generator */ +#define M360_BRG_EXTC_BRGCLK (0<<14) /* Source is BRGCLK */ +#define M360_BRG_EXTC_CLK2 (1<<14) /* Source is CLK2 pin */ +#define M360_BRG_EXTC_CLK6 (2<<14) /* Source is CLK6 pin */ +#define M360_BRG_ATB (1<<13) /* Autobaud */ +#define M360_BRG_115200 (13<<1) /* Assume 25 MHz clock */ +#define M360_BRG_57600 (26<<1) +#define M360_BRG_38400 (40<<1) +#define M360_BRG_19200 (80<<1) +#define M360_BRG_9600 (162<<1) +#define M360_BRG_4800 (324<<1) +#define M360_BRG_2400 (650<<1) +#define M360_BRG_1200 (1301<<1) +#define M360_BRG_600 (2603<<1) +#define M360_BRG_300 ((324<<1) | 1) +#define M360_BRG_150 ((650<<1) | 1) +#define M360_BRG_75 ((1301<<1) | 1) + +/* + ************************************************************************* + * MC68360 DUAL-PORT RAM AND REGISTERS * + ************************************************************************* + */ +typedef struct m360_ { + /* + * Dual-port RAM + */ + rtems_unsigned8 dpram0[0x400]; /* Microcode program */ + rtems_unsigned8 dpram1[0x200]; + rtems_unsigned8 dpram2[0x100]; /* Microcode scratch */ + rtems_unsigned8 dpram3[0x100]; /* Not on REV A or B masks */ + rtems_unsigned8 _rsv0[0xC00-0x800]; + m360SCCENparms_t scc1p; + rtems_unsigned8 _rsv1[0xCB0-0xC00-sizeof(m360SCCENparms_t)]; + m360MiscParms_t miscp; + rtems_unsigned8 _rsv2[0xD00-0xCB0-sizeof(m360MiscParms_t)]; + m360SCCparms_t scc2p; + rtems_unsigned8 _rsv3[0xD80-0xD00-sizeof(m360SCCparms_t)]; + m360SPIparms_t spip; + rtems_unsigned8 _rsv4[0xDB0-0xD80-sizeof(m360SPIparms_t)]; + m360TimerParms_t tmp; + rtems_unsigned8 _rsv5[0xE00-0xDB0-sizeof(m360TimerParms_t)]; + m360SCCparms_t scc3p; + rtems_unsigned8 _rsv6[0xE70-0xE00-sizeof(m360SCCparms_t)]; + m360IDMAparms_t idma1p; + rtems_unsigned8 _rsv7[0xE80-0xE70-sizeof(m360IDMAparms_t)]; + m360SMCparms_t smc1p; + rtems_unsigned8 _rsv8[0xF00-0xE80-sizeof(m360SMCparms_t)]; + m360SCCparms_t scc4p; + rtems_unsigned8 _rsv9[0xF70-0xF00-sizeof(m360SCCparms_t)]; + m360IDMAparms_t idma2p; + rtems_unsigned8 _rsv10[0xF80-0xF70-sizeof(m360IDMAparms_t)]; + m360SMCparms_t smc2p; + rtems_unsigned8 _rsv11[0x1000-0xF80-sizeof(m360SMCparms_t)]; + + /* + * SIM Block + */ + rtems_unsigned32 mcr; + rtems_unsigned32 _pad00; + rtems_unsigned8 avr; + rtems_unsigned8 rsr; + rtems_unsigned16 _pad01; + rtems_unsigned8 clkocr; + rtems_unsigned8 _pad02; + rtems_unsigned16 _pad03; + rtems_unsigned16 pllcr; + rtems_unsigned16 _pad04; + rtems_unsigned16 cdvcr; + rtems_unsigned16 pepar; + rtems_unsigned32 _pad05[2]; + rtems_unsigned16 _pad06; + rtems_unsigned8 sypcr; + rtems_unsigned8 swiv; + rtems_unsigned16 _pad07; + rtems_unsigned16 picr; + rtems_unsigned16 _pad08; + rtems_unsigned16 pitr; + rtems_unsigned16 _pad09; + rtems_unsigned8 _pad10; + rtems_unsigned8 swsr; + rtems_unsigned32 bkar; + rtems_unsigned32 bcar; + rtems_unsigned32 _pad11[2]; + + /* + * MEMC Block + */ + rtems_unsigned32 gmr; + rtems_unsigned16 mstat; + rtems_unsigned16 _pad12; + rtems_unsigned32 _pad13[2]; + m360MEMCRegisters_t memc[8]; + rtems_unsigned8 _pad14[0xF0-0xD0]; + rtems_unsigned8 _pad15[0x100-0xF0]; + rtems_unsigned8 _pad16[0x500-0x100]; + + /* + * IDMA1 Block + */ + rtems_unsigned16 iccr; + rtems_unsigned16 _pad17; + rtems_unsigned16 cmr1; + rtems_unsigned16 _pad18; + rtems_unsigned32 sapr1; + rtems_unsigned32 dapr1; + rtems_unsigned32 bcr1; + rtems_unsigned8 fcr1; + rtems_unsigned8 _pad19; + rtems_unsigned8 cmar1; + rtems_unsigned8 _pad20; + rtems_unsigned8 csr1; + rtems_unsigned8 _pad21; + rtems_unsigned16 _pad22; + + /* + * SDMA Block + */ + rtems_unsigned8 sdsr; + rtems_unsigned8 _pad23; + rtems_unsigned16 sdcr; + rtems_unsigned32 sdar; + + /* + * IDMA2 Block + */ + rtems_unsigned16 _pad24; + rtems_unsigned16 cmr2; + rtems_unsigned32 sapr2; + rtems_unsigned32 dapr2; + rtems_unsigned32 bcr2; + rtems_unsigned8 fcr2; + rtems_unsigned8 _pad26; + rtems_unsigned8 cmar2; + rtems_unsigned8 _pad27; + rtems_unsigned8 csr2; + rtems_unsigned8 _pad28; + rtems_unsigned16 _pad29; + rtems_unsigned32 _pad30; + + /* + * CPIC Block + */ + rtems_unsigned32 cicr; + rtems_unsigned32 cipr; + rtems_unsigned32 cimr; + rtems_unsigned32 cisr; + + /* + * Parallel I/O Block + */ + rtems_unsigned16 padir; + rtems_unsigned16 papar; + rtems_unsigned16 paodr; + rtems_unsigned16 padat; + rtems_unsigned32 _pad31[2]; + rtems_unsigned16 pcdir; + rtems_unsigned16 pcpar; + rtems_unsigned16 pcso; + rtems_unsigned16 pcdat; + rtems_unsigned16 pcint; + rtems_unsigned16 _pad32; + rtems_unsigned32 _pad33[5]; + + /* + * TIMER Block + */ + rtems_unsigned16 tgcr; + rtems_unsigned16 _pad34; + rtems_unsigned32 _pad35[3]; + rtems_unsigned16 tmr1; + rtems_unsigned16 tmr2; + rtems_unsigned16 trr1; + rtems_unsigned16 trr2; + rtems_unsigned16 tcr1; + rtems_unsigned16 tcr2; + rtems_unsigned16 tcn1; + rtems_unsigned16 tcn2; + rtems_unsigned16 tmr3; + rtems_unsigned16 tmr4; + rtems_unsigned16 trr3; + rtems_unsigned16 trr4; + rtems_unsigned16 tcr3; + rtems_unsigned16 tcr4; + rtems_unsigned16 tcn3; + rtems_unsigned16 tcn4; + rtems_unsigned16 ter1; + rtems_unsigned16 ter2; + rtems_unsigned16 ter3; + rtems_unsigned16 ter4; + rtems_unsigned32 _pad36[2]; + + /* + * CP Block + */ + rtems_unsigned16 cr; + rtems_unsigned16 _pad37; + rtems_unsigned16 rccr; + rtems_unsigned16 _pad38; + rtems_unsigned32 _pad39[3]; + rtems_unsigned16 _pad40; + rtems_unsigned16 rter; + rtems_unsigned16 _pad41; + rtems_unsigned16 rtmr; + rtems_unsigned32 _pad42[5]; + + /* + * BRG Block + */ + rtems_unsigned32 brgc1; + rtems_unsigned32 brgc2; + rtems_unsigned32 brgc3; + rtems_unsigned32 brgc4; + + /* + * SCC Block + */ + m360SCCRegisters_t scc1; + m360SCCRegisters_t scc2; + m360SCCRegisters_t scc3; + m360SCCRegisters_t scc4; + + /* + * SMC Block + */ + m360SMCRegisters_t smc1; + m360SMCRegisters_t smc2; + + /* + * SPI Block + */ + rtems_unsigned16 spmode; + rtems_unsigned16 _pad43[2]; + rtems_unsigned8 spie; + rtems_unsigned8 _pad44; + rtems_unsigned16 _pad45; + rtems_unsigned8 spim; + rtems_unsigned8 _pad46[2]; + rtems_unsigned8 spcom; + rtems_unsigned16 _pad47[2]; + + /* + * PIP Block + */ + rtems_unsigned16 pipc; + rtems_unsigned16 _pad48; + rtems_unsigned16 ptpr; + rtems_unsigned32 pbdir; + rtems_unsigned32 pbpar; + rtems_unsigned16 _pad49; + rtems_unsigned16 pbodr; + rtems_unsigned32 pbdat; + rtems_unsigned32 _pad50[6]; + + /* + * SI Block + */ + rtems_unsigned32 simode; + rtems_unsigned8 sigmr; + rtems_unsigned8 _pad51; + rtems_unsigned8 sistr; + rtems_unsigned8 sicmr; + rtems_unsigned32 _pad52; + rtems_unsigned32 sicr; + rtems_unsigned16 _pad53; + rtems_unsigned16 sirp[2]; + rtems_unsigned16 _pad54; + rtems_unsigned32 _pad55[2]; + rtems_unsigned8 siram[256]; +} m360_t; + +extern volatile m360_t m360; + +#endif /* __MC68360_h */ diff --git a/cpukit/score/cpu/m68k/rtems/m68k/qsm.h b/cpukit/score/cpu/m68k/rtems/m68k/qsm.h new file mode 100644 index 0000000000..e1bf33bc12 --- /dev/null +++ b/cpukit/score/cpu/m68k/rtems/m68k/qsm.h @@ -0,0 +1,209 @@ +/* + *------------------------------------------------------------------- + * + * QSM -- Queued Serial Module + * + * The QSM contains two serial interfaces: (a) the queued serial + * peripheral interface (QSPI) and the serial communication interface + * (SCI). The QSPI provides peripheral expansion and/or interprocessor + * communication through a full-duplex, synchronous, three-wire bus. A + * self contained RAM queue permits serial data transfers without CPU + * intervention and automatic continuous sampling. The SCI provides a + * standard non-return to zero mark/space format with wakeup functions + * to allow the CPU to run uninterrupted until woken + * + * For more information, refer to Motorola's "Modular Microcontroller + * Family Queued Serial Module Reference Manual" (Motorola document + * QSMRM/AD). + * + * This file has been created by John S. Gwynne for support of + * Motorola's 68332 MCU in the efi332 project. + * + * Redistribution and use in source and binary forms are permitted + * provided that the following conditions are met: + * 1. Redistribution of source code and documentation must retain + * the above authorship, this list of conditions and the + * following disclaimer. + * 2. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * This software is provided "AS IS" without warranty of any kind, + * either expressed or implied, including, but not limited to, the + * implied warranties of merchantability, title and fitness for a + * particular purpose. + * + *------------------------------------------------------------------ + * + * $Id$ + */ + +#ifndef _QSM_H_ +#define _QSM_H_ + + +#include <efi332.h> + + +/* SAM-- shift and mask */ +#undef SAM +#define SAM(a,b,c) ((a << b) & c) + + +/* QSM_CRB (QSM Control Register Block) base address of the QSM + control registers */ +#if SIM_MM == 0 +#define QSM_CRB 0x7ffc00 +#else +#undef SIM_MM +#define SIM_MM 1 +#define QSM_CRB 0xfffc00 +#endif + + +#define QSMCR (volatile unsigned short int * const)(0x00 + QSM_CRB) + /* QSM Configuration Register */ +#define STOP 0x8000 /* Stop Enable */ +#define FRZ 0x6000 /* Freeze Control */ +#define SUPV 0x0080 /* Supervisor/Unrestricted */ +#define IARB 0x000f /* Inerrupt Arbitration */ + + +#define QTEST (volatile unsigned short int * const)(0x02 + QSM_CRB) + /* QSM Test Register */ +/* Used only for factor testing */ + + +#define QILR (volatile unsigned char * const)(0x04 + QSM_CRB) + /* QSM Interrupt Level Register */ +#define ILQSPI 0x38 /* Interrupt Level for QSPI */ +#define ILSCI 0x07 /* Interrupt Level for SCI */ + + +#define QIVR (volatile unsigned char * const)(0x05 + QSM_CRB) + /* QSM Interrupt Vector Register */ +#define INTV 0xff /* Interrupt Vector Number */ + + +#define SCCR0 (volatile unsigned short int * const)(0x08 + QSM_CRB) + /* SCI Control Register 0 */ +#define SCBR 0x1fff /* SCI Baud Rate */ + + +#define SCCR1 (volatile unsigned short int * const)(0x0a + QSM_CRB) + /* SCI Control Register 1 */ +#define LOOPS 0x4000 /* Loop Mode */ +#define WOMS 0x2000 /* Wired-OR Mode for SCI Pins */ +#define ILT 0x1000 /* Idle-Line Detect Type */ +#define PT 0x0800 /* Parity Type */ +#define PE 0x0400 /* Parity Enable */ +#define M 0x0200 /* Mode Select */ +#define WAKE 0x0100 /* Wakeup by Address Mark */ +#define TIE 0x0080 /* Transmit Complete Interrupt Enable */ +#define TCIE 0x0040 /* Transmit Complete Interrupt Enable */ +#define RIE 0x0020 /* Receiver Interrupt Enable */ +#define ILIE 0x0010 /* Idle-Line Interrupt Enable */ +#define TE 0x0008 /* Transmitter Enable */ +#define RE 0x0004 /* Receiver Enable */ +#define RWU 0x0002 /* Receiver Wakeup */ +#define SBK 0x0001 /* Send Break */ + + +#define SCSR (volatile unsigned short int * const)(0x0c + QSM_CRB) + /* SCI Status Register */ +#define TDRE 0x0100 /* Transmit Data Register Empty */ +#define TC 0x0080 /* Transmit Complete */ +#define RDRF 0x0040 /* Receive Data Register Full */ +#define RAF 0x0020 /* Receiver Active */ +#define IDLE 0x0010 /* Idle-Line Detected */ +#define OR 0x0008 /* Overrun Error */ +#define NF 0x0004 /* Noise Error Flag */ +#define FE 0x0002 /* Framing Error */ +#define PF 0x0001 /* Parity Error */ + + +#define SCDR (volatile unsigned short int * const)(0x0e + QSM_CRB) + /* SCI Data Register */ + + +#define PORTQS (volatile unsigned char * const)(0x15 + QSM_CRB) + /* Port QS Data Register */ + +#define PQSPAR (volatile unsigned char * const)(0x16 + QSM_CRB) + /* PORT QS Pin Assignment Rgister */ +/* Any bit cleared (zero) defines the corresponding pin to be an I/O + pin. Any bit set defines the corresponding pin to be a QSPI + signal. */ +/* note: PQS2 is a digital I/O pin unless the SPI is enabled in which + case it becomes the SPI serial clock SCK. */ +/* note: PQS7 is a digital I/O pin unless the SCI transmitter is + enabled in which case it becomes the SCI serial output TxD. */ +#define QSMFun 0x0 +#define QSMDis 0x1 +/* + * PQSPAR Field | QSM Function | Discrete I/O pin + *------------------+--------------+------------------ */ +#define PQSPA0 0 /* MISO | PQS0 */ +#define PQSPA1 1 /* MOSI | PQS1 */ +#define PQSPA2 2 /* SCK | PQS2 (see note)*/ +#define PQSPA3 3 /* PCSO/!SS | PQS3 */ +#define PQSPA4 4 /* PCS1 | PQS4 */ +#define PQSPA5 5 /* PCS2 | PQS5 */ +#define PQSPA6 6 /* PCS3 | PQS6 */ +#define PQSPA7 7 /* TxD | PQS7 (see note)*/ + + +#define DDRQS (volatile unsigned char * const)(0x17 + QSM_CRB) + /* PORT QS Data Direction Register */ +/* Clearing a bit makes the corresponding pin an input; setting a bit + makes the pin an output. */ + + +#define SPCR0 (volatile unsigned short int * const)(0x18 + QSM_CRB) + /* QSPI Control Register 0 */ +#define MSTR 0x8000 /* Master/Slave Mode Select */ +#define WOMQ 0x4000 /* Wired-OR Mode for QSPI Pins */ +#define BITS 0x3c00 /* Bits Per Transfer */ +#define CPOL 0x0200 /* Clock Polarity */ +#define CPHA 0x0100 /* Clock Phase */ +#define SPBR 0x00ff /* Serial Clock Baud Rate */ + + +#define SPCR1 (volatile unsigned short int * const)(0x1a + QSM_CRB) + /* QSPI Control Register 1 */ +#define SPE 0x8000 /* QSPI Enable */ +#define DSCKL 0x7f00 /* Delay before SCK */ +#define DTL 0x00ff /* Length of Delay after Transfer */ + + +#define SPCR2 (volatile unsigned short int * const)(0x1c + QSM_CRB) + /* QSPI Control Register 2 */ +#define SPIFIE 0x8000 /* SPI Finished Interrupt Enable */ +#define WREN 0x4000 /* Wrap Enable */ +#define WRTO 0x2000 /* Wrap To */ +#define ENDQP 0x0f00 /* Ending Queue Pointer */ +#define NEWQP 0x000f /* New Queue Pointer Value */ + + +#define SPCR3 (volatile unsigned char * const)(0x1e + QSM_CRB) + /* QSPI Control Register 3 */ +#define LOOPQ 0x0400 /* QSPI Loop Mode */ +#define HMIE 0x0200 /* HALTA and MODF Interrupt Enable */ +#define HALT 0x0100 /* Halt */ + + +#define SPSR (volatile unsigned char * const)(0x1f + QSM_CRB) + /* QSPI Status Register */ +#define SPIF 0x0080 /* QSPI Finished Flag */ +#define MODF 0x0040 /* Mode Fault Flag */ +#define HALTA 0x0020 /* Halt Acknowlwdge Flag */ +#define CPTQP x0000f /* Completed Queue Pointer */ + +#define QSPIRR (volatile unsigned char * const)(0x100 + QSM_CRB) + /* QSPI Receive Data RAM */ +#define QSPITR (volatile unsigned char * const)(0x120 + QSM_CRB) + /* QSPI Transmit Data RAM */ +#define QSPIcR (volatile unsigned char * const)(0x140 + QSM_CRB) + /* QSPI Command RAM */ + +#endif /* _QSM_H_ */ diff --git a/cpukit/score/cpu/m68k/rtems/m68k/sim.h b/cpukit/score/cpu/m68k/rtems/m68k/sim.h new file mode 100644 index 0000000000..fae7fe8783 --- /dev/null +++ b/cpukit/score/cpu/m68k/rtems/m68k/sim.h @@ -0,0 +1,328 @@ +/* + *------------------------------------------------------------------- + * + * SIM -- System Integration Module + * + * The system integration module (SIM) is used on many Motorola 16- + * and 32-bit MCUs for the following functions: + * + * () System configuration and protection. Bus and software watchdog + * monitors are provided in addition to periodic interrupt generators. + * + * () Clock signal generation for other intermodule bus (IMB) members + * and external devices. + * + * () The generation of chip-select signals that simplify external + * circuitry interface. + * + * () Data ports that are available for general purpose input and + * output. + * + * () A system test block that is intended only for factory tests. + * + * For more information, refer to Motorola's "Modular Microcontroller + * Family System Integration Module Reference Manual" (Motorola document + * SIMRM/AD). + * + * This file has been created by John S. Gwynne for support of + * Motorola's 68332 MCU in the efi332 project. + * + * Redistribution and use in source and binary forms are permitted + * provided that the following conditions are met: + * 1. Redistribution of source code and documentation must retain + * the above authorship, this list of conditions and the + * following disclaimer. + * 2. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * This software is provided "AS IS" without warranty of any kind, + * either expressed or implied, including, but not limited to, the + * implied warranties of merchantability, title and fitness for a + * particular purpose. + * + *------------------------------------------------------------------ + * + * $Id$ + */ + +#ifndef _SIM_H_ +#define _SIM_H_ + + +#include <efi332.h> + + +/* SAM-- shift and mask */ +#undef SAM +#define SAM(a,b,c) ((a << b) & c) + + + +/* SIM_CRB (SIM Control Register Block) base address of the SIM + control registers */ +/* not included in ram_init.h */ +#if SIM_MM == 0 +#define SIM_CRB 0x7ffa00 +#else +#undef SIM_MM +#define SIM_MM 1 +#define SIM_CRB 0xfffa00 +#endif +/* end not included in ram_init.h */ + + + +#define SIMCR (volatile unsigned short int * const)(0x00 + SIM_CRB) + /* Module Configuration Register */ +#define EXOFF 0x8000 /* External Clock Off */ +#define FRZSW 0x4000 /* Freeze Software Enable */ +#define FRZBM 0x2000 /* Freeze Bus Monitor Enable */ +#define SLVEN 0x0800 /* Factory Test Model Enabled (ro)*/ +#define SHEN 0x0300 /* Show Cycle Enable */ +#define SUPV 0x0080 /* Supervisor/Unrestricted Data Space */ +#define MM 0x0040 /* Module Mapping */ +#define IARB 0x000f /* Interrupt Arbitration Field */ + + + +#define SIMTR (volatile unsigned short int * const)(0x02 + SIM_CRB) + /* SIM Test Register */ +/* Used only for factor testing */ + + + +#define SYNCR (volatile unsigned short int * const)(0x04 + SIM_CRB) + /* Clock Synthesizer Control Register */ +#define W 0x8000 /* Frequency Control (VCO) */ +#define X 0x4000 /* Frequency Control Bit (Prescale) */ +#define Y 0x3f00 /* Frequency Control Counter */ +#define EDIV 0x0080 /* ECLK Divide Rate */ +#define SLIMP 0x0010 /* Limp Mode Status */ +#define SLOCK 0x0008 /* Synthesizer Lock */ +#define RSTEN 0x0004 /* Reset Enable */ +#define STSIM 0x0002 /* Stop Mode SIM Clock */ +#define STEXT 0x0001 /* Stop Mode External Clock */ + + + +#define RSR (volatile unsigned char * const)(0x07 + SIM_CRB) + /* Reset Status Register */ +#define EXT 0x0080 /* External Reset */ +#define POW 0x0040 /* Power-On Reset */ +#define SW 0x0020 /* Software Watchdog Reset */ +#define DBF 0x0010 /* Double Bus Fault Reset */ +#define LOC 0x0004 /* Loss of Clock Reset */ +#define SYS 0x0002 /* System Reset */ +#define TST 0x0001 /* Test Submodule Reset */ + + + +#define SIMTRE (volatile unsigned short int * const)(0x08 + SIM_CRB) + /* System Integration Test Register */ +/* Used only for factor testing */ + + + +#define PORTE0 (volatile unsigned char * const)(0x11 + SIM_CRB) +#define PORTE1 (volatile unsigned char * const)(0x13 + SIM_CRB) + /* Port E Data Register */ +#define DDRE (volatile unsigned char * const)(0x15 + SIM_CRB) + /* Port E Data Direction Register */ +#define PEPAR (volatile unsigned char * const)(0x17 + SIM_CRB) + /* Port E Pin Assignment Register */ +/* Any bit cleared (zero) defines the corresponding pin to be an I/O + pin. Any bit set defines the corresponding pin to be a bus control + signal. */ + + + +#define PORTF0 (volatile unsigned char * const)(0x19 + SIM_CRB) +#define PORTF1 (volatile unsigned char * const)(0x1b + SIM_CRB) + /* Port F Data Register */ +#define DDRF (volatile unsigned char * const)(0x1d + SIM_CRB) + /* Port E Data Direction Register */ +#define PFPAR (volatile unsigned char * const)(0x1f + SIM_CRB) +/* Any bit cleared (zero) defines the corresponding pin to be an I/O + pin. Any bit set defines the corresponding pin to be a bus control + signal. */ + + + +#define SYPCR (volatile unsigned char * const)(0x21 + SIM_CRB) +/* !!! can write to only once after reset !!! */ + /* System Protection Control Register */ +#define SWE 0x80 /* Software Watch Enable */ +#define SWP 0x40 /* Software Watchdog Prescale */ +#define SWT 0x30 /* Software Watchdog Timing */ +#define HME 0x08 /* Halt Monitor Enable */ +#define BME 0x04 /* Bus Monitor External Enable */ +#define BMT 0x03 /* Bus Monitor Timing */ + + + +#define PICR (volatile unsigned short int * const)(0x22 + SIM_CRB) + /* Periodic Interrupt Control Reg. */ +#define PIRQL 0x0700 /* Periodic Interrupt Request Level */ +#define PIV 0x00ff /* Periodic Interrupt Level */ + + + +#define PITR (volatile unsigned short int * const)(0x24 + SIM_CRB) + /* Periodic Interrupt Timer Register */ +#define PTP 0x0100 /* Periodic Timer Prescaler Control */ +#define PITM 0x00ff /* Periodic Interrupt Timing Modulus */ + + + +#define SWSR (volatile unsigned char * const)(0x27 + SIM_CRB) + /* Software Service Register */ +/* write 0x55 then 0xaa to service the software watchdog */ + + + +#define TSTMSRA (volatile unsigned short int * const)(0x30 + SIM_CRB) + /* Test Module Master Shift A */ +#define TSTMSRB (volatile unsigned short int * const)(0x32 + SIM_CRB) + /* Test Module Master Shift A */ +#define TSTSC (volatile unsigned short int * const)(0x34 + SIM_CRB) + /* Test Module Shift Count */ +#define TSTRC (volatile unsigned short int * const)(0x36 + SIM_CRB) + /* Test Module Repetition Counter */ +#define CREG (volatile unsigned short int * const)(0x38 + SIM_CRB) + /* Test Module Control */ +#define DREG (volatile unsigned short int * const)(0x3a + SIM_CRB) + /* Test Module Distributed */ +/* Used only for factor testing */ + + + +#define PORTC (volatile unsigned char * const)(0x41 + SIM_CRB) + /* Port C Data */ + + + +#define CSPAR0 (volatile unsigned short int * const)(0x44 + SIM_CRB) + /* Chip Select Pin Assignment + Resgister 0 */ +/* CSPAR0 contains seven two-bit fields that determine the functions + of corresponding chip-select pins. CSPAR0[15:14] are not + used. These bits always read zero; write have no effect. CSPAR0 bit + 1 always reads one; writes to CSPAR0 bit 1 have no effect. */ +#define CSPAR1 (volatile unsigned short int * const)(0x46 + SIM_CRB) + /* Chip Select Pin Assignment + Register 1 */ +/* CSPAR1 contains five two-bit fields that determine the finctions of + corresponding chip-select pins. CSPAR1[15:10] are not used. These + bits always read zero; writes have no effect. */ +/* + * + * Bit Field | Description + * ------------+--------------- + * 00 | Discrete Output + * 01 | Alternate Function + * 10 | Chip Select (8-bit port) + * 11 | Chip Select (16-bit port) + */ +#define DisOut 0x0 +#define AltFun 0x1 +#define CS8bit 0x2 +#define CS16bit 0x3 +/* + * + * CSPARx Field |Chip Select Signal | Alternate Signal | Discrete Output + *-----------------+--------------------+--------------------+---------------*/ +#define CS_5 12 /* !CS5 | FC2 | PC2 */ +#define CS_4 10 /* !CS4 | FC1 | PC1 */ +#define CS_3 8 /* !CS3 | FC0 | PC0 */ +#define CS_2 6 /* !CS2 | !BGACK | */ +#define CS_1 4 /* !CS1 | !BG | */ +#define CS_0 2 /* !CS0 | !BR | */ +#define CSBOOT 0 /* !CSBOOT | | */ +/* | | | */ +#define CS_10 8 /* !CS10 | ADDR23 | ECLK */ +#define CS_9 6 /* !CS9 | ADDR22 | PC6 */ +#define CS_8 4 /* !CS8 | ADDR21 | PC5 */ +#define CS_7 2 /* !CS7 | ADDR20 | PC4 */ +#define CS_6 0 /* !CS6 | ADDR19 | PC3 */ + +#define BS_2K 0x0 +#define BS_8K 0x1 +#define BS_16K 0x2 +#define BS_64K 0x3 +#define BS_128K 0x4 +#define BS_256K 0x5 +#define BS_512K 0x6 +#define BS_1M 0x7 + +#define CSBARBT (volatile unsigned short int * const)(0x48 + SIM_CRB) +#define CSBAR0 (volatile unsigned short int * const)(0x4c + SIM_CRB) +#define CSBAR1 (volatile unsigned short int * const)(0x50 + SIM_CRB) +#define CSBAR2 (volatile unsigned short int * const)(0x54 + SIM_CRB) +#define CSBAR3 (volatile unsigned short int * const)(0x58 + SIM_CRB) +#define CSBAR4 (volatile unsigned short int * const)(0x5c + SIM_CRB) +#define CSBAR5 (volatile unsigned short int * const)(0x60 + SIM_CRB) +#define CSBAR6 (volatile unsigned short int * const)(0x64 + SIM_CRB) +#define CSBAR7 (volatile unsigned short int * const)(0x68 + SIM_CRB) +#define CSBAR8 (volatile unsigned short int * const)(0x6c + SIM_CRB) +#define CSBAR9 (volatile unsigned short int * const)(0x70 + SIM_CRB) +#define CSBAR10 (volatile unsigned short int * const)(0x74 + SIM_CRB) + +#define MODE 0x8000 +#define Disable 0 +#define LowerByte 0x2000 +#define UpperByte 0x4000 +#define BothBytes 0x6000 +#define ReadOnly 0x0800 +#define WriteOnly 0x1000 +#define ReadWrite 0x1800 +#define SyncAS 0x0 +#define SyncDS 0x0400 + +#define WaitStates_0 (0x0 << 6) +#define WaitStates_1 (0x1 << 6) +#define WaitStates_2 (0x2 << 6) +#define WaitStates_3 (0x3 << 6) +#define WaitStates_4 (0x4 << 6) +#define WaitStates_5 (0x5 << 6) +#define WaitStates_6 (0x6 << 6) +#define WaitStates_7 (0x7 << 6) +#define WaitStates_8 (0x8 << 6) +#define WaitStates_9 (0x9 << 6) +#define WaitStates_10 (0xa << 6) +#define WaitStates_11 (0xb << 6) +#define WaitStates_12 (0xc << 6) +#define WaitStates_13 (0xd << 6) +#define FastTerm (0xe << 6) +#define External (0xf << 6) + +#define CPUSpace (0x0 << 4) +#define UserSpace (0x1 << 4) +#define SupSpace (0x2 << 4) +#define UserSupSpace (0x3 << 4) + +#define IPLevel_any 0x0 +#define IPLevel_1 0x2 +#define IPLevel_2 0x4 +#define IPLevel_3 0x6 +#define IPLevel_4 0x8 +#define IPLevel_5 0xa +#define IPLevel_6 0xc +#define IPLevel_7 0xe + +#define AVEC 1 + +#define CSORBT (volatile unsigned short int * const)(0x4a + SIM_CRB) +#define CSOR0 (volatile unsigned short int * const)(0x4e + SIM_CRB) +#define CSOR1 (volatile unsigned short int * const)(0x52 + SIM_CRB) +#define CSOR2 (volatile unsigned short int * const)(0x56 + SIM_CRB) +#define CSOR3 (volatile unsigned short int * const)(0x5a + SIM_CRB) +#define CSOR4 (volatile unsigned short int * const)(0x5e + SIM_CRB) +#define CSOR5 (volatile unsigned short int * const)(0x62 + SIM_CRB) +#define CSOR6 (volatile unsigned short int * const)(0x66 + SIM_CRB) +#define CSOR7 (volatile unsigned short int * const)(0x6a + SIM_CRB) +#define CSOR8 (volatile unsigned short int * const)(0x6e + SIM_CRB) +#define CSOR9 (volatile unsigned short int * const)(0x72 + SIM_CRB) +#define CSOR10 (volatile unsigned short int * const)(0x76 + SIM_CRB) + +#endif /* _SIM_h_ */ diff --git a/cpukit/score/cpu/m68k/sim.h b/cpukit/score/cpu/m68k/sim.h new file mode 100644 index 0000000000..fae7fe8783 --- /dev/null +++ b/cpukit/score/cpu/m68k/sim.h @@ -0,0 +1,328 @@ +/* + *------------------------------------------------------------------- + * + * SIM -- System Integration Module + * + * The system integration module (SIM) is used on many Motorola 16- + * and 32-bit MCUs for the following functions: + * + * () System configuration and protection. Bus and software watchdog + * monitors are provided in addition to periodic interrupt generators. + * + * () Clock signal generation for other intermodule bus (IMB) members + * and external devices. + * + * () The generation of chip-select signals that simplify external + * circuitry interface. + * + * () Data ports that are available for general purpose input and + * output. + * + * () A system test block that is intended only for factory tests. + * + * For more information, refer to Motorola's "Modular Microcontroller + * Family System Integration Module Reference Manual" (Motorola document + * SIMRM/AD). + * + * This file has been created by John S. Gwynne for support of + * Motorola's 68332 MCU in the efi332 project. + * + * Redistribution and use in source and binary forms are permitted + * provided that the following conditions are met: + * 1. Redistribution of source code and documentation must retain + * the above authorship, this list of conditions and the + * following disclaimer. + * 2. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * This software is provided "AS IS" without warranty of any kind, + * either expressed or implied, including, but not limited to, the + * implied warranties of merchantability, title and fitness for a + * particular purpose. + * + *------------------------------------------------------------------ + * + * $Id$ + */ + +#ifndef _SIM_H_ +#define _SIM_H_ + + +#include <efi332.h> + + +/* SAM-- shift and mask */ +#undef SAM +#define SAM(a,b,c) ((a << b) & c) + + + +/* SIM_CRB (SIM Control Register Block) base address of the SIM + control registers */ +/* not included in ram_init.h */ +#if SIM_MM == 0 +#define SIM_CRB 0x7ffa00 +#else +#undef SIM_MM +#define SIM_MM 1 +#define SIM_CRB 0xfffa00 +#endif +/* end not included in ram_init.h */ + + + +#define SIMCR (volatile unsigned short int * const)(0x00 + SIM_CRB) + /* Module Configuration Register */ +#define EXOFF 0x8000 /* External Clock Off */ +#define FRZSW 0x4000 /* Freeze Software Enable */ +#define FRZBM 0x2000 /* Freeze Bus Monitor Enable */ +#define SLVEN 0x0800 /* Factory Test Model Enabled (ro)*/ +#define SHEN 0x0300 /* Show Cycle Enable */ +#define SUPV 0x0080 /* Supervisor/Unrestricted Data Space */ +#define MM 0x0040 /* Module Mapping */ +#define IARB 0x000f /* Interrupt Arbitration Field */ + + + +#define SIMTR (volatile unsigned short int * const)(0x02 + SIM_CRB) + /* SIM Test Register */ +/* Used only for factor testing */ + + + +#define SYNCR (volatile unsigned short int * const)(0x04 + SIM_CRB) + /* Clock Synthesizer Control Register */ +#define W 0x8000 /* Frequency Control (VCO) */ +#define X 0x4000 /* Frequency Control Bit (Prescale) */ +#define Y 0x3f00 /* Frequency Control Counter */ +#define EDIV 0x0080 /* ECLK Divide Rate */ +#define SLIMP 0x0010 /* Limp Mode Status */ +#define SLOCK 0x0008 /* Synthesizer Lock */ +#define RSTEN 0x0004 /* Reset Enable */ +#define STSIM 0x0002 /* Stop Mode SIM Clock */ +#define STEXT 0x0001 /* Stop Mode External Clock */ + + + +#define RSR (volatile unsigned char * const)(0x07 + SIM_CRB) + /* Reset Status Register */ +#define EXT 0x0080 /* External Reset */ +#define POW 0x0040 /* Power-On Reset */ +#define SW 0x0020 /* Software Watchdog Reset */ +#define DBF 0x0010 /* Double Bus Fault Reset */ +#define LOC 0x0004 /* Loss of Clock Reset */ +#define SYS 0x0002 /* System Reset */ +#define TST 0x0001 /* Test Submodule Reset */ + + + +#define SIMTRE (volatile unsigned short int * const)(0x08 + SIM_CRB) + /* System Integration Test Register */ +/* Used only for factor testing */ + + + +#define PORTE0 (volatile unsigned char * const)(0x11 + SIM_CRB) +#define PORTE1 (volatile unsigned char * const)(0x13 + SIM_CRB) + /* Port E Data Register */ +#define DDRE (volatile unsigned char * const)(0x15 + SIM_CRB) + /* Port E Data Direction Register */ +#define PEPAR (volatile unsigned char * const)(0x17 + SIM_CRB) + /* Port E Pin Assignment Register */ +/* Any bit cleared (zero) defines the corresponding pin to be an I/O + pin. Any bit set defines the corresponding pin to be a bus control + signal. */ + + + +#define PORTF0 (volatile unsigned char * const)(0x19 + SIM_CRB) +#define PORTF1 (volatile unsigned char * const)(0x1b + SIM_CRB) + /* Port F Data Register */ +#define DDRF (volatile unsigned char * const)(0x1d + SIM_CRB) + /* Port E Data Direction Register */ +#define PFPAR (volatile unsigned char * const)(0x1f + SIM_CRB) +/* Any bit cleared (zero) defines the corresponding pin to be an I/O + pin. Any bit set defines the corresponding pin to be a bus control + signal. */ + + + +#define SYPCR (volatile unsigned char * const)(0x21 + SIM_CRB) +/* !!! can write to only once after reset !!! */ + /* System Protection Control Register */ +#define SWE 0x80 /* Software Watch Enable */ +#define SWP 0x40 /* Software Watchdog Prescale */ +#define SWT 0x30 /* Software Watchdog Timing */ +#define HME 0x08 /* Halt Monitor Enable */ +#define BME 0x04 /* Bus Monitor External Enable */ +#define BMT 0x03 /* Bus Monitor Timing */ + + + +#define PICR (volatile unsigned short int * const)(0x22 + SIM_CRB) + /* Periodic Interrupt Control Reg. */ +#define PIRQL 0x0700 /* Periodic Interrupt Request Level */ +#define PIV 0x00ff /* Periodic Interrupt Level */ + + + +#define PITR (volatile unsigned short int * const)(0x24 + SIM_CRB) + /* Periodic Interrupt Timer Register */ +#define PTP 0x0100 /* Periodic Timer Prescaler Control */ +#define PITM 0x00ff /* Periodic Interrupt Timing Modulus */ + + + +#define SWSR (volatile unsigned char * const)(0x27 + SIM_CRB) + /* Software Service Register */ +/* write 0x55 then 0xaa to service the software watchdog */ + + + +#define TSTMSRA (volatile unsigned short int * const)(0x30 + SIM_CRB) + /* Test Module Master Shift A */ +#define TSTMSRB (volatile unsigned short int * const)(0x32 + SIM_CRB) + /* Test Module Master Shift A */ +#define TSTSC (volatile unsigned short int * const)(0x34 + SIM_CRB) + /* Test Module Shift Count */ +#define TSTRC (volatile unsigned short int * const)(0x36 + SIM_CRB) + /* Test Module Repetition Counter */ +#define CREG (volatile unsigned short int * const)(0x38 + SIM_CRB) + /* Test Module Control */ +#define DREG (volatile unsigned short int * const)(0x3a + SIM_CRB) + /* Test Module Distributed */ +/* Used only for factor testing */ + + + +#define PORTC (volatile unsigned char * const)(0x41 + SIM_CRB) + /* Port C Data */ + + + +#define CSPAR0 (volatile unsigned short int * const)(0x44 + SIM_CRB) + /* Chip Select Pin Assignment + Resgister 0 */ +/* CSPAR0 contains seven two-bit fields that determine the functions + of corresponding chip-select pins. CSPAR0[15:14] are not + used. These bits always read zero; write have no effect. CSPAR0 bit + 1 always reads one; writes to CSPAR0 bit 1 have no effect. */ +#define CSPAR1 (volatile unsigned short int * const)(0x46 + SIM_CRB) + /* Chip Select Pin Assignment + Register 1 */ +/* CSPAR1 contains five two-bit fields that determine the finctions of + corresponding chip-select pins. CSPAR1[15:10] are not used. These + bits always read zero; writes have no effect. */ +/* + * + * Bit Field | Description + * ------------+--------------- + * 00 | Discrete Output + * 01 | Alternate Function + * 10 | Chip Select (8-bit port) + * 11 | Chip Select (16-bit port) + */ +#define DisOut 0x0 +#define AltFun 0x1 +#define CS8bit 0x2 +#define CS16bit 0x3 +/* + * + * CSPARx Field |Chip Select Signal | Alternate Signal | Discrete Output + *-----------------+--------------------+--------------------+---------------*/ +#define CS_5 12 /* !CS5 | FC2 | PC2 */ +#define CS_4 10 /* !CS4 | FC1 | PC1 */ +#define CS_3 8 /* !CS3 | FC0 | PC0 */ +#define CS_2 6 /* !CS2 | !BGACK | */ +#define CS_1 4 /* !CS1 | !BG | */ +#define CS_0 2 /* !CS0 | !BR | */ +#define CSBOOT 0 /* !CSBOOT | | */ +/* | | | */ +#define CS_10 8 /* !CS10 | ADDR23 | ECLK */ +#define CS_9 6 /* !CS9 | ADDR22 | PC6 */ +#define CS_8 4 /* !CS8 | ADDR21 | PC5 */ +#define CS_7 2 /* !CS7 | ADDR20 | PC4 */ +#define CS_6 0 /* !CS6 | ADDR19 | PC3 */ + +#define BS_2K 0x0 +#define BS_8K 0x1 +#define BS_16K 0x2 +#define BS_64K 0x3 +#define BS_128K 0x4 +#define BS_256K 0x5 +#define BS_512K 0x6 +#define BS_1M 0x7 + +#define CSBARBT (volatile unsigned short int * const)(0x48 + SIM_CRB) +#define CSBAR0 (volatile unsigned short int * const)(0x4c + SIM_CRB) +#define CSBAR1 (volatile unsigned short int * const)(0x50 + SIM_CRB) +#define CSBAR2 (volatile unsigned short int * const)(0x54 + SIM_CRB) +#define CSBAR3 (volatile unsigned short int * const)(0x58 + SIM_CRB) +#define CSBAR4 (volatile unsigned short int * const)(0x5c + SIM_CRB) +#define CSBAR5 (volatile unsigned short int * const)(0x60 + SIM_CRB) +#define CSBAR6 (volatile unsigned short int * const)(0x64 + SIM_CRB) +#define CSBAR7 (volatile unsigned short int * const)(0x68 + SIM_CRB) +#define CSBAR8 (volatile unsigned short int * const)(0x6c + SIM_CRB) +#define CSBAR9 (volatile unsigned short int * const)(0x70 + SIM_CRB) +#define CSBAR10 (volatile unsigned short int * const)(0x74 + SIM_CRB) + +#define MODE 0x8000 +#define Disable 0 +#define LowerByte 0x2000 +#define UpperByte 0x4000 +#define BothBytes 0x6000 +#define ReadOnly 0x0800 +#define WriteOnly 0x1000 +#define ReadWrite 0x1800 +#define SyncAS 0x0 +#define SyncDS 0x0400 + +#define WaitStates_0 (0x0 << 6) +#define WaitStates_1 (0x1 << 6) +#define WaitStates_2 (0x2 << 6) +#define WaitStates_3 (0x3 << 6) +#define WaitStates_4 (0x4 << 6) +#define WaitStates_5 (0x5 << 6) +#define WaitStates_6 (0x6 << 6) +#define WaitStates_7 (0x7 << 6) +#define WaitStates_8 (0x8 << 6) +#define WaitStates_9 (0x9 << 6) +#define WaitStates_10 (0xa << 6) +#define WaitStates_11 (0xb << 6) +#define WaitStates_12 (0xc << 6) +#define WaitStates_13 (0xd << 6) +#define FastTerm (0xe << 6) +#define External (0xf << 6) + +#define CPUSpace (0x0 << 4) +#define UserSpace (0x1 << 4) +#define SupSpace (0x2 << 4) +#define UserSupSpace (0x3 << 4) + +#define IPLevel_any 0x0 +#define IPLevel_1 0x2 +#define IPLevel_2 0x4 +#define IPLevel_3 0x6 +#define IPLevel_4 0x8 +#define IPLevel_5 0xa +#define IPLevel_6 0xc +#define IPLevel_7 0xe + +#define AVEC 1 + +#define CSORBT (volatile unsigned short int * const)(0x4a + SIM_CRB) +#define CSOR0 (volatile unsigned short int * const)(0x4e + SIM_CRB) +#define CSOR1 (volatile unsigned short int * const)(0x52 + SIM_CRB) +#define CSOR2 (volatile unsigned short int * const)(0x56 + SIM_CRB) +#define CSOR3 (volatile unsigned short int * const)(0x5a + SIM_CRB) +#define CSOR4 (volatile unsigned short int * const)(0x5e + SIM_CRB) +#define CSOR5 (volatile unsigned short int * const)(0x62 + SIM_CRB) +#define CSOR6 (volatile unsigned short int * const)(0x66 + SIM_CRB) +#define CSOR7 (volatile unsigned short int * const)(0x6a + SIM_CRB) +#define CSOR8 (volatile unsigned short int * const)(0x6e + SIM_CRB) +#define CSOR9 (volatile unsigned short int * const)(0x72 + SIM_CRB) +#define CSOR10 (volatile unsigned short int * const)(0x76 + SIM_CRB) + +#endif /* _SIM_h_ */ diff --git a/cpukit/score/cpu/no_cpu/asm.h b/cpukit/score/cpu/no_cpu/asm.h new file mode 100644 index 0000000000..66d98be652 --- /dev/null +++ b/cpukit/score/cpu/no_cpu/asm.h @@ -0,0 +1,98 @@ +/* asm.h + * + * This include file attempts to address the problems + * caused by incompatible flavors of assemblers and + * toolsets. It primarily addresses variations in the + * use of leading underscores on symbols and the requirement + * that register names be preceded by a %. + * + * + * NOTE: The spacing in the use of these macros + * is critical to them working as advertised. + * + * COPYRIGHT: + * + * This file is based on similar code found in newlib available + * from ftp.cygnus.com. The file which was used had no copyright + * notice. This file is freely distributable as long as the source + * of the file is noted. This file is: + * + * COPYRIGHT (c) 1994. + * On-Line Applications Research Corporation (OAR). + * + * $Id$ + */ + +#ifndef __NO_CPU_ASM_h +#define __NO_CPU_ASM_h + +/* + * Indicate we are in an assembly file and get the basic CPU definitions. + */ + +#define ASM +#include <rtems/score/no_cpu.h> + +/* + * Recent versions of GNU cpp define variables which indicate the + * need for underscores and percents. If not using GNU cpp or + * the version does not support this, then you will obviously + * have to define these as appropriate. + */ + +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#ifndef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ +#endif + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a ## b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) + +/* + * define macros for all of the registers on this CPU + * + * EXAMPLE: #define d0 REG (d0) + */ + +/* + * Define macros to handle section beginning and ends. + */ + + +#define BEGIN_CODE_DCL .text +#define END_CODE_DCL +#define BEGIN_DATA_DCL .data +#define END_DATA_DCL +#define BEGIN_CODE .text +#define END_CODE +#define BEGIN_DATA +#define END_DATA +#define BEGIN_BSS +#define END_BSS +#define END + +/* + * Following must be tailor for a particular flavor of the C compiler. + * They may need to put underscores in front of the symbols. + */ + +#define PUBLIC(sym) .globl SYM (sym) +#define EXTERN(sym) .globl SYM (sym) + +#endif +/* end of include file */ + + diff --git a/cpukit/score/cpu/no_cpu/cpu.c b/cpukit/score/cpu/no_cpu/cpu.c new file mode 100644 index 0000000000..ba533324ac --- /dev/null +++ b/cpukit/score/cpu/no_cpu/cpu.c @@ -0,0 +1,160 @@ +/* + * XXX CPU Dependent Source + * + * + * 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/system.h> +#include <rtems/score/isr.h> +#include <rtems/score/wkspace.h> + +/* _CPU_Initialize + * + * This routine performs processor dependent initialization. + * + * INPUT PARAMETERS: + * cpu_table - CPU table to initialize + * thread_dispatch - address of disptaching routine + */ + + +void _CPU_Initialize( + rtems_cpu_table *cpu_table, + void (*thread_dispatch) /* ignored on this CPU */ +) +{ + /* + * The thread_dispatch argument is the address of the entry point + * for the routine called at the end of an ISR once it has been + * decided a context switch is necessary. On some compilation + * systems it is difficult to call a high-level language routine + * from assembly. This allows us to trick these systems. + * + * If you encounter this problem save the entry point in a CPU + * dependent variable. + */ + + _CPU_Thread_dispatch_pointer = thread_dispatch; + + /* + * If there is not an easy way to initialize the FP context + * during Context_Initialize, then it is usually easier to + * save an "uninitialized" FP context here and copy it to + * the task's during Context_Initialize. + */ + + /* FP context initialization support goes here */ + + _CPU_Table = *cpu_table; +} + +/*PAGE + * + * _CPU_ISR_Get_level + */ + +unsigned32 _CPU_ISR_Get_level( void ) +{ + /* + * This routine returns the current interrupt level. + */ +} + +/*PAGE + * + * _CPU_ISR_install_raw_handler + */ + +void _CPU_ISR_install_raw_handler( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + /* + * This is where we install the interrupt handler into the "raw" interrupt + * table used by the CPU to dispatch interrupt handlers. + */ +} + +/*PAGE + * + * _CPU_ISR_install_vector + * + * This kernel routine installs the RTEMS handler for the + * specified vector. + * + * Input parameters: + * vector - interrupt vector number + * old_handler - former ISR for this vector number + * new_handler - replacement ISR for this vector number + * + * Output parameters: NONE + * + */ + +void _CPU_ISR_install_vector( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + *old_handler = _ISR_Vector_table[ vector ]; + + /* + * If the interrupt vector table is a table of pointer to isr entry + * points, then we need to install the appropriate RTEMS interrupt + * handler for this vector number. + */ + + _CPU_ISR_install_raw_handler( vector, new_handler, old_handler ); + + /* + * We put the actual user ISR address in '_ISR_vector_table'. This will + * be used by the _ISR_Handler so the user gets control. + */ + + _ISR_Vector_table[ vector ] = new_handler; +} + +/*PAGE + * + * _CPU_Install_interrupt_stack + */ + +void _CPU_Install_interrupt_stack( void ) +{ +} + +/*PAGE + * + * _CPU_Thread_Idle_body + * + * NOTES: + * + * 1. This is the same as the regular CPU independent algorithm. + * + * 2. If you implement this using a "halt", "idle", or "shutdown" + * instruction, then don't forget to put it in an infinite loop. + * + * 3. Be warned. Some processors with onboard DMA have been known + * to stop the DMA if the CPU were put in IDLE mode. This might + * also be a problem with other on-chip peripherals. So use this + * hook with caution. + */ + +void _CPU_Thread_Idle_body( void ) +{ + + for( ; ; ) + /* insert your "halt" instruction here */ ; +} diff --git a/cpukit/score/cpu/no_cpu/cpu_asm.c b/cpukit/score/cpu/no_cpu/cpu_asm.c new file mode 100644 index 0000000000..5a36ece987 --- /dev/null +++ b/cpukit/score/cpu/no_cpu/cpu_asm.c @@ -0,0 +1,165 @@ +/* cpu_asm.c ===> cpu_asm.S or cpu_asm.s + * + * This file contains the basic algorithms for all assembly code used + * in an specific CPU port of RTEMS. These algorithms must be implemented + * in assembly language + * + * NOTE: This is supposed to be a .S or .s file NOT a C file. + * + * 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$ + */ + +/* + * This is supposed to be an assembly file. This means that system.h + * and cpu.h should not be included in a "real" cpu_asm file. An + * implementation in assembly should include "cpu_asm.h> + */ + +#include <rtems/system.h> +#include <rtems/score/cpu.h> +/* #include "cpu_asm.h> */ + +/* + * _CPU_Context_save_fp_context + * + * This routine is responsible for saving the FP context + * at *fp_context_ptr. If the point to load the FP context + * from is changed then the pointer is modified by this routine. + * + * Sometimes a macro implementation of this is in cpu.h which dereferences + * the ** and a similarly named routine in this file is passed something + * like a (Context_Control_fp *). The general rule on making this decision + * is to avoid writing assembly language. + */ + +void _CPU_Context_save_fp( + void **fp_context_ptr +) +{ +} + +/* + * _CPU_Context_restore_fp_context + * + * This routine is responsible for restoring the FP context + * at *fp_context_ptr. If the point to load the FP context + * from is changed then the pointer is modified by this routine. + * + * Sometimes a macro implementation of this is in cpu.h which dereferences + * the ** and a similarly named routine in this file is passed something + * like a (Context_Control_fp *). The general rule on making this decision + * is to avoid writing assembly language. + */ + +void _CPU_Context_restore_fp( + void **fp_context_ptr +) +{ +} + +/* _CPU_Context_switch + * + * This routine performs a normal non-FP context switch. + */ + +void _CPU_Context_switch( + Context_Control *run, + Context_Control *heir +) +{ +} + +/* + * _CPU_Context_restore + * + * This routine is generallu used only to restart self in an + * efficient manner. It may simply be a label in _CPU_Context_switch. + * + * NOTE: May be unnecessary to reload some registers. + */ + +void _CPU_Context_restore( + Context_Control *new_context +) +{ +} + +/* void __ISR_Handler() + * + * This routine provides the RTEMS interrupt management. + * + */ + +void _ISR_Handler() +{ + /* + * This discussion ignores a lot of the ugly details in a real + * implementation such as saving enough registers/state to be + * able to do something real. Keep in mind that the goal is + * to invoke a user's ISR handler which is written in C and + * uses a certain set of registers. + * + * Also note that the exact order is to a large extent flexible. + * Hardware will dictate a sequence for a certain subset of + * _ISR_Handler while requirements for setting + */ + + /* + * At entry to "common" _ISR_Handler, the vector number must be + * available. On some CPUs the hardware puts either the vector + * number or the offset into the vector table for this ISR in a + * known place. If the hardware does not give us this information, + * then the assembly portion of RTEMS for this port will contain + * a set of distinct interrupt entry points which somehow place + * the vector number in a known place (which is safe if another + * interrupt nests this one) and branches to _ISR_Handler. + * + * save some or all context on stack + * may need to save some special interrupt information for exit + * + * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE ) + * if ( _ISR_Nest_level == 0 ) + * switch to software interrupt stack + * #endif + * + * _ISR_Nest_level++; + * + * _Thread_Dispatch_disable_level++; + * + * (*_ISR_Vector_table[ vector ])( vector ); + * + * --_ISR_Nest_level; + * + * if ( _ISR_Nest_level ) + * goto the label "exit interrupt (simple case)" + * + * #if ( CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE ) + * restore stack + * #endif + * + * if ( !_Context_Switch_necessary ) + * goto the label "exit interrupt (simple case)" + * + * if ( !_ISR_Signals_to_thread_executing ) + * _ISR_Signals_to_thread_executing = FALSE; + * goto the label "exit interrupt (simple case)" + * + * call _Thread_Dispatch() or prepare to return to _ISR_Dispatch + * + * prepare to get out of interrupt + * return from interrupt (maybe to _ISR_Dispatch) + * + * LABEL "exit interrupt (simple case): + * prepare to get out of interrupt + * return from interrupt + */ +} + diff --git a/cpukit/score/cpu/no_cpu/rtems/asm.h b/cpukit/score/cpu/no_cpu/rtems/asm.h new file mode 100644 index 0000000000..66d98be652 --- /dev/null +++ b/cpukit/score/cpu/no_cpu/rtems/asm.h @@ -0,0 +1,98 @@ +/* asm.h + * + * This include file attempts to address the problems + * caused by incompatible flavors of assemblers and + * toolsets. It primarily addresses variations in the + * use of leading underscores on symbols and the requirement + * that register names be preceded by a %. + * + * + * NOTE: The spacing in the use of these macros + * is critical to them working as advertised. + * + * COPYRIGHT: + * + * This file is based on similar code found in newlib available + * from ftp.cygnus.com. The file which was used had no copyright + * notice. This file is freely distributable as long as the source + * of the file is noted. This file is: + * + * COPYRIGHT (c) 1994. + * On-Line Applications Research Corporation (OAR). + * + * $Id$ + */ + +#ifndef __NO_CPU_ASM_h +#define __NO_CPU_ASM_h + +/* + * Indicate we are in an assembly file and get the basic CPU definitions. + */ + +#define ASM +#include <rtems/score/no_cpu.h> + +/* + * Recent versions of GNU cpp define variables which indicate the + * need for underscores and percents. If not using GNU cpp or + * the version does not support this, then you will obviously + * have to define these as appropriate. + */ + +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#ifndef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ +#endif + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a ## b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) + +/* + * define macros for all of the registers on this CPU + * + * EXAMPLE: #define d0 REG (d0) + */ + +/* + * Define macros to handle section beginning and ends. + */ + + +#define BEGIN_CODE_DCL .text +#define END_CODE_DCL +#define BEGIN_DATA_DCL .data +#define END_DATA_DCL +#define BEGIN_CODE .text +#define END_CODE +#define BEGIN_DATA +#define END_DATA +#define BEGIN_BSS +#define END_BSS +#define END + +/* + * Following must be tailor for a particular flavor of the C compiler. + * They may need to put underscores in front of the symbols. + */ + +#define PUBLIC(sym) .globl SYM (sym) +#define EXTERN(sym) .globl SYM (sym) + +#endif +/* end of include file */ + + diff --git a/cpukit/score/cpu/sparc/README b/cpukit/score/cpu/sparc/README new file mode 100644 index 0000000000..c4c2200075 --- /dev/null +++ b/cpukit/score/cpu/sparc/README @@ -0,0 +1,110 @@ +# +# $Id$ +# + +This file discusses SPARC specific issues which are important to +this port. The primary topics in this file are: + + + Global Register Usage + + Stack Frame + + EF bit in the PSR + + +Global Register Usage +===================== + +This information on register usage is based heavily on a comment in the +file gcc-2.7.0/config/sparc/sparc.h in the the gcc 2.7.0 source. + + + g0 is hardwired to 0 + + On non-v9 systems: + - g1 is free to use as temporary. + - g2-g4 are reserved for applications. Gcc normally uses them as + temporaries, but this can be disabled via the -mno-app-regs option. + - g5 through g7 are reserved for the operating system. + + On v9 systems: + - g1 and g5 are free to use as temporaries. + - g2-g4 are reserved for applications (the compiler will not normally use + them, but they can be used as temporaries with -mapp-regs). + - g6-g7 are reserved for the operating system. + + NOTE: As of gcc 2.7.0 register g1 was used in the following scenarios: + + + as a temporary by the 64 bit sethi pattern + + when restoring call-preserved registers in large stack frames + +RTEMS places no constraints on the usage of the global registers. Although +gcc assumes that either g5-g7 (non-V9) or g6-g7 (V9) are reserved for the +operating system, RTEMS does not assume any special use for them. + + + +Stack Frame +=========== + +The stack grows downward (i.e. to lower addresses) on the SPARC architecture. + +The following is the organization of the stack frame: + + + + | ............... | + fp | | + +-------------------------------+ + | | + | Local registers, temporaries, | + | and saved floats | x bytes + | | + sp + x +-------------------------------+ + | | + | outgoing parameters past | + | the sixth one | x bytes + | | + sp + 92 +-------------------------------+ * + | | * + | area for callee to save | * + | register arguments | * 24 bytes + | | * + sp + 68 +-------------------------------+ * + | | * + | structure return pointer | * 4 bytes + | | * + sp + 64 +-------------------------------+ * + | | * + | local register set | * 32 bytes + | | * + sp + 32 +-------------------------------+ * + | | * + | input register set | * 32 bytes + | | * + sp +-------------------------------+ * + + +* = minimal stack frame + +x = optional components + +EF bit in the PSR +================= + +The EF (enable floating point unit) in the PSR is utilized in this port to +prevent non-floating point tasks from performing floating point +operations. This bit is maintained as part of the integer context. +However, the floating point context is switched BEFORE the integer +context. Thus the EF bit in place at the time of the FP switch may +indicate that FP operations are disabled. This occurs on certain task +switches, when the EF bit will be 0 for the outgoing task and thus a fault +will be generated on the first FP operation of the FP context save. + +The remedy for this is to enable FP access as the first step in both the +save and restore of the FP context area. This bit will be subsequently +reloaded by the integer context switch. + +Two of the scenarios which demonstrate this problem are outlined below: + +1. When the first FP task is switched to. The system tasks are not FP and +thus would be unable to restore the FP context of the incoming task. + +2. On a deferred FP context switch. In this case, the system might switch +from FP Task A to non-FP Task B and then to FP Task C. In this scenario, +the floating point state must technically be saved by a non-FP task. diff --git a/cpukit/score/cpu/sparc/asm.h b/cpukit/score/cpu/sparc/asm.h new file mode 100644 index 0000000000..a3d62416b8 --- /dev/null +++ b/cpukit/score/cpu/sparc/asm.h @@ -0,0 +1,111 @@ +/* asm.h + * + * This include file attempts to address the problems + * caused by incompatible flavors of assemblers and + * toolsets. It primarily addresses variations in the + * use of leading underscores on symbols and the requirement + * that register names be preceded by a %. + * + * + * NOTE: The spacing in the use of these macros + * is critical to them working as advertised. + * + * COPYRIGHT: + * + * This file is based on similar code found in newlib available + * from ftp.cygnus.com. The file which was used had no copyright + * notice. This file is freely distributable as long as the source + * of the file is noted. + * + * $Id$ + */ + +#ifndef __SPARC_ASM_h +#define __SPARC_ASM_h + +/* + * Indicate we are in an assembly file and get the basic CPU definitions. + */ + +#define ASM + +#include <rtems/score/sparc.h> +#include <rtems/score/cpu.h> + +/* + * Recent versions of GNU cpp define variables which indicate the + * need for underscores and percents. If not using GNU cpp or + * the version does not support this, then you will obviously + * have to define these as appropriate. + */ + +/* XXX __USER_LABEL_PREFIX__ and __REGISTER_PREFIX__ do not work on gcc 2.7.0 */ +/* XXX The following ifdef magic fixes the problem but results in a warning */ +/* XXX when compiling assembly code. */ +#undef __USER_LABEL_PREFIX__ +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#ifndef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ +#endif + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a ## b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) + +/* + * define macros for all of the registers on this CPU + * + * EXAMPLE: #define d0 REG (d0) + */ + +/* + * Define macros to handle section beginning and ends. + */ + + +#define BEGIN_CODE_DCL .text +#define END_CODE_DCL +#define BEGIN_DATA_DCL .data +#define END_DATA_DCL +#define BEGIN_CODE .text +#define END_CODE +#define BEGIN_DATA +#define END_DATA +#define BEGIN_BSS +#define END_BSS +#define END + +/* + * Following must be tailor for a particular flavor of the C compiler. + * They may need to put underscores in front of the symbols. + */ + +#define PUBLIC(sym) .globl SYM (sym) +#define EXTERN(sym) .globl SYM (sym) + +/* + * Entry for traps which jump to a programmer-specified trap handler. + */ + +#define TRAP(_vector, _handler) \ + mov %psr, %l0 ; \ + sethi %hi(_handler), %l4 ; \ + jmp %l4+%lo(_handler); \ + mov _vector, %l3 + +#endif +/* end of include file */ + + diff --git a/cpukit/score/cpu/sparc/cpu.c b/cpukit/score/cpu/sparc/cpu.c new file mode 100644 index 0000000000..23a93f176e --- /dev/null +++ b/cpukit/score/cpu/sparc/cpu.c @@ -0,0 +1,404 @@ +/* + * SPARC Dependent Source + * + * 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. + * + * Ported to ERC32 implementation of the SPARC by On-Line Applications + * Research Corporation (OAR) under contract to the European Space + * Agency (ESA). + * + * ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995. + * European Space Agency. + * + * $Id$ + */ + +#include <rtems/system.h> +#include <rtems/score/isr.h> + +#if defined(erc32) +#include <erc32.h> +#endif + +/* + * This initializes the set of opcodes placed in each trap + * table entry. The routine which installs a handler is responsible + * for filling in the fields for the _handler address and the _vector + * trap type. + * + * The constants following this structure are masks for the fields which + * must be filled in when the handler is installed. + */ + +const CPU_Trap_table_entry _CPU_Trap_slot_template = { + 0xa1480000, /* mov %psr, %l0 */ + 0x29000000, /* sethi %hi(_handler), %l4 */ + 0x81c52000, /* jmp %l4 + %lo(_handler) */ + 0xa6102000 /* mov _vector, %l3 */ +}; + +/*PAGE + * + * _CPU_Initialize + * + * This routine performs processor dependent initialization. + * + * Input Parameters: + * cpu_table - CPU table to initialize + * thread_dispatch - address of disptaching routine + * + * Output Parameters: NONE + * + * NOTE: There is no need to save the pointer to the thread dispatch routine. + * The SPARC's assembly code can reference it directly with no problems. + */ + +void _CPU_Initialize( + rtems_cpu_table *cpu_table, + void (*thread_dispatch) /* ignored on this CPU */ +) +{ + void *pointer; + unsigned32 trap_table_start; + unsigned32 tbr_value; + CPU_Trap_table_entry *old_tbr; + CPU_Trap_table_entry *trap_table; + + /* + * Install the executive's trap table. All entries from the original + * trap table are copied into the executive's trap table. This is essential + * since this preserves critical trap handlers such as the window underflow + * and overflow handlers. It is the responsibility of the BSP to provide + * install these in the initial trap table. + */ + + trap_table_start = (unsigned32) &_CPU_Trap_Table_area; + if (trap_table_start & (SPARC_TRAP_TABLE_ALIGNMENT-1)) + trap_table_start = (trap_table_start + SPARC_TRAP_TABLE_ALIGNMENT) & + ~(SPARC_TRAP_TABLE_ALIGNMENT-1); + + trap_table = (CPU_Trap_table_entry *) trap_table_start; + + sparc_get_tbr( tbr_value ); + + old_tbr = (CPU_Trap_table_entry *) (tbr_value & 0xfffff000); + + memcpy( trap_table, (void *) old_tbr, 256 * sizeof( CPU_Trap_table_entry ) ); + + sparc_set_tbr( trap_table_start ); + + /* + * This seems to be the most appropriate way to obtain an initial + * FP context on the SPARC. The NULL fp context is copied it to + * the task's FP context during Context_Initialize. + */ + + pointer = &_CPU_Null_fp_context; + _CPU_Context_save_fp( &pointer ); + + /* + * Grab our own copy of the user's CPU table. + */ + + _CPU_Table = *cpu_table; + +#if defined(erc32) + + /* + * ERC32 specific initialization + */ + + _ERC32_MEC_Timer_Control_Mirror = 0; + ERC32_MEC.Timer_Control = 0; + + ERC32_MEC.Control |= ERC32_CONFIGURATION_POWER_DOWN_ALLOWED; + +#endif + +} + +/*PAGE + * + * _CPU_ISR_Get_level + * + * Input Parameters: NONE + * + * Output Parameters: + * returns the current interrupt level (PIL field of the PSR) + */ + +unsigned32 _CPU_ISR_Get_level( void ) +{ + unsigned32 level; + + sparc_get_interrupt_level( level ); + + return level; +} + +/*PAGE + * + * _CPU_ISR_install_raw_handler + * + * This routine installs the specified handler as a "raw" non-executive + * supported trap handler (a.k.a. interrupt service routine). + * + * Input Parameters: + * vector - trap table entry number plus synchronous + * vs. asynchronous information + * new_handler - address of the handler to be installed + * old_handler - pointer to an address of the handler previously installed + * + * Output Parameters: NONE + * *new_handler - address of the handler previously installed + * + * NOTE: + * + * On the SPARC, there are really only 256 vectors. However, the executive + * has no easy, fast, reliable way to determine which traps are synchronous + * and which are asynchronous. By default, synchronous traps return to the + * instruction which caused the interrupt. So if you install a software + * trap handler as an executive interrupt handler (which is desirable since + * RTEMS takes care of window and register issues), then the executive needs + * to know that the return address is to the trap rather than the instruction + * following the trap. + * + * So vectors 0 through 255 are treated as regular asynchronous traps which + * provide the "correct" return address. Vectors 256 through 512 are assumed + * by the executive to be synchronous and to require that the return address + * be fudged. + * + * If you use this mechanism to install a trap handler which must reexecute + * the instruction which caused the trap, then it should be installed as + * an asynchronous trap. This will avoid the executive changing the return + * address. + */ + +void _CPU_ISR_install_raw_handler( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + unsigned32 real_vector; + CPU_Trap_table_entry *tbr; + CPU_Trap_table_entry *slot; + unsigned32 u32_tbr; + unsigned32 u32_handler; + + /* + * Get the "real" trap number for this vector ignoring the synchronous + * versus asynchronous indicator included with our vector numbers. + */ + + real_vector = SPARC_REAL_TRAP_NUMBER( vector ); + + /* + * Get the current base address of the trap table and calculate a pointer + * to the slot we are interested in. + */ + + sparc_get_tbr( u32_tbr ); + + u32_tbr &= 0xfffff000; + + tbr = (CPU_Trap_table_entry *) u32_tbr; + + slot = &tbr[ real_vector ]; + + /* + * Get the address of the old_handler from the trap table. + * + * NOTE: The old_handler returned will be bogus if it does not follow + * the RTEMS model. + */ + +#define HIGH_BITS_MASK 0xFFFFFC00 +#define HIGH_BITS_SHIFT 10 +#define LOW_BITS_MASK 0x000003FF + + if ( slot->mov_psr_l0 == _CPU_Trap_slot_template.mov_psr_l0 ) { + u32_handler = + ((slot->sethi_of_handler_to_l4 & HIGH_BITS_MASK) << HIGH_BITS_SHIFT) | + (slot->jmp_to_low_of_handler_plus_l4 & LOW_BITS_MASK); + *old_handler = (proc_ptr) u32_handler; + } else + *old_handler = 0; + + /* + * Copy the template to the slot and then fix it. + */ + + *slot = _CPU_Trap_slot_template; + + u32_handler = (unsigned32) new_handler; + + slot->mov_vector_l3 |= vector; + slot->sethi_of_handler_to_l4 |= + (u32_handler & HIGH_BITS_MASK) >> HIGH_BITS_SHIFT; + slot->jmp_to_low_of_handler_plus_l4 |= (u32_handler & LOW_BITS_MASK); +} + +/*PAGE + * + * _CPU_ISR_install_vector + * + * This kernel routine installs the RTEMS handler for the + * specified vector. + * + * Input parameters: + * vector - interrupt vector number + * new_handler - replacement ISR for this vector number + * old_handler - pointer to former ISR for this vector number + * + * Output parameters: + * *old_handler - former ISR for this vector number + * + */ + +void _CPU_ISR_install_vector( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + unsigned32 real_vector; + proc_ptr ignored; + + /* + * Get the "real" trap number for this vector ignoring the synchronous + * versus asynchronous indicator included with our vector numbers. + */ + + real_vector = SPARC_REAL_TRAP_NUMBER( vector ); + + /* + * Return the previous ISR handler. + */ + + *old_handler = _ISR_Vector_table[ real_vector ]; + + /* + * Install the wrapper so this ISR can be invoked properly. + */ + + _CPU_ISR_install_raw_handler( vector, _ISR_Handler, &ignored ); + + /* + * We put the actual user ISR address in '_ISR_vector_table'. This will + * be used by the _ISR_Handler so the user gets control. + */ + + _ISR_Vector_table[ real_vector ] = new_handler; +} + +/*PAGE + * + * _CPU_Context_Initialize + * + * This kernel routine initializes the basic non-FP context area associated + * with each thread. + * + * Input parameters: + * the_context - pointer to the context area + * stack_base - address of memory for the SPARC + * size - size in bytes of the stack area + * new_level - interrupt level for this context area + * entry_point - the starting execution point for this this context + * is_fp - TRUE if this context is associated with an FP thread + * + * Output parameters: NONE + */ + +void _CPU_Context_Initialize( + Context_Control *the_context, + unsigned32 *stack_base, + unsigned32 size, + unsigned32 new_level, + void *entry_point, + boolean is_fp +) +{ + unsigned32 stack_high; /* highest "stack aligned" address */ + unsigned32 the_size; + unsigned32 tmp_psr; + + /* + * On CPUs with stacks which grow down (i.e. SPARC), we build the stack + * based on the stack_high address. + */ + + stack_high = ((unsigned32)(stack_base) + size); + stack_high &= ~(CPU_STACK_ALIGNMENT - 1); + + the_size = size & ~(CPU_STACK_ALIGNMENT - 1); + + /* + * See the README in this directory for a diagram of the stack. + */ + + the_context->o7 = ((unsigned32) entry_point) - 8; + the_context->o6_sp = stack_high - CPU_MINIMUM_STACK_FRAME_SIZE; + the_context->i6_fp = stack_high; + + /* + * Build the PSR for the task. Most everything can be 0 and the + * CWP is corrected during the context switch. + * + * The EF bit determines if the floating point unit is available. + * The FPU is ONLY enabled if the context is associated with an FP task + * and this SPARC model has an FPU. + */ + + sparc_get_psr( tmp_psr ); + tmp_psr &= ~SPARC_PSR_PIL_MASK; + tmp_psr |= (new_level << 8) & SPARC_PSR_PIL_MASK; + tmp_psr &= ~SPARC_PSR_EF_MASK; /* disabled by default */ + +#if (SPARC_HAS_FPU == 1) + /* + * If this bit is not set, then a task gets a fault when it accesses + * a floating point register. This is a nice way to detect floating + * point tasks which are not currently declared as such. + */ + + if ( is_fp ) + tmp_psr |= SPARC_PSR_EF_MASK; +#endif + the_context->psr = tmp_psr; +} + +/*PAGE + * + * _CPU_Thread_Idle_body + * + * Some SPARC implementations have low power, sleep, or idle modes. This + * tries to take advantage of those models. + */ + +#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE) + +/* + * This is the implementation for the erc32. + * + * NOTE: Low power mode was enabled at initialization time. + */ + +#if defined(erc32) + +void _CPU_Thread_Idle_body( void ) +{ + while (1) { + ERC32_MEC.Power_Down = 0; /* value is irrelevant */ + } +} + +#endif + +#endif /* CPU_PROVIDES_IDLE_THREAD_BODY */ diff --git a/cpukit/score/cpu/sparc/rtems/asm.h b/cpukit/score/cpu/sparc/rtems/asm.h new file mode 100644 index 0000000000..a3d62416b8 --- /dev/null +++ b/cpukit/score/cpu/sparc/rtems/asm.h @@ -0,0 +1,111 @@ +/* asm.h + * + * This include file attempts to address the problems + * caused by incompatible flavors of assemblers and + * toolsets. It primarily addresses variations in the + * use of leading underscores on symbols and the requirement + * that register names be preceded by a %. + * + * + * NOTE: The spacing in the use of these macros + * is critical to them working as advertised. + * + * COPYRIGHT: + * + * This file is based on similar code found in newlib available + * from ftp.cygnus.com. The file which was used had no copyright + * notice. This file is freely distributable as long as the source + * of the file is noted. + * + * $Id$ + */ + +#ifndef __SPARC_ASM_h +#define __SPARC_ASM_h + +/* + * Indicate we are in an assembly file and get the basic CPU definitions. + */ + +#define ASM + +#include <rtems/score/sparc.h> +#include <rtems/score/cpu.h> + +/* + * Recent versions of GNU cpp define variables which indicate the + * need for underscores and percents. If not using GNU cpp or + * the version does not support this, then you will obviously + * have to define these as appropriate. + */ + +/* XXX __USER_LABEL_PREFIX__ and __REGISTER_PREFIX__ do not work on gcc 2.7.0 */ +/* XXX The following ifdef magic fixes the problem but results in a warning */ +/* XXX when compiling assembly code. */ +#undef __USER_LABEL_PREFIX__ +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#ifndef __REGISTER_PREFIX__ +#define __REGISTER_PREFIX__ +#endif + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a ## b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) + +/* + * define macros for all of the registers on this CPU + * + * EXAMPLE: #define d0 REG (d0) + */ + +/* + * Define macros to handle section beginning and ends. + */ + + +#define BEGIN_CODE_DCL .text +#define END_CODE_DCL +#define BEGIN_DATA_DCL .data +#define END_DATA_DCL +#define BEGIN_CODE .text +#define END_CODE +#define BEGIN_DATA +#define END_DATA +#define BEGIN_BSS +#define END_BSS +#define END + +/* + * Following must be tailor for a particular flavor of the C compiler. + * They may need to put underscores in front of the symbols. + */ + +#define PUBLIC(sym) .globl SYM (sym) +#define EXTERN(sym) .globl SYM (sym) + +/* + * Entry for traps which jump to a programmer-specified trap handler. + */ + +#define TRAP(_vector, _handler) \ + mov %psr, %l0 ; \ + sethi %hi(_handler), %l4 ; \ + jmp %l4+%lo(_handler); \ + mov _vector, %l3 + +#endif +/* end of include file */ + + diff --git a/cpukit/score/cpu/unix/cpu.c b/cpukit/score/cpu/unix/cpu.c new file mode 100644 index 0000000000..4c1604465f --- /dev/null +++ b/cpukit/score/cpu/unix/cpu.c @@ -0,0 +1,969 @@ +/* + * UNIX Simulator Dependent Source + * + * + * To anyone who acknowledges that this file is provided "AS IS" + * without any express or implied warranty: + * permission to use, copy, modify, and distribute this file + * for any purpose is hereby granted without fee, provided that + * the above copyright notice and this notice appears in all + * copies, and that the name of Division Incorporated not be + * used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * Division Incorporated makes no representations about the + * suitability of this software for any purpose. + * + * $Id$ + */ + +#include <rtems/system.h> +#include <rtems/score/isr.h> +#include <rtems/score/interr.h> + +#if defined(solaris2) +/* +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 3 +#undef __STRICT_ANSI__ +#define __STRICT_ANSI__ +*/ +#define __EXTENSIONS__ +#endif + +#if defined(linux) +#define MALLOC_0_RETURNS_NULL +#endif + +#include <sys/types.h> +#include <sys/times.h> +#include <stdio.h> +#include <stdlib.h> +#include <setjmp.h> +#include <signal.h> +#include <time.h> +#include <sys/time.h> +#include <errno.h> +#include <unistd.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <sys/sem.h> +#include <string.h> /* memset */ + +#ifndef SA_RESTART +#define SA_RESTART 0 +#endif + +typedef struct { + jmp_buf regs; + sigset_t isr_level; +} Context_Control_overlay; + +void _CPU_Signal_initialize(void); +void _CPU_Stray_signal(int); +void _CPU_ISR_Handler(int); + +sigset_t _CPU_Signal_mask; +Context_Control _CPU_Context_Default_with_ISRs_enabled; +Context_Control _CPU_Context_Default_with_ISRs_disabled; + +/* + * Which cpu are we? Used by libcpu and libbsp. + */ + +int cpu_number; + +/*PAGE + * + * _CPU_ISR_From_CPU_Init + */ + +sigset_t posix_empty_mask; + +void _CPU_ISR_From_CPU_Init() +{ + unsigned32 i; + proc_ptr old_handler; + + /* + * Generate an empty mask to be used by disable_support + */ + + sigemptyset(&posix_empty_mask); + + /* + * Block all the signals except SIGTRAP for the debugger + * and SIGABRT for fatal errors. + */ + + (void) sigfillset(&_CPU_Signal_mask); + (void) sigdelset(&_CPU_Signal_mask, SIGTRAP); + (void) sigdelset(&_CPU_Signal_mask, SIGABRT); + (void) sigdelset(&_CPU_Signal_mask, SIGIOT); + (void) sigdelset(&_CPU_Signal_mask, SIGCONT); + + _CPU_ISR_Enable(1); + + /* + * Set the handler for all signals to be signal_handler + * which will then vector out to the correct handler + * for whichever signal actually happened. Initially + * set the vectors to the stray signal handler. + */ + + for (i = 0; i < CPU_INTERRUPT_NUMBER_OF_VECTORS; i++) + (void)_CPU_ISR_install_vector(i, _CPU_Stray_signal, &old_handler); + + _CPU_Signal_initialize(); +} + +void _CPU_Signal_initialize( void ) +{ + struct sigaction act; + sigset_t mask; + + /* mark them all active except for TraceTrap and Abort */ + + sigfillset(&mask); + sigdelset(&mask, SIGTRAP); + sigdelset(&mask, SIGABRT); + sigdelset(&mask, SIGIOT); + sigdelset(&mask, SIGCONT); + sigprocmask(SIG_UNBLOCK, &mask, 0); + + act.sa_handler = _CPU_ISR_Handler; + act.sa_mask = mask; + act.sa_flags = SA_RESTART; + + sigaction(SIGHUP, &act, 0); + sigaction(SIGINT, &act, 0); + sigaction(SIGQUIT, &act, 0); + sigaction(SIGILL, &act, 0); +#ifdef SIGEMT + sigaction(SIGEMT, &act, 0); +#endif + sigaction(SIGFPE, &act, 0); + sigaction(SIGKILL, &act, 0); + sigaction(SIGBUS, &act, 0); + sigaction(SIGSEGV, &act, 0); +#ifdef SIGSYS + sigaction(SIGSYS, &act, 0); +#endif + sigaction(SIGPIPE, &act, 0); + sigaction(SIGALRM, &act, 0); + sigaction(SIGTERM, &act, 0); + sigaction(SIGUSR1, &act, 0); + sigaction(SIGUSR2, &act, 0); + sigaction(SIGCHLD, &act, 0); + sigaction(SIGCLD, &act, 0); + sigaction(SIGPWR, &act, 0); + sigaction(SIGVTALRM, &act, 0); + sigaction(SIGPROF, &act, 0); + sigaction(SIGIO, &act, 0); + sigaction(SIGWINCH, &act, 0); + sigaction(SIGSTOP, &act, 0); + sigaction(SIGTTIN, &act, 0); + sigaction(SIGTTOU, &act, 0); + sigaction(SIGURG, &act, 0); +#ifdef SIGLOST + sigaction(SIGLOST, &act, 0); +#endif + +} + +/*PAGE + * + * _CPU_Context_From_CPU_Init + */ + +void _CPU_Context_From_CPU_Init() +{ + +#if defined(hppa1_1) && defined(RTEMS_UNIXLIB_SETJMP) + /* + * HACK - set the _SYSTEM_ID to 0x20c so that setjmp/longjmp + * will handle the full 32 floating point registers. + */ + + { + extern unsigned32 _SYSTEM_ID; + + _SYSTEM_ID = 0x20c; + } +#endif + + /* + * get default values to use in _CPU_Context_Initialize() + */ + + + (void) memset( + &_CPU_Context_Default_with_ISRs_enabled, + 0, + sizeof(Context_Control) + ); + (void) memset( + &_CPU_Context_Default_with_ISRs_disabled, + 0, + sizeof(Context_Control) + ); + + _CPU_ISR_Set_level( 0 ); + _CPU_Context_switch( + &_CPU_Context_Default_with_ISRs_enabled, + &_CPU_Context_Default_with_ISRs_enabled + ); + + _CPU_ISR_Set_level( 1 ); + _CPU_Context_switch( + &_CPU_Context_Default_with_ISRs_disabled, + &_CPU_Context_Default_with_ISRs_disabled + ); +} + +/*PAGE + * + * _CPU_ISR_Get_level + */ + +sigset_t GET_old_mask; + +unsigned32 _CPU_ISR_Get_level( void ) +{ +/* sigset_t old_mask; */ + unsigned32 old_level; + + sigprocmask(0, 0, &GET_old_mask); + + if (memcmp((void *)&posix_empty_mask, (void *)&GET_old_mask, sizeof(sigset_t))) + old_level = 1; + else + old_level = 0; + + return old_level; +} + +/* _CPU_Initialize + * + * This routine performs processor dependent initialization. + * + * INPUT PARAMETERS: + * cpu_table - CPU table to initialize + * thread_dispatch - address of disptaching routine + */ + + +void _CPU_Initialize( + rtems_cpu_table *cpu_table, + void (*thread_dispatch) /* ignored on this CPU */ +) +{ + /* + * The thread_dispatch argument is the address of the entry point + * for the routine called at the end of an ISR once it has been + * decided a context switch is necessary. On some compilation + * systems it is difficult to call a high-level language routine + * from assembly. This allows us to trick these systems. + * + * If you encounter this problem save the entry point in a CPU + * dependent variable. + */ + + _CPU_Thread_dispatch_pointer = thread_dispatch; + + /* + * XXX; If there is not an easy way to initialize the FP context + * during Context_Initialize, then it is usually easier to + * save an "uninitialized" FP context here and copy it to + * the task's during Context_Initialize. + */ + + /* XXX: FP context initialization support */ + + _CPU_Table = *cpu_table; + + _CPU_ISR_From_CPU_Init(); + + _CPU_Context_From_CPU_Init(); + +} + +/*PAGE + * + * _CPU_ISR_install_raw_handler + */ + +void _CPU_ISR_install_raw_handler( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + _CPU_Fatal_halt( 0xdeaddead ); +} + +/*PAGE + * + * _CPU_ISR_install_vector + * + * This kernel routine installs the RTEMS handler for the + * specified vector. + * + * Input parameters: + * vector - interrupt vector number + * old_handler - former ISR for this vector number + * new_handler - replacement ISR for this vector number + * + * Output parameters: NONE + * + */ + + +void _CPU_ISR_install_vector( + unsigned32 vector, + proc_ptr new_handler, + proc_ptr *old_handler +) +{ + *old_handler = _ISR_Vector_table[ vector ]; + + /* + * If the interrupt vector table is a table of pointer to isr entry + * points, then we need to install the appropriate RTEMS interrupt + * handler for this vector number. + */ + + /* + * We put the actual user ISR address in '_ISR_vector_table'. This will + * be used by the _CPU_ISR_Handler so the user gets control. + */ + + _ISR_Vector_table[ vector ] = new_handler; +} + +/*PAGE + * + * _CPU_Install_interrupt_stack + */ + +void _CPU_Install_interrupt_stack( void ) +{ +} + +/*PAGE + * + * _CPU_Thread_Idle_body + * + * Stop until we get a signal which is the logically the same thing + * entering low-power or sleep mode on a real processor and waiting for + * an interrupt. This significantly reduces the consumption of host + * CPU cycles which is again similar to low power mode. + */ + +void _CPU_Thread_Idle_body( void ) +{ + while (1) + pause(); +} + +/*PAGE + * + * _CPU_Context_Initialize + */ + +void _CPU_Context_Initialize( + Context_Control *_the_context, + unsigned32 *_stack_base, + unsigned32 _size, + unsigned32 _new_level, + void *_entry_point, + boolean _is_fp +) +{ + void *source; + unsigned32 *addr; + unsigned32 jmp_addr; + unsigned32 _stack_low; /* lowest "stack aligned" address */ + unsigned32 _stack_high; /* highest "stack aligned" address */ + unsigned32 _the_size; + + jmp_addr = (unsigned32) _entry_point; + + /* + * On CPUs with stacks which grow down, we build the stack + * based on the _stack_high address. On CPUs with stacks which + * grow up, we build the stack based on the _stack_low address. + */ + + _stack_low = (unsigned32)(_stack_base) + CPU_STACK_ALIGNMENT - 1; + _stack_low &= ~(CPU_STACK_ALIGNMENT - 1); + + _stack_high = (unsigned32)(_stack_base) + _size; + _stack_high &= ~(CPU_STACK_ALIGNMENT - 1); + + if (_stack_high > _stack_low) + _the_size = _stack_high - _stack_low; + else + _the_size = _stack_low - _stack_high; + + /* + * Slam our jmp_buf template into the context we are creating + */ + + if ( _new_level == 0 ) + source = &_CPU_Context_Default_with_ISRs_enabled; + else + source = &_CPU_Context_Default_with_ISRs_disabled; + + memcpy( + _the_context, + source, + sizeof(Context_Control) /* sizeof(jmp_buf)); */ + ); + + addr = (unsigned32 *)_the_context; + +#if defined(hppa1_1) + *(addr + RP_OFF) = jmp_addr; + *(addr + SP_OFF) = (unsigned32)(_stack_low + CPU_FRAME_SIZE); + + /* + * See if we are using shared libraries by checking + * bit 30 in 24 off of newp. If bit 30 is set then + * we are using shared libraries and the jump address + * points to the pointer, so we put that into rp instead. + */ + + if (jmp_addr & 0x40000000) { + jmp_addr &= 0xfffffffc; + *(addr + RP_OFF) = *(unsigned32 *)jmp_addr; + } +#elif defined(sparc) + + /* + * See /usr/include/sys/stack.h in Solaris 2.3 for a nice + * diagram of the stack. + */ + + asm ("ta 0x03"); /* flush registers */ + + *(addr + RP_OFF) = jmp_addr + ADDR_ADJ_OFFSET; + *(addr + SP_OFF) = (unsigned32)(_stack_high - CPU_FRAME_SIZE); + *(addr + FP_OFF) = (unsigned32)(_stack_high); + +#elif defined(i386) + + /* + * This information was gathered by disassembling setjmp(). + */ + + { + unsigned32 stack_ptr; + + stack_ptr = _stack_high - CPU_FRAME_SIZE; + + *(addr + EBX_OFF) = 0xFEEDFEED; + *(addr + ESI_OFF) = 0xDEADDEAD; + *(addr + EDI_OFF) = 0xDEAFDEAF; + *(addr + EBP_OFF) = stack_ptr; + *(addr + ESP_OFF) = stack_ptr; + *(addr + RET_OFF) = jmp_addr; + + addr = (unsigned32 *) stack_ptr; + + addr[ 0 ] = jmp_addr; + addr[ 1 ] = (unsigned32) stack_ptr; + addr[ 2 ] = (unsigned32) stack_ptr; + } + +#else +#error "UNKNOWN CPU!!!" +#endif + +} + +/*PAGE + * + * _CPU_Context_restore + */ + +void _CPU_Context_restore( + Context_Control *next +) +{ + Context_Control_overlay *nextp = (Context_Control_overlay *)next; + + sigprocmask( SIG_SETMASK, &nextp->isr_level, 0 ); + longjmp( nextp->regs, 0 ); +} + +/*PAGE + * + * _CPU_Context_switch + */ + +void _CPU_Context_switch( + Context_Control *current, + Context_Control *next +) +{ + Context_Control_overlay *currentp = (Context_Control_overlay *)current; + Context_Control_overlay *nextp = (Context_Control_overlay *)next; + + int status; + + /* + * Switch levels in one operation + */ + + status = sigprocmask( SIG_SETMASK, &nextp->isr_level, ¤tp->isr_level ); + if ( status ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + status + ); + + if (setjmp(currentp->regs) == 0) { /* Save the current context */ + longjmp(nextp->regs, 0); /* Switch to the new context */ + if ( status ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + status + ); + } + +} + +/*PAGE + * + * _CPU_Save_float_context + */ + +void _CPU_Save_float_context( + Context_Control_fp *fp_context +) +{ +} + +/*PAGE + * + * _CPU_Restore_float_context + */ + +void _CPU_Restore_float_context( + Context_Control_fp *fp_context +) +{ +} + +/*PAGE + * + * _CPU_ISR_Disable_support + */ + +unsigned32 _CPU_ISR_Disable_support(void) +{ + int status; + sigset_t old_mask; + + status = sigprocmask(SIG_BLOCK, &_CPU_Signal_mask, &old_mask); + if ( status ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + status + ); + + if (memcmp((void *)&posix_empty_mask, (void *)&old_mask, sizeof(sigset_t))) + return 1; + + return 0; +} + +/*PAGE + * + * _CPU_ISR_Enable + */ + +void _CPU_ISR_Enable( + unsigned32 level +) +{ + int status; + + if (level == 0) + status = sigprocmask(SIG_UNBLOCK, &_CPU_Signal_mask, 0); + else + status = sigprocmask(SIG_BLOCK, &_CPU_Signal_mask, 0); + + if ( status ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + status + ); +} + +/*PAGE + * + * _CPU_ISR_Handler + * + * External interrupt handler. + * This is installed as a UNIX signal handler. + * It vectors out to specific user interrupt handlers. + */ + +void _CPU_ISR_Handler(int vector) +{ + extern void _Thread_Dispatch(void); + extern unsigned32 _Thread_Dispatch_disable_level; + extern boolean _Context_Switch_necessary; + + if (_ISR_Nest_level++ == 0) { + /* switch to interrupt stack */ + } + + _Thread_Dispatch_disable_level++; + + if (_ISR_Vector_table[vector]) { + _ISR_Vector_table[vector](vector); + } else { + _CPU_Stray_signal(vector); + } + + if (_ISR_Nest_level-- == 0) { + /* switch back to original stack */ + } + + _Thread_Dispatch_disable_level--; + + if (_Thread_Dispatch_disable_level == 0 && + (_Context_Switch_necessary || _ISR_Signals_to_thread_executing)) { + _ISR_Signals_to_thread_executing = FALSE; + _CPU_ISR_Enable(0); + _Thread_Dispatch(); + } +} + +/*PAGE + * + * _CPU_Stray_signal + */ + +void _CPU_Stray_signal(int sig_num) +{ + char buffer[ 4 ]; + + /* + * print "stray" msg about ones which that might mean something + * Avoid using the stdio section of the library. + * The following is generally safe. + */ + + switch (sig_num) + { + case SIGCLD: + break; + + default: + { + /* + * We avoid using the stdio section of the library. + * The following is generally safe + */ + + int digit; + int number = sig_num; + int len = 0; + + digit = number / 100; + number %= 100; + if (digit) buffer[len++] = '0' + digit; + + digit = number / 10; + number %= 10; + if (digit || len) buffer[len++] = '0' + digit; + + digit = number; + buffer[len++] = '0' + digit; + + buffer[ len++ ] = '\n'; + + write( 2, "Stray signal ", 13 ); + write( 2, buffer, len ); + + } + } + + /* + * If it was a "fatal" signal, then exit here + * If app code has installed a hander for one of these, then + * we won't call _CPU_Stray_signal, so this is ok. + */ + + switch (sig_num) { + case SIGINT: + case SIGHUP: + case SIGQUIT: + case SIGILL: +#ifdef SIGEMT + case SIGEMT: +#endif + case SIGKILL: + case SIGBUS: + case SIGSEGV: + case SIGTERM: + _CPU_Fatal_error(0x100 + sig_num); + } +} + +/*PAGE + * + * _CPU_Fatal_error + */ + +void _CPU_Fatal_error(unsigned32 error) +{ + setitimer(ITIMER_REAL, 0, 0); + + if ( error ) { +#ifdef RTEMS_DEBUG + abort(); +#endif + if (getenv("RTEMS_DEBUG")) + abort(); + } + + _exit(error); +} + +/* + * Special Purpose Routines to hide the use of UNIX system calls. + */ + +int _CPU_Get_clock_vector( void ) +{ + return SIGALRM; +} + +void _CPU_Start_clock( + int microseconds +) +{ + struct itimerval new; + + new.it_value.tv_sec = 0; + new.it_value.tv_usec = microseconds; + new.it_interval.tv_sec = 0; + new.it_interval.tv_usec = microseconds; + + setitimer(ITIMER_REAL, &new, 0); +} + +void _CPU_Stop_clock( void ) +{ + struct itimerval new; + struct sigaction act; + + /* + * Set the SIGALRM signal to ignore any last + * signals that might come in while we are + * disarming the timer and removing the interrupt + * vector. + */ + + (void) memset(&act, 0, sizeof(act)); + act.sa_handler = SIG_IGN; + + sigaction(SIGALRM, &act, 0); + + (void) memset(&new, 0, sizeof(new)); + setitimer(ITIMER_REAL, &new, 0); +} + +int _CPU_SHM_Semid; +extern void fix_syscall_errno( void ); + +void _CPU_SHM_Init( + unsigned32 maximum_nodes, + boolean is_master_node, + void **shm_address, + unsigned32 *shm_length +) +{ + int i; + int shmid; + char *shm_addr; + key_t shm_key; + key_t sem_key; + int status; + int shm_size; + + if (getenv("RTEMS_SHM_KEY")) + shm_key = strtol(getenv("RTEMS_SHM_KEY"), 0, 0); + else +#ifdef RTEMS_SHM_KEY + shm_key = RTEMS_SHM_KEY; +#else + shm_key = 0xa000; +#endif + + if (getenv("RTEMS_SHM_SIZE")) + shm_size = strtol(getenv("RTEMS_SHM_SIZE"), 0, 0); + else +#ifdef RTEMS_SHM_SIZE + shm_size = RTEMS_SHM_SIZE; +#else + shm_size = 64 * 1024; +#endif + + if (getenv("RTEMS_SHM_SEMAPHORE_KEY")) + sem_key = strtol(getenv("RTEMS_SHM_SEMAPHORE_KEY"), 0, 0); + else +#ifdef RTEMS_SHM_SEMAPHORE_KEY + sem_key = RTEMS_SHM_SEMAPHORE_KEY; +#else + sem_key = 0xa001; +#endif + + shmid = shmget(shm_key, shm_size, IPC_CREAT | 0660); + if ( shmid == -1 ) { + fix_syscall_errno(); /* in case of newlib */ + perror( "shmget" ); + _CPU_Fatal_halt( 0xdead0001 ); + } + + shm_addr = shmat(shmid, (char *)0, SHM_RND); + if ( shm_addr == (void *)-1 ) { + fix_syscall_errno(); /* in case of newlib */ + perror( "shmat" ); + _CPU_Fatal_halt( 0xdead0002 ); + } + + _CPU_SHM_Semid = semget(sem_key, maximum_nodes + 1, IPC_CREAT | 0660); + if ( _CPU_SHM_Semid == -1 ) { + fix_syscall_errno(); /* in case of newlib */ + perror( "semget" ); + _CPU_Fatal_halt( 0xdead0003 ); + } + + if ( is_master_node ) { + for ( i=0 ; i <= maximum_nodes ; i++ ) { +#if defined(solaris2) + union semun { + int val; + struct semid_ds *buf; + ushort *array; + } help; + + help.val = 1; + status = semctl( _CPU_SHM_Semid, i, SETVAL, help ); +#endif +#if defined(hpux) + status = semctl( _CPU_SHM_Semid, i, SETVAL, 1 ); +#endif + + fix_syscall_errno(); /* in case of newlib */ + if ( status == -1 ) { + _CPU_Fatal_halt( 0xdead0004 ); + } + } + } + + *shm_address = shm_addr; + *shm_length = shm_size; + +} + +int _CPU_Get_pid( void ) +{ + return getpid(); +} + +/* + * Define this to use signals for MPCI shared memory driver. + * If undefined, the shared memory driver will poll from the + * clock interrupt. + * Ref: ../shmsupp/getcfg.c + * + * BEWARE:: many UN*X kernels and debuggers become severely confused when + * debugging programs which use signals. The problem is *much* + * worse when using multiple signals, since ptrace(2) tends to + * drop all signals except 1 in the case of multiples. + * On hpux9, this problem was so bad, we couldn't use interrupts + * with the shared memory driver if we ever hoped to debug + * RTEMS programs. + * Maybe systems that use /proc don't have this problem... + */ + + +int _CPU_SHM_Get_vector( void ) +{ +#ifdef CPU_USE_SHM_INTERRUPTS + return SIGUSR1; +#else + return 0; +#endif +} + +void _CPU_SHM_Send_interrupt( + int pid, + int vector +) +{ + kill((pid_t) pid, vector); +} + +void _CPU_SHM_Lock( + int semaphore +) +{ + struct sembuf sb; + int status; + + sb.sem_num = semaphore; + sb.sem_op = -1; + sb.sem_flg = 0; + + while (1) { + status = semop(_CPU_SHM_Semid, &sb, 1); + if ( status >= 0 ) + break; + if ( status == -1 ) { + fix_syscall_errno(); /* in case of newlib */ + if (errno == EINTR) + continue; + perror("shm lock"); + _CPU_Fatal_halt( 0xdead0005 ); + } + } + +} + +void _CPU_SHM_Unlock( + int semaphore +) +{ + struct sembuf sb; + int status; + + sb.sem_num = semaphore; + sb.sem_op = 1; + sb.sem_flg = 0; + + while (1) { + status = semop(_CPU_SHM_Semid, &sb, 1); + if ( status >= 0 ) + break; + + if ( status == -1 ) { + fix_syscall_errno(); /* in case of newlib */ + if (errno == EINTR) + continue; + perror("shm unlock"); + _CPU_Fatal_halt( 0xdead0006 ); + } + } + +} diff --git a/cpukit/score/include/rtems/debug.h b/cpukit/score/include/rtems/debug.h new file mode 100644 index 0000000000..afe6251bbe --- /dev/null +++ b/cpukit/score/include/rtems/debug.h @@ -0,0 +1,98 @@ +/* debug.h + * + * This include file contains the information pertaining to the debug + * support within RTEMS. It is currently cast in the form of a + * Manager since it is externally accessible. + * + * + * 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$ + */ + +#ifndef __RTEMS_DEBUG_h +#define __RTEMS_DEBUG_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The following type is used to manage the debug mask. + */ + +typedef unsigned32 rtems_debug_control; + +/* + * These constants represent various classes of debugging. + */ + +#define RTEMS_DEBUG_ALL_MASK 0xffffffff +#define RTEMS_DEBUG_REGION 0x00000001 + +/* + * This variable contains the current debug level. + */ + +EXTERN rtems_debug_control _Debug_Level; + +/* + * _Debug_Manager_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this manager. + */ + +void _Debug_Manager_initialization( void ); + +/* + * rtems_debug_enable + * + * DESCRIPTION: + * + * This routine enables the specified types of debug checks. + */ + +void rtems_debug_enable ( + rtems_debug_control to_be_enabled +); + +/* + * rtems_debug_disable + * + * DESCRIPTION: + * + * This routine disables the specified types of debug checks. + */ + +void rtems_debug_disable ( + rtems_debug_control to_be_disabled +); + +/* + * + * _Debug_Is_enabled + * + * DESCRIPTION: + * + * This routine returns TRUE if the requested debug level is + * enabled, and FALSE otherwise. + */ + +boolean _Debug_Is_enabled( + rtems_debug_control level +); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/address.h b/cpukit/score/include/rtems/score/address.h new file mode 100644 index 0000000000..d9be75ee4b --- /dev/null +++ b/cpukit/score/include/rtems/score/address.h @@ -0,0 +1,31 @@ +/* address.h + * + * This include file contains the information required to manipulate + * physical addresses. + * + * 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$ + */ + +#ifndef __RTEMS_ADDRESSES_h +#define __RTEMS_ADDRESSES_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/address.inl> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/apiext.h b/cpukit/score/include/rtems/score/apiext.h new file mode 100644 index 0000000000..44e7bc8dd3 --- /dev/null +++ b/cpukit/score/include/rtems/score/apiext.h @@ -0,0 +1,102 @@ +/* apiext.h + * + * XXX + * + * 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$ + */ + + +#ifndef __API_EXTENSIONS_h +#define __API_EXTENSIONS_h + +#include <rtems/score/chain.h> +#include <rtems/score/thread.h> + +/* + * The control structure which defines the points at which an API + * can add an extension to the system initialization thread. + */ + +typedef void (*API_extensions_Predriver_hook)(void); +typedef void (*API_extensions_Postdriver_hook)(void); +typedef void (*API_extensions_Postswitch_hook)( + Thread_Control * + ); + + +typedef struct { + Chain_Node Node; + API_extensions_Predriver_hook predriver_hook; + API_extensions_Postdriver_hook postdriver_hook; + API_extensions_Postswitch_hook postswitch_hook; +} API_extensions_Control; + +/* + * This is the list of API extensions to the system initialization. + */ + +EXTERN Chain_Control _API_extensions_List; + +/* + * _API_extensions_Initialization + * + * DESCRIPTION: + * + * This routine initializes the API extension handler. + * + */ + +void _API_extensions_Initialization( void ); + +/* + * _API_extensions_Add + * + * DESCRIPTION: + * + * XXX + */ + +void _API_extensions_Add( + API_extensions_Control *the_extension +); + +/* + * _API_extensions_Run_predriver + * + * DESCRIPTION: + * + * XXX + */ + +void _API_extensions_Run_predriver( void ); + +/* + * _API_extensions_Run_postdriver + * + * DESCRIPTION: + * + * XXX + */ + +void _API_extensions_Run_postdriver( void ); + +/* + * _API_extensions_Run_postswitch + * + * DESCRIPTION: + * + * XXX + */ + +void _API_extensions_Run_postswitch( void ); + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/bitfield.h b/cpukit/score/include/rtems/score/bitfield.h new file mode 100644 index 0000000000..6dbf1e0ba0 --- /dev/null +++ b/cpukit/score/include/rtems/score/bitfield.h @@ -0,0 +1,98 @@ +/* bitfield.h + * + * This include file contains all bit field manipulation routines. + * + * 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$ + */ + +#ifndef __RTEMS_BITFIELD_h +#define __RTEMS_BITFIELD_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * _Bitfield_Find_first_bit + * + * DESCRIPTION: + * + * This routine returns the bit_number of the first bit set + * in the specified value. The correspondence between bit_number + * and actual bit position is processor dependent. The search for + * the first bit set may run from most to least significant bit + * or vice-versa. + * + * NOTE: + * + * This routine is used when the executing thread is removed + * from the ready state and, as a result, its performance has a + * significant impact on the performance of the executive as a whole. + */ + +#if ( CPU_USE_GENERIC_BITFIELD_DATA == TRUE ) + +#ifndef INIT + extern const unsigned char __log2table[256]; +#else +const unsigned char __log2table[256] = { + 7, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; +#endif + +#endif + +#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE ) + +#define _Bitfield_Find_first_bit( _value, _bit_number ) \ + _CPU_Bitfield_Find_first_bit( _value, _bit_number ) + +#else + +/* + * The following must be a macro because if a CPU specific version + * is used it will most likely use inline assembly. + */ + +#define _Bitfield_Find_first_bit( _value, _bit_number ) \ + { \ + register __value = (_value); \ + register const unsigned char *__p = __log2table; \ + \ + if ( __value < 0x100 ) \ + (_bit_number) = __p[ __value ] + 8; \ + else \ + (_bit_number) = __p[ __value >> 8 ]; \ + } + +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/chain.h b/cpukit/score/include/rtems/score/chain.h new file mode 100644 index 0000000000..11c1f8aee0 --- /dev/null +++ b/cpukit/score/include/rtems/score/chain.h @@ -0,0 +1,168 @@ +/* chain.h + * + * This include file contains all the constants and structures associated + * with the Doubly Linked Chain 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$ + */ + +#ifndef __RTEMS_CHAIN_h +#define __RTEMS_CHAIN_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/address.h> + +/* + * This is used to manage each element (node) which is placed + * on a chain. + * + * NOTE: Typically, a more complicated structure will use the + * chain package. The more complicated structure will + * include a chain node as the first element in its + * control structure. It will then call the chain package + * with a pointer to that node element. The node pointer + * and the higher level structure start at the same address + * so the user can cast the pointers back and forth. + * + */ + +typedef struct Chain_Node_struct Chain_Node; + +struct Chain_Node_struct { + Chain_Node *next; + Chain_Node *previous; +}; + +/* + * This is used to manage a chain. A chain consists of a doubly + * linked list of zero or more nodes. + * + * NOTE: This implementation does not require special checks for + * manipulating the first and last elements on the chain. + * To accomplish this the chain control structure is + * treated as two overlapping chain nodes. The permanent + * head of the chain overlays a node structure on the + * first and permanent_null fields. The permanent tail + * of the chain overlays a node structure on the + * permanent_null and last elements of the structure. + * + */ + +typedef struct { + Chain_Node *first; + Chain_Node *permanent_null; + Chain_Node *last; +} Chain_Control; + +/* + * _Chain_Initialize + * + * DESCRIPTION: + * + * This routine initializes the_chain structure to manage the + * contiguous array of number_nodes nodes which starts at + * starting_address. Each node is of node_size bytes. + * + */ + +void _Chain_Initialize( + Chain_Control *the_chain, + void *starting_address, + unsigned32 number_nodes, + unsigned32 node_size +); + +/* + * _Chain_Get_first_unprotected + */ + +#ifndef USE_INLINES +Chain_Node *_Chain_Get_first_unprotected( + Chain_Control *the_chain +); +#endif + +/* + * _Chain_Extract + * + * DESCRIPTION: + * + * This routine extracts the_node from the chain on which it resides. + * It disables interrupts to insure the atomicity of the + * extract operation. + * + */ + +void _Chain_Extract( + Chain_Node *the_node +); + +/* + * _Chain_Get + * + * DESCRIPTION: + * + * This function removes the first node from the_chain and returns + * a pointer to that node. If the_chain is empty, then NULL is returned. + * It disables interrupts to insure the atomicity of the + * get operation. + * + */ + +Chain_Node *_Chain_Get( + Chain_Control *the_chain +); + +/* + * _Chain_Insert + * + * DESCRIPTION: + * + * This routine inserts the_node on a chain immediately following + * after_node. It disables interrupts to insure the atomicity + * of the extract operation. + * + */ + +void _Chain_Insert( + Chain_Node *after_node, + Chain_Node *the_node +); + +/* + * _Chain_Append + * + * DESCRIPTION: + * + * This routine appends the_node onto the end of the_chain. + * It disables interrupts to insure the atomicity of the + * append operation. + * + */ + +void _Chain_Append( + Chain_Control *the_chain, + Chain_Node *the_node +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/chain.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/context.h b/cpukit/score/include/rtems/score/context.h new file mode 100644 index 0000000000..4cd1f1e4c5 --- /dev/null +++ b/cpukit/score/include/rtems/score/context.h @@ -0,0 +1,134 @@ +/* context.h + * + * This include file contains all information about a context. + * + * 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$ + */ + +#ifndef __RTEMS_CONTEXT_h +#define __RTEMS_CONTEXT_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/cpu.h> + +/* + * The following constant defines the number of bytes required + * to store a full floating point context. + */ + +#define CONTEXT_FP_SIZE CPU_CONTEXT_FP_SIZE + +/* + * The following variable is set to TRUE when a reschedule operation + * has determined that the processor should be taken away from the + * currently executing thread and given to the heir thread. + */ + +EXTERN boolean _Context_Switch_necessary; + +/* + * _Context_Initialize + * + * DESCRIPTION: + * + * This routine initializes THE_CONTEXT such that the stack + * pointer, interrupt level, and entry point are correct for the + * thread's initial state. + */ + +#define \ + _Context_Initialize( _the_context, _stack, _size, _isr, _entry, _is_fp ) \ + _CPU_Context_Initialize( _the_context, _stack, _size, _isr, _entry, _is_fp ) + +/* + * _Context_Switch + * + * DESCRIPTION: + * + * This routine saves the current context into the EXECUTING + * context record and restores the context specified by HEIR. + */ + +#define _Context_Switch( _executing, _heir ) \ + _CPU_Context_switch( _executing, _heir ) + +/* + * _Context_Restart_self + * + * DESCRIPTION: + * + * This routine restarts the calling thread by restoring its initial + * stack pointer and returning to the thread's entry point. + */ + +#define _Context_Restart_self( _the_context ) \ + _CPU_Context_Restart_self( _the_context ) + +/* + * _Context_Fp_start + * + * DESCRIPTION: + * + * This function returns the starting address of the floating + * point context save area. It is assumed that the are reserved + * for the floating point save area is large enough. + */ + +#define _Context_Fp_start( _base, _offset ) \ + _CPU_Context_Fp_start( (_base), (_offset) ) + +/* + * _Context_Initialize_fp + * + * DESCRIPTION: + * + * This routine initializes the floating point context save + * area to contain an initial known state. + */ + +#define _Context_Initialize_fp( _fp_area ) \ + _CPU_Context_Initialize_fp( _fp_area ) + +/* + * _Context_Restore_fp + * + * DESCRIPTION: + * + * This routine restores the floating point context contained + * in the FP_CONTEXT area. It is assumed that the current + * floating point context has been saved by a previous invocation + * of SAVE_FP. + */ + +#define _Context_Restore_fp( _fp ) \ + _CPU_Context_restore_fp( _fp ) + +/* + * _Context_Save_fp + * + * DESCRIPTION: + * + * This routine saves the current floating point context + * in the FP_CONTEXT area. + */ + +#define _Context_Save_fp( _fp ) \ + _CPU_Context_save_fp( _fp ) + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/copyrt.h b/cpukit/score/include/rtems/score/copyrt.h new file mode 100644 index 0000000000..c711ba09b3 --- /dev/null +++ b/cpukit/score/include/rtems/score/copyrt.h @@ -0,0 +1,42 @@ +/* copyrt.h + * + * This include file contains the copyright notice for RTEMS + * which is included in every binary copy of the executive. + * + * 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$ + */ + +#ifndef __RTEMS_COPYRIGHT_h +#define __RTEMS_COPYRIGHT_h + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef INIT + +const char _Copyright_Notice[] = +"COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.\n\ +On-Line Applications Research Corporation (OAR).\n\ +All rights assigned to U.S. Government, 1994.\n"; + +#else + +extern const char _Copyright_Notice[]; + +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/coremsg.h b/cpukit/score/include/rtems/score/coremsg.h new file mode 100644 index 0000000000..b51e07ef61 --- /dev/null +++ b/cpukit/score/include/rtems/score/coremsg.h @@ -0,0 +1,274 @@ +/* coremsg.h + * + * This include file contains all the constants and structures associated + * with the Message queue 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$ + */ + +#ifndef __RTEMS_CORE_MESSAGE_QUEUE_h +#define __RTEMS_CORE_MESSAGE_QUEUE_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> +#include <rtems/score/priority.h> +#include <rtems/score/watchdog.h> + +/* + * The following type defines the callout which the API provides + * to support global/multiprocessor operations on message_queues. + */ + +typedef void ( *CORE_message_queue_API_mp_support_callout )( + Thread_Control *, + Objects_Id + ); + +/* + * The following defines the data types needed to manipulate + * the contents of message buffers. + * Since msgs are variable length we just make a ptr to 1. + */ + +typedef struct { + unsigned32 size; + +#ifndef __cplusplus + /* NOTE: [0] is gcc specific, + * but specifically disallowed by ANSI STD C++ + * g++ warns about it, so we #ifdef it out to + * get rid of warnings when compiled by g++. + */ + unsigned32 buffer[0]; +#endif + +} CORE_message_queue_Buffer; + +/* + * The following records define the organization of a message + * buffer. + */ + +typedef struct { + Chain_Node Node; + CORE_message_queue_Buffer Contents; +} CORE_message_queue_Buffer_control; + +/* + * Blocking disciplines for a message_queue. + */ + +typedef enum { + CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO, + CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY +} CORE_message_queue_Disciplines; + +/* + * The following enumerated type details the modes in which a message + * may be submitted to a message queue. The message may be posted + * in a send or urgent fashion. + */ + +typedef enum { + CORE_MESSAGE_QUEUE_SEND_REQUEST = 0, + CORE_MESSAGE_QUEUE_URGENT_REQUEST = 1 +} CORE_message_queue_Submit_types; + +/* + * Core Message queue handler return statuses. + */ + +typedef enum { + CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL, + CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE, + CORE_MESSAGE_QUEUE_STATUS_TOO_MANY, + CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED, + CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT, + CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED, + CORE_MESSAGE_QUEUE_STATUS_TIMEOUT +} CORE_message_queue_Status; + +/* + * The following defines the control block used to manage the + * attributes of each message queue. + */ + +typedef struct { + CORE_message_queue_Disciplines discipline; +} CORE_message_queue_Attributes; + +/* + * The following defines the type for a Notification handler. A notification + * handler is invoked when the message queue makes a 0->1 transition on + * pending messages. + */ + +typedef void (*CORE_message_queue_Notify_Handler)( void * ); + +/* + * The following defines the control block used to manage each + * counting message_queue. + */ + +typedef struct { + Thread_queue_Control Wait_queue; + CORE_message_queue_Attributes Attributes; + unsigned32 maximum_pending_messages; + unsigned32 number_of_pending_messages; + unsigned32 maximum_message_size; + Chain_Control Pending_messages; + CORE_message_queue_Buffer *message_buffers; + CORE_message_queue_Notify_Handler notify_handler; + void *notify_argument; + Chain_Control Inactive_messages; +} CORE_message_queue_Control; + +/* + * _CORE_message_queue_Initialize + * + * DESCRIPTION: + * + * This routine initializes the message_queue based on the parameters passed. + */ + +boolean _CORE_message_queue_Initialize( + CORE_message_queue_Control *the_message_queue, + Objects_Classes the_class, + CORE_message_queue_Attributes *the_message_queue_attributes, + unsigned32 maximum_pending_messages, + unsigned32 maximum_message_size, + Thread_queue_Extract_callout proxy_extract_callout +); + +/* + * _CORE_message_queue_Close + * + * DESCRIPTION: + * + * This function closes a message by returning all allocated space and + * flushing the message_queue's task wait queue. + */ + +void _CORE_message_queue_Close( + CORE_message_queue_Control *the_message_queue, + Thread_queue_Flush_callout remote_extract_callout, + unsigned32 status +); + +/* + * + * _CORE_message_queue_Flush + * + * DESCRIPTION: + * + * This function flushes the message_queue's task wait queue. The number + * messages flushed from the queue is returned. + * + */ + +unsigned32 _CORE_message_queue_Flush( + CORE_message_queue_Control *the_message_queue +); + +/* + * _CORE_message_queue_Flush_support + * + * DESCRIPTION: + * + * This routine flushes all outstanding messages and returns + * them to the inactive message chain. + */ + +unsigned32 _CORE_message_queue_Flush_support( + CORE_message_queue_Control *the_message_queue +); + +/* + * + * _CORE_message_queue_Broadcast + * + * DESCRIPTION: + * + * This function sends a message for every thread waiting on the queue and + * returns the number of threads made ready by the message. + * + */ + +CORE_message_queue_Status _CORE_message_queue_Broadcast( + CORE_message_queue_Control *the_message_queue, + void *buffer, + unsigned32 size, + Objects_Id id, + CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, + unsigned32 *count +); + +/* + * + * _CORE_message_queue_Submit + * + * DESCRIPTION: + * + * This routine implements the send and urgent message functions. It + * processes a message that is to be submitted to the designated + * message queue. The message will either be processed as a + * send message which it will be inserted at the rear of the queue + * or it will be processed as an urgent message which will be inserted + * at the front of the queue. + * + */ + +CORE_message_queue_Status _CORE_message_queue_Submit( + CORE_message_queue_Control *the_message_queue, + void *buffer, + unsigned32 size, + Objects_Id id, + CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, + CORE_message_queue_Submit_types submit_type +); + +/* + * + * _CORE_message_queue_Seize + * + * DESCRIPTION: + * + * This kernel routine dequeues a message, copies the message buffer to + * a given destination buffer, and frees the message buffer to the + * inactive message pool. The thread will be blocked if wait is TRUE, + * otherwise an error will be given to the thread if no messages are available. + * + */ + +void _CORE_message_queue_Seize( + CORE_message_queue_Control *the_message_queue, + Objects_Id id, + void *buffer, + unsigned32 *size, + boolean wait, + Watchdog_Interval timeout +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/coremsg.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ + diff --git a/cpukit/score/include/rtems/score/coremutex.h b/cpukit/score/include/rtems/score/coremutex.h new file mode 100644 index 0000000000..73b7e34417 --- /dev/null +++ b/cpukit/score/include/rtems/score/coremutex.h @@ -0,0 +1,171 @@ +/* mutex.h + * + * This include file contains all the constants and structures associated + * with the Mutex Handler. A mutex is an enhanced version of the standard + * Dijkstra binary semaphore used to provide synchronization and mutual + * exclusion capabilities. + * + * 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$ + */ + +#ifndef __RTEMS_CORE_MUTEX_h +#define __RTEMS_CORE_MUTEX_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> +#include <rtems/score/priority.h> +#include <rtems/score/watchdog.h> + +/* + * The following type defines the callout which the API provides + * to support global/multiprocessor operations on mutexes. + */ + +typedef void ( *CORE_mutex_API_mp_support_callout )( + Thread_Control *, + Objects_Id + ); + +/* + * Blocking disciplines for a mutex. + */ + +typedef enum { + CORE_MUTEX_DISCIPLINES_FIFO, + CORE_MUTEX_DISCIPLINES_PRIORITY, + CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT, + CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING +} CORE_mutex_Disciplines; + +/* + * Mutex handler return statuses. + */ + +typedef enum { + CORE_MUTEX_STATUS_SUCCESSFUL, + CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT, + CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED, + CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE, + CORE_MUTEX_WAS_DELETED, + CORE_MUTEX_TIMEOUT +} CORE_mutex_Status; + +/* + * Locked and unlocked values + */ + +#define CORE_MUTEX_UNLOCKED 1 +#define CORE_MUTEX_LOCKED 0 + +/* + * The following defines the control block used to manage the + * attributes of each mutex. + */ + +typedef struct { + boolean allow_nesting; + CORE_mutex_Disciplines discipline; + Priority_Control priority_ceiling; +} CORE_mutex_Attributes; + +/* + * The following defines the control block used to manage each mutex. + */ + +typedef struct { + Thread_queue_Control Wait_queue; + CORE_mutex_Attributes Attributes; + unsigned32 lock; + unsigned32 nest_count; + Thread_Control *holder; + Objects_Id holder_id; +} CORE_mutex_Control; + +/* + * _CORE_mutex_Initialize + * + * DESCRIPTION: + * + * This routine initializes the mutex based on the parameters passed. + */ + +void _CORE_mutex_Initialize( + CORE_mutex_Control *the_mutex, + Objects_Classes the_class, + CORE_mutex_Attributes *the_mutex_attributes, + unsigned32 initial_lock, + Thread_queue_Extract_callout proxy_extract_callout +); + +/* + * _CORE_mutex_Seize + * + * DESCRIPTION: + * + * This routine attempts to receive a unit from the_mutex. + * If a unit is available or if the wait flag is FALSE, then the routine + * returns. Otherwise, the calling task is blocked until a unit becomes + * available. + */ + +void _CORE_mutex_Seize( + CORE_mutex_Control *the_mutex, + Objects_Id id, + boolean wait, + Watchdog_Interval timeout +); + +/* + * _CORE_mutex_Surrender + * + * DESCRIPTION: + * + * This routine frees a unit to the mutex. If a task was blocked waiting for + * a unit from this mutex, then that task will be readied and the unit + * given to that task. Otherwise, the unit will be returned to the mutex. + */ + +CORE_mutex_Status _CORE_mutex_Surrender( + CORE_mutex_Control *the_mutex, + Objects_Id id, + CORE_mutex_API_mp_support_callout api_mutex_mp_support +); + +/* + * _CORE_mutex_Flush + * + * DESCRIPTION: + * + * This routine assists in the deletion of a mutex by flushing the associated + * wait queue. + */ + +void _CORE_mutex_Flush( + CORE_mutex_Control *the_mutex, + Thread_queue_Flush_callout remote_extract_callout, + unsigned32 status +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/coremutex.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ + diff --git a/cpukit/score/include/rtems/score/coresem.h b/cpukit/score/include/rtems/score/coresem.h new file mode 100644 index 0000000000..88f712be5d --- /dev/null +++ b/cpukit/score/include/rtems/score/coresem.h @@ -0,0 +1,156 @@ +/* core_sem.h + * + * This include file contains all the constants and structures associated + * with the Counting Semaphore Handler. A counting semaphore is the + * standard Dijkstra binary semaphore used to provide synchronization + * and mutual exclusion capabilities. + * + * 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$ + */ + +#ifndef __RTEMS_CORE_COUNTING_SEMAPHORE_h +#define __RTEMS_CORE_COUNTING_SEMAPHORE_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> +#include <rtems/score/priority.h> +#include <rtems/score/watchdog.h> + +/* + * The following type defines the callout which the API provides + * to support global/multiprocessor operations on semaphores. + */ + +typedef void ( *CORE_semaphore_API_mp_support_callout )( + Thread_Control *, + Objects_Id + ); + +/* + * Blocking disciplines for a semaphore. + */ + +typedef enum { + CORE_SEMAPHORE_DISCIPLINES_FIFO, + CORE_SEMAPHORE_DISCIPLINES_PRIORITY +} CORE_semaphore_Disciplines; + +/* + * Core Semaphore handler return statuses. + */ + +typedef enum { + CORE_SEMAPHORE_STATUS_SUCCESSFUL, + CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT, + CORE_SEMAPHORE_WAS_DELETED, + CORE_SEMAPHORE_TIMEOUT +} CORE_semaphore_Status; + +/* + * The following defines the control block used to manage the + * attributes of each semaphore. + */ + +typedef struct { + CORE_semaphore_Disciplines discipline; +} CORE_semaphore_Attributes; + +/* + * The following defines the control block used to manage each + * counting semaphore. + */ + +typedef struct { + Thread_queue_Control Wait_queue; + CORE_semaphore_Attributes Attributes; + unsigned32 count; +} CORE_semaphore_Control; + +/* + * _CORE_semaphore_Initialize + * + * DESCRIPTION: + * + * This routine initializes the semaphore based on the parameters passed. + */ + +void _CORE_semaphore_Initialize( + CORE_semaphore_Control *the_semaphore, + Objects_Classes the_class, + CORE_semaphore_Attributes *the_semaphore_attributes, + unsigned32 initial_value, + Thread_queue_Extract_callout proxy_extract_callout +); + +/* + * _CORE_semaphore_Seize + * + * DESCRIPTION: + * + * This routine attempts to receive a unit from the_semaphore. + * If a unit is available or if the wait flag is FALSE, then the routine + * returns. Otherwise, the calling task is blocked until a unit becomes + * available. + */ + +void _CORE_semaphore_Seize( + CORE_semaphore_Control *the_semaphore, + Objects_Id id, + boolean wait, + Watchdog_Interval timeout +); + +/* + * _CORE_semaphore_Surrender + * + * DESCRIPTION: + * + * This routine frees a unit to the semaphore. If a task was blocked waiting + * for a unit from this semaphore, then that task will be readied and the unit + * given to that task. Otherwise, the unit will be returned to the semaphore. + */ + +CORE_semaphore_Status _CORE_semaphore_Surrender( + CORE_semaphore_Control *the_semaphore, + Objects_Id id, + CORE_semaphore_API_mp_support_callout api_semaphore_mp_support +); + +/* + * _CORE_semaphore_Flush + * + * DESCRIPTION: + * + * This routine assists in the deletion of a semaphore by flushing the + * associated wait queue. + */ + +void _CORE_semaphore_Flush( + CORE_semaphore_Control *the_semaphore, + Thread_queue_Flush_callout remote_extract_callout, + unsigned32 status +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/coresem.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ + diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h new file mode 100644 index 0000000000..c1a0650d0a --- /dev/null +++ b/cpukit/score/include/rtems/score/heap.h @@ -0,0 +1,226 @@ +/* heap.h + * + * This include file contains the information pertaining to the Heap + * Handler. A heap is a doubly linked list of variable size + * blocks which are allocated using the first fit method. Garbage + * collection is performed each time a block is returned to the heap by + * coalescing neighbor blocks. Control information for both allocated + * and unallocated blocks is contained in the heap space. A heap header + * contains control information for the heap. + * + * 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$ + */ + +#ifndef __RTEMS_HEAP_h +#define __RTEMS_HEAP_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Status codes for heap_extend + */ + +typedef enum { + HEAP_EXTEND_SUCCESSFUL, + HEAP_EXTEND_ERROR, + HEAP_EXTEND_NOT_IMPLEMENTED +} Heap_Extend_status; + +/* + * Constants used in the size/used field of each heap block to + * indicate when a block is free or in use. + */ + +#define HEAP_BLOCK_USED 1 /* indicates block is in use */ +#define HEAP_BLOCK_FREE 0 /* indicates block is free */ + +/* + * The size/used field value for the dummy front and back flags. + */ + +#define HEAP_DUMMY_FLAG (0 + HEAP_BLOCK_USED) + +/* + * The following constants reflect various requirements of the + * heap data structures which impact the management of a heap. + * + * NOTE: Because free block overhead is greater than used block + * overhead AND a portion of the allocated space is from + * the extra free block overhead, the absolute lower bound + * of the minimum fragment size is equal to the size of + * the free block overhead. + */ + +#define HEAP_OVERHEAD \ + (sizeof( unsigned32 ) * 2) /* size dummy first and last blocks */ +#define HEAP_BLOCK_USED_OVERHEAD \ + (sizeof( void * ) * 2) /* num bytes overhead in used block */ +#define HEAP_MINIMUM_SIZE \ + (HEAP_OVERHEAD + sizeof (Heap_Block)) + /* min number of bytes the user may */ + /* specify for the heap size */ + +/* + * The following defines the data structure used to manage + * individual blocks in a heap. When the block is allocated, the + * next and previous fields are not used by the Heap Handler + * and thus the address returned for the block starts at + * the address of the next field. + * + * NOTE: The next and previous pointers are only valid when the + * block is free. Caution must be exercised to insure that + * allocated blocks are large enough to contain them and + * that they are not accidentally overwritten when the + * block is actually allocated. + */ + +typedef struct Heap_Block_struct Heap_Block; + +struct Heap_Block_struct { + unsigned32 back_flag; /* size and status of prev block */ + unsigned32 front_flag; /* size and status of block */ + Heap_Block *next; /* pointer to next block */ + Heap_Block *previous; /* pointer to previous block */ +}; + +/* + * The following defines the control block used to manage each heap. + * + * NOTE: + * + * This structure is layed out such that it can be used a a dummy + * first and last block on the free block chain. The extra padding + * insures the dummy last block is the correct size. + * + * The first Heap_Block starts at first while the second starts at + * final. This is effectively the same trick as is used in the Chain + * Handler. + */ + +typedef struct { + Heap_Block *start; /* first valid block address in heap */ + Heap_Block *final; /* last valid block address in heap */ + + Heap_Block *first; /* pointer to first block in heap */ + Heap_Block *permanent_null; /* always NULL pointer */ + Heap_Block *last; /* pointer to last block in heap */ + unsigned32 page_size; /* allocation unit */ + unsigned32 reserved; +} Heap_Control; + +/* + * _Heap_Initialize + * + * DESCRIPTION: + * + * This routine initializes the_heap record to manage the + * contiguous heap of size bytes which starts at starting_address. + * Blocks of memory are allocated from the heap in multiples of + * page_size byte units. + */ + +unsigned32 _Heap_Initialize( + Heap_Control *the_heap, + void *starting_address, + unsigned32 size, + unsigned32 page_size +); + +/* + * _Heap_Extend + * + * DESCRIPTION: + * + * This routine grows the_heap memory area using the size bytes which + * begin at starting_address. + */ + +Heap_Extend_status _Heap_Extend( + Heap_Control *the_heap, + void *starting_address, + unsigned32 size, + unsigned32 *amount_extended +); + +/* + * _Heap_Allocate + * + * DESCRIPTION: + * + * DESCRIPTION: + * + * This function attempts to allocate a block of size bytes from + * the_heap. If insufficient memory is free in the_heap to allocate + * a block of the requested size, then NULL is returned. + */ + +void *_Heap_Allocate( + Heap_Control *the_heap, + unsigned32 size +); + +/* + * _Heap_Size_of_user_area + * + * DESCRIPTION: + * + * This kernel routine sets size to the size of the given heap block. + * It returns TRUE if the starting_address is in the heap, and FALSE + * otherwise. + */ + +boolean _Heap_Size_of_user_area( + Heap_Control *the_heap, + void *starting_address, + unsigned32 *size +); + +/* + * _Heap_Free + * + * DESCRIPTION: + * + * This routine returns the block of memory which begins + * at starting_address to the_heap. Any coalescing which is + * possible with the freeing of this routine is performed. + */ + +boolean _Heap_Free( + Heap_Control *the_heap, + void *start_address +); + +/* + * _Heap_Walk + * + * DESCRIPTION: + * + * This routine walks the heap to verify its integrity. + */ + +void _Heap_Walk( + Heap_Control *the_heap, + int source, + boolean do_dump +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/heap.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/interr.h b/cpukit/score/include/rtems/score/interr.h new file mode 100644 index 0000000000..b9b2a3c51a --- /dev/null +++ b/cpukit/score/include/rtems/score/interr.h @@ -0,0 +1,94 @@ +/* interr.h + * + * This include file contains constants and prototypes related + * to the Internal Error 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$ + */ + +#ifndef __RTEMS_INTERNAL_ERROR_h +#define __RTEMS_INTERNAL_ERROR_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This type lists the possible sources from which an error + * can be reported. + */ + +typedef enum { + INTERNAL_ERROR_CORE, + INTERNAL_ERROR_RTEMS_API +} Internal_errors_Source; + +/* + * A list of errors which are generated internally by the executive core. + */ + +typedef enum { + INTERNAL_ERROR_NO_CONFIGURATION_TABLE, + INTERNAL_ERROR_NO_CPU_TABLE, + INTERNAL_ERROR_INVALID_WORKSPACE_ADDRESS, + INTERNAL_ERROR_TOO_LITTLE_WORKSPACE, + INTERNAL_ERROR_WORKSPACE_ALLOCATION, + INTERNAL_ERROR_INTERRUPT_STACK_TOO_SMALL, + INTERNAL_ERROR_THREAD_EXITTED, + INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION, + INTERNAL_ERROR_INVALID_NODE, + INTERNAL_ERROR_NO_MPCI, + INTERNAL_ERROR_BAD_PACKET, + INTERNAL_ERROR_OUT_OF_PACKETS, + INTERNAL_ERROR_OUT_OF_GLOBAL_OBJECTS, + INTERNAL_ERROR_OUT_OF_PROXIES, + INTERNAL_ERROR_INVALID_GLOBAL_ID, + INTERNAL_ERROR_BAD_STACK_HOOK +} Internal_errors_Core_list; + +/* + * This type holds the fatal error information. + */ + +typedef struct { + Internal_errors_Source the_source; + boolean is_internal; + unsigned32 the_error; +} Internal_errors_Information; + +/* + * When a fatal error occurs, the error information is stored here. + */ + +EXTERN Internal_errors_Information Internal_errors_What_happened; + +/* + * _Internal_error_Occurred + * + * DESCRIPTION: + * + * This routine is invoked when the application or the executive itself + * determines that a fatal error has occurred. + */ + +void volatile _Internal_error_Occurred( + Internal_errors_Source the_source, + boolean is_internal, + unsigned32 the_error +); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/isr.h b/cpukit/score/include/rtems/score/isr.h new file mode 100644 index 0000000000..cf8f4cad59 --- /dev/null +++ b/cpukit/score/include/rtems/score/isr.h @@ -0,0 +1,224 @@ +/* isr.h + * + * This include file contains all the constants and structures associated + * with the management of processor interrupt levels. This handler + * supports interrupt critical sections, vectoring of user interrupt + * handlers, nesting of interrupts, and manipulating interrupt levels. + * + * 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$ + */ + +#ifndef __ISR_h +#define __ISR_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The following type defines the control block used to manage + * the interrupt level portion of the status register. + */ + +typedef unsigned32 ISR_Level; + +/* + * The following type defines the type used to manage the vectors. + */ + +typedef unsigned32 ISR_Vector_number; + +/* + * Return type for ISR Handler + */ + +typedef void ISR_Handler; + +/* + * Pointer to an ISR Handler + */ + +typedef ISR_Handler ( *ISR_Handler_entry )( + ISR_Vector_number + ); +/* + * This constant promotes out the number of vectors truly supported by + * the current CPU being used. This is usually the number of distinct vectors + * the cpu can vector. + */ + +#define ISR_NUMBER_OF_VECTORS CPU_INTERRUPT_NUMBER_OF_VECTORS + +/* + * This constant promotes out the highest valid interrupt vector number. + */ + +#define ISR_INTERRUPT_MAXIMUM_VECTOR_NUMBER CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER + +/* + * The following is TRUE if signals have been sent to the currently + * executing thread by an ISR handler. + */ + +EXTERN boolean _ISR_Signals_to_thread_executing; + +/* + * The following contains the interrupt service routine nest level. + * When this variable is zero, a thread is executing. + */ + +EXTERN unsigned32 _ISR_Nest_level; + +/* + * The following declares the Vector Table. Application + * interrupt service routines are vectored by the ISR Handler via this table. + */ + +EXTERN ISR_Handler_entry _ISR_Vector_table[ ISR_NUMBER_OF_VECTORS ]; + +/* + * _ISR_Handler_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this handler. + */ + +void _ISR_Handler_initialization ( void ); + +/* + * _ISR_Disable + * + * DESCRIPTION: + * + * This routine disables all interrupts so that a critical section + * of code can be executing without being interrupted. Upon return, + * the argument _level will contain the previous interrupt mask level. + */ + +#define _ISR_Disable( _level ) \ + _CPU_ISR_Disable( _level ) + +/* + * _ISR_Enable + * + * DESCRIPTION: + * + * This routine enables interrupts to the previous interrupt mask + * LEVEL. It is used at the end of a critical section of code to + * enable interrupts so they can be processed again. + */ + +#define _ISR_Enable( _level ) \ + _CPU_ISR_Enable( _level ) + +/* + * _ISR_Flash + * + * DESCRIPTION: + * + * This routine temporarily enables interrupts to the previous + * interrupt mask level and then disables all interrupts so that + * the caller can continue into the second part of a critical + * section. This routine is used to temporarily enable interrupts + * during a long critical section. It is used in long sections of + * critical code when a point is reached at which interrupts can + * be temporarily enabled. Deciding where to flash interrupts + * in a long critical section is often difficult and the point + * must be selected with care to insure that the critical section + * properly protects itself. + */ + +#define _ISR_Flash( _level ) \ + _CPU_ISR_Flash( _level ) + +/* + * _ISR_Install_vector + * + * DESCRIPTION: + * + * This routine installs new_handler as the interrupt service routine + * for the specified vector. The previous interrupt service routine is + * returned as old_handler. + */ + +#define _ISR_Install_vector( _vector, _new_handler, _old_handler ) \ + _CPU_ISR_install_vector( _vector, _new_handler, _old_handler ) + +/* + * _ISR_Get_level + * + * DESCRIPTION: + * + * This routine returns the current interrupt level. + */ + +#define _ISR_Get_level() \ + _CPU_ISR_Get_level() + +/* + * _ISR_Set_level + * + * DESCRIPTION: + * + * This routine sets the current interrupt level to that specified + * by new_level. The new interrupt level is effective when the + * routine exits. + */ + +#define _ISR_Set_level( _new_level ) \ + _CPU_ISR_Set_level( _new_level ) + +/* + * _ISR_Handler + * + * DESCRIPTION: + * + * This routine is the interrupt dispatcher. ALL interrupts + * are vectored to this routine so that minimal context can be saved + * and setup performed before the application's high-level language + * interrupt service routine is invoked. After the application's + * interrupt service routine returns control to this routine, it + * will determine if a thread dispatch is necessary. If so, it will + * insure that the necessary thread scheduling operations are + * performed when the outermost interrupt service routine exits. + * + * NOTE: Implemented in assembly language. + */ + +void _ISR_Handler( void ); + +/* + * _ISR_Dispatch + * + * DESCRIPTION: + * + * This routine provides a wrapper so that the routine + * _Thread_Dispatch can be invoked when a reschedule is necessary + * at the end of the outermost interrupt service routine. This + * wrapper is necessary to establish the processor context needed + * by _Thread_Dispatch and to save the processor context which is + * corrupted by _Thread_Dispatch. This context typically consists + * of registers which are not preserved across routine invocations. + * + * NOTE: Implemented in assembly language. + */ + +void _ISR_Dispatch( void ); + +#include <rtems/score/isr.inl> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/mpci.h b/cpukit/score/include/rtems/score/mpci.h new file mode 100644 index 0000000000..25d7ac4094 --- /dev/null +++ b/cpukit/score/include/rtems/score/mpci.h @@ -0,0 +1,411 @@ +/* mpci.h + * + * This include file contains all the constants and structures associated + * with the MPCI layer. It provides mechanisms to utilize packets. + * + * 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$ + */ + +#ifndef __MPCI_h +#define __MPCI_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/mppkt.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> +#include <rtems/score/tqdata.h> +#include <rtems/score/watchdog.h> +#include <rtems/score/coresem.h> + +/* + * The following constants define the stack size requirements for + * the system threads. + */ + +#define MPCI_RECEIVE_SERVER_STACK_SIZE \ + ( STACK_MINIMUM_SIZE + \ + CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK + \ + _CPU_Table.extra_mpci_receive_server_stack \ + ) + +/* + * The following defines the node number used when a broadcast is desired. + */ + +#define MPCI_ALL_NODES 0 + +/* + * For packets associated with requests that don't already have a timeout, + * use the one specified by this MPCI driver. The value specified by + * the MPCI driver sets an upper limit on how long a remote request + * should take to complete. + */ + +#define MPCI_DEFAULT_TIMEOUT 0xFFFFFFFF + +/* + * The following records define the Multiprocessor Communications + * Interface (MPCI) Table. This table defines the user-provided + * MPCI which is a required part of a multiprocessor system. + * + * For non-blocking local operations that become remote operations, + * we need a timeout. This is a per-driver timeout: default_timeout + */ + +typedef void MPCI_Entry; + +typedef MPCI_Entry ( *MPCI_initialization_entry )( void ); + +typedef MPCI_Entry ( *MPCI_get_packet_entry )( + MP_packet_Prefix ** + ); + +typedef MPCI_Entry ( *MPCI_return_packet_entry )( + MP_packet_Prefix * + ); + +typedef MPCI_Entry ( *MPCI_send_entry )( + unsigned32, + MP_packet_Prefix * + ); + +typedef MPCI_Entry ( *MPCI_receive_entry )( + MP_packet_Prefix ** + ); + +typedef struct { + unsigned32 default_timeout; /* in ticks */ + unsigned32 maximum_packet_size; + MPCI_initialization_entry initialization; + MPCI_get_packet_entry get_packet; + MPCI_return_packet_entry return_packet; + MPCI_send_entry send_packet; + MPCI_receive_entry receive_packet; +} MPCI_Control; + +/* + * The following defines the type for packet processing routines + * invoked by the MPCI Receive server. + */ + +typedef void (*MPCI_Packet_processor)( MP_packet_Prefix * ); + +/* + * The following enumerated type defines the list of + * internal MP operations. + */ + +typedef enum { + MPCI_PACKETS_SYSTEM_VERIFY = 0 +} MPCI_Internal_Remote_operations; + +/* + * The following data structure defines the packet used to perform + * remote event operations. + */ + +typedef struct { + MP_packet_Prefix Prefix; + MPCI_Internal_Remote_operations operation; + unsigned32 maximum_nodes; + unsigned32 maximum_global_objects; +} MPCI_Internal_packet; + +/* + * This is the core semaphore which the MPCI Receive Server blocks on. + */ + +EXTERN CORE_semaphore_Control _MPCI_Semaphore; +/* + * The following thread queue is used to maintain a list of tasks + * which currently have outstanding remote requests. + */ + +EXTERN Thread_queue_Control _MPCI_Remote_blocked_threads; + +/* + * The following define the internal pointers to the user's + * configuration information. + */ + +EXTERN MPCI_Control *_MPCI_table; + +/* + * The following points to the MPCI Receive Server. + */ + +EXTERN Thread_Control *_MPCI_Receive_server_tcb; + +/* + * The following table contains the process packet routines provided + * by each object that supports MP operations. + */ + +EXTERN MPCI_Packet_processor _MPCI_Packet_processors[MP_PACKET_CLASSES_LAST+1]; + +/* + * _MPCI_Handler_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this handler. + */ + +void _MPCI_Handler_initialization( + MPCI_Control *users_mpci_table, + unsigned32 timeout_status +); + +/* + * _MPCI_Create_server + * + * DESCRIPTION: + * + * This routine creates the packet receive server used in MP systems. + */ + +void _MPCI_Create_server( void ); + +/* + * _MPCI_Initialization + * + * DESCRIPTION: + * + * This routine initializes the MPCI driver by + * invoking the user provided MPCI initialization callout. + */ + +void _MPCI_Initialization ( void ); + +/* + * _MPCI_Register_packet_processor + * + * DESCRIPTION: + * + * This routine registers the MPCI packet processor for the + * designated object class. + */ + +void _MPCI_Register_packet_processor( + MP_packet_Classes the_object, + MPCI_Packet_processor the_packet_processor + +); + +/* + * _MPCI_Get_packet + * + * DESCRIPTION: + * + * This function obtains a packet by invoking the user provided + * MPCI get packet callout. + */ + +MP_packet_Prefix *_MPCI_Get_packet ( void ); + +/* + * _MPCI_Return_packet + * + * DESCRIPTION: + * + * This routine returns a packet by invoking the user provided + * MPCI return packet callout. + */ + +void _MPCI_Return_packet ( + MP_packet_Prefix *the_packet +); + +/* + * _MPCI_Send_process_packet + * + * DESCRIPTION: + * + * This routine sends a process packet by invoking the user provided + * MPCI send callout. + */ + +void _MPCI_Send_process_packet ( + unsigned32 destination, + MP_packet_Prefix *the_packet +); + +/* + * _MPCI_Send_request_packet + * + * DESCRIPTION: + * + * This routine sends a request packet by invoking the user provided + * MPCI send callout. + */ + +unsigned32 _MPCI_Send_request_packet ( + unsigned32 destination, + MP_packet_Prefix *the_packet, + States_Control extra_state +); + +/* + * _MPCI_Send_response_packet + * + * DESCRIPTION: + * + * This routine sends a response packet by invoking the user provided + * MPCI send callout. + */ + +void _MPCI_Send_response_packet ( + unsigned32 destination, + MP_packet_Prefix *the_packet +); + +/* + * _MPCI_Receive_packet + * + * DESCRIPTION: + * + * This routine receives a packet by invoking the user provided + * MPCI receive callout. + */ + +MP_packet_Prefix *_MPCI_Receive_packet ( void ); + +/* + * _MPCI_Process_response + * + * DESCRIPTION: + * + * This routine obtains a packet by invoking the user provided + * MPCI get packet callout. + */ + +Thread_Control *_MPCI_Process_response ( + MP_packet_Prefix *the_packet +); + +/*PAGE + * + * _MPCI_Receive_server + * + */ + +Thread _MPCI_Receive_server( + unsigned32 ignored +); + +/*PAGE + * + * _MPCI_Announce + * + * DESCRIPTION: + * + * XXX + */ + +void _MPCI_Announce ( void ); + +/* + * _MPCI_Internal_packets_Send_process_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * process operation can be performed on another node. + */ + +void _MPCI_Internal_packets_Send_process_packet ( + MPCI_Internal_Remote_operations operation +); + +/* + * _MPCI_Internal_packets_Send_request_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive operation can be initiated on another node. + * + * This routine is not needed since there are no request + * packets to be sent by this manager. + */ + +/* + * _MPCI_Internal_packets_Send_response_packet + * + * DESCRIPTION: + * + * This routine performs a remote procedure call so that a + * directive can be performed on another node. + * + * This routine is not needed since there are no response + * packets to be sent by this manager. + */ + +/* + * + * _MPCI_Internal_packets_Process_packet + * + * DESCRIPTION: + * + * This routine performs the actions specific to this package for + * the request from another node. + */ + +void _MPCI_Internal_packets_Process_packet ( + MP_packet_Prefix *the_packet_prefix +); + +/* + * _MPCI_Internal_packets_Send_object_was_deleted + * + * DESCRIPTION: + * + * This routine is invoked indirectly by the thread queue + * when a proxy has been removed from the thread queue and + * the remote node must be informed of this. + * + * This routine is not needed since there are no objects + * deleted by this manager. + */ + +/* + * _MPCI_Internal_packets_Send_extract_proxy + * + * DESCRIPTION: + * + * This routine is invoked when a task is deleted and it + * has a proxy which must be removed from a thread queue and + * the remote node must be informed of this. + * + * This routine is not needed since there are no objects + * deleted by this manager. + */ + +/* + * _MPCI_Internal_packets_Get_packet + * + * DESCRIPTION: + * + * This routine is used to obtain a internal threads mp packet. + */ + + MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void ); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/mppkt.h b/cpukit/score/include/rtems/score/mppkt.h new file mode 100644 index 0000000000..0c651bc4e8 --- /dev/null +++ b/cpukit/score/include/rtems/score/mppkt.h @@ -0,0 +1,100 @@ +/* mppkt.h + * + * This package is the specification for the Packet Handler. + * This handler defines the basic packet and provides + * mechanisms to utilize packets based on this prefix. + * Packets are the fundamental basis for messages passed between + * nodes in an MP system. + * + * + * 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$ + */ + +#ifndef __MP_PACKET_h +#define __MP_PACKET_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> +#include <rtems/score/priority.h> +#include <rtems/score/watchdog.h> + +/* + * The following enumerated type defines the packet classes. + * + * NOTE: In general, each class corresponds to a manager + * which supports global operations. Each manager + * defines the set of supported operations. + */ + +typedef enum { + MP_PACKET_MPCI_INTERNAL = 0, + MP_PACKET_TASKS = 1, + MP_PACKET_MESSAGE_QUEUE = 2, + MP_PACKET_SEMAPHORE = 3, + MP_PACKET_PARTITION = 4, + MP_PACKET_REGION = 5, + MP_PACKET_EVENT = 6, + MP_PACKET_SIGNAL = 7 +} MP_packet_Classes; + +#define MP_PACKET_CLASSES_FIRST MP_PACKET_MPCI_INTERNAL +#define MP_PACKET_CLASSES_LAST MP_PACKET_SIGNAL + +/* + * The following record contains the prefix for every packet + * passed between nodes in an MP system. + * + * NOTE: This structure is padded to insure that anything + * following it is on a 16 byte boundary. This is + * the most stringent structure alignment rule + * encountered yet (i960CA). + */ + +typedef struct { + MP_packet_Classes the_class; + Objects_Id id; + Objects_Id source_tid; + Priority_Control source_priority; + unsigned32 return_code; + unsigned32 length; + unsigned32 to_convert; + Watchdog_Interval timeout; +} MP_packet_Prefix; + +/* + * An MPCI must support packets of at least this size. + */ + +#define MP_PACKET_MINIMUM_PACKET_SIZE 64 + +/* + * The following constant defines the number of unsigned32's + * in a packet which must be converted to native format in a + * heterogeneous system. In packets longer than + * MP_PACKET_MINIMUN_HETERO_CONVERSION unsigned32's, some of the "extra" data + * may a user message buffer which is not automatically endian swapped. + */ + +#define MP_PACKET_MINIMUN_HETERO_CONVERSION ( sizeof( MP_packet_Prefix ) / 4 ) + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/mppkt.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/object.h b/cpukit/score/include/rtems/score/object.h new file mode 100644 index 0000000000..d70009c3c9 --- /dev/null +++ b/cpukit/score/include/rtems/score/object.h @@ -0,0 +1,397 @@ +/* object.h + * + * This include file contains all the constants and structures associated + * with the Object Handler. This Handler provides mechanisms which + * can be used to initialize and manipulate all objects which have + * ids. + * + * 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$ + */ + +#ifndef __OBJECTS_h +#define __OBJECTS_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/chain.h> + +/* + * The following type defines the control block used to manage + * object names. + */ + +typedef void * Objects_Name; + +/* + * Space for object names is allocated in multiples of this. + * + * NOTE: Must be a power of 2. Matches the name manipulation routines. + */ + +#define OBJECTS_NAME_ALIGNMENT 4 + +/* + * Functions which compare names are prototyped like this. + */ + +typedef boolean (*Objects_Name_comparators)( + void * /* name_1 */, + void * /* name_2 */, + unsigned32 /* length */ +); + +/* + * The following type defines the control block used to manage + * object IDs. The format is as follows (0=LSB): + * + * Bits 0 .. 15 = index + * Bits 16 .. 25 = node + * Bits 26 .. 31 = class + */ + +typedef unsigned32 Objects_Id; + +#define OBJECTS_INDEX_START_BIT 0 +#define OBJECTS_NODE_START_BIT 16 +#define OBJECTS_CLASS_START_BIT 26 + +#define OBJECTS_INDEX_MASK 0x0000ffff +#define OBJECTS_NODE_MASK 0x03ff0000 +#define OBJECTS_CLASS_MASK 0xfc000000 + +#define OBJECTS_INDEX_VALID_BITS 0x0000ffff +#define OBJECTS_NODE_VALID_BITS 0x000003ff +#define OBJECTS_CLASS_VALID_BITS 0x000000cf + +/* + * This enumerated type is used in the class field of the object ID. + */ + +typedef enum { + OBJECTS_NO_CLASS = 0, + OBJECTS_INTERNAL_THREADS = 1, + OBJECTS_RTEMS_TASKS = 2, + OBJECTS_POSIX_THREADS = 3, + OBJECTS_RTEMS_TIMERS = 4, + OBJECTS_RTEMS_SEMAPHORES = 5, + OBJECTS_RTEMS_MESSAGE_QUEUES = 6, + OBJECTS_RTEMS_PARTITIONS = 7, + OBJECTS_RTEMS_REGIONS = 8, + OBJECTS_RTEMS_PORTS = 9, + OBJECTS_RTEMS_PERIODS = 10, + OBJECTS_RTEMS_EXTENSIONS = 11, + OBJECTS_POSIX_KEYS = 12, + OBJECTS_POSIX_INTERRUPTS = 13, + OBJECTS_POSIX_MESSAGE_QUEUES = 14, + OBJECTS_POSIX_MUTEXES = 15, + OBJECTS_POSIX_SEMAPHORES = 16, + OBJECTS_POSIX_CONDITION_VARIABLES = 17 +} Objects_Classes; + +#define OBJECTS_CLASSES_FIRST OBJECTS_NO_CLASS +#define OBJECTS_CLASSES_LAST OBJECTS_POSIX_CONDITION_VARIABLES +#define OBJECTS_CLASSES_FIRST_THREAD_CLASS OBJECTS_MPCI_PACKETS +#define OBJECTS_CLASSES_LAST_THREAD_CLASS OBJECTS_POSIX_THREADS + +/* + * This enumerated type lists the locations which may be returned + * by _Objects_Get. These codes indicate the success of locating + * an object with the specified ID. + */ + +typedef enum { + OBJECTS_LOCAL = 0, /* object is local */ + OBJECTS_REMOTE = 1, /* object is remote */ + OBJECTS_ERROR = 2 /* id was invalid */ +} Objects_Locations; + +/* + * The following defines the Object Control Block used to manage + * each object local to this node. + */ + +typedef struct { + Chain_Node Node; + Objects_Id id; + Objects_Name name; +} Objects_Control; + +/* + * The following defines the structure for the information used to + * manage each class of objects. + */ + +typedef struct { + Objects_Classes the_class; /* Class of this object */ + Objects_Id minimum_id; /* minimum valid id of this type */ + Objects_Id maximum_id; /* maximum valid id of this type */ + unsigned32 maximum; /* maximum number of objects */ + Objects_Control **local_table; /* table of local object pointers */ + Objects_Name *name_table; /* table of local object names */ + Chain_Control *global_table; /* pointer to global table */ + Chain_Control Inactive; /* chain of inactive ctl blocks */ + boolean is_string; /* TRUE if names are strings */ + unsigned32 name_length; /* maximum length of names */ + boolean is_thread; /* TRUE if these are threads */ + /* irregardless of API */ +} Objects_Information; + +/* + * The following defines the data storage which contains the + * node number of the local node. + */ + +EXTERN unsigned32 _Objects_Local_node; +EXTERN unsigned32 _Objects_Maximum_nodes; + +/* + * The following is the list of information blocks for each object + * class. From the ID, we can go to one of these information blocks, + * and obtain a pointer to the appropriate object control block. + */ + +EXTERN Objects_Information + *_Objects_Information_table[OBJECTS_CLASSES_LAST + 1]; + +/* + * The following defines the constant which may be used + * with _Objects_Get to manipulate the calling task. + * + */ + +#define OBJECTS_ID_OF_SELF ((Objects_Id) 0) + +/* + * The following define the constants which may be used in name searches. + */ + +#define OBJECTS_SEARCH_ALL_NODES 0 +#define OBJECTS_SEARCH_OTHER_NODES 0x7FFFFFFE +#define OBJECTS_SEARCH_LOCAL_NODE 0x7FFFFFFF +#define OBJECTS_WHO_AM_I 0 + +/* + * Parameters and return id's for _Objects_Get_next + */ + +#define OBJECTS_ID_INITIAL_INDEX (0) +#define OBJECTS_ID_FINAL_INDEX (0xffff) + +#define OBJECTS_ID_INITIAL(_class, _node) \ + _Objects_Build_id( (_class), (_node), OBJECTS_ID_INITIAL_INDEX ) + +#define OBJECTS_ID_FINAL ((Objects_Id)~0) + +/* + * _Objects_Handler_initialization + * + * DESCRIPTION: + * + * This function performs the initialization necessary for this handler. + * + */ + +void _Objects_Handler_initialization( + unsigned32 node, + unsigned32 maximum_nodes, + unsigned32 maximum_global_objects +); + +/* + * _Objects_Initialize_information + * + * DESCRIPTION: + * + * This function initializes an object class information record. + * SUPPORTS_GLOBAL is TRUE if the object class supports global + * objects, and FALSE otherwise. Maximum indicates the number + * of objects required in this class and size indicates the size + * in bytes of each control block for this object class. The + * name length and string designator are also set. In addition, + * the class may be a task, therefore this information is also included. + */ + +void _Objects_Initialize_information ( + Objects_Information *information, + Objects_Classes the_class, + boolean supports_global, + unsigned32 maximum, + unsigned32 size, + boolean is_string, + unsigned32 maximum_name_length, + boolean is_task +); + +/* + * _Objects_Clear_name + * + * DESCRIPTION: + * + * XXX + */ + +void _Objects_Clear_name( + void *name, + unsigned32 length +); + +/* + * _Objects_Copy_name_string + * + * DESCRIPTION: + * + * XXX + */ + +void _Objects_Copy_name_string( + void *source, + void *destination +); + +/* + * _Objects_Copy_name_raw + * + * DESCRIPTION: + * + * XXX + */ + +void _Objects_Copy_name_raw( + void *source, + void *destination, + unsigned32 length +); + +/* + * _Objects_Compare_name_string + * + * DESCRIPTION: + * + * XXX + */ + +boolean _Objects_Compare_name_string( + void *name_1, + void *name_2, + unsigned32 length +); + +/* + * _Objects_Compare_name_raw + * + * DESCRIPTION: + * + * XXX + */ + +boolean _Objects_Compare_name_raw( + void *name_1, + void *name_2, + unsigned32 length +); +/* + * _Objects_Name_to_id + * + * DESCRIPTION: + * + * This function implements the common portion of the object + * identification directives. This directive returns the object + * id associated with name. If more than one object of this class + * is named name, then the object to which the id belongs is + * arbitrary. Node indicates the extent of the search for the + * id of the object named name. If the object class supports global + * objects, then the search can be limited to a particular node + * or allowed to encompass all nodes. + * + */ + +typedef enum { + OBJECTS_SUCCESSFUL, + OBJECTS_INVALID_NAME, + OBJECTS_INVALID_NODE +} Objects_Name_to_id_errors; + +#define OBJECTS_NAME_ERRORS_FIRST OBJECTS_SUCCESSFUL +#define OBJECTS_NAME_ERRORS_LAST OBJECTS_INVALID_NODE + +Objects_Name_to_id_errors _Objects_Name_to_id( + Objects_Information *information, + Objects_Name name, + unsigned32 node, + Objects_Id *id +); + +/* + * _Objects_Get + * + * DESCRIPTION: + * + * This function maps object ids to object control blocks. + * If id corresponds to a local object, then it returns + * the_object control pointer which maps to id and location + * is set to OBJECTS_LOCAL. If the object class supports global + * objects and the object id is global and resides on a remote + * node, then location is set to OBJECTS_REMOTE, and the_object + * is undefined. Otherwise, location is set to OBJECTS_ERROR + * and the_object is undefined. + * + */ + +Objects_Control *_Objects_Get ( + Objects_Information *information, + Objects_Id id, + Objects_Locations *location +); + +/* + * _Objects_Get_next + * + * DESCRIPTION: + * + * Like _Objects_Get, but is used to find "next" open object. + * + */ + +Objects_Control *_Objects_Get_next( + Objects_Information *information, + Objects_Id id, + unsigned32 *location_p, + Objects_Id *next_id_p +); + +/* + * _Objects_Get_information + * + * DESCRIPTION: + * + * Returns the information control block for the class of objects + * corresponding to this id. + */ + +Objects_Information *_Objects_Get_information( + Objects_Id id +); + +/* + * Pieces of object.inl are promoted out to the user + */ + +#include <rtems/score/object.inl> +#include <rtems/score/objectmp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/objectmp.h b/cpukit/score/include/rtems/score/objectmp.h new file mode 100644 index 0000000000..96496656df --- /dev/null +++ b/cpukit/score/include/rtems/score/objectmp.h @@ -0,0 +1,152 @@ +/* objectmp.h + * + * This include file contains all the constants and structures associated + * with the manipulation of Global RTEMS Objects. + * + * 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$ + */ + +#ifndef __RTEMS_OBJECTS_MP_h +#define __RTEMS_OBJECTS_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This defines the Global Object Control Block used to manage + * objects resident on other nodes. + */ + +typedef struct { + Objects_Control Object; + unsigned32 name; /* XXX broken but works */ + /* XXX If any API is MP with variable length names .. BOOM!!!! */ +} Objects_MP_Control; + +/* + * _Objects_MP_Handler_initialization + * + * DESCRIPTION: + * + * This routine intializes the inactive global object chain + * based on the maximum number of global objects configured. + */ + +void _Objects_MP_Handler_initialization ( + unsigned32 node, + unsigned32 maximum_nodes, + unsigned32 maximum_global_objects +); + +/*PAGE + * + * _Objects_MP_Open + * + * DESCRIPTION: + * + * This routine place the specified global object in the + * specified information table. + */ + +void _Objects_MP_Open ( + Objects_Information *information, + Objects_MP_Control *the_global_object, + unsigned32 the_name, /* XXX -- wrong for variable */ + Objects_Id the_id +); + +/* + * _Objects_MP_Allocate_and_open + * + * DESCRIPTION: + * + * This routine allocates a global object control block + * and places it in the specified information table. If the + * allocation fails, then is_fatal_error determines the + * error processing actions taken. + */ + +boolean _Objects_MP_Allocate_and_open ( + Objects_Information *information, + unsigned32 the_name, /* XXX -- wrong for variable length */ + Objects_Id the_id, + boolean is_fatal_error +); + +/* + * _Objects_MP_Close + * + * DESCRIPTION: + * + * This routine removes a global object from the specified + * information table and deallocates the global object control block. + */ + +void _Objects_MP_Close ( + Objects_Information *information, + Objects_Id the_id +); + +/* + * _Objects_MP_Global_name_search + * + * DESCRIPTION: + * + * This routine looks for the object with the_name in the global + * object tables indicated by information. It returns the ID of the + * object with that name if one is found. + */ + +Objects_Name_to_id_errors _Objects_MP_Global_name_search ( + Objects_Information *information, + Objects_Name the_name, + unsigned32 nodes_to_search, + Objects_Id *the_id +); + +/* + * _Objects_MP_Is_remote + * + * DESCRIPTION: + * + * This function searches the Global Object Table managed + * by information for the object indicated by ID. If the object + * is found, then location is set to objects_remote, otherwise + * location is set to objects_error. In both cases, the_object + * is undefined. + */ + +void _Objects_MP_Is_remote ( + Objects_Information *information, + Objects_Id the_id, + Objects_Locations *location, + Objects_Control **the_object +); + +/* + * The following chain header is used to manage the set of + * inactive global object control blocks. + */ + +EXTERN unsigned32 _Objects_MP_Maximum_global_objects; +EXTERN Chain_Control _Objects_MP_Inactive_global_objects; + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/objectmp.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/priority.h b/cpukit/score/include/rtems/score/priority.h new file mode 100644 index 0000000000..b7de14f0f9 --- /dev/null +++ b/cpukit/score/include/rtems/score/priority.h @@ -0,0 +1,96 @@ +/* priority.h + * + * This include file contains all thread priority manipulation routines. + * This Handler provides mechanisms which can be used to + * initialize and manipulate thread priorities. + * + * 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$ + */ + +#ifndef __PRIORITY_h +#define __PRIORITY_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The following type defines the control block used to manage + * thread priorities. + * + * NOTE: Priority 0 is reserved for internal threads only. + */ + +typedef unsigned32 Priority_Control; + +#define PRIORITY_MINIMUM 0 /* highest thread priority */ +#define PRIORITY_MAXIMUM 255 /* lowest thread priority */ + +/* + * The following record defines the information associated with + * each thread to manage its interaction with the priority bit maps. + */ + +typedef struct { + Priority_Bit_map_control *minor; /* addr of minor bit map slot */ + Priority_Bit_map_control ready_major; /* priority bit map ready mask */ + Priority_Bit_map_control ready_minor; /* priority bit map ready mask */ + Priority_Bit_map_control block_major; /* priority bit map block mask */ + Priority_Bit_map_control block_minor; /* priority bit map block mask */ +} Priority_Information; + +/* + * The following data items are the priority bit map. + * Each of the sixteen bits used in the _Priority_Major_bit_map is + * associated with one of the sixteen entries in the _Priority_Bit_map. + * Each bit in the _Priority_Bit_map indicates whether or not there are + * threads ready at a particular priority. The mapping of + * individual priority levels to particular bits is processor + * dependent as is the value of each bit used to indicate that + * threads are ready at that priority. + */ + +EXTERN volatile Priority_Bit_map_control _Priority_Major_bit_map; +EXTERN Priority_Bit_map_control _Priority_Bit_map[16] CPU_STRUCTURE_ALIGNMENT; + +/* + * The definition of the Priority_Bit_map_control type is CPU dependent. + * + */ + +/* + * Priority Bitfield Manipulation Routines + * + * NOTE: + * + * These may simply be pass throughs to CPU dependent routines. + */ + +#if ( CPU_USE_GENERIC_BITFIELD_CODE == FALSE ) + +#define _Priority_Mask( _bit_number ) \ + _CPU_Priority_Mask( _bit_number ) + +#define _Priority_Bits_index( _priority ) \ + _CPU_Priority_bits_index( _priority ) + +#endif + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/priority.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/stack.h b/cpukit/score/include/rtems/score/stack.h new file mode 100644 index 0000000000..bf72782b42 --- /dev/null +++ b/cpukit/score/include/rtems/score/stack.h @@ -0,0 +1,50 @@ +/* stack.h + * + * This include file contains all information about the thread + * Stack Handler. This Handler provides mechanisms which can be used to + * initialize and utilize stacks. + * + * 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$ + */ + +#ifndef __STACK_h +#define __STACK_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The following constant defines the minimum stack size which every + * thread must exceed. + */ + +#define STACK_MINIMUM_SIZE CPU_STACK_MINIMUM_SIZE + +/* + * The following defines the control block used to manage each stack. + */ + +typedef struct { + unsigned32 size; /* stack size */ + void *area; /* low memory addr of stack */ +} Stack_Control; + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/stack.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/states.h b/cpukit/score/include/rtems/score/states.h new file mode 100644 index 0000000000..1f8fd49fae --- /dev/null +++ b/cpukit/score/include/rtems/score/states.h @@ -0,0 +1,78 @@ +/* states.h + * + * This include file contains thread execution state information. + * + * 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$ + */ + +#ifndef __RTEMS_STATES_h +#define __RTEMS_STATES_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The following type defines the control block used to manage a + * thread's state. + */ + +typedef unsigned32 States_Control; + +/* + * The following constants define the individual states which may be + * be used to compose and manipulate a thread's state. + */ + +#define STATES_ALL_SET 0xffff /* all states */ +#define STATES_READY 0x0000 /* ready to run */ +#define STATES_DORMANT 0x0001 /* created not started */ +#define STATES_SUSPENDED 0x0002 /* waiting for resume */ +#define STATES_TRANSIENT 0x0004 /* thread in transition */ +#define STATES_DELAYING 0x0008 /* wait for timeout */ +#define STATES_WAITING_FOR_TIME 0x0010 /* wait for TOD */ +#define STATES_WAITING_FOR_BUFFER 0x0020 +#define STATES_WAITING_FOR_SEGMENT 0x0040 +#define STATES_WAITING_FOR_MESSAGE 0x0080 +#define STATES_WAITING_FOR_EVENT 0x0100 +#define STATES_WAITING_FOR_SEMAPHORE 0x0200 +#define STATES_WAITING_FOR_MUTEX 0x0400 +#define STATES_WAITING_FOR_CONDITION_VARIABLE 0x0800 +#define STATES_WAITING_FOR_RPC_REPLY 0x1000 +#define STATES_WAITING_FOR_PERIOD 0x2000 + +#define STATES_LOCALLY_BLOCKED ( STATES_WAITING_FOR_BUFFER | \ + STATES_WAITING_FOR_SEGMENT | \ + STATES_WAITING_FOR_MESSAGE | \ + STATES_WAITING_FOR_MUTEX | \ + STATES_WAITING_FOR_CONDITION_VARIABLE | \ + STATES_WAITING_FOR_SEMAPHORE ) + +#define STATES_WAITING_ON_THREAD_QUEUE \ + ( STATES_LOCALLY_BLOCKED | \ + STATES_WAITING_FOR_RPC_REPLY ) + +#define STATES_BLOCKED ( STATES_DELAYING | \ + STATES_WAITING_FOR_TIME | \ + STATES_WAITING_FOR_PERIOD | \ + STATES_WAITING_FOR_EVENT | \ + STATES_WAITING_ON_THREAD_QUEUE ) + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/states.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/sysstate.h b/cpukit/score/include/rtems/score/sysstate.h new file mode 100644 index 0000000000..d7e43b2356 --- /dev/null +++ b/cpukit/score/include/rtems/score/sysstate.h @@ -0,0 +1,66 @@ +/* sysstates.h + * + * This include file contains information regarding the system state. + * + * 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$ + */ + +#ifndef __RTEMS_SYSTEM_STATE_h +#define __RTEMS_SYSTEM_STATE_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* types */ + +/* enumerated constants */ + +/* + * The following type defines the possible system states. + */ + +typedef enum { + SYSTEM_STATE_BEFORE_INITIALIZATION, /* start -> end of 1st init part */ + SYSTEM_STATE_BEFORE_MULTITASKING, /* end of 1st -> beginning of 2nd */ + SYSTEM_STATE_BEGIN_MULTITASKING, /* just before multitasking starts */ + SYSTEM_STATE_UP, /* normal operation */ + SYSTEM_STATE_FAILED /* fatal error occurred */ +} System_state_Codes; + +#define SYSTEM_STATE_CODES_FIRST SYSTEM_STATE_BEFORE_INITIALIZATION +#define SYSTEM_STATE_CODES_LAST SYSTEM_STATE_FAILED + +/* + * The following variable indicates whether or not this is + * an multiprocessing system. + */ + +EXTERN boolean _System_state_Is_multiprocessing; + +/* + * The following variable contains the current system state. + */ + +EXTERN System_state_Codes _System_state_Current; + +/* + * Make it possible for the application to get the system state information. + */ + +#include <rtems/score/sysstate.inl> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h new file mode 100644 index 0000000000..74399545b9 --- /dev/null +++ b/cpukit/score/include/rtems/score/thread.h @@ -0,0 +1,585 @@ +/* thread.h + * + * This include file contains all constants and structures associated + * with the thread control block. + * + * 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$ + */ + +#ifndef __THREAD_h +#define __THREAD_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/context.h> +#include <rtems/score/cpu.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/object.h> +#include <rtems/score/priority.h> +#include <rtems/score/stack.h> +#include <rtems/score/states.h> +#include <rtems/score/tod.h> +#include <rtems/score/tqdata.h> +#include <rtems/score/watchdog.h> + +/* + * The following defines the "return type" of a thread. + */ + +typedef void Thread; + +/* + * The following defines the ways in which the entry point for a + * thread can be invoked. Basically, it can be passed any + * combination/permutation of a pointer and an unsigned32 value. + * + * NOTE: For now, we are ignoring the return type. + */ + +typedef enum { + THREAD_START_NUMERIC, + THREAD_START_POINTER, + THREAD_START_BOTH_POINTER_FIRST, + THREAD_START_BOTH_NUMERIC_FIRST +} Thread_Start_types; + +typedef Thread ( *Thread_Entry )( ); + +/* + * The following structure contains the information which defines + * the starting state of a thread. + */ + +typedef struct { + Thread_Entry entry_point; /* starting thread address */ + Thread_Start_types prototype; /* how task is invoked */ + void *pointer_argument; /* pointer argument */ + unsigned32 numeric_argument; /* numeric argument */ + /* initial execution modes */ + boolean is_preemptible; + boolean is_timeslice; + unsigned32 isr_level; + Priority_Control initial_priority; /* initial priority */ + Stack_Control Initial_stack; /* stack information */ + void *fp_context; /* initial FP context area address */ + void *stack; /* initial FP context area address */ +} Thread_Start_information; + +/* + * The following structure contains the information necessary to manage + * a thread which it is waiting for a resource. + */ + +#define THREAD_STATUS_PROXY_BLOCKING 0x1111111 + +typedef struct { + Objects_Id id; /* waiting on this object */ + unsigned32 count; /* "generic" fields to be used */ + void *return_argument; /* when blocking */ + void *return_argument_1; + unsigned32 option; + + /* + * NOTE: The following assumes that all API return codes can be + * treated as an unsigned32. + */ + unsigned32 return_code; /* status for thread awakened */ + + Chain_Control Block2n; /* 2 - n priority blocked chain */ + Thread_queue_Control *queue; /* pointer to thread queue */ +} Thread_Wait_information; + +/* + * The following defines the control block used to manage + * each thread proxy. + * + * NOTE: It is critical that proxies and threads have identical + * memory images for the shared part. + */ + +typedef struct { + Objects_Control Object; + States_Control current_state; + Priority_Control current_priority; + Priority_Control real_priority; + unsigned32 resource_count; + Thread_Wait_information Wait; + Watchdog_Control Timer; + MP_packet_Prefix *receive_packet; + /****************** end of common block ********************/ + Chain_Node Active; +} Thread_Proxy_control; + + +/* + * The following record defines the control block used + * to manage each thread. + * + * NOTE: It is critical that proxies and threads have identical + * memory images for the shared part. + */ + +typedef enum { + THREAD_API_RTEMS, + THREAD_API_POSIX +} Thread_APIs; + +#define THREAD_API_FIRST THREAD_API_RTEMS +#define THREAD_API_LAST THREAD_API_POSIX + +typedef struct { + Objects_Control Object; + States_Control current_state; + Priority_Control current_priority; + Priority_Control real_priority; + unsigned32 resource_count; + Thread_Wait_information Wait; + Watchdog_Control Timer; + MP_packet_Prefix *receive_packet; + /****************** end of common block ********************/ + boolean is_global; + boolean do_post_task_switch_extension; + Chain_Control *ready; + Priority_Information Priority_map; + Thread_Start_information Start; + boolean is_preemptible; + boolean is_timeslice; + Context_Control Registers; + void *fp_context; + void *API_Extensions[ THREAD_API_LAST + 1 ]; + void **extensions; +} Thread_Control; + +/* + * The following constants define the stack size requirements for + * the idle thread. + */ + + +#define THREAD_IDLE_STACK_SIZE STACK_MINIMUM_SIZE + +/* + * The following defines the information control block used to + * manage this class of objects. + */ + +EXTERN Objects_Information _Thread_Internal_information; + +/* + * The following define the thread control pointers used to access + * and manipulate the idle thread. + */ + +EXTERN Thread_Control *_Thread_Idle; + +/* + * The following context area contains the context of the "thread" + * which invoked the start multitasking routine. This context is + * restored as the last action of the stop multitasking routine. Thus + * control of the processor can be returned to the environment + * which initiated the system. + */ + +EXTERN Context_Control _Thread_BSP_context; + +/* + * The following declares the dispatch critical section nesting + * counter which is used to prevent context switches at inopportune + * moments. + */ + +EXTERN unsigned32 _Thread_Dispatch_disable_level; + +/* + * The following holds how many user extensions are in the system. This + * is used to determine how many user extension data areas to allocate + * per thread. + */ + +EXTERN unsigned32 _Thread_Maximum_extensions; + +/* + * The following data items are used to manage timeslicing. + */ + +EXTERN unsigned32 _Thread_Ticks_remaining_in_timeslice; +EXTERN unsigned32 _Thread_Ticks_per_timeslice; + +/* + * The following points to the array of FIFOs used to manage the + * set of ready threads. + */ + +EXTERN Chain_Control *_Thread_Ready_chain; + +/* + * The following points to the thread which is currently executing. + * This thread is implicitly manipulated by numerous directives. + */ + +EXTERN Thread_Control *_Thread_Executing; + +/* + * The following points to the highest priority ready thread + * in the system. Unless the current thread is not preemptibl, + * then this thread will be context switched to when the next + * dispatch occurs. + */ + +EXTERN Thread_Control *_Thread_Heir; + +/* + * The following points to the thread whose floating point + * context is currently loaded. + */ + +EXTERN Thread_Control *_Thread_Allocated_fp; + +/* + * _Thread_Handler_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this handler. + */ + +void _Thread_Handler_initialization ( + unsigned32 ticks_per_timeslice, + unsigned32 maximum_extensions, + unsigned32 maximum_proxies +); + +/* + * _Thread_Create_idle + * + * DESCRIPTION: + * + * This routine creates the idle thread. + * + * WARNING!! No thread should be created before this one. + */ + +void _Thread_Create_idle( void ); + +/* + * _Thread_Start_multitasking + * + * DESCRIPTION: + * + * This routine initiates multitasking. It is invoked only as + * part of initialization and its invocation is the last act of + * the non-multitasking part of the system initialization. + */ + +void _Thread_Start_multitasking( void ); + +/* + * _Thread_Dispatch + * + * DESCRIPTION: + * + * This routine is responsible for transferring control of the + * processor from the executing thread to the heir thread. As part + * of this process, it is responsible for the following actions: + * + * + saving the context of the executing thread + * + restoring the context of the heir thread + * + dispatching any signals for the resulting executing thread + */ + +void _Thread_Dispatch( void ); + +/* + * _Thread_Initialize + * + * DESCRIPTION: + * + * XXX + */ + +boolean _Thread_Initialize( + Objects_Information *information, + Thread_Control *the_thread, + void *stack_area, /* NULL if to be allocated */ + unsigned32 stack_size, /* insure it is >= min */ + boolean is_fp, /* TRUE if thread uses FP */ + Priority_Control priority, + boolean is_preemptible, + boolean is_timeslice, + unsigned32 isr_level, + Objects_Name name + +); + +/* + * _Thread_Start + * + * DESCRIPTION: + * + * XXX + */ + +boolean _Thread_Start( + Thread_Control *the_thread, + Thread_Start_types the_prototype, + void *entry_point, + void *pointer_argument, + unsigned32 numeric_argument +); + +/* + * _Thread_Restart + * + * DESCRIPTION: + * + * XXX + */ + +/* XXX multiple task arg profiles */ + +boolean _Thread_Restart( + Thread_Control *the_thread, + void *pointer_argument, + unsigned32 numeric_argument +); + +/* + * _Thread_Close + * + * DESCRIPTION: + * + * XXX + */ + +void _Thread_Close( + Objects_Information *information, + Thread_Control *the_thread +); + +/* + * _Thread_Ready + * + * DESCRIPTION: + * + * This routine removes any set states for the_thread. It performs + * any necessary scheduling operations including the selection of + * a new heir thread. + */ + +void _Thread_Ready( + Thread_Control *the_thread +); + +/* + * _Thread_Clear_state + * + * DESCRIPTION: + * + * This routine clears the indicated STATES for the_thread. It performs + * any necessary scheduling operations including the selection of + * a new heir thread. + */ + +void _Thread_Clear_state( + Thread_Control *the_thread, + States_Control state +); + +/* + * _Thread_Set_state + * + * DESCRIPTION: + * + * This routine sets the indicated states for the_thread. It performs + * any necessary scheduling operations including the selection of + * a new heir thread. + * + */ + +void _Thread_Set_state( + Thread_Control *the_thread, + States_Control state +); + +/* + * _Thread_Set_transient + * + * DESCRIPTION: + * + * This routine sets the TRANSIENT state for the_thread. It performs + * any necessary scheduling operations including the selection of + * a new heir thread. + */ + +void _Thread_Set_transient( + Thread_Control *the_thread +); + +/* + * _Thread_Reset_timeslice + * + * DESCRIPTION: + * + * This routine is invoked upon expiration of the currently + * executing thread's timeslice. If no other thread's are ready + * at the priority of the currently executing thread, then the + * executing thread's timeslice is reset. Otherwise, the + * currently executing thread is placed at the rear of the + * FIFO for this priority and a new heir is selected. + */ + +void _Thread_Reset_timeslice( void ); + +/* + * _Thread_Tickle_timeslice + * + * DESCRIPTION: + * + * This routine is invoked as part of processing each clock tick. + * It is responsible for determining if the current thread allows + * timeslicing and, if so, when its timeslice expires. + */ + +void _Thread_Tickle_timeslice( void ); + +/* + * _Thread_Yield_processor + * + * DESCRIPTION: + * + * This routine is invoked when a thread wishes to voluntarily + * transfer control of the processor to another thread of equal + * or greater priority. + */ + +void _Thread_Yield_processor( void ); + +/* + * _Thread_Load_environment + * + * DESCRIPTION: + * + * This routine initializes the context of the_thread to its + * appropriate starting state. + */ + +void _Thread_Load_environment( + Thread_Control *the_thread +); + +/* + * _Thread_Handler + * + * DESCRIPTION: + * + * This routine is the wrapper function for all threads. It is + * the starting point for all threads. The user provided thread + * entry point is invoked by this routine. Operations + * which must be performed immediately before and after the user's + * thread executes are found here. + */ + +void _Thread_Handler( void ); + +/* + * _Thread_Delay_ended + * + * DESCRIPTION: + * + * This routine is invoked when a thread must be unblocked at the + * end of a time based delay (i.e. wake after or wake when). + */ + +void _Thread_Delay_ended( + Objects_Id id, + void *ignored +); + +/* + * _Thread_Change_priority + * + * DESCRIPTION: + * + * This routine changes the current priority of the_thread to + * new_priority. It performs any necessary scheduling operations + * including the selection of a new heir thread. + */ + +void _Thread_Change_priority ( + Thread_Control *the_thread, + Priority_Control new_priority +); + +/* + * _Thread_Set_priority + * + * DESCRIPTION: + * + * This routine updates the priority related fields in the_thread + * control block to indicate the current priority is now new_priority. + */ + +void _Thread_Set_priority( + Thread_Control *the_thread, + Priority_Control new_priority +); + +/* + * _Thread_Evaluate_mode + * + * DESCRIPTION: + * + * This routine XXX + */ + +boolean _Thread_Evaluate_mode( void ); + +/* + * _Thread_Get + * + * NOTE: If we are not using static inlines, this must be a real + * subroutine call. + */ + +#ifndef USE_INLINES +Thread_Control *_Thread_Get ( + Objects_Id id, + Objects_Locations *location +); +#endif + +/* + * _Thread_Idle_body + * + * DESCRIPTION: + * + * This routine is the body of the system idle thread. + */ + +#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE) +Thread _Thread_Idle_body( + unsigned32 ignored +); +#endif + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/thread.inl> +#endif +#include <rtems/score/threadmp.h> + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/threadmp.h b/cpukit/score/include/rtems/score/threadmp.h new file mode 100644 index 0000000000..0466a04065 --- /dev/null +++ b/cpukit/score/include/rtems/score/threadmp.h @@ -0,0 +1,89 @@ +/* threadmp.h + * + * This include file contains the specification for all routines + * and data specific to the multiprocessing portion of the thread package. + * + * 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$ + */ + +#ifndef __RTEMS_THREAD_MP_h +#define __RTEMS_THREAD_MP_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * _Thread_MP_Handler_initialization + * + * DESCRIPTION: + * + * This routine initializes the multiprocessing portion of the Thread Handler. + */ + +void _Thread_MP_Handler_initialization ( + unsigned32 maximum_proxies +); + +/* + * _Thread_MP_Allocate_proxy + * + * DESCRIPTION: + * + * This allocates a proxy control block from + * the inactive chain of free proxy control blocks. + * + * NOTE: This function returns a thread control pointer + * because proxies are substitutes for remote threads. + */ + +Thread_Control *_Thread_MP_Allocate_proxy ( + States_Control the_state +); + +/* + * _Thread_MP_Find_proxy + * + * DESCRIPTION: + * + * This function removes the proxy control block for the specified + * id from the active chain of proxy control blocks. + */ + +Thread_Control *_Thread_MP_Find_proxy ( + Objects_Id the_id +); + +/* + * The following is used to determine when the multiprocessing receive + * thread is executing so that a proxy can be allocated instead of + * blocking the multiprocessing receive thread. + */ + +EXTERN Thread_Control *_Thread_MP_Receive; + +/* + * The following chains are used to manage proxies. + */ + +EXTERN Chain_Control _Thread_MP_Active_proxies; +EXTERN Chain_Control _Thread_MP_Inactive_proxies; + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/threadmp.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/threadq.h b/cpukit/score/include/rtems/score/threadq.h new file mode 100644 index 0000000000..6a074daf16 --- /dev/null +++ b/cpukit/score/include/rtems/score/threadq.h @@ -0,0 +1,301 @@ +/* threadq.h + * + * This include file contains all the constants and structures associated + * with the manipulation of objects. + * + * 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$ + */ + +#ifndef __THREAD_QUEUE_h +#define __THREAD_QUEUE_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/tqdata.h> + +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/score/watchdog.h> + +/* + * Constant for indefinite wait. + */ + +#define THREAD_QUEUE_WAIT_FOREVER WATCHDOG_NO_TIMEOUT + +/* + * The following type defines the callout used when a remote task + * is extracted from a local thread queue. + */ + +typedef void ( *Thread_queue_Flush_callout )( + Thread_Control * + ); + +/* + * The following type defines the callout used when a local task + * is extracted from a remote thread queue (i.e. it's proxy must + * extracted from the remote queue). + */ + +typedef void ( *Thread_queue_Extract_callout )( + Thread_Control * + ); + +EXTERN Thread_queue_Extract_callout + _Thread_queue_Extract_table[ OBJECTS_CLASSES_LAST + 1 ]; + +/* + * _Thread_queue_Dequeue + * + * DESCRIPTION: + * + * This function returns a pointer to a thread waiting on + * the_thread_queue. The selection of this thread is based on + * the discipline of the_thread_queue. If no threads are waiting + * on the_thread_queue, then NULL is returned. + */ + +Thread_Control *_Thread_queue_Dequeue( + Thread_queue_Control *the_thread_queue +); + +/* + * _Thread_queue_Enqueue + * + * DESCRIPTION: + * + * This routine enqueues the currently executing thread on + * the_thread_queue with an optional timeout. + */ + +void _Thread_queue_Enqueue( + Thread_queue_Control *the_thread_queue, + Watchdog_Interval timeout +); + +/* + * _Thread_queue_Extract + * + * DESCRIPTION: + * + * This routine removes the_thread from the_thread_queue + * and cancels any timeouts associated with this blocking. + */ + +void _Thread_queue_Extract( + Thread_queue_Control *the_thread_queue, + Thread_Control *the_thread +); + +/* + * _Thread_queue_Extract_with_proxy + * + * DESCRIPTION: + * + * This routine extracts the_thread from the_thread_queue + * and insures that if there is a proxy for this task on + * another node, it is also dealt with. + */ + +boolean _Thread_queue_Extract_with_proxy( + Thread_Control *the_thread +); + +/* + * _Thread_queue_First + * + * DESCRIPTION: + * + * This function returns a pointer to the "first" thread + * on the_thread_queue. The "first" thread is selected + * based on the discipline of the_thread_queue. + */ + +Thread_Control *_Thread_queue_First( + Thread_queue_Control *the_thread_queue +); + +/* + * _Thread_queue_Flush + * + * DESCRIPTION: + * + * This routine unblocks all threads blocked on the_thread_queue + * and cancels any associated timeouts. + */ + +void _Thread_queue_Flush( + Thread_queue_Control *the_thread_queue, + Thread_queue_Flush_callout remote_extract_callout, + unsigned32 status +); + +/* + * _Thread_queue_Initialize + * + * DESCRIPTION: + * + * This routine initializes the_thread_queue based on the + * discipline indicated in attribute_set. The state set on + * threads which block on the_thread_queue is state. + */ + +void _Thread_queue_Initialize( + Thread_queue_Control *the_thread_queue, + Objects_Classes the_class, + Thread_queue_Disciplines the_discipline, + States_Control state, + Thread_queue_Extract_callout proxy_extract_callout, + unsigned32 timeout_status +); + +/* + * _Thread_queue_Dequeue_priority + * + * DESCRIPTION: + * + * This function returns a pointer to the highest priority + * thread waiting on the_thread_queue. If no threads are waiting + * on the_thread_queue, then NULL is returned. + */ + +Thread_Control *_Thread_queue_Dequeue_priority( + Thread_queue_Control *the_thread_queue +); + +/* + * _Thread_queue_Enqueue_priority + * + * DESCRIPTION: + * + * This routine enqueues the currently executing thread on + * the_thread_queue with an optional timeout using the + * priority discipline. + */ + +void _Thread_queue_Enqueue_priority( + Thread_queue_Control *the_thread_queue, + Thread_Control *the_thread, + Watchdog_Interval timeout +); + +/* + * _Thread_queue_Extract_priority + * + * DESCRIPTION: + * + * This routine removes the_thread from the_thread_queue + * and cancels any timeouts associated with this blocking. + */ + +void _Thread_queue_Extract_priority( + Thread_queue_Control *the_thread_queue, + Thread_Control *the_thread +); + +/* + * _Thread_queue_First_priority + * + * DESCRIPTION: + * + * This function returns a pointer to the "first" thread + * on the_thread_queue. The "first" thread is the highest + * priority thread waiting on the_thread_queue. + */ + +Thread_Control *_Thread_queue_First_priority( + Thread_queue_Control *the_thread_queue +); + +/* + * _Thread_queue_Dequeue_FIFO + * + * DESCRIPTION: + * + * This function returns a pointer to the thread which has + * been waiting the longest on the_thread_queue. If no + * threads are waiting on the_thread_queue, then NULL is returned. + */ + +Thread_Control *_Thread_queue_Dequeue_fifo( + Thread_queue_Control *the_thread_queue +); + +/* + * _Thread_queue_Enqueue_FIFO + * + * DESCRIPTION: + * + * This routine enqueues the currently executing thread on + * the_thread_queue with an optional timeout using the + * FIFO discipline. + */ + +void _Thread_queue_Enqueue_fifo( + Thread_queue_Control *the_thread_queue, + Thread_Control *the_thread, + Watchdog_Interval timeout +); + +/* + * _Thread_queue_Extract_FIFO + * + * DESCRIPTION: + * + * This routine removes the_thread from the_thread_queue + * and cancels any timeouts associated with this blocking. + */ + +void _Thread_queue_Extract_fifo( + Thread_queue_Control *the_thread_queue, + Thread_Control *the_thread +); + +/* + * _Thread_queue_First_FIFO + * + * DESCRIPTION: + * + * This function returns a pointer to the "first" thread + * on the_thread_queue. The first thread is the thread + * which has been waiting longest on the_thread_queue. + */ + +Thread_Control *_Thread_queue_First_fifo( + Thread_queue_Control *the_thread_queue +); + +/* + * _Thread_queue_timeout + * + * DESCRIPTION: + * + * This routine is invoked when a task's request has not + * been satisfied after the timeout interval specified to + * enqueue. The task represented by ID will be unblocked and + * its status code will be set in it's control block to indicate + * that a timeout has occurred. + */ + +void _Thread_queue_Timeout ( + Objects_Id id, + void *ignored +); + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/tod.h b/cpukit/score/include/rtems/score/tod.h new file mode 100644 index 0000000000..b0fb686014 --- /dev/null +++ b/cpukit/score/include/rtems/score/tod.h @@ -0,0 +1,260 @@ +/* tod.h + * + * This include file contains all the constants and structures associated + * with the Time of Day 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$ + */ + +#ifndef __TIME_OF_DAY_h +#define __TIME_OF_DAY_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> +#include <rtems/score/watchdog.h> + +/* + * The following constants are related to the time of day. + */ + +#define TOD_SECONDS_PER_MINUTE 60 +#define TOD_MINUTES_PER_HOUR 60 +#define TOD_MONTHS_PER_YEAR 12 +#define TOD_DAYS_PER_YEAR 365 +#define TOD_HOURS_PER_DAY 24 +#define TOD_SECONDS_PER_DAY (TOD_SECONDS_PER_MINUTE * \ + TOD_MINUTES_PER_HOUR * \ + TOD_HOURS_PER_DAY) + +#define TOD_SECONDS_PER_NON_LEAP_YEAR (365 * TOD_SECONDS_PER_DAY) + +#define TOD_MICROSECONDS_PER_SECOND 1000000 +#define TOD_MILLISECONDS_PER_SECOND 1000 + +/* + * The following constant define the earliest year to which an + * time of day can be initialized. This is considered the + * epoch. + */ + +#define TOD_BASE_YEAR 1988 + +/* + * The following record defines the time of control block. This + * control block is used to maintain the current time of day. + */ + +typedef struct { /* RTEID style time/date */ + unsigned32 year; /* year, A.D. */ + unsigned32 month; /* month, 1 -> 12 */ + unsigned32 day; /* day, 1 -> 31 */ + unsigned32 hour; /* hour, 0 -> 23 */ + unsigned32 minute; /* minute, 0 -> 59 */ + unsigned32 second; /* second, 0 -> 59 */ + unsigned32 ticks; /* elapsed ticks between secs */ +} TOD_Control; + +/* + * The following contains the current time of day. + */ + +EXTERN TOD_Control _TOD_Current; + +/* + * The following contains the number of seconds from 00:00:00 + * January 1, TOD_BASE_YEAR until the current time of day. + */ + +EXTERN Watchdog_Interval _TOD_Seconds_since_epoch; + +/* + * The following contains the number of ticks since the + * system was booted. + */ + +EXTERN Watchdog_Interval _TOD_Ticks_since_boot; + +/* + * The following contains the number of microseconds per tick. + */ + +EXTERN unsigned32 _TOD_Microseconds_per_tick; + +/* + * The following contains the number of clock ticks per second. + * + * NOTE: + * + * If one second is NOT evenly divisible by the number of microseconds + * per clock tick, this value will contain only the integer portion + * of the division. This means that the interval between clock ticks + * can be a source of error in the current time of day. + */ + +EXTERN unsigned32 _TOD_Ticks_per_second; + +/* + * This is the control structure for the watchdog timer which + * fires to service the seconds chain. + */ + +EXTERN Watchdog_Control _TOD_Seconds_watchdog; + +#ifdef INIT + +/* + * The following array contains the number of days in all months. + * The first dimension should be 1 for leap years, and 0 otherwise. + * The second dimension should range from 1 to 12 for January to + * February, respectively. + */ + +const unsigned32 _TOD_Days_per_month[ 2 ][ 13 ] = { + { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } +}; + +/* + * The following array contains the number of days in all months + * up to the month indicated by the index of the second dimension. + * The first dimension should be 1 for leap years, and 0 otherwise. + */ + +const unsigned16 _TOD_Days_to_date[2][13] = { + { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }, + { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 } +}; + +/* + * The following array contains the number of days in the years + * since the last leap year. The index should be 0 for leap + * years, and the number of years since the beginning of a leap + * year otherwise. + */ + +const unsigned16 _TOD_Days_since_last_leap_year[4] = { 0, 366, 761, 1126 }; + +#else + +extern const unsigned16 _TOD_Days_to_date[2][13]; /* Julian days */ +extern const unsigned16 _TOD_Days_since_last_leap_year[4]; +extern const unsigned32 _TOD_Days_per_month[2][13]; + +#endif + +/* + * _TOD_Handler_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this handler. + */ + +void _TOD_Handler_initialization( + unsigned32 microseconds_per_tick +); + +/* + * _TOD_Set + * + * DESCRIPTION: + * + * This routine sets the current time of day to THE_TOD and + * the equivalent SECONDS_SINCE_EPOCH. + */ + +void _TOD_Set( + TOD_Control *the_tod, + Watchdog_Interval seconds_since_epoch +); + +/* + * _TOD_Validate + * + * DESCRIPTION: + * + * This function returns TRUE if THE_TOD contains + * a valid time of day, and FALSE otherwise. + */ + +boolean _TOD_Validate( + TOD_Control *the_tod +); + +/* + * _TOD_To_seconds + * + * DESCRIPTION: + * + * This function returns the number seconds between the epoch and THE_TOD. + */ + +Watchdog_Interval _TOD_To_seconds( + TOD_Control *the_tod +); + +/* + * _TOD_Tickle + * + * DESCRIPTION: + * + * This routine is scheduled as a watchdog function and is invoked at + * each second boundary. It updates the current time of day to indicate + * that a second has passed and processes the seconds watchdog chain. + */ + +void _TOD_Tickle( + Objects_Id id, + void *ignored +); + +/* + * TOD_MILLISECONDS_TO_MICROSECONDS + * + * DESCRIPTION: + * + * This routine converts an interval expressed in milliseconds to microseconds. + * + * NOTE: + * + * This must be a macro so it can be used in "static" tables. + */ + +#define TOD_MILLISECONDS_TO_MICROSECONDS(_ms) ((_ms) * 1000) + +/* + * TOD_MILLISECONDS_TO_TICKS + * + * DESCRIPTION: + * + * This routine converts an interval expressed in milliseconds to ticks. + * + * NOTE: + * + * This must be a macro so it can be used in "static" tables. + */ + +#define TOD_MILLISECONDS_TO_TICKS(_ms) \ + (TOD_MILLISECONDS_TO_MICROSECONDS(_ms) / _TOD_Microseconds_per_tick) + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/tod.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/tqdata.h b/cpukit/score/include/rtems/score/tqdata.h new file mode 100644 index 0000000000..c9c9585f7f --- /dev/null +++ b/cpukit/score/include/rtems/score/tqdata.h @@ -0,0 +1,91 @@ +/* tqdata.h + * + * This include file contains all the constants and structures + * needed to declare a thread queue. + * + * 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$ + */ + +#ifndef __THREAD_QUEUE_DATA_h +#define __THREAD_QUEUE_DATA_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/chain.h> +#include <rtems/score/priority.h> +#include <rtems/score/states.h> + +/* + * The following enumerated type details all of the disciplines + * supported by the Thread Queue Handler. + */ + +typedef enum { + THREAD_QUEUE_DISCIPLINE_FIFO, /* FIFO queue discipline */ + THREAD_QUEUE_DISCIPLINE_PRIORITY /* PRIORITY queue discipline */ +} Thread_queue_Disciplines; + +/* + * The following enumerated types indicate what happened while the thread + * queue was in the synchronization window. + */ + +typedef enum { + THREAD_QUEUE_SYNCHRONIZED, + THREAD_QUEUE_NOTHING_HAPPENED, + THREAD_QUEUE_TIMEOUT, + THREAD_QUEUE_SATISFIED +} Thread_queue_States; + +/* + * The following constants are used to manage the priority queues. + * + * There are four chains used to maintain a priority -- each chain + * manages a distinct set of task priorities. The number of chains + * is determined by TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS. + * The following set must be consistent. + * + * The set below configures 4 headers -- each contains 64 priorities. + * Header x manages priority range (x*64) through ((x*64)+63). If + * the priority is more than half way through the priority range it + * is in, then the search is performed from the rear of the chain. + * This halves the search time to find the insertion point. + */ + +#define TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS 4 +#define TASK_QUEUE_DATA_PRIORITIES_PER_HEADER 64 +#define TASK_QUEUE_DATA_REVERSE_SEARCH_MASK 0x20 + +typedef struct { + union { + Chain_Control Fifo; /* FIFO discipline list */ + Chain_Control Priority[TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS]; + /* priority discipline list */ + } Queues; + Thread_queue_States sync_state; /* alloc/dealloc critical section */ + Thread_queue_Disciplines discipline; /* queue discipline */ + States_Control state; /* state of threads on Thread_q */ + unsigned32 timeout_status; + unsigned32 count; +} Thread_queue_Control; + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/tqdata.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/userext.h b/cpukit/score/include/rtems/score/userext.h new file mode 100644 index 0000000000..1a6ac3437e --- /dev/null +++ b/cpukit/score/include/rtems/score/userext.h @@ -0,0 +1,213 @@ +/* userext.h + * + * This include file contains all information about user extensions. This + * Handler provides mechanisms which can be used to initialize and manipulate + * all user extensions. + * + * 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$ + */ + +#ifndef __USER_EXTENSIONS_h +#define __USER_EXTENSIONS_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/interr.h> +#include <rtems/score/chain.h> +#include <rtems/score/thread.h> + +/* + * The following records defines the User Extension Table. + * This table defines the application dependent routines which + * are invoked at critical points in the life of each thread and + * the system as a whole. + */ + +typedef void User_extensions_routine; + +typedef boolean ( *User_extensions_thread_create_extension )( + Thread_Control *, + Thread_Control * + ); + +typedef User_extensions_routine ( *User_extensions_thread_delete_extension )( + Thread_Control *, + Thread_Control * + ); + +typedef User_extensions_routine ( *User_extensions_thread_start_extension )( + Thread_Control *, + Thread_Control * + ); + +typedef User_extensions_routine ( *User_extensions_thread_restart_extension )( + Thread_Control *, + Thread_Control * + ); + +typedef User_extensions_routine ( *User_extensions_thread_switch_extension )( + Thread_Control *, + Thread_Control * + ); + +typedef User_extensions_routine ( *User_extensions_thread_begin_extension )( + Thread_Control * + ); + +typedef User_extensions_routine ( *User_extensions_thread_exitted_extension )( + Thread_Control * + ); + +typedef User_extensions_routine ( *User_extensions_fatal_extension )( + Internal_errors_Source /* the_source */, + boolean /* is_internal */, + unsigned32 /* the_error */ + ); + + +typedef struct { + User_extensions_thread_create_extension thread_create; + User_extensions_thread_start_extension thread_start; + User_extensions_thread_restart_extension thread_restart; + User_extensions_thread_delete_extension thread_delete; + User_extensions_thread_switch_extension thread_switch; + User_extensions_thread_begin_extension thread_begin; + User_extensions_thread_exitted_extension thread_exitted; + User_extensions_fatal_extension fatal; +} User_extensions_Table; + +/* + * The following is used to manage each user extension set. + */ + +typedef struct { + Chain_Node Node; + User_extensions_Table Callouts; +} User_extensions_Control; + +/* + * The following contains the static extension set which may be + * configured by the application. + */ + +EXTERN User_extensions_Control _User_extensions_Initial; + +/* + * The following is used to manage the list of active extensions. + */ + +EXTERN Chain_Control _User_extensions_List; + +/* + * _User_extensions_Thread_create + * + * DESCRIPTION: + * + * This routine is used to invoke the user extension for + * the thread creation operate. + */ + +boolean _User_extensions_Thread_create ( + Thread_Control *the_thread +); + +/* + * _User_extensions_Thread_delete + * + * DESCRIPTION: + * + * This routine is used to invoke the user extension for + * the thread deletion operation. + */ + +void _User_extensions_Thread_delete ( + Thread_Control *the_thread +); + +/* + * _User_extensions_Thread_start + * + * DESCRIPTION: + * + * This routine is used to invoke the user extension for + * the thread start operation. + */ + +void _User_extensions_Thread_start ( + Thread_Control *the_thread +); + +/* + * _User_extensions_Thread_restart + * + * DESCRIPTION: + * + * This routine is used to invoke the user extension for + * the thread restart operation. + */ + +void _User_extensions_Thread_restart ( + Thread_Control *the_thread +); + +/* + * _User_extensions_Thread_begin + * + * DESCRIPTION: + * + * This routine is used to invoke the user extension which + * is invoked when a thread begins. + */ + +void _User_extensions_Thread_begin ( + Thread_Control *executing +); + +/* + * _User_extensions_Thread_exitted + * + * DESCRIPTION: + * + * This routine is used to invoke the user extension which + * is invoked when a thread exits. + */ + +void _User_extensions_Thread_exitted ( + Thread_Control *executing +); + +/* + * _User_extensions_Fatal + * + * DESCRIPTION: + * + * This routine is used to invoke the user extension invoked + * when a fatal error occurs. + */ + +void _User_extensions_Fatal ( + Internal_errors_Source the_source, + boolean is_internal, + unsigned32 the_error +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/userext.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/watchdog.h b/cpukit/score/include/rtems/score/watchdog.h new file mode 100644 index 0000000000..9b13407c8e --- /dev/null +++ b/cpukit/score/include/rtems/score/watchdog.h @@ -0,0 +1,185 @@ +/* watchdog.h + * + * This include file contains all the constants and structures associated + * with watchdog timers. This Handler provides mechanisms which can be + * used to initialize and manipulate watchdog timers. + * + * 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$ + */ + +#ifndef __WATCHDOG_h +#define __WATCHDOG_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/object.h> + +/* + * The following type defines the control block used to manage + * intervals. + */ + +typedef unsigned32 Watchdog_Interval; + +/* + * The following types define a pointer to a watchdog service routine. + */ + +typedef void Watchdog_Service_routine; + +typedef Watchdog_Service_routine ( *Watchdog_Service_routine_entry )( + Objects_Id, + void * + ); + +/* + * Constant for indefinite wait. (actually an illegal interval) + */ + +#define WATCHDOG_NO_TIMEOUT 0 + +/* + * The following enumerated type lists the states in which a + * watchdog timer may be at any given time. + */ + +typedef enum { + WATCHDOG_INACTIVE, /* off all chains */ + WATCHDOG_BEING_INSERTED, /* off all chains, searching for insertion point */ + WATCHDOG_ACTIVE, /* on chain, allowed to fire */ + WATCHDOG_REMOVE_IT /* on chain, remove without firing if expires */ +} Watchdog_States; + +/* + * The following enumerated type details the manner in which + * a watchdog chain may be adjusted by the Watchdog_Adjust + * routine. The direction indicates a movement FORWARD + * or BACKWARD in time. + */ + +typedef enum { + WATCHDOG_FORWARD, /* adjust delta value forward */ + WATCHDOG_BACKWARD /* adjust delta value backward */ +} Watchdog_Adjust_directions; + +/* + * The following record defines the control block used + * to manage each watchdog timer. + */ + +typedef struct { + Chain_Node Node; + Watchdog_States state; + Watchdog_Interval initial; + Watchdog_Interval delta_interval; + Watchdog_Service_routine_entry routine; + Objects_Id id; + void *user_data; +} Watchdog_Control; + +/* + * The following are used for synchronization purposes + * during an insert on a watchdog delta chain. + */ + +EXTERN volatile unsigned32 _Watchdog_Sync_level; +EXTERN volatile unsigned32 _Watchdog_Sync_count; + +/* + * The following defines the watchdog chains which are managed + * on ticks and second boundaries. + */ + +EXTERN Chain_Control _Watchdog_Ticks_chain; +EXTERN Chain_Control _Watchdog_Seconds_chain; + +/* + * _Watchdog_Handler_initialization + * + * DESCRIPTION: + * + * This routine initializes the watchdog handler. The watchdog + * synchronization flag is initialized and the watchdog chains are + * initialized and emptied. + */ + +void _Watchdog_Handler_initialization( void ); + +/* + * _Watchdog_Remove + * + * DESCRIPTION: + * + * This routine removes THE_WATCHDOG from the watchdog chain on which + * it resides and returns the state THE_WATCHDOG timer was in. + */ + +Watchdog_States _Watchdog_Remove ( + Watchdog_Control *the_watchdog +); + +/* + * _Watchdog_Adjust + * + * DESCRIPTION: + * + * This routine adjusts the HEADER watchdog chain in the forward + * or backward DIRECTION for UNITS ticks. + */ + +void _Watchdog_Adjust ( + Chain_Control *header, + Watchdog_Adjust_directions direction, + Watchdog_Interval units +); + +/* + * _Watchdog_Insert + * + * DESCRIPTION: + * + * This routine inserts THE_WATCHDOG into the HEADER watchdog chain + * for a time of UNITS. The INSERT_MODE indicates whether + * THE_WATCHDOG is to be activated automatically or later, explicitly + * by the caller. + * + */ + +void _Watchdog_Insert ( + Chain_Control *header, + Watchdog_Control *the_watchdog +); + +/* + * _Watchdog_Tickle + * + * DESCRIPTION: + * + * This routine is invoked at appropriate intervals to update + * the HEADER watchdog chain. + */ + +void _Watchdog_Tickle ( + Chain_Control *header +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/watchdog.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/score/wkspace.h b/cpukit/score/include/rtems/score/wkspace.h new file mode 100644 index 0000000000..9814a707b1 --- /dev/null +++ b/cpukit/score/include/rtems/score/wkspace.h @@ -0,0 +1,71 @@ +/* wkspace.h + * + * This include file contains information related to the + * RAM Workspace. This Handler provides mechanisms which can be used to + * define, initialize and manipulate the workspace. + * + * 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$ + */ + +#ifndef __WORKSPACE_h +#define __WORKSPACE_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtems/score/heap.h> +#include <rtems/score/interr.h> + +/* + * The following is used to manage the Workspace. + * + */ + +EXTERN Heap_Control _Workspace_Area; /* executive heap header */ + +/* + * _Workspace_Handler_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this handler. + */ + +void _Workspace_Handler_initialization( + void *starting_address, + unsigned32 size +); + +/* + * _Workspace_Allocate_or_fatal_error + * + * DESCRIPTION: + * + * This routine returns the address of a block of memory of size + * bytes. If a block of the appropriate size cannot be allocated + * from the workspace, then the internal error handler is invoked. + */ + +void *_Workspace_Allocate_or_fatal_error( + unsigned32 size +); + +#ifndef __RTEMS_APPLICATION__ +#include <rtems/score/wkspace.inl> +#endif + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/include/rtems/system.h b/cpukit/score/include/rtems/system.h new file mode 100644 index 0000000000..9b50159c81 --- /dev/null +++ b/cpukit/score/include/rtems/system.h @@ -0,0 +1,134 @@ +/* system.h + * + * This include file contains information that is included in every + * function in the executive. This must be the first include file + * included in all internal RTEMS files. + * + * 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$ + */ + +#ifndef __RTEMS_SYSTEM_h +#define __RTEMS_SYSTEM_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The following define the CPU Family and Model within the family + * + * NOTE: The string "REPLACE_THIS_WITH_USE_INLINE_OR_MACROS" is replaced + * with either "USE_INLINES" or "USE_MACROS" based upon the + * whether this target configuration uses the inline or + * macro implementations of the inlined RTEMS routines. + */ + + +#define REPLACE_THIS_WITH_USE_INLINE_OR_MACROS + +/* + * The following insures that all data is declared in the space + * of the Initialization Manager. It is referenced as "external" + * in every other file. + */ + +#ifdef INIT +#undef EXTERN +#define EXTERN +#else +#undef EXTERN +#define EXTERN extern +#endif + +/* + * The following (in conjunction with compiler arguments) are used + * to choose between the use of static inline functions and macro + * functions. The static inline implementation allows better + * type checking with no cost in code size or execution speed. + */ + +#ifdef USE_INLINES +# define STATIC static +# ifdef __GNUC__ +# define INLINE __inline__ +# else +# define INLINE inline +# endif +#else +# define STATIC +# define INLINE +#endif + +/* + * Include a base set of files. + */ + +/* + * XXX: Eventually proc_ptr needs to disappear!!! + */ + +typedef void * proc_ptr; + +#include <rtems/score/cpu.h> /* processor specific information */ + +/* + * Define NULL + */ + +#ifndef NULL +#define NULL 0 /* NULL value */ +#endif + +/* + * Boolean constants + */ + +#if !defined( TRUE ) || (TRUE != 1) +#undef TRUE +#define TRUE (1) +#endif + +#if !defined( FALSE ) || (FALSE != 0) +#undef FALSE +#define FALSE (0) +#endif + +#define stringify( _x ) # _x + +#define RTEMS_offsetof(type, field) \ + ((unsigned32) &(((type *) 0)->field)) + +/* + * The following is the extern for the RTEMS version string. + * The contents of this string are CPU specific. + */ + +extern const char _RTEMS_version[]; /* RTEMS version string */ +extern const char _Copyright_Notice[]; /* RTEMS copyright string */ + +/* + * The following defines the CPU dependent information table. + */ + +EXTERN rtems_cpu_table _CPU_Table; /* CPU dependent info */ + +/* + * XXX weird RTEMS stuff + */ + +#define RTEMS_MAXIMUM_NAME_LENGTH 4 + +#ifdef __cplusplus +} +#endif + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/address.inl b/cpukit/score/inline/rtems/score/address.inl new file mode 100644 index 0000000000..343123c981 --- /dev/null +++ b/cpukit/score/inline/rtems/score/address.inl @@ -0,0 +1,120 @@ +/* inline/address.inl + * + * This include file contains the bodies of the routines + * about addresses which are inlined. + * + * 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$ + */ + +#ifndef __INLINE_ADDRESSES_inl +#define __INLINE_ADDRESSES_inl + +/*PAGE + * + * _Addresses_Add_offset + * + * DESCRIPTION: + * + * This function is used to add an offset to a base address. + * It returns the resulting address. This address is typically + * converted to an access type before being used further. + */ + +STATIC INLINE void *_Addresses_Add_offset ( + void *base, + unsigned32 offset +) +{ + return (void *)((char *)base + offset); +} + +/*PAGE + * + * _Addresses_Subtract_offset + * + * DESCRIPTION: + * + * This function is used to subtract an offset from a base + * address. It returns the resulting address. This address is + * typically converted to an access type before being used further. + */ + +STATIC INLINE void *_Addresses_Subtract_offset ( + void *base, + unsigned32 offset +) +{ + return (void *)((char *)base - offset); +} + +/*PAGE + * + * _Addresses_Subtract + * + * DESCRIPTION: + * + * This function is used to subtract two addresses. It returns the + * resulting offset. + * + * NOTE: The cast of an address to an unsigned32 makes this code + * dependent on an addresses being thirty two bits. + */ + +STATIC INLINE unsigned32 _Addresses_Subtract ( + void *left, + void *right +) +{ + return ((char *) left - (char *) right); +} + +/*PAGE + * + * _Addresses_Is_aligned + * + * DESCRIPTION: + * + * This function returns TRUE if the given address is correctly + * aligned for this processor and FALSE otherwise. Proper alignment + * is based on correctness and efficiency. + */ + +STATIC INLINE boolean _Addresses_Is_aligned ( + void *address +) +{ + return ( ( (unsigned32)address % CPU_ALIGNMENT ) == 0 ); +} + +/*PAGE + * + * _Addresses_Is_in_range + * + * DESCRIPTION: + * + * This function returns TRUE if the given address is within the + * memory range specified and FALSE otherwise. base is the address + * of the first byte in the memory range and limit is the address + * of the last byte in the memory range. The base address is + * assumed to be lower than the limit address. + */ + +STATIC INLINE boolean _Addresses_Is_in_range ( + void *address, + void *base, + void *limit +) +{ + return ( address >= base && address <= limit ); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/chain.inl b/cpukit/score/inline/rtems/score/chain.inl new file mode 100644 index 0000000000..7fd3fef934 --- /dev/null +++ b/cpukit/score/inline/rtems/score/chain.inl @@ -0,0 +1,390 @@ +/* inline/chain.inl + * + * This include file contains the bodies of the routines which are + * associated with doubly linked chains and inlined. + * + * NOTE: The routines in this file are ordered from simple + * to complex. No other Chain Handler routine is referenced + * unless it has already been defined. + * + * 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$ + */ + +#ifndef __INLINE_CHAIN_inl +#define __INLINE_CHAIN_inl + +/*PAGE + * + * _Chain_Are_nodes_equal + * + * DESCRIPTION: + * + * This function returns TRUE if LEFT and RIGHT are equal, + * and FALSE otherwise. + */ + +STATIC INLINE boolean _Chain_Are_nodes_equal( + Chain_Node *left, + Chain_Node *right +) +{ + return left == right; +} + +/*PAGE + * + * _Chain_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_chain is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _Chain_Is_null( + Chain_Control *the_chain +) +{ + return ( the_chain == NULL ); +} + +/*PAGE + * + * _Chain_Is_null_node + * + * DESCRIPTION: + * + * This function returns TRUE if the_node is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _Chain_Is_null_node( + Chain_Node *the_node +) +{ + return ( the_node == NULL ); +} + +/*PAGE + * + * _Chain_Head + * + * DESCRIPTION: + * + * This function returns a pointer to the first node on the chain. + */ + +STATIC INLINE Chain_Node *_Chain_Head( + Chain_Control *the_chain +) +{ + return (Chain_Node *) the_chain; +} + +/*PAGE + * + * _Chain_Tail + * + * DESCRIPTION: + * + * This function returns a pointer to the last node on the chain. + */ + +STATIC INLINE Chain_Node *_Chain_Tail( + Chain_Control *the_chain +) +{ + return (Chain_Node *) &the_chain->permanent_null; +} + +/*PAGE + * + * _Chain_Is_empty + * + * DESCRIPTION: + * + * This function returns TRUE if there a no nodes on the_chain and + * FALSE otherwise. + */ + +STATIC INLINE boolean _Chain_Is_empty( + Chain_Control *the_chain +) +{ + return ( the_chain->first == _Chain_Tail( the_chain ) ); +} + +/*PAGE + * + * _Chain_Is_first + * + * DESCRIPTION: + * + * This function returns TRUE if the_node is the first node on a chain and + * FALSE otherwise. + */ + +STATIC INLINE boolean _Chain_Is_first( + Chain_Node *the_node +) +{ + return ( the_node->previous == NULL ); +} + +/*PAGE + * + * _Chain_Is_last + * + * DESCRIPTION: + * + * This function returns TRUE if the_node is the last node on a chain and + * FALSE otherwise. + */ + +STATIC INLINE boolean _Chain_Is_last( + Chain_Node *the_node +) +{ + return ( the_node->next == NULL ); +} + +/*PAGE + * + * _Chain_Has_only_one_node + * + * DESCRIPTION: + * + * This function returns TRUE if there is only one node on the_chain and + * FALSE otherwise. + */ + +STATIC INLINE boolean _Chain_Has_only_one_node( + Chain_Control *the_chain +) +{ + return ( the_chain->first == the_chain->last ); +} + +/*PAGE + * + * _Chain_Is_head + * + * DESCRIPTION: + * + * This function returns TRUE if the_node is the head of the_chain and + * FALSE otherwise. + */ + +STATIC INLINE boolean _Chain_Is_head( + Chain_Control *the_chain, + Chain_Node *the_node +) +{ + return ( the_node == _Chain_Head( the_chain ) ); +} + +/*PAGE + * + * _Chain_Is_tail + * + * DESCRIPTION: + * + * This function returns TRUE if the_node is the tail of the_chain and + * FALSE otherwise. + */ + +STATIC INLINE boolean _Chain_Is_tail( + Chain_Control *the_chain, + Chain_Node *the_node +) +{ + return ( the_node == _Chain_Tail( the_chain ) ); +} + +/*PAGE + * + * Chain_Initialize_empty + * + * DESCRIPTION: + * + * This routine initializes the specified chain to contain zero nodes. + */ + +STATIC INLINE void _Chain_Initialize_empty( + Chain_Control *the_chain +) +{ + the_chain->first = _Chain_Tail( the_chain ); + the_chain->permanent_null = NULL; + the_chain->last = _Chain_Head( the_chain ); +} + +/*PAGE + * + * _Chain_Extract_unprotected + * + * DESCRIPTION: + * + * This routine extracts the_node from the chain on which it resides. + * It does NOT disable interrupts to insure the atomicity of the + * extract operation. + */ + +STATIC INLINE void _Chain_Extract_unprotected( + Chain_Node *the_node +) +{ + Chain_Node *next; + Chain_Node *previous; + + next = the_node->next; + previous = the_node->previous; + next->previous = previous; + previous->next = next; +} + +/*PAGE + * + * _Chain_Get_first_unprotected + * + * DESCRIPTION: + * + * This function removes the first node from the_chain and returns + * a pointer to that node. It does NOT disable interrupts to insure + * the atomicity of the get operation. + */ + +STATIC INLINE Chain_Node *_Chain_Get_first_unprotected( + Chain_Control *the_chain +) +{ + Chain_Node *return_node; + Chain_Node *new_first; + + return_node = the_chain->first; + new_first = return_node->next; + the_chain->first = new_first; + new_first->previous = _Chain_Head( the_chain ); + + return return_node; +} + +/*PAGE + * + * Chain_Get_unprotected + * + * DESCRIPTION: + * + * This function removes the first node from the_chain and returns + * a pointer to that node. If the_chain is empty, then NULL is returned. + * It does NOT disable interrupts to insure the atomicity of the + * get operation. + */ + +STATIC INLINE Chain_Node *_Chain_Get_unprotected( + Chain_Control *the_chain +) +{ + if ( !_Chain_Is_empty( the_chain ) ) + return _Chain_Get_first_unprotected( the_chain ); + else + return NULL; +} + +/*PAGE + * + * _Chain_Insert_unprotected + * + * DESCRIPTION: + * + * This routine inserts the_node on a chain immediately following + * after_node. It does NOT disable interrupts to insure the atomicity + * of the extract operation. + */ + +STATIC INLINE void _Chain_Insert_unprotected( + Chain_Node *after_node, + Chain_Node *the_node +) +{ + Chain_Node *before_node; + + the_node->previous = after_node; + before_node = after_node->next; + after_node->next = the_node; + the_node->next = before_node; + before_node->previous = the_node; +} + +/*PAGE + * + * _Chain_Append_unprotected + * + * DESCRIPTION: + * + * This routine appends the_node onto the end of the_chain. + * It does NOT disable interrupts to insure the atomicity of the + * append operation. + */ + +STATIC INLINE void _Chain_Append_unprotected( + Chain_Control *the_chain, + Chain_Node *the_node +) +{ + Chain_Node *old_last_node; + + the_node->next = _Chain_Tail( the_chain ); + old_last_node = the_chain->last; + the_chain->last = the_node; + old_last_node->next = the_node; + the_node->previous = old_last_node; +} + +/*PAGE + * + * _Chain_Prepend_unprotected + * + * DESCRIPTION: + * + * This routine prepends the_node onto the front of the_chain. + * It does NOT disable interrupts to insure the atomicity of the + * prepend operation. + */ + +STATIC INLINE void _Chain_Prepend_unprotected( + Chain_Control *the_chain, + Chain_Node *the_node +) +{ + _Chain_Insert_unprotected( _Chain_Head( the_chain ), the_node ); + +} + +/*PAGE + * + * _Chain_Prepend + * + * DESCRIPTION: + * + * This routine prepends the_node onto the front of the_chain. + * It disables interrupts to insure the atomicity of the + * prepend operation. + */ + +STATIC INLINE void _Chain_Prepend( + Chain_Control *the_chain, + Chain_Node *the_node +) +{ + _Chain_Insert( _Chain_Head( the_chain ), the_node ); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/coremsg.inl b/cpukit/score/inline/rtems/score/coremsg.inl new file mode 100644 index 0000000000..84e7250aa7 --- /dev/null +++ b/cpukit/score/inline/rtems/score/coremsg.inl @@ -0,0 +1,260 @@ +/* coremsg.inl + * + * This include file contains the static inline implementation of all + * inlined routines in the Core Message 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$ + */ + +#ifndef __CORE_MESSAGE_QUEUE_inl +#define __CORE_MESSAGE_QUEUE_inl + +#include <string.h> /* needed for memcpy */ + +/*PAGE + * + * _CORE_message_queue_Send + * + * DESCRIPTION: + * + * This routine sends a message to the end of the specified message queue. + */ + +STATIC INLINE CORE_message_queue_Status _CORE_message_queue_Send( + CORE_message_queue_Control *the_message_queue, + void *buffer, + unsigned32 size, + Objects_Id id, + CORE_message_queue_API_mp_support_callout api_message_queue_mp_support +) +{ + return _CORE_message_queue_Submit( + the_message_queue, + buffer, + size, + id, + api_message_queue_mp_support, + CORE_MESSAGE_QUEUE_SEND_REQUEST + ); +} + +/*PAGE + * + * _CORE_message_queue_Urgent + * + * DESCRIPTION: + * + * This routine sends a message to the front of the specified message queue. + */ + +STATIC INLINE CORE_message_queue_Status _CORE_message_queue_Urgent( + CORE_message_queue_Control *the_message_queue, + void *buffer, + unsigned32 size, + Objects_Id id, + CORE_message_queue_API_mp_support_callout api_message_queue_mp_support +) +{ + return _CORE_message_queue_Submit( + the_message_queue, + buffer, + size, + id, + api_message_queue_mp_support, + CORE_MESSAGE_QUEUE_URGENT_REQUEST + ); +} + +/*PAGE + * + * _CORE_message_queue_Copy_buffer + * + * DESCRIPTION: + * + * This routine copies the contents of the source message buffer + * to the destination message buffer. + */ + +STATIC INLINE void _CORE_message_queue_Copy_buffer ( + void *source, + void *destination, + unsigned32 size +) +{ + memcpy(destination, source, size); +} + +/*PAGE + * + * _CORE_message_queue_Allocate_message_buffer + * + * DESCRIPTION: + * + * This function allocates a message buffer from the inactive + * message buffer chain. + */ + +STATIC INLINE CORE_message_queue_Buffer_control * +_CORE_message_queue_Allocate_message_buffer ( + CORE_message_queue_Control *the_message_queue +) +{ + return (CORE_message_queue_Buffer_control *) + _Chain_Get( &the_message_queue->Inactive_messages ); +} + +/*PAGE + * + * _CORE_message_queue_Free_message_buffer + * + * DESCRIPTION: + * + * This routine frees a message buffer to the inactive + * message buffer chain. + */ + +STATIC INLINE void _CORE_message_queue_Free_message_buffer ( + CORE_message_queue_Control *the_message_queue, + CORE_message_queue_Buffer_control *the_message +) +{ + _Chain_Append( &the_message_queue->Inactive_messages, &the_message->Node ); +} + +/*PAGE + * + * _CORE_message_queue_Get_pending_message + * + * DESCRIPTION: + * + * This function removes the first message from the_message_queue + * and returns a pointer to it. + */ + +STATIC INLINE + CORE_message_queue_Buffer_control *_CORE_message_queue_Get_pending_message ( + CORE_message_queue_Control *the_message_queue +) +{ + return (CORE_message_queue_Buffer_control *) + _Chain_Get_unprotected( &the_message_queue->Pending_messages ); +} + +/*PAGE + * + * _CORE_message_queue_Is_priority + * + * DESCRIPTION: + * + * This function returns TRUE if the priority attribute is + * enabled in the attribute_set and FALSE otherwise. + */ + +STATIC INLINE boolean _CORE_message_queue_Is_priority( + CORE_message_queue_Attributes *the_attribute +) +{ + return (the_attribute->discipline == CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY); +} + +/*PAGE + * + * _CORE_message_queue_Append + * + * DESCRIPTION: + * + * This routine places the_message at the rear of the outstanding + * messages on the_message_queue. + */ + +STATIC INLINE void _CORE_message_queue_Append ( + CORE_message_queue_Control *the_message_queue, + CORE_message_queue_Buffer_control *the_message +) +{ + _Chain_Append( &the_message_queue->Pending_messages, &the_message->Node ); +} + +/*PAGE + * + * _CORE_message_queue_Prepend + * + * DESCRIPTION: + * + * This routine places the_message at the front of the outstanding + * messages on the_message_queue. + */ + +STATIC INLINE void _CORE_message_queue_Prepend ( + CORE_message_queue_Control *the_message_queue, + CORE_message_queue_Buffer_control *the_message +) +{ + _Chain_Prepend( + &the_message_queue->Pending_messages, + &the_message->Node + ); +} + +/*PAGE + * + * _CORE_message_queue_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_message_queue is TRUE and FALSE otherwise. + */ + +STATIC INLINE boolean _CORE_message_queue_Is_null ( + CORE_message_queue_Control *the_message_queue +) +{ + return ( the_message_queue == NULL ); +} + +/*PAGE + * + * _CORE_message_queue_Is_notify_enabled + * + * DESCRIPTION: + * + * This function returns TRUE if notification is enabled on this message + * queue and FALSE otherwise. + */ + +STATIC INLINE boolean _CORE_message_queue_Is_notify_enabled ( + CORE_message_queue_Control *the_message_queue +) +{ + return (the_message_queue->notify_handler != NULL); +} + +/*PAGE + * + * _CORE_message_queue_Set_notify + * + * DESCRIPTION: + * + * This routine initializes the notification information for the_message_queue. + */ + +STATIC INLINE void _CORE_message_queue_Set_notify ( + CORE_message_queue_Control *the_message_queue, + CORE_message_queue_Notify_Handler the_handler, + void *the_argument +) +{ + the_message_queue->notify_handler = the_handler; + the_message_queue->notify_argument = the_argument; +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/coremutex.inl b/cpukit/score/inline/rtems/score/coremutex.inl new file mode 100644 index 0000000000..537d6f7e5f --- /dev/null +++ b/cpukit/score/inline/rtems/score/coremutex.inl @@ -0,0 +1,124 @@ +/* inline/coremutex.inl + * + * This include file contains all of the inlined routines associated + * with the CORE mutexes. + * + * 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$ + */ + +#ifndef __INLINE_CORE_MUTEX_inl +#define __INLINE_CORE_MUTEX_inl + +/*PAGE + * + * _CORE_mutex_Is_locked + * + * DESCRIPTION: + * + * This routine returns TRUE if the mutex specified is locked and FALSE + * otherwise. + */ + +STATIC INLINE boolean _CORE_mutex_Is_locked( + CORE_mutex_Control *the_mutex +) +{ + return the_mutex->lock == CORE_MUTEX_LOCKED; +} + +/*PAGE + * + * _CORE_mutex_Is_fifo + * + * DESCRIPTION: + * + * This routine returns TRUE if the mutex's wait discipline is FIFO and FALSE + * otherwise. + */ + +STATIC INLINE boolean _CORE_mutex_Is_fifo( + CORE_mutex_Attributes *the_attribute +) +{ + return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_FIFO; +} + +/*PAGE + * + * _CORE_mutex_Is_priority + * + * DESCRIPTION: + * + * This routine returns TRUE if the mutex's wait discipline is PRIORITY and + * FALSE otherwise. + */ + +STATIC INLINE boolean _CORE_mutex_Is_priority( + CORE_mutex_Attributes *the_attribute +) +{ + return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY; +} + +/*PAGE + * + * _CORE_mutex_Is_inherit_priority + * + * DESCRIPTION: + * + * This routine returns TRUE if the mutex's wait discipline is + * INHERIT_PRIORITY and FALSE otherwise. + */ + +STATIC INLINE boolean _CORE_mutex_Is_inherit_priority( + CORE_mutex_Attributes *the_attribute +) +{ + return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT; +} + +/*PAGE + * + * _CORE_mutex_Is_priority_ceiling + * + * DESCRIPTION: + * + * This routine returns TRUE if the mutex's wait discipline is + * PRIORITY_CEILING and FALSE otherwise. + */ + +STATIC INLINE boolean _CORE_mutex_Is_priority_ceiling( + CORE_mutex_Attributes *the_attribute +) +{ + return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING; +} + +/*PAGE + * + * _CORE_mutex_Is_nesting_allowed + * + * DESCRIPTION: + * + * This routine returns TRUE if the mutex allows a task to obtain a + * semaphore more than once and nest. + */ + +STATIC INLINE boolean _CORE_mutex_Is_nesting_allowed( + CORE_mutex_Attributes *the_attribute +) +{ + return the_attribute->allow_nesting == TRUE; + +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/coresem.inl b/cpukit/score/inline/rtems/score/coresem.inl new file mode 100644 index 0000000000..6f82318d10 --- /dev/null +++ b/cpukit/score/inline/rtems/score/coresem.inl @@ -0,0 +1,54 @@ +/* inline/coresem.inl + * + * This include file contains all of the inlined routines associated + * with the CORE semaphore. + * + * 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$ + */ + +#ifndef __INLINE_CORE_SEMAPHORE_inl +#define __INLINE_CORE_SEMAPHORE_inl + +/*PAGE + * + * _CORE_semaphore_Is_priority + * + * DESCRIPTION: + * + * This function returns TRUE if the priority attribute is + * enabled in the attribute_set and FALSE otherwise. + */ + +STATIC INLINE boolean _CORE_semaphore_Is_priority( + CORE_semaphore_Attributes *the_attribute +) +{ + return ( the_attribute->discipline == CORE_SEMAPHORE_DISCIPLINES_PRIORITY ); +} + +/*PAGE + * + * _CORE_semaphore_Get_count + * + * DESCRIPTION: + * + * This routine returns the current count associated with the semaphore. + */ + +STATIC INLINE unsigned32 _CORE_semaphore_Get_count( + CORE_semaphore_Control *the_semaphore +) +{ + return the_semaphore->count; +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/heap.inl b/cpukit/score/inline/rtems/score/heap.inl new file mode 100644 index 0000000000..6b4b1af74e --- /dev/null +++ b/cpukit/score/inline/rtems/score/heap.inl @@ -0,0 +1,274 @@ +/* heap.inl + * + * This file contains the static inline implementation of the inlined + * routines from the heap 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$ + */ + +#ifndef __HEAP_inl +#define __HEAP_inl + +#include <rtems/score/address.h> + +/*PAGE + * + * _Heap_Head + * + * DESCRIPTION: + * + * This function returns the head of the specified heap. + */ + +STATIC INLINE Heap_Block *_Heap_Head ( + Heap_Control *the_heap +) +{ + return (Heap_Block *)&the_heap->start; +} + +/*PAGE + * + * _Heap_Tail + * + * DESCRIPTION: + * + * This function returns the tail of the specified heap. + */ + +STATIC INLINE Heap_Block *_Heap_Tail ( + Heap_Control *the_heap +) +{ + return (Heap_Block *)&the_heap->final; +} + +/*PAGE + * + * _Heap_Previous_block + * + * DESCRIPTION: + * + * This function returns the address of the block which physically + * precedes the_block in memory. + */ + +STATIC INLINE Heap_Block *_Heap_Previous_block ( + Heap_Block *the_block +) +{ + return (Heap_Block *) _Addresses_Subtract_offset( + (void *)the_block, + the_block->back_flag & ~ HEAP_BLOCK_USED + ); +} + +/*PAGE + * + * _Heap_Next_block + * + * DESCRIPTION: + * + * This function returns the address of the block which physically + * follows the_block in memory. + * + * NOTE: Next_block assumes that the block is free. + */ + +STATIC INLINE Heap_Block *_Heap_Next_block ( + Heap_Block *the_block +) +{ + return (Heap_Block *) _Addresses_Add_offset( + (void *)the_block, + the_block->front_flag & ~ HEAP_BLOCK_USED + ); +} + +/*PAGE + * + * _Heap_Block_at + * + * DESCRIPTION: + * + * This function calculates and returns a block's location (address) + * in the heap based upad a base address and an offset. + */ + +STATIC INLINE Heap_Block *_Heap_Block_at( + void *base, + unsigned32 offset +) +{ + return (Heap_Block *) _Addresses_Add_offset( (void *)base, offset ); +} + +/*PAGE + * + * _Heap_User_block_at + * + * DESCRIPTION: + * + * XXX + */ + +STATIC INLINE Heap_Block *_Heap_User_block_at( + void *base +) +{ + unsigned32 offset; + + offset = *(((unsigned32 *) base) - 1); + return _Heap_Block_at( base, -offset + -HEAP_BLOCK_USED_OVERHEAD); +} + +/*PAGE + * + * _Heap_Is_previous_block_free + * + * DESCRIPTION: + * + * This function returns TRUE if the previous block of the_block + * is free, and FALSE otherwise. + */ + +STATIC INLINE boolean _Heap_Is_previous_block_free ( + Heap_Block *the_block +) +{ + return !(the_block->back_flag & HEAP_BLOCK_USED); +} + +/*PAGE + * + * _Heap_Is_block_free + * + * DESCRIPTION: + * + * This function returns TRUE if the block is free, and FALSE otherwise. + */ + +STATIC INLINE boolean _Heap_Is_block_free ( + Heap_Block *the_block +) +{ + return !(the_block->front_flag & HEAP_BLOCK_USED); +} + +/*PAGE + * + * _Heap_Is_block_used + * + * DESCRIPTION: + * + * This function returns TRUE if the block is currently allocated, + * and FALSE otherwise. + */ + +STATIC INLINE boolean _Heap_Is_block_used ( + Heap_Block *the_block +) +{ + return (the_block->front_flag & HEAP_BLOCK_USED); +} + +/*PAGE + * + * _Heap_Block_size + * + * DESCRIPTION: + * + * This function returns the size of the_block in bytes. + */ + +STATIC INLINE unsigned32 _Heap_Block_size ( + Heap_Block *the_block +) +{ + return (the_block->front_flag & ~HEAP_BLOCK_USED); +} + +/*PAGE + * + * _Heap_Start_of_user_area + * + * DESCRIPTION: + * + * This function returns the starting address of the portion of the block + * which the user may access. + */ + +STATIC INLINE void *_Heap_Start_of_user_area ( + Heap_Block *the_block +) +{ + return (void *) &the_block->next; +} + +/*PAGE + * + * _Heap_Is_block_in + * + * DESCRIPTION: + * + * This function returns TRUE if the_block is within the memory area + * managed by the_heap, and FALSE otherwise. + */ + +STATIC INLINE boolean _Heap_Is_block_in ( + Heap_Control *the_heap, + Heap_Block *the_block +) +{ + return _Addresses_Is_in_range( the_block, the_heap->start, the_heap->final ); +} + +/*PAGE + * + * _Heap_Is_page_size_valid + * + * DESCRIPTION: + * + * This function validates a specified heap page size. If the page size + * is 0 or if lies outside a page size alignment boundary it is invalid + * and FALSE is returned. Otherwise, the page size is valid and TRUE is + * returned. + */ + +STATIC INLINE boolean _Heap_Is_page_size_valid( + unsigned32 page_size +) +{ + return ((page_size != 0) && + ((page_size % CPU_HEAP_ALIGNMENT) == 0)); +} + +/*PAGE + * + * _Heap_Build_flag + * + * DESCRIPTION: + * + * This function returns the block flag composed of size and in_use_flag. + * The flag returned is suitable for use as a back or front flag in a + * heap block. + */ + +STATIC INLINE unsigned32 _Heap_Build_flag ( + unsigned32 size, + unsigned32 in_use_flag +) +{ + return size | in_use_flag; +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/isr.inl b/cpukit/score/inline/rtems/score/isr.inl new file mode 100644 index 0000000000..2dd41315bc --- /dev/null +++ b/cpukit/score/inline/rtems/score/isr.inl @@ -0,0 +1,73 @@ +/* isr.inl + * + * This include file contains the static implementation of all + * inlined routines in the 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$ + */ + +#ifndef __ISR_inl +#define __ISR_inl + +/*PAGE + * + * _ISR_Is_in_progress + * + * DESCRIPTION: + * + * This function returns TRUE if the processor is currently servicing + * and interrupt and FALSE otherwise. A return value of TRUE indicates + * that the caller is an interrupt service routine, NOT a thread. The + * directives available to an interrupt service routine are restricted. + */ + +STATIC INLINE boolean _ISR_Is_in_progress( void ) +{ + return (_ISR_Nest_level != 0); +} + +/*PAGE + * + * _ISR_Is_vector_number_valid + * + * DESCRIPTION: + * + * This function returns TRUE if the vector is a valid vector number + * for this processor and FALSE otherwise. + */ + +STATIC INLINE boolean _ISR_Is_vector_number_valid ( + unsigned32 vector +) +{ + return ( vector <= CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER ); +} + +/*PAGE + * + * _ISR_Is_valid_user_handler + * + * + * DESCRIPTION: + * + * This function returns TRUE if handler is the entry point of a valid + * use interrupt service routine and FALSE otherwise. + */ + +STATIC INLINE boolean _ISR_Is_valid_user_handler ( + void *handler +) +{ + return ( handler != NULL); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/mppkt.inl b/cpukit/score/inline/rtems/score/mppkt.inl new file mode 100644 index 0000000000..c8b6ecd117 --- /dev/null +++ b/cpukit/score/inline/rtems/score/mppkt.inl @@ -0,0 +1,58 @@ +/* inline/mppkt.inl + * + * This package is the implementation of the Packet Handler + * routines which are inlined. + * + * 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$ + */ + +#ifndef __INLINE_MP_PACKET_inl +#define __INLINE_MP_PACKET_inl + +/*PAGE + * + * _Mp_packet_Is_valid_packet_class + * + * DESCRIPTION: + * + * This function returns TRUE if the the_packet_class is valid, + * and FALSE otherwise. + * + * NOTE: Check for lower bounds (MP_PACKET_CLASSES_FIRST ) is unnecessary + * because this enum starts at lower bound of zero. + */ + +STATIC INLINE boolean _Mp_packet_Is_valid_packet_class ( + MP_packet_Classes the_packet_class +) +{ + return ( the_packet_class <= MP_PACKET_CLASSES_LAST ); +} + +/*PAGE + * + * _Mp_packet_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the the_packet_class is null, + * and FALSE otherwise. + */ + +STATIC INLINE boolean _Mp_packet_Is_null ( + MP_packet_Prefix *the_packet +) +{ + return the_packet == NULL; +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/object.inl b/cpukit/score/inline/rtems/score/object.inl new file mode 100644 index 0000000000..249814bacf --- /dev/null +++ b/cpukit/score/inline/rtems/score/object.inl @@ -0,0 +1,244 @@ +/* object.inl + * + * This include file contains the static inline implementation of all + * of the inlined routines in the Object 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$ + */ + +#ifndef __OBJECTS_inl +#define __OBJECTS_inl + +/*PAGE + * + * _Objects_Build_id + * + * DESCRIPTION: + * + * This function builds an object's id from the processor node and index + * values specified. + */ + +STATIC INLINE Objects_Id _Objects_Build_id( + Objects_Classes the_class, + unsigned32 node, + unsigned32 index +) +{ + return ( (the_class << OBJECTS_CLASS_START_BIT) | + (node << OBJECTS_NODE_START_BIT) | + (index << OBJECTS_INDEX_START_BIT) ); +} + +/*PAGE + * + * _Objects_Get_class + * + * DESCRIPTION: + * + * This function returns the class portion of the ID. + */ + +STATIC INLINE Objects_Classes _Objects_Get_class( + Objects_Id id +) +{ + return (Objects_Classes) + ((id >> OBJECTS_CLASS_START_BIT) & OBJECTS_CLASS_VALID_BITS); +} + + +/*PAGE + * + * _Objects_Get_node + * + * DESCRIPTION: + * + * This function returns the node portion of the ID. + */ + +STATIC INLINE unsigned32 _Objects_Get_node( + Objects_Id id +) +{ + return (id >> OBJECTS_NODE_START_BIT) & OBJECTS_NODE_VALID_BITS; +} + +/*PAGE + * + * _Objects_Get_index + * + * DESCRIPTION: + * + * This function returns the index portion of the ID. + */ + +STATIC INLINE unsigned32 _Objects_Get_index( + Objects_Id id +) +{ + return (id >> OBJECTS_INDEX_START_BIT) & OBJECTS_INDEX_VALID_BITS; +} + +/*PAGE + * + * _Objects_Is_class_valid + * + * DESCRIPTION: + * + * This function returns TRUE if the class is valid. + */ + +STATIC INLINE boolean _Objects_Is_class_valid( + Objects_Classes the_class +) +{ + return the_class <= OBJECTS_CLASSES_LAST; +} + +/*PAGE + * + * _Objects_Is_local_node + * + * DESCRIPTION: + * + * This function returns TRUE if the node is of the local object, and + * FALSE otherwise. + */ + +STATIC INLINE boolean _Objects_Is_local_node( + unsigned32 node +) +{ + return ( node == _Objects_Local_node ); +} + +/*PAGE + * + * _Objects_Is_local_id + * + * DESCRIPTION: + * + * This function returns TRUE if the id is of a local object, and + * FALSE otherwise. + */ + +STATIC INLINE boolean _Objects_Is_local_id( + Objects_Id id +) +{ + return _Objects_Is_local_node( _Objects_Get_node(id) ); +} + +/*PAGE + * + * _Objects_Are_ids_equal + * + * DESCRIPTION: + * + * This function returns TRUE if left and right are equal, + * and FALSE otherwise. + */ + +STATIC INLINE boolean _Objects_Are_ids_equal( + Objects_Id left, + Objects_Id right +) +{ + return ( left == right ); +} + +/*PAGE + * + * _Objects_Allocate + * + * DESCRIPTION: + * + * This function allocates a object control block from + * the inactive chain of free object control blocks. + */ + +STATIC INLINE Objects_Control *_Objects_Allocate( + Objects_Information *information +) +{ + return (Objects_Control *) _Chain_Get( &information->Inactive ); +} + +/*PAGE + * + * _Objects_Free + * + * DESCRIPTION: + * + * This function frees a object control block to the + * inactive chain of free object control blocks. + */ + +STATIC INLINE void _Objects_Free( + Objects_Information *information, + Objects_Control *the_object +) +{ + _Chain_Append( &information->Inactive, &the_object->Node ); +} + +/*PAGE + * + * _Objects_Open + * + * DESCRIPTION: + * + * This function places the_object control pointer and object name + * in the Local Pointer and Local Name Tables, respectively. + */ + +STATIC INLINE void _Objects_Open( + Objects_Information *information, + Objects_Control *the_object, + Objects_Name name +) +{ + unsigned32 index; + + index = _Objects_Get_index( the_object->id ); + information->local_table[ index ] = the_object; + + if ( information->is_string ) + _Objects_Copy_name_string( name, the_object->name ); + else + _Objects_Copy_name_raw( name, the_object->name, information->name_length ); +} + +/*PAGE + * + * _Objects_Close + * + * DESCRIPTION: + * + * This function removes the_object control pointer and object name + * in the Local Pointer and Local Name Tables. + */ + +STATIC INLINE void _Objects_Close( + Objects_Information *information, + Objects_Control *the_object +) +{ + unsigned32 index; + + index = _Objects_Get_index( the_object->id ); + information->local_table[ index ] = NULL; + _Objects_Clear_name( the_object->name, information->name_length ); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/objectmp.inl b/cpukit/score/inline/rtems/score/objectmp.inl new file mode 100644 index 0000000000..dda2799643 --- /dev/null +++ b/cpukit/score/inline/rtems/score/objectmp.inl @@ -0,0 +1,73 @@ +/* inline/objectmp.inl + * + * This include file contains the bodies of all inlined routines + * which deal with global objects. + * + * 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$ + */ + +#ifndef __INLINE_MP_OBJECTS_inl +#define __INLINE_MP_OBJECTS_inl + +/*PAGE + * + * _Objects_MP_Allocate_global_object + * + * DESCRIPTION: + * + * This function allocates a Global Object control block. + */ + +STATIC INLINE Objects_MP_Control *_Objects_MP_Allocate_global_object ( + void +) +{ + return (Objects_MP_Control *) + _Chain_Get( &_Objects_MP_Inactive_global_objects ); +} + +/*PAGE + * + * _Objects_MP_Free_global_object + * + * DESCRIPTION: + * + * This routine deallocates a Global Object control block. + */ + +STATIC INLINE void _Objects_MP_Free_global_object ( + Objects_MP_Control *the_object +) +{ + _Chain_Append( + &_Objects_MP_Inactive_global_objects, + &the_object->Object.Node + ); +} + +/*PAGE + * + * _Objects_MP_Is_null_global_object + * + * DESCRIPTION: + * + * This function returns whether the global object is NULL or not. + */ + +STATIC INLINE boolean _Objects_MP_Is_null_global_object ( + Objects_MP_Control *the_object +) +{ + return( the_object == NULL ); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/priority.inl b/cpukit/score/inline/rtems/score/priority.inl new file mode 100644 index 0000000000..d65056057b --- /dev/null +++ b/cpukit/score/inline/rtems/score/priority.inl @@ -0,0 +1,247 @@ +/* priority.inl + * + * This file contains the static inline implementation of all inlined + * routines in the Priority 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$ + */ + +#ifndef __PRIORITY_inl +#define __PRIORITY_inl + +#include <rtems/score/bitfield.h> + +/*PAGE + * + * _Priority_Handler_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this handler. + */ + +STATIC INLINE void _Priority_Handler_initialization( void ) +{ + unsigned32 index; + + _Priority_Major_bit_map = 0; + for ( index=0 ; index <16 ; index++ ) + _Priority_Bit_map[ index ] = 0; +} + +/*PAGE + * + * _Priority_Is_valid + * + * DESCRIPTION: + * + * This function returns TRUE if the_priority if valid for a + * user task, and FALSE otherwise. + */ + +STATIC INLINE boolean _Priority_Is_valid ( + Priority_Control the_priority +) +{ + /* + * Since PRIORITY_MINIMUM is 0 and priorities are stored unsigned, + * then checking for less than 0 is unnecessary. + */ + + return ( the_priority <= PRIORITY_MAXIMUM ); +} + +/*PAGE + * + * _Priority_Major + * + * DESCRIPTION: + * + * This function returns the major portion of the_priority. + */ + +STATIC INLINE unsigned32 _Priority_Major ( + Priority_Control the_priority +) +{ + return ( the_priority / 16 ); +} + +/*PAGE + * + * _Priority_Minor + * + * DESCRIPTION: + * + * This function returns the minor portion of the_priority. + */ + +STATIC INLINE unsigned32 _Priority_Minor ( + Priority_Control the_priority +) +{ + return ( the_priority % 16 ); +} + +#if ( CPU_USE_GENERIC_BITFIELD_CODE == TRUE ) + +/*PAGE + * + * _Priority_Mask + * + * DESCRIPTION: + * + * This function returns the mask associated with the major or minor + * number passed to it. + */ + +STATIC INLINE unsigned32 _Priority_Mask ( + unsigned32 bit_number +) +{ + return (0x8000 >> bit_number); +} + + +/*PAGE + * + * _Priority_Bits_index + * + * DESCRIPTION: + * + * This function translates the bit numbers returned by the bit scan + * of a priority bit field into something suitable for use as + * a major or minor component of a priority. + */ + +STATIC INLINE unsigned32 _Priority_Bits_index ( + unsigned32 bit_number +) +{ + return bit_number; +} + +#endif + +/*PAGE + * + * _Priority_Add_to_bit_map + * + * DESCRIPTION: + * + * This routine uses the_priority_map to update the priority + * bit maps to indicate that a thread has been readied. + */ + +STATIC INLINE void _Priority_Add_to_bit_map ( + Priority_Information *the_priority_map +) +{ + *the_priority_map->minor |= the_priority_map->ready_minor; + _Priority_Major_bit_map |= the_priority_map->ready_major; +} + +/*PAGE + * + * _Priority_Remove_from_bit_map + * + * DESCRIPTION: + * + * This routine uses the_priority_map to update the priority + * bit maps to indicate that a thread has been removed from the + * ready state. + */ + +STATIC INLINE void _Priority_Remove_from_bit_map ( + Priority_Information *the_priority_map +) +{ + *the_priority_map->minor &= the_priority_map->block_minor; + if ( *the_priority_map->minor == 0 ) + _Priority_Major_bit_map &= the_priority_map->block_major; +} + +/*PAGE + * + * _Priority_Get_highest + * + * DESCRIPTION: + * + * This function returns the priority of the highest priority + * ready thread. + */ + +STATIC INLINE Priority_Control _Priority_Get_highest( void ) +{ + Priority_Bit_map_control minor; + Priority_Bit_map_control major; + + _Bitfield_Find_first_bit( _Priority_Major_bit_map, major ); + _Bitfield_Find_first_bit( _Priority_Bit_map[major], minor ); + + return (_Priority_Bits_index( major ) << 4) + + _Priority_Bits_index( minor ); +} + +/*PAGE + * + * _Priority_Initialize_information + * + * DESCRIPTION: + * + * This routine initializes the_priority_map so that it + * contains the information necessary to manage a thread + * at new_priority. + */ + +STATIC INLINE void _Priority_Initialize_information( + Priority_Information *the_priority_map, + Priority_Control new_priority +) +{ + Priority_Bit_map_control major; + Priority_Bit_map_control minor; + Priority_Bit_map_control mask; + + major = _Priority_Major( new_priority ); + minor = _Priority_Minor( new_priority ); + + the_priority_map->minor = + &_Priority_Bit_map[ _Priority_Bits_index(major) ]; + + mask = _Priority_Mask( major ); + the_priority_map->ready_major = mask; + the_priority_map->block_major = ~mask; + + mask = _Priority_Mask( minor ); + the_priority_map->ready_minor = mask; + the_priority_map->block_minor = ~mask; +} + +/*PAGE + * + * _Priority_Is_group_empty + * + * DESCRIPTION: + * + * This function returns TRUE if the priority GROUP is empty, and + * FALSE otherwise. + */ + +STATIC INLINE boolean _Priority_Is_group_empty ( + Priority_Control the_priority +) +{ + return the_priority == 0; +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/stack.inl b/cpukit/score/inline/rtems/score/stack.inl new file mode 100644 index 0000000000..d29874a7dd --- /dev/null +++ b/cpukit/score/inline/rtems/score/stack.inl @@ -0,0 +1,81 @@ +/* stack.inl + * + * This file contains the static inline implementation of the inlined + * routines from the Stack 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$ + */ + +#ifndef __STACK_inl +#define __STACK_inl + +/*PAGE + * + * _Stack_Initialize + * + * DESCRIPTION: + * + * This routine initializes the_stack record to indicate that + * size bytes of memory starting at starting_address have been + * reserved for a stack. + */ + +STATIC INLINE void _Stack_Initialize ( + Stack_Control *the_stack, + void *starting_address, + unsigned32 size +) +{ + the_stack->area = starting_address; + the_stack->size = size; +} + +/*PAGE + * + * _Stack_Is_enough + * + * DESCRIPTION: + * + * This function returns TRUE if size bytes is enough memory for + * a valid stack area on this processor, and FALSE otherwise. + */ + +STATIC INLINE boolean _Stack_Is_enough ( + unsigned32 size +) +{ + return ( size >= STACK_MINIMUM_SIZE ); +} + +/*PAGE + * + * _Stack_Adjust_size + * + * DESCRIPTION: + * + * This function increases the stack size to insure that the thread + * has the desired amount of stack space after the initial stack + * pointer is determined based on alignment restrictions. + * + * NOTE: + * + * The amount of adjustment for alignment is CPU dependent. + */ + +STATIC INLINE unsigned32 _Stack_Adjust_size ( + unsigned32 size +) +{ + return size + CPU_STACK_ALIGNMENT; +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/states.inl b/cpukit/score/inline/rtems/score/states.inl new file mode 100644 index 0000000000..fad8ce727c --- /dev/null +++ b/cpukit/score/inline/rtems/score/states.inl @@ -0,0 +1,384 @@ +/* states.inl + * + * This file contains the macro implementation of the inlined + * routines associated with thread state information. + * + * 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$ + */ + +#ifndef __STATES_inl +#define __STATES_inl + +/*PAGE + * + * _States_Set + * + * DESCRIPTION: + * + * This function sets the given states_to_set into the current_state + * passed in. The result is returned to the user in current_state. + */ + +STATIC INLINE States_Control _States_Set ( + States_Control states_to_set, + States_Control current_state +) +{ + return (current_state | states_to_set); +} + +/*PAGE + * + * _States_Clear + * + * DESCRIPTION: + * + * This function clears the given states_to_clear into the current_state + * passed in. The result is returned to the user in current_state. + */ + +STATIC INLINE States_Control _States_Clear ( + States_Control states_to_clear, + States_Control current_state +) +{ + return (current_state & ~states_to_clear); +} + +/*PAGE + * + * _States_Is_ready + * + * DESCRIPTION: + * + * This function returns TRUE if the_states indicates that the + * state is READY, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_ready ( + States_Control the_states +) +{ + return (the_states == STATES_READY); +} + +/*PAGE + * + * _States_Is_only_dormant + * + * DESCRIPTION: + * + * This function returns TRUE if the DORMANT state is the ONLY state + * set in the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_only_dormant ( + States_Control the_states +) +{ + return (the_states == STATES_DORMANT); +} + +/*PAGE + * + * _States_Is_dormant + * + * DESCRIPTION: + * + * This function returns TRUE if the DORMANT state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_dormant ( + States_Control the_states +) +{ + return (the_states & STATES_DORMANT); +} + +/*PAGE + * + * _States_Is_suspended + * + * DESCRIPTION: + * + * This function returns TRUE if the SUSPENDED state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_suspended ( + States_Control the_states +) +{ + return (the_states & STATES_SUSPENDED); +} + +/*PAGE + * + * _States_Is_Transient + * + * DESCRIPTION: + * + * This function returns TRUE if the TRANSIENT state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_transient ( + States_Control the_states +) +{ + return (the_states & STATES_TRANSIENT); +} + +/*PAGE + * + * _States_Is_delaying + * + * DESCRIPTION: + * + * This function returns TRUE if the DELAYING state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_delaying ( + States_Control the_states +) +{ + return (the_states & STATES_DELAYING); +} + +/*PAGE + * + * _States_Is_waiting_for_buffer + * + * DESCRIPTION: + * + * This function returns TRUE if the WAITING_FOR_BUFFER state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_waiting_for_buffer ( + States_Control the_states +) +{ + return (the_states & STATES_WAITING_FOR_BUFFER); +} + +/*PAGE + * + * _States_Is_waiting_for_segment + * + * DESCRIPTION: + * + * This function returns TRUE if the WAITING_FOR_SEGMENT state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_waiting_for_segment ( + States_Control the_states +) +{ + return (the_states & STATES_WAITING_FOR_SEGMENT); +} + +/*PAGE + * + * _States_Is_waiting_for_message + * + * DESCRIPTION: + * + * This function returns TRUE if the WAITING_FOR_MESSAGE state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_waiting_for_message ( + States_Control the_states +) +{ + return (the_states & STATES_WAITING_FOR_MESSAGE); +} + +/*PAGE + * + * _States_Is_waiting_for_event + * + * DESCRIPTION: + * + * This function returns TRUE if the WAITING_FOR_EVENT state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_waiting_for_event ( + States_Control the_states +) +{ + return (the_states & STATES_WAITING_FOR_EVENT); +} + +/*PAGE + * + * _States_Is_waiting_for_mutex + * + * DESCRIPTION: + * + * This function returns TRUE if the WAITING_FOR_MUTEX state + * is set in the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_waiting_for_mutex ( + States_Control the_states +) +{ + return (the_states & STATES_WAITING_FOR_MUTEX); +} + +/*PAGE + * + * _States_Is_waiting_for_semaphore + * + * DESCRIPTION: + * + * This function returns TRUE if the WAITING_FOR_SEMAPHORE state + * is set in the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_waiting_for_semaphore ( + States_Control the_states +) +{ + return (the_states & STATES_WAITING_FOR_SEMAPHORE); +} + +/*PAGE + * + * _States_Is_waiting_for_time + * + * DESCRIPTION: + * + * This function returns TRUE if the WAITING_FOR_TIME state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_waiting_for_time ( + States_Control the_states +) +{ + return (the_states & STATES_WAITING_FOR_TIME); +} + +/*PAGE + * + * _States_Is_waiting_for_rpc_reply + * + * DESCRIPTION: + * + * This function returns TRUE if the WAITING_FOR_TIME state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_waiting_for_rpc_reply ( + States_Control the_states +) +{ + return (the_states & STATES_WAITING_FOR_RPC_REPLY); +} + +/*PAGE + * + * _States_Is_waiting_for_period + * + * DESCRIPTION: + * + * This function returns TRUE if the WAITING_FOR_PERIOD state is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_waiting_for_period ( + States_Control the_states +) +{ + return (the_states & STATES_WAITING_FOR_PERIOD); +} + +/*PAGE + * + * _States_Is_locally_blocked + * + * DESCRIPTION: + * + * This function returns TRUE if one of the states which indicates + * that a task is blocked waiting for a local resource is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_locally_blocked ( + States_Control the_states +) +{ + return (the_states & STATES_LOCALLY_BLOCKED); +} + +/*PAGE + * + * _States_Is_waiting_on_thread_queue + * + * DESCRIPTION: + * + * This function returns TRUE if one of the states which indicates + * that a task is blocked waiting for a local resource is set in + * the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_waiting_on_thread_queue ( + States_Control the_states +) +{ + return (the_states & STATES_WAITING_ON_THREAD_QUEUE); +} + +/*PAGE + * + * _States_Is_blocked + * + * DESCRIPTION: + * + * This function returns TRUE if one of the states which indicates + * that a task is blocked is set in the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Is_blocked ( + States_Control the_states +) +{ + return (the_states & STATES_BLOCKED); +} + +/*PAGE + * + * + * _States_Are_set + * + * DESCRIPTION: + * + * This function returns TRUE if any of the states in the mask + * are set in the_states, and FALSE otherwise. + */ + +STATIC INLINE boolean _States_Are_set ( + States_Control the_states, + States_Control mask +) +{ + return ( (the_states & mask) != STATES_READY); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/sysstate.inl b/cpukit/score/inline/rtems/score/sysstate.inl new file mode 100644 index 0000000000..08f8b9c513 --- /dev/null +++ b/cpukit/score/inline/rtems/score/sysstate.inl @@ -0,0 +1,154 @@ +/* sysstates.inl + * + * This file contains the inline implementation of routines regarding the + * system state. + * + * 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$ + */ + +#ifndef __SYSTEM_STATE_inl +#define __SYSTEM_STATE_inl + +/*PAGE + * + * _System_state_Handler_initialization + * + * DESCRIPTION: + * + * This routine initializes the system state handler. + */ + +STATIC INLINE void _System_state_Handler_initialization ( + boolean is_multiprocessing +) +{ + _System_state_Current = SYSTEM_STATE_BEFORE_INITIALIZATION; + _System_state_Is_multiprocessing = is_multiprocessing; +} + +/*PAGE + * + * _System_state_Set + * + * DESCRIPTION: + * + * This routine sets the current system state to that specified by + * the called. + */ + +STATIC INLINE void _System_state_Set ( + System_state_Codes state +) +{ + _System_state_Current = state; +} + +/*PAGE + * + * _System_state_Get + * + * DESCRIPTION: + * + * This function returns the current system state. + */ + +STATIC INLINE System_state_Codes _System_state_Get ( void ) +{ + return _System_state_Current; +} + +/*PAGE + * + * _System_state_Is_before_initialization + * + * DESCRIPTION: + * + * This function returns TRUE if the state is equal to the + * "before initialization" state, and FALSE otherwise. + */ + +STATIC INLINE boolean _System_state_Is_before_initialization ( + System_state_Codes state +) +{ + return (state == SYSTEM_STATE_BEFORE_INITIALIZATION); +} + +/*PAGE + * + * _System_state_Is_before_multitasking + * + * DESCRIPTION: + * + * This function returns TRUE if the state is equal to the + * "before multitasking" state, and FALSE otherwise. + */ + +STATIC INLINE boolean _System_state_Is_before_multitasking ( + System_state_Codes state +) +{ + return (state == SYSTEM_STATE_BEFORE_MULTITASKING); +} + +/*PAGE + * + * _System_state_Is_begin_multitasking + * + * DESCRIPTION: + * + * This function returns TRUE if the state is equal to the + * "begin multitasking" state, and FALSE otherwise. + */ + +STATIC INLINE boolean _System_state_Is_begin_multitasking ( + System_state_Codes state +) +{ + return (state == SYSTEM_STATE_BEGIN_MULTITASKING); +} + +/*PAGE + * + * _System_state_Is_up + * + * DESCRIPTION: + * + * This function returns TRUE if the state is equal to the + * "up" state, and FALSE otherwise. + */ + +STATIC INLINE boolean _System_state_Is_up ( + System_state_Codes state +) +{ + return (state == SYSTEM_STATE_UP); +} + +/*PAGE + * + * _System_state_Is_failed + * + * DESCRIPTION: + * + * This function returns TRUE if the state is equal to the + * "failed" state, and FALSE otherwise. + */ + +STATIC INLINE boolean _System_state_Is_failed ( + System_state_Codes state +) +{ + return (state == SYSTEM_STATE_FAILED); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/thread.inl b/cpukit/score/inline/rtems/score/thread.inl new file mode 100644 index 0000000000..53d5d41751 --- /dev/null +++ b/cpukit/score/inline/rtems/score/thread.inl @@ -0,0 +1,404 @@ +/* thread.inl + * + * This file contains the macro implementation of the inlined + * routines from the Thread 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$ + */ + +#ifndef __THREAD_inl +#define __THREAD_inl + +/*PAGE + * + * _Thread_Stop_multitasking + * + * DESCRIPTION: + * + * This routine halts multitasking and returns control to + * the "thread" (i.e. the BSP) which initially invoked the + * routine which initialized the system. + */ + +STATIC INLINE void _Thread_Stop_multitasking( void ) +{ + _Context_Switch( &_Thread_Executing->Registers, &_Thread_BSP_context ); +} + +/*PAGE + * + * _Thread_Is_executing + * + * DESCRIPTION: + * + * This function returns TRUE if the_thread is the currently executing + * thread, and FALSE otherwise. + */ + +STATIC INLINE boolean _Thread_Is_executing ( + Thread_Control *the_thread +) +{ + return ( the_thread == _Thread_Executing ); +} + +/*PAGE + * + * _Thread_Is_heir + * + * DESCRIPTION: + * + * This function returns TRUE if the_thread is the heir + * thread, and FALSE otherwise. + */ + +STATIC INLINE boolean _Thread_Is_heir ( + Thread_Control *the_thread +) +{ + return ( the_thread == _Thread_Heir ); +} + +/*PAGE + * + * _Thread_Is_executing_also_the_heir + * + * DESCRIPTION: + * + * This function returns TRUE if the currently executing thread + * is also the heir thread, and FALSE otherwise. + */ + +STATIC INLINE boolean _Thread_Is_executing_also_the_heir( void ) +{ + return ( _Thread_Executing == _Thread_Heir ); +} + +/*PAGE + * + * _Thread_Resume + * + * DESCRIPTION: + * + * This routine clears the SUSPENDED state for the_thread. It performs + * any necessary scheduling operations including the selection of + * a new heir thread. + */ + +STATIC INLINE void _Thread_Resume ( + Thread_Control *the_thread +) +{ + _Thread_Clear_state( the_thread, STATES_SUSPENDED ); +} + +/*PAGE + * + * _Thread_Unblock + * + * DESCRIPTION: + * + * This routine clears any blocking state for the_thread. It performs + * any necessary scheduling operations including the selection of + * a new heir thread. + */ + +STATIC INLINE void _Thread_Unblock ( + Thread_Control *the_thread +) +{ + _Thread_Clear_state( the_thread, STATES_BLOCKED ); +} + +/*PAGE + * + * _Thread_Restart_self + * + * DESCRIPTION: + * + * This routine resets the current context of the calling thread + * to that of its initial state. + */ + +STATIC INLINE void _Thread_Restart_self( void ) +{ + if ( _Thread_Executing->fp_context != NULL ) + _Context_Restore_fp( &_Thread_Executing->fp_context ); + + _CPU_Context_Restart_self( &_Thread_Executing->Registers ); +} + +/*PAGE + * + * _Thread_Calculate_heir + * + * DESCRIPTION: + * + * This function returns a pointer to the highest priority + * ready thread. + */ + +STATIC INLINE void _Thread_Calculate_heir( void ) +{ + _Thread_Heir = (Thread_Control *) + _Thread_Ready_chain[ _Priority_Get_highest() ].first; +} + +/*PAGE + * + * _Thread_Is_allocated_fp + * + * DESCRIPTION: + * + * This function returns TRUE if the floating point context of + * the_thread is currently loaded in the floating point unit, and + * FALSE otherwise. + */ + +STATIC INLINE boolean _Thread_Is_allocated_fp ( + Thread_Control *the_thread +) +{ + return ( the_thread == _Thread_Allocated_fp ); +} + +/*PAGE + * + * _Thread_Deallocate_fp + * + * DESCRIPTION: + * + * This routine is invoked when the currently loaded floating + * point context is now longer associated with an active thread. + */ + +STATIC INLINE void _Thread_Deallocate_fp( void ) +{ + _Thread_Allocated_fp = NULL; +} + +/*PAGE + * + * _Thread_Disable_dispatch + * + * DESCRIPTION: + * + * This routine prevents dispatching. + */ + +STATIC INLINE void _Thread_Disable_dispatch( void ) +{ + _Thread_Dispatch_disable_level += 1; +} + +/*PAGE + * + * _Thread_Enable_dispatch + * + * DESCRIPTION: + * + * This routine allows dispatching to occur again. If this is + * the outer most dispatching critical section, then a dispatching + * operation will be performed and, if necessary, control of the + * processor will be transferred to the heir thread. + */ + +#if ( CPU_INLINE_ENABLE_DISPATCH == TRUE ) +STATIC INLINE void _Thread_Enable_dispatch() +{ + if ( (--_Thread_Dispatch_disable_level) == 0 ) + _Thread_Dispatch(); +} +#endif + +#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE ) +void _Thread_Enable_dispatch( void ); +#endif + +/*PAGE + * + * _Thread_Unnest_dispatch + * + * DESCRIPTION: + * + * This routine allows dispatching to occur again. However, + * no dispatching operation is performed even if this is the outer + * most dispatching critical section. + */ + +STATIC INLINE void _Thread_Unnest_dispatch( void ) +{ + _Thread_Dispatch_disable_level -= 1; +} + +/*PAGE + * + * _Thread_Is_dispatching_enabled + * + * DESCRIPTION: + * + * This function returns TRUE if dispatching is disabled, and FALSE + * otherwise. + */ + +STATIC INLINE boolean _Thread_Is_dispatching_enabled( void ) +{ + return ( _Thread_Dispatch_disable_level == 0 ); +} + +/*PAGE + * + * _Thread_Is_context_switch_necessary + * + * DESCRIPTION: + * + * This function returns TRUE if dispatching is disabled, and FALSE + * otherwise. + */ + +STATIC INLINE boolean _Thread_Is_context_switch_necessary( void ) +{ + return ( _Context_Switch_necessary ); +} + +/*PAGE + * + * _Thread_Dispatch_initialization + * + * DESCRIPTION: + * + * This routine initializes the thread dispatching subsystem. + */ + +STATIC INLINE void _Thread_Dispatch_initialization( void ) +{ + _Thread_Dispatch_disable_level = 1; +} + +/*PAGE + * + * _Thread_Is_null + * + * DESCRIPTION: + * + * This function returns TRUE if the_thread is NULL and FALSE otherwise. + */ + +STATIC INLINE boolean _Thread_Is_null ( + Thread_Control *the_thread +) +{ + return ( the_thread == NULL ); +} + +/*PAGE + * + * _Thread_Get + * + * DESCRIPTION: + * + * This function maps thread IDs to thread control + * blocks. If ID corresponds to a local thread, then it + * returns the_thread control pointer which maps to ID + * and location is set to OBJECTS_LOCAL. If the thread ID is + * global and resides on a remote node, then location is set + * to OBJECTS_REMOTE, and the_thread is undefined. + * Otherwise, location is set to OBJECTS_ERROR and + * the_thread is undefined. + * + * NOTE: XXX... This routine may be able to be optimized. + */ + +STATIC INLINE Thread_Control *_Thread_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + Objects_Classes the_class; + Objects_Information *information; + Thread_Control *tp = (Thread_Control *) 0; + + if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) { + _Thread_Disable_dispatch(); + *location = OBJECTS_LOCAL; + tp = _Thread_Executing; + goto done; + } + + the_class = _Objects_Get_class( id ); + + if ( the_class > OBJECTS_CLASSES_LAST ) { + *location = OBJECTS_ERROR; + goto done; + } + + information = _Objects_Information_table[ the_class ]; + + if ( !information || !information->is_thread ) { + *location = OBJECTS_ERROR; + goto done; + } + + tp = (Thread_Control *) _Objects_Get( information, id, location ); + +done: + return tp; +} + + +/* + * _Thread_Is_proxy_blocking + * + * DESCRIPTION: + * + * This function returns TRUE if the status code is equal to the + * status which indicates that a proxy is blocking, and FALSE otherwise. + */ + +STATIC INLINE boolean _Thread_Is_proxy_blocking ( + unsigned32 code +) +{ + return (code == THREAD_STATUS_PROXY_BLOCKING); +} + +/*PAGE + * + * _Thread_Internal_allocate + * + * DESCRIPTION: + * + * This routine allocates an internal thread. + */ + +STATIC INLINE Thread_Control *_Thread_Internal_allocate( void ) +{ + return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information ); +} + +/*PAGE + * + * _Thread_Internal_free + * + * DESCRIPTION: + * + * This routine frees an internal thread. + */ + +STATIC INLINE void _Thread_Internal_free ( + Thread_Control *the_task +) +{ + _Objects_Free( &_Thread_Internal_information, &the_task->Object ); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/threadmp.inl b/cpukit/score/inline/rtems/score/threadmp.inl new file mode 100644 index 0000000000..f16f64e48a --- /dev/null +++ b/cpukit/score/inline/rtems/score/threadmp.inl @@ -0,0 +1,61 @@ +/* inline/threadmp.inl + * + * This include file contains the bodies of all inlined routines + * for the multiprocessing part of thread package. + * + * 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$ + */ + +#ifndef __INLINE_MP_THREAD_inl +#define __INLINE_MP_THREAD_inl + +/*PAGE + * + * _Thread_MP_Is_receive + * + * DESCRIPTION: + * + * This function returns true if the thread in question is the + * multiprocessing receive thread. + */ + +STATIC INLINE boolean _Thread_MP_Is_receive ( + Thread_Control *the_thread +) +{ + return the_thread == _Thread_MP_Receive; +} + +/*PAGE + * + * _Thread_MP_Free_proxy + * + * DESCRIPTION: + * + * This routine frees a proxy control block to the + * inactive chain of free proxy control blocks. + */ + +STATIC INLINE void _Thread_MP_Free_proxy ( + Thread_Control *the_thread +) +{ + Thread_Proxy_control *the_proxy; + + the_proxy = (Thread_Proxy_control *) the_thread; + + _Chain_Extract( &the_proxy->Active ); + + _Chain_Append( &_Thread_MP_Inactive_proxies, &the_thread->Object.Node ); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/tod.inl b/cpukit/score/inline/rtems/score/tod.inl new file mode 100644 index 0000000000..5ed1e76d8f --- /dev/null +++ b/cpukit/score/inline/rtems/score/tod.inl @@ -0,0 +1,82 @@ +/* tod.inl + * + * This file contains the static inline implementation of the inlined routines + * from the Time of Day 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$ + */ + +#ifndef __TIME_OF_DAY_inl +#define __TIME_OF_DAY_inl + +/*PAGE + * + * _TOD_Is_set + * + * DESCRIPTION: + * + * This function returns TRUE if the application has set the current + * time of day, and FALSE otherwise. + */ + +STATIC INLINE boolean _TOD_Is_set( void ) +{ + return _Watchdog_Is_active( &_TOD_Seconds_watchdog ); +} + +/*PAGE + * + * _TOD_Tickle_ticks + * + * DESCRIPTION: + * + * This routine increments the ticks field of the current time of + * day at each clock tick. + */ + +STATIC INLINE void _TOD_Tickle_ticks( void ) +{ + _TOD_Current.ticks += 1; + _TOD_Ticks_since_boot += 1; +} + +/*PAGE + * + * _TOD_Deactivate + * + * DESCRIPTION: + * + * This routine deactivates updating of the current time of day. + */ + +STATIC INLINE void _TOD_Deactivate( void ) +{ + _Watchdog_Remove( &_TOD_Seconds_watchdog ); +} + +/*PAGE + * + * _TOD_Activate + * + * DESCRIPTION: + * + * This routine activates updating of the current time of day. + */ + +STATIC INLINE void _TOD_Activate( + Watchdog_Interval ticks +) +{ + _Watchdog_Insert_ticks( &_TOD_Seconds_watchdog, ticks ); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/tqdata.inl b/cpukit/score/inline/rtems/score/tqdata.inl new file mode 100644 index 0000000000..c7d8630062 --- /dev/null +++ b/cpukit/score/inline/rtems/score/tqdata.inl @@ -0,0 +1,89 @@ +/* tqdata.inl + * + * This file contains the static inline implementation of the inlined + * routines needed to support the Thread Queue Data. + * + * 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$ + */ + +#ifndef __THREAD_QUEUE_DATA_inl +#define __THREAD_QUEUE_DATA_inl + +/*PAGE + * + * _Thread_queue_Header_number + * + * DESCRIPTION: + * + * This function returns the index of the priority chain on which + * a thread of the_priority should be placed. + */ + +STATIC INLINE unsigned32 _Thread_queue_Header_number ( + Priority_Control the_priority +) +{ + return (the_priority / TASK_QUEUE_DATA_PRIORITIES_PER_HEADER); +} + +/*PAGE + * + * _Thread_queue_Is_reverse_search + * + * DESCRIPTION: + * + * This function returns TRUE if the_priority indicates that the + * enqueue search should start at the front of this priority + * group chain, and FALSE if the search should start at the rear. + */ + +STATIC INLINE boolean _Thread_queue_Is_reverse_search ( + Priority_Control the_priority +) +{ + return ( the_priority & TASK_QUEUE_DATA_REVERSE_SEARCH_MASK ); +} + +/*PAGE + * + * _Thread_queue_Get_number_waiting + * + * DESCRIPTION: + * + * This function returns the number of threads waiting on this thread queue. + */ + +STATIC INLINE unsigned32 _Thread_queue_Get_number_waiting ( + Thread_queue_Control *the_thread_queue +) +{ + return ( the_thread_queue->count ); +} + +/*PAGE + * + * _Thread_queue_Enter_critical_section + * + * DESCRIPTION: + * + * This routine is invoked to indicate that the specified thread queue is + * entering a critical section. + */ + +STATIC INLINE void _Thread_queue_Enter_critical_section ( + Thread_queue_Control *the_thread_queue +) +{ + the_thread_queue->sync_state = THREAD_QUEUE_NOTHING_HAPPENED; +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/userext.inl b/cpukit/score/inline/rtems/score/userext.inl new file mode 100644 index 0000000000..a9a858b2e2 --- /dev/null +++ b/cpukit/score/inline/rtems/score/userext.inl @@ -0,0 +1,121 @@ +/* userext.inl + * + * This file contains the macro implementation of the inlined routines + * from the User Extension 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$ + */ + +#ifndef __USER_EXTENSIONS_inl +#define __USER_EXTENSIONS_inl + +/*PAGE + * + * _User_extensions_Handler_initialization + * + * DESCRIPTION: + * + * This routine performs the initialization necessary for this handler. + */ + +STATIC INLINE void _User_extensions_Handler_initialization ( + User_extensions_Table *initial_extensions +) +{ + _Chain_Initialize_empty( &_User_extensions_List ); + + if ( initial_extensions ) { + _User_extensions_Initial.Callouts = *initial_extensions; + _Chain_Append( &_User_extensions_List, &_User_extensions_Initial.Node ); + } +} + +/*PAGE + * + * _User_extensions_Add_set + * + * DESCRIPTION: + * + * This routine is used to add a user extension set to the active list. + */ + +STATIC INLINE void _User_extensions_Add_set ( + User_extensions_Control *the_extension, + User_extensions_Table *extension_table +) +{ + the_extension->Callouts = *extension_table; + + _Chain_Append( &_User_extensions_List, &the_extension->Node ); +} + +/*PAGE + * + * _User_extensions_Add_API_set + * DESCRIPTION: + * + * This routine is used to add an API extension set to the active list. + */ + +STATIC INLINE void _User_extensions_Add_API_set ( + User_extensions_Control *the_extension +) +{ + _Chain_Prepend( &_User_extensions_List, &the_extension->Node ); +} + +/*PAGE + * + * _User_extensions_Remove_set + * + * DESCRIPTION: + * + * This routine is used to remove a user extension set from the active list. + */ + +STATIC INLINE void _User_extensions_Remove_set ( + User_extensions_Control *the_extension +) +{ + _Chain_Extract( &the_extension->Node ); +} + +/*PAGE + * + * _User_extensions_Thread_switch + * + * DESCRIPTION: + * + * This routine is used to invoke the user extension which + * is invoked when a context switch occurs. + */ + +STATIC INLINE void _User_extensions_Thread_switch ( + Thread_Control *executing, + Thread_Control *heir +) +{ + Chain_Node *the_node; + User_extensions_Control *the_extension; + + for ( the_node = _User_extensions_List.first ; + !_Chain_Is_tail( &_User_extensions_List, the_node ) ; + the_node = the_node->next ) { + + the_extension = (User_extensions_Control *) the_node; + + if ( the_extension->Callouts.thread_switch != NULL ) + (*the_extension->Callouts.thread_switch)( executing, heir ); + } +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/watchdog.inl b/cpukit/score/inline/rtems/score/watchdog.inl new file mode 100644 index 0000000000..75fb662dfc --- /dev/null +++ b/cpukit/score/inline/rtems/score/watchdog.inl @@ -0,0 +1,324 @@ +/* watchdog.inl + * + * This file contains the static inline implementation of all inlined + * routines in the Watchdog 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$ + */ + +#ifndef __WATCHDOG_inl +#define __WATCHDOG_inl + +/*PAGE + * + * _Watchdog_Initialize + * + * DESCRIPTION: + * + * This routine initializes the specified watchdog. The watchdog is + * made inactive, the watchdog id and handler routine are set to the + * specified values. + */ + +STATIC INLINE void _Watchdog_Initialize( + Watchdog_Control *the_watchdog, + Watchdog_Service_routine_entry routine, + Objects_Id id, + void *user_data +) +{ + the_watchdog->state = WATCHDOG_INACTIVE; + the_watchdog->routine = routine; + the_watchdog->id = id; + the_watchdog->user_data = user_data; +} + +/*PAGE + * + * _Watchdog_Is_active + * + * DESCRIPTION: + * + * This routine returns TRUE if the watchdog timer is in the ACTIVE + * state, and FALSE otherwise. + */ + +STATIC INLINE boolean _Watchdog_Is_active( + Watchdog_Control *the_watchdog +) +{ + + return ( the_watchdog->state == WATCHDOG_ACTIVE ); + +} + +/*PAGE + * + * _Watchdog_Activate + * + * DESCRIPTION: + * + * This routine activates THE_WATCHDOG timer which is already + * on a watchdog chain. + */ + +STATIC INLINE void _Watchdog_Activate( + Watchdog_Control *the_watchdog +) +{ + + the_watchdog->state = WATCHDOG_ACTIVE; + +} + +/*PAGE + * + * _Watchdog_Deactivate + * + * DESCRIPTION: + * + * This routine deactivates THE_WATCHDOG timer which will remain + * on a watchdog chain. + */ + +STATIC INLINE void _Watchdog_Deactivate( + Watchdog_Control *the_watchdog +) +{ + + the_watchdog->state = WATCHDOG_REMOVE_IT; + +} + +/*PAGE + * + * _Watchdog_Tickle_ticks + * + * DESCRIPTION: + * + * This routine is invoked at each clock tick to update the ticks + * watchdog chain. + */ + +STATIC INLINE void _Watchdog_Tickle_ticks( void ) +{ + + _Watchdog_Tickle( &_Watchdog_Ticks_chain ); + +} + +/*PAGE + * + * _Watchdog_Tickle_seconds + * + * DESCRIPTION: + * + * This routine is invoked at each clock tick to update the seconds + * watchdog chain. + */ + +STATIC INLINE void _Watchdog_Tickle_seconds( void ) +{ + + _Watchdog_Tickle( &_Watchdog_Seconds_chain ); + +} + +/*PAGE + * + * _Watchdog_Insert_ticks + * + * DESCRIPTION: + * + * This routine inserts THE_WATCHDOG into the ticks watchdog chain + * for a time of UNITS ticks. The INSERT_MODE indicates whether + * THE_WATCHDOG is to be activated automatically or later, explicitly + * by the caller. + */ + +STATIC INLINE void _Watchdog_Insert_ticks( + Watchdog_Control *the_watchdog, + Watchdog_Interval units +) +{ + + the_watchdog->initial = units; + + _Watchdog_Insert( &_Watchdog_Ticks_chain, the_watchdog ); + +} + +/*PAGE + * + * _Watchdog_Insert_seconds + * + * DESCRIPTION: + * + * This routine inserts THE_WATCHDOG into the seconds watchdog chain + * for a time of UNITS seconds. The INSERT_MODE indicates whether + * THE_WATCHDOG is to be activated automatically or later, explicitly + * by the caller. + */ + +STATIC INLINE void _Watchdog_Insert_seconds( + Watchdog_Control *the_watchdog, + Watchdog_Interval units +) +{ + + the_watchdog->initial = units; + + _Watchdog_Insert( &_Watchdog_Seconds_chain, the_watchdog ); + +} + +/*PAGE + * + * _Watchdog_Adjust_seconds + * + * DESCRIPTION: + * + * This routine adjusts the seconds watchdog chain in the forward + * or backward DIRECTION for UNITS seconds. This is invoked when the + * current time of day is changed. + */ + +STATIC INLINE void _Watchdog_Adjust_seconds( + Watchdog_Adjust_directions direction, + Watchdog_Interval units +) +{ + + _Watchdog_Adjust( &_Watchdog_Seconds_chain, direction, units ); + +} + +/*PAGE + * + * _Watchdog_Adjust_ticks + * + * DESCRIPTION: + * + * This routine adjusts the ticks watchdog chain in the forward + * or backward DIRECTION for UNITS ticks. + */ + +STATIC INLINE void _Watchdog_Adjust_ticks( + Watchdog_Adjust_directions direction, + Watchdog_Interval units +) +{ + + _Watchdog_Adjust( &_Watchdog_Ticks_chain, direction, units ); + +} + +/*PAGE + * + * _Watchdog_Reset + * + * DESCRIPTION: + * + * This routine resets THE_WATCHDOG timer to its state at INSERT + * time. This routine is valid only on interval watchdog timers + * and is used to make an interval watchdog timer fire "every" so + * many ticks. + */ + +STATIC INLINE void _Watchdog_Reset( + Watchdog_Control *the_watchdog +) +{ + + (void) _Watchdog_Remove( the_watchdog ); + + _Watchdog_Insert( &_Watchdog_Ticks_chain, the_watchdog ); + +} + +/*PAGE + * + * _Watchdog_Next + * + * DESCRIPTION: + * + * This routine returns a pointer to the watchdog timer following + * THE_WATCHDOG on the watchdog chain. + */ + +STATIC INLINE Watchdog_Control *_Watchdog_Next( + Watchdog_Control *the_watchdog +) +{ + + return ( (Watchdog_Control *) the_watchdog->Node.next ); + +} + +/*PAGE + * + * _Watchdog_Previous + * + * DESCRIPTION: + * + * This routine returns a pointer to the watchdog timer preceding + * THE_WATCHDOG on the watchdog chain. + */ + +STATIC INLINE Watchdog_Control *_Watchdog_Previous( + Watchdog_Control *the_watchdog +) +{ + + return ( (Watchdog_Control *) the_watchdog->Node.previous ); + +} + +/*PAGE + * + * _Watchdog_First + * + * DESCRIPTION: + * + * This routine returns a pointer to the first watchdog timer + * on the watchdog chain HEADER. + */ + +STATIC INLINE Watchdog_Control *_Watchdog_First( + Chain_Control *header +) +{ + + return ( (Watchdog_Control *) header->first ); + +} + +/*PAGE + * + * _Watchdog_Last + * + * DESCRIPTION: + * + * This routine returns a pointer to the last watchdog timer + * on the watchdog chain HEADER. + */ + +STATIC INLINE Watchdog_Control *_Watchdog_Last( + Chain_Control *header +) +{ + + return ( (Watchdog_Control *) header->last ); + +} + +#endif +/* end of include file */ diff --git a/cpukit/score/inline/rtems/score/wkspace.inl b/cpukit/score/inline/rtems/score/wkspace.inl new file mode 100644 index 0000000000..47174a9c9d --- /dev/null +++ b/cpukit/score/inline/rtems/score/wkspace.inl @@ -0,0 +1,57 @@ +/* wkspace.inl + * + * This include file contains the bodies of the routines which contains + * information related to the RAM Workspace. + * + * 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$ + */ + +#ifndef __WORKSPACE_inl +#define __WORKSPACE_inl + +/*PAGE + * + * _Workspace_Allocate + * + * DESCRIPTION: + * + * This routine returns the address of a block of memory of size + * bytes. If a block of the appropriate size cannot be allocated + * from the workspace, then NULL is returned. + */ + +STATIC INLINE void *_Workspace_Allocate( + unsigned32 size +) +{ + return _Heap_Allocate( &_Workspace_Area, size ); +} + +/*PAGE + * + * _Workspace_Free + * + * DESCRIPTION: + * + * This function frees the specified block of memory. If the block + * belongs to the Workspace and can be successfully freed, then + * TRUE is returned. Otherwise FALSE is returned. + */ + +STATIC INLINE boolean _Workspace_Free( + void *block +) +{ + return _Heap_Free( &_Workspace_Area, block ); +} + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/README b/cpukit/score/macros/README new file mode 100644 index 0000000000..b2f0c4d481 --- /dev/null +++ b/cpukit/score/macros/README @@ -0,0 +1,18 @@ +# +# $Id$ +# + +The files in this directory are not considered the "primary" source +of inlined routines for RTEMS. The "inline" directory contains +the implementations of the inlined basis which are regularly +tested. In general, an effort is made to keep the contents of +this directory up to date but testing is only performed irregularly +and even then it is usually with a single target processor and BSP. + +The primary purpose of the code in this directory is to insure +that RTEMS can be compiled using a C compiler which does not support +static inline routines. + +These were last successfully tested on 2/1/95 on a prerelease version +of 3.2.0. The testing was done only on the Force CPU386 i386 target board. +No testing was done on version of the code in the final release. diff --git a/cpukit/score/macros/rtems/score/README b/cpukit/score/macros/rtems/score/README new file mode 100644 index 0000000000..b2f0c4d481 --- /dev/null +++ b/cpukit/score/macros/rtems/score/README @@ -0,0 +1,18 @@ +# +# $Id$ +# + +The files in this directory are not considered the "primary" source +of inlined routines for RTEMS. The "inline" directory contains +the implementations of the inlined basis which are regularly +tested. In general, an effort is made to keep the contents of +this directory up to date but testing is only performed irregularly +and even then it is usually with a single target processor and BSP. + +The primary purpose of the code in this directory is to insure +that RTEMS can be compiled using a C compiler which does not support +static inline routines. + +These were last successfully tested on 2/1/95 on a prerelease version +of 3.2.0. The testing was done only on the Force CPU386 i386 target board. +No testing was done on version of the code in the final release. diff --git a/cpukit/score/macros/rtems/score/address.inl b/cpukit/score/macros/rtems/score/address.inl new file mode 100644 index 0000000000..c0d45c3c6b --- /dev/null +++ b/cpukit/score/macros/rtems/score/address.inl @@ -0,0 +1,68 @@ +/* macros/address.h + * + * This include file contains the bodies of the routines + * about addresses which are inlined. + * + * 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$ + */ + +#ifndef __MACROS_ADDRESSES_h +#define __MACROS_ADDRESSES_h + +/*PAGE + * + * _Addresses_Add_offset + * + */ + +#define _Addresses_Add_offset( _base, _offset ) \ + ((void *)((char *)(_base) + (_offset))) + +/*PAGE + * + * _Addresses_Subtract_offset + * + */ + +#define _Addresses_Subtract_offset( _base, _offset ) \ + ((void *)((char *)(_base) - (_offset))) + +/*PAGE + * + * _Addresses_Subtract + * + * NOTE: The cast of an address to an unsigned32 makes this code + * dependent on an addresses being thirty two bits. + */ + +#define _Addresses_Subtract( _left, _right ) \ + ((void *)(_left) - (void *)(_right)) + +/*PAGE + * + * _Addresses_Is_aligned + * + */ + +#define _Addresses_Is_aligned( _address ) \ + ( ( (unsigned32)(_address) % 4 ) == 0 ) + +/*PAGE + * + * _Addresses_Is_in_range + * + */ + +#define _Addresses_Is_in_range( _address, _base, _limit ) \ + ( (_address) >= (_base) && (_address) <= (_limit) ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/chain.inl b/cpukit/score/macros/rtems/score/chain.inl new file mode 100644 index 0000000000..0f09499f1d --- /dev/null +++ b/cpukit/score/macros/rtems/score/chain.inl @@ -0,0 +1,200 @@ +/* macros/chain.h + * + * This include file contains the bodies of the routines which are + * associated with doubly linked chains and inlined. + * + * 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$ + */ + +#ifndef __MACROS_CHAIN_h +#define __MACROS_CHAIN_h + +/*PAGE + * + * _Chain_Are_nodes_equal + */ + +#define _Chain_Are_nodes_equal( _left, _right ) \ + ( (_left) == (_right) ) + +/*PAGE + * + * _Chain_Is_null + */ + +#define _Chain_Is_null( _the_chain ) \ + ( (_the_chain) == NULL ) + +/*PAGE + * + * _Chain_Is_null_node + */ + +#define _Chain_Is_null_node( _the_node ) \ + ( (_the_node) == NULL ) + +/*PAGE + * + * _Chain_Head + */ + +#define _Chain_Head( _the_chain ) \ + ((Chain_Node *) (_the_chain)) + +/*PAGE + * + * _Chain_Tail + */ + +#define _Chain_Tail( _the_chain ) \ + ((Chain_Node *) &(_the_chain)->permanent_null) + +/*PAGE + * + * _Chain_Is_empty + */ + +#define _Chain_Is_empty( _the_chain ) \ + ( (_the_chain)->first == _Chain_Tail( (_the_chain) ) ) + +/*PAGE + * + * _Chain_Is_first + */ + +#define _Chain_Is_first( _the_node ) \ + ( (the_node)->previous == NULL ) + +/*PAGE + * + * _Chain_Is_last + */ + +#define _Chain_Is_last( _the_node ) \ + ( (_the_node)->next == NULL ) + +/*PAGE + * + * _Chain_Has_only_one_node + */ + +#define _Chain_Has_only_one_node( _the_chain ) \ + ( (_the_chain)->first == (_the_chain)->last ) + +/*PAGE + * + * _Chain_Is_head + */ + +#define _Chain_Is_head( _the_chain, _the_node ) \ + ( (_the_node) == _Chain_Head( (_the_chain) ) ) + +/*PAGE + * + * _Chain_Is_tail + */ + +#define _Chain_Is_tail( _the_chain, _the_node ) \ + ( (_the_node) == _Chain_Tail( (_the_chain) ) ) + +/*PAGE + * + * Chain_Initialize_empty + */ + +#define _Chain_Initialize_empty( _the_chain ) \ +{ \ + (_the_chain)->first = _Chain_Tail( (_the_chain) ); \ + (_the_chain)->permanent_null = NULL; \ + (_the_chain)->last = _Chain_Head( (_the_chain) ); \ +} + +/*PAGE + * + * _Chain_Extract_unprotected + */ + +#define _Chain_Extract_unprotected( _the_node ) \ +{ \ + Chain_Node *_next; \ + Chain_Node *_previous; \ + \ + _next = (_the_node)->next; \ + _previous = (_the_node)->previous; \ + _next->previous = _previous; \ + _previous->next = _next; \ +} + +/*PAGE + * + * _Chain_Get_unprotected + */ + +/*PAGE + * + * Chain_Get_unprotected + */ + +#define _Chain_Get_unprotected( _the_chain ) \ + (( !_Chain_Is_empty( (_the_chain) ) ) \ + ? _Chain_Get_first_unprotected( (_the_chain) ) \ + : NULL) + +/*PAGE + * + * _Chain_Insert_unprotected + */ + +#define _Chain_Insert_unprotected( _after_node, _the_node ) \ +{ \ + Chain_Node *_before_node; \ + \ + (_the_node)->previous = (_after_node); \ + _before_node = (_after_node)->next; \ + (_after_node)->next = (_the_node); \ + (_the_node)->next = _before_node; \ + _before_node->previous = (_the_node); \ +} + +/*PAGE + * + * _Chain_Append_unprotected + */ + +#define _Chain_Append_unprotected( _the_chain, _the_node ) \ +{ \ + Chain_Node *_old_last_node; \ + \ + (_the_node)->next = _Chain_Tail( (_the_chain) ); \ + _old_last_node = (_the_chain)->last; \ + (_the_chain)->last = (_the_node); \ + _old_last_node->next = (_the_node); \ + (_the_node)->previous = _old_last_node; \ +} + +/*PAGE + * + * _Chain_Prepend_unprotected + */ + +#define _Chain_Prepend_unprotected( _the_chain, _the_node ) \ + _Chain_Insert_unprotected( _Chain_Head( (_the_chain) ), (_the_node) ) + +/*PAGE + * + * _Chain_Prepend + */ + +#define _Chain_Prepend( _the_chain, _the_node ) \ + _Chain_Insert( _Chain_Head( (_the_chain) ), (_the_node) ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/coremsg.inl b/cpukit/score/macros/rtems/score/coremsg.inl new file mode 100644 index 0000000000..90bef885ed --- /dev/null +++ b/cpukit/score/macros/rtems/score/coremsg.inl @@ -0,0 +1,143 @@ +/* coremsg.inl + * + * This include file contains the macro implementation of all + * inlined routines in the Core Message 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$ + */ + +#ifndef __CORE_MESSAGE_QUEUE_inl +#define __CORE_MESSAGE_QUEUE_inl + +/*PAGE + * + * _CORE_message_queue_Send + * + */ + +#define _CORE_message_queue_Send( _the_message_queue, _buffer, _size, \ +_id, _api_message_queue_mp_support ) \ + _CORE_message_queue_Submit( (_the_message_queue), (_buffer), (_size), \ + (_id), (_api_message_queue_mp_support), CORE_MESSAGE_QUEUE_SEND_REQUEST ) + +/*PAGE + * + * _CORE_message_queue_Urgent + * + */ + +#define _CORE_message_queue_Urgent( _the_message_queue, _buffer, _size, \ +_id, _api_message_queue_mp_support ) \ + _CORE_message_queue_Submit( (_the_message_queue), (_buffer), (_size), \ + (_id), (_api_message_queue_mp_support), CORE_MESSAGE_QUEUE_URGENT_REQUEST ) + +/*PAGE + * + * _CORE_message_queue_Copy_buffer + */ + +#define _CORE_message_queue_Copy_buffer( _source, _destination, _size ) \ + memcpy( _destination, _source, _size) + +/*PAGE + * + * _CORE_message_queue_Allocate_message_buffer + * + */ + +#define _CORE_message_queue_Allocate_message_buffer( _the_message_queue ) \ + (CORE_message_queue_Buffer_control *) \ + _Chain_Get( &(_the_message_queue)->Inactive_messages ) + +/*PAGE + * + * _CORE_message_queue_Free_message_buffer + * + */ + +#define _CORE_message_queue_Free_message_buffer( _the_message_queue, _the_message ) \ + _Chain_Append( \ + &(_the_message_queue)->Inactive_messages, \ + &(_the_message)->Node \ + ) + +/*PAGE + * + * _CORE_message_queue_Is_priority + * + */ + +#define _CORE_message_queue_Is_priority( _the_attribute ) \ + ((_the_attribute)->discipline == CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY) + +/*PAGE + * + * _CORE_message_queue_Get_pending_message + * + */ + +#define _CORE_message_queue_Get_pending_message( _the_message_queue ) \ + (CORE_message_queue_Buffer_control *) \ + _Chain_Get_unprotected( &(_the_message_queue)->Pending_messages ) + +/*PAGE + * + * _CORE_message_queue_Append + * + */ + +#define _CORE_message_queue_Append( _the_message_queue, _the_message ) \ + _Chain_Append( &(_the_message_queue)->Pending_messages, \ + &(_the_message)->Node ) + +/*PAGE + * + * _CORE_message_queue_Prepend + * + */ + +#define _CORE_message_queue_Prepend( _the_message_queue, _the_message ) \ + _Chain_Prepend( &(_the_message_queue)->Pending_messages, \ + &(_the_message)->Node ) + +/*PAGE + * + * _CORE_message_queue_Is_null + * + */ + +#define _CORE_message_queue_Is_null( _the_message_queue ) \ + ( (_the_message_queue) == NULL ) + +/*PAGE + * + * _CORE_message_queue_Is_notify_enabled + * + */ + +#define _CORE_message_queue_Is_notify_enabled( _the_message_queue ) \ + ( (_the_message_queue)->notify_handler != NULL ) + +/*PAGE + * + * _CORE_message_queue_Set_notify + * + */ + +#define _CORE_message_queue_Set_notify( \ + _the_message_queue, _the_handler, _the_argument ) \ + do { \ + (_the_message_queue)->notify_handler = (_the_handler); \ + (_the_message_queue)->notify_argument = (_the_argument); \ + } while ( 0 ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/coremutex.inl b/cpukit/score/macros/rtems/score/coremutex.inl new file mode 100644 index 0000000000..e8dbc9322c --- /dev/null +++ b/cpukit/score/macros/rtems/score/coremutex.inl @@ -0,0 +1,77 @@ +/* macros/coremutex.h + * + * This include file contains all of the inlined routines associated + * with core mutexes. + * + * 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$ + */ + +#ifndef __MACROS_CORE_MUTEX_h +#define __MACROS_CORE_MUTEX_h + + +/*PAGE + * + * _CORE_mutex_Is_locked + * + */ + +#define _CORE_mutex_Is_locked( _the_mutex ) \ + ( (_the_mutex)->lock == CORE_MUTEX_LOCKED ) + +/*PAGE + * + * _CORE_mutex_Is_fifo + * + */ + +#define _CORE_mutex_Is_fifo( _the_attribute ) \ + ( (_the_attribute)->discipline == CORE_MUTEX_DISCIPLINES_FIFO ) + +/*PAGE + * + * _CORE_mutex_Is_priority + * + */ + +#define _CORE_mutex_Is_priority( _the_attribute ) \ + ( (_the_attribute)->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY ) + +/*PAGE + * + * _CORE_mutex_Is_inherit_priority + * + */ + +#define _CORE_mutex_Is_inherit_priority( _the_attribute ) \ + ( (_the_attribute)->discipline == \ + CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT ) + +/*PAGE + * + * _CORE_mutex_Is_priority_ceiling + * + */ + +#define _CORE_mutex_Is_priority_ceiling( _the_attribute )\ + ( (_the_attribute)->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING ) + +/*PAGE + * + * _CORE_mutex_Is_nesting_allowed + * + */ + +#define _CORE_mutex_Is_nesting_allowed( _the_attribute ) \ + ( (_the_attribute)->allow_nesting == TRUE ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/coresem.inl b/cpukit/score/macros/rtems/score/coresem.inl new file mode 100644 index 0000000000..499b4a1433 --- /dev/null +++ b/cpukit/score/macros/rtems/score/coresem.inl @@ -0,0 +1,40 @@ +/* macros/coresem.h + * + * This include file contains all of the inlined routines associated + * with core semaphores. + * + * 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$ + */ + +#ifndef __MACROS_CORE_SEMAPHORE_h +#define __MACROS_CORE_SEMAPHORE_h + +/*PAGE + * + * _CORE_semaphore_Is_priority + * + */ + +#define _CORE_semaphore_Is_priority( _the_attribute ) \ + ( (_the_attribute)->discipline == CORE_SEMAPHORE_DISCIPLINES_PRIORITY ) + +/*PAGE + * + * _Core_semaphore_Get_count + * + */ + +#define _Core_semaphore_Get_count( _the_semaphore ) \ + ( (_the_semaphore)->count ) + + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/heap.inl b/cpukit/score/macros/rtems/score/heap.inl new file mode 100644 index 0000000000..94f4ff9194 --- /dev/null +++ b/cpukit/score/macros/rtems/score/heap.inl @@ -0,0 +1,150 @@ +/* heap.inl + * + * This file contains the macro implementation of the inlined + * routines from the heap 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$ + */ + +#ifndef __HEAP_inl +#define __HEAP_inl + +#include <rtems/score/address.h> + +/*PAGE + * + * _Heap_Head + */ + +#define _Heap_Head( _the_heap ) \ + ((Heap_Block *)&(_the_heap)->start) + +/*PAGE + * + * _Heap_Tail + */ + +#define _Heap_Tail( _the_heap ) \ + ((Heap_Block *)&(_the_heap)->final) + +/*PAGE + * + * _Heap_Previous_block + */ + +#define _Heap_Previous_block( _the_block ) \ + ( (Heap_Block *) _Addresses_Subtract_offset( \ + (void *)(_the_block), \ + (_the_block)->back_flag & ~ HEAP_BLOCK_USED \ + ) \ + ) + +/*PAGE + * + * _Heap_Next_block + */ + +#define _Heap_Next_block( _the_block ) \ + ( (Heap_Block *) _Addresses_Add_offset( \ + (void *)(_the_block), \ + (_the_block)->front_flag & ~ HEAP_BLOCK_USED \ + ) \ + ) + +/*PAGE + * + * _Heap_Block_at + */ + +#define _Heap_Block_at( _base, _offset ) \ + ( (Heap_Block *) \ + _Addresses_Add_offset( (void *)(_base), (_offset) ) ) + +/*PAGE + * + * _Heap_User_block_at + * + */ + +#define _Heap_User_block_at( _base ) \ + _Heap_Block_at( \ + (_base), \ + -*(((unsigned32 *) (_base)) - 1) + -HEAP_BLOCK_USED_OVERHEAD \ + ) + +/*PAGE + * + * _Heap_Is_previous_block_free + */ + +#define _Heap_Is_previous_block_free( _the_block ) \ + ( !((_the_block)->back_flag & HEAP_BLOCK_USED) ) + +/*PAGE + * + * _Heap_Is_block_free + */ + +#define _Heap_Is_block_free( _the_block ) \ + ( !((_the_block)->front_flag & HEAP_BLOCK_USED) ) + +/*PAGE + * + * _Heap_Is_block_used + */ + +#define _Heap_Is_block_used( _the_block ) \ + ((_the_block)->front_flag & HEAP_BLOCK_USED) + +/*PAGE + * + * _Heap_Block_size + */ + +#define _Heap_Block_size( _the_block ) \ + ((_the_block)->front_flag & ~HEAP_BLOCK_USED) + +/*PAGE + * + * _Heap_Start_of_user_area + */ + +#define _Heap_Start_of_user_area( _the_block ) \ + ((void *) &(_the_block)->next) + +/*PAGE + * + * _Heap_Is_block_in + */ + +#define _Heap_Is_block_in( _the_heap, _the_block ) \ + ( ((_the_block) >= (_the_heap)->start) && \ + ((_the_block) <= (_the_heap)->final) ) + +/*PAGE + * + * _Heap_Is_page_size_valid + */ + +#define _Heap_Is_page_size_valid( _page_size ) \ + ( ((_page_size) != 0) && \ + (((_page_size) % CPU_HEAP_ALIGNMENT) == 0) ) + +/*PAGE + * + * _Heap_Build_flag + */ + +#define _Heap_Build_flag( _size, _in_use_flag ) \ + ( (_size) | (_in_use_flag)) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/isr.inl b/cpukit/score/macros/rtems/score/isr.inl new file mode 100644 index 0000000000..95f0319396 --- /dev/null +++ b/cpukit/score/macros/rtems/score/isr.inl @@ -0,0 +1,48 @@ +/* isr.inl + * + * This include file contains the macro implementation of all + * inlined routines in the 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$ + */ + +#ifndef __ISR_inl +#define __ISR_inl + +/*PAGE + * + * _ISR_Is_in_progress + * + */ + +#define _ISR_Is_in_progress() \ + (_ISR_Nest_level != 0) + +/*PAGE + * + * _ISR_Is_vector_number_valid + * + */ + +#define _ISR_Is_vector_number_valid( _vector ) \ + ( (_vector) <= CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER ) + +/*PAGE + * + * _ISR_Is_valid_user_handler + * + */ + +#define _ISR_Is_valid_user_handler( _handler ) \ + ((_handler) != NULL) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/mppkt.inl b/cpukit/score/macros/rtems/score/mppkt.inl new file mode 100644 index 0000000000..ff1d51034b --- /dev/null +++ b/cpukit/score/macros/rtems/score/mppkt.inl @@ -0,0 +1,41 @@ +/* macros/mppkt.h + * + * This package is the implementation of the Packet Handler + * routines which are inlined. + * + * 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$ + */ + +#ifndef __MACROS_MP_PACKET_h +#define __MACROS_MP_PACKET_h + +/*PAGE + * + * _Mp_packet_Is_valid_packet_class + * + * NOTE: Check for lower bounds (MP_PACKET_CLASSES_FIRST ) is unnecessary + * because this enum starts at lower bound of zero. + */ + +#define _Mp_packet_Is_valid_packet_class( _the_packet_class ) \ + ( (_the_packet_class) <= MP_PACKET_CLASSES_LAST ) + +/*PAGE + * + * _Mp_packet_Is_null + * + */ + +#define _Mp_packet_Is_null ( _the_packet ) \ + ( (_the_packet) == NULL ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/object.inl b/cpukit/score/macros/rtems/score/object.inl new file mode 100644 index 0000000000..8a5a0a3411 --- /dev/null +++ b/cpukit/score/macros/rtems/score/object.inl @@ -0,0 +1,148 @@ +/* object.inl + * + * This include file contains the macro implementation of all + * of the inlined routines in the Object 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$ + */ + +#ifndef __OBJECTS_inl +#define __OBJECTS_inl + +/*PAGE + * + * _Objects_Build_id + * + */ + +#define _Objects_Build_id( _the_class, _node, _index ) \ + ( ((_the_class) << OBJECTS_CLASS_START_BIT) | \ + ((_node) << OBJECTS_NODE_START_BIT) | \ + ((_index) << OBJECTS_INDEX_START_BIT) ) + +/*PAGE + * + * _Objects_Get_class + */ + +#define _Objects_Get_class( _id ) \ + (Objects_Classes) \ + (((_id) >> OBJECTS_CLASS_START_BIT) & OBJECTS_CLASS_VALID_BITS) + +/*PAGE + * + * _Objects_Get_node + * + */ + +#define _Objects_Get_node( _id ) \ + (((_id) >> OBJECTS_NODE_START_BIT) & OBJECTS_NODE_VALID_BITS) + +/*PAGE + * + * _Objects_Get_index + * + */ + +#define _Objects_Get_index( _id ) \ + (((_id) >> OBJECTS_INDEX_START_BIT) & OBJECTS_INDEX_VALID_BITS) + +/*PAGE + * + * _Objects_Is_class_valid + * + */ + +#define _Objects_Is_class_valid( _the_class ) \ + ( (_the_class) <= OBJECTS_CLASSES_LAST ) + +/*PAGE + * + * _Objects_Is_local_node + * + */ + +#define _Objects_Is_local_node( _node ) \ + ( (_node) == _Objects_Local_node ) + +/*PAGE + * + * _Objects_Is_local_id + * + */ + +#define _Objects_Is_local_id( _id ) \ + _Objects_Is_local_node( _Objects_Get_node(_id) ) + +/*PAGE + * + * _Objects_Are_ids_equal + * + */ + +#define _Objects_Are_ids_equal( _left, _right ) \ + ( (_left) == (_right) ) + +/*PAGE + * + * _Objects_Allocate + * + */ + +#define _Objects_Allocate( _information ) \ + (Objects_Control *) _Chain_Get( &(_information)->Inactive ) + +/*PAGE + * + * _Objects_Free + * + */ + +#define _Objects_Free( _information, _the_object ) \ + _Chain_Append( &(_information)->Inactive, &(_the_object)->Node ) + +/*PAGE + * + * _Objects_Open + * + */ + +#define _Objects_Open( _information, _the_object, _name ) \ + { \ + unsigned32 _index; \ + \ + _index = _Objects_Get_index( (_the_object)->id ); \ + (_information)->local_table[ _index ] = (_the_object); \ + \ + if ( (_information)->is_string ) \ + _Objects_Copy_name_string( (_name), (_the_object)->name ); \ + else \ + _Objects_Copy_name_raw( \ + (_name), (_the_object)->name, (_information)->name_length ); \ + } + +/*PAGE + * + * _Objects_Close + * + */ + +#define _Objects_Close( _information, _the_object ) \ + { \ + unsigned32 _index; \ + \ + _index = _Objects_Get_index( (_the_object)->id ); \ + (_information)->local_table[ _index ] = NULL; \ + _Objects_Clear_name( (_the_object)->name, (_information)->name_length ); \ + } + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/objectmp.inl b/cpukit/score/macros/rtems/score/objectmp.inl new file mode 100644 index 0000000000..2f1c5ac7fa --- /dev/null +++ b/cpukit/score/macros/rtems/score/objectmp.inl @@ -0,0 +1,50 @@ +/* macros/objectmp.inl + * + * This include file contains the bodies of all inlined routines + * which deal with global objects. + * + * 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$ + */ + +#ifndef __MACROS_MP_OBJECTS_inl +#define __MACROS_MP_OBJECTS_inl + +/*PAGE + * + * _Objects_MP_Allocate_global_object + * + */ + +#define _Objects_MP_Allocate_global_object() \ + (Objects_MP_Control *) \ + _Chain_Get( &_Objects_MP_Inactive_global_objects ) + +/*PAGE + * _Objects_MP_Free_global_object + * + */ + +#define _Objects_MP_Free_global_object( _the_object ) \ + _Chain_Append( \ + &_Objects_MP_Inactive_global_objects, \ + &(_the_object)->Object.Node \ + ) + +/*PAGE + * _Objects_MP_Is_null_global_object + * + */ + +#define _Objects_MP_Is_null_global_object( _the_object ) \ + ( (_the_object) == NULL ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/priority.inl b/cpukit/score/macros/rtems/score/priority.inl new file mode 100644 index 0000000000..4c5d32b3b3 --- /dev/null +++ b/cpukit/score/macros/rtems/score/priority.inl @@ -0,0 +1,170 @@ +/* priority.inl + * + * This file contains the macro implementation of all inlined routines + * in the Priority 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$ + */ + +#ifndef __PRIORITY_inl +#define __PRIORITY_inl + +#include <rtems/score/bitfield.h> + +/*PAGE + * + * _Priority_Handler_initialization + * + */ + +#define _Priority_Handler_initialization() \ + { \ + unsigned32 index; \ + \ + _Priority_Major_bit_map = 0; \ + for ( index=0 ; index <16 ; index++ ) \ + _Priority_Bit_map[ index ] = 0; \ + } + +/*PAGE + * + * _Priority_Is_valid + * + */ + + /* + * Since PRIORITY_MINIMUM is 0 and priorities are stored unsigned, + * then checking for less than 0 is unnecessary. + */ + +#define _Priority_Is_valid( _the_priority ) \ + ( (_the_priority) <= PRIORITY_MAXIMUM ) + +/*PAGE + * + * _Priority_Major + * + */ + +#define _Priority_Major( _the_priority ) ( (_the_priority) / 16 ) + +/*PAGE + * + * _Priority_Minor + * + */ + +#define _Priority_Minor( _the_priority ) ( (_the_priority) % 16 ) + +#if ( CPU_USE_GENERIC_BITFIELD_CODE == TRUE ) + +/*PAGE + * + * _Priority_Mask + * + */ + +#define _Priority_Mask( _bit_number ) \ + (0x8000 >> _bit_number) + +/*PAGE + * + * _Priority_Bits_index + * + */ + +#define _Priority_Bits_index( _bit_number ) \ + (_bit_number) + +#endif + +/*PAGE + * + * _Priority_Add_to_bit_map + * + */ + +#define _Priority_Add_to_bit_map( _the_priority_map ) \ + { \ + *(_the_priority_map)->minor |= (_the_priority_map)->ready_minor; \ + _Priority_Major_bit_map |= (_the_priority_map)->ready_major; \ + } + +/*PAGE + * + * _Priority_Remove_from_bit_map + * + */ + +#define _Priority_Remove_from_bit_map( _the_priority_map ) \ + { \ + *(_the_priority_map)->minor &= (_the_priority_map)->block_minor; \ + if ( *(_the_priority_map)->minor == 0 ) \ + _Priority_Major_bit_map &= (_the_priority_map)->block_major; \ + } + +/*PAGE + * + * _Priority_Get_highest + * + */ + +#define _Priority_Get_highest( _high_priority ) \ + { \ + Priority_Bit_map_control minor; \ + Priority_Bit_map_control major; \ + \ + _Bitfield_Find_first_bit( _Priority_Major_bit_map, major ); \ + _Bitfield_Find_first_bit( _Priority_Bit_map[major], minor ); \ + \ + (_high_priority) = (_Priority_Bits_index( major ) * 16) + \ + _Priority_Bits_index( minor ); \ + } + +/*PAGE + * + * _Priority_Initialize_information + * + */ + +#define _Priority_Initialize_information( \ + _the_priority_map, _new_priority ) \ + { \ + Priority_Bit_map_control _major; \ + Priority_Bit_map_control _minor; \ + Priority_Bit_map_control _mask; \ + \ + _major = _Priority_Major( (_new_priority) ); \ + _minor = _Priority_Minor( (_new_priority) ); \ + \ + (_the_priority_map)->minor = \ + &_Priority_Bit_map[ _Priority_Bits_index(_major) ]; \ + \ + _mask = _Priority_Mask( _major ); \ + (_the_priority_map)->ready_major = _mask; \ + (_the_priority_map)->block_major = ~_mask; \ + \ + _mask = _Priority_Mask( _minor ); \ + (_the_priority_map)->ready_minor = _mask; \ + (_the_priority_map)->block_minor = ~_mask; \ + } + +/*PAGE + * + * _Priority_Is_group_empty + * + */ + +#define _Priority_Is_group_empty ( _the_priority ) \ + ( (_the_priority) == 0 ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/stack.inl b/cpukit/score/macros/rtems/score/stack.inl new file mode 100644 index 0000000000..d20eebd0b9 --- /dev/null +++ b/cpukit/score/macros/rtems/score/stack.inl @@ -0,0 +1,50 @@ +/* stack.inl + * + * This file contains the macro implementation of the inlined + * routines from the Stack 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$ + */ + +#ifndef __STACK_inl +#define __STACK_inl + +/*PAGE + * + * _Stack_Initialize + * + */ + +#define _Stack_Initialize( _the_stack, _starting_address, _size ) \ + { \ + (_the_stack)->area = (_starting_address); \ + (_the_stack)->size = (_size); \ + } + +/*PAGE + * + * _Stack_Is_enough + * + */ + +#define _Stack_Is_enough( _size ) \ + ( (_size) >= STACK_MINIMUM_SIZE ) + +/*PAGE + * + * _Stack_Adjust_size + */ + +#define _Stack_Adjust_size( _size ) \ + ((_size) + CPU_STACK_ALIGNMENT) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/states.inl b/cpukit/score/macros/rtems/score/states.inl new file mode 100644 index 0000000000..4fa138d107 --- /dev/null +++ b/cpukit/score/macros/rtems/score/states.inl @@ -0,0 +1,210 @@ +/* states.inl + * + * This file contains the macro implementation of the inlined + * routines associated with thread state information. + * + * 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$ + */ + +#ifndef __STATES_inl +#define __STATES_inl + +/*PAGE + * + * _States_Set + * + */ + +#define _States_Set( _states_to_set, _current_state ) \ + ((_current_state) | (_states_to_set)) + +/*PAGE + * + * _States_Clear + * + */ + +#define _States_Clear( _states_to_clear, _current_state ) \ + ((_current_state) & ~(_states_to_clear)) + +/*PAGE + * + * _States_Is_ready + * + */ + +#define _States_Is_ready( _the_states ) \ + ( (_the_states) == STATES_READY ) + +/*PAGE + * + * _States_Is_only_dormant + * + */ + +#define _States_Is_only_dormant( _the_states ) \ + ( (_the_states) == STATES_DORMANT ) + +/*PAGE + * + * _States_Is_dormant + * + */ + +#define _States_Is_dormant( _the_states ) \ + ( (_the_states) & STATES_DORMANT ) + +/*PAGE + * + * _States_Is_suspended + * + */ + +#define _States_Is_suspended( _the_states ) \ + ( (_the_states) & STATES_SUSPENDED ) + +/*PAGE + * + * _States_Is_Transient + * + */ + +#define _States_Is_transient( _the_states ) \ + ( (_the_states) & STATES_TRANSIENT ) + +/*PAGE + * + * _States_Is_delaying + * + */ + +#define _States_Is_delaying( _the_states ) \ + ( (_the_states) & STATES_DELAYING ) + +/*PAGE + * + * _States_Is_waiting_for_buffer + * + */ + +#define _States_Is_waiting_for_buffer( _the_states ) \ + ( (_the_states) & STATES_WAITING_FOR_BUFFER ) + +/*PAGE + * + * _States_Is_waiting_for_segment + * + */ + +#define _States_Is_waiting_for_segment( _the_states ) \ + ( (_the_states) & STATES_WAITING_FOR_SEGMENT ) + +/*PAGE + * + * _States_Is_waiting_for_message + * + */ + +#define _States_Is_waiting_for_message( _the_states ) \ + ( (_the_states) & STATES_WAITING_FOR_MESSAGE ) + +/*PAGE + * + * _States_Is_waiting_for_event + * + */ + +#define _States_Is_waiting_for_event( _the_states ) \ + ( (_the_states) & STATES_WAITING_FOR_EVENT ) + +/*PAGE + * + * _States_Is_waiting_for_mutex + * + */ + +#define _States_Is_waiting_for_mutex( _the_states ) \ + ( (_the_states) & STATES_WAITING_FOR_MUTEX ) + +/*PAGE + * + * _States_Is_waiting_for_semaphore + * + */ + +#define _States_Is_waiting_for_semaphore( _the_states ) \ + ( (_the_states) & STATES_WAITING_FOR_SEMAPHORE ) + +/*PAGE + * + * _States_Is_waiting_for_time + * + */ + +#define _States_Is_waiting_for_time( _the_states ) \ + ( (_the_states) & STATES_WAITING_FOR_TIME ) + +/*PAGE + * + * _States_Is_waiting_for_rpc_reply + * + */ + +#define _States_Is_waiting_for_rpc_reply( _the_states ) \ + ( (_the_states) & STATES_WAITING_FOR_RPC_REPLY ) + +/*PAGE + * + * _States_Is_waiting_for_period + * + */ + +#define _States_Is_waiting_for_period( _the_states ) \ + ( (_the_states) & STATES_WAITING_FOR_PERIOD ) + +/*PAGE + * + * _States_Is_locally_blocked + * + */ + +#define _States_Is_locally_blocked( _the_states ) \ + ( (_the_states) & STATES_LOCALLY_BLOCKED ) + +/*PAGE + * + * _States_Is_waiting_on_thread_queue + * + */ + +#define _States_Is_waiting_on_thread_queue( _the_states ) \ + ( (_the_states) & STATES_WAITING_ON_THREAD_QUEUE ) + +/*PAGE + * + * _States_Is_blocked + * + */ + +#define _States_Is_blocked( _the_states ) \ + ( (_the_states) & STATES_BLOCKED ) + +/*PAGE + * + * _States_Are_set + * + */ + +#define _States_Are_set( _the_states, _mask ) \ + ( ((_the_states) & (_mask)) != STATES_READY ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/sysstate.inl b/cpukit/score/macros/rtems/score/sysstate.inl new file mode 100644 index 0000000000..d0cb932924 --- /dev/null +++ b/cpukit/score/macros/rtems/score/sysstate.inl @@ -0,0 +1,90 @@ +/* sysstates.inl + * + * This file contains the macro implementation of routines regarding the + * system state. + * + * 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$ + */ + +#ifndef __SYSTEM_STATE_inl +#define __SYSTEM_STATE_inl + +/*PAGE + * + * _System_state_Handler_initialization + */ + +#define _System_state_Handler_initialization( _is_multiprocessing ) \ + do { \ + _System_state_Current = SYSTEM_STATE_BEFORE_INITIALIZATION; \ + _System_state_Is_multiprocessing = (_is_multiprocessing); \ + } while ( 0 ) + +/*PAGE + * + * _System_state_Set + */ + +#define _System_state_Set( _state ) \ + do { \ + _System_state_Current = (_state); \ + } while ( 0 ) + +/*PAGE + * + * _System_state_Get + */ + +#define _System_state_Get() \ + (_System_state_Current) + +/*PAGE + * + * _System_state_Is_before_initialization + */ + +#define _System_state_Is_before_initialization( _state ) \ + ((_state) == SYSTEM_STATE_BEFORE_INITIALIZATION) + +/*PAGE + * + * _System_state_Is_before_multitasking + */ + +#define _System_state_Is_before_multitasking( _state ) \ + ((_state) == SYSTEM_STATE_BEFORE_MULTITASKING) + +/*PAGE + * + * _System_state_Is_begin_multitasking + */ + +#define _System_state_Is_begin_multitasking( _state ) \ + ((_state) == SYSTEM_STATE_BEGIN_MULTITASKING) + +/*PAGE + * + * _System_state_Is_up + */ + +#define _System_state_Is_up( _state ) \ + ((_state) == SYSTEM_STATE_UP) + +/*PAGE + * + * _System_state_Is_failed + */ + +#define _System_state_Is_failed( _state ) \ + ((_state) == SYSTEM_STATE_FAILED) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/thread.inl b/cpukit/score/macros/rtems/score/thread.inl new file mode 100644 index 0000000000..735686aa20 --- /dev/null +++ b/cpukit/score/macros/rtems/score/thread.inl @@ -0,0 +1,217 @@ +/* thread.inl + * + * This file contains the macro implementation of the inlined + * routines from the Thread 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$ + */ + +#ifndef __THREAD_inl +#define __THREAD_inl + +/*PAGE + * + * _Thread_Stop_multitasking + * + */ + +#define _Thread_Stop_multitasking() \ + _Context_Switch( &_Thread_Executing->Registers, &_Thread_BSP_context ); + +/*PAGE + * + * _Thread_Is_executing + * + */ + +#define _Thread_Is_executing( _the_thread ) \ + ( (_the_thread) == _Thread_Executing ) + +/*PAGE + * + * _Thread_Is_heir + * + */ + +#define _Thread_Is_heir( _the_thread ) \ + ( (_the_thread) == _Thread_Heir ) + +/*PAGE + * + * _Thread_Is_executing_also_the_heir + * + */ + +#define _Thread_Is_executing_also_the_heir() \ + ( _Thread_Executing == _Thread_Heir ) + +/*PAGE + * + * _Thread_Resume + * + */ + +#define _Thread_Resume( _the_thread ) \ + _Thread_Clear_state( (_the_thread), STATES_SUSPENDED ) + +/*PAGE + * + * _Thread_Unblock + * + */ + +#define _Thread_Unblock( _the_thread ) \ + _Thread_Clear_state( (_the_thread), STATES_BLOCKED ); + +/*PAGE + * + * _Thread_Restart_self + * + */ + +#define _Thread_Restart_self() \ + { \ + if ( _Thread_Executing->fp_context != NULL ) \ + _Context_Restore_fp( &_Thread_Executing->fp_context ); \ + \ + _CPU_Context_Restart_self( &_Thread_Executing->Registers ); \ + } + +/*PAGE + * + * _Thread_Calculate_heir + * + */ + +#define _Thread_Calculate_heir() \ + { \ + Priority_Control highest; \ + \ + _Priority_Get_highest( highest ); \ + \ + _Thread_Heir = (Thread_Control *) _Thread_Ready_chain[ highest ].first; \ + } + +/*PAGE + * + * _Thread_Is_allocated_fp + * + */ + +#define _Thread_Is_allocated_fp( _the_thread ) \ + ( (_the_thread) == _Thread_Allocated_fp ) + +/*PAGE + * + * _Thread_Deallocate_fp + * + */ + +#define _Thread_Deallocate_fp() \ + _Thread_Allocated_fp = NULL + +/*PAGE + * + * _Thread_Disable_dispatch + * + */ + +#define _Thread_Disable_dispatch() \ + _Thread_Dispatch_disable_level += 1 + +/*PAGE + * + * _Thread_Enable_dispatch + * + */ + +#if ( CPU_INLINE_ENABLE_DISPATCH == TRUE ) +#define _Thread_Enable_dispatch() \ + { if ( (--_Thread_Dispatch_disable_level) == 0 ) \ + _Thread_Dispatch(); \ + } +#endif + +#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE ) +void _Thread_Enable_dispatch( void ); +#endif + +/*PAGE + * + * _Thread_Unnest_dispatch + * + */ + +#define _Thread_Unnest_dispatch() \ + _Thread_Dispatch_disable_level -= 1 + +/*PAGE + * + * _Thread_Is_dispatching_enabled + * + */ + +#define _Thread_Is_dispatching_enabled() \ + ( _Thread_Dispatch_disable_level == 0 ) + +/*PAGE + * + * _Thread_Is_context_switch_necessary + * + */ + +#define _Thread_Is_context_switch_necessary() \ + ( _Context_Switch_necessary == TRUE ) + +/*PAGE + * + * _Thread_Dispatch_initialization + * + */ + +#define _Thread_Dispatch_initialization() \ + _Thread_Dispatch_disable_level = 1 + +/*PAGE + * + * _Thread_Is_null + * + */ + +#define _Thread_Is_null( _the_thread ) \ + ( (_the_thread) == NULL ) + +/* + * _Thread_Is_proxy_blocking + * + */ + +#define _Thread_Is_proxy_blocking( _code ) \ + ( (_code) == THREAD_STATUS_PROXY_BLOCKING ) + +/* + * _Thread_Internal_allocate + * + */ + +#define _Thread_Internal_allocate() \ + ((Thread_Control *) _Objects_Allocate( &_Thread_Internal_information )) + +/* + * _Thread_Internal_free + * + */ + +#define _Thread_Internal_free( _the_task ) \ + _Objects_Free( &_Thread_Internal_information, &(_the_task)->Object ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/threadmp.inl b/cpukit/score/macros/rtems/score/threadmp.inl new file mode 100644 index 0000000000..c601862f96 --- /dev/null +++ b/cpukit/score/macros/rtems/score/threadmp.inl @@ -0,0 +1,50 @@ +/* macros/threadmp.h + * + * This include file contains the bodies of all inlined routines + * for the multiprocessing part of thread package. + * + * 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$ + */ + +#ifndef __MACROS_MP_THREAD_h +#define __MACROS_MP_THREAD_h + +/*PAGE + * + * _Thread_MP_Is_receive + * + */ + +#define _Thread_MP_Is_receive( _the_thread ) \ + ( (_the_thread) == _Thread_MP_Receive) + +/*PAGE + * + * _Thread_MP_Free_proxy + * + */ + +#define _Thread_MP_Free_proxy( _the_thread ) \ +{ \ + Thread_Proxy_control *_the_proxy; \ + \ + _the_proxy = (Thread_Proxy_control *) (_the_thread); \ + \ + _Chain_Extract( &_the_proxy->Active ); \ + \ + _Chain_Append( \ + &_Thread_MP_Inactive_proxies, \ + &(_the_thread)->Object.Node \ + ); \ +} + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/tod.inl b/cpukit/score/macros/rtems/score/tod.inl new file mode 100644 index 0000000000..ecab4e6eae --- /dev/null +++ b/cpukit/score/macros/rtems/score/tod.inl @@ -0,0 +1,58 @@ +/* tod.inl + * + * This file contains the macro implementation of the inlined routines + * from the Time of Day 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$ + */ + +#ifndef __TIME_OF_DAY_inl +#define __TIME_OF_DAY_inl + +/*PAGE + * + * _TOD_Is_set + * + */ + +#define _TOD_Is_set() \ + _Watchdog_Is_active( &_TOD_Seconds_watchdog ) + +/*PAGE + * + * _TOD_Tickle_ticks + * + */ + +#define _TOD_Tickle_ticks() \ + _TOD_Current.ticks++; \ + _TOD_Ticks_since_boot++ + +/*PAGE + * + * _TOD_Deactivate + * + */ + +#define _TOD_Deactivate() \ + _Watchdog_Remove( &_TOD_Seconds_watchdog ) + +/*PAGE + * + * _TOD_Activate + * + */ + +#define _TOD_Activate( _ticks ) \ + _Watchdog_Insert_ticks( &_TOD_Seconds_watchdog, (_ticks) ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/tqdata.inl b/cpukit/score/macros/rtems/score/tqdata.inl new file mode 100644 index 0000000000..5ffb79bcb1 --- /dev/null +++ b/cpukit/score/macros/rtems/score/tqdata.inl @@ -0,0 +1,59 @@ +/* tqdata.inl + * + * This file contains the macro implementation of the inlined + * routines needed to support the Thread Queue Data. + * + * 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$ + */ + +#ifndef __THREAD_QUEUE_DATA_inl +#define __THREAD_QUEUE_DATA_inl + +/*PAGE + * + * _Thread_queue_Header_number + * + */ + +#define _Thread_queue_Header_number( _the_priority ) \ + ((_the_priority) / TASK_QUEUE_DATA_PRIORITIES_PER_HEADER) + +/*PAGE + * + * _Thread_queue_Is_reverse_search + * + */ + +#define _Thread_queue_Is_reverse_search( _the_priority ) \ + ( (_the_priority) & TASK_QUEUE_DATA_REVERSE_SEARCH_MASK ) + +/*PAGE + * + * _Thread_queue_Get_number_waiting + * + */ + +#define _Thread_queue_Get_number_waiting( _the_thread_queue ) \ + ( (_the_thread_queue)->count ) + +/*PAGE + * + * _Thread_queue_Enter_critical_section + * + */ + +#define _Thread_queue_Enter_critical_section( _the_thread_queue ) \ + do { \ + (_the_thread_queue)->sync_state = THREAD_QUEUE_NOTHING_HAPPENED; \ + } while ( 0 ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/userext.inl b/cpukit/score/macros/rtems/score/userext.inl new file mode 100644 index 0000000000..4b5b8083bf --- /dev/null +++ b/cpukit/score/macros/rtems/score/userext.inl @@ -0,0 +1,126 @@ +/* userext.inl + * + * This file contains the macro implementation of the inlined routines + * from the User Extension 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$ + */ + +#ifndef __USER_EXTENSIONS_inl +#define __USER_EXTENSIONS_inl + +/*PAGE + * + * _User_extensions_Handler_initialization + * + */ + +#define _User_extensions_Handler_initialization( _initial_extensions ) \ + { \ + _Chain_Initialize_empty( &_User_extensions_List ); \ + \ + if ( (_initial_extensions) ) { \ + _User_extensions_Initial.Callouts = *(_initial_extensions); \ + _Chain_Append( \ + &_User_extensions_List, &_User_extensions_Initial.Node ); \ + } \ + } + +/*PAGE + * + * _User_extensions_Add_set + */ + +#define _User_extensions_Add_set( _the_extension, _extension_table ) \ + do { \ + (_the_extension)->Callouts = *(_extension_table); \ + \ + _Chain_Append( &_User_extensions_List, &(_the_extension)->Node ); \ + } while ( 0 ) + +/*PAGE + * + * _User_extensions_Add_API_set + */ + +#define _User_extensions_Add_API_set( _the_extension ) \ + _Chain_Prepend( &_User_extensions_List, &(_the_extension)->Node ) + + +/*PAGE + * + * _User_extensions_Remove_set + */ + +#define _User_extensions_Remove_set( _the_extension ) \ + _Chain_Extract( &(_the_extension)->Node ) + +/*PAGE + * + * _User_extensions_Run_list_forward + * + * NOTE: No parentheses around macro names here to avoid + * messing up the name and function call expansion. + */ + +#define _User_extensions_Run_list_forward( _name, _arguments ) \ + do { \ + Chain_Node *the_node; \ + User_extensions_Control *the_extension; \ + \ + for ( the_node = _User_extensions_List.first ; \ + !_Chain_Is_tail( &_User_extensions_List, the_node ) ; \ + the_node = the_node->next ) { \ + the_extension = (User_extensions_Control *) the_node; \ + \ + if ( the_extension->Callouts.## _name != NULL ) \ + (*the_extension->Callouts.## _name) _arguments; \ + \ + } \ + \ + } while ( 0 ) + +/*PAGE + * + * _User_extensions_Run_list_backward + * + * NOTE: No parentheses around macro names here to avoid + * messing up the name and function call expansion. + */ + +#define _User_extensions_Run_list_backward( _name, _arguments ) \ + do { \ + Chain_Node *the_node; \ + User_extensions_Control *the_extension; \ + \ + for ( the_node = _User_extensions_List.last ; \ + !_Chain_Is_head( &_User_extensions_List, the_node ) ; \ + the_node = the_node->previous ) { \ + the_extension = (User_extensions_Control *) the_node; \ + \ + if ( the_extension->Callouts.## _name != NULL ) \ + (*the_extension->Callouts.## _name) _arguments; \ + \ + } \ + \ + } while ( 0 ) + +/*PAGE + * + * _User_extensions_Thread_switch + * + */ + +#define _User_extensions_Thread_switch( _executing, _heir ) \ + _User_extensions_Run_list_forward(thread_switch, (_executing, _heir) ) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/watchdog.inl b/cpukit/score/macros/rtems/score/watchdog.inl new file mode 100644 index 0000000000..d24224f93d --- /dev/null +++ b/cpukit/score/macros/rtems/score/watchdog.inl @@ -0,0 +1,172 @@ +/* watchdog.inl + * + * This file contains the macro implementation of all inlined routines + * in the Watchdog 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$ + */ + +#ifndef __WATCHDOG_inl +#define __WATCHDOG_inl + +#include <rtems/score/object.h> + +/*PAGE + * + * _Watchdog_Initialize + * + */ + +#define _Watchdog_Initialize( _the_watchdog, _routine, _id, _user_data ) \ + { \ + (_the_watchdog)->state = WATCHDOG_INACTIVE; \ + (_the_watchdog)->routine = (_routine); \ + (_the_watchdog)->id = (_id); \ + (_the_watchdog)->user_data = (_user_data); \ + } + +/*PAGE + * + * _Watchdog_Is_active + * + */ + +#define _Watchdog_Is_active( _the_watchdog ) \ + ( (_the_watchdog)->state == WATCHDOG_ACTIVE ) + +/*PAGE + * + * _Watchdog_Activate + * + */ + +#define _Watchdog_Activate( _the_watchdog ) \ + (_the_watchdog)->state = WATCHDOG_ACTIVE + +/*PAGE + * + * _Watchdog_Deactivate + * + */ + +#define _Watchdog_Deactivate( _the_watchdog ) \ + (_the_watchdog)->state = WATCHDOG_REMOVE_IT + +/*PAGE + * + * _Watchdog_Tickle_ticks + * + */ + +#define _Watchdog_Tickle_ticks() \ + _Watchdog_Tickle( &_Watchdog_Ticks_chain ) + +/*PAGE + * + * _Watchdog_Tickle_seconds + * + */ + +#define _Watchdog_Tickle_seconds() \ + _Watchdog_Tickle( &_Watchdog_Seconds_chain ) + +/*PAGE + * + * _Watchdog_Insert_ticks + * + */ + +#define _Watchdog_Insert_ticks( _the_watchdog, _units ) \ + do { \ + (_the_watchdog)->initial = (_units); \ + _Watchdog_Insert( &_Watchdog_Ticks_chain, (_the_watchdog) ); \ + } while ( 0 ) + +/*PAGE + * + * _Watchdog_Insert_seconds + * + */ + +#define _Watchdog_Insert_seconds( _the_watchdog, _units ) \ + do { \ + (_the_watchdog)->initial = (_units); \ + _Watchdog_Insert( &_Watchdog_Seconds_chain, (_the_watchdog) ); \ + } while ( 0 ) + +/*PAGE + * + * _Watchdog_Adjust_seconds + * + */ + +#define _Watchdog_Adjust_seconds( _direction, _units ) \ + _Watchdog_Adjust( &_Watchdog_Seconds_chain, (_direction), (_units) ) + +/*PAGE + * + * _Watchdog_Adjust_ticks + * + */ + +#define _Watchdog_Adjust_ticks( _direction, _units ) \ + _Watchdog_Adjust( &_Watchdog_Ticks_chain, (_direction), (_units) ) + +/*PAGE + * + * _Watchdog_Reset + * + */ + +#define _Watchdog_Reset( _the_watchdog ) \ + { \ + (void) _Watchdog_Remove( (_the_watchdog) ); \ + _Watchdog_Insert( &_Watchdog_Ticks_chain, (_the_watchdog) ); \ + } + +/*PAGE + * + * _Watchdog_Next + * + */ + +#define _Watchdog_Next( _watchdog ) \ + ((Watchdog_Control *) (_watchdog)->Node.next) + +/*PAGE + * + * _Watchdog_Previous + * + */ + +#define _Watchdog_Previous( _watchdog ) \ + ((Watchdog_Control *) (_watchdog)->Node.previous) + +/*PAGE + * + * _Watchdog_First + * + */ + +#define _Watchdog_First( _header ) \ + ((Watchdog_Control *) (_header)->first) + +/*PAGE + * + * _Watchdog_Last + * + */ + +#define _Watchdog_Last( _header ) \ + ((Watchdog_Control *) (_header)->last) + +#endif +/* end of include file */ diff --git a/cpukit/score/macros/rtems/score/wkspace.inl b/cpukit/score/macros/rtems/score/wkspace.inl new file mode 100644 index 0000000000..5efe247fb1 --- /dev/null +++ b/cpukit/score/macros/rtems/score/wkspace.inl @@ -0,0 +1,39 @@ +/* wkspace.inl + * + * This file contains the macro implementation of the inlined routines + * from the RAM Workspace 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$ + */ + +#ifndef __WORKSPACE_inl +#define __WORKSPACE_inl + +/*PAGE + * + * _Workspace_Allocate + * + */ + +#define _Workspace_Allocate( _size ) \ + _Heap_Allocate( &_Workspace_Area, (_size) ) + +/*PAGE + * + * _Workspace_Free + * + */ + +#define _Workspace_Free( _block ) \ + _Heap_Free( &_Workspace_Area, (_block) ) + +#endif +/* end of include file */ diff --git a/cpukit/score/src/apiext.c b/cpukit/score/src/apiext.c new file mode 100644 index 0000000000..6e82b49a53 --- /dev/null +++ b/cpukit/score/src/apiext.c @@ -0,0 +1,105 @@ +/* apiext.c + * + * XXX + * + * 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/system.h> +#include <rtems/score/apiext.h> + +/*PAGE + * + * _API_extensions_Initialization + */ + +void _API_extensions_Initialization( void ) +{ + _Chain_Initialize_empty( &_API_extensions_List ); +} + +/*PAGE + * + * _API_extensions_Add + */ + +void _API_extensions_Add( + API_extensions_Control *the_extension +) +{ + _Chain_Append( &_API_extensions_List, &the_extension->Node ); +} + +/*PAGE + * + * _API_extensions_Run_predriver + */ + +void _API_extensions_Run_predriver( void ) +{ + Chain_Node *the_node; + API_extensions_Control *the_extension; + + for ( the_node = _API_extensions_List.first ; + !_Chain_Is_tail( &_API_extensions_List, the_node ) ; + the_node = the_node->next ) { + + the_extension = (API_extensions_Control *) the_node; + + if ( the_extension->predriver_hook ) + (*the_extension->predriver_hook)(); + } +} + +/*PAGE + * + * _API_extensions_Run_postdriver + */ + +void _API_extensions_Run_postdriver( void ) +{ + Chain_Node *the_node; + API_extensions_Control *the_extension; + + for ( the_node = _API_extensions_List.first ; + !_Chain_Is_tail( &_API_extensions_List, the_node ) ; + the_node = the_node->next ) { + + the_extension = (API_extensions_Control *) the_node; + + if ( the_extension->postdriver_hook ) + (*the_extension->postdriver_hook)(); + } +} + +/*PAGE + * + * _API_extensions_Run_postswitch + */ + +void _API_extensions_Run_postswitch( void ) +{ + Chain_Node *the_node; + API_extensions_Control *the_extension; + + for ( the_node = _API_extensions_List.first ; + !_Chain_Is_tail( &_API_extensions_List, the_node ) ; + the_node = the_node->next ) { + + the_extension = (API_extensions_Control *) the_node; + + if ( the_extension->postswitch_hook ) + (*the_extension->postswitch_hook)( _Thread_Executing ); + } +} + +/* end of file */ diff --git a/cpukit/score/src/chain.c b/cpukit/score/src/chain.c new file mode 100644 index 0000000000..5ef56ed5ad --- /dev/null +++ b/cpukit/score/src/chain.c @@ -0,0 +1,202 @@ +/* + * Chain Handler + * + * NOTE: + * + * The order of this file is to allow proper compilation due to the + * order of inlining required by the compiler. + * + * 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/system.h> +#include <rtems/score/address.h> +#include <rtems/score/chain.h> +#include <rtems/score/isr.h> + +/*PAGE + * + * _Chain_Initialize + * + * This kernel routine initializes a doubly linked chain. + * + * Input parameters: + * the_chain - pointer to chain header + * starting_address - starting address of first node + * number_nodes - number of nodes in chain + * node_size - size of node in bytes + * + * Output parameters: NONE + */ + +void _Chain_Initialize( + Chain_Control *the_chain, + void *starting_address, + unsigned32 number_nodes, + unsigned32 node_size +) +{ + unsigned32 count; + Chain_Node *current; + Chain_Node *next; + + count = number_nodes; + current = _Chain_Head( the_chain ); + the_chain->permanent_null = NULL; + next = (Chain_Node *)starting_address; + while ( count-- ) { + current->next = next; + next->previous = current; + current = next; + next = (Chain_Node *) + _Addresses_Add_offset( (void *) next, node_size ); + } + current->next = _Chain_Tail( the_chain ); + the_chain->last = current; +} + +/*PAGE + * + * _Chain_Get_first_unprotected + */ + +#ifndef USE_INLINES +Chain_Node *_Chain_Get_first_unprotected( + Chain_Control *the_chain +) +{ + Chain_Node *return_node; + Chain_Node *new_first; + + return_node = the_chain->first; + new_first = return_node->next; + the_chain->first = new_first; + new_first->previous = _Chain_Head( the_chain ); + + return return_node; +} +#endif /* USE_INLINES */ + +/*PAGE + * + * _Chain_Get + * + * This kernel routine returns a pointer to a node taken from the + * given chain. + * + * Input parameters: + * the_chain - pointer to chain header + * + * Output parameters: + * return_node - pointer to node in chain allocated + * CHAIN_END - if no nodes available + * + * INTERRUPT LATENCY: + * only case + */ + +Chain_Node *_Chain_Get( + Chain_Control *the_chain +) +{ + ISR_Level level; + Chain_Node *return_node; + + return_node = NULL; + _ISR_Disable( level ); + if ( !_Chain_Is_empty( the_chain ) ) + return_node = _Chain_Get_first_unprotected( the_chain ); + _ISR_Enable( level ); + return return_node; +} + +/*PAGE + * + * _Chain_Append + * + * This kernel routine puts a node on the end of the specified chain. + * + * Input parameters: + * the_chain - pointer to chain header + * node - address of node to put at rear of chain + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * only case + */ + +void _Chain_Append( + Chain_Control *the_chain, + Chain_Node *node +) +{ + ISR_Level level; + + _ISR_Disable( level ); + _Chain_Append_unprotected( the_chain, node ); + _ISR_Enable( level ); +} + +/*PAGE + * + * _Chain_Extract + * + * This kernel routine deletes the given node from a chain. + * + * Input parameters: + * node - pointer to node in chain to be deleted + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * only case + */ + +void _Chain_Extract( + Chain_Node *node +) +{ + ISR_Level level; + + _ISR_Disable( level ); + _Chain_Extract_unprotected( node ); + _ISR_Enable( level ); +} + +/*PAGE + * + * _Chain_Insert + * + * This kernel routine inserts a given node after a specified node + * a requested chain. + * + * Input parameters: + * after_node - pointer to node in chain to be inserted after + * node - pointer to node to be inserted + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * only case + */ + +void _Chain_Insert( + Chain_Node *after_node, + Chain_Node *node +) +{ + ISR_Level level; + + _ISR_Disable( level ); + _Chain_Insert_unprotected( after_node, node ); + _ISR_Enable( level ); +} diff --git a/cpukit/score/src/coremsg.c b/cpukit/score/src/coremsg.c new file mode 100644 index 0000000000..05e4fb799d --- /dev/null +++ b/cpukit/score/src/coremsg.c @@ -0,0 +1,432 @@ +/* + * CORE Message Queue Handler + * + * DESCRIPTION: + * + * This package is the implementation of the CORE Message Queue Handler. + * This core object provides task synchronization and communication functions + * via messages passed to queue objects. + * + * 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/system.h> +#include <rtems/score/chain.h> +#include <rtems/score/isr.h> +#include <rtems/score/object.h> +#include <rtems/score/coremsg.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/score/wkspace.h> +#include <rtems/score/mpci.h> + +/*PAGE + * + * _CORE_message_queue_Initialize + * + * This routine initializes a newly created message queue based on the + * specified data. + * + * Input parameters: + * the_message_queue - the message queue to initialize + * the_class - the API specific object class + * the_message_queue_attributes - the message queue's attributes + * maximum_pending_messages - maximum message and reserved buffer count + * maximum_message_size - maximum size of each message + * proxy_extract_callout - remote extract support + * + * Output parameters: + * TRUE - if the message queue is initialized + * FALSE - if the message queue is NOT initialized + */ + +boolean _CORE_message_queue_Initialize( + CORE_message_queue_Control *the_message_queue, + Objects_Classes the_class, + CORE_message_queue_Attributes *the_message_queue_attributes, + unsigned32 maximum_pending_messages, + unsigned32 maximum_message_size, + Thread_queue_Extract_callout proxy_extract_callout +) +{ + unsigned32 message_buffering_required; + unsigned32 allocated_message_size; + + the_message_queue->maximum_pending_messages = maximum_pending_messages; + the_message_queue->number_of_pending_messages = 0; + the_message_queue->maximum_message_size = maximum_message_size; + _CORE_message_queue_Set_notify( the_message_queue, NULL, NULL ); + + /* + * round size up to multiple of a ptr for chain init + */ + + allocated_message_size = maximum_message_size; + if (allocated_message_size & (sizeof(unsigned32) - 1)) { + allocated_message_size += sizeof(unsigned32); + allocated_message_size &= ~(sizeof(unsigned32) - 1); + } + + message_buffering_required = maximum_pending_messages * + (allocated_message_size + sizeof(CORE_message_queue_Buffer_control)); + + the_message_queue->message_buffers = (CORE_message_queue_Buffer *) + _Workspace_Allocate( message_buffering_required ); + + if (the_message_queue->message_buffers == 0) + return FALSE; + + _Chain_Initialize ( + &the_message_queue->Inactive_messages, + the_message_queue->message_buffers, + maximum_pending_messages, + allocated_message_size + sizeof( CORE_message_queue_Buffer_control ) + ); + + _Chain_Initialize_empty( &the_message_queue->Pending_messages ); + + _Thread_queue_Initialize( + &the_message_queue->Wait_queue, + the_class, + _CORE_message_queue_Is_priority( the_message_queue_attributes ) ? + THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, + STATES_WAITING_FOR_MESSAGE, + proxy_extract_callout, + CORE_MESSAGE_QUEUE_STATUS_TIMEOUT + ); + + return TRUE; +} + +/*PAGE + * + * _CORE_message_queue_Close + * + * This function closes a message by returning all allocated space and + * flushing the message_queue's task wait queue. + * + * Input parameters: + * the_message_queue - the message_queue to be flushed + * remote_extract_callout - function to invoke remotely + * status - status to pass to thread + * + * Output parameters: NONE + */ + +void _CORE_message_queue_Close( + CORE_message_queue_Control *the_message_queue, + Thread_queue_Flush_callout remote_extract_callout, + unsigned32 status +) +{ + + if ( the_message_queue->number_of_pending_messages != 0 ) + (void) _CORE_message_queue_Flush_support( the_message_queue ); + else + _Thread_queue_Flush( + &the_message_queue->Wait_queue, + remote_extract_callout, + status + ); + + (void) _Workspace_Free( the_message_queue->message_buffers ); + +} + +/*PAGE + * + * _CORE_message_queue_Flush + * + * This function flushes the message_queue's task wait queue. The number + * of messages flushed from the queue is returned. + * + * Input parameters: + * the_message_queue - the message_queue to be flushed + * + * Output parameters: + * returns - the number of messages flushed from the queue + */ + +unsigned32 _CORE_message_queue_Flush( + CORE_message_queue_Control *the_message_queue +) +{ + if ( the_message_queue->number_of_pending_messages != 0 ) + return _CORE_message_queue_Flush_support( the_message_queue ); + else + return 0; +} + +/*PAGE + * + * _CORE_message_queue_Broadcast + * + * This function sends a message for every thread waiting on the queue and + * returns the number of threads made ready by the message. + * + * Input parameters: + * the_message_queue - message is submitted to this message queue + * buffer - pointer to message buffer + * size - size in bytes of message to send + * id - id of message queue + * api_message_queue_mp_support - api specific mp support callout + * count - area to store number of threads made ready + * + * Output parameters: + * count - number of threads made ready + * CORE_MESSAGE_QUEUE_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +CORE_message_queue_Status _CORE_message_queue_Broadcast( + CORE_message_queue_Control *the_message_queue, + void *buffer, + unsigned32 size, + Objects_Id id, + CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, + unsigned32 *count +) +{ + Thread_Control *the_thread; + unsigned32 number_broadcasted; + Thread_Wait_information *waitp; + unsigned32 constrained_size; + + number_broadcasted = 0; + while ((the_thread = _Thread_queue_Dequeue(&the_message_queue->Wait_queue))) { + waitp = &the_thread->Wait; + number_broadcasted += 1; + + constrained_size = size; + if ( size > the_message_queue->maximum_message_size ) + constrained_size = the_message_queue->maximum_message_size; + + _CORE_message_queue_Copy_buffer( + buffer, + waitp->return_argument, + constrained_size + ); + + *(unsigned32 *)the_thread->Wait.return_argument_1 = size; + + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) + (*api_message_queue_mp_support) ( the_thread, id ); + + } + *count = number_broadcasted; + return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; +} + +/*PAGE + * + * _CORE_message_queue_Seize + * + * This kernel routine dequeues a message, copies the message buffer to + * a given destination buffer, and frees the message buffer to the + * inactive message pool. The thread will be blocked if wait is TRUE, + * otherwise an error will be given to the thread if no messages are available. + * + * Input parameters: + * the_message_queue - pointer to message queue + * id - id of object we are waitig on + * buffer - pointer to message buffer to be filled + * size - pointer to the size of buffer to be filled + * wait - TRUE if wait is allowed, FALSE otherwise + * timeout - time to wait for a message + * + * Output parameters: NONE + * + * NOTE: Dependent on BUFFER_LENGTH + * + * INTERRUPT LATENCY: + * available + * wait + */ + +void _CORE_message_queue_Seize( + CORE_message_queue_Control *the_message_queue, + Objects_Id id, + void *buffer, + unsigned32 *size, + boolean wait, + Watchdog_Interval timeout +) +{ + ISR_Level level; + CORE_message_queue_Buffer_control *the_message; + Thread_Control *executing; + + executing = _Thread_Executing; + executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; + _ISR_Disable( level ); + if ( the_message_queue->number_of_pending_messages != 0 ) { + the_message_queue->number_of_pending_messages -= 1; + + the_message = _CORE_message_queue_Get_pending_message( the_message_queue ); + _ISR_Enable( level ); + *size = the_message->Contents.size; + _CORE_message_queue_Copy_buffer(the_message->Contents.buffer,buffer,*size ); + _CORE_message_queue_Free_message_buffer(the_message_queue, the_message ); + return; + } + + if ( !wait ) { + _ISR_Enable( level ); + executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT; + return; + } + + _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue ); + executing->Wait.queue = &the_message_queue->Wait_queue; + executing->Wait.id = id; + executing->Wait.return_argument = (void *)buffer; + executing->Wait.return_argument_1 = (void *)size; + _ISR_Enable( level ); + + _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout ); +} + +/*PAGE + * + * _CORE_message_queue_Flush_support + * + * This message handler routine removes all messages from a message queue + * and returns them to the inactive message pool. The number of messages + * flushed from the queue is returned + * + * Input parameters: + * the_message_queue - pointer to message queue + * + * Output parameters: + * returns - number of messages placed on inactive chain + * + * INTERRUPT LATENCY: + * only case + */ + +unsigned32 _CORE_message_queue_Flush_support( + CORE_message_queue_Control *the_message_queue +) +{ + ISR_Level level; + Chain_Node *inactive_first; + Chain_Node *message_queue_first; + Chain_Node *message_queue_last; + unsigned32 count; + + _ISR_Disable( level ); + inactive_first = the_message_queue->Inactive_messages.first; + message_queue_first = the_message_queue->Pending_messages.first; + message_queue_last = the_message_queue->Pending_messages.last; + + the_message_queue->Inactive_messages.first = message_queue_first; + message_queue_last->next = inactive_first; + inactive_first->previous = message_queue_last; + message_queue_first->previous = + _Chain_Head( &the_message_queue->Inactive_messages ); + + _Chain_Initialize_empty( &the_message_queue->Pending_messages ); + + count = the_message_queue->number_of_pending_messages; + the_message_queue->number_of_pending_messages = 0; + _ISR_Enable( level ); + return count; +} + +/*PAGE + * + * _CORE_message_queue_Submit + * + * This routine implements the send and urgent message functions. It + * processes a message that is to be submitted to the designated + * message queue. The message will either be processed as a + * send message which it will be inserted at the rear of the queue + * or it will be processed as an urgent message which will be inserted + * at the front of the queue. + * + * Input parameters: + * the_message_queue - message is submitted to this message queue + * buffer - pointer to message buffer + * size - size in bytes of message to send + * id - id of message queue + * api_message_queue_mp_support - api specific mp support callout + * submit_type - send or urgent message + * + * Output parameters: + * CORE_MESSAGE_QUEUE_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +CORE_message_queue_Status _CORE_message_queue_Submit( + CORE_message_queue_Control *the_message_queue, + void *buffer, + unsigned32 size, + Objects_Id id, + CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, + CORE_message_queue_Submit_types submit_type +) +{ + CORE_message_queue_Buffer_control *the_message; + Thread_Control *the_thread; + + if ( size > the_message_queue->maximum_message_size ) + return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE; + + /* + * Is there a thread currently waiting on this message queue? + */ + + the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue ); + if ( the_thread ) + { + _CORE_message_queue_Copy_buffer( + buffer, + the_thread->Wait.return_argument, + size + ); + *(unsigned32 *)the_thread->Wait.return_argument_1 = size; + + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) + (*api_message_queue_mp_support) ( the_thread, id ); + + return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; + } + + /* + * No one waiting on this one currently. + * Allocate a message buffer and store it away + */ + + if ( the_message_queue->number_of_pending_messages == + the_message_queue->maximum_pending_messages ) { + return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY; + } + + the_message = _CORE_message_queue_Allocate_message_buffer(the_message_queue); + if ( the_message == 0) + return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED; + + _CORE_message_queue_Copy_buffer( buffer, the_message->Contents.buffer, size ); + the_message->Contents.size = size; + + the_message_queue->number_of_pending_messages += 1; + + switch ( submit_type ) { + case CORE_MESSAGE_QUEUE_SEND_REQUEST: + _CORE_message_queue_Append( the_message_queue, the_message ); + break; + case CORE_MESSAGE_QUEUE_URGENT_REQUEST: + _CORE_message_queue_Prepend( the_message_queue, the_message ); + break; + } + + return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; +} diff --git a/cpukit/score/src/coremutex.c b/cpukit/score/src/coremutex.c new file mode 100644 index 0000000000..a0c3fd0264 --- /dev/null +++ b/cpukit/score/src/coremutex.c @@ -0,0 +1,269 @@ +/* + * Mutex Handler + * + * DESCRIPTION: + * + * This package is the implementation of the Mutex Handler. + * This handler provides synchronization and mutual exclusion capabilities. + * + * 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/system.h> +#include <rtems/score/isr.h> +#include <rtems/score/coremutex.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> + +/*PAGE + * + * _CORE_mutex_Initialize + * + * This routine initializes a mutex at create time and set the control + * structure according to the values passed. + * + * Input parameters: + * the_mutex - the mutex control block to initialize + * the_class - the API class of the object + * the_mutex_attributes - the mutex attributes specified at create time + * initial_lock - mutex initial lock or unlocked status + * proxy_extract_callout - MP specific extract callout + * + * Output parameters: NONE + */ + +void _CORE_mutex_Initialize( + CORE_mutex_Control *the_mutex, + Objects_Classes the_class, + CORE_mutex_Attributes *the_mutex_attributes, + unsigned32 initial_lock, + Thread_queue_Extract_callout proxy_extract_callout +) +{ + +/* Add this to the RTEMS environment later ????????? + rtems_assert( initial_lock == CORE_MUTEX_LOCKED || + initial_lock == CORE_MUTEX_UNLOCKED ); + */ + + the_mutex->Attributes = *the_mutex_attributes; + the_mutex->lock = initial_lock; + + if ( initial_lock == CORE_MUTEX_LOCKED ) { + the_mutex->nest_count = 1; + the_mutex->holder = _Thread_Executing; + the_mutex->holder_id = _Thread_Executing->Object.id; + _Thread_Executing->resource_count++; + } else { + the_mutex->nest_count = 0; + the_mutex->holder = NULL; + the_mutex->holder_id = 0; + } + + _Thread_queue_Initialize( + &the_mutex->Wait_queue, + the_class, + _CORE_mutex_Is_priority( the_mutex_attributes ) ? + THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, + STATES_WAITING_FOR_MUTEX, + proxy_extract_callout, + CORE_MUTEX_TIMEOUT + ); +} + +/*PAGE + * + * _CORE_mutex_Seize + * + * This routine attempts to allocate a mutex to the calling thread. + * + * Input parameters: + * the_mutex - pointer to mutex control block + * id - id of object to wait on + * wait - TRUE if wait is allowed, FALSE otherwise + * timeout - number of ticks to wait (0 means forever) + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * available + * wait + */ + +void _CORE_mutex_Seize( + CORE_mutex_Control *the_mutex, + Objects_Id id, + boolean wait, + Watchdog_Interval timeout +) +{ + Thread_Control *executing; + ISR_Level level; + + executing = _Thread_Executing; + executing->Wait.return_code = CORE_MUTEX_STATUS_SUCCESSFUL; + _ISR_Disable( level ); + if ( ! _CORE_mutex_Is_locked( the_mutex ) ) { + the_mutex->lock = CORE_MUTEX_LOCKED; + the_mutex->holder = executing; + the_mutex->holder_id = executing->Object.id; + the_mutex->nest_count = 1; + executing->resource_count++; + _ISR_Enable( level ); + return; + } + + if ( _Objects_Are_ids_equal( + _Thread_Executing->Object.id, the_mutex->holder_id ) ) { + if ( _CORE_mutex_Is_nesting_allowed( &the_mutex->Attributes ) ) + the_mutex->nest_count++; + else + executing->Wait.return_code = CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED; + + _ISR_Enable( level ); + return; + } + + if ( !wait ) { + _ISR_Enable( level ); + executing->Wait.return_code = CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT; + return; + } + + _Thread_queue_Enter_critical_section( &the_mutex->Wait_queue ); + executing->Wait.queue = &the_mutex->Wait_queue; + executing->Wait.id = id; + _ISR_Enable( level ); + + if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) && + the_mutex->holder->current_priority > + _Thread_Executing->current_priority ) { + _Thread_Change_priority( + the_mutex->holder, _Thread_Executing->current_priority ); + } + + _Thread_queue_Enqueue( &the_mutex->Wait_queue, timeout ); +} + +/* + * _CORE_mutex_Surrender + * + * DESCRIPTION: + * + * This routine frees a unit to the mutex. If a task was blocked waiting for + * a unit from this mutex, then that task will be readied and the unit + * given to that task. Otherwise, the unit will be returned to the mutex. + * + * Input parameters: + * the_mutex - the mutex to be flushed + * id - id of parent mutex + * api_mutex_mp_support - api dependent MP support actions + * + * Output parameters: + * CORE_MUTEX_STATUS_SUCCESSFUL - if successful + * core error code - if unsuccessful + */ + +CORE_mutex_Status _CORE_mutex_Surrender( + CORE_mutex_Control *the_mutex, + Objects_Id id, + CORE_mutex_API_mp_support_callout api_mutex_mp_support +) +{ + Thread_Control *the_thread; + + if ( !_Objects_Are_ids_equal( + _Thread_Executing->Object.id, the_mutex->holder_id ) ) + return( CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE ); + + the_mutex->nest_count--; + + if ( the_mutex->nest_count != 0 ) + return( CORE_MUTEX_STATUS_SUCCESSFUL ); + + _Thread_Executing->resource_count--; + the_mutex->holder = NULL; + the_mutex->holder_id = 0; + + /* + * Whether or not someone is waiting for the mutex, an + * inherited priority must be lowered if this is the last + * mutex (i.e. resource) this task has. + */ + + if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) && + _Thread_Executing->resource_count == 0 && + _Thread_Executing->real_priority != + _Thread_Executing->current_priority ) { + _Thread_Change_priority( + _Thread_Executing, + _Thread_Executing->real_priority + ); + } + + if ( ( the_thread = _Thread_queue_Dequeue( &the_mutex->Wait_queue ) ) ) { + + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) { + + the_mutex->holder = NULL; + the_mutex->holder_id = the_thread->Object.id; + the_mutex->nest_count = 1; + + ( *api_mutex_mp_support)( the_thread, id ); + + } else { + + the_mutex->holder = the_thread; + the_mutex->holder_id = the_thread->Object.id; + the_thread->resource_count++; + the_mutex->nest_count = 1; + + /* + * No special action for priority inheritance because the_thread + * is guaranteed to be the highest priority thread waiting for + * the mutex. + */ + } + } else + the_mutex->lock = CORE_MUTEX_UNLOCKED; + + return( CORE_MUTEX_STATUS_SUCCESSFUL ); +} + +/*PAGE + * + * _CORE_mutex_Flush + * + * This function a flushes the mutex's task wait queue. + * + * Input parameters: + * the_mutex - the mutex to be flushed + * remote_extract_callout - function to invoke remotely + * status - status to pass to thread + * + * Output parameters: NONE + */ + +void _CORE_mutex_Flush( + CORE_mutex_Control *the_mutex, + Thread_queue_Flush_callout remote_extract_callout, + unsigned32 status +) +{ + + _Thread_queue_Flush( + &the_mutex->Wait_queue, + remote_extract_callout, + status + ); + +} diff --git a/cpukit/score/src/coresem.c b/cpukit/score/src/coresem.c new file mode 100644 index 0000000000..0e55926304 --- /dev/null +++ b/cpukit/score/src/coresem.c @@ -0,0 +1,184 @@ +/* + * CORE Semaphore Handler + * + * DESCRIPTION: + * + * This package is the implementation of the CORE Semaphore Handler. + * This core object utilizes standard Dijkstra counting semaphores to provide + * synchronization and mutual exclusion capabilities. + * + * 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/system.h> +#include <rtems/score/isr.h> +#include <rtems/score/coresem.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> +#include <rtems/score/mpci.h> + +/*PAGE + * + * CORE_semaphore_Initialize + * + * This function initialize a semaphore and sets the initial value based + * on the given count. + * + * Input parameters: + * the_semaphore - the semaphore control block to initialize + * the_class - the API class of the object + * the_semaphore_attributes - the attributes specified at create time + * initial_value - semaphore's initial value + * proxy_extract_callout - MP specific extract callout + * + * Output parameters: NONE + */ + +void _CORE_semaphore_Initialize( + CORE_semaphore_Control *the_semaphore, + Objects_Classes the_class, + CORE_semaphore_Attributes *the_semaphore_attributes, + unsigned32 initial_value, + Thread_queue_Extract_callout proxy_extract_callout +) +{ + + the_semaphore->Attributes = *the_semaphore_attributes; + the_semaphore->count = initial_value; + + _Thread_queue_Initialize( + &the_semaphore->Wait_queue, + the_class, + _CORE_semaphore_Is_priority( the_semaphore_attributes ) ? + THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO, + STATES_WAITING_FOR_SEMAPHORE, + proxy_extract_callout, + CORE_SEMAPHORE_TIMEOUT + ); +} + +/*PAGE + * + * _CORE_semaphore_Surrender + * + * Input parameters: + * the_semaphore - the semaphore to be flushed + * id - id of parent semaphore + * api_semaphore_mp_support - api dependent MP support actions + * + * Output parameters: + * CORE_SEMAPHORE_STATUS_SUCCESSFUL - if successful + * core error code - if unsuccessful + * + * Output parameters: + */ + +CORE_semaphore_Status _CORE_semaphore_Surrender( + CORE_semaphore_Control *the_semaphore, + Objects_Id id, + CORE_semaphore_API_mp_support_callout api_semaphore_mp_support +) +{ + Thread_Control *the_thread; + + if ( (the_thread = _Thread_queue_Dequeue(&the_semaphore->Wait_queue)) ) { + + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) + (*api_semaphore_mp_support) ( the_thread, id ); + + } else + the_semaphore->count += 1; + + return( CORE_SEMAPHORE_STATUS_SUCCESSFUL ); +} + +/*PAGE + * + * _CORE_semaphore_Seize + * + * This routine attempts to allocate a core semaphore to the calling thread. + * + * Input parameters: + * the_semaphore - pointer to semaphore control block + * id - id of object to wait on + * wait - TRUE if wait is allowed, FALSE otherwise + * timeout - number of ticks to wait (0 means forever) + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * available + * wait + */ + +void _CORE_semaphore_Seize( + CORE_semaphore_Control *the_semaphore, + Objects_Id id, + boolean wait, + Watchdog_Interval timeout +) +{ + Thread_Control *executing; + ISR_Level level; + + executing = _Thread_Executing; + executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL; + _ISR_Disable( level ); + if ( the_semaphore->count != 0 ) { + the_semaphore->count -= 1; + _ISR_Enable( level ); + return; + } + + if ( !wait ) { + _ISR_Enable( level ); + executing->Wait.return_code = CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT; + return; + } + + _Thread_queue_Enter_critical_section( &the_semaphore->Wait_queue ); + executing->Wait.queue = &the_semaphore->Wait_queue; + executing->Wait.id = id; + _ISR_Enable( level ); + + _Thread_queue_Enqueue( &the_semaphore->Wait_queue, timeout ); +} + + +/*PAGE + * + * _CORE_semaphore_Flush + * + * This function a flushes the semaphore's task wait queue. + * + * Input parameters: + * the_semaphore - the semaphore to be flushed + * remote_extract_callout - function to invoke remotely + * status - status to pass to thread + * + * Output parameters: NONE + */ + +void _CORE_semaphore_Flush( + CORE_semaphore_Control *the_semaphore, + Thread_queue_Flush_callout remote_extract_callout, + unsigned32 status +) +{ + + _Thread_queue_Flush( + &the_semaphore->Wait_queue, + remote_extract_callout, + status + ); + +} diff --git a/cpukit/score/src/coretod.c b/cpukit/score/src/coretod.c new file mode 100644 index 0000000000..1a11034ceb --- /dev/null +++ b/cpukit/score/src/coretod.c @@ -0,0 +1,235 @@ +/* + * Time of Day (TOD) 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/system.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <rtems/score/tod.h> +#include <rtems/score/watchdog.h> + +/*PAGE + * + * _TOD_Handler_initialization + * + * This routine initializes the time of day handler. + * + * Input parameters: + * microseconds_per_tick - microseconds between clock ticks + * + * Output parameters: NONE + */ + +void _TOD_Handler_initialization( + unsigned32 microseconds_per_tick +) +{ + _TOD_Microseconds_per_tick = microseconds_per_tick; + + _TOD_Ticks_since_boot = 0; + _TOD_Seconds_since_epoch = 0; + + _TOD_Current.year = TOD_BASE_YEAR; + _TOD_Current.month = 1; + _TOD_Current.day = 1; + _TOD_Current.hour = 0; + _TOD_Current.minute = 0; + _TOD_Current.second = 0; + _TOD_Current.ticks = 0; + + if ( microseconds_per_tick == 0 ) + _TOD_Ticks_per_second = 0; + else + _TOD_Ticks_per_second = + TOD_MICROSECONDS_PER_SECOND / microseconds_per_tick; + + _Watchdog_Initialize( &_TOD_Seconds_watchdog, _TOD_Tickle, 0, NULL ); +} + +/*PAGE + * + * _TOD_Set + * + * This rountine sets the current date and time with the specified + * new date and time structure. + * + * Input parameters: + * the_tod - pointer to the time and date structure + * seconds_since_epoch - seconds since system epoch + * + * Output parameters: NONE + */ + +void _TOD_Set( + TOD_Control *the_tod, + Watchdog_Interval seconds_since_epoch +) +{ + Watchdog_Interval ticks_until_next_second; + + _Thread_Disable_dispatch(); + _TOD_Deactivate(); + + if ( seconds_since_epoch < _TOD_Seconds_since_epoch ) + _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, + _TOD_Seconds_since_epoch - seconds_since_epoch ); + else + _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, + seconds_since_epoch - _TOD_Seconds_since_epoch ); + + ticks_until_next_second = _TOD_Ticks_per_second; + if ( ticks_until_next_second > _TOD_Current.ticks ) + ticks_until_next_second -= _TOD_Current.ticks; + + _TOD_Current = *the_tod; + _TOD_Seconds_since_epoch = seconds_since_epoch; + _TOD_Activate( ticks_until_next_second ); + + _Thread_Enable_dispatch(); +} + +/*PAGE + * + * _TOD_Validate + * + * This kernel routine checks the validity of a date and time structure. + * + * Input parameters: + * the_tod - pointer to a time and date structure + * + * Output parameters: + * TRUE - if the date, time, and tick are valid + * FALSE - if the the_tod is invalid + * + * NOTE: This routine only works for leap-years through 2099. + */ + +boolean _TOD_Validate( + TOD_Control *the_tod +) +{ + unsigned32 days_in_month; + + if ((the_tod->ticks >= _TOD_Ticks_per_second) || + (the_tod->second >= TOD_SECONDS_PER_MINUTE) || + (the_tod->minute >= TOD_MINUTES_PER_HOUR) || + (the_tod->hour >= TOD_HOURS_PER_DAY) || + (the_tod->month == 0) || + (the_tod->month > TOD_MONTHS_PER_YEAR) || + (the_tod->year < TOD_BASE_YEAR) || + (the_tod->day == 0) ) + return FALSE; + + if ( (the_tod->year % 4) == 0 ) + days_in_month = _TOD_Days_per_month[ 1 ][ the_tod->month ]; + else + days_in_month = _TOD_Days_per_month[ 0 ][ the_tod->month ]; + + if ( the_tod->day > days_in_month ) + return FALSE; + + return TRUE; +} + +/*PAGE + * + * _TOD_To_seconds + * + * This routine returns the seconds from the epoch until the + * current date and time. + * + * Input parameters: + * the_tod - pointer to the time and date structure + * + * Output parameters: + * returns - seconds since epoch until the_tod + */ + +unsigned32 _TOD_To_seconds( + TOD_Control *the_tod +) +{ + unsigned32 time; + unsigned32 year_mod_4; + + time = the_tod->day - 1; + year_mod_4 = the_tod->year & 3; + + if ( year_mod_4 == 0 ) + time += _TOD_Days_to_date[ 1 ][ the_tod->month ]; + else + time += _TOD_Days_to_date[ 0 ][ the_tod->month ]; + + time += ( (the_tod->year - TOD_BASE_YEAR) / 4 ) * + ( (TOD_DAYS_PER_YEAR * 4) + 1); + + time += _TOD_Days_since_last_leap_year[ year_mod_4 ]; + + time *= TOD_SECONDS_PER_DAY; + + time += ((the_tod->hour * TOD_MINUTES_PER_HOUR) + the_tod->minute) + * TOD_SECONDS_PER_MINUTE; + + time += the_tod->second; + + return( time ); +} + +/*PAGE + * + * _TOD_Tickle + * + * This routine updates the calendar time and tickles the + * per second watchdog timer chain. + * + * Input parameters: + * ignored - this parameter is ignored + * + * Output parameters: NONE + * + * NOTE: This routine only works for leap-years through 2099. + */ + +void _TOD_Tickle( + Objects_Id id, + void *ignored +) +{ + unsigned32 leap; + + _TOD_Current.ticks = 0; + ++_TOD_Seconds_since_epoch; + if ( ++_TOD_Current.second >= TOD_SECONDS_PER_MINUTE ) { + _TOD_Current.second = 0; + if ( ++_TOD_Current.minute >= TOD_MINUTES_PER_HOUR ) { + _TOD_Current.minute = 0; + if ( ++_TOD_Current.hour >= TOD_HOURS_PER_DAY ) { + _TOD_Current.hour = 0; + if ( _TOD_Current.year & 0x3 ) leap = 0; + else leap = 1; + if ( ++_TOD_Current.day > + _TOD_Days_per_month[ leap ][ _TOD_Current.month ]) { + _TOD_Current.day = 1; + if ( ++_TOD_Current.month > TOD_MONTHS_PER_YEAR ) { + _TOD_Current.month = 1; + _TOD_Current.year++; + } + } + } + } + } + + _Watchdog_Tickle_seconds(); + _Watchdog_Insert_ticks( &_TOD_Seconds_watchdog, _TOD_Ticks_per_second ); +} diff --git a/cpukit/score/src/heap.c b/cpukit/score/src/heap.c new file mode 100644 index 0000000000..11d8a31cee --- /dev/null +++ b/cpukit/score/src/heap.c @@ -0,0 +1,537 @@ +/* + * Heap 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/system.h> +#include <rtems/score/sysstate.h> +#include <rtems/score/heap.h> + +/*PAGE + * + * _Heap_Initialize + * + * This kernel routine initializes a heap. + * + * Input parameters: + * the_heap - pointer to heap header + * starting_address - starting address of heap + * size - size of heap + * page_size - allocatable unit of memory + * + * Output parameters: + * returns - maximum memory available if RTEMS_SUCCESSFUL + * 0 - otherwise + * + * This is what a heap looks like in memory immediately + * after initialization: + * + * +--------------------------------+ + * 0 | size = 0 | status = used | a.k.a. dummy back flag + * +--------------------------------+ + * 4 | size = size-8 | status = free | a.k.a. front flag + * +--------------------------------+ + * 8 | next = PERM HEAP_TAIL | + * +--------------------------------+ + * 12 | previous = PERM HEAP_HEAD | + * +--------------------------------+ + * | | + * | memory available | + * | for allocation | + * | | + * +--------------------------------+ + * size - 8 | size = size-8 | status = free | a.k.a. back flag + * +--------------------------------+ + * size - 4 | size = 0 | status = used | a.k.a. dummy front flag + * +--------------------------------+ + */ + +unsigned32 _Heap_Initialize( + Heap_Control *the_heap, + void *starting_address, + unsigned32 size, + unsigned32 page_size +) +{ + Heap_Block *the_block; + unsigned32 the_size; + + if ( !_Heap_Is_page_size_valid( page_size ) || + (size < HEAP_MINIMUM_SIZE) ) + return 0; + + the_heap->page_size = page_size; + the_size = size - HEAP_OVERHEAD; + + the_block = (Heap_Block *) starting_address; + the_block->back_flag = HEAP_DUMMY_FLAG; + the_block->front_flag = the_size; + the_block->next = _Heap_Tail( the_heap ); + the_block->previous = _Heap_Head( the_heap ); + + the_heap->start = the_block; + the_heap->first = the_block; + the_heap->permanent_null = NULL; + the_heap->last = the_block; + + the_block = _Heap_Next_block( the_block ); + the_block->back_flag = the_size; + the_block->front_flag = HEAP_DUMMY_FLAG; + the_heap->final = the_block; + + return ( the_size - HEAP_BLOCK_USED_OVERHEAD ); +} + +/*PAGE + * + * _Heap_Extend + * + * This routine grows the_heap memory area using the size bytes which + * begin at starting_address. + * + * Input parameters: + * the_heap - pointer to heap header. + * starting_address - pointer to the memory area. + * size - size in bytes of the memory block to allocate. + * + * Output parameters: + * *amount_extended - amount of memory added to the_heap + */ + +Heap_Extend_status _Heap_Extend( + Heap_Control *the_heap, + void *starting_address, + unsigned32 size, + unsigned32 *amount_extended +) +{ + Heap_Block *the_block; + unsigned32 *p; + + /* + * The overhead was taken from the original heap memory. + */ + + Heap_Block *old_final; + Heap_Block *new_final; + + /* + * There are five possibilities for the location of starting + * address: + * + * 1. non-contiguous lower address (NOT SUPPORTED) + * 2. contiguous lower address (NOT SUPPORTED) + * 3. in the heap (ERROR) + * 4. contiguous higher address (SUPPORTED) + * 5. non-contiguous higher address (NOT SUPPORTED) + * + * As noted, this code only supports (4). + */ + + if ( starting_address >= (void *) the_heap->start && /* case 3 */ + starting_address <= (void *) the_heap->final + ) + return HEAP_EXTEND_ERROR; + + if ( starting_address < (void *) the_heap->start ) { /* cases 1 and 2 */ + + return HEAP_EXTEND_NOT_IMPLEMENTED; /* cases 1 and 2 */ + + } else { /* cases 4 and 5 */ + + the_block = (Heap_Block *) (starting_address - HEAP_OVERHEAD); + if ( the_block != the_heap->final ) + return HEAP_EXTEND_NOT_IMPLEMENTED; /* case 5 */ + } + + /* + * Currently only case 4 should make it to this point. + * The basic trick is to make the extend area look like a used + * block and free it. + */ + + *amount_extended = size; + + old_final = the_heap->final; + new_final = _Addresses_Add_offset( old_final, size ); + /* SAME AS: _Addresses_Add_offset( starting_address, size-HEAP_OVERHEAD ); */ + + the_heap->final = new_final; + + old_final->front_flag = + new_final->back_flag = _Heap_Build_flag( size, HEAP_BLOCK_USED ); + new_final->front_flag = HEAP_DUMMY_FLAG; + + /* + * Must pass in address of "user" area + * So add in the offset field. + */ + + p = (unsigned32 *) &old_final->next; + *p = sizeof(unsigned32); + p++; + _Heap_Free( the_heap, p ); + + return HEAP_EXTEND_SUCCESSFUL; +} + +/*PAGE + * + * _Heap_Allocate + * + * This kernel routine allocates the requested size of memory + * from the specified heap. + * + * Input parameters: + * the_heap - pointer to heap header. + * size - size in bytes of the memory block to allocate. + * + * Output parameters: + * returns - starting address of memory block allocated + */ + +void *_Heap_Allocate( + Heap_Control *the_heap, + unsigned32 size +) +{ + unsigned32 excess; + unsigned32 the_size; + Heap_Block *the_block; + Heap_Block *next_block; + Heap_Block *temporary_block; + void *ptr; + unsigned32 offset; + + excess = size % the_heap->page_size; + the_size = size + the_heap->page_size + HEAP_BLOCK_USED_OVERHEAD; + + if ( excess ) + the_size += the_heap->page_size - excess; + + if ( the_size < sizeof( Heap_Block ) ) + the_size = sizeof( Heap_Block ); + + for ( the_block = the_heap->first; + ; + the_block = the_block->next ) { + if ( the_block == _Heap_Tail( the_heap ) ) + return( NULL ); + if ( the_block->front_flag >= the_size ) + break; + } + + if ( (the_block->front_flag - the_size) > + (the_heap->page_size + HEAP_BLOCK_USED_OVERHEAD) ) { + the_block->front_flag -= the_size; + next_block = _Heap_Next_block( the_block ); + next_block->back_flag = the_block->front_flag; + + temporary_block = _Heap_Block_at( next_block, the_size ); + temporary_block->back_flag = + next_block->front_flag = _Heap_Build_flag( the_size, + HEAP_BLOCK_USED ); + ptr = _Heap_Start_of_user_area( next_block ); + } else { + next_block = _Heap_Next_block( the_block ); + next_block->back_flag = _Heap_Build_flag( the_block->front_flag, + HEAP_BLOCK_USED ); + the_block->front_flag = next_block->back_flag; + the_block->next->previous = the_block->previous; + the_block->previous->next = the_block->next; + ptr = _Heap_Start_of_user_area( the_block ); + } + + /* + * round ptr up to a multiple of page size + * Have to save the bump amount in the buffer so that free can figure it out + */ + + offset = the_heap->page_size - (((unsigned32) ptr) & (the_heap->page_size - 1)); + ptr += offset; + *(((unsigned32 *) ptr) - 1) = offset; + +#ifdef RTEMS_DEBUG + { + unsigned32 ptr_u32; + ptr_u32 = (unsigned32) ptr; + if (ptr_u32 & (the_heap->page_size - 1)) + abort(); + } +#endif + + return ptr; +} + +/*PAGE + * + * _Heap_Size_of_user_area + * + * This kernel routine returns the size of the memory area + * given heap block. + * + * Input parameters: + * the_heap - pointer to heap header + * starting_address - starting address of the memory block to free. + * size - pointer to size of area + * + * Output parameters: + * size - size of area filled in + * TRUE - if starting_address is valid heap address + * FALSE - if starting_address is invalid heap address + */ + +boolean _Heap_Size_of_user_area( + Heap_Control *the_heap, + void *starting_address, + unsigned32 *size +) +{ + Heap_Block *the_block; + Heap_Block *next_block; + unsigned32 the_size; + + the_block = _Heap_User_block_at( starting_address ); + + if ( !_Heap_Is_block_in( the_heap, the_block ) || + _Heap_Is_block_free( the_block ) ) + return( FALSE ); + + the_size = _Heap_Block_size( the_block ); + next_block = _Heap_Block_at( the_block, the_size ); + + if ( !_Heap_Is_block_in( the_heap, next_block ) || + (the_block->front_flag != next_block->back_flag) ) + return( FALSE ); + + *size = the_size; + return( TRUE ); +} + +/*PAGE + * + * _Heap_Free + * + * This kernel routine returns the memory designated by the + * given heap and given starting address to the memory pool. + * + * Input parameters: + * the_heap - pointer to heap header + * starting_address - starting address of the memory block to free. + * + * Output parameters: + * TRUE - if starting_address is valid heap address + * FALSE - if starting_address is invalid heap address + */ + +boolean _Heap_Free( + Heap_Control *the_heap, + void *starting_address +) +{ + Heap_Block *the_block; + Heap_Block *next_block; + Heap_Block *new_next_block; + Heap_Block *previous_block; + Heap_Block *temporary_block; + unsigned32 the_size; + + the_block = _Heap_User_block_at( starting_address ); + + if ( !_Heap_Is_block_in( the_heap, the_block ) || + _Heap_Is_block_free( the_block ) ) { + return( FALSE ); + } + + the_size = _Heap_Block_size( the_block ); + next_block = _Heap_Block_at( the_block, the_size ); + + if ( !_Heap_Is_block_in( the_heap, next_block ) || + (the_block->front_flag != next_block->back_flag) ) { + return( FALSE ); + } + + if ( _Heap_Is_previous_block_free( the_block ) ) { + previous_block = _Heap_Previous_block( the_block ); + + if ( !_Heap_Is_block_in( the_heap, previous_block ) ) { + return( FALSE ); + } + + if ( _Heap_Is_block_free( next_block ) ) { /* coalesce both */ + previous_block->front_flag += next_block->front_flag + the_size; + temporary_block = _Heap_Next_block( previous_block ); + temporary_block->back_flag = previous_block->front_flag; + next_block->next->previous = next_block->previous; + next_block->previous->next = next_block->next; + } + else { /* coalesce prev */ + previous_block->front_flag = + next_block->back_flag = previous_block->front_flag + the_size; + } + } + else if ( _Heap_Is_block_free( next_block ) ) { /* coalesce next */ + the_block->front_flag = the_size + next_block->front_flag; + new_next_block = _Heap_Next_block( the_block ); + new_next_block->back_flag = the_block->front_flag; + the_block->next = next_block->next; + the_block->previous = next_block->previous; + next_block->previous->next = the_block; + next_block->next->previous = the_block; + + if (the_heap->first == next_block) + the_heap->first = the_block; + } + else { /* no coalesce */ + next_block->back_flag = + the_block->front_flag = the_size; + the_block->previous = _Heap_Head( the_heap ); + the_block->next = the_heap->first; + the_heap->first = the_block; + the_block->next->previous = the_block; + } + + return( TRUE ); +} + +/*PAGE + * + * _Heap_Walk + * + * This kernel routine walks the heap and verifies its correctness. + * + * Input parameters: + * the_heap - pointer to heap header + * source - a numeric indicator of the invoker of this routine + * do_dump - when TRUE print the information + * + * Output parameters: NONE + */ + +#ifndef RTEMS_DEBUG + +void _Heap_Walk( + Heap_Control *the_heap, + int source, + boolean do_dump +) +{ +} + +#else + +#include <stdio.h> +#include <unistd.h> + +void _Heap_Walk( + Heap_Control *the_heap, + int source, + boolean do_dump +) +{ + Heap_Block *the_block = 0; /* avoid warnings */ + Heap_Block *next_block = 0; /* avoid warnings */ + int notdone = 1; + int error = 0; + int passes = 0; + + /* + * We don't want to allow walking the heap until we have + * transferred control to the user task so we watch the + * system state. + */ + + if ( !_System_state_Is_up( _System_state_Get() ) ) + return; + + the_block = the_heap->start; + + if (do_dump == TRUE) { + printf("\nPASS: %d start @ 0x%p final 0x%p, first 0x%p last 0x%p\n", + source, the_heap->start, the_heap->final, + the_heap->first, the_heap->last + ); + } + + /* + * Handle the 1st block + */ + + if (the_block->back_flag != HEAP_DUMMY_FLAG) { + printf("PASS: %d Back flag of 1st block isn't HEAP_DUMMY_FLAG\n", source); + error = 1; + } + + while (notdone) { + passes++; + if (error && (passes > 10)) + abort(); + + if (do_dump == TRUE) { + printf("PASS: %d Block @ 0x%p Back %d, Front %d", + source, the_block, + the_block->back_flag, the_block->front_flag); + if ( _Heap_Is_block_free(the_block) ) { + printf( " Prev 0x%p, Next 0x%p\n", + the_block->previous, the_block->next); + } else { + printf("\n"); + } + } + + /* + * Handle the last block + */ + + if ( the_block->front_flag != HEAP_DUMMY_FLAG ) { + next_block = _Heap_Next_block(the_block); + if ( the_block->front_flag != next_block->back_flag ) { + error = 1; + printf("PASS: %d Front and back flags don't match\n", source); + printf(" Current Block: Back - %d, Front - %d", + the_block->back_flag, the_block->front_flag); + if (do_dump == TRUE) { + if (_Heap_Is_block_free(the_block)) { + printf(" Prev 0x%p, Next 0x%p\n", + the_block->previous, the_block->next); + } else { + printf("\n"); + } + } else { + printf("\n"); + } + printf(" Next Block: Back - %d, Front - %d", + next_block->back_flag, next_block->front_flag); + if (do_dump == TRUE) { + if (_Heap_Is_block_free(next_block)) { + printf(" Prev 0x%p, Next 0x%p\n", + the_block->previous, the_block->next); + } else { + printf("\n"); + } + } else { + printf("\n"); + } + } + } + + if (the_block->front_flag == HEAP_DUMMY_FLAG) + notdone = 0; + else + the_block = next_block; + } + + if (error) + abort(); +} +#endif diff --git a/cpukit/score/src/interr.c b/cpukit/score/src/interr.c new file mode 100644 index 0000000000..04a77fbe37 --- /dev/null +++ b/cpukit/score/src/interr.c @@ -0,0 +1,61 @@ +/* + * Internal Error 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/system.h> +#include <rtems/score/interr.h> +#include <rtems/score/sysstate.h> +#include <rtems/score/userext.h> + +/*PAGE + * + * _Internal_error_Occurred + * + * This routine 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_source - what subsystem the error originated in + * is_internal - if the error was internally generated + * the_error - fatal error status code + * + * Output parameters: + * As much information as possible is stored in a CPU dependent fashion. + * See the CPU dependent code for more information. + * + * NOTE: The the_error is not necessarily a directive status code. + */ + +void volatile _Internal_error_Occurred( + Internal_errors_Source the_source, + boolean is_internal, + unsigned32 the_error +) +{ + + Internal_errors_What_happened.the_source = the_source; + Internal_errors_What_happened.is_internal = is_internal; + Internal_errors_What_happened.the_error = the_error; + + _User_extensions_Fatal( the_source, is_internal, the_error ); + + _System_state_Set( SYSTEM_STATE_FAILED ); + + _CPU_Fatal_halt( the_error ); + + /* will not return from this routine */ +} diff --git a/cpukit/score/src/isr.c b/cpukit/score/src/isr.c new file mode 100644 index 0000000000..afc4cdcf38 --- /dev/null +++ b/cpukit/score/src/isr.c @@ -0,0 +1,60 @@ +/* + * ISR 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/system.h> +#include <rtems/score/isr.h> +#include <rtems/score/stack.h> +#include <rtems/score/interr.h> +#include <rtems/score/wkspace.h> + +/* _ISR_Handler_initialization + * + * This routine initializes the ISR handler. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _ISR_Handler_initialization( void ) +{ + _ISR_Signals_to_thread_executing = FALSE; + + _ISR_Nest_level = 0; + +#if ( CPU_ALLOCATE_INTERRUPT_STACK == TRUE ) + + if ( _CPU_Table.interrupt_stack_size < STACK_MINIMUM_SIZE ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_INTERRUPT_STACK_TOO_SMALL + ); + + _CPU_Interrupt_stack_low = + _Workspace_Allocate_or_fatal_error( _CPU_Table.interrupt_stack_size ); + + _CPU_Interrupt_stack_high = _Addresses_Add_offset( + _CPU_Interrupt_stack_low, + _CPU_Table.interrupt_stack_size + ); + +#endif + +#if ( CPU_HAS_HARDWARE_INTERRUPT_STACK == TRUE ) + _CPU_Install_interrupt_stack(); +#endif + +} diff --git a/cpukit/score/src/mpci.c b/cpukit/score/src/mpci.c new file mode 100644 index 0000000000..c3090aacc1 --- /dev/null +++ b/cpukit/score/src/mpci.c @@ -0,0 +1,524 @@ +/* + * Multiprocessing Communications Interface (MPCI) 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/system.h> +#include <rtems/score/cpu.h> +#include <rtems/score/interr.h> +#include <rtems/score/mpci.h> +#include <rtems/score/mppkt.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> +#include <rtems/score/tqdata.h> +#include <rtems/score/watchdog.h> +#include <rtems/score/sysstate.h> + +#include <rtems/score/coresem.h> + +/*PAGE + * + * _MPCI_Handler_initialization + * + * This subprogram performs the initialization necessary for this handler. + */ + +void _MPCI_Handler_initialization( + MPCI_Control *users_mpci_table, + unsigned32 timeout_status +) +{ + CORE_semaphore_Attributes attributes; + + if ( _System_state_Is_multiprocessing && !users_mpci_table ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_NO_MPCI + ); + + _MPCI_table = users_mpci_table; + + if ( !_System_state_Is_multiprocessing ) + return; + + /* + * Register the MP Process Packet routine. + */ + + _MPCI_Register_packet_processor( + MP_PACKET_MPCI_INTERNAL, + _MPCI_Internal_packets_Process_packet + ); + + /* + * Create the counting semaphore used by the MPCI Receive Server. + */ + + attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO; + + _CORE_semaphore_Initialize( + &_MPCI_Semaphore, + OBJECTS_NO_CLASS, /* free floating semaphore */ + &attributes, /* the_semaphore_attributes */ + 0, /* initial_value */ + NULL /* proxy_extract_callout */ + ); + + _Thread_queue_Initialize( + &_MPCI_Remote_blocked_threads, + OBJECTS_NO_CLASS, + THREAD_QUEUE_DISCIPLINE_FIFO, + STATES_WAITING_FOR_RPC_REPLY, + NULL, + timeout_status + ); +} + +/*PAGE + * + * _MPCI_Create_server + * + * This subprogram creates the MPCI receive server. + */ + +char *_MPCI_Internal_name = "MPCI"; + +void _MPCI_Create_server( void ) +{ + + if ( !_System_state_Is_multiprocessing ) + return; + + /* + * Initialize the MPCI Receive Server + */ + + _MPCI_Receive_server_tcb = _Thread_Internal_allocate(); + + _Thread_Initialize( + &_Thread_Internal_information, + _MPCI_Receive_server_tcb, + NULL, /* allocate the stack */ + MPCI_RECEIVE_SERVER_STACK_SIZE, + CPU_ALL_TASKS_ARE_FP, + PRIORITY_MINIMUM, + FALSE, /* no preempt */ + FALSE, /* not timesliced */ + 0, /* all interrupts enabled */ + _MPCI_Internal_name + ); + + _Thread_Start( + _MPCI_Receive_server_tcb, + THREAD_START_NUMERIC, + _MPCI_Receive_server, + NULL, + 0 + ); +} + +/*PAGE + * + * _MPCI_Initialization + * + * This subprogram initializes the MPCI driver by + * invoking the user provided MPCI initialization callout. + */ + +void _MPCI_Initialization ( void ) +{ + (*_MPCI_table->initialization)(); +} + +/*PAGE + * + * _MPCI_Register_packet_processor + * + * This routine registers the MPCI packet processor for the + * designated object class. + */ + +void _MPCI_Register_packet_processor( + Objects_Classes the_class, + MPCI_Packet_processor the_packet_processor + +) +{ + _MPCI_Packet_processors[ the_class ] = the_packet_processor; +} + +/*PAGE + * + * _MPCI_Get_packet + * + * This subprogram obtains a packet by invoking the user provided + * MPCI get packet callout. + */ + +MP_packet_Prefix *_MPCI_Get_packet ( void ) +{ + MP_packet_Prefix *the_packet; + + (*_MPCI_table->get_packet)( &the_packet ); + + if ( the_packet == NULL ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_OUT_OF_PACKETS + ); + + /* + * Put in a default timeout that will be used for + * all packets that do not otherwise have a timeout. + */ + + the_packet->timeout = MPCI_DEFAULT_TIMEOUT; + + return the_packet; +} + +/*PAGE + * + * _MPCI_Return_packet + * + * This subprogram returns a packet by invoking the user provided + * MPCI return packet callout. + */ + +void _MPCI_Return_packet ( + MP_packet_Prefix *the_packet +) +{ + (*_MPCI_table->return_packet)( the_packet ); +} + +/*PAGE + * + * _MPCI_Send_process_packet + * + * This subprogram sends a process packet by invoking the user provided + * MPCI send callout. + */ + +void _MPCI_Send_process_packet ( + unsigned32 destination, + MP_packet_Prefix *the_packet +) +{ + the_packet->source_tid = _Thread_Executing->Object.id; + the_packet->to_convert = + ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / + sizeof(unsigned32); + + (*_MPCI_table->send_packet)( destination, the_packet ); +} + +/*PAGE + * + * _MPCI_Send_request_packet + * + * This subprogram sends a request packet by invoking the user provided + * MPCI send callout. + */ + +unsigned32 _MPCI_Send_request_packet ( + unsigned32 destination, + MP_packet_Prefix *the_packet, + States_Control extra_state +) +{ + the_packet->source_tid = _Thread_Executing->Object.id; + the_packet->source_priority = _Thread_Executing->current_priority; + the_packet->to_convert = + ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / + sizeof(unsigned32); + + _Thread_Executing->Wait.id = the_packet->id; + + _Thread_Executing->Wait.queue = &_MPCI_Remote_blocked_threads; + + _Thread_Disable_dispatch(); + + (*_MPCI_table->send_packet)( destination, the_packet ); + + _Thread_queue_Enter_critical_section( &_MPCI_Remote_blocked_threads ); + + /* + * See if we need a default timeout + */ + + if (the_packet->timeout == MPCI_DEFAULT_TIMEOUT) + the_packet->timeout = _MPCI_table->default_timeout; + + _Thread_queue_Enqueue( &_MPCI_Remote_blocked_threads, the_packet->timeout ); + + _Thread_Executing->current_state = + _States_Set( extra_state, _Thread_Executing->current_state ); + + _Thread_Enable_dispatch(); + + return _Thread_Executing->Wait.return_code; +} + +/*PAGE + * + * _MPCI_Send_response_packet + * + * This subprogram sends a response packet by invoking the user provided + * MPCI send callout. + */ + +void _MPCI_Send_response_packet ( + unsigned32 destination, + MP_packet_Prefix *the_packet +) +{ + the_packet->source_tid = _Thread_Executing->Object.id; + + (*_MPCI_table->send_packet)( destination, the_packet ); +} + +/*PAGE + * + * _MPCI_Receive_packet + * + * This subprogram receives a packet by invoking the user provided + * MPCI receive callout. + */ + +MP_packet_Prefix *_MPCI_Receive_packet ( void ) +{ + MP_packet_Prefix *the_packet; + + (*_MPCI_table->receive_packet)( &the_packet ); + + return the_packet; +} + +/*PAGE + * + * _MPCI_Process_response + * + * This subprogram obtains a packet by invoking the user provided + * MPCI get packet callout. + */ + +Thread_Control *_MPCI_Process_response ( + MP_packet_Prefix *the_packet +) +{ + Thread_Control *the_thread; + Objects_Locations location; + + the_thread = _Thread_Get( the_packet->id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + case OBJECTS_REMOTE: + the_thread = NULL; /* IMPOSSIBLE */ + break; + case OBJECTS_LOCAL: + _Thread_queue_Extract( &_MPCI_Remote_blocked_threads, the_thread ); + the_thread->Wait.return_code = the_packet->return_code; + _Thread_Unnest_dispatch(); + break; + } + + return the_thread; +} + +/*PAGE + * + * _MPCI_Receive_server + * + */ + +Thread _MPCI_Receive_server( + unsigned32 ignored +) +{ + + MP_packet_Prefix *the_packet; + MPCI_Packet_processor the_function; + Thread_Control *executing; + + executing = _Thread_Executing; + + for ( ; ; ) { + + executing->receive_packet = NULL; + + _Thread_Disable_dispatch(); + _CORE_semaphore_Seize( &_MPCI_Semaphore, 0, TRUE, WATCHDOG_NO_TIMEOUT ); + _Thread_Enable_dispatch(); + + for ( ; ; ) { + the_packet = _MPCI_Receive_packet(); + + if ( !the_packet ) + break; + + executing->receive_packet = the_packet; + + if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) ) + break; + + the_function = _MPCI_Packet_processors[ the_packet->the_class ]; + + if ( !the_function ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_BAD_PACKET + ); + + (*the_function)( the_packet ); + } + } +} + +/*PAGE + * + * _MPCI_Announce + * + */ + +void _MPCI_Announce ( void ) +{ + _Thread_Disable_dispatch(); + (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0 ); + _Thread_Enable_dispatch(); +} + +/*PAGE + * + * _MPCI_Internal_packets_Send_process_packet + * + */ + +void _MPCI_Internal_packets_Send_process_packet ( + MPCI_Internal_Remote_operations operation +) +{ + MPCI_Internal_packet *the_packet; + + switch ( operation ) { + + case MPCI_PACKETS_SYSTEM_VERIFY: + + the_packet = _MPCI_Internal_packets_Get_packet(); + the_packet->Prefix.the_class = MP_PACKET_MPCI_INTERNAL; + the_packet->Prefix.length = sizeof ( MPCI_Internal_packet ); + the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet ); + the_packet->operation = operation; + + the_packet->maximum_nodes = _Objects_Maximum_nodes; + + the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects; + + _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix ); + break; + } +} + +/*PAGE + * + * _MPCI_Internal_packets_Send_request_packet + * + * This subprogram is not needed since there are no request + * packets to be sent by this manager. + * + */ + +/*PAGE + * + * _MPCI_Internal_packets_Send_response_packet + * + * This subprogram is not needed since there are no response + * packets to be sent by this manager. + * + */ + +/*PAGE + * + * + * _MPCI_Internal_packets_Process_packet + * + */ + +void _MPCI_Internal_packets_Process_packet ( + MP_packet_Prefix *the_packet_prefix +) +{ + MPCI_Internal_packet *the_packet; + unsigned32 maximum_nodes; + unsigned32 maximum_global_objects; + + the_packet = (MPCI_Internal_packet *) the_packet_prefix; + + switch ( the_packet->operation ) { + + case MPCI_PACKETS_SYSTEM_VERIFY: + + maximum_nodes = the_packet->maximum_nodes; + maximum_global_objects = the_packet->maximum_global_objects; + if ( maximum_nodes != _Objects_Maximum_nodes || + maximum_global_objects != _Objects_MP_Maximum_global_objects ) { + + _MPCI_Return_packet( the_packet_prefix ); + + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION + ); + } + + _MPCI_Return_packet( the_packet_prefix ); + + break; + } +} + +/*PAGE + * + * _MPCI_Internal_packets_Send_object_was_deleted + * + * This subprogram is not needed since there are no objects + * deleted by this manager. + * + */ + +/*PAGE + * + * _MPCI_Internal_packets_Send_extract_proxy + * + * This subprogram is not needed since there are no objects + * deleted by this manager. + * + */ + +/*PAGE + * + * _MPCI_Internal_packets_Get_packet + * + */ + +MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void ) +{ + return ( (MPCI_Internal_packet *) _MPCI_Get_packet() ); +} + +/* end of file */ diff --git a/cpukit/score/src/object.c b/cpukit/score/src/object.c new file mode 100644 index 0000000000..4f672086fe --- /dev/null +++ b/cpukit/score/src/object.c @@ -0,0 +1,512 @@ +/* + * Object 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/system.h> +#include <rtems/score/chain.h> +#include <rtems/score/object.h> +#include <rtems/score/objectmp.h> +#include <rtems/score/thread.h> +#include <rtems/score/wkspace.h> +#include <rtems/score/sysstate.h> + +/*PAGE + * + * _Objects_Handler_initialization + * + * This routine initializes the object handler. + * + * Input parameters: + * node - local node + * maximum_nodes - number of nodes in the system + * maximum_global_objects - number of configured global objects + * + * Output parameters: NONE + */ + +void _Objects_Handler_initialization( + unsigned32 node, + unsigned32 maximum_nodes, + unsigned32 maximum_global_objects +) +{ + if ( node < 1 || node > maximum_nodes ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_INVALID_NODE + ); + + _Objects_Local_node = node; + _Objects_Maximum_nodes = maximum_nodes; + + _Objects_MP_Handler_initialization( + node, + maximum_nodes, + maximum_global_objects + ); +} + +/*PAGE + * + * _Objects_Initialize_information + * + * This routine initializes all object information related data structures. + * + * Input parameters: + * information - object information table + * the_class - object class + * supports_global - TRUE if this is a global object class + * maximum - maximum objects of this class + * is_string - TRUE if names for this object are strings + * size - size of this object's control block + * + * Output parameters: NONE + */ + +void _Objects_Initialize_information( + Objects_Information *information, + Objects_Classes the_class, + boolean supports_global, + unsigned32 maximum, + unsigned32 size, + boolean is_string, + unsigned32 maximum_name_length, + boolean is_thread +) +{ + unsigned32 minimum_index; + unsigned32 index; + Objects_Control *the_object; + unsigned32 name_length; + void *name_area; + + information->maximum = maximum; + information->the_class = the_class; + information->is_string = is_string; + information->is_thread = is_thread; + + /* + * Set the entry in the object information table. + */ + + _Objects_Information_table[ the_class ] = information; + + /* + * Calculate minimum and maximum Id's + */ + + if ( maximum == 0 ) minimum_index = 0; + else minimum_index = 1; + + information->minimum_id = + _Objects_Build_id( the_class, _Objects_Local_node, minimum_index ); + + information->maximum_id = + _Objects_Build_id( the_class, _Objects_Local_node, maximum ); + + /* + * Allocate local pointer table + */ + + information->local_table = _Workspace_Allocate_or_fatal_error( + (maximum + 1) * sizeof(Objects_Control *) + ); + + /* + * Allocate name table + */ + + name_length = maximum_name_length; + + if (name_length & (OBJECTS_NAME_ALIGNMENT-1)) + name_length = (name_length + OBJECTS_NAME_ALIGNMENT) & + ~(OBJECTS_NAME_ALIGNMENT-1); + + information->name_length = name_length; + + name_area = _Workspace_Allocate_or_fatal_error( (maximum + 1) * name_length ); + information->name_table = name_area; + + /* + * Initialize local pointer table + */ + + for ( index=0 ; index <= maximum ; index++ ) { + information->local_table[ index ] = NULL; + } + + /* + * Initialize objects .. if there are any + */ + + if ( maximum == 0 ) { + _Chain_Initialize_empty( &information->Inactive ); + } else { + + _Chain_Initialize( + &information->Inactive, + _Workspace_Allocate_or_fatal_error( maximum * size ), + maximum, + size + ); + + the_object = (Objects_Control *) information->Inactive.first; + for ( index=1; index <= maximum ; index++ ) { + the_object->id = + _Objects_Build_id( the_class, _Objects_Local_node, index ); + + the_object->name = (void *) name_area; + + name_area = _Addresses_Add_offset( name_area, name_length ); + + the_object = (Objects_Control *) the_object->Node.next; + } + + } + + /* + * Take care of multiprocessing + */ + + if ( supports_global == TRUE && _System_state_Is_multiprocessing ) { + + information->global_table = _Workspace_Allocate_or_fatal_error( + (_Objects_Maximum_nodes + 1) * sizeof(Chain_Control) + ); + + for ( index=1; index <= _Objects_Maximum_nodes ; index++ ) + _Chain_Initialize_empty( &information->global_table[ index ] ); + } + else + information->global_table = NULL; +} + +/*PAGE + * + * _Objects_Clear_name + * + * XXX + */ + +void _Objects_Clear_name( + void *name, + unsigned32 length +) +{ + unsigned32 index; + unsigned32 maximum = length / OBJECTS_NAME_ALIGNMENT; + unsigned32 *name_ptr = name; + + for ( index=0 ; index < maximum ; index++ ) + *name_ptr++ = 0; +} + +/*PAGE + * + * _Objects_Copy_name_string + * + * XXX + */ + +void _Objects_Copy_name_string( + void *source, + void *destination +) +{ + unsigned8 *source_p = source; + unsigned8 *destination_p = destination; + + do { + *destination_p++ = *source_p; + } while ( *source_p++ ); +} + +/*PAGE + * + * _Objects_Copy_name_raw + * + * XXX + */ + +void _Objects_Copy_name_raw( + void *source, + void *destination, + unsigned32 length +) +{ + unsigned32 *source_p = source; + unsigned32 *destination_p = destination; + unsigned32 tmp_length = length / OBJECTS_NAME_ALIGNMENT; + + while ( tmp_length-- ) + *destination_p++ = *source_p++; +} + +/*PAGE + * + * _Objects_Compare_name_string + * + * XXX + */ + +boolean _Objects_Compare_name_string( + void *name_1, + void *name_2, + unsigned32 length +) +{ + unsigned8 *name_1_p = name_1; + unsigned8 *name_2_p = name_2; + unsigned32 tmp_length = length; + + do { + if ( *name_1_p++ != *name_2_p++ ) + return FALSE; + if ( !tmp_length-- ) + return FALSE; + } while ( *name_1_p ); + + return TRUE; +} + +/*PAGE + * + * _Objects_Compare_name_raw + * + * XXX + */ + +boolean _Objects_Compare_name_raw( + void *name_1, + void *name_2, + unsigned32 length +) +{ + unsigned32 *name_1_p = name_1; + unsigned32 *name_2_p = name_2; + unsigned32 tmp_length = length / OBJECTS_NAME_ALIGNMENT; + + while ( tmp_length-- ) + if ( *name_1_p++ != *name_2_p++ ) + return FALSE; + + return TRUE; +} + + +/*PAGE + * + * _Objects_Name_to_id + * + * These kernel routines search the object table(s) for the given + * object name and returns the associated object id. + * + * Input parameters: + * information - object information + * name - user defined object name + * node - node indentifier (0 indicates any node) + * id - address of return ID + * + * Output parameters: + * id - object id + * OBJECTS_SUCCESSFUL - if successful + * error code - if unsuccessful + */ + +Objects_Name_to_id_errors _Objects_Name_to_id( + Objects_Information *information, + Objects_Name name, + unsigned32 node, + Objects_Id *id +) +{ + boolean search_local_node; + Objects_Control **objects; + Objects_Control *the_object; + unsigned32 index; + unsigned32 name_length; + Objects_Name_comparators compare_them; + + if ( name == 0 ) + return OBJECTS_INVALID_NAME; + + search_local_node = FALSE; + + if ( information->maximum != 0 && + (node == OBJECTS_SEARCH_ALL_NODES || node == OBJECTS_SEARCH_LOCAL_NODE || + _Objects_Is_local_node( node ) ) ) + search_local_node = TRUE; + + if ( search_local_node ) { + objects = information->local_table; + + name_length = information->name_length; + + if ( information->is_string ) compare_them = _Objects_Compare_name_string; + else compare_them = _Objects_Compare_name_raw; + + for ( index = 1; index <= information->maximum; index++ ) { + + the_object = objects[ index ]; + + if ( !the_object || !the_object->name ) + continue; + + if ( (*compare_them)( name, the_object->name, name_length ) ) { + *id = the_object->id; + return OBJECTS_SUCCESSFUL; + } + } + } + + if ( _Objects_Is_local_node( node ) || node == OBJECTS_SEARCH_LOCAL_NODE ) + return OBJECTS_INVALID_NAME; + + return ( _Objects_MP_Global_name_search( information, name, node, id ) ); +} + +/*PAGE + * + * _Objects_Get + * + * This routine sets the object pointer for the given + * object id based on the given object information structure. + * + * Input parameters: + * information - pointer to entry in table for this class + * id - object id to search for + * location - address of where to store the location + * + * Output parameters: + * returns - address of object if local + * location - one of the following: + * OBJECTS_ERROR - invalid object ID + * OBJECTS_REMOTE - remote object + * OBJECTS_LOCAL - local object + */ + +Objects_Control *_Objects_Get( + Objects_Information *information, + Objects_Id id, + Objects_Locations *location +) +{ + Objects_Control *the_object; + unsigned32 index; + + index = id - information->minimum_id; + + if ( information->maximum >= index ) { + _Thread_Disable_dispatch(); + if ( (the_object = information->local_table[index+1]) != NULL ) { + *location = OBJECTS_LOCAL; + return( the_object ); + } + _Thread_Enable_dispatch(); + *location = OBJECTS_ERROR; + return( NULL ); + } + *location = OBJECTS_ERROR; + _Objects_MP_Is_remote( information, id, location, &the_object ); + return the_object; +} + + +/*PAGE + * + * _Objects_Get_next + * + * Like _Objects_Get, but considers the 'id' as a "hint" and + * finds next valid one after that point. + * Mostly used for monitor and debug traversal of an object. + * + * Input parameters: + * information - pointer to entry in table for this class + * id - object id to search for + * location - address of where to store the location + * next_id - address to store next id to try + * + * Output parameters: + * returns - address of object if local + * location - one of the following: + * OBJECTS_ERROR - invalid object ID + * OBJECTS_REMOTE - remote object + * OBJECTS_LOCAL - local object + * next_id - will contain a reasonable "next" id to continue traversal + * + * NOTE: + * assumes can add '1' to an id to get to next index. + */ + +Objects_Control * +_Objects_Get_next( + Objects_Information *information, + Objects_Id id, + unsigned32 *location_p, + Objects_Id *next_id_p +) +{ + Objects_Control *object; + Objects_Id next_id; + + if (_Objects_Get_index(id) == OBJECTS_ID_INITIAL_INDEX) + next_id = information->minimum_id; + else + next_id = id; + + do { + /* walked off end of list? */ + if (_Objects_Get_index(next_id) > information->maximum) + { + *location_p = OBJECTS_ERROR; + goto final; + } + + /* try to grab one */ + object = _Objects_Get(information, next_id, location_p); + + next_id++; + + } while (*location_p != OBJECTS_LOCAL); + + *next_id_p = next_id; + return object; + +final: + *next_id_p = OBJECTS_ID_FINAL; + return 0; +} + +/*PAGE + * + * _Objects_Get_information + * + * XXX + */ + +Objects_Information *_Objects_Get_information( + Objects_Id id +) +{ + Objects_Classes the_class; + + the_class = _Objects_Get_class( id ); + + if ( !_Objects_Is_class_valid( the_class ) ) + return NULL; + + return _Objects_Information_table[ the_class ]; +} + diff --git a/cpukit/score/src/objectmp.c b/cpukit/score/src/objectmp.c new file mode 100644 index 0000000000..7546c33585 --- /dev/null +++ b/cpukit/score/src/objectmp.c @@ -0,0 +1,275 @@ +/* + * Multiprocessing Support for the Object 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/system.h> +#include <rtems/score/interr.h> +#include <rtems/score/object.h> +#include <rtems/score/wkspace.h> +#include <rtems/score/thread.h> + +/*PAGE + * + * _Objects_MP_Handler_initialization + * + */ + +void _Objects_MP_Handler_initialization ( + unsigned32 node, + unsigned32 maximum_nodes, + unsigned32 maximum_global_objects +) +{ + _Objects_MP_Maximum_global_objects = maximum_global_objects; + + if ( maximum_global_objects == 0 ) { + _Chain_Initialize_empty( &_Objects_MP_Inactive_global_objects ); + return; + } + + _Chain_Initialize( + &_Objects_MP_Inactive_global_objects, + _Workspace_Allocate_or_fatal_error( + maximum_global_objects * sizeof( Objects_MP_Control ) + ), + maximum_global_objects, + sizeof( Objects_MP_Control ) + ); + +} + +/*PAGE + * + * _Objects_MP_Open + * + */ + +void _Objects_MP_Open ( + Objects_Information *information, + Objects_MP_Control *the_global_object, + unsigned32 the_name, /* XXX -- wrong for variable */ + Objects_Id the_id +) +{ + the_global_object->Object.id = the_id; + the_global_object->name = the_name; + + _Chain_Prepend( + &information->global_table[ _Objects_Get_node( the_id ) ], + &the_global_object->Object.Node + ); + +} + +/*PAGE + * + * _Objects_MP_Allocate_and_open + * + */ + +boolean _Objects_MP_Allocate_and_open ( + Objects_Information *information, + unsigned32 the_name, /* XXX -- wrong for variable */ + Objects_Id the_id, + boolean is_fatal_error +) +{ + Objects_MP_Control *the_global_object; + + the_global_object = _Objects_MP_Allocate_global_object(); + if ( _Objects_MP_Is_null_global_object( the_global_object ) ) { + + if ( is_fatal_error == FALSE ) + return FALSE; + + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_OUT_OF_GLOBAL_OBJECTS + ); + + } + + _Objects_MP_Open( information, the_global_object, the_name, the_id ); + + return TRUE; +} + +/*PAGE + * + * _Objects_MP_Close + * + */ + +void _Objects_MP_Close ( + Objects_Information *information, + Objects_Id the_id +) +{ + Chain_Control *the_chain; + Chain_Node *the_node; + Objects_MP_Control *the_object; + + the_chain = &information->global_table[ _Objects_Get_node( the_id ) ]; + + for ( the_node = the_chain->first ; + !_Chain_Is_tail( the_chain, the_node ) ; + the_node = the_node->next ) { + + the_object = (Objects_MP_Control *) the_node; + + if ( _Objects_Are_ids_equal( the_object->Object.id, the_id ) ) { + + _Chain_Extract( the_node ); + _Objects_MP_Free_global_object( the_object ); + return; + } + + } + + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_INVALID_GLOBAL_ID + ); +} + +/*PAGE + * + * _Objects_MP_Global_name_search + * + */ + +Objects_Name_to_id_errors _Objects_MP_Global_name_search ( + Objects_Information *information, + Objects_Name the_name, + unsigned32 nodes_to_search, + Objects_Id *the_id +) +{ + unsigned32 low_node; + unsigned32 high_node; + unsigned32 node_index; + Chain_Control *the_chain; + Chain_Node *the_node; + Objects_MP_Control *the_object; + unsigned32 name_to_use = *(unsigned32 *)the_name; /* XXX variable */ + + if ( nodes_to_search > _Objects_Maximum_nodes ) + return OBJECTS_INVALID_NODE; + + if ( information->global_table == NULL ) + return OBJECTS_INVALID_NAME; + + if ( nodes_to_search == OBJECTS_SEARCH_ALL_NODES || + nodes_to_search == OBJECTS_SEARCH_OTHER_NODES ) { + low_node = 1; + high_node = _Objects_Maximum_nodes; + } else { + low_node = + high_node = nodes_to_search; + } + + _Thread_Disable_dispatch(); + + for ( node_index = low_node ; node_index <= high_node ; node_index++ ) { + + /* + * NOTE: The local node was search (if necessary) by + * _Objects_Name_to_id before this was invoked. + */ + + if ( !_Objects_Is_local_node( node_index ) ) { + the_chain = &information->global_table[ node_index ]; + + for ( the_node = the_chain->first ; + !_Chain_Is_tail( the_chain, the_node ) ; + the_node = the_node->next ) { + + the_object = (Objects_MP_Control *) the_node; + + if ( the_object->name == name_to_use ) { + *the_id = the_object->Object.id; + _Thread_Enable_dispatch(); + return OBJECTS_SUCCESSFUL; + } + } + } + } + + _Thread_Enable_dispatch(); + return OBJECTS_INVALID_NAME; +} + +/*PAGE + * + * _Objects_MP_Is_remote + * + */ + +void _Objects_MP_Is_remote ( + Objects_Information *information, + Objects_Id the_id, + Objects_Locations *location, + Objects_Control **the_object +) +{ + unsigned32 node; + Chain_Control *the_chain; + Chain_Node *the_node; + Objects_MP_Control *the_global_object; + + node = _Objects_Get_node( the_id ); + + /* + * NOTE: The local node was search (if necessary) by + * _Objects_Name_to_id before this was invoked. + * + * The NODE field of an object id cannot be 0 + * because 0 is an invalid node number. + */ + + if ( node == 0 || + _Objects_Is_local_node( node ) || + node > _Objects_Maximum_nodes || + information->global_table == NULL ) { + + *location = OBJECTS_ERROR; + *the_object = NULL; + return; + } + + _Thread_Disable_dispatch(); + + the_chain = &information->global_table[ node ]; + + for ( the_node = the_chain->first ; + !_Chain_Is_tail( the_chain, the_node ) ; + the_node = the_node->next ) { + + the_global_object = (Objects_MP_Control *) the_node; + + if ( _Objects_Are_ids_equal( the_global_object->Object.id, the_id ) ) { + _Thread_Unnest_dispatch(); + *location = OBJECTS_REMOTE; + *the_object = (Objects_Control *) the_global_object; + return; + } + } + + _Thread_Enable_dispatch(); + *location = OBJECTS_ERROR; + *the_object = NULL; + +} diff --git a/cpukit/score/src/thread.c b/cpukit/score/src/thread.c new file mode 100644 index 0000000000..afd36a0fd8 --- /dev/null +++ b/cpukit/score/src/thread.c @@ -0,0 +1,1257 @@ +/* + * Thread 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/system.h> +#include <rtems/score/apiext.h> +#include <rtems/score/context.h> +#include <rtems/score/interr.h> +#include <rtems/score/isr.h> +#include <rtems/score/object.h> +#include <rtems/score/priority.h> +#include <rtems/score/states.h> +#include <rtems/score/sysstate.h> +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> +#include <rtems/score/userext.h> +#include <rtems/score/wkspace.h> + +/*PAGE + * + * _Thread_Handler_initialization + * + * This routine initializes all thread manager related data structures. + * + * Input parameters: + * ticks_per_timeslice - clock ticks per quantum + * maximum_proxies - number of proxies to initialize + * + * Output parameters: NONE + */ + +char *_Thread_Idle_name = "IDLE"; + +void _Thread_Handler_initialization( + unsigned32 ticks_per_timeslice, + unsigned32 maximum_extensions, + unsigned32 maximum_proxies +) +{ + unsigned32 index; + + /* + * BOTH stacks hooks must be set or both must be NULL. + * Do not allow mixture. + */ + + if ( !( ( _CPU_Table.stack_allocate_hook == 0 ) + == ( _CPU_Table.stack_free_hook == 0 ) ) ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_BAD_STACK_HOOK + ); + + _Context_Switch_necessary = FALSE; + _Thread_Executing = NULL; + _Thread_Heir = NULL; + _Thread_Allocated_fp = NULL; + + _Thread_Maximum_extensions = maximum_extensions; + + _Thread_Ticks_remaining_in_timeslice = ticks_per_timeslice; + _Thread_Ticks_per_timeslice = ticks_per_timeslice; + + _Thread_Ready_chain = _Workspace_Allocate_or_fatal_error( + (PRIORITY_MAXIMUM + 1) * sizeof(Chain_Control) + ); + + for ( index=0; index <= PRIORITY_MAXIMUM ; index++ ) + _Chain_Initialize_empty( &_Thread_Ready_chain[ index ] ); + + _Thread_MP_Handler_initialization( maximum_proxies ); + + /* + * Initialize this class of objects. + */ + + _Objects_Initialize_information( + &_Thread_Internal_information, + OBJECTS_INTERNAL_THREADS, + FALSE, + ( _System_state_Is_multiprocessing ) ? 2 : 1, + sizeof( Thread_Control ), + TRUE, + 8, + TRUE + ); + +} + +/*PAGE + * + * _Thread_Create_idle + */ + +void _Thread_Create_idle( void ) +{ + void *idle; + + /* + * The entire workspace is zeroed during its initialization. Thus, all + * fields not explicitly assigned were explicitly zeroed by + * _Workspace_Initialization. + */ + + _Thread_Idle = _Thread_Internal_allocate(); + + /* + * Initialize the IDLE task. + */ + +#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE) + idle = _CPU_Thread_Idle_body; +#else + idle = _Thread_Idle_body; +#endif + + if ( _CPU_Table.idle_task ) + idle = _CPU_Table.idle_task; + + _Thread_Initialize( + &_Thread_Internal_information, + _Thread_Idle, + NULL, /* allocate the stack */ + THREAD_IDLE_STACK_SIZE, + CPU_IDLE_TASK_IS_FP, + PRIORITY_MAXIMUM, + TRUE, /* preemptable */ + FALSE, /* not timesliced */ + 0, /* all interrupts enabled */ + _Thread_Idle_name + ); + + /* + * WARNING!!! This is necessary to "kick" start the system and + * MUST be done before _Thread_Start is invoked. + */ + + _Thread_Heir = + _Thread_Executing = _Thread_Idle; + + _Thread_Start( + _Thread_Idle, + THREAD_START_NUMERIC, + idle, + NULL, + 0 + ); + +} + +/*PAGE + * + * _Thread_Start_multitasking + * + * This kernel routine readies the requested thread, the thread chain + * is adjusted. A new heir thread may be selected. + * + * Input parameters: + * system_thread - pointer to system initialization thread control block + * idle_thread - pointer to idle thread control block + * + * Output parameters: NONE + * + * NOTE: This routine uses the "blocking" heir selection mechanism. + * This insures the correct heir after a thread restart. + * + * INTERRUPT LATENCY: + * ready chain + * select heir + */ + +void _Thread_Start_multitasking( void ) +{ + /* + * The system is now multitasking and completely initialized. + * This system thread now either "goes away" in a single processor + * system or "turns into" the server thread in an MP system. + */ + + _System_state_Set( SYSTEM_STATE_UP ); + + _Context_Switch_necessary = FALSE; + + _Thread_Executing = _Thread_Heir; + + _Context_Switch( &_Thread_BSP_context, &_Thread_Executing->Registers ); +} + +/*PAGE + * + * _Thread_Dispatch + * + * This kernel routine determines if a dispatch is needed, and if so + * dispatches to the heir thread. Once the heir is running an attempt + * is made to dispatch any ASRs. + * + * ALTERNATE ENTRY POINTS: + * void _Thread_Enable_dispatch(); + * + * Input parameters: NONE + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * dispatch thread + * no dispatch thread + */ + +#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE ) +void _Thread_Enable_dispatch( void ) +{ + if ( --_Thread_Dispatch_disable_level ) + return; + _Thread_Dispatch(); +} +#endif + +void _Thread_Dispatch( void ) +{ + Thread_Control *executing; + Thread_Control *heir; + ISR_Level level; + + executing = _Thread_Executing; + _ISR_Disable( level ); + while ( _Context_Switch_necessary == TRUE ) { + heir = _Thread_Heir; + _Thread_Dispatch_disable_level = 1; + _Context_Switch_necessary = FALSE; + _Thread_Executing = heir; + _ISR_Enable( level ); + + _User_extensions_Thread_switch( executing, heir ); + + _Thread_Ticks_remaining_in_timeslice = _Thread_Ticks_per_timeslice; + + /* + * If the CPU has hardware floating point, then we must address saving + * and restoring it as part of the context switch. + * + * The second conditional compilation section selects the algorithm used + * to context switch between floating point tasks. The deferred algorithm + * can be significantly better in a system with few floating point tasks + * because it reduces the total number of save and restore FP context + * operations. However, this algorithm can not be used on all CPUs due + * to unpredictable use of FP registers by some compilers for integer + * operations. + */ + +#if ( CPU_HARDWARE_FP == TRUE ) +#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE ) + if ( (heir->fp_context != NULL) && !_Thread_Is_allocated_fp( heir ) ) { + if ( _Thread_Allocated_fp != NULL ) + _Context_Save_fp( &_Thread_Allocated_fp->fp_context ); + _Context_Restore_fp( &heir->fp_context ); + _Thread_Allocated_fp = heir; + } +#else + if ( executing->fp_context != NULL ) + _Context_Save_fp( &executing->fp_context ); + + if ( heir->fp_context != NULL ) + _Context_Restore_fp( &heir->fp_context ); +#endif +#endif + + _Context_Switch( &executing->Registers, &heir->Registers ); + + executing = _Thread_Executing; + + _ISR_Disable( level ); + } + + _Thread_Dispatch_disable_level = 0; + + _ISR_Enable( level ); + + if ( executing->do_post_task_switch_extension ) { + executing->do_post_task_switch_extension = FALSE; + _API_extensions_Run_postswitch(); + } + +} + +/*PAGE + * + * _Thread_Stack_Allocate + * + * Allocate the requested stack space for the thread. + * return the actual size allocated after any adjustment + * or return zero if the allocation failed. + * Set the Start.stack field to the address of the stack + */ + +static unsigned32 _Thread_Stack_Allocate( + Thread_Control *the_thread, + unsigned32 stack_size) +{ + void *stack_addr = 0; + + if ( !_Stack_Is_enough( stack_size ) ) + stack_size = STACK_MINIMUM_SIZE; + + /* + * Call ONLY the CPU table stack allocate hook, _or_ the + * the RTEMS workspace allocate. This is so the stack free + * routine can call the correct deallocation routine. + */ + + if ( _CPU_Table.stack_allocate_hook ) + { + stack_addr = (*_CPU_Table.stack_allocate_hook)( stack_size ); + } else { + + /* + * First pad the requested size so we allocate enough memory + * so the context initialization can align it properly. The address + * returned the workspace allocate must be directly stored in the + * stack control block because it is later used in the free sequence. + * + * Thus it is the responsibility of the CPU dependent code to + * get and keep the stack adjust factor, the stack alignment, and + * the context initialization sequence in sync. + */ + + stack_size = _Stack_Adjust_size( stack_size ); + stack_addr = _Workspace_Allocate( stack_size ); + } + + if ( !stack_addr ) + stack_size = 0; + + the_thread->Start.stack = stack_addr; + + return stack_size; +} + +/* + * _Thread_Stack_Free + * + * Deallocate the Thread's stack. + */ + +static void _Thread_Stack_Free(void *stack_addr) +{ + /* + * Call ONLY the CPU table stack free hook, or the + * the RTEMS workspace free. This is so the free + * routine properly matches the allocation of the stack. + */ + + if ( _CPU_Table.stack_free_hook ) + (*_CPU_Table.stack_free_hook)( stack_addr ); + else + _Workspace_Free( stack_addr ); +} + +/*PAGE + * + * _Thread_Initialize + * + * XXX + */ + +boolean _Thread_Initialize( + Objects_Information *information, + Thread_Control *the_thread, + void *stack_area, /* NULL if to be allocated */ + unsigned32 stack_size, /* insure it is >= min */ + boolean is_fp, /* TRUE if thread uses FP */ + Priority_Control priority, + boolean is_preemptible, + boolean is_timeslice, + unsigned32 isr_level, + Objects_Name name + +) +{ + unsigned32 actual_stack_size; + void *stack; + void *fp_area; + void *extensions_area; + + /* + * Allocate and Initialize the stack for this thread. + */ + + if ( !_Stack_Is_enough( stack_size ) ) + actual_stack_size = STACK_MINIMUM_SIZE; + else + actual_stack_size = stack_size; + + actual_stack_size = _Stack_Adjust_size( actual_stack_size ); + stack = stack_area; + + if ( !stack ) { + actual_stack_size = _Thread_Stack_Allocate( the_thread, stack_size ); + + if ( !actual_stack_size ) + return FALSE; /* stack allocation failed */ + + stack = the_thread->Start.stack; + } else + the_thread->Start.stack = NULL; + + _Stack_Initialize( + &the_thread->Start.Initial_stack, + stack, + actual_stack_size + ); + + /* + * Allocate the floating point area for this thread + */ + + if ( is_fp ) { + + fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE ); + if ( !fp_area ) { + if ( the_thread->Start.stack ) + (void) _Thread_Stack_Free( the_thread->Start.stack ); + return FALSE; + } + fp_area = _Context_Fp_start( fp_area, 0 ); + + } else + fp_area = NULL; + + the_thread->fp_context = fp_area; + the_thread->Start.fp_context = fp_area; + + + /* + * Allocate the extensions area for this thread + */ + + if ( _Thread_Maximum_extensions ) { + extensions_area = _Workspace_Allocate( + (_Thread_Maximum_extensions + 1) * sizeof( void * ) + ); + + if ( !extensions_area ) { + if ( fp_area ) + (void) _Workspace_Free( fp_area ); + + if ( the_thread->Start.stack ) + (void) _Thread_Stack_Free( the_thread->Start.stack ); + + return FALSE; + } + } else + extensions_area = NULL; + + the_thread->extensions = extensions_area; + + /* + * General initialization + */ + + the_thread->Start.is_preemptible = is_preemptible; + the_thread->Start.is_timeslice = is_timeslice; + the_thread->Start.isr_level = isr_level; + + the_thread->current_state = STATES_DORMANT; + the_thread->resource_count = 0; + the_thread->real_priority = priority; + the_thread->Start.initial_priority = priority; + + _Thread_Set_priority( the_thread, priority ); + + /* + * Open the object + */ + + _Objects_Open( information, &the_thread->Object, name ); + + /* + * Invoke create extensions + */ + + if ( !_User_extensions_Thread_create( the_thread ) ) { + + if ( extensions_area ) + (void) _Workspace_Free( extensions_area ); + + if ( fp_area ) + (void) _Workspace_Free( fp_area ); + + if ( the_thread->Start.stack ) + (void) _Thread_Stack_Free( the_thread->Start.stack ); + + return FALSE; + } + + return TRUE; + +} + +/* + * _Thread_Start + * + * DESCRIPTION: + * + * XXX + */ + +boolean _Thread_Start( + Thread_Control *the_thread, + Thread_Start_types the_prototype, + void *entry_point, + void *pointer_argument, + unsigned32 numeric_argument +) +{ + if ( _States_Is_dormant( the_thread->current_state ) ) { + + the_thread->Start.entry_point = entry_point; + + the_thread->Start.prototype = the_prototype; + the_thread->Start.pointer_argument = pointer_argument; + the_thread->Start.numeric_argument = numeric_argument; + + _Thread_Load_environment( the_thread ); + + _Thread_Ready( the_thread ); + + _User_extensions_Thread_start( the_thread ); + + return TRUE; + } + + return FALSE; + +} + +/* + * _Thread_Restart + * + * DESCRIPTION: + * + * XXX + */ + +boolean _Thread_Restart( + Thread_Control *the_thread, + void *pointer_argument, + unsigned32 numeric_argument +) +{ + if ( !_States_Is_dormant( the_thread->current_state ) ) { + + _Thread_Set_transient( the_thread ); + the_thread->resource_count = 0; + the_thread->is_preemptible = the_thread->Start.is_preemptible; + the_thread->is_timeslice = the_thread->Start.is_timeslice; + + the_thread->Start.pointer_argument = pointer_argument; + the_thread->Start.numeric_argument = numeric_argument; + + if ( !_Thread_queue_Extract_with_proxy( the_thread ) ) { + + if ( _Watchdog_Is_active( &the_thread->Timer ) ) + (void) _Watchdog_Remove( &the_thread->Timer ); + } + + if ( the_thread->current_priority != the_thread->Start.initial_priority ) { + the_thread->real_priority = the_thread->Start.initial_priority; + _Thread_Set_priority( the_thread, the_thread->Start.initial_priority ); + } + + _Thread_Load_environment( the_thread ); + + _Thread_Ready( the_thread ); + + _User_extensions_Thread_restart( the_thread ); + + if ( _Thread_Is_executing ( the_thread ) ) + _Thread_Restart_self(); + + return TRUE; + } + + return FALSE; +} + +/* + * _Thread_Close + * + * DESCRIPTION: + * + * XXX + */ + +void _Thread_Close( + Objects_Information *information, + Thread_Control *the_thread +) +{ + _Objects_Close( information, &the_thread->Object ); + + _Thread_Set_state( the_thread, STATES_TRANSIENT ); + + if ( !_Thread_queue_Extract_with_proxy( the_thread ) ) { + + if ( _Watchdog_Is_active( &the_thread->Timer ) ) + (void) _Watchdog_Remove( &the_thread->Timer ); + } + + _User_extensions_Thread_delete( the_thread ); + +#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE ) + if ( _Thread_Is_allocated_fp( the_thread ) ) + _Thread_Deallocate_fp(); +#endif + the_thread->fp_context = NULL; + + if ( the_thread->Start.fp_context ) + (void) _Workspace_Free( the_thread->Start.fp_context ); + + if ( the_thread->Start.stack ) + (void) _Workspace_Free( the_thread->Start.stack ); + + if ( the_thread->extensions ) + (void) _Workspace_Free( the_thread->extensions ); + + the_thread->Start.stack = NULL; + the_thread->extensions = NULL; +} + +/*PAGE + * + * _Thread_Ready + * + * This kernel routine readies the requested thread, the thread chain + * is adjusted. A new heir thread may be selected. + * + * Input parameters: + * the_thread - pointer to thread control block + * + * Output parameters: NONE + * + * NOTE: This routine uses the "blocking" heir selection mechanism. + * This insures the correct heir after a thread restart. + * + * INTERRUPT LATENCY: + * ready chain + * select heir + */ + +void _Thread_Ready( + Thread_Control *the_thread +) +{ + ISR_Level level; + Thread_Control *heir; + + _ISR_Disable( level ); + + the_thread->current_state = STATES_READY; + + _Priority_Add_to_bit_map( &the_thread->Priority_map ); + + _Chain_Append_unprotected( the_thread->ready, &the_thread->Object.Node ); + + _ISR_Flash( level ); + + _Thread_Calculate_heir(); + + heir = _Thread_Heir; + + if ( !_Thread_Is_executing( heir ) && _Thread_Executing->is_preemptible ) + _Context_Switch_necessary = TRUE; + + _ISR_Enable( level ); +} + +/*PAGE + * + * _Thread_Clear_state + * + * This kernel routine clears the appropriate states in the + * requested thread. The thread ready chain is adjusted if + * necessary and the Heir thread is set accordingly. + * + * Input parameters: + * the_thread - pointer to thread control block + * state - state set to clear + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * priority map + * select heir + */ + +void _Thread_Clear_state( + Thread_Control *the_thread, + States_Control state +) +{ + ISR_Level level; + + _ISR_Disable( level ); + the_thread->current_state = + _States_Clear( state, the_thread->current_state ); + + if ( _States_Is_ready( the_thread->current_state ) ) { + + _Priority_Add_to_bit_map( &the_thread->Priority_map ); + + _Chain_Append_unprotected( the_thread->ready, &the_thread->Object.Node ); + + _ISR_Flash( level ); + + if ( the_thread->current_priority < _Thread_Heir->current_priority ) { + _Thread_Heir = the_thread; + if ( _Thread_Executing->is_preemptible || + the_thread->current_priority == 0 ) + _Context_Switch_necessary = TRUE; + } + } + _ISR_Enable( level ); +} + +/*PAGE + * + * _Thread_Set_state + * + * This kernel routine sets the requested state in the THREAD. The + * THREAD chain is adjusted if necessary. + * + * Input parameters: + * the_thread - pointer to thread control block + * state - state to be set + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * ready chain + * select map + */ + +void _Thread_Set_state( + Thread_Control *the_thread, + States_Control state +) +{ + ISR_Level level; + Chain_Control *ready; + + ready = the_thread->ready; + _ISR_Disable( level ); + if ( !_States_Is_ready( the_thread->current_state ) ) { + the_thread->current_state = + _States_Set( state, the_thread->current_state ); + _ISR_Enable( level ); + return; + } + + the_thread->current_state = state; + + if ( _Chain_Has_only_one_node( ready ) ) { + + _Chain_Initialize_empty( ready ); + _Priority_Remove_from_bit_map( &the_thread->Priority_map ); + + } else + _Chain_Extract_unprotected( &the_thread->Object.Node ); + + _ISR_Flash( level ); + + if ( _Thread_Is_heir( the_thread ) ) + _Thread_Calculate_heir(); + + if ( _Thread_Is_executing( the_thread ) ) + _Context_Switch_necessary = TRUE; + + _ISR_Enable( level ); +} + +/*PAGE + * + * _Thread_Set_transient + * + * This kernel routine places the requested thread in the transient state + * which will remove it from the ready queue, if necessary. No + * rescheduling is necessary because it is assumed that the transient + * state will be cleared before dispatching is enabled. + * + * Input parameters: + * the_thread - pointer to thread control block + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * only case + */ + +void _Thread_Set_transient( + Thread_Control *the_thread +) +{ + ISR_Level level; + unsigned32 old_state; + Chain_Control *ready; + + ready = the_thread->ready; + _ISR_Disable( level ); + + old_state = the_thread->current_state; + the_thread->current_state = _States_Set( STATES_TRANSIENT, old_state ); + + if ( _States_Is_ready( old_state ) ) { + if ( _Chain_Has_only_one_node( ready ) ) { + + _Chain_Initialize_empty( ready ); + _Priority_Remove_from_bit_map( &the_thread->Priority_map ); + + } else + _Chain_Extract_unprotected( &the_thread->Object.Node ); + } + + _ISR_Enable( level ); + +} + +/*PAGE + * + * _Thread_Reset_timeslice + * + * This routine will remove the running thread from the ready chain + * and place it immediately at the rear of this chain and then the + * timeslice counter is reset. The heir THREAD will be updated if + * the running is also the currently the heir. + * + * Input parameters: NONE + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * ready chain + * select heir + */ + +void _Thread_Reset_timeslice( void ) +{ + ISR_Level level; + Thread_Control *executing; + Chain_Control *ready; + + executing = _Thread_Executing; + ready = executing->ready; + _ISR_Disable( level ); + if ( _Chain_Has_only_one_node( ready ) ) { + _Thread_Ticks_remaining_in_timeslice = _Thread_Ticks_per_timeslice; + _ISR_Enable( level ); + return; + } + _Chain_Extract_unprotected( &executing->Object.Node ); + _Chain_Append_unprotected( ready, &executing->Object.Node ); + + _ISR_Flash( level ); + + if ( _Thread_Is_heir( executing ) ) + _Thread_Heir = (Thread_Control *) ready->first; + + _Context_Switch_necessary = TRUE; + + _ISR_Enable( level ); +} + +/*PAGE + * + * _Thread_Tickle_timeslice + * + * This scheduler routine determines if timeslicing is enabled + * for the currently executing thread and, if so, updates the + * timeslice count and checks for timeslice expiration. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _Thread_Tickle_timeslice( void ) +{ + if ( !_Thread_Executing->is_timeslice || + !_Thread_Executing->is_preemptible || + !_States_Is_ready( _Thread_Executing->current_state ) ) + return; + + if ( --_Thread_Ticks_remaining_in_timeslice == 0 ) { + _Thread_Reset_timeslice(); + } +} + +/*PAGE + * + * _Thread_Yield_processor + * + * This kernel routine will remove the running THREAD from the ready chain + * and place it immediatly at the rear of this chain. Reset timeslice + * and yield the processor functions both use this routine, therefore if + * reset is TRUE and this is the only thread on the chain then the + * timeslice counter is reset. The heir THREAD will be updated if the + * running is also the currently the heir. + * + * Input parameters: NONE + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * ready chain + * select heir + */ + +void _Thread_Yield_processor( void ) +{ + ISR_Level level; + Thread_Control *executing; + Chain_Control *ready; + + executing = _Thread_Executing; + ready = executing->ready; + _ISR_Disable( level ); + if ( !_Chain_Has_only_one_node( ready ) ) { + _Chain_Extract_unprotected( &executing->Object.Node ); + _Chain_Append_unprotected( ready, &executing->Object.Node ); + + _ISR_Flash( level ); + + if ( _Thread_Is_heir( executing ) ) + _Thread_Heir = (Thread_Control *) ready->first; + _Context_Switch_necessary = TRUE; + } + else if ( !_Thread_Is_heir( executing ) ) + _Context_Switch_necessary = TRUE; + + _ISR_Enable( level ); +} + +/*PAGE + * + * _Thread_Load_environment + * + * Load starting environment for another thread from its start area in the + * thread. Only called from t_restart and t_start. + * + * Input parameters: + * the_thread - thread control block pointer + * + * Output parameters: NONE + */ + +void _Thread_Load_environment( + Thread_Control *the_thread +) +{ + boolean is_fp = FALSE; + + if ( the_thread->Start.fp_context ) { + the_thread->fp_context = the_thread->Start.fp_context; + _Context_Initialize_fp( &the_thread->fp_context ); + is_fp = TRUE; + } + + the_thread->do_post_task_switch_extension = FALSE; + the_thread->is_preemptible = the_thread->Start.is_preemptible; + the_thread->is_timeslice = the_thread->Start.is_timeslice; + + _Context_Initialize( + &the_thread->Registers, + the_thread->Start.Initial_stack.area, + the_thread->Start.Initial_stack.size, + the_thread->Start.isr_level, + _Thread_Handler, + is_fp + ); + +} + +/*PAGE + * + * _Thread_Handler + * + * This routine is the default thread exitted error handler. It is + * returned to when a thread exits. The configured fatal error handler + * is invoked to process the exit. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _Thread_Handler( void ) +{ + Thread_Control *executing; + + executing = _Thread_Executing; + + /* + * Take care that 'begin' extensions get to complete before + * 'switch' extensions can run. This means must keep dispatch + * disabled until all 'begin' extensions complete. + */ + + _User_extensions_Thread_begin( executing ); + + /* + * At this point, the dispatch disable level BETTER be 1. + */ + + _Thread_Enable_dispatch(); + + switch ( executing->Start.prototype ) { + case THREAD_START_NUMERIC: + (*executing->Start.entry_point)( executing->Start.numeric_argument ); + break; + case THREAD_START_POINTER: + (*executing->Start.entry_point)( executing->Start.pointer_argument ); + break; + case THREAD_START_BOTH_POINTER_FIRST: + (*executing->Start.entry_point)( + executing->Start.pointer_argument, + executing->Start.numeric_argument + ); + break; + case THREAD_START_BOTH_NUMERIC_FIRST: + (*executing->Start.entry_point)( + executing->Start.numeric_argument, + executing->Start.pointer_argument + ); + break; + } + + _User_extensions_Thread_exitted( executing ); + + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_THREAD_EXITTED + ); +} + +/*PAGE + * + * _Thread_Delay_ended + * + * This routine processes a thread whose delay period has ended. + * It is called by the watchdog handler. + * + * Input parameters: + * id - thread id + * + * Output parameters: NONE + */ + +void _Thread_Delay_ended( + Objects_Id id, + void *ignored +) +{ + Thread_Control *the_thread; + Objects_Locations location; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + case OBJECTS_REMOTE: /* impossible */ + break; + case OBJECTS_LOCAL: + _Thread_Unblock( the_thread ); + _Thread_Unnest_dispatch(); + break; + } +} + +/*PAGE + * + * _Thread_Change_priority + * + * This kernel routine changes the priority of the thread. The + * thread chain is adjusted if necessary. + * + * Input parameters: + * the_thread - pointer to thread control block + * new_priority - ultimate priority + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * ready chain + * select heir + */ + +void _Thread_Change_priority( + Thread_Control *the_thread, + Priority_Control new_priority +) +{ + ISR_Level level; + + _Thread_Set_transient( the_thread ); + + if ( the_thread->current_priority != new_priority ) + _Thread_Set_priority( the_thread, new_priority ); + + _ISR_Disable( level ); + + the_thread->current_state = + _States_Clear( STATES_TRANSIENT, the_thread->current_state ); + + if ( ! _States_Is_ready( the_thread->current_state ) ) { + _ISR_Enable( level ); + return; + } + + _Priority_Add_to_bit_map( &the_thread->Priority_map ); + _Chain_Append_unprotected( the_thread->ready, &the_thread->Object.Node ); + + _ISR_Flash( level ); + + _Thread_Calculate_heir(); + + if ( !_Thread_Is_executing_also_the_heir() && + _Thread_Executing->is_preemptible ) + _Context_Switch_necessary = TRUE; + + _ISR_Enable( level ); +} + +/*PAGE + * + * _Thread_Set_priority + * + * This directive enables and disables several modes of + * execution for the requesting thread. + * + * Input parameters: + * the_thread - pointer to thread priority + * new_priority - new priority + * + * Output: NONE + */ + +void _Thread_Set_priority( + Thread_Control *the_thread, + Priority_Control new_priority +) +{ + the_thread->current_priority = new_priority; + the_thread->ready = &_Thread_Ready_chain[ new_priority ]; + + _Priority_Initialize_information( &the_thread->Priority_map, new_priority ); +} + +/*PAGE + * + * _Thread_Evaluate_mode + * + * XXX + */ + +boolean _Thread_Evaluate_mode( void ) +{ + Thread_Control *executing; + + executing = _Thread_Executing; + + if ( !_States_Is_ready( executing->current_state ) || + ( !_Thread_Is_heir( executing ) && executing->is_preemptible ) ) { + _Context_Switch_necessary = TRUE; + return TRUE; + } + + return FALSE; +} + +/*PAGE + * + * _Thread_Get + * + * NOTE: If we are not using static inlines, this must be a real + * subroutine call. + * + * NOTE: XXX... This routine may be able to be optimized. + */ + +#ifndef USE_INLINES + +Thread_Control *_Thread_Get ( + Objects_Id id, + Objects_Locations *location +) +{ + Objects_Classes the_class; + Objects_Information *information; + + if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) { + _Thread_Disable_dispatch(); + *location = OBJECTS_LOCAL; + return( _Thread_Executing ); + } + + the_class = _Objects_Get_class( id ); + + if ( the_class > OBJECTS_CLASSES_LAST ) { + *location = OBJECTS_ERROR; + return (Thread_Control *) 0; + } + + information = _Objects_Information_table[ the_class ]; + + if ( !information || !information->is_thread ) { + *location = OBJECTS_ERROR; + return (Thread_Control *) 0; + } + + return (Thread_Control *) _Objects_Get( information, id, location ); +} + +#endif + +/*PAGE + * + * _Thread_Idle_body + * + * This kernel routine is the idle thread. The idle thread runs any time + * no other thread is ready to run. This thread loops forever with + * interrupts enabled. + * + * Input parameters: + * ignored - this parameter is ignored + * + * Output parameters: NONE + */ + +#if (CPU_PROVIDES_IDLE_THREAD_BODY == FALSE) +Thread _Thread_Idle_body( + unsigned32 ignored +) +{ + for( ; ; ) ; +} +#endif diff --git a/cpukit/score/src/threadmp.c b/cpukit/score/src/threadmp.c new file mode 100644 index 0000000000..31f7e5ff62 --- /dev/null +++ b/cpukit/score/src/threadmp.c @@ -0,0 +1,164 @@ +/* + * Multiprocessing Support for the Thread 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/system.h> +#include <rtems/score/priority.h> +#include <rtems/score/thread.h> +#include <rtems/score/wkspace.h> +#include <rtems/score/isr.h> + +/*PAGE + * + * _Thread_MP_Handler_initialization + * + */ + +void _Thread_MP_Handler_initialization ( + unsigned32 maximum_proxies +) +{ + + _Chain_Initialize_empty( &_Thread_MP_Active_proxies ); + + if ( maximum_proxies == 0 ) { + _Chain_Initialize_empty( &_Thread_MP_Inactive_proxies ); + return; + } + + + _Chain_Initialize( + &_Thread_MP_Inactive_proxies, + _Workspace_Allocate_or_fatal_error( + maximum_proxies * sizeof( Thread_Proxy_control ) + ), + maximum_proxies, + sizeof( Thread_Proxy_control ) + ); + +} + +/*PAGE + * + * _Thread_MP_Allocate_proxy + * + */ + +Thread_Control *_Thread_MP_Allocate_proxy ( + States_Control the_state +) +{ + Thread_Control *the_thread; + Thread_Proxy_control *the_proxy; + + the_thread = (Thread_Control *)_Chain_Get( &_Thread_MP_Inactive_proxies ); + + if ( !_Thread_Is_null( the_thread ) ) { + + the_proxy = (Thread_Proxy_control *) the_thread; + + _Thread_Executing->Wait.return_code = THREAD_STATUS_PROXY_BLOCKING; + + the_proxy->receive_packet = _Thread_MP_Receive->receive_packet; + + the_proxy->Object.id = _Thread_MP_Receive->receive_packet->source_tid; + + the_proxy->current_priority = + _Thread_MP_Receive->receive_packet->source_priority; + + the_proxy->current_state = _States_Set( STATES_DORMANT, the_state ); + + the_proxy->Wait = _Thread_Executing->Wait; + + _Chain_Append( &_Thread_MP_Active_proxies, &the_proxy->Active ); + + return the_thread; + } + + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_OUT_OF_PROXIES + ); + + /* + * NOTE: The following return insures that the compiler will + * think that all paths return a value. + */ + + return NULL; +} + +/*PAGE + * + * _Thread_MP_Find_proxy + * + */ + +/* + * The following macro provides the offset of the Active element + * in the Thread_Proxy_control structure. This is the logical + * equivalent of the POSITION attribute in Ada. + */ + +#define _Thread_MP_Proxy_Active_offset \ + ((unsigned32)&(((Thread_Proxy_control *)0))->Active) + +Thread_Control *_Thread_MP_Find_proxy ( + Objects_Id the_id +) +{ + + Chain_Node *proxy_node; + Thread_Control *the_thread; + ISR_Level level; + +restart: + + _ISR_Disable( level ); + + for ( proxy_node = _Thread_MP_Active_proxies.first; + !_Chain_Is_tail( &_Thread_MP_Active_proxies, proxy_node ) ; + ) { + + the_thread = _Addresses_Subtract_offset( + proxy_node, + _Thread_MP_Proxy_Active_offset + ); + + if ( _Objects_Are_ids_equal( the_thread->Object.id, the_id ) ) { + _ISR_Enable( level ); + return the_thread; + } + + _ISR_Flash( level ); + + proxy_node = proxy_node->next; + + /* + * A proxy which is only dormant is not in a blocking state. + * Therefore, we are looking at proxy which has been moved from + * active to inactive chain (by an ISR) and need to restart + * the search. + */ + + if ( _States_Is_only_dormant( the_thread->current_state ) ) { + _ISR_Enable( level ); + goto restart; + } + } + + _ISR_Enable( level ); + return NULL; +} diff --git a/cpukit/score/src/threadq.c b/cpukit/score/src/threadq.c new file mode 100644 index 0000000000..c02de10ee0 --- /dev/null +++ b/cpukit/score/src/threadq.c @@ -0,0 +1,967 @@ +/* + * Thread Queue 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/system.h> +#include <rtems/score/chain.h> +#include <rtems/score/isr.h> +#include <rtems/score/object.h> +#include <rtems/score/states.h> +#include <rtems/score/thread.h> +#include <rtems/score/threadq.h> +#include <rtems/score/tqdata.h> + +/*PAGE + * + * _Thread_queue_Initialize + * + * This routine initializes the specified threadq. + * + * Input parameters: + * the_thread_queue - pointer to a threadq header + * the_class - class of the object to which this belongs + * discipline - queueing discipline + * state - state of waiting threads + * proxy_extract_callout - MP specific callout + * timeout_status - return on a timeout + * + * Output parameters: NONE + */ + +void _Thread_queue_Initialize( + Thread_queue_Control *the_thread_queue, + Objects_Classes the_class, + Thread_queue_Disciplines the_discipline, + States_Control state, + Thread_queue_Extract_callout proxy_extract_callout, + unsigned32 timeout_status +) +{ + unsigned32 index; + + _Thread_queue_Extract_table[ the_class ] = proxy_extract_callout; + + the_thread_queue->state = state; + the_thread_queue->discipline = the_discipline; + the_thread_queue->timeout_status = timeout_status; + the_thread_queue->sync_state = THREAD_QUEUE_SYNCHRONIZED; + + switch ( the_discipline ) { + case THREAD_QUEUE_DISCIPLINE_FIFO: + _Chain_Initialize_empty( &the_thread_queue->Queues.Fifo ); + break; + case THREAD_QUEUE_DISCIPLINE_PRIORITY: + for( index=0 ; + index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ; + index++) + _Chain_Initialize_empty( &the_thread_queue->Queues.Priority[index] ); + break; + } + +} + +/*PAGE + * + * _Thread_queue_Enqueue + * + * This routine blocks a thread, places it on a thread, and optionally + * starts a timeout timer. + * + * Input parameters: + * the_thread_queue - pointer to threadq + * timeout - interval to wait + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * only case + */ + +void _Thread_queue_Enqueue( + Thread_queue_Control *the_thread_queue, + Watchdog_Interval timeout +) +{ + Thread_Control *the_thread; + + the_thread = _Thread_Executing; + + if ( _Thread_MP_Is_receive( the_thread ) && the_thread->receive_packet ) + the_thread = _Thread_MP_Allocate_proxy( the_thread_queue->state ); + else + _Thread_Set_state( the_thread, the_thread_queue->state ); + + if ( timeout ) { + _Watchdog_Initialize( + &the_thread->Timer, + _Thread_queue_Timeout, + the_thread->Object.id, + NULL + ); + + _Watchdog_Insert_ticks( &the_thread->Timer, timeout ); + } + + switch( the_thread_queue->discipline ) { + case THREAD_QUEUE_DISCIPLINE_FIFO: + _Thread_queue_Enqueue_fifo( the_thread_queue, the_thread, timeout ); + break; + case THREAD_QUEUE_DISCIPLINE_PRIORITY: + _Thread_queue_Enqueue_priority( the_thread_queue, the_thread, timeout ); + break; + } +} + +/*PAGE + * + * _Thread_queue_Dequeue + * + * This routine removes a thread from the specified threadq. If the + * threadq discipline is FIFO, it unblocks a thread, and cancels its + * timeout timer. Priority discipline is processed elsewhere. + * + * Input parameters: + * the_thread_queue - pointer to threadq + * + * Output parameters: + * returns - thread dequeued or NULL + * + * INTERRUPT LATENCY: + * check sync + */ + +Thread_Control *_Thread_queue_Dequeue( + Thread_queue_Control *the_thread_queue +) +{ + Thread_Control *the_thread; + + switch ( the_thread_queue->discipline ) { + case THREAD_QUEUE_DISCIPLINE_FIFO: + the_thread = _Thread_queue_Dequeue_fifo( the_thread_queue ); + break; + case THREAD_QUEUE_DISCIPLINE_PRIORITY: + the_thread = _Thread_queue_Dequeue_priority( the_thread_queue ); + break; + default: /* this is only to prevent warnings */ + the_thread = NULL; + break; + } + + return( the_thread ); +} + +/*PAGE + * + * _Thread_queue_Extract_with_proxy + * + * This routine extracts the_thread from the_thread_queue + * and insures that if there is a proxy for this task on + * another node, it is also dealt with. + * + * XXX + */ + +boolean _Thread_queue_Extract_with_proxy( + Thread_Control *the_thread +) +{ + States_Control state; + Objects_Classes the_class; + Thread_queue_Extract_callout proxy_extract_callout; + + state = the_thread->current_state; + + if ( _States_Is_waiting_on_thread_queue( state ) ) { + if ( _States_Is_waiting_for_rpc_reply( state ) && + _States_Is_locally_blocked( state ) ) { + + the_class = _Objects_Get_class( the_thread->Wait.id ); + + proxy_extract_callout = _Thread_queue_Extract_table[ the_class ]; + + if ( proxy_extract_callout ) + (*proxy_extract_callout)( the_thread ); + } + _Thread_queue_Extract( the_thread->Wait.queue, the_thread ); + + return TRUE; + } + return FALSE; +} + +/*PAGE + * + * _Thread_queue_Extract + * + * This routine removes a specific thread from the specified threadq, + * deletes any timeout, and unblocks the thread. + * + * Input parameters: + * the_thread_queue - pointer to a threadq header + * the_thread - pointer to a thread control block + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: NONE + */ + +void _Thread_queue_Extract( + Thread_queue_Control *the_thread_queue, + Thread_Control *the_thread +) +{ + switch ( the_thread_queue->discipline ) { + case THREAD_QUEUE_DISCIPLINE_FIFO: + _Thread_queue_Extract_fifo( the_thread_queue, the_thread ); + break; + case THREAD_QUEUE_DISCIPLINE_PRIORITY: + _Thread_queue_Extract_priority( the_thread_queue, the_thread ); + break; + } +} + +/*PAGE + * + * _Thread_queue_Flush + * + * This kernel routine flushes the given thread queue. + * + * Input parameters: + * the_thread_queue - pointer to threadq to be flushed + * remote_extract_callout - pointer to routine which extracts a remote thread + * status - status to return to the thread + * + * Output parameters: NONE + */ + +void _Thread_queue_Flush( + Thread_queue_Control *the_thread_queue, + Thread_queue_Flush_callout remote_extract_callout, + unsigned32 status +) +{ + Thread_Control *the_thread; + + while ( (the_thread = _Thread_queue_Dequeue( the_thread_queue )) ) { + if ( _Objects_Is_local_id( the_thread->Object.id ) ) + the_thread->Wait.return_code = status; + else + ( *remote_extract_callout )( the_thread ); + } +} + +/*PAGE + * + * _Thread_queue_First + * + * This routines returns a pointer to the first thread on the + * specified threadq. + * + * Input parameters: + * the_thread_queue - pointer to thread queue + * + * Output parameters: + * returns - first thread or NULL + */ + +Thread_Control *_Thread_queue_First( + Thread_queue_Control *the_thread_queue +) +{ + Thread_Control *the_thread; + + switch ( the_thread_queue->discipline ) { + case THREAD_QUEUE_DISCIPLINE_FIFO: + the_thread = _Thread_queue_First_fifo( the_thread_queue ); + break; + case THREAD_QUEUE_DISCIPLINE_PRIORITY: + the_thread = _Thread_queue_First_priority( the_thread_queue ); + break; + default: /* this is only to prevent warnings */ + the_thread = NULL; + break; + } + + return the_thread; +} + +/*PAGE + * + * _Thread_queue_Timeout + * + * This routine processes a thread which timeouts while waiting on + * a thread queue. It is called by the watchdog handler. + * + * Input parameters: + * id - thread id + * + * Output parameters: NONE + */ + +void _Thread_queue_Timeout( + Objects_Id id, + void *ignored +) +{ + Thread_Control *the_thread; + Thread_queue_Control *the_thread_queue; + Objects_Locations location; + + the_thread = _Thread_Get( id, &location ); + switch ( location ) { + case OBJECTS_ERROR: + case OBJECTS_REMOTE: /* impossible */ + break; + case OBJECTS_LOCAL: + the_thread_queue = the_thread->Wait.queue; + + /* + * If the_thread_queue is not synchronized, then it is either + * "nothing happened", "timeout", or "satisfied". If the_thread + * is the executing thread, then it is in the process of blocking + * and it is the thread which is responsible for the synchronization + * process. + * + * If it is not satisfied, then it is "nothing happened" and + * this is the "timeout" transition. After a request is satisfied, + * a timeout is not allowed to occur. + */ + + if ( the_thread_queue->sync_state != THREAD_QUEUE_SYNCHRONIZED && + _Thread_Is_executing( the_thread ) ) { + if ( the_thread_queue->sync_state != THREAD_QUEUE_SATISFIED ) + the_thread_queue->sync_state = THREAD_QUEUE_TIMEOUT; + } else { + the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status; + _Thread_queue_Extract( the_thread->Wait.queue, the_thread ); + } + _Thread_Unnest_dispatch(); + break; + } +} + +/*PAGE + * + * _Thread_queue_Enqueue_fifo + * + * This routine blocks a thread, places it on a thread, and optionally + * starts a timeout timer. + * + * Input parameters: + * the_thread_queue - pointer to threadq + * the_thread - pointer to the thread to block + * timeout - interval to wait + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * only case + */ + +void _Thread_queue_Enqueue_fifo ( + Thread_queue_Control *the_thread_queue, + Thread_Control *the_thread, + Watchdog_Interval timeout +) +{ + ISR_Level level; + Thread_queue_States sync_state; + + _ISR_Disable( level ); + + sync_state = the_thread_queue->sync_state; + the_thread_queue->sync_state = THREAD_QUEUE_SYNCHRONIZED; + + switch ( sync_state ) { + case THREAD_QUEUE_SYNCHRONIZED: + /* + * This should never happen. It indicates that someone did not + * enter a thread queue critical section. + */ + break; + + case THREAD_QUEUE_NOTHING_HAPPENED: + _Chain_Append_unprotected( + &the_thread_queue->Queues.Fifo, + &the_thread->Object.Node + ); + _ISR_Enable( level ); + return; + + case THREAD_QUEUE_TIMEOUT: + the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status; + _ISR_Enable( level ); + break; + + case THREAD_QUEUE_SATISFIED: + if ( _Watchdog_Is_active( &the_thread->Timer ) ) { + _Watchdog_Deactivate( &the_thread->Timer ); + _ISR_Enable( level ); + (void) _Watchdog_Remove( &the_thread->Timer ); + } else + _ISR_Enable( level ); + break; + } + + /* + * Global objects with thread queue's should not be operated on from an + * ISR. But the sync code still must allow short timeouts to be processed + * correctly. + */ + + _Thread_Unblock( the_thread ); + + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) + _Thread_MP_Free_proxy( the_thread ); + +} + +/*PAGE + * + * _Thread_queue_Dequeue_fifo + * + * This routine removes a thread from the specified threadq. + * + * Input parameters: + * the_thread_queue - pointer to threadq + * + * Output parameters: + * returns - thread dequeued or NULL + * + * INTERRUPT LATENCY: + * check sync + * FIFO + */ + +Thread_Control *_Thread_queue_Dequeue_fifo( + Thread_queue_Control *the_thread_queue +) +{ + ISR_Level level; + Thread_Control *the_thread; + + _ISR_Disable( level ); + if ( !_Chain_Is_empty( &the_thread_queue->Queues.Fifo ) ) { + + the_thread = (Thread_Control *) + _Chain_Get_first_unprotected( &the_thread_queue->Queues.Fifo ); + + if ( !_Watchdog_Is_active( &the_thread->Timer ) ) { + _ISR_Enable( level ); + _Thread_Unblock( the_thread ); + } else { + _Watchdog_Deactivate( &the_thread->Timer ); + _ISR_Enable( level ); + (void) _Watchdog_Remove( &the_thread->Timer ); + _Thread_Unblock( the_thread ); + } + + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) + _Thread_MP_Free_proxy( the_thread ); + + return the_thread; + } + + switch ( the_thread_queue->sync_state ) { + case THREAD_QUEUE_SYNCHRONIZED: + case THREAD_QUEUE_SATISFIED: + _ISR_Enable( level ); + return NULL; + + case THREAD_QUEUE_NOTHING_HAPPENED: + case THREAD_QUEUE_TIMEOUT: + the_thread_queue->sync_state = THREAD_QUEUE_SATISFIED; + _ISR_Enable( level ); + return _Thread_Executing; + } + return NULL; /* this is only to prevent warnings */ +} + +/*PAGE + * + * _Thread_queue_Extract_fifo + * + * This routine removes a specific thread from the specified threadq, + * deletes any timeout, and unblocks the thread. + * + * Input parameters: + * the_thread_queue - pointer to a threadq header + * the_thread - pointer to the thread to block + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * EXTRACT_FIFO + */ + +void _Thread_queue_Extract_fifo( + Thread_queue_Control *the_thread_queue, + Thread_Control *the_thread +) +{ + ISR_Level level; + + _ISR_Disable( level ); + + if ( !_States_Is_waiting_on_thread_queue( the_thread->current_state ) ) { + _ISR_Enable( level ); + return; + } + + _Chain_Extract_unprotected( &the_thread->Object.Node ); + + if ( !_Watchdog_Is_active( &the_thread->Timer ) ) { + _ISR_Enable( level ); + } else { + _Watchdog_Deactivate( &the_thread->Timer ); + _ISR_Enable( level ); + (void) _Watchdog_Remove( &the_thread->Timer ); + } + + _Thread_Unblock( the_thread ); + + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) + _Thread_MP_Free_proxy( the_thread ); + +} + +/*PAGE + * + * _Thread_queue_First_fifo + * + * This routines returns a pointer to the first thread on the + * specified threadq. + * + * Input parameters: + * the_thread_queue - pointer to threadq + * + * Output parameters: + * returns - first thread or NULL + */ + +Thread_Control *_Thread_queue_First_fifo( + Thread_queue_Control *the_thread_queue +) +{ + if ( !_Chain_Is_empty( &the_thread_queue->Queues.Fifo ) ) + return (Thread_Control *) the_thread_queue->Queues.Fifo.first; + + return NULL; +} + +/*PAGE + * + * _Thread_queue_Enqueue_priority + * + * This routine blocks a thread, places it on a thread, and optionally + * starts a timeout timer. + * + * Input parameters: + * the_thread_queue - pointer to threadq + * thread - thread to insert + * timeout - timeout interval in ticks + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * forward less than + * forward equal + */ + +void _Thread_queue_Enqueue_priority( + Thread_queue_Control *the_thread_queue, + Thread_Control *the_thread, + Watchdog_Interval timeout +) +{ + Priority_Control search_priority; + Thread_Control *search_thread; + ISR_Level level; + Chain_Control *header; + unsigned32 header_index; + Chain_Node *the_node; + Chain_Node *next_node; + Chain_Node *previous_node; + Chain_Node *search_node; + Priority_Control priority; + States_Control block_state; + Thread_queue_States sync_state; + + _Chain_Initialize_empty( &the_thread->Wait.Block2n ); + + priority = the_thread->current_priority; + header_index = _Thread_queue_Header_number( priority ); + header = &the_thread_queue->Queues.Priority[ header_index ]; + block_state = the_thread_queue->state; + + if ( _Thread_queue_Is_reverse_search( priority ) ) + goto restart_reverse_search; + +restart_forward_search: + search_priority = PRIORITY_MINIMUM - 1; + _ISR_Disable( level ); + search_thread = (Thread_Control *) header->first; + while ( !_Chain_Is_tail( header, (Chain_Node *)search_thread ) ) { + search_priority = search_thread->current_priority; + if ( priority <= search_priority ) + break; + +#if ( CPU_UNROLL_ENQUEUE_PRIORITY == TRUE ) + search_thread = (Thread_Control *) search_thread->Object.Node.next; + if ( _Chain_Is_tail( header, (Chain_Node *)search_thread ) ) + break; + search_priority = search_thread->current_priority; + if ( priority <= search_priority ) + break; +#endif + _ISR_Flash( level ); + if ( !_States_Are_set( search_thread->current_state, block_state) ) { + _ISR_Enable( level ); + goto restart_forward_search; + } + search_thread = + (Thread_Control *)search_thread->Object.Node.next; + } + + if ( the_thread_queue->sync_state != THREAD_QUEUE_NOTHING_HAPPENED ) + goto synchronize; + + the_thread_queue->sync_state = THREAD_QUEUE_SYNCHRONIZED; + + if ( priority == search_priority ) + goto equal_priority; + + search_node = (Chain_Node *) search_thread; + previous_node = search_node->previous; + the_node = (Chain_Node *) the_thread; + + the_node->next = search_node; + the_node->previous = previous_node; + previous_node->next = the_node; + search_node->previous = the_node; + _ISR_Enable( level ); + return; + +restart_reverse_search: + search_priority = PRIORITY_MAXIMUM + 1; + + _ISR_Disable( level ); + search_thread = (Thread_Control *) header->last; + while ( !_Chain_Is_head( header, (Chain_Node *)search_thread ) ) { + search_priority = search_thread->current_priority; + if ( priority >= search_priority ) + break; +#if ( CPU_UNROLL_ENQUEUE_PRIORITY == TRUE ) + search_thread = (Thread_Control *) search_thread->Object.Node.previous; + if ( _Chain_Is_head( header, (Chain_Node *)search_thread ) ) + break; + search_priority = search_thread->current_priority; + if ( priority >= search_priority ) + break; +#endif + _ISR_Flash( level ); + if ( !_States_Are_set( search_thread->current_state, block_state) ) { + _ISR_Enable( level ); + goto restart_reverse_search; + } + search_thread = (Thread_Control *) + search_thread->Object.Node.previous; + } + + if ( the_thread_queue->sync_state != THREAD_QUEUE_NOTHING_HAPPENED ) + goto synchronize; + + the_thread_queue->sync_state = THREAD_QUEUE_SYNCHRONIZED; + + if ( priority == search_priority ) + goto equal_priority; + + search_node = (Chain_Node *) search_thread; + next_node = search_node->next; + the_node = (Chain_Node *) the_thread; + + the_node->next = next_node; + the_node->previous = search_node; + search_node->next = the_node; + next_node->previous = the_node; + _ISR_Enable( level ); + return; + +equal_priority: /* add at end of priority group */ + search_node = _Chain_Tail( &search_thread->Wait.Block2n ); + previous_node = search_node->previous; + the_node = (Chain_Node *) the_thread; + + the_node->next = search_node; + the_node->previous = previous_node; + previous_node->next = the_node; + search_node->previous = the_node; + _ISR_Enable( level ); + return; + +synchronize: + + sync_state = the_thread_queue->sync_state; + the_thread_queue->sync_state = THREAD_QUEUE_SYNCHRONIZED; + + switch ( sync_state ) { + case THREAD_QUEUE_SYNCHRONIZED: + /* + * This should never happen. It indicates that someone did not + * enter a thread queue critical section. + */ + break; + + case THREAD_QUEUE_NOTHING_HAPPENED: + /* + * This should never happen. All of this was dealt with above. + */ + break; + + case THREAD_QUEUE_TIMEOUT: + the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status; + _ISR_Enable( level ); + break; + + case THREAD_QUEUE_SATISFIED: + if ( _Watchdog_Is_active( &the_thread->Timer ) ) { + _Watchdog_Deactivate( &the_thread->Timer ); + _ISR_Enable( level ); + (void) _Watchdog_Remove( &the_thread->Timer ); + } else + _ISR_Enable( level ); + break; + } + + /* + * Global objects with thread queue's should not be operated on from an + * ISR. But the sync code still must allow short timeouts to be processed + * correctly. + */ + + _Thread_Unblock( the_thread ); + + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) + _Thread_MP_Free_proxy( the_thread ); +} + +/*PAGE + * + * _Thread_queue_Dequeue_priority + * + * This routine removes a thread from the specified PRIORITY based + * threadq, unblocks it, and cancels its timeout timer. + * + * Input parameters: + * the_thread_queue - pointer to thread queue + * + * Output parameters: + * returns - thread dequeued or NULL + * + * INTERRUPT LATENCY: + * only case + */ + +Thread_Control *_Thread_queue_Dequeue_priority( + Thread_queue_Control *the_thread_queue +) +{ + unsigned32 index; + ISR_Level level; + Thread_Control *the_thread = NULL; /* just to remove warnings */ + Thread_Control *new_first_thread; + Chain_Node *new_first_node; + Chain_Node *new_second_node; + Chain_Node *last_node; + Chain_Node *next_node; + Chain_Node *previous_node; + + _ISR_Disable( level ); + for( index=0 ; + index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ; + index++ ) { + if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) { + the_thread = (Thread_Control *) + the_thread_queue->Queues.Priority[ index ].first; + goto dequeue; + } + } + + switch ( the_thread_queue->sync_state ) { + case THREAD_QUEUE_SYNCHRONIZED: + case THREAD_QUEUE_SATISFIED: + _ISR_Enable( level ); + return NULL; + + case THREAD_QUEUE_NOTHING_HAPPENED: + case THREAD_QUEUE_TIMEOUT: + the_thread_queue->sync_state = THREAD_QUEUE_SATISFIED; + _ISR_Enable( level ); + return _Thread_Executing; + } + +dequeue: + new_first_node = the_thread->Wait.Block2n.first; + new_first_thread = (Thread_Control *) new_first_node; + next_node = the_thread->Object.Node.next; + previous_node = the_thread->Object.Node.previous; + + if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) { + last_node = the_thread->Wait.Block2n.last; + new_second_node = new_first_node->next; + + previous_node->next = new_first_node; + next_node->previous = new_first_node; + new_first_node->next = next_node; + new_first_node->previous = previous_node; + + if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) { + /* > two threads on 2-n */ + new_second_node->previous = + _Chain_Head( &new_first_thread->Wait.Block2n ); + + new_first_thread->Wait.Block2n.first = new_second_node; + new_first_thread->Wait.Block2n.last = last_node; + + last_node->next = _Chain_Tail( &new_first_thread->Wait.Block2n ); + } + } else { + previous_node->next = next_node; + next_node->previous = previous_node; + } + + if ( !_Watchdog_Is_active( &the_thread->Timer ) ) { + _ISR_Enable( level ); + _Thread_Unblock( the_thread ); + } else { + _Watchdog_Deactivate( &the_thread->Timer ); + _ISR_Enable( level ); + (void) _Watchdog_Remove( &the_thread->Timer ); + _Thread_Unblock( the_thread ); + } + + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) + _Thread_MP_Free_proxy( the_thread ); + return( the_thread ); +} + +/*PAGE + * + * _Thread_queue_Extract_priority + * + * This routine removes a specific thread from the specified threadq, + * deletes any timeout, and unblocks the thread. + * + * Input parameters: + * the_thread_queue - pointer to a threadq header + * the_thread - pointer to a thread control block + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * EXTRACT_PRIORITY + */ + +void _Thread_queue_Extract_priority( + Thread_queue_Control *the_thread_queue, + Thread_Control *the_thread +) +{ + ISR_Level level; + Chain_Node *the_node; + Chain_Node *next_node; + Chain_Node *previous_node; + Thread_Control *new_first_thread; + Chain_Node *new_first_node; + Chain_Node *new_second_node; + Chain_Node *last_node; + + the_node = (Chain_Node *) the_thread; + _ISR_Disable( level ); + if ( _States_Is_waiting_on_thread_queue( the_thread->current_state ) ) { + next_node = the_node->next; + previous_node = the_node->previous; + + if ( !_Chain_Is_empty( &the_thread->Wait.Block2n ) ) { + new_first_node = the_thread->Wait.Block2n.first; + new_first_thread = (Thread_Control *) new_first_node; + last_node = the_thread->Wait.Block2n.last; + new_second_node = new_first_node->next; + + previous_node->next = new_first_node; + next_node->previous = new_first_node; + new_first_node->next = next_node; + new_first_node->previous = previous_node; + + if ( !_Chain_Has_only_one_node( &the_thread->Wait.Block2n ) ) { + /* > two threads on 2-n */ + new_second_node->previous = + _Chain_Head( &new_first_thread->Wait.Block2n ); + new_first_thread->Wait.Block2n.first = new_second_node; + + new_first_thread->Wait.Block2n.last = last_node; + last_node->next = _Chain_Tail( &new_first_thread->Wait.Block2n ); + } + } else { + previous_node->next = next_node; + next_node->previous = previous_node; + } + + if ( !_Watchdog_Is_active( &the_thread->Timer ) ) { + _ISR_Enable( level ); + _Thread_Unblock( the_thread ); + } else { + _Watchdog_Deactivate( &the_thread->Timer ); + _ISR_Enable( level ); + (void) _Watchdog_Remove( &the_thread->Timer ); + _Thread_Unblock( the_thread ); + } + + if ( !_Objects_Is_local_id( the_thread->Object.id ) ) + _Thread_MP_Free_proxy( the_thread ); + } + else + _ISR_Enable( level ); +} + +/*PAGE + * + * _Thread_queue_First_priority + * + * This routines returns a pointer to the first thread on the + * specified threadq. + * + * Input parameters: + * the_thread_queue - pointer to thread queue + * + * Output parameters: + * returns - first thread or NULL + */ + +Thread_Control *_Thread_queue_First_priority ( + Thread_queue_Control *the_thread_queue +) +{ + unsigned32 index; + + for( index=0 ; + index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ; + index++ ) { + if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) + return (Thread_Control *) + the_thread_queue->Queues.Priority[ index ].first; + } + return NULL; +} diff --git a/cpukit/score/src/userext.c b/cpukit/score/src/userext.c new file mode 100644 index 0000000000..6261220d58 --- /dev/null +++ b/cpukit/score/src/userext.c @@ -0,0 +1,204 @@ +/* + * User Extension Handler + * + * NOTE: XXX + * + * 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/system.h> +#include <rtems/score/userext.h> + +/*PAGE + * + * _User_extensions_Thread_create + */ + +boolean _User_extensions_Thread_create ( + Thread_Control *the_thread +) +{ + Chain_Node *the_node; + User_extensions_Control *the_extension; + boolean status; + + for ( the_node = _User_extensions_List.first ; + !_Chain_Is_tail( &_User_extensions_List, the_node ) ; + the_node = the_node->next ) { + + the_extension = (User_extensions_Control *) the_node; + + if ( the_extension->Callouts.thread_create != NULL ) { + status = (*the_extension->Callouts.thread_create)( + _Thread_Executing, + the_thread + ); + if ( !status ) + return FALSE; + } + } + + return TRUE; +} + +/*PAGE + * + * _User_extensions_Thread_delete + */ + +void _User_extensions_Thread_delete ( + Thread_Control *the_thread +) +{ + Chain_Node *the_node; + User_extensions_Control *the_extension; + + for ( the_node = _User_extensions_List.last ; + !_Chain_Is_head( &_User_extensions_List, the_node ) ; + the_node = the_node->previous ) { + + the_extension = (User_extensions_Control *) the_node; + + if ( the_extension->Callouts.thread_delete != NULL ) + (*the_extension->Callouts.thread_delete)( + _Thread_Executing, + the_thread + ); + } +} + +/*PAGE + * + * _User_extensions_Thread_start + * + */ + +void _User_extensions_Thread_start ( + Thread_Control *the_thread +) +{ + Chain_Node *the_node; + User_extensions_Control *the_extension; + + for ( the_node = _User_extensions_List.first ; + !_Chain_Is_tail( &_User_extensions_List, the_node ) ; + the_node = the_node->next ) { + + the_extension = (User_extensions_Control *) the_node; + + if ( the_extension->Callouts.thread_start != NULL ) + (*the_extension->Callouts.thread_start)( + _Thread_Executing, + the_thread + ); + } +} + +/*PAGE + * + * _User_extensions_Thread_restart + * + */ + +void _User_extensions_Thread_restart ( + Thread_Control *the_thread +) +{ + Chain_Node *the_node; + User_extensions_Control *the_extension; + + for ( the_node = _User_extensions_List.first ; + !_Chain_Is_tail( &_User_extensions_List, the_node ) ; + the_node = the_node->next ) { + + the_extension = (User_extensions_Control *) the_node; + + if ( the_extension->Callouts.thread_restart != NULL ) + (*the_extension->Callouts.thread_restart)( + _Thread_Executing, + the_thread + ); + } +} + +/*PAGE + * + * _User_extensions_Thread_begin + * + */ + +void _User_extensions_Thread_begin ( + Thread_Control *executing +) +{ + Chain_Node *the_node; + User_extensions_Control *the_extension; + + for ( the_node = _User_extensions_List.first ; + !_Chain_Is_tail( &_User_extensions_List, the_node ) ; + the_node = the_node->next ) { + + the_extension = (User_extensions_Control *) the_node; + + if ( the_extension->Callouts.thread_begin != NULL ) + (*the_extension->Callouts.thread_begin)( executing ); + } +} + +/*PAGE + * + * _User_extensions_Thread_exitted + */ + +void _User_extensions_Thread_exitted ( + Thread_Control *executing +) +{ + Chain_Node *the_node; + User_extensions_Control *the_extension; + + for ( the_node = _User_extensions_List.last ; + !_Chain_Is_head( &_User_extensions_List, the_node ) ; + the_node = the_node->previous ) { + + the_extension = (User_extensions_Control *) the_node; + + if ( the_extension->Callouts.thread_exitted != NULL ) + (*the_extension->Callouts.thread_exitted)( executing ); + } +} + +/*PAGE + * + * _User_extensions_Fatal + */ + +void _User_extensions_Fatal ( + Internal_errors_Source the_source, + boolean is_internal, + unsigned32 the_error +) +{ + Chain_Node *the_node; + User_extensions_Control *the_extension; + + for ( the_node = _User_extensions_List.last ; + !_Chain_Is_head( &_User_extensions_List, the_node ) ; + the_node = the_node->previous ) { + + the_extension = (User_extensions_Control *) the_node; + + if ( the_extension->Callouts.fatal != NULL ) + (*the_extension->Callouts.fatal)( the_source, is_internal, the_error ); + } +} + + diff --git a/cpukit/score/src/watchdog.c b/cpukit/score/src/watchdog.c new file mode 100644 index 0000000000..0f72bd3d5c --- /dev/null +++ b/cpukit/score/src/watchdog.c @@ -0,0 +1,267 @@ +/* + * Watchdog 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/system.h> +#include <rtems/score/isr.h> +#include <rtems/score/watchdog.h> + +/*PAGE + * + * _Watchdog_Handler_initialization + * + * This routine initializes the watchdog handler. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _Watchdog_Handler_initialization( void ) +{ + _Watchdog_Sync_count = 0; + _Watchdog_Sync_level = 0; + _Chain_Initialize_empty( &_Watchdog_Ticks_chain ); + _Chain_Initialize_empty( &_Watchdog_Seconds_chain ); +} + +/*PAGE + * + * _Watchdog_Remove + * + * The routine removes a watchdog from a delta chain and updates + * the delta counters of the remaining watchdogs. + */ + +Watchdog_States _Watchdog_Remove( + Watchdog_Control *the_watchdog +) +{ + ISR_Level level; + Watchdog_States previous_state; + Watchdog_Control *next_watchdog; + + _ISR_Disable( level ); + previous_state = the_watchdog->state; + switch ( previous_state ) { + case WATCHDOG_INACTIVE: + break; + + case WATCHDOG_BEING_INSERTED: + + /* + * It is not actually on the chain so just change the state and + * the Insert operation we interrupted will be aborted. + */ + the_watchdog->state = WATCHDOG_INACTIVE; + break; + + case WATCHDOG_ACTIVE: + case WATCHDOG_REMOVE_IT: + + the_watchdog->state = WATCHDOG_INACTIVE; + next_watchdog = _Watchdog_Next( the_watchdog ); + + if ( _Watchdog_Next(next_watchdog) ) + next_watchdog->delta_interval += the_watchdog->delta_interval; + + if ( _Watchdog_Sync_count ) + _Watchdog_Sync_level = _ISR_Nest_level; + + _Chain_Extract_unprotected( &the_watchdog->Node ); + break; + } + _ISR_Enable( level ); + return( previous_state ); +} + +/*PAGE + * + * _Watchdog_Adjust + * + * This routine adjusts the delta chain backward or forward in response + * to a time change. + * + * Input parameters: + * header - pointer to the delta chain to be adjusted + * direction - forward or backward adjustment to delta chain + * units - units to adjust + * + * Output parameters: + */ + +void _Watchdog_Adjust( + Chain_Control *header, + Watchdog_Adjust_directions direction, + Watchdog_Interval units +) +{ + if ( !_Chain_Is_empty( header ) ) { + switch ( direction ) { + case WATCHDOG_BACKWARD: + _Watchdog_First( header )->delta_interval += units; + break; + case WATCHDOG_FORWARD: + while ( units ) { + if ( units < _Watchdog_First( header )->delta_interval ) { + _Watchdog_First( header )->delta_interval -= units; + break; + } else { + units -= _Watchdog_First( header )->delta_interval; + _Watchdog_First( header )->delta_interval = 1; + _Watchdog_Tickle( header ); + if ( _Chain_Is_empty( header ) ) + break; + } + } + break; + } + } +} + +/*PAGE + * + * _Watchdog_Insert + * + * This routine inserts a watchdog timer on to the appropriate delta + * chain while updating the delta interval counters. + */ + +void _Watchdog_Insert( + Chain_Control *header, + Watchdog_Control *the_watchdog +) +{ + ISR_Level level; + Watchdog_Control *after; + unsigned32 insert_isr_nest_level; + Watchdog_Interval delta_interval; + + + insert_isr_nest_level = _ISR_Nest_level; + the_watchdog->state = WATCHDOG_BEING_INSERTED; + + _Watchdog_Sync_count++; +restart: + delta_interval = the_watchdog->initial; + + _ISR_Disable( level ); + + for ( after = _Watchdog_First( header ) ; + ; + after = _Watchdog_Next( after ) ) { + + if ( delta_interval == 0 || !_Watchdog_Next( after ) ) + break; + + if ( delta_interval < after->delta_interval ) { + after->delta_interval -= delta_interval; + break; + } + + delta_interval -= after->delta_interval; + + /* + * If you experience problems comment out the _ISR_Flash line. + * 3.2.0 was the first release with this critical section redesigned. + * Under certain circumstances, the PREVIOUS critical section algorithm + * used around this flash point allowed interrupts to execute + * which violated the design assumptions. The critical section + * mechanism used here WAS redesigned to address this. + */ + + _ISR_Flash( level ); + + if ( the_watchdog->state != WATCHDOG_BEING_INSERTED ) { + goto exit_insert; + } + + if ( _Watchdog_Sync_level > insert_isr_nest_level ) { + _Watchdog_Sync_level = insert_isr_nest_level; + _ISR_Enable( level ); + goto restart; + } + } + + _Watchdog_Activate( the_watchdog ); + + the_watchdog->delta_interval = delta_interval; + + _Chain_Insert_unprotected( after->Node.previous, &the_watchdog->Node ); + +exit_insert: + _Watchdog_Sync_level = insert_isr_nest_level; + _Watchdog_Sync_count--; + _ISR_Enable( level ); +} + +/*PAGE + * + * _Watchdog_Tickle + * + * This routine decrements the delta counter in response to a tick. The + * delta chain is updated accordingly. + * + * Input parameters: + * header - pointer to the delta chain to be tickled + * + * Output parameters: NONE + */ + +void _Watchdog_Tickle( + Chain_Control *header +) +{ + Watchdog_Control *the_watchdog; + + if ( _Chain_Is_empty( header ) ) + return; + + the_watchdog = _Watchdog_First( header ); + the_watchdog->delta_interval--; + if ( the_watchdog->delta_interval != 0 ) + return; + + do { + switch( _Watchdog_Remove( the_watchdog ) ) { + case WATCHDOG_ACTIVE: + (*the_watchdog->routine)( + the_watchdog->id, + the_watchdog->user_data + ); + break; + + case WATCHDOG_INACTIVE: + /* + * This state indicates that the watchdog is not on any chain. + * Thus, it is NOT on a chain being tickled. This case should + * never occur. + */ + break; + + case WATCHDOG_BEING_INSERTED: + /* + * This state indicates that the watchdog is in the process of + * BEING inserted on the chain. Thus, it can NOT be on a chain + * being tickled. This case should never occur. + */ + break; + + case WATCHDOG_REMOVE_IT: + break; + } + the_watchdog = _Watchdog_First( header ); + } while ( !_Chain_Is_empty( header ) && + (the_watchdog->delta_interval == 0) ); +} diff --git a/cpukit/score/src/wkspace.c b/cpukit/score/src/wkspace.c new file mode 100644 index 0000000000..1dda9408bb --- /dev/null +++ b/cpukit/score/src/wkspace.c @@ -0,0 +1,88 @@ +/* + * Workspace Handler + * + * XXX + * + * NOTE: + * + * 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/system.h> +#include <rtems/score/wkspace.h> +#include <rtems/score/interr.h> + +/*PAGE + * + * _Workspace_Handler_initialization + */ + +void _Workspace_Handler_initialization( + void *starting_address, + unsigned32 size +) +{ + unsigned32 *zero_out_array; + unsigned32 index; + unsigned32 memory_available; + + if ( !starting_address || !_Addresses_Is_aligned( starting_address ) ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_INVALID_WORKSPACE_ADDRESS + ); + + if ( _CPU_Table.do_zero_of_workspace ) { + for( zero_out_array = (unsigned32 *) starting_address, index = 0 ; + index < size / 4 ; + index++ ) + zero_out_array[ index ] = 0; + } + + memory_available = _Heap_Initialize( + &_Workspace_Area, + starting_address, + size, + CPU_HEAP_ALIGNMENT + ); + + if ( memory_available == 0 ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_TOO_LITTLE_WORKSPACE + ); +} + +/*PAGE + * + * _Workspace_Allocate_or_fatal_error + * + */ + +void *_Workspace_Allocate_or_fatal_error( + unsigned32 size +) +{ + void *memory; + + memory = _Workspace_Allocate( size ); + + if ( memory == NULL ) + _Internal_error_Occurred( + INTERNAL_ERROR_CORE, + TRUE, + INTERNAL_ERROR_WORKSPACE_ALLOCATION + ); + + return memory; +} |