4569063d7a0d7946f76bed4d9a426c8f157d3c40
[sbcl.git] / src / runtime / x86-sunos-os.c
1 #include <stdio.h>
2 #include <sys/param.h>
3 #include <sys/file.h>
4 #include "sbcl.h"
5 #include "./signal.h"
6 #include "os.h"
7 #include "arch.h"
8 #include "globals.h"
9 #include "interrupt.h"
10 #include "interr.h"
11 #include "lispregs.h"
12 #include <sys/socket.h>
13 #include <sys/utsname.h>
14
15 #include <sys/types.h>
16 #include <signal.h>
17 #include <sys/time.h>
18 #include <sys/stat.h>
19 #include <unistd.h>
20
21 #include "validate.h"
22 #ifdef LISP_FEATURE_SB_THREAD
23 #error "Define threading support functions"
24 #else
25 int arch_os_thread_init(struct thread *thread) {
26   stack_t sigstack;
27 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
28     /* Signal handlers are run on the control stack, so if it is exhausted
29      * we had better use an alternate stack for whatever signal tells us
30      * we've exhausted it */
31     sigstack.ss_sp=((void *) thread)+dynamic_values_bytes;
32     sigstack.ss_flags=0;
33     sigstack.ss_size = 32*SIGSTKSZ;
34     sigaltstack(&sigstack,0);
35 #endif
36      return 1;                   /* success */
37 }
38 int arch_os_thread_cleanup(struct thread *thread) {
39     return 1;                   /* success */
40 }
41 #endif
42
43 os_context_register_t   *
44 os_context_register_addr(os_context_t *context, int offset)
45 {
46     /* Solaris x86 holds %esp value in UESP */
47     switch(offset) {
48     case reg_EAX: return &context->uc_mcontext.gregs[11];
49     case reg_ECX: return &context->uc_mcontext.gregs[10];
50     case reg_EDX: return &context->uc_mcontext.gregs[9];
51     case reg_EBX: return &context->uc_mcontext.gregs[8];
52     case reg_ESP: return &context->uc_mcontext.gregs[17]; /* REG_UESP */
53     case reg_EBP: return &context->uc_mcontext.gregs[6];
54     case reg_ESI: return &context->uc_mcontext.gregs[5];
55     case reg_EDI: return &context->uc_mcontext.gregs[4];
56     default: return 0;
57     }
58     return &context->uc_mcontext.gregs[offset];
59 }
60
61 os_context_register_t *
62 os_context_pc_addr(os_context_t *context)
63 {
64     return &(context->uc_mcontext.gregs[14]); /* REG_EIP */
65 }
66
67 os_context_register_t *
68 os_context_sp_addr(os_context_t *context)
69 {
70     return &(context->uc_mcontext.gregs[17]); /* REG_UESP */
71 }
72
73 sigset_t *
74 os_context_sigmask_addr(os_context_t *context)
75 {
76     return &(context->uc_sigmask);
77 }
78
79 void os_flush_icache(os_vm_address_t address, os_vm_size_t length)
80 {
81 }
82
83 unsigned long
84 os_context_fp_control(os_context_t *context)
85 {
86     int *state = context->uc_mcontext.fpregs.fp_reg_set.fpchip_state.state;
87     /* The STATE array is in the format used by the x86 instruction FNSAVE,
88      * so the FPU control word is in the first 16 bits */
89     int cw = (state[0] & 0xffff);
90     int sw = context->uc_mcontext.fpregs.fp_reg_set.fpchip_state.status;
91     return (cw ^ 0x3f) | (sw << 16);
92 }