Skip to content

Commit

Permalink
Added targets for Qemu and GRUB2 boot, updated README.
Browse files Browse the repository at this point in the history
  • Loading branch information
IPlayZed committed Jan 16, 2022
1 parent f7f903f commit 2c60226
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
4 changes: 3 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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];
}
}

Expand All @@ -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);
}

0 comments on commit 2c60226

Please sign in to comment.