makefile: move pdlibc to extlib, add C++ stub standard headers

It now kind of compiles with x86_64-elf gcc (does not link though)
This commit is contained in:
Edgaru089 2021-11-04 20:15:58 +08:00
parent 964893b14a
commit 98f92a9958
48 changed files with 134 additions and 28 deletions

View File

@ -1,6 +1,6 @@
#pragma once
#include <cstdint>
#include <stdint.h>
namespace helos {

View File

@ -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 {

View File

@ -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;
}

View File

@ -2,7 +2,7 @@
#include "ramdisk.hpp"
#include "../../memory/memory.h"
#include "../../memory/paging_internal.h"
#include <cstring>
#include <string.h>
namespace helos {

View File

@ -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;

View File

@ -1,6 +1,6 @@
#include "fat.hpp"
#include <cstring>
#include <string.h>
namespace helos {
namespace filesystem {

5
libstd/README Normal file
View File

@ -0,0 +1,5 @@
This folder is in place for the most standard headers not in the PDLibC extlib.
Mostly for C++ standard headers.

25
libstd/__cpp_config.hpp Normal file
View File

@ -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

23
libstd/exception Normal file
View File

@ -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
}

51
libstd/new Normal file
View File

@ -0,0 +1,51 @@
#pragma once
#include <__cpp_config.hpp>
#include <exception>
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
}

3
main.h
View File

@ -1,3 +1,6 @@
#pragma once
#include "stddef.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,7 +1,6 @@
#pragma once
#include <cstddef>
#include <limits>
#include <stddef.h>
#include <new>
#include "memory.h"
@ -30,11 +29,11 @@ public:
template<typename Other>
constexpr kAllocator(const kAllocator<Other> &) {}
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<T> &, const kAllocator<U> &) {
//
// 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

View File

@ -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

View File

@ -1,7 +1,7 @@
#include "stack.h"
#include "../runtime/stdio.h"
#include <memory.h>
#include <string.h>
void stack_InitBuffered(stack *s, void *buffer, uintptr_t size) {