diff --git a/Kernel/Include/Arch/CPU.h b/Kernel/Include/Arch/CPU.h index d142bc9..83e2710 100644 --- a/Kernel/Include/Arch/CPU.h +++ b/Kernel/Include/Arch/CPU.h @@ -1,5 +1,5 @@ #pragma once -#include +#include static inline void CPUYield() { __asm__ volatile ("yield" ::: "memory"); diff --git a/Kernel/Include/Arch/DTB.h b/Kernel/Include/Arch/DTB.h new file mode 100644 index 0000000..c73efa9 --- /dev/null +++ b/Kernel/Include/Arch/DTB.h @@ -0,0 +1,35 @@ +#pragma once + +#include + +typedef struct FDTHeader { + UInt32 magic; // 0xd00dfeed + UInt32 totalSize; + UInt32 offDtStruct; + UInt32 offDtStrings; + UInt32 offMemRsvMap; + UInt32 version; + UInt32 lastCompVersion; + UInt32 bootCpuidPhys; + UInt32 sizeDtStrings; + UInt32 sizeDtStruct; +} FDTHeader; + +typedef struct FDTProperty { + UInt32 length; + UInt32 nameOffset; +} FDTProperty; + +typedef enum FDTToken { + FDTTokenBeginNode = 0x1, + FDTTokenEndNode = 0x2, + FDTTokenProperty = 0x3, + FDTTokenNOP = 0x4, + FDTTokenEnd = 0x9, +} FDTToken; + +enum { + kFDTHeaderMagic = 0xd00dfeed, +}; + +void DTBParse(Pointer dtb); \ No newline at end of file diff --git a/Kernel/Include/Arch/Exceptions.h b/Kernel/Include/Arch/Exceptions.h index df48045..fe069c1 100644 --- a/Kernel/Include/Arch/Exceptions.h +++ b/Kernel/Include/Arch/Exceptions.h @@ -1,5 +1,5 @@ #pragma once -#include +#include typedef struct ExceptionsContext { UInt64 x0; diff --git a/Kernel/Include/Arch/IO.h b/Kernel/Include/Arch/IO.h index 91f494b..980f76a 100644 --- a/Kernel/Include/Arch/IO.h +++ b/Kernel/Include/Arch/IO.h @@ -1,5 +1,5 @@ #pragma once -#include +#include static inline void IOAddressWrite32(Address address, UInt32 value) { __asm__ volatile ("dsb sy" ::: "memory"); // wait till all previous writes are finished physically diff --git a/Kernel/Include/IO/Serial.h b/Kernel/Include/IO/Serial.h index f2d7787..f87d102 100644 --- a/Kernel/Include/IO/Serial.h +++ b/Kernel/Include/IO/Serial.h @@ -1,5 +1,5 @@ #pragma once -#include +#include enum { kUARTBaseAddress = 0x09000000, // TODO: make it dynamic by parsing DTB diff --git a/Kernel/Include/Lib/Align.h b/Kernel/Include/Lib/Align.h new file mode 100644 index 0000000..7d86a1b --- /dev/null +++ b/Kernel/Include/Lib/Align.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +static inline UInt64 AlignUp64(UInt64 value, UInt64 alignment) { + return (value + alignment - 1) & ~(alignment - 1); +} + +static inline UInt64 AlignDown64(UInt64 value, UInt64 alignment) { + return value & ~(alignment - 1); +} + +static inline UInt32 AlignUp32(UInt32 value, UInt32 alignment) { + return (value + alignment - 1) & ~(alignment - 1); +} + +static inline UInt32 AlignDown32(UInt32 value, UInt32 alignment) { + return value & ~(alignment - 1); +} diff --git a/Kernel/Include/Lib/Bytes.h b/Kernel/Include/Lib/Bytes.h new file mode 100644 index 0000000..852c199 --- /dev/null +++ b/Kernel/Include/Lib/Bytes.h @@ -0,0 +1,10 @@ +#pragma once +#include + +static inline UInt32 BytesSwap32(UInt32 value) { + return __builtin_bswap32(value); +} + +static inline UInt64 BytesSwap64(UInt64 value) { + return __builtin_bswap64(value); +} diff --git a/Kernel/Include/Lib/String.h b/Kernel/Include/Lib/String.h index 201334f..89572df 100644 --- a/Kernel/Include/Lib/String.h +++ b/Kernel/Include/Lib/String.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include void* StringSet(BytePointer destination, ASCII value, Size count); diff --git a/Kernel/Include/OS/Log.h b/Kernel/Include/OS/Log.h index 5b9d1d2..a19fcd6 100644 --- a/Kernel/Include/OS/Log.h +++ b/Kernel/Include/OS/Log.h @@ -1,5 +1,5 @@ #pragma once -#include +#include enum { kOSLogBufferSize = 1024, diff --git a/Kernel/Include/OS/Panic.h b/Kernel/Include/OS/Panic.h index 2eb3722..cb31981 100644 --- a/Kernel/Include/OS/Panic.h +++ b/Kernel/Include/OS/Panic.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include __attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame); diff --git a/Kernel/Include/types.h b/Kernel/Include/types.h index 3e4261f..8f9a059 100644 --- a/Kernel/Include/types.h +++ b/Kernel/Include/types.h @@ -3,12 +3,19 @@ #pragma once +#if defined(NDEBUG) || defined(__OPTIMIZE__) + #define IS_RELEASE 1 +#else + #define IS_RELEASE 0 +#endif + typedef unsigned char UInt8; typedef unsigned short UInt16; typedef unsigned int UInt32; typedef unsigned long long UInt64; typedef unsigned long long UInt; +typedef void* Pointer; typedef UInt Address; typedef UInt8* BytePointer; typedef UInt8* MemoryPointer;