diff --git a/Makefile b/Makefile
index 7403716..d7ae0dc 100644
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,24 @@ OBJDIR=build/obj
BINDIR=build/bin
# Object to link (temp)
-l_objects=./build/obj/kaleid/crtlib/memory.o ./build/obj/kaleid/crtlib/rand.o ./build/obj/kaleid/crtlib/string.o ./build/obj/kaleid/crtlib/ultoa.o ./build/obj/kaleid/crtlib/strtol.o ./build/obj/kaleid/crtlib/utoa.o ./build/obj/kaleid/crtlib/status.o ./build/obj/kaleid/crtlib/atoul.o ./build/obj/kaleid/crtlib/atol.o ./build/obj/kaleid/crtlib/itoa.o ./build/obj/kaleid/crtlib/ltoa.o ./build/obj/kaleid/crtlib/atou.o ./build/obj/kaleid/crtlib/arith.o ./build/obj/kaleid/crtlib/atoi.o ./build/obj/kaleid/extras/prog.o ./build/obj/kaleid/extras/argv.o ./build/obj/kaleid/kernel/init/table.o ./build/obj/kaleid/kernel/init/init.o ./build/obj/kaleid/kernel/io/vga.o ./build/obj/kaleid/kernel/io/cursor.o ./build/obj/kaleid/kernel/io/term.o ./build/obj/kaleid/kernel/ke/panic.o ./build/obj/boot/loader.o
+l_objects=./build/obj/kaleid/crtlib/memory.o \
+ ./build/obj/kaleid/crtlib/rand.o \
+ ./build/obj/kaleid/crtlib/string.o \
+ ./build/obj/kaleid/crtlib/ultoa.o \
+ ./build/obj/kaleid/crtlib/utoa.o \
+ ./build/obj/kaleid/crtlib/ctype.o \
+ ./build/obj/kaleid/crtlib/itoa.o \
+ ./build/obj/kaleid/crtlib/ltoa.o \
+ ./build/obj/kaleid/crtlib/sprintf.o \
+ ./build/obj/kaleid/extras/prog.o \
+ ./build/obj/kaleid/extras/argv.o \
+ ./build/obj/kaleid/kernel/init/table.o \
+ ./build/obj/kaleid/kernel/init/init.o \
+ ./build/obj/kaleid/kernel/io/vga.o \
+ ./build/obj/kaleid/kernel/io/cursor.o \
+ ./build/obj/kaleid/kernel/io/term.o \
+ ./build/obj/kaleid/kernel/ke/panic.o \
+ ./build/obj/boot/loader.o
#Color codes
CL='\033[0;32m'
@@ -91,6 +108,7 @@ make_disk:
@$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img
@echo ${CL2}[make_disk]${CL} OK${CL3}
+
kaleid: kernel loader
test: kaleid
@@ -98,7 +116,6 @@ test: kaleid
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm
-
test32: kaleid
@qemu-system-i386 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log &
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm
diff --git a/Makefile.in b/Makefile.in
index 8e4c573..eec9b98 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -27,7 +27,7 @@
// The madman's Makefile
#include "build/preproc.h"
-CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc"
+CCNAME=x86_64-elf-gcc
CC2NAME=gcc
COPTIM=-O2
CWARNS=-Wall -Wextra // -Werror=implicit-function-declaration
@@ -35,7 +35,7 @@ CINCLUDES=-Ikaleid/include
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large // -std=gnu11
CFLAGS2=_ASMTYPE -mno-red-zone -mno-mmx -mno-sse -mno-sse2
-CFLAGS=$(CFLAGS1) $(CFLAGS2)
+CFLAGS=$(CFLAGS1) $(CFLAGS2) -DNDEBUG
CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES)
@@ -48,16 +48,7 @@ KERNDIR=kaleid/kernel
SYSTDIR=kaleid/system
LINXDIR=kaleid/test
-//----------------------------------------------------------------------------#
-// TESTING MAKEFILE
-pseudo_kern:
- $(ASM) $(BOOTFLAGS) $(BOOTDIR)/pseudo_kernel.s -o $(OBJDIR)/boot/pkernel.bin
-
-testing: bootloader pseudo_kern
- cat $(BINDIR)/bootloader.bin $(OBJDIR)/boot/pkernel.bin > $(BINDIR)/boot.bin
-
-//----------------------------------------------------------------------------#
// COMMON MAKEFILE
COBJDIR=$(OBJDIR)/$(COMMDIR)
@@ -69,25 +60,25 @@ TCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES)
KCC=$(CC) -D_OSK_SOURCE -D_KALEID_KERNEL
comm-convert:
- COMPILE_CONVRT1(itoa) -D_NEED_ITOA
- COMPILE_CONVRT1(ltoa) -D_NEED_LTOA
- COMPILE_CONVRT1(utoa) -D_NEED_UTOA
- COMPILE_CONVRT1(ultoa) -D_NEED_ULTOA
- COMPILE_CONVRT2(atoi) -D_NEED_ATOI
- COMPILE_CONVRT2(atol) -D_NEED_ATOL
- COMPILE_CONVRT2(atou) -D_NEED_ATOU
- COMPILE_CONVRT2(atoul) -D_NEED_ATOUL
+ @COMPILE_CONVRT1(itoa) -D_NEED_ITOA
+ @COMPILE_CONVRT1(ltoa) -D_NEED_LTOA
+ @COMPILE_CONVRT1(utoa) -D_NEED_UTOA
+ @COMPILE_CONVRT1(ultoa) -D_NEED_ULTOA
+ @COMPILE_CONVRT2(atoi) -D_NEED_ATOI
+ @COMPILE_CONVRT2(atol) -D_NEED_ATOL
+ @COMPILE_CONVRT2(atou) -D_NEED_ATOU
+ @COMPILE_CONVRT2(atoul) -D_NEED_ATOUL
common: comm-convert
- COMPILE_COMMON(rand)
- COMPILE_COMMON(ctype)
- COMPILE_COMMON(string)
- COMPILE_COMMON(status)
- COMPILE_COMMON(memory) -fno-strict-aliasing
- COMPILE_COMMON(strtol)
- COMPILE_COMMON(sprintf)
- COMPILE_COMMON(../extras/prog)
- COMPILE_COMMON(../extras/argv)
+ @COMPILE_COMMON(rand)
+ @COMPILE_COMMON(ctype)
+ @COMPILE_COMMON(string)
+ @COMPILE_COMMON(status)
+ @COMPILE_COMMON(memory) -fno-strict-aliasing
+ @COMPILE_COMMON(strtol)
+ @COMPILE_COMMON(sprintf)
+ @COMPILE_COMMON(../extras/prog)
+ @COMPILE_COMMON(../extras/argv)
tests: common
$(TCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o
@@ -101,12 +92,12 @@ KOBJDIR=$(OBJDIR)/$(KERNDIR)
KERNOBJS=KOBJ6(init/init, init/table, ke/panic, io/term, io/cursor, io/vga)
kernel: common
- COMPILE_KERNEL(init/init)
- COMPILE_KERNEL(init/table)
- COMPILE_KERNEL(ke/panic)
- COMPILE_KERNEL(io/cursor)
- COMPILE_KERNEL(io/term)
- COMPILE_KERNEL(io/vga)
+ @COMPILE_KERNEL(init/init)
+ @COMPILE_KERNEL(init/table)
+ @COMPILE_KERNEL(ke/panic)
+ @COMPILE_KERNEL(io/cursor)
+ @COMPILE_KERNEL(io/term)
+ @COMPILE_KERNEL(io/vga)
//LINK_KERNEL(kaleid-kernel.elf)
//----------------------------------------------------------------------------#
diff --git a/boot/loader/cpu/cpu.inc b/boot/loader/cpu/cpu.inc
index 8b92819..25a3b08 100644
--- a/boot/loader/cpu/cpu.inc
+++ b/boot/loader/cpu/cpu.inc
@@ -23,6 +23,10 @@
; along with OS/K. If not, see . ;
;=----------------------------------------------------------------------------=;
+[global temporize]
+[global bitemporize]
+[global tritemporize]
+
[BITS 64]
temporize:
@@ -60,4 +64,11 @@ tritemporize:
; ---------------------------------------------------------------------------- ;
; Returns the CPU Vendor String.pointer in eax ;
; ---------------------------------------------------------------------------- ;
-cpu_vendor
+cpu_vendor:
+
+ ;; Calling the competent authorities
+ mov eax, 0
+ cpuid
+
+ ret
+.string db " "
diff --git a/boot/loader/io/terminal.inc b/boot/loader/io/terminal.inc
index 1037c10..c2bce9a 100644
--- a/boot/loader/io/terminal.inc
+++ b/boot/loader/io/terminal.inc
@@ -22,7 +22,7 @@
; You should have received a copy of the GNU General Public License ;
; along with OS/K. If not, see . ;
;=----------------------------------------------------------------------------=;
-
+[global testf]
;;VIDEO
%define TRAM 0xB8000 ; [T]ext[RAM]
@@ -41,6 +41,17 @@ VGA_X dq 0
[BITS 64]
+testf:
+ push rsi
+ push rbx
+ mov esi, teststr
+ mov bl, 0xF
+ call write
+ pop rsi
+ pop rbx
+ ret
+teststr: db "Salut",0
+
;-----------------------------------------------------------------------;
; x64/LM Clear Text Screen Function ;
diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm
index 0ddf7b6..33236e0 100644
--- a/boot/loader/loader.asm
+++ b/boot/loader/loader.asm
@@ -62,16 +62,16 @@ MB_start:
; Prints 'ERR:XX' where 'XX' is the str in AX ;
; ---------------------------------------------------------------------------- ;
Error:
- mov word [CODE], ax
+ mov word [.code], ax
push esi
mov bl, 0x0c
- mov esi, ERGO
+ mov esi, .ergo
call write32
pop esi
jmp Die
-ERGO : db "A", 219, 219, " Error "
-CODE : db "00"
- db 0x0
+.ergo : db 219, 219, 219, " Error "
+.code : db "00"
+ db 0x0
; ---------------------------------------------------------------------------- ;
; Kills the mind of your computer to get it prostrated ;
; ---------------------------------------------------------------------------- ;
@@ -101,11 +101,11 @@ lbegin:
call clear ; Clear the screen
;; BEGIN OF CHECKLIST
- call MB_check ; Check Multiboot State
+ call MB_check ; Check Multiboot State, ERR 01
- call Check_cpuid ; Check if cpuid supported
- call Is64Bits ; Check if long mode available
- call CheckA20 ; Check if A20 is correctly enable
+ call Check_cpuid ; Check if cpuid supported, ERR 02
+ call Is64Bits ; Check if long mode available, ERR 03
+ call CheckA20 ; Check if A20 is correctly enable, ERR 04
;; BEGIN OF WORK
call Setup_paging ; Enable paging
@@ -126,6 +126,7 @@ lbegin:
x64_K db "Now in x64 long mode", 0x0A, 0x0D, 0x0
GoKernel db "Launching Kernel...", 0
+nokernel db 219, 219, 219, " Error 05 : Kernel returns",0
_loader64:
;; Some cleanup
@@ -152,7 +153,12 @@ _loader64:
call tritemporize ; Let time to see
extern StartKern
- jmp StartKern
+ call StartKern
;; We must never reach this point ------------------------------------------- ;;
+ call tritemporize ; Let time to see
+ call clear
+ mov bl, 0x0c
+ mov esi, nokernel ; Error 05
+ call write
jmp Die
diff --git a/kaleid/crtlib/sprintf.c b/kaleid/crtlib/sprintf.c
index 5613434..8174ddd 100644
--- a/kaleid/crtlib/sprintf.c
+++ b/kaleid/crtlib/sprintf.c
@@ -230,6 +230,7 @@ size_t vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
// Unknown/unsupported modifier :|
*str++ = mod;
+ ret++;
break;
}
diff --git a/kaleid/include/kernel/base.h b/kaleid/include/kernel/base.h
index 507a7ce..cb5a160 100644
--- a/kaleid/include/kernel/base.h
+++ b/kaleid/include/kernel/base.h
@@ -61,6 +61,7 @@ typedef enum KernelState_t KernelState_t;
// Get Process_t structure of current CPU
#define GetCurCPU() (cpuTable[_GetCurCPU()])
+#define PANICSTR_SIZE 1024
//------------------------------------------//
@@ -73,7 +74,7 @@ struct Processor_t
int index;
// Panic string
- char panicStr[1024];
+ char panicStr[PANICSTR_SIZE];
// Number of ticks since boot time
ulong ticks;
diff --git a/kaleid/include/kernel/term.h b/kaleid/include/kernel/term.h
index 83d2bb2..29477ee 100644
--- a/kaleid/include/kernel/term.h
+++ b/kaleid/include/kernel/term.h
@@ -96,6 +96,9 @@ extern Terminal_t *stdOut;
#define GetStdOut() (stdOut)
#define SetStdOut(x) (stdOut = (x))
+// Debug purposes
+volatile ushort *vga;
+
//------------------------------------------//
#ifndef _NO_DEBUG
diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c
index 5dbbdcd..cfa2991 100644
--- a/kaleid/kernel/init/init.c
+++ b/kaleid/kernel/init/init.c
@@ -25,11 +25,17 @@
#include
#include
+
+extern void testf(void);
+
//
// Entry point of the Kaleid kernel
//
-noreturn void StartKern(void* mbt, unsigned int mb_magic)
+noreturn void StartKern(void *mbInfo, int mbMagic)
{
+ (void)mbInfo;
+ (void)mbMagic;
+
// We're not ready to deal with interrupts
DisableIRQs();
diff --git a/kaleid/kernel/init/table.c b/kaleid/kernel/init/table.c
index 273105a..5fcdd2c 100644
--- a/kaleid/kernel/init/table.c
+++ b/kaleid/kernel/init/table.c
@@ -27,5 +27,7 @@
int cpuCount = 1;
Processor_t cpuTable[NCPUS] = {0};
-Terminal_t *stdOut, *stdDbg;
+Terminal_t *stdOut = 0, *stdDbg = 0;
+
+volatile ushort *vga = (volatile ushort *)0xB8000;
diff --git a/kaleid/kernel/io/term.c b/kaleid/kernel/io/term.c
index 1d8adcc..fa5da06 100644
--- a/kaleid/kernel/io/term.c
+++ b/kaleid/kernel/io/term.c
@@ -32,12 +32,10 @@ extern Terminal_t VGA_Terminal;
//
void InitTerms(void)
{
- KalAssert(!GetStdOut() && !GetStdDbg());
+ //KalAssert(!GetStdOut() && !GetStdDbg());
VGA_Init();
- // vgaTerm.initDone = INITOK;
-
SetStdDbg(&VGA_Terminal);
SetStdOut(&VGA_Terminal);
diff --git a/kaleid/kernel/io/vga.c b/kaleid/kernel/io/vga.c
index 54bc63d..9a75cdb 100644
--- a/kaleid/kernel/io/vga.c
+++ b/kaleid/kernel/io/vga.c
@@ -37,12 +37,12 @@
#define VGA_ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8)
//
-// Fill terminal with '\0'
+// Clear terminal
//
error_t VGA_ClearTermUnlocked(Terminal_t *term)
{
const uchar color = VGA_ComputeColorCode(term->fgColor, term->bgColor);
- const ushort filler = VGA_ComputeEntry('\0', color);
+ const ushort filler = VGA_ComputeEntry(' ', color);
const size_t bufsize = term->width * term->height;
// Fill the buffer
@@ -70,15 +70,15 @@ error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch)
// Line feed first takes us to the very end of the line
// Later in this function we actually do the line feed
else if (ch == '\n') {
- term->currentY = term->width - 1;
+ term->currentX = term->width - 1;
}
// Tabulations account for "term->tabSize" spaces
else if (ch == '\t') {
- prevY = term->currentY;
+ prevY = term->currentX;
for (i = 0; i < term->tabSize; i++) {
// Make sure tabulations can't spread over two lines
- if (term->currentY == prevY) {
+ if (term->currentX == prevY) {
VGA_PutOnTermUnlocked(term, ' ');
}
}
@@ -86,7 +86,7 @@ error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch)
else {
ushort *buffer = (ushort *)term->data;
- const size_t offset = VGA_ComputeOffset(term, term->currentY, term->currentY);
+ const size_t offset = VGA_ComputeOffset(term, term->currentX, term->currentY);
buffer[offset] = VGA_ComputeEntry(ch, VGA_ComputeColorCode(term->fgColor, term->bgColor));
}
diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c
index 3127321..c799d19 100644
--- a/kaleid/kernel/ke/panic.c
+++ b/kaleid/kernel/ke/panic.c
@@ -60,16 +60,16 @@ noreturn void StartPanic(const char *fmt, ...)
fmt = "(no message given)";
}
- if (GetPanicStr()) {
- GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "\ndouble panic!");
+ if (*GetPanicStr()) {
+ GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "\nDouble panic!");
HaltCPU();
}
va_start(ap, fmt);
- vsnprintf(GetPanicStr(), sizeof GetPanicStr(), fmt, ap);
+ vsnprintf(GetPanicStr(), PANICSTR_SIZE, fmt, ap);
va_end(ap);
- GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "\npanic!\n\n");
+ GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "\nPanic!\n\n");
GetStdOut()->PrintOnTermUnlocked(GetStdOut(), GetPanicStr());
HaltCPU();