From 5629675a326ecf2ff3fd23f154beb525c171048d Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 17 Feb 2019 13:42:25 +0100 Subject: [PATCH] sparc: add defines and minimum set of required files Gets the stage0 bootstrap to run. Imlementation is probably nonsense at this point. Change-Id: I10876efbb54314b864c0ad951152757cdb2fd366 Reviewed-on: https://review.haiku-os.org/c/1061 Reviewed-by: waddlesplash --- build/jam/ArchitectureRules | 8 ++ build/jam/repositories/HaikuPorts/sparc | 0 build/jam/repositories/HaikuPortsCross/sparc | 72 ++++++++++ configure | 5 +- docs/develop/packages/FileFormat.rst | 1 + headers/config/HaikuConfig.h | 7 + headers/os/arch/sparc/arch_debugger.h | 15 ++ headers/os/kernel/debugger.h | 3 + headers/posix/arch/sparc64/arch_setjmp.h | 11 ++ headers/posix/arch/sparc64/signal.h | 55 +++++++ .../private/kernel/arch/sparc/arch_atomic.h | 103 +++++++++++++ headers/private/kernel/arch/sparc/arch_cpu.h | 52 +++++++ .../private/kernel/arch/sparc/arch_debug.h | 0 headers/private/kernel/arch/sparc/arch_int.h | 18 +++ .../private/kernel/arch/sparc/arch_kernel.h | 34 +++++ .../kernel/arch/sparc/arch_kernel_args.h | 37 +++++ .../kernel/arch/sparc/arch_system_info.h | 13 ++ .../private/kernel/arch/sparc/arch_thread.h | 47 ++++++ .../kernel/arch/sparc/arch_thread_types.h | 44 ++++++ .../kernel/arch/sparc/arch_user_debugger.h | 19 +++ headers/private/kernel/arch/sparc/arch_vm.h | 17 +++ .../arch/sparc/arch_vm_translation_map.h | 0 .../private/kernel/arch/sparc/arch_vm_types.h | 0 .../system/arch/sparc/arch_commpage_defs.h | 0 .../private/system/arch/sparc/arch_config.h | 0 headers/private/system/arch/sparc/arch_elf.h | 0 .../system/arch/sparc/arch_real_time_data.h | 21 +++ src/data/package_infos/sparc/haiku | 135 ++++++++++++++++++ .../debug/arch/sparc/arch_debug_support.cpp | 52 +++++++ .../platform/openfirmware/arch/sparc/Jamfile | 15 ++ src/system/glue/arch/sparc/Jamfile | 21 +++ src/system/glue/arch/sparc/crti.S | 29 ++++ src/system/glue/arch/sparc/crtn.S | 15 ++ src/system/libroot/os/arch/sparc/Jamfile | 22 +++ src/system/libroot/os/arch/sparc/tls.c | 53 +++++++ .../gensyscalls/arch/sparc/arch_gensyscalls.h | 2 + 36 files changed, 925 insertions(+), 1 deletion(-) create mode 100644 build/jam/repositories/HaikuPorts/sparc create mode 100644 build/jam/repositories/HaikuPortsCross/sparc create mode 100644 headers/os/arch/sparc/arch_debugger.h create mode 100644 headers/posix/arch/sparc64/arch_setjmp.h create mode 100644 headers/posix/arch/sparc64/signal.h create mode 100644 headers/private/kernel/arch/sparc/arch_atomic.h create mode 100644 headers/private/kernel/arch/sparc/arch_cpu.h create mode 100644 headers/private/kernel/arch/sparc/arch_debug.h create mode 100644 headers/private/kernel/arch/sparc/arch_int.h create mode 100644 headers/private/kernel/arch/sparc/arch_kernel.h create mode 100644 headers/private/kernel/arch/sparc/arch_kernel_args.h create mode 100644 headers/private/kernel/arch/sparc/arch_system_info.h create mode 100644 headers/private/kernel/arch/sparc/arch_thread.h create mode 100644 headers/private/kernel/arch/sparc/arch_thread_types.h create mode 100644 headers/private/kernel/arch/sparc/arch_user_debugger.h create mode 100644 headers/private/kernel/arch/sparc/arch_vm.h create mode 100644 headers/private/kernel/arch/sparc/arch_vm_translation_map.h create mode 100644 headers/private/kernel/arch/sparc/arch_vm_types.h create mode 100644 headers/private/system/arch/sparc/arch_commpage_defs.h create mode 100644 headers/private/system/arch/sparc/arch_config.h create mode 100644 headers/private/system/arch/sparc/arch_elf.h create mode 100644 headers/private/system/arch/sparc/arch_real_time_data.h create mode 100644 src/data/package_infos/sparc/haiku create mode 100644 src/kits/debug/arch/sparc/arch_debug_support.cpp create mode 100644 src/system/boot/platform/openfirmware/arch/sparc/Jamfile create mode 100644 src/system/glue/arch/sparc/Jamfile create mode 100644 src/system/glue/arch/sparc/crti.S create mode 100644 src/system/glue/arch/sparc/crtn.S create mode 100644 src/system/libroot/os/arch/sparc/Jamfile create mode 100644 src/system/libroot/os/arch/sparc/tls.c create mode 100644 src/tools/gensyscalls/arch/sparc/arch_gensyscalls.h diff --git a/build/jam/ArchitectureRules b/build/jam/ArchitectureRules index 54809c2d8c..ce36276b3c 100644 --- a/build/jam/ArchitectureRules +++ b/build/jam/ArchitectureRules @@ -243,6 +243,14 @@ rule KernelArchitectureSetup architecture # offset in floppy image (>= sizeof(haiku_loader)) HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 384 ; # in kB + case sparc : + HAIKU_KERNEL_PLATFORM ?= openfirmware ; + HAIKU_BOOT_TARGETS += openfirmware ; + + HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB + # offset in floppy image (>= sizeof(haiku_loader)) + HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 384 ; # in kB + case arm : HAIKU_KERNEL_PLATFORM ?= u-boot ; HAIKU_BOOT_TARGETS += u-boot ; diff --git a/build/jam/repositories/HaikuPorts/sparc b/build/jam/repositories/HaikuPorts/sparc new file mode 100644 index 0000000000..e69de29bb2 diff --git a/build/jam/repositories/HaikuPortsCross/sparc b/build/jam/repositories/HaikuPortsCross/sparc new file mode 100644 index 0000000000..7339ab2229 --- /dev/null +++ b/build/jam/repositories/HaikuPortsCross/sparc @@ -0,0 +1,72 @@ +BootstrapPackageRepository HaikuPortsCross + : sparc + : + # architecture "any" packages + haikuporter-0-1 + noto-20170202-7 + : + # repository architecture packages (stage 0) + gcc_bootstrap-7.3.0_2018_05_01-1 + gcc_bootstrap_syslibs-7.3.0_2018_05_01-1 + gcc_bootstrap_syslibs_devel-7.3.0_2018_05_01-1 + + : + # repository architecture packages (stage 1) + bash_bootstrap-4.4.012-1 + binutils_bootstrap-2.28.1_2017_08_05-1 + bison_bootstrap-3.0.4-5 + coreutils_bootstrap-8.22-1 + curl_bootstrap-7.40.0-1 + curl_bootstrap_devel-7.40.0-1 + expat_bootstrap-2.1.0-1 + expat_bootstrap_devel-2.1.0-1 + findutils_bootstrap-4.6.0-1 + flex_bootstrap-2.5.35-1 + freetype_bootstrap-2.6.3-1 + freetype_bootstrap_devel-2.6.3-1 + gawk_bootstrap-3.1.8-2 + grep_bootstrap-2.14-1 + icu_bootstrap-57.1-2 + icu_bootstrap_devel-57.1-2 + less_bootstrap-451-1 + m4_bootstrap-1.4.16-1 + make_bootstrap-4.1-2 + ncurses6_bootstrap-6.0-1 + ncurses6_bootstrap_devel-6.0-1 + python_bootstrap-2.7.6-1 + sed_bootstrap-4.2.1-1 + texinfo_bootstrap-4.13a-1 + zlib_bootstrap-1.2.11-1 + zlib_bootstrap_devel-1.2.11-1 + + : + # repository architecture packages (stage 2) + libsolv_bootstrap-0.3.0_haiku_2014_12_22-1 + libsolv_bootstrap_devel-0.3.0_haiku_2014_12_22-1 + + : + # source packages + bash_bootstrap + binutils_bootstrap + bison_bootstrap + coreutils_bootstrap + curl_bootstrap + expat_bootstrap + findutils_bootstrap + flex_bootstrap + freetype_bootstrap + gawk_bootstrap + gcc_bootstrap + grep_bootstrap + less_bootstrap + libsolv_bootstrap + m4_bootstrap + make_bootstrap + ncurses6_bootstrap + python_bootstrap + sed_bootstrap + texinfo_bootstrap + zlib_bootstrap + : + # debuginfo packages + ; diff --git a/configure b/configure index 2eefb7d502..4667dae2d4 100755 --- a/configure +++ b/configure @@ -33,7 +33,7 @@ options: variables will be set accordingly. specifies the target architecture, either "x86_gcc2", "x86", "x86_64", "ppc", "m68k", - "arm", "arm64", "riscv32", "riscv64" + "arm", "arm64", "riscv32", "riscv64", "sparc" This option and --cross-tools-prefix can be specified multiple times. The first cross tools specify the primary tools, the subsequent ones the @@ -273,6 +273,7 @@ standard_gcc_settings() powerpc-*) targetCpu=ppc;; riscv32-*) targetCpu=riscv32;; riscv64-*) targetCpu=riscv64;; + sparc64-*) targetCpu=sparc;; x86_64-*) targetCpu=x86_64;; *) echo "Unsupported gcc target machine: $gccMachine" >&2 @@ -682,6 +683,7 @@ while [ $# -gt 0 ] ; do arm) targetMachine=arm-unknown-haiku;; riscv32) targetMachine=riscv32-unknown-haiku;; riscv64) targetMachine=riscv64-unknown-haiku;; + sparc) targetMachine=sparc64-unknown-haiku;; *) echo "Unsupported target architecture: $targetArch" >&2 exit 1 @@ -742,6 +744,7 @@ while [ $# -gt 0 ] ; do arm64) targetMachine=arm64-unknown-haiku;; riscv32) targetMachine=riscv32-unknown-haiku;; riscv64) targetMachine=riscv64-unknown-haiku;; + sparc) targetMachine=sparc64-unknown-haiku;; *) echo "Unsupported target architecture: $2" >&2 exit 1 diff --git a/docs/develop/packages/FileFormat.rst b/docs/develop/packages/FileFormat.rst index 6d02dd8600..f0b66e2509 100644 --- a/docs/develop/packages/FileFormat.rst +++ b/docs/develop/packages/FileFormat.rst @@ -620,6 +620,7 @@ B_HPKG_ATTRIBUTE_ID_PACKAGE_ARCHITECTURE ("package:architecture") 5 B_PACKAGE_ARCHITECTURE_PPC PowerPC 6 B_PACKAGE_ARCHITECTURE_ARM ARM 7 B_PACKAGE_ARCHITECTURE_M68K m68k + 8 B_PACKAGE_ARCHITECTURE_SPARC sparc = =============================== ========================================= :Child Attributes: none diff --git a/headers/config/HaikuConfig.h b/headers/config/HaikuConfig.h index 7006ffcf2a..632636dfed 100644 --- a/headers/config/HaikuConfig.h +++ b/headers/config/HaikuConfig.h @@ -71,6 +71,13 @@ # define __HAIKU_ARCH_ABI "riscv64" # define __HAIKU_ARCH_RISCV32 1 # define __HAIKU_ARCH_BITS 64 +#elif defined(__sparc64__) +# define __HAIKU_ARCH sparc64 +# define __HAIKU_ARCH_ABI "sparc" +# define __HAIKU_ARCH_SPARC 1 +# define __HAIKU_ARCH_PHYSICAL_BITS 64 +# define __HAIKU_BIG_ENDIAN 1 +# define __HAIKU_ARCH_BITS 64 #else # error Unsupported architecture! #endif diff --git a/headers/os/arch/sparc/arch_debugger.h b/headers/os/arch/sparc/arch_debugger.h new file mode 100644 index 0000000000..eaa14c0df9 --- /dev/null +++ b/headers/os/arch/sparc/arch_debugger.h @@ -0,0 +1,15 @@ +/* + * Copyright 2005-2019, Haiku Inc. + * Distributed under the terms of the MIT License. + */ +#ifndef _ARCH_SPARC_DEBUGGER_H +#define _ARCH_SPARC_DEBUGGER_H + + +struct sparc_debug_cpu_state { + uint32 dummy; +} __attribute__((aligned(8))); + + +#endif // _ARCH_SPARC_DEBUGGER_H + diff --git a/headers/os/kernel/debugger.h b/headers/os/kernel/debugger.h index 5e1082f268..569a5d13ab 100644 --- a/headers/os/kernel/debugger.h +++ b/headers/os/kernel/debugger.h @@ -18,6 +18,7 @@ #include #include #include +#include #if defined(__x86_64__) @@ -32,6 +33,8 @@ typedef struct mipsel_debug_cpu_state debug_cpu_state; #elif defined(__arm__) typedef struct arm_debug_cpu_state debug_cpu_state; +#elif defined(__sparc64__) + typedef struct sparc_debug_cpu_state debug_cpu_state; #else #error unsupported architecture #endif diff --git a/headers/posix/arch/sparc64/arch_setjmp.h b/headers/posix/arch/sparc64/arch_setjmp.h new file mode 100644 index 0000000000..0384d66c38 --- /dev/null +++ b/headers/posix/arch/sparc64/arch_setjmp.h @@ -0,0 +1,11 @@ +/* + * Copyright 2019 Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _ARCH_SETJMP_H_ +#define _ARCH_SETJMP_H_ + +// FIXME determine size +typedef unsigned long __jmp_buf[1]; + +#endif /* _ARCH_SETJMP_H_ */ diff --git a/headers/posix/arch/sparc64/signal.h b/headers/posix/arch/sparc64/signal.h new file mode 100644 index 0000000000..8f5a4dbc07 --- /dev/null +++ b/headers/posix/arch/sparc64/signal.h @@ -0,0 +1,55 @@ +/* + * Copyright 2019 Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _ARCH_SIGNAL_H_ +#define _ARCH_SIGNAL_H_ + + +/* + * Architecture-specific structure passed to signal handlers + */ + +#if __sparc64__ + +struct vregs +{ + // ulong g0; // always 0, so no need to save + ulong g1; + ulong g2; + ulong g3; + ulong g4; + ulong g5; + ulong g6; + ulong g7; + ulong o0; + ulong o1; + ulong o2; + ulong o3; + ulong o4; + ulong o5; + ulong sp; + ulong o7; + ulong l0; + ulong l1; + ulong l2; + ulong l3; + ulong l4; + ulong l5; + ulong l6; + ulong l7; + ulong i0; + ulong i1; + ulong i2; + ulong i3; + ulong i4; + ulong i5; + ulong fp; + ulong i7; + // TODO: sparc: Fix floats in vregs +}; + + +#endif /* __sparc64__ */ + +#endif /* _ARCH_SIGNAL_H_ */ diff --git a/headers/private/kernel/arch/sparc/arch_atomic.h b/headers/private/kernel/arch/sparc/arch_atomic.h new file mode 100644 index 0000000000..8ddbb554c2 --- /dev/null +++ b/headers/private/kernel/arch/sparc/arch_atomic.h @@ -0,0 +1,103 @@ +/* + * Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org. + * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck IV + */ +#ifndef _KERNEL_ARCH_SPARC_ATOMIC_H +#define _KERNEL_ARCH_SPARC_ATOMIC_H + + +static inline void +memory_read_barrier_inline(void) +{ + // TODO +} + + +static inline void +memory_write_barrier_inline(void) +{ + // TODO +} + + +static inline void +memory_full_barrier_inline(void) +{ + // TODO +} + + +#define memory_read_barrier memory_read_barrier_inline +#define memory_write_barrier memory_write_barrier_inline +#define memory_full_barrier memory_full_barrier_inline + + +static inline void +atomic_set_inline(int32* value, int32 newValue) +{ + memory_write_barrier(); + *(volatile int32*)value = newValue; +} + + +static inline int32 +atomic_get_and_set_inline(int32* value, int32 newValue) +{ + // BIG TODO: PowerPC Atomic get and set +// asm volatile("xchgl %0, (%1)" +// : "+r" (newValue) +// : "r" (value) +// : "memory"); + return newValue; +} + + +static inline int32 +atomic_test_and_set_inline(int32* value, int32 newValue, int32 testAgainst) +{ + // BIG TODO: PowerPC Atomic test and set inline +// asm volatile("lock; cmpxchgl %2, (%3)" +// : "=a" (newValue) +// : "0" (testAgainst), "r" (newValue), "r" (value) +// : "memory"); + return newValue; +} + + +static inline int32 +atomic_add_inline(int32* value, int32 newValue) +{ + // BIG TODO: PowerPC Atomic add inline +// asm volatile("lock; xaddl %0, (%1)" +// : "+r" (newValue) +// : "r" (value) +// : "memory"); + return newValue; +} + + +static inline int32 +atomic_get_inline(int32* value) +{ + int32 newValue = *(volatile int32*)value; + memory_read_barrier(); + return newValue; +} + + +#define atomic_set atomic_set_inline +#define atomic_get_and_set atomic_get_and_set_inline +#ifndef atomic_test_and_set +# define atomic_test_and_set atomic_test_and_set_inline +#endif +#ifndef atomic_add +# define atomic_add atomic_add_inline +#endif +#define atomic_get atomic_get_inline + + +#endif // _KERNEL_ARCH_PPC_ATOMIC_H + diff --git a/headers/private/kernel/arch/sparc/arch_cpu.h b/headers/private/kernel/arch/sparc/arch_cpu.h new file mode 100644 index 0000000000..750a46c0ff --- /dev/null +++ b/headers/private/kernel/arch/sparc/arch_cpu.h @@ -0,0 +1,52 @@ +/* + * Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_SPARC_CPU_H +#define _KERNEL_ARCH_SPARC_CPU_H + + +#include +#include +#include + + +#define CPU_MAX_CACHE_LEVEL 8 +#define CACHE_LINE_SIZE 128 + // 128 Byte lines on PPC970 + + +#define set_ac() +#define clear_ac() + + +typedef struct arch_cpu_info { + int null; +} arch_cpu_info; + + +#ifdef __cplusplus +extern "C" { +#endif + + +static inline void +arch_cpu_pause(void) +{ + // TODO: CPU pause +} + + +static inline void +arch_cpu_idle(void) +{ + // TODO: CPU idle call +} + + +#ifdef __cplusplus +} +#endif + +#endif /* _KERNEL_ARCH_SPARC_CPU_H */ diff --git a/headers/private/kernel/arch/sparc/arch_debug.h b/headers/private/kernel/arch/sparc/arch_debug.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/headers/private/kernel/arch/sparc/arch_int.h b/headers/private/kernel/arch/sparc/arch_int.h new file mode 100644 index 0000000000..d59e0eb684 --- /dev/null +++ b/headers/private/kernel/arch/sparc/arch_int.h @@ -0,0 +1,18 @@ +/* + * Copyright 2005-2019, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel Dörfler + * Ingo Weinhold + * Adrien Destugues + */ +#ifndef _KERNEL_ARCH_SPARC_INT_H +#define _KERNEL_ARCH_SPARC_INT_H + +#include + +#define NUM_IO_VECTORS 256 + + +#endif /* _KERNEL_ARCH_SPARC_INT_H */ diff --git a/headers/private/kernel/arch/sparc/arch_kernel.h b/headers/private/kernel/arch/sparc/arch_kernel.h new file mode 100644 index 0000000000..25d49ae0d2 --- /dev/null +++ b/headers/private/kernel/arch/sparc/arch_kernel.h @@ -0,0 +1,34 @@ +/* +** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. +** Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk +** Distributed under the terms of the MIT License. +*/ +#ifndef _KERNEL_ARCH_SPARC_KERNEL_H +#define _KERNEL_ARCH_SPARC_KERNEL_H + +#include + +// memory layout +#define KERNEL_BASE 0x80000000 +#define KERNEL_SIZE 0x80000000 +#define KERNEL_TOP (KERNEL_BASE + (KERNEL_SIZE - 1)) + +/* +** User space layout is a little special: +** The user space does not completely cover the space not covered by the kernel. +** This is accomplished by starting user space at 1Mb and running to 64kb short of kernel space. +** The lower 1Mb reserved spot makes it easy to find null pointer references and guarantees a +** region wont be placed there. The 64kb region assures a user space thread cannot pass +** a buffer into the kernel as part of a syscall that would cross into kernel space. +*/ +#define USER_BASE 0x100000 +#define USER_BASE_ANY USER_BASE +#define USER_SIZE (0x80000000 - (0x10000 + 0x100000)) +#define USER_TOP (USER_BASE + (USER_SIZE - 1)) + +#define KERNEL_USER_DATA_BASE 0x60000000 +#define USER_STACK_REGION 0x70000000 +#define USER_STACK_REGION_SIZE ((USER_TOP - USER_STACK_REGION) + 1) + +#endif /* _KERNEL_ARCH_SPARC_KERNEL_H */ + diff --git a/headers/private/kernel/arch/sparc/arch_kernel_args.h b/headers/private/kernel/arch/sparc/arch_kernel_args.h new file mode 100644 index 0000000000..5a381015a5 --- /dev/null +++ b/headers/private/kernel/arch/sparc/arch_kernel_args.h @@ -0,0 +1,37 @@ +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk. All rights reserved. +** Distributed under the terms of the MIT License. +*/ +#ifndef KERNEL_ARCH_SPARC_KERNEL_ARGS_H +#define KERNEL_ARCH_SPARC_KERNEL_ARGS_H + +#ifndef KERNEL_BOOT_KERNEL_ARGS_H +# error This file is included from only +#endif + +#define _PACKED __attribute__((packed)) + +#define MAX_VIRTUAL_RANGES_TO_KEEP 32 + +// kernel args +typedef struct { + // architecture specific + uint64 cpu_frequency; + uint64 bus_frequency; + uint64 time_base_frequency; + + addr_range framebuffer; // maps where the framebuffer is located, in physical memory + int screen_x, screen_y, screen_depth; + + // The virtual ranges we want to keep in the kernel. E.g. those belonging + // to the Open Firmware. + uint32 num_virtual_ranges_to_keep; + addr_range virtual_ranges_to_keep[MAX_VIRTUAL_RANGES_TO_KEEP]; + + // platform type we booted from + int platform; +} arch_kernel_args; + +#endif /* KERNEL_ARCH_SPARC_KERNEL_ARGS_H */ + diff --git a/headers/private/kernel/arch/sparc/arch_system_info.h b/headers/private/kernel/arch/sparc/arch_system_info.h new file mode 100644 index 0000000000..23d2ba56ab --- /dev/null +++ b/headers/private/kernel/arch/sparc/arch_system_info.h @@ -0,0 +1,13 @@ +/* + * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_SPARC_SYSTEM_INFO_H +#define _KERNEL_ARCH_SPARC_SYSTEM_INFO_H + + +/* nothing to be seen here yet */ + + +#endif /* _KRENEL_ARCH_SPARC_SYSTEM_INFO_H */ + diff --git a/headers/private/kernel/arch/sparc/arch_thread.h b/headers/private/kernel/arch/sparc/arch_thread.h new file mode 100644 index 0000000000..bf98ef6687 --- /dev/null +++ b/headers/private/kernel/arch/sparc/arch_thread.h @@ -0,0 +1,47 @@ +/* + * Copyright 2003-2019, Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel Dörfler + * Ingo Weinhold + * Adrien Destugues + */ +#ifndef _KERNEL_ARCH_SPARC_THREAD_H +#define _KERNEL_ARCH_SPARC_THREAD_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void ppc_push_iframe(struct iframe_stack *stack, struct iframe *frame); +void ppc_pop_iframe(struct iframe_stack *stack); +struct iframe *ppc_get_user_iframe(void); + + +static inline Thread * +arch_thread_get_current_thread(void) +{ + Thread *t; + //asm volatile("mfsprg2 %0" : "=r"(t)); + t = NULL; + return t; +} + + +static inline void +arch_thread_set_current_thread(Thread *t) +{ + //asm volatile("mtsprg2 %0" : : "r"(t)); +} + + +#ifdef __cplusplus +} +#endif + + +#endif /* _KERNEL_ARCH_SPARC_THREAD_H */ + diff --git a/headers/private/kernel/arch/sparc/arch_thread_types.h b/headers/private/kernel/arch/sparc/arch_thread_types.h new file mode 100644 index 0000000000..c3bb584291 --- /dev/null +++ b/headers/private/kernel/arch/sparc/arch_thread_types.h @@ -0,0 +1,44 @@ +/* +** Copyright 2001, Travis Geiselbrecht. All rights reserved. +** Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk +** Distributed under the terms of the MIT License. +*/ +#ifndef KERNEL_ARCH_SPARC_THREAD_TYPES_H +#define KERNEL_ARCH_SPARC_THREAD_TYPES_H + + +#include + + +#define IFRAME_TRACE_DEPTH 4 + +struct iframe_stack { + struct iframe *frames[IFRAME_TRACE_DEPTH]; + int32 index; +}; + +// architecture specific thread info +struct arch_thread { + void *sp; // stack pointer + void *interrupt_stack; + + // used to track interrupts on this thread + struct iframe_stack iframes; +}; + +struct arch_team { + // gcc treats empty structures as zero-length in C, but as if they contain + // a char in C++. So we have to put a dummy in to be able to use the struct + // from both in a consistent way. + char dummy; +}; + +struct arch_fork_arg { + // gcc treats empty structures as zero-length in C, but as if they contain + // a char in C++. So we have to put a dummy in to be able to use the struct + // from both in a consistent way. + char dummy; +}; + +#endif /* KERNEL_ARCH_SPARC_THREAD_TYPES_H */ + diff --git a/headers/private/kernel/arch/sparc/arch_user_debugger.h b/headers/private/kernel/arch/sparc/arch_user_debugger.h new file mode 100644 index 0000000000..e9917aa8c7 --- /dev/null +++ b/headers/private/kernel/arch/sparc/arch_user_debugger.h @@ -0,0 +1,19 @@ +/* + * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_SPARC_USER_DEBUGGER_H +#define _KERNEL_ARCH_SPARC_USER_DEBUGGER_H + + +struct arch_team_debug_info { + uint32 dummy; +}; + +struct arch_thread_debug_info { + uint32 dummy; +}; + +#endif // _KERNEL_ARCH_SPARC_USER_DEBUGGER_H + diff --git a/headers/private/kernel/arch/sparc/arch_vm.h b/headers/private/kernel/arch/sparc/arch_vm.h new file mode 100644 index 0000000000..2621cdf67e --- /dev/null +++ b/headers/private/kernel/arch/sparc/arch_vm.h @@ -0,0 +1,17 @@ +/* + * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2091, Adrien Destugues, pulkomandy@pulkomandy.tk. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef ARCH_SPARC_VM_H +#define ARCH_SPARC_VM_H + +/* This many pages will be read/written on I/O if possible */ + +#define NUM_IO_PAGES 4 + /* 16 kB */ + +#define PAGE_SHIFT 12 + +#endif /* ARCH_SPARC_VM_H */ + diff --git a/headers/private/kernel/arch/sparc/arch_vm_translation_map.h b/headers/private/kernel/arch/sparc/arch_vm_translation_map.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/headers/private/kernel/arch/sparc/arch_vm_types.h b/headers/private/kernel/arch/sparc/arch_vm_types.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/headers/private/system/arch/sparc/arch_commpage_defs.h b/headers/private/system/arch/sparc/arch_commpage_defs.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/headers/private/system/arch/sparc/arch_config.h b/headers/private/system/arch/sparc/arch_config.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/headers/private/system/arch/sparc/arch_elf.h b/headers/private/system/arch/sparc/arch_elf.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/headers/private/system/arch/sparc/arch_real_time_data.h b/headers/private/system/arch/sparc/arch_real_time_data.h new file mode 100644 index 0000000000..4d63960eed --- /dev/null +++ b/headers/private/system/arch/sparc/arch_real_time_data.h @@ -0,0 +1,21 @@ +/* + * Copyright 2018 Haiku Inc. All Rights Reserved. + * Copyright 2006, Ingo Weinhold . + * Copyright 2019, Adrien Destugues . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_REAL_TIME_DATA_H +#define _KERNEL_ARCH_REAL_TIME_DATA_H + +#include +#include + + +struct arch_real_time_data { + bigtime_t system_time_offset; + uint32 system_time_conversion_factor; + uint32 _padding; +}; + +#endif /* _KERNEL_ARCH_REAL_TIME_DATA_H */ + diff --git a/src/data/package_infos/sparc/haiku b/src/data/package_infos/sparc/haiku new file mode 100644 index 0000000000..49a53a8055 --- /dev/null +++ b/src/data/package_infos/sparc/haiku @@ -0,0 +1,135 @@ +name haiku +version %HAIKU_VERSION% +architecture sparc +summary "The Haiku base system" + +description "The Haiku base system includes all system core software, like +boot loader, kernel, the system libraries, servers, and applications." + +packager "The Haiku build system" +vendor "Haiku Project" + +copyrights "2001-2019 Haiku, Inc. et al" +licenses { + MIT + "GNU LGPL v2.1" +} +flags system_package + +provides { + haiku=%HAIKU_VERSION% compat>=R1~beta1 + cmd:arp + cmd:chop + cmd:clear + cmd:compress + cmd:df + cmd:ftp + cmd:ftpd + cmd:hd + cmd:hey + cmd:login + cmd:more + cmd:passwd + cmd:ping + cmd:ping6 + cmd:prio + cmd:ps + cmd:renice + cmd:resattr + cmd:su + cmd:telnet + cmd:telnetd + cmd:top + cmd:tput + cmd:traceroute + cmd:trash + cmd:unchop + cmd:useradd + cmd:watch + cmd:xres +} + +requires { + coreutils + cmd:sh +#ifdef HAIKU_REGULAR_BUILD + cmd:bunzip2 + cmd:gunzip + cmd:tar + cmd:unzip +#endif + lib:libfreetype +#ifdef HAIKU_BUILD_FEATURE_SPARC_FONTCONFIG_ENABLED + lib:libfontconfig +#endif + lib:libgcc_s + lib:libicudata >= 57 + lib:libicui18n >= 57 + lib:libicuio >= 57 + lib:libicule >= 57 + lib:libiculx >= 57 + lib:libicutest >= 57 + lib:libicutu >= 57 + lib:libicuuc >= 57 + lib:libncurses >= 6.0 +#ifdef HAIKU_REGULAR_BUILD +#ifdef HAIKU_BUILD_FEATURE_SPARC_EXPAT_ENABLED + lib:libexpat +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_GUTENPRINT_ENABLED + lib:libgutenprint +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_LIBICNS_ENABLED + lib:libicns +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_JASPER_ENABLED + lib:libjasper +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_JPEG_ENABLED + lib:libjpeg +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_LIBPNG_ENABLED + lib:libpng >= 16.0 +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_TIFF_ENABLED + lib:libtiff >= 5.2 +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_LIBWEBP_ENABLED + lib:libwebp +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_ILMBASE_ENABLED + lib:libhalf + lib:libiex + lib:libiexmath + lib:libilmthread + lib:libimath +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_OPENEXR_ENABLED + lib:libilmimf + lib:libilmimfutil +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_OPENSSL_ENABLED + lib:libssl >= 1.0.0 + lib:libcrypto >= 1.0.0 +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_FFMPEG_ENABLED + lib:libavcodec >= 58 + lib:libavfilter >= 7 + lib:libavformat >= 58 + lib:libavutil >= 56 + lib:libswresample >= 3 +#endif +#ifdef HAIKU_BUILD_FEATURE_SPARC_ZSTD_ENABLED + lib:libzstd >= 1 +#endif +#endif + lib:libsolv + lib:libsolvext + lib:libstdc++ + lib:libsupc++ + lib:libz + noto +#ifdef HAIKU_REGULAR_BUILD + noto_sans_cjk_jp +#endif +} diff --git a/src/kits/debug/arch/sparc/arch_debug_support.cpp b/src/kits/debug/arch/sparc/arch_debug_support.cpp new file mode 100644 index 0000000000..83f6b35cdf --- /dev/null +++ b/src/kits/debug/arch/sparc/arch_debug_support.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. + * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include "arch_debug_support.h" + + +struct stack_frame { + struct stack_frame *previous; + void *return_address; +}; + + +status_t +arch_debug_get_instruction_pointer(debug_context *context, thread_id thread, + void **ip, void **stackFrameAddress) +{ + // get the CPU state + debug_cpu_state cpuState; + status_t error = debug_get_cpu_state(context, thread, NULL, &cpuState); + if (error != B_OK) + return error; + + *ip = (void*)cpuState.rip; + *stackFrameAddress = (void*)cpuState.rbp; + + return B_OK; +} + + +status_t +arch_debug_get_stack_frame(debug_context *context, void *stackFrameAddress, + debug_stack_frame_info *stackFrameInfo) +{ + stack_frame stackFrame; + ssize_t bytesRead = debug_read_memory(context, stackFrameAddress, + &stackFrame, sizeof(stackFrame)); + if (bytesRead < B_OK) + return bytesRead; + if (bytesRead != sizeof(stackFrame)) + return B_ERROR; + + stackFrameInfo->frame = stackFrameAddress; + stackFrameInfo->parent_frame = stackFrame.previous; + stackFrameInfo->return_address = stackFrame.return_address; + return B_OK; +} diff --git a/src/system/boot/platform/openfirmware/arch/sparc/Jamfile b/src/system/boot/platform/openfirmware/arch/sparc/Jamfile new file mode 100644 index 0000000000..b081899dd7 --- /dev/null +++ b/src/system/boot/platform/openfirmware/arch/sparc/Jamfile @@ -0,0 +1,15 @@ +SubDir HAIKU_TOP src system boot platform openfirmware arch sparc ; + +SubDirHdrs $(HAIKU_TOP) src system boot platform $(TARGET_BOOT_PLATFORM) ; +UsePrivateSystemHeaders ; +UsePrivateHeaders kernel [ FDirName kernel arch $(TARGET_KERNEL_ARCH) ] + [ FDirName kernel boot platform $(HAIKU_KERNEL_PLATFORM) ] + [ FDirName kernel boot platform $(HAIKU_BOOT_PLATFORM) ] ; + +SubDirC++Flags -fno-rtti ; + +BootStaticLibrary boot_platform_openfirmware_sparc : +; + +SEARCH on [ FGristFiles arch_cpu_asm.S arch_mmu.cpp ] + = [ FDirName $(HAIKU_TOP) src system kernel arch $(TARGET_KERNEL_ARCH) ] ; diff --git a/src/system/glue/arch/sparc/Jamfile b/src/system/glue/arch/sparc/Jamfile new file mode 100644 index 0000000000..96847ec368 --- /dev/null +++ b/src/system/glue/arch/sparc/Jamfile @@ -0,0 +1,21 @@ +SubDir HAIKU_TOP src system glue arch sparc ; + +local architectureObject ; +for architectureObject in [ MultiArchSubDirSetup sparc ] { + on $(architectureObject) { + local architecture = $(TARGET_PACKAGING_ARCH) ; + + UsePrivateSystemHeaders ; + + local sources = + crti.S + crtn.S + ; + MergeObject <$(architecture)>glue_arch_$(TARGET_ARCH).o : $(sources) ; + + if $(HAIKU_BUILD_TYPE) = bootstrap { + # build a version for stage0 of the bootstrap process + BootstrapStage0PlatformObjects [ FGristFiles $(sources) ] : true ; + } + } +} diff --git a/src/system/glue/arch/sparc/crti.S b/src/system/glue/arch/sparc/crti.S new file mode 100644 index 0000000000..5b907ede34 --- /dev/null +++ b/src/system/glue/arch/sparc/crti.S @@ -0,0 +1,29 @@ +/* + Copyright 2019, Adrien Destugues + * Distributed under the terms of the MIT License. + */ + + +/** This file contains the first part of the ".init" and ".fini" sections in + * the ELF executable. + * The functions defined here will be called during initialization/termination + * of the loaded executable/library. The ".init" and ".fini" sections are + * stacked together like this: + * + * crti.S entry point + * crtbegin.S GCC specific: constructors/destructors are called, ... + * crtend.S + * crtn.S call to _init_after/_term_after + * exit + */ + + +.section .init +.global _init +.type _init, #function + // crtbegin.o stuff comes here + +.section .fini +.global _fini +.type _fini, #function + // crtend.o stuff comes here diff --git a/src/system/glue/arch/sparc/crtn.S b/src/system/glue/arch/sparc/crtn.S new file mode 100644 index 0000000000..cb8bef1c96 --- /dev/null +++ b/src/system/glue/arch/sparc/crtn.S @@ -0,0 +1,15 @@ +/* + * Copyright 2019, Adrien Destugues, pulkomandy@pulkomandy.tk + * Distributed under the terms of the MIT License. + */ + + +/** This file contains the final part of the ".init" and ".fini" sections in + * the ELF executable. It is tightly connected to crti.S. + * Have a look at crti.S to find a description of what happens here. + */ + + +.section .init + +.section .fini diff --git a/src/system/libroot/os/arch/sparc/Jamfile b/src/system/libroot/os/arch/sparc/Jamfile new file mode 100644 index 0000000000..d33938b2e0 --- /dev/null +++ b/src/system/libroot/os/arch/sparc/Jamfile @@ -0,0 +1,22 @@ +SubDir HAIKU_TOP src system libroot os arch sparc ; + +SubDirC++Flags -std=gnu++11 ; + +local architectureObject ; +for architectureObject in [ MultiArchSubDirSetup sparc ] { + on $(architectureObject) { + local architecture = $(TARGET_PACKAGING_ARCH) ; + + UsePrivateKernelHeaders ; + UsePrivateSystemHeaders ; + + SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ; + + MergeObject <$(architecture)>os_arch_$(TARGET_ARCH).o : + tls.c + + generic_atomic.cpp + generic_system_time_nsecs.cpp + ; + } +} diff --git a/src/system/libroot/os/arch/sparc/tls.c b/src/system/libroot/os/arch/sparc/tls.c new file mode 100644 index 0000000000..79c0a5a632 --- /dev/null +++ b/src/system/libroot/os/arch/sparc/tls.c @@ -0,0 +1,53 @@ +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the MIT License. +*/ + +// ToDo: this is a dummy implementation - I've not yet gained enough knowledge +// to decide how this should be done, so it's just broken now (okay for single +// threaded apps, though). + +// we don't want to have the inline assembly included here +#ifndef _NO_INLINE_ASM +# define _NO_INLINE_ASM 1 +#endif + +#include "support/TLS.h" +#include "tls.h" + + +static int32 gNextSlot = TLS_FIRST_FREE_SLOT; +static void *gSlots[TLS_MAX_KEYS]; + + +int32 +tls_allocate(void) +{ + int32 next = atomic_add(&gNextSlot, 1); + if (next >= TLS_MAX_KEYS) + return B_NO_MEMORY; + + return next; +} + + +void * +tls_get(int32 index) +{ + return gSlots[index]; +} + + +void ** +tls_address(int32 index) +{ + return &gSlots[index]; +} + + +void +tls_set(int32 index, void *value) +{ + gSlots[index] = value; +} + diff --git a/src/tools/gensyscalls/arch/sparc/arch_gensyscalls.h b/src/tools/gensyscalls/arch/sparc/arch_gensyscalls.h new file mode 100644 index 0000000000..620802d3a9 --- /dev/null +++ b/src/tools/gensyscalls/arch/sparc/arch_gensyscalls.h @@ -0,0 +1,2 @@ +#define SYSCALL_RETURN_TYPE_ALIGNMENT_TYPE long +#define SYSCALL_PARAMETER_ALIGNMENT_TYPE long