engine-alpha-netbsd-1.3.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/Alpha 1.1(+)
  5.  *
  6.  * 1.00 93/08/04 proven
  7.  *      -Started coding this file.
  8.  *
  9.  * 95/04/22 cgd
  10.  * -Modified to make it go with NetBSD/Alpha
  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.  
  16. #include <pthread.h>
  17. #include <sys/types.h>
  18. #include <sys/socket.h>
  19. #include <sys/syscall.h>
  20. #include <stdlib.h>
  21. #include <fcntl.h>
  22. #include <stdio.h>
  23. /* ==========================================================================
  24.  * machdep_save_state()
  25.  */
  26. int machdep_save_state(void)
  27. {
  28.   return __machdep_save_int_state(pthread_run->machdep_data.machdep_istate);
  29. }
  30. void machdep_restore_state(void)
  31. {
  32.   __machdep_restore_int_state(pthread_run->machdep_data.machdep_istate);
  33. }
  34. void machdep_save_float_state (void)
  35. {
  36.   __machdep_save_fp_state(pthread_run->machdep_data.machdep_fstate);
  37. }
  38. void machdep_restore_float_state (void)
  39. {
  40.   __machdep_restore_fp_state(pthread_run->machdep_data.machdep_fstate);
  41. }
  42. /* ==========================================================================
  43.  * machdep_set_thread_timer()
  44.  */
  45. void machdep_set_thread_timer(struct machdep_pthread *machdep_pthread)
  46. {
  47.     if (setitimer(ITIMER_VIRTUAL, &(machdep_pthread->machdep_timer), NULL)) {
  48.         PANIC();
  49.     }
  50. }
  51. /* ==========================================================================
  52.  * machdep_unset_thread_timer()
  53.  */
  54. void machdep_unset_thread_timer(struct machdep_pthread *machdep_pthread)
  55. {
  56.     struct itimerval zeroval = { { 0, 0 }, { 0, 0} };
  57.     if (setitimer(ITIMER_VIRTUAL, &zeroval, NULL)) {
  58.         PANIC();
  59.     }
  60. }
  61. /* ==========================================================================
  62.  * machdep_pthread_cleanup()
  63.  */
  64. void *machdep_pthread_cleanup(struct machdep_pthread *machdep_pthread)
  65. {
  66.     return(machdep_pthread->machdep_stack);
  67. }
  68. /* ==========================================================================
  69.  * machdep_pthread_start()
  70.  */
  71. void machdep_pthread_start(void)
  72. {
  73. context_switch_done();
  74. pthread_sched_resume ();
  75.     /* Run current threads start routine with argument */
  76.     pthread_exit(pthread_run->machdep_data.start_routine
  77.       (pthread_run->machdep_data.start_argument));
  78.     /* should never reach here */
  79.     PANIC();
  80. }
  81. /* ==========================================================================
  82.  * __machdep_stack_free()
  83.  */
  84. void __machdep_stack_free(void * stack)
  85. {
  86.     free(stack);
  87. }
  88. /* ==========================================================================
  89.  * __machdep_stack_alloc()
  90.  */
  91. void * __machdep_stack_alloc(size_t size)
  92. {
  93.     void * stack;
  94.     return(malloc(size));
  95. }
  96. /* ==========================================================================
  97.  * __machdep_pthread_create()
  98.  */
  99. void __machdep_pthread_create(struct machdep_pthread *machdep_pthread,
  100.   void *(* start_routine)(), void *start_argument, 
  101.   long stack_size, long nsec, long flags)
  102. {
  103.     machdep_pthread->start_routine = start_routine;
  104.     machdep_pthread->start_argument = start_argument;
  105.     machdep_pthread->machdep_timer.it_value.tv_sec = 0;
  106.     machdep_pthread->machdep_timer.it_interval.tv_sec = 0;
  107.     machdep_pthread->machdep_timer.it_interval.tv_usec = 0;
  108.     machdep_pthread->machdep_timer.it_value.tv_usec = nsec / 1000;
  109.     /* Set up new stack frame so that it looks like it returned from a
  110.        longjmp() to the beginning of machdep_pthread_start().  */
  111.     machdep_pthread->machdep_istate[8/*ISTATE_RA*/] = 0;
  112.     machdep_pthread->machdep_istate[0/*ISTATE_PC*/] = (long)machdep_pthread_start;
  113.     machdep_pthread->machdep_istate[10/*ISTATE_PV*/] = (long)machdep_pthread_start;
  114.     /* Alpha stack starts high and builds down. */
  115.     {
  116.       long stk_addr = (long) machdep_pthread->machdep_stack;
  117.       stk_addr += stack_size - 1024;
  118.       stk_addr &= ~15;
  119.       machdep_pthread->machdep_istate[9/*ISTATE_SP*/] = stk_addr;
  120.     }
  121. }
  122. int safe_store (loc, new)
  123.      int *loc;
  124.      int new;
  125. {
  126.   int locked, old;
  127.   asm ("mb" : : : "memory");
  128.   do {
  129.     asm ("ldl_l %0,%1" : "=r" (old) : "m" (*loc));
  130.     asm ("stl_c %0,%1" : "=r" (locked), "=m" (*loc) : "0" (new));
  131.   } while (!locked);
  132.   asm ("mb" : : : "memory");
  133.   return old;
  134. }
  135. /* ==========================================================================
  136.  * machdep_sys_creat()
  137.  */
  138. machdep_sys_creat(char * path, int mode)
  139. {   
  140.         return(machdep_sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode));
  141. }   
  142. /* ==========================================================================
  143.  * machdep_sys_wait3()
  144.  */  
  145. machdep_sys_wait3(int * b, int c, int * d)
  146. {    
  147.         return(machdep_sys_wait4(0, b, c, d));
  148. }   
  149.  
  150. /* ==========================================================================
  151.  * machdep_sys_waitpid()
  152.  */   
  153. machdep_sys_waitpid(int a, int * b, int c)
  154. {
  155.         return(machdep_sys_wait4(a, b, c, NULL));
  156. }
  157. /* ==========================================================================
  158.  * machdep_sys_getdtablesize()
  159.  */
  160. machdep_sys_getdtablesize()
  161. {
  162.         return(sysconf(_SC_OPEN_MAX));
  163. }
  164. /* ==========================================================================
  165.  * machdep_sys_lseek()
  166.  */
  167. off_t machdep_sys_lseek(int fd, off_t offset, int whence)
  168. {
  169. extern off_t __syscall();
  170. return(__syscall((quad_t)SYS_lseek, fd, 0, offset, whence));
  171. }
  172. /* ==========================================================================
  173.  * machdep_sys_getdirentries()
  174.  */
  175. machdep_sys_getdirentries(int fd, char * buf, int len, int * seek)
  176. {
  177.         return(machdep_sys_getdents(fd, buf, len));
  178. }