Merge pull request #50 from os-k-team/cpu&memory

Cpu&memory
This commit is contained in:
Adrien Bourmault 2019-03-23 00:07:36 +01:00 committed by GitHub
commit 48d700438c
18 changed files with 348 additions and 304 deletions

View File

@ -71,55 +71,55 @@ kal_com_obj= $(KOBJDIR)/atoi.o $(KOBJDIR)/ctype.o \
$(KOBJDIR)/utoa.o $(KOBJDIR)/ltoa.o \ $(KOBJDIR)/utoa.o $(KOBJDIR)/ltoa.o \
$(KOBJDIR)/ultoa.o $(KOBJDIR)/ultoa.o
$(KOBJDIR)/atoi.o: $(KERNELDIR)/crtlib/atoi.c $(KOBJDIR)/atoi.o: $(KERNELDIR)/crtlib/atoi.c $(KERNELDIR)/include/*/*.h
@$(KCC) -D_NEED_ATOI $< -o $@ @$(KCC) -D_NEED_ATOI $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/atol.o: $(KERNELDIR)/crtlib/atoi.c $(KOBJDIR)/atol.o: $(KERNELDIR)/crtlib/atoi.c $(KERNELDIR)/include/*/*.h
@$(KCC) -D_NEED_ATOL $< -o $@ @$(KCC) -D_NEED_ATOL $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/atou.o: $(KERNELDIR)/crtlib/atoi.c $(KOBJDIR)/atou.o: $(KERNELDIR)/crtlib/atoi.c $(KERNELDIR)/include/*/*.h
@$(KCC) -D_NEED_ATOU $< -o $@ @$(KCC) -D_NEED_ATOU $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/atoul.o: $(KERNELDIR)/crtlib/atoi.c $(KOBJDIR)/atoul.o: $(KERNELDIR)/crtlib/atoi.c $(KERNELDIR)/include/*/*.h
@$(KCC) -D_NEED_ATOUL $< -o $@ @$(KCC) -D_NEED_ATOUL $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/ctype.o: $(KERNELDIR)/crtlib/ctype.c $(KOBJDIR)/ctype.o: $(KERNELDIR)/crtlib/ctype.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/itoa.o: $(KERNELDIR)/crtlib/itoa.c $(KOBJDIR)/itoa.o: $(KERNELDIR)/crtlib/itoa.c $(KERNELDIR)/include/*/*.h
@$(KCC) -D_NEED_ITOA $< -o $@ @$(KCC) -D_NEED_ITOA $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/ltoa.o: $(KERNELDIR)/crtlib/itoa.c $(KOBJDIR)/ltoa.o: $(KERNELDIR)/crtlib/itoa.c $(KERNELDIR)/include/*/*.h
@$(KCC) -D_NEED_LTOA $< -o $@ @$(KCC) -D_NEED_LTOA $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/utoa.o: $(KERNELDIR)/crtlib/itoa.c $(KOBJDIR)/utoa.o: $(KERNELDIR)/crtlib/itoa.c $(KERNELDIR)/include/*/*.h
@$(KCC) -D_NEED_UTOA $< -o $@ @$(KCC) -D_NEED_UTOA $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/ultoa.o: $(KERNELDIR)/crtlib/itoa.c $(KOBJDIR)/ultoa.o: $(KERNELDIR)/crtlib/itoa.c $(KERNELDIR)/include/*/*.h
@$(KCC) -D_NEED_ULTOA $< -o $@ @$(KCC) -D_NEED_ULTOA $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/mem.o: $(KERNELDIR)/crtlib/mem.c $(KOBJDIR)/mem.o: $(KERNELDIR)/crtlib/mem.c $(KERNELDIR)/include/*/*.h
@$(KCC) -fno-strict-aliasing $< -o $@ @$(KCC) -fno-strict-aliasing $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/rand.o: $(KERNELDIR)/crtlib/rand.c $(KOBJDIR)/rand.o: $(KERNELDIR)/crtlib/rand.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/sprintf.o: $(KERNELDIR)/crtlib/sprintf.c $(KOBJDIR)/sprintf.o: $(KERNELDIR)/crtlib/sprintf.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/status.o: $(KERNELDIR)/crtlib/status.c $(KOBJDIR)/status.o: $(KERNELDIR)/crtlib/status.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/string.o: $(KERNELDIR)/crtlib/string.c $(KOBJDIR)/string.o: $(KERNELDIR)/crtlib/string.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/strtol.o: $(KERNELDIR)/crtlib/strtol.c $(KOBJDIR)/strtol.o: $(KERNELDIR)/crtlib/strtol.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/argv.o: $(KERNELDIR)/extras/argv.c $(KOBJDIR)/argv.o: $(KERNELDIR)/extras/argv.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/prog.o: $(KERNELDIR)/extras/prog.c $(KOBJDIR)/prog.o: $(KERNELDIR)/extras/prog.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
@ -130,34 +130,34 @@ kal_kern_obj= $(KOBJDIR)/kernel/cpuid.o $(KOBJDIR)/kernel/init.o \
$(KOBJDIR)/kernel/panic.o $(KOBJDIR)/kernel/map.o \ $(KOBJDIR)/kernel/panic.o $(KOBJDIR)/kernel/map.o \
$(KOBJDIR)/kernel/heap.o $(KOBJDIR)/kernel/malloc.o $(KOBJDIR)/kernel/heap.o $(KOBJDIR)/kernel/malloc.o
$(KOBJDIR)/kernel/cpuid.o: $(KERNELDIR)/kernel/cpu/cpuid.c $(KOBJDIR)/kernel/cpuid.o: $(KERNELDIR)/kernel/cpu/cpuid.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/init.o: $(KERNELDIR)/kernel/init/init.c $(KOBJDIR)/kernel/init.o: $(KERNELDIR)/kernel/init/init.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/table.o: $(KERNELDIR)/kernel/init/table.c $(KOBJDIR)/kernel/table.o: $(KERNELDIR)/kernel/init/table.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/cursor.o: $(KERNELDIR)/kernel/io/cursor.c $(KOBJDIR)/kernel/cursor.o: $(KERNELDIR)/kernel/io/cursor.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/term.o: $(KERNELDIR)/kernel/io/term.c $(KOBJDIR)/kernel/term.o: $(KERNELDIR)/kernel/io/term.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/vga.o: $(KERNELDIR)/kernel/io/vga.c $(KOBJDIR)/kernel/vga.o: $(KERNELDIR)/kernel/io/vga.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/panic.o: $(KERNELDIR)/kernel/ke/panic.c $(KOBJDIR)/kernel/panic.o: $(KERNELDIR)/kernel/ke/panic.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/map.o: $(KERNELDIR)/kernel/mm/map.c $(KOBJDIR)/kernel/map.o: $(KERNELDIR)/kernel/mm/map.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/heap.o: $(KERNELDIR)/kernel/mm/heap.c $(KOBJDIR)/kernel/heap.o: $(KERNELDIR)/kernel/mm/heap.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/malloc.o: $(KERNELDIR)/kernel/mm/malloc.c $(KOBJDIR)/kernel/malloc.o: $(KERNELDIR)/kernel/mm/malloc.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
@ -165,13 +165,13 @@ $(KOBJDIR)/kernel/malloc.o: $(KERNELDIR)/kernel/mm/malloc.c
./ProjectTree: ./.stylehlp_sh ./ProjectTree: ./.stylehlp_sh
@cat ./.stylehlp_sh > ./ProjectTree @cat ./.stylehlp_sh > ./ProjectTree
@echo "\n" >> ./ProjectTree @echo "\n" >> ./ProjectTree
@tree >> ./ProjectTree @tree --dirsfirst >> ./ProjectTree
@echo ${CL2}[$@] ${CL}Generated.${CL3} @echo ${CL2}[$@] ${CL}Generated.${CL3}
## MAIN MAKEFILE ------------------------------------------------------------- # ## MAIN MAKEFILE ------------------------------------------------------------- #
.PHONY: test .PHONY: test
test: all test: all
@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 -m 5G -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 64 > loader_disasm64.asm
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm
.PHONY: test32 .PHONY: test32
@ -182,7 +182,7 @@ test32: all
.PHONY: debug .PHONY: debug
debug: all 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 & @qemu-system-x86_64 -m 5G -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 64 > loader_disasm64.asm
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm @ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm

View File

@ -24,9 +24,7 @@
. .
├── AUTHORS
├── boot ├── boot
│   ├── folder.desc
│   ├── grub │   ├── grub
│   │   ├── create_disk.sh │   │   ├── create_disk.sh
│   │   ├── grub.cfg │   │   ├── grub.cfg
@ -34,69 +32,67 @@
│   │   ├── mount.sh │   │   ├── mount.sh
│   │   ├── multiboot.pdf │   │   ├── multiboot.pdf
│   │   └── umount.sh │   │   └── umount.sh
│   └── loader │   ├── loader
│   ├── cpu │   │   ├── cpu
│   │   ├── cpu32.inc │   │   │   ├── cpu32.inc
│   │   └── cpu.inc │   │   │   └── cpu.inc
│   ├── io │   │   ├── io
│   │   └── terminal.inc │   │   │   └── terminal.inc
│   ├── loader.asm │   │   ├── mem
│   ├── mem │   │   │   ├── management.inc
│   │   ├── management.inc │   │   │   └── structures.inc
│   │   └── structures.inc │   │   ├── multiboot
│   └── multiboot │   │   │   ├── check.inc
│   ├── check.inc │   │   │   └── header.inc
│   └── header.inc │   │   └── loader.asm
│   └── folder.desc
├── build ├── build
│   ├── bin │   ├── bin
│   │   ├── disk.img │   │   ├── disk.img
│   │   └── kaleid │   │   └── kaleid
│   ├── kernel.ld │   ├── obj
│   └── obj │   │   ├── boot
│   ├── boot │   │   │   ├── kaleid.x86_64
│   │   ├── kaleid.x86_64 │   │   │   └── loader.o
│   │   └── loader.o │   │   └── kaleid
│   └── kaleid │   │   ├── kernel
│   ├── argv.o │   │   │   ├── init
│   ├── atoi.o │   │   │   │   ├── init.o
│   ├── atol.o │   │   │   │   └── table.o
│   ├── atoul.o │   │   │   ├── io
│   ├── atou.o │   │   │   │   ├── cursor.o
│   ├── ctype.o │   │   │   │   ├── term.o
│   ├── itoa.o │   │   │   │   └── vga.o
│   ├── kernel │   │   │   ├── ke
│   │   ├── cpuid.o │   │   │   │   └── panic.o
│   │   ├── cursor.o │   │   │   ├── cpuid.o
│   │   ├── heap.o
│   │   ├── init
│   │   │   ├── init.o
│   │   │   └── table.o
│   │   ├── init.o
│   │   ├── io
│   │   │   ├── cursor.o │   │   │   ├── cursor.o
│   │   │   ├── heap.o
│   │   │   ├── init.o
│   │   │   ├── malloc.o
│   │   │   ├── map.o
│   │   │   ├── panic.o
│   │   │   ├── table.o
│   │   │   ├── term.o │   │   │   ├── term.o
│   │   │   └── vga.o │   │   │   └── vga.o
│   │   ├── ke │   │   ├── argv.o
│   │   │   └── panic.o │   │   ├── atoi.o
│   │   ├── malloc.o │   │   ├── atol.o
│   │   ├── map.o │   │   ├── atoul.o
│   │   ├── panic.o │   │   ├── atou.o
│   │   ├── table.o │   │   ├── ctype.o
│   │   ├── term.o │   │   ├── itoa.o
│   │   └── vga.o │   │   ├── ltoa.o
│   ├── ltoa.o │   │   ├── mem.o
│   ├── mem.o │   │   ├── prog.o
│   ├── prog.o │   │   ├── rand.o
│   ├── rand.o │   │   ├── sprintf.o
│   ├── sprintf.o │   │   ├── status.o
│   ├── status.o │   │   ├── string.o
│   ├── string.o │   │   ├── strtol.o
│   ├── strtol.o │   │   ├── ultoa.o
│   ├── ultoa.o │   │   └── utoa.o
│   └── utoa.o │   └── kernel.ld
├── ChangeLog
├── COPYING
├── grub.log
├── kaleid ├── kaleid
│   ├── crtlib │   ├── crtlib
│   │   ├── atoi.c │   │   ├── atoi.c
@ -126,20 +122,20 @@
│   │   │   ├── locks.h │   │   │   ├── locks.h
│   │   │   ├── malloc.h │   │   │   ├── malloc.h
│   │   │   └── prog.h │   │   │   └── prog.h
│   │   ├── kernel
│   │   │   ├── base.h
│   │   │   ├── cpu.h
│   │   │   ├── heap.h
│   │   │   ├── iomisc.h
│   │   │   ├── mm.h
│   │   │   ├── multiboot.h
│   │   │   ├── panic.h
│   │   │   ├── proc.h
│   │   │   ├── sched.h
│   │   │   └── term.h
│   │   ├── kalbase.h │   │   ├── kalbase.h
│   │   ├── kaleid.h │   │   ├── kaleid.h
│   │   ├── kalext.h │   │   └── kalext.h
│   │   └── kernel
│   │   ├── base.h
│   │   ├── cpu.h
│   │   ├── heap.h
│   │   ├── iomisc.h
│   │   ├── mm.h
│   │   ├── multiboot.h
│   │   ├── panic.h
│   │   ├── proc.h
│   │   ├── sched.h
│   │   └── term.h
│   └── kernel │   └── kernel
│   ├── cpu │   ├── cpu
│   │   └── cpuid.c │   │   └── cpuid.c
@ -160,6 +156,10 @@
│   └── proc │   └── proc
│   ├── Makefile │   ├── Makefile
│   └── sched.c │   └── sched.c
├── AUTHORS
├── ChangeLog
├── COPYING
├── grub.log
├── loader_disasm32.asm ├── loader_disasm32.asm
├── loader_disasm64.asm ├── loader_disasm64.asm
├── Makefile ├── Makefile

View File

@ -44,6 +44,11 @@ MB_header:
dd MB_HEADER_MAGIC dd MB_HEADER_MAGIC
dd MB_HEADER_FLAGS dd MB_HEADER_FLAGS
dd CHECKSUM dd CHECKSUM
times 5 dd 0x0
dd MB_VIDEO_MODE
dd MB_VIDEO_WIDTH
dd MB_VIDEO_HEIGHT
dd MB_VIDEO_DEPTH
[section .text] [section .text]
@ -71,7 +76,7 @@ Error:
call write32 call write32
pop esi pop esi
jmp Die jmp Die
.ergo : db 219, 219, 219, " Error " .ergo : db 219, 219, 219, " OS/K Loader Error "
.code : db "00" .code : db "00"
db 0x0 db 0x0
; ---------------------------------------------------------------------------- ; ; ---------------------------------------------------------------------------- ;
@ -104,6 +109,12 @@ mbMagic dq 0
lbegin: lbegin:
call clear ; Clear the screen call clear ; Clear the screen
push esi ; Print the logo
mov bl, 0x0E
mov esi, LOGO
call write32
pop esi
;; BEGIN OF CHECKLIST ;; BEGIN OF CHECKLIST
call MB_check ; Check Multiboot State, ERR 01 call MB_check ; Check Multiboot State, ERR 01
@ -115,12 +126,6 @@ lbegin:
call Setup_paging ; Enable paging call Setup_paging ; Enable paging
call Go64 ; Prepare switch into long mode call Go64 ; Prepare switch into long mode
push esi ; Print the logo
mov bl, 0x0E
mov esi, LOGO
call write32
pop esi
;call disable_cursor ;call disable_cursor
lgdt [GDT64.pointer] lgdt [GDT64.pointer]
@ -154,6 +159,7 @@ _loader64:
call write call write
;; Launch the kernel ! ;; Launch the kernel !
;; XXX CHECK THE RAM BEFORE CALLING KERNEL !
call tritemporize ; Let time to see call tritemporize ; Let time to see
mov rdi, [mbInfo] mov rdi, [mbInfo]

View File

@ -27,8 +27,13 @@
MB_AOUT_KLUDGE equ 0 << 16 ; if we are not an ELF executable MB_AOUT_KLUDGE equ 0 << 16 ; if we are not an ELF executable
MB_ALIGN equ 1 << 0 ; Ask to align loaded modules on page boundaries MB_ALIGN equ 1 << 0 ; Ask to align loaded modules on page boundaries
MB_MEMINFO equ 1 << 1 ; Ask to provide memory map MB_MEMINFO equ 1 << 1 ; Ask to provide memory map
MB_VIDEOINFO equ 1 << 2 ; Ask to provide video infos
MB_VIDEO_MODE equ 0x1 ; Text mode
MB_VIDEO_WIDTH equ 80
MB_VIDEO_HEIGHT equ 24
MB_VIDEO_DEPTH equ 0x0
MB_HEADER_MAGIC equ 0x1badb002 MB_HEADER_MAGIC equ 0x1badb002
MB_GRUB_MAGIC equ 0x2badb002 MB_GRUB_MAGIC equ 0x2badb002
MB_HEADER_FLAGS equ MB_AOUT_KLUDGE|MB_ALIGN|MB_MEMINFO MB_HEADER_FLAGS equ MB_AOUT_KLUDGE|MB_ALIGN|MB_MEMINFO|MB_VIDEOINFO
CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS) CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS)
KERNEL_STACK equ 0x00200000 ; Stack starts at the 2mb address & grows down KERNEL_STACK equ 0x00200000 ; Stack starts at the 2mb address & grows down

View File

@ -77,23 +77,13 @@ noreturn void __assert_handler(const char *, const char *, int, const char *);
// When debugging // // When debugging //
//------------------------------------------// //------------------------------------------//
#if !defined(_NO_DEBUG) && !defined(NDEBUG) && !defined(KalAssert) #if /*!defined(_NO_DEBUG) && !defined(NDEBUG) &&*/ !defined(KalAssert)
// //
// Check whether (x) holds, if not call __assert_handler // Check whether (x) holds, if not call __assert_handler
// //
#define KalAssert KalAlwaysAssert #define KalAssert KalAlwaysAssert
#ifndef _OSK_SOURCE
// When not building for OS/K, use the system's assert
#include <assert.h>
#undef KalAlwaysAssert
#define KalAlwaysAssert assert
#endif
//------------------------------------------// //------------------------------------------//
// When not debugging // // When not debugging //
//------------------------------------------// //------------------------------------------//

View File

@ -51,7 +51,7 @@ enum LockType_t
// Mutex-type lock // Mutex-type lock
// //
// WARNING // WARNING
// AquireLock() panics when used on a mutex while not running a process // AcquireLock() panics when used on a mutex while not running a process
KLOCK_MUTEX, KLOCK_MUTEX,
// Spinlock-type lock // Spinlock-type lock
@ -121,18 +121,18 @@ void DestroyLock(Lock_t *lock)
} }
// //
// Aquire the lock // Acquire the lock
// Panic on double aquisition since that should never happen // Panic on double acquisition since that should never happen
// until we have at least a basic scheduler // until we have at least a basic scheduler
// //
static inline static inline
void AquireLock(Lock_t *lock) void AcquireLock(Lock_t *lock)
{ {
KalAssert(lock->initDone == INITOK); KalAssert(lock->initDone == INITOK);
while (!__sync_bool_compare_and_swap(&lock->locked, 0, 1)) { while (!__sync_bool_compare_and_swap(&lock->locked, 0, 1)) {
#ifdef _KALEID_KERNEL #ifdef _KALEID_KERNEL
StartPanic("AquireLock on an already locked object"); StartPanic("AcquireLock on an already locked object");
#else #else
if likely (lock->type == KLOCK_SPINLOCK) continue; if likely (lock->type == KLOCK_SPINLOCK) continue;
#ifdef _OSK_SOURCE #ifdef _OSK_SOURCE
@ -146,8 +146,8 @@ void AquireLock(Lock_t *lock)
} }
// //
// Release an already aquired lock // Release an already acquired lock
// Panic if the lock was never aquired // Panic if the lock was never acquired
// //
static inline static inline
void ReleaseLock(Lock_t *lock) void ReleaseLock(Lock_t *lock)
@ -161,7 +161,7 @@ void ReleaseLock(Lock_t *lock)
} }
// //
// Tries to aquire lock // Tries to acquire lock
// //
static inline static inline
bool AttemptLock(Lock_t *lock) bool AttemptLock(Lock_t *lock)

View File

@ -61,7 +61,6 @@ typedef enum TermColor_t TermColor_t;
// Get Process_t structure of current CPU // Get Process_t structure of current CPU
#define GetCurCPU() (cpuTable[_GetCurCPU()]) #define GetCurCPU() (cpuTable[_GetCurCPU()])
#define PANICSTR_SIZE 1024
//Get the BootInfo_t structure //Get the BootInfo_t structure
#define GetBootInfo(x) bootTab.x #define GetBootInfo(x) bootTab.x
@ -75,9 +74,6 @@ struct Processor_t
// CPU number, index in CPU list // CPU number, index in CPU list
int index; int index;
// Panic string
char panicStr[PANICSTR_SIZE];
// Number of ticks since boot time // Number of ticks since boot time
ulong ticks; ulong ticks;
@ -106,15 +102,18 @@ struct BootInfo_t
{ {
// The Bootloader infos (GRUB in our case) // The Bootloader infos (GRUB in our case)
struct { struct {
ushort valid;
uint grubFlags; //flags uint grubFlags; //flags
uint modulesCount; //mods_count uint modulesCount; //mods_count
void *modulesAddr; //mods_addr void *modulesAddr; //mods_addr
uint grubName; //boot_loader_name char *grubName; //boot_loader_name
void *mbHeaderAddr; void *mbHeaderAddr;
} btldr; } btldr;
// Informations about drives // Informations about drives
struct { struct {
ushort drvValid;
ushort bufferValid;
uint bootDrv; //boot_device uint bootDrv; //boot_device
uint bufferLength; //drives_length uint bufferLength; //drives_length
void *bufferAddr; //drives_addr void *bufferAddr; //drives_addr
@ -122,6 +121,9 @@ struct BootInfo_t
// Informations about memory // Informations about memory
struct { struct {
ushort memValid;
ushort mapValid;
//BIOS provided low and up memory //BIOS provided low and up memory
uint lowMemory; //mem_lower uint lowMemory; //mem_lower
uint upMemory; //mem_upper uint upMemory; //mem_upper
@ -129,10 +131,13 @@ struct BootInfo_t
//GRUB provided memory map //GRUB provided memory map
uint mapLength; //mmap_length uint mapLength; //mmap_length
void *mapAddr; //mmap_addr void *mapAddr; //mmap_addr
uint ramSize; //The ram (init by map.c)
} memory; } memory;
// Informations about the video drive // Informations about the video drive
struct { struct {
ushort valid;
uint vbeControl; //vbe_control_info uint vbeControl; //vbe_control_info
uint vbeModeInfo; //vbe_mode_info uint vbeModeInfo; //vbe_mode_info
ushort vbeMode; //vbe_mode ushort vbeMode; //vbe_mode
@ -149,6 +154,8 @@ struct BootInfo_t
// Informations about the microcode firmware (BIOS/EFI) // Informations about the microcode firmware (BIOS/EFI)
struct { struct {
ushort apmValid;
ushort romValid;
uint apmTable; //apm_table uint apmTable; //apm_table
uint romTable; //config_table uint romTable; //config_table
} firmware; } firmware;

View File

@ -25,6 +25,8 @@
#include <kernel/multiboot.h> #include <kernel/multiboot.h>
#include <kernel/base.h> #include <kernel/base.h>
#define MINIMUM_RAM_SIZE 16 //Mio, the minimum RAM size.
// //
// Returns a pointer to the first entry of the memory map // Returns a pointer to the first entry of the memory map
// //

View File

@ -31,9 +31,8 @@
//------------------------------------------// //------------------------------------------//
// Can't use the macro because panicStr is an array #define PANICSTR_SIZE 1024
static inline char *GetPanicStr(void) extern volatile char PanicStr[PANICSTR_SIZE];
{ return GetCurCPU().panicStr; }
//------------------------------------------// //------------------------------------------//

View File

@ -80,46 +80,35 @@ struct Terminal_t
TermColor_t bgColor; TermColor_t bgColor;
// Defined in driver // Defined in driver
error_t (*ClearTermUnlocked)(Terminal_t *); error_t (*clear)(Terminal_t *);
error_t (*PutOnTermUnlocked)(Terminal_t *, char); error_t (*putchar)(Terminal_t *, char);
error_t (*PrintOnTermUnlocked)(Terminal_t *, const char *);
}; };
//------------------------------------------// //------------------------------------------//
void InitTerms(void); void InitTerms(void);
error_t ClearTerm(Terminal_t *); error_t ClearTerm(Terminal_t *);
error_t PutOnTerm(Terminal_t *, char);
error_t PrintOnTerm(Terminal_t *, const char *);
error_t ChTermColor(Terminal_t *, TermColor_t, TermColor_t); error_t ChTermColor(Terminal_t *, TermColor_t, TermColor_t);
error_t PutOnTerm(Terminal_t *, char);
error_t PutOnTermUnlocked(Terminal_t *, char);
error_t PrintOnTerm(Terminal_t *, const char *);
error_t PrintOnTermUnlocked(Terminal_t *, const char *);
error_t KernLog(const char *, ...); error_t KernLog(const char *, ...);
//------------------------------------------// //------------------------------------------//
extern Terminal_t *stdOut; extern Terminal_t *StdOut;
#define GetStdOut() (stdOut) extern Terminal_t *StdDbg;
#define SetStdOut(x) (stdOut = (x))
// Debug purposes
volatile ushort *vga;
//------------------------------------------// //------------------------------------------//
#ifndef _NO_DEBUG #ifndef _NO_DEBUG
extern Terminal_t *stdDbg;
#define GetStdDbg() (stdDbg)
#define SetStdDbg(x) (stdDbg = (x))
error_t DebugLog(const char *, ...); error_t DebugLog(const char *, ...);
#else // _NO_DEBUG #else // _NO_DEBUG
#define GetStdDbg() NULL
#define SetStdDbg(x) ((void)0)
#define DebugLog(fmt, ...) EOK #define DebugLog(fmt, ...) EOK
#endif #endif
//------------------------------------------// //------------------------------------------//

View File

@ -22,56 +22,87 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/multiboot.h>
#include <kernel/term.h> #include <kernel/term.h>
#include <kernel/panic.h> #include <kernel/panic.h>
#include <kernel/mm.h> #include <kernel/mm.h>
// //
// BootInfo_t initialization. It is necessary because grub will potentially be // BootInfo_t initialization. It is necessary because grub will potentially be
// wiped since it is below 1MB.... // wiped since it is below 1MB.... And we must reorganize all that stuff.
// //
void InitBootInfo(multiboot_info_t *mbi) void InitBootInfo(multiboot_info_t *mbi)
{ {
KalAssert(mbi);
extern uint MB_header; extern uint MB_header;
char *okStr = "available";
char *noStr = "unavailable";
//Retrieves the bootloader informations // We need the multiboot structure
KalAlwaysAssert(mbi);
//Retrieves the bootloader flags to ensure infos are valid
GetBootInfo(btldr).grubFlags = mbi->flags; GetBootInfo(btldr).grubFlags = mbi->flags;
GetBootInfo(btldr).grubName = (mbi->boot_loader_name);
if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
GetBootInfo(btldr).grubName = (char*)(ullong)(mbi->boot_loader_name);
GetBootInfo(btldr).mbHeaderAddr = (void*)(ullong)&MB_header;
GetBootInfo(btldr).valid = 1;
}
if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MODS) {
GetBootInfo(btldr).modulesCount = mbi->mods_count; GetBootInfo(btldr).modulesCount = mbi->mods_count;
GetBootInfo(btldr).modulesAddr = (void*)(ullong)mbi->mods_addr; GetBootInfo(btldr).modulesAddr = (void*)(ullong)mbi->mods_addr;
GetBootInfo(btldr).mbHeaderAddr = (void*)(ullong)&MB_header; }
DebugLog("\n[InitBootInfo] %s\n", GetBootInfo(btldr).grubName);
DebugLog("[InitBootInfo] Header address : %p, modules address : %p\n",
GetBootInfo(btldr).mbHeaderAddr, GetBootInfo(btldr).modulesAddr);
DebugLog("[InitBootInfo] GRUB flags : %x\n", GetBootInfo(btldr).grubFlags);
//Retrieves the drives informations //Retrieves the drives informations
GetBootInfo(drives).bootDrv = mbi->boot_device; if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_DRIVE_INFO) {
GetBootInfo(drives).bufferLength = mbi->drives_length; GetBootInfo(drives).bufferLength = mbi->drives_length;
GetBootInfo(drives).bufferAddr = (void*)(ullong)mbi->drives_addr; GetBootInfo(drives).bufferAddr = (void*)(ullong)mbi->drives_addr;
DebugLog("[InitBootInfo] Root drive : %x\n", GetBootInfo(drives).bufferValid = 1;
GetBootInfo(drives).bootDrv); }
if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOTDEV) {
GetBootInfo(drives).bootDrv = mbi->boot_device;
GetBootInfo(drives).drvValid = 1;
}
//Retrieves the memory informations //Retrieves the memory informations
if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEMORY) {
GetBootInfo(memory).lowMemory = mbi->mem_lower; GetBootInfo(memory).lowMemory = mbi->mem_lower;
GetBootInfo(memory).upMemory = mbi->mem_upper; GetBootInfo(memory).upMemory = mbi->mem_upper;
GetBootInfo(memory).memValid = 1;
}
if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP) {
GetBootInfo(memory).mapAddr = (void*)(ullong)mbi->mmap_addr; GetBootInfo(memory).mapAddr = (void*)(ullong)mbi->mmap_addr;
GetBootInfo(memory).mapLength = mbi->mmap_length; GetBootInfo(memory).mapLength = mbi->mmap_length;
DebugLog("[InitBootInfo] Low memory : %d Kio, Up memory : %d Mio\n", GetBootInfo(memory).mapValid = 1;
GetBootInfo(memory).lowMemory, GetBootInfo(memory).upMemory / (MB/KB)); }
DebugLog("[InitBootInfo] Memory map address : %p, length : %d\n",
GetBootInfo(memory).mapAddr, GetBootInfo(memory).mapLength);
// XXX assign video infos, but unused at this time // XXX assign video infos, but unused at this time
// Retrieves the firmware infos // Retrieves the firmware infos
GetBootInfo(firmware).apmTable = mbi->apm_table; if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) {
GetBootInfo(firmware).romTable = mbi->config_table; GetBootInfo(firmware).romTable = mbi->config_table;
DebugLog("[InitBootInfo] APM Table : %p, ROM Table : %p\n", GetBootInfo(firmware).romValid = 1;
GetBootInfo(firmware).apmTable, GetBootInfo(firmware).romTable); }
if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_APM_TABLE) {
GetBootInfo(firmware).apmTable = mbi->apm_table;
GetBootInfo(firmware).apmValid = 1;
}
//Now we check (debug)
/*DebugLog("[InitBootInfo] Flags : %b\n\n",
GetBootInfo(btldr).grubFlags);*/
DebugLog("[InitBootInfo] Boot loader %s\n",
GetBootInfo(btldr).valid ? okStr : noStr);
DebugLog("[InitBootInfo] Boot drive %s\n",
GetBootInfo(drives).drvValid ? okStr : noStr);
DebugLog("[InitBootInfo] Disk buffer %s\n",
GetBootInfo(drives).bufferValid ? okStr : noStr);
DebugLog("[InitBootInfo] Basic mem %s\n",
GetBootInfo(memory).memValid ? okStr : noStr);
DebugLog("[InitBootInfo] Memory map %s\n",
GetBootInfo(memory).mapValid ? okStr : noStr);
DebugLog("[InitBootInfo] ROM table %s\n",
GetBootInfo(firmware).romValid ? okStr : noStr);
DebugLog("[InitBootInfo] APM table %s\n\n",
GetBootInfo(firmware).apmValid ? okStr : noStr);
} }
@ -90,13 +121,15 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic)
KernLog("%c%c%c OS/K\n\n", 219, 219, 219); KernLog("%c%c%c OS/K\n\n", 219, 219, 219);
KalAlwaysAssert(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC); KalAlwaysAssert(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC);
KernLog("[Init] We have magic : %x\n", mbMagic); KernLog("[Init] We have magic : %x\n\n", mbMagic);
//Initialize the BootInfo_t structure //Initialize the BootInfo_t structure
InitBootInfo(mbInfo); InitBootInfo(mbInfo);
//Memory mapping //Memory mapping
InitMemoryMap(); error_t mapBad = InitMemoryMap();
if (mapBad)
StartPanic("[Init] The memory map failed to initialize. Error : %d", mapBad);
// We're out // We're out
KernLog("\n[Init] Evil never dies !"); KernLog("\n[Init] Evil never dies !");

View File

@ -28,5 +28,7 @@ int cpuCount = 1;
Processor_t cpuTable[NCPUS] = {0}; Processor_t cpuTable[NCPUS] = {0};
BootInfo_t bootTab = {0}; BootInfo_t bootTab = {0};
Terminal_t *StdOut = 0, *StdDbg = 0;
volatile char PanicStr[PANICSTR_SIZE] = {0};
Terminal_t *stdOut = 0, *stdDbg = 0;

View File

@ -32,14 +32,14 @@ extern Terminal_t VGA_Terminal;
// //
void InitTerms(void) void InitTerms(void)
{ {
KalAssert(!GetStdOut() && !GetStdDbg()); KalAssert(!StdOut && !StdDbg);
VGA_Init(); VGA_Init();
SetStdDbg(&VGA_Terminal); StdDbg = &VGA_Terminal;
SetStdOut(&VGA_Terminal); StdOut = &VGA_Terminal;
ClearTerm(GetStdOut()); ClearTerm(StdOut);
} }
// //
@ -52,8 +52,8 @@ error_t ClearTerm(Terminal_t *term)
if (term == NULL) return EINVAL; if (term == NULL) return EINVAL;
KalAssert(term->initDone == INITOK); KalAssert(term->initDone == INITOK);
AquireLock(&term->lock); AcquireLock(&term->lock);
retcode = term->ClearTermUnlocked(term); retcode = term->clear(term);
ReleaseLock(&term->lock); ReleaseLock(&term->lock);
return retcode; return retcode;
@ -70,7 +70,7 @@ error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor)
if (term == NULL) if (term == NULL)
return EINVAL; return EINVAL;
AquireLock(&term->lock); AcquireLock(&term->lock);
term->fgColor = fgColor; term->fgColor = fgColor;
term->bgColor = bgColor; term->bgColor = bgColor;
@ -81,39 +81,99 @@ error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor)
} }
// //
// Writes a single character on the terminal // Writes a single character on the terminal (UNLOCKED version)
//
error_t PutOnTermUnlocked(Terminal_t *term, char ch)
{
uint i;
size_t prevY;
error_t rc = EOK;
if (ch == '\r') {
term->currentX = 0;
return EOK;
}
// 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->currentX = term->width - 1;
}
// Tabulations account for "term->tabSize" spaces
else if (ch == '\t') {
prevY = term->currentX;
for (i = 0; i < term->tabSize; i++) {
// Make sure tabulations can't spread over two lines
if (term->currentX == prevY) {
rc = term->putchar(term, ' ');
if (rc) return rc;
}
}
}
else rc = term->putchar(term, ch);
// Did we reach the end of line?
if (!rc && ++term->currentX == term->width) {
term->currentX = 0;
// Did we reach the buffer's end?
if (++term->currentY == term->height) {
term->currentY = 0;
}
}
return rc;
}
//
// Writes a single character on the terminal (LOCKED version)
// //
error_t PutOnTerm(Terminal_t *term, char ch) error_t PutOnTerm(Terminal_t *term, char ch)
{ {
error_t retcode; error_t rc;
if (term == NULL) return EINVAL; if (term == NULL) return EINVAL;
KalAssert(term->initDone == INITOK); KalAssert(term->initDone == INITOK);
AquireLock(&term->lock); AcquireLock(&term->lock);
retcode = term->PutOnTermUnlocked(term, ch); rc = PutOnTermUnlocked(term, ch);
ReleaseLock(&term->lock); ReleaseLock(&term->lock);
return retcode; return rc;
} }
// //
// Prints string on terminal // Prints string on terminal (UNLOCKED version)
//
error_t PrintOnTermUnlocked(Terminal_t *term, const char *str)
{
error_t rc = EOK;
while (*str && rc == EOK) {
rc = PutOnTermUnlocked(term, *str++);
}
return rc;
}
//
// Prints string on terminal (LOCKED version)
// //
error_t PrintOnTerm(Terminal_t *term, const char *str) error_t PrintOnTerm(Terminal_t *term, const char *str)
{ {
error_t retcode = EOK; error_t rc = EOK;
if (term == NULL) return EINVAL; if (term == NULL) return EINVAL;
KalAssert(term->initDone == INITOK); KalAssert(term->initDone == INITOK);
AquireLock(&term->lock); AcquireLock(&term->lock);
while (*str && retcode == EOK) { rc = PrintOnTermUnlocked(term, str);
retcode = term->PutOnTermUnlocked(term, *str++);
}
ReleaseLock(&term->lock); ReleaseLock(&term->lock);
return retcode; return rc;
} }
// //
@ -130,7 +190,7 @@ error_t KernLog(const char *fmt, ...)
vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap); vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap);
va_end(ap); va_end(ap);
return PrintOnTerm(GetStdOut(), logbuf); return PrintOnTerm(StdOut, logbuf);
} }
#ifndef _NO_DEBUG #ifndef _NO_DEBUG
@ -148,7 +208,7 @@ error_t DebugLog(const char *fmt, ...)
vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap); vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap);
va_end(ap); va_end(ap);
return PrintOnTerm(GetStdDbg(), logbuf); return PrintOnTerm(StdDbg, logbuf);
} }
#endif #endif

View File

@ -59,69 +59,15 @@ error_t VGA_ClearTermUnlocked(Terminal_t *term)
// //
error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch) error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch)
{ {
uint i;
size_t prevY;
if (ch == '\r') {
term->currentX = 0;
return EOK;
}
// 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->currentX = term->width - 1;
}
// Tabulations account for "term->tabSize" spaces
else if (ch == '\t') {
prevY = term->currentX;
for (i = 0; i < term->tabSize; i++) {
// Make sure tabulations can't spread over two lines
if (term->currentX == prevY) {
VGA_PutOnTermUnlocked(term, ' ');
}
}
}
else {
ushort *buffer = (ushort *)term->data; ushort *buffer = (ushort *)term->data;
const size_t offset = VGA_ComputeOffset(term, term->currentX, term->currentY); const size_t offset = VGA_ComputeOffset(term, term->currentX, term->currentY);
buffer[offset] = VGA_ComputeEntry(ch, VGA_ComputeColorCode(term->fgColor, term->bgColor)); buffer[offset] = VGA_ComputeEntry(ch, VGA_ComputeColorCode(term->fgColor, term->bgColor));
}
// Did we reach the end of line?
if (++term->currentX == term->width) {
term->currentX = 0;
// Did we reach the buffer's end?
if (++term->currentY == term->height) {
// XXX scroll up
term->currentY = 0;
}
}
// Nothing can go wrong
return EOK; return EOK;
} }
//
// Prints string on terminal
//
error_t VGA_PrintOnTermUnlocked(Terminal_t *term, const char *str)
{
error_t retcode = EOK;
while (*str && retcode == EOK) {
retcode = term->PutOnTermUnlocked(term, *str++);
}
return retcode;
}
// //
// VGA output // VGA output
// XXX custom sizes
// //
Terminal_t VGA_Terminal = { Terminal_t VGA_Terminal = {
.initDone = FALSE, .initDone = FALSE,
@ -140,9 +86,8 @@ Terminal_t VGA_Terminal = {
.fgColor = KTERM_COLOR_LGREY, .fgColor = KTERM_COLOR_LGREY,
.bgColor = KTERM_COLOR_BLACK, .bgColor = KTERM_COLOR_BLACK,
.ClearTermUnlocked = VGA_ClearTermUnlocked, .clear = VGA_ClearTermUnlocked,
.PutOnTermUnlocked = VGA_PutOnTermUnlocked, .putchar = VGA_PutOnTermUnlocked,
.PrintOnTermUnlocked = VGA_PrintOnTermUnlocked,
}; };

View File

@ -37,8 +37,8 @@ noreturn void __assert_handler(const char *msg,
(void)file; (void)line; (void)func; (void)file; (void)line; (void)func;
StartPanic("cpu%d: In function '%s', from %s line %d - assert() failed: '%s'", StartPanic("In function '%s', from %s line %d - assertion failed: '%s'",
_GetCurCPU(), func, file, line, msg); func, file, line, msg);
} }
// //
@ -52,25 +52,23 @@ noreturn void StartPanic(const char *fmt, ...)
DisableIRQs(); DisableIRQs();
if (GetCurProc()) _SetCurProc(NULL); if (GetCurProc()) _SetCurProc(NULL);
if (GetStdOut() == NULL) CrashSystem(); if (StdOut == NULL) CrashSystem();
GetStdOut()->ClearTermUnlocked(GetStdOut());
if (fmt == NULL) { if (fmt == NULL) {
fmt = "(no message given)"; fmt = "(no message given)";
} }
if (*GetPanicStr()) { if (PanicStr[0] != 0) {
GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "\nDouble panic!"); PrintOnTermUnlocked(StdOut, "\nDouble panic!");
HaltCPU(); HaltCPU();
} }
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(GetPanicStr(), PANICSTR_SIZE, fmt, ap); vsnprintf((char *)PanicStr, PANICSTR_SIZE, fmt, ap);
va_end(ap); va_end(ap);
GetStdOut()->PrintOnTermUnlocked(GetStdOut(), "\nPanic!\n\n"); PrintOnTermUnlocked(StdOut, "\nPanic!\n\n");
GetStdOut()->PrintOnTermUnlocked(GetStdOut(), GetPanicStr()); PrintOnTermUnlocked(StdOut, (char *)PanicStr);
HaltCPU(); HaltCPU();
} }

View File

@ -47,11 +47,11 @@ void InitHeap(void)
} }
// //
// Aquires control of the heap's lock // Acquires control of the heap's lock
// //
void LockHeap(void) void LockHeap(void)
{ {
AquireLock(&_heap_lock); AcquireLock(&_heap_lock);
} }
// //

View File

@ -46,7 +46,7 @@ error_t KalAllocMemory(void **ptr, size_t req, int flags, size_t align)
UnlockHeap(); UnlockHeap();
if (rc) { if (rc) {
if ((flags & M_CANFAIL) == 0) if ((flags & M_CANFAIL) != 0)
return rc; return rc;
StartPanic("Out of memory"); StartPanic("Out of memory");
} }
@ -66,6 +66,6 @@ error_t KalAllocMemory(void **ptr, size_t req, int flags, size_t align)
error_t KalFreeMemory(void *ptr) error_t KalFreeMemory(void *ptr)
{ {
(void)ptr; (void)ptr;
return 0; return EOK;
} }

View File

@ -27,8 +27,16 @@
error_t InitMemoryMap(void) error_t InitMemoryMap(void)
{ {
///uint MapIsValid = (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP = MULTIBOOT_INFO_MEM_MAP ? 1 : 0); if (!GetBootInfo(memory).memValid && GetBootInfo(memory).mapValid)
KalAlwaysAssert(MapIsValid); return ENXIO;
DebugLog("[InitMemoryMap] Memory map address : %p, length : %d\n",
GetBootInfo(memory).mapAddr, GetBootInfo(memory).mapLength);
if ((GetBootInfo(memory).upMemory / (MB/KB)) <= MINIMUM_RAM_SIZE) //XXX before loading kernel...
return ENOMEM;
DebugLog("[InitMemoryMap] Low memory : %d Kio, Up memory : %d Mio\n",
GetBootInfo(memory).lowMemory, GetBootInfo(memory).upMemory / (MB/KB));
return EOK; return EOK;
} }