Completely start over and implement printf - #1
Merged
Merged
Conversation
There was a problem hiding this comment.
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
stdiowithprintfplus 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
%shandling treats thel/lllength modifier as if it changes pointer size and then consumes two stack slots (argp += 2). This is not compatible with standardprintfsemantics (%lsis 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.