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

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

View File

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

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

View File

@ -6,7 +6,7 @@
; https://github.com/ice-bit/iceOS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
global kernel_load
global kernel_loader
extern kernel_main
section .text
@ -23,3 +23,6 @@ section .bss
align 4
kernel_stack:
resb KERNEL_STACK_SZ ; Reserver 4 KB

View File

@ -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);
}

View File

@ -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();

View File

@ -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);
}

View File

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

View File

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

View File

@ -12,13 +12,13 @@
#include <stdint.h> // For uinx_t
#include <stddef.h> // 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

View File

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