2 * The x86 Win32 incarnation of arch-dependent OS-dependent routines.
3 * See also "win32-os.c".
7 * This software is part of the SBCL system. See the README file for
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.
19 #include <sys/param.h>
21 #include <sys/types.h>
29 #include "interrupt.h"
34 #include <sys/types.h>
39 #include "thread.h" /* dynamic_values_bytes */
43 size_t os_vm_page_size;
45 int arch_os_thread_init(struct thread *thread) {
47 //unsigned long cur_stack_base;
48 //unsigned long cur_stack_end;
51 //asm volatile ("movl %%fs:8,%0": "=r" (cur_stack_base));
52 // asm volatile ("movl %%fs:4,%0": "=r" (cur_stack_end));
54 asm volatile ("movl %%fs:0,%0": "=r" (cur_stack_end));
56 // fprintf(stderr, "#x%08lx #x%08lx.\n", cur_stack_base, cur_stack_end);
58 //if (cur_stack_base > thread->control_stack_start) {
59 // cur_stack_base = thread->control_stack_start;
62 //if (cur_stack_end < thread->control_stack_end) {
63 // cur_stack_end = thread->control_stack_end;
66 // fprintf(stderr, "#x%08lx #x%08lx.\n", cur_stack_base, cur_stack_end);
71 //asm volatile ("movl %0,%%fs:8": : "r" (cur_stack_base));
72 //asm volatile ("movl %0,%%fs:4": : "r" (cur_stack_end));
74 thread->control_stack_end = cur_stack_end;
77 #ifdef LISP_FEATURE_SB_THREAD
78 /* this must be called from a function that has an exclusive lock
81 struct user_desc ldt_entry = {
82 1, 0, 0, /* index, address, length filled in later */
83 1, MODIFY_LDT_CONTENTS_DATA, 0, 0, 0, 1
86 get_spinlock(&modify_ldt_lock,thread);
87 n=modify_ldt(0,local_ldt_copy,sizeof local_ldt_copy);
88 /* get next free ldt entry */
92 for(n=0,p=local_ldt_copy;*p;p+=LDT_ENTRY_SIZE/sizeof(u32))
95 ldt_entry.entry_number=n;
96 ldt_entry.base_addr=(unsigned long) thread;
97 ldt_entry.limit=dynamic_values_bytes;
98 ldt_entry.limit_in_pages=0;
99 if (modify_ldt (1, &ldt_entry, sizeof (ldt_entry)) != 0) {
101 /* modify_ldt call failed: something magical is not happening */
104 __asm__ __volatile__ ("movw %w0, %%fs" : : "q"
105 ((n << 3) /* selector number */
106 + (1 << 2) /* TI set = LDT */
107 + 3)); /* privilege level */
108 thread->tls_cookie=n;
117 /* free any arch/os-specific resources used by thread, which is now
118 * defunct. Not called on live threads
121 int arch_os_thread_cleanup(struct thread *thread) {
125 os_context_register_t *
126 os_context_register_addr(os_context_t *context, int offset)
129 case reg_EAX: return &context->Eax;
130 case reg_ECX: return &context->Ecx;
131 case reg_EDX: return &context->Edx;
132 case reg_EBX: return &context->Ebx;
133 case reg_ESP: return &context->Esp;
134 case reg_EBP: return &context->Ebp;
135 case reg_ESI: return &context->Esi;
136 case reg_EDI: return &context->Edi;
141 os_context_register_t *
142 os_context_pc_addr(os_context_t *context)
144 return &context->Eip; /* REG_EIP */
147 os_context_register_t *
148 os_context_sp_addr(os_context_t *context)
150 return &context->Esp; /* REG_UESP */
153 os_context_register_t *
154 os_context_fp_addr(os_context_t *context)
156 return &context->Ebp; /* REG_EBP */
160 os_context_fp_control(os_context_t *context)
162 return ((((context->FloatSave.ControlWord) & 0xffff) ^ 0x3f) |
163 (((context->FloatSave.StatusWord) & 0xffff) << 16));
167 os_restore_fp_control(os_context_t *context)
169 asm ("fldcw %0" : : "m" (context->FloatSave.ControlWord));
173 os_flush_icache(os_vm_address_t address, os_vm_size_t length)