From 882aaa3844a77628d709363f0103086348ac5735 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Mon, 11 Mar 2019 14:07:16 +0100 Subject: [PATCH 01/29] Stuff I don't remember --- Makefile | 25 +++++++++++++++++++++---- Makefile.in | 2 +- kaleid/crtlib/sprintf.c | 1 + kaleid/kernel/init/init.c | 9 ++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0dc4347..cb4500f 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' @@ -92,18 +109,18 @@ make_disk: @echo ${CL2}[make_disk]${CL} OK${CL3} test: kernel loader - @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log & + qemu-system-x86_64 -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 @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm test32: kernel loader - @qemu-system-i386 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -enable-kvm 2> qemu.log & + 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 @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm debug: kernel loader - @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & + qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm diff --git a/Makefile.in b/Makefile.in index 8e4c573..4e4c536 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 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/kernel/init/init.c b/kaleid/kernel/init/init.c index c50108a..961e55d 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -28,11 +28,18 @@ // // Entry point of the Kaleid kernel // -noreturn void StartKern(void* multibooot_info, int multiboot_magic) +noreturn void StartKern(void *mbInfo, int mbMagic) { + (void)mbInfo; + (void)mbMagic; + // We're not ready to deal with interrupts DisableIRQs(); + volatile ushort *vga = (volatile ushort *)0xB8000; + + *vga++ = 'AA'; + // Kernel terminals InitTerms(); From 1e2bf99bd46d9bdc35c9e0d774e2456847eca78c Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 11 Mar 2019 14:16:56 +0100 Subject: [PATCH 02/29] merge --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 37b89cd..64e4a70 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,6 @@ test: kaleid @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm -<<<<<<< HEAD test32: kernel loader 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 From c39f733e6d0cd97167bb3028990d812315fdd531 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 11 Mar 2019 14:17:02 +0100 Subject: [PATCH 03/29] merge --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 64e4a70..c4f5406 100644 --- a/Makefile +++ b/Makefile @@ -124,7 +124,7 @@ test32: kernel loader debug: kernel loader qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & -======= + 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 @@ -132,7 +132,6 @@ test32: kaleid debug: kaleid @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & ->>>>>>> master @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm From 1beaf2b46d1a2e41c22aba249662cbb3b6857326 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 11 Mar 2019 14:47:11 +0100 Subject: [PATCH 04/29] Step 0 : InitTerms() is the bug --- Makefile.in | 9 --------- boot/loader/io/terminal.inc | 13 ++++++++++++- boot/loader/loader.asm | 22 +++++++++++++--------- kaleid/kernel/init/init.c | 10 ++++++---- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Makefile.in b/Makefile.in index 4e4c536..84325f7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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) diff --git a/boot/loader/io/terminal.inc b/boot/loader/io/terminal.inc index 1037c10..2df0252 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..13278b3 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 "ERROR 05 : Kernel launching error",0 _loader64: ;; Some cleanup @@ -155,4 +156,7 @@ _loader64: jmp StartKern ;; We must never reach this point ------------------------------------------- ;; + mov bl, 0x0c + mov esi, nokernel ; Error 05 + call write jmp Die diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index bda40a5..af6cfa7 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -25,10 +25,12 @@ #include #include + +extern void testf(void); + // // Entry point of the Kaleid kernel // - noreturn void StartKern(void *mbInfo, int mbMagic) { (void)mbInfo; @@ -39,12 +41,12 @@ noreturn void StartKern(void *mbInfo, int mbMagic) volatile ushort *vga = (volatile ushort *)0xB8000; - *vga++ = 'AA'; - // Kernel terminals //InitTerms(); + *vga++ = ('A' << 8 | 0x0F); + // We're out - //StartPanic("Goodbye World :("); + StartPanic("Goodbye World :("); } From fe12e3bca9d39b31f63bc2d3cd148d2f9221d8c1 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 11 Mar 2019 15:23:01 +0100 Subject: [PATCH 05/29] Debug stuff --- Makefile.in | 2 +- kaleid/include/kernel/term.h | 3 +++ kaleid/kernel/init/init.c | 8 +++----- kaleid/kernel/init/table.c | 4 +++- kaleid/kernel/io/term.c | 4 +--- kaleid/kernel/io/vga.c | 4 ++-- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Makefile.in b/Makefile.in index 84325f7..194b4ce 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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) 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 af6cfa7..3caa32d 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -39,14 +39,12 @@ noreturn void StartKern(void *mbInfo, int mbMagic) // We're not ready to deal with interrupts DisableIRQs(); - volatile ushort *vga = (volatile ushort *)0xB8000; - // Kernel terminals - //InitTerms(); + InitTerms(); - *vga++ = ('A' << 8 | 0x0F); + *vga = 'A' | (0x0F << 8); // We're out - StartPanic("Goodbye World :("); + // StartPanic("Goodbye World :("); } 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..dea935b 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 From 2aeaefe7acf17c7ae9b0e95647b7ccd743069f3f Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 11 Mar 2019 18:10:54 +0100 Subject: [PATCH 06/29] Step 1 : StartPanic is the real problem --- boot/loader/loader.asm | 6 ++++-- kaleid/kernel/init/init.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index 13278b3..33236e0 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -126,7 +126,7 @@ lbegin: x64_K db "Now in x64 long mode", 0x0A, 0x0D, 0x0 GoKernel db "Launching Kernel...", 0 -nokernel db "ERROR 05 : Kernel launching error",0 +nokernel db 219, 219, 219, " Error 05 : Kernel returns",0 _loader64: ;; Some cleanup @@ -153,9 +153,11 @@ _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 diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 3caa32d..ce72856 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -42,9 +42,11 @@ noreturn void StartKern(void *mbInfo, int mbMagic) // Kernel terminals InitTerms(); - *vga = 'A' | (0x0F << 8); + vga = 0xB8000; + + *vga = ('A') | (0x0F << 8); // We're out - // StartPanic("Goodbye World :("); + //StartPanic("Goodbye World :("); } From 021c94489bea8adc4eb2bc0d4801e85a5b4a505e Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 11 Mar 2019 18:17:08 +0100 Subject: [PATCH 07/29] Step 1 : StartPanic is the real problem --- boot/loader/cpu/cpu.inc | 4 ++++ kaleid/kernel/init/init.c | 2 -- kaleid/kernel/ke/panic.c | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/boot/loader/cpu/cpu.inc b/boot/loader/cpu/cpu.inc index 8b92819..2bf937a 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: diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index ce72856..39858b5 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -42,8 +42,6 @@ noreturn void StartKern(void *mbInfo, int mbMagic) // Kernel terminals InitTerms(); - vga = 0xB8000; - *vga = ('A') | (0x0F << 8); // We're out diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c index 3127321..cbb9ac0 100644 --- a/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -62,6 +62,7 @@ noreturn void StartPanic(const char *fmt, ...) if (GetPanicStr()) { GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "\ndouble panic!"); + tritemporize(); HaltCPU(); } @@ -72,6 +73,7 @@ noreturn void StartPanic(const char *fmt, ...) GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "\npanic!\n\n"); GetStdOut()->PrintOnTermUnlocked(GetStdOut(), GetPanicStr()); + tritemporize(); HaltCPU(); } @@ -81,6 +83,7 @@ noreturn void StartPanic(const char *fmt, ...) noreturn void CrashSystem(void) { DisableIRQs(); + tritemporize(); HaltCPU(); } From 348c3b7eadd16623f1e19c4c5842f2943b954973 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 11 Mar 2019 18:17:49 +0100 Subject: [PATCH 08/29] Step 1 : StartPanic is the real problem --- kaleid/kernel/ke/panic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c index cbb9ac0..4e8c7d6 100644 --- a/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -50,6 +50,7 @@ noreturn void StartPanic(const char *fmt, ...) va_list ap; DisableIRQs(); + *vga = ('B') | (0x0F << 8); if (GetCurProc()) _SetCurProc(NULL); if (GetStdOut() == NULL) CrashSystem(); From 4ba948669fdfa622b2931e05a3de18963990d332 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 11 Mar 2019 18:25:35 +0100 Subject: [PATCH 09/29] Step 1 : In StartPanic is the real problem --- Makefile | 9 -------- Makefile.in | 46 ++++++++++++++++++------------------- boot/loader/cpu/cpu.inc | 6 ++--- boot/loader/io/terminal.inc | 2 +- kaleid/kernel/init/init.c | 2 +- kaleid/kernel/ke/panic.c | 2 ++ 6 files changed, 30 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index c4f5406..d7ae0dc 100644 --- a/Makefile +++ b/Makefile @@ -116,15 +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: kernel loader - 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 - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm - -debug: kernel loader - qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & - 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 194b4ce..eec9b98 100644 --- a/Makefile.in +++ b/Makefile.in @@ -60,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 @@ -92,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 2bf937a..5fa0a5d 100644 --- a/boot/loader/cpu/cpu.inc +++ b/boot/loader/cpu/cpu.inc @@ -23,9 +23,9 @@ ; along with OS/K. If not, see . ; ;=----------------------------------------------------------------------------=; -global temporize -global bitemporize -global tritemporize +[global temporize] +[global bitemporize] +[global tritemporize] [BITS 64] diff --git a/boot/loader/io/terminal.inc b/boot/loader/io/terminal.inc index 2df0252..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 +[global testf] ;;VIDEO %define TRAM 0xB8000 ; [T]ext[RAM] diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 39858b5..943d3a5 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -45,6 +45,6 @@ noreturn void StartKern(void *mbInfo, int mbMagic) *vga = ('A') | (0x0F << 8); // We're out - //StartPanic("Goodbye World :("); + StartPanic("Goodbye World :("); } diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c index 4e8c7d6..366dd14 100644 --- a/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -55,6 +55,8 @@ noreturn void StartPanic(const char *fmt, ...) if (GetCurProc()) _SetCurProc(NULL); if (GetStdOut() == NULL) CrashSystem(); + HaltCPU(); + GetStdOut()->ClearTermUnlocked(GetStdOut()); if (fmt == NULL) { From 228df83a1a1e0927eadae0a2ca74d7d16a3ce80e Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 11 Mar 2019 19:22:37 +0100 Subject: [PATCH 10/29] Merging from master (#34) * Update Readme.md * Debug this beautiful panicked kernel ! * Stuff I don't remember * stuff * merge * merge * Step 0 : InitTerms() is the bug * Debug stuff * Step 1 : StartPanic is the real problem * Step 1 : StartPanic is the real problem * Step 1 : StartPanic is the real problem * Step 1 : In StartPanic is the real problem * Step 1 : In StartPanic is the real problem * Step 1 : In StartPanic is the real problem * Step 1 : In StartPanic is the real problem * Step 1 : In StartPanic is the real problem * Step 1.5 : \n was a problem * Step 2 : Well... It was a 'sleepy' problem * Step 2 : Well... It was a 'sleepy' problem * Step 2.1 : GetPanicStr is an array * Step 2.2 : Now panic accept 8 chars * Ok then ! --- Makefile | 23 ++++++++++++-- Makefile.in | 59 +++++++++++++++--------------------- boot/grub/grub-install.sh | 4 +++ boot/grub/umount.sh | 2 +- boot/loader/cpu/cpu.inc | 4 +++ boot/loader/io/terminal.inc | 13 +++++++- boot/loader/loader.asm | 26 ++++++++++------ kaleid/crtlib/sprintf.c | 1 + kaleid/include/kernel/base.h | 3 +- kaleid/include/kernel/term.h | 3 ++ kaleid/kernel/init/init.c | 8 ++++- kaleid/kernel/init/table.c | 4 ++- kaleid/kernel/io/term.c | 4 +-- kaleid/kernel/io/vga.c | 12 ++++---- kaleid/kernel/ke/panic.c | 8 ++--- 15 files changed, 109 insertions(+), 65 deletions(-) diff --git a/Makefile b/Makefile index 9383282..d7ae0dc 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ ASM=nasm LD=ld ASMFLAGS=-f elf64 -LDFLAGS= -melf_x86_64 +LDFLAGS=-melf_x86_64 #Folders MBRDIR=boot/grub @@ -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/grub/grub-install.sh b/boot/grub/grub-install.sh index 44d591f..cd76028 100755 --- a/boot/grub/grub-install.sh +++ b/boot/grub/grub-install.sh @@ -38,6 +38,10 @@ sudo losetup /dev/loop1 $1 -o 1048576 > /dev/null #mounting the logical partitio echo ${CL2}[grub-install.sh]${NC} Mounting volume... \(mount\)${CL3} ## Mount +if [ -e $2/boot ]  +then + sudo umount $2 > /dev/null +fi sudo mount /dev/loop1 $2 > /dev/null echo ${CL2}[grub-install.sh]${NC} Installing grub... \(grub-install\)${CL3} diff --git a/boot/grub/umount.sh b/boot/grub/umount.sh index cf8035b..0948aba 100755 --- a/boot/grub/umount.sh +++ b/boot/grub/umount.sh @@ -29,8 +29,8 @@ CL3='\033[0m' NC='\033[1;37m' set -e #exit if error -#sleep 3 sync +sleep 1 echo ${CL2}[umount.sh]${NC} Unmounting volume... \(umount\)${CL3} sudo umount $1 echo ${CL2}[umount.sh]${NC} Unmounting image... \(losetup\)${CL3} diff --git a/boot/loader/cpu/cpu.inc b/boot/loader/cpu/cpu.inc index d97e2d6..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: 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 ed1b828..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(); From 8660d529123ed8d872c6ac2be60b34130a2a4845 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 12 Mar 2019 15:29:15 +0100 Subject: [PATCH 12/29] Assert --- kaleid/kernel/io/term.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kaleid/kernel/io/term.c b/kaleid/kernel/io/term.c index fa5da06..5392b23 100644 --- a/kaleid/kernel/io/term.c +++ b/kaleid/kernel/io/term.c @@ -32,7 +32,7 @@ extern Terminal_t VGA_Terminal; // void InitTerms(void) { - //KalAssert(!GetStdOut() && !GetStdDbg()); + KalAssert(!GetStdOut() && !GetStdDbg()); VGA_Init(); From b9322e60e0b895e9f487ad7169f709cc4e84316c Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 12 Mar 2019 17:13:09 +0100 Subject: [PATCH 13/29] stuff --- .stylehlp | 26 ++++++++++++++++++++++++++ boot/loader/loader.asm | 8 +++++++- kaleid/kernel/init/init.c | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.stylehlp b/.stylehlp index 588d391..66bda54 100644 --- a/.stylehlp +++ b/.stylehlp @@ -24,3 +24,29 @@ //------------------------------------------// + +;=----------------------------------------------------------------------------=; +; GNU GPL OS/K ; +; ; +; Desc: ; +; ; +; ; +; Copyright © 2018-2019 The OS/K Team ; +; ; +; This file is part of OS/K. ; +; ; +; OS/K is free software: you can redistribute it and/or modify ; +; it under the terms of the GNU General Public License as published by ; +; the Free Software Foundation, either version 3 of the License, or ; +; (at your option) any later version. ; +; ; +; OS/K is distributed in the hope that it will be useful, ; +; but WITHOUT ANY WARRANTY; without even the implied warranty of ; +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; +; GNU General Public License for more details. ; +; ; +; You should have received a copy of the GNU General Public License ; +; along with OS/K. If not, see . ; +;=----------------------------------------------------------------------------=; + + diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index 33236e0..5cf97c7 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -95,9 +95,15 @@ Die: _loader: jmp lbegin -LOGO: db 219, 219, 219, " OS/K", 0 +LOGO db 219, 219, 219, " OS/K", 0 +mbInfo dq 0 +mbMagic dq 0 lbegin: + + pop ebx ; 1st argument multiboot info pointer + pop eax ; 2nd argument is magic number + call clear ; Clear the screen ;; BEGIN OF CHECKLIST diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index cfa2991..1d56806 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -43,6 +43,6 @@ noreturn void StartKern(void *mbInfo, int mbMagic) InitTerms(); // We're out - StartPanic("Goodbye World :("); + StartPanic("We had\n *mbInfo : %x\n mbMagic : %x\n\nGoodbye World :(", mbInfo, mbMagic); } From 4a9b54cc3ebea56aa3730c571225153c1bcaebf4 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 12 Mar 2019 17:25:25 +0100 Subject: [PATCH 14/29] stuff --- boot/loader/loader.asm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index 5cf97c7..fffa136 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -102,7 +102,9 @@ mbMagic dq 0 lbegin: pop ebx ; 1st argument multiboot info pointer + mov [mbInfo], ebx pop eax ; 2nd argument is magic number + mov [mbMagic], eax call clear ; Clear the screen @@ -159,6 +161,9 @@ _loader64: call tritemporize ; Let time to see extern StartKern + + push qword 12 + push qword 12 call StartKern ;; We must never reach this point ------------------------------------------- ;; From 8fca2de33f62599fd87baeb813068f999f526082 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 12 Mar 2019 17:31:25 +0100 Subject: [PATCH 15/29] Revert "stuff" This reverts commit be94ec4d2c1d5e3de08e50a0733bd53c69d1acd8, reversing changes made to 2d9e02db0e580eaf9ccb6a6d2176ee16107a4b0a. --- boot/loader/loader.asm | 1 + kaleid/kernel/init/init.c | 2 -- kaleid/kernel/io/term.c | 2 +- kaleid/kernel/ke/panic.c | 5 ----- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index 7baa2c6..fffa136 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -161,6 +161,7 @@ _loader64: call tritemporize ; Let time to see extern StartKern + push qword 12 push qword 12 call StartKern diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index e454774..1d56806 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -42,8 +42,6 @@ noreturn void StartKern(void *mbInfo, int mbMagic) // Kernel terminals InitTerms(); - *vga = ('A') | (0x0F << 8); - // We're out StartPanic("We had\n *mbInfo : %x\n mbMagic : %x\n\nGoodbye World :(", mbInfo, mbMagic); } diff --git a/kaleid/kernel/io/term.c b/kaleid/kernel/io/term.c index fa5da06..5392b23 100644 --- a/kaleid/kernel/io/term.c +++ b/kaleid/kernel/io/term.c @@ -32,7 +32,7 @@ extern Terminal_t VGA_Terminal; // void InitTerms(void) { - //KalAssert(!GetStdOut() && !GetStdDbg()); + KalAssert(!GetStdOut() && !GetStdDbg()); VGA_Init(); diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c index d946f7e..c799d19 100644 --- a/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -50,13 +50,10 @@ noreturn void StartPanic(const char *fmt, ...) va_list ap; DisableIRQs(); - *vga = ('B') | (0x0F << 8); if (GetCurProc()) _SetCurProc(NULL); if (GetStdOut() == NULL) CrashSystem(); - HaltCPU(); - GetStdOut()->ClearTermUnlocked(GetStdOut()); if (fmt == NULL) { @@ -75,7 +72,6 @@ noreturn void StartPanic(const char *fmt, ...) GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "\nPanic!\n\n"); GetStdOut()->PrintOnTermUnlocked(GetStdOut(), GetPanicStr()); - tritemporize(); HaltCPU(); } @@ -85,7 +81,6 @@ noreturn void StartPanic(const char *fmt, ...) noreturn void CrashSystem(void) { DisableIRQs(); - tritemporize(); HaltCPU(); } From f836157c902e5b4d2289caa8f271c6549b03d2ff Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 12 Mar 2019 18:24:27 +0100 Subject: [PATCH 16/29] stuff --- boot/loader/loader.asm | 4 ++-- kaleid/kernel/init/init.c | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index fffa136..1a12b81 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -162,8 +162,8 @@ _loader64: extern StartKern - push qword 12 - push qword 12 + mov rsi, [mbInfo] + mov rdi, [mbMagic] call StartKern ;; We must never reach this point ------------------------------------------- ;; diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 1d56806..39ad1ed 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -33,9 +33,6 @@ extern void testf(void); // noreturn void StartKern(void *mbInfo, int mbMagic) { - (void)mbInfo; - (void)mbMagic; - // We're not ready to deal with interrupts DisableIRQs(); @@ -43,6 +40,6 @@ noreturn void StartKern(void *mbInfo, int mbMagic) InitTerms(); // We're out - StartPanic("We had\n *mbInfo : %x\n mbMagic : %x\n\nGoodbye World :(", mbInfo, mbMagic); + StartPanic("We had\n *mbInfo : %p\n mbMagic : %x\n\nGoodbye World :(", mbInfo, mbMagic); } From 32c7c99bc2bdccc29b152abf0144a85687b22774 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 12 Mar 2019 22:11:00 +0100 Subject: [PATCH 17/29] Just learned SysV ABI calling conventions and clean-up stuff --- boot/loader/cpu/cpu.inc | 7 ++++--- boot/loader/cpu/cpu32.inc | 1 + boot/loader/io/terminal.inc | 8 +++----- boot/loader/loader.asm | 21 +++++++-------------- boot/loader/mem/management.inc | 2 +- boot/loader/mem/structures.inc | 4 ++-- kaleid/kernel/init/init.c | 2 +- 7 files changed, 19 insertions(+), 26 deletions(-) diff --git a/boot/loader/cpu/cpu.inc b/boot/loader/cpu/cpu.inc index 25a3b08..4700598 100644 --- a/boot/loader/cpu/cpu.inc +++ b/boot/loader/cpu/cpu.inc @@ -23,11 +23,12 @@ ; along with OS/K. If not, see . ; ;=----------------------------------------------------------------------------=; -[global temporize] -[global bitemporize] -[global tritemporize] +global temporize +global bitemporize +global tritemporize [BITS 64] +[section .text] temporize: push rcx diff --git a/boot/loader/cpu/cpu32.inc b/boot/loader/cpu/cpu32.inc index c67fb08..9eaa036 100644 --- a/boot/loader/cpu/cpu32.inc +++ b/boot/loader/cpu/cpu32.inc @@ -24,6 +24,7 @@ ;=----------------------------------------------------------------------------=; [BITS 32] +[section .text] ; ---------------------------------------------------------------------------- ; ; Checks if the CPU is compatible with 64-bits operating systems ; diff --git a/boot/loader/io/terminal.inc b/boot/loader/io/terminal.inc index c2bce9a..50b4175 100644 --- a/boot/loader/io/terminal.inc +++ b/boot/loader/io/terminal.inc @@ -22,7 +22,9 @@ ; You should have received a copy of the GNU General Public License ; ; along with OS/K. If not, see . ; ;=----------------------------------------------------------------------------=; -[global testf] + +[BITS 64] +[section .text] ;;VIDEO %define TRAM 0xB8000 ; [T]ext[RAM] @@ -30,16 +32,12 @@ %define VGA_HEIGHT 80 ;; GLOBAL DATA - NextTRAM dq 0xB8000 ; Last position of cursor NextTRAM32 dq 0xB8000 ; Last position of cursor VGA_X32 dq 0 VGA_HEIGHT64 dq VGA_HEIGHT VGA_X dq 0 -;; TEXT - -[BITS 64] testf: push rsi diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index 1a12b81..785e4c2 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -31,9 +31,10 @@ %include "boot/loader/cpu/cpu.inc" %include "boot/loader/mem/structures.inc" -[BITS 32] -[global MB_start] +global MB_start +extern StartKern +[BITS 32] [section .multiboot] ;; MAGNIFICENT MULTIBOOT HEADER FOR GRUB ------------------------------------ ;; @@ -50,8 +51,8 @@ MB_start: mov esp, KERNEL_STACK ; Setup the stack push 0 ; Reset EFLAGS popf - push eax ; 2nd argument is magic number - push ebx ; 1st argument multiboot info pointer + mov [mbInfo], ebx + mov [mbMagic], eax mov ecx, eax ; For debug call _loader add esp, 8 ; Cleanup arguments "A la MIPS" @@ -100,12 +101,6 @@ mbInfo dq 0 mbMagic dq 0 lbegin: - - pop ebx ; 1st argument multiboot info pointer - mov [mbInfo], ebx - pop eax ; 2nd argument is magic number - mov [mbMagic], eax - call clear ; Clear the screen ;; BEGIN OF CHECKLIST @@ -160,10 +155,8 @@ _loader64: ;; Launch the kernel ! call tritemporize ; Let time to see - extern StartKern - - mov rsi, [mbInfo] - mov rdi, [mbMagic] + mov rdi, [mbInfo] + mov rsi, [mbMagic] call StartKern ;; We must never reach this point ------------------------------------------- ;; diff --git a/boot/loader/mem/management.inc b/boot/loader/mem/management.inc index 876d2fe..b44bf4f 100644 --- a/boot/loader/mem/management.inc +++ b/boot/loader/mem/management.inc @@ -24,7 +24,7 @@ ;=----------------------------------------------------------------------------=; [BITS 32] - +[section .text] ; ---------------------------------------------------------------------------- ; ; Constructor for the page tables in protected mode ; ; ---------------------------------------------------------------------------- ; diff --git a/boot/loader/mem/structures.inc b/boot/loader/mem/structures.inc index 4b92e56..0c7bd8b 100644 --- a/boot/loader/mem/structures.inc +++ b/boot/loader/mem/structures.inc @@ -24,7 +24,7 @@ ;=----------------------------------------------------------------------------=; [BITS 32] -section .rodata +[section .rodata] ;; GDT WITH DOC ALIGN 4096 GDT64: @@ -44,7 +44,7 @@ GDT64: dq GDT64 ;; EMPTY PAGE TABLES (identity of the first 1GiB) -section .bss +[section .bss] ALIGN 4096 PML4_table: resb 4096 diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 39ad1ed..6430af3 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -40,6 +40,6 @@ noreturn void StartKern(void *mbInfo, int mbMagic) InitTerms(); // We're out - StartPanic("We had\n *mbInfo : %p\n mbMagic : %x\n\nGoodbye World :(", mbInfo, mbMagic); + StartPanic("We had\n *mbInfo : %p\n mbMagic : %p\n\nGoodbye World :(", mbInfo, mbMagic); } From 17f714719b0a3eeb575755f7b41a0b3f2bd5fb22 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 12 Mar 2019 23:25:30 +0100 Subject: [PATCH 18/29] multiboooooooot --- boot/loader/multiboot/header.inc | 2 +- kaleid/include/multiboot/multiboot.h | 472 ++++++++++----------------- kaleid/kernel/init/init.c | 10 +- 3 files changed, 178 insertions(+), 306 deletions(-) diff --git a/boot/loader/multiboot/header.inc b/boot/loader/multiboot/header.inc index 337d168..06f89a4 100644 --- a/boot/loader/multiboot/header.inc +++ b/boot/loader/multiboot/header.inc @@ -29,6 +29,6 @@ MB_ALIGN equ 1 << 0 ; Ask to align loaded modules on page bounda MB_MEMINFO equ 1 << 1 ; Ask to provide memory map MB_HEADER_MAGIC equ 0x1badb002 MB_GRUB_MAGIC equ 0x2badb002 -MB_HEADER_FLAGS equ 0x0 ; MB_AOUT_KLUDGE|MB_ALIGN|MB_MEMINFO +MB_HEADER_FLAGS equ MB_AOUT_KLUDGE|MB_ALIGN|MB_MEMINFO CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS) KERNEL_STACK equ 0x00200000 ; Stack starts at the 2mb address & grows down diff --git a/kaleid/include/multiboot/multiboot.h b/kaleid/include/multiboot/multiboot.h index 2c93a2a..2a5d469 100644 --- a/kaleid/include/multiboot/multiboot.h +++ b/kaleid/include/multiboot/multiboot.h @@ -1,91 +1,102 @@ -/* multiboot2.h - Multiboot 2 header file. */ -/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY - * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR - * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: multiboot.h - Multiboot header file. // +// // +// // +// Copyright © 1999,2003,2007-2010 Free Software Foundation, Inc. // +// // +// Note: In this header, "the software" refers to the multiboot.h file. // +// // +// Permission is hereby granted, free of charge, to any person // +// obtaining a copy of this software and associated documentation // +// files (the "Software"), to deal in the Software without restriction, // +// including without limitation the rights to use, copy, modify, merge, // +// publish, distribute, sublicense, and/or sell copies of the Software, // +// and to permit persons to whom the Software is furnished to do so, // +// subject to the following conditions: // +// // +// The above copyright notice and this permission notice shall be included // +// in all copies or substantial portions of the Software. // +// // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // +// IN NO EVENT SHALL ANY DEVELOPER OR DISTRIBUTOR BE LIABLE FOR // +// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.. // +//----------------------------------------------------------------------------// #ifndef MULTIBOOT_HEADER #define MULTIBOOT_HEADER 1 /* How many bytes from the start of the file we search for the header. */ -#define MULTIBOOT_SEARCH 32768 -#define MULTIBOOT_HEADER_ALIGN 8 +#define MULTIBOOT_SEARCH 8192 +#define MULTIBOOT_HEADER_ALIGN 4 /* The magic field should contain this. */ -#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6 +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 /* This should be in %eax. */ -#define MULTIBOOT2_BOOTLOADER_MAGIC 0x36d76289 +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 /* Alignment of multiboot modules. */ #define MULTIBOOT_MOD_ALIGN 0x00001000 /* Alignment of the multiboot info structure. */ -#define MULTIBOOT_INFO_ALIGN 0x00000008 +#define MULTIBOOT_INFO_ALIGN 0x00000004 /* Flags set in the 'flags' member of the multiboot header. */ -#define MULTIBOOT_TAG_ALIGN 8 -#define MULTIBOOT_TAG_TYPE_END 0 -#define MULTIBOOT_TAG_TYPE_CMDLINE 1 -#define MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME 2 -#define MULTIBOOT_TAG_TYPE_MODULE 3 -#define MULTIBOOT_TAG_TYPE_BASIC_MEMINFO 4 -#define MULTIBOOT_TAG_TYPE_BOOTDEV 5 -#define MULTIBOOT_TAG_TYPE_MMAP 6 -#define MULTIBOOT_TAG_TYPE_VBE 7 -#define MULTIBOOT_TAG_TYPE_FRAMEBUFFER 8 -#define MULTIBOOT_TAG_TYPE_ELF_SECTIONS 9 -#define MULTIBOOT_TAG_TYPE_APM 10 -#define MULTIBOOT_TAG_TYPE_EFI32 11 -#define MULTIBOOT_TAG_TYPE_EFI64 12 -#define MULTIBOOT_TAG_TYPE_SMBIOS 13 -#define MULTIBOOT_TAG_TYPE_ACPI_OLD 14 -#define MULTIBOOT_TAG_TYPE_ACPI_NEW 15 -#define MULTIBOOT_TAG_TYPE_NETWORK 16 -#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17 -#define MULTIBOOT_TAG_TYPE_EFI_BS 18 -#define MULTIBOOT_TAG_TYPE_EFI32_IH 19 -#define MULTIBOOT_TAG_TYPE_EFI64_IH 20 -#define MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR 21 +/* Align all boot modules on i386 page (4KB) boundaries. */ +#define MULTIBOOT_PAGE_ALIGN 0x00000001 -#define MULTIBOOT_HEADER_TAG_END 0 -#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1 -#define MULTIBOOT_HEADER_TAG_ADDRESS 2 -#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS 3 -#define MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS 4 -#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5 -#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6 -#define MULTIBOOT_HEADER_TAG_EFI_BS 7 -#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI32 8 -#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 -#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10 +/* Must pass memory information to OS. */ +#define MULTIBOOT_MEMORY_INFO 0x00000002 -#define MULTIBOOT_ARCHITECTURE_I386 0 -#define MULTIBOOT_ARCHITECTURE_MIPS32 4 -#define MULTIBOOT_HEADER_TAG_OPTIONAL 1 +/* Must pass video information to OS. */ +#define MULTIBOOT_VIDEO_MODE 0x00000004 -#define MULTIBOOT_LOAD_PREFERENCE_NONE 0 -#define MULTIBOOT_LOAD_PREFERENCE_LOW 1 -#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2 +/* This flag indicates the use of the address fields in the header. */ +#define MULTIBOOT_AOUT_KLUDGE 0x00010000 -#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1 -#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2 +/* Flags to be set in the 'flags' member of the multiboot info structure. */ + +/* is there basic lower/upper memory information? */ +#define MULTIBOOT_INFO_MEMORY 0x00000001 +/* is there a boot device set? */ +#define MULTIBOOT_INFO_BOOTDEV 0x00000002 +/* is the command-line defined? */ +#define MULTIBOOT_INFO_CMDLINE 0x00000004 +/* are there modules to do something with? */ +#define MULTIBOOT_INFO_MODS 0x00000008 + +/* These next two are mutually exclusive */ + +/* is there a symbol table loaded? */ +#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010 +/* is there an ELF section header table? */ +#define MULTIBOOT_INFO_ELF_SHDR 0X00000020 + +/* is there a full memory map? */ +#define MULTIBOOT_INFO_MEM_MAP 0x00000040 + +/* Is there drive info? */ +#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080 + +/* Is there a config table? */ +#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100 + +/* Is there a boot loader name? */ +#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200 + +/* Is there a APM table? */ +#define MULTIBOOT_INFO_APM_TABLE 0x00000400 + +/* Is there video information? */ +#define MULTIBOOT_INFO_VBE_INFO 0x00000800 +#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 #ifndef ASM_FILE @@ -99,184 +110,96 @@ struct multiboot_header /* Must be MULTIBOOT_MAGIC - see above. */ multiboot_uint32_t magic; - /* ISA */ - multiboot_uint32_t architecture; - - /* Total header length. */ - multiboot_uint32_t header_length; + /* Feature flags. */ + multiboot_uint32_t flags; /* The above fields plus this one must equal 0 mod 2^32. */ multiboot_uint32_t checksum; -}; -struct multiboot_header_tag -{ - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; -}; - -struct multiboot_header_tag_information_request -{ - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; - multiboot_uint32_t requests[0]; -}; - -struct multiboot_header_tag_address -{ - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; + /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ multiboot_uint32_t header_addr; multiboot_uint32_t load_addr; multiboot_uint32_t load_end_addr; multiboot_uint32_t bss_end_addr; -}; - -struct multiboot_header_tag_entry_address -{ - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; multiboot_uint32_t entry_addr; -}; -struct multiboot_header_tag_console_flags -{ - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; - multiboot_uint32_t console_flags; -}; - -struct multiboot_header_tag_framebuffer -{ - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; + /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ + multiboot_uint32_t mode_type; multiboot_uint32_t width; multiboot_uint32_t height; multiboot_uint32_t depth; }; -struct multiboot_header_tag_module_align +/* The symbol table for a.out. */ +struct multiboot_aout_symbol_table { - multiboot_uint16_t type; - multiboot_uint16_t flags; + multiboot_uint32_t tabsize; + multiboot_uint32_t strsize; + multiboot_uint32_t addr; + multiboot_uint32_t reserved; +}; +typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; + +/* The section header table for ELF. */ +struct multiboot_elf_section_header_table +{ + multiboot_uint32_t num; multiboot_uint32_t size; + multiboot_uint32_t addr; + multiboot_uint32_t shndx; }; +typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t; -struct multiboot_header_tag_relocatable +struct multiboot_info { - multiboot_uint16_t type; - multiboot_uint16_t flags; - multiboot_uint32_t size; - multiboot_uint32_t min_addr; - multiboot_uint32_t max_addr; - multiboot_uint32_t align; - multiboot_uint32_t preference; -}; + /* Multiboot info version number */ + multiboot_uint32_t flags; -struct multiboot_color -{ - multiboot_uint8_t red; - multiboot_uint8_t green; - multiboot_uint8_t blue; -}; - -struct multiboot_mmap_entry -{ - multiboot_uint64_t addr; - multiboot_uint64_t len; -#define MULTIBOOT_MEMORY_AVAILABLE 1 -#define MULTIBOOT_MEMORY_RESERVED 2 -#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 -#define MULTIBOOT_MEMORY_NVS 4 -#define MULTIBOOT_MEMORY_BADRAM 5 - multiboot_uint32_t type; - multiboot_uint32_t zero; -}; -typedef struct multiboot_mmap_entry multiboot_memory_map_t; - -struct multiboot_tag -{ - multiboot_uint32_t type; - multiboot_uint32_t size; -}; - -struct multiboot_tag_string -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - char string[0]; -}; - -struct multiboot_tag_module -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t mod_start; - multiboot_uint32_t mod_end; - char cmdline[0]; -}; - -struct multiboot_tag_basic_meminfo -{ - multiboot_uint32_t type; - multiboot_uint32_t size; + /* Available memory from BIOS */ multiboot_uint32_t mem_lower; multiboot_uint32_t mem_upper; -}; -struct multiboot_tag_bootdev -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t biosdev; - multiboot_uint32_t slice; - multiboot_uint32_t part; -}; + /* "root" partition */ + multiboot_uint32_t boot_device; -struct multiboot_tag_mmap -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t entry_size; - multiboot_uint32_t entry_version; - struct multiboot_mmap_entry entries[0]; -}; + /* Kernel command line */ + multiboot_uint32_t cmdline; -struct multiboot_vbe_info_block -{ - multiboot_uint8_t external_specification[512]; -}; + /* Boot-Module list */ + multiboot_uint32_t mods_count; + multiboot_uint32_t mods_addr; -struct multiboot_vbe_mode_info_block -{ - multiboot_uint8_t external_specification[256]; -}; + union + { + multiboot_aout_symbol_table_t aout_sym; + multiboot_elf_section_header_table_t elf_sec; + } u; -struct multiboot_tag_vbe -{ - multiboot_uint32_t type; - multiboot_uint32_t size; + /* Memory Mapping buffer */ + multiboot_uint32_t mmap_length; + multiboot_uint32_t mmap_addr; + /* Drive Info buffer */ + multiboot_uint32_t drives_length; + multiboot_uint32_t drives_addr; + + /* ROM configuration table */ + multiboot_uint32_t config_table; + + /* Boot Loader Name */ + multiboot_uint32_t boot_loader_name; + + /* APM table */ + multiboot_uint32_t apm_table; + + /* Video */ + multiboot_uint32_t vbe_control_info; + multiboot_uint32_t vbe_mode_info; multiboot_uint16_t vbe_mode; multiboot_uint16_t vbe_interface_seg; multiboot_uint16_t vbe_interface_off; multiboot_uint16_t vbe_interface_len; - struct multiboot_vbe_info_block vbe_control_info; - struct multiboot_vbe_mode_info_block vbe_mode_info; -}; - -struct multiboot_tag_framebuffer_common -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint64_t framebuffer_addr; multiboot_uint32_t framebuffer_pitch; multiboot_uint32_t framebuffer_width; @@ -286,19 +209,12 @@ struct multiboot_tag_framebuffer_common #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 multiboot_uint8_t framebuffer_type; - multiboot_uint16_t reserved; -}; - -struct multiboot_tag_framebuffer -{ - struct multiboot_tag_framebuffer_common common; - union { struct { + multiboot_uint32_t framebuffer_palette_addr; multiboot_uint16_t framebuffer_palette_num_colors; - struct multiboot_color framebuffer_palette[0]; }; struct { @@ -311,21 +227,46 @@ struct multiboot_tag_framebuffer }; }; }; +typedef struct multiboot_info multiboot_info_t; -struct multiboot_tag_elf_sections +struct multiboot_color { - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t num; - multiboot_uint32_t entsize; - multiboot_uint32_t shndx; - char sections[0]; + multiboot_uint8_t red; + multiboot_uint8_t green; + multiboot_uint8_t blue; }; -struct multiboot_tag_apm +struct multiboot_mmap_entry { - multiboot_uint32_t type; multiboot_uint32_t size; + multiboot_uint64_t addr; + multiboot_uint64_t len; +#define MULTIBOOT_MEMORY_AVAILABLE 1 +#define MULTIBOOT_MEMORY_RESERVED 2 +#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 +#define MULTIBOOT_MEMORY_NVS 4 +#define MULTIBOOT_MEMORY_BADRAM 5 + multiboot_uint32_t type; +} __attribute__((packed)); +typedef struct multiboot_mmap_entry multiboot_memory_map_t; + +struct multiboot_mod_list +{ + /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */ + multiboot_uint32_t mod_start; + multiboot_uint32_t mod_end; + + /* Module command line */ + multiboot_uint32_t cmdline; + + /* padding to take it to 16 bytes (must be zero) */ + multiboot_uint32_t pad; +}; +typedef struct multiboot_mod_list multiboot_module_t; + +/* APM BIOS info. */ +struct multiboot_apm_info +{ multiboot_uint16_t version; multiboot_uint16_t cseg; multiboot_uint32_t offset; @@ -337,81 +278,6 @@ struct multiboot_tag_apm multiboot_uint16_t dseg_len; }; -struct multiboot_tag_efi32 -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t pointer; -}; - -struct multiboot_tag_efi64 -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint64_t pointer; -}; - -struct multiboot_tag_smbios -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint8_t major; - multiboot_uint8_t minor; - multiboot_uint8_t reserved[6]; - multiboot_uint8_t tables[0]; -}; - -struct multiboot_tag_old_acpi -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint8_t rsdp[0]; -}; - -struct multiboot_tag_new_acpi -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint8_t rsdp[0]; -}; - -struct multiboot_tag_network -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint8_t dhcpack[0]; -}; - -struct multiboot_tag_efi_mmap -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t descr_size; - multiboot_uint32_t descr_vers; - multiboot_uint8_t efi_mmap[0]; -}; - -struct multiboot_tag_efi32_ih -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t pointer; -}; - -struct multiboot_tag_efi64_ih -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint64_t pointer; -}; - -struct multiboot_tag_load_base_addr -{ - multiboot_uint32_t type; - multiboot_uint32_t size; - multiboot_uint32_t load_base_addr; -}; - #endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */ diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 6430af3..fe17fd9 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -31,7 +31,7 @@ extern void testf(void); // // Entry point of the Kaleid kernel // -noreturn void StartKern(void *mbInfo, int mbMagic) +noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic) { // We're not ready to deal with interrupts DisableIRQs(); @@ -39,7 +39,13 @@ noreturn void StartKern(void *mbInfo, int mbMagic) // Kernel terminals InitTerms(); + char *grubver = mbInfo->boot_loader_name; + + // We're out - StartPanic("We had\n *mbInfo : %p\n mbMagic : %p\n\nGoodbye World :(", mbInfo, mbMagic); + StartPanic("We get\n *mbInfo : %x\n mbMagic : %x\n\n\ + We were loaded by : %s \n\n\ + \nGoodbye World :(", mbInfo, mbMagic, grubver); } + From afdd3508c6ba602e0bd0685beb3c0ec65ac81660 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 12 Mar 2019 23:36:47 +0100 Subject: [PATCH 19/29] stuff --- kaleid/kernel/init/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index fe17fd9..c41a1f2 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -39,7 +39,7 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic) // Kernel terminals InitTerms(); - char *grubver = mbInfo->boot_loader_name; + multiboot_uint32_t *grubver = mbInfo->boot_loader_name; // We're out From 9ab5bbc58c7fb52ab98c2e65d4be323be983b027 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 13 Mar 2019 09:19:43 +0100 Subject: [PATCH 20/29] multiboot&memory stuff --- kaleid/include/multiboot/multiboot.h | 2 +- kaleid/kernel/init/init.c | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/kaleid/include/multiboot/multiboot.h b/kaleid/include/multiboot/multiboot.h index 2a5d469..8c7d00f 100644 --- a/kaleid/include/multiboot/multiboot.h +++ b/kaleid/include/multiboot/multiboot.h @@ -6,7 +6,7 @@ // // // Copyright © 1999,2003,2007-2010 Free Software Foundation, Inc. // // // -// Note: In this header, "the software" refers to the multiboot.h file. // +// Note: In this header, "the Software" refers to the multiboot.h file. // // // // Permission is hereby granted, free of charge, to any person // // obtaining a copy of this software and associated documentation // diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index c41a1f2..d2dd85f 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -39,13 +39,19 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic) // Kernel terminals InitTerms(); - multiboot_uint32_t *grubver = mbInfo->boot_loader_name; - - // We're out - StartPanic("We get\n *mbInfo : %x\n mbMagic : %x\n\n\ - We were loaded by : %s \n\n\ - \nGoodbye World :(", mbInfo, mbMagic, grubver); + StartPanic( "We were loaded by : %s\n\n\n" + "We get\n" + " *mbInfo : %x\n" + " mbMagic : %x\n" + " mbBootdrv : %x\n" + "\nGoodbye World :(", + + mbInfo->boot_loader_name, + mbInfo, + mbMagic, + mbInfo->boot_device + ); } From ced75b51f2e22fe4548dd18180dcca59e0e5071a Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 13 Mar 2019 17:03:52 +0100 Subject: [PATCH 21/29] stuff I don't remember --- boot/loader/cpu/cpu.inc | 13 ---- kaleid/include/multiboot/multiboot.h | 91 +++++++++++++--------------- kaleid/kernel/init/init.c | 10 +-- kaleid/kernel/init/table.c | 2 - 4 files changed, 48 insertions(+), 68 deletions(-) diff --git a/boot/loader/cpu/cpu.inc b/boot/loader/cpu/cpu.inc index 4700598..f0fbc95 100644 --- a/boot/loader/cpu/cpu.inc +++ b/boot/loader/cpu/cpu.inc @@ -60,16 +60,3 @@ tritemporize: loop .looping pop rcx ret - - -; ---------------------------------------------------------------------------- ; -; Returns the CPU Vendor String.pointer in eax ; -; ---------------------------------------------------------------------------- ; -cpu_vendor: - - ;; Calling the competent authorities - mov eax, 0 - cpuid - - ret -.string db " " diff --git a/kaleid/include/multiboot/multiboot.h b/kaleid/include/multiboot/multiboot.h index 8c7d00f..04f6322 100644 --- a/kaleid/include/multiboot/multiboot.h +++ b/kaleid/include/multiboot/multiboot.h @@ -5,105 +5,98 @@ // // // // // Copyright © 1999,2003,2007-2010 Free Software Foundation, Inc. // +// Copyright © 2018-2019 The OS/K Team // // // -// Note: In this header, "the Software" refers to the multiboot.h file. // +// This file is part of OS/K. // // // -// Permission is hereby granted, free of charge, to any person // -// obtaining a copy of this software and associated documentation // -// files (the "Software"), to deal in the Software without restriction, // -// including without limitation the rights to use, copy, modify, merge, // -// publish, distribute, sublicense, and/or sell copies of the Software, // -// and to permit persons to whom the Software is furnished to do so, // -// subject to the following conditions: // +// OS/K is free software: you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation, either version 3 of the License, or // +// any later version. // // // -// The above copyright notice and this permission notice shall be included // -// in all copies or substantial portions of the Software. // +// OS/K is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY//without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // // // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // -// IN NO EVENT SHALL ANY DEVELOPER OR DISTRIBUTOR BE LIABLE FOR // -// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // -// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.. // +// You should have received a copy of the GNU General Public License // +// along with OS/K. If not, see . // //----------------------------------------------------------------------------// #ifndef MULTIBOOT_HEADER #define MULTIBOOT_HEADER 1 /* How many bytes from the start of the file we search for the header. */ -#define MULTIBOOT_SEARCH 8192 -#define MULTIBOOT_HEADER_ALIGN 4 +#define MULTIBOOT_SEARCH 8192 +#define MULTIBOOT_HEADER_ALIGN 4 /* The magic field should contain this. */ -#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 /* This should be in %eax. */ -#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 /* Alignment of multiboot modules. */ -#define MULTIBOOT_MOD_ALIGN 0x00001000 +#define MULTIBOOT_MOD_ALIGN 0x00001000 /* Alignment of the multiboot info structure. */ -#define MULTIBOOT_INFO_ALIGN 0x00000004 +#define MULTIBOOT_INFO_ALIGN 0x00000004 /* Flags set in the 'flags' member of the multiboot header. */ /* Align all boot modules on i386 page (4KB) boundaries. */ -#define MULTIBOOT_PAGE_ALIGN 0x00000001 +#define MULTIBOOT_PAGE_ALIGN 0x00000001 /* Must pass memory information to OS. */ -#define MULTIBOOT_MEMORY_INFO 0x00000002 +#define MULTIBOOT_MEMORY_INFO 0x00000002 /* Must pass video information to OS. */ -#define MULTIBOOT_VIDEO_MODE 0x00000004 +#define MULTIBOOT_VIDEO_MODE 0x00000004 /* This flag indicates the use of the address fields in the header. */ -#define MULTIBOOT_AOUT_KLUDGE 0x00010000 +#define MULTIBOOT_AOUT_KLUDGE 0x00010000 -/* Flags to be set in the 'flags' member of the multiboot info structure. */ -/* is there basic lower/upper memory information? */ -#define MULTIBOOT_INFO_MEMORY 0x00000001 +#define MULTIBOOT_INFO_MEMORY 0x00000001 /* is there a boot device set? */ -#define MULTIBOOT_INFO_BOOTDEV 0x00000002 +#define MULTIBOOT_INFO_BOOTDEV 0x00000002 /* is the command-line defined? */ -#define MULTIBOOT_INFO_CMDLINE 0x00000004 +#define MULTIBOOT_INFO_CMDLINE 0x00000004 /* are there modules to do something with? */ -#define MULTIBOOT_INFO_MODS 0x00000008 +#define MULTIBOOT_INFO_MODS 0x00000008 /* These next two are mutually exclusive */ /* is there a symbol table loaded? */ -#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010 +#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010 /* is there an ELF section header table? */ -#define MULTIBOOT_INFO_ELF_SHDR 0X00000020 +#define MULTIBOOT_INFO_ELF_SHDR 0x00000020 /* is there a full memory map? */ -#define MULTIBOOT_INFO_MEM_MAP 0x00000040 +#define MULTIBOOT_INFO_MEM_MAP 0x00000040 /* Is there drive info? */ -#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080 +#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080 /* Is there a config table? */ -#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100 +#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100 /* Is there a boot loader name? */ -#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200 +#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200 /* Is there a APM table? */ -#define MULTIBOOT_INFO_APM_TABLE 0x00000400 +#define MULTIBOOT_INFO_APM_TABLE 0x00000400 /* Is there video information? */ -#define MULTIBOOT_INFO_VBE_INFO 0x00000800 -#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 +#define MULTIBOOT_INFO_VBE_INFO 0x00000800 +#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000 #ifndef ASM_FILE -typedef unsigned char multiboot_uint8_t; -typedef unsigned short multiboot_uint16_t; -typedef unsigned int multiboot_uint32_t; -typedef unsigned long long multiboot_uint64_t; +typedef unsigned char multiboot_uint8_t; +typedef unsigned short multiboot_uint16_t; +typedef unsigned int multiboot_uint32_t; +typedef unsigned long long multiboot_uint64_t; struct multiboot_header { @@ -207,7 +200,7 @@ struct multiboot_info multiboot_uint8_t framebuffer_bpp; #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 -#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 +#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 multiboot_uint8_t framebuffer_type; union { @@ -241,8 +234,8 @@ struct multiboot_mmap_entry multiboot_uint32_t size; multiboot_uint64_t addr; multiboot_uint64_t len; -#define MULTIBOOT_MEMORY_AVAILABLE 1 -#define MULTIBOOT_MEMORY_RESERVED 2 +#define MULTIBOOT_MEMORY_AVAILABLE 1 +#define MULTIBOOT_MEMORY_RESERVED 2 #define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 #define MULTIBOOT_MEMORY_NVS 4 #define MULTIBOOT_MEMORY_BADRAM 5 diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index d2dd85f..c6a1853 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -42,16 +42,18 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic) // We're out StartPanic( "We were loaded by : %s\n\n\n" "We get\n" - " *mbInfo : %x\n" + " *mbInfo : %p\n" " mbMagic : %x\n" " mbBootdrv : %x\n" + " *mbMmap : %p\n" + " `-length : %d\n" "\nGoodbye World :(", mbInfo->boot_loader_name, mbInfo, mbMagic, - mbInfo->boot_device + mbInfo->boot_device, + mbInfo->mmap_addr, + mbInfo->mmap_length ); } - - diff --git a/kaleid/kernel/init/table.c b/kaleid/kernel/init/table.c index 5fcdd2c..7a51088 100644 --- a/kaleid/kernel/init/table.c +++ b/kaleid/kernel/init/table.c @@ -29,5 +29,3 @@ Processor_t cpuTable[NCPUS] = {0}; Terminal_t *stdOut = 0, *stdDbg = 0; -volatile ushort *vga = (volatile ushort *)0xB8000; - From 9ffc2348d2bd444a4cbeb5b590c08542d3c13f2e Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 14 Mar 2019 13:12:01 +0100 Subject: [PATCH 22/29] little makefile stuff --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d7ae0dc..00e3ce4 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,7 @@ test: kaleid @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm -test32: kaleid +test32: @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 @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm From 7ba6b95c199173ecd7dae16f3029daa7d7db848d Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 14 Mar 2019 18:30:29 +0100 Subject: [PATCH 23/29] working on cpu --- kaleid/include/kernel/cpu.h | 23 +++++++++++++++++++++++ kaleid/kernel/cpu/cpuid.c | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 kaleid/include/kernel/cpu.h create mode 100644 kaleid/kernel/cpu/cpuid.c diff --git a/kaleid/include/kernel/cpu.h b/kaleid/include/kernel/cpu.h new file mode 100644 index 0000000..3a26310 --- /dev/null +++ b/kaleid/include/kernel/cpu.h @@ -0,0 +1,23 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: CPU related functions // +// // +// // +// Copyright © 2018-2019 The OS/K Team // +// // +// This file is part of OS/K. // +// // +// OS/K is free software: you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation, either version 3 of the License, or // +// any later version. // +// // +// OS/K is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY//without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with OS/K. If not, see . // +//----------------------------------------------------------------------------// diff --git a/kaleid/kernel/cpu/cpuid.c b/kaleid/kernel/cpu/cpuid.c new file mode 100644 index 0000000..1728396 --- /dev/null +++ b/kaleid/kernel/cpu/cpuid.c @@ -0,0 +1,23 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: CPU detection // +// // +// // +// Copyright © 2018-2019 The OS/K Team // +// // +// This file is part of OS/K. // +// // +// OS/K is free software: you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation, either version 3 of the License, or // +// any later version. // +// // +// OS/K is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY//without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with OS/K. If not, see . // +//----------------------------------------------------------------------------// From 107688098e8cbf55a8ce9547ce8e64f2aea9c677 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 14 Mar 2019 18:33:12 +0100 Subject: [PATCH 24/29] working on cpu --- kaleid/include/kernel/mm.h | 23 +++++++++++++++++++++++ kaleid/kernel/mm/.placeholder | 0 2 files changed, 23 insertions(+) create mode 100644 kaleid/include/kernel/mm.h create mode 100644 kaleid/kernel/mm/.placeholder diff --git a/kaleid/include/kernel/mm.h b/kaleid/include/kernel/mm.h new file mode 100644 index 0000000..95971fe --- /dev/null +++ b/kaleid/include/kernel/mm.h @@ -0,0 +1,23 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: Memory related functions // +// // +// // +// Copyright © 2018-2019 The OS/K Team // +// // +// This file is part of OS/K. // +// // +// OS/K is free software: you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation, either version 3 of the License, or // +// any later version. // +// // +// OS/K is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY//without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with OS/K. If not, see . // +//----------------------------------------------------------------------------// diff --git a/kaleid/kernel/mm/.placeholder b/kaleid/kernel/mm/.placeholder new file mode 100644 index 0000000..e69de29 From 7add4179868f741959a5fd37880ce8f97cdae7cc Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 14 Mar 2019 21:00:03 +0100 Subject: [PATCH 25/29] stuff --- kaleid/include/kernel/cpu.h | 6 ++++++ kaleid/kernel/cpu/cpuid.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/kaleid/include/kernel/cpu.h b/kaleid/include/kernel/cpu.h index 3a26310..f347d99 100644 --- a/kaleid/include/kernel/cpu.h +++ b/kaleid/include/kernel/cpu.h @@ -21,3 +21,9 @@ // You should have received a copy of the GNU General Public License // // along with OS/K. If not, see . // //----------------------------------------------------------------------------// + +#define cpuid(in, a, b, c, d) asm("cpuid" \ + : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ + : "a" (in) \ + ); + diff --git a/kaleid/kernel/cpu/cpuid.c b/kaleid/kernel/cpu/cpuid.c index 1728396..7cab5a5 100644 --- a/kaleid/kernel/cpu/cpuid.c +++ b/kaleid/kernel/cpu/cpuid.c @@ -21,3 +21,5 @@ // You should have received a copy of the GNU General Public License // // along with OS/K. If not, see . // //----------------------------------------------------------------------------// + + From 77b9f2d066ae78a2f347b4a4a213329d3a18713f Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sat, 16 Mar 2019 22:33:09 +0100 Subject: [PATCH 26/29] Makefile stuff --- Makefile | 21 +++++++++------------ boot/grub/grub-install.sh | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 00e3ce4..5537649 100644 --- a/Makefile +++ b/Makefile @@ -63,17 +63,12 @@ CL3='\033[0m' NC='\033[1;37m' kernel: - cpp ./Makefile.in > build/Makefile.out - python build/idttool.py - make kernel -f build/Makefile.out.2 - rm build/Makefile.out build/Makefile.out.2 - -kernel-asm: - cpp -D_TO_ASM ./Makefile.in > build/Makefile.out - python build/idttool.py - make kernel -f build/Makefile.out.2 - rm build/Makefile.out build/Makefile.out.2 - + @echo ${CL2}[[kernel]]${NC} Making kernel...${CL3} + @cpp ./Makefile.in > build/Makefile.out + @python build/idttool.py + @make kernel -f build/Makefile.out.2 + @rm build/Makefile.out build/Makefile.out.2 + @echo ${CL2}[[kernel]]${CL} Terminated without error.${CL3} tests: cpp -D_TESTS ./Makefile.in > build/Makefile.out python build/idttool.py @@ -84,8 +79,9 @@ boot.mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg @mkdir -p $(BINDIR)/disk @echo ${CL2}[boot.mbr]${NC} Installing MBR on image...${CL3} @$(MBRDIR)/grub-install.sh $(BINDIR)/disk.img $(BINDIR)/disk $(MBRDIR)/grub.cfg - @echo ${CL2}[boot.mbr]${CL} OK${CL3} + @tail -1 grub.log | head -1 | grep "Installation terminée, sans erreur." @rmdir $(BINDIR)/disk + @echo ${CL2}[boot.mbr]${CL} Terminated without error.${CL3} boot.loader.asm: $(LOADERDIR)/loader.asm @echo ${CL2}[boot.loader.asm]${NC} Making loader...${CL3} @@ -106,6 +102,7 @@ copykernel: make_disk: @echo ${CL2}[make_disk]${NC} Constructing disk image...${CL3} @$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img + @echo ${CL2}[make_disk]${CL} OK${CL3} diff --git a/boot/grub/grub-install.sh b/boot/grub/grub-install.sh index cd76028..d89d6eb 100755 --- a/boot/grub/grub-install.sh +++ b/boot/grub/grub-install.sh @@ -61,4 +61,4 @@ sudo umount /dev/loop1 > /dev/null echo ${CL2}[grub-install.sh]${NC} Unmounting image... \(losetup\)${CL3} sudo losetup -D > /dev/null -echo ${CL2}[grub-install.sh]${CL} Terminated without error. See grub.log for more informations.${CL3} +echo ${CL2}[grub-install.sh]${CL} See grub.log for more informations.${CL3} From bc53c696fccbdbbc7360d44eaec2968cdf70548f Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sun, 17 Mar 2019 22:32:52 +0100 Subject: [PATCH 27/29] Big reorganization of the makefile --- Makefile | 223 +++++++++++------- Makefile.in | 104 -------- build/idttool.py | 14 -- build/obj/kaleid/crtlib/test/.placeholder | 0 build/obj/kaleid/extras/.placeholder | 0 .../{common/test => kernel}/.placeholder | 0 build/obj/kaleid/kernel/init/.placeholder | 0 build/obj/kaleid/kernel/io/.placeholder | 0 build/obj/kaleid/kernel/ke/.placeholder | 0 build/obj/kaleid/test/.placeholder | 0 build/preproc.h | 44 ---- kaleid/kernel/cpu/cpuid.c | 2 +- 12 files changed, 145 insertions(+), 242 deletions(-) delete mode 100644 Makefile.in delete mode 100644 build/idttool.py delete mode 100644 build/obj/kaleid/crtlib/test/.placeholder delete mode 100644 build/obj/kaleid/extras/.placeholder rename build/obj/kaleid/{common/test => kernel}/.placeholder (100%) delete mode 100644 build/obj/kaleid/kernel/init/.placeholder delete mode 100644 build/obj/kaleid/kernel/io/.placeholder delete mode 100644 build/obj/kaleid/kernel/ke/.placeholder delete mode 100644 build/obj/kaleid/test/.placeholder delete mode 100644 build/preproc.h diff --git a/Makefile b/Makefile index 5537649..35b2feb 100644 --- a/Makefile +++ b/Makefile @@ -22,117 +22,182 @@ # along with OS/K. If not, see . # #=----------------------------------------------------------------------------=# -.PHONY: all +## VARIABLES ----------------------------------------------------------------- # #Programs ASM=nasm LD=ld +CCNAME=x86_64-elf-gcc + ASMFLAGS=-f elf64 LDFLAGS=-melf_x86_64 +COPTIM=-O2 +CWARNS=-Wall -Wextra # -Werror=implicit-function-declaration +CINCLUDES=-Ikaleid/include +CFLAGS1=-nostdlib -ffreestanding -mcmodel=large # -std=gnu11 +CFLAGS2= -c -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fno-strict-aliasing +CFLAGS=$(CFLAGS1) $(CFLAGS2) -DNDEBUG +KCC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) -D_OSK_SOURCE -D_KALEID_KERNEL #Folders MBRDIR=boot/grub LOADERDIR=boot/loader +KERNELDIR=kaleid 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/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' CL2='\033[1;36m' CL3='\033[0m' NC='\033[1;37m' -kernel: - @echo ${CL2}[[kernel]]${NC} Making kernel...${CL3} - @cpp ./Makefile.in > build/Makefile.out - @python build/idttool.py - @make kernel -f build/Makefile.out.2 - @rm build/Makefile.out build/Makefile.out.2 - @echo ${CL2}[[kernel]]${CL} Terminated without error.${CL3} -tests: - cpp -D_TESTS ./Makefile.in > build/Makefile.out - python build/idttool.py - make tests -f build/Makefile.out.2 - rm build/Makefile.out build/Makefile.out.2 +## MAIN MAKEFILE ------------------------------------------------------------- # +.PHONY: all +all : kernel -boot.mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg - @mkdir -p $(BINDIR)/disk - @echo ${CL2}[boot.mbr]${NC} Installing MBR on image...${CL3} - @$(MBRDIR)/grub-install.sh $(BINDIR)/disk.img $(BINDIR)/disk $(MBRDIR)/grub.cfg - @tail -1 grub.log | head -1 | grep "Installation terminée, sans erreur." - @rmdir $(BINDIR)/disk - @echo ${CL2}[boot.mbr]${CL} Terminated without error.${CL3} - -boot.loader.asm: $(LOADERDIR)/loader.asm - @echo ${CL2}[boot.loader.asm]${NC} Making loader...${CL3} - @$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(OBJDIR)/boot/loader.o > /dev/null - @echo ${CL2}[boot.loader.asm]${CL} OK${CL3} - -loader: boot.loader.asm link copykernel - -copykernel: - @mkdir -p $(BINDIR)/disk - @echo ${CL2}[disk]${NC} Integrating kernel...${CL3} - @$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk - @cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid - @$(MBRDIR)/umount.sh $(BINDIR)/disk - @echo ${CL2}[disk]${CL} OK${CL3} - @rmdir $(BINDIR)/disk - -make_disk: - @echo ${CL2}[make_disk]${NC} Constructing disk image...${CL3} - @$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img - - @echo ${CL2}[make_disk]${CL} OK${CL3} - - -kaleid: kernel loader - -test: kaleid +.PHONY: test +test: all @qemu-system-x86_64 -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 @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm - -test32: +.PHONY: test32 +test32: all @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 @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm -debug: kaleid +.PHONY: debug +debug: all @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm -boot: make_disk boot.mbr - @echo ${CL2}[[boot]]${CL} Terminated without error.${CL3} -all: boot kaleid - @echo ${CL2}[[all]]${CL} Terminated without error.${CL3} +.PHONY: kernel +kernel: $(BINDIR)/kaleid $(BINDIR)/disk.img + @mkdir -p $(BINDIR)/disk + @echo ${CL2}[[$@]] ${NC}Integrating kernel...${CL3} + -@$(MBRDIR)/umount.sh $(BINDIR)/disk + @$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk + @cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid + @$(MBRDIR)/umount.sh $(BINDIR)/disk + @echo ${CL2}[[$@]] ${CL}Success.${CL3} + @rmdir $(BINDIR)/disk -link: - @$(LD) $(LDFLAGS) -T build/kernel.ld $(l_objects) -o $(OBJDIR)/boot/kaleid.x86_64 - @x86_64-elf-objcopy -I elf64-x86-64 -O elf32-i386 $(OBJDIR)/boot/kaleid.x86_64 $(BINDIR)/kaleid +.PHONY: install_mbr +install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg + @mkdir -p $(BINDIR)/disk + @echo ${CL2}[$@] ${NC}Installing MBR on image...${CL3} + -@$(MBRDIR)/umount.sh $(BINDIR)/disk + @$(MBRDIR)/grub-install.sh $(BINDIR)/disk.img $(BINDIR)/disk $(MBRDIR)/grub.cfg + @tail -1 grub.log | head -1 | grep "Installation terminée, sans erreur." + @rmdir $(BINDIR)/disk + @echo ${CL2}[$@] ${CL}Success.${CL3} +.PHONY: clean clean: - @rm -Rf $(BINDIR)/* - @rm -Rf $(OBJDIR)/*/*/*/*.o + -@$(MBRDIR)/umount.sh $(BINDIR)/disk + @rm -Rvf $(BINDIR)/*.* + @rm -Rvf $(OBJDIR)/*.o + @rm -Rvf $(OBJDIR)/*/*.o + @rm -Rvf $(OBJDIR)/*/*/*.o + +.PHONY: kal_com +kal_com: $(OBJDIR)/kaleid/atoi.o $(OBJDIR)/kaleid/ctype.o \ + $(OBJDIR)/kaleid/itoa.o $(OBJDIR)/kaleid/memory.o \ + $(OBJDIR)/kaleid/rand.o $(OBJDIR)/kaleid/sprintf.o \ + $(OBJDIR)/kaleid/status.o $(OBJDIR)/kaleid/string.o \ + $(OBJDIR)/kaleid/strtol.o $(OBJDIR)/kaleid/argv.o \ + $(OBJDIR)/kaleid/prog.o $(OBJDIR)/kaleid/atol.o \ + $(OBJDIR)/kaleid/atou.o $(OBJDIR)/kaleid/atoul.o \ + $(OBJDIR)/kaleid/utoa.o $(OBJDIR)/kaleid/ltoa.o \ + $(OBJDIR)/kaleid/ultoa.o + +.PHONY: kal_kern +kal_kern: $(OBJDIR)/kaleid/kernel/cpuid.o $(OBJDIR)/kaleid/kernel/init.o \ + $(OBJDIR)/kaleid/kernel/table.o $(OBJDIR)/kaleid/kernel/cursor.o \ + $(OBJDIR)/kaleid/kernel/term.o $(OBJDIR)/kaleid/kernel/vga.o \ + $(OBJDIR)/kaleid/kernel/panic.o + + +$(BINDIR)/kaleid: $(OBJDIR)/boot/kaleid.x86_64 + @echo ${CL2}[$@] ${NC}Objcopy...${CL3} + @x86_64-elf-objcopy -I elf64-x86-64 -O elf32-i386 $(OBJDIR)/boot/kaleid.x86_64 $(BINDIR)/kaleid + @echo ${CL2}[$@] ${CL}Success.${CL3} + +$(OBJDIR)/boot/kaleid.x86_64: $(OBJDIR)/boot/loader.o kal_com kal_kern + @echo ${CL2}[$@] ${NC}Linking kernel objects...${CL3} + @$(LD) $(LDFLAGS) -T build/kernel.ld \ + $(OBJDIR)/boot/loader.o \ + $(OBJDIR)/kaleid/*.o \ + $(OBJDIR)/kaleid/kernel/*.o \ + -o $(OBJDIR)/boot/kaleid.x86_64 + @echo ${CL2}[$@] ${CL}Success.${CL3} + +$(OBJDIR)/boot/loader.o: $(LOADERDIR)/loader.asm + @echo ${CL2}[$@] ${NC}Making loader...${CL3} + @$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(OBJDIR)/boot/loader.o > /dev/null + @echo ${CL2}[$@] ${CL}Success.${CL3} + +$(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh + @echo ${CL2}[$@]${NC} Constructing disk image...${CL3} + -@$(MBRDIR)/umount.sh $(BINDIR)/disk + @$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img + @make install_mbr + @echo ${CL2}[$@]${NC} Constructing disk image...${CL3} +## KALEID MAKEFILE ----------------------------------------------------------- # + +# Crtlib objects +$(OBJDIR)/kaleid/atoi.o: $(KERNELDIR)/crtlib/atoi.c + @$(KCC) -D_NEED_ATOI $< -o $@ +$(OBJDIR)/kaleid/atol.o: $(KERNELDIR)/crtlib/atoi.c + @$(KCC) -D_NEED_ATOL $< -o $@ +$(OBJDIR)/kaleid/atou.o: $(KERNELDIR)/crtlib/atoi.c + @$(KCC) -D_NEED_ATOU $< -o $@ +$(OBJDIR)/kaleid/atoul.o: $(KERNELDIR)/crtlib/atoi.c + @$(KCC) -D_NEED_ATOUL $< -o $@ +$(OBJDIR)/kaleid/ctype.o: $(KERNELDIR)/crtlib/ctype.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/itoa.o: $(KERNELDIR)/crtlib/itoa.c + @$(KCC) -D_NEED_ITOA $< -o $@ +$(OBJDIR)/kaleid/ltoa.o: $(KERNELDIR)/crtlib/itoa.c + @$(KCC) -D_NEED_LTOA $< -o $@ +$(OBJDIR)/kaleid/utoa.o: $(KERNELDIR)/crtlib/itoa.c + @$(KCC) -D_NEED_UTOA $< -o $@ +$(OBJDIR)/kaleid/ultoa.o: $(KERNELDIR)/crtlib/itoa.c + @$(KCC) -D_NEED_ULTOA $< -o $@ +$(OBJDIR)/kaleid/memory.o: $(KERNELDIR)/crtlib/memory.c + @$(KCC) -fno-strict-aliasing $< -o $@ +$(OBJDIR)/kaleid/rand.o: $(KERNELDIR)/crtlib/rand.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/sprintf.o: $(KERNELDIR)/crtlib/sprintf.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/status.o: $(KERNELDIR)/crtlib/status.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/string.o: $(KERNELDIR)/crtlib/string.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/strtol.o: $(KERNELDIR)/crtlib/strtol.c + @$(KCC) $< -o $@ + +# Extra objects +$(OBJDIR)/kaleid/argv.o: $(KERNELDIR)/extras/argv.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/prog.o: $(KERNELDIR)/extras/prog.c + @$(KCC) $< -o $@ + +# Kernel objects +$(OBJDIR)/kaleid/kernel/cpuid.o: $(KERNELDIR)/kernel/cpu/cpuid.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/kernel/init.o: $(KERNELDIR)/kernel/init/init.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/kernel/table.o: $(KERNELDIR)/kernel/init/table.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/kernel/cursor.o: $(KERNELDIR)/kernel/io/cursor.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/kernel/term.o: $(KERNELDIR)/kernel/io/term.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/kernel/vga.o: $(KERNELDIR)/kernel/io/vga.c + @$(KCC) $< -o $@ +$(OBJDIR)/kaleid/kernel/panic.o: $(KERNELDIR)/kernel/ke/panic.c + @$(KCC) $< -o $@ diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index eec9b98..0000000 --- a/Makefile.in +++ /dev/null @@ -1,104 +0,0 @@ -// -*- Mode: Makefile -*- - -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Desc: Project Makefile // -// // -// // -// Copyright © 2018-2019 The OS/K Team // -// // -// This file is part of OS/K. // -// // -// OS/K is free software: you can redistribute it and/or modify // -// it under the terms of the GNU General Public License as published by // -// the Free Software Foundation, either version 3 of the License, or // -// any later version. // -// // -// OS/K is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY//without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU General Public License for more details. // -// // -// You should have received a copy of the GNU General Public License // -// along with OS/K. If not, see . // -//----------------------------------------------------------------------------// - -// The madman's Makefile -#include "build/preproc.h" - -CCNAME=x86_64-elf-gcc -CC2NAME=gcc -COPTIM=-O2 -CWARNS=-Wall -Wextra // -Werror=implicit-function-declaration -CINCLUDES=-Ikaleid/include - -CFLAGS1=-nostdlib -ffreestanding -mcmodel=large // -std=gnu11 -CFLAGS2=_ASMTYPE -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -CFLAGS=$(CFLAGS1) $(CFLAGS2) -DNDEBUG - -CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) - -BINDIR=build/bin -OBJDIR=build/obj - -BOOTDIR=boot -COMMDIR=kaleid/crtlib -KERNDIR=kaleid/kernel -SYSTDIR=kaleid/system -LINXDIR=kaleid/test - - -// COMMON MAKEFILE - -COBJDIR=$(OBJDIR)/$(COMMDIR) -LOBJDIR=$(OBJDIR)/$(LINXDIR) - -COMMOBJS=COBJ6(string, status, rand, memory, strtol, sprintf) COBJ4(itoa, ltoa, utoa, ultoa) COBJ4(atoi, atol, atou, atoul) COBJ3(../extras/prog, ../extras/argv, ctype) - -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 - -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) - -tests: common - $(TCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o - $(TCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/comm-test - -//----------------------------------------------------------------------------# -// KERNEL MAKEFILE - -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) - //LINK_KERNEL(kaleid-kernel.elf) - -//----------------------------------------------------------------------------# - diff --git a/build/idttool.py b/build/idttool.py deleted file mode 100644 index 200d19d..0000000 --- a/build/idttool.py +++ /dev/null @@ -1,14 +0,0 @@ -# don't mind this file - -f1 = open("build/Makefile.out", "r+") -f2 = open("build/Makefile.out.2", "w+") - -fl = f1.readlines() -for ln in fl: - if ln[0] == ' ' and ln[1] != ' ': - f2.write('\t') - f2.write(ln) - -f1.close() -f2.close() - diff --git a/build/obj/kaleid/crtlib/test/.placeholder b/build/obj/kaleid/crtlib/test/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/build/obj/kaleid/extras/.placeholder b/build/obj/kaleid/extras/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/build/obj/kaleid/common/test/.placeholder b/build/obj/kaleid/kernel/.placeholder similarity index 100% rename from build/obj/kaleid/common/test/.placeholder rename to build/obj/kaleid/kernel/.placeholder diff --git a/build/obj/kaleid/kernel/init/.placeholder b/build/obj/kaleid/kernel/init/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/build/obj/kaleid/kernel/io/.placeholder b/build/obj/kaleid/kernel/io/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/build/obj/kaleid/kernel/ke/.placeholder b/build/obj/kaleid/kernel/ke/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/build/obj/kaleid/test/.placeholder b/build/obj/kaleid/test/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/build/preproc.h b/build/preproc.h deleted file mode 100644 index 746bd2c..0000000 --- a/build/preproc.h +++ /dev/null @@ -1,44 +0,0 @@ -// be careful with this file - -#ifdef _TESTS -# define CCC TCC -#else -# define CCC KCC -#endif - -#ifdef _TO_ASM -# define _CSPREF -S -# define _OUTFIX S -# define _ASMTYPE -masm=intel -# define LINK_KERNEL(out) -#else -# define _CSPREF -c -# define _OUTFIX o -# define _ASMTYPE -# define LINK_KERNEL(out) $(KCC) -T ./build/kernel.ld $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/out -#endif - -#define COMPILE_CONVRT1(file) $(CCC) _CSPREF $(COMMDIR)/itoa.c -o $(COBJDIR)/file._OUTFIX -#define COMPILE_CONVRT2(file) $(CCC) _CSPREF $(COMMDIR)/atoi.c -o $(COBJDIR)/file._OUTFIX - -#define COMPILE_COMMON(file) $(CCC) _CSPREF $(COMMDIR)/file.c -o $(COBJDIR)/file._OUTFIX -#define COMPILE_KERNEL(file) $(KCC) _CSPREF $(KERNDIR)/file.c -o $(KOBJDIR)/file._OUTFIX - -#define COBJ1(x1) $(COBJDIR)/x1.o -#define COBJ2(x1,x2) COBJ1(x1) $(COBJDIR)/x2.o -#define COBJ3(x1,x2,x3) COBJ2(x1,x2) $(COBJDIR)/x3.o -#define COBJ4(x1,x2,x3,x4) COBJ3(x1,x2,x3) $(COBJDIR)/x4.o -#define COBJ5(x1,x2,x3,x4,x5) COBJ4(x1,x2,x3,x4) $(COBJDIR)/x5.o -#define COBJ6(x1,x2,x3,x4,x5,x6) COBJ5(x1,x2,x3,x4,x5) $(COBJDIR)/x6.o -#define COBJ7(x1,x2,x3,x4,x5,x6,x7) COBJ6(x1,x2,x3,x4,x5,x6) $(COBJDIR)/x7.o -#define COBJ8(x1,x2,x3,x4,x5,x6,x7,x8) COBJ7(x1,x2,x3,x4,x5,x6,x7) $(COBJDIR)/x8.o - -#define KOBJ1(x1) $(KOBJDIR)/x1.o -#define KOBJ2(x1,x2) KOBJ1(x1) $(KOBJDIR)/x2.o -#define KOBJ3(x1,x2,x3) KOBJ2(x1,x2) $(KOBJDIR)/x3.o -#define KOBJ4(x1,x2,x3,x4) KOBJ3(x1,x2,x3) $(KOBJDIR)/x4.o -#define KOBJ5(x1,x2,x3,x4,x5) KOBJ4(x1,x2,x3,x4) $(KOBJDIR)/x5.o -#define KOBJ6(x1,x2,x3,x4,x5,x6) KOBJ5(x1,x2,x3,x4,x5) $(KOBJDIR)/x6.o -#define KOBJ7(x1,x2,x3,x4,x5,x6,x7) KOBJ6(x1,x2,x3,x4,x5,x6) $(KOBJDIR)/x7.o -#define KOBJ8(x1,x2,x3,x4,x5,x6,x7,x8) KOBJ7(x1,x2,x3,x4,x5,x6,x7) $(KOBJDIR)/x8.o - diff --git a/kaleid/kernel/cpu/cpuid.c b/kaleid/kernel/cpu/cpuid.c index 7cab5a5..ef8b36a 100644 --- a/kaleid/kernel/cpu/cpuid.c +++ b/kaleid/kernel/cpu/cpuid.c @@ -22,4 +22,4 @@ // along with OS/K. If not, see . // //----------------------------------------------------------------------------// - +int stub; From fb5fc7ba6cd770b9ee72521c91361bd0e923d7f7 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sun, 17 Mar 2019 22:47:21 +0100 Subject: [PATCH 28/29] Big reorganization of the makefile --- Makefile | 187 +++++++++++++++++++++++++++---------------------------- 1 file changed, 92 insertions(+), 95 deletions(-) diff --git a/Makefile b/Makefile index 35b2feb..02e1fd7 100644 --- a/Makefile +++ b/Makefile @@ -52,103 +52,23 @@ CL2='\033[1;36m' CL3='\033[0m' NC='\033[1;37m' -## MAIN MAKEFILE ------------------------------------------------------------- # + .PHONY: all -all : kernel +all : OS/K -.PHONY: test -test: all - @qemu-system-x86_64 -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 - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm -.PHONY: test32 -test32: all - @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 - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm - -.PHONY: debug -debug: all - @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm - @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm - - -.PHONY: kernel -kernel: $(BINDIR)/kaleid $(BINDIR)/disk.img - @mkdir -p $(BINDIR)/disk - @echo ${CL2}[[$@]] ${NC}Integrating kernel...${CL3} - -@$(MBRDIR)/umount.sh $(BINDIR)/disk - @$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk - @cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid - @$(MBRDIR)/umount.sh $(BINDIR)/disk - @echo ${CL2}[[$@]] ${CL}Success.${CL3} - @rmdir $(BINDIR)/disk - -.PHONY: install_mbr -install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg - @mkdir -p $(BINDIR)/disk - @echo ${CL2}[$@] ${NC}Installing MBR on image...${CL3} - -@$(MBRDIR)/umount.sh $(BINDIR)/disk - @$(MBRDIR)/grub-install.sh $(BINDIR)/disk.img $(BINDIR)/disk $(MBRDIR)/grub.cfg - @tail -1 grub.log | head -1 | grep "Installation terminée, sans erreur." - @rmdir $(BINDIR)/disk - @echo ${CL2}[$@] ${CL}Success.${CL3} - -.PHONY: clean -clean: - -@$(MBRDIR)/umount.sh $(BINDIR)/disk - @rm -Rvf $(BINDIR)/*.* - @rm -Rvf $(OBJDIR)/*.o - @rm -Rvf $(OBJDIR)/*/*.o - @rm -Rvf $(OBJDIR)/*/*/*.o - -.PHONY: kal_com -kal_com: $(OBJDIR)/kaleid/atoi.o $(OBJDIR)/kaleid/ctype.o \ - $(OBJDIR)/kaleid/itoa.o $(OBJDIR)/kaleid/memory.o \ - $(OBJDIR)/kaleid/rand.o $(OBJDIR)/kaleid/sprintf.o \ - $(OBJDIR)/kaleid/status.o $(OBJDIR)/kaleid/string.o \ - $(OBJDIR)/kaleid/strtol.o $(OBJDIR)/kaleid/argv.o \ - $(OBJDIR)/kaleid/prog.o $(OBJDIR)/kaleid/atol.o \ - $(OBJDIR)/kaleid/atou.o $(OBJDIR)/kaleid/atoul.o \ - $(OBJDIR)/kaleid/utoa.o $(OBJDIR)/kaleid/ltoa.o \ - $(OBJDIR)/kaleid/ultoa.o - -.PHONY: kal_kern -kal_kern: $(OBJDIR)/kaleid/kernel/cpuid.o $(OBJDIR)/kaleid/kernel/init.o \ - $(OBJDIR)/kaleid/kernel/table.o $(OBJDIR)/kaleid/kernel/cursor.o \ - $(OBJDIR)/kaleid/kernel/term.o $(OBJDIR)/kaleid/kernel/vga.o \ - $(OBJDIR)/kaleid/kernel/panic.o - - -$(BINDIR)/kaleid: $(OBJDIR)/boot/kaleid.x86_64 - @echo ${CL2}[$@] ${NC}Objcopy...${CL3} - @x86_64-elf-objcopy -I elf64-x86-64 -O elf32-i386 $(OBJDIR)/boot/kaleid.x86_64 $(BINDIR)/kaleid - @echo ${CL2}[$@] ${CL}Success.${CL3} - -$(OBJDIR)/boot/kaleid.x86_64: $(OBJDIR)/boot/loader.o kal_com kal_kern - @echo ${CL2}[$@] ${NC}Linking kernel objects...${CL3} - @$(LD) $(LDFLAGS) -T build/kernel.ld \ - $(OBJDIR)/boot/loader.o \ - $(OBJDIR)/kaleid/*.o \ - $(OBJDIR)/kaleid/kernel/*.o \ - -o $(OBJDIR)/boot/kaleid.x86_64 - @echo ${CL2}[$@] ${CL}Success.${CL3} - -$(OBJDIR)/boot/loader.o: $(LOADERDIR)/loader.asm - @echo ${CL2}[$@] ${NC}Making loader...${CL3} - @$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(OBJDIR)/boot/loader.o > /dev/null - @echo ${CL2}[$@] ${CL}Success.${CL3} - -$(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh - @echo ${CL2}[$@]${NC} Constructing disk image...${CL3} - -@$(MBRDIR)/umount.sh $(BINDIR)/disk - @$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img - @make install_mbr - @echo ${CL2}[$@]${NC} Constructing disk image...${CL3} ## KALEID MAKEFILE ----------------------------------------------------------- # -# Crtlib objects +# Common objects +kal_com_obj= $(OBJDIR)/kaleid/atoi.o $(OBJDIR)/kaleid/ctype.o \ + $(OBJDIR)/kaleid/itoa.o $(OBJDIR)/kaleid/memory.o \ + $(OBJDIR)/kaleid/rand.o $(OBJDIR)/kaleid/sprintf.o \ + $(OBJDIR)/kaleid/status.o $(OBJDIR)/kaleid/string.o \ + $(OBJDIR)/kaleid/strtol.o $(OBJDIR)/kaleid/argv.o \ + $(OBJDIR)/kaleid/prog.o $(OBJDIR)/kaleid/atol.o \ + $(OBJDIR)/kaleid/atou.o $(OBJDIR)/kaleid/atoul.o \ + $(OBJDIR)/kaleid/utoa.o $(OBJDIR)/kaleid/ltoa.o \ + $(OBJDIR)/kaleid/ultoa.o + $(OBJDIR)/kaleid/atoi.o: $(KERNELDIR)/crtlib/atoi.c @$(KCC) -D_NEED_ATOI $< -o $@ $(OBJDIR)/kaleid/atol.o: $(KERNELDIR)/crtlib/atoi.c @@ -179,14 +99,17 @@ $(OBJDIR)/kaleid/string.o: $(KERNELDIR)/crtlib/string.c @$(KCC) $< -o $@ $(OBJDIR)/kaleid/strtol.o: $(KERNELDIR)/crtlib/strtol.c @$(KCC) $< -o $@ - -# Extra objects $(OBJDIR)/kaleid/argv.o: $(KERNELDIR)/extras/argv.c @$(KCC) $< -o $@ $(OBJDIR)/kaleid/prog.o: $(KERNELDIR)/extras/prog.c @$(KCC) $< -o $@ # Kernel objects +kal_kern_obj= $(OBJDIR)/kaleid/kernel/cpuid.o $(OBJDIR)/kaleid/kernel/init.o \ + $(OBJDIR)/kaleid/kernel/table.o $(OBJDIR)/kaleid/kernel/cursor.o \ + $(OBJDIR)/kaleid/kernel/term.o $(OBJDIR)/kaleid/kernel/vga.o \ + $(OBJDIR)/kaleid/kernel/panic.o + $(OBJDIR)/kaleid/kernel/cpuid.o: $(KERNELDIR)/kernel/cpu/cpuid.c @$(KCC) $< -o $@ $(OBJDIR)/kaleid/kernel/init.o: $(KERNELDIR)/kernel/init/init.c @@ -201,3 +124,77 @@ $(OBJDIR)/kaleid/kernel/vga.o: $(KERNELDIR)/kernel/io/vga.c @$(KCC) $< -o $@ $(OBJDIR)/kaleid/kernel/panic.o: $(KERNELDIR)/kernel/ke/panic.c @$(KCC) $< -o $@ + +## MAIN MAKEFILE ------------------------------------------------------------- # + +.PHONY: test +test: all + @qemu-system-x86_64 -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 + @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm +.PHONY: test32 +test32: all + @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 + @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm + +.PHONY: debug +debug: all + @qemu-system-x86_64 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S -enable-kvm 2> qemu.log & + @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm + @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm + +.PHONY:OS/K +OS/K: $(BINDIR)/kaleid $(BINDIR)/disk.img + @mkdir -p $(BINDIR)/disk + @echo ${CL2}[[$@]] ${NC}Integrating kernel...${CL3} + -@$(MBRDIR)/umount.sh $(BINDIR)/disk + @$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk + @cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid + @$(MBRDIR)/umount.sh $(BINDIR)/disk + @echo ${CL2}[[$@]] ${CL}Success.${CL3} + @rmdir $(BINDIR)/disk + +.PHONY: install_mbr +install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg + @mkdir -p $(BINDIR)/disk + @echo ${CL2}[$@] ${NC}Installing MBR on image...${CL3} + -@$(MBRDIR)/umount.sh $(BINDIR)/disk + @$(MBRDIR)/grub-install.sh $(BINDIR)/disk.img $(BINDIR)/disk $(MBRDIR)/grub.cfg + @tail -1 grub.log | head -1 | grep "Installation terminée, sans erreur." + @rmdir $(BINDIR)/disk + @echo ${CL2}[$@] ${CL}Success.${CL3} + +.PHONY: clean +clean: + -@$(MBRDIR)/umount.sh $(BINDIR)/disk + @rm -Rvf $(BINDIR)/*.* + @rm -Rvf $(OBJDIR)/*.o + @rm -Rvf $(OBJDIR)/*/*.o + @rm -Rvf $(OBJDIR)/*/*/*.o + +$(BINDIR)/kaleid: $(OBJDIR)/boot/kaleid.x86_64 + @echo ${CL2}[$@] ${NC}Objcopy...${CL3} + @x86_64-elf-objcopy -I elf64-x86-64 -O elf32-i386 $(OBJDIR)/boot/kaleid.x86_64 $(BINDIR)/kaleid + @echo ${CL2}[$@] ${CL}Success.${CL3} + +$(OBJDIR)/boot/kaleid.x86_64: $(kal_kern_obj) $(kal_com_obj) $(OBJDIR)/boot/loader.o + @echo ${CL2}[$@] ${NC}Linking kernel objects...${CL3} + @$(LD) $(LDFLAGS) -T build/kernel.ld \ + $(OBJDIR)/boot/loader.o \ + $(OBJDIR)/kaleid/*.o \ + $(OBJDIR)/kaleid/kernel/*.o \ + -o $(OBJDIR)/boot/kaleid.x86_64 + @echo ${CL2}[$@] ${CL}Success.${CL3} + +$(OBJDIR)/boot/loader.o: $(LOADERDIR)/loader.asm + @echo ${CL2}[$@] ${NC}Making loader...${CL3} + @$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(OBJDIR)/boot/loader.o > /dev/null + @echo ${CL2}[$@] ${CL}Success.${CL3} + +$(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh + @echo ${CL2}[$@]${NC} Constructing disk image...${CL3} + -@$(MBRDIR)/umount.sh $(BINDIR)/disk + @$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img + @make install_mbr + @echo ${CL2}[$@]${NC} Constructing disk image...${CL3} From a8e28c491b332e47517010548932bc4995aa3579 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sun, 17 Mar 2019 22:52:34 +0100 Subject: [PATCH 29/29] Update Readme.md --- Readme.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Readme.md b/Readme.md index 566c708..3133e29 100644 --- a/Readme.md +++ b/Readme.md @@ -20,19 +20,17 @@ To compile this project from sources, you must first install the dependencies ``` apt update && apt upgrade -apt install grub-pc dosfstools make nasm +apt install grub-pc dosfstools make nasm qemu ``` You also need to have the [x86-64 ELF gcc cross-compiler](https://www.os-k.eu/build-tools/cross-cc.tar.xz) in `/opt/cross-cc`. -To compile for the first time, you must compile the whole project, in order to build the loop disk image : - +To compile, simply use at the root of this project : ``` -make all +make ``` -After that, you can use this to compile the kernel only : - +To compile and test, simply use at the root of this project : ``` -make kaleid +make test ```