From 93e7d1f389fb573abd00e7d17eaa633b14bfd614 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 24 Aug 2020 10:20:43 +0100 Subject: [PATCH] Fixed linux compatibility --- CMakeLists.txt | 9 +++-- photon/libc/sys/linux/__fio.h | 7 ++++ photon/libc/sys/linux/fio.c | 13 ++----- photon/libc/sys/linux/machine/x86_64/crt0.s | 11 +++--- photon/libc/sys/linux/sys/_errno.h | 39 +++++++++++++++++++++ 5 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 photon/libc/sys/linux/sys/_errno.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5129fc7..03114fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ -cmake_minimum_required(VERSION 3.5) -# project(photon C ASM-ATT) +if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") + cmake_minimum_required(VERSION 3.5) + project(photon C ASM-ATT) +endif () macro(subdirlist result curdir) file(GLOB children RELATIVE ${curdir} ${curdir}/*) @@ -12,6 +14,7 @@ macro(subdirlist result curdir) set(${result} ${dirlist}) endmacro() +include(Bundles) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/platform.cmake) platform_config(${PHOTON_TARGET}) @@ -42,7 +45,7 @@ file(GLOB photon_libc_crt ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/machine/${machine}/crt*.s) add_library(crt OBJECT ${photon_libc_crt}) -target_compile_options(crt PRIVATE -c -ffreestanding -nostdlib) +# target_compile_options(crt PRIVATE -c -ffreestanding -nostdlib) file(GLOB platform_sources ${CMAKE_CURRENT_SOURCE_DIR}/photon/libc/sys/${platform}/*.c diff --git a/photon/libc/sys/linux/__fio.h b/photon/libc/sys/linux/__fio.h index 7b697c7..8abb397 100644 --- a/photon/libc/sys/linux/__fio.h +++ b/photon/libc/sys/linux/__fio.h @@ -15,9 +15,16 @@ struct __io_file { }; extern int __fileno(struct __io_file *f); +extern void __fio_init(); +extern unsigned int __fio_read(struct __io_file *f, char *buf, unsigned int sz); extern unsigned int __fio_write(struct __io_file *f, const char *buf, unsigned int sz); extern unsigned int __fio_flush(struct __io_file *f); extern int __fio_error(struct __io_file *f); +extern int __fio_ungetc(struct __io_file *f, char c); + +extern int __fio_fopen(const char *path, const char *mode, struct __io_file *out); +extern int __fio_fclose(struct __io_file *in); +extern int __fio_fdopen(int fd, const char *mode, struct __io_file *out); #if defined(__cplusplus) } diff --git a/photon/libc/sys/linux/fio.c b/photon/libc/sys/linux/fio.c index 3a89c4e..f17d30c 100644 --- a/photon/libc/sys/linux/fio.c +++ b/photon/libc/sys/linux/fio.c @@ -2,21 +2,14 @@ #include "__syscall.h" #include "unistd.h" -struct __io_file __stdin = {}; -struct __io_file __stdout = {}; -struct __io_file __stderr = {}; +struct __io_file __stdin = { .fd = 0 }; +struct __io_file __stdout = { .fd = 1 }; +struct __io_file __stderr = { .fd = 2 }; struct __io_file *stdin = &__stdin; struct __io_file *stdout = &__stdout; struct __io_file *stderr = &__stderr; -void __fio_init() -{ - __stdin.fd = 0; - __stdout.fd = 1; - __stderr.fd = 2; -} - int __fileno(struct __io_file *f) { return f->fd; diff --git a/photon/libc/sys/linux/machine/x86_64/crt0.s b/photon/libc/sys/linux/machine/x86_64/crt0.s index 6941741..d127a67 100644 --- a/photon/libc/sys/linux/machine/x86_64/crt0.s +++ b/photon/libc/sys/linux/machine/x86_64/crt0.s @@ -8,11 +8,12 @@ .type main, @function _start: - pop %rbp - pop %rdi - mov %rsp, %rsi - andq $-16, %rsp - call __fio_init + xor %ebp, %ebp + mov (%rsp), %edi + lea 8(%rsp), %rsi + lea 16(%rsp, %rdi, 8), %rdx + xor %eax, %eax + call main movq %rax, %rdi movq $60, %rax diff --git a/photon/libc/sys/linux/sys/_errno.h b/photon/libc/sys/linux/sys/_errno.h new file mode 100644 index 0000000..0955e02 --- /dev/null +++ b/photon/libc/sys/linux/sys/_errno.h @@ -0,0 +1,39 @@ +#ifndef SYS_MAGENTA_SYS__ERRNO_H_ +#define SYS_MAGENTA_SYS__ERRNO_H_ + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* I/O error */ +#define ENXIO 6 /* No such device or address */ +#define E2BIG 7 /* Argument list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file number */ +#define ECHILD 10 /* No child processes */ +#define EAGAIN 11 /* Try again */ +#define ENOMEM 12 /* Out of memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Device or resource busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* File table overflow */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Not a typewriter */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ +#define EDOM 33 /* Math argument out of domain of func */ +#define ERANGE 34 /* Math result not representable */ + +#endif