1
/* ==== machdep.c ============================================================
2
* Copyright (c) 1993, 1994 Chris Provenzano, proven@athena.mit.edu
4
* Description : Machine dependent functions for SunOS-4.1.3 on sparc
7
* -Started coding this file.
11
static const char rcsid[] = "$Id$";
17
/* These would be defined in setjmp.h, if _POSIX_SOURCE and _XOPEN_SOURCE
18
were both undefined. But we've already included it, and lost the
25
/* ==========================================================================
26
* machdep_save_state()
28
int machdep_save_state(void)
30
return setjmp (pthread_run->machdep_data.machdep_state);
33
/* ==========================================================================
34
* machdep_restore_state()
36
extern void machdep_restore_from_setjmp (jmp_buf, long);
37
void machdep_restore_state(void)
39
machdep_restore_from_setjmp (pthread_run->machdep_data.machdep_state, 1);
42
void machdep_save_float_state (void) { }
43
void machdep_restore_float_state (void) { }
45
/* ==========================================================================
46
* machdep_set_thread_timer()
48
void machdep_set_thread_timer(struct machdep_pthread *machdep_pthread)
50
if (setitimer(ITIMER_VIRTUAL, &(machdep_pthread->machdep_timer), NULL)) {
55
/* ==========================================================================
56
* machdep_unset_thread_timer()
58
void machdep_unset_thread_timer(struct machdep_pthread *machdep_pthread)
60
struct itimerval zeroval = { { 0, 0 }, { 0, 0} };
62
if (setitimer(ITIMER_VIRTUAL, &zeroval, NULL)) {
67
/* ==========================================================================
68
* machdep_pthread_cleanup()
70
void *machdep_pthread_cleanup(struct machdep_pthread *machdep_pthread)
72
return(machdep_pthread->machdep_stack);
75
/* ==========================================================================
76
* machdep_pthread_start()
78
void machdep_pthread_start(void)
80
context_switch_done();
81
pthread_sched_resume ();
83
/* Run current threads start routine with argument */
84
pthread_exit(pthread_run->machdep_data.start_routine
85
(pthread_run->machdep_data.start_argument));
87
/* should never reach here */
91
/* ==========================================================================
92
* __machdep_stack_free()
94
void __machdep_stack_free(void * stack)
99
/* ==========================================================================
100
* __machdep_stack_alloc()
102
void * __machdep_stack_alloc(size_t size)
106
return(malloc(size));
109
/* ==========================================================================
110
* __machdep_pthread_create()
112
void __machdep_pthread_create(struct machdep_pthread *machdep_pthread,
113
void *(* start_routine)(), void *start_argument,
114
long stack_size, long nsec, long flags)
116
machdep_pthread->start_routine = start_routine;
117
machdep_pthread->start_argument = start_argument;
119
machdep_pthread->machdep_timer.it_value.tv_sec = 0;
120
machdep_pthread->machdep_timer.it_interval.tv_sec = 0;
121
machdep_pthread->machdep_timer.it_interval.tv_usec = 0;
122
machdep_pthread->machdep_timer.it_value.tv_usec = nsec / 1000;
124
setjmp(machdep_pthread->machdep_state);
126
/* Set up new stack frame so that it looks like it returned from a
127
longjmp() to the beginning of machdep_pthread_start(). */
128
machdep_pthread->machdep_state[JB_RA] = 0;
129
machdep_pthread->machdep_state[JB_PC] = (long)machdep_pthread_start;
130
machdep_pthread->machdep_state[JB_PV] = (long)machdep_pthread_start;
132
/* Alpha stack starts high and builds down. */
134
long stk_addr = (long) machdep_pthread->machdep_stack;
135
stk_addr += stack_size - 1024;
137
machdep_pthread->machdep_state[JB_SP] = stk_addr;
141
/* ==========================================================================
142
* machdep_sys_wait3()
144
machdep_sys_wait3(int * b, int c, int * d)
146
return(machdep_sys_wait4(0, b, c, d));
149
/* ==========================================================================
150
* machdep_sys_waitpid()
152
machdep_sys_waitpid(int pid, int * statusp, int options)
154
return machdep_sys_wait4 (pid, statusp, options, NULL);
157
/* These are found in flsbuf.o in the Alpha libc. I don't know what
158
they're for, precisely. */
163
long a1 = *(long *)(p+48);
164
long t0 = *(long *)(p+8);
173
*(char**)(p + 8) = p;
183
_findbuf () { abort (); }
184
_wrtchk () { abort (); }
185
_xflsbuf () { abort (); }
186
_flsbuf () { abort (); }
188
void __xxx_never_called () {
189
/* Force other stuff to get dragged in. */
195
int safe_store (loc, new)
200
asm ("mb" : : : "memory");
202
asm ("ldl_l %0,%1" : "=r" (old) : "m" (*loc));
203
asm ("stl_c %0,%1" : "=r" (locked), "=m" (*loc) : "0" (new));
205
asm ("mb" : : : "memory");