Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
73f6c0dade | |||
e09f1790a0 | |||
f066462f29 | |||
ded76cd0af | |||
d681320463 | |||
3113fb08c3 |
|
@ -11,6 +11,10 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
|||
SET(CMAKE_SYSTEM_NAME Generic)
|
||||
SET(CMAKE_CROSSCOMPILING 1)
|
||||
|
||||
enable_language(ASM)
|
||||
enable_language(C)
|
||||
enable_language(CXX)
|
||||
|
||||
project(chroma)
|
||||
|
||||
SET(src_files
|
||||
|
@ -29,9 +33,10 @@ SET(src_files
|
|||
${CMAKE_SOURCE_DIR}/src/system/memory/liballoc.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/system/memory/physmem.c
|
||||
${CMAKE_SOURCE_DIR}/src/system/process/process.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/system/extern/extern_defs.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/drivers/elf.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/drivers/devices/devices.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/drivers/devices/input/keyboard.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/drivers/devices/io/ps2_keyboard.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/drivers/devices/io/apic.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/drivers/devices/storage/ata.cpp
|
||||
)
|
||||
|
@ -41,7 +46,7 @@ SET(lib_files
|
|||
${CMAKE_SOURCE_DIR}/src/lainlib/mutex/ticketlock.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/lainlib/compression/lzgmini.c
|
||||
${CMAKE_SOURCE_DIR}/src/lainlib/string/str.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/editor/EditorMain.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/lainlib/vector/vector.cpp
|
||||
)
|
||||
|
||||
include_directories("inc" "D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++" "D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32")
|
||||
|
@ -50,6 +55,10 @@ SET(src_no_sse
|
|||
${CMAKE_SOURCE_DIR}/src/system/interrupts.cpp
|
||||
)
|
||||
|
||||
SET(src_as
|
||||
${CMAKE_SOURCE_DIR}/src/global/core-att.s
|
||||
)
|
||||
|
||||
SET(src_preamble
|
||||
${CMAKE_SOURCE_DIR}/src/global/crt0.o
|
||||
${CMAKE_SOURCE_DIR}/src/global/crti.o
|
||||
|
@ -70,5 +79,5 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
|||
add_executable(kernel)
|
||||
|
||||
target_sources(kernel PUBLIC ${src_preamble} PUBLIC ${src_files} PUBLIC ${src_no_sse} PUBLIC ${lib_files} PUBLIC ${src_epilogue})
|
||||
target_compile_options(kernel PRIVATE -ffreestanding -O0 -Wall -Wextra -Wall -Werror -fPIC -fno-exceptions -fno-omit-frame-pointer -mno-red-zone -fno-stack-protector -fno-rtti -ggdb3)
|
||||
target_compile_options(kernel PRIVATE -ffreestanding -O0 -Wall -Wextra -Wall -Werror -fPIC -fno-exceptions -fno-omit-frame-pointer -mno-red-zone -fno-stack-protector -fno-strict-aliasing $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti> -ggdb3)
|
||||
target_link_options(kernel PRIVATE -T ${CMAKE_SOURCE_DIR}/linker.ld -ffreestanding -O2 -nostdlib -nostartfiles -lgcc)
|
||||
|
|
47
README.md
47
README.md
|
@ -38,10 +38,55 @@ It will compile the kernel, and create an OS image with `mkbootimg`.
|
|||
### Linux
|
||||
|
||||
The system for linux is a lot easier, but you *do* need an x86_64-elf-gcc cross compiler. You can get one from the AUR on Arch-based distros (like Manjaro), or make one yourself using [the OSDev Wiki guide](https://wiki.osdev.org/GCC_Cross-Compiler)
|
||||
Simply run the `init.sh` to generate a makefile, then `make` to create the image file.
|
||||
|
||||
On the Chroma side, Simply run the `init.sh` to generate a makefile, then `make` to create the image file.
|
||||
|
||||
|
||||
The generated IMG works in QEMU, or on a physical test device (unlike a lot of other hobby OSes!)
|
||||
This means you can use any emulator or hypervisor to run it.
|
||||
|
||||
|
||||
## Project structure
|
||||
|
||||
The repository has a lot of files and folders after setting up a workspace. This is a guide to all the files and folders.
|
||||
|
||||
```
|
||||
|
||||
File Location | Description
|
||||
/
|
||||
├── bin/ | Binary Output folder
|
||||
│ └── img/ | Image Output folder.
|
||||
│ └── chroma.img | Disk Image file, as an alternative to ISO below.
|
||||
│ |
|
||||
├── inc/ | Global header include folder.
|
||||
│ ├── driver/ | Header files for the default driver implementations.
|
||||
│ ├── editor/ | Header files for the builtin editor and debugger.
|
||||
│ ├── kernel/ | Header files for the Chroma kernel itself.
|
||||
│ └── lainlib/ | Header files for the Lainlib standard library.
|
||||
│ |
|
||||
├── src/ | Source files.
|
||||
│ ├── assets/ | Assorted linkable files that will be bundled with the built image.
|
||||
│ ├── drivers/ | Handling of the default driver implementations.
|
||||
│ ├── editor/ | Handling of the builtin editor and debugger.
|
||||
│ ├── global/ | Various files used in global objects (ie. the C RunTime, new core bootstrapping, etc)
|
||||
│ ├── lainlib/ | Handling of the Lainlib standard library.
|
||||
│ ├── system/ | Core Kernel files.
|
||||
│ ├── video/ | Writing and drawing on the screen.
|
||||
│ └── kernel.cpp | The primary kernel entry point.
|
||||
│ |
|
||||
├── tools/ | Auxiliary tools used in the buildsystem.
|
||||
│ └── mkbootimg/ | Creates a bootable .img file based on the chroma.json configuration file below.
|
||||
│ |
|
||||
├── .gitignore | Git Repository Ignored Files
|
||||
├── build_and_run.sh | shell script that builds the img file and runs it using run.sh below.
|
||||
├── choma.bxrc | bxrc (Bochs Runtime Config) file for the Bochs emulator and debugger.
|
||||
├── chroma.iso | ISO disc image file that can be loaded into a VM or onto a boot disk.
|
||||
├── chroma.json | MkBootImg configuration file
|
||||
├── CMakeLists.txt | Buildscript and CMake project configuration file.
|
||||
├── LICENSE | Chroma's License. MIT License.
|
||||
├── linker.ld | GCC linkerscript that places files and addresses at their expected positions.
|
||||
├── post.sh | Postprocessing script; Generates the final img file, and attempts to update a VirtualBox configuration named "Chroma" to run this new file instead.
|
||||
├── pre.sh | First-time setup script; generates the font file binary and generates the CMake buildscripts.
|
||||
├── README.md | This file.
|
||||
└── run.bat | Attempts to start a Virtualbox VM named "chroma".
|
||||
```
|
|
@ -2,6 +2,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "lainlib/vector/vector.h"
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2021 ***
|
||||
|
@ -50,7 +51,50 @@ namespace Device {
|
|||
};
|
||||
};
|
||||
|
||||
// TODO: GenericKeyboard
|
||||
class GenericKeyboard : public GenericDevice {
|
||||
public:
|
||||
struct KeyboardData {
|
||||
char Char;
|
||||
char Scancode;
|
||||
bool Pressed;
|
||||
};
|
||||
|
||||
// This is an input device.
|
||||
DeviceType GetType() const final {
|
||||
return DeviceType::INTERFACE;
|
||||
};
|
||||
|
||||
// Provided for utility checks.
|
||||
static DeviceType GetRootType() {
|
||||
return DeviceType::INTERFACE;
|
||||
};
|
||||
|
||||
virtual bool isPressed(uint8_t) const = 0;
|
||||
virtual uint8_t getLastPress() const = 0;
|
||||
|
||||
size_t readBuffer(void* dest, size_t index, size_t len) {
|
||||
size_t lengthRead = len;
|
||||
|
||||
if (index > buffer.size()) {
|
||||
return 0;
|
||||
} else if (index + len > buffer.size()) {
|
||||
lengthRead = sizeof(KeyboardData) - index; // TODO: wat?
|
||||
}
|
||||
|
||||
memcpy((uint8_t*) dest, ((uint8_t*)buffer.data) + index, lengthRead);
|
||||
return lengthRead;
|
||||
}
|
||||
|
||||
size_t getBufferSize() {
|
||||
return buffer.size();
|
||||
}
|
||||
|
||||
protected:
|
||||
lainlib::vector<KeyboardData> buffer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// TODO: GenericDebugger
|
||||
// TODO: GenericNetwork
|
||||
|
||||
|
|
39
inc/driver/io/ps2_keyboard.h
Normal file
39
inc/driver/io/ps2_keyboard.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
#include <driver/generic/device.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2022 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
extern char keys[128];
|
||||
|
||||
namespace Device {
|
||||
class PS2Keyboard : public GenericKeyboard {
|
||||
bool keyStates[128];
|
||||
uint8_t lastPress = 0;
|
||||
uint8_t* callback;
|
||||
|
||||
public:
|
||||
PS2Keyboard();
|
||||
|
||||
// The instance of this singleton class.
|
||||
static PS2Keyboard* driver;
|
||||
|
||||
const char* GetName() const {
|
||||
return "PS2 Keyboard";
|
||||
};
|
||||
|
||||
void Init();
|
||||
void InterruptHandler();
|
||||
|
||||
void setState(bool state, uint8_t key);
|
||||
bool isPressed(uint8_t key) const;
|
||||
|
||||
uint8_t getLastPress() const {
|
||||
return keys[lastPress];
|
||||
}
|
||||
|
||||
void SetCallback(uint32_t*);
|
||||
};
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
#include <kernel/chroma.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2020 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char Char;
|
||||
char Scancode;
|
||||
bool Pressed;
|
||||
} KeyboardData;
|
||||
|
||||
typedef void (*KeyboardCallback)(KeyboardData Frame);
|
||||
|
||||
extern KeyboardCallback KeyboardCallbacks[16];
|
||||
|
||||
int SetupKBCallback(void (*Handler)(KeyboardData Frame));
|
||||
|
||||
void UninstallKBCallback(int Index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -6,10 +6,6 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
;* Memory map
|
||||
;* 0h - 600h reserved for the system
|
||||
|
@ -156,9 +152,3 @@ typedef struct {
|
|||
* MMapEnt *mmap_ent = &bootboot.mmap; mmap_ent++;
|
||||
* until you reach bootboot->size */
|
||||
} __attribute__((packed)) bootinfo;
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -9,10 +9,6 @@
|
|||
* It also provides the symbols for the framebuffer and configuration file, which are both equually important.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define UNUSED(x) (void)x
|
||||
|
||||
#include <stdint.h>
|
||||
|
@ -73,7 +69,6 @@ void WriteChar(const char character);
|
|||
|
||||
void WriteStringWithFont(const char* string);
|
||||
|
||||
void InitInterrupts();
|
||||
void InitSerial();
|
||||
void InitPrint();
|
||||
|
||||
|
@ -82,12 +77,14 @@ void SetupIDT();
|
|||
|
||||
int ParseKernelHeader(size_t InitrdPtr);
|
||||
|
||||
int Main();
|
||||
|
||||
void Exit(int code);
|
||||
|
||||
void SomethingWentWrong(const char* Message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
extern "C" {
|
||||
#endif
|
||||
void InitInterrupts();
|
||||
|
||||
int Main();
|
||||
void Exit(int code);
|
||||
void SomethingWentWrong(const char* Message);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace ACPI {
|
|||
MADT();
|
||||
|
||||
void LogDump();
|
||||
void Initialize();
|
||||
void Init();
|
||||
// Get the byte of the end of the table.
|
||||
size_t GetEndOfTable();
|
||||
// Get all of the entries in the table, as an array.
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace ACPI {
|
|||
// RSDP Entries themselves.
|
||||
struct RSDT {
|
||||
ACPIHeader Header;
|
||||
uint32_t* OtherSDTs;
|
||||
uint32_t OtherSDTs[];
|
||||
} __attribute__((packed));
|
||||
|
||||
RSDP();
|
||||
|
|
|
@ -29,21 +29,21 @@ struct StackFrame {
|
|||
*/
|
||||
class Core {
|
||||
public:
|
||||
Core() {}
|
||||
Core(){}
|
||||
Core(size_t LAPIC, size_t ID);
|
||||
|
||||
size_t ID;
|
||||
size_t LocalAPIC;
|
||||
size_t ID = 0;
|
||||
size_t LocalAPIC = 0;
|
||||
|
||||
address_space_t* AddressSpace;
|
||||
address_space_t* AddressSpace = nullptr;
|
||||
|
||||
uint8_t* SyscallStack;
|
||||
size_t StackAddress;
|
||||
uint8_t StackData[Constants::Core::STACK_SIZE];
|
||||
uint8_t* SyscallStack = 0;
|
||||
size_t StackAddress = 0;
|
||||
uint8_t StackData[Constants::Core::STACK_SIZE] = { 0 };
|
||||
|
||||
IDT CoreIDT;
|
||||
GDT CoreGDT;
|
||||
TSS64 CoreTSS;
|
||||
IDT CoreIDT = { 0, 0 };
|
||||
GDT CoreGDT = { 0, 0 };
|
||||
TSS64 CoreTSS = { };
|
||||
|
||||
void LoadExtraRegisters(uint8_t* Data);
|
||||
void SaveExtraRegisters(uint8_t* Data);
|
||||
|
@ -53,28 +53,17 @@ class Core {
|
|||
static Core* GetCurrent() {
|
||||
size_t CoreID = 0;
|
||||
__asm__ __volatile__("mov %0, %%fs\n" : "=r"(CoreID) : :);
|
||||
return &Processors[CoreID];
|
||||
return Processors[CoreID];
|
||||
}
|
||||
|
||||
static Core* GetCore(int ID) { return &Processors[ID]; }
|
||||
static Core* GetCore(int ID) { return Processors[ID]; }
|
||||
|
||||
static void PreInit();
|
||||
static void Init();
|
||||
|
||||
private:
|
||||
static Core Processors[];
|
||||
|
||||
// Initialization vectors for all new cores.
|
||||
// Numbers derived from boot.h space.
|
||||
// Specifically, the bootloader ROM.
|
||||
enum Initialization {
|
||||
PAGETABLES = 0x600,
|
||||
STARTUP = 0x620,
|
||||
STACK = 0x670,
|
||||
GDT = 0x680,
|
||||
IDT = 0x690
|
||||
};
|
||||
static Core* Processors[];
|
||||
|
||||
void Bootstrap();
|
||||
void SetupData(size_t ID);
|
||||
|
||||
} __attribute__((packed));
|
||||
};
|
||||
|
|
|
@ -8,10 +8,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t LowLimit;
|
||||
uint16_t BaseLow;
|
||||
|
@ -86,7 +82,3 @@ typedef struct __attribute__((packed)) {
|
|||
uint16_t Length;
|
||||
size_t Address;
|
||||
} IDT;
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
|
@ -6,13 +6,12 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const char* ExceptionStrings[];
|
||||
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
size_t rip;
|
||||
size_t cs;
|
||||
|
@ -30,12 +29,17 @@ typedef struct __attribute__((packed)) {
|
|||
size_t ss;
|
||||
} EXCEPTION_FRAME;
|
||||
|
||||
|
||||
typedef void (*IRQHandler)(INTERRUPT_FRAME* Frame);
|
||||
|
||||
extern IRQHandler IRQ_Handlers[16];
|
||||
typedef struct {
|
||||
IRQHandler handlers[8];
|
||||
size_t numHandlers;
|
||||
} IRQHandlerData;
|
||||
|
||||
void InstallIRQ(int IRQ, void (*Handler)(INTERRUPT_FRAME* Frame));
|
||||
extern IRQHandlerData IRQHandlers[32];
|
||||
|
||||
size_t InstallIRQ(int IRQ, IRQHandler handler);
|
||||
void UninstallIRQHandler(int IRQ, size_t ID);
|
||||
|
||||
__attribute__((no_caller_saved_registers)) void IRQ_Common(INTERRUPT_FRAME* Frame, size_t Interupt);
|
||||
__attribute__((no_caller_saved_registers)) void ISR_Common(INTERRUPT_FRAME* Frame, size_t Interrupt);
|
||||
|
@ -95,5 +99,5 @@ void IRQ14Handler(INTERRUPT_FRAME* Frame);
|
|||
void IRQ15Handler(INTERRUPT_FRAME* Frame);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
}
|
||||
#endif
|
|
@ -8,11 +8,7 @@
|
|||
|
||||
#define PAUSE __asm__ __volatile__("pause")
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
typedef struct {
|
||||
uint8_t ACK;
|
||||
uint8_t SelfTest;
|
||||
uint8_t Echo;
|
||||
|
@ -22,7 +18,6 @@ typedef struct {
|
|||
|
||||
extern KBD_FLAGS KbdFlags;
|
||||
|
||||
|
||||
DESC_TBL ReadGDT(void);
|
||||
void WriteGDT(DESC_TBL GDTData);
|
||||
|
||||
|
@ -69,12 +64,14 @@ void Send8042(size_t);
|
|||
void WriteSerialChar(const char);
|
||||
void WriteSerialString(const char*, size_t);
|
||||
|
||||
int SerialPrintf(const char* format, ...);
|
||||
int Printf(const char* Format, ...);
|
||||
|
||||
void* memcpy(void* dest, void const* src, size_t len);
|
||||
void* memset(void* dst, int src, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int SerialPrintf(const char* format, ...);
|
||||
int Printf(const char* Format, ...);
|
||||
void* memcpy(void* dest, void const* src, size_t len);
|
||||
void* memset(void* dst, int src, size_t len);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <lainlib/lainlib.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <kernel/system/interrupts.h>
|
||||
#include <lainlib/lainlib.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2020 ***
|
||||
|
@ -41,10 +38,18 @@ extern "C" {
|
|||
|
||||
#define CONCAT(x, y) x ## y
|
||||
#define CONCAT2(x, y) CONCAT(x, y)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#define ASSERT(exp, error) \
|
||||
if(!(exp)) SomethingWentWrong(error);
|
||||
// typedef char CONCAT2(static_assert, __LINE__) [(exp) ? 1 : -1]
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define CLZ(num) (num ? __builtin_clzll(num) : 64)
|
||||
|
||||
#define IS_ALIGNED(addr) (((size_t) addr | 0xFFFFFFFFFFFFF000) == 0)
|
||||
|
@ -142,6 +147,8 @@ extern "C" {
|
|||
#define KERNEL_HEAP_REGION 0xFFFFE00080000000ull // Kernel Object Space (kmalloc will allocate into this region)
|
||||
#define KERNEL_HEAP_END 0xFFFFE000C0000000ull // End of Kernel Object Space
|
||||
|
||||
#define APIC_REGION 0x00000000FEE00000ull // Physical location of the APIC MMIO region.
|
||||
|
||||
#define DIRECT_REGION 0xFFFF800000000000ull
|
||||
|
||||
#define LOWER_REGION 0x0000000100000000ull // Lower Memory cutoff - 4GB
|
||||
|
@ -221,10 +228,15 @@ size_t AllocatorMaxBlockSize(void);
|
|||
size_t AllocatorPoolOverhead(void);
|
||||
size_t AllocatorAllocateOverhead(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
size_t AlignUpwards(size_t Pointer, size_t Alignment);
|
||||
size_t AlignDownwards(size_t Pointer, size_t Alignment);
|
||||
void* AlignPointer(const void* Pointer, size_t Alignment);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/************************************************************
|
||||
|
@ -235,6 +247,10 @@ extern size_t memstart;
|
|||
|
||||
extern size_t end;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void ListMemoryMap();
|
||||
|
||||
void InitMemoryManager();
|
||||
|
@ -268,6 +284,7 @@ void TraversePageTables();
|
|||
void* memcpy(void* dest, void const* src, size_t len);
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
* C h r o m a A l l o c a t o r
|
||||
**********************************************/
|
||||
|
@ -298,6 +315,6 @@ extern void *PREFIX(realloc)(void *, size_t); ///< The standard function.
|
|||
extern void *PREFIX(calloc)(size_t, size_t); ///< The standard function.
|
||||
extern void PREFIX(free)(void *); ///< The standard function.
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,9 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
@ -179,7 +175,3 @@ typedef struct {
|
|||
|
||||
extern pci_device_t** pci_root_devices;
|
||||
extern pci_entry_t* pci_map;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -3,10 +3,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// This file contains all of the bitmap fonts made by me (Curle) and taken from the public domain
|
||||
// eg. http://dimensionalrift.homelinux.net/combuster/mos3/?p=viewsource&file=/modules/gfx/font8_8.asm
|
||||
|
||||
|
@ -468,7 +464,3 @@ const unsigned char bitfont_block[32][8] = {
|
|||
{ 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F}, // U+259E (boxes top right and bottom left)
|
||||
{ 0xF0, 0xF0, 0xF0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF}, // U+259F (boxes right and bottom)
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -5,10 +5,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Drawing routines for screen manipulation.
|
||||
* This will be pulled out into the Helix library soon.
|
||||
|
@ -60,7 +56,3 @@ void DrawLineRoundedRect(size_t x, size_t y, size_t width, size_t height, size_t
|
|||
void DrawFilledCircle(size_t centerX, size_t centerY, size_t radius);
|
||||
void DrawLineCircle(size_t centerX, size_t centerY, size_t radius);
|
||||
void DrawLineCircleCorners(size_t centerX, size_t centerY, size_t radius, char cornerMask);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -28,10 +28,6 @@
|
|||
#ifndef _LIBLZG_H_
|
||||
#define _LIBLZG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LZG_VERSION "1.0.10" /**< @brief LZG library version string */
|
||||
#define LZG_VERNUM 0x0100000a /**< @brief LZG library version number (strictly */
|
||||
/* incremental) */
|
||||
|
@ -320,8 +316,4 @@ lzg_uint32_t LZG_Version(void);
|
|||
*/
|
||||
const char* LZG_VersionString(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _LIBLZG_H_
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <kernel/system/pci.h>
|
||||
|
@ -183,7 +179,3 @@ void E1000InterruptFired(INTERRUPT_FRAME* InterruptContext);
|
|||
uint8_t* E1000GetMAC(e1000_device_t* Device);
|
||||
// Send a packet
|
||||
int E1000Send(e1000_device_t* Device, const void* Data, uint16_t Length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,9 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2020 ***
|
||||
*** Chroma ***
|
||||
|
@ -25,5 +21,5 @@ extern "C" {
|
|||
#include <lainlib/compression/lzg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#include <lainlib/vector/vector.h>
|
||||
#endif
|
|
@ -1,9 +1,5 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct list_entry {
|
||||
struct list_entry* Previous;
|
||||
struct list_entry* Next;
|
||||
|
@ -36,7 +32,3 @@ bool ListIsEmpty(list_entry_t* Head);
|
|||
for(pos = UNSAFE_CAST((head)->next, typeof(*(pos)), member); &pos->member != (head); pos = LISTNEXT(pos, member))
|
||||
|
||||
#define LASTENTRY 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -5,10 +5,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef volatile int spinlock_t;
|
||||
|
||||
/* A set of macros that acquire and release a mutex spinlock. */
|
||||
|
@ -22,7 +18,3 @@ typedef volatile int spinlock_t;
|
|||
#define SPUNLOCK(name) \
|
||||
__sync_synchronize(); \
|
||||
name = 0;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -7,11 +7,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* This file provides a simple implementation of a ticket-based locking system.
|
||||
* You should probably prefer Spinlock over Ticketlock.
|
||||
*
|
||||
|
@ -22,6 +17,10 @@ extern "C" {
|
|||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
size_t NowServing;
|
||||
size_t NextTicket;
|
||||
|
@ -35,6 +34,6 @@ bool TicketAttemptLock(ticketlock_t* Lock);
|
|||
|
||||
void TicketUnlock(ticketlock_t* Lock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -6,14 +6,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
size_t strlen(const char* String);
|
||||
|
||||
bool strcmp(char* a, const char* b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
bool strcmp(char* a, const char* b);
|
129
inc/lainlib/vector/vector.h
Normal file
129
inc/lainlib/vector/vector.h
Normal file
|
@ -0,0 +1,129 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <kernel/system/memory.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2022 ***
|
||||
*** Lainlib ***
|
||||
***********************/
|
||||
|
||||
// integer typedefs
|
||||
using u32 = uint32_t;
|
||||
|
||||
namespace lainlib {
|
||||
|
||||
template<typename T>
|
||||
struct vector {
|
||||
T& operator [] (u32 i) {
|
||||
return this->data[i];
|
||||
}
|
||||
|
||||
T operator [] (u32 i) const {
|
||||
return this->data[i];
|
||||
}
|
||||
|
||||
u32 size() {
|
||||
return bytes / sizeof(T);
|
||||
}
|
||||
|
||||
template<typename access_type>
|
||||
access_type handle_read(const void *buf) {
|
||||
access_type v;
|
||||
memcpy(&v,buf,sizeof(access_type));
|
||||
return v;
|
||||
}
|
||||
|
||||
template<typename access_type>
|
||||
void handle_write(void *buf, access_type v) {
|
||||
memcpy(buf,&v,sizeof(access_type));
|
||||
}
|
||||
|
||||
// insert at end as a var as a raw set of bytes into the Array
|
||||
template<typename Y>
|
||||
void emplace_back(Y v) {
|
||||
const u32 len = sizeof(v);
|
||||
|
||||
reserve(len);
|
||||
|
||||
// actually write in the data
|
||||
handle_write(&data[size()], v);
|
||||
bytes += len;
|
||||
}
|
||||
|
||||
T pop() {
|
||||
const T v = data[size() - 1];
|
||||
bytes -= sizeof(v);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void reserve_raw(u32 size) {
|
||||
capacity = size;
|
||||
data = (T*)krealloc(data, size);
|
||||
}
|
||||
|
||||
void resize(u32 in) {
|
||||
const u32 len = in * sizeof(T);
|
||||
|
||||
const u32 old_len = size();
|
||||
|
||||
reserve_raw( bytes);
|
||||
bytes = len;
|
||||
|
||||
// default initialize the new elements
|
||||
for(u32 i = old_len; i < size(); i++) {
|
||||
data[i] = {};
|
||||
}
|
||||
}
|
||||
|
||||
// make sure there is enough left for the allocation we are doing
|
||||
void reserve(u32 size) {
|
||||
const u32 free_size = capacity - bytes;
|
||||
|
||||
// we have room to just dump this in
|
||||
if(free_size >= size) {
|
||||
return;
|
||||
} else {
|
||||
const u32 new_capacity = (capacity + size) * 2;
|
||||
reserve_raw(new_capacity);
|
||||
}
|
||||
}
|
||||
|
||||
// raw mem read and writes over the array
|
||||
T read_var(u32 idx) {
|
||||
return handle_read<T>(data[idx]);
|
||||
}
|
||||
|
||||
template<typename Y>
|
||||
void write_var(u32 idx, T v) {
|
||||
return handle_write(data[idx], v);
|
||||
}
|
||||
|
||||
// insert raw memory block into the array
|
||||
void push_mem(const void* newData, u32 size)
|
||||
{
|
||||
reserve(size);
|
||||
|
||||
memcpy(data[bytes], newData, size);
|
||||
bytes += size;
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
if(data) {
|
||||
kfree(data);
|
||||
data = nullptr;
|
||||
}
|
||||
|
||||
bytes = 0;
|
||||
capacity = 0;
|
||||
}
|
||||
|
||||
T* data = nullptr;
|
||||
|
||||
// in raw bytes
|
||||
u32 bytes = 0;
|
||||
u32 capacity = 0;
|
||||
};
|
||||
}
|
|
@ -22,7 +22,7 @@ Device::GenericStorage* StorageDevicesArray[MAX_STORAGE_DEVICES];
|
|||
size_t CurrentStorageDevice = 0;
|
||||
|
||||
// Internal storage. TODO: Make this not a pain to maintain
|
||||
const char* DeviceNames[] = {"Storage", "Keyboard", "Networking"};
|
||||
const char* DeviceNames[] = {"Storage", "Internal", "Peripheral", "Networking"};
|
||||
|
||||
|
||||
// Add a device pointer to the managed list.
|
||||
|
@ -30,7 +30,7 @@ void Device::RegisterDevice(Device::GenericDevice* Device) {
|
|||
DevicesArray[CurrentDevice] = Device;
|
||||
Device->DeviceID = CurrentDevice;
|
||||
CurrentDevice++;
|
||||
SerialPrintf("[DEVICE] Registered device %d called %s of type %s\r\n", CurrentDevice - 1, Device->GetName(),
|
||||
SerialPrintf("[ DEV] Registered device %d called %s of type %s\r\n", CurrentDevice - 1, Device->GetName(),
|
||||
DeviceNames[Device->GetType()]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,160 +0,0 @@
|
|||
#include <kernel/chroma.h>
|
||||
#include <driver/keyboard.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2020 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This file contains (mostly unused) implementations of a full PS/2 keyboard driver.
|
||||
*
|
||||
* It provides provisions for full 2-way communication, as well as auxiliary key commands.
|
||||
* //TODO: Media keys?
|
||||
*
|
||||
* Once this driver is to a workable state, I would like to start adding a proper keyboard buffer,
|
||||
* which will integrate with a window system.
|
||||
*
|
||||
*/
|
||||
|
||||
KBD_FLAGS KbdFlags;
|
||||
|
||||
char keys[128] = {
|
||||
0, 27,
|
||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b',
|
||||
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
|
||||
0,
|
||||
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '#',
|
||||
0,
|
||||
'\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
|
||||
0,
|
||||
'*', 0,
|
||||
' ', 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'-',
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'+',
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, 0, 0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
|
||||
KeyboardCallback KeyboardCallbacks[16] = {
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
static int CurrentCallback = 0;
|
||||
|
||||
int SetupKBCallback(void (* Handler)(KeyboardData Frame)) {
|
||||
KeyboardCallbacks[CurrentCallback++] = Handler;
|
||||
return CurrentCallback;
|
||||
}
|
||||
|
||||
void UninstallKBCallback(int Number) {
|
||||
KeyboardCallbacks[Number] = NULL; // 0 is used in the common check to make sure that the function is callable.
|
||||
// This removes this callback from that check, ergo the function will no longer be called.
|
||||
}
|
||||
|
||||
void KbdEcho() {
|
||||
if (!KbdFlags.EchoCount) {
|
||||
if (!KbdFlags.Echo) {
|
||||
Send8042(0xEE);
|
||||
}
|
||||
} else {
|
||||
KbdFlags.EchoCount = 0;
|
||||
KbdFlags.Echo = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UpdateKeyboard(uint8_t msg) {
|
||||
|
||||
switch (msg) {
|
||||
case 0x0:
|
||||
KbdFlags.Error = 1;
|
||||
//ResendBuffer();
|
||||
break;
|
||||
case 0xAA:
|
||||
KbdFlags.SelfTest = 1;
|
||||
break;
|
||||
case 0xEE:
|
||||
KbdFlags.Echo = 0;
|
||||
KbdFlags.EchoCount = 2;
|
||||
KbdEcho();
|
||||
break;
|
||||
case 0xFA:
|
||||
KbdFlags.ACK = 1;
|
||||
//ProgressBuffer();
|
||||
break;
|
||||
case 0xFC:
|
||||
case 0xFD:
|
||||
KbdFlags.SelfTest = 0;
|
||||
KbdFlags.Error = 1;
|
||||
//RestartKbd();
|
||||
break;
|
||||
case 0xFE:
|
||||
//ResendBuffer();
|
||||
break;
|
||||
case 0xFF:
|
||||
KbdFlags.Error = 1;
|
||||
//ResendBuffer();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
KeyboardData data = (KeyboardData) {
|
||||
.Char = msg > 0x80 && msg < 0xD8 ? keys[msg - 0x80] : keys[msg],
|
||||
.Scancode = static_cast<char>(msg),
|
||||
.Pressed = !(msg > 0x80 && msg < 0xD8),
|
||||
};
|
||||
|
||||
void (* Handler)(KeyboardData data);
|
||||
|
||||
for (size_t handlerNum = 0; handlerNum < 16; handlerNum++) {
|
||||
Handler = KeyboardCallbacks[handlerNum];
|
||||
if (Handler) {
|
||||
Handler(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Send8042(size_t info) {
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
unsigned char chr = (unsigned char) info;
|
||||
if (chr != 0) {
|
||||
WritePort(0x60, chr, 1);
|
||||
WaitFor8042();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WaitFor8042() {
|
||||
|
||||
bool full = true;
|
||||
while (full) {
|
||||
full = ReadPort(0x64, 1) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -2,6 +2,8 @@
|
|||
#include <kernel/system/acpi/madt.h>
|
||||
#include <kernel/system/io.h>
|
||||
#include <kernel/system/memory.h>
|
||||
#include "kernel/system/core.hpp"
|
||||
#include "kernel/chroma.h"
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2021 ***
|
||||
|
@ -51,7 +53,7 @@ void APIC::Enable() {
|
|||
}
|
||||
|
||||
void APIC::SendEOI() {
|
||||
WriteRegister(Registers::EOI, 0);
|
||||
*((volatile uint32_t*) 0xfee000B0) = 0;
|
||||
}
|
||||
|
||||
bool APIC::IsReady() {
|
||||
|
@ -59,14 +61,20 @@ bool APIC::IsReady() {
|
|||
}
|
||||
|
||||
void APIC::Init() {
|
||||
SerialPrintf("[ACPI] Enabling APICs...");
|
||||
Device::RegisterDevice(this);
|
||||
|
||||
SerialPrintf("[ ACPI] Enabling APICs...\r\n");
|
||||
|
||||
SerialPrintf("[ ACPI] Memory Mapping APICs..\r\n");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
MapVirtualPage(&KernelAddressSpace, (size_t) Address + i * PAGE_SIZE, (size_t) Address + i * PAGE_SIZE, 3);
|
||||
}
|
||||
|
||||
Address = (void*) ACPI::MADT::instance->LocalAPICBase;
|
||||
|
||||
// TODO: Check whether the identity mapping covers this address
|
||||
SerialPrintf("[ MADT] The APIC of this core is at 0x%p\r\n", (size_t) Address);
|
||||
|
||||
if (Address == nullptr) {
|
||||
SerialPrintf("[ACPI] Unable to locate APICs.");
|
||||
SerialPrintf("[ ACPI] Unable to locate APICs.\r\n");
|
||||
for (;;) { }
|
||||
}
|
||||
|
||||
|
@ -74,13 +82,9 @@ void APIC::Init() {
|
|||
WriteModelSpecificRegister(0x1B, (ReadModelSpecificRegister(0x1B) | 0x800) & ~(1 << 10));
|
||||
Enable();
|
||||
|
||||
// Disable PIC1 and 2
|
||||
WritePort(0x21, 0xFF, 1);
|
||||
WritePort(0xA1, 0xFF, 1);
|
||||
|
||||
SerialPrintf("[ACPI] Enabling Global APIC..");
|
||||
SerialPrintf("[ ACPI] Enabling Global APIC..\r\n");
|
||||
IOAPICs = ACPI::MADT::instance->GetIOApicEntries();
|
||||
SerialPrintf("[ACPI] Enabling Interrupt Source Overrides..");
|
||||
SerialPrintf("[ ACPI] Enabling Interrupt Source Overrides..\r\n");
|
||||
ISOs = ACPI::MADT::instance->GetISOEntries();
|
||||
|
||||
Ready = true;
|
||||
|
@ -108,8 +112,8 @@ void APIC::InitializeCore(int Core, size_t EntryPoint) {
|
|||
WriteRegister(Registers::ICR1, 0x600 | ((uint32_t) (EntryPoint / PAGE_SIZE)));
|
||||
}
|
||||
|
||||
void APIC::SetInternal(uint8_t Vector, uint32_t GSI, uint16_t Flags, int Core, int Status) {
|
||||
UNUSED(Core);
|
||||
void APIC::SetInternal(uint8_t Vector, uint32_t GSI, uint16_t Flags, int CoreID, int Status) {
|
||||
|
||||
size_t temp = Vector;
|
||||
int64_t target = -1;
|
||||
|
||||
|
@ -121,7 +125,7 @@ void APIC::SetInternal(uint8_t Vector, uint32_t GSI, uint16_t Flags, int Core, i
|
|||
}
|
||||
|
||||
if (target == -1) {
|
||||
SerialPrintf("[APIC] No ISO found when setting up redirect.");
|
||||
SerialPrintf("[ APIC] No ISO found when setting up redirect.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -134,6 +138,24 @@ void APIC::SetInternal(uint8_t Vector, uint32_t GSI, uint16_t Flags, int Core, i
|
|||
if (!Status)
|
||||
temp |= (1 << 16);
|
||||
|
||||
// TODO
|
||||
temp |= (((size_t) Core::GetCore(CoreID)->LocalAPIC) << 56);
|
||||
uint32_t IORegister = (GSI - IOAPICs[target]->GSI) * 2 + 0x10;
|
||||
|
||||
SerialPrintf("[ APIC] Setting interrupt %u, redirect %u, on LAPIC %u(%u) of core %u, address 0x%p, register 0x%p, data 0x%p\r\n", GSI, Vector, Core::GetCore(CoreID)->LocalAPIC, target, CoreID, IOAPICs[target]->Address, IORegister, temp);
|
||||
|
||||
WriteIO(IOAPICs[target]->Address, IORegister, (uint32_t) temp);
|
||||
WriteIO(IOAPICs[target]->Address, IORegister + 1, (uint32_t)(temp >> 32));
|
||||
}
|
||||
|
||||
void APIC::Set(int CPU, uint8_t IRQ, int Enabled) {
|
||||
for(size_t i = 0; ISOs[i] != 0; i++) {
|
||||
// We need to make sure we take into account the overrides, so check whether any IRQ is overriden
|
||||
if (ISOs[i]->IRQ == IRQ) {
|
||||
SetInternal(ISOs[i]->IRQ + 0x20, ISOs[i]->Interrupt, ISOs[i]->Flags, CPU, Enabled);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no overrides, we can just remap it upwards
|
||||
SetInternal(IRQ + 0x20, IRQ, 0, CPU, Enabled);
|
||||
}
|
170
src/drivers/devices/io/ps2_keyboard.cpp
Normal file
170
src/drivers/devices/io/ps2_keyboard.cpp
Normal file
|
@ -0,0 +1,170 @@
|
|||
#include <driver/io/ps2_keyboard.h>
|
||||
#include <kernel/chroma.h>
|
||||
#include "driver/io/apic.h"
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2022 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
char keys[128] = {
|
||||
0, 27,
|
||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b',
|
||||
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
|
||||
0,
|
||||
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '#',
|
||||
0,
|
||||
'\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
|
||||
0,
|
||||
'*', 0,
|
||||
' ', 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'-',
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'+',
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, 0, 0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
|
||||
char shiftedKeys[128] = {
|
||||
0,
|
||||
0, // ESC
|
||||
33, // !
|
||||
64, // @
|
||||
35, // #
|
||||
36, // $
|
||||
37, // %
|
||||
94, // ^
|
||||
38, // &
|
||||
42, // *
|
||||
40, // (
|
||||
41, // )
|
||||
95, // _
|
||||
43, // +
|
||||
0,
|
||||
0,
|
||||
81, // Q
|
||||
87,
|
||||
69,
|
||||
82,
|
||||
84,
|
||||
89,
|
||||
85,
|
||||
73,
|
||||
79,
|
||||
80, // P
|
||||
123, // {
|
||||
125, // }
|
||||
0,
|
||||
10,
|
||||
65, // A
|
||||
83,
|
||||
68,
|
||||
70,
|
||||
71,
|
||||
72,
|
||||
74,
|
||||
75,
|
||||
76, // L
|
||||
58, // :
|
||||
34, // "
|
||||
126, // ~
|
||||
0,
|
||||
124, // |
|
||||
90, // Z
|
||||
88,
|
||||
67,
|
||||
86,
|
||||
66,
|
||||
78,
|
||||
77, // M
|
||||
60, // <
|
||||
62, // >
|
||||
63, // ?
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
32, // SPACE
|
||||
};
|
||||
|
||||
Device::PS2Keyboard* Device::PS2Keyboard::driver;
|
||||
|
||||
using namespace Device;
|
||||
|
||||
void IRQRedirect(INTERRUPT_FRAME* irq) {
|
||||
UNUSED(irq);
|
||||
PS2Keyboard::driver->InterruptHandler();
|
||||
}
|
||||
|
||||
PS2Keyboard::PS2Keyboard() {
|
||||
driver = this;
|
||||
}
|
||||
|
||||
void PS2Keyboard::setState(bool state, uint8_t key) {
|
||||
keyStates[key] = state;
|
||||
|
||||
if(state)
|
||||
lastPress = key;
|
||||
else
|
||||
lastPress = 0;
|
||||
|
||||
if(callback != nullptr)
|
||||
callback[key] = state;
|
||||
}
|
||||
|
||||
bool PS2Keyboard::isPressed(uint8_t key) const {
|
||||
return keyStates[key];
|
||||
}
|
||||
|
||||
void PS2Keyboard::Init() {
|
||||
Device::RegisterDevice(this);
|
||||
buffer.reserve(100);
|
||||
|
||||
for (size_t idx = 0; idx < 128; idx++) {
|
||||
keyStates[idx] = false;
|
||||
}
|
||||
|
||||
InstallIRQ(1, IRQRedirect);
|
||||
}
|
||||
|
||||
void PS2Keyboard::InterruptHandler() {
|
||||
uint8_t state = ReadPort(0x64, 1);
|
||||
|
||||
// while keyboard has input and the buffer is not empty
|
||||
while (state & 1 && !(state & 0x20)) {
|
||||
uint8_t keycode = ReadPort(0x60, 1);
|
||||
uint8_t scancode = keycode & 0x7f;
|
||||
uint8_t keystate = !(keycode & 0x80);
|
||||
|
||||
if (keystate)
|
||||
SerialPrintf("[ KEY] %c pressed.\r\n", keys[scancode]);
|
||||
|
||||
state = ReadPort(0x64, 1);
|
||||
setState(keystate, scancode);
|
||||
KeyboardData data { keys[scancode], (char) scancode, (bool) keystate };
|
||||
buffer.emplace_back(data);
|
||||
}
|
||||
}
|
||||
|
||||
void PS2Keyboard::SetCallback(uint32_t* data) {
|
||||
callback = (uint8_t*) data;
|
||||
|
||||
for (size_t idx = 0; idx < 128; idx++) {
|
||||
callback[idx] = false;
|
||||
}
|
||||
}
|
|
@ -4,10 +4,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file provides utility functions for parsing ELF headers.
|
||||
* This exists so that the kernel can find itself for remapping,
|
||||
|
@ -92,7 +88,3 @@ int ParseKernelHeader(size_t InitrdPtr) {
|
|||
return flag;
|
||||
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,5 +1,4 @@
|
|||
#include <kernel/chroma.h>
|
||||
#include <driver/keyboard.h>
|
||||
#include <kernel/video/draw.h>
|
||||
#include <editor/main.h>
|
||||
|
||||
|
@ -11,11 +10,9 @@
|
|||
/**
|
||||
* Contains startup and setup routines for the Chroma Editor.
|
||||
*/
|
||||
static KeyboardCallback KernelHandler;
|
||||
|
||||
void Editor::StartEditor(int callbackID) {
|
||||
KernelHandler = KeyboardCallbacks[callbackID];
|
||||
|
||||
UNUSED(callbackID);
|
||||
EditorLayout layout;
|
||||
layout.ScreenHeight = PrintInfo.screenHeight;
|
||||
layout.ScreenWidth = PrintInfo.screenWidth;
|
||||
|
|
131
src/global/core-att.s
Normal file
131
src/global/core-att.s
Normal file
|
@ -0,0 +1,131 @@
|
|||
#************************
|
||||
#*** Team Kitty, 2021 ***
|
||||
#*** Chroma ***
|
||||
#************************
|
||||
|
||||
# Initial startup routines for new cores.
|
||||
# New cores start in 16 bit real mode.
|
||||
# Because of this, this is the only necessary assembler file in the OS.
|
||||
|
||||
# First, bring them up to Protected and Long mode.
|
||||
# Then enable all necessary auxiliary features.
|
||||
# Pass off to the CPP code to handle the heavy work, we just want the core running.
|
||||
|
||||
.code16
|
||||
.equ BASE, 0x1000
|
||||
|
||||
.global stack
|
||||
.extern initcpu
|
||||
|
||||
.extern coreidt
|
||||
|
||||
.extern ProtectedGDT
|
||||
.extern LongGDT
|
||||
|
||||
# 16-bit startup.
|
||||
# Initialize registers.
|
||||
# Load GDT
|
||||
# Set flags
|
||||
# Immediately jump to protected mode.
|
||||
|
||||
.global startCore
|
||||
startCore:
|
||||
cli
|
||||
mov $0x0, %ax
|
||||
mov %ax, %ds
|
||||
mov %ax, %es
|
||||
mov %ax, %fs
|
||||
mov %ax, %gs
|
||||
mov %ax, %ss
|
||||
.code64
|
||||
lgdt ProtectedGDT
|
||||
.code16
|
||||
mov %cr0, %eax
|
||||
or $0x1, %ax
|
||||
mov %eax, %cr0
|
||||
|
||||
ljmpl $0x8, $startCore32
|
||||
|
||||
.code32
|
||||
|
||||
# Protected mode setup.
|
||||
# Set page tables
|
||||
# Set PAE
|
||||
# Immediately jump to long mode.
|
||||
|
||||
.section .text
|
||||
startCore32:
|
||||
mov $0x10, %bx
|
||||
mov %bx, %ds
|
||||
mov %bx, %es
|
||||
mov %bx, %ss
|
||||
|
||||
mov $0xA000, %eax
|
||||
mov %eax, %cr3
|
||||
|
||||
mov %cr4, %eax # Enable PAE
|
||||
or $32, %eax # 1 << 5
|
||||
or $128, %eax # 1 << 7
|
||||
mov %eax, %cr4
|
||||
|
||||
mov $0xC0000080, %ecx
|
||||
rdmsr
|
||||
or $256, %eax # 1 << 8
|
||||
wrmsr
|
||||
|
||||
mov %cr0, %eax
|
||||
or $2147483648, %eax # 1 << 31
|
||||
mov %eax, %cr0
|
||||
.code64
|
||||
lgdt LongGDT
|
||||
.code32
|
||||
ljmp $0x8, $startCore64
|
||||
|
||||
# Long mode setup.
|
||||
# Prepare registers.
|
||||
# Set flags
|
||||
# Load the final GDT and IDT
|
||||
# Jump to the leave function.
|
||||
|
||||
.code64
|
||||
startCore64:
|
||||
mov $0x10, %ax
|
||||
mov %ax, %ds
|
||||
mov %ax, %es
|
||||
mov %ax, %ss
|
||||
|
||||
mov $0x0, %ax
|
||||
mov %ax, %ds
|
||||
mov %ax, %gs
|
||||
|
||||
lgdt LongGDT
|
||||
lidt coreidt
|
||||
|
||||
mov $0x0, %rbp
|
||||
push $0
|
||||
popf
|
||||
|
||||
mov (leave), %rax
|
||||
jmp leave
|
||||
|
||||
# Final setup.
|
||||
# Set some flags in registers.
|
||||
# Jump into C++ code.
|
||||
|
||||
leave:
|
||||
push %rbp
|
||||
|
||||
mov %cr0, %rax
|
||||
btr $2, %eax
|
||||
bts $1, %eax
|
||||
mov %rax, %cr0
|
||||
|
||||
mov %cr4, %rax
|
||||
bts $9, %eax
|
||||
bts $10, %eax
|
||||
mov %rax, %cr4
|
||||
|
||||
call initcpu
|
||||
|
||||
.global endCore
|
||||
endCore:
|
|
@ -1,27 +1,29 @@
|
|||
;************************
|
||||
;*** Team Kitty, 2021 ***
|
||||
;*** Chroma ***
|
||||
;************************
|
||||
.intel_syntax noprefix
|
||||
#************************
|
||||
#*** Team Kitty, 2021 ***
|
||||
#*** Chroma ***
|
||||
#************************
|
||||
|
||||
; Initial startup routines for new cores.
|
||||
; New cores start in 16 bit real mode.
|
||||
; Because of this, this is the only necessary assembler file in the OS.
|
||||
# Initial startup routines for new cores.
|
||||
# New cores start in 16 bit real mode.
|
||||
# Because of this, this is the only necessary assembler file in the OS.
|
||||
|
||||
; First, bring them up to Protected and Long mode.
|
||||
; Then enable all necessary auxiliary features.
|
||||
; Pass off to the CPP code to handle the heavy work, we just want the core running.
|
||||
# First, bring them up to Protected and Long mode.
|
||||
# Then enable all necessary auxiliary features.
|
||||
# Pass off to the CPP code to handle the heavy work, we just want the core running.
|
||||
|
||||
[bits 16]
|
||||
BASE equ 0x1000
|
||||
.intel_syntax
|
||||
|
||||
global stack
|
||||
extern initcpu
|
||||
.code16
|
||||
.equ BASE, 0x1000
|
||||
|
||||
extern coreidt
|
||||
extern coregdt
|
||||
.global stack
|
||||
.extern initcpu
|
||||
|
||||
global startCore
|
||||
startCore:
|
||||
.extern coreidt
|
||||
.extern coregdt
|
||||
|
||||
.global startCore
|
||||
cli
|
||||
mov ax, 0x0
|
||||
mov ds, ax
|
||||
|
@ -38,9 +40,9 @@ startCore:
|
|||
|
||||
jmp 0x8:(startCore32 - startCore + BASE)
|
||||
|
||||
[bits 32]
|
||||
.code32
|
||||
|
||||
section .text
|
||||
.section .text
|
||||
startCore32:
|
||||
mov bx, 0x10
|
||||
mov ds, bx
|
||||
|
@ -67,7 +69,7 @@ startCore32:
|
|||
lgdt [gdt_long - startCore + BASE]
|
||||
jmp 8:(startCore64 - startCore + BASE)
|
||||
|
||||
[bits 64]
|
||||
.code64
|
||||
startCore64:
|
||||
mov ax, 0x10
|
||||
mov ds, ax
|
||||
|
|
|
@ -1,42 +1,35 @@
|
|||
#include <kernel/chroma.h>
|
||||
#include <kernel/video/draw.h>
|
||||
#include <driver/keyboard.h>
|
||||
#include <editor/main.h>
|
||||
#include "kernel/system/acpi/rsdt.h"
|
||||
#include "kernel/system/acpi/madt.h"
|
||||
#include "driver/io/apic.h"
|
||||
#include "driver/io/ps2_keyboard.h"
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2020 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This file is the entry point to the system.
|
||||
* It dictates the order of operations of everything the kernel actually does.
|
||||
* If a function isn't fired here, directly or indirectly, it is not run.
|
||||
*/
|
||||
|
||||
static bool KernelLoaded = false;
|
||||
bool KernelLoaded = false;
|
||||
|
||||
address_space_t KernelAddressSpace;
|
||||
|
||||
|
||||
size_t KernelAddr = (size_t) &LoadAddr;
|
||||
size_t KernelEnd = (size_t) &end;
|
||||
|
||||
void PrintPressedChar(KeyboardData data);
|
||||
int CharPrinterCallbackID;
|
||||
void TrackInternalBuffer(KeyboardData data);
|
||||
void TrackInternalBuffer(Device::GenericKeyboard::KeyboardData data);
|
||||
int InternalBufferID;
|
||||
|
||||
size_t BufferLength = 0;
|
||||
char* InternalBuffer;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* C++ code! Scary!
|
||||
* This is a temporary measure to experiment with the Editor system.
|
||||
|
@ -70,9 +63,7 @@ extern "C" int Main(void) {
|
|||
PrepareCPU();
|
||||
|
||||
PCIEnumerate();
|
||||
|
||||
InitMemoryManager();
|
||||
|
||||
InitPaging();
|
||||
|
||||
Printf("Paging complete. System initialized.\n\r");
|
||||
|
@ -86,26 +77,24 @@ extern "C" int Main(void) {
|
|||
|
||||
SetForegroundColor(0x00FFFFFF);
|
||||
|
||||
CharPrinterCallbackID = SetupKBCallback(&PrintPressedChar);
|
||||
|
||||
InternalBufferID = SetupKBCallback(&TrackInternalBuffer);
|
||||
Device::APIC::driver = new Device::APIC();
|
||||
Device::PS2Keyboard::driver = new Device::PS2Keyboard();
|
||||
|
||||
ACPI::RSDP::instance->Init(0);
|
||||
ACPI::MADT::instance->Init();
|
||||
|
||||
Core::PreInit();
|
||||
|
||||
Device::APIC::driver->Init();
|
||||
Device::PS2Keyboard::driver->Init();
|
||||
|
||||
Core::Init();
|
||||
|
||||
for (;;) { }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void PrintPressedChar(KeyboardData data) {
|
||||
if (!KernelLoaded) return;
|
||||
|
||||
if (data.Pressed) {
|
||||
SerialPrintf("Key pressed: [\\%c (%x)]\r\n", data.Char, data.Scancode);
|
||||
Printf("%c", data.Char);
|
||||
} else {
|
||||
SerialPrintf("Key released: [\\%c]\r\n", data.Char);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
extern "C" void TrackInternalBuffer(KeyboardData data) {
|
||||
if (!data.Pressed) return;
|
||||
|
||||
|
@ -139,8 +128,7 @@ extern "C" void TrackInternalBuffer(KeyboardData data) {
|
|||
InternalBuffer[BufferLength] = data.Char;
|
||||
BufferLength++;
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
extern "C" void SomethingWentWrong(const char* Message) {
|
||||
SerialPrintf("Assertion failed! %s\r\n", Message);
|
||||
|
|
|
@ -27,10 +27,6 @@
|
|||
|
||||
#include <lainlib/lainlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*-- PRIVATE -----------------------------------------------------------------*/
|
||||
|
||||
/* Internal definitions */
|
||||
|
@ -191,8 +187,4 @@ lzg_uint32_t LZG_Decode(const unsigned char *in, lzg_uint32_t insize,
|
|||
return 0;
|
||||
else
|
||||
return decodedSize;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -8,10 +8,6 @@
|
|||
*** Lainlib ***
|
||||
************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This file handles all the logic for interfacing with the E1000 networking device.
|
||||
* This card is labelled either the Intel I217, or Intel Gigabit 82577LM.
|
||||
|
@ -355,7 +351,3 @@ int E1000Send(e1000_device_t* Device, const void* Data, uint16_t Length) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -5,9 +5,6 @@
|
|||
*** Lainlib ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct mac_address {
|
||||
uint8_t MAC[6];
|
||||
|
@ -25,7 +22,3 @@ struct ethernet_packet {
|
|||
uint16_t Type;
|
||||
uint8_t Payload[];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,8 +1,5 @@
|
|||
#include <lainlib/list/list.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void ListAdd(list_entry_t* Head, list_entry_t* New) {
|
||||
New->Next = Head->Next;
|
||||
|
@ -29,7 +26,3 @@ void ListRemove(list_entry_t* Entry) {
|
|||
bool ListIsEmpty(list_entry_t* Head) {
|
||||
return Head->Next == Head;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -2,14 +2,12 @@
|
|||
|
||||
#define PAUSE __asm__ __volatile__("pause")
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void TicketLock(ticketlock_t* Lock) {
|
||||
size_t Ticket = __atomic_fetch_add(&Lock->NextTicket, 1, __ATOMIC_RELAXED);
|
||||
__sync_synchronize();
|
||||
while(__atomic_load_8(&Lock->NowServing, __ATOMIC_ACQUIRE) != Ticket) {
|
||||
while (__atomic_load_8(&Lock->NowServing, __ATOMIC_ACQUIRE) != Ticket) {
|
||||
PAUSE;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +15,8 @@ void TicketLock(ticketlock_t* Lock) {
|
|||
bool TicketAttemptLock(ticketlock_t* Lock) {
|
||||
size_t Ticket = __atomic_load_8(&Lock->NowServing, __ATOMIC_RELAXED);
|
||||
__sync_synchronize();
|
||||
return __atomic_compare_exchange_8(&Lock->NowServing, &Ticket, Ticket + 1, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED);
|
||||
return __atomic_compare_exchange_8(&Lock->NowServing, &Ticket, Ticket + 1, false, __ATOMIC_ACQUIRE,
|
||||
__ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
void TicketUnlock(ticketlock_t* Lock) {
|
||||
|
@ -26,6 +25,4 @@ void TicketUnlock(ticketlock_t* Lock) {
|
|||
__atomic_store_8(&Lock->NowServing, NextTicket, __ATOMIC_RELEASE);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -7,10 +7,6 @@
|
|||
*** Lainlib ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
size_t strlen(const char* String) {
|
||||
size_t Len = 0;
|
||||
while(String[Len] != '\0') {
|
||||
|
@ -28,7 +24,3 @@ bool strcmp(char* a, const char* b) {
|
|||
bI++;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
6
src/lainlib/vector/vector.cpp
Normal file
6
src/lainlib/vector/vector.cpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include <lainlib/lainlib.h>
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2022 ***
|
||||
*** Lainlib ***
|
||||
***********************/
|
|
@ -18,8 +18,8 @@ size_t MADT::GetEndOfTable() {
|
|||
return ((size_t) &Header->Header) + Header->Header.Length;
|
||||
}
|
||||
|
||||
void MADT::Initialize() {
|
||||
SerialPrintf("[ACPI] Loading Multiple APIC Descriptor Tables..");
|
||||
void MADT::Init() {
|
||||
SerialPrintf("[ ACPI] Loading Multiple APIC Descriptor Tables..\r\n");
|
||||
Address = ACPI::RSDP::instance->FindEntry("APIC");
|
||||
Header = reinterpret_cast<MADTHeader*>(Address);
|
||||
|
||||
|
@ -40,6 +40,7 @@ MADT::IOAPICEntry** MADT::GetIOApicEntries() {
|
|||
|
||||
if (table->Type == MADT::Type::IOAPIC) {
|
||||
MADT::IOAPICEntry* io_apic = reinterpret_cast<MADT::IOAPICEntry*>(table);
|
||||
MapVirtualPage(&KernelAddressSpace, io_apic->Address, io_apic->Address, 3);
|
||||
entries[count] = (MADT::IOAPICEntry*) ((size_t) io_apic);
|
||||
count++;
|
||||
}
|
||||
|
|
|
@ -61,23 +61,28 @@ void* RSDP::GetFACP(RSDT* Root) {
|
|||
|
||||
void RSDP::Init(size_t RSDP) {
|
||||
UNUSED(RSDP);
|
||||
SerialPrintf("[ACPI] Loading ACPI subsystem..");
|
||||
SerialPrintf("[ ACPI] Loading ACPI subsystem..\r\n");
|
||||
|
||||
Descriptor = (DescriptorV2*) GetRSDP();
|
||||
Table = (RSDT *) TO_DIRECT(Descriptor->Header.RSDT);
|
||||
|
||||
SerialPrintf("[RSDP] Dumping RSDT..");
|
||||
auto* table = reinterpret_cast<RSDP::RSDT*>(TO_DIRECT(Descriptor->Header.RSDT));
|
||||
size_t entries = (table->Header.Length - sizeof(table->Header)) / 4;
|
||||
|
||||
SerialPrintf("[ RSDP] Dumping RSDT. Table at 0x%p..\r\n", (size_t) Table);
|
||||
size_t entries = (Table->Header.Length - sizeof(Table->Header)) / 4;
|
||||
SerialPrintf("[ RSDP] Found %u entries.\r\n", entries);
|
||||
|
||||
// For each entry: if valid, search for the specified name.
|
||||
for (size_t i = 0; i < entries; i++) {
|
||||
if (table->OtherSDTs[i] == 0x0)
|
||||
if (Table->OtherSDTs[i] == 0x0)
|
||||
continue;
|
||||
|
||||
ACPIHeader* header = reinterpret_cast<ACPIHeader*>(table->OtherSDTs[i]);
|
||||
SerialPrintf("[RSDP] Entry %d: Signature %.4s, OEM %.6s\n", i, header->Signature, header->OEMID);
|
||||
ACPIHeader* header = (ACPIHeader*) ((size_t) 0 + (uint32_t) Table->OtherSDTs[i]);
|
||||
char signature[5];
|
||||
memcpy(signature, header->Signature, 4);
|
||||
signature[4] = '\0';
|
||||
char oem[7];
|
||||
memcpy(oem, header->OEMID, 6);
|
||||
oem[6] = '\0';
|
||||
SerialPrintf("[ RSDP] Entry %d: Signature %s, OEM %s\n", i, signature, oem);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,17 +7,14 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
extern size_t startCore;
|
||||
extern size_t endCore;
|
||||
|
||||
int Cores = 0;
|
||||
volatile bool Ready = false;
|
||||
|
||||
Core Core::Processors[Constants::Core::MAX_CORES];
|
||||
Core* Core::Processors[Constants::Core::MAX_CORES];
|
||||
TSS64 Tasks[Constants::Core::MAX_CORES];
|
||||
ACPI::MADT::LAPICEntry* LAPICs[Constants::Core::MAX_CORES];
|
||||
|
||||
extern "C" void initcpu() {
|
||||
extern "C" [[noreturn]] void initcpu() {
|
||||
// Init APIC
|
||||
WriteModelSpecificRegister(0x1B, (ReadModelSpecificRegister(0x1B) | 0x800) & ~(1 << 10));
|
||||
Device::APIC::driver->Enable();
|
||||
|
@ -25,7 +22,6 @@ extern "C" void initcpu() {
|
|||
__asm__ __volatile__("mov %%fs, %0" : : "r" (Device::APIC::driver->GetCurrentCore()) : );
|
||||
|
||||
SerialPrintf("[CORE] Core %d ready.\r\n", Device::APIC::driver->GetCurrentCore());
|
||||
// TODO: New GDT
|
||||
__asm__ __volatile__("cli");
|
||||
Ready = true;
|
||||
__asm__ __volatile__("sti");
|
||||
|
@ -38,22 +34,29 @@ Core::Core(size_t APIC, size_t ID) {
|
|||
GetCore(ID)->LocalAPIC = APIC;
|
||||
|
||||
Bootstrap();
|
||||
SetupData(ID);
|
||||
//SetupData(ID);
|
||||
|
||||
Device::APIC::driver->InitializeCore(APIC, CORE_BOOTSTRAP);
|
||||
Device::APIC::driver->InitializeCore(APIC, reinterpret_cast<size_t>(initcpu));
|
||||
|
||||
while (Ready != true) {
|
||||
__asm__ ("nop");
|
||||
while (!Ready) {
|
||||
__asm__ __volatile__ ("nop");
|
||||
}
|
||||
|
||||
Ready = false;
|
||||
}
|
||||
|
||||
void Core::PreInit() {
|
||||
for (size_t i = 0; i < Constants::Core::MAX_CORES; i++) {
|
||||
Processors[i] = new Core();
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Init() {
|
||||
|
||||
using namespace ACPI;
|
||||
|
||||
Ready = false;
|
||||
SerialPrintf("[CORE] Enabling Multiprocessing\n");
|
||||
SerialPrintf("[ CORE] Enabling Multiprocessing\r\n");
|
||||
|
||||
memset(Tasks, 0, Constants::Core::MAX_CORES * sizeof(TSS64));
|
||||
for (size_t i = 0; i < Constants::Core::MAX_CORES; i++)
|
||||
|
@ -65,8 +68,6 @@ void Core::Init() {
|
|||
|
||||
// While there are more entries in the table..
|
||||
while ((size_t) table < MADT::instance->GetEndOfTable()) {
|
||||
// Move to the next entry (by skipping the length of the current entry)
|
||||
table = (MADT::RecordTableEntry*) (((size_t) table) + table->Length);
|
||||
// Check for a LAPIC record (which indicates a unique physical core)
|
||||
if (table->Type == MADT::Type::LAPIC) {
|
||||
// Find the data for the LAPIC with a reinterpret
|
||||
|
@ -79,48 +80,30 @@ void Core::Init() {
|
|||
// Move to the next core if there is one.
|
||||
Cores++;
|
||||
}
|
||||
// Move to the next entry (by skipping the length of the current entry)
|
||||
table = (MADT::RecordTableEntry*) (((size_t) table) + table->Length);
|
||||
}
|
||||
|
||||
SerialPrintf("[CORE] Found %d cores.\n", Cores);
|
||||
|
||||
SerialPrintf("[ CORE] Found %d core(s).\r\n", Cores);
|
||||
if (Cores > 1)
|
||||
SerialPrintf("[CORE] Bringing up other cores.\n");
|
||||
SerialPrintf("[ CORE] Bringing up other cores.\r\n");
|
||||
|
||||
// For each non-bootstrap core, initialize the necessary data and populate the array.
|
||||
for (int i = 0; i < Cores; i++) {
|
||||
SerialPrintf("[CORE] Enabling core %d.\n", i);
|
||||
if (Device::APIC::driver->GetCurrentCore() != LAPICs[i]->Core)
|
||||
Processors[i] = Core(LAPICs[i]->APIC, LAPICs[i]->Core);
|
||||
|
||||
if (Device::APIC::driver->GetCurrentCore() != LAPICs[i]->Core) {
|
||||
SerialPrintf("[ CORE] Enabling core %d.\r\n", i);
|
||||
delete Processors[i];
|
||||
Core* c = new Core(LAPICs[i]->APIC, LAPICs[i]->Core);
|
||||
Processors[i] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Bootstrap() {
|
||||
size_t coreStarterLen = endCore - startCore;
|
||||
|
||||
for (size_t i = 0; i < coreStarterLen + 2; i += PAGE_SIZE)
|
||||
MapVirtualPage(AddressSpace, CORE_BOOTSTRAP + i, CORE_BOOTSTRAP + i, 0);
|
||||
|
||||
memcpy((void*) CORE_BOOTSTRAP, &startCore, coreStarterLen);
|
||||
// TODO
|
||||
}
|
||||
|
||||
void Core::SetupData(size_t Core) {
|
||||
// Write page tables
|
||||
GetCore(Core)->AddressSpace->PML4 = GetCurrent()->AddressSpace->PML4;
|
||||
*((size_t*) Initialization::PAGETABLES) = (size_t) GetCore(Core)->AddressSpace->PML4;
|
||||
|
||||
// Prepare stack
|
||||
memset(GetCore(Core)->StackData, 0, Constants::Core::STACK_SIZE);
|
||||
*((size_t*) Initialization::STACK) = (size_t) GetCore(Core)->StackData + Constants::Core::STACK_SIZE;
|
||||
|
||||
// GDT = 0x680
|
||||
// IDT = 0x690
|
||||
__asm__ __volatile__("sgdt (0x680)\n sidt (0x690)");
|
||||
|
||||
// Set startup address
|
||||
*((size_t*) Initialization::STARTUP) = (size_t) &initcpu;
|
||||
}
|
||||
|
||||
|
||||
void Core::StackTrace(size_t Cycles) {
|
||||
StackFrame* stack;
|
||||
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
#include <kernel/chroma.h>
|
||||
#include <kernel/system/interrupts.h>
|
||||
#include "driver/io/apic.h"
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2020 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This class provides functions for setting up and preparing the CPU for the things the kernel will do.
|
||||
* Mainly, it allows you to:
|
||||
*
|
||||
|
@ -44,6 +41,11 @@ __attribute__((aligned(64))) static volatile size_t InitGDT[5] = {
|
|||
0
|
||||
};
|
||||
|
||||
__attribute__((aligned(64))) static DESC_TBL CoreGDT = {
|
||||
.Limit = sizeof(InitGDT),
|
||||
.Base = (size_t) InitGDT
|
||||
};
|
||||
|
||||
__attribute__((aligned(64))) static volatile TSS64 TSSEntries;
|
||||
|
||||
__attribute__((aligned(64))) static volatile IDT_GATE IDTEntries[256];
|
||||
|
@ -65,53 +67,17 @@ static void RefreshCS() {
|
|||
|
||||
|
||||
void PrepareCPU() {
|
||||
|
||||
SetupInitialGDT();
|
||||
SetupIDT();
|
||||
|
||||
//SetupExtensions();
|
||||
|
||||
InitInterrupts();
|
||||
|
||||
/* In either case, we tell the Master PIC it's been read to receive any IRQ. */
|
||||
WritePort(0x20, 0x20, 1);
|
||||
}
|
||||
|
||||
/*void SetupExtensions() {
|
||||
|
||||
// Enable SSE
|
||||
size_t CR0 = ReadControlRegister(0);
|
||||
|
||||
CR0 &= ~(1 << 2);
|
||||
CR0 |= 1;
|
||||
|
||||
WriteControlRegister(0, CR0);
|
||||
|
||||
// Enable OSXSAVE and gang
|
||||
size_t CR4 = ReadControlRegister(4);
|
||||
CR4 |= (1 << 9);
|
||||
CR4 |= (1 << 10);
|
||||
CR4 |= (1 << 18);
|
||||
|
||||
WriteControlRegister(4, CR4);
|
||||
|
||||
// Enable AVX (and AVX-512 in future)
|
||||
|
||||
CR0 = ReadExtendedControlRegister(0);
|
||||
SerialPrintf("XCR0 is currently %x.\n", CR0);
|
||||
CR0 |= (1 << 0);
|
||||
CR0 |= (1 << 1);
|
||||
CR0 |= (1 << 2);
|
||||
|
||||
CR0 |= (1 << 5);
|
||||
CR0 |= (1 << 6);
|
||||
CR0 |= (1 << 7);
|
||||
|
||||
SerialPrintf("About to write xcr0: %x\n", CR0);
|
||||
WriteExtendedControlRegister(0, CR0);
|
||||
}
|
||||
*/
|
||||
|
||||
void SetupInitialGDT() {
|
||||
DESC_TBL GDTData;
|
||||
size_t TSSBase = (uint64_t) (&TSSEntries);
|
||||
|
||||
uint16_t TSSLower = (uint16_t) TSSBase;
|
||||
|
@ -119,15 +85,13 @@ void SetupInitialGDT() {
|
|||
uint8_t TSSMid2 = (uint8_t) (TSSBase >> 24);
|
||||
uint32_t TSSHigher = (uint32_t) (TSSBase >> 32);
|
||||
|
||||
GDTData.Limit = sizeof(InitGDT) - 1;
|
||||
GDTData.Base = (size_t) InitGDT;
|
||||
|
||||
((TSS_ENTRY*) (&((GDT_ENTRY*) InitGDT)[3]))->BaseLow = TSSLower;
|
||||
((TSS_ENTRY*) (&((GDT_ENTRY*) InitGDT)[3]))->BaseMid1 = TSSMid1;
|
||||
((TSS_ENTRY*) (&((GDT_ENTRY*) InitGDT)[3]))->BaseMid2 = TSSMid2;
|
||||
((TSS_ENTRY*) (&((GDT_ENTRY*) InitGDT)[3]))->BaseHigh = TSSHigher;
|
||||
|
||||
WriteGDT(GDTData);
|
||||
WriteGDT(CoreGDT);
|
||||
WriteTSR(3 << 3);
|
||||
RefreshCS();
|
||||
}
|
||||
|
@ -262,13 +226,10 @@ void SetupIDT() {
|
|||
SetISR(46, (size_t) IRQ14Handler);
|
||||
SetISR(47, (size_t) IRQ15Handler);
|
||||
|
||||
|
||||
//TODO: ISRs 32 to 256
|
||||
for (size_t i = 0; i < 32; i++) {
|
||||
IRQHandlers[i] = {{}, 0 };
|
||||
}
|
||||
|
||||
WriteIDT(IDTData);
|
||||
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
}
|
55
src/system/extern/extern_defs.cpp
vendored
Normal file
55
src/system/extern/extern_defs.cpp
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
/************************
|
||||
*** Team Kitty, 2022 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#include <kernel/system/descriptors.h>
|
||||
|
||||
/**
|
||||
* Contains definitions that are used by external files.
|
||||
* That means, independent programs or assembler files.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The template GDT entry for a newly initialized core.
|
||||
* Protected Mode.
|
||||
* TODO: Document what the entries here are.
|
||||
*/
|
||||
|
||||
__attribute__((aligned(64))) size_t ProtectedGDTEntry[3] = {
|
||||
0,
|
||||
0x00CF9A000000FFFF,
|
||||
0x00CF92000000FFFF
|
||||
};
|
||||
|
||||
/**
|
||||
* The GDT table value to be loaded into each newly initialized core.
|
||||
* Protected Mode.
|
||||
*/
|
||||
|
||||
DESC_TBL ProtectedGDT = {
|
||||
.Limit = sizeof(ProtectedGDTEntry) - 1,
|
||||
.Base = (size_t) &ProtectedGDTEntry
|
||||
};
|
||||
|
||||
/**
|
||||
* The template GDT entry for a newly initialized core.
|
||||
* Long Mode.
|
||||
* TODO: Document what the entries here are.
|
||||
*/
|
||||
__attribute__((aligned(64))) size_t LongGDTEntry[3] = {
|
||||
0,
|
||||
0x00AF98000000FFFF,
|
||||
0x00CF92000000FFFF
|
||||
};
|
||||
|
||||
/**
|
||||
* The GDT table value to be loaded into each newly initialized core.
|
||||
* Long Mode.
|
||||
*/
|
||||
|
||||
DESC_TBL LongGDT = {
|
||||
.Limit = sizeof(LongGDTEntry) - 1,
|
||||
.Base = (size_t) &LongGDTEntry
|
||||
};
|
||||
|
|
@ -2,16 +2,13 @@
|
|||
#include <kernel/video/draw.h>
|
||||
#include <kernel/system/interrupts.h>
|
||||
#include <stdbool.h>
|
||||
#include "driver/io/apic.h"
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2020 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This file contains all of the ISR and IRQ
|
||||
* (Interrupt Service Request) functions.
|
||||
*
|
||||
|
@ -41,6 +38,10 @@ extern "C" {
|
|||
* these having a size_t input as an error code.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char* ExceptionStrings[] = {
|
||||
"Division by Zero",
|
||||
"Debug",
|
||||
|
@ -76,15 +77,7 @@ const char* ExceptionStrings[] = {
|
|||
"Reserved"
|
||||
};
|
||||
|
||||
typedef void (* IRQHandler)(INTERRUPT_FRAME* Frame);
|
||||
|
||||
IRQHandler IRQ_Handlers[16] = {
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
|
||||
typedef unsigned long long int uword_t;
|
||||
IRQHandlerData IRQHandlers[32];
|
||||
|
||||
/* All of the ISR routines call this function for now.
|
||||
! This function is NOT leaf, and it might clobber the stack.
|
||||
|
@ -124,114 +117,83 @@ void ISR_Error_Common(INTERRUPT_FRAME* Frame, size_t ErrorCode, size_t Exception
|
|||
which was set up earlier by irq_install.*/
|
||||
void IRQ_Common(INTERRUPT_FRAME* Frame, size_t Interrupt) {
|
||||
// First we need to define a function pointer..
|
||||
void (* Handler)(INTERRUPT_FRAME* Frame);
|
||||
IRQHandlerData handler;
|
||||
|
||||
/* We set all uninitialized routines to 0, so the if(handler) check here allows us to
|
||||
safely tell whether we've actually got something for this IRQ. */
|
||||
Handler = IRQ_Handlers[Interrupt];
|
||||
// If there's something there,
|
||||
if (Handler) {
|
||||
SerialPrintf("[ IRQ] IRQ %d raised!\r\n", Interrupt);
|
||||
// Call the handler.
|
||||
Handler(Frame);
|
||||
handler = IRQHandlers[Interrupt];
|
||||
if (handler.numHandlers > 0) {
|
||||
//SerialPrintf("[ IRQ] IRQ %d raised!\r\n", Interrupt);
|
||||
// Call the handlers
|
||||
for (size_t i = 0; i < handler.numHandlers; i++)
|
||||
handler.handlers[i](Frame);
|
||||
}
|
||||
/* The Slave PIC must be told it's been read in order to receive another 8+ IRQ. */
|
||||
if (Interrupt > 7)
|
||||
WritePort(0xA0, 0x20, 1);
|
||||
|
||||
/* In either case, we tell the Master PIC it's been read to receive any IRQ. */
|
||||
WritePort(0x20, 0x20, 1);
|
||||
|
||||
Device::APIC::driver->SendEOI();
|
||||
}
|
||||
|
||||
#define PIC1 0x20 /* IO base address for master PIC */
|
||||
#define PIC2 0xA0 /* IO base address for slave PIC */
|
||||
#define PIC1_COMMAND PIC1
|
||||
#define PIC1_DATA (PIC1+1)
|
||||
#define PIC2_COMMAND PIC2
|
||||
#define PIC2_DATA (PIC2+1)
|
||||
|
||||
#define ICW1_ICW4 0x01 /* ICW4 (not) needed */
|
||||
#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
|
||||
#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
|
||||
#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
|
||||
#define ICW1_INIT 0x10 /* Initialization - required! */
|
||||
|
||||
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
|
||||
#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
|
||||
#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
|
||||
#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
|
||||
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
|
||||
|
||||
/* However, in order to actually be able to receive IRQs, we need to remap the PICs. */
|
||||
void RemapIRQControllers() {
|
||||
/* 0x20 is the Master PIC,
|
||||
0xA0 is the Slave PIC. */
|
||||
WritePort(0x20, 0x11, 1);
|
||||
WritePort(0xA0, 0x11, 1);
|
||||
WritePort(0x21, 0x20, 1);
|
||||
WritePort(0xA1, 0x28, 1);
|
||||
WritePort(0x21, 0x04, 1);
|
||||
WritePort(0xA1, 0x02, 1);
|
||||
WritePort(0x21, 0x01, 1);
|
||||
WritePort(0xA1, 0x01, 1);
|
||||
WritePort(0x21, 0x0, 1);
|
||||
WritePort(0xA1, 0x0, 1);
|
||||
|
||||
WritePort(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4, 1); // starts the initialization sequence (in cascade mode)
|
||||
WritePort(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4, 1);
|
||||
WritePort(PIC1_DATA, 32, 1); // ICW2: Master PIC vector offset
|
||||
WritePort(PIC2_DATA, 32 + 8, 1); // ICW2: Slave PIC vector offset
|
||||
WritePort(PIC1_DATA, 4, 1); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
|
||||
WritePort(PIC2_DATA, 2, 1); // ICW3: tell Slave PIC its cascade identity (0000 0010)
|
||||
|
||||
WritePort(PIC1_DATA, ICW4_8086, 1);
|
||||
WritePort(PIC2_DATA, ICW4_8086, 1);
|
||||
|
||||
WritePort(PIC1_DATA, 0xFF, 1); // restore saved masks.
|
||||
WritePort(PIC2_DATA, 0xFF, 1);
|
||||
|
||||
}
|
||||
|
||||
/* In order to actually handle the IRQs, though, we need to tell the kernel *where* the handlers are. */
|
||||
/* A simple wrapper that adds a function pointer to the IRQ array. */
|
||||
void InstallIRQ(int IRQ, void (* Handler)(INTERRUPT_FRAME* Frame)) {
|
||||
IRQ_Handlers[IRQ] = Handler;
|
||||
size_t InstallIRQ(int IRQ, IRQHandler Handler) {
|
||||
if (IRQ <= 32) {
|
||||
Device::APIC::driver->Set(Core::GetCurrent()->ID, IRQ, 1);
|
||||
|
||||
IRQHandlerData* target = &IRQHandlers[IRQ];
|
||||
if (target->numHandlers < 7) {
|
||||
target->handlers[target->numHandlers] = Handler;
|
||||
target->numHandlers++;
|
||||
return target->numHandlers;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A simple wrapper that unlinks a function pointer, rendering the IRQ unused. */
|
||||
void UninstallIRQHandler(int IRQ) {
|
||||
IRQ_Handlers[IRQ] = NULL; // 0 is used in the common check to make sure that the function is callable.
|
||||
void UninstallIRQHandler(int IRQ, size_t ID) {
|
||||
IRQHandlers[IRQ].handlers[ID] = NULL; // 0 is used in the common check to make sure that the function is callable.
|
||||
// This removes this IRQ from that check, ergo the function will no longer be called.
|
||||
}
|
||||
|
||||
void EmptyIRQ(INTERRUPT_FRAME* frame) {
|
||||
|
||||
UNUSED(frame);
|
||||
|
||||
// Flash the borders green, then back to blue
|
||||
SetForegroundColor(0x0000FF00);
|
||||
for (size_t y = 0; y < bootldr.fb_height; y++) {
|
||||
for (size_t x = 0; x < 20; x++) {
|
||||
DrawPixel(x, y);
|
||||
}
|
||||
|
||||
for (size_t x = (bootldr.fb_width - 20); x < bootldr.fb_width; x++) {
|
||||
DrawPixel(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t x = 0; x < bootldr.fb_width; x++) {
|
||||
for (size_t y = 0; y < 20; y++) {
|
||||
DrawPixel(x, y);
|
||||
}
|
||||
|
||||
for (size_t y = (bootldr.fb_height - 20); y < bootldr.fb_height; y++) {
|
||||
DrawPixel(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 100000; i++) { }
|
||||
|
||||
SetForegroundColor(0x000000FF);
|
||||
for (size_t y = 0; y < bootldr.fb_height; y++) {
|
||||
for (size_t x = 0; x < 20; x++) {
|
||||
DrawPixel(x, y);
|
||||
}
|
||||
|
||||
for (size_t x = (bootldr.fb_width - 20); x < bootldr.fb_width; x++) {
|
||||
DrawPixel(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t x = 0; x < bootldr.fb_width; x++) {
|
||||
for (size_t y = 0; y < 20; y++) {
|
||||
DrawPixel(x, y);
|
||||
}
|
||||
|
||||
for (size_t y = (bootldr.fb_height - 20); y < bootldr.fb_height; y++) {
|
||||
DrawPixel(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void KeyboardCallback(INTERRUPT_FRAME* frame) {
|
||||
UNUSED(frame);
|
||||
|
||||
uint8_t msg = ReadPort(0x60, 1);
|
||||
|
||||
UpdateKeyboard(msg);
|
||||
|
||||
WaitFor8042();
|
||||
}
|
||||
|
||||
void InitInterrupts() {
|
||||
size_t RFLAGS = ReadControlRegister('f');
|
||||
|
||||
|
@ -239,11 +201,6 @@ void InitInterrupts() {
|
|||
WriteControlRegister('f', RFLAGS | (1 << 9));
|
||||
}
|
||||
|
||||
|
||||
InstallIRQ(1, &KeyboardCallback);
|
||||
|
||||
Send8042(0xF002);
|
||||
|
||||
__asm__ __volatile__("sti");
|
||||
}
|
||||
|
||||
|
@ -368,7 +325,7 @@ __attribute__((interrupt)) void ISR14Handler(INTERRUPT_FRAME* Frame, size_t Erro
|
|||
|
||||
SerialPrintf("[FAULT] } at address\n[FAULT] 0x%p\r\n\n", ReadControlRegister(2));
|
||||
|
||||
Core::GetCurrent()->StackTrace(6);
|
||||
Core::GetCurrent()->StackTrace(10);
|
||||
ISR_Error_Common(Frame, ErrorCode, 14); // Page Fault
|
||||
}
|
||||
|
||||
|
@ -510,6 +467,6 @@ __attribute__((interrupt)) void IRQ15Handler(INTERRUPT_FRAME* Frame) {
|
|||
IRQ_Common(Frame, 15);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,6 +1,4 @@
|
|||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <kernel/system/memory.h>
|
||||
#include <kernel/system/io.h>
|
||||
|
||||
|
@ -9,10 +7,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/************************************************
|
||||
* C O N S T A N T S A N D M A C R O S
|
||||
*************************************************/
|
||||
|
@ -138,10 +132,6 @@ static void BlockSetSize(block_header_t* Block, size_t Size) {
|
|||
Block->Size = Size | (Block->Size & (BLOCK_FREE | BLOCK_PREV_FREE));
|
||||
}
|
||||
|
||||
static int BlockIsLast(const block_header_t* Block) {
|
||||
return BlockSize(Block) == 0;
|
||||
}
|
||||
|
||||
static int BlockIsFree(const block_header_t* Block) {
|
||||
return CAST(int, Block->Size & BLOCK_FREE);
|
||||
}
|
||||
|
@ -179,13 +169,11 @@ static block_header_t* OffsetToBlock(const void* Address, size_t Size) {
|
|||
}
|
||||
|
||||
static block_header_t* BlockGetPrevious(const block_header_t* Current) {
|
||||
ASSERT(BlockPrevIsFree(Current), "BlockGetPrevious: Previous block NOT free");
|
||||
return Current->LastBlock;
|
||||
}
|
||||
|
||||
static block_header_t* BlockGetNext(const block_header_t* Current) {
|
||||
block_header_t* NextBlock = OffsetToBlock(WhereBlock(Current), BlockSize(Current) - BLOCK_OVERHEAD);
|
||||
ASSERT(!BlockIsLast(Current), "BlockGetNext: Current block is last!");
|
||||
return NextBlock;
|
||||
}
|
||||
|
||||
|
@ -212,17 +200,17 @@ static void BlockMarkUsed(block_header_t* Current) {
|
|||
* P O I N T E R A L I G N M E N T F U N C T I O N S
|
||||
************************************************************************************/
|
||||
|
||||
size_t AlignUpwards(size_t Pointer, size_t Alignment) {
|
||||
extern "C" size_t AlignUpwards(size_t Pointer, size_t Alignment) {
|
||||
//ASSERT(((Alignment & (Alignment - 1)) == 0));
|
||||
return (Pointer + (Alignment - 1)) & ~(Alignment - 1);
|
||||
}
|
||||
|
||||
size_t AlignDownwards(size_t Pointer, size_t Alignment) {
|
||||
extern "C" size_t AlignDownwards(size_t Pointer, size_t Alignment) {
|
||||
//ASSERT((Alignment & (Alignment - 1) == 0));
|
||||
return (Pointer - (Pointer & (Alignment - 1)));
|
||||
}
|
||||
|
||||
void* AlignPointer(const void* Pointer, size_t Alignment) {
|
||||
extern "C" void* AlignPointer(const void* Pointer, size_t Alignment) {
|
||||
|
||||
const ptrdiff_t AlignedPointer =
|
||||
((
|
||||
|
@ -230,7 +218,6 @@ void* AlignPointer(const void* Pointer, size_t Alignment) {
|
|||
+ (Alignment - 1))
|
||||
& ~(Alignment - 1)
|
||||
);
|
||||
ASSERT(((Alignment & (Alignment - 1)) == 0), "AlignPointer: Requested alignment not aligned!");
|
||||
|
||||
return CAST(void*, AlignedPointer);
|
||||
}
|
||||
|
@ -299,8 +286,6 @@ static block_header_t* FindSuitableBlock(allocator_control_t* Controller, int* F
|
|||
SLMap = Controller->SecondLevel_Bitmap[FirstLevel];
|
||||
}
|
||||
|
||||
ASSERT(SLMap, "FindSuitableBlock: Second level bitmap not present!");
|
||||
|
||||
SecondLevel = Alloc_FindFirstOne(SLMap);
|
||||
*SecondLevelIndex = SecondLevel;
|
||||
|
||||
|
@ -311,9 +296,6 @@ static void RemoveFreeBlock(allocator_control_t* Controller, block_header_t* Blo
|
|||
block_header_t* PreviousBlock = Block->LastFreeBlock;
|
||||
block_header_t* NextBlock = Block->NextFreeBlock;
|
||||
|
||||
ASSERT(PreviousBlock, "RemoveFreeBlock: PreviousBlock is null!");
|
||||
ASSERT(NextBlock, "RemoveFreeBlock: NextBlock is null!");
|
||||
|
||||
NextBlock->LastFreeBlock = PreviousBlock;
|
||||
PreviousBlock->NextFreeBlock = NextBlock;
|
||||
|
||||
|
@ -334,7 +316,6 @@ static void
|
|||
InsertFreeBlock(allocator_control_t* Controller, block_header_t* NewBlock, int FirstLevel, int SecondLevel) {
|
||||
block_header_t* Current = Controller->Blocks[FirstLevel][SecondLevel];
|
||||
|
||||
ASSERT(Current, "InsertFreeBlock: Current Block is null!");
|
||||
if (!Current) {
|
||||
SerialPrintf(
|
||||
"Extra info: \r\n\tFirst Level: %x Second Level: %x\r\nFirst Level bitmap: %x, Second Level bitmap: %x\r\n\tBlocks %x, BlocksAddress: %x",
|
||||
|
@ -342,16 +323,12 @@ InsertFreeBlock(allocator_control_t* Controller, block_header_t* NewBlock, int F
|
|||
Controller->Blocks, Controller->Blocks[FirstLevel][SecondLevel]);
|
||||
for (;;) { }
|
||||
}
|
||||
ASSERT(NewBlock, "InsertFreeBlock: New Block is null!");
|
||||
|
||||
NewBlock->NextFreeBlock = Current;
|
||||
NewBlock->LastFreeBlock = &Controller->BlockNull;
|
||||
|
||||
Current->LastFreeBlock = NewBlock;
|
||||
|
||||
ASSERT(WhereBlock(NewBlock) == AlignPointer(WhereBlock(NewBlock), ALIGN_SIZE),
|
||||
"InsertFreeBlock: Current block is not memory aligned!");
|
||||
|
||||
Controller->Blocks[FirstLevel][SecondLevel] = NewBlock;
|
||||
Controller->FirstLevel_Bitmap |= (1U << FirstLevel);
|
||||
Controller->SecondLevel_Bitmap[FirstLevel] |= (1U << SecondLevel);
|
||||
|
@ -380,15 +357,8 @@ static block_header_t* SplitBlock(block_header_t* Block, size_t NewSize) {
|
|||
|
||||
const size_t RemainingSize = BlockSize(Block) - (NewSize + BLOCK_OVERHEAD);
|
||||
|
||||
ASSERT(WhereBlock(Overlap) == AlignPointer(WhereBlock(Overlap), ALIGN_SIZE),
|
||||
"SplitBlock: Requested size results in intermediary block which is not aligned!");
|
||||
|
||||
ASSERT(BlockSize(Block) == RemainingSize + NewSize + BLOCK_OVERHEAD, "SplitBlock: Maths error!");
|
||||
|
||||
BlockSetSize(Overlap, RemainingSize);
|
||||
|
||||
ASSERT(BlockSize(Overlap) >= BLOCK_MIN_SIZE, "SplitBlock: Requested size results in new block that is too small!");
|
||||
|
||||
BlockSetSize(Block, NewSize);
|
||||
|
||||
BlockMarkFree(Overlap);
|
||||
|
@ -397,7 +367,6 @@ static block_header_t* SplitBlock(block_header_t* Block, size_t NewSize) {
|
|||
}
|
||||
|
||||
static block_header_t* MergeBlockDown(block_header_t* Previous, block_header_t* Block) {
|
||||
ASSERT(!BlockIsLast(Previous), "MergeBlockDown: Previous block is the last block! (Current block is first block?)");
|
||||
|
||||
Previous->Size += BlockSize(Block) + BLOCK_OVERHEAD;
|
||||
BlockLinkToNext(Previous);
|
||||
|
@ -408,8 +377,6 @@ static block_header_t* MergeEmptyBlockDown(allocator_control_t* Controller, bloc
|
|||
|
||||
if (BlockPrevIsFree(Block)) {
|
||||
block_header_t* Previous = BlockGetPrevious(Block);
|
||||
ASSERT(Previous, "MergeEmptyBlockDown: Previous block is null!");
|
||||
ASSERT(BlockIsFree(Previous), "MergeEmptyBlockDown: Previous block is free!");
|
||||
RemoveBlock(Controller, Previous);
|
||||
Block = MergeBlockDown(Previous, Block);
|
||||
}
|
||||
|
@ -419,10 +386,8 @@ static block_header_t* MergeEmptyBlockDown(allocator_control_t* Controller, bloc
|
|||
|
||||
static block_header_t* MergeNextBlockDown(allocator_control_t* Controller, block_header_t* Block) {
|
||||
block_header_t* NextBlock = BlockGetNext(Block);
|
||||
ASSERT(NextBlock, "MergeNextBlockDown: Next Block is null!");
|
||||
|
||||
if (BlockIsFree(NextBlock)) {
|
||||
ASSERT(!BlockIsLast(Block), "MergeNextBlockDown: Current block is the last block!");
|
||||
RemoveBlock(Controller, NextBlock);
|
||||
Block = MergeBlockDown(Block, NextBlock);
|
||||
}
|
||||
|
@ -431,7 +396,6 @@ static block_header_t* MergeNextBlockDown(allocator_control_t* Controller, block
|
|||
}
|
||||
|
||||
static void TrimBlockFree(allocator_control_t* Controller, block_header_t* Block, size_t Size) {
|
||||
ASSERT(BlockIsFree(Block), "TrimBlockFree: Current block is wholly free!");
|
||||
|
||||
if (CanBlockSplit(Block, Size)) {
|
||||
block_header_t* RemainingBlock = SplitBlock(Block, Size);
|
||||
|
@ -445,8 +409,6 @@ static void TrimBlockFree(allocator_control_t* Controller, block_header_t* Block
|
|||
}
|
||||
|
||||
static void TrimBlockUsed(allocator_control_t* Controller, block_header_t* Block, size_t Size) {
|
||||
ASSERT(!BlockIsFree(Block), "TrimBlockUsed: The current block is wholly used!");
|
||||
|
||||
if (CanBlockSplit(Block, Size)) {
|
||||
|
||||
block_header_t* RemainingBlock = SplitBlock(Block, Size);
|
||||
|
@ -492,7 +454,6 @@ static block_header_t* LocateFreeBlock(allocator_control_t* Controller, size_t S
|
|||
}
|
||||
|
||||
if (Block) {
|
||||
ASSERT(BlockSize(Block) >= Size, "LocateFreeBlock: Found a block that is too small!");
|
||||
RemoveFreeBlock(Controller, Block, FirstLevel, SecondLevel);
|
||||
}
|
||||
|
||||
|
@ -503,7 +464,6 @@ static void* PrepareUsedBlock(allocator_control_t* Controller, block_header_t* B
|
|||
void* Pointer = 0;
|
||||
|
||||
if (Block) {
|
||||
ASSERT(Size, "PrepareUsedBlock: Size is 0!");
|
||||
TrimBlockFree(Controller, Block, Size);
|
||||
BlockMarkUsed(Block);
|
||||
Pointer = WhereBlock(Block);
|
||||
|
@ -616,10 +576,6 @@ void RemovePoolFromAllocator(allocator_t Allocator, mempool_t Pool) {
|
|||
|
||||
int FirstLevel = 0, SecondLevel = 0;
|
||||
|
||||
ASSERT(BlockIsFree(Block), "RemovePoolFromAllocator: Current block is free!");
|
||||
ASSERT(!BlockIsFree(BlockGetNext(Block)), "RemovePoolFromAllocator: Next Block is not free!");
|
||||
ASSERT(BlockSize(BlockGetNext(Block)) == 0, "RemovePoolFromAllocator: Next block is size 0!");
|
||||
|
||||
RoundUpBlockSize(BlockSize(Block), &FirstLevel, &SecondLevel);
|
||||
RemoveFreeBlock(Controller, Block, FirstLevel, SecondLevel);
|
||||
}
|
||||
|
@ -702,8 +658,6 @@ void* AllocatorMalign(allocator_t Allocator, size_t Alignment, size_t Size) {
|
|||
|
||||
block_header_t* Block = LocateFreeBlock(Controller, AlignedSize);
|
||||
|
||||
ASSERT(sizeof(block_header_t) == BLOCK_MIN_SIZE + BLOCK_OVERHEAD, "AllocatorMalign: Maths error!");
|
||||
|
||||
if (Block) {
|
||||
void* Address = WhereBlock(Block);
|
||||
void* AlignedAddress = AlignPointer(Address, Alignment);
|
||||
|
@ -721,8 +675,6 @@ void* AllocatorMalign(allocator_t Allocator, size_t Alignment, size_t Size) {
|
|||
Gap = CAST(size_t, CAST(ptrdiff_t, AlignedAddress) - CAST(ptrdiff_t, Address));
|
||||
}
|
||||
|
||||
ASSERT(Gap >= MinimumGap, "AllocatorMalign: Maths error 2!");
|
||||
|
||||
Block = TrimBlockLeadingFree(Controller, Block, Gap);
|
||||
|
||||
}
|
||||
|
@ -735,7 +687,6 @@ void AllocatorFree(allocator_t Allocator, void* Address) {
|
|||
if (Address) {
|
||||
allocator_control_t* Controller = CAST(allocator_control_t*, Allocator);
|
||||
block_header_t* Block = WhichBlock(Address);
|
||||
ASSERT(!BlockIsFree(Block), "AllocatorFree: Attempting to free a freed block!");
|
||||
|
||||
BlockMarkFree(Block);
|
||||
Block = MergeEmptyBlockDown(Controller, Block);
|
||||
|
@ -780,8 +731,6 @@ void* AllocatorRealloc(allocator_t Allocator, void* Address, size_t NewSize) {
|
|||
|
||||
const size_t AdjustedSize = AlignRequestSize(NewSize, ALIGN_SIZE);
|
||||
|
||||
ASSERT(!BlockIsFree(Block), "AllocatorRealloc: Requested block is not free!");
|
||||
|
||||
if (AdjustedSize > CurrentSize && (!BlockIsFree(NextBlock) || AdjustedSize > CombinedSize)) {
|
||||
// We're going to need more room
|
||||
|
||||
|
@ -804,7 +753,3 @@ void* AllocatorRealloc(allocator_t Allocator, void* Address, size_t NewSize) {
|
|||
|
||||
return Pointer;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -3,10 +3,6 @@
|
|||
|
||||
/** Durand's Amazing Super Duper Memory functions. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define VERSION "1.1"
|
||||
#define ALIGNMENT 16ul//4ul ///< This is the byte alignment that memory must be allocated on. IMPORTANT for GTK and other stuff.
|
||||
|
||||
|
@ -69,29 +65,29 @@ static int liballoc_free(void* ptr, size_t count) {
|
|||
|
||||
/** This macro will conveniently align our pointer upwards */
|
||||
#define ALIGN(ptr) \
|
||||
if ( ALIGNMENT > 1 ) \
|
||||
{ \
|
||||
uintptr_t diff; \
|
||||
ptr = (void*)((uintptr_t)ptr + ALIGN_INFO); \
|
||||
diff = (uintptr_t)ptr & (ALIGNMENT-1); \
|
||||
if ( diff != 0 ) \
|
||||
{ \
|
||||
diff = ALIGNMENT - diff; \
|
||||
ptr = (void*)((uintptr_t)ptr + diff); \
|
||||
} \
|
||||
*((ALIGN_TYPE*)((uintptr_t)ptr - ALIGN_INFO)) = \
|
||||
diff + ALIGN_INFO; \
|
||||
if ( ALIGNMENT > 1 ) \
|
||||
{ \
|
||||
uintptr_t ldiff; \
|
||||
ptr = (void*)((uintptr_t)ptr + ALIGN_INFO); \
|
||||
ldiff = (uintptr_t)ptr & (ALIGNMENT-1); \
|
||||
if ( diff != 0 ) \
|
||||
{ \
|
||||
ldiff = ALIGNMENT - ldiff; \
|
||||
ptr = (void*)((uintptr_t)ptr + ldiff); \
|
||||
} \
|
||||
*((ALIGN_TYPE*)((uintptr_t)ptr - ALIGN_INFO)) = \
|
||||
ldiff + ALIGN_INFO; \
|
||||
}
|
||||
|
||||
|
||||
#define UNALIGN(ptr) \
|
||||
if ( ALIGNMENT > 1 ) \
|
||||
{ \
|
||||
uintptr_t diff = *((ALIGN_TYPE*)((uintptr_t)ptr - ALIGN_INFO)); \
|
||||
if ( diff < (ALIGNMENT + ALIGN_INFO) ) \
|
||||
{ \
|
||||
ptr = (void*)((uintptr_t)ptr - diff); \
|
||||
} \
|
||||
#define UNALIGN(ptr) \
|
||||
if ( ALIGNMENT > 1 ) \
|
||||
{ \
|
||||
uintptr_t diff = *((ALIGN_TYPE*)((uintptr_t)ptr - ALIGN_INFO)); \
|
||||
if ( diff < (ALIGNMENT + ALIGN_INFO) ) \
|
||||
{ \
|
||||
ptr = (void*)((uintptr_t)ptr - diff); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
@ -814,10 +810,6 @@ void* PREFIX(realloc)(void* p, size_t size) {
|
|||
return ptr;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
void operator delete(void* addr, unsigned long __attribute__((unused)) size) {
|
||||
PREFIX(free)(addr);
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PAGE_TABLES_GET_PDPT(address) \
|
||||
(address & ((size_t) 0x1FF << 39)) >> 39
|
||||
#define PAGE_TABLES_GET_PDP(address) \
|
||||
|
@ -58,6 +54,19 @@ void InitPaging() {
|
|||
MapVirtualPageNoDirect(&KernelAddressSpace, Addr, TO_DIRECT(Addr), DEFAULT_PAGE_FLAGS);
|
||||
}
|
||||
|
||||
SerialPrintf("[ Mem] Identity mapping the entire BIOS memory map.\r\n");
|
||||
for (MMapEnt* MapEntry = &bootldr.mmap; (size_t) MapEntry < (size_t) &bootldr + bootldr.size; MapEntry++) {
|
||||
size_t entry_from = MMapEnt_Ptr(MapEntry);
|
||||
size_t entry_to = MMapEnt_Ptr(MapEntry) + MMapEnt_Size(MapEntry);
|
||||
for (size_t i = entry_from; i < entry_to; i += PAGE_SIZE) {
|
||||
MapVirtualPageNoDirect(&KernelAddressSpace, i, i, DEFAULT_PAGE_FLAGS);
|
||||
MapVirtualPageNoDirect(&KernelAddressSpace, i, TO_DIRECT(i), DEFAULT_PAGE_FLAGS);
|
||||
}
|
||||
}
|
||||
|
||||
SerialPrintf("[ Mem] Identity mapping core system hardware.\r\n");
|
||||
MapVirtualPageNoDirect(&KernelAddressSpace, APIC_REGION, APIC_REGION, DEFAULT_PAGE_FLAGS);
|
||||
|
||||
SerialPrintf("[ Mem] Mapping 0x%x bytes of bootloader structure, starting at 0x%p\r\n", bootldr.size,
|
||||
BootldrAddress);
|
||||
for (size_t i = BootldrAddress; i < (BootldrAddress + bootldr.size); i += PAGE_SIZE)
|
||||
|
@ -340,6 +349,10 @@ size_t* CreateNewPageTable(address_space_t* AddressSpace) {
|
|||
return NewPML4;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
void *operator new(size_t size) {
|
||||
return kmalloc(size);
|
||||
}
|
||||
#endif
|
||||
|
||||
void *operator new[](size_t size) {
|
||||
return kmalloc(size);
|
||||
}
|
|
@ -1,16 +1,11 @@
|
|||
#include <kernel/chroma.h>
|
||||
#include <lainlib/lainlib.h>
|
||||
|
||||
|
||||
/************************
|
||||
*** Team Kitty, 2020 ***
|
||||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This file contains functions for physical memory management.
|
||||
*
|
||||
* Physical Memory Management is performed with Buddy List allocators, which are one of the most performant systems available.
|
||||
|
@ -21,6 +16,9 @@ extern "C" {
|
|||
* TODO: Document this mess.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MIN_ORDER 3
|
||||
#define PEEK(type, address) (*((volatile type*)(address)))
|
||||
|
@ -174,7 +172,7 @@ void InitMemoryManager() {
|
|||
|
||||
MemoryPages = FreeMemorySize / PAGE_SIZE;
|
||||
|
||||
SerialPrintf("[ Mem] %u MB of memory detected.\r\n", (FreeMemorySize / 1024) / 1024);
|
||||
SerialPrintf("[ Mem] %u MB of usable memory detected, %u MB total.\r\n", (FreeMemorySize / 1024) / 1024, (FullMemorySize / 1024) / 1024);
|
||||
}
|
||||
|
||||
|
||||
|
@ -346,6 +344,6 @@ void* memset(void* dst, int src, size_t len) {
|
|||
return dst;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -5,10 +5,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This file contains functions for accessing the PCI bus,
|
||||
* and devices contained wherein.
|
||||
*
|
||||
|
@ -750,8 +746,4 @@ const char* PCIGetClassName(uint8_t DeviceClass) {
|
|||
}
|
||||
|
||||
return "Invalid device!";
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -5,10 +5,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This file serves to allow us to communicate with the computer through raw I/O.
|
||||
* It provides interfaces for Ports and commonly used Registers (Control Registers, Model-Specific Registers, GDT, IDT..)
|
||||
*
|
||||
|
@ -257,8 +253,3 @@ void WriteTSR(uint16_t TSRData) {
|
|||
|
||||
__asm__ __volatile__("ltr %[src]" : : [src] "m"(TSRData) :);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -4,10 +4,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This file provides functions related to the Serial port.
|
||||
* Through this file, you send and receive text and extra debugging information if available.
|
||||
*/
|
||||
|
@ -49,8 +45,4 @@ void WriteSerialString(const char* str, size_t len) {
|
|||
for (size_t i = 0; i < len; i++) {
|
||||
WriteSerialChar(str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -7,10 +7,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This file contains all of the draw-to-screen routines.
|
||||
* It (currently; 23/08/20) handles the keyboard input test routine,
|
||||
|
@ -478,7 +474,3 @@ void DrawFilledCircle(size_t centerX, size_t centerY, size_t radius) {
|
|||
DrawVerticalLine(centerX, centerY - radius, 2 * radius + 1);
|
||||
DrawFilledCircleInternal(centerX, centerY, radius, 3, 0);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -6,10 +6,6 @@
|
|||
*** Chroma ***
|
||||
***********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This file contains all of the String / Print related functions
|
||||
* that are required by the core of the kernel.
|
||||
*
|
||||
|
@ -36,7 +32,7 @@ void NumToStr(char* Buffer, size_t Num, size_t Base) {
|
|||
|
||||
}
|
||||
|
||||
int SerialPrintf(const char* Format, ...) {
|
||||
extern "C" int SerialPrintf(const char* Format, ...) {
|
||||
va_list Parameters;
|
||||
va_start(Parameters, Format);
|
||||
|
||||
|
@ -283,7 +279,3 @@ size_t ParseHexColor(const char* Stream, bool bgFlag) {
|
|||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user