Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cpp-Kernel

A simple 32-bit "Hello World" kernel written in C++ and assembly.

Features

  • VGA Text Mode Driver: A simple driver to print characters to the screen.
  • Terminal Driver: A higher-level driver for writing strings to the terminal.
  • Multiboot Header: A basic multiboot header to be compliant with bootloaders.
  • 32-bit Protected Mode: The kernel runs in 32-bit protected mode.

File Descriptions

  • boot.asm: This file contains the assembly code that boots the kernel. It sets up a 32-bit protected mode environment and then calls the C++ kernel's main function. It also contains the multiboot header.
  • kernel.cpp: This is the main kernel file. It contains the kmain function, which is the entry point for the C++ part of the kernel. It initializes the terminal and prints a message to the screen.
  • terminal.h and terminal.cpp: These files implement a simple terminal driver that allows writing strings to the VGA text buffer.
  • vga.h: This file contains definitions for the VGA text mode colors and buffer.
  • linker.ld: This is the linker script. It tells the linker how to arrange the different sections of the kernel in memory. It places the boot code at the beginning, followed by the rest of the kernel, and sets the starting memory address to 1MB.
  • Makefile: This file contains the instructions for building the kernel. It compiles the assembly and C++ code, links them together, and provides a run command to execute the kernel in QEMU.
  • README.md: This file.

Control Flow

  1. Bootloader: A bootloader (like GRUB, or in this case, QEMU's built-in bootloader) loads the kernel.bin file into memory.
  2. boot.asm:
    • The execution starts at the start label in boot.asm.
    • It first sets up the Global Descriptor Table (GDT) to switch the CPU into 32-bit protected mode.
    • It then jumps to the protected_mode label.
    • In protected mode, it sets up the segment registers.
    • It then calls the kmain function in kernel.cpp.
  3. kernel.cpp:
    • The kmain function is executed.
    • It calls terminal_initialize() to clear the screen.
    • It then calls terminal_writestring() to print "Hello, Kernel!\n" to the screen.
  4. Halt: After kmain returns, the boot.asm code executes the hlt instruction, which halts the CPU.

Building and Running

To build and run the kernel, you will need nasm, zig, and qemu.

make run

This will compile the kernel and run it in QEMU.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages