From 8c3f4c20200ffa030131feff6a511f3a7e3936e0 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 15 Aug 2021 16:25:15 +0100 Subject: [PATCH] Added Horizon target --- photon/libc/sys/{magenta => horizon}/__fio.h | 4 +- photon/libc/sys/{magenta => horizon}/__heap.h | 4 +- photon/libc/sys/horizon/__init.h | 4 + .../libc/sys/{magenta => horizon}/__system.h | 0 photon/libc/sys/horizon/config.cmake | 0 .../libc/sys/{magenta => horizon}/environ.c | 0 photon/libc/sys/{magenta => horizon}/fio.c | 3 +- photon/libc/sys/{magenta => horizon}/heap.c | 10 +- photon/libc/sys/{magenta => horizon}/init.c | 7 ++ .../machine/x86_64/crt0.s | 0 .../sys/{magenta => horizon}/sys/_errno.h | 4 +- .../sys/{magenta => horizon}/sys/_fconst.h | 0 .../libc/sys/{magenta => horizon}/sys/types.h | 0 photon/libc/sys/{magenta => horizon}/system.c | 0 photon/libc/sys/magenta/__init.h | 4 - photon/libc/sys/magenta/config.cmake | 1 - .../libc/sys/magenta/machine/x86_64/syscall.c | 108 ------------------ 17 files changed, 23 insertions(+), 126 deletions(-) rename photon/libc/sys/{magenta => horizon}/__fio.h (93%) rename photon/libc/sys/{magenta => horizon}/__heap.h (50%) create mode 100644 photon/libc/sys/horizon/__init.h rename photon/libc/sys/{magenta => horizon}/__system.h (100%) create mode 100644 photon/libc/sys/horizon/config.cmake rename photon/libc/sys/{magenta => horizon}/environ.c (100%) rename photon/libc/sys/{magenta => horizon}/fio.c (95%) rename photon/libc/sys/{magenta => horizon}/heap.c (85%) rename photon/libc/sys/{magenta => horizon}/init.c (97%) rename photon/libc/sys/{magenta => horizon}/machine/x86_64/crt0.s (100%) rename photon/libc/sys/{magenta => horizon}/sys/_errno.h (95%) rename photon/libc/sys/{magenta => horizon}/sys/_fconst.h (100%) rename photon/libc/sys/{magenta => horizon}/sys/types.h (100%) rename photon/libc/sys/{magenta => horizon}/system.c (100%) delete mode 100644 photon/libc/sys/magenta/__init.h delete mode 100644 photon/libc/sys/magenta/config.cmake delete mode 100644 photon/libc/sys/magenta/machine/x86_64/syscall.c diff --git a/photon/libc/sys/magenta/__fio.h b/photon/libc/sys/horizon/__fio.h similarity index 93% rename from photon/libc/sys/magenta/__fio.h rename to photon/libc/sys/horizon/__fio.h index 16a0b77..7b0131e 100644 --- a/photon/libc/sys/magenta/__fio.h +++ b/photon/libc/sys/horizon/__fio.h @@ -1,5 +1,5 @@ -#ifndef SYS_MAGENTA___FIO_H_ -#define SYS_MAGENTA___FIO_H_ +#ifndef SYS_HORIZON___FIO_H_ +#define SYS_HORIZON___FIO_H_ #define __FIO_BUFSZ 512 diff --git a/photon/libc/sys/magenta/__heap.h b/photon/libc/sys/horizon/__heap.h similarity index 50% rename from photon/libc/sys/magenta/__heap.h rename to photon/libc/sys/horizon/__heap.h index e6c3ae2..c01cb9f 100644 --- a/photon/libc/sys/magenta/__heap.h +++ b/photon/libc/sys/horizon/__heap.h @@ -1,5 +1,5 @@ -#ifndef SYS_MAGENTA_HEAP_H_ -#define SYS_MAGENTA_HEAP_H_ +#ifndef SYS_HORIZON_HEAP_H_ +#define SYS_HORIZON_HEAP_H_ #include "__init.h" diff --git a/photon/libc/sys/horizon/__init.h b/photon/libc/sys/horizon/__init.h new file mode 100644 index 0000000..ee8d68c --- /dev/null +++ b/photon/libc/sys/horizon/__init.h @@ -0,0 +1,4 @@ +#ifndef SYS_HORIZON_INIT_H_ +#define SYS_HORIZON_INIT_H_ + +#endif diff --git a/photon/libc/sys/magenta/__system.h b/photon/libc/sys/horizon/__system.h similarity index 100% rename from photon/libc/sys/magenta/__system.h rename to photon/libc/sys/horizon/__system.h diff --git a/photon/libc/sys/horizon/config.cmake b/photon/libc/sys/horizon/config.cmake new file mode 100644 index 0000000..e69de29 diff --git a/photon/libc/sys/magenta/environ.c b/photon/libc/sys/horizon/environ.c similarity index 100% rename from photon/libc/sys/magenta/environ.c rename to photon/libc/sys/horizon/environ.c diff --git a/photon/libc/sys/magenta/fio.c b/photon/libc/sys/horizon/fio.c similarity index 95% rename from photon/libc/sys/magenta/fio.c rename to photon/libc/sys/horizon/fio.c index 2b56c89..b9880f3 100644 --- a/photon/libc/sys/magenta/fio.c +++ b/photon/libc/sys/horizon/fio.c @@ -1,4 +1,3 @@ -#include #include #include "sys/types.h" #include "__fio.h" @@ -60,7 +59,7 @@ unsigned int __fio_read(struct __io_file *f, char *buf, unsigned int sz) unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz) { - mx_console_write(buf, sz); + //mx_console_write(buf, sz); return sz; } diff --git a/photon/libc/sys/magenta/heap.c b/photon/libc/sys/horizon/heap.c similarity index 85% rename from photon/libc/sys/magenta/heap.c rename to photon/libc/sys/horizon/heap.c index 56c8cfb..e43ddb7 100644 --- a/photon/libc/sys/magenta/heap.c +++ b/photon/libc/sys/horizon/heap.c @@ -2,8 +2,7 @@ #include #include #include -#include -#include +#include #include #define ROUND_UP(x, b) x += (b) - ((x) % (b)) @@ -22,7 +21,7 @@ void __crt_heap_init(size_t sz) &heap_vmo); mx_vaddr_t heap = 0; - mx_vmar_map(mx_get_startup_handle(MX_B_VMAR_ROOT), + mx_vmar_map(mx_bootstrap_handle_get(MX_B_VMAR_ROOT), MX_VM_PERM_READ | MX_VM_PERM_WRITE, 0, heap_vmo, 0, sz, &heap); @@ -54,10 +53,10 @@ void *__crt_heap_extend(size_t sz) mx_vmo_set_size(heap_vmo, heap_sz + sz); mx_vaddr_t vmar_base, alloc_base; - mx_vmar_bounds(mx_get_startup_handle(MX_B_VMAR_ROOT), &vmar_base, NULL); + mx_vmar_bounds(mx_bootstrap_handle_get(MX_B_VMAR_ROOT), &vmar_base, NULL); size_t offset = heap_end - vmar_base; - mx_vmar_map(mx_get_startup_handle(MX_B_VMAR_ROOT), + mx_vmar_map(mx_bootstrap_handle_get(MX_B_VMAR_ROOT), MX_VM_PERM_READ | MX_VM_PERM_WRITE | MX_VM_SPECIFIC, offset, heap_vmo, heap_sz, sz, &alloc_base); heap_sz += sz; @@ -67,4 +66,5 @@ void *__crt_heap_extend(size_t sz) heap_end += sz; return out; + return NULL; } diff --git a/photon/libc/sys/magenta/init.c b/photon/libc/sys/horizon/init.c similarity index 97% rename from photon/libc/sys/magenta/init.c rename to photon/libc/sys/horizon/init.c index acf3a88..7c3fbe8 100644 --- a/photon/libc/sys/magenta/init.c +++ b/photon/libc/sys/horizon/init.c @@ -18,6 +18,7 @@ const char **__crt_environ() extern int main(int, const char **); extern void __crt_run_atexit(); +#if 0 static void parse_args( mx_bootstrap_msg_t *args, mx_handle_t *handles, const char **argv, const char **envp, int hndc, mx_bootstrap_handle_t *handles_out) @@ -112,3 +113,9 @@ int __crt_init(mx_handle_t bootstrap) hang(); return 0; } +#endif + +int __crt_init(mx_handle_t bootstrap) +{ + return -1; +} diff --git a/photon/libc/sys/magenta/machine/x86_64/crt0.s b/photon/libc/sys/horizon/machine/x86_64/crt0.s similarity index 100% rename from photon/libc/sys/magenta/machine/x86_64/crt0.s rename to photon/libc/sys/horizon/machine/x86_64/crt0.s diff --git a/photon/libc/sys/magenta/sys/_errno.h b/photon/libc/sys/horizon/sys/_errno.h similarity index 95% rename from photon/libc/sys/magenta/sys/_errno.h rename to photon/libc/sys/horizon/sys/_errno.h index 0955e02..72e9709 100644 --- a/photon/libc/sys/magenta/sys/_errno.h +++ b/photon/libc/sys/horizon/sys/_errno.h @@ -1,5 +1,5 @@ -#ifndef SYS_MAGENTA_SYS__ERRNO_H_ -#define SYS_MAGENTA_SYS__ERRNO_H_ +#ifndef SYS_HORIZON_SYS__ERRNO_H_ +#define SYS_HORIZON_SYS__ERRNO_H_ #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ diff --git a/photon/libc/sys/magenta/sys/_fconst.h b/photon/libc/sys/horizon/sys/_fconst.h similarity index 100% rename from photon/libc/sys/magenta/sys/_fconst.h rename to photon/libc/sys/horizon/sys/_fconst.h diff --git a/photon/libc/sys/magenta/sys/types.h b/photon/libc/sys/horizon/sys/types.h similarity index 100% rename from photon/libc/sys/magenta/sys/types.h rename to photon/libc/sys/horizon/sys/types.h diff --git a/photon/libc/sys/magenta/system.c b/photon/libc/sys/horizon/system.c similarity index 100% rename from photon/libc/sys/magenta/system.c rename to photon/libc/sys/horizon/system.c diff --git a/photon/libc/sys/magenta/__init.h b/photon/libc/sys/magenta/__init.h deleted file mode 100644 index 5b9d6d4..0000000 --- a/photon/libc/sys/magenta/__init.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef SYS_MAGENTA_INIT_H_ -#define SYS_MAGENTA_INIT_H_ - -#endif diff --git a/photon/libc/sys/magenta/config.cmake b/photon/libc/sys/magenta/config.cmake deleted file mode 100644 index 85667a9..0000000 --- a/photon/libc/sys/magenta/config.cmake +++ /dev/null @@ -1 +0,0 @@ -set(photon_platform_frameworks magenta) diff --git a/photon/libc/sys/magenta/machine/x86_64/syscall.c b/photon/libc/sys/magenta/machine/x86_64/syscall.c deleted file mode 100644 index dc54634..0000000 --- a/photon/libc/sys/magenta/machine/x86_64/syscall.c +++ /dev/null @@ -1,108 +0,0 @@ -#include - -intptr_t __syscall0(uintptr_t id) -{ - intptr_t ret = 0; - asm volatile("mov %1, %%rax; syscall; mov %%rax, %0" - : "=m" (ret) - : "m" (id)); - return ret; -} - -intptr_t __syscall1(uintptr_t id, uintptr_t p0) -{ - intptr_t ret = 0; - asm volatile( - "mov %1, %%rax;" - "mov %2, %%rdi;" - "syscall;" - "mov %%rax, %0" - : "=m" (ret) - : "m" (id), "m" (p0)); - return ret; -} - -intptr_t __syscall2(uintptr_t id, uintptr_t p0, uintptr_t p1) -{ - intptr_t ret = 0; - asm volatile( - "mov %1, %%rax;" - "mov %2, %%rdi;" - "mov %3, %%rsi;" - "syscall;" - "mov %%rax, %0" - : "=m" (ret) - : "m" (id), "m" (p0), "m" (p1)); - return ret; -} - -intptr_t __syscall3(uintptr_t id, uintptr_t p0, uintptr_t p1, uintptr_t p2) -{ - intptr_t ret = 0; - asm volatile( - "movq %1, %%rax;" - "mov %2, %%rdi;" - "mov %3, %%rsi;" - "mov %4, %%rdx;" - "syscall;" - "mov %%rax, %0" - : "=m" (ret) - : "m" (id), "m" (p0), "m" (p1), "m" (p2)); - return ret; -} - -intptr_t __syscall4(uintptr_t id, uintptr_t p0, uintptr_t p1, uintptr_t p2, - uintptr_t p3) -{ - intptr_t ret = 0; - asm volatile( - "mov %1, %%rax;" - "mov %2, %%rdi;" - "mov %3, %%rsi;" - "mov %4, %%rdx;" - "mov %5, %%r10;" - "syscall;" - "mov %%rax, %0" - : "=m" (ret) - : "m" (id), "m" (p0), "m" (p1), "m" (p2), "m" (p3)); - return ret; -} - -intptr_t __syscall5(uintptr_t id, uintptr_t p0, uintptr_t p1, uintptr_t p2, - uintptr_t p3, uintptr_t p4) -{ - intptr_t ret = 0; - asm volatile( - "mov %1, %%rax;" - "mov %2, %%rdi;" - "mov %3, %%rsi;" - "mov %4, %%rdx;" - "mov %5, %%r10;" - "mov %6, %%r8;" - "syscall;" - "mov %%rax, %0" - : "=m" (ret) - : "m" (id), "m" (p0), "m" (p1), "m" (p2), "m" (p3), "m" (p4)); - return ret; -} - -intptr_t __syscall6(uintptr_t id, uintptr_t p0, uintptr_t p1, uintptr_t p2, - uintptr_t p3, uintptr_t p4, uintptr_t p5) -{ - intptr_t ret = 0; - asm volatile( - "mov %1, %%rax;" - "mov %2, %%rdi;" - "mov %3, %%rsi;" - "mov %4, %%rdx;" - "mov %5, %%r10;" - "mov %6, %%r8;" - "mov %7, %%r9;" - "syscall;" - "mov %%rax, %0" - : "=m" (ret) - : "m" (id), "m" (p0), "m" (p1), "m" (p2), "m" (p3), "m" (p4), - "m" (p5)); - return ret; -} -