diff --git a/Makefile b/Makefile index 71990e8..1c7bf59 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,13 @@ CFLAGS = -m32 -nostdlib -fno-builtin -fno-exceptions -fno-leading-underscore -fno-pie -fno-stack-protector LDFLAGS = -disk.img: boot.sector kernel.bin hello.bin print.bin hello.txt boot32.bin kernel32.bin +DISK_IMG_FILES = kernel.bin hello.bin print.bin boot32.bin kernel32.bin +KERNEL32_OBJS = screenstuff.o io.o kernel32_strap.o kernel32.o + +run: disk.img + qemu-system-x86_64 disk.img + +disk.img: clean boot.sector $(DISK_IMG_FILES) dd if=/dev/zero of=disk.img count=43 bs=100k dd if=boot.sector of=disk.img conv=notrunc mount disk.img img.d @@ -10,26 +16,20 @@ disk.img: boot.sector kernel.bin hello.bin print.bin hello.txt boot32.bin kernel umount img.d chmod 777 disk.img +clean: + rm $(DISK_IMG_FILES) $(KERNEL32_OBJS) boot.sector disk.img || true + boot.sector: boot.asm nasm $< -o $@ -kernel.bin: kernel.asm +%.bin: %.asm nasm $< -o $@ -hello.bin: hello.asm - nasm $< -o $@ - -print.bin: print.asm - nasm $< -o $@ - -boot32.bin: boot32.asm - nasm $< -o $@ - -kernel32.bin: kernel32.ld kernel32_strap.o kernel32.o - ld $(LDFLAGS) -T $< - -kernel32.o: kernel32.c - gcc $(CFLAGS) -o $@ -c $< +kernel32.bin: kernel32.ld $(KERNEL32_OBJS) + ld $(LDFLAGS) -T $< $(KERNEL32_OBJS) kernel32_strap.o: kernel32_strap.asm - nasm -felf32 $< -o $@ \ No newline at end of file + nasm -felf32 $< -o $@ + +%.o: %.c + gcc $(CFLAGS) -o $@ -c $< \ No newline at end of file diff --git a/io.c b/io.c new file mode 100644 index 0000000..bcd6885 --- /dev/null +++ b/io.c @@ -0,0 +1,10 @@ +#include "io.h" + +void outb(uint16_t portnumber, uint8_t data) { + asm volatile("outb %0, %1" : : "a" (data), "Nd" (portnumber)); +} +uint8_t inb(uint16_t portnumber) { + uint8_t result; + asm volatile("inb %1, %0" : "=a" (result) : "Nd" (portnumber)); + return result; +} \ No newline at end of file diff --git a/io.h b/io.h new file mode 100644 index 0000000..a558cf3 --- /dev/null +++ b/io.h @@ -0,0 +1,9 @@ +#ifndef IO_H +#define IO_H + +#include "types.h" + +void outb(uint16_t portnumber, uint8_t data); +uint8_t inb(uint16_t portnumber); + +#endif \ No newline at end of file diff --git a/kernel32.c b/kernel32.c index 8ad01c5..e6d26f7 100644 --- a/kernel32.c +++ b/kernel32.c @@ -1,155 +1,6 @@ -#include #include "types.h" - -uint16_t* VMEM_ADDR = (uint16_t*)0xb8000; -const int TERM_WIDTH = 80; -const int TERM_HEIGHT = 25; - -int cursor_x = 0; -int cursor_y = 0; - -void outb(uint16_t portnumber, uint8_t data) { - asm volatile("outb %0, %1" : : "a" (data), "Nd" (portnumber)); -} -uint8_t inb(uint16_t portnumber) { - uint8_t result; - asm volatile("inb %1, %0" : "=a" (result) : "Nd" (portnumber)); - return result; -} - -uint16_t get_curpos() { - uint16_t cursor_position = 0; - uint8_t* cursor_position_split = (uint8_t*)&cursor_position; - outb(0x3D4, 0x0F); - cursor_position_split[0] = inb(0x3D5); - outb(0x3D4, 0x0E); - cursor_position_split[1] = inb(0x3D5); - return cursor_position; -} - -void init_term() { - uint16_t cursor_position = get_curpos(); - - cursor_y = cursor_position / TERM_WIDTH; - cursor_x = cursor_position % TERM_WIDTH; -} - -void clear_screen() { - for (int i=0; i +#include "types.h" +#include "io.h" + +uint16_t get_curpos(); +void init_term(); +void clear_screen(); +void clear_line(int line); +void set_curpos_raw(int curpos); +void set_curpos(int x, int y); +int int_to_decimal(unsigned int number, char* string_buffer); +int int_to_hex(unsigned int number, char* string_buffer); +void printf(const char* string, ...); + +#endif \ No newline at end of file