Here's a tree organization of my directory... (you can also find it on http://www.github.com/kssuraaj28)
Code: Select all
├── boot
│ ├── stage1
│ │ ├── CHS.asm
│ │ ├── debug
│ │ ├── disk_read.asm
│ │ ├── print.asm
│ │ └── stage1.asm
│ └── stage2
│ ├── func16.asm
│ ├── func32.asm
│ ├── GDT.asm
│ ├── pagingsetup.asm
│ └── stage2.asm
├── disk.img
├── kernel
│ ├── asm
│ │ ├── cursor.asm
│ │ ├── cursor.o
│ │ ├── entry.asm
│ │ ├── entry.o
│ │ ├── hal.asm
│ │ ├── hal.o
│ │ ├── interruptstubs.asm
│ │ ├── interruptstubs.o
│ │ └── timer.o
│ ├── c
│ │ ├── io.c
│ │ ├── o.h
│ │ ├── io.o
│ │ ├── hal.c
│ │ ├── hal.h
│ │ ├── hal.o
│ │ ├── inthandling.c
│ │ ├── inthandling.h
│ │ ├── inthandling.o
│ │ ├── kernel.c
│ │ ├── kernel.o
│ │ ├── keyboard.c
│ │ ├── keyboard.h
│ │ ├── keyboard.o
│ │ ├── kshell.c
│ │ ├── kshell.o
│ │ ├── phymem.c
│ │ ├── phymem.h
│ │ ├── phymem.o
│ │ ├── timer.c
│ │ ├── timer.h
│ │ ├── timer.o
│ │ ├── virtmem.c
│ │ ├── virtmem.h
│ │ └── virtmem.o
│ ├── kernel.elf
│ └── linker.ld
├── kernel.bin
├── Makefile
├── readme.md
├── script.sh
├── stage1.bin
└── stage2.bin
Here's the makefile, which describes how I build the OS.
Code: Select all
C_SOURCES = $(wildcard kernel/c/*.c)
ASM_SOURCES = $(wildcard kernel/asm/*.asm)
C_OBJECTS = ${C_SOURCES:.c=.o}
ASM_OBJECTS = ${ASM_SOURCES:.asm=.o}
.PHONY : all assemble run clean
all: assemble
run : assemble
qemu-system-i386 -drive format=raw,file=disk.img -monitor stdio
debug: assemble
qemu-system-i386 -s -hda disk.img &
gdb -ex "target remote localhost:1234" -ex "symbol-file kernel/kernel.elf" -ex "b kmain" -ex "continue"
assemble: disk.img kernel.bin stage1.bin stage2.bin
dd if=stage1.bin of=disk.img bs=1 count=3 seek=0 skip=0 conv=notrunc
dd if=stage1.bin of=disk.img bs=1 count=451 seek=62 skip=62 conv=notrunc
mcopy -i disk.img stage2.bin kernel.bin :: -D o
kernel.bin : kernel/kernel.elf
objcopy -O binary $^ $@
chmod -x $@
#You can use the --print-map option to look at what the linker does
kernel/kernel.elf : $(C_OBJECTS) $(ASM_OBJECTS)
i686-elf-ld $^ -T kernel/linker.ld -e kmain -o $@
chmod -x $@
%.o : %.c
i686-elf-gcc -ffreestanding $< -c -o $@ -Wall -Werror -g
%.o : %.asm
nasm $< -o $@ -f elf32
stage1.bin : boot/stage1/stage1.asm
nasm $^ -f bin -o $@
stage2.bin: boot/stage2/stage2.asm
nasm $^ -f bin -o $@
disk.img:
truncate $@ -s 1M
mkfs.vfat -F12 -S512 -s1 $@
clean :
rm $(C_OBJECTS) $(ASM_OBJECTS) *.bin