From 98f92a9958b4b889f8864a20b33504caa7728808 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Thu, 4 Nov 2021 20:15:58 +0800 Subject: [PATCH] makefile: move pdlibc to extlib, add C++ stub standard headers It now kind of compiles with x86_64-elf gcc (does not link though) --- cppruntime/perm.hpp | 2 +- driver/block/blockdevice.cpp | 4 +- driver/block/blockdevice.hpp | 2 +- driver/block/ramdisk.cpp | 2 +- driver/block/ramdisk.hpp | 2 +- driver/filesystem/fat/fat.cpp | 2 +- {libc => extlib/pdlibc}/README | 0 {libc => extlib/pdlibc}/abs.c | 0 {libc => extlib/pdlibc}/include/assert.h | 0 {libc => extlib/pdlibc}/include/ctype.h | 0 {libc => extlib/pdlibc}/include/errno.h | 0 {libc => extlib/pdlibc}/include/float.h | 0 {libc => extlib/pdlibc}/include/inttypes.h | 0 {libc => extlib/pdlibc}/include/iso646.h | 0 {libc => extlib/pdlibc}/include/limits.h | 0 {libc => extlib/pdlibc}/include/locale.h | 0 .../pdlibc}/include/pdclib/_PDCLIB_config.h | 0 .../pdlibc}/include/pdclib/_PDCLIB_defguard.h | 0 .../pdlibc}/include/pdclib/_PDCLIB_glue.h | 0 .../pdlibc}/include/pdclib/_PDCLIB_internal.h | 0 .../pdlibc}/include/pdclib/_PDCLIB_lib_ext1.h | 0 .../pdlibc}/include/pdclib/_PDCLIB_print.h | 0 .../pdlibc}/include/pdclib/_PDCLIB_tzcode.h | 0 {libc => extlib/pdlibc}/include/signal.h | 0 {libc => extlib/pdlibc}/include/stdalign.h | 0 {libc => extlib/pdlibc}/include/stdarg.h | 0 {libc => extlib/pdlibc}/include/stdbool.h | 0 {libc => extlib/pdlibc}/include/stddef.h | 0 {libc => extlib/pdlibc}/include/stdint.h | 0 {libc => extlib/pdlibc}/include/stdio.h | 0 {libc => extlib/pdlibc}/include/stdlib.h | 0 {libc => extlib/pdlibc}/include/stdnoreturn.h | 0 {libc => extlib/pdlibc}/include/string.h | 0 {libc => extlib/pdlibc}/include/threads.h | 0 {libc => extlib/pdlibc}/include/time.h | 0 {libc => extlib/pdlibc}/include/wctype.h | 0 {libc => extlib/pdlibc}/memcmp.c | 0 {libc => extlib/pdlibc}/strncat.c | 0 {libc => extlib/pdlibc}/strncmp.c | 0 {libc => extlib/pdlibc}/strncpy.c | 0 libstd/README | 5 ++ libstd/__cpp_config.hpp | 25 +++++++++ libstd/exception | 23 +++++++++ libstd/new | 51 +++++++++++++++++++ main.h | 3 ++ memory/memory.hpp | 23 ++++----- memory/memory_cpp.cpp | 16 +++--- util/stack.c | 2 +- 48 files changed, 134 insertions(+), 28 deletions(-) rename {libc => extlib/pdlibc}/README (100%) rename {libc => extlib/pdlibc}/abs.c (100%) rename {libc => extlib/pdlibc}/include/assert.h (100%) rename {libc => extlib/pdlibc}/include/ctype.h (100%) rename {libc => extlib/pdlibc}/include/errno.h (100%) rename {libc => extlib/pdlibc}/include/float.h (100%) rename {libc => extlib/pdlibc}/include/inttypes.h (100%) rename {libc => extlib/pdlibc}/include/iso646.h (100%) rename {libc => extlib/pdlibc}/include/limits.h (100%) rename {libc => extlib/pdlibc}/include/locale.h (100%) rename {libc => extlib/pdlibc}/include/pdclib/_PDCLIB_config.h (100%) rename {libc => extlib/pdlibc}/include/pdclib/_PDCLIB_defguard.h (100%) rename {libc => extlib/pdlibc}/include/pdclib/_PDCLIB_glue.h (100%) rename {libc => extlib/pdlibc}/include/pdclib/_PDCLIB_internal.h (100%) rename {libc => extlib/pdlibc}/include/pdclib/_PDCLIB_lib_ext1.h (100%) rename {libc => extlib/pdlibc}/include/pdclib/_PDCLIB_print.h (100%) rename {libc => extlib/pdlibc}/include/pdclib/_PDCLIB_tzcode.h (100%) rename {libc => extlib/pdlibc}/include/signal.h (100%) rename {libc => extlib/pdlibc}/include/stdalign.h (100%) rename {libc => extlib/pdlibc}/include/stdarg.h (100%) rename {libc => extlib/pdlibc}/include/stdbool.h (100%) rename {libc => extlib/pdlibc}/include/stddef.h (100%) rename {libc => extlib/pdlibc}/include/stdint.h (100%) rename {libc => extlib/pdlibc}/include/stdio.h (100%) rename {libc => extlib/pdlibc}/include/stdlib.h (100%) rename {libc => extlib/pdlibc}/include/stdnoreturn.h (100%) rename {libc => extlib/pdlibc}/include/string.h (100%) rename {libc => extlib/pdlibc}/include/threads.h (100%) rename {libc => extlib/pdlibc}/include/time.h (100%) rename {libc => extlib/pdlibc}/include/wctype.h (100%) rename {libc => extlib/pdlibc}/memcmp.c (100%) rename {libc => extlib/pdlibc}/strncat.c (100%) rename {libc => extlib/pdlibc}/strncmp.c (100%) rename {libc => extlib/pdlibc}/strncpy.c (100%) create mode 100644 libstd/README create mode 100644 libstd/__cpp_config.hpp create mode 100644 libstd/exception create mode 100644 libstd/new diff --git a/cppruntime/perm.hpp b/cppruntime/perm.hpp index 20bb812..5e8e381 100644 --- a/cppruntime/perm.hpp +++ b/cppruntime/perm.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace helos { diff --git a/driver/block/blockdevice.cpp b/driver/block/blockdevice.cpp index 965f89a..8c06959 100644 --- a/driver/block/blockdevice.cpp +++ b/driver/block/blockdevice.cpp @@ -22,8 +22,8 @@ public: return backing->BlockSize() * cnt; } - ::helos::Permission Permission() const override { - return backing->Permission(); + ::helos::Permission DevicePermission() const override { + return backing->DevicePermission(); } uint64_t ReadBlock(uint64_t blockOffset, void *data, uint64_t blockCount) const override { diff --git a/driver/block/blockdevice.hpp b/driver/block/blockdevice.hpp index bdf20cc..f2c6a36 100644 --- a/driver/block/blockdevice.hpp +++ b/driver/block/blockdevice.hpp @@ -25,7 +25,7 @@ public: // Permission returns the permission on the entire device (Read, Write, Exec) - virtual Permission Permission() const { + virtual Permission DevicePermission() const { return PermRead | PermWrite | PermExecute; } diff --git a/driver/block/ramdisk.cpp b/driver/block/ramdisk.cpp index 133799d..a987f0e 100644 --- a/driver/block/ramdisk.cpp +++ b/driver/block/ramdisk.cpp @@ -2,7 +2,7 @@ #include "ramdisk.hpp" #include "../../memory/memory.h" #include "../../memory/paging_internal.h" -#include +#include namespace helos { diff --git a/driver/block/ramdisk.hpp b/driver/block/ramdisk.hpp index 0407dd7..655e5fa 100644 --- a/driver/block/ramdisk.hpp +++ b/driver/block/ramdisk.hpp @@ -25,7 +25,7 @@ public: uint64_t Size() const override { return blockcount; } uint64_t SizeBytes() const override { return blocksize * blockcount; } - ::helos::Permission Permission() const override { return perm; } + ::helos::Permission DevicePermission() const override { return perm; } uint64_t ReadBlock(uint64_t blockOffset, void *data, uint64_t blockCount) const override; uint64_t WriteBlock(uint64_t blockOffset, const void *data, uint64_t blockCount) override; diff --git a/driver/filesystem/fat/fat.cpp b/driver/filesystem/fat/fat.cpp index ca984c3..505b393 100644 --- a/driver/filesystem/fat/fat.cpp +++ b/driver/filesystem/fat/fat.cpp @@ -1,6 +1,6 @@ #include "fat.hpp" -#include +#include namespace helos { namespace filesystem { diff --git a/libc/README b/extlib/pdlibc/README similarity index 100% rename from libc/README rename to extlib/pdlibc/README diff --git a/libc/abs.c b/extlib/pdlibc/abs.c similarity index 100% rename from libc/abs.c rename to extlib/pdlibc/abs.c diff --git a/libc/include/assert.h b/extlib/pdlibc/include/assert.h similarity index 100% rename from libc/include/assert.h rename to extlib/pdlibc/include/assert.h diff --git a/libc/include/ctype.h b/extlib/pdlibc/include/ctype.h similarity index 100% rename from libc/include/ctype.h rename to extlib/pdlibc/include/ctype.h diff --git a/libc/include/errno.h b/extlib/pdlibc/include/errno.h similarity index 100% rename from libc/include/errno.h rename to extlib/pdlibc/include/errno.h diff --git a/libc/include/float.h b/extlib/pdlibc/include/float.h similarity index 100% rename from libc/include/float.h rename to extlib/pdlibc/include/float.h diff --git a/libc/include/inttypes.h b/extlib/pdlibc/include/inttypes.h similarity index 100% rename from libc/include/inttypes.h rename to extlib/pdlibc/include/inttypes.h diff --git a/libc/include/iso646.h b/extlib/pdlibc/include/iso646.h similarity index 100% rename from libc/include/iso646.h rename to extlib/pdlibc/include/iso646.h diff --git a/libc/include/limits.h b/extlib/pdlibc/include/limits.h similarity index 100% rename from libc/include/limits.h rename to extlib/pdlibc/include/limits.h diff --git a/libc/include/locale.h b/extlib/pdlibc/include/locale.h similarity index 100% rename from libc/include/locale.h rename to extlib/pdlibc/include/locale.h diff --git a/libc/include/pdclib/_PDCLIB_config.h b/extlib/pdlibc/include/pdclib/_PDCLIB_config.h similarity index 100% rename from libc/include/pdclib/_PDCLIB_config.h rename to extlib/pdlibc/include/pdclib/_PDCLIB_config.h diff --git a/libc/include/pdclib/_PDCLIB_defguard.h b/extlib/pdlibc/include/pdclib/_PDCLIB_defguard.h similarity index 100% rename from libc/include/pdclib/_PDCLIB_defguard.h rename to extlib/pdlibc/include/pdclib/_PDCLIB_defguard.h diff --git a/libc/include/pdclib/_PDCLIB_glue.h b/extlib/pdlibc/include/pdclib/_PDCLIB_glue.h similarity index 100% rename from libc/include/pdclib/_PDCLIB_glue.h rename to extlib/pdlibc/include/pdclib/_PDCLIB_glue.h diff --git a/libc/include/pdclib/_PDCLIB_internal.h b/extlib/pdlibc/include/pdclib/_PDCLIB_internal.h similarity index 100% rename from libc/include/pdclib/_PDCLIB_internal.h rename to extlib/pdlibc/include/pdclib/_PDCLIB_internal.h diff --git a/libc/include/pdclib/_PDCLIB_lib_ext1.h b/extlib/pdlibc/include/pdclib/_PDCLIB_lib_ext1.h similarity index 100% rename from libc/include/pdclib/_PDCLIB_lib_ext1.h rename to extlib/pdlibc/include/pdclib/_PDCLIB_lib_ext1.h diff --git a/libc/include/pdclib/_PDCLIB_print.h b/extlib/pdlibc/include/pdclib/_PDCLIB_print.h similarity index 100% rename from libc/include/pdclib/_PDCLIB_print.h rename to extlib/pdlibc/include/pdclib/_PDCLIB_print.h diff --git a/libc/include/pdclib/_PDCLIB_tzcode.h b/extlib/pdlibc/include/pdclib/_PDCLIB_tzcode.h similarity index 100% rename from libc/include/pdclib/_PDCLIB_tzcode.h rename to extlib/pdlibc/include/pdclib/_PDCLIB_tzcode.h diff --git a/libc/include/signal.h b/extlib/pdlibc/include/signal.h similarity index 100% rename from libc/include/signal.h rename to extlib/pdlibc/include/signal.h diff --git a/libc/include/stdalign.h b/extlib/pdlibc/include/stdalign.h similarity index 100% rename from libc/include/stdalign.h rename to extlib/pdlibc/include/stdalign.h diff --git a/libc/include/stdarg.h b/extlib/pdlibc/include/stdarg.h similarity index 100% rename from libc/include/stdarg.h rename to extlib/pdlibc/include/stdarg.h diff --git a/libc/include/stdbool.h b/extlib/pdlibc/include/stdbool.h similarity index 100% rename from libc/include/stdbool.h rename to extlib/pdlibc/include/stdbool.h diff --git a/libc/include/stddef.h b/extlib/pdlibc/include/stddef.h similarity index 100% rename from libc/include/stddef.h rename to extlib/pdlibc/include/stddef.h diff --git a/libc/include/stdint.h b/extlib/pdlibc/include/stdint.h similarity index 100% rename from libc/include/stdint.h rename to extlib/pdlibc/include/stdint.h diff --git a/libc/include/stdio.h b/extlib/pdlibc/include/stdio.h similarity index 100% rename from libc/include/stdio.h rename to extlib/pdlibc/include/stdio.h diff --git a/libc/include/stdlib.h b/extlib/pdlibc/include/stdlib.h similarity index 100% rename from libc/include/stdlib.h rename to extlib/pdlibc/include/stdlib.h diff --git a/libc/include/stdnoreturn.h b/extlib/pdlibc/include/stdnoreturn.h similarity index 100% rename from libc/include/stdnoreturn.h rename to extlib/pdlibc/include/stdnoreturn.h diff --git a/libc/include/string.h b/extlib/pdlibc/include/string.h similarity index 100% rename from libc/include/string.h rename to extlib/pdlibc/include/string.h diff --git a/libc/include/threads.h b/extlib/pdlibc/include/threads.h similarity index 100% rename from libc/include/threads.h rename to extlib/pdlibc/include/threads.h diff --git a/libc/include/time.h b/extlib/pdlibc/include/time.h similarity index 100% rename from libc/include/time.h rename to extlib/pdlibc/include/time.h diff --git a/libc/include/wctype.h b/extlib/pdlibc/include/wctype.h similarity index 100% rename from libc/include/wctype.h rename to extlib/pdlibc/include/wctype.h diff --git a/libc/memcmp.c b/extlib/pdlibc/memcmp.c similarity index 100% rename from libc/memcmp.c rename to extlib/pdlibc/memcmp.c diff --git a/libc/strncat.c b/extlib/pdlibc/strncat.c similarity index 100% rename from libc/strncat.c rename to extlib/pdlibc/strncat.c diff --git a/libc/strncmp.c b/extlib/pdlibc/strncmp.c similarity index 100% rename from libc/strncmp.c rename to extlib/pdlibc/strncmp.c diff --git a/libc/strncpy.c b/extlib/pdlibc/strncpy.c similarity index 100% rename from libc/strncpy.c rename to extlib/pdlibc/strncpy.c diff --git a/libstd/README b/libstd/README new file mode 100644 index 0000000..81ccc80 --- /dev/null +++ b/libstd/README @@ -0,0 +1,5 @@ + +This folder is in place for the most standard headers not in the PDLibC extlib. + +Mostly for C++ standard headers. + diff --git a/libstd/__cpp_config.hpp b/libstd/__cpp_config.hpp new file mode 100644 index 0000000..1a1a5a7 --- /dev/null +++ b/libstd/__cpp_config.hpp @@ -0,0 +1,25 @@ +#pragma once + + +#if __cplusplus >= 201103L +#define __CXX11 +#endif +#if __cplusplus >= 201402L +#define __CXX14 +#endif +#if __cplusplus >= 201703L +#define __CXX17 +#endif +#if __cplusplus >= 202002L +#define __CXX20 +#endif + + +#ifdef __CXX11 +#define __NOTHROW noexcept +#define __NOTHROW_SINCECXX11 __NOTHROW +#else +#define __NOTHROW throw() +#define __NOTHROW_SINCECXX11 +#endif + diff --git a/libstd/exception b/libstd/exception new file mode 100644 index 0000000..2b9db6a --- /dev/null +++ b/libstd/exception @@ -0,0 +1,23 @@ +#pragma once +#include <__cpp_config.hpp> + +extern "C++" { +namespace std { + + +class exception { +public: + exception() __NOTHROW {} +#ifdef __CXX11 + exception(const exception &) = default; + exception &operator=(const exception &) = default; + exception(exception &&) = default; + exception &operator=(exception &&) = default; +#endif + + virtual const char *what() const __NOTHROW { return "std::exception"; }; +}; + + +} // namespace std +} diff --git a/libstd/new b/libstd/new new file mode 100644 index 0000000..de030ff --- /dev/null +++ b/libstd/new @@ -0,0 +1,51 @@ +#pragma once +#include <__cpp_config.hpp> + +#include + +extern "C++" { +namespace std { + + +class bad_alloc: public exception { +public: + bad_alloc() __NOTHROW {} +#ifdef __CXX11 + bad_alloc(const bad_alloc &) = default; + bad_alloc &operator=(const bad_alloc &) = default; +#endif + virtual ~bad_alloc() __NOTHROW {} + + virtual const char *what() const __NOTHROW { return "std::bad_alloc"; } +}; + +#ifdef __CXX11 +class bad_array_new_length: public bad_alloc { +public: + bad_array_new_length() __NOTHROW {} + virtual ~bad_array_new_length() __NOTHROW {} + + virtual const char *what() const __NOTHROW { return "std::bad_array_new_length"; } +}; +#endif + + +#ifdef __CXX17 +enum class align_val_t : size_t {}; +#endif + +struct nothrow_t { +#ifdef __CXX11 + explicit nothrow_t() = default; +#endif +}; +extern const nothrow_t nothrow; + + +// new_handler omitted + +// new/delete omitted, use memory/memory.hpp + + +} // namespace std +} diff --git a/main.h b/main.h index cb8fbd0..f981abe 100644 --- a/main.h +++ b/main.h @@ -1,3 +1,6 @@ +#pragma once + +#include "stddef.h" #ifdef __cplusplus extern "C" { diff --git a/memory/memory.hpp b/memory/memory.hpp index 7e1cd13..e0525be 100644 --- a/memory/memory.hpp +++ b/memory/memory.hpp @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include #include #include "memory.h" @@ -30,11 +29,11 @@ public: template constexpr kAllocator(const kAllocator &) {} - Type *allocate(std::size_t n) { + Type *allocate(size_t n) { return kMalloc(n * sizeof(Type)); } - void deallocate(Type *p, std::size_t n) { + void deallocate(Type *p, size_t n) { kFree(p); } }; @@ -59,25 +58,25 @@ bool operator!=(const kAllocator &, const kAllocator &) { // // operators new and delete only call kMalloc/kFree, so C++ code // must stay after paging setup -void *operator new(std::size_t size); -void *operator new[](std::size_t size); +void *operator new(size_t size); +void *operator new[](size_t size); #if __cplusplus >= 201703L -void *operator new(std::size_t size, std::align_val_t align); -void *operator new[](std::size_t size, std::align_val_t align); +void *operator new(size_t size, std::align_val_t align); +void *operator new[](size_t size, std::align_val_t align); #endif void operator delete(void *ptr) noexcept; void operator delete[](void *ptr) noexcept; #if __cplusplus >= 201402L -void operator delete(void *ptr, std::size_t size) noexcept; -void operator delete[](void *ptr, std::size_t size) noexcept; +void operator delete(void *ptr, size_t size) noexcept; +void operator delete[](void *ptr, size_t size) noexcept; #endif #if __cplusplus >= 201703L void operator delete(void *ptr, std::align_val_t align) noexcept; void operator delete[](void *ptr, std::align_val_t align) noexcept; -void operator delete(void *ptr, std::size_t size, std::align_val_t align) noexcept; -void operator delete[](void *ptr, std::size_t size, std::align_val_t align) noexcept; +void operator delete(void *ptr, size_t size, std::align_val_t align) noexcept; +void operator delete[](void *ptr, size_t size, std::align_val_t align) noexcept; #endif #endif // HELOS diff --git a/memory/memory_cpp.cpp b/memory/memory_cpp.cpp index 4463c70..262132f 100644 --- a/memory/memory_cpp.cpp +++ b/memory/memory_cpp.cpp @@ -3,25 +3,25 @@ #include "../extlib/dlmalloc/malloc-2.8.6.h" -void *operator new(std::size_t size) { return kMalloc(size); } -void *operator new[](std::size_t size) { return kMalloc(size); } +void *operator new(size_t size) { return kMalloc(size); } +void *operator new[](size_t size) { return kMalloc(size); } void operator delete(void *ptr) noexcept { kFree(ptr); } void operator delete[](void *ptr) noexcept { kFree(ptr); } #if __cplusplus >= 201703L -void *operator new(std::size_t size, std::align_val_t align) { return dlmemalign((size_t)align, size); } -void *operator new[](std::size_t size, std::align_val_t align) { return dlmemalign((size_t)align, size); } +void *operator new(size_t size, std::align_val_t align) { return dlmemalign((size_t)align, size); } +void *operator new[](size_t size, std::align_val_t align) { return dlmemalign((size_t)align, size); } #endif #if __cplusplus >= 201402L -void operator delete(void *ptr, std::size_t size) noexcept { kFree(ptr); } -void operator delete[](void *ptr, std::size_t size) noexcept { kFree(ptr); } +void operator delete(void *ptr, size_t size) noexcept { kFree(ptr); } +void operator delete[](void *ptr, size_t size) noexcept { kFree(ptr); } #endif #if __cplusplus >= 201703L void operator delete(void *ptr, std::align_val_t align) noexcept { kFree(ptr); } void operator delete[](void *ptr, std::align_val_t align) noexcept { kFree(ptr); } -void operator delete(void *ptr, std::size_t size, std::align_val_t align) noexcept { kFree(ptr); } -void operator delete[](void *ptr, std::size_t size, std::align_val_t align) noexcept { kFree(ptr); } +void operator delete(void *ptr, size_t size, std::align_val_t align) noexcept { kFree(ptr); } +void operator delete[](void *ptr, size_t size, std::align_val_t align) noexcept { kFree(ptr); } #endif diff --git a/util/stack.c b/util/stack.c index 500f9f8..f82a43a 100644 --- a/util/stack.c +++ b/util/stack.c @@ -1,7 +1,7 @@ #include "stack.h" #include "../runtime/stdio.h" -#include +#include void stack_InitBuffered(stack *s, void *buffer, uintptr_t size) {