1
/* ==== machdep.c ============================================================
2
* Copyright (c) 1993, 1994 Chris Provenzano, proven@athena.mit.edu
4
* Description : Machine dependent functions for NetBSD/Alpha 1.1(+)
7
* -Started coding this file.
10
* -Modified to make it go with NetBSD/Alpha
14
static const char rcsid[] = "engine-alpha-osf1.c,v 1.4.4.1 1995/12/13 05:41:37 proven Exp";
18
#include <sys/types.h>
19
#include <sys/socket.h>
20
#include <sys/syscall.h>
25
/* ==========================================================================
26
* machdep_save_state()
28
int machdep_save_state(void)
30
return __machdep_save_int_state(pthread_run->machdep_data.machdep_istate);
33
void machdep_restore_state(void)
35
__machdep_restore_int_state(pthread_run->machdep_data.machdep_istate);
38
void machdep_save_float_state (void)
40
__machdep_save_fp_state(pthread_run->machdep_data.machdep_fstate);
43
void machdep_restore_float_state (void)
45
__machdep_restore_fp_state(pthread_run->machdep_data.machdep_fstate);
48
/* ==========================================================================
49
* machdep_set_thread_timer()
51
void machdep_set_thread_timer(struct machdep_pthread *machdep_pthread)
53
if (setitimer(ITIMER_VIRTUAL, &(machdep_pthread->machdep_timer), NULL)) {
58
/* ==========================================================================
59
* machdep_unset_thread_timer()
61
void machdep_unset_thread_timer(struct machdep_pthread *machdep_pthread)
63
struct itimerval zeroval = { { 0, 0 }, { 0, 0} };
65
if (setitimer(ITIMER_VIRTUAL, &zeroval, NULL)) {
70
/* ==========================================================================
71
* machdep_pthread_cleanup()
73
void *machdep_pthread_cleanup(struct machdep_pthread *machdep_pthread)
75
return(machdep_pthread->machdep_stack);
78
/* ==========================================================================
79
* machdep_pthread_start()
81
void machdep_pthread_start(void)
83
context_switch_done();
84
pthread_sched_resume ();
86
/* Run current threads start routine with argument */
87
pthread_exit(pthread_run->machdep_data.start_routine
88
(pthread_run->machdep_data.start_argument));
90
/* should never reach here */
94
/* ==========================================================================
95
* __machdep_stack_free()
97
void __machdep_stack_free(void * stack)
102
/* ==========================================================================
103
* __machdep_stack_alloc()
105
void * __machdep_stack_alloc(size_t size)
109
return(malloc(size));
112
/* ==========================================================================
113
* __machdep_pthread_create()
115
void __machdep_pthread_create(struct machdep_pthread *machdep_pthread,
116
void *(* start_routine)(), void *start_argument,
117
long stack_size, long nsec, long flags)
119
machdep_pthread->start_routine = start_routine;
120
machdep_pthread->start_argument = start_argument;
122
machdep_pthread->machdep_timer.it_value.tv_sec = 0;
123
machdep_pthread->machdep_timer.it_interval.tv_sec = 0;
124
machdep_pthread->machdep_timer.it_interval.tv_usec = 0;
125
machdep_pthread->machdep_timer.it_value.tv_usec = nsec / 1000;
127
/* Set up new stack frame so that it looks like it returned from a
128
longjmp() to the beginning of machdep_pthread_start(). */
129
machdep_pthread->machdep_istate[8/*ISTATE_RA*/] = 0;
130
machdep_pthread->machdep_istate[0/*ISTATE_PC*/] = (long)machdep_pthread_start;
131
machdep_pthread->machdep_istate[10/*ISTATE_PV*/] = (long)machdep_pthread_start;
133
/* Alpha stack starts high and builds down. */
135
long stk_addr = (long) machdep_pthread->machdep_stack;
136
stk_addr += stack_size - 1024;
138
machdep_pthread->machdep_istate[9/*ISTATE_SP*/] = stk_addr;
142
int safe_store (loc, new)
147
asm ("mb" : : : "memory");
149
asm ("ldl_l %0,%1" : "=r" (old) : "m" (*loc));
150
asm ("stl_c %0,%1" : "=r" (locked), "=m" (*loc) : "0" (new));
152
asm ("mb" : : : "memory");
156
/* ==========================================================================
157
* machdep_sys_creat()
159
machdep_sys_creat(char * path, int mode)
161
return(machdep_sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode));
164
/* ==========================================================================
165
* machdep_sys_wait3()
167
machdep_sys_wait3(int * b, int c, int * d)
169
return(machdep_sys_wait4(0, b, c, d));
172
/* ==========================================================================
173
* machdep_sys_waitpid()
175
machdep_sys_waitpid(int a, int * b, int c)
177
return(machdep_sys_wait4(a, b, c, NULL));
180
/* ==========================================================================
181
* machdep_sys_getdtablesize()
183
machdep_sys_getdtablesize()
185
return(sysconf(_SC_OPEN_MAX));
188
/* ==========================================================================
189
* machdep_sys_lseek()
191
off_t machdep_sys_lseek(int fd, off_t offset, int whence)
193
extern off_t __syscall();
195
return(__syscall((quad_t)SYS_lseek, fd, 0, offset, whence));
198
/* ==========================================================================
199
* machdep_sys_getdirentries()
201
machdep_sys_getdirentries(int fd, char * buf, int len, int * seek)
203
return(machdep_sys_getdents(fd, buf, len));