home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-v.zip / nspr30-v / include / md / _netbsd.h < prev    next >
C/C++ Source or Header  |  1998-11-14  |  6KB  |  214 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef nspr_netbsd_defs_h___
  20. #define nspr_netbsd_defs_h___
  21.  
  22. #include <sys/syscall.h>
  23.  
  24. #define PR_LINKER_ARCH    "netbsd"
  25. #define _PR_SI_SYSNAME  "NetBSD"
  26. #if defined(__i386__)
  27. #define _PR_SI_ARCHITECTURE "x86"
  28. #elif defined(__alpha__)
  29. #define _PR_SI_ARCHITECTURE "alpha"
  30. #elif defined(__m68k__)
  31. #define _PR_SI_ARCHITECTURE "m68k"
  32. #elif defined(__powerpc__)
  33. #define _PR_SI_ARCHITECTURE "powerpc"
  34. #elif defined(__sparc__)
  35. #define _PR_SI_ARCHITECTURE "sparc"
  36. #elif defined(__arm32__)
  37. #define _PR_SI_ARCHITECTURE "arm32"
  38. #endif
  39.  
  40. #define PR_DLL_SUFFIX        ".so.1.0"
  41.  
  42. #define _PR_VMBASE              0x30000000
  43. #define _PR_STACK_VMBASE    0x50000000
  44. #define _MD_DEFAULT_STACK_SIZE    65536L
  45. #define _MD_MMAP_FLAGS          MAP_PRIVATE
  46.  
  47. #undef  HAVE_STACK_GROWING_UP
  48. #define HAVE_DLL
  49. #define USE_DLFCN
  50. #define _PR_HAVE_SOCKADDR_LEN
  51. #define _PR_NO_LARGE_FILES
  52. #define _PR_STAT_HAS_ST_ATIMESPEC
  53.  
  54. #define USE_SETJMP
  55.  
  56. #ifndef _PR_PTHREADS
  57. #include <setjmp.h>
  58.  
  59. #define PR_CONTEXT_TYPE    sigjmp_buf
  60.  
  61. #define CONTEXT(_th) ((_th)->md.context)
  62.  
  63. #if defined(__i386__) || defined(__sparc__) || defined(__m68k__) || defined(__powerpc__)
  64. #define JB_SP_INDEX 2
  65. #elif defined(__alpha__)
  66. #define JB_SP_INDEX 34
  67. #elif defined(__arm32__)
  68. /*
  69.  * On the arm32, the jmpbuf regs underwent a name change after NetBSD 1.3.
  70.  */
  71. #ifdef JMPBUF_REG_R13
  72. #define JB_SP_INDEX JMPBUF_REG_R13
  73. #else
  74. #define JB_SP_INDEX _JB_REG_R13
  75. #endif
  76. #else
  77. #error "Need to define SP index in jmp_buf here"
  78. #endif
  79. #define _MD_GET_SP(_th)    (_th)->md.context[JB_SP_INDEX]
  80.  
  81. #define PR_NUM_GCREGS    _JBLEN
  82.  
  83. /*
  84. ** Initialize a thread context to run "_main()" when started
  85. */
  86. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
  87. {  \
  88.     *status = PR_TRUE;  \
  89.     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
  90.         _main();  \
  91.     }  \
  92.     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
  93. }
  94.  
  95. #define _MD_SWITCH_CONTEXT(_thread)  \
  96.     if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
  97.         (_thread)->md.errcode = errno;  \
  98.         _PR_Schedule();  \
  99.     }
  100.  
  101. /*
  102. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  103. */
  104. #define _MD_RESTORE_CONTEXT(_thread) \
  105. {   \
  106.     errno = (_thread)->md.errcode;  \
  107.     _MD_SET_CURRENT_THREAD(_thread);  \
  108.     siglongjmp(CONTEXT(_thread), 1);  \
  109. }
  110.  
  111. /* Machine-dependent (MD) data structures */
  112.  
  113. struct _MDThread {
  114.     PR_CONTEXT_TYPE context;
  115.     int id;
  116.     int errcode;
  117. };
  118.  
  119. struct _MDThreadStack {
  120.     PRInt8 notused;
  121. };
  122.  
  123. struct _MDLock {
  124.     PRInt8 notused;
  125. };
  126.  
  127. struct _MDSemaphore {
  128.     PRInt8 notused;
  129. };
  130.  
  131. struct _MDCVar {
  132.     PRInt8 notused;
  133. };
  134.  
  135. struct _MDSegment {
  136.     PRInt8 notused;
  137. };
  138.  
  139. /*
  140.  * md-specific cpu structure field
  141.  */
  142. #define _PR_MD_MAX_OSFD FD_SETSIZE
  143.  
  144. struct _MDCPU_Unix {
  145.     PRCList ioQ;
  146.     PRUint32 ioq_timeout;
  147.     PRInt32 ioq_max_osfd;
  148.     PRInt32 ioq_osfd_cnt;
  149. #ifndef _PR_USE_POLL
  150.     fd_set fd_read_set, fd_write_set, fd_exception_set;
  151.     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  152.                 fd_exception_cnt[_PR_MD_MAX_OSFD];
  153. #else
  154.     struct pollfd *ioq_pollfds;
  155.     int ioq_pollfds_size;
  156. #endif    /* _PR_USE_POLL */
  157. };
  158.  
  159. #define _PR_IOQ(_cpu)            ((_cpu)->md.md_unix.ioQ)
  160. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  161. #define _PR_FD_READ_SET(_cpu)        ((_cpu)->md.md_unix.fd_read_set)
  162. #define _PR_FD_READ_CNT(_cpu)        ((_cpu)->md.md_unix.fd_read_cnt)
  163. #define _PR_FD_WRITE_SET(_cpu)        ((_cpu)->md.md_unix.fd_write_set)
  164. #define _PR_FD_WRITE_CNT(_cpu)        ((_cpu)->md.md_unix.fd_write_cnt)
  165. #define _PR_FD_EXCEPTION_SET(_cpu)    ((_cpu)->md.md_unix.fd_exception_set)
  166. #define _PR_FD_EXCEPTION_CNT(_cpu)    ((_cpu)->md.md_unix.fd_exception_cnt)
  167. #define _PR_IOQ_TIMEOUT(_cpu)        ((_cpu)->md.md_unix.ioq_timeout)
  168. #define _PR_IOQ_MAX_OSFD(_cpu)        ((_cpu)->md.md_unix.ioq_max_osfd)
  169. #define _PR_IOQ_OSFD_CNT(_cpu)        ((_cpu)->md.md_unix.ioq_osfd_cnt)
  170. #define _PR_IOQ_POLLFDS(_cpu)        ((_cpu)->md.md_unix.ioq_pollfds)
  171. #define _PR_IOQ_POLLFDS_SIZE(_cpu)    ((_cpu)->md.md_unix.ioq_pollfds_size)
  172.  
  173. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
  174.  
  175. struct _MDCPU {
  176.     struct _MDCPU_Unix md_unix;
  177. };
  178.  
  179. #define _MD_INIT_LOCKS()
  180. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  181. #define _MD_FREE_LOCK(lock)
  182. #define _MD_LOCK(lock)
  183. #define _MD_UNLOCK(lock)
  184. #define _MD_INIT_IO()
  185. #define _MD_IOQ_LOCK()
  186. #define _MD_IOQ_UNLOCK()
  187.  
  188. #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
  189. #define _MD_INIT_THREAD                 _MD_InitializeThread
  190. #define _MD_EXIT_THREAD(thread)
  191. #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
  192. #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
  193. #define _MD_CLEAN_THREAD(_thread)
  194.  
  195. #endif /* ! _PR_PTHREADS */
  196.  
  197. #define _MD_EARLY_INIT                  _MD_EarlyInit
  198. #define _MD_FINAL_INIT            _PR_UnixInit
  199. #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
  200. #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
  201.  
  202. /*
  203.  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  204.  * unwrapped version.
  205.  */
  206. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  207. #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
  208.  
  209. #if NetBSD1_3 == 1L
  210. typedef unsigned int nfds_t;
  211. #endif
  212.  
  213. #endif /* nspr_netbsd_defs_h___ */
  214.