home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / include / md / _reliantunix.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.6 KB  |  212 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. /*
  20.  * reliantunix.h
  21.  * 5/18/96 Taken from nec.h -- chrisk@netscape.com
  22.  * 3/14/97 Modified for nspr20 -- chrisk@netscape.com
  23.  */
  24. #ifndef nspr_reliantunix_defs_h___
  25. #define nspr_reliantunix_defs_h___
  26.  
  27. /*
  28.  * Internal configuration macros
  29.  */
  30.  
  31. #define PR_LINKER_ARCH    "reliantunix"
  32. #define _PR_SI_SYSNAME    "ReliantUNIX"
  33. #define _PR_SI_ARCHITECTURE "mips"
  34. #define PR_DLL_SUFFIX ".so"
  35.  
  36. #define _PR_VMBASE        0x30000000
  37. #define _PR_STACK_VMBASE    0x50000000
  38. #define _MD_DEFAULT_STACK_SIZE    (2*65536L)
  39. #define _MD_MMAP_FLAGS        MAP_PRIVATE|MAP_FIXED
  40.  
  41. #undef  HAVE_STACK_GROWING_UP
  42. #define HAVE_DLL
  43. #define USE_DLFCN
  44. #define NEED_STRFTIME_LOCK
  45. #define NEED_TIME_R
  46. #define HAVE_NETCONFIG
  47. #define HAVE_WEAK_IO_SYMBOLS
  48. #define HAVE_WEAK_MALLOC_SYMBOLS
  49. #define _PR_RECV_BROKEN /* recv doesn't work on Unix Domain Sockets */
  50.  
  51. /*
  52.  * Mike Patnode indicated that it is possibly safe now to use context-switching
  53.  * calls that do not change the signal mask, like setjmp vs. sigsetjmp.
  54.  * So we'll use our homegrown, getcontext/setcontext-compatible stuff which 
  55.  * will save us the getcontext/setcontext system calls at each context switch.
  56.  * It already works in FastTrack 2.01, so it should do it here :-)
  57.  *  - chrisk 040497
  58.  */
  59. #define USE_SETCXT /* temporarily disabled... */
  60.  
  61. #include <ucontext.h>
  62.  
  63. #ifdef USE_SETCXT
  64. /* use non-syscall machine language replacement */
  65. #define _GETCONTEXT        getcxt
  66. #define _SETCONTEXT        setcxt
  67. /* defined in os_ReliantUNIX.s */
  68. extern int getcxt(ucontext_t *);
  69. extern int setcxt(ucontext_t *);
  70. #else
  71. #define _GETCONTEXT        getcontext
  72. #define _SETCONTEXT        setcontext
  73. #endif
  74.  
  75. #define _MD_GET_SP(_t)        (_t)->md.context.uc_mcontext.gpregs[CXT_SP]
  76. #define _PR_CONTEXT_TYPE    ucontext_t
  77. #define _PR_NUM_GCREGS        NGREG
  78.  
  79. #define CONTEXT(_thread) (&(_thread)->md.context)
  80.  
  81. #define _PR_IS_NATIVE_THREAD_SUPPORTED() 0
  82.  
  83. /*
  84. ** Machine-dependent (MD) data structures.
  85. */
  86. struct _MDThread {
  87.     _PR_CONTEXT_TYPE context;
  88.     int id;
  89.     int errcode;
  90. };
  91.  
  92. struct _MDThreadStack {
  93.     PRInt8 notused;
  94. };
  95.  
  96. struct _MDLock {
  97.     PRInt8 notused;
  98. };
  99.  
  100. struct _MDSemaphore {
  101.     PRInt8 notused;
  102. };
  103.  
  104. struct _MDCVar {
  105.     PRInt8 notused;
  106. };
  107.  
  108. struct _MDSegment {
  109.     PRInt8 notused;
  110. };
  111.  
  112. struct _MDCPU {
  113.     struct _MDCPU_Unix md_unix;
  114. };
  115.  
  116. #define _MD_INIT_LOCKS()
  117. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  118. #define _MD_FREE_LOCK(lock)
  119. #define _MD_LOCK(lock)
  120. #define _MD_UNLOCK(lock)
  121. #define _MD_INIT_IO()
  122. #define _MD_IOQ_LOCK()
  123. #define _MD_IOQ_UNLOCK()
  124.  
  125. /*
  126. ** Initialize the thread context preparing it to execute "_main()"
  127. ** - get a nice, fresh context
  128. ** - set its SP to the stack we allcoated for it
  129. ** - set it to start things at "e"
  130. */
  131. #define _MD_INIT_CONTEXT(thread, _sp, _main, status)                \
  132.     PR_BEGIN_MACRO                                                  \
  133.     *status = PR_TRUE;                                              \
  134.     _GETCONTEXT(CONTEXT(thread));                                   \
  135.     /* this is supposed to point to the stack BASE, not to SP */    \
  136.     CONTEXT(thread)->uc_stack.ss_sp = thread->stack->stackBottom;   \
  137.     CONTEXT(thread)->uc_stack.ss_size = thread->stack->stackSize;   \
  138.     CONTEXT(thread)->uc_mcontext.gpregs[CXT_SP] = ((unsigned long)_sp - 128) & 0xfffffff8; \
  139.     CONTEXT(thread)->uc_mcontext.gpregs[CXT_T9] = _main;            \
  140.     CONTEXT(thread)->uc_mcontext.gpregs[CXT_EPC] = _main;           \
  141.     CONTEXT(thread)->uc_mcontext.gpregs[CXT_RA] = 0;                \
  142.     thread->no_sched = 0;                                           \
  143.     PR_END_MACRO
  144.  
  145. /*
  146. ** Save current context as it is scheduled away
  147. */
  148. #define _MD_SWITCH_CONTEXT(_thread)       \
  149.     PR_BEGIN_MACRO                        \
  150.     if (!_GETCONTEXT(CONTEXT(_thread))) { \
  151.     _MD_SAVE_ERRNO(_thread);          \
  152.     _MD_SET_LAST_THREAD(_thread);     \
  153.         _PR_Schedule();                   \
  154.     }                                     \
  155.     PR_END_MACRO
  156.  
  157. /*
  158. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT or set up
  159. **  by _MD_INIT_CONTEXT
  160. **  CXT_V0 is the register that holds the return value.
  161. **   We must set it to 1 so that we can see if the return from
  162. **   getcontext() is the result of calling getcontext() or
  163. **   setcontext()...
  164. **   setting a context got with getcontext() appears to
  165. **   return from getcontext(), too!
  166. **  CXT_A3 is the register that holds status when returning
  167. **   from a syscall. It is set to 0 to indicate success,
  168. **   because we want getcontext() on the other side of the magic
  169. **   door to be ok.
  170. */
  171. #define _MD_RESTORE_CONTEXT(_thread)   \
  172.     PR_BEGIN_MACRO                     \
  173.     ucontext_t *uc = CONTEXT(_thread); \
  174.     uc->uc_mcontext.gpregs[CXT_V0] = 1;\
  175.     uc->uc_mcontext.gpregs[CXT_A3] = 0;\
  176.     _MD_RESTORE_ERRNO(_thread);        \
  177.     _MD_SET_CURRENT_THREAD(_thread);   \
  178.     _SETCONTEXT(uc);                   \
  179.     PR_END_MACRO
  180.  
  181. #define _MD_SAVE_ERRNO(t)     (t)->md.errcode = errno;
  182. #define _MD_RESTORE_ERRNO(t)     errno = (t)->md.errcode;
  183.  
  184. #define _MD_GET_INTERVAL    _PR_UNIX_GetInterval
  185. #define _MD_INTERVAL_PER_SEC    _PR_UNIX_TicksPerSecond
  186.  
  187. #define _MD_EARLY_INIT        _MD_EarlyInit
  188. #define _MD_FINAL_INIT        _PR_UnixInit
  189. #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
  190. #define _MD_INIT_THREAD        _MD_InitializeThread
  191. #define _MD_EXIT_THREAD(thread)
  192. #define _MD_SUSPEND_THREAD(thread)
  193. #define _MD_RESUME_THREAD(thread)
  194. #define _MD_CLEAN_THREAD(_thread)
  195.  
  196. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  197. #define S_ISSOCK(mode)   ((mode&0xF000) == 0xC000)
  198. #endif
  199. #if !defined(S_ISLNK) && defined(S_IFLNK)
  200. #define S_ISLNK(mode)   ((mode&0xA000) == 0xC000)
  201. #endif
  202.  
  203. #include <sys/time.h>
  204. #include <sys/types.h>
  205. #include <sys/select.h>
  206. extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
  207.     fd_set *execptfds, struct timeval *timeout);
  208. #define _MD_SELECT(nfds,r,w,e,tv) _select(nfds,r,w,e,tv)
  209. #define _MD_POLL _poll
  210.  
  211. #endif /* nspr_reliantunix_defs_h___ */
  212.