diff --git a/README.md b/README.md index fad035f..ad948d2 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,27 @@ The main goal of the project is to be multiboot compliant and bootable through a bootloader supporting the multiboot standard. The architecture in mind now is x86 and it is assumed that the system is in legacy BIOS mode. -## Build +## Build and install ### Environment - Ubuntu 20.04 - Install dependencies: `sudo apt install g++ binutils libc6-dev-i386 make` +- Optional dependencies (if you plan to boot the kernel with Qemu): `sudo apt qemu-system-x86` -To build issue command `make mykernel.bin` in `src`. +### Boot with Qemu -To install issue `make install` in `src`. This requires sudo privilages -and will do the build as well. +Most will prefer this. -The kernel binary by default is installed into `/boot` with `make install`. +1. To build and install issue command `make install` in `src`. +2. To boot the kernel with Qemu issue `qemu-system-i386 --kernel mykernel.bin` in `out`. + +### Boot on real hardware with GRUB2 + +This will NOT break your system in any way ;). +If you want to run it on bare metal, you must have GRUB2 installed. + +The kernel binary by default is installed into `/boot` with `make grubinstall`. There are multiple ways to add it as an entry, but the easy and dirty way is to add it explicitly as a custom binary into the generated GRUB script, which is located at `/boot/grub/grub.cfg`. diff --git a/src/Makefile b/src/Makefile index 84e78c3..a5a7a32 100644 --- a/src/Makefile +++ b/src/Makefile @@ -18,6 +18,8 @@ mykernel.bin: linker.ld ${objectfiles} ld ${LD_PARAMS} -T $< -o $@ ${objectfiles} install: mykernel.bin - sudo cp $< /boot/mykernel.bin mv $< ../out mv *.o ../out + +grubinstall: mykernel.bin + sudo cp $< /boot/mykernel.bin \ No newline at end of file diff --git a/src/kernel.cpp b/src/kernel.cpp index ced69b6..0180198 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -3,6 +3,9 @@ typedef unsigned short USHORT; #define HIGH_BYTE 0xFF00 #define VRAM_ADDRS (USHORT*)0xb8000 #define MESSAGE (char*)"Kernel main test" +#define TRUE 1==1 +#define FALSE !TRUE +#define LANG_C "C" /* As we do not use glibc, we must write our very basic implementation of print. * This implementation only support putting ASCII characters on the screen, with black background and white text. @@ -14,11 +17,10 @@ typedef unsigned short USHORT; * */ void printf(char* str) { - USHORT* vram= VRAM_ADDRS; + USHORT* vram = VRAM_ADDRS; for(int i = 0; str[i] != '\0'; ++i) { - USHORT vram_high_byte = (vram[i] & HIGH_BYTE); - vram[i] = vram_high_byte | str[i]; + vram[i] = (USHORT)(vram[i] & HIGH_BYTE) | str[i]; } } @@ -28,7 +30,7 @@ void printf(char* str) * to the stack. The multiboot structure can be used for kernel operation, while * the multiboot flag can be used to make sure the enviroment is indeed multiboot. * */ -extern "C" void kernel_main(void* multiboot_struct, unsigned int multiboot_flag) { +extern LANG_C void kernel_main(void* multiboot_struct, unsigned int multiboot_flag) { printf(MESSAGE); - while(1); + while(TRUE); }