Compare commits

..

54 Commits

Author SHA1 Message Date
986c7816b1
Adjust structure of the image folder
Reduces the kernel initrd size.
2020-11-28 16:52:34 +00:00
2b1d6cca5f
Fixes for memory. Lots of work left.
Mainly, we need to be able to locate the kernel executable physically in memory.
2020-11-28 16:52:17 +00:00
4468cee2e7
Fix embarassing bug in paging impl that caused crashes.. 2020-11-26 04:01:22 +00:00
4e7f8d47a5
Add better output to GPF handler 2020-11-26 03:50:30 +00:00
e2635c8125
Fix ordering of INTERRUPT_FRAME in header 2020-11-26 03:49:54 +00:00
c451afba0d
Add debugging symbols to output.. 2020-11-26 03:48:41 +00:00
3f2ac2db36
Add a memstart symbol to the linkerscript
This replaces the old way of appending the memory bitmap to the end of the kernel, which started causing problems with expansion..

I hardcoded the value to 0x1440, which is the start of the first FREE block of memory given to SeaBIOS in QEMU. This should be changed in the future..
2020-11-09 18:48:47 +00:00
a9c0fcdfde
Adjust the crt0 file to insert a null stack frame before calling the kernel. Provides a solid base for the stack unwinding. 2020-11-09 18:44:42 +00:00
39c1956819
Minimise printing in physmem - turns out serial output is SLOW. 2020-11-09 18:43:59 +00:00
c8c1af3961
Adjust formatting in paging that i missed 2020-11-09 18:43:20 +00:00
63a5bfa4d6
Flailing with Invalid Opcode.. 2020-11-09 18:43:06 +00:00
0de541b069
Add stack unwinding to critical ISRs.
Also adjust the formatting of serial prints..
2020-11-09 18:41:34 +00:00
1cb5c671f7
Add basic stack unwinding functionality 2020-11-09 18:39:34 +00:00
91063e12d2
Add opcode handling.. started debugging memory management. 2020-10-30 22:24:59 +00:00
903b5439ba
Fix building on Windows by dpeter99
Fix CMake invocation that confused it into using Visual Studio build tools..
2020-10-18 18:27:07 +02:00
Curle
162c4def06
Fix pre.sh
I can't spell!
2020-10-18 13:14:15 +01:00
Curle
5421541208
Comment out the post-build script.
More preparation for build server.
2020-10-16 23:28:02 +01:00
Curle
b9b1cb4337
Update pre.sh with explicit cross-linker
Just to help automating the build process.
2020-10-16 23:24:41 +01:00
266e00a3d8
Fix typo in post-build script 2020-09-29 02:03:48 +01:00
ff60205e11
Remove large image file, add extra stuff to the gitignore 2020-09-29 01:58:29 +01:00
5ad73b7046
Move toolchain to VirtualBox. qemu is too restrictive :/ 2020-09-29 01:36:05 +01:00
81313cef42
Refactor CPU preparation into cpu.c, work on enabling AVX and SSE 2020-09-25 16:48:20 +01:00
d342772ed3
Poke paging. Still a little strange. Removed excess debugging. 2020-09-25 16:47:10 +01:00
Curle
cf30822677
We have virtual memory management!
Even if it's a little broken...
2020-09-07 20:56:49 +01:00
f30a0ebd68
Add defs required for kernel to compile 2020-09-03 21:37:03 +01:00
ee7f3c76f7
Add symbols to linker script for page table generation 2020-08-31 21:53:44 +01:00
78fb7f061f
Add new files to CMake 2020-08-31 21:53:10 +01:00
833562c7be
Change bracketing to make gcc -Werror happy 2020-08-31 21:51:41 +01:00
35715d1501
Add MMIO read/write functions. 2020-08-31 21:51:07 +01:00
48f574a170
Add missing invlpg function to cpu.c 2020-08-31 21:50:20 +01:00
baf09c80f2
Rework memory management. 2020-08-31 21:47:52 +01:00
53506eccb8
Add BXRC file for Bochs support. 2020-08-31 21:47:12 +01:00
58a944ee6e
Add startings of new kernel-side library
Lainlib is libk. It is separate from Helix, which will become the 3D engine common to the kernel and the userspace.
2020-08-31 21:44:54 +01:00
59896e4765
Remove dead files 2020-08-27 02:10:05 +01:00
ed89a1fb77
Remove ISO components 2020-08-27 02:08:03 +01:00
Curle
b6554e8501
Update README for new build process 2020-08-27 01:57:59 +01:00
aba82eaacb
Add support for C++
This was a doozy. I had to recompile gcc with a custom target to get it to output the CRT{BEGIN/END}.o files with proper 64 bit relocations.

The CMakeLists.txt file was also edited to allow these files to be linked (thereby actually adding the support) as well as to automatically create the boot image upon build.
2020-08-27 01:39:56 +01:00
4c9108bc87
Add PCI Enumeration to boot output 2020-08-23 02:32:47 +01:00
73b51c851d
Add basic PCI support.
Currently can only enumerate the PCI bus with a basic process, and retrieve basic details on every valid device.
2020-08-23 00:50:10 +01:00
493ef776e2
Refresh all files with project headers and documentation 2020-08-23 00:48:49 +01:00
3eb69c052d
Removed unnecessary VGA textmode header 2020-08-23 00:47:15 +01:00
7d0e2142a3
Removed unnecessary ISO files 2020-08-23 00:46:43 +01:00
e580d20e0d
Add Windows version of mkbootimg for platform agnosticity 2020-08-19 23:39:30 +01:00
5498f1f923
Move from CD-ROM images to Hard Disk images.
This involves a new img/ folder, a new program called mkbootimg, the accompanying chroma.json file that instructs mkbootimg how to create the image.

An extra Powershell script is included for brevity.
2020-08-19 22:57:06 +01:00
Curle
9d539287a7
Create README.md 2020-07-10 10:47:16 +01:00
0d21ec9f02
Add shebang lines to scripts 2020-07-07 20:07:01 -04:00
destoer
4b4ad2ca65
fix compilier warnings 2020-07-08 00:38:59 +01:00
destoer
c26e0e0599
remove junk files 2020-07-07 21:39:28 +01:00
destoer
f2531d9ec5
remove makefile 2020-07-07 21:36:17 +01:00
destoer
39917539af
removed junk files 2020-07-07 21:34:57 +01:00
e475442f4b
Added Windows build script 2020-07-07 01:24:54 +01:00
destoer
86307dda70
added build scripts 2020-07-07 01:21:18 +01:00
5892af699d
Add missing files from git migration 2020-07-05 22:58:37 +01:00
97576bab02
Attempts at fixing paging.
Have somehow fixed the drawing routines along the way.

I also tried to implement a better keyboard handler, but that's quite a ways away right now.
2020-04-11 22:59:39 +01:00
8 changed files with 85 additions and 12 deletions

View File

@ -3,12 +3,13 @@
"config": "img/boot/config",
"initrd": {
"type": "tar",
"directory": "img/boot"
"file": "img/boot/exe"
},
"partitions": [
{
"type": "boot",
"size": 4
"size": 4,
"directory": "img/boot/loader"
},
{
"type": "Microsoft basic data",

View File

@ -14,7 +14,8 @@ extern "C" {
#define BOOT_MAGIC "BOOT"
/* minimum protocol level:
* hardcoded kernel name, static kernel memory addresses */
* hardcoded kernel name, static kernel memory addresses
* this is the default */
#define PROTOCOL_MINIMAL 0
/* static protocol level:
* kernel name parsed from environment, static kernel memory addresses */
@ -27,6 +28,7 @@ extern "C" {
/* loader types, just informational */
#define LOADER_BIOS (0<<2)
/* unless we get to a weird stage, these should never be used. */
#define LOADER_UEFI (1<<2)
#define LOADER_RPI (2<<2)
@ -106,6 +108,31 @@ typedef struct {
} __attribute__((packed)) bootinfo;
typedef struct {
uint32_t Magic;
uint8_t Class;
uint8_t Endianness;
uint8_t Version;
uint8_t ABI;
uint8_t ABIVersion;
uint8_t Unused[7];
uint16_t Type;
uint16_t TargetArchitecture;
uint32_t ELFVersion;
size_t EntryPoint;
size_t ProgramHeadersTable;
size_t SectionHeadersTable;
uint32_t Flags;
uint16_t ELFHeaderSize;
uint16_t ProgramHeadersEntrySize;
uint16_t ProgramHeaderEntries;
uint16_t SectionHeadersEntrySize;
uint16_t SectionHeaderEntries;
uint16_t SectionHeaderNameEntry;
uint8_t End;
} __attribute__((packed)) ELF64Header_t;
#ifdef __cplusplus
}
#endif

View File

@ -28,6 +28,7 @@ extern bootinfo bootldr;
extern unsigned char* environment;
extern uint8_t fb;
extern volatile unsigned char _binary_font_psf_start;
extern volatile size_t* _kernel_text_start;
extern address_space_t KernelAddressSpace;

View File

@ -8,6 +8,8 @@
*** Chroma ***
***********************/
size_t KernelLocation;
/************************************************
* C O N S T A N T S A N D M A C R O S
@ -52,6 +54,8 @@
#define ERR_RESERVED 0x8
#define ERR_INST 0x10
#define ELF64MAGIC 0x7F454c46
/*
* The way we boot, using BOOTBOOT, and the static hard drive images, means
@ -104,8 +108,6 @@
#define FB_REGION 0xFFFFFFFFFC000000ull // Cannot move!
#define FB_PHYSICAL 0x00000000E0000000ull // Physical location of the Framebuffer
#define KERNEL_REGION 0xFFFFFFFFFFE00000ull // -2MiB, from bootloader
#define KERNEL_PHYSICAL 0x0000000000008000ull // Physical location of the kernel
#define KERNEL_PHYSICAL_2 0x000000000011C000ull // For some reason the kernel is split in half
#define USER_REGION 0x00007FFFFFFFFFFFull // Not needed yet, but we're higher half so we might as well be thorough

View File

@ -20,9 +20,48 @@ address_space_t KernelAddressSpace;
int Main(void) {
KernelAddressSpace = (address_space_t) {0};
KernelLocation = 0x112600;
SerialPrintf("\r\n[ boot] Booting Chroma..\r\n");
SerialPrintf("[ boot] Kernel loaded at 0x%p, ends at 0x%p, is %d bytes long.\r\n", KernelAddr, KernelEnd, KernelEnd - KernelAddr);
SerialPrintf("[ boot] Initrd is physically at 0x%p, and is %d bytes long.\r\n", bootldr.initrd_ptr, bootldr.initrd_size);
SerialPrintf("[ boot] Searching for kernel... Constants start at 0x%p\r\n", &_kernel_text_start);
// We stop at the constants in the kernel, otherwise we'll read the constant ELF64MAGIC which is stored inside the kernel...
size_t headerLoc = 0;
for(size_t i = KernelAddr; i < KernelEnd; i++) {
if(i < (size_t) (&_kernel_text_start) - KernelAddr) {
if(*((volatile uint32_t*)(i)) == ELF64MAGIC) {
SerialPrintf("[ boot] Matched kernel header at 0x%p.\r\n", i);
}
}
}
int flag = 0;
if(headerLoc) {
ELF64Header_t* PotentialKernelHeader = (ELF64Header_t*) &headerLoc;
SerialPrintf(
"[ boot] Considering ELF with:\r\n\tBitness %d\r\n\tEntry point 0x%p\r\n\tFile type %s : %d\r\n\tArchitecture %s : %d\r\n",
PotentialKernelHeader->Class == 2 ? 64 : 32, PotentialKernelHeader->EntryPoint, PotentialKernelHeader->Type == 0x02 ? "EXECUTABLE" : "OTHER", PotentialKernelHeader->Type, PotentialKernelHeader->TargetArchitecture == 0x3E ? "AMD64" : "OTHER", PotentialKernelHeader->TargetArchitecture);
if(PotentialKernelHeader->EntryPoint == KernelAddr) {
SerialPrintf("[ boot] Header at 0x%p matches kernel header.\r\n", headerLoc);
flag = 1;
}
if(!flag) {
for(size_t i = 0; i < 8; i++) {
SerialPrintf("[ boot] Header dump part %d: 0x%x\r\n", i, *((volatile uint32_t*)(headerLoc + i)));
}
}
}
if(!flag) {
SerialPrintf("[ boot] Unable to find kernel in memory. Fatal error.\r\n");
//for(;;) {}
}
SerialPrintf("[ boot] The bootloader has put the paging tables at 0x%p.\r\n", ReadControlRegister(3));

View File

@ -48,7 +48,7 @@
*
*/
extern size_t _kernel_text_start;
//extern size_t _kernel_text_start;
extern size_t _kernel_rodata_start;
extern size_t _kernel_data_start;
@ -138,10 +138,10 @@ void InitPaging() {
SerialPrintf("[ Mem] Identity mapping higher half complete.\n");
MMapEnt* TopEntry = (MMapEnt*)(((&bootldr) + bootldr.size) - sizeof(MMapEnt));
MMapEnt* TopEntry = (MMapEnt*)(((size_t) (&bootldr) + bootldr.size) - sizeof(MMapEnt));
size_t LargestAddress = TopEntry->ptr + TopEntry->size;
SerialPrintf("[ Mem] About to map lower memory into the Direct Region.\n");
SerialPrintf("[ Mem] About to map lower memory into the Direct Region. Highest address = 0x%p\n", AlignUpwards(LargestAddress, PAGE_SIZE));
for(size_t Address = 0; Address < AlignUpwards(LargestAddress, PAGE_SIZE); Address += PAGE_SIZE) {
MapVirtualMemory(&KernelAddressSpace, (size_t*)(((char*)Address) + DIRECT_REGION), Address, MAP_WRITE);
}
@ -151,16 +151,16 @@ void InitPaging() {
//TODO: Disallow execution of rodata and data, and bootldr/environment
for(void* Address = CAST(void*, KERNEL_REGION);
Address < CAST(void*, KERNEL_REGION + 0x2000); // Lower half of Kernel
Address < CAST(void*, KERNEL_REGION + (KernelEnd - KernelAddr)); // Lower half of Kernel
Address = CAST(void*, CAST(char*, Address) + PAGE_SIZE)) {
MapVirtualMemory(&KernelAddressSpace, Address, (CAST(size_t, Address) - KERNEL_REGION) + KERNEL_PHYSICAL, MAP_EXEC);
MapVirtualMemory(&KernelAddressSpace, Address, (CAST(size_t, Address) - KERNEL_REGION) + KernelLocation, MAP_EXEC);
}
for(void* Address = CAST(void*, KERNEL_REGION + 0x2000);
/*for(void* Address = CAST(void*, KERNEL_REGION + 0x2000);
Address < CAST(void*, KERNEL_REGION + 0x12000); // Higher half of kernel
Address = CAST(void*, CAST(char*, Address) + PAGE_SIZE)) {
MapVirtualMemory(&KernelAddressSpace, Address, (CAST(size_t, Address) - KERNEL_REGION) + KERNEL_PHYSICAL_2, MAP_EXEC);
}
}*/
for(void* Address = CAST(void*, FB_REGION);
Address < CAST(void*, 0x200000); // TODO: Turn this into a calculation with bootldr.fb_size
@ -169,6 +169,9 @@ void InitPaging() {
}
SerialPrintf("[ Mem] Kernel mapped into pagetables. New PML4 at 0x%p\r\n", KernelAddressSpace.PML4);
SerialPrintf("[ Mem] About to move into our own pagetables.\r\n");
WriteControlRegister(3, (size_t) KernelAddressSpace.PML4);
SerialPrintf("[ Mem] We survived!\r\n");
//ASSERT(Allocator != NULL);
}

Binary file not shown.