diff --git a/src/kernel/core/arch/x86/arch_cpu.c b/src/kernel/core/arch/x86/arch_cpu.c index 72a22e0ec1..91b5b7fce2 100755 --- a/src/kernel/core/arch/x86/arch_cpu.c +++ b/src/kernel/core/arch/x86/arch_cpu.c @@ -1,24 +1,22 @@ /* +** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +** ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ -#include #include -#include #include -#include #include #include -#include -#include #include -#include - #include +#include #include + static struct tss **tss; static int *tss_loaded; @@ -51,7 +49,7 @@ arch_cpu_init2(kernel_args *ka) gGDT = (segment_descriptor *)ka->arch_args.vir_gdt; vm_create_anonymous_region(vm_get_kernel_aspace_id(), "gdt", (void **)&gGDT, - B_EXACT_KERNEL_ADDRESS, PAGE_SIZE, B_ALREADY_WIRED, + B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); // currently taken out of the build, because it's not yet used (and assumes @@ -91,7 +89,7 @@ arch_cpu_init2(kernel_args *ka) tss[i]->ss0 = KERNEL_DATA_SEG; // add TSS descriptor for this new TSS - set_tss_descriptor(&gGDT[TSS_BASE_SEGMENT + i], (addr)tss[i], sizeof(struct tss)); + set_tss_descriptor(&gGDT[TSS_BASE_SEGMENT + i], (addr_t)tss[i], sizeof(struct tss)); } // setup TLS descriptors (one for every CPU) @@ -106,7 +104,7 @@ arch_cpu_init2(kernel_args *ka) void -i386_set_tss_and_kstack(addr kstack) +i386_set_tss_and_kstack(addr_t kstack) { int currentCPU = smp_get_current_cpu(); @@ -124,7 +122,7 @@ i386_set_tss_and_kstack(addr kstack) void -arch_cpu_invalidate_TLB_range(addr start, addr end) +arch_cpu_invalidate_TLB_range(addr_t start, addr_t end) { int num_pages = end/PAGE_SIZE - start/PAGE_SIZE; while (num_pages-- >= 0) { @@ -135,7 +133,7 @@ arch_cpu_invalidate_TLB_range(addr start, addr end) void -arch_cpu_invalidate_TLB_list(addr pages[], int num_pages) +arch_cpu_invalidate_TLB_list(addr_t pages[], int num_pages) { int i; for (i = 0; i < num_pages; i++) { @@ -145,12 +143,12 @@ arch_cpu_invalidate_TLB_list(addr pages[], int num_pages) int -arch_cpu_user_memcpy(void *to, const void *from, size_t size, addr *fault_handler) +arch_cpu_user_memcpy(void *to, const void *from, size_t size, addr_t *fault_handler) { char *tmp = (char *)to; char *s = (char *)from; - *fault_handler = (addr)&&error; + *fault_handler = (addr_t)&&error; while (size--) *tmp++ = *s++; @@ -165,11 +163,11 @@ error: int -arch_cpu_user_strlcpy(char *to, const char *from, size_t size, addr *faultHandler) +arch_cpu_user_strlcpy(char *to, const char *from, size_t size, addr_t *faultHandler) { int from_length = 0; - *faultHandler = (addr)&&error; + *faultHandler = (addr_t)&&error; if (size > 0) { to[--size] = '\0'; @@ -193,11 +191,11 @@ error: int -arch_cpu_user_memset(void *s, char c, size_t count, addr *fault_handler) +arch_cpu_user_memset(void *s, char c, size_t count, addr_t *fault_handler) { char *xs = (char *)s; - *fault_handler = (addr)&&error; + *fault_handler = (addr_t)&&error; while (count--) *xs++ = c; diff --git a/src/kernel/core/arch/x86/arch_dbg_console.c b/src/kernel/core/arch/x86/arch_dbg_console.c index a9008f22b6..f8052441b9 100755 --- a/src/kernel/core/arch/x86/arch_dbg_console.c +++ b/src/kernel/core/arch/x86/arch_dbg_console.c @@ -6,6 +6,7 @@ ** Modified 2001/09/05 by Rob Judd ** Modified 2002/09/28 by Marcus Overhagen */ + #include #include #include diff --git a/src/kernel/core/arch/x86/arch_debug.c b/src/kernel/core/arch/x86/arch_debug.c index f51f96c3cf..a366ee56f8 100755 --- a/src/kernel/core/arch/x86/arch_debug.c +++ b/src/kernel/core/arch/x86/arch_debug.c @@ -66,7 +66,7 @@ dbg_stack_trace(int argc, char **argv) } else { uint32 eip = *((uint32 *)ebp + 1); const char *symbol, *image; - addr baseAddress; + addr_t baseAddress; bool exactMatch; if (eip == 0 || ebp == 0) diff --git a/src/kernel/core/arch/x86/arch_faults.c b/src/kernel/core/arch/x86/arch_faults.c index 385e8519ab..05987a8fc2 100755 --- a/src/kernel/core/arch/x86/arch_faults.c +++ b/src/kernel/core/arch/x86/arch_faults.c @@ -2,25 +2,14 @@ ** Copyright 2001, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ -#include + +#include #include #include -#include -#include -#include -#include +#include -#include -#include #include -#include -#include - -#include - -#include - // XXX this module is largely outdated. Will probably be removed later. int arch_faults_init(kernel_args *ka) diff --git a/src/kernel/core/arch/x86/arch_int.c b/src/kernel/core/arch/x86/arch_int.c index b3b530f5f7..1bc2b73d81 100755 --- a/src/kernel/core/arch/x86/arch_int.c +++ b/src/kernel/core/arch/x86/arch_int.c @@ -1,23 +1,15 @@ /* ** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. ** Distributed under the terms of the OpenBeOS License. -*/ - -/* +** ** Copyright 2001, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ -#include #include -#include -#include #include #include #include -#include -#include -#include #include #include @@ -31,8 +23,6 @@ #include #include -#include - #include #define MAX_ARGS 16 @@ -195,7 +185,7 @@ i386_handle_trap(struct iframe frame) case 14: // page fault { unsigned int cr2; - addr newip; + addr_t newip; asm("movl %%cr2, %0" : "=r" (cr2)); @@ -223,7 +213,6 @@ i386_handle_trap(struct iframe frame) { uint64 retcode; unsigned int args[MAX_ARGS]; - int rc; thread_atkernel_entry(); #if 0 @@ -243,15 +232,11 @@ i386_handle_trap(struct iframe frame) ** each is verified to make sure someone doesn't try to clobber it */ if (frame.ecx <= MAX_ARGS) { - if ((addr)frame.edx >= KERNEL_BASE && (addr)frame.edx <= KERNEL_TOP) { - retcode = ERR_VM_BAD_USER_MEMORY; - } else { - rc = user_memcpy(args, (void *)frame.edx, frame.ecx * sizeof(unsigned int)); - if (rc < 0) - retcode = ERR_VM_BAD_USER_MEMORY; - else - ret = syscall_dispatcher(frame.eax, (void *)args, &retcode); - } + if (IS_KERNEL_ADDRESS(frame.edx) + || user_memcpy(args, (void *)frame.edx, frame.ecx * sizeof(unsigned int)) < B_OK) { + retcode = B_BAD_ADDRESS; + } else + ret = syscall_dispatcher(frame.eax, (void *)args, &retcode); } else { // want to pass too many args into the system retcode = EINVAL; @@ -361,7 +346,7 @@ arch_int_init2(kernel_args *ka) { idt = (desc_table *)ka->arch_args.vir_idt; vm_create_anonymous_region(vm_get_kernel_aspace_id(), "idt", (void *)&idt, - B_EXACT_KERNEL_ADDRESS, PAGE_SIZE, B_ALREADY_WIRED, + B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); return 0; } diff --git a/src/kernel/core/arch/x86/arch_smp.c b/src/kernel/core/arch/x86/arch_smp.c index 67de70691f..56223f19b3 100755 --- a/src/kernel/core/arch/x86/arch_smp.c +++ b/src/kernel/core/arch/x86/arch_smp.c @@ -1,9 +1,11 @@ /* +** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +** ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ -#include #include #include #include @@ -111,10 +113,10 @@ arch_smp_init(kernel_args *ka) // setup regions that represent the apic & ioapic vm_create_anonymous_region(vm_get_kernel_aspace_id(), "local_apic", (void *)&apic, - B_EXACT_KERNEL_ADDRESS, PAGE_SIZE, B_ALREADY_WIRED, + B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); vm_create_anonymous_region(vm_get_kernel_aspace_id(), "ioapic", (void *)&ioapic, - B_EXACT_KERNEL_ADDRESS, PAGE_SIZE, B_ALREADY_WIRED, + B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); // set up the local apic on the boot cpu diff --git a/src/kernel/core/arch/x86/arch_thread.c b/src/kernel/core/arch/x86/arch_thread.c index 26695ffeb6..d4afdff4d6 100755 --- a/src/kernel/core/arch/x86/arch_thread.c +++ b/src/kernel/core/arch/x86/arch_thread.c @@ -1,23 +1,19 @@ /* +** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +** ** Copyright 2001, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ - -#include -#include -#include -#include -#include #include #include #include #include -#include -#include -#include #include +#include + //#define TRACE_ARCH_THREAD #ifdef TRACE_ARCH_THREAD @@ -77,6 +73,7 @@ arch_thread_init_thread_struct(struct thread *t) // set up an initial state (stack & fpu) memset(&t->arch_info, 0, sizeof(t->arch_info)); + // ToDo: note, this has to be done only once // let the asm function know the offset to the interrupt stack within struct thread // I know no better ( = static) way to tell the asm function the offset i386_stack_init(&((struct thread *)0)->arch_info.interrupt_stack); @@ -146,13 +143,11 @@ arch_thread_init_tls(struct thread *thread) tls[TLS_BASE_ADDRESS_SLOT] = thread->user_local_storage; tls[TLS_THREAD_ID_SLOT] = thread->id; tls[TLS_ERRNO_SLOT] = 0; - - set_tls_context(thread); } void -arch_thread_switch_kstack_and_call(struct thread *t, addr new_kstack, void (*func)(void *), void *arg) +arch_thread_switch_kstack_and_call(struct thread *t, addr_t new_kstack, void (*func)(void *), void *arg) { i386_switch_stack_and_call(new_kstack, func, arg); } @@ -206,7 +201,7 @@ arch_thread_context_switch(struct thread *t_from, struct thread *t_to) panic("arch_thread_context_switch: bad pgdir 0x%lx\n", new_pgdir); i386_fsave_swap(t_from->arch_info.fpu_state, t_to->arch_info.fpu_state); - i386_context_switch(&t_from->arch_info, &t_to->arch_info, (addr)new_pgdir); + i386_context_switch(&t_from->arch_info, &t_to->arch_info, (addr_t)new_pgdir); } @@ -225,9 +220,9 @@ arch_thread_dump_info(void *info) */ void -arch_thread_enter_uspace(struct thread *t, addr entry, void *args1, void *args2) +arch_thread_enter_uspace(struct thread *t, addr_t entry, void *args1, void *args2) { - addr ustack_top = t->user_stack_base + STACK_SIZE; + addr_t ustack_top = t->user_stack_base + STACK_SIZE; TRACE(("arch_thread_enter_uspace: entry 0x%lx, args %p %p, ustack_top 0x%lx\n", entry, args1, args2, ustack_top)); diff --git a/src/kernel/core/arch/x86/arch_vm.c b/src/kernel/core/arch/x86/arch_vm.c index 0be3257dfe..b03cb1b911 100755 --- a/src/kernel/core/arch/x86/arch_vm.c +++ b/src/kernel/core/arch/x86/arch_vm.c @@ -5,12 +5,9 @@ #include -#include -#include #include #include #include -#include #include #include @@ -18,8 +15,8 @@ #include -#define TRACE_ARCH_VM 0 -#if TRACE_ARCH_VM +#define TRACE_ARCH_VM +#ifdef TRACE_ARCH_VM # define TRACE(x) dprintf x #else # define TRACE(x) ; diff --git a/src/kernel/core/arch/x86/arch_vm_translation_map.c b/src/kernel/core/arch/x86/arch_vm_translation_map.c index 4daec66ada..0769bea681 100755 --- a/src/kernel/core/arch/x86/arch_vm_translation_map.c +++ b/src/kernel/core/arch/x86/arch_vm_translation_map.c @@ -1,27 +1,22 @@ /* +** Copyright 2002-2004, The OpenBeOS Team. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +** ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ -#include -#include -#include #include #include #include #include -#include -#include -#include #include #include -#include -#include #include - -#include #include +#include + #define TRACE_VM_TMAP 0 #if TRACE_VM_TMAP # define TRACE(x) dprintf x @@ -790,27 +785,27 @@ vm_translation_map_module_init2(kernel_args *ka) temp = (void *)kernel_pgdir_virt; vm_create_anonymous_region(vm_get_kernel_aspace_id(), "kernel_pgdir", &temp, - B_EXACT_KERNEL_ADDRESS, PAGE_SIZE, B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); + B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); temp = (void *)paddr_desc; vm_create_anonymous_region(vm_get_kernel_aspace_id(), "physical_page_mapping_descriptors", &temp, - B_EXACT_KERNEL_ADDRESS, ROUNDUP(sizeof(paddr_chunk_desc) * 1024, PAGE_SIZE), + B_EXACT_ADDRESS, ROUNDUP(sizeof(paddr_chunk_desc) * 1024, PAGE_SIZE), B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); temp = (void *)virtual_pmappings; vm_create_anonymous_region(vm_get_kernel_aspace_id(), "iospace_virtual_chunk_descriptors", &temp, - B_EXACT_KERNEL_ADDRESS, ROUNDUP(sizeof(paddr_chunk_desc *) * num_virtual_chunks, PAGE_SIZE), + B_EXACT_ADDRESS, ROUNDUP(sizeof(paddr_chunk_desc *) * num_virtual_chunks, PAGE_SIZE), B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); temp = (void *)iospace_pgtables; vm_create_anonymous_region(vm_get_kernel_aspace_id(), "iospace_pgtables", &temp, - B_EXACT_KERNEL_ADDRESS, PAGE_SIZE * (IOSPACE_SIZE / (PAGE_SIZE * 1024)), + B_EXACT_ADDRESS, B_PAGE_SIZE * (IOSPACE_SIZE / (B_PAGE_SIZE * 1024)), B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); TRACE(("vm_translation_map_module_init2: creating iospace\n")); temp = (void *)IOSPACE_BASE; vm_create_null_region(vm_get_kernel_aspace_id(), "iospace", &temp, - B_EXACT_KERNEL_ADDRESS, IOSPACE_SIZE); + B_EXACT_ADDRESS, IOSPACE_SIZE); TRACE(("vm_translation_map_module_init2: done\n"));