diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a799c93 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +obj diff --git a/Makefile b/Makefile index e69de29..15ecd26 100644 --- a/Makefile +++ b/Makefile @@ -0,0 +1,41 @@ +AS := i386-elf-as +ASFLAGS := +CC := i386-elf-gcc +CCFLAGS := -std=gnu99 -ffreestanding -O2 -Wall -Wextra +LD := $(CC) +LDFLAGS := -T boot/linker.ld -ffreestanding -O2 -nostdlib +LIBS := -lgcc + +SSRC := $(wildcard src/*.s) +CSRC := $(wildcard src/*.c) +OBJ := $(patsubst src/%.c,obj/%.o,$(CSRC))\ + $(patsubst src/%.s,obj/%.o,$(SSRC)) + +NAME := bozOS + +all: $(NAME) + +obj/%.o: src/%.s + mkdir -p obj/ + $(AS) $(ASFLAGS) $< -o $@ + +obj/%.o: src/%.c + mkdir -p obj/ + $(CC) $(CCFLAGS) -c $< -o $@ + +$(NAME): $(OBJ) + mkdir -p build/ + $(LD) $(LDFLAGS) -o build/$(NAME).bin $(OBJ) $(LIBS) + +run: $(NAME) + qemu-system-i386 -kernel build/$(NAME).bin + +clean: + rm -rf obj/ + +fclean: clean + rm -rf build/ + +re: fclean all + +.PHONY: all clean fclean re run diff --git a/boot/linker.ld b/boot/linker.ld new file mode 100644 index 0000000..e56537d --- /dev/null +++ b/boot/linker.ld @@ -0,0 +1,28 @@ +ENTRY(_start) + +SECTIONS +{ + . = 2M; + + .text BLOCK(4K) : ALIGN(4K) + { + *(.multiboot) + *(.text) + } + + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } +} diff --git a/src/kernel.c b/src/kernel.c index 84198ef..133b20c 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -41,6 +41,13 @@ static inline uint16_t vga_entry(unsigned char uc, uint8_t color) { return (uint16_t)uc | (uint16_t)color << 8; } +size_t strlen(const char *str) { + size_t len = 0; + while (str[len]) + len++; + return len; +} + static const size_t VGA_WIDTH = 80; static const size_t VGA_HEIGHT = 25;