Changeset 3a4ae6c in rtems for c/src/lib/libbsp/i386


Ignore:
Timestamp:
09/11/95 19:35:39 (27 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
ced11f99
Parents:
5072b07
Message:

The word "RTEMS" almost completely removed from the core.

Configuration Table Template file added and all tests
modified to use this. All gvar.h and conftbl.h files
removed from test directories.

Configuration parameter maximum_devices added.

Core semaphore and mutex handlers added and RTEMS API Semaphore
Manager updated to reflect this.

Initialization sequence changed to invoke API specific initialization
routines. Initialization tasks table now owned by RTEMS Tasks Manager.

Added user extension for post-switch.

Utilized user extensions to implement API specific functionality
like signal dispatching.

Added extensions to the System Initialization Thread so that an
API can register a function to be invoked while the system
is being initialized. These are largely equivalent to the
pre-driver and post-driver hooks.

Added the Modules file oar-go32_p5, modified oar-go32, and modified
the file make/custom/go32.cfg to look at an environment varable which
determines what CPU model is being used.

All BSPs updated to reflect named devices and clock driver's IOCTL
used by the Shared Memory Driver. Also merged clock isr into
main file and removed ckisr.c where possible.

Updated spsize to reflect new and moved variables.

Makefiles for the executive source and include files updated to show
break down of files into Core, RTEMS API, and Neither.

Header and inline files installed into subdirectory based on whether
logically in the Core or a part of the RTEMS API.

Location:
c/src/lib/libbsp/i386
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/i386/force386/clock/ckinit.c

    r5072b07 r3a4ae6c  
    2020
    2121#include <bsp.h>
    22 #include <clockdrv.h>
     22
     23#include <rtems/libio.h>
     24
    2325#include <stdlib.h>
    2426
     27#define CLOCK_VECTOR  0x38
     28
     29rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
     30
    2531volatile rtems_unsigned32 Clock_driver_ticks;
    26 rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
     32
    2733rtems_isr_entry  Old_ticker;
    2834
    29 rtems_device_driver Clock_initialize(
    30   rtems_device_major_number major,
    31   rtems_device_minor_number minor,
    32   void *pargp,
    33   rtems_id tid,
    34   rtems_unsigned32 *rval
     35void Clock_exit( void );
     36 
     37/*
     38 * These are set by clock driver during its init
     39 */
     40 
     41rtems_device_major_number rtems_clock_major = ~0;
     42rtems_device_major_number rtems_clock_minor = 0;
     43
     44/*
     45 *  This is the ISR handler.
     46 */
     47
     48rtems_isr Clock_isr(
     49  rtems_vector_number vector
    3550)
    3651{
    37   Install_clock( Clock_isr );
    38 }
    39 
    40 void ReInstall_clock(
    41   rtems_isr_entry clock_isr
    42 )
    43 {
    44   rtems_unsigned32 isrlevel = 0;
    45 
    46   rtems_interrupt_disable( isrlevel );
    47    (void) set_vector( clock_isr, 0x38, 1 );
    48   rtems_interrupt_enable( isrlevel );
     52  /* enable_tracing(); */
     53  Clock_driver_ticks += 1;
     54  if ( Clock_isrs == 1 ) {
     55    rtems_clock_tick();
     56    Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
     57  }
     58  else
     59    Clock_isrs -= 1;
    4960}
    5061
     
    5768
    5869  if ( BSP_Configuration.ticks_per_timeslice ) {
    59     Old_ticker = ( rtems_isr_entry ) set_vector( clock_isr, 0x38, 1 );
     70    Old_ticker = ( rtems_isr_entry ) set_vector( clock_isr, CLOCK_VECTOR, 1 );
    6071    outport_byte( TBCR, 0x14 );  /* reset it, delay mode, 50X */
    6172    outport_byte( TBDR, 0x50 );  /* 1 millisecond */
     
    6374  }
    6475  atexit( Clock_exit );
     76}
     77
     78void ReInstall_clock(
     79  rtems_isr_entry clock_isr
     80)
     81{
     82  rtems_unsigned32 isrlevel = 0;
     83
     84  rtems_interrupt_disable( isrlevel );
     85   (void) set_vector( clock_isr, CLOCK_VECTOR, 1 );
     86  rtems_interrupt_enable( isrlevel );
    6587}
    6688
     
    7496}
    7597
     98rtems_device_driver Clock_initialize(
     99  rtems_device_major_number major,
     100  rtems_device_minor_number minor,
     101  void *pargp
     102)
     103{
     104  Install_clock( Clock_isr );
     105 
     106  /*
     107   * make major/minor avail to others such as shared memory driver
     108   */
     109 
     110  rtems_clock_major = major;
     111  rtems_clock_minor = minor;
     112 
     113  return RTEMS_SUCCESSFUL;
     114}
     115 
     116rtems_device_driver Clock_control(
     117  rtems_device_major_number major,
     118  rtems_device_minor_number minor,
     119  void *pargp
     120)
     121{
     122    rtems_libio_ioctl_args_t *args = pargp;
     123 
     124    if (args == 0)
     125        goto done;
     126 
     127    /*
     128     * This is hokey, but until we get a defined interface
     129     * to do this, it will just be this simple...
     130     */
     131 
     132    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
     133    {
     134        Clock_isr(CLOCK_VECTOR);
     135    }
     136    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
     137    {
     138        ReInstall_clock(args->buffer);
     139    }
     140 
     141done:
     142    return RTEMS_SUCCESSFUL;
     143}
  • c/src/lib/libbsp/i386/force386/console/console.c

    r5072b07 r3a4ae6c  
    1515#define F386_INIT
    1616
     17#include <bsp.h>
     18#include <rtems/libio.h>
     19
    1720#include <stdlib.h>
    18 
    19 #include <rtems.h>
    20 #include "console.h"
    21 #include "bsp.h"
    2221
    2322/*  console_cleanup
     
    6261  rtems_device_major_number  major,
    6362  rtems_device_minor_number  minor,
    64   void                      *arg,
    65   rtems_id                   self,
    66   rtems_unsigned32          *status
    67 )
    68 {
    69    /*
    70     *  flush the console now and at exit.  Just in case.
    71     */
    72 
    73    console_cleanup();
    74 
    75    atexit( console_cleanup );
     63  void                      *arg
     64)
     65{
     66  rtems_status_code status;
     67
     68  /*
     69   *  flush the console now and at exit.  Just in case.
     70   */
     71
     72  console_cleanup();
     73
     74  status = rtems_io_register_name(
     75    "/dev/console",
     76    major,
     77    (rtems_device_minor_number) 0
     78  );
     79 
     80  if (status != RTEMS_SUCCESSFUL)
     81    rtems_fatal_error_occurred(status);
     82
     83  atexit( console_cleanup );
     84
     85  return RTEMS_SUCCESSFUL;
    7686}
    7787
     
    173183
    174184/*
    175  * __read  -- read bytes from the serial port. Ignore fd, since
    176  *            we only have stdin.
    177  */
    178 
    179 int __read(
    180   int fd,
    181   char *buf,
    182   int nbytes
    183 )
    184 {
    185   int i = 0;
    186 
    187   for (i = 0; i < nbytes; i++) {
    188     *(buf + i) = inbyte();
    189     if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
    190       (*(buf + i++)) = '\n';
    191       (*(buf + i)) = 0;
     185 *  Open entry point
     186 */
     187 
     188rtems_device_driver console_open(
     189  rtems_device_major_number major,
     190  rtems_device_minor_number minor,
     191  void                    * arg
     192)
     193{
     194  return RTEMS_SUCCESSFUL;
     195}
     196 
     197/*
     198 *  Close entry point
     199 */
     200 
     201rtems_device_driver console_close(
     202  rtems_device_major_number major,
     203  rtems_device_minor_number minor,
     204  void                    * arg
     205)
     206{
     207  return RTEMS_SUCCESSFUL;
     208}
     209
     210/*
     211 * read bytes from the serial port. We only have stdin.
     212 */
     213 
     214rtems_device_driver console_read(
     215  rtems_device_major_number major,
     216  rtems_device_minor_number minor,
     217  void                    * arg
     218)
     219{
     220  rtems_libio_rw_args_t *rw_args;
     221  char *buffer;
     222  int maximum;
     223  int count = 0;
     224 
     225  rw_args = (rtems_libio_rw_args_t *) arg;
     226 
     227  buffer = rw_args->buffer;
     228  maximum = rw_args->count;
     229 
     230  for (count = 0; count < maximum; count++) {
     231    buffer[ count ] = inbyte();
     232    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
     233      buffer[ count++ ]  = '\n';
     234      buffer[ count ]  = 0;
    192235      break;
    193236    }
    194237  }
    195   return (i);
    196 }
    197 
    198 /*
    199  * __write -- write bytes to the serial port. Ignore fd, since
    200  *            stdout and stderr are the same. Since we have no filesystem,
    201  *            open will only return an error.
    202  */
    203 
    204 int __write(
    205   int fd,
    206   char *buf,
    207   int nbytes
    208 )
    209 {
    210   int i;
    211 
    212   for (i = 0; i < nbytes; i++) {
    213     if (*(buf + i) == '\n') {
    214       outbyte ('\r');
     238 
     239  rw_args->bytes_moved = count;
     240  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
     241}
     242 
     243/*
     244 * write bytes to the serial port. Stdout and stderr are the same.
     245 */
     246 
     247rtems_device_driver console_write(
     248  rtems_device_major_number major,
     249  rtems_device_minor_number minor,
     250  void                    * arg
     251)
     252{
     253  int count;
     254  int maximum;
     255  rtems_libio_rw_args_t *rw_args;
     256  char *buffer;
     257 
     258  rw_args = (rtems_libio_rw_args_t *) arg;
     259 
     260  buffer = rw_args->buffer;
     261  maximum = rw_args->count;
     262 
     263  for (count = 0; count < maximum; count++) {
     264    if ( buffer[ count ] == '\n') {
     265      outbyte('\r');
    215266    }
    216     outbyte (*(buf + i));
    217   }
    218   return (nbytes);
    219 }
     267    outbyte( buffer[ count ] );
     268  }
     269  return maximum;
     270}
     271 
     272/*
     273 *  IO Control entry point
     274 */
     275 
     276rtems_device_driver console_control(
     277  rtems_device_major_number major,
     278  rtems_device_minor_number minor,
     279  void                    * arg
     280)
     281{
     282  return RTEMS_SUCCESSFUL;
     283}
     284
  • c/src/lib/libbsp/i386/force386/include/bsp.h

    r5072b07 r3a4ae6c  
    2323#include <rtems.h>
    2424#include <iosupp.h>
     25#include <console.h>
     26#include <clockdrv.h>
    2527
    2628/*
     
    129131#endif
    130132
     133/*
     134 *  Device Driver Table Entries
     135 */
     136
     137/*
     138 * NOTE: Use the standard Console driver entry
     139 */
     140 
     141/*
     142 * NOTE: Use the standard Clock driver entry
     143 */
     144
     145/*
     146 * How many libio files we want
     147 */
     148
     149#define BSP_LIBIO_MAX_FDS       20
     150
    131151/* miscellaneous stuff assumed to exist */
    132152
  • c/src/lib/libbsp/i386/force386/startup/bspstart.c

    r5072b07 r3a4ae6c  
    2121 */
    2222
    23 #include <rtems.h>
    2423#include <bsp.h>
     24#include <rtems/libio.h>
     25
    2526#include <libcsupport.h>
    2627
     28#include <fcntl.h>
     29
     30#ifdef STACK_CHECKER_ON
    2731#include <stackchk.h>
     32#endif
    2833
    2934/*
     
    3641
    3742rtems_cpu_table Cpu_table;
     43
     44char *rtems_progname;
    3845
    3946/*      Initialize whatever libc we are using
     
    5158
    5259    RTEMS_Malloc_Initialize((void *) heap_start, 64 * 1024, 0);
     60
     61    /*
     62     *  Init the RTEMS libio facility to provide UNIX-like system
     63     *  calls for use by newlib (ie: provide __open, __close, etc)
     64     *  Uses malloc() to get area for the iops, so must be after malloc init
     65     */
     66
     67    rtems_libio_init();
    5368
    5469    /*
     
    7186}
    7287
    73 int bsp_start(
     88/*
     89 * After drivers are setup, register some "filenames"
     90 * and open stdin, stdout, stderr files
     91 *
     92 * Newlib will automatically associate the files with these
     93 * (it hardcodes the numbers)
     94 */
     95 
     96void
     97bsp_postdriver_hook(void)
     98{
     99  int stdin_fd, stdout_fd, stderr_fd;
     100 
     101  if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1)
     102    rtems_fatal_error_occurred('STD0');
     103 
     104  if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
     105    rtems_fatal_error_occurred('STD1');
     106 
     107  if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
     108    rtems_fatal_error_occurred('STD2');
     109 
     110  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
     111    rtems_fatal_error_occurred('STIO');
     112}
     113
     114int main(
    74115  int argc,
    75116  char **argv,
     
    77118)
    78119{
     120 
     121  if ((argc > 0) && argv && argv[0])
     122    rtems_progname = argv[0];
     123  else
     124    rtems_progname = "RTEMS";
     125 
    79126  /*
    80127   *  FORCE documentation incorrectly states that the bus request
     
    93140  Cpu_table.predriver_hook = bsp_libc_init;  /* RTEMS resources available */
    94141
    95   Cpu_table.postdriver_hook = NULL;   /* Call our main() for constructors */
     142  Cpu_table.postdriver_hook = bsp_postdriver_hook;
    96143
    97144  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
     
    138185#endif
    139186
     187  /*
     188   * Tell libio how many fd's we want and allow it to tweak config
     189   */
     190
     191  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
     192
    140193  rtems_initialize_executive( &BSP_Configuration, &Cpu_table );
    141194  /* does not return */
  • c/src/lib/libbsp/i386/go32/clock/ckinit.c

    r5072b07 r3a4ae6c  
    1212
    1313#include <bsp.h>
    14 #include <clockdrv.h>
     14#include <rtems/libio.h>
     15
    1516#include <stdlib.h>
    1617
    1718volatile rtems_unsigned32 Clock_driver_ticks;
    18 rtems_unsigned32 Clock_isrs_per_tick;           /* ISRs per tick */
    19 rtems_unsigned32 Clock_isrs;                    /* ISRs until next tick */
     19rtems_unsigned32 Clock_isrs_per_tick;  /* ISRs per tick */
     20rtems_unsigned32 Clock_isrs;   /* ISRs until next tick */
    2021rtems_isr_entry  Old_ticker;
     22
     23#define CLOCK_VECTOR 0x8
     24
     25void Clock_exit( void );
     26
     27/*
     28 * These are set by clock driver during its init
     29 */
     30 
     31rtems_device_major_number rtems_clock_major = ~0;
     32rtems_device_minor_number rtems_clock_minor;
     33
     34rtems_isr Clock_isr(
     35  rtems_vector_number vector
     36)
     37{
     38    /* touch interrupt controller for irq0 (0x20+0) */
     39    outport_byte( 0x20, 0x20 );
     40
     41    Clock_driver_ticks += 1;
     42
     43#if 0 && defined(pentium)
     44    {
     45      extern long long Last_RDTSC;
     46      __asm __volatile( ".byte 0x0F, 0x31" : "=A" (Last_RDTSC) );
     47    }
     48#endif
     49
     50    if ( Clock_isrs == 1 ) {
     51      rtems_clock_tick();
     52      Clock_isrs = Clock_isrs_per_tick;
     53    } else {
     54      Clock_isrs -= 1;
     55    }
     56}
     57
     58void Install_clock(
     59  rtems_isr_entry clock_isr
     60)
     61{
     62    unsigned int microseconds_per_isr;
     63
     64#if 0
     65    /* Initialize clock from on-board real time clock.  This breaks the */
     66    /* test code which assumes which assumes the application will do it. */
     67    {
     68       rtems_time_of_day Now;
     69       extern void init_rtc( void );
     70       extern long rtc_read( rtems_time_of_day * tod );
     71       init_rtc();
     72       if ( rtc_read( &Now ) >= 0 )
     73         clock_set( &Now );
     74       }
     75#endif
     76
     77    /* Start by assuming hardware counter is large enough, then */
     78    /* scale it until it actually fits.    */
     79    Clock_driver_ticks = 0;
     80    Clock_isrs_per_tick = 1;
     81
     82    if ( BSP_Configuration.microseconds_per_tick == 0 )
     83       microseconds_per_isr = 10000; /* default 10 ms */
     84    else
     85       microseconds_per_isr = BSP_Configuration.microseconds_per_tick;
     86    while ( US_TO_TICK(microseconds_per_isr) > 65535 )  {
     87      Clock_isrs_per_tick  *= 10;
     88      microseconds_per_isr /= 10;
     89    }
     90
     91    /* Initialize count in ckisr.c */
     92    Clock_isrs = Clock_isrs_per_tick;
     93
     94#if 0
     95    /* This was dropped in the last revision.  Its a nice thing to know. */
     96    TICKS_PER_SECOND = 1000000 / (Clock_isrs_per_tick * microseconds_per_isr);
     97#endif
     98
     99    if ( BSP_Configuration.ticks_per_timeslice )  {
     100      /* 105/88 approximates TIMER_TICK*1e-6 */
     101      unsigned int count = US_TO_TICK( microseconds_per_isr );
     102
     103      Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
     104      outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN );
     105      outport_byte( TIMER_CNTR0, count >> 0 & 0xff );
     106      outport_byte( TIMER_CNTR0, count >> 8 & 0xff );
     107    }
     108    atexit( Clock_exit );
     109}
     110
     111void ReInstall_clock(
     112  rtems_isr_entry clock_isr
     113)
     114{
     115  rtems_unsigned32 isrlevel = 0;
     116
     117  rtems_interrupt_disable( isrlevel );
     118   (void) set_vector( clock_isr, CLOCK_VECTOR, 1 );
     119  rtems_interrupt_enable( isrlevel );
     120}
     121
     122void Clock_exit( void )
     123{
     124  if ( BSP_Configuration.ticks_per_timeslice ) {
     125 extern void rtc_set_dos_date( void );
     126
     127 /* reset to DOS value: */
     128 outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN );
     129 outport_byte( TIMER_CNTR0, 0 );
     130 outport_byte( TIMER_CNTR0, 0 );
     131
     132 /* reset time-of-day */
     133 rtc_set_dos_date();
     134 
     135 /* re-enable old handler: assume it was one of ours */
     136 set_vector( (rtems_isr_entry)Old_ticker, CLOCK_VECTOR, 1 );
     137  }
     138}
    21139
    22140rtems_device_driver Clock_initialize(
    23141  rtems_device_major_number major,
    24142  rtems_device_minor_number minor,
    25   void *pargp,
    26   rtems_id tid,
    27   rtems_unsigned32 *rval
     143  void *pargp
    28144)
    29145{
    30146  Install_clock( Clock_isr );
    31 }
    32 
    33 void ReInstall_clock(
    34   rtems_isr_entry clock_isr
    35 )
    36 {
    37   rtems_unsigned32 isrlevel = 0;
    38 
    39   rtems_interrupt_disable( isrlevel );
    40    (void) set_vector( clock_isr, 0x8, 1 );
    41   rtems_interrupt_enable( isrlevel );
    42 }
    43 
    44 void Install_clock(
    45   rtems_isr_entry clock_isr
    46 )
    47 {
    48     unsigned int        microseconds_per_isr;
    49 
    50 #if 0
    51     /* Initialize clock from on-board real time clock.  This breaks the */
    52     /* test code which assumes which assumes the application will do it. */
    53     {
    54         rtems_time_of_day Now;
    55         extern void init_rtc( void );
    56         extern long rtc_read( rtems_time_of_day * tod );
    57         init_rtc();
    58         if ( rtc_read( &Now ) >= 0 )
    59             clock_set( &Now );
    60     }
    61 #endif
    62 
    63     /* Start by assuming hardware counter is large enough, then */
    64     /* scale it until it actually fits.                         */
    65     Clock_driver_ticks = 0;
    66     Clock_isrs_per_tick = 1;
    67 
    68     if ( BSP_Configuration.microseconds_per_tick == 0 )
    69         microseconds_per_isr = 10000;   /* default 10 ms */
    70     else
    71         microseconds_per_isr = BSP_Configuration.microseconds_per_tick;
    72     while ( US_TO_TICK(microseconds_per_isr) > 65535 )  {
    73         Clock_isrs_per_tick  *= 10;
    74         microseconds_per_isr /= 10;
    75     }
    76 
    77     /* Initialize count in ckisr.c */
    78     Clock_isrs = Clock_isrs_per_tick;
    79 
    80 #if 0
    81     /* This was dropped in the last revision.  Its a nice thing to know. */
    82     TICKS_PER_SECOND = 1000000 / (Clock_isrs_per_tick * microseconds_per_isr);
    83 #endif
    84 
    85     if ( BSP_Configuration.ticks_per_timeslice )  {
    86         /* 105/88 approximates TIMER_TICK*1e-6 */
    87         unsigned int count = US_TO_TICK( microseconds_per_isr );
    88 
    89         Old_ticker = (rtems_isr_entry) set_vector( clock_isr, 0x8, 1 );
    90         outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN );
    91         outport_byte( TIMER_CNTR0, count >> 0 & 0xff );
    92         outport_byte( TIMER_CNTR0, count >> 8 & 0xff );
    93     }
    94     atexit( Clock_exit );
    95 }
    96 
    97 void Clock_exit( void )
    98 {
    99   if ( BSP_Configuration.ticks_per_timeslice ) {
    100         extern void rtc_set_dos_date( void );
    101 
    102         /* reset to DOS value: */
    103         outport_byte( TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN );
    104         outport_byte( TIMER_CNTR0, 0 );
    105         outport_byte( TIMER_CNTR0, 0 );
    106 
    107         /* reset time-of-day */
    108         rtc_set_dos_date();
    109        
    110         /* re-enable old handler: assume it was one of ours */
    111         set_vector( (rtems_isr_entry)Old_ticker, 0x8, 1 );
    112   }
    113 }
    114 
     147 
     148  /*
     149   * make major/minor avail to others such as shared memory driver
     150   */
     151 
     152  rtems_clock_major = major;
     153  rtems_clock_minor = minor;
     154 
     155  return RTEMS_SUCCESSFUL;
     156}
     157 
     158rtems_device_driver Clock_control(
     159  rtems_device_major_number major,
     160  rtems_device_minor_number minor,
     161  void *pargp
     162)
     163{
     164    rtems_libio_ioctl_args_t *args = pargp;
     165 
     166    if (args == 0)
     167        goto done;
     168 
     169    /*
     170     * This is hokey, but until we get a defined interface
     171     * to do this, it will just be this simple...
     172     */
     173 
     174    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
     175    {
     176        Clock_isr(CLOCK_VECTOR);
     177    }
     178    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
     179    {
     180        ReInstall_clock(args->buffer);
     181    }
     182 
     183done:
     184    return RTEMS_SUCCESSFUL;
     185}
    115186
    116187#if 0 && defined(pentium)
    117 /* This can be used to get extremely accurate timing on a pentium.      */
    118 /* It isn't supported. [bryce]                                          */
     188/* This can be used to get extremely accurate timing on a pentium. */
     189/* It isn't supported. [bryce]      */
    119190#define HZ 90.0
    120191volatile long long Last_RDTSC;
    121192#define RDTSC()\
    122193  ({ long long _now; __asm __volatile (".byte 0x0F,0x31":"=A"(_now)); _now; })
     194
    123195long long Kernel_Time_ns( void )
    124196{
     
    129201    disable_intr( flags );
    130202    now = 1e9 * Clock_driver_ticks / isrs_per_second
    131               + (RDTSC() - Last_RDTSC) * (1000.0/HZ);
     203       + (RDTSC() - Last_RDTSC) * (1000.0/HZ);
    132204    enable_intr( flags );
    133205    return now;
  • c/src/lib/libbsp/i386/go32/console/console.c

    r5072b07 r3a4ae6c  
    99#include <stdlib.h>
    1010
    11 #include <rtems.h>
    12 #include "console.h"
    13 #include "bsp.h"
     11#include <bsp.h>
     12#include <rtems/libio.h>
    1413
    1514#include <dpmi.h>
     
    4342 */
    4443
    45 /* Set this if console I/O should use go32 (DOS) read/write calls.      */
    46 /* Otherwise, direct hardware accesses will be used.                    */
    47 int                     _IBMPC_Use_Go32_IO      = 0;
    48 
    49 static rtems_isr_entry  old_keyboard_isr        = NULL;
    50 extern void             _IBMPC_keyboard_isr( rtems_unsigned32 interrupt );
    51 
     44/* Set this if console I/O should use go32 (DOS) read/write calls.   */
     45/* Otherwise, direct hardware accesses will be used.                 */
     46
     47int      _IBMPC_Use_Go32_IO  = 0;
     48
     49static rtems_isr_entry  old_keyboard_isr  = NULL;
     50
     51extern void    _IBMPC_keyboard_isr( rtems_unsigned32 interrupt );
    5252
    5353rtems_device_driver console_initialize(
    5454  rtems_device_major_number  major,
    5555  rtems_device_minor_number  minor,
    56   void                      *arg,
    57   rtems_id                   self,
    58   rtems_unsigned32          *status
    59 )
    60 {
    61     if ( _IBMPC_Use_Go32_IO )  {
    62         /* Nothing.  We let DOS and go32 do all the work. */
    63     } else {
    64         /* Grap the keyboard interrupt so DOS doesn't steal our */
    65         /* keystrokes.                                          */
    66         rtems_status_code       status;
    67         status = rtems_interrupt_catch( _IBMPC_keyboard_isr, 9,
    68                                         &old_keyboard_isr );
    69         if ( status )  {
    70             int write( int, void *, int );
    71             void exit( int );
    72             char msg[] = "error initializing keyboard\n";
    73             write( 2, msg, sizeof msg - 1 );
    74             exit( 1 );
    75         }
     56  void                      *arg
     57)
     58{
     59  rtems_status_code status;
     60
     61  if ( _IBMPC_Use_Go32_IO )  {
     62    /* Nothing.  We let DOS and go32 do all the work. */
     63  } else {
     64    /* Grap the keyboard interrupt so DOS doesn't steal our */
     65    /* keystrokes.                                    */
     66    rtems_status_code  status;
     67
     68    status =
     69      rtems_interrupt_catch( _IBMPC_keyboard_isr, 9, &old_keyboard_isr );
     70
     71    if ( status )  {
     72      int write( int, void *, int );
     73      void exit( int );
     74
     75      char msg[] = "error initializing keyboard\n";
     76      write( 2, msg, sizeof msg - 1 );
     77      exit( 1 );
    7678    }
    77 
    78     atexit( console_cleanup );
     79  }
     80
     81  status = rtems_io_register_name(
     82    "/dev/console",
     83    major,
     84    (rtems_device_minor_number) 0
     85  );
     86 
     87  if (status != RTEMS_SUCCESSFUL)
     88    rtems_fatal_error_occurred(status);
     89 
     90  atexit( console_cleanup );
     91
     92  return RTEMS_SUCCESSFUL;
    7993}
    8094
     
    118132    outbyte( ch );
    119133    if ( ch == '\r' )
    120         outbyte( '\n' );
     134      outbyte( '\n' );
    121135#endif
    122136    return ch;
     
    139153
    140154/*
    141  * __read  -- read bytes from the console. Ignore fd, since
    142  *            we only have stdin.
    143  */
    144 
    145 int __read(
    146   int fd,
    147   char *buf,
    148   int nbytes
    149 )
    150 {
    151   int i = 0;
    152 
    153   for ( i = 0; i < nbytes; i++ ) {
    154     buf[i] = inbyte();
    155     if ( buf[i] == '\r' ) {
    156         /* What if this goes past the end of the buffer?  We're hosed. [bhc] */
    157         buf[i++] = '\n';
    158         buf[i] = '\0';
    159         break;
     155 *  Open entry point
     156 */
     157 
     158rtems_device_driver console_open(
     159  rtems_device_major_number major,
     160  rtems_device_minor_number minor,
     161  void                    * arg
     162)
     163{
     164  return RTEMS_SUCCESSFUL;
     165}
     166
     167/*
     168 *  Close entry point
     169 */
     170 
     171rtems_device_driver console_close(
     172  rtems_device_major_number major,
     173  rtems_device_minor_number minor,
     174  void                    * arg
     175)
     176{
     177  return RTEMS_SUCCESSFUL;
     178}
     179 
     180/*
     181 * read bytes from the serial port. We only have stdin.
     182 */
     183 
     184rtems_device_driver console_read(
     185  rtems_device_major_number major,
     186  rtems_device_minor_number minor,
     187  void                    * arg
     188)
     189{
     190  rtems_libio_rw_args_t *rw_args;
     191  char *buffer;
     192  int maximum;
     193  int count = 0;
     194 
     195  rw_args = (rtems_libio_rw_args_t *) arg;
     196 
     197  buffer = rw_args->buffer;
     198  maximum = rw_args->count;
     199 
     200  for (count = 0; count < maximum; count++) {
     201    buffer[ count ] = inbyte();
     202    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
     203      /* What if this goes past the end of the buffer?  We're hosed. [bhc] */
     204      buffer[ count++ ]  = '\n';
     205      buffer[ count ]  = 0;
     206      break;
    160207    }
    161208  }
    162   return i;
    163 }
    164 
    165 /*
    166  * __write -- write bytes to the console. Ignore fd, since
    167  *            stdout and stderr are the same. Since we have no filesystem,
    168  *            open will only return an error.
    169  */
    170 
    171 int __write(
    172   int fd,
    173   char *buf,
    174   int nbytes
    175 )
    176 {
    177   int i;
    178 
    179   for (i = 0; i < nbytes; i++) {
    180     if (*(buf + i) == '\n') {
    181       outbyte ('\r');
     209 
     210  rw_args->bytes_moved = count;
     211  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
     212}
     213 
     214/*
     215 * write bytes to the serial port. Stdout and stderr are the same.
     216 */
     217 
     218rtems_device_driver console_write(
     219  rtems_device_major_number major,
     220  rtems_device_minor_number minor,
     221  void                    * arg
     222)
     223{
     224  int count;
     225  int maximum;
     226  rtems_libio_rw_args_t *rw_args;
     227  char *buffer;
     228 
     229  rw_args = (rtems_libio_rw_args_t *) arg;
     230 
     231  buffer = rw_args->buffer;
     232  maximum = rw_args->count;
     233 
     234  for (count = 0; count < maximum; count++) {
     235    if ( buffer[ count ] == '\n') {
     236      outbyte('\r');
    182237    }
    183     outbyte (*(buf + i));
     238    outbyte( buffer[ count ] );
    184239  }
    185   return (nbytes);
    186 }
     240  return maximum;
     241}
     242 
     243/*
     244 *  IO Control entry point
     245 */
     246 
     247rtems_device_driver console_control(
     248  rtems_device_major_number major,
     249  rtems_device_minor_number minor,
     250  void                    * arg
     251)
     252{
     253  return RTEMS_SUCCESSFUL;
     254}
     255
  • c/src/lib/libbsp/i386/go32/include/bsp.h

    r5072b07 r3a4ae6c  
    2323#include <rtems.h>
    2424#include <iosupp.h>
     25#include <console.h>
     26#include <clockdrv.h>
    2527
    2628/*
     
    125127#endif
    126128
     129/*
     130 *  Device Driver Table Entries
     131 */
     132
     133/*
     134 * NOTE: Use the standard Console driver entry
     135 */
     136 
     137/*
     138 * NOTE: Use the standard Clock driver entry
     139 */
     140
     141/*
     142 * How many libio files we want
     143 */
     144
     145#define BSP_LIBIO_MAX_FDS       20
     146
    127147/* functions */
    128148
     
    134154
    135155extern rtems_configuration_table BSP_Configuration;
    136 
    137 #if 0
    138 extern i386_IDT_slot Interrupt_descriptor_table[ 256 ];
    139 extern i386_GDT_slot Global_descriptor_table[ 8192 ];
    140 BSP_EXTERN unsigned short Idt[3];  /* Interrupt Descriptor Table Address */
    141 BSP_EXTERN unsigned short Gdt[3];  /* Global Descriptor Table Address */
    142 BSP_EXTERN unsigned int   Idt_base;
    143 BSP_EXTERN unsigned int   Gdt_base;
    144 #endif
    145156
    146157/* routines */
  • c/src/lib/libbsp/i386/go32/startup/bspstart.c

    r5072b07 r3a4ae6c  
    2121 */
    2222
    23 #include <rtems.h>
    2423#include <bsp.h>
     24#include <rtems/libio.h>
     25 
    2526#include <libcsupport.h>
    26 
     27#include <z8036.h>
     28 
     29#include <string.h>
     30#include <fcntl.h>
     31 
     32#ifdef STACK_CHECKER_ON
    2733#include <stackchk.h>
     34#endif
    2835
    2936/*
     
    3643
    3744rtems_cpu_table Cpu_table;
     45
     46char *rtems_progname;
    3847
    3948/*      Initialize whatever libc we are using
     
    5867
    5968    /*
     69     *  Init the RTEMS libio facility to provide UNIX-like system
     70     *  calls for use by newlib (ie: provide __open, __close, etc)
     71     *  Uses malloc() to get area for the iops, so must be after malloc init
     72     */
     73
     74    rtems_libio_init();
     75
     76    /*
    6077     * Set up for the libc handling.
    6178     */
     
    7592
    7693}
    77 
    78 void bsp_start()
     94 
     95/*
     96 * After drivers are setup, register some "filenames"
     97 * and open stdin, stdout, stderr files
     98 *
     99 * Newlib will automatically associate the files with these
     100 * (it hardcodes the numbers)
     101 */
     102 
     103void
     104bsp_postdriver_hook(void)
    79105{
    80     extern void * sbrk( int );
    81 
    82     Cpu_table.pretasking_hook           = NULL;
    83     Cpu_table.predriver_hook = bsp_libc_init;  /* RTEMS resources available */
    84     Cpu_table.postdriver_hook = NULL;   /* Call our main() for constructors */
    85     Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
    86     Cpu_table.do_zero_of_workspace      = TRUE;
    87     Cpu_table.interrupt_table_segment   = 0;/* get_ds(); */
    88     Cpu_table.interrupt_table_offset    = (void *)0;
    89     Cpu_table.interrupt_stack_size      = 4096;
    90     Cpu_table.extra_system_initialization_stack = 0;
    91 
    92     /*
    93      *  Copy the table
    94      */
    95     BSP_Configuration = Configuration;
    96 
    97     BSP_Configuration.work_space_start = sbrk( Configuration.work_space_size );
    98     if ( BSP_Configuration.work_space_start == 0 )  {
    99         /* Big trouble */
    100         int     write( int, void *, int );
    101         void    _exit( int );
    102         char    msg[] = "bsp_start() couldn't sbrk() RTEMS work space\n";
    103         write( 2, msg, sizeof msg - 1 );
    104         _exit( 1 );
    105     }
    106 
    107     /*
    108      * Add 1 region for Malloc in libc_low
    109      */
    110 
    111     BSP_Configuration.maximum_regions++;
    112 
    113     /*
    114      * Add 1 extension for newlib libc
    115      */
     106  int stdin_fd, stdout_fd, stderr_fd;
     107 
     108  if ((stdin_fd = __open("/dev/console", O_RDONLY, 0)) == -1)
     109    rtems_fatal_error_occurred('STD0');
     110 
     111  if ((stdout_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
     112    rtems_fatal_error_occurred('STD1');
     113 
     114  if ((stderr_fd = __open("/dev/console", O_WRONLY, 0)) == -1)
     115    rtems_fatal_error_occurred('STD2');
     116 
     117  if ((stdin_fd != 0) || (stdout_fd != 1) || (stderr_fd != 2))
     118    rtems_fatal_error_occurred('STIO');
     119}
     120
     121/* This is the original command line passed from DOS */
     122char ** Go32_Argv;
     123
     124int main(
     125  int argc,
     126  char **argv,
     127  char **environp
     128)
     129{
     130  extern void * sbrk( int );
     131  extern volatile void _exit( int );
     132
     133  /* Set up arguments that we can access later */
     134  Go32_Argv = argv;
     135
     136  if ((argc > 0) && argv && argv[0])
     137    rtems_progname = argv[0];
     138  else
     139    rtems_progname = "RTEMS";
     140
     141  Cpu_table.pretasking_hook     = NULL;
     142  Cpu_table.predriver_hook = bsp_libc_init;  /* RTEMS resources available */
     143  Cpu_table.postdriver_hook = bsp_postdriver_hook;
     144  Cpu_table.idle_task = NULL;  /* do not override system IDLE task */
     145  Cpu_table.do_zero_of_workspace = TRUE;
     146  Cpu_table.interrupt_table_segment = 0;/* get_ds(); */
     147  Cpu_table.interrupt_table_offset = (void *)0;
     148  Cpu_table.interrupt_stack_size = 4096;
     149  Cpu_table.extra_system_initialization_stack = 0;
     150
     151  /*
     152   *  Copy the table
     153   */
     154  BSP_Configuration = Configuration;
     155
     156  BSP_Configuration.work_space_start = sbrk( Configuration.work_space_size );
     157  if ( BSP_Configuration.work_space_start == 0 )  {
     158    /* Big trouble */
     159    int write( int, void *, int );
     160    char msg[] = "bsp_start() couldn't sbrk() RTEMS work space\n";
     161    write( 2, msg, sizeof msg - 1 );
     162    _exit( 1 );
     163  }
     164
     165  /*
     166   * Add 1 region for Malloc in libc_low
     167   */
     168
     169  BSP_Configuration.maximum_regions++;
     170
     171  /*
     172   * Add 1 extension for newlib libc
     173   */
    116174
    117175#ifdef RTEMS_NEWLIB
    118     BSP_Configuration.maximum_extensions++;
    119 #endif
    120 
    121     /*
    122      * Add another extension if using the stack checker
    123      */
     176  BSP_Configuration.maximum_extensions++;
     177#endif
     178
     179  /*
     180   * Add another extension if using the stack checker
     181   */
    124182
    125183#ifdef STACK_CHECKER_ON
    126     BSP_Configuration.maximum_extensions++;
    127 #endif
    128 
    129     rtems_initialize_executive( &BSP_Configuration, &Cpu_table );
    130     /* does not return */
    131 
    132     /* no cleanup necessary for GO32 */
     184  BSP_Configuration.maximum_extensions++;
     185#endif
     186
     187  /*
     188   * Tell libio how many fd's we want and allow it to tweak config
     189   */
     190
     191  rtems_libio_config(&BSP_Configuration, BSP_LIBIO_MAX_FDS);
     192
     193  rtems_initialize_executive( &BSP_Configuration, &Cpu_table );
     194  /* does not return */
     195
     196  /* We only return here if the executive has finished.  This happens   */
     197  /* when the task has called exit().                                   */
     198  /* At this point we call _exit() which resides in djgcc.              */
     199   
     200  for (;;)
     201          _exit( 0 );
     202
     203  /* no cleanup necessary for GO32 */
     204
     205  return 0;
    133206}
Note: See TracChangeset for help on using the changeset viewer.