Author: axeld Date: 2009-10-15 17:10:01 +0200 (Thu, 15 Oct 2009) New Revision: 33602 Changeset: http://dev.haiku-os.org/changeset/33602/haiku Added: haiku/trunk/src/system/kernel/arch/ppc/arch_smp.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_system_info.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_thread.cpp haiku/trunk/src/system/kernel/arch/ppc/arch_timer.cpp Removed: haiku/trunk/src/system/kernel/arch/ppc/arch_smp.c haiku/trunk/src/system/kernel/arch/ppc/arch_system_info.c haiku/trunk/src/system/kernel/arch/ppc/arch_thread.c haiku/trunk/src/system/kernel/arch/ppc/arch_timer.c Modified: haiku/trunk/src/system/kernel/arch/ppc/Jamfile Log: * Replaced C with C++ files, should fix BOM's build problem, but will likely introduce new ones I currently cannot check. Modified: haiku/trunk/src/system/kernel/arch/ppc/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/Jamfile 2009-10-15 14:40:58 UTC (rev 33601) +++ haiku/trunk/src/system/kernel/arch/ppc/Jamfile 2009-10-15 15:10:01 UTC (rev 33602) @@ -18,10 +18,10 @@ arch_mmu.cpp arch_platform.cpp arch_real_time_clock.cpp - arch_smp.c - arch_system_info.c - arch_thread.c - arch_timer.c + arch_smp.cpp + arch_system_info.cpp + arch_thread.cpp + arch_timer.cpp arch_user_debugger.cpp arch_vm.cpp arch_vm_translation_map.cpp Copied: haiku/trunk/src/system/kernel/arch/ppc/arch_smp.cpp (from rev 33591, haiku/trunk/src/system/kernel/arch/ppc/arch_smp.c) =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_smp.cpp (rev 0) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_smp.cpp 2009-10-15 15:10:01 UTC (rev 33602) @@ -0,0 +1,40 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include <KernelExport.h> + +#include <boot/stage2.h> +#include <arch/smp.h> +#include <debug.h> + + +status_t +arch_smp_init(kernel_args *args) +{ + return B_OK; +} + + +status_t +arch_smp_per_cpu_init(kernel_args *args, int32 cpu) +{ + return B_OK; +} + + +void +arch_smp_send_ici(int32 target_cpu) +{ + panic("called arch_smp_send_ici!\n"); +} + + +void +arch_smp_send_broadcast_ici() +{ + panic("called arch_smp_send_broadcast_ici\n"); +} + Copied: haiku/trunk/src/system/kernel/arch/ppc/arch_system_info.cpp (from rev 33591, haiku/trunk/src/system/kernel/arch/ppc/arch_system_info.c) =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_system_info.cpp (rev 0) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_system_info.cpp 2009-10-15 15:10:01 UTC (rev 33602) @@ -0,0 +1,99 @@ +/* + * Copyright 2006, Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>. + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include <OS.h> + +#include <arch_cpu.h> +#include <arch/system_info.h> +#include <boot/kernel_args.h> + + +static uint64 sCPUClockFrequency; +static uint64 sBusClockFrequency; +static enum cpu_types sCPUType; +static uint16 sCPURevision; + +struct cpu_model { + uint16 version; + enum cpu_types beos_type; +}; + +// mapping of CPU versions to BeOS enum cpu_types +struct cpu_model kCPUModels[] = { + { MPC601, B_CPU_PPC_601 }, + { MPC603, B_CPU_PPC_603 }, + { MPC604, B_CPU_PPC_604 }, + { MPC602, B_CPU_PPC_603ev }, + { MPC603e, B_CPU_PPC_603e }, + { MPC603ev, B_CPU_PPC_603ev }, + { MPC750, B_CPU_PPC_750 }, + { MPC604ev, B_CPU_PPC_604ev }, + { MPC7400, B_CPU_PPC_7400 }, + { MPC620, B_CPU_PPC_620 }, + { IBM403, B_CPU_PPC_IBM_403 }, + { IBM401A1, B_CPU_PPC_IBM_401A1 }, + { IBM401B2, B_CPU_PPC_IBM_401B2 }, + { IBM401C2, B_CPU_PPC_IBM_401C2 }, + { IBM401D2, B_CPU_PPC_IBM_401D2 }, + { IBM401E2, B_CPU_PPC_IBM_401E2 }, + { IBM401F2, B_CPU_PPC_IBM_401F2 }, + { IBM401G2, B_CPU_PPC_IBM_401G2 }, + { IBMPOWER3, B_CPU_PPC_IBM_POWER3 }, + { MPC860, B_CPU_PPC_860 }, + { MPC8240, B_CPU_PPC_8240 }, + { IBM405GP, B_CPU_PPC_IBM_405GP }, + { IBM405L, B_CPU_PPC_IBM_405L }, + { IBM750FX, B_CPU_PPC_IBM_750FX }, + { MPC7450, B_CPU_PPC_7450 }, + { MPC7455, B_CPU_PPC_7455 }, + { MPC7457, B_CPU_PPC_7457 }, + { MPC7447A, B_CPU_PPC_7447A }, + { MPC7448, B_CPU_PPC_7448 }, + { MPC7410, B_CPU_PPC_7410 }, + { MPC8245, B_CPU_PPC_8245 }, + { 0, B_CPU_PPC_UNKNOWN } +}; + + +status_t +arch_get_system_info(system_info *info, size_t size) +{ + info->cpu_type = sCPUType; + info->cpu_revision = sCPURevision; + + info->cpu_clock_speed = sCPUClockFrequency; + info->bus_clock_speed = sBusClockFrequency; + + info->platform_type = B_MAC_PLATFORM; + + return B_OK; +} + + +status_t +arch_system_info_init(struct kernel_args *args) +{ + int i; + + sCPUClockFrequency = args->arch_args.cpu_frequency; + sBusClockFrequency = args->arch_args.bus_frequency; + + // The PVR (processor version register) contains processor version and + // revision. + uint32 pvr = get_pvr(); + uint16 version = (uint16)(pvr >> 16); + sCPURevision = (uint16)(pvr & 0xffff); + + // translate the version to a BeOS cpu_types constant + sCPUType = B_CPU_PPC_UNKNOWN; + for (i = 0; kCPUModels[i].beos_type != B_CPU_PPC_UNKNOWN; i++) { + if (version == kCPUModels[i].version) { + sCPUType = kCPUModels[i].beos_type; + break; + } + } + + return B_OK; +} Copied: haiku/trunk/src/system/kernel/arch/ppc/arch_thread.cpp (from rev 33591, haiku/trunk/src/system/kernel/arch/ppc/arch_thread.c) =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_thread.cpp (rev 0) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_thread.cpp 2009-10-15 15:10:01 UTC (rev 33602) @@ -0,0 +1,262 @@ +/* + * Copyright 2003-2007, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> + * Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx> + * + * Copyright 2001, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + +#include <arch_thread.h> + +#include <arch_cpu.h> +#include <arch/thread.h> +#include <boot/stage2.h> +#include <kernel.h> +#include <thread.h> +#include <vm_types.h> +//#include <arch/vm_translation_map.h> + +#include <string.h> + +// Valid initial arch_thread state. We just memcpy() it when initializing +// a new thread structure. +static struct arch_thread sInitialState; + +// Helper function for thread creation, defined in arch_asm.S. +extern void ppc_kernel_thread_root(); + +extern void ppc_switch_stack_and_call(addr_t newKstack, void (*func)(void *), + void *arg); + + +void +ppc_push_iframe(struct iframe_stack *stack, struct iframe *frame) +{ + ASSERT(stack->index < IFRAME_TRACE_DEPTH); + stack->frames[stack->index++] = frame; +} + + +void +ppc_pop_iframe(struct iframe_stack *stack) +{ + ASSERT(stack->index > 0); + stack->index--; +} + + +/** Returns the current iframe structure of the running thread. + * This function must only be called in a context where it's actually + * sure that such iframe exists; ie. from syscalls, but usually not + * from standard kernel threads. + */ +static struct iframe * +ppc_get_current_iframe(void) +{ + struct thread *thread = thread_get_current_thread(); + + ASSERT(thread->arch_info.iframes.index >= 0); + return thread->arch_info.iframes.frames[thread->arch_info.iframes.index - 1]; +} + + +/** \brief Returns the current thread's topmost (i.e. most recent) + * userland->kernel transition iframe (usually the first one, save for + * interrupts in signal handlers). + * \return The iframe, or \c NULL, if there is no such iframe (e.g. when + * the thread is a kernel thread). + */ +struct iframe * +ppc_get_user_iframe(void) +{ + struct thread *thread = thread_get_current_thread(); + int i; + + for (i = thread->arch_info.iframes.index - 1; i >= 0; i--) { + struct iframe *frame = thread->arch_info.iframes.frames[i]; + if (frame->srr1 & MSR_PRIVILEGE_LEVEL) + return frame; + } + + return NULL; +} + + +// #pragma mark - + + +status_t +arch_thread_init(struct kernel_args *args) +{ + // Initialize the static initial arch_thread state (sInitialState). + // Currently nothing to do, i.e. zero initialized is just fine. + + return B_OK; +} + + +status_t +arch_team_init_team_struct(struct team *team, bool kernel) +{ + // Nothing to do. The structure is empty. + return B_OK; +} + + +status_t +arch_thread_init_thread_struct(struct thread *thread) +{ + // set up an initial state (stack & fpu) + memcpy(&thread->arch_info, &sInitialState, sizeof(struct arch_thread)); + + return B_OK; +} + + +status_t +arch_thread_init_kthread_stack(struct thread *t, int (*start_func)(void), + void (*entry_func)(void), void (*exit_func)(void)) +{ + addr_t *kstack = (addr_t *)t->kernel_stack_base; + addr_t *kstackTop = (addr_t *)t->kernel_stack_top; + + // clear the kernel stack +#ifdef DEBUG_KERNEL_STACKS +# ifdef STACK_GROWS_DOWNWARDS + memset((void *)((addr_t)kstack + KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE), 0, + KERNEL_STACK_SIZE); +# else + memset(kstack, 0, KERNEL_STACK_SIZE); +# endif +#else + memset(kstack, 0, KERNEL_STACK_SIZE); +#endif + + // space for frame pointer and return address, and stack frames must be + // 16 byte aligned + kstackTop -= 2; + kstackTop = (addr_t*)((addr_t)kstackTop & ~0xf); + + // LR, CR, r2, r13-r31, f13-f31, as pushed by ppc_context_switch() + kstackTop -= 22 + 2 * 19; + + // let LR point to ppc_kernel_thread_root() + kstackTop[0] = (addr_t)&ppc_kernel_thread_root; + + // the arguments of ppc_kernel_thread_root() are the functions to call, + // provided in registers r13-r15 + kstackTop[3] = (addr_t)entry_func; + kstackTop[4] = (addr_t)start_func; + kstackTop[5] = (addr_t)exit_func; + + // save this stack position + t->arch_info.sp = (void *)kstackTop; + + return B_OK; +} + + +status_t +arch_thread_init_tls(struct thread *thread) +{ + // TODO: Implement! + return B_OK; +} + + +void +arch_thread_switch_kstack_and_call(struct thread *t, addr_t newKstack, + void (*func)(void *), void *arg) +{ + ppc_switch_stack_and_call(newKstack, func, arg); +} + + +void +arch_thread_context_switch(struct thread *t_from, struct thread *t_to) +{ + // set the new kernel stack in the EAR register. + // this is used in the exception handler code to decide what kernel stack to + // switch to if the exception had happened when the processor was in user mode + asm("mtear %0" :: "g"(t_to->kernel_stack_top - 8)); + + // switch the asids if we need to + if (t_to->team->address_space != NULL) { + // the target thread has is user space + if (t_from->team != t_to->team) { + // switching to a new address space + ppc_translation_map_change_asid(&t_to->team->address_space->translation_map); + } + } + + ppc_context_switch(&t_from->arch_info.sp, t_to->arch_info.sp); +} + + +void +arch_thread_dump_info(void *info) +{ + struct arch_thread *at = (struct arch_thread *)info; + + dprintf("\tsp: %p\n", at->sp); +} + + +status_t +arch_thread_enter_userspace(struct thread *thread, addr_t entry, void *arg1, void *arg2) +{ + panic("arch_thread_enter_uspace(): not yet implemented\n"); + return B_ERROR; +} + + +bool +arch_on_signal_stack(struct thread *thread) +{ + return false; +} + + +status_t +arch_setup_signal_frame(struct thread *thread, struct sigaction *sa, int sig, int sigMask) +{ + return B_ERROR; +} + + +int64 +arch_restore_signal_frame(void) +{ + return 0; +} + + + +/** Saves everything needed to restore the frame in the child fork in the + * arch_fork_arg structure to be passed to arch_restore_fork_frame(). + * Also makes sure to return the right value. + */ + +void +arch_store_fork_frame(struct arch_fork_arg *arg) +{ +} + + +/** Restores the frame from a forked team as specified by the provided + * arch_fork_arg structure. + * Needs to be called from within the child team, ie. instead of + * arch_thread_enter_uspace() as thread "starter". + * This function does not return to the caller, but will enter userland + * in the child team at the same position where the parent team left of. + */ + +void +arch_restore_fork_frame(struct arch_fork_arg *arg) +{ +} + Copied: haiku/trunk/src/system/kernel/arch/ppc/arch_timer.cpp (from rev 33591, haiku/trunk/src/system/kernel/arch/ppc/arch_timer.c) =================================================================== --- haiku/trunk/src/system/kernel/arch/ppc/arch_timer.cpp (rev 0) +++ haiku/trunk/src/system/kernel/arch/ppc/arch_timer.cpp 2009-10-15 15:10:01 UTC (rev 33602) @@ -0,0 +1,46 @@ +/* +** Copyright 2001, Travis Geiselbrecht. All rights reserved. +** Distributed under the terms of the NewOS License. +*/ + + +#include <boot/stage2.h> +#include <kernel.h> +#include <debug.h> + +#include <timer.h> +#include <arch/timer.h> + + +static bigtime_t sTickRate; + + +void +arch_timer_set_hardware_timer(bigtime_t timeout) +{ + bigtime_t new_val_64; + + if(timeout < 1000) + timeout = 1000; + + new_val_64 = (timeout * sTickRate) / 1000000; + + asm("mtdec %0" :: "r"((uint32)new_val_64)); +} + + +void +arch_timer_clear_hardware_timer() +{ + asm("mtdec %0" :: "r"(0x7fffffff)); +} + + +int +arch_init_timer(kernel_args *ka) +{ + sTickRate = ka->arch_args.time_base_frequency; + + return 0; +} +