Fixed all previous bugs...however strange things happens when OS runs

This commit is contained in:
ice-bit 2019-07-03 21:04:05 +02:00
parent bec03e3d1b
commit a0b6eb882a
14 changed files with 66 additions and 49 deletions

View File

@ -49,4 +49,5 @@
modules.order modules.order
Module.symvers Module.symvers
Mkfile.old Mkfile.old
dkms.conf dkms.conf
.vscode/*

View File

@ -4,7 +4,11 @@ iso:
run: run:
qemu-system-x86_64 -cdrom iceOS.iso qemu-system-x86_64 -cdrom iceOS.iso
bochs:
bochs -f bochs_cfg -q
clean: clean:
rm -rf obj/ kernel/*.o kernel/cpu/*.o iso_root/boot/kernel.elf rm -rf obj/ kernel/*.o kernel/cpu/*.o iso_root/boot/kernel.elf
rm -rf kernel/drivers/*.o kernel/libc/*.o rm -rf kernel/drivers/*.o kernel/libc/*.o
rm -rf PyramidKernel.iso bochslog.txt commands rm -rf iceOS.iso bochslog.txt commands iso_root
rm -rf vscode/*

View File

@ -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

View File

@ -1,6 +1,6 @@
# grub config file # grub config file
mkdir -p iso_root/boot/grub/ mkdir -p iso_root/boot/grub/
cat iso_root/boot/grub/grub.cfg <<EOF cat > iso_root/boot/grub/grub.cfg << EOF
set timeout = 0 set timeout = 0
set default = 0 set default = 0
@ -13,10 +13,10 @@ EOF
# CPU # CPU
mkdir -p obj/ mkdir -p obj/
make -C kernel/cpu make -C kernel/cpu
cp kernel/cpu*.o obj/ cp kernel/cpu/*.o obj/
# Kernel # Kernel
make -C kernel/ make -C kernel
cp kernel/*.o obj/ cp kernel/*.o obj/
# Drivers # Drivers

View File

@ -4,7 +4,7 @@ CC = i686-elf-gcc # cross-compiler
CFLAGS = -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c CFLAGS = -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c
all:${OBJS} all: ${OBJS}
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) $< -o $@ $(CC) $(CFLAGS) $< -o $@

View File

@ -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 ASM = nasm
ASMFLAGS = -f elf ASMFLAGS = -f elf
all: $(OBJS) all: $(OBJS)
%.asm.o: %.asm.o: %.asm
$(ASM) $(ASMFLAGS) $< -o $@ $(ASM) $(ASMFLAGS) $< -o $@

View File

@ -6,7 +6,7 @@
; https://github.com/ice-bit/iceOS ; ; https://github.com/ice-bit/iceOS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
global kernel_load global kernel_loader
extern kernel_main extern kernel_main
section .text section .text
@ -22,4 +22,7 @@ KERNEL_STACK_SZ equ 4096 ; 4 KB for the stack
section .bss section .bss
align 4 align 4
kernel_stack: kernel_stack:
resb KERNEL_STACK_SZ ; Reserver 4 KB resb KERNEL_STACK_SZ ; Reserver 4 KB

View File

@ -9,7 +9,7 @@
static uint32_t fb_col = 0; // X static uint32_t fb_col = 0; // X
static uint32_t fb_row = 0; // Y 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; uint8_t *fb = VGA_PTR;
fb[i*2] = c; fb[i*2] = c;
fb[i*2 + 1] = ((bg & 0x0F) << 4) | (fg | 0x0F); 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]; uint8_t c = buf[i];
if(c == '\n' || c == '\r') if(c == '\n' || c == '\r')
newline(); newline();
else if(c == '\t') { else {
pos = fb_col + (fb_row * VGA_WIDTH); pos = fb_col + (fb_row * VGA_WIDTH);
write_cell(pos, " ", fg, bg); write_cell(pos, (uint8_t)c, fg, bg);
cursor_adv();
} else {
pos = fb_col + (fb_row * VGA_WIDTH);
write_cell(pos, c, fg, bg);
cursor_adv(); cursor_adv();
} }
} }
@ -74,7 +70,7 @@ void kprint(uint8_t *buf) {
} }
void init_prompt() { void init_prompt() {
const uint8_t *prompt = "\nuser@iceOS-$"; uint8_t *prompt = (uint8_t*)"\nuser@iceOS-$";
kprint_c(prompt, strlen(prompt), GREEN, BLACK); kprint_c(prompt, strlen(prompt), GREEN, BLACK);
} }

View File

@ -45,7 +45,7 @@ enum TTY_COLORS {
#define VGA_LOW_BYTE 15 #define VGA_LOW_BYTE 15
/* Kernel's VGA API */ /* 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 move_cursor(uint16_t pos);
void cursor_adv(); void cursor_adv();
void backspace(); void backspace();

View File

@ -3,13 +3,13 @@
#include "../drivers/tty.h" #include "../drivers/tty.h"
int printf(const char *format, ...) { int printf(const char *format, ...) {
char buf[20],c,*s; uint8_t buf[20],c,*s;
int val; int val;
int32_t uval; int32_t uval;
va_list ap; va_list ap;
va_start(ap, format); 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] == '%') { if(format[i] == '%') {
i++; i++;
while(format[i] == ' ') while(format[i] == ' ')
@ -32,23 +32,23 @@ int printf(const char *format, ...) {
kprint(buf); kprint(buf);
break; break;
case 'c': case 'c':
s = va_arg(ap, char*); s = va_arg(ap, uint8_t*);
kprint_c(&c, 1, WHITE, BLACK); kprint_c(&c, 1, WHITE, BLACK);
break; break;
case 's': case 's':
s = va_arg(ap, char*); s = va_arg(ap, uint8_t*);
kprint(s); kprint(s);
break; break;
default: default:
kprint_c((char*)format+1, 1, WHITE, BLACK); kprint_c((uint8_t*)format+1, 1, WHITE, BLACK);
} }
} else } else
kprint_c((char*)format+1, 1, WHITE, BLACK); kprint_c((uint8_t*)format+1, 1, WHITE, BLACK);
} }
va_end(ap); va_end(ap);
return 0; return 0;
} }
void puts(int8_t *buf) { void puts(const char *buf) {
printf("%s\n", buf); printf("%s\n", buf);
} }

View File

@ -14,6 +14,6 @@
#include <stdarg.h> #include <stdarg.h>
int printf(const char *format, ...); int printf(const char *format, ...);
void puts(uint8_t *buf); void puts(const char *buf);
#endif #endif

View File

@ -2,15 +2,14 @@
// C library implementation // 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)) { while ((*s1) && (*s1 == *s2)) {
s1++; s1++;
s2++; s2++;
} }
return (*(uint8_t*)s1 - *(uint8_t*)s2); return (*(uint8_t*)s1 - *(uint8_t*)s2);
} }
uint8_t *itoa(int32_t val, uint8_t *buf, uint32_t radix) {
char *itoa(int val, char *buf, int radix) {
uint32_t i = 0; uint32_t i = 0;
uint32_t start = i; uint32_t start = i;
@ -34,19 +33,21 @@ char *itoa(int val, char *buf, int radix) {
buf[i++]= a + 'a' - 10; buf[i++]= a + 'a' - 10;
} while(x /= radix); } while(x /= radix);
char *s = buf+start; uint8_t *s = buf+start;
char *e = buf+(i-1); uint8_t *e = buf+(i-1);
while(s < e) { while(s < e) {
char t = *s; uint8_t t = *s;
*s = *e; *s = *e;
*e = t; *e = t;
i++; i++;
e--; 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 i = 0;
uint32_t start = i; uint32_t start = i;
uint32_t x = val; uint32_t x = val;
@ -65,11 +66,11 @@ char *uitoa(uint32_t val, char *buf, int radix) {
buf[i++] = a + 'a' - 10; buf[i++] = a + 'a' - 10;
} while(x /= radix); } while(x /= radix);
char *s = buf+start; uint8_t *s = buf+start;
char *e = buf+(i+1); uint8_t *e = buf+(i+1);
while(s < e) { while(s < e) {
char t = *s; uint8_t t = *s;
*s = *e; *s = *e;
*e = t; *e = t;
s++; s++;
@ -80,7 +81,7 @@ char *uitoa(uint32_t val, char *buf, int radix) {
return buf; return buf;
} }
size_t strlen(const char *buf) { size_t strlen(const uint8_t *buf) {
unsigned int i = 0; unsigned int i = 0;
while(buf[i] != 0) while(buf[i] != 0)
i++; i++;
@ -90,7 +91,7 @@ size_t strlen(const char *buf) {
/* Worst memset implementation /* Worst memset implementation
* i could find on the net. * i could find on the net.
* however it works so... */ * 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; char *mem = (char*)s;
for(size_t i = 0; i < n; i++) for(size_t i = 0; i < n; i++)
@ -109,14 +110,14 @@ void *memmove(void *dst, const void *src, size_t len) {
return dstmem; return dstmem;
} }
void strupper(char *str) { void strupper(uint8_t *str) {
for(unsigned int i = 0; i < strlen(str); i++) { for(unsigned int i = 0; i < strlen(str); i++) {
if(str[i] == 'a' && str[i] < 'z') if(str[i] == 'a' && str[i] < 'z')
str[i] &= 0x4F; str[i] &= 0x4F;
} }
} }
void strlower(char *str) { void strlower(uint8_t *str) {
for(unsigned int i = 0; i < strlen(str); i++) { for(unsigned int i = 0; i < strlen(str); i++) {
if(str[i] == 'A' && str[i] < 'Z') if(str[i] == 'A' && str[i] < 'Z')
str[i] |= 0x60; str[i] |= 0x60;

View File

@ -12,13 +12,13 @@
#include <stdint.h> // For uinx_t #include <stdint.h> // For uinx_t
#include <stddef.h> // For size_t #include <stddef.h> // For size_t
int32_t strcmp(const char *s1, const char *s2); int32_t strcmp(const uint8_t *s1, const uint8_t *s2);
char *itoa(int val, char *buf, int radix); uint8_t *itoa(int32_t val, uint8_t *buf, uint32_t radix);
char *uitoa(uint32_t val, char *buf, int radix); uint8_t *uitoa(uint32_t val, uint8_t *buf, uint32_t radix);
size_t strlen(const char *buf); size_t strlen(const uint8_t *buf);
void *memset(void *s, int c, size_t n); void *memset(void *s, uint32_t c, size_t n);
void *memmove(void *dst, const void *src, size_t len); void *memmove(void *dst, const void *src, size_t len);
void strupper(char *str); void strupper(uint8_t *str);
void strlower(char *str); void strlower(uint8_t *str);
#endif #endif

View File

@ -1,4 +1,4 @@
ENTRY(kernel_load) ENTRY(kernel_loader)
. = 0x00100000; . = 0x00100000;