Skip to content

Completely start over and implement printf - #1

Merged
lassedtu merged 1 commit into
mainfrom
new-bootloader
Aug 4, 2026
Merged

Completely start over and implement printf#1
lassedtu merged 1 commit into
mainfrom
new-bootloader

Conversation

@lassedtu

@lassedtu lassedtu commented Aug 4, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI lite review requested due to automatic review settings August 4, 2026 16:17
@lassedtu
lassedtu merged commit 21bebcb into main Aug 4, 2026
@lassedtu
lassedtu deleted the new-bootloader branch August 4, 2026 16:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR resets the OS to a new two-stage boot flow (stage1 boot sector + stage2 real-mode loader) and introduces a freestanding printf implementation for stage2 output, while removing the prior VGA/IDT/PIC/keyboard/shell/printk-based kernel.

Changes:

  • Replaced the old single-stage boot + kernel subsystem stack with stage1/stage2 bootloader layout and new linker scripts.
  • Added a stage2 freestanding stdio with printf plus small x86 BIOS/arith helpers.
  • Added a minimal 32-bit kernel entry stub and updated build/run docs + Makefile.

Reviewed changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/vga.h Removed prior VGA text-mode interface.
src/vga.c Removed prior VGA text-mode implementation.
src/shell.h Removed prior shell interface.
src/shell.c Removed prior shell implementation.
src/printk.h Removed prior kernel printf-style logging interface.
src/printk.c Removed prior kernel printf-style logging implementation.
src/pic.h Removed prior PIC interface.
src/pic.c Removed prior PIC implementation.
src/panic.h Removed prior panic interface.
src/panic.c Removed prior panic implementation.
src/keyboard.h Removed prior keyboard IRQ interface.
src/keyboard.c Removed prior keyboard IRQ implementation.
src/kernel/main.asm Added new 32-bit kernel entry/stack stub.
src/kernel/kernel.c Added minimal kernel_main stub.
src/kernel.h Removed old kernel header.
src/kernel.c Removed old kernel main (IDT/PIC/VGA/shell init).
src/kernel.asm Removed old kernel entry assembly.
src/isr.asm Removed old ISR stubs.
src/idt.h Removed old IDT interface.
src/idt.c Removed old IDT setup + interrupt handler.
src/bootloader/stage2/x86.h Added stage2 x86 helper declarations.
src/bootloader/stage2/x86.asm Added stage2 x86 helper implementations (div + BIOS teletype).
src/bootloader/stage2/stdio.h Added stage2 stdio API.
src/bootloader/stage2/stdio.c Added stage2 putc/puts/printf implementation.
src/bootloader/stage2/stdint.h Added minimal fixed-width integer + bool typedefs for stage2.
src/bootloader/stage2/main.c Added stage2 C entry that exercises printf.
src/bootloader/stage2/main.asm Added stage2 loader (loads kernel + calls C entry).
src/bootloader/stage1/boot.asm Added stage1 boot sector that loads stage2.
src/boot.asm Removed prior boot sector implementation.
README.md Updated project name/docs; added toolchain + make/run instructions.
Makefile Replaced build pipeline with stage1/stage2/kernel targets and image construction.
linkerScript.ld Removed old linker script.
linker/stage2.ld Added stage2 linker script.
linker/kernel.ld Added kernel linker script.
build.sh Removed old build wrapper script.
.vscode/settings.json Removed workspace settings.
Suppressed comments (1)

src/bootloader/stage2/stdio.c:79

  • The %s handling treats the l/ll length modifier as if it changes pointer size and then consumes two stack slots (argp += 2). This is not compatible with standard printf semantics (%ls is a wide string, not a “far char*”), and it will desynchronize the argument cursor so subsequent format specifiers read the wrong arguments.
    case 's':
        if (ctx->length == PRINTF_LENGTH_LONG || ctx->length == PRINTF_LENGTH_LONG_LONG)
        {
            puts_f(*(const char **)argp);
            argp += 2;
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +47 to +51
xor eax, eax
mov al, [boot_drive]
push eax
call cstart_
add sp, 4
Comment on lines +126 to +134
void printf(const char *fmt, ...)
{
int *argp = (int *)&fmt;
PrintfContext ctx;

printf_context_reset(&ctx);

argp++;

Comment on lines +9 to +16
void puts(const char *str)
{
while (*str)
{
putc(*str);
str++;
}
}
const char *str = "another string";

puts("Hello world from C!\r\n");
printf("Formatted %% %c %s %ls\r\n", 'a', "string", str);
Comment on lines +32 to +56
mov ax, KERNEL_LOAD_SEGMENT
mov es, ax
mov bx, KERNEL_LOAD_OFFSET

mov ah, 0x02 ; BIOS read sectors
mov al, KERNEL_SECTORS
mov ch, 0x00 ; cylinder 0
mov cl, KERNEL_START_SECTOR ; sector index on track
mov dh, 0x00 ; head 0
mov dl, [boot_drive]
int 0x13
jc disk_error

; Call stage2 C entry in real mode.
; The boot drive (DL) is forwarded as an argument.
xor eax, eax
mov al, [boot_drive]
push eax
call cstart_
add sp, 4

realmode_hang:
cli
hlt
jmp realmode_hang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants