Feat: Kernel up and running.
This commit is contained in:
@@ -13,32 +13,40 @@ BLUE='\033[0;34m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Prepare build environment
|
||||
echo -e "Preparing build environment...${NC}"
|
||||
echo -e "Creating Folders${NC}"
|
||||
mkdir -p bin obj boot include
|
||||
echo -e "${GREEN}✓ ${NC}Folders created.${NC}"
|
||||
|
||||
# Step 1: Assemble Stage 1 bootloader (MBR - 512 bytes)
|
||||
echo -e "${BLUE}[1/6]${NC} Assembling Stage 1 bootloader (MBR)..."
|
||||
nasm -f bin boot.asm -o boot.bin
|
||||
nasm -f bin ./boot/boot.asm -o ./bin/boot.bin
|
||||
|
||||
# Step 2: Assemble Stage 2 bootloader (extended loader)
|
||||
echo -e "${BLUE}[2/6]${NC} Assembling Stage 2 bootloader..."
|
||||
nasm -f bin elevator.asm -o elevator.bin
|
||||
nasm -f bin ./boot/elevator.asm -o ./bin/elevator.bin
|
||||
|
||||
# Step 3: Assemble kernel entry point
|
||||
echo -e "${BLUE}[3/6]${NC} Assembling kernel entry..."
|
||||
nasm -f elf64 kernel.asm -o kernel.asm.o
|
||||
nasm -f elf64 kernel.asm -o ./obj/kernel.asm.o
|
||||
|
||||
# Step 4: Compile kernel C code
|
||||
echo -e "${BLUE}[4/6]${NC} Compiling kernel..."
|
||||
gcc -ffreestanding -c kernel.c -o kernel.c.o -mcmodel=large -mno-red-zone -fno-pic -fno-pie -static -fno-stack-protector -nostdlib -mno-mmx -mno-sse -mno-sse2 -m64
|
||||
gcc -ffreestanding -c kernel.c -o ./obj/kernel.c.o -mcmodel=large -mno-red-zone -fno-pic -fno-pie -static -fno-stack-protector -nostdlib -mno-mmx -mno-sse -mno-sse2 -m64
|
||||
|
||||
# Step 5: Link kernel
|
||||
echo -e "${BLUE}[5/6]${NC} Linking kernel..."
|
||||
ld -T linker.ld -o kernel.bin kernel.asm.o kernel.c.o --oformat binary
|
||||
ld -T linker.ld -o ./bin/kernel.bin ./obj/kernel.asm.o ./obj/kernel.c.o --oformat binary --nostdlib
|
||||
|
||||
# Step 6: Create OS image
|
||||
echo -e "${BLUE}[6/6]${NC} Creating OS image..."
|
||||
cat boot.bin elevator.bin kernel.bin > os-image.bin
|
||||
cat ./bin/boot.bin ./bin/elevator.bin ./bin/kernel.bin > os.bin
|
||||
|
||||
# Pad to floppy size (1.44MB)
|
||||
truncate -s 1440K os-image.bin
|
||||
# FIX: Uncomment the line below if you want to ensure the image is exactly 1.44MB
|
||||
#
|
||||
# truncate -s 1440K os-image.bin
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}✓ Build complete!${NC}"
|
||||
@@ -55,17 +63,18 @@ echo ""
|
||||
echo "File Sizes:"
|
||||
printf "%-15s %10s\n" "File" "Size"
|
||||
printf "%-15s %10s\n" "----" "----"
|
||||
printf "%-15s %10d bytes\n" "boot.bin" $(stat -f%z boot.bin 2>/dev/null || stat -c%s stage1.bin 2>/dev/null)
|
||||
printf "%-15s %10d bytes\n" "elevator.bin" $(stat -f%z elevator.bin 2>/dev/null || stat -c%s stage2.bin 2>/dev/null)
|
||||
printf "%-15s %10d bytes\n" "kernel.bin" $(stat -f%z kernel.bin 2>/dev/null || stat -c%s kernel.bin 2>/dev/null)
|
||||
printf "%-15s %10d bytes\n" "os-image.bin" $(stat -f%z os-image.bin 2>/dev/null || stat -c%s os-image.bin 2>/dev/null)
|
||||
printf "%-15s %10d bytes\n" "boot.bin" $(stat -f%z ./bin/boot.bin 2>/dev/null || stat -c%s ./bin/boot.bin 2>/dev/null)
|
||||
printf "%-15s %10d bytes\n" "elevator.bin" $(stat -f%z ./bin/elevator.bin 2>/dev/null || stat -c%s ./bin/elevator.bin 2>/dev/null)
|
||||
printf "%-15s %10d bytes\n" "kernel.bin" $(stat -f%z ./bin/kernel.bin 2>/dev/null || stat -c%s ./bin/kernel.bin 2>/dev/null)
|
||||
printf "%-15s %10d bytes\n" "os.bin" $(stat -f%z os.bin 2>/dev/null || stat -c%s os.bin 2>/dev/null)
|
||||
echo ""
|
||||
|
||||
echo -e "${YELLOW}Running QEMU...${NC}"
|
||||
echo "==================================="
|
||||
echo "Press Ctrl+C to exit QEMU"
|
||||
echo ""
|
||||
qemu-system-x86_64 -drive format=raw,file=os-image.bin -no-reboot -d cpu_reset
|
||||
|
||||
qemu-system-x86_64 -drive format=raw,file=os.bin -no-reboot
|
||||
|
||||
|
||||
echo -e "${GREEN}Done!${NC}"
|
||||
|
||||
Reference in New Issue
Block a user