From a7c23bb4a92806407b15fef56a5652326c3f8622 Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Sun, 24 Feb 2019 14:20:56 +0100 Subject: [PATCH] kernel/arch/sparc: stubs to get the kernel to link Add empty implementation of timer, elf, vm, debugger support, to let the kernel link. Also add the kernel linker script. Change-Id: If0795fa6554aea3df1ee544c25cc4832634ffd78 Reviewed-on: https://review.haiku-os.org/c/1108 Reviewed-by: waddlesplash --- .../kernel/arch/sparc/arch_thread_types.h | 1 + headers/private/kernel/arch/sparc/types.h | 4 +- headers/private/system/arch/sparc/asm_defs.h | 20 +++ src/system/boot/arch/sparc/Jamfile | 33 ++++ src/system/kernel/arch/sparc/Jamfile | 23 +++ .../kernel/arch/sparc/arch_commpage.cpp | 29 +++ src/system/kernel/arch/sparc/arch_cpu.cpp | 99 ++++++++++ src/system/kernel/arch/sparc/arch_debug.cpp | 106 +++++++++++ .../kernel/arch/sparc/arch_debug_console.cpp | 95 ++++++++++ src/system/kernel/arch/sparc/arch_elf.cpp | 99 ++++++++++ src/system/kernel/arch/sparc/arch_int.cpp | 56 ++++++ .../kernel/arch/sparc/arch_platform.cpp | 27 +++ .../arch/sparc/arch_real_time_clock.cpp | 37 ++++ src/system/kernel/arch/sparc/arch_smp.cpp | 58 ++++++ .../kernel/arch/sparc/arch_system_info.cpp | 35 ++++ src/system/kernel/arch/sparc/arch_thread.cpp | 170 ++++++++++++++++++ src/system/kernel/arch/sparc/arch_timer.cpp | 40 +++++ .../kernel/arch/sparc/arch_user_debugger.cpp | 95 ++++++++++ src/system/kernel/arch/sparc/arch_vm.cpp | 122 +++++++++++++ .../arch/sparc/arch_vm_translation_map.cpp | 100 +++++++++++ src/system/kernel/lib/arch/sparc/Jamfile | 27 +++ src/system/ldscripts/sparc/kernel.ld | 60 +++++++ src/system/libroot/posix/arch/sparc/Jamfile | 26 +++ .../libroot/posix/arch/sparc/siglongjmp.S | 20 +++ .../libroot/posix/arch/sparc/sigsetjmp.S | 13 ++ 25 files changed, 1393 insertions(+), 2 deletions(-) create mode 100644 headers/private/system/arch/sparc/asm_defs.h create mode 100644 src/system/boot/arch/sparc/Jamfile create mode 100644 src/system/kernel/arch/sparc/Jamfile create mode 100644 src/system/kernel/arch/sparc/arch_commpage.cpp create mode 100644 src/system/kernel/arch/sparc/arch_cpu.cpp create mode 100644 src/system/kernel/arch/sparc/arch_debug.cpp create mode 100644 src/system/kernel/arch/sparc/arch_debug_console.cpp create mode 100644 src/system/kernel/arch/sparc/arch_elf.cpp create mode 100644 src/system/kernel/arch/sparc/arch_int.cpp create mode 100644 src/system/kernel/arch/sparc/arch_platform.cpp create mode 100644 src/system/kernel/arch/sparc/arch_real_time_clock.cpp create mode 100644 src/system/kernel/arch/sparc/arch_smp.cpp create mode 100644 src/system/kernel/arch/sparc/arch_system_info.cpp create mode 100644 src/system/kernel/arch/sparc/arch_thread.cpp create mode 100644 src/system/kernel/arch/sparc/arch_timer.cpp create mode 100644 src/system/kernel/arch/sparc/arch_user_debugger.cpp create mode 100644 src/system/kernel/arch/sparc/arch_vm.cpp create mode 100644 src/system/kernel/arch/sparc/arch_vm_translation_map.cpp create mode 100644 src/system/kernel/lib/arch/sparc/Jamfile create mode 100644 src/system/ldscripts/sparc/kernel.ld create mode 100644 src/system/libroot/posix/arch/sparc/Jamfile create mode 100644 src/system/libroot/posix/arch/sparc/siglongjmp.S create mode 100644 src/system/libroot/posix/arch/sparc/sigsetjmp.S diff --git a/headers/private/kernel/arch/sparc/arch_thread_types.h b/headers/private/kernel/arch/sparc/arch_thread_types.h index c3bb584291..dae90803d2 100644 --- a/headers/private/kernel/arch/sparc/arch_thread_types.h +++ b/headers/private/kernel/arch/sparc/arch_thread_types.h @@ -8,6 +8,7 @@ #include +#include #define IFRAME_TRACE_DEPTH 4 diff --git a/headers/private/kernel/arch/sparc/types.h b/headers/private/kernel/arch/sparc/types.h index 0277bdd368..52764846f9 100644 --- a/headers/private/kernel/arch/sparc/types.h +++ b/headers/private/kernel/arch/sparc/types.h @@ -2,8 +2,8 @@ ** Copyright 2001, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ -#ifndef _ALPHA_TYPES_H -#define _ALPHA_TYPES_H +#ifndef _SPARC_TYPES_H +#define _SPARC_TYPES_H typedef unsigned long uint64; typedef long int64; diff --git a/headers/private/system/arch/sparc/asm_defs.h b/headers/private/system/arch/sparc/asm_defs.h new file mode 100644 index 0000000000..7f2b542153 --- /dev/null +++ b/headers/private/system/arch/sparc/asm_defs.h @@ -0,0 +1,20 @@ +/* + * Copyright 2008, François Revol, revol@free.fr. + * Distributed under the terms of the MIT License. + */ +#ifndef SYSTEM_ARCH_SPARC_ASM_DEFS_H +#define SYSTEM_ARCH_SPARC_ASM_DEFS_H + + +/* include arch version helpers */ +//#include + +#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_SPARC_ASM_DEFS_H */ + + diff --git a/src/system/boot/arch/sparc/Jamfile b/src/system/boot/arch/sparc/Jamfile new file mode 100644 index 0000000000..0ff3a31120 --- /dev/null +++ b/src/system/boot/arch/sparc/Jamfile @@ -0,0 +1,33 @@ +SubDir HAIKU_TOP src system boot arch sparc ; + +{ + local defines = _BOOT_MODE ; + + defines = [ FDefines $(defines) ] ; + SubDirCcFlags $(defines) ; + SubDirC++Flags $(defines) -fno-rtti ; +} + + +local kernelLibArchObjects = + byteorder.o + memcpy.o + memset.o +; + +BootMergeObject boot_arch_$(TARGET_KERNEL_ARCH).o : + debug_uart_8250.cpp + #arch_uart_8250.cpp + arch_elf.cpp + : # additional flags + : + $(kernelArchObjects) + $(kernelLibArchObjects) +; + +SEARCH on [ FGristFiles arch_elf.cpp arch_uart_8250.cpp ] + = [ FDirName $(HAIKU_TOP) src system kernel arch $(TARGET_KERNEL_ARCH) ] ; + +SEARCH on [ FGristFiles debug_uart_8250.cpp ] + = [ FDirName $(HAIKU_TOP) src system kernel arch generic ] ; + diff --git a/src/system/kernel/arch/sparc/Jamfile b/src/system/kernel/arch/sparc/Jamfile new file mode 100644 index 0000000000..f98db03143 --- /dev/null +++ b/src/system/kernel/arch/sparc/Jamfile @@ -0,0 +1,23 @@ +SubDir HAIKU_TOP src system kernel arch sparc ; + +KernelMergeObject kernel_arch_sparc.o : + arch_asm.S + arch_commpage.cpp + arch_cpu.cpp + arch_debug.cpp + arch_debug_console.cpp + arch_elf.cpp + arch_int.cpp + arch_platform.cpp + arch_real_time_clock.cpp + arch_smp.cpp + arch_system_info.cpp + arch_timer.cpp + arch_thread.cpp + arch_user_debugger.cpp + arch_vm.cpp + arch_vm_translation_map.cpp + : + $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + : +; diff --git a/src/system/kernel/arch/sparc/arch_commpage.cpp b/src/system/kernel/arch/sparc/arch_commpage.cpp new file mode 100644 index 0000000000..b7378611ab --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_commpage.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2007, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include + +#include + +#include + +#include +#include +#include + + +status_t +arch_commpage_init(void) +{ + return B_OK; +} + + +status_t +arch_commpage_init_post_cpus(void) +{ + return B_OK; +} + diff --git a/src/system/kernel/arch/sparc/arch_cpu.cpp b/src/system/kernel/arch/sparc/arch_cpu.cpp new file mode 100644 index 0000000000..c8fa731a13 --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_cpu.cpp @@ -0,0 +1,99 @@ +/* + * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include +#include +#include + + +status_t +arch_cpu_preboot_init_percpu(kernel_args *args, int curr_cpu) +{ + return B_OK; +} + + +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) +{ + return B_OK; +} + + +status_t +arch_cpu_init_post_vm(kernel_args *args) +{ + return B_OK; +} + + +status_t +arch_cpu_init_post_modules(kernel_args *args) +{ + return B_OK; +} + + +void +arch_cpu_sync_icache(void *address, size_t len) +{ +} + + +void +arch_cpu_memory_read_barrier(void) +{ +} + + +void +arch_cpu_memory_write_barrier(void) +{ +} + + +void +arch_cpu_invalidate_TLB_range(addr_t start, addr_t end) +{ +} + + +void +arch_cpu_invalidate_TLB_list(addr_t pages[], int num_pages) +{ +} + + +void +arch_cpu_global_TLB_invalidate(void) +{ +} + + +void +arch_cpu_user_TLB_invalidate(void) +{ +} + + +status_t +arch_cpu_shutdown(bool reboot) +{ + return B_ERROR; +} diff --git a/src/system/kernel/arch/sparc/arch_debug.cpp b/src/system/kernel/arch/sparc/arch_debug.cpp new file mode 100644 index 0000000000..495c9abf0e --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_debug.cpp @@ -0,0 +1,106 @@ +/* + * Copyright 2019, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Adrien Destugues + */ + + +#include + + +void +arch_debug_stack_trace(void) +{ +} + + +bool +arch_debug_contains_call(Thread *thread, const char *symbol, + addr_t start, addr_t end) +{ + return false; +} + + +void * +arch_debug_get_caller(void) +{ + return NULL; +} + + +void +arch_debug_save_registers(struct arch_debug_registers* registers) +{ +} + + +void +arch_debug_call_with_fault_handler(cpu_ent* cpu, jmp_buf jumpBuffer, + void (*function)(void*), void* parameter) +{ +} + + +bool +arch_is_debug_variable_defined(const char* variableName) +{ + // TODO: Implement! + return false; +} + + +status_t +arch_set_debug_variable(const char* variableName, uint64 value) +{ + // TODO: Implement! + return B_ENTRY_NOT_FOUND; +} + + +status_t +arch_get_debug_variable(const char* variableName, uint64* value) +{ + // TODO: Implement! + return B_ENTRY_NOT_FOUND; +} + + +int32 +arch_debug_get_stack_trace(addr_t* returnAddresses, int32 maxCount, + int32 skipIframes, int32 skipFrames, uint32 flags) +{ + return 0; +} + + +ssize_t +arch_debug_gdb_get_registers(char* buffer, size_t bufferSize) +{ + // TODO: Implement! + return B_NOT_SUPPORTED; +} + + +void* +arch_debug_get_interrupt_pc(bool* _isSyscall) +{ + // TODO: Implement! + return NULL; +} + + +status_t +arch_debug_init(kernel_args *args) +{ +#if 0 + add_debugger_command("where", &stack_trace, "Same as \"sc\""); + add_debugger_command("bt", &stack_trace, "Same as \"sc\" (as in gdb)"); + add_debugger_command("sc", &stack_trace, "Stack crawl for current thread"); +#endif + + return B_NO_ERROR; +} + diff --git a/src/system/kernel/arch/sparc/arch_debug_console.cpp b/src/system/kernel/arch/sparc/arch_debug_console.cpp new file mode 100644 index 0000000000..32eaa295fe --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_debug_console.cpp @@ -0,0 +1,95 @@ +/* + * Copyright 2003-2006, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + * + * Copyright 2001, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + + +#include +#include +#include +#include + +#include + + +void +arch_debug_remove_interrupt_handler(uint32 line) +{ +} + + +void +arch_debug_install_interrupt_handlers(void) +{ +} + + +int +arch_debug_blue_screen_try_getchar(void) +{ + return 0; +} + + +char +arch_debug_blue_screen_getchar(void) +{ + return 0; +} + + +int +arch_debug_serial_try_getchar(void) +{ + // TODO: Implement correctly! + return arch_debug_serial_getchar(); +} + + +char +arch_debug_serial_getchar(void) +{ + return 0; +} + + +void +arch_debug_serial_putchar(const char c) +{ +} + + +void +arch_debug_serial_puts(const char *s) +{ + while (*s != '\0') { + arch_debug_serial_putchar(*s); + s++; + } +} + + +void +arch_debug_serial_early_boot_message(const char *string) +{ + // this function will only be called in fatal situations +} + + +status_t +arch_debug_console_init(kernel_args *args) +{ + return B_OK; +} + + +status_t +arch_debug_console_init_settings(kernel_args *args) +{ + return B_OK; +} + + diff --git a/src/system/kernel/arch/sparc/arch_elf.cpp b/src/system/kernel/arch/sparc/arch_elf.cpp new file mode 100644 index 0000000000..452f9d80fe --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_elf.cpp @@ -0,0 +1,99 @@ +/* + * Copyright 2019, Adrien Destugues + * Copyright 2010, Ithamar R. Adema + * Copyright 2009, Johannes Wischert, johanneswi@gmail.com. + * Copyright 2005, Ingo Weinhold . + * Copyright 2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include + + +//#define TRACE_ARCH_ELF +#ifdef TRACE_ARCH_ELF +# define TRACE(x) dprintf x +# define CHATTY 1 +#else +# define TRACE(x) ; +# define CHATTY 0 +#endif + + +#ifndef _BOOT_MODE +static bool +is_in_image(struct elf_image_info *image, addr_t address) +{ + return (address >= image->text_region.start + && address < image->text_region.start + image->text_region.size) + || (address >= image->data_region.start + && address < image->data_region.start + image->data_region.size); +} +#endif // !_BOOT_MODE + + +int +arch_elf_relocate_rel(struct elf_image_info *image, + struct elf_image_info *resolve_image, Elf64_Rel *rel, int rel_len) +{ + // there are no rel entries in M68K elf + return B_NO_ERROR; +} + + +static inline void +write_32(addr_t P, Elf32_Word value) +{ + *(Elf32_Word*)P = value; +} + + +static inline void +write_16(addr_t P, Elf32_Word value) +{ + // bits 16:29 + *(Elf32_Half*)P = (Elf32_Half)value; +} + + +static inline bool +write_16_check(addr_t P, Elf32_Word value) +{ + // bits 15:0 + if ((value & 0xffff0000) && (~value & 0xffff8000)) + return false; + *(Elf32_Half*)P = (Elf32_Half)value; + return true; +} + + +static inline bool +write_8(addr_t P, Elf32_Word value) +{ + // bits 7:0 + *(uint8 *)P = (uint8)value; + return true; +} + + +static inline bool +write_8_check(addr_t P, Elf32_Word value) +{ + // bits 7:0 + if ((value & 0xffffff00) && (~value & 0xffffff80)) + return false; + *(uint8 *)P = (uint8)value; + return true; +} + + +int +arch_elf_relocate_rela(struct elf_image_info *image, + struct elf_image_info *resolve_image, Elf64_Rela *rel, int rel_len) +{ + return B_OK; +} diff --git a/src/system/kernel/arch/sparc/arch_int.cpp b/src/system/kernel/arch/sparc/arch_int.cpp new file mode 100644 index 0000000000..885044d2aa --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_int.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2003-2011, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Adrien Destugues, pulkomandy@pulkomandy.tk + */ + + +#include + + +status_t +arch_int_init(kernel_args *args) +{ + return B_OK; +} + + +status_t +arch_int_init_post_vm(kernel_args *args) +{ + return B_OK; +} + + +status_t +arch_int_init_post_device_manager(struct kernel_args *args) +{ + return B_OK; +} + + +status_t +arch_int_init_io(kernel_args* args) +{ + return B_OK; +} + + +void +arch_int_enable_io_interrupt(int irq) +{ +} + + +void +arch_int_disable_io_interrupt(int irq) +{ +} + + +void +arch_int_assign_to_cpu(int32 irq, int32 cpu) +{ +} diff --git a/src/system/kernel/arch/sparc/arch_platform.cpp b/src/system/kernel/arch/sparc/arch_platform.cpp new file mode 100644 index 0000000000..30a2394057 --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_platform.cpp @@ -0,0 +1,27 @@ +/* Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk. + * Distributed under the terms of the MIT License. + */ + + +#include + + +status_t +arch_platform_init(struct kernel_args *kernelArgs) +{ + return B_OK; +} + + +status_t +arch_platform_init_post_vm(struct kernel_args *kernelArgs) +{ + return B_OK; +} + + +status_t +arch_platform_init_post_thread(struct kernel_args *kernelArgs) +{ + return B_OK; +} diff --git a/src/system/kernel/arch/sparc/arch_real_time_clock.cpp b/src/system/kernel/arch/sparc/arch_real_time_clock.cpp new file mode 100644 index 0000000000..937b58d595 --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_real_time_clock.cpp @@ -0,0 +1,37 @@ +#include + +#include +#include + + +status_t +arch_rtc_init(kernel_args *args, struct real_time_data *data) +{ + return B_OK; +} + + +uint32 +arch_rtc_get_hw_time(void) +{ + return 0; +} + + +void +arch_rtc_set_hw_time(uint32 seconds) +{ +} + + +void +arch_rtc_set_system_time_offset(struct real_time_data *data, bigtime_t offset) +{ +} + + +bigtime_t +arch_rtc_get_system_time_offset(struct real_time_data *data) +{ + return 0; +} diff --git a/src/system/kernel/arch/sparc/arch_smp.cpp b/src/system/kernel/arch/sparc/arch_smp.cpp new file mode 100644 index 0000000000..5971139e11 --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_smp.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2007, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * François Revol + * + * Copyright 2004, Axel Dörfler, axeld@pinc-software.de + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include +#include +#include + + +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_multicast_ici(CPUSet& cpuSet) +{ +#if KDEBUG + if (are_interrupts_enabled()) + panic("arch_smp_send_multicast_ici: called with interrupts enabled"); +#endif +} + + +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"); +} + + diff --git a/src/system/kernel/arch/sparc/arch_system_info.cpp b/src/system/kernel/arch/sparc/arch_system_info.cpp new file mode 100644 index 0000000000..97905d62e9 --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_system_info.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2007, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * François Revol + * + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include + +#include +#include +#include + + +static uint64 sCPUClockFrequency; +static uint64 sBusClockFrequency; +static uint16 sCPURevision; + + +void +arch_fill_topology_node(cpu_topology_node_info* node, int32 cpu) +{ +} + + +status_t +arch_system_info_init(struct kernel_args *args) +{ + return B_OK; +} + diff --git a/src/system/kernel/arch/sparc/arch_thread.cpp b/src/system/kernel/arch/sparc/arch_thread.cpp new file mode 100644 index 0000000000..2cc0009bfe --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_thread.cpp @@ -0,0 +1,170 @@ +/* Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include +#include +#include +#include +#include + + +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(Team *team, bool kernel) +{ + // Nothing to do. The structure is empty. + return B_OK; +} + + +status_t +arch_thread_init_thread_struct(Thread *thread) +{ + // set up an initial state (stack & fpu) + //memcpy(&thread->arch_info, &sInitialState, sizeof(struct arch_thread)); + + return B_OK; +} + + +void +arch_thread_init_kthread_stack(Thread* thread, void* _stack, void* _stackTop, + void (*function)(void*), const void* data) +{ +#if 0 + addr_t *kstack = (addr_t *)t->kernel_stack_base; + addr_t *kstackTop = (addr_t *)t->kernel_stack_base; + + // 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 m68k_context_switch() + kstackTop -= 22 + 2 * 19; + + // let LR point to m68k_kernel_thread_root() + kstackTop[0] = (addr_t)&m68k_kernel_thread_root; + + // the arguments of m68k_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; +#else + panic("arch_thread_init_kthread_stack(): Implement me!"); +#endif +} + + +status_t +arch_thread_init_tls(Thread *thread) +{ + // TODO: Implement! + return B_OK; +} + + +void +arch_thread_context_switch(Thread *from, Thread *to) +{ +} + + +void +arch_thread_dump_info(void *info) +{ +} + + +status_t +arch_thread_enter_userspace(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(Thread *thread) +{ + return false; +} + + +status_t +arch_setup_signal_frame(Thread *thread, struct sigaction *sa, + struct signal_frame_data *signalFrameData) +{ + return B_ERROR; +} + + +int64 +arch_restore_signal_frame(struct signal_frame_data* signalFrameData) +{ + return 0; +} + + +void +arch_check_syscall_restart(Thread *thread) +{ +} + + +/** 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) +{ +} + diff --git a/src/system/kernel/arch/sparc/arch_timer.cpp b/src/system/kernel/arch/sparc/arch_timer.cpp new file mode 100644 index 0000000000..edda9d3031 --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_timer.cpp @@ -0,0 +1,40 @@ +/* + * Copyright 2019, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Adrien Destugues + */ + + +#include +#include +#include +#include + + +void +arch_timer_set_hardware_timer(bigtime_t timeout) +{ +} + + +void +arch_timer_clear_hardware_timer() +{ +} + + +int +arch_init_timer(kernel_args *args) +{ + return B_OK; +} + + +bigtime_t +system_time(void) +{ + // TODO + return 0; +} diff --git a/src/system/kernel/arch/sparc/arch_user_debugger.cpp b/src/system/kernel/arch/sparc/arch_user_debugger.cpp new file mode 100644 index 0000000000..08023893e8 --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_user_debugger.cpp @@ -0,0 +1,95 @@ +/* + * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include + + +void +arch_clear_team_debug_info(struct arch_team_debug_info *info) +{ +} + + +void +arch_destroy_team_debug_info(struct arch_team_debug_info *info) +{ + arch_clear_team_debug_info(info); +} + + +void +arch_clear_thread_debug_info(struct arch_thread_debug_info *info) +{ +} + + +void +arch_destroy_thread_debug_info(struct arch_thread_debug_info *info) +{ + arch_clear_thread_debug_info(info); +} + + +void +arch_update_thread_single_step() +{ +} + + +void +arch_set_debug_cpu_state(const debug_cpu_state *cpuState) +{ +} + + +void +arch_get_debug_cpu_state(debug_cpu_state *cpuState) +{ +} + + +status_t +arch_get_thread_debug_cpu_state(Thread* thread, debug_cpu_state* cpuState) +{ + return B_UNSUPPORTED; +} + + +status_t +arch_set_breakpoint(void *address) +{ + return B_ERROR; +} + + +status_t +arch_clear_breakpoint(void *address) +{ + return B_ERROR; +} + + +status_t +arch_set_watchpoint(void *address, uint32 type, int32 length) +{ + return B_ERROR; +} + + +status_t +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/sparc/arch_vm.cpp b/src/system/kernel/arch/sparc/arch_vm.cpp new file mode 100644 index 0000000000..5aa8636c06 --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_vm.cpp @@ -0,0 +1,122 @@ +/* + * Copyright 2001, Travis Geiselbrecht. All rights reserved. + * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include + + +//#define TRACE_ARCH_VM +#ifdef TRACE_ARCH_VM +# define TRACE(x) dprintf x +#else +# define TRACE(x) ; +#endif + + +status_t +arch_vm_init(kernel_args *args) +{ + return B_OK; +} + + +status_t +arch_vm_init_post_area(kernel_args *args) +{ + return B_OK; +} + + +status_t +arch_vm_init_post_modules(kernel_args *args) +{ + return B_OK; +} + + +status_t +arch_vm_init_end(kernel_args *args) +{ + TRACE(("arch_vm_init_end(): %lu virtual ranges to keep:\n", + args->arch_args.num_virtual_ranges_to_keep)); + + for (int i = 0; i < (int)args->arch_args.num_virtual_ranges_to_keep; i++) { + addr_range &range = args->arch_args.virtual_ranges_to_keep[i]; + + TRACE((" start: %p, size: 0x%lx\n", (void*)range.start, range.size)); + +#if 0 + // skip ranges outside the kernel address space + if (!IS_KERNEL_ADDRESS(range.start)) { + TRACE((" no kernel address, skipping...\n")); + continue; + } + + phys_addr_t physicalAddress; + void *address = (void*)range.start; + if (vm_get_page_mapping(VMAddressSpace::KernelID(), range.start, + &physicalAddress) != B_OK) + panic("arch_vm_init_end(): No page mapping for %p\n", address); + area_id area = vm_map_physical_memory(VMAddressSpace::KernelID(), + "boot loader reserved area", &address, + B_EXACT_ADDRESS, range.size, + B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, + physicalAddress, true); + if (area < 0) { + panic("arch_vm_init_end(): Failed to create area for boot loader " + "reserved area: %p - %p\n", (void*)range.start, + (void*)(range.start + range.size)); + } +#endif + } + +#if 0 + // Throw away any address space mappings we've inherited from the boot + // loader and have not yet turned into an area. + vm_free_unused_boot_loader_range(0, 0xffffffff - B_PAGE_SIZE + 1); +#endif + + return B_OK; +} + + +void +arch_vm_aspace_swap(struct VMAddressSpace *from, struct VMAddressSpace *to) +{ + // This functions is only invoked when a userland thread is in the process + // of dying. It switches to the kernel team and does whatever cleanup is + // necessary (in case it is the team's main thread, it will delete the + // team). + // It is however not necessary to change the page directory. Userland team's + // page directories include all kernel mappings as well. Furthermore our + // arch specific translation map data objects are ref-counted, so they won't + // go away as long as they are still used on any CPU. +} + + +bool +arch_vm_supports_protection(uint32 protection) +{ + return true; +} + + +void +arch_vm_unset_memory_type(VMArea *area) +{ +} + + +status_t +arch_vm_set_memory_type(VMArea *area, addr_t physicalBase, uint32 type) +{ + if (type == 0) + return B_OK; + + return B_ERROR; +} diff --git a/src/system/kernel/arch/sparc/arch_vm_translation_map.cpp b/src/system/kernel/arch/sparc/arch_vm_translation_map.cpp new file mode 100644 index 0000000000..afb42677a2 --- /dev/null +++ b/src/system/kernel/arch/sparc/arch_vm_translation_map.cpp @@ -0,0 +1,100 @@ +/* + * Copyright 2007-2010, François Revol, revol@free.fr. + * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk. + * Distributed under the terms of the MIT License. + * + * Copyright 2001, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + + +#include +#include +#include +#include +#include + + +#define TRACE_VM_TMAP +#ifdef TRACE_VM_TMAP +# define TRACE(x...) dprintf(x) +#else +# define TRACE(x...) ; +#endif + + +status_t +arch_vm_translation_map_init(kernel_args *args, + VMPhysicalPageMapper** _physicalPageMapper) +{ + TRACE("vm_translation_map_init: entry\n"); + +#ifdef TRACE_VM_TMAP + TRACE("physical memory ranges:\n"); + for (uint32 i = 0; i < args->num_physical_memory_ranges; i++) { + phys_addr_t start = args->physical_memory_range[i].start; + phys_addr_t end = start + args->physical_memory_range[i].size; + TRACE(" %#10" B_PRIxPHYSADDR " - %#10" B_PRIxPHYSADDR "\n", start, + end); + } + + TRACE("allocated physical ranges:\n"); + for (uint32 i = 0; i < args->num_physical_allocated_ranges; i++) { + phys_addr_t start = args->physical_allocated_range[i].start; + phys_addr_t end = start + args->physical_allocated_range[i].size; + TRACE(" %#10" B_PRIxPHYSADDR " - %#10" B_PRIxPHYSADDR "\n", start, + end); + } + + TRACE("allocated virtual ranges:\n"); + for (uint32 i = 0; i < args->num_virtual_allocated_ranges; i++) { + addr_t start = args->virtual_allocated_range[i].start; + addr_t end = start + args->virtual_allocated_range[i].size; + TRACE(" %#10" B_PRIxADDR " - %#10" B_PRIxADDR "\n", start, end); + } +#endif + + return B_OK; +} + + +status_t +arch_vm_translation_map_init_post_sem(kernel_args *args) +{ + return B_OK; +} + + +status_t +arch_vm_translation_map_init_post_area(kernel_args *args) +{ + TRACE("vm_translation_map_init_post_area: entry\n"); + return B_OK; +} + + +status_t +arch_vm_translation_map_early_map(kernel_args *args, addr_t va, phys_addr_t pa, + uint8 attributes, phys_addr_t (*get_free_page)(kernel_args *)) +{ + TRACE("early_tmap: entry pa 0x%lx va 0x%lx\n", pa, va); + return B_OK; +} + + +status_t +arch_vm_translation_map_create_map(bool kernel, VMTranslationMap** _map) +{ + return B_OK; +} + + +bool +arch_vm_translation_map_is_kernel_page_accessible(addr_t virtualAddress, + uint32 protection) +{ + return false; +} + diff --git a/src/system/kernel/lib/arch/sparc/Jamfile b/src/system/kernel/lib/arch/sparc/Jamfile new file mode 100644 index 0000000000..93c51fa330 --- /dev/null +++ b/src/system/kernel/lib/arch/sparc/Jamfile @@ -0,0 +1,27 @@ +SubDir HAIKU_TOP src system kernel lib arch sparc ; + +SEARCH_SOURCE += [ FDirName $(librootSources) os arch generic ] ; + +local librootSources = [ FDirName $(HAIKU_TOP) src system libroot ] ; +local posixSources = [ FDirName $(librootSources) posix ] ; + +SEARCH_SOURCE += [ FDirName $(librootSources) os arch $(TARGET_ARCH) ] ; +SEARCH_SOURCE += [ FDirName $(librootSources) os arch generic ] ; + +KernelMergeObject kernel_os_arch_$(TARGET_ARCH).o : + generic_system_time_nsecs.cpp + : $(TARGET_KERNEL_PIC_CCFLAGS) +; + +SEARCH_SOURCE += [ FDirName $(posixSources) arch $(TARGET_ARCH) ] ; +SEARCH_SOURCE += [ FDirName $(posixSources) string arch generic ] ; +SEARCH_SOURCE += [ FDirName $(posixSources) string arch $(TARGET_ARCH) ] ; + +KernelMergeObject kernel_lib_posix_arch_$(TARGET_ARCH).o : + siglongjmp.S + sigsetjmp.S + + memcpy.c + memset.c + : $(TARGET_KERNEL_PIC_CCFLAGS) +; diff --git a/src/system/ldscripts/sparc/kernel.ld b/src/system/ldscripts/sparc/kernel.ld new file mode 100644 index 0000000000..07866a664c --- /dev/null +++ b/src/system/ldscripts/sparc/kernel.ld @@ -0,0 +1,60 @@ +OUTPUT_FORMAT("elf64-sparc") +OUTPUT_ARCH(sparc:v9) + +ENTRY(_start) +SECTIONS +{ + . = 0xFFFFFFFF80000000 + SIZEOF_HEADERS; + + .interp : { *(.interp) } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) } + .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) } + .rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) } + .rela.got : { *(.rela.got) } + .rela.ctors : { *(.rela.ctors) } + .rela.dtors : { *(.rela.dtors) } + .rela.init : { *(.rela.init) } + .rela.fini : { *(.rela.fini) } + .rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) } + .rela.plt : { *(.rela.plt) } + .init : { *(.init) } =0x90909090 + .plt : { *(.plt) } + + /* text/read-only data */ + .text : { *(.text .text.* .gnu.linkonce.t.*) } =0x90909090 + + .rodata : { *(.rodata) } + + . = ALIGN(0x8); + altcodepatch_begin = .; + .altcodepatch : { *(.altcodepatch) } + altcodepatch_end = .; + + /* writable data */ + . = ALIGN(0x1000); + __data_start = .; + .data : { *(.data .gnu.linkonce.d.*) } + + . = ALIGN(0x4); + __ctor_list = .; + .ctors : { *(.ctors) } + __ctor_end = .; + __dtor_list = .; + .dtors : { *(.dtors) } + __dtor_end = .; + .got : { *(.got.plt) *(.got) } + .dynamic : { *(.dynamic) } + + /* uninitialized data (in same segment as writable data) */ + __bss_start = .; + .bss : { *(.bss) } + + . = ALIGN(0x1000); + _end = . ; + + /* Strip unnecessary stuff */ + /DISCARD/ : { *(.comment .note .eh_frame) } +} diff --git a/src/system/libroot/posix/arch/sparc/Jamfile b/src/system/libroot/posix/arch/sparc/Jamfile new file mode 100644 index 0000000000..591da4d161 --- /dev/null +++ b/src/system/libroot/posix/arch/sparc/Jamfile @@ -0,0 +1,26 @@ +SubDir HAIKU_TOP src system libroot posix arch sparc ; + +local architectureObject ; +for architectureObject in [ MultiArchSubDirSetup sparc ] { + on $(architectureObject) { + local architecture = $(TARGET_PACKAGING_ARCH) ; + + UsePrivateSystemHeaders ; + + local genericSources = + setjmp_save_sigs.c + longjmp_return.c + ; + + MergeObject <$(architecture)>posix_arch_$(TARGET_ARCH).o : + sigsetjmp.S + siglongjmp.S + + $(genericSources) + ; + + SEARCH on [ FGristFiles $(genericSources) ] + = [ FDirName $(SUBDIR) $(DOTDOT) generic ] ; + } +} + diff --git a/src/system/libroot/posix/arch/sparc/siglongjmp.S b/src/system/libroot/posix/arch/sparc/siglongjmp.S new file mode 100644 index 0000000000..a2f3b962d7 --- /dev/null +++ b/src/system/libroot/posix/arch/sparc/siglongjmp.S @@ -0,0 +1,20 @@ +/* + * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk + * Distributed under the terms of the Haiku License. + */ + + +#include + + +/* int __siglongjmp(jmp_buf buffer, int value) */ +FUNCTION(siglongjmp): +FUNCTION(longjmp): +FUNCTION(_longjmp): + ret +FUNCTION_END(siglongjmp) +FUNCTION_END(longjmp) +FUNCTION_END(_longjmp) + +#pragma weak longjmp=siglongjmp + diff --git a/src/system/libroot/posix/arch/sparc/sigsetjmp.S b/src/system/libroot/posix/arch/sparc/sigsetjmp.S new file mode 100644 index 0000000000..594f881460 --- /dev/null +++ b/src/system/libroot/posix/arch/sparc/sigsetjmp.S @@ -0,0 +1,13 @@ +/* Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk. + * Distributed under the terms of the MIT License. + */ + + +#include + + +/* int setjmp(jmp_buf buffer) */ +FUNCTION(setjmp): +FUNCTION(_setjmp): + ret +FUNCTION_END(setjmp)