From 5222f12a3258fc1a52606765ce4e729a5af5fc72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sun, 12 Oct 2008 18:13:11 +0000 Subject: [PATCH] - Add m68k pendant of: r27529 & r27778 - handle skipIframes parameter r27530 - allow faults with ints disabled if there is a handler r27648 - call the end-of-interrupt thread callback r27718 - add , not used yet r27722 - register the commpage as image and symbols (but we don't use it yet) - remove dupped call to thread_get_current_thread() - use 16MB iospace for now, 4MB seems too small. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27999 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/system/arch/m68k/asm_defs.h | 17 +++++++++++++ src/system/kernel/arch/m68k/arch_commpage.cpp | 4 +++ src/system/kernel/arch/m68k/arch_cpu.cpp | 5 ++++ src/system/kernel/arch/m68k/arch_debug.cpp | 25 ++++++++++++++++--- src/system/kernel/arch/m68k/arch_int.cpp | 22 +++++++++++++++- .../m68k/arch_vm_translation_map_impl.cpp | 3 ++- 6 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 headers/private/system/arch/m68k/asm_defs.h diff --git a/headers/private/system/arch/m68k/asm_defs.h b/headers/private/system/arch/m68k/asm_defs.h new file mode 100644 index 0000000000..1f89478ec9 --- /dev/null +++ b/headers/private/system/arch/m68k/asm_defs.h @@ -0,0 +1,17 @@ +/* + * Copyright 2008, François Revol, revol@free.fr. + * Distributed under the terms of the MIT License. + */ +#ifndef SYSTEM_ARCH_M68K_ASM_DEFS_H +#define SYSTEM_ARCH_M68K_ASM_DEFS_H + + +#define SYMBOL(name) .global name; name +#define SYMBOL_END(name) 1: .size name, 1b - name +#define STATIC_FUNCTION(name) .type name, @function; name +#define FUNCTION(name) .global name; .type name, @function; name +#define FUNCTION_END(name) 1: .size name, 1b - name + + +#endif /* SYSTEM_ARCH_M68K_ASM_DEFS_H */ + diff --git a/src/system/kernel/arch/m68k/arch_commpage.cpp b/src/system/kernel/arch/m68k/arch_commpage.cpp index 812e89b161..8398d67ff9 100644 --- a/src/system/kernel/arch/m68k/arch_commpage.cpp +++ b/src/system/kernel/arch/m68k/arch_commpage.cpp @@ -11,6 +11,7 @@ #include #include +#include #include @@ -20,6 +21,9 @@ arch_commpage_init(void) { /* no optimized memcpy or anything yet */ /* we don't use it for syscall yet either */ + // add syscall to the commpage image + image_id image = get_commpage_image(); + return B_OK; } diff --git a/src/system/kernel/arch/m68k/arch_cpu.cpp b/src/system/kernel/arch/m68k/arch_cpu.cpp index da7f454931..3a90acced2 100644 --- a/src/system/kernel/arch/m68k/arch_cpu.cpp +++ b/src/system/kernel/arch/m68k/arch_cpu.cpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include extern struct m68k_cpu_ops cpu_ops_030; extern struct m68k_cpu_ops cpu_ops_040; @@ -93,6 +95,9 @@ arch_cpu_init_post_vm(kernel_args *args) status_t arch_cpu_init_post_modules(kernel_args *args) { + // add the functions to the commpage image + image_id image = get_commpage_image(); + return B_OK; } diff --git a/src/system/kernel/arch/m68k/arch_debug.cpp b/src/system/kernel/arch/m68k/arch_debug.cpp index 05da44cd91..0352b22370 100644 --- a/src/system/kernel/arch/m68k/arch_debug.cpp +++ b/src/system/kernel/arch/m68k/arch_debug.cpp @@ -284,18 +284,32 @@ arch_debug_get_caller(void) } +/*! Captures a stack trace (the return addresses) of the current thread. + \param returnAddresses The array the return address shall be written to. + \param maxCount The maximum number of return addresses to be captured. + \param skipIframes The number of interrupt frames that shall be skipped. If + greater than 0, \a skipFrames is ignored. + \param skipFrames The number of stack frames that shall be skipped. + \param userOnly If \c true, only userland return addresses are captured. + \return The number of return addresses written to the given array. +*/ int32 arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, int32 skipIframes, int32 skipFrames, bool userOnly) { -// TODO: Support skipIframes! struct iframe_stack *frameStack; addr_t framePointer; int32 count = 0; int32 i, num = 0, last = 0; - // always skip our own frame - skipFrames++; + // Keep skipping normal stack frames until we've skipped the iframes we're + // supposed to skip. + if (skipIframes > 0) { + skipFrames = INT_MAX; + } else { + // always skip our own frame + skipFrames++; + } struct thread* thread = thread_get_current_thread(); framePointer = (addr_t)get_current_stack_frame(); @@ -323,6 +337,11 @@ arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, if (frame) { ip = frame->cpu.pc; nextFrame = frame->a[6]; + + if (skipIframes > 0) { + if (--skipIframes == 0) + skipFrames = 0; + } } else { if (get_next_frame(framePointer, &nextFrame, &ip) != B_OK) break; diff --git a/src/system/kernel/arch/m68k/arch_int.cpp b/src/system/kernel/arch/m68k/arch_int.cpp index dfa2a87327..c1d05ce919 100644 --- a/src/system/kernel/arch/m68k/arch_int.cpp +++ b/src/system/kernel/arch/m68k/arch_int.cpp @@ -168,6 +168,7 @@ m68k_exception_entry(struct iframe *iframe) { int vector = iframe->cpu.vector >> 2; int ret = B_HANDLED_INTERRUPT; + bool hardwareInterrupt = false; if (vector != -1) { dprintf("m68k_exception_entry: time %lld vector 0x%x, iframe %p, " @@ -193,7 +194,6 @@ m68k_exception_entry(struct iframe *iframe) if (kernelDebugger) { // if this thread has a fault handler, we're allowed to be here - struct thread *thread = thread_get_current_thread(); if (thread && thread->fault_handler != 0) { iframe->cpu.pc = thread->fault_handler; break; @@ -206,6 +206,17 @@ m68k_exception_entry(struct iframe *iframe) (void *)iframe->cpu.pc); break; } else if ((iframe->cpu.sr & SR_IP_MASK) != 0) { + // interrupts disabled + + // If a page fault handler is installed, we're allowed to be here. + // TODO: Now we are generally allowing user_memcpy() with interrupts + // disabled, which in most cases is a bug. We should add some thread + // flag allowing to explicitly indicate that this handling is desired. + if (thread && thread->fault_handler != 0) { + iframe->cpu.pc = thread->fault_handler; + return; + } + // if the interrupts were disabled, and we are not running the // kernel startup the page fault was not allowed to happen and // we must panic @@ -265,6 +276,7 @@ dprintf("handling I/O interrupts...\n"); } #endif dprintf("handling I/O interrupts done\n"); + hardwareInterrupt = true; break; } @@ -288,6 +300,14 @@ dprintf("handling I/O interrupts done\n"); scheduler_reschedule(); RELEASE_THREAD_LOCK(); restore_interrupts(state); + } else if (hardwareInterrupt && thread->post_interrupt_callback != NULL) { + void (*callback)(void*) = thread->post_interrupt_callback; + void* data = thread->post_interrupt_data; + + thread->post_interrupt_callback = NULL; + thread->post_interrupt_data = NULL; + + callback(data); } // pop iframe diff --git a/src/system/kernel/arch/m68k/arch_vm_translation_map_impl.cpp b/src/system/kernel/arch/m68k/arch_vm_translation_map_impl.cpp index 4af4e5635d..aad31b2c46 100644 --- a/src/system/kernel/arch/m68k/arch_vm_translation_map_impl.cpp +++ b/src/system/kernel/arch/m68k/arch_vm_translation_map_impl.cpp @@ -66,7 +66,8 @@ #endif // 4 MB of iospace -#define IOSPACE_SIZE (4*1024*1024) +//#define IOSPACE_SIZE (4*1024*1024) +#define IOSPACE_SIZE (16*1024*1024) // 256K = 2^6*4K #define IOSPACE_CHUNK_SIZE (NUM_PAGEENT_PER_TBL*B_PAGE_SIZE)