Changeset 37f4c2d in rtems for c/src/exec


Ignore:
Timestamp:
09/27/95 20:53:58 (27 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
07058e7
Parents:
c701f197
Message:

Modified UNIX simulator port so all references to native unix
stuff is in the executive source proper in the file cpu.c. This
should help avoid conflicts between RTEMS POSIX files and UNIX files.

Location:
c/src/exec/score
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/score/cpu/unix/cpu.c

    rc701f197 r37f4c2d  
    2121#include <rtems/score/interr.h>
    2222
     23#if defined(solaris2)
     24#undef  _POSIX_C_SOURCE
     25#define _POSIX_C_SOURCE 3
     26#undef  __STRICT_ANSI__
     27#define __STRICT_ANSI__
     28#endif
     29 
     30#if defined(linux)
     31#define MALLOC_0_RETURNS_NULL
     32#endif
     33 
    2334#include <stdio.h>
    2435#include <stdlib.h>
     36#include <setjmp.h>
    2537#include <signal.h>
    2638#include <time.h>
    2739#include <sys/time.h>
     40#include <sys/types.h>
     41#include <errno.h>
     42#include <unistd.h>
     43#include <sys/ipc.h>
     44#include <sys/shm.h>
     45#include <sys/sem.h>
    2846
    2947#ifndef SA_RESTART
    3048#define SA_RESTART 0
    3149#endif
     50
     51typedef struct {
     52  jmp_buf   regs;
     53  sigset_t  isr_level;
     54} Context_Control_overlay;
    3255
    3356void  _CPU_Signal_initialize(void);
     
    376399
    377400  if ( _new_level == 0 )
    378     source = _CPU_Context_Default_with_ISRs_enabled.regs;
     401    source = &_CPU_Context_Default_with_ISRs_enabled;
    379402  else
    380     source = _CPU_Context_Default_with_ISRs_disabled.regs;
     403    source = &_CPU_Context_Default_with_ISRs_disabled;
    381404     
    382405  memcpy(_the_context, source, sizeof(Context_Control) ); /* sizeof(jmp_buf)); */
     
    453476)
    454477{
    455   sigprocmask( SIG_SETMASK, &next->isr_level, 0 );
    456   longjmp( next->regs, 0 );
     478  Context_Control_overlay *nextp = (Context_Control_overlay *)next;
     479
     480  sigprocmask( SIG_SETMASK, &nextp->isr_level, 0 );
     481  longjmp( nextp->regs, 0 );
    457482}
    458483
     
    467492)
    468493{
     494  Context_Control_overlay *currentp = (Context_Control_overlay *)current;
     495  Context_Control_overlay *nextp = (Context_Control_overlay *)next;
     496
    469497  int status;
    470498
     
    473501   */
    474502
    475   status = sigprocmask( SIG_SETMASK, &next->isr_level, &current->isr_level );
     503  status = sigprocmask( SIG_SETMASK, &nextp->isr_level, &currentp->isr_level );
    476504  if ( status )
    477505    _Internal_error_Occurred(
     
    481509    );
    482510
    483   if (setjmp(current->regs) == 0) {    /* Save the current context */
    484      longjmp(next->regs, 0);           /* Switch to the new context */
     511  if (setjmp(currentp->regs) == 0) {    /* Save the current context */
     512     longjmp(nextp->regs, 0);           /* Switch to the new context */
    485513     if ( status )
    486514       _Internal_error_Occurred(
     
    611639void _CPU_Stray_signal(int sig_num)
    612640{
    613   char buffer[ 80 ];   
     641  char buffer[ 4 ];   
    614642
    615643  /*
     
    618646   */
    619647
    620   write(
    621     2,
    622     buffer,
    623     sprintf( buffer, "Stray signal %d\n", sig_num )
    624   );
     648  buffer[ 0 ] = (sig_num >> 4) + 0x30;
     649  buffer[ 1 ] = (sig_num & 0xf) + 0x30;
     650  buffer[ 2 ] = '\n';
     651
     652  write( 2, "Stray signal 0x", 12 );
     653  write( 2, buffer, 3 );
    625654 
    626655  /*
     
    681710  return output;
    682711}
     712
     713
     714/*
     715 *  Special Purpose Routines to hide the use of UNIX system calls.
     716 */
     717
     718#if 0
     719/* XXX clock had this set of #define's */
     720
     721/*
     722 *  In order to get the types and prototypes used in this file under
     723 *  Solaris 2.3, it is necessary to pull the following magic.
     724 */
     725 
     726#if defined(solaris)
     727#warning "Ignore the undefining __STDC__ warning"
     728#undef __STDC__
     729#define __STDC__ 0
     730#undef  _POSIX_C_SOURCE
     731#endif
     732#endif
     733
     734int _CPU_Get_clock_vector( void )
     735{
     736  return SIGALRM;
     737}
     738
     739
     740void _CPU_Start_clock(
     741  int microseconds
     742)
     743{
     744  struct itimerval  new;
     745
     746  new.it_value.tv_sec = 0;
     747  new.it_value.tv_usec = microseconds;
     748  new.it_interval.tv_sec = 0;
     749  new.it_interval.tv_usec = microseconds;
     750
     751  setitimer(ITIMER_REAL, &new, 0);
     752}
     753
     754void _CPU_Stop_clock( void )
     755{
     756  struct itimerval  new;
     757  struct sigaction  act;
     758 
     759  /*
     760   * Set the SIGALRM signal to ignore any last
     761   * signals that might come in while we are
     762   * disarming the timer and removing the interrupt
     763   * vector.
     764   */
     765 
     766  act.sa_handler = SIG_IGN;
     767
     768  sigaction(SIGALRM, &act, 0);
     769 
     770  new.it_value.tv_sec = 0;
     771  new.it_value.tv_usec = 0;
     772 
     773  setitimer(ITIMER_REAL, &new, 0);
     774}
     775
     776int  _CPU_SHM_Semid;
     777extern       void fix_syscall_errno( void );
     778
     779void _CPU_SHM_Init(
     780  unsigned32   maximum_nodes,
     781  boolean      is_master_node,
     782  void       **shm_address,
     783  unsigned32  *shm_length
     784)
     785{
     786  int          i;
     787  int          shmid;
     788  char        *shm_addr;
     789  key_t        shm_key;
     790  key_t        sem_key;
     791  int          status;
     792  int          shm_size;
     793 
     794  if (getenv("RTEMS_SHM_KEY"))
     795    shm_key = strtol(getenv("RTEMS_SHM_KEY"), 0, 0);
     796  else
     797#ifdef RTEMS_SHM_KEY
     798    shm_key = RTEMS_SHM_KEY;
     799#else
     800    shm_key = 0xa000;
     801#endif
     802 
     803    if (getenv("RTEMS_SHM_SIZE"))
     804      shm_size = strtol(getenv("RTEMS_SHM_SIZE"), 0, 0);
     805    else
     806#ifdef RTEMS_SHM_SIZE
     807      shm_size = RTEMS_SHM_SIZE;
     808#else
     809      shm_size = 64 * 1024;
     810#endif
     811 
     812    if (getenv("RTEMS_SHM_SEMAPHORE_KEY"))
     813      sem_key = strtol(getenv("RTEMS_SHM_SEMAPHORE_KEY"), 0, 0);
     814    else
     815#ifdef RTEMS_SHM_SEMAPHORE_KEY
     816      sem_key = RTEMS_SHM_SEMAPHORE_KEY;
     817#else
     818      sem_key = 0xa001;
     819#endif
     820 
     821    shmid = shmget(shm_key, shm_size, IPC_CREAT | 0660);
     822    if ( shmid == -1 ) {
     823      fix_syscall_errno(); /* in case of newlib */
     824      perror( "shmget" );
     825      _CPU_Fatal_halt( 0xdead0001 );
     826    }
     827 
     828    shm_addr = shmat(shmid, (char *)0, SHM_RND);
     829    if ( shm_addr == (void *)-1 ) {
     830      fix_syscall_errno(); /* in case of newlib */
     831      perror( "shmat" );
     832      _CPU_Fatal_halt( 0xdead0002 );
     833    }
     834 
     835    _CPU_SHM_Semid = semget(sem_key, maximum_nodes + 1, IPC_CREAT | 0660);
     836    if ( _CPU_SHM_Semid == -1 ) {
     837      fix_syscall_errno(); /* in case of newlib */
     838      perror( "semget" );
     839      _CPU_Fatal_halt( 0xdead0003 );
     840    }
     841 
     842    if ( is_master_node ) {
     843      for ( i=0 ; i <= maximum_nodes ; i++ ) {
     844#if defined(solaris2)
     845        union semun {
     846          int val;
     847          struct semid_ds *buf;
     848          ushort *array;
     849        } help;
     850 
     851        help.val = 1;
     852        status = semctl( _CPU_SHM_Semid, i, SETVAL, help );
     853#endif
     854#if defined(hpux)
     855        status = semctl( _CPU_SHM_Semid, i, SETVAL, 1 );
     856#endif
     857 
     858        fix_syscall_errno(); /* in case of newlib */
     859        if ( status == -1 ) {
     860          _CPU_Fatal_halt( 0xdead0004 );
     861        }
     862      }
     863    }
     864 
     865  *shm_address = shm_addr;
     866  *shm_length = shm_size;
     867
     868}
     869
     870int _CPU_Get_pid( void )
     871{
     872  return getpid();
     873}
     874
     875/*
     876 * Define this to use signals for MPCI shared memory driver.
     877 * If undefined, the shared memory driver will poll from the
     878 * clock interrupt.
     879 * Ref: ../shmsupp/getcfg.c
     880 *
     881 * BEWARE:: many UN*X kernels and debuggers become severely confused when
     882 *          debugging programs which use signals.  The problem is *much*
     883 *          worse when using multiple signals, since ptrace(2) tends to
     884 *          drop all signals except 1 in the case of multiples.
     885 *          On hpux9, this problem was so bad, we couldn't use interrupts
     886 *          with the shared memory driver if we ever hoped to debug
     887 *          RTEMS programs.
     888 *          Maybe systems that use /proc don't have this problem...
     889 */
     890 
     891 
     892int _CPU_SHM_Get_vector( void )
     893{
     894#ifdef CPU_USE_SHM_INTERRUPTS
     895  return SIGUSR1;
     896#else
     897  return 0;
     898#endif
     899}
     900
     901void _CPU_SHM_Send_interrupt(
     902  int pid,
     903  int vector
     904)
     905{
     906  kill((pid_t) pid, vector);
     907}
     908
     909void _CPU_SHM_Lock(
     910  int semaphore
     911)
     912{
     913  struct sembuf      sb;
     914  int                status;
     915 
     916  sb.sem_num = semaphore;
     917  sb.sem_op  = -1;
     918  sb.sem_flg = 0;
     919 
     920  while (1) {
     921    status = semop(_CPU_SHM_Semid, &sb, 1);
     922    if ( status >= 0 )
     923      break;
     924    if ( status == -1 ) {
     925       fix_syscall_errno();    /* in case of newlib */
     926        if (errno == EINTR)
     927            continue;
     928        perror("shm lock");
     929        _CPU_Fatal_halt( 0xdead0005 );
     930    }
     931  }
     932
     933}
     934
     935void _CPU_SHM_Unlock(
     936  int semaphore
     937)
     938{
     939  struct sembuf  sb;
     940  int            status;
     941 
     942  sb.sem_num = semaphore;
     943  sb.sem_op  = 1;
     944  sb.sem_flg = 0;
     945 
     946  while (1) {
     947    status = semop(_CPU_SHM_Semid, &sb, 1);
     948    if ( status >= 0 )
     949      break;
     950 
     951    if ( status == -1 ) {
     952      fix_syscall_errno();    /* in case of newlib */
     953      if (errno == EINTR)
     954          continue;
     955      perror("shm unlock");
     956      _CPU_Fatal_halt( 0xdead0006 );
     957    }
     958  }
     959
     960}
  • c/src/exec/score/cpu/unix/cpu.h

    rc701f197 r37f4c2d  
    3232#endif
    3333
     34#include <rtems/score/unixsize.h>
     35
    3436#if defined(solaris2)
    3537#undef  _POSIX_C_SOURCE
     
    4244#define MALLOC_0_RETURNS_NULL
    4345#endif
    44 
    45 #include <unistd.h>
    46 #include <setjmp.h>
    47 #include <signal.h>
    4846
    4947/* conditional compilation parameters */
     
    432430 */
    433431
     432/*
     433 *  This is really just the area for the following fields.
     434 *
     435 *    jmp_buf   regs;
     436 *    sigset_t  isr_level;
     437 *
     438 *  Doing it this way avoids conflicts between the native stuff and the
     439 *  RTEMS stuff.
     440 */
    434441typedef struct {
    435   jmp_buf   regs;
    436   sigset_t  isr_level;
     442  char      Area[ CPU_CONTEXT_SIZE_IN_BYTES ];
    437443} Context_Control;
    438444
     
    969975}
    970976
     977/*
     978 *  Special Purpose Routines to hide the use of UNIX system calls.
     979 */
     980
     981int _CPU_Get_clock_vector( void );
     982
     983void _CPU_Start_clock(
     984  int microseconds
     985);
     986
     987void _CPU_Stop_clock( void );
     988
     989void _CPU_SHM_Init(
     990  unsigned32   maximum_nodes,
     991  boolean      is_master_node,
     992  void       **shm_address,
     993  unsigned32  *shm_length
     994);
     995
     996int _CPU_Get_pid( void );
     997 
     998int _CPU_SHM_Get_vector( void );
     999 
     1000void _CPU_SHM_Send_interrupt(
     1001  int pid,
     1002  int vector
     1003);
     1004 
     1005void _CPU_SHM_Lock(
     1006  int semaphore
     1007);
     1008
     1009void _CPU_SHM_Unlock(
     1010  int semaphore
     1011);
     1012
    9711013#ifdef __cplusplus
    9721014}
Note: See TracChangeset for help on using the changeset viewer.