Working kernel written on C and userspace-ready #1
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <types.h>
|
#include <Types.h>
|
||||||
|
|
||||||
static inline void CPUYield() {
|
static inline void CPUYield() {
|
||||||
__asm__ volatile ("yield" ::: "memory");
|
__asm__ volatile ("yield" ::: "memory");
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Types.h>
|
||||||
|
|
||||||
|
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);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <types.h>
|
#include <Types.h>
|
||||||
|
|
||||||
typedef struct ExceptionsContext {
|
typedef struct ExceptionsContext {
|
||||||
UInt64 x0;
|
UInt64 x0;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <types.h>
|
#include <Types.h>
|
||||||
|
|
||||||
static inline void IOAddressWrite32(Address address, UInt32 value) {
|
static inline void IOAddressWrite32(Address address, UInt32 value) {
|
||||||
__asm__ volatile ("dsb sy" ::: "memory"); // wait till all previous writes are finished physically
|
__asm__ volatile ("dsb sy" ::: "memory"); // wait till all previous writes are finished physically
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <types.h>
|
#include <Types.h>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kUARTBaseAddress = 0x09000000, // TODO: make it dynamic by parsing DTB
|
kUARTBaseAddress = 0x09000000, // TODO: make it dynamic by parsing DTB
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Types.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <Types.h>
|
||||||
|
|
||||||
|
static inline UInt32 BytesSwap32(UInt32 value) {
|
||||||
|
return __builtin_bswap32(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline UInt64 BytesSwap64(UInt64 value) {
|
||||||
|
return __builtin_bswap64(value);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <types.h>
|
#include <Types.h>
|
||||||
#include <Lib/VAArgs.h>
|
#include <Lib/VAArgs.h>
|
||||||
|
|
||||||
void* StringSet(BytePointer destination, ASCII value, Size count);
|
void* StringSet(BytePointer destination, ASCII value, Size count);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <types.h>
|
#include <Types.h>
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kOSLogBufferSize = 1024,
|
kOSLogBufferSize = 1024,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <types.h>
|
#include <Types.h>
|
||||||
#include <Arch/Exceptions.h>
|
#include <Arch/Exceptions.h>
|
||||||
|
|
||||||
__attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame);
|
__attribute__((noreturn)) void OSPanicException(ExceptionsContext* frame);
|
||||||
|
|||||||
@@ -3,12 +3,19 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(NDEBUG) || defined(__OPTIMIZE__)
|
||||||
|
#define IS_RELEASE 1
|
||||||
|
#else
|
||||||
|
#define IS_RELEASE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef unsigned char UInt8;
|
typedef unsigned char UInt8;
|
||||||
typedef unsigned short UInt16;
|
typedef unsigned short UInt16;
|
||||||
typedef unsigned int UInt32;
|
typedef unsigned int UInt32;
|
||||||
typedef unsigned long long UInt64;
|
typedef unsigned long long UInt64;
|
||||||
typedef unsigned long long UInt;
|
typedef unsigned long long UInt;
|
||||||
|
|
||||||
|
typedef void* Pointer;
|
||||||
typedef UInt Address;
|
typedef UInt Address;
|
||||||
typedef UInt8* BytePointer;
|
typedef UInt8* BytePointer;
|
||||||
typedef UInt8* MemoryPointer;
|
typedef UInt8* MemoryPointer;
|
||||||
|
|||||||
Reference in New Issue
Block a user