_netbsd.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 Mozilla Public
  4. * License Version 1.1 (the "License"); you may not use this file
  5. * except in compliance with the License. You may obtain a copy of
  6. * the License at http://www.mozilla.org/MPL/
  7. *
  8. * Software distributed under the License is distributed on an "AS
  9. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. * implied. See the License for the specific language governing
  11. * rights and limitations under the License.
  12. *
  13. * The Original Code is the Netscape Portable Runtime (NSPR).
  14. *
  15. * The Initial Developer of the Original Code is Netscape
  16. * Communications Corporation. Portions created by Netscape are
  17. * Copyright (C) 1998-2000 Netscape Communications Corporation. All
  18. * Rights Reserved.
  19. *
  20. * Contributor(s):
  21. *
  22. * Alternatively, the contents of this file may be used under the
  23. * terms of the GNU General Public License Version 2 or later (the
  24. * "GPL"), in which case the provisions of the GPL are applicable
  25. * instead of those above. If you wish to allow use of your
  26. * version of this file only under the terms of the GPL and not to
  27. * allow others to use your version of this file under the MPL,
  28. * indicate your decision by deleting the provisions above and
  29. * replace them with the notice and other provisions required by
  30. * the GPL. If you do not delete the provisions above, a recipient
  31. * may use your version of this file under either the MPL or the
  32. * GPL.
  33. */
  34. #ifndef nspr_netbsd_defs_h___
  35. #define nspr_netbsd_defs_h___
  36. #include <sys/syscall.h>
  37. #include <sys/param.h> /* for __NetBSD_Version__ */
  38. #define PR_LINKER_ARCH "netbsd"
  39. #define _PR_SI_SYSNAME "NetBSD"
  40. #if defined(__i386__)
  41. #define _PR_SI_ARCHITECTURE "x86"
  42. #elif defined(__alpha__)
  43. #define _PR_SI_ARCHITECTURE "alpha"
  44. #elif defined(__m68k__)
  45. #define _PR_SI_ARCHITECTURE "m68k"
  46. #elif defined(__powerpc__)
  47. #define _PR_SI_ARCHITECTURE "powerpc"
  48. #elif defined(__sparc_v9__)
  49. #define _PR_SI_ARCHITECTURE "sparc64"
  50. #elif defined(__sparc__)
  51. #define _PR_SI_ARCHITECTURE "sparc"
  52. #elif defined(__mips__)
  53. #define _PR_SI_ARCHITECTURE "mips"
  54. #elif defined(__arm32__) || defined(__arm__) || defined(__armel__) \
  55. || defined(__armeb__)
  56. #define _PR_SI_ARCHITECTURE "arm"
  57. #endif
  58. #if defined(__ELF__)
  59. #define PR_DLL_SUFFIX ".so"
  60. #else
  61. #define PR_DLL_SUFFIX ".so.1.0"
  62. #endif
  63. #define _PR_VMBASE 0x30000000
  64. #define _PR_STACK_VMBASE 0x50000000
  65. #define _MD_DEFAULT_STACK_SIZE 65536L
  66. #define _MD_MMAP_FLAGS MAP_PRIVATE
  67. #undef HAVE_STACK_GROWING_UP
  68. #define HAVE_DLL
  69. #define USE_DLFCN
  70. #define _PR_HAVE_SOCKADDR_LEN
  71. #define _PR_NO_LARGE_FILES
  72. #define _PR_STAT_HAS_ST_ATIMESPEC
  73. #define _PR_POLL_AVAILABLE
  74. #define _PR_USE_POLL
  75. #define _PR_HAVE_SYSV_SEMAPHORES
  76. #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
  77. #if __NetBSD_Version__ >= 105000000
  78. #define _PR_INET6
  79. #define _PR_HAVE_INET_NTOP
  80. #define _PR_HAVE_GETHOSTBYNAME2
  81. #define _PR_HAVE_GETADDRINFO
  82. #define _PR_INET6_PROBE
  83. #endif
  84. #if __NetBSD_Version__ >= 106370000
  85. /* NetBSD 1.6ZK */
  86. #define _PR_HAVE_GETPROTO_R
  87. #define _PR_HAVE_GETPROTO_R_INT
  88. #endif
  89. #define USE_SETJMP
  90. #ifndef _PR_PTHREADS
  91. #include <setjmp.h>
  92. #define PR_CONTEXT_TYPE sigjmp_buf
  93. #define CONTEXT(_th) ((_th)->md.context)
  94. /*
  95. ** Initialize a thread context to run "_main()" when started
  96. */
  97. #ifdef __i386__
  98. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  99. { \
  100. sigsetjmp(CONTEXT(_thread), 1); \
  101. CONTEXT(_thread)[2] = (unsigned char*) ((_sp) - 128); \
  102. CONTEXT(_thread)[0] = (int) _main; \
  103. *status = PR_TRUE; \
  104. }
  105. #define _MD_GET_SP(_thread) CONTEXT(_thread)[2]
  106. #endif
  107. #ifdef __sparc_v9__
  108. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  109. { \
  110. sigsetjmp(CONTEXT(_thread), 1); \
  111. CONTEXT(_thread)[1] = (unsigned char*) ((_sp) - 176 - 0x7ff); \
  112. CONTEXT(_thread)[2] = (long) _main; \
  113. CONTEXT(_thread)[3] = (long) _main + 4; \
  114. *status = PR_TRUE; \
  115. }
  116. #define _MD_GET_SP(_thread) (CONTEXT(_thread)[2]+0x7ff)
  117. #elif defined(__sparc__)
  118. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  119. { \
  120. sigsetjmp(CONTEXT(_thread), 1); \
  121. CONTEXT(_thread)[2] = (unsigned char*) ((_sp) - 128); \
  122. CONTEXT(_thread)[3] = (int) _main; \
  123. CONTEXT(_thread)[4] = (int) _main + 4; \
  124. *status = PR_TRUE; \
  125. }
  126. #define _MD_GET_SP(_thread) CONTEXT(_thread)[2]
  127. #endif
  128. #ifdef __powerpc__
  129. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  130. { \
  131. sigsetjmp(CONTEXT(_thread), 1); \
  132. CONTEXT(_thread)[3] = (unsigned char*) ((_sp) - 128); \
  133. CONTEXT(_thread)[4] = (int) _main; \
  134. *status = PR_TRUE; \
  135. }
  136. #define _MD_GET_SP(_thread) CONTEXT(_thread)[3]
  137. #endif
  138. #ifdef __m68k__
  139. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  140. { \
  141. sigsetjmp(CONTEXT(_thread), 1); \
  142. CONTEXT(_thread)[2] = (unsigned char*) ((_sp) - 128); \
  143. CONTEXT(_thread)[5] = (int) _main; \
  144. *status = PR_TRUE; \
  145. }
  146. #define _MD_GET_SP(_thread) CONTEXT(_thread)[2]
  147. #endif
  148. #ifdef __mips__
  149. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  150. { \
  151. sigsetjmp(CONTEXT(_thread), 1); \
  152. CONTEXT(_thread)[32] = (unsigned char*) ((_sp) - 128); \
  153. CONTEXT(_thread)[2] = (int) _main; \
  154. CONTEXT(_thread)[28] = (int) _main; \
  155. *status = PR_TRUE; \
  156. }
  157. #define _MD_GET_SP(_thread) CONTEXT(_thread)[32]
  158. #endif
  159. #if defined(__arm32__) || defined(__arm__) || defined(__armel__) \
  160. || defined(__armeb__)
  161. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  162. { \
  163. sigsetjmp(CONTEXT(_thread), 1); \
  164. CONTEXT(_thread)[23] = (unsigned char*) ((_sp) - 128); \
  165. CONTEXT(_thread)[24] = (int) _main; \
  166. *status = PR_TRUE; \
  167. }
  168. #define _MD_GET_SP(_thread) CONTEXT(_thread)[23]
  169. #endif
  170. #ifdef __alpha__
  171. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
  172. { \
  173. sigsetjmp(CONTEXT(_thread), 1); \
  174. CONTEXT(_thread)[34] = (unsigned char*) ((_sp) - 128); \
  175. CONTEXT(_thread)[2] = (long) _main; \
  176. CONTEXT(_thread)[30] = (long) _main; \
  177. CONTEXT(_thread)[31] = (long) _main; \
  178. *status = PR_TRUE; \
  179. }
  180. #define _MD_GET_SP(_thread) CONTEXT(_thread)[34]
  181. #endif
  182. #ifndef _MD_INIT_CONTEXT
  183. #error "Need to define _MD_INIT_CONTEXT for this platform"
  184. #endif
  185. #define PR_NUM_GCREGS _JBLEN
  186. #define _MD_SWITCH_CONTEXT(_thread) \
  187. if (!sigsetjmp(CONTEXT(_thread), 1)) { \
  188. (_thread)->md.errcode = errno; \
  189. _PR_Schedule(); \
  190. }
  191. /*
  192. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  193. */
  194. #define _MD_RESTORE_CONTEXT(_thread) \
  195. { \
  196. errno = (_thread)->md.errcode; \
  197. _MD_SET_CURRENT_THREAD(_thread); \
  198. siglongjmp(CONTEXT(_thread), 1); \
  199. }
  200. /* Machine-dependent (MD) data structures */
  201. struct _MDThread {
  202. PR_CONTEXT_TYPE context;
  203. int id;
  204. int errcode;
  205. };
  206. struct _MDThreadStack {
  207. PRInt8 notused;
  208. };
  209. struct _MDLock {
  210. PRInt8 notused;
  211. };
  212. struct _MDSemaphore {
  213. PRInt8 notused;
  214. };
  215. struct _MDCVar {
  216. PRInt8 notused;
  217. };
  218. struct _MDSegment {
  219. PRInt8 notused;
  220. };
  221. /*
  222. * md-specific cpu structure field
  223. */
  224. #define _PR_MD_MAX_OSFD FD_SETSIZE
  225. struct _MDCPU_Unix {
  226. PRCList ioQ;
  227. PRUint32 ioq_timeout;
  228. PRInt32 ioq_max_osfd;
  229. PRInt32 ioq_osfd_cnt;
  230. #ifndef _PR_USE_POLL
  231. fd_set fd_read_set, fd_write_set, fd_exception_set;
  232. PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  233. fd_exception_cnt[_PR_MD_MAX_OSFD];
  234. #else
  235. struct pollfd *ioq_pollfds;
  236. int ioq_pollfds_size;
  237. #endif /* _PR_USE_POLL */
  238. };
  239. #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
  240. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  241. #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
  242. #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
  243. #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
  244. #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
  245. #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
  246. #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
  247. #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
  248. #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
  249. #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
  250. #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
  251. #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
  252. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
  253. struct _MDCPU {
  254. struct _MDCPU_Unix md_unix;
  255. };
  256. #define _MD_INIT_LOCKS()
  257. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  258. #define _MD_FREE_LOCK(lock)
  259. #define _MD_LOCK(lock)
  260. #define _MD_UNLOCK(lock)
  261. #define _MD_INIT_IO()
  262. #define _MD_IOQ_LOCK()
  263. #define _MD_IOQ_UNLOCK()
  264. #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
  265. #define _MD_INIT_THREAD _MD_InitializeThread
  266. #define _MD_EXIT_THREAD(thread)
  267. #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread
  268. #define _MD_RESUME_THREAD(thread) _MD_resume_thread
  269. #define _MD_CLEAN_THREAD(_thread)
  270. #endif /* ! _PR_PTHREADS */
  271. #define _MD_EARLY_INIT _MD_EarlyInit
  272. #define _MD_FINAL_INIT _PR_UnixInit
  273. #define _MD_GET_INTERVAL _PR_UNIX_GetInterval
  274. #define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond
  275. /*
  276. * We wrapped the select() call. _MD_SELECT refers to the built-in,
  277. * unwrapped version.
  278. */
  279. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  280. #if defined(_PR_POLL_AVAILABLE)
  281. #include <poll.h>
  282. #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
  283. #endif
  284. #if NetBSD1_3 == 1L
  285. typedef unsigned int nfds_t;
  286. #endif
  287. #endif /* nspr_netbsd_defs_h___ */