diff --git a/headers/private/kernel/arch/m68k/arch_cpu.h b/headers/private/kernel/arch/m68k/arch_cpu.h index 7e9373b7ad..9fded52767 100644 --- a/headers/private/kernel/arch/m68k/arch_cpu.h +++ b/headers/private/kernel/arch/m68k/arch_cpu.h @@ -15,6 +15,9 @@ #define SR_IP_MASK 0x0700 #define SR_S 0x2000 +#define M68K_SR_T_MASK 0xC000 +#define M68K_SR_T0 14 +#define M68K_SR_T1 15 #ifndef _ASSEMBLER diff --git a/headers/private/kernel/arch/m68k/arch_vm.h b/headers/private/kernel/arch/m68k/arch_vm.h index 99f66e3f41..ed129b90b3 100644 --- a/headers/private/kernel/arch/m68k/arch_vm.h +++ b/headers/private/kernel/arch/m68k/arch_vm.h @@ -25,6 +25,7 @@ struct m68k_vm_ops { status_t (*arch_vm_translation_map_early_map)(kernel_args *ka, addr_t virtualAddress, addr_t physicalAddress, uint8 attributes, addr_t (*get_free_page)(kernel_args *)); status_t (*arch_vm_translation_map_early_query)(addr_t va, addr_t *out_physical); + void (*m68k_set_pgdir)(void *); #if 0 /* ppc stuff only ? */ status_t (*m68k_map_address_range)(addr_t virtualAddress, addr_t physicalAddress, size_t size); @@ -33,5 +34,17 @@ struct m68k_vm_ops { #endif }; +#ifdef __cplusplus +extern "C" { +#endif + +extern struct m68k_vm_ops *get_vm_ops(); + +extern void *m68k_translation_map_get_pgdir(vm_translation_map *map); +extern void m68k_set_pgdir(void *rt); + +#ifdef __cplusplus +} +#endif #endif /* ARCH_M68K_VM_H */ diff --git a/src/system/kernel/arch/m68k/arch_030_mmu.cpp b/src/system/kernel/arch/m68k/arch_030_mmu.cpp index 9e155d4d1f..9754212753 100644 --- a/src/system/kernel/arch/m68k/arch_030_mmu.cpp +++ b/src/system/kernel/arch/m68k/arch_030_mmu.cpp @@ -10,12 +10,28 @@ #include -#define ARCH_M68K_MMU_TYPE MMU_68030 +#define ARCH_M68K_MMU_TYPE 68030 #include "arch_vm_translation_map_impl.cpp" +static void +set_pgdir(void *rt) +{ + long_page_directory_entry entry; + *(uint64 *)&entry = DFL_PAGEENT_VAL; + entry.type = DT_ROOT; + entry.addr = TA_TO_PREA(((addr_t)rt)); + + asm volatile( \ + "pmove (%0),%%srp\n" \ + "pmove (%0),%%crp\n" \ + : : "a"((uint64 *)&entry)); + +} + + struct m68k_vm_ops m68030_vm_ops = { - m68k_translation_map_get_pgdir, + _m68k_translation_map_get_pgdir, m68k_vm_translation_map_init_map, m68k_vm_translation_map_init_kernel_map_post_sem, m68k_vm_translation_map_init, @@ -23,6 +39,7 @@ struct m68k_vm_ops m68030_vm_ops = { m68k_vm_translation_map_init_post_sem, m68k_vm_translation_map_early_map, /*m68k_vm_translation_map_*/early_query, + set_pgdir, #if 0 m68k_map_address_range, m68k_unmap_address_range, diff --git a/src/system/kernel/arch/m68k/arch_atomic.c b/src/system/kernel/arch/m68k/arch_atomic.c index 23a30d3292..94a622a3d2 100644 --- a/src/system/kernel/arch/m68k/arch_atomic.c +++ b/src/system/kernel/arch/m68k/arch_atomic.c @@ -19,6 +19,9 @@ * Slow, using spinlocks... */ +#warning M68K: detect 060 here +#if 0 + static spinlock atomic_lock = 0; int64 @@ -241,3 +244,4 @@ access_violation: // XXX kill application return -1; } +#endif diff --git a/src/system/kernel/arch/m68k/arch_commpage.cpp b/src/system/kernel/arch/m68k/arch_commpage.cpp index c9226ca38b..812e89b161 100644 --- a/src/system/kernel/arch/m68k/arch_commpage.cpp +++ b/src/system/kernel/arch/m68k/arch_commpage.cpp @@ -14,18 +14,12 @@ #include -// user syscall assembly stubs -extern "C" void _user_syscall_int(void); -extern unsigned int _user_syscall_int_end; -extern "C" void _user_syscall_sysenter(void); -extern unsigned int _user_syscall_sysenter_end; - status_t arch_commpage_init(void) { - panic("WRITEME"); - return B_NO_INIT; + /* no optimized memcpy or anything yet */ + /* we don't use it for syscall yet either */ return B_OK; } diff --git a/src/system/kernel/arch/m68k/arch_cpu.cpp b/src/system/kernel/arch/m68k/arch_cpu.cpp index c8bab02492..eaf0e996ea 100644 --- a/src/system/kernel/arch/m68k/arch_cpu.cpp +++ b/src/system/kernel/arch/m68k/arch_cpu.cpp @@ -42,6 +42,16 @@ arch_cpu_preboot_init_percpu(kernel_args *args, int curr_cpu) } +status_t +arch_cpu_init_percpu(kernel_args *args, int curr_cpu) +{ + //detect_cpu(curr_cpu); + + // we only support one anyway... + return 0; +} + + status_t arch_cpu_init(kernel_args *args) { diff --git a/src/system/kernel/arch/m68k/arch_thread.c b/src/system/kernel/arch/m68k/arch_thread.c index a8d41e052e..617786c0b6 100644 --- a/src/system/kernel/arch/m68k/arch_thread.c +++ b/src/system/kernel/arch/m68k/arch_thread.c @@ -18,7 +18,9 @@ #include #include #include +#include #include +#include //#include #include @@ -90,6 +92,28 @@ m68k_get_user_iframe(void) } +void * +m68k_next_page_directory(struct thread *from, struct thread *to) +{ + if (from->team->address_space != NULL && to->team->address_space != NULL) { + // they are both user space threads + if (from->team == to->team) { + // dont change the pgdir, same address space + return NULL; + } + // switching to a new address space + return m68k_translation_map_get_pgdir(&to->team->address_space->translation_map); + } else if (from->team->address_space == NULL && to->team->address_space == NULL) { + // they must both be kernel space threads + return NULL; + } else if (to->team->address_space == NULL) { + // the one we're switching to is kernel space + return m68k_translation_map_get_pgdir(&vm_kernel_address_space()->translation_map); + } + + return m68k_translation_map_get_pgdir(&to->team->address_space->translation_map); +} + // #pragma mark - @@ -181,24 +205,17 @@ arch_thread_switch_kstack_and_call(struct thread *t, addr_t newKstack, void -arch_thread_context_switch(struct thread *t_from, struct thread *t_to) +arch_thread_context_switch(struct thread *from, struct thread *to) { -#warning M68K: WRITEME - // 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_base + KERNEL_STACK_SIZE - 8)); + addr_t newPageDirectory; - // 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 - m68k_translation_map_change_asid(&t_to->team->address_space->translation_map); - } - } + newPageDirectory = (addr_t)m68k_next_page_directory(from, to); - m68k_context_switch(&t_from->arch_info.sp, t_to->arch_info.sp); + if ((newPageDirectory % B_PAGE_SIZE) != 0) + panic("arch_thread_context_switch: bad pgdir 0x%lx\n", newPageDirectory); +#warning M68K: export from arch_vm.c + m68k_set_pgdir(newPageDirectory); + m68k_context_switch(&from->arch_info.sp, to->arch_info.sp); } diff --git a/src/system/kernel/arch/m68k/arch_user_debugger.cpp b/src/system/kernel/arch/m68k/arch_user_debugger.cpp index 52b12079ca..a48fc52217 100644 --- a/src/system/kernel/arch/m68k/arch_user_debugger.cpp +++ b/src/system/kernel/arch/m68k/arch_user_debugger.cpp @@ -13,6 +13,7 @@ #include +#warning M68K: WRITEME void arch_clear_team_debug_info(struct arch_team_debug_info *info) { @@ -39,6 +40,28 @@ arch_destroy_thread_debug_info(struct arch_thread_debug_info *info) } +void +arch_update_thread_single_step() +{ + if (struct iframe* frame = m68k_get_user_iframe()) { + struct thread* thread = thread_get_current_thread(); + + // set/clear T1 in SR depending on if single stepping is desired + // T1 T0 + // 0 0 no tracing + // 0 1 trace on flow + // 1 0 single step + // 1 1 undef + if (thread->debug_info.flags & B_THREAD_DEBUG_SINGLE_STEP) { + frame->cpu.sr &= ~(M68K_SR_T_MASK); + frame->cpu.sr |= (1 << M68K_SR_T1); + } else { + frame->cpu.sr &= ~(M68K_SR_T_MASK); + } + } +} + + void arch_set_debug_cpu_state(const struct debug_cpu_state *cpuState) { @@ -78,3 +101,8 @@ arch_clear_watchpoint(void *address) return B_ERROR; } +bool +arch_has_breakpoints(struct arch_team_debug_info *info) +{ + return false; +} diff --git a/src/system/kernel/arch/m68k/arch_vm.cpp b/src/system/kernel/arch/m68k/arch_vm.cpp index 74ea5f0f4e..7a5959934c 100644 --- a/src/system/kernel/arch/m68k/arch_vm.cpp +++ b/src/system/kernel/arch/m68k/arch_vm.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -103,6 +104,8 @@ arch_vm_init_post_modules(kernel_args *args) void arch_vm_aspace_swap(vm_address_space *aspace) { + m68k_set_pgdir(m68k_translation_map_get_pgdir( + &aspace->translation_map)); } diff --git a/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp b/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp index 24badfee0e..f49723ff9c 100644 --- a/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp +++ b/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp @@ -33,7 +33,8 @@ extern struct m68k_vm_ops m68030_vm_ops; //extern struct m68k_vm_ops m68030_vm_ops; //extern struct m68k_vm_ops m68030_vm_ops; -static m68k_vm_ops *get_vm_ops() +#warning M68K: use a static! +m68k_vm_ops *get_vm_ops() { int mmu = arch_mmu_type; @@ -126,6 +127,11 @@ arch_vm_translation_map_early_query(addr_t va, addr_t *out_physical) // #pragma mark - +void +m68k_set_pgdir(void *rt) +{ + return get_vm_ops()->m68k_set_pgdir(rt); +} #if 0 status_t 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 7e7ae56bcb..e2e3e239f3 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 @@ -132,8 +132,9 @@ static status_t put_physical_page_tmap(addr_t va); static void flush_tmap(vm_translation_map *map); +#warning M68K: RENAME static void * -m68k_translation_map_get_pgdir(vm_translation_map *map) +_m68k_translation_map_get_pgdir(vm_translation_map *map) { return map->arch_data->rtdir_phys; } diff --git a/src/system/kernel/arch/ppc/arch_user_debugger.cpp b/src/system/kernel/arch/ppc/arch_user_debugger.cpp index 7cad26e8e9..a724bbf1e0 100644 --- a/src/system/kernel/arch/ppc/arch_user_debugger.cpp +++ b/src/system/kernel/arch/ppc/arch_user_debugger.cpp @@ -36,6 +36,12 @@ arch_destroy_thread_debug_info(struct arch_thread_debug_info *info) } +void +arch_update_thread_single_step() +{ +} + + void arch_set_debug_cpu_state(const struct debug_cpu_state *cpuState) { @@ -75,3 +81,8 @@ arch_clear_watchpoint(void *address) return B_ERROR; } +bool +arch_has_breakpoints(struct arch_team_debug_info *info) +{ + return false; +}