e5c389507fd4c93dca713277f9bcc4afff6dd634
[sbcl.git] / src / runtime / x86-linux-os.c
1 /*
2  * The x86 Linux incarnation of arch-dependent OS-dependent routines.
3  * See also "linux-os.c".
4  */
5
6 /*
7  * This software is part of the SBCL system. See the README file for
8  * more information.
9  *
10  * This software is derived from the CMU CL system, which was
11  * written at Carnegie Mellon University and released into the
12  * public domain. The software is in the public domain and is
13  * provided with absolutely no warranty. See the COPYING and CREDITS
14  * files for more information.
15  */
16
17 #include <stdio.h>
18 #include <sys/param.h>
19 #include <sys/file.h>
20 #include "./signal.h"
21 #include "os.h"
22 #include "arch.h"
23 #include "globals.h"
24 #include "interrupt.h"
25 #include "interr.h"
26 #include "lispregs.h"
27 #include "sbcl.h"
28 #include <sys/socket.h>
29 #include <sys/utsname.h>
30
31 #include <sys/types.h>
32 #include <signal.h>
33 /* #include <sys/sysinfo.h> */
34 #include <sys/time.h>
35 #include <sys/stat.h>
36 #include <unistd.h>
37
38 #include "validate.h"
39 size_t os_vm_page_size;
40
41 #if defined GENCGC
42 #include "gencgc.h"
43 #endif
44
45 /* KLUDGE: As of kernel 2.2.14 on Red Hat 6.2, there's code in the
46  * <sys/ucontext.h> file to define symbolic names for offsets into
47  * gregs[], but it's conditional on __USE_GNU and not defined, so
48  * we need to do this nasty absolute index magic number thing
49  * instead. */
50 os_context_register_t *
51 os_context_register_addr(os_context_t *context, int offset)
52 {
53     switch(offset) {
54     case  0: return &context->uc_mcontext.gregs[11]; /* EAX */
55     case  2: return &context->uc_mcontext.gregs[10]; /* ECX */
56     case  4: return &context->uc_mcontext.gregs[9]; /* EDX */
57     case  6: return &context->uc_mcontext.gregs[8]; /* EBX */
58     case  8: return &context->uc_mcontext.gregs[7]; /* ESP */
59     case 10: return &context->uc_mcontext.gregs[6]; /* EBP */
60     case 12: return &context->uc_mcontext.gregs[5]; /* ESI */
61     case 14: return &context->uc_mcontext.gregs[4]; /* EDI */
62     default: return 0;
63     }
64     return &context->uc_mcontext.gregs[offset];
65 }
66
67 os_context_register_t *
68 os_context_pc_addr(os_context_t *context)
69 {
70     return &context->uc_mcontext.gregs[14]; /*  REG_EIP */
71 }
72
73 os_context_register_t *
74 os_context_sp_addr(os_context_t *context)
75 {                               
76     return &context->uc_mcontext.gregs[17]; /* REG_UESP */
77 }
78
79 os_context_register_t *
80 os_context_fp_addr(os_context_t *context)
81 {
82     return &context->uc_mcontext.gregs[6]; /* REG_EBP */
83 }
84
85 unsigned long
86 os_context_fp_control(os_context_t *context)
87 {
88     return ((((context->uc_mcontext.fpregs->cw) & 0xffff) ^ 0x3f) |
89             (((context->uc_mcontext.fpregs->sw) & 0xffff) << 16));
90 }
91
92 sigset_t *
93 os_context_sigmask_addr(os_context_t *context)
94 {
95     return &context->uc_sigmask;
96 }
97
98 void
99 os_restore_fp_control(os_context_t *context)
100 {
101     asm ("fldcw %0" : : "m" (context->uc_mcontext.fpregs->cw));
102 }
103
104 void
105 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
106 {
107 }
108