Changeset d1193c7 in rtems
- Timestamp:
- 09/18/96 20:47:31 (26 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- 2069773
- Parents:
- a4d97d94
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/exec/score/cpu/unix/cpu.c
ra4d97d94 rd1193c7 30 30 #define __EXTENSIONS__ 31 31 #endif 32 32 33 33 #if defined(linux) 34 34 #define MALLOC_0_RETURNS_NULL 35 35 #endif 36 36 37 37 #include <sys/types.h> 38 38 #include <sys/times.h> … … 64 64 65 65 static sigset_t _CPU_Signal_mask; 66 static Context_Control_overlay _CPU_Context_Default_with_ISRs_enabled; 67 static Context_Control_overlay _CPU_Context_Default_with_ISRs_disabled; 66 static Context_Control_overlay 67 CPU_STRUCTURE_ALIGNMENT _CPU_Context_Default_with_ISRs_enabled; 68 static Context_Control_overlay 69 CPU_STRUCTURE_ALIGNMENT _CPU_Context_Default_with_ISRs_disabled; 68 70 69 71 /* … … 124 126 struct sigaction act; 125 127 sigset_t mask; 126 128 127 129 /* mark them all active except for TraceTrap and Abort */ 128 130 129 131 mask = _CPU_Signal_mask; 130 132 sigprocmask(SIG_UNBLOCK, &mask, 0); 131 133 132 134 act.sa_handler = _CPU_ISR_Handler; 133 135 act.sa_mask = mask; 134 136 act.sa_flags = SA_RESTART; 135 137 136 138 sigaction(SIGHUP, &act, 0); 137 139 sigaction(SIGINT, &act, 0); … … 194 196 */ 195 197 196 198 197 199 (void) memset( 198 200 &_CPU_Context_Default_with_ISRs_enabled, … … 211 213 (Context_Control *) &_CPU_Context_Default_with_ISRs_enabled 212 214 ); 213 215 214 216 _CPU_ISR_Set_level( 1 ); 215 217 _CPU_Context_switch( … … 227 229 { 228 230 sigset_t old_mask; 229 231 230 232 sigprocmask(SIG_BLOCK, 0, &old_mask); 231 233 232 234 if (memcmp((void *)&posix_empty_mask, (void *)&old_mask, sizeof(sigset_t))) 233 235 return 1; 234 236 235 237 return 0; 236 238 } … … 347 349 * _CPU_Thread_Idle_body 348 350 * 349 * Stop until we get a signal which is the logically the same thing 351 * Stop until we get a signal which is the logically the same thing 350 352 * entering low-power or sleep mode on a real processor and waiting for 351 353 * an interrupt. This significantly reduces the consumption of host … … 367 369 368 370 /*PAGE 369 * 371 * 370 372 * _CPU_Context_Initialize 371 373 */ … … 390 392 /* 391 393 * On CPUs with stacks which grow down, we build the stack 392 * based on the _stack_high address. On CPUs with stacks which 393 * grow up, we build the stack based on the _stack_low address. 394 * based on the _stack_high address. On CPUs with stacks which 395 * grow up, we build the stack based on the _stack_low address. 394 396 */ 395 397 … … 415 417 *_the_context = *(Context_Control *) 416 418 &_CPU_Context_Default_with_ISRs_disabled; 417 419 418 420 addr = (unsigned32 *)_the_context; 419 421 … … 447 449 448 450 #elif defined(i386) 449 451 450 452 /* 451 453 * This information was gathered by disassembling setjmp(). … … 463 465 *(addr + ESP_OFF) = stack_ptr; 464 466 *(addr + RET_OFF) = jmp_addr; 465 467 466 468 addr = (unsigned32 *) stack_ptr; 467 469 468 470 addr[ 0 ] = jmp_addr; 469 471 addr[ 1 ] = (unsigned32) stack_ptr; … … 512 514 int status; 513 515 #endif 514 516 515 517 currentp->isr_level = _CPU_ISR_Disable_support(); 516 518 517 519 do_jump( currentp, nextp ); 518 520 … … 527 529 } 528 530 #endif 529 531 530 532 #ifdef RTEMS_DEBUG 531 533 if (_CPU_ISR_Get_level() == 0) 532 534 abort(); 533 535 #endif 534 536 535 537 _CPU_ISR_Enable(currentp->isr_level); 536 538 } 537 538 static void do_jump( 539 540 static void do_jump( 539 541 Context_Control_overlay *currentp, 540 Context_Control_overlay *nextp 542 Context_Control_overlay *nextp 541 543 ) 542 544 { … … 672 674 { 673 675 char buffer[ 4 ]; 674 676 675 677 /* 676 678 * print "stray" msg about ones which that might mean something … … 678 680 * The following is generally safe. 679 681 */ 680 682 681 683 switch (sig_num) 682 684 { 683 685 case SIGCLD: 684 686 break; 685 687 686 688 default: 687 689 { … … 690 692 * The following is generally safe 691 693 */ 692 694 693 695 int digit; 694 696 int number = sig_num; … … 705 707 digit = number; 706 708 buffer[len++] = '0' + digit; 707 709 708 710 buffer[ len++ ] = '\n'; 709 711 710 712 write( 2, "Stray signal ", 13 ); 711 713 write( 2, buffer, len ); … … 713 715 } 714 716 } 715 717 716 718 /* 717 719 * If it was a "fatal" signal, then exit here … … 719 721 * we won't call _CPU_Stray_signal, so this is ok. 720 722 */ 721 723 722 724 switch (sig_num) { 723 725 case SIGINT: … … 766 768 } 767 769 768 void _CPU_Start_clock( 770 void _CPU_Start_clock( 769 771 int microseconds 770 772 ) … … 784 786 struct itimerval new; 785 787 struct sigaction act; 786 788 787 789 /* 788 790 * Set the SIGALRM signal to ignore any last … … 791 793 * vector. 792 794 */ 793 795 794 796 (void) memset(&act, 0, sizeof(act)); 795 797 act.sa_handler = SIG_IGN; 796 798 797 799 sigaction(SIGALRM, &act, 0); 798 800 799 801 (void) memset(&new, 0, sizeof(new)); 800 802 setitimer(ITIMER_REAL, &new, 0); … … 804 806 extern void fix_syscall_errno( void ); 805 807 806 void _CPU_SHM_Init( 808 void _CPU_SHM_Init( 807 809 unsigned32 maximum_nodes, 808 810 boolean is_master_node, … … 818 820 int status; 819 821 int shm_size; 820 822 821 823 if (getenv("RTEMS_SHM_KEY")) 822 824 shm_key = strtol(getenv("RTEMS_SHM_KEY"), 0, 0); … … 827 829 shm_key = 0xa000; 828 830 #endif 829 831 830 832 if (getenv("RTEMS_SHM_SIZE")) 831 833 shm_size = strtol(getenv("RTEMS_SHM_SIZE"), 0, 0); … … 836 838 shm_size = 64 * 1024; 837 839 #endif 838 840 839 841 if (getenv("RTEMS_SHM_SEMAPHORE_KEY")) 840 842 sem_key = strtol(getenv("RTEMS_SHM_SEMAPHORE_KEY"), 0, 0); … … 845 847 sem_key = 0xa001; 846 848 #endif 847 849 848 850 shmid = shmget(shm_key, shm_size, IPC_CREAT | 0660); 849 851 if ( shmid == -1 ) { … … 852 854 _CPU_Fatal_halt( 0xdead0001 ); 853 855 } 854 856 855 857 shm_addr = shmat(shmid, (char *)0, SHM_RND); 856 858 if ( shm_addr == (void *)-1 ) { … … 859 861 _CPU_Fatal_halt( 0xdead0002 ); 860 862 } 861 863 862 864 _CPU_SHM_Semid = semget(sem_key, maximum_nodes + 1, IPC_CREAT | 0660); 863 865 if ( _CPU_SHM_Semid == -1 ) { … … 866 868 _CPU_Fatal_halt( 0xdead0003 ); 867 869 } 868 870 869 871 if ( is_master_node ) { 870 872 for ( i=0 ; i <= maximum_nodes ; i++ ) { … … 875 877 ushort *array; 876 878 } help; 877 879 878 880 help.val = 1; 879 881 status = semctl( _CPU_SHM_Semid, i, SETVAL, help ); … … 882 884 status = semctl( _CPU_SHM_Semid, i, SETVAL, 1 ); 883 885 #endif 884 886 885 887 fix_syscall_errno(); /* in case of newlib */ 886 888 if ( status == -1 ) { … … 889 891 } 890 892 } 891 893 892 894 *shm_address = shm_addr; 893 895 *shm_length = shm_size; … … 915 917 * Maybe systems that use /proc don't have this problem... 916 918 */ 917 918 919 920 919 921 int _CPU_SHM_Get_vector( void ) 920 922 { … … 934 936 } 935 937 936 void _CPU_SHM_Lock( 938 void _CPU_SHM_Lock( 937 939 int semaphore 938 940 ) … … 940 942 struct sembuf sb; 941 943 int status; 942 944 943 945 sb.sem_num = semaphore; 944 946 sb.sem_op = -1; 945 947 sb.sem_flg = 0; 946 948 947 949 while (1) { 948 950 status = semop(_CPU_SHM_Semid, &sb, 1); … … 966 968 struct sembuf sb; 967 969 int status; 968 970 969 971 sb.sem_num = semaphore; 970 972 sb.sem_op = 1; 971 973 sb.sem_flg = 0; 972 974 973 975 while (1) { 974 976 status = semop(_CPU_SHM_Semid, &sb, 1); 975 977 if ( status >= 0 ) 976 978 break; 977 979 978 980 if ( status == -1 ) { 979 981 fix_syscall_errno(); /* in case of newlib */ -
cpukit/score/cpu/unix/cpu.c
ra4d97d94 rd1193c7 30 30 #define __EXTENSIONS__ 31 31 #endif 32 32 33 33 #if defined(linux) 34 34 #define MALLOC_0_RETURNS_NULL 35 35 #endif 36 36 37 37 #include <sys/types.h> 38 38 #include <sys/times.h> … … 64 64 65 65 static sigset_t _CPU_Signal_mask; 66 static Context_Control_overlay _CPU_Context_Default_with_ISRs_enabled; 67 static Context_Control_overlay _CPU_Context_Default_with_ISRs_disabled; 66 static Context_Control_overlay 67 CPU_STRUCTURE_ALIGNMENT _CPU_Context_Default_with_ISRs_enabled; 68 static Context_Control_overlay 69 CPU_STRUCTURE_ALIGNMENT _CPU_Context_Default_with_ISRs_disabled; 68 70 69 71 /* … … 124 126 struct sigaction act; 125 127 sigset_t mask; 126 128 127 129 /* mark them all active except for TraceTrap and Abort */ 128 130 129 131 mask = _CPU_Signal_mask; 130 132 sigprocmask(SIG_UNBLOCK, &mask, 0); 131 133 132 134 act.sa_handler = _CPU_ISR_Handler; 133 135 act.sa_mask = mask; 134 136 act.sa_flags = SA_RESTART; 135 137 136 138 sigaction(SIGHUP, &act, 0); 137 139 sigaction(SIGINT, &act, 0); … … 194 196 */ 195 197 196 198 197 199 (void) memset( 198 200 &_CPU_Context_Default_with_ISRs_enabled, … … 211 213 (Context_Control *) &_CPU_Context_Default_with_ISRs_enabled 212 214 ); 213 215 214 216 _CPU_ISR_Set_level( 1 ); 215 217 _CPU_Context_switch( … … 227 229 { 228 230 sigset_t old_mask; 229 231 230 232 sigprocmask(SIG_BLOCK, 0, &old_mask); 231 233 232 234 if (memcmp((void *)&posix_empty_mask, (void *)&old_mask, sizeof(sigset_t))) 233 235 return 1; 234 236 235 237 return 0; 236 238 } … … 347 349 * _CPU_Thread_Idle_body 348 350 * 349 * Stop until we get a signal which is the logically the same thing 351 * Stop until we get a signal which is the logically the same thing 350 352 * entering low-power or sleep mode on a real processor and waiting for 351 353 * an interrupt. This significantly reduces the consumption of host … … 367 369 368 370 /*PAGE 369 * 371 * 370 372 * _CPU_Context_Initialize 371 373 */ … … 390 392 /* 391 393 * On CPUs with stacks which grow down, we build the stack 392 * based on the _stack_high address. On CPUs with stacks which 393 * grow up, we build the stack based on the _stack_low address. 394 * based on the _stack_high address. On CPUs with stacks which 395 * grow up, we build the stack based on the _stack_low address. 394 396 */ 395 397 … … 415 417 *_the_context = *(Context_Control *) 416 418 &_CPU_Context_Default_with_ISRs_disabled; 417 419 418 420 addr = (unsigned32 *)_the_context; 419 421 … … 447 449 448 450 #elif defined(i386) 449 451 450 452 /* 451 453 * This information was gathered by disassembling setjmp(). … … 463 465 *(addr + ESP_OFF) = stack_ptr; 464 466 *(addr + RET_OFF) = jmp_addr; 465 467 466 468 addr = (unsigned32 *) stack_ptr; 467 469 468 470 addr[ 0 ] = jmp_addr; 469 471 addr[ 1 ] = (unsigned32) stack_ptr; … … 512 514 int status; 513 515 #endif 514 516 515 517 currentp->isr_level = _CPU_ISR_Disable_support(); 516 518 517 519 do_jump( currentp, nextp ); 518 520 … … 527 529 } 528 530 #endif 529 531 530 532 #ifdef RTEMS_DEBUG 531 533 if (_CPU_ISR_Get_level() == 0) 532 534 abort(); 533 535 #endif 534 536 535 537 _CPU_ISR_Enable(currentp->isr_level); 536 538 } 537 538 static void do_jump( 539 540 static void do_jump( 539 541 Context_Control_overlay *currentp, 540 Context_Control_overlay *nextp 542 Context_Control_overlay *nextp 541 543 ) 542 544 { … … 672 674 { 673 675 char buffer[ 4 ]; 674 676 675 677 /* 676 678 * print "stray" msg about ones which that might mean something … … 678 680 * The following is generally safe. 679 681 */ 680 682 681 683 switch (sig_num) 682 684 { 683 685 case SIGCLD: 684 686 break; 685 687 686 688 default: 687 689 { … … 690 692 * The following is generally safe 691 693 */ 692 694 693 695 int digit; 694 696 int number = sig_num; … … 705 707 digit = number; 706 708 buffer[len++] = '0' + digit; 707 709 708 710 buffer[ len++ ] = '\n'; 709 711 710 712 write( 2, "Stray signal ", 13 ); 711 713 write( 2, buffer, len ); … … 713 715 } 714 716 } 715 717 716 718 /* 717 719 * If it was a "fatal" signal, then exit here … … 719 721 * we won't call _CPU_Stray_signal, so this is ok. 720 722 */ 721 723 722 724 switch (sig_num) { 723 725 case SIGINT: … … 766 768 } 767 769 768 void _CPU_Start_clock( 770 void _CPU_Start_clock( 769 771 int microseconds 770 772 ) … … 784 786 struct itimerval new; 785 787 struct sigaction act; 786 788 787 789 /* 788 790 * Set the SIGALRM signal to ignore any last … … 791 793 * vector. 792 794 */ 793 795 794 796 (void) memset(&act, 0, sizeof(act)); 795 797 act.sa_handler = SIG_IGN; 796 798 797 799 sigaction(SIGALRM, &act, 0); 798 800 799 801 (void) memset(&new, 0, sizeof(new)); 800 802 setitimer(ITIMER_REAL, &new, 0); … … 804 806 extern void fix_syscall_errno( void ); 805 807 806 void _CPU_SHM_Init( 808 void _CPU_SHM_Init( 807 809 unsigned32 maximum_nodes, 808 810 boolean is_master_node, … … 818 820 int status; 819 821 int shm_size; 820 822 821 823 if (getenv("RTEMS_SHM_KEY")) 822 824 shm_key = strtol(getenv("RTEMS_SHM_KEY"), 0, 0); … … 827 829 shm_key = 0xa000; 828 830 #endif 829 831 830 832 if (getenv("RTEMS_SHM_SIZE")) 831 833 shm_size = strtol(getenv("RTEMS_SHM_SIZE"), 0, 0); … … 836 838 shm_size = 64 * 1024; 837 839 #endif 838 840 839 841 if (getenv("RTEMS_SHM_SEMAPHORE_KEY")) 840 842 sem_key = strtol(getenv("RTEMS_SHM_SEMAPHORE_KEY"), 0, 0); … … 845 847 sem_key = 0xa001; 846 848 #endif 847 849 848 850 shmid = shmget(shm_key, shm_size, IPC_CREAT | 0660); 849 851 if ( shmid == -1 ) { … … 852 854 _CPU_Fatal_halt( 0xdead0001 ); 853 855 } 854 856 855 857 shm_addr = shmat(shmid, (char *)0, SHM_RND); 856 858 if ( shm_addr == (void *)-1 ) { … … 859 861 _CPU_Fatal_halt( 0xdead0002 ); 860 862 } 861 863 862 864 _CPU_SHM_Semid = semget(sem_key, maximum_nodes + 1, IPC_CREAT | 0660); 863 865 if ( _CPU_SHM_Semid == -1 ) { … … 866 868 _CPU_Fatal_halt( 0xdead0003 ); 867 869 } 868 870 869 871 if ( is_master_node ) { 870 872 for ( i=0 ; i <= maximum_nodes ; i++ ) { … … 875 877 ushort *array; 876 878 } help; 877 879 878 880 help.val = 1; 879 881 status = semctl( _CPU_SHM_Semid, i, SETVAL, help ); … … 882 884 status = semctl( _CPU_SHM_Semid, i, SETVAL, 1 ); 883 885 #endif 884 886 885 887 fix_syscall_errno(); /* in case of newlib */ 886 888 if ( status == -1 ) { … … 889 891 } 890 892 } 891 893 892 894 *shm_address = shm_addr; 893 895 *shm_length = shm_size; … … 915 917 * Maybe systems that use /proc don't have this problem... 916 918 */ 917 918 919 920 919 921 int _CPU_SHM_Get_vector( void ) 920 922 { … … 934 936 } 935 937 936 void _CPU_SHM_Lock( 938 void _CPU_SHM_Lock( 937 939 int semaphore 938 940 ) … … 940 942 struct sembuf sb; 941 943 int status; 942 944 943 945 sb.sem_num = semaphore; 944 946 sb.sem_op = -1; 945 947 sb.sem_flg = 0; 946 948 947 949 while (1) { 948 950 status = semop(_CPU_SHM_Semid, &sb, 1); … … 966 968 struct sembuf sb; 967 969 int status; 968 970 969 971 sb.sem_num = semaphore; 970 972 sb.sem_op = 1; 971 973 sb.sem_flg = 0; 972 974 973 975 while (1) { 974 976 status = semop(_CPU_SHM_Semid, &sb, 1); 975 977 if ( status >= 0 ) 976 978 break; 977 979 978 980 if ( status == -1 ) { 979 981 fix_syscall_errno(); /* in case of newlib */
Note: See TracChangeset
for help on using the changeset viewer.