michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nspr_irix_defs_h___ michael@0: #define nspr_irix_defs_h___ michael@0: michael@0: #define _PR_HAVE_ATOMIC_CAS michael@0: michael@0: /* michael@0: * MipsPro assembler defines _LANGUAGE_ASSEMBLY michael@0: */ michael@0: #ifndef _LANGUAGE_ASSEMBLY michael@0: michael@0: #include "prclist.h" michael@0: #include "prthread.h" michael@0: #include michael@0: michael@0: /* michael@0: * Internal configuration macros michael@0: */ michael@0: michael@0: #define PR_LINKER_ARCH "irix" michael@0: #define _PR_SI_SYSNAME "IRIX" michael@0: #define _PR_SI_ARCHITECTURE "mips" michael@0: #define PR_DLL_SUFFIX ".so" michael@0: michael@0: #define _PR_VMBASE 0x30000000 michael@0: #define _PR_STACK_VMBASE 0x50000000 michael@0: #define _PR_NUM_GCREGS 9 michael@0: #define _MD_MMAP_FLAGS MAP_PRIVATE michael@0: michael@0: #define _MD_DEFAULT_STACK_SIZE 65536L michael@0: #define _MD_MIN_STACK_SIZE 16384L michael@0: michael@0: #undef HAVE_STACK_GROWING_UP michael@0: #define HAVE_WEAK_IO_SYMBOLS michael@0: #define HAVE_WEAK_MALLOC_SYMBOLS michael@0: #define HAVE_DLL michael@0: #define USE_DLFCN michael@0: #define _PR_HAVE_ATOMIC_OPS michael@0: #define _PR_POLL_AVAILABLE michael@0: #define _PR_USE_POLL michael@0: #define _PR_STAT_HAS_ST_ATIM michael@0: #define _PR_HAVE_OFF64_T michael@0: #define HAVE_POINTER_LOCALTIME_R michael@0: #define _PR_HAVE_POSIX_SEMAPHORES michael@0: #define PR_HAVE_POSIX_NAMED_SHARED_MEMORY michael@0: #define _PR_ACCEPT_INHERIT_NONBLOCK michael@0: michael@0: #ifdef _PR_INET6 michael@0: #define _PR_HAVE_INET_NTOP michael@0: #define _PR_HAVE_GETIPNODEBYNAME michael@0: #define _PR_HAVE_GETIPNODEBYADDR michael@0: #define _PR_HAVE_GETADDRINFO michael@0: #endif michael@0: michael@0: /* Initialization entry points */ michael@0: NSPR_API(void) _MD_EarlyInit(void); michael@0: #define _MD_EARLY_INIT _MD_EarlyInit michael@0: michael@0: NSPR_API(void) _MD_IrixInit(void); michael@0: #define _MD_FINAL_INIT _MD_IrixInit michael@0: michael@0: #define _MD_INIT_IO() michael@0: michael@0: /* Timer operations */ michael@0: NSPR_API(PRIntervalTime) _MD_IrixGetInterval(void); michael@0: #define _MD_GET_INTERVAL _MD_IrixGetInterval michael@0: michael@0: NSPR_API(PRIntervalTime) _MD_IrixIntervalPerSec(void); michael@0: #define _MD_INTERVAL_PER_SEC _MD_IrixIntervalPerSec michael@0: michael@0: /* GC operations */ michael@0: NSPR_API(void *) _MD_GetSP(PRThread *thread); michael@0: #define _MD_GET_SP _MD_GetSP michael@0: michael@0: /* The atomic operations */ michael@0: #include michael@0: #define _MD_INIT_ATOMIC() michael@0: #define _MD_ATOMIC_INCREMENT(val) add_then_test((unsigned long*)val, 1) michael@0: #define _MD_ATOMIC_ADD(ptr, val) add_then_test((unsigned long*)ptr, (unsigned long)val) michael@0: #define _MD_ATOMIC_DECREMENT(val) add_then_test((unsigned long*)val, 0xffffffff) michael@0: #define _MD_ATOMIC_SET(val, newval) test_and_set((unsigned long*)val, newval) michael@0: michael@0: #if defined(_PR_PTHREADS) michael@0: #else /* defined(_PR_PTHREADS) */ michael@0: michael@0: /************************************************************************/ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: michael@0: /* michael@0: * Data region private to each sproc. This region is setup by calling michael@0: * mmap(...,MAP_LOCAL,...). The private data is mapped at the same michael@0: * address in every sproc, but every sproc gets a private mapping. michael@0: * michael@0: * Just make sure that this structure fits in a page, as only one page michael@0: * is allocated for the private region. michael@0: */ michael@0: struct sproc_private_data { michael@0: struct PRThread *me; michael@0: struct _PRCPU *cpu; michael@0: struct PRThread *last; michael@0: PRUintn intsOff; michael@0: int sproc_pid; michael@0: }; michael@0: michael@0: extern char *_nspr_sproc_private; michael@0: michael@0: #define _PR_PRDA() ((struct sproc_private_data *) _nspr_sproc_private) michael@0: #define _MD_SET_CURRENT_THREAD(_thread) _PR_PRDA()->me = (_thread) michael@0: #define _MD_THIS_THREAD() (_PR_PRDA()->me) michael@0: #define _MD_LAST_THREAD() (_PR_PRDA()->last) michael@0: #define _MD_SET_LAST_THREAD(_thread) _PR_PRDA()->last = (_thread) michael@0: #define _MD_CURRENT_CPU() (_PR_PRDA()->cpu) michael@0: #define _MD_SET_CURRENT_CPU(_cpu) _PR_PRDA()->cpu = (_cpu) michael@0: #define _MD_SET_INTSOFF(_val) (_PR_PRDA()->intsOff = _val) michael@0: #define _MD_GET_INTSOFF() (_PR_PRDA()->intsOff) michael@0: michael@0: #define _MD_SET_SPROC_PID(_val) (_PR_PRDA()->sproc_pid = _val) michael@0: #define _MD_GET_SPROC_PID() (_PR_PRDA()->sproc_pid) michael@0: michael@0: NSPR_API(struct PRThread*) _MD_get_attached_thread(void); michael@0: NSPR_API(struct PRThread*) _MD_get_current_thread(void); michael@0: #define _MD_GET_ATTACHED_THREAD() _MD_get_attached_thread() michael@0: #define _MD_CURRENT_THREAD() _MD_get_current_thread() michael@0: michael@0: #define _MD_CHECK_FOR_EXIT() { \ michael@0: if (_pr_irix_exit_now) { \ michael@0: _PR_POST_SEM(_pr_irix_exit_sem); \ michael@0: _MD_Wakeup_CPUs(); \ michael@0: _exit(0); \ michael@0: } \ michael@0: } michael@0: michael@0: #define _MD_ATTACH_THREAD(threadp) michael@0: michael@0: #define _MD_SAVE_ERRNO(_thread) (_thread)->md.errcode = errno; michael@0: #define _MD_RESTORE_ERRNO(_thread) errno = (_thread)->md.errcode; michael@0: michael@0: extern struct _PRCPU *_pr_primordialCPU; michael@0: extern usema_t *_pr_irix_exit_sem; michael@0: extern PRInt32 _pr_irix_exit_now; michael@0: extern int _pr_irix_primoridal_cpu_fd[]; michael@0: extern PRInt32 _pr_irix_process_exit; michael@0: extern PRInt32 _pr_irix_process_exit_code; michael@0: michael@0: /* Thread operations */ michael@0: #define _PR_LOCK_HEAP() { \ michael@0: PRIntn _is; \ michael@0: if (_pr_primordialCPU) { \ michael@0: if (_MD_GET_ATTACHED_THREAD() && \ michael@0: !_PR_IS_NATIVE_THREAD( \ michael@0: _MD_GET_ATTACHED_THREAD())) \ michael@0: _PR_INTSOFF(_is); \ michael@0: _PR_LOCK(_pr_heapLock); \ michael@0: } michael@0: michael@0: #define _PR_UNLOCK_HEAP() if (_pr_primordialCPU) { \ michael@0: _PR_UNLOCK(_pr_heapLock); \ michael@0: if (_MD_GET_ATTACHED_THREAD() && \ michael@0: !_PR_IS_NATIVE_THREAD( \ michael@0: _MD_GET_ATTACHED_THREAD())) \ michael@0: _PR_INTSON(_is); \ michael@0: } \ michael@0: } michael@0: michael@0: #define _PR_OPEN_POLL_SEM(_sem) usopenpollsema(_sem, 0666) michael@0: #define _PR_WAIT_SEM(_sem) uspsema(_sem) michael@0: #define _PR_POST_SEM(_sem) usvsema(_sem) michael@0: michael@0: #define _MD_CVAR_POST_SEM(threadp) usvsema((threadp)->md.cvar_pollsem) michael@0: michael@0: #define _MD_IOQ_LOCK() michael@0: #define _MD_IOQ_UNLOCK() michael@0: michael@0: struct _MDLock { michael@0: ulock_t lock; michael@0: usptr_t *arena; michael@0: }; michael@0: michael@0: /* michael@0: * disable pre-emption for the LOCAL threads when calling the arena lock michael@0: * routines michael@0: */ michael@0: michael@0: #define _PR_LOCK(lock) { \ michael@0: PRIntn _is; \ michael@0: PRThread *me = _MD_GET_ATTACHED_THREAD(); \ michael@0: if (me && !_PR_IS_NATIVE_THREAD(me)) \ michael@0: _PR_INTSOFF(_is); \ michael@0: ussetlock(lock); \ michael@0: if (me && !_PR_IS_NATIVE_THREAD(me)) \ michael@0: _PR_FAST_INTSON(_is); \ michael@0: } michael@0: michael@0: #define _PR_UNLOCK(lock) { \ michael@0: PRIntn _is; \ michael@0: PRThread *me = _MD_GET_ATTACHED_THREAD(); \ michael@0: if (me && !_PR_IS_NATIVE_THREAD(me)) \ michael@0: _PR_INTSOFF(_is); \ michael@0: usunsetlock(lock); \ michael@0: if (me && !_PR_IS_NATIVE_THREAD(me)) \ michael@0: _PR_FAST_INTSON(_is); \ michael@0: } michael@0: michael@0: NSPR_API(PRStatus) _MD_NEW_LOCK(struct _MDLock *md); michael@0: NSPR_API(void) _MD_FREE_LOCK(struct _MDLock *lockp); michael@0: michael@0: #define _MD_LOCK(_lockp) _PR_LOCK((_lockp)->lock) michael@0: #define _MD_UNLOCK(_lockp) _PR_UNLOCK((_lockp)->lock) michael@0: #define _MD_TEST_AND_LOCK(_lockp) (uscsetlock((_lockp)->lock, 1) == 0) michael@0: michael@0: extern ulock_t _pr_heapLock; michael@0: michael@0: struct _MDThread { michael@0: jmp_buf jb; michael@0: usptr_t *pollsem_arena; michael@0: usema_t *cvar_pollsem; michael@0: PRInt32 cvar_pollsemfd; michael@0: PRInt32 cvar_pollsem_select; /* acquire sem by calling select */ michael@0: PRInt32 cvar_wait; /* if 1, thread is waiting on cvar Q */ michael@0: PRInt32 id; michael@0: PRInt32 suspending_id; michael@0: int errcode; michael@0: }; michael@0: michael@0: struct _MDThreadStack { michael@0: PRInt8 notused; michael@0: }; michael@0: michael@0: struct _MDSemaphore { michael@0: usema_t *sem; michael@0: }; michael@0: michael@0: struct _MDCVar { michael@0: ulock_t mdcvar_lock; michael@0: }; michael@0: michael@0: struct _MDSegment { michael@0: PRInt8 notused; michael@0: }; michael@0: michael@0: /* michael@0: * md-specific cpu structure field michael@0: */ michael@0: #define _PR_MD_MAX_OSFD FD_SETSIZE michael@0: michael@0: struct _MDCPU_Unix { michael@0: PRCList ioQ; michael@0: PRUint32 ioq_timeout; michael@0: PRInt32 ioq_max_osfd; michael@0: PRInt32 ioq_osfd_cnt; michael@0: #ifndef _PR_USE_POLL michael@0: fd_set fd_read_set, fd_write_set, fd_exception_set; michael@0: PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD], michael@0: fd_exception_cnt[_PR_MD_MAX_OSFD]; michael@0: #else michael@0: struct pollfd *ioq_pollfds; michael@0: int ioq_pollfds_size; michael@0: #endif /* _PR_USE_POLL */ michael@0: }; michael@0: michael@0: #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ) michael@0: #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu)) michael@0: #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set) michael@0: #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt) michael@0: #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set) michael@0: #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt) michael@0: #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set) michael@0: #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt) michael@0: #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout) michael@0: #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd) michael@0: #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt) michael@0: #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds) michael@0: #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size) michael@0: michael@0: #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32 michael@0: michael@0: michael@0: struct _MDCPU { michael@0: PRInt32 id; michael@0: PRInt32 suspending_id; michael@0: struct _MDCPU_Unix md_unix; michael@0: }; michael@0: michael@0: /* michael@0: ** Initialize the thread context preparing it to execute _main. michael@0: */ michael@0: #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ michael@0: PR_BEGIN_MACRO \ michael@0: int *jb = (_thread)->md.jb; \ michael@0: *status = PR_TRUE; \ michael@0: (void) setjmp(jb); \ michael@0: (_thread)->md.jb[JB_SP] = (int) ((_sp) - 64); \ michael@0: (_thread)->md.jb[JB_PC] = (int) _main; \ michael@0: _thread->no_sched = 0; \ michael@0: PR_END_MACRO michael@0: michael@0: /* michael@0: ** Switch away from the current thread context by saving its state and michael@0: ** calling the thread scheduler. Reload cpu when we come back from the michael@0: ** context switch because it might have changed. michael@0: * michael@0: * XXX RUNQ lock needed before clearing _PR_NO_SCHED flag, because the michael@0: * thread may be unr RUNQ? michael@0: */ michael@0: #define _MD_SWITCH_CONTEXT(_thread) \ michael@0: PR_BEGIN_MACRO \ michael@0: PR_ASSERT(_thread->no_sched); \ michael@0: if (!setjmp(_thread->md.jb)) { \ michael@0: _MD_SAVE_ERRNO(_thread) \ michael@0: _MD_SET_LAST_THREAD(_thread); \ michael@0: _PR_Schedule(); \ michael@0: } else { \ michael@0: PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \ michael@0: _MD_LAST_THREAD()->no_sched = 0; \ michael@0: } \ michael@0: PR_END_MACRO michael@0: michael@0: /* michael@0: ** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or michael@0: ** initialized by _MD_INIT_CONTEXT. michael@0: */ michael@0: #define _MD_RESTORE_CONTEXT(_newThread) \ michael@0: PR_BEGIN_MACRO \ michael@0: int *jb = (_newThread)->md.jb; \ michael@0: _MD_RESTORE_ERRNO(_newThread) \ michael@0: _MD_SET_CURRENT_THREAD(_newThread); \ michael@0: _newThread->no_sched = 1; \ michael@0: longjmp(jb, 1); \ michael@0: PR_END_MACRO michael@0: michael@0: NSPR_API(PRStatus) _MD_InitThread(struct PRThread *thread, michael@0: PRBool wakeup_parent); michael@0: NSPR_API(PRStatus) _MD_InitAttachedThread(struct PRThread *thread, michael@0: PRBool wakeup_parent); michael@0: #define _MD_INIT_THREAD(thread) _MD_InitThread(thread, PR_TRUE) michael@0: #define _MD_INIT_ATTACHED_THREAD(thread) \ michael@0: _MD_InitAttachedThread(thread, PR_FALSE) michael@0: michael@0: NSPR_API(void) _MD_ExitThread(struct PRThread *thread); michael@0: #define _MD_EXIT_THREAD _MD_ExitThread michael@0: michael@0: NSPR_API(void) _MD_SuspendThread(struct PRThread *thread); michael@0: #define _MD_SUSPEND_THREAD _MD_SuspendThread michael@0: michael@0: NSPR_API(void) _MD_ResumeThread(struct PRThread *thread); michael@0: #define _MD_RESUME_THREAD _MD_ResumeThread michael@0: michael@0: NSPR_API(void) _MD_SuspendCPU(struct _PRCPU *thread); michael@0: #define _MD_SUSPEND_CPU _MD_SuspendCPU michael@0: michael@0: NSPR_API(void) _MD_ResumeCPU(struct _PRCPU *thread); michael@0: #define _MD_RESUME_CPU _MD_ResumeCPU michael@0: michael@0: #define _MD_BEGIN_SUSPEND_ALL() michael@0: #define _MD_END_SUSPEND_ALL() michael@0: #define _MD_BEGIN_RESUME_ALL() michael@0: #define _MD_END_RESUME_ALL() michael@0: michael@0: NSPR_API(void) _MD_InitLocks(void); michael@0: #define _MD_INIT_LOCKS _MD_InitLocks michael@0: michael@0: NSPR_API(void) _MD_CleanThread(struct PRThread *thread); michael@0: #define _MD_CLEAN_THREAD _MD_CleanThread michael@0: michael@0: #define _MD_YIELD() sginap(0) michael@0: michael@0: /* The _PR_MD_WAIT_LOCK and _PR_MD_WAKEUP_WAITER functions put to sleep and michael@0: * awaken a thread which is waiting on a lock or cvar. michael@0: */ michael@0: NSPR_API(PRStatus) _MD_wait(struct PRThread *, PRIntervalTime timeout); michael@0: #define _MD_WAIT _MD_wait michael@0: michael@0: NSPR_API(void) _PR_MD_primordial_cpu(); michael@0: NSPR_API(void) _PR_MD_WAKEUP_PRIMORDIAL_CPU(); michael@0: michael@0: NSPR_API(PRStatus) _MD_WakeupWaiter(struct PRThread *); michael@0: #define _MD_WAKEUP_WAITER _MD_WakeupWaiter michael@0: michael@0: NSPR_API(void ) _MD_exit(PRIntn status); michael@0: #define _MD_EXIT _MD_exit michael@0: michael@0: #include "prthread.h" michael@0: michael@0: NSPR_API(void) _MD_SetPriority(struct _MDThread *thread, michael@0: PRThreadPriority newPri); michael@0: #define _MD_SET_PRIORITY _MD_SetPriority michael@0: michael@0: NSPR_API(PRStatus) _MD_CreateThread( michael@0: struct PRThread *thread, michael@0: void (*start) (void *), michael@0: PRThreadPriority priority, michael@0: PRThreadScope scope, michael@0: PRThreadState state, michael@0: PRUint32 stackSize); michael@0: #define _MD_CREATE_THREAD _MD_CreateThread michael@0: michael@0: extern void _MD_CleanupBeforeExit(void); michael@0: #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit michael@0: michael@0: NSPR_API(void) _PR_MD_PRE_CLEANUP(PRThread *me); michael@0: michael@0: michael@0: /* The following defines the unwrapped versions of select() and poll(). */ michael@0: extern int _select(int nfds, fd_set *readfds, fd_set *writefds, michael@0: fd_set *exceptfds, struct timeval *timeout); michael@0: #define _MD_SELECT _select michael@0: michael@0: #include michael@0: #include michael@0: #define _MD_POLL _poll michael@0: extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout); michael@0: michael@0: michael@0: #define HAVE_THREAD_AFFINITY 1 michael@0: michael@0: NSPR_API(PRInt32) _MD_GetThreadAffinityMask(PRThread *unused, PRUint32 *mask); michael@0: #define _MD_GETTHREADAFFINITYMASK _MD_GetThreadAffinityMask michael@0: michael@0: NSPR_API(void) _MD_InitRunningCPU(struct _PRCPU *cpu); michael@0: #define _MD_INIT_RUNNING_CPU _MD_InitRunningCPU michael@0: michael@0: #endif /* defined(_PR_PTHREADS) */ michael@0: michael@0: #endif /* _LANGUAGE_ASSEMBLY */ michael@0: michael@0: #endif /* nspr_irix_defs_h___ */