diff --git a/.giignore b/.giignore index 6d5206b..53b3cb2 100644 --- a/.giignore +++ b/.giignore @@ -49,4 +49,5 @@ modules.order Module.symvers Mkfile.old -dkms.conf \ No newline at end of file +dkms.conf +.vscode/* diff --git a/Makefile b/Makefile index 52f2e24..17c3a32 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,11 @@ iso: run: qemu-system-x86_64 -cdrom iceOS.iso +bochs: + bochs -f bochs_cfg -q + clean: rm -rf obj/ kernel/*.o kernel/cpu/*.o iso_root/boot/kernel.elf rm -rf kernel/drivers/*.o kernel/libc/*.o - rm -rf PyramidKernel.iso bochslog.txt commands \ No newline at end of file + rm -rf iceOS.iso bochslog.txt commands iso_root + rm -rf vscode/* \ No newline at end of file diff --git a/bochs_cfg b/bochs_cfg index e69de29..df47b6c 100644 --- a/bochs_cfg +++ b/bochs_cfg @@ -0,0 +1,12 @@ +# System configuration. +romimage: file=$BXSHARE/BIOS-bochs-latest +vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest +cpu: model=corei7_ivy_bridge_3770k, ips=120000000 +clock: sync=slowdown +megs: 256 +boot: cdrom, disk + + +# CDROM +ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15 +ata1-master: type=cdrom, path="iceOS.iso", status=inserted \ No newline at end of file diff --git a/build.sh b/build.sh index 5b7fed3..f5e3217 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ # grub config file mkdir -p iso_root/boot/grub/ -cat iso_root/boot/grub/grub.cfg < iso_root/boot/grub/grub.cfg << EOF set timeout = 0 set default = 0 @@ -13,10 +13,10 @@ EOF # CPU mkdir -p obj/ make -C kernel/cpu -cp kernel/cpu*.o obj/ +cp kernel/cpu/*.o obj/ # Kernel -make -C kernel/ +make -C kernel cp kernel/*.o obj/ # Drivers diff --git a/kernel/Makefile b/kernel/Makefile index beefc4a..abcec33 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -4,7 +4,7 @@ CC = i686-elf-gcc # cross-compiler CFLAGS = -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c -all:${OBJS} +all: ${OBJS} %.o: %.c $(CC) $(CFLAGS) $< -o $@ \ No newline at end of file diff --git a/kernel/cpu/Makefile b/kernel/cpu/Makefile index f9b37dc..535c5b6 100644 --- a/kernel/cpu/Makefile +++ b/kernel/cpu/Makefile @@ -1,8 +1,8 @@ -OBJS = multiboot.asm.o kernel_load.asm.o ports.asm.o +OBJS = multiboot.asm.o kernel_loader.asm.o ports.asm.o ASM = nasm ASMFLAGS = -f elf all: $(OBJS) -%.asm.o: +%.asm.o: %.asm $(ASM) $(ASMFLAGS) $< -o $@ \ No newline at end of file diff --git a/kernel/cpu/kernel_load.asm b/kernel/cpu/kernel_loader.asm similarity index 89% rename from kernel/cpu/kernel_load.asm rename to kernel/cpu/kernel_loader.asm index 7b36b52..2ad44d6 100644 --- a/kernel/cpu/kernel_load.asm +++ b/kernel/cpu/kernel_loader.asm @@ -6,7 +6,7 @@ ; https://github.com/ice-bit/iceOS ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -global kernel_load +global kernel_loader extern kernel_main section .text @@ -22,4 +22,7 @@ KERNEL_STACK_SZ equ 4096 ; 4 KB for the stack section .bss align 4 kernel_stack: - resb KERNEL_STACK_SZ ; Reserver 4 KB \ No newline at end of file + resb KERNEL_STACK_SZ ; Reserver 4 KB + + + diff --git a/kernel/drivers/tty.c b/kernel/drivers/tty.c index 253d7e5..7362d8b 100644 --- a/kernel/drivers/tty.c +++ b/kernel/drivers/tty.c @@ -9,7 +9,7 @@ static uint32_t fb_col = 0; // X static uint32_t fb_row = 0; // Y -void write_cell(int16_t i, int8_t c, uint8_t fg, uint8_t bg) { +void write_cell(int16_t i, uint8_t c, uint8_t fg, uint8_t bg) { uint8_t *fb = VGA_PTR; fb[i*2] = c; fb[i*2 + 1] = ((bg & 0x0F) << 4) | (fg | 0x0F); @@ -57,13 +57,9 @@ void kprint_c(uint8_t *buf, uint32_t len, uint8_t fg, uint8_t bg) { uint8_t c = buf[i]; if(c == '\n' || c == '\r') newline(); - else if(c == '\t') { + else { pos = fb_col + (fb_row * VGA_WIDTH); - write_cell(pos, " ", fg, bg); - cursor_adv(); - } else { - pos = fb_col + (fb_row * VGA_WIDTH); - write_cell(pos, c, fg, bg); + write_cell(pos, (uint8_t)c, fg, bg); cursor_adv(); } } @@ -74,7 +70,7 @@ void kprint(uint8_t *buf) { } void init_prompt() { - const uint8_t *prompt = "\nuser@iceOS-$"; + uint8_t *prompt = (uint8_t*)"\nuser@iceOS-$"; kprint_c(prompt, strlen(prompt), GREEN, BLACK); } diff --git a/kernel/drivers/tty.h b/kernel/drivers/tty.h index 9e308cd..1fab53f 100644 --- a/kernel/drivers/tty.h +++ b/kernel/drivers/tty.h @@ -45,7 +45,7 @@ enum TTY_COLORS { #define VGA_LOW_BYTE 15 /* Kernel's VGA API */ -void write_cell(int16_t i, int8_t c, uint8_t fg, uint8_t bg); +void write_cell(int16_t i, uint8_t c, uint8_t fg, uint8_t bg); void move_cursor(uint16_t pos); void cursor_adv(); void backspace(); diff --git a/kernel/libc/stdio.c b/kernel/libc/stdio.c index 235235e..f288a05 100644 --- a/kernel/libc/stdio.c +++ b/kernel/libc/stdio.c @@ -3,13 +3,13 @@ #include "../drivers/tty.h" int printf(const char *format, ...) { - char buf[20],c,*s; + uint8_t buf[20],c,*s; int val; int32_t uval; va_list ap; va_start(ap, format); - for(size_t i = 0; i < strlen(format); i++) { + for(size_t i = 0; i < strlen((uint8_t*)format); i++) { if(format[i] == '%') { i++; while(format[i] == ' ') @@ -32,23 +32,23 @@ int printf(const char *format, ...) { kprint(buf); break; case 'c': - s = va_arg(ap, char*); + s = va_arg(ap, uint8_t*); kprint_c(&c, 1, WHITE, BLACK); break; case 's': - s = va_arg(ap, char*); + s = va_arg(ap, uint8_t*); kprint(s); break; default: - kprint_c((char*)format+1, 1, WHITE, BLACK); + kprint_c((uint8_t*)format+1, 1, WHITE, BLACK); } } else - kprint_c((char*)format+1, 1, WHITE, BLACK); + kprint_c((uint8_t*)format+1, 1, WHITE, BLACK); } va_end(ap); return 0; } -void puts(int8_t *buf) { +void puts(const char *buf) { printf("%s\n", buf); } \ No newline at end of file diff --git a/kernel/libc/stdio.h b/kernel/libc/stdio.h index ffd50bd..81bd41e 100644 --- a/kernel/libc/stdio.h +++ b/kernel/libc/stdio.h @@ -14,6 +14,6 @@ #include int printf(const char *format, ...); -void puts(uint8_t *buf); +void puts(const char *buf); #endif \ No newline at end of file diff --git a/kernel/libc/string.c b/kernel/libc/string.c index 599877f..1670b35 100644 --- a/kernel/libc/string.c +++ b/kernel/libc/string.c @@ -2,15 +2,14 @@ // C library implementation -int32_t strcmp(const char *s1, const char *s2) { +int32_t strcmp(const uint8_t *s1, const uint8_t *s2) { while ((*s1) && (*s1 == *s2)) { s1++; s2++; } return (*(uint8_t*)s1 - *(uint8_t*)s2); } - -char *itoa(int val, char *buf, int radix) { +uint8_t *itoa(int32_t val, uint8_t *buf, uint32_t radix) { uint32_t i = 0; uint32_t start = i; @@ -34,19 +33,21 @@ char *itoa(int val, char *buf, int radix) { buf[i++]= a + 'a' - 10; } while(x /= radix); - char *s = buf+start; - char *e = buf+(i-1); + uint8_t *s = buf+start; + uint8_t *e = buf+(i-1); while(s < e) { - char t = *s; + uint8_t t = *s; *s = *e; *e = t; i++; e--; } + buf[i] = 0; + return buf; } -char *uitoa(uint32_t val, char *buf, int radix) { +uint8_t *uitoa(uint32_t val, uint8_t *buf, uint32_t radix) { uint32_t i = 0; uint32_t start = i; uint32_t x = val; @@ -65,11 +66,11 @@ char *uitoa(uint32_t val, char *buf, int radix) { buf[i++] = a + 'a' - 10; } while(x /= radix); - char *s = buf+start; - char *e = buf+(i+1); + uint8_t *s = buf+start; + uint8_t *e = buf+(i+1); while(s < e) { - char t = *s; + uint8_t t = *s; *s = *e; *e = t; s++; @@ -80,7 +81,7 @@ char *uitoa(uint32_t val, char *buf, int radix) { return buf; } -size_t strlen(const char *buf) { +size_t strlen(const uint8_t *buf) { unsigned int i = 0; while(buf[i] != 0) i++; @@ -90,7 +91,7 @@ size_t strlen(const char *buf) { /* Worst memset implementation * i could find on the net. * however it works so... */ -void *memset(void *s, int c, size_t n) { +void *memset(void *s, uint32_t c, size_t n) { char *mem = (char*)s; for(size_t i = 0; i < n; i++) @@ -109,14 +110,14 @@ void *memmove(void *dst, const void *src, size_t len) { return dstmem; } -void strupper(char *str) { +void strupper(uint8_t *str) { for(unsigned int i = 0; i < strlen(str); i++) { if(str[i] == 'a' && str[i] < 'z') str[i] &= 0x4F; } } -void strlower(char *str) { +void strlower(uint8_t *str) { for(unsigned int i = 0; i < strlen(str); i++) { if(str[i] == 'A' && str[i] < 'Z') str[i] |= 0x60; diff --git a/kernel/libc/string.h b/kernel/libc/string.h index a7401a1..b18edd3 100644 --- a/kernel/libc/string.h +++ b/kernel/libc/string.h @@ -12,13 +12,13 @@ #include // For uinx_t #include // For size_t -int32_t strcmp(const char *s1, const char *s2); -char *itoa(int val, char *buf, int radix); -char *uitoa(uint32_t val, char *buf, int radix); -size_t strlen(const char *buf); -void *memset(void *s, int c, size_t n); +int32_t strcmp(const uint8_t *s1, const uint8_t *s2); +uint8_t *itoa(int32_t val, uint8_t *buf, uint32_t radix); +uint8_t *uitoa(uint32_t val, uint8_t *buf, uint32_t radix); +size_t strlen(const uint8_t *buf); +void *memset(void *s, uint32_t c, size_t n); void *memmove(void *dst, const void *src, size_t len); -void strupper(char *str); -void strlower(char *str); +void strupper(uint8_t *str); +void strlower(uint8_t *str); #endif diff --git a/link.ld b/link.ld index 2544e5c..3328d73 100644 --- a/link.ld +++ b/link.ld @@ -1,4 +1,4 @@ -ENTRY(kernel_load) +ENTRY(kernel_loader) . = 0x00100000;