diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..faf5bef --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +# Notes for our reference. We will remove this before merging to master. +# multiboot_header.S is needed to make your binary Multiboot2-compliant. +# Use x86_64-elf-* toolchain or adapt to your toolchain names. +AS = x86_64-elf-as +CC = x86_64-elf-gcc +LD = x86_64-elf-ld +OBJCOPY = x86_64-elf-objcopy + +CFLAGS = -m64 -ffreestanding -O2 -Wall -Wextra -fno-pic -fno-stack-protector -fno-builtin +LDFLAGS = -T link.ld + +all: iso/boot/kernel.elf plug-os.iso + +kernel.o: kernel.c + $(CC) $(CFLAGS) -c kernel.c -o kernel.o + +entry.o: entry.S + $(AS) --64 entry.S -o entry.o + +multiboot_header.o: multiboot_header.S + $(AS) multiboot_header.S -o multiboot_header.o + +kernel.elf: multiboot_header.o entry.o kernel.o + $(LD) $(LDFLAGS) -o kernel.elf multiboot_header.o entry.o kernel.o + +iso/boot/kernel.elf: kernel.elf + mkdir -p iso/boot/grub + cp kernel.elf iso/boot/ + cp grub.cfg iso/boot/grub/ + +os.iso: + grub-mkrescue -o os.iso iso/ # on some systems you may need grub2-mkrescue + +clean: + rm -rf *.o kernel.elf iso os.iso diff --git a/boot/entry/entry64.S b/boot/entry/entry64.S new file mode 100644 index 0000000..e69de29 diff --git a/boot/grub/grub.cfg b/boot/grub/grub.cfg index 84edf63..fccb2eb 100644 --- a/boot/grub/grub.cfg +++ b/boot/grub/grub.cfg @@ -1,7 +1,8 @@ -set timeout=0 +set timeout=3 set default=0 -menuentry "My OS" { - multiboot2 /boot/kernel.elf - boot +menuentry "plugOS (multiboot2)" { + multiboot2 /boot/kernel.elf + module2 /boot/initramfs.img # optional + boot } diff --git a/boot/multiboot/multiboot_header.S b/boot/multiboot/multiboot_header.S new file mode 100644 index 0000000..ddc62a5 --- /dev/null +++ b/boot/multiboot/multiboot_header.S @@ -0,0 +1,12 @@ + .section .multiboot, "a" + .align 8 + .long 0xE85250D6 /* multiboot2 magic */ + .long 0 /* architecture (0 = i386) - fine for GRUB */ + .long multiboot_header_end - multiboot_header /* header length placeholder */ + .long 0 /* checksum placeholder (computed at link or filled later) */ + + /* --- tags go here (info request, entry address, etc). Example: end tag --- */ + .long 0 /* tag type = end (0) */ + .long 8 /* size = 8 (tag header size) */ + +multiboot_header_end: diff --git a/boot/multiboot/multiboot_specs.txt b/boot/multiboot/multiboot_specs.txt new file mode 100644 index 0000000..01fb637 --- /dev/null +++ b/boot/multiboot/multiboot_specs.txt @@ -0,0 +1 @@ +Here we will store our notes \ No newline at end of file diff --git a/docs/project_structure.txt b/docs/project_structure.txt new file mode 100644 index 0000000..0ae551c --- /dev/null +++ b/docs/project_structure.txt @@ -0,0 +1,72 @@ +myos/ +│ +├── build/ # All temporary/generated build artifacts go here. +│ ├── iso/ # GRUB-ready ISO tree (boot/, grub/, kernel.elf, etc.) +│ └── obj/ # Object files (.o) +│ +├── boot/ # Bootloader-related code +│ ├── grub/ # GRUB config +│ │ └── grub.cfg +│ ├── multiboot/ # Multiboot2 header and support files +│ │ ├── multiboot_header.S +│ │ └── multiboot_specs.txt # (optional notes for yourself) +│ └── entry/ # CPU entry, long-mode switch, early platform code +│ ├── entry32.S +│ └── entry64.S +│ +├── kernel/ # Kernel proper +│ ├── arch/ # Architecture-specific code (x86_64) +│ │ └── x86_64/ +│ │ ├── mm/ # Paging, PML4 setup, frame allocator +│ │ │ ├── paging.c +│ │ │ └── paging.h +│ │ ├── interrupts/ +│ │ │ ├── idt.c +│ │ │ ├── idt.h +│ │ │ ├── isr.S +│ │ │ └── irq.c +│ │ ├── gdt/ +│ │ │ ├── gdt.c +│ │ │ └── gdt.h +│ │ ├── cpufeatures.c +│ │ └── cpufeatures.h +│ │ +│ ├── drivers/ # Hardware drivers (framebuffer, keyboard, rtc…) +│ │ ├── framebuffer.c +│ │ ├── keyboard.c +│ │ └── pci.c +│ │ +│ ├── fs/ # Filesystems (VFS, ext2, initrd parsing) +│ │ ├── vfs.c +│ │ └── vfs.h +│ │ +│ ├── lib/ # Kernel-side libs (string/mem, logging, util) +│ │ ├── string.c +│ │ ├── memory.c +│ │ └── panic.c +│ │ +│ ├── scheduler/ # (Future) tasking, context switch, user mode +│ │ ├── task.c +│ │ └── task.h +│ │ +│ ├── kernel.c # Main entry point (kernel_main) +│ └── kernel.h +│ +├── scripts/ # Utility scripts for building/toolchain/ISO +│ ├── build_iso.sh +│ ├── run_qemu.sh +│ └── debug_gdb.sh +│ +├── toolchain/ # Cross-compiler build scripts or prebuilts +│ ├── build_gcc.sh +│ ├── build_binutils.sh +│ └── README.md +│ +├── include/ # Shared headers +│ ├── stdint.h +│ ├── stdbool.h +│ └── common.h +│ +├── link.ld # Kernel linker script +├── Makefile # Top-level build orchestration +└── README.md