diff options
Diffstat (limited to '')
22 files changed, 1398 insertions, 319 deletions
diff --git a/c/src/lib/libbsp/m68k/dmv152/clock/ckinit.c b/c/src/lib/libbsp/m68k/dmv152/clock/ckinit.c index d5f0f5e023..8715cdcc26 100644 --- a/c/src/lib/libbsp/m68k/dmv152/clock/ckinit.c +++ b/c/src/lib/libbsp/m68k/dmv152/clock/ckinit.c @@ -19,36 +19,46 @@ */ #include <stdlib.h> - -#include <rtems.h> + #include <bsp.h> -#include <clockdrv.h> +#include <rtems/libio.h> rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ volatile rtems_unsigned32 Clock_driver_ticks; /* ticks since initialization */ rtems_isr_entry Old_ticker; -rtems_device_driver Clock_initialize( - rtems_device_major_number major, - rtems_device_minor_number minor, - void *pargp, - rtems_id tid, - rtems_unsigned32 *rval -) -{ - Install_clock( Clock_isr ); -} +void Clock_exit( void ); -void ReInstall_clock( - rtems_isr_entry clock_isr +#define CLOCK_VECTOR TIMER_VECTOR + +/* + * These are set by clock driver during its init + */ + +rtems_device_major_number rtems_clock_major = ~0; +rtems_device_minor_number rtems_clock_minor; + +/* + * ISR Handler + */ + +rtems_isr Clock_isr( + rtems_vector_number vector ) { - rtems_unsigned32 isrlevel = 0 ; + Clock_driver_ticks += 1; - rtems_interrupt_disable( isrlevel ); - (void) set_vector( clock_isr, TIMER_VECTOR, 1 ); - rtems_interrupt_enable( isrlevel ); + Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xE2 ); + Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x22 ); + Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xC6 ); + + if ( Clock_isrs == 1 ) { + rtems_clock_tick(); + Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; + } + else + Clock_isrs -= 1; } void Install_clock( @@ -61,7 +71,7 @@ void Install_clock( Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; if ( BSP_Configuration.ticks_per_timeslice ) { - Old_ticker = (rtems_isr_entry) set_vector( clock_isr, TIMER_VECTOR, 1 ); + Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); Z8x36_WRITE( TIMER, MASTER_CFG, 0xd4 ); Z8x36_READ ( TIMER, MASTER_INTR, data ); @@ -69,7 +79,7 @@ void Install_clock( Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x04 ); Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0xCE ); Z8x36_WRITE( TIMER, CT1_MODE_SPEC, 0x83 ); - Z8x36_WRITE( TIMER, CNT_TMR_VECTOR, TIMER_VECTOR ); + Z8x36_WRITE( TIMER, CNT_TMR_VECTOR, CLOCK_VECTOR ); Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x20 ); Z8x36_READ ( TIMER, MASTER_INTR, data ); Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0xDA) | 0x80 ); @@ -87,6 +97,17 @@ void Install_clock( } } +void ReInstall_clock( + rtems_isr_entry clock_isr +) +{ + rtems_unsigned32 isrlevel = 0 ; + + rtems_interrupt_disable( isrlevel ); + (void) set_vector( clock_isr, CLOCK_VECTOR, 1 ); + rtems_interrupt_enable( isrlevel ); +} + void Clock_exit( void ) { rtems_unsigned8 data; @@ -99,3 +120,51 @@ void Clock_exit( void ) } } + +rtems_device_driver Clock_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +) +{ + Install_clock( Clock_isr ); + + /* + * make major/minor avail to others such as shared memory driver + */ + + rtems_clock_major = major; + rtems_clock_minor = minor; + + return RTEMS_SUCCESSFUL; +} + +rtems_device_driver Clock_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +) +{ + rtems_libio_ioctl_args_t *args = pargp; + + if (args == 0) + goto done; + + /* + * This is hokey, but until we get a defined interface + * to do this, it will just be this simple... + */ + + if (args->command == rtems_build_name('I', 'S', 'R', ' ')) + { + Clock_isr(CLOCK_VECTOR); + } + else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) + { + ReInstall_clock(args->buffer); + } + +done: + return RTEMS_SUCCESSFUL; +} + diff --git a/c/src/lib/libbsp/m68k/dmv152/console/console.c b/c/src/lib/libbsp/m68k/dmv152/console/console.c index bb0f365b9c..ed0cd801c8 100644 --- a/c/src/lib/libbsp/m68k/dmv152/console/console.c +++ b/c/src/lib/libbsp/m68k/dmv152/console/console.c @@ -14,10 +14,9 @@ #define D152_INIT -#include <rtems.h> -#include "console.h" -#include "bsp.h" - +#include <bsp.h> +#include <rtems/libio.h> + /* console_initialize * * This routine initializes the console IO driver. @@ -28,19 +27,27 @@ * * Return values: */ - + rtems_device_driver console_initialize( rtems_device_major_number major, rtems_device_minor_number minor, - void *arg, - rtems_id self, - rtems_unsigned32 *status + void *arg ) { - *status = RTEMS_SUCCESSFUL; + rtems_status_code status; + + status = rtems_io_register_name( + "/dev/console", + major, + (rtems_device_minor_number) 0 + ); + + if (status != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(status); + + return RTEMS_SUCCESSFUL; } - /* is_character_ready * * This routine returns TRUE if a character is available. @@ -139,48 +146,102 @@ void outbyte( } /* - * __read -- read bytes from the serial port. Ignore fd, since - * we only have stdin. + * Open entry point */ -int __read( - int fd, - char *buf, - int nbytes +rtems_device_driver console_open( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg ) { - int i = 0; + return RTEMS_SUCCESSFUL; +} + +/* + * Close entry point + */ + +rtems_device_driver console_close( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; +} + +/* + * read bytes from the serial port. We only have stdin. + */ - for (i = 0; i < nbytes; i++) { - *(buf + i) = inbyte(); - if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { - (*(buf + i++)) = '\n'; - (*(buf + i)) = 0; +rtems_device_driver console_read( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + rtems_libio_rw_args_t *rw_args; + char *buffer; + int maximum; + int count = 0; + + rw_args = (rtems_libio_rw_args_t *) arg; + + buffer = rw_args->buffer; + maximum = rw_args->count; + + for (count = 0; count < maximum; count++) { + buffer[ count ] = inbyte(); + if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { + buffer[ count++ ] = '\n'; + buffer[ count ] = 0; break; } } - return (i); + + rw_args->bytes_moved = count; + return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; } /* - * __write -- write bytes to the serial port. Ignore fd, since - * stdout and stderr are the same. Since we have no filesystem, - * open will only return an error. + * write bytes to the serial port. Stdout and stderr are the same. */ -int __write( - int fd, - char *buf, - int nbytes +rtems_device_driver console_write( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg ) { - int i; + int count; + int maximum; + rtems_libio_rw_args_t *rw_args; + char *buffer; - for (i = 0; i < nbytes; i++) { - if (*(buf + i) == '\n') { - outbyte ('\r'); + rw_args = (rtems_libio_rw_args_t *) arg; + + buffer = rw_args->buffer; + maximum = rw_args->count; + + for (count = 0; count < maximum; count++) { + if ( buffer[ count ] == '\n') { + outbyte('\r'); } - outbyte (*(buf + i)); + outbyte( buffer[ count ] ); } - return (nbytes); + return maximum; +} + +/* + * IO Control entry point + */ + +rtems_device_driver console_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; } diff --git a/c/src/lib/libbsp/m68k/dmv152/include/bsp.h b/c/src/lib/libbsp/m68k/dmv152/include/bsp.h index c2d3918e7f..5a31136005 100644 --- a/c/src/lib/libbsp/m68k/dmv152/include/bsp.h +++ b/c/src/lib/libbsp/m68k/dmv152/include/bsp.h @@ -21,7 +21,10 @@ extern "C" { #endif #include <rtems.h> +#include <console.h> +#include <clockdrv.h> #include <iosupp.h> +#include <vmeintr.h> #include <z8530.h> #include <z8536.h> @@ -151,6 +154,24 @@ extern rtems_configuration_table BSP_Configuration; extern m68k_isr_entry M68Kvec[]; /* vector table address */ +/* + * Device Driver Table Entries + */ + +/* + * NOTE: Use the standard Console driver entry + */ + +/* + * NOTE: Use the standard Clock driver entry + */ + +/* + * How many libio files we want + */ + +#define BSP_LIBIO_MAX_FDS 20 + /* functions */ void bsp_cleanup( void ); diff --git a/c/src/lib/libbsp/m68k/dmv152/startup/bspstart.c b/c/src/lib/libbsp/m68k/dmv152/startup/bspstart.c index e66abc9ad2..4079ee4a8e 100644 --- a/c/src/lib/libbsp/m68k/dmv152/startup/bspstart.c +++ b/c/src/lib/libbsp/m68k/dmv152/startup/bspstart.c @@ -21,11 +21,17 @@ * $Id$ */ -#include <rtems.h> #include <bsp.h> +#include <rtems/libio.h> + #include <libcsupport.h> -#include <vmeintr.h> - + +#include <string.h> +#include <fcntl.h> + +#ifdef STACK_CHECKER_ON +#include <stackchk.h> +#endif /* * The original table from the application and our copy of it with * some changes. @@ -36,6 +42,8 @@ rtems_configuration_table BSP_Configuration; rtems_cpu_table Cpu_table; +char *rtems_progname; + /* Initialize whatever libc we are using * called from postdriver hook */ @@ -52,6 +60,14 @@ void bsp_libc_init() RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0); /* + * Init the RTEMS libio facility to provide UNIX-like system + * calls for use by newlib (ie: provide __open, __close, etc) + * Uses malloc() to get area for the iops, so must be after malloc init + */ + + rtems_libio_init(); + + /* * Set up for the libc handling. */ @@ -69,7 +85,33 @@ void bsp_libc_init() #endif } -int bsp_start( +/* + * After drivers are setup, register some "filenames" + * and open stdin, stdout, stderr files + * + * Newlib will automatically associate the files with these + * (it hardcodes the numbers) + */ + +void +bsp_postdriver_hook(void) +{ + int stdin_fd, stdout_fd, stderr_fd; + + if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1) + rtems_fatal_error_occurred('STD0'); + + if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1) + rtems_fatal_error_occurred('STD1'); + + if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1) + rtems_fatal_error_occurred('STD2'); + + if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2)) + rtems_fatal_error_occurred('STIO'); +} + +int main( int argc, char **argv, char **environp @@ -79,6 +121,11 @@ int bsp_start( int index; void *vbr; + if ((argc > 0) && argv && argv[0]) + rtems_progname = argv[0]; + else + rtems_progname = "RTEMS"; + monitors_vector_table = (m68k_isr_entry *)0; /* Monitor Vectors are at 0 */ m68k_set_vbr( monitors_vector_table ); @@ -115,7 +162,7 @@ int bsp_start( Cpu_table.predriver_hook = bsp_libc_init; /* RTEMS resources available */ - Cpu_table.postdriver_hook = NULL; /* Call our main() for constructors */ + Cpu_table.postdriver_hook = bsp_postdriver_hook; Cpu_table.idle_task = NULL; /* do not override system IDLE task */ @@ -159,6 +206,12 @@ int bsp_start( BSP_Configuration.maximum_extensions++; #endif + /* + * Tell libio how many fd's we want and allow it to tweak config + */ + + rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); + rtems_initialize_executive( &BSP_Configuration, &Cpu_table ); /* does not return */ diff --git a/c/src/lib/libbsp/m68k/gen68302/clock/ckinit.c b/c/src/lib/libbsp/m68k/gen68302/clock/ckinit.c index be3cf6ab21..f842bbc83c 100644 --- a/c/src/lib/libbsp/m68k/gen68302/clock/ckinit.c +++ b/c/src/lib/libbsp/m68k/gen68302/clock/ckinit.c @@ -20,11 +20,12 @@ #include <stdlib.h> /* for atexit() */ -#include <rtems.h> #include <bsp.h> -#include <clockdrv.h> +#include <rtems/libio.h> + #include "m68302.h" +#define CLOCK_VECTOR 137 #define TMR1_VAL ( RBIT_TMR_RST /* software reset the timer */\ | RBIT_TMR_ICLK_MASTER16 /* master clock divided by 16 */\ @@ -49,18 +50,35 @@ volatile rtems_unsigned32 Clock_driver_ticks; */ rtems_unsigned32 Clock_isrs; +void Clock_exit( void ); + +/* + * These are set by clock driver during its init + */ + +rtems_device_major_number rtems_clock_major = ~0; +rtems_device_minor_number rtems_clock_minor; -rtems_device_driver Clock_initialize( - rtems_device_major_number major, - rtems_device_minor_number minor, - void *pargp, - rtems_id tid, - rtems_unsigned32 *rval +/* + * ISR Handler + */ + +rtems_isr Clock_isr( + rtems_vector_number vector ) { - Install_clock( Clock_isr ); -} + Clock_driver_ticks += 1; + m302.reg.isr = RBIT_ISR_TIMER1; /* clear in-service bit */ + m302.reg.ter1 = (RBIT_TER_REF | RBIT_TER_CAP); /* clear timer intr request */ + + if ( Clock_isrs == 1 ) { + rtems_clock_tick(); + Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; + } + else + Clock_isrs -= 1; +} void Install_clock( rtems_isr_entry clock_isr @@ -71,7 +89,7 @@ void Install_clock( Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; if ( BSP_Configuration.ticks_per_timeslice ) { -/* set_vector( clock_isr, 137, 1 );*/ +/* set_vector( clock_isr, CLOCK_VECTOR, 1 );*/ m302.reg.trr1 = TRR1_VAL; /* set timer reference register */ m302.reg.tmr1 = TMR1_VAL; /* set timer mode register & enable */ @@ -84,6 +102,16 @@ void Install_clock( } } +void ReInstall_clock( + rtems_isr_entry clock_isr +) +{ + rtems_unsigned32 isrlevel; + + rtems_interrupt_disable( isrlevel ); + /* (void) set_vector( clock_isr, CLOCK_VECTOR, 1 ); */ + rtems_interrupt_enable( isrlevel ); +} void Clock_exit( void ) { @@ -92,3 +120,51 @@ void Clock_exit( void ) /* do not restore old vector */ } } + +rtems_device_driver Clock_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +) +{ + Install_clock( Clock_isr ); + + /* + * make major/minor avail to others such as shared memory driver + */ + + rtems_clock_major = major; + rtems_clock_minor = minor; + + return RTEMS_SUCCESSFUL; +} + +rtems_device_driver Clock_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +) +{ + rtems_libio_ioctl_args_t *args = pargp; + + if (args == 0) + goto done; + + /* + * This is hokey, but until we get a defined interface + * to do this, it will just be this simple... + */ + + if (args->command == rtems_build_name('I', 'S', 'R', ' ')) + { + Clock_isr( CLOCK_VECTOR); + } + else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) + { + ReInstall_clock(args->buffer); + } + +done: + return RTEMS_SUCCESSFUL; +} + diff --git a/c/src/lib/libbsp/m68k/gen68302/console/console.c b/c/src/lib/libbsp/m68k/gen68302/console/console.c index 7f488c5cfd..dd461e4557 100644 --- a/c/src/lib/libbsp/m68k/gen68302/console/console.c +++ b/c/src/lib/libbsp/m68k/gen68302/console/console.c @@ -14,9 +14,8 @@ #define GEN68302_INIT -#include <rtems.h> -#include "console.h" #include <bsp.h> +#include <rtems/libio.h> #include "m68302.h" @@ -34,11 +33,10 @@ rtems_device_driver console_initialize( rtems_device_major_number major, rtems_device_minor_number minor, - void *arg, - rtems_id self, - rtems_unsigned32 *status + void *arg ) { + rtems_status_code status; volatile m302_dualPortRAM_t *p = &m302; p->reg.pacnt |= 0x0003; /* enable RXD2 and TXD2 signals */ @@ -81,9 +79,18 @@ rtems_device_driver console_initialize( p->reg.scc[1].sccm = 0x03; /* enable only Tx & Rx interrupts */ p->reg.scc[1].scm = 0x01BD; - *status = RTEMS_SUCCESSFUL; -} + status = rtems_io_register_name( + "/dev/console", + major, + (rtems_device_minor_number) 0 + ); + + if (status != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(status); + + return RTEMS_SUCCESSFUL; +} /* is_character_ready * @@ -194,48 +201,102 @@ void outbyte( } /* - * __read -- read bytes from the serial port. Ignore fd, since - * we only have stdin. + * Open entry point + */ + +rtems_device_driver console_open( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; +} + +/* + * Close entry point */ -int __read( - int fd, - char *buf, - int nbytes +rtems_device_driver console_close( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg ) { - int i = 0; + return RTEMS_SUCCESSFUL; +} + +/* + * read bytes from the serial port. We only have stdin. + */ - for (i = 0; i < nbytes; i++) { - *(buf + i) = inbyte(); - if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { - (*(buf + i++)) = '\n'; - (*(buf + i)) = 0; +rtems_device_driver console_read( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + rtems_libio_rw_args_t *rw_args; + char *buffer; + int maximum; + int count = 0; + + rw_args = (rtems_libio_rw_args_t *) arg; + + buffer = rw_args->buffer; + maximum = rw_args->count; + + for (count = 0; count < maximum; count++) { + buffer[ count ] = inbyte(); + if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { + buffer[ count++ ] = '\n'; + buffer[ count ] = 0; break; } } - return (i); + + rw_args->bytes_moved = count; + return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; } /* - * __write -- write bytes to the serial port. Ignore fd, since - * stdout and stderr are the same. Since we have no filesystem, - * open will only return an error. + * write bytes to the serial port. Stdout and stderr are the same. */ -int __write( - int fd, - char *buf, - int nbytes +rtems_device_driver console_write( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg ) { - int i; + int count; + int maximum; + rtems_libio_rw_args_t *rw_args; + char *buffer; - for (i = 0; i < nbytes; i++) { - if (*(buf + i) == '\n') { - outbyte ('\r'); + rw_args = (rtems_libio_rw_args_t *) arg; + + buffer = rw_args->buffer; + maximum = rw_args->count; + + for (count = 0; count < maximum; count++) { + if ( buffer[ count ] == '\n') { + outbyte('\r'); } - outbyte (*(buf + i)); + outbyte( buffer[ count ] ); } - return (nbytes); + return maximum; +} + +/* + * IO Control entry point + */ + +rtems_device_driver console_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; } diff --git a/c/src/lib/libbsp/m68k/gen68302/include/bsp.h b/c/src/lib/libbsp/m68k/gen68302/include/bsp.h index 04745e01d6..eed274fb9a 100644 --- a/c/src/lib/libbsp/m68k/gen68302/include/bsp.h +++ b/c/src/lib/libbsp/m68k/gen68302/include/bsp.h @@ -23,7 +23,9 @@ extern "C" { #endif #include <rtems.h> +#include <console.h> #include <iosupp.h> +#include <clockdrv.h> /* * Define the time limits for RTEMS Test Suite test durations. @@ -81,6 +83,24 @@ extern "C" { #define EXTERN extern #endif +/* + * Device Driver Table Entries + */ + +/* + * NOTE: Use the standard Console driver entry + */ + +/* + * NOTE: Use the standard Clock driver entry + */ + +/* + * How many libio files we want + */ + +#define BSP_LIBIO_MAX_FDS 20 + /* miscellaneous stuff assumed to exist */ extern rtems_configuration_table BSP_Configuration; diff --git a/c/src/lib/libbsp/m68k/gen68302/start/start302.s b/c/src/lib/libbsp/m68k/gen68302/start/start302.s index 2682066e84..d92ed1ce6b 100644 --- a/c/src/lib/libbsp/m68k/gen68302/start/start302.s +++ b/c/src/lib/libbsp/m68k/gen68302/start/start302.s @@ -227,7 +227,10 @@ loop: movel d0,a1@+ | to zero out uninitialized movec a0,isp | set interrupt stack #endif - jsr SYM (bsp_start) + move.l #0,a7@- | environp + move.l #0,a7@- | argv + move.l #0,a7@- | argc + jsr SYM (main) nop Bad: bra Bad diff --git a/c/src/lib/libbsp/m68k/gen68302/start302/start302.s b/c/src/lib/libbsp/m68k/gen68302/start302/start302.s index 2682066e84..d92ed1ce6b 100644 --- a/c/src/lib/libbsp/m68k/gen68302/start302/start302.s +++ b/c/src/lib/libbsp/m68k/gen68302/start302/start302.s @@ -227,7 +227,10 @@ loop: movel d0,a1@+ | to zero out uninitialized movec a0,isp | set interrupt stack #endif - jsr SYM (bsp_start) + move.l #0,a7@- | environp + move.l #0,a7@- | argv + move.l #0,a7@- | argc + jsr SYM (main) nop Bad: bra Bad diff --git a/c/src/lib/libbsp/m68k/gen68302/startup/bspstart.c b/c/src/lib/libbsp/m68k/gen68302/startup/bspstart.c index 976046cf9f..72e1656e04 100644 --- a/c/src/lib/libbsp/m68k/gen68302/startup/bspstart.c +++ b/c/src/lib/libbsp/m68k/gen68302/startup/bspstart.c @@ -20,10 +20,17 @@ * $Id$ */ -#include <rtems.h> #include <bsp.h> +#include <rtems/libio.h> + #include <libcsupport.h> - + +#include <string.h> +#include <fcntl.h> + +#ifdef STACK_CHECKER_ON +#include <stackchk.h> +#endif /* * The original table from the application and our copy of it with @@ -35,6 +42,8 @@ rtems_configuration_table BSP_Configuration; rtems_cpu_table Cpu_table; +char *rtems_progname; + /* Initialize whatever libc we are using * called from postdriver hook */ @@ -58,6 +67,14 @@ void bsp_libc_init() RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0); /* + * Init the RTEMS libio facility to provide UNIX-like system + * calls for use by newlib (ie: provide __open, __close, etc) + * Uses malloc() to get area for the iops, so must be after malloc init + */ + + rtems_libio_init(); + + /* * Set up for the libc handling. */ @@ -75,13 +92,43 @@ void bsp_libc_init() #endif } +/* + * After drivers are setup, register some "filenames" + * and open stdin, stdout, stderr files + * + * Newlib will automatically associate the files with these + * (it hardcodes the numbers) + */ + +void +bsp_postdriver_hook(void) +{ + int stdin_fd, stdout_fd, stderr_fd; + + if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1) + rtems_fatal_error_occurred('STD0'); + + if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1) + rtems_fatal_error_occurred('STD1'); + + if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1) + rtems_fatal_error_occurred('STD2'); + + if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2)) + rtems_fatal_error_occurred('STIO'); +} -int bsp_start( +int main( int argc, char **argv, char **environp ) { + if ((argc > 0) && argv && argv[0]) + rtems_progname = argv[0]; + else + rtems_progname = "RTEMS"; + /* * Allocate the memory for the RTEMS Work Space. This can come from * a variety of places: hard coded address, malloc'ed from outside @@ -90,7 +137,7 @@ int bsp_start( * of work space from the last physical address on the CPU board. */ #if 0 -a Cpu_table.interrupt_vector_table = (mc68000_isr *) 0/*&M68Kvec*/; + Cpu_table.interrupt_vector_table = (mc68000_isr *) 0/*&M68Kvec*/; #endif @@ -123,6 +170,12 @@ a Cpu_table.interrupt_vector_table = (mc68000_isr *) 0/*&M68Kvec*/; #endif /* + * Tell libio how many fd's we want and allow it to tweak config + */ + + rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); + + /* * Need to "allocate" the memory for the RTEMS Workspace and * tell the RTEMS configuration where it is. This memory is * not malloc'ed. It is just "pulled from the air". @@ -143,7 +196,7 @@ a Cpu_table.interrupt_vector_table = (mc68000_isr *) 0/*&M68Kvec*/; Cpu_table.predriver_hook = bsp_libc_init; /* RTEMS resources available */ - Cpu_table.postdriver_hook = NULL; + Cpu_table.postdriver_hook = bsp_postdriver_hook; Cpu_table.idle_task = NULL; /* do not override system IDLE task */ diff --git a/c/src/lib/libbsp/m68k/idp/clock/ckinit.c b/c/src/lib/libbsp/m68k/idp/clock/ckinit.c index b27e9bbe38..7966fc61d1 100644 --- a/c/src/lib/libbsp/m68k/idp/clock/ckinit.c +++ b/c/src/lib/libbsp/m68k/idp/clock/ckinit.c @@ -26,9 +26,8 @@ #include <stdlib.h> -#include <rtems.h> -#include <clockdrv.h> #include <bsp.h> +#include <rtems/libio.h> rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ volatile rtems_unsigned32 Clock_driver_ticks; @@ -39,30 +38,53 @@ extern rtems_configuration_table Configuration; extern void led_putnum(); void Disable_clock(); -#define TIMER_VECTOR 0x4D +#define CLOCK_VECTOR 0x4D -rtems_device_driver Clock_initialize( - rtems_device_major_number major, - rtems_device_minor_number minor, - void *pargp, - rtems_id tid, - rtems_unsigned32 *rval -) -{ - Install_clock( Clock_isr ); -} +void Clock_exit( void ); + +/* + * These are set by clock driver during its init + */ + +rtems_device_major_number rtems_clock_major = ~0; +rtems_device_minor_number rtems_clock_minor; + -void ReInstall_clock( clock_isr ) -rtems_isr_entry clock_isr; -{ - rtems_unsigned32 isrlevel = 0 ; +/* + * ISR Handler + * + * + * ((1ms * 6.5 MHz) / 2^5) = 203.125) where 6.5 MHz is the clock rate of the + * MC68230, 2^5 is the prescaler factor, and 1ms is the common interrupt + * interval for the Clock_isr routine. + * Therefore, 203 (decimal) is the number to program into the CPRH-L registers + * of the MC68230 for countdown. However, I have found that 193 instead of + * 203 provides greater accuracy -- why? The crystal should be more accurate + * than that + */ - rtems_interrupt_disable( isrlevel ); - (void) set_vector( clock_isr, TIMER_VECTOR, 1 ); - rtems_interrupt_enable( isrlevel ); +rtems_isr Clock_isr( + rtems_vector_number vector +) +{ + Clock_driver_ticks += 1; + /* acknowledge interrupt + TSR = 1; */ + MC68230_WRITE (TSR, 1); + + if ( Clock_isrs == 1 ) { + rtems_clock_tick(); + /* Cast to an integer so that 68EC040 IDP which doesn't have an FPU doesn't + have a heart attack -- if you use newlib1.6 or greater and get + libgcc.a for gcc with software floating point support, this is not + a problem */ + Clock_isrs = + (int)(BSP_Configuration.microseconds_per_tick / 1000); + } + else + Clock_isrs -= 1; } -/* The following was added for debugging purposes */ void Disable_clock() { /* Disable timer */ @@ -77,7 +99,7 @@ rtems_isr_entry clock_isr; if ( Configuration.ticks_per_timeslice ) { /* led_putnum('c'); * for debugging purposes */ - Old_ticker = (rtems_isr_entry) set_vector( clock_isr, TIMER_VECTOR, 1 ); + Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); /* Disable timer for initialization */ MC68230_WRITE (TCR, 0x00); @@ -85,8 +107,8 @@ rtems_isr_entry clock_isr; /* some PI/T initialization stuff here -- see comment in the ckisr.c file in this directory to understand why I use the values that I do */ /* Set up the interrupt vector on the MC68230 chip: - TIVR = TIMER_VECTOR; */ - MC68230_WRITE (TIVR, TIMER_VECTOR); + TIVR = CLOCK_VECTOR; */ + MC68230_WRITE (TIVR, CLOCK_VECTOR); /* Set CPRH through CPRL to 193 (not 203) decimal for countdown--see ckisr.c CPRH = 0x00; @@ -108,6 +130,17 @@ rtems_isr_entry clock_isr; } } +void ReInstall_clock( clock_isr ) +rtems_isr_entry clock_isr; +{ + rtems_unsigned32 isrlevel = 0 ; + + rtems_interrupt_disable( isrlevel ); + (void) set_vector( clock_isr, CLOCK_VECTOR, 1 ); + rtems_interrupt_enable( isrlevel ); +} + +/* The following was added for debugging purposes */ void Clock_exit( void ) { rtems_unsigned8 data; @@ -123,3 +156,51 @@ void Clock_exit( void ) /* do not restore old vector */ } } + +rtems_device_driver Clock_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +) +{ + Install_clock( Clock_isr ); + + /* + * make major/minor avail to others such as shared memory driver + */ + + rtems_clock_major = major; + rtems_clock_minor = minor; + + return RTEMS_SUCCESSFUL; +} + +rtems_device_driver Clock_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +) +{ + rtems_libio_ioctl_args_t *args = pargp; + + if (args == 0) + goto done; + + /* + * This is hokey, but until we get a defined interface + * to do this, it will just be this simple... + */ + + if (args->command == rtems_build_name('I', 'S', 'R', ' ')) + { + Clock_isr(CLOCK_VECTOR); + } + else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) + { + ReInstall_clock(args->buffer); + } + +done: + return RTEMS_SUCCESSFUL; +} + diff --git a/c/src/lib/libbsp/m68k/idp/console/console.c b/c/src/lib/libbsp/m68k/idp/console/console.c index 7bb720c120..5540d26fcd 100644 --- a/c/src/lib/libbsp/m68k/idp/console/console.c +++ b/c/src/lib/libbsp/m68k/idp/console/console.c @@ -11,17 +11,15 @@ #define MIDP_INIT -#include "rtems.h" -#include "console.h" -#include "bsp.h" +#include <bsp.h> +#include <rtems/libio.h> -#include "ringbuf.h" +#include <ringbuf.h> Ring_buffer_t Buffer[ 2 ]; rtems_isr C_Receive_ISR(rtems_vector_number vector); - /* console_initialize * * This routine initializes the console IO driver. @@ -36,18 +34,44 @@ rtems_isr C_Receive_ISR(rtems_vector_number vector); rtems_device_driver console_initialize( rtems_device_major_number major, rtems_device_minor_number minor, - void *arg, - rtems_id self, - rtems_unsigned32 *status + void *arg ) { + rtems_status_code status; Ring_buffer_Initialize( &Buffer[ 0 ] ); Ring_buffer_Initialize( &Buffer[ 1 ] ); init_pit(); - *status = RTEMS_SUCCESSFUL; + status = rtems_io_register_name( + "/dev/console", + major, + (rtems_device_minor_number) 0 + ); + + if (status != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(status); + + status = rtems_io_register_name( + "/dev/tty00", + major, + (rtems_device_minor_number) 0 + ); + + if (status != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(status); + + status = rtems_io_register_name( + "/dev/tty01", + major, + (rtems_device_minor_number) 1 + ); + + if (status != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(status); + + return RTEMS_SUCCESSFUL; } @@ -151,66 +175,108 @@ void outbyte( } /* - * __read -- read bytes from the serial port. Ignore fd, since - * we only have stdin. + * Open entry point + */ + +rtems_device_driver console_open( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; +} + +/* + * Close entry point + */ + +rtems_device_driver console_close( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; +} + +/* + * read bytes from the serial port. We only have stdin. */ -int __read( - int fd, - char *buf, - int nbytes +rtems_device_driver console_read( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg ) { - int i = 0; - int port; - - /* - * Map port A to stdin, stdout, and stderr. - * Map everything else to port B. - */ - - if ( fd <= 2 ) port = 0; - else port = 1; - - for (i = 0; i < nbytes; i++) { - *(buf + i) = inbyte( port ); - if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { - (*(buf + i++)) = '\n'; - (*(buf + i)) = 0; + rtems_libio_rw_args_t *rw_args; + char *buffer; + int maximum; + int count = 0; + + rw_args = (rtems_libio_rw_args_t *) arg; + + buffer = rw_args->buffer; + maximum = rw_args->count; + + if ( minor > 1 ) + return RTEMS_INVALID_NUMBER; + + for (count = 0; count < maximum; count++) { + buffer[ count ] = inbyte( minor ); + if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { + buffer[ count++ ] = '\n'; + buffer[ count ] = 0; break; } } - return (i); + + rw_args->bytes_moved = count; + return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; } /* - * __write -- write bytes to the serial port. Ignore fd, since - * stdout and stderr are the same. Since we have no filesystem, - * open will only return an error. + * write bytes to the serial port. Stdout and stderr are the same. */ -int __write( - int fd, - char *buf, - int nbytes +rtems_device_driver console_write( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg ) { - int i; - int port; - - /* - * Map port A to stdin, stdout, and stderr. - * Map everything else to port B. - */ - - if ( fd <= 2 ) port = 0; - else port = 1; - - for (i = 0; i < nbytes; i++) { - if (*(buf + i) == '\n') { - outbyte ('\r', port ); + int count; + int maximum; + rtems_libio_rw_args_t *rw_args; + char *buffer; + + rw_args = (rtems_libio_rw_args_t *) arg; + + buffer = rw_args->buffer; + maximum = rw_args->count; + + if ( minor > 1 ) + return RTEMS_INVALID_NUMBER; + + for (count = 0; count < maximum; count++) { + if ( buffer[ count ] == '\n') { + outbyte('\r', minor ); } - outbyte (*(buf + i), port ); + outbyte( buffer[ count ], minor ); } - return (nbytes); + return maximum; +} + +/* + * IO Control entry point + */ + +rtems_device_driver console_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; } diff --git a/c/src/lib/libbsp/m68k/idp/include/bsp.h b/c/src/lib/libbsp/m68k/idp/include/bsp.h index 68faeba68c..65fcfe1e6e 100644 --- a/c/src/lib/libbsp/m68k/idp/include/bsp.h +++ b/c/src/lib/libbsp/m68k/idp/include/bsp.h @@ -10,6 +10,7 @@ #include <rtems.h> #include <console.h> +#include <clockdrv.h> #include <mc68230.h> #include <mc68681.h> @@ -52,6 +53,24 @@ #define EXTERN extern #endif +/* + * Device Driver Table Entries + */ + +/* + * NOTE: Use the standard Console driver entry + */ + +/* + * NOTE: Use the standard Clock driver entry + */ + +/* + * How many libio files we want + */ + +#define BSP_LIBIO_MAX_FDS 20 + /* miscellaneous stuff assumed to exist */ extern rtems_configuration_table BSP_Configuration; diff --git a/c/src/lib/libbsp/m68k/idp/startup/bspstart.c b/c/src/lib/libbsp/m68k/idp/startup/bspstart.c index a0b738c53e..233449282e 100644 --- a/c/src/lib/libbsp/m68k/idp/startup/bspstart.c +++ b/c/src/lib/libbsp/m68k/idp/startup/bspstart.c @@ -20,9 +20,17 @@ * $Id$ */ -#include <rtems.h> #include <bsp.h> +#include <rtems/libio.h> + #include <libcsupport.h> + +#include <string.h> +#include <fcntl.h> + +#ifdef STACK_CHECKER_ON +#include <stackchk.h> +#endif unsigned char *duart_base; extern struct duart_regs duart_info; @@ -41,6 +49,8 @@ rtems_configuration_table BSP_Configuration; rtems_cpu_table Cpu_table; +char *rtems_progname; + /* Initialize whatever libc we are using * called from postdriver hook */ @@ -56,6 +66,14 @@ void bsp_libc_init() /* Create 64 KByte memory region for RTEMS executive */ RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0); + + /* + * Init the RTEMS libio facility to provide UNIX-like system + * calls for use by newlib (ie: provide __open, __close, etc) + * Uses malloc() to get area for the iops, so must be after malloc init + */ + + rtems_libio_init(); /* * Set up for the libc handling. @@ -76,7 +94,33 @@ void bsp_libc_init() } -int bsp_start( +/* + * After drivers are setup, register some "filenames" + * and open stdin, stdout, stderr files + * + * Newlib will automatically associate the files with these + * (it hardcodes the numbers) + */ + +void +bsp_postdriver_hook(void) +{ + int stdin_fd, stdout_fd, stderr_fd; + + if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1) + rtems_fatal_error_occurred('STD0'); + + if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1) + rtems_fatal_error_occurred('STD1'); + + if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1) + rtems_fatal_error_occurred('STD2'); + + if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2)) + rtems_fatal_error_occurred('STIO'); +} + +int main( int argc, char **argv, char **environp @@ -85,6 +129,11 @@ int bsp_start( m68k_isr_entry *monitors_vector_table; int index; + if ((argc > 0) && argv && argv[0]) + rtems_progname = argv[0]; + else + rtems_progname = "RTEMS"; + duart_base = (unsigned char *)DUART_ADDR; /* @@ -121,7 +170,7 @@ int bsp_start( Cpu_table.predriver_hook = bsp_libc_init; /* RTEMS resources available */ - Cpu_table.postdriver_hook = NULL; + Cpu_table.postdriver_hook = bsp_postdriver_hook; Cpu_table.idle_task = NULL; /* do not override system IDLE task */ @@ -164,6 +213,12 @@ int bsp_start( BSP_Configuration.maximum_extensions++; #endif + /* + * Tell libio how many fd's we want and allow it to tweak config + */ + + rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); + /* led_putnum('e'); * for debugging purposes only */ rtems_initialize_executive( &BSP_Configuration, &Cpu_table );/* does not return */ diff --git a/c/src/lib/libbsp/m68k/mvme136/clock/ckinit.c b/c/src/lib/libbsp/m68k/mvme136/clock/ckinit.c index de88fe9252..195d4a11af 100644 --- a/c/src/lib/libbsp/m68k/mvme136/clock/ckinit.c +++ b/c/src/lib/libbsp/m68k/mvme136/clock/ckinit.c @@ -20,9 +20,8 @@ #include <stdlib.h> -#include <rtems.h> #include <bsp.h> -#include <clockdrv.h> +#include <rtems/libio.h> #include <z8036.h> #define MICRVAL 0xe2 /* disable lower chain, no vec */ @@ -35,31 +34,43 @@ #define T1CSRVAL 0xc6 /* enable interrupt, allow and */ /* and trigger countdown */ +#define TIMER 0xfffb0000 +#define RELOAD 0x24 /* clr IP & IUS,allow countdown */ + +#define CLOCK_VECTOR 66 + rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ -volatile rtems_unsigned32 Clock_driver_ticks; - /* ticks since initialization */ + +volatile rtems_unsigned32 Clock_driver_ticks; /* ticks since initialization */ + rtems_isr_entry Old_ticker; -rtems_device_driver Clock_initialize( - rtems_device_major_number major, - rtems_device_minor_number minor, - void *pargp, - rtems_id tid, - rtems_unsigned32 *rval -) -{ - Install_clock( Clock_isr ); -} +void Clock_exit( void ); -void ReInstall_clock( - rtems_isr_entry clock_isr +/* + * These are set by clock driver during its init + */ + +rtems_device_major_number rtems_clock_major = ~0; +rtems_device_minor_number rtems_clock_minor; + +/* + * ISR Handler + */ + +rtems_isr Clock_isr( + rtems_vector_number vector ) { - rtems_unsigned32 isrlevel; + Clock_driver_ticks += 1; + ((volatile struct z8036_map *) TIMER)->CT1_CMD_STATUS = RELOAD; - rtems_interrupt_disable( isrlevel ); - (void) set_vector( clock_isr, 66, 1 ); - rtems_interrupt_enable( isrlevel ); + if ( Clock_isrs == 1 ) { + rtems_clock_tick(); + Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; + } + else + Clock_isrs -= 1; } void Install_clock( @@ -72,30 +83,42 @@ void Install_clock( Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; if ( BSP_Configuration.ticks_per_timeslice ) { - Old_ticker = (rtems_isr_entry) set_vector( clock_isr, 66, 1 ); + Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); timer = (struct z8036_map *) 0xfffb0000; timer->MASTER_INTR = MICRVAL; timer->CT1_MODE_SPEC = T1MSRVAL; - *((rtems_unsigned16 *)0xfffb0016) = MS_COUNT; /* write countdown value */ -/* - timer->CT1_TIME_CONST_MSB = (MS_COUNT >> 8); - timer->CT1_TIME_CONST_LSB = (MS_COUNT & 0xff); -*/ + *((rtems_unsigned16 *)0xfffb0016) = MS_COUNT; /* write countdown value */ + + /* + * timer->CT1_TIME_CONST_MSB = (MS_COUNT >> 8); + * timer->CT1_TIME_CONST_LSB = (MS_COUNT & 0xff); + */ + timer->MASTER_CFG = MCCRVAL; timer->CT1_CMD_STATUS = T1CSRVAL; -/* - * Enable interrupt via VME interrupt mask register - */ + /* + * Enable interrupt via VME interrupt mask register + */ (*(rtems_unsigned8 *)0xfffb0038) &= 0xfd; - atexit( Clock_exit ); } } +void ReInstall_clock( + rtems_isr_entry clock_isr +) +{ + rtems_unsigned32 isrlevel; + + rtems_interrupt_disable( isrlevel ); + (void) set_vector( clock_isr, CLOCK_VECTOR, 1 ); + rtems_interrupt_enable( isrlevel ); +} + void Clock_exit( void ) { volatile struct z8036_map *timer; @@ -109,3 +132,51 @@ void Clock_exit( void ) /* do not restore old vector */ } } + +rtems_device_driver Clock_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +) +{ + Install_clock( Clock_isr ); + + /* + * make major/minor avail to others such as shared memory driver + */ + + rtems_clock_major = major; + rtems_clock_minor = minor; + + return RTEMS_SUCCESSFUL; +} + +rtems_device_driver Clock_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +) +{ + rtems_libio_ioctl_args_t *args = pargp; + + if (args == 0) + goto done; + + /* + * This is hokey, but until we get a defined interface + * to do this, it will just be this simple... + */ + + if (args->command == rtems_build_name('I', 'S', 'R', ' ')) + { + Clock_isr(CLOCK_VECTOR); + } + else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) + { + ReInstall_clock(args->buffer); + } + +done: + return RTEMS_SUCCESSFUL; +} + diff --git a/c/src/lib/libbsp/m68k/mvme136/console/console.c b/c/src/lib/libbsp/m68k/mvme136/console/console.c index 6bfcf84481..e619fc1428 100644 --- a/c/src/lib/libbsp/m68k/mvme136/console/console.c +++ b/c/src/lib/libbsp/m68k/mvme136/console/console.c @@ -14,9 +14,8 @@ #define M136_INIT -#include <rtems.h> -#include "console.h" -#include "bsp.h" +#include <bsp.h> +#include <rtems/libio.h> /* console_initialize * @@ -32,14 +31,24 @@ rtems_device_driver console_initialize( rtems_device_major_number major, rtems_device_minor_number minor, - void *arg, - rtems_id self, - rtems_unsigned32 *status + void *arg ) { + rtems_status_code status; + _Write_m681 = ( struct w_m681_info * ) M681ADDR; _Read_m681 = ( struct r_m681_info * ) M681ADDR; - *status = RTEMS_SUCCESSFUL; + + status = rtems_io_register_name( + "/dev/console", + major, + (rtems_device_minor_number) 0 + ); + + if (status != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(status); + + return RTEMS_SUCCESSFUL; } @@ -112,48 +121,102 @@ void outbyte( } /* - * __read -- read bytes from the serial port. Ignore fd, since - * we only have stdin. + * Open entry point */ -int __read( - int fd, - char *buf, - int nbytes +rtems_device_driver console_open( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg ) { - int i = 0; + return RTEMS_SUCCESSFUL; +} + +/* + * Close entry point + */ + +rtems_device_driver console_close( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; +} + +/* + * read bytes from the serial port. We only have stdin. + */ - for (i = 0; i < nbytes; i++) { - *(buf + i) = inbyte(); - if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { - (*(buf + i++)) = '\n'; - (*(buf + i)) = 0; +rtems_device_driver console_read( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + rtems_libio_rw_args_t *rw_args; + char *buffer; + int maximum; + int count = 0; + + rw_args = (rtems_libio_rw_args_t *) arg; + + buffer = rw_args->buffer; + maximum = rw_args->count; + + for (count = 0; count < maximum; count++) { + buffer[ count ] = inbyte(); + if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { + buffer[ count++ ] = '\n'; + buffer[ count ] = 0; break; } } - return (i); + + rw_args->bytes_moved = count; + return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; } /* - * __write -- write bytes to the serial port. Ignore fd, since - * stdout and stderr are the same. Since we have no filesystem, - * open will only return an error. + * write bytes to the serial port. Stdout and stderr are the same. */ -int __write( - int fd, - char *buf, - int nbytes +rtems_device_driver console_write( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg ) { - int i; + int count; + int maximum; + rtems_libio_rw_args_t *rw_args; + char *buffer; - for (i = 0; i < nbytes; i++) { - if (*(buf + i) == '\n') { - outbyte ('\r'); + rw_args = (rtems_libio_rw_args_t *) arg; + + buffer = rw_args->buffer; + maximum = rw_args->count; + + for (count = 0; count < maximum; count++) { + if ( buffer[ count ] == '\n') { + outbyte('\r'); } - outbyte (*(buf + i)); + outbyte( buffer[ count ] ); } - return (nbytes); + return maximum; +} + +/* + * IO Control entry point + */ + +rtems_device_driver console_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; } diff --git a/c/src/lib/libbsp/m68k/mvme136/include/bsp.h b/c/src/lib/libbsp/m68k/mvme136/include/bsp.h index 939a09d41e..85d899ee7c 100644 --- a/c/src/lib/libbsp/m68k/mvme136/include/bsp.h +++ b/c/src/lib/libbsp/m68k/mvme136/include/bsp.h @@ -21,6 +21,8 @@ extern "C" { #endif #include <rtems.h> +#include <clockdrv.h> +#include <console.h> #include <iosupp.h> /* @@ -124,6 +126,24 @@ EXTERN volatile struct w_m681_info *_Write_m681; /* M68681 write registers */ extern m68k_isr_entry M68Kvec[]; /* vector table address */ +/* + * Device Driver Table Entries + */ + +/* + * NOTE: Use the standard Console driver entry + */ + +/* + * NOTE: Use the standard Clock driver entry + */ + +/* + * How many libio files we want + */ + +#define BSP_LIBIO_MAX_FDS 20 + /* functions */ void bsp_cleanup( void ); diff --git a/c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c b/c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c index 916b495520..5f822855e8 100644 --- a/c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c +++ b/c/src/lib/libbsp/m68k/mvme136/startup/bspstart.c @@ -20,12 +20,18 @@ * $Id$ */ -#include <rtems.h> #include <bsp.h> +#include <rtems/libio.h> + #include <libcsupport.h> #include <z8036.h> -#include "stackchk.h" +#include <string.h> +#include <fcntl.h> + +#ifdef STACK_CHECKER_ON +#include <stackchk.h> +#endif /* * The original table from the application and our copy of it with @@ -37,6 +43,8 @@ rtems_configuration_table BSP_Configuration; rtems_cpu_table Cpu_table; +char *rtems_progname; + /* Initialize whatever libc we are using * called from postdriver hook */ @@ -46,6 +54,10 @@ void bsp_libc_init() extern int end; rtems_unsigned32 heap_start; +#ifdef RTEMS_DEBUG + rtems_debug_enable( RTEMS_DEBUG_ALL_MASK ); +#endif + heap_start = (rtems_unsigned32) &end; if (heap_start & (CPU_ALIGNMENT-1)) heap_start = (heap_start + CPU_ALIGNMENT) & ~(CPU_ALIGNMENT-1); @@ -53,6 +65,14 @@ void bsp_libc_init() RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0); /* + * Init the RTEMS libio facility to provide UNIX-like system + * calls for use by newlib (ie: provide __open, __close, etc) + * Uses malloc() to get area for the iops, so must be after malloc init + */ + + rtems_libio_init(); + + /* * Set up for the libc handling. */ @@ -70,7 +90,34 @@ void bsp_libc_init() #endif } -int bsp_start( +/* + * After drivers are setup, register some "filenames" + * and open stdin, stdout, stderr files + * + * Newlib will automatically associate the files with these + * (it hardcodes the numbers) + */ + +void +bsp_postdriver_hook(void) +{ + int stdin_fd, stdout_fd, stderr_fd; + + if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1) + rtems_fatal_error_occurred('STD0'); + + if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1) + rtems_fatal_error_occurred('STD1'); + + if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1) + rtems_fatal_error_occurred('STD2'); + + if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2)) + rtems_fatal_error_occurred('STIO'); +} + + +int main( int argc, char **argv, char **environp @@ -79,6 +126,11 @@ int bsp_start( m68k_isr_entry *monitors_vector_table; int index; + if ((argc > 0) && argv && argv[0]) + rtems_progname = argv[0]; + else + rtems_progname = "RTEMS"; + monitors_vector_table = (m68k_isr_entry *)0; /* 135Bug Vectors are at 0 */ m68k_set_vbr( monitors_vector_table ); @@ -104,7 +156,7 @@ int bsp_start( Cpu_table.predriver_hook = bsp_libc_init; /* RTEMS resources available */ - Cpu_table.postdriver_hook = NULL; + Cpu_table.postdriver_hook = bsp_postdriver_hook; Cpu_table.idle_task = NULL; /* do not override system IDLE task */ @@ -147,6 +199,12 @@ int bsp_start( BSP_Configuration.maximum_extensions++; #endif + /* + * Tell libio how many fd's we want and allow it to tweak config + */ + + rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); + rtems_initialize_executive( &BSP_Configuration, &Cpu_table ); /* does not return */ diff --git a/c/src/lib/libbsp/m68k/mvme162/clock/ckinit.c b/c/src/lib/libbsp/m68k/mvme162/clock/ckinit.c index 4118b4d360..df0a13d52f 100644 --- a/c/src/lib/libbsp/m68k/mvme162/clock/ckinit.c +++ b/c/src/lib/libbsp/m68k/mvme162/clock/ckinit.c @@ -27,9 +27,8 @@ #include <stdlib.h> -#include <rtems.h> #include <bsp.h> -#include <clockdrv.h> +#include <rtems/libio.h> #define MS_COUNT 1000 /* T2's countdown constant (1 ms) */ #define CLOCK_INT_LEVEL 6 /* T2's interrupt level */ @@ -38,24 +37,33 @@ rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ volatile rtems_unsigned32 Clock_driver_ticks; /* ticks since initialization */ rtems_isr_entry Old_ticker; -rtems_device_driver Clock_initialize( - rtems_device_major_number major, - rtems_device_minor_number minor, - void *pargp, - rtems_id tid, - rtems_unsigned32 *rval -) -{ - Install_clock( Clock_isr ); -} +void Clock_exit( void ); + +#define CLOCK_VECTOR (VBR0 * 0x10 + 0x9) +/* + * These are set by clock driver during its init + */ + +rtems_device_major_number rtems_clock_major = ~0; +rtems_device_minor_number rtems_clock_minor; + -void ReInstall_clock(rtems_isr_entry clock_isr) +/* + * ISR Handler + */ + +rtems_isr Clock_isr(rtems_vector_number vector) { - rtems_unsigned32 isrlevel; + Clock_driver_ticks += 1; + lcsr->timer_cnt_2 = 0; /* clear counter */ + lcsr->intr_clear |= 0x02000000; - rtems_interrupt_disable( isrlevel ); - (void) set_vector( clock_isr, VBR0 * 0x10 + 0x9, 1 ); - rtems_interrupt_enable( isrlevel ); + if ( Clock_isrs == 1 ) { + rtems_clock_tick(); + Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; + } + else + Clock_isrs -= 1; } void Install_clock(rtems_isr_entry clock_isr ) @@ -66,7 +74,7 @@ void Install_clock(rtems_isr_entry clock_isr ) if ( BSP_Configuration.ticks_per_timeslice ) { Old_ticker = - (rtems_isr_entry) set_vector( clock_isr, VBR0 * 0x10 + 0x9, 1 ); + (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); lcsr->vector_base |= MASK_INT; /* unmask VMEchip2 interrupts */ lcsr->to_ctl = 0xE7; /* prescaler to 1 MHz (see Appendix A1) */ lcsr->timer_cmp_2 = MS_COUNT; @@ -79,10 +87,66 @@ void Install_clock(rtems_isr_entry clock_isr ) atexit( Clock_exit ); } +} +void ReInstall_clock(rtems_isr_entry clock_isr) +{ + rtems_unsigned32 isrlevel; + + rtems_interrupt_disable( isrlevel ); + (void) set_vector( clock_isr, CLOCK_VECTOR, 1 ); + rtems_interrupt_enable( isrlevel ); } void Clock_exit( void ) { /* Dummy for now. See other m68k BSP's for code examples */ } + +rtems_device_driver Clock_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +) +{ + Install_clock( Clock_isr ); + + /* + * make major/minor avail to others such as shared memory driver + */ + + rtems_clock_major = major; + rtems_clock_minor = minor; + + return RTEMS_SUCCESSFUL; +} + +rtems_device_driver Clock_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *pargp +) +{ + rtems_libio_ioctl_args_t *args = pargp; + + if (args == 0) + goto done; + + /* + * This is hokey, but until we get a defined interface + * to do this, it will just be this simple... + */ + + if (args->command == rtems_build_name('I', 'S', 'R', ' ')) + { + Clock_isr(CLOCK_VECTOR); + } + else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) + { + ReInstall_clock(args->buffer); + } + +done: + return RTEMS_SUCCESSFUL; +} + diff --git a/c/src/lib/libbsp/m68k/mvme162/console/console.c b/c/src/lib/libbsp/m68k/mvme162/console/console.c index 0892f5f200..72595f3bce 100644 --- a/c/src/lib/libbsp/m68k/mvme162/console/console.c +++ b/c/src/lib/libbsp/m68k/mvme162/console/console.c @@ -21,10 +21,9 @@ #define M162_INIT -#include <rtems.h> -#include "console.h" -#include "bsp.h" -#include "ringbuf.h" +#include <bsp.h> +#include <rtems/libio.h> +#include <ringbuf.h> Ring_buffer_t Buffer[2]; @@ -54,12 +53,11 @@ rtems_isr C_Receive_ISR(rtems_vector_number vector) rtems_device_driver console_initialize( rtems_device_major_number major, rtems_device_minor_number minor, - void *arg, - rtems_id self, - rtems_unsigned32 *status + void *arg ) { int i; + rtems_status_code status; /* * Initialise receiver interrupts on both ports @@ -79,7 +77,34 @@ rtems_device_driver console_initialize( mcchip->gen_control = 2; /* MIEN */ mcchip->SCC_int_ctl = 0x13; /* SCC IEN, IPL3 */ - *status = RTEMS_SUCCESSFUL; + status = rtems_io_register_name( + "/dev/console", + major, + (rtems_device_minor_number) 0 + ); + + if (status != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(status); + + status = rtems_io_register_name( + "/dev/tty00", + major, + (rtems_device_minor_number) 0 + ); + + if (status != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(status); + + status = rtems_io_register_name( + "/dev/tty01", + major, + (rtems_device_minor_number) 0 + ); + + if (status != RTEMS_SUCCESSFUL) + rtems_fatal_error_occurred(status); + + return RTEMS_SUCCESSFUL; } /* @@ -100,7 +125,7 @@ rtems_boolean char_ready(int port, char *ch) * Block on char input */ -char char_wait(int port) +char inbyte(int port) { unsigned char tmp_char; @@ -113,7 +138,7 @@ char char_wait(int port) * XON/XOFF flow control. */ -void char_put(int port, char ch) +void outbyte(int port, char ch) { while (1) { if (ZREAD0(port) & TX_BUFFER_EMPTY) break; @@ -122,45 +147,108 @@ void char_put(int port, char ch) } /* - * Map port A (1) to stdin, stdout, and stderr. - * Map everything else to port B (0). + * Open entry point + */ + +rtems_device_driver console_open( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; +} + +/* + * Close entry point + */ + +rtems_device_driver console_close( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; +} + +/* + * read bytes from the serial port. We only have stdin. */ -int __read(int fd, char *buf, int nbytes) +rtems_device_driver console_read( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) { - int i, port; + rtems_libio_rw_args_t *rw_args; + char *buffer; + int maximum; + int count = 0; + + rw_args = (rtems_libio_rw_args_t *) arg; - if ( fd <= 2 ) port = 1; - else port = 0; + buffer = rw_args->buffer; + maximum = rw_args->count; - for (i = 0; i < nbytes; i++) { - *(buf + i) = char_wait(port); - if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { - (*(buf + i++)) = '\n'; - (*(buf + i)) = 0; + if ( minor > 1 ) + return RTEMS_INVALID_NUMBER; + + for (count = 0; count < maximum; count++) { + buffer[ count ] = inbyte( minor ); + if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { + buffer[ count++ ] = '\n'; + buffer[ count ] = 0; break; } } - return (i); + + rw_args->bytes_moved = count; + return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; } /* - * Map port A (1) to stdin, stdout, and stderr. - * Map everything else to port B (0). + * write bytes to the serial port. Stdout and stderr are the same. */ -int __write(int fd, char *buf, int nbytes) +rtems_device_driver console_write( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) { - int i, port; - - if ( fd <= 2 ) port = 1; - else port = 0; - - for (i = 0; i < nbytes; i++) { - if (*(buf + i) == '\n') { - char_put (port, '\r'); + int count; + int maximum; + rtems_libio_rw_args_t *rw_args; + char *buffer; + + rw_args = (rtems_libio_rw_args_t *) arg; + + buffer = rw_args->buffer; + maximum = rw_args->count; + + if ( minor > 1 ) + return RTEMS_INVALID_NUMBER; + + for (count = 0; count < maximum; count++) { + if ( buffer[ count ] == '\n') { + outbyte('\r', minor ); } - char_put (port, *(buf + i)); + outbyte( buffer[ count ], minor ); } - return (nbytes); + return maximum; +} + +/* + * IO Control entry point + */ + +rtems_device_driver console_control( + rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return RTEMS_SUCCESSFUL; } diff --git a/c/src/lib/libbsp/m68k/mvme162/include/bsp.h b/c/src/lib/libbsp/m68k/mvme162/include/bsp.h index b11ac753b8..54e74da532 100644 --- a/c/src/lib/libbsp/m68k/mvme162/include/bsp.h +++ b/c/src/lib/libbsp/m68k/mvme162/include/bsp.h @@ -28,6 +28,8 @@ extern "C" { #endif #include <rtems.h> +#include <clockdrv.h> +#include <console.h> #include <iosupp.h> /* @@ -248,6 +250,24 @@ typedef volatile struct gcsr_regs { #define EXTERN extern #endif +/* + * Device Driver Table Entries + */ + +/* + * NOTE: Use the standard Console driver entry + */ + +/* + * NOTE: Use the standard Clock driver entry + */ + +/* + * How many libio files we want + */ + +#define BSP_LIBIO_MAX_FDS 20 + /* miscellaneous stuff assumed to exist */ extern rtems_configuration_table BSP_Configuration; diff --git a/c/src/lib/libbsp/m68k/mvme162/startup/bspstart.c b/c/src/lib/libbsp/m68k/mvme162/startup/bspstart.c index efbb89cb67..973a78a9f4 100644 --- a/c/src/lib/libbsp/m68k/mvme162/startup/bspstart.c +++ b/c/src/lib/libbsp/m68k/mvme162/startup/bspstart.c @@ -27,10 +27,17 @@ * $Id$ */ -#include <rtems.h> #include <bsp.h> +#include <rtems/libio.h> + #include <libcsupport.h> -#include <z8036.h> + +#include <string.h> +#include <fcntl.h> + +#ifdef STACK_CHECKER_ON +#include <stackchk.h> +#endif /* * The original table from the application and our copy of it with @@ -42,6 +49,8 @@ rtems_configuration_table BSP_Configuration; rtems_cpu_table Cpu_table; +char *rtems_progname; + /* Initialize whatever libc we are using * called from postdriver hook */ @@ -58,6 +67,14 @@ void bsp_libc_init() RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0); /* + * Init the RTEMS libio facility to provide UNIX-like system + * calls for use by newlib (ie: provide __open, __close, etc) + * Uses malloc() to get area for the iops, so must be after malloc init + */ + + rtems_libio_init(); + + /* * Set up for the libc handling. */ @@ -75,7 +92,33 @@ void bsp_libc_init() #endif } -int bsp_start( +/* + * After drivers are setup, register some "filenames" + * and open stdin, stdout, stderr files + * + * Newlib will automatically associate the files with these + * (it hardcodes the numbers) + */ + +void +bsp_postdriver_hook(void) +{ + int stdin_fd, stdout_fd, stderr_fd; + + if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1) + rtems_fatal_error_occurred('STD0'); + + if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1) + rtems_fatal_error_occurred('STD1'); + + if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1) + rtems_fatal_error_occurred('STD2'); + + if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2)) + rtems_fatal_error_occurred('STIO'); +} + +int main( int argc, char **argv, char **environp @@ -84,6 +127,11 @@ int bsp_start( m68k_isr_entry *monitors_vector_table; int index; + if ((argc > 0) && argv && argv[0]) + rtems_progname = argv[0]; + else + rtems_progname = "RTEMS"; + /* * 162Bug Vectors are at 0xFFE00000 */ @@ -121,7 +169,7 @@ int bsp_start( Cpu_table.predriver_hook = bsp_libc_init; /* RTEMS resources available */ - Cpu_table.postdriver_hook = NULL; /* Call our main() for constructors */ + Cpu_table.postdriver_hook = bsp_postdriver_hook; Cpu_table.idle_task = NULL; /* do not override system IDLE task */ @@ -161,6 +209,12 @@ int bsp_start( BSP_Configuration.maximum_extensions++; #endif + /* + * Tell libio how many fd's we want and allow it to tweak config + */ + + rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS); + BSP_Configuration.work_space_start = (void *) (RAM_END - BSP_Configuration.work_space_size); |