diff --git a/.gitignore b/.gitignore index 3d5b43a..5c63990 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ badloader.img baddos.img +kernel_entry.o +kernel.o +kernel.bin \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..abe21c6 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +all: bootloader baddos + +bootloader: + nasm -f bin main.asm -o badloader.img +kernel: + nasm -f elf kernel_entry.asm -o kernel_entry.o + gcc -m16 -ffreestanding -c kernel.c -o kernel.o + ld -m elf_i386 -T linker.ld --oformat binary kernel_entry.o kernel.o -o kernel.bin +baddos: bootloader kernel + cat badloader.img kernel.bin > baddos.img +clean: + rm -f *.o *.img *.bin diff --git a/kernel.c b/kernel.c index 7bf7f9c..b9fb9e5 100644 --- a/kernel.c +++ b/kernel.c @@ -11,7 +11,7 @@ void print(const char* str) { } } -void main() { +void kernel_main() { print("Welcome to BadDOS!\r\n"); print("type something or die:\r\n"); @@ -21,4 +21,25 @@ void main() { print_char(c); if (c == '\r') print("\r\n"); } +} + +char get_char() { + char c; + __asm__ __volatile__( + "mov ah, 0x00;" + "int 0x16;" + "mov %[char], al;" + : [char] "=r" (c) + ); + return c; +} + +void print_char(char c) { + __asm__ __volatile__( + "mov ah, 0x0E;" + "mov al, %[char];" + "int 0x10;" + : + : [char] "r" (c) + ); } \ No newline at end of file diff --git a/kernel_entry.asm b/kernel_entry.asm index cd7dce3..b7dc079 100644 --- a/kernel_entry.asm +++ b/kernel_entry.asm @@ -1,7 +1,11 @@ ; wait, WHAT? we have a bad DOS now????? This is absurd! You can't just add a SECOND project into the FIRST project. [BITS 16] -[ORG 0x7E00] +[GLOBAL start] +[EXTERN kernel_main] + + + start: cli diff --git a/linker.ld b/linker.ld new file mode 100644 index 0000000..553ed70 --- /dev/null +++ b/linker.ld @@ -0,0 +1,15 @@ +SECTIONS { + . = 0x7E00; + + .text : { + *(.text) + } + + .data : { + *(.data) + } + + .bss : { + *(.bss) + } +} \ No newline at end of file