Compare commits

..

52 Commits

Author SHA1 Message Date
c94a469baf
Fix embarassing bug in paging impl that caused crashes.. 2020-11-26 04:03:44 +00:00
868eed64ef
Add better output to GPF handler 2020-11-26 04:03:43 +00:00
fc3efd7c68
Fix ordering of INTERRUPT_FRAME in header 2020-11-26 04:03:43 +00:00
4a86fbd114
Add debugging symbols to output.. 2020-11-26 04:03:43 +00:00
75f44b0514
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-26 04:03:43 +00:00
bd8213356e
Adjust the crt0 file to insert a null stack frame before calling the kernel. Provides a solid base for the stack unwinding. 2020-11-26 04:03:43 +00:00
9b0aceac55
Minimise printing in physmem - turns out serial output is SLOW. 2020-11-26 04:03:43 +00:00
c5be09fc5d
Adjust formatting in paging that i missed 2020-11-26 04:03:43 +00:00
429fa55a73
Flailing with Invalid Opcode.. 2020-11-26 04:03:43 +00:00
acfe8c2666
Add stack unwinding to critical ISRs.
Also adjust the formatting of serial prints..
2020-11-26 04:03:43 +00:00
9646eac29e
Add basic stack unwinding functionality 2020-11-26 04:03:42 +00:00
0c0f52dbb9
Add opcode handling.. started debugging memory management. 2020-11-26 04:03:42 +00:00
fe15a79fc3
Fix building on Windows by dpeter99
Fix CMake invocation that confused it into using Visual Studio build tools..
2020-11-26 04:03:42 +00:00
Curle
b4121964c5
Fix pre.sh
I can't spell!
2020-11-26 04:03:42 +00:00
Curle
649c475f5d
Comment out the post-build script.
More preparation for build server.
2020-11-26 04:03:42 +00:00
Curle
caca55de6e
Update pre.sh with explicit cross-linker
Just to help automating the build process.
2020-11-26 04:03:42 +00:00
ba9e97a46a
Fix typo in post-build script 2020-11-26 04:03:42 +00:00
428dfce021
Remove large image file, add extra stuff to the gitignore 2020-11-26 04:03:42 +00:00
19c2ba6b72
Move toolchain to VirtualBox. qemu is too restrictive :/ 2020-11-26 04:03:42 +00:00
b86d8af721
Refactor CPU preparation into cpu.c, work on enabling AVX and SSE 2020-11-26 04:03:42 +00:00
0ff9705fc8
Poke paging. Still a little strange. Removed excess debugging. 2020-11-26 04:03:41 +00:00
Curle
15165b1562
We have virtual memory management!
Even if it's a little broken...
2020-11-26 04:03:41 +00:00
8665e4c634
Add defs required for kernel to compile 2020-11-26 04:03:41 +00:00
25d8f97693
Add symbols to linker script for page table generation 2020-11-26 04:03:41 +00:00
bd5389f1fc
Add new files to CMake 2020-11-26 04:03:41 +00:00
bade5bde21
Change bracketing to make gcc -Werror happy 2020-11-26 04:03:41 +00:00
9c65d7d19f
Add MMIO read/write functions. 2020-11-26 04:03:41 +00:00
2e662e3717
Add missing invlpg function to cpu.c 2020-11-26 04:03:41 +00:00
6faadded24
Rework memory management. 2020-11-26 04:03:41 +00:00
be4ee498c4
Add BXRC file for Bochs support. 2020-11-26 04:03:40 +00:00
a915465fc1
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-11-26 04:03:40 +00:00
61dbcc0dec
Remove dead files 2020-11-26 04:03:40 +00:00
86778f1518
Remove ISO components 2020-11-26 04:03:40 +00:00
Curle
8a3e80213f
Update README for new build process 2020-11-26 04:03:40 +00:00
b3e3f153b5
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-11-26 04:03:40 +00:00
aa9600b2b0
Add PCI Enumeration to boot output 2020-11-26 04:03:40 +00:00
e8214d5650
Add basic PCI support.
Currently can only enumerate the PCI bus with a basic process, and retrieve basic details on every valid device.
2020-11-26 04:03:39 +00:00
1f514e9cb2
Refresh all files with project headers and documentation 2020-11-26 04:03:39 +00:00
ce85ddbd1c
Removed unnecessary VGA textmode header 2020-11-26 04:03:39 +00:00
f6e2f3ac5d
Removed unnecessary ISO files 2020-11-26 04:03:39 +00:00
7e7a76a5b9
Add Windows version of mkbootimg for platform agnosticity 2020-11-26 04:03:38 +00:00
c992564365
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-11-26 04:03:38 +00:00
Curle
83aef00afa
Create README.md 2020-11-26 04:03:29 +00:00
af77c415ac
Add shebang lines to scripts 2020-11-26 04:03:29 +00:00
destoer
7603180791
fix compilier warnings 2020-11-26 04:03:29 +00:00
destoer
65aa630701
remove junk files 2020-11-26 04:03:29 +00:00
destoer
2e78df807b
remove makefile 2020-11-26 04:03:29 +00:00
destoer
7e9d2ec0f8
removed junk files 2020-11-26 04:03:28 +00:00
54489cdc75
Added Windows build script 2020-11-26 04:03:28 +00:00
destoer
f192162c54
added build scripts 2020-11-26 04:03:28 +00:00
74b44aab7f
Add missing files from git migration 2020-11-26 04:02:56 +00:00
d522d40ac8 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 23:02:54 +01:00
8 changed files with 12 additions and 85 deletions

View File

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

View File

@ -14,8 +14,7 @@ extern "C" {
#define BOOT_MAGIC "BOOT" #define BOOT_MAGIC "BOOT"
/* minimum protocol level: /* 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 #define PROTOCOL_MINIMAL 0
/* static protocol level: /* static protocol level:
* kernel name parsed from environment, static kernel memory addresses */ * kernel name parsed from environment, static kernel memory addresses */
@ -28,7 +27,6 @@ extern "C" {
/* loader types, just informational */ /* loader types, just informational */
#define LOADER_BIOS (0<<2) #define LOADER_BIOS (0<<2)
/* unless we get to a weird stage, these should never be used. */
#define LOADER_UEFI (1<<2) #define LOADER_UEFI (1<<2)
#define LOADER_RPI (2<<2) #define LOADER_RPI (2<<2)
@ -108,31 +106,6 @@ typedef struct {
} __attribute__((packed)) bootinfo; } __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 #ifdef __cplusplus
} }
#endif #endif

View File

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

View File

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

View File

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

Binary file not shown.