3 --- /dev/null Sun Dec 27 17:45:54 1998
4 +++ machdep/engine-i386-netbsd-1.3.c Mon Mar 2 19:44:34 1998
6 +/* ==== machdep.c ============================================================
7 + * Copyright (c) 1993, 1994 Chris Provenzano, proven@athena.mit.edu
9 + * Copyright (c) 1993 by Chris Provenzano, proven@mit.edu
10 + * All rights reserved.
12 + * Redistribution and use in source and binary forms, with or without
13 + * modification, are permitted provided that the following conditions
15 + * 1. Redistributions of source code must retain the above copyright
16 + * notice, this list of conditions and the following disclaimer.
17 + * 2. Redistributions in binary form must reproduce the above copyright
18 + * notice, this list of conditions and the following disclaimer in the
19 + * documentation and/or other materials provided with the distribution.
20 + * 3. All advertising materials mentioning features or use of this software
21 + * must display the following acknowledgement:
22 + * This product includes software developed by Chris Provenzano.
23 + * 4. The name of Chris Provenzano may not be used to endorse or promote
24 + * products derived from this software without specific prior written
27 + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``AS IS'' AND
28 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 + * ARE DISCLAIMED. IN NO EVENT SHALL CHRIS PROVENZANO BE LIABLE FOR ANY
31 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 + * Description : Machine dependent functions for NetBSD on i386
41 + * 1.00 93/08/04 proven
42 + * -Started coding this file.
46 +static const char rcsid[] = "$Id: patch-aw,v 1.1 1998/12/28 22:22:02 bad Exp $";
50 +#include <sys/types.h>
51 +#include <sys/socket.h>
56 +/* ==========================================================================
57 + * machdep_save_state()
59 +int machdep_save_state(void)
61 + return(_setjmp(pthread_run->machdep_data.machdep_state));
64 +/* ==========================================================================
65 + * machdep_save_state()
67 +int machdep_save_float_state(struct pthread * pthread)
69 + char * fdata = (char *)pthread->machdep_data.machdep_float_state;
71 + __asm__ ("fsave %0"::"m" (*fdata));
74 +/* ==========================================================================
75 + * machdep_restore_state()
77 +void machdep_restore_state(void)
79 + _longjmp(pthread_run->machdep_data.machdep_state, 1);
82 +/* ==========================================================================
83 + * machdep_restore_float_state()
85 +int machdep_restore_float_state(void)
87 + char * fdata = (char *)pthread_run->machdep_data.machdep_float_state;
89 + __asm__ ("frstor %0"::"m" (*fdata));
92 +/* ==========================================================================
93 + * machdep_set_thread_timer()
95 +void machdep_set_thread_timer(struct machdep_pthread *machdep_pthread)
97 + if (setitimer(ITIMER_VIRTUAL, &(machdep_pthread->machdep_timer), NULL)) {
102 +/* ==========================================================================
103 + * machdep_unset_thread_timer()
105 +void machdep_unset_thread_timer(struct machdep_pthread *machdep_pthread)
107 + struct itimerval zeroval = { { 0, 0 }, { 0, 0 } };
110 + if (machdep_pthread) {
111 + ret = setitimer(ITIMER_VIRTUAL, &zeroval,
112 + &(machdep_pthread->machdep_timer));
114 + ret = setitimer(ITIMER_VIRTUAL, &zeroval, NULL);
122 +/* ==========================================================================
123 + * machdep_pthread_cleanup()
125 +void *machdep_pthread_cleanup(struct machdep_pthread *machdep_pthread)
127 + return(machdep_pthread->machdep_stack);
130 +/* ==========================================================================
131 + * machdep_pthread_start()
133 +void machdep_pthread_start(void)
135 + context_switch_done();
136 + pthread_sched_resume();
138 + /* Run current threads start routine with argument */
139 + pthread_exit(pthread_run->machdep_data.start_routine
140 + (pthread_run->machdep_data.start_argument));
142 + /* should never reach here */
146 +/* ==========================================================================
147 + * __machdep_stack_free()
149 +void __machdep_stack_free(void * stack)
154 +/* ==========================================================================
155 + * __machdep_stack_alloc()
157 +void * __machdep_stack_alloc(size_t size)
161 + return(malloc(size));
164 +/* ==========================================================================
165 + * __machdep_pthread_create()
167 +void __machdep_pthread_create(struct machdep_pthread *machdep_pthread,
168 + void *(* start_routine)(), void *start_argument,
169 + long stack_size, long nsec, long flags)
171 + machdep_pthread->start_routine = start_routine;
172 + machdep_pthread->start_argument = start_argument;
174 + machdep_pthread->machdep_timer.it_value.tv_sec = 0;
175 + machdep_pthread->machdep_timer.it_interval.tv_sec = 0;
176 + machdep_pthread->machdep_timer.it_interval.tv_usec = 0;
177 + machdep_pthread->machdep_timer.it_value.tv_usec = nsec / 1000;
179 + _setjmp(machdep_pthread->machdep_state);
181 + * Set up new stact frame so that it looks like it
182 + * returned from a longjmp() to the beginning of
183 + * machdep_pthread_start().
185 + machdep_pthread->machdep_state[0] = (int)machdep_pthread_start;
187 + /* Stack starts high and builds down. */
188 + machdep_pthread->machdep_state[2] =
189 + (int)machdep_pthread->machdep_stack + stack_size;
192 +/* ==========================================================================
193 + * machdep_sys_creat()
195 +machdep_sys_creat(char * path, int mode)
197 + return(machdep_sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode));
200 +/* ==========================================================================
201 + * machdep_sys_wait3()
203 +machdep_sys_wait3(int * b, int c, int * d)
205 + return(machdep_sys_wait4(0, b, c, d));
208 +/* ==========================================================================
209 + * machdep_sys_waitpid()
211 +machdep_sys_waitpid(int a, int * b, int c)
213 + return(machdep_sys_wait4(a, b, c, NULL));
216 +/* ==========================================================================
217 + * machdep_sys_getdtablesize()
219 +machdep_sys_getdtablesize()
221 + return(sysconf(_SC_OPEN_MAX));
224 +/* ==========================================================================
225 + * machdep_sys_getdirentries()
227 +machdep_sys_getdirentries(int fd, char * buf, int len, int * seek)
229 + return(machdep_sys_getdents(fd, buf, len));