0.7.6.12:
[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
42 /* KLUDGE: As of kernel 2.2.14 on Red Hat 6.2, there's code in the
43  * <sys/ucontext.h> file to define symbolic names for offsets into
44  * gregs[], but it's conditional on __USE_GNU and not defined, so
45  * we need to do this nasty absolute index magic number thing
46  * instead. */
47 os_context_register_t *
48 os_context_register_addr(os_context_t *context, int offset)
49 {
50     switch(offset) {
51     case  0: return &context->uc_mcontext.gregs[11]; /* EAX */
52     case  2: return &context->uc_mcontext.gregs[10]; /* ECX */
53     case  4: return &context->uc_mcontext.gregs[9]; /* EDX */
54     case  6: return &context->uc_mcontext.gregs[8]; /* EBX */
55     case  8: return &context->uc_mcontext.gregs[7]; /* ESP */
56     case 10: return &context->uc_mcontext.gregs[6]; /* EBP */
57     case 12: return &context->uc_mcontext.gregs[5]; /* ESI */
58     case 14: return &context->uc_mcontext.gregs[4]; /* EDI */
59     default: return 0;
60     }
61     return &context->uc_mcontext.gregs[offset];
62 }
63
64 os_context_register_t *
65 os_context_pc_addr(os_context_t *context)
66 {
67     return &context->uc_mcontext.gregs[14]; /*  REG_EIP */
68 }
69
70 os_context_register_t *
71 os_context_sp_addr(os_context_t *context)
72 {                               
73     return &context->uc_mcontext.gregs[17]; /* REG_UESP */
74 }
75
76 os_context_register_t *
77 os_context_fp_addr(os_context_t *context)
78 {
79     return &context->uc_mcontext.gregs[6]; /* REG_EBP */
80 }
81
82 unsigned long
83 os_context_fp_control(os_context_t *context)
84 {
85     return ((((context->uc_mcontext.fpregs->cw) & 0xffff) ^ 0x3f) |
86             (((context->uc_mcontext.fpregs->sw) & 0xffff) << 16));
87 }
88
89 sigset_t *
90 os_context_sigmask_addr(os_context_t *context)
91 {
92     return &context->uc_sigmask;
93 }
94
95 void
96 os_restore_fp_control(os_context_t *context)
97 {
98     asm ("fldcw %0" : : "m" (context->uc_mcontext.fpregs->cw));
99 }
100
101 void
102 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
103 {
104 }
105