engine-powerpc-netbsd.c
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:6k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* ==== machdep.c ============================================================
  2.  * Copyright (c) 1993, 1994 Chris Provenzano, proven@athena.mit.edu
  3.  *
  4.  * Description : Machine dependent functions for NetBSD/PowerPC (1.5+)
  5.  *
  6.  *     1.00 93/08/04 proven
  7.  *      -Started coding this file.
  8.  *
  9.  *     2001/01/10 briggs
  10.  *     -Modified to make it go with NetBSD/PowerPC
  11.  */
  12. #ifndef lint
  13. static const char rcsid[] = "engine-alpha-osf1.c,v 1.4.4.1 1995/12/13 05:41:37 proven Exp";
  14. #endif
  15. #include <pthread.h>
  16. #include <sys/types.h>
  17. #include <sys/socket.h>
  18. #include <sys/syscall.h>
  19. #include <stdlib.h>
  20. #include <fcntl.h>
  21. #include <stdio.h>
  22. /* ==========================================================================
  23.  * machdep_pthread_start()
  24.  */
  25. void machdep_pthread_start(void)
  26. {
  27.        context_switch_done();
  28.        pthread_sched_resume ();
  29.        /* XXXMLG
  30.         * This is EXTREMELY bogus, but it seems that this function is called
  31.         * with the pthread kernel locked.  If this happens, __errno() will
  32.         * return the wrong address until after the first context switch.
  33.         *
  34.         * Clearly there is a leak of pthread_kernel somewhere, but until
  35.         * it is found, we force a context switch here, just before calling
  36.         * the thread start routine.  When we return from pthread_yield
  37.         * the kernel will be unlocked.
  38.         */
  39.        pthread_yield();
  40.     /* Run current threads start routine with argument */
  41.     pthread_exit(pthread_run->machdep_data.start_routine
  42.       (pthread_run->machdep_data.start_argument));
  43.     /* should never reach here */
  44.     PANIC();
  45. }
  46. /* ==========================================================================
  47.  * __machdep_pthread_create()
  48.  */
  49. void __machdep_pthread_create(struct machdep_pthread *machdep_pthread,
  50.   void *(* start_routine)(void *), void *start_argument,
  51.   long stack_size, long nsec, long flags)
  52. {
  53.     machdep_pthread->start_routine = start_routine;
  54.     machdep_pthread->start_argument = start_argument;
  55.     machdep_pthread->machdep_timer.it_value.tv_sec = 0;
  56.     machdep_pthread->machdep_timer.it_interval.tv_sec = 0;
  57.     machdep_pthread->machdep_timer.it_interval.tv_usec = 0;
  58.     machdep_pthread->machdep_timer.it_value.tv_usec = nsec / 1000;
  59.     /* Set up new stack frame so that it looks like it returned from a
  60.        longjmp() to the beginning of machdep_pthread_start().  */
  61.     /* state is sigmask, then r8-r31 where r11 is the LR
  62.      * So, istate[3] is r10, which is the SP
  63.      * So, istate[4] is r11, which is the LR
  64.      * So, istate[5] is r12, which is the CR
  65.      */
  66.     machdep_pthread->machdep_istate[4] = (long)machdep_pthread_start;
  67.     machdep_pthread->machdep_istate[5] = 0;
  68.     /* PowerPC stack starts high and builds down, and needs to be 16-byte
  69.        aligned. */
  70.     machdep_pthread->machdep_istate[3] =
  71. ((long) machdep_pthread->machdep_stack + stack_size) & ~0xf;
  72. }
  73. /* ==========================================================================
  74.  * machdep_save_state()
  75.  */
  76. int machdep_save_state(void)
  77. {
  78.   return( _setjmp(pthread_run->machdep_data.machdep_istate) );
  79. }
  80. void machdep_restore_state(void)
  81. {
  82.   _longjmp(pthread_run->machdep_data.machdep_istate, 1);
  83. }
  84. void machdep_save_float_state (struct pthread *pthread)
  85. {
  86.   __machdep_save_fp_state(pthread->machdep_data.machdep_fstate);
  87. }
  88. void machdep_restore_float_state (void)
  89. {
  90.   __machdep_restore_fp_state(pthread_run->machdep_data.machdep_fstate);
  91. }
  92. /* ==========================================================================
  93.  * machdep_set_thread_timer()
  94.  */
  95. void machdep_set_thread_timer(struct machdep_pthread *machdep_pthread)
  96. {
  97.     if (setitimer(ITIMER_VIRTUAL, &(machdep_pthread->machdep_timer), NULL)) {
  98.         PANIC();
  99.     }
  100. }
  101. /* ==========================================================================
  102.  * machdep_unset_thread_timer()
  103.  */
  104. void machdep_unset_thread_timer(struct machdep_pthread *machdep_pthread)
  105. {
  106.     struct itimerval zeroval = { { 0, 0 }, { 0, 0} };
  107.     if (setitimer(ITIMER_VIRTUAL, &zeroval, NULL)) {
  108.         PANIC();
  109.     }
  110. }
  111. /* ==========================================================================
  112.  * machdep_pthread_cleanup()
  113.  */
  114. void *machdep_pthread_cleanup(struct machdep_pthread *machdep_pthread)
  115. {
  116.     return(machdep_pthread->machdep_stack);
  117. }
  118. void *machdep_pthread_cleanup(struct machdep_pthread *machdep_pthread);
  119. void machdep_pthread_start(void);
  120. /* ==========================================================================
  121.  * __machdep_stack_free()
  122.  */
  123. void
  124. __machdep_stack_free(void * stack)
  125. {
  126.     free(stack);
  127. }
  128. /* ==========================================================================
  129.  * __machdep_stack_alloc()
  130.  */
  131. void *
  132. __machdep_stack_alloc(size_t size)
  133. {
  134.     return(malloc(size));
  135. }
  136. /* ==========================================================================
  137.  * machdep_sys_creat()
  138.  */
  139. int
  140. machdep_sys_creat(char * path, int mode)
  141. {  
  142.         return(machdep_sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode));
  143. }  
  144. /* ==========================================================================
  145.  * machdep_sys_wait3()
  146.  */ 
  147. int
  148. machdep_sys_wait3(int * b, int c, int *d)
  149. {   
  150.         return(machdep_sys_wait4(0, b, c, d));
  151. }  
  152. /* ==========================================================================
  153.  * machdep_sys_waitpid()
  154.  */  
  155. int
  156. machdep_sys_waitpid(int a, int * b, int c)
  157. {
  158.         return(machdep_sys_wait4(a, b, c, NULL));
  159. }
  160. /* ==========================================================================
  161.  * machdep_sys_getdtablesize()
  162.  */
  163. int
  164. machdep_sys_getdtablesize(void)
  165. {
  166.         return(sysconf(_SC_OPEN_MAX));
  167. }
  168. /* ==========================================================================
  169.  * machdep_sys_lseek()
  170.  */
  171. off_t
  172. machdep_sys_lseek(int fd, off_t offset, int whence)
  173. {
  174.        return(__syscall((quad_t)SYS_lseek, fd, 0, offset, whence));
  175. }
  176. int
  177. machdep_sys_ftruncate( int fd, off_t length)
  178. {
  179.        quad_t q;
  180.        int rv;
  181.        q = __syscall((quad_t)SYS_ftruncate, fd,0, length);
  182.        if( /* LINTED constant */ sizeof( quad_t ) == sizeof( register_t ) ||
  183.            /* LINTED constant */ BYTE_ORDER == LITTLE_ENDIAN )
  184.                rv = (int)q;
  185.        else
  186.                rv = (int)((u_quad_t)q >> 32);
  187.        return rv;
  188. }
  189. /* ==========================================================================
  190.  * machdep_sys_getdirentries()
  191.  */
  192. int
  193. machdep_sys_getdirentries(int fd, char * buf, int len, int * seek)
  194. {
  195.         return(machdep_sys_getdents(fd, buf, len));