Working kernel written on C and userspace-ready #1
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"defaultWorkspaceType": "compilationDatabase",
|
|
||||||
"compilationDatabase": {
|
|
||||||
"searchPaths": [".", "Kernel"]
|
|
||||||
},
|
|
||||||
"backgroundIndexing": true,
|
|
||||||
"backgroundPreparationMode": "enabled"
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|||||||
file(GLOB_RECURSE KERNEL_SOURCES CMAKE_CONFIGURE_DEPENDS
|
file(GLOB_RECURSE KERNEL_SOURCES CMAKE_CONFIGURE_DEPENDS
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/KernelMain.c
|
${CMAKE_CURRENT_SOURCE_DIR}/Source/KernelMain.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/Arch/entry.S
|
${CMAKE_CURRENT_SOURCE_DIR}/Source/Arch/entry.S
|
||||||
|
# ${CMAKE_CURRENT_SOURCE_DIR}/Source/IO/*.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/**/*.c
|
${CMAKE_CURRENT_SOURCE_DIR}/Source/**/*.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
static inline void CPUYield() {
|
||||||
|
__asm__ volatile ("yield" ::: "memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void CPUWaitForInterrupt() {
|
||||||
|
__asm__ volatile ("wfi" ::: "memory");
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
static inline void IOAddressWrite32(UInt64 address, UInt32 value) {
|
||||||
|
__asm__ volatile ("dsb sy" ::: "memory"); // wait till all previous writes are finished physically
|
||||||
|
*(volatile UInt32*)address = value;
|
||||||
|
__asm__ volatile ("dsb sy" ::: "memory"); // wait till my write is finished physically
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline UInt32 IOAddressRead32(UInt64 address) {
|
||||||
|
UInt32 value = *(volatile UInt32*)address;
|
||||||
|
__asm__ volatile ("dsb ld" ::: "memory"); // wait till my read is finished physically
|
||||||
|
return value;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
enum {
|
||||||
|
kUARTBaseAddress = 0x09000000, // TODO: make it dynamic by parsing DTB
|
||||||
|
};
|
||||||
|
|
||||||
|
Int32 IOSerialPutCharacter(ASCII character);
|
||||||
|
Int32 IOSerialPutString(const ASCII* string);
|
||||||
@@ -7,12 +7,18 @@ 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 UInt Address;
|
||||||
|
typedef UInt8* BytePointer;
|
||||||
|
typedef UInt8* MemoryPointer;
|
||||||
|
|
||||||
typedef signed char Int8;
|
typedef signed char Int8;
|
||||||
typedef signed short Int16;
|
typedef signed short Int16;
|
||||||
typedef signed int Int32;
|
typedef signed int Int32;
|
||||||
typedef signed long long Int64;
|
typedef signed long long Int64;
|
||||||
|
typedef int Int;
|
||||||
|
|
||||||
typedef UInt64 Size;
|
typedef UInt64 Size;
|
||||||
|
typedef char ASCII;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#include <IO/IOSerial.h>
|
||||||
|
#include <Arch/IO.h>
|
||||||
|
#include <Arch/CPU.h>
|
||||||
|
|
||||||
|
Int32 IOSerialPutCharacter(ASCII character) {
|
||||||
|
// TXFF -- TRansmit FIFO Full for PL011 is 5 bit of FR reg (0x18)
|
||||||
|
UInt64 uartFR = kUARTBaseAddress + 0x18;
|
||||||
|
|
||||||
|
while ((IOAddressRead32(uartFR) & (1 << 5)) != 0) {
|
||||||
|
CPUYield();
|
||||||
|
}
|
||||||
|
|
||||||
|
IOAddressWrite32(kUARTBaseAddress, character);
|
||||||
|
return character;
|
||||||
|
}
|
||||||
|
|
||||||
|
Int32 IOSerialPutString(const ASCII* string) {
|
||||||
|
Int i = 0;
|
||||||
|
while (string[i] != '\0') {
|
||||||
|
IOSerialPutCharacter(string[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "types.h"
|
#include <types.h>
|
||||||
|
#include <IO/IOSerial.h>
|
||||||
|
|
||||||
void KernelMain(void) {
|
void KernelMain(void) {
|
||||||
volatile UInt64 meow = 0x12345;
|
IOSerialPutString("Meow nya!!\n");
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user