diff --git a/.gitignore b/.gitignore index 457fe7b..3c22653 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode -loader.o +*.o +*.bin diff --git a/Makefile b/Makefile index 86ebba7..e1dab8c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -GPPPARAMS = -m32 +GPPPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore ASPARAMS = --32 LDPARAMS = -melf_i386 @@ -11,7 +11,7 @@ objs = loader.o kernel.o as $(ASPARAMS) -o $@ $< ferglos.bin: linker.ld $(objs) - ld $(LDPARAMS) -T linker.ld $< -o $@ $(objs) + ld $(LDPARAMS) -T $< -o $@ $(objs) install: ferglos.bin sudo cp $< /boot/ferglos.bin diff --git a/README.md b/README.md new file mode 100644 index 0000000..85ad977 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Ya boy wrote his own operating system!!!! diff --git a/kernel.cpp b/kernel.cpp index 4e87d96..2dba39c 100644 --- a/kernel.cpp +++ b/kernel.cpp @@ -1,8 +1,22 @@ +// yip - ya'boy is writing his own printf +// libc doesn't exist yet so got no choice + +void printf(char* str) { + unsigned short* vid_mem = (unsigned short*)0xb8000; + for (int i = 0; str[i] != '\0'; i++) { + //high byte is colour, so just need to copy to text address + vid_mem[i] = (vid_mem[i] * 0xFF00) | str[i]; + } +} + +extern "C" constructor start_ctors; +extern "C" constructor end_ctors; + /* take in the multiboot structure and the GRUB magic number not sure I actually need magic_num though */ -void ferglos_Main(void* mb_struct, unsigned int magic_num) { +extern "C" void ferglos_Main(void* mb_struct, unsigned int magic_num) { printf("Hello, Sailor!"); while (1) diff --git a/linker.ld b/linker.ld index e69de29..90d6ffe 100644 --- a/linker.ld +++ b/linker.ld @@ -0,0 +1,35 @@ +ENTRY(loader) +OUTPUT_FORMAT(elf32-i386) +OUTPUT_ARCH(i386:i386) + +SECTIONS +{ + . = 0x0100000; + .text : + { + *(.multiboot) + *(.text*) + *(.rodata) + } + + .data : + { + start_ctors = .; + KEEP(*(.init_array )); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*))); + end_ctors = .; + + *(.data) + } + + .bss : + { + *.(.bss) + } + + /DISCARD/ : + { + *(.fini_array*) + *(.comment) + } +} \ No newline at end of file