1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

Merge pull request #52 from os-k-team/master

master
This commit is contained in:
Adrien Bourmault 2019-03-23 00:13:09 +01:00 committed by GitHub
commit 45920797c3
32 changed files with 1009 additions and 418 deletions

110
Makefile
View File

@ -32,11 +32,11 @@ CCNAME=x86_64-elf-gcc
ASMFLAGS=-f elf64
LDFLAGS=-melf_x86_64
COPTIM=-O2
CWARNS=-Wall -Wextra # -Werror=implicit-function-declaration
CWARNS=-Wall -Wextra -Werror=implicit-function-declaration
CINCLUDES=-Ikaleid/include
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large # -std=gnu11
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
CFLAGS=$(CFLAGS1) $(CFLAGS2)
KCC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) -D_OSK_SOURCE -D_KALEID_KERNEL
#Folders
@ -61,93 +61,103 @@ all : OS/K
## KALEID MAKEFILE ----------------------------------------------------------- #
# Common objects
kal_com_obj= $(KOBJDIR)/atoi.o $(KOBJDIR)/ctype.o \
$(KOBJDIR)/itoa.o $(KOBJDIR)/memory.o \
$(KOBJDIR)/rand.o $(KOBJDIR)/sprintf.o \
$(KOBJDIR)/status.o $(KOBJDIR)/string.o \
$(KOBJDIR)/strtol.o $(KOBJDIR)/argv.o \
$(KOBJDIR)/prog.o $(KOBJDIR)/atol.o \
$(KOBJDIR)/atou.o $(KOBJDIR)/atoul.o \
$(KOBJDIR)/utoa.o $(KOBJDIR)/ltoa.o \
kal_com_obj= $(KOBJDIR)/atoi.o $(KOBJDIR)/ctype.o \
$(KOBJDIR)/itoa.o $(KOBJDIR)/mem.o \
$(KOBJDIR)/rand.o $(KOBJDIR)/sprintf.o \
$(KOBJDIR)/status.o $(KOBJDIR)/string.o \
$(KOBJDIR)/strtol.o $(KOBJDIR)/argv.o \
$(KOBJDIR)/prog.o $(KOBJDIR)/atol.o \
$(KOBJDIR)/atou.o $(KOBJDIR)/atoul.o \
$(KOBJDIR)/utoa.o $(KOBJDIR)/ltoa.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 $@
@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 $@
@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 $@
@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 $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/ctype.o: $(KERNELDIR)/crtlib/ctype.c
$(KOBJDIR)/ctype.o: $(KERNELDIR)/crtlib/ctype.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@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 $@
@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 $@
@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 $@
@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 $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/memory.o: $(KERNELDIR)/crtlib/memory.c
$(KOBJDIR)/mem.o: $(KERNELDIR)/crtlib/mem.c $(KERNELDIR)/include/*/*.h
@$(KCC) -fno-strict-aliasing $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/rand.o: $(KERNELDIR)/crtlib/rand.c
$(KOBJDIR)/rand.o: $(KERNELDIR)/crtlib/rand.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/sprintf.o: $(KERNELDIR)/crtlib/sprintf.c
$(KOBJDIR)/sprintf.o: $(KERNELDIR)/crtlib/sprintf.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/status.o: $(KERNELDIR)/crtlib/status.c
$(KOBJDIR)/status.o: $(KERNELDIR)/crtlib/status.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/string.o: $(KERNELDIR)/crtlib/string.c
$(KOBJDIR)/string.o: $(KERNELDIR)/crtlib/string.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/strtol.o: $(KERNELDIR)/crtlib/strtol.c
$(KOBJDIR)/strtol.o: $(KERNELDIR)/crtlib/strtol.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/argv.o: $(KERNELDIR)/extras/argv.c
$(KOBJDIR)/argv.o: $(KERNELDIR)/extras/argv.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/prog.o: $(KERNELDIR)/extras/prog.c
$(KOBJDIR)/prog.o: $(KERNELDIR)/extras/prog.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
# Kernel objects
kal_kern_obj= $(KOBJDIR)/kernel/cpuid.o $(KOBJDIR)/kernel/init.o \
$(KOBJDIR)/kernel/table.o $(KOBJDIR)/kernel/cursor.o \
$(KOBJDIR)/kernel/term.o $(KOBJDIR)/kernel/vga.o \
$(KOBJDIR)/kernel/panic.o
kal_kern_obj= $(KOBJDIR)/kernel/cpuid.o $(KOBJDIR)/kernel/init.o \
$(KOBJDIR)/kernel/table.o $(KOBJDIR)/kernel/cursor.o \
$(KOBJDIR)/kernel/term.o $(KOBJDIR)/kernel/vga.o \
$(KOBJDIR)/kernel/panic.o $(KOBJDIR)/kernel/map.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 $@
@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 $@
@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 $@
@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 $@
@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 $@
@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 $@
@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 $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/map.o: $(KERNELDIR)/kernel/mm/map.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/heap.o: $(KERNELDIR)/kernel/mm/heap.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/malloc.o: $(KERNELDIR)/kernel/mm/malloc.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
@ -155,13 +165,13 @@ $(KOBJDIR)/kernel/panic.o: $(KERNELDIR)/kernel/ke/panic.c
./ProjectTree: ./.stylehlp_sh
@cat ./.stylehlp_sh > ./ProjectTree
@echo "\n" >> ./ProjectTree
@tree >> ./ProjectTree
@tree --dirsfirst >> ./ProjectTree
@echo ${CL2}[$@] ${CL}Generated.${CL3}
## 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 &
@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 32 > loader_disasm32.asm
.PHONY: test32
@ -172,7 +182,7 @@ test32: all
.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 &
@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 32 > loader_disasm32.asm
@ -180,19 +190,17 @@ debug: all
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)/umount.sh $(BINDIR)/disk || /bin/true
@$(MBRDIR)/grub-install.sh $(BINDIR)/disk.img $(BINDIR)/disk $(MBRDIR)/grub.cfg
@rmdir $(BINDIR)/disk
@echo ${CL2}[$@] ${CL}Success.${CL3}
.PHONY: clean
clean:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rvf ./ProjectTree
@rm -Rvf $(BINDIR)/*.*
@rm -Rvf $(OBJDIR)/*.o
@rm -Rvf $(OBJDIR)/*/*.o
@rm -Rvf $(OBJDIR)/*/*/*.o
@rm -Rvf $(BINDIR)/* $(OBJDIR)/*.o \
$(OBJDIR)/*/*.o $(OBJDIR)/*/*.x86_64 $(OBJDIR)/*/*/*.o
@echo ${CL2}[[$@]] ${CL}Cleaned.${CL3}
$(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64
@ -209,14 +217,14 @@ $(LOBJDIR)/kaleid.x86_64: $(kal_kern_obj) $(kal_com_obj) $(LOBJDIR)/loader.o
-o $(LOBJDIR)/kaleid.x86_64
@echo ${CL2}[$@] ${CL}Success.${CL3}
$(LOBJDIR)/loader.o: $(LOADERDIR)/loader.asm
$(LOBJDIR)/loader.o: $(LOADERDIR)/loader.asm $(LOADERDIR)/*/*.inc
@echo ${CL2}[$@] ${NC}Making loader...${CL3}
@$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(LOBJDIR)/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)/umount.sh $(BINDIR)/disk || /bin/true
@$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img
@make install_mbr
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
@ -225,7 +233,7 @@ $(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh
OS/K: $(BINDIR)/kaleid $(BINDIR)/disk.img ./ProjectTree
@mkdir -p $(BINDIR)/disk
@echo ${CL2}[[$@]] ${NC}Integrating kernel...${CL3}
-@$(MBRDIR)/umount.sh $(BINDIR)/disk
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk
@cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid
@$(MBRDIR)/umount.sh $(BINDIR)/disk

View File

@ -24,9 +24,7 @@
.
├── AUTHORS
├── boot
│   ├── folder.desc
│   ├── grub
│   │   ├── create_disk.sh
│   │   ├── grub.cfg
@ -34,72 +32,73 @@
│   │   ├── mount.sh
│   │   ├── multiboot.pdf
│   │   └── umount.sh
│   └── loader
│   ├── cpu
│   │   ├── cpu32.inc
│   │   └── cpu.inc
│   ├── io
│   │   └── terminal.inc
│   ├── loader.asm
│   ├── mem
│   │   ├── management.inc
│   │   └── structures.inc
│   └── multiboot
│   ├── check.inc
│   └── header.inc
│   ├── loader
│   │   ├── cpu
│   │   │   ├── cpu32.inc
│   │   │   └── cpu.inc
│   │   ├── io
│   │   │   └── terminal.inc
│   │   ├── mem
│   │   │   ├── management.inc
│   │   │   └── structures.inc
│   │   ├── multiboot
│   │   │   ├── check.inc
│   │   │   └── header.inc
│   │   └── loader.asm
│   └── folder.desc
├── build
│   ├── bin
│   │   ├── disk.img
│   │   └── kaleid
│   ├── kernel.ld
│   └── obj
│   ├── boot
│   │   ├── kaleid.x86_64
│   │   └── loader.o
│   └── kaleid
│   ├── argv.o
│   ├── atoi.o
│   ├── atol.o
│   ├── atoul.o
│   ├── atou.o
│   ├── ctype.o
│   ├── itoa.o
│   ├── kernel
│   │   ├── cpuid.o
│   │   ├── cursor.o
│   │   ├── init
│   │   │   ├── init.o
│   │   │   └── table.o
│   │   ├── init.o
│   │   ├── io
│   │   │   ├── cursor.o
│   │   │   ├── term.o
│   │   │   └── vga.o
│   │   ├── ke
│   │   │   └── panic.o
│   │   ├── panic.o
│   │   ├── table.o
│   │   ├── term.o
│   │   └── vga.o
│   ├── ltoa.o
│   ├── memory.o
│   ├── prog.o
│   ├── rand.o
│   ├── sprintf.o
│   ├── status.o
│   ├── string.o
│   ├── strtol.o
│   ├── ultoa.o
│   └── utoa.o
├── ChangeLog
├── COPYING
├── grub.log
│   ├── obj
│   │   ├── boot
│   │   │   ├── kaleid.x86_64
│   │   │   └── loader.o
│   │   └── kaleid
│   │   ├── kernel
│   │   │   ├── init
│   │   │   │   ├── init.o
│   │   │   │   └── table.o
│   │   │   ├── io
│   │   │   │   ├── cursor.o
│   │   │   │   ├── term.o
│   │   │   │   └── vga.o
│   │   │   ├── ke
│   │   │   │   └── panic.o
│   │   │   ├── cpuid.o
│   │   │   ├── cursor.o
│   │   │   ├── heap.o
│   │   │   ├── init.o
│   │   │   ├── malloc.o
│   │   │   ├── map.o
│   │   │   ├── panic.o
│   │   │   ├── table.o
│   │   │   ├── term.o
│   │   │   └── vga.o
│   │   ├── argv.o
│   │   ├── atoi.o
│   │   ├── atol.o
│   │   ├── atoul.o
│   │   ├── atou.o
│   │   ├── ctype.o
│   │   ├── itoa.o
│   │   ├── ltoa.o
│   │   ├── mem.o
│   │   ├── prog.o
│   │   ├── rand.o
│   │   ├── sprintf.o
│   │   ├── status.o
│   │   ├── string.o
│   │   ├── strtol.o
│   │   ├── ultoa.o
│   │   └── utoa.o
│   └── kernel.ld
├── kaleid
│   ├── crtlib
│   │   ├── atoi.c
│   │   ├── ctype.c
│   │   ├── itoa.c
│   │   ├── memory.c
│   │   ├── mem.c
│   │   ├── rand.c
│   │   ├── sprintf.c
│   │   ├── status.c
@ -123,20 +122,20 @@
│   │   │   ├── locks.h
│   │   │   ├── malloc.h
│   │   │   └── prog.h
│   │   ├── kalbase.h
│   │   ├── kaleid.h
│   │   ├── kalext.h
│   │   ├── kernel
│   │   │   ├── base.h
│   │   │   ├── cpu.h
│   │   │   ├── heap.h
│   │   │   ├── iomisc.h
│   │   │   ├── mm.h
│   │   │   ├── multiboot.h
│   │   │   ├── panic.h
│   │   │   ├── proc.h
│   │   │   ├── sched.h
│   │   │   └── term.h
│   │   └── multiboot
│   │   └── multiboot.h
│   │   ├── kalbase.h
│   │   ├── kaleid.h
│   │   └── kalext.h
│   └── kernel
│   ├── cpu
│   │   └── cpuid.c
@ -151,9 +150,16 @@
│   ├── ke
│   │   └── panic.c
│   ├── mm
│   │   ├── heap.c
│   │   ├── malloc.c
│   │   └── map.c
│   └── proc
│   ├── Makefile
│   └── sched.c
├── AUTHORS
├── ChangeLog
├── COPYING
├── grub.log
├── loader_disasm32.asm
├── loader_disasm64.asm
├── Makefile
@ -161,4 +167,4 @@
├── qemu.log
└── Readme.md
31 directories, 105 files
30 directories, 112 files

Binary file not shown.

View File

@ -28,7 +28,6 @@
;;VIDEO
%define TRAM 0xB8000 ; [T]ext[RAM]
%define VRAM 0xA0000 ; [V]ideo[RAM]
%define VGA_HEIGHT 80
;; GLOBAL DATA
@ -38,19 +37,6 @@ VGA_X32 dq 0
VGA_HEIGHT64 dq VGA_HEIGHT
VGA_X dq 0
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 ;
;-----------------------------------------------------------------------;

View File

@ -32,6 +32,7 @@
%include "boot/loader/mem/structures.inc"
global MB_start
global MB_header
extern StartKern
[BITS 32]
@ -43,6 +44,11 @@ MB_header:
dd MB_HEADER_MAGIC
dd MB_HEADER_FLAGS
dd CHECKSUM
times 5 dd 0x0
dd MB_VIDEO_MODE
dd MB_VIDEO_WIDTH
dd MB_VIDEO_HEIGHT
dd MB_VIDEO_DEPTH
[section .text]
@ -70,7 +76,7 @@ Error:
call write32
pop esi
jmp Die
.ergo : db 219, 219, 219, " Error "
.ergo : db 219, 219, 219, " OS/K Loader Error "
.code : db "00"
db 0x0
; ---------------------------------------------------------------------------- ;
@ -103,6 +109,12 @@ mbMagic dq 0
lbegin:
call clear ; Clear the screen
push esi ; Print the logo
mov bl, 0x0E
mov esi, LOGO
call write32
pop esi
;; BEGIN OF CHECKLIST
call MB_check ; Check Multiboot State, ERR 01
@ -114,12 +126,6 @@ lbegin:
call Setup_paging ; Enable paging
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
lgdt [GDT64.pointer]
@ -153,6 +159,7 @@ _loader64:
call write
;; Launch the kernel !
;; XXX CHECK THE RAM BEFORE CALLING KERNEL !
call tritemporize ; Let time to see
mov rdi, [mbInfo]

View File

@ -27,8 +27,13 @@
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_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_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)
KERNEL_STACK equ 0x00200000 ; Stack starts at the 2mb address & grows down

View File

@ -23,9 +23,31 @@
//----------------------------------------------------------------------------//
#include <kalbase.h>
#include <extras/malloc.h>
/* DO NOT compile with strict aliasing on */
//------------------------------------------//
// Memory allocation //
//------------------------------------------//
void *malloc(size_t n)
{
void *ptr;
error_t rc;
rc = KalAllocMemory(&ptr, n, 0, 0);
__set_errno(rc);
return ptr;
}
void free(void *ptr)
{
error_t rc = KalFreeMemory(ptr);
(void)rc;
}
//------------------------------------------//
// memset() family //
//------------------------------------------//

View File

@ -47,17 +47,15 @@ const char *KalGetProgVersion(void)
return __progvers;
}
bool KalSetProgVers(const char *vers)
error_t KalSetProgVers(const char *vers)
{
(void)vers;
__set_errno(ENOSYS);
return false;
return ENOSYS;
}
bool KalSetProgName(const char *name)
error_t KalSetProgName(const char *name)
{
(void)name;
__set_errno(ENOSYS);
return false;
return ENOSYS;
}

View File

@ -77,23 +77,13 @@ noreturn void __assert_handler(const char *, const char *, int, const char *);
// 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
//
#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 //
//------------------------------------------//

View File

@ -45,6 +45,19 @@
//------------------------------------------//
#ifndef _NO_UNITS
#define KB (1UL << 10)
#define MB (1UL << 20)
#define GB (1UL << 30)
#define TB (1UL << 40)
#endif
#ifndef _ALIGN_UP
#define _ALIGN_UP(x, s) (((x) + (s) - 1) & (~((s) - 1)))
#endif
//------------------------------------------//
#ifndef __BEGIN_DECLS
#ifdef __cpluplus
# define __EXTERN_C extern "C"

View File

@ -66,7 +66,7 @@ extern error_t __errno;
#define errno __errno
#endif
#define __get_errno(x) error_t x = errno;
#define __get_errno(x) error_t x = errno
#define __set_errno(x) (errno = (x))
#else
@ -183,6 +183,11 @@ unsigned long strtoul(const char *restrict, char **restrict, int);
//------------------------------------------//
void *malloc(size_t) __attribute__((__malloc__));
void free(void *);
//------------------------------------------//
int rand(void);
void srand(unsigned int);
@ -239,6 +244,30 @@ DEC_CTYPE_FUNC(isalnum, (_AL|_DG));
//------------------------------------------//
#ifndef __min_defined
#define __min_defined
static inline int min(int __x, int __y)
{ return __x < __y ? __x : __y; }
#endif
#ifndef __lmin_defined
#define __lmin_defined
static inline int lmin(long __x, long __y)
{ return __x < __y ? __x : __y; }
#endif
#ifndef __max_defined
#define __max_defined
static inline int max(int __x, int __y)
{ return __x > __y ? __x : __y; }
#endif
#ifndef __lmax_defined
#define __lmax_defined
static inline int lmax(long __x, long __y)
{ return __x > __y ? __x : __y; }
#endif
#ifndef __abs_defined
#define __abs_defined
static inline int abs(int __x)

View File

@ -28,52 +28,55 @@
//------------------------------------------//
// Everything went fine
#define EOK 0
#define EOK 0
// Operation not permitted
#define EPERM 1
#define EPERM 1
// No such file or directory
#define ENOENT 2
#define ENOENT 2
// No such process
#define ESRCH 3
#define ESRCH 3
// Syscall interrupted (e.g. by signal)
#define EINTR 4
#define EINTR 4
// I/0 error
#define EIO 5
#define EIO 5
// No such device or address
#define ENXIO 6
#define ENXIO 6
// Argument list too long
#define E2BIG 7
#define E2BIG 7
// Not an executable format
#define ENOEXEC 8
#define ENOEXEC 8
// Bad file number
#define EBADF 9
#define EBADF 9
// Try again
#define EAGAIN 11
#define EAGAIN 11
// Out of memory
#define ENOMEM 12
#define ENOMEM 12
// Invalid argument
#define EINVAL 22
#define EINVAL 22
// Functionality not implemented
#define ENOSYS 38
#define ENOSYS 38
// Component crashed
#define ECRASH 500
// Address already in use
#define EADDRINUSE 98
// System is panicking
#define EPANIC 600
// Failure (unspecified reason)
#define EFAILED 256
// Alignment error
#define EALIGN 257
//------------------------------------------//

View File

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

View File

@ -35,16 +35,34 @@ extern "C" {
//------------------------------------------//
//
// ¯\_(ツ)_/¯
//
#ifndef _STDLIB_H
void *malloc(unsigned long);
void free(void *);
#endif
// Flags for KalAllocMemory
enum
{
// Return zeroed-out memory
M_ZEROED = 1,
#define KalAllocMemory malloc
#define KalFreeMemory free
// Crash if allocation fails (ENABLED by default in the kernel)
M_FAILCRASH = 2,
// Do NOT crash if allocation failed (meaningless outside of the kernel)
M_CANFAIL = 4,
};
enum
{
// Default memory allocation alignment (in bytes)
// Asking KalAllocMemory for an alignment of 0
// will cause it to use this value
M_DEFAULT_ALIGNMENT = alignof(QWORD),
// Minimal memory allocation alignment (in bytes)
// Asking KalAllocMemory for an nonzero alignment
// lower than this value will cause a EALIGN error
M_MINIMAL_ALIGNMENT = M_DEFAULT_ALIGNMENT
};
error_t KalAllocMemory(void **ptr, size_t req, int flags, size_t align);
error_t KalFreeMemory(void *ptr);
//------------------------------------------//

View File

@ -43,8 +43,8 @@ extern const char *__progvers;
const char *KalGetProgName(void);
const char *KalGetProgVersion(void);
bool KalSetProgVers(const char *);
bool KalSetProgName(const char *);
error_t KalSetProgVers(const char *);
error_t KalSetProgName(const char *);
//------------------------------------------//

View File

@ -42,10 +42,10 @@ typedef struct Terminal_t Terminal_t;
typedef struct ListHead_t ListHead_t;
typedef struct ListNode_t ListNode_t;
typedef struct Processor_t Processor_t;
typedef struct BootInfo_t BootInfo_t;
typedef enum ProcState_t ProcState_t;
typedef enum TermColor_t TermColor_t;
typedef enum KernelState_t KernelState_t;
//------------------------------------------//
// Multiprocessor misc. //
@ -61,8 +61,9 @@ typedef enum KernelState_t KernelState_t;
// Get Process_t structure of current CPU
#define GetCurCPU() (cpuTable[_GetCurCPU()])
#define PANICSTR_SIZE 1024
//Get the BootInfo_t structure
#define GetBootInfo(x) bootTab.x
//------------------------------------------//
//
@ -73,9 +74,6 @@ struct Processor_t
// CPU number, index in CPU list
int index;
// Panic string
char panicStr[PANICSTR_SIZE];
// Number of ticks since boot time
ulong ticks;
@ -96,11 +94,78 @@ struct Processor_t
ListHead_t *timeCritProcs;
};
#define FB_EGA_TEXT 2
#define FB_INDEXED 0
#define FB_RGB 1
#define BINFO_SIZE 4096
struct BootInfo_t
{
// The Bootloader infos (GRUB in our case)
struct {
ushort valid;
uint grubFlags; //flags
uint modulesCount; //mods_count
void *modulesAddr; //mods_addr
char *grubName; //boot_loader_name
void *mbHeaderAddr;
} btldr;
// Informations about drives
struct {
ushort drvValid;
ushort bufferValid;
uint bootDrv; //boot_device
uint bufferLength; //drives_length
void *bufferAddr; //drives_addr
} drives;
// Informations about memory
struct {
ushort memValid;
ushort mapValid;
//BIOS provided low and up memory
uint lowMemory; //mem_lower
uint upMemory; //mem_upper
//GRUB provided memory map
uint mapLength; //mmap_length
void *mapAddr; //mmap_addr
uint ramSize; //The ram (init by map.c)
} memory;
// Informations about the video drive
struct {
ushort valid;
uint vbeControl; //vbe_control_info
uint vbeModeInfo; //vbe_mode_info
ushort vbeMode; //vbe_mode
ushort vbeInterfaceSeg; //vbe_interface_seg
ushort vbeInterfaceOff; //vbe_interface_off
ushort vbeInterfaceLen; //vbe_interface_len
void* framebufferAddr; //framebuffer_addr
uint framebufferPitch; //framebuffer_pitch
uint framebufferWidth; //framebuffer_width
uint framebufferHeight; //framebuffer_height
uchar framebufferBpp; //framebuffer_bpp
uchar framebufferType; //framebuffer_type
} video;
// Informations about the microcode firmware (BIOS/EFI)
struct {
ushort apmValid;
ushort romValid;
uint apmTable; //apm_table
uint romTable; //config_table
} firmware;
};
//------------------------------------------//
extern int cpuCount;
extern Processor_t cpuTable[NCPUS];
extern BootInfo_t bootTab;
//------------------------------------------//
#define DEC_PER_CPU(name, field, type) \

View File

@ -22,8 +22,21 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H
#include <kernel/base.h>
#endif
#ifndef _KALKERN_CPU_H
#define _KALKERN_CPU_H
//------------------------------------------//
#define cpuid(in, a, b, c, d) asm("cpuid" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "a" (in) \
);
//------------------------------------------//
#endif

View File

@ -0,0 +1,51 @@
//----------------------------------------------------------------------------//
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H
#include <kernel/base.h>
#endif
#ifndef _KALKERN_MM_H
#define _KALKERN_MM_H
//------------------------------------------//
#define _HEAP_START (4 * MB)
void InitHeap(void);
void LockHeap(void);
void UnlockHeap(void);
size_t GetHeapSize(void);
size_t GetMaxHeapSize(void);
error_t SetMaxHeapSize(size_t);
error_t GrowHeap(size_t);
error_t ShrinkHeap(size_t);
//------------------------------------------//
#endif

View File

@ -22,7 +22,6 @@
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H
#include <kernel/base.h>
#endif

View File

@ -21,3 +21,20 @@
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kernel/multiboot.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
//
void *GetMemoryMap(void);
//
// Initializes the memory map structure
//
error_t InitMemoryMap(void);
// -------------------------------------------------------------------------- //

View File

@ -93,74 +93,74 @@
#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 uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long long ullong;
struct multiboot_header
{
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic;
uint magic;
/* Feature flags. */
multiboot_uint32_t flags;
uint flags;
/* The above fields plus this one must equal 0 mod 2^32. */
multiboot_uint32_t checksum;
uint checksum;
/* 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;
multiboot_uint32_t entry_addr;
uint header_addr;
uint load_addr;
uint load_end_addr;
uint bss_end_addr;
uint entry_addr;
/* 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;
uint mode_type;
uint width;
uint height;
uint depth;
};
/* The symbol table for a.out. */
struct multiboot_aout_symbol_table
{
multiboot_uint32_t tabsize;
multiboot_uint32_t strsize;
multiboot_uint32_t addr;
multiboot_uint32_t reserved;
uint tabsize;
uint strsize;
uint addr;
uint 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;
uint num;
uint size;
uint addr;
uint shndx;
};
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
struct multiboot_info
{
/* Multiboot info version number */
multiboot_uint32_t flags;
uint flags;
/* Available memory from BIOS */
multiboot_uint32_t mem_lower;
multiboot_uint32_t mem_upper;
uint mem_lower;
uint mem_upper;
/* "root" partition */
multiboot_uint32_t boot_device;
uint boot_device;
/* Kernel command line */
multiboot_uint32_t cmdline;
uint cmdline;
/* Boot-Module list */
multiboot_uint32_t mods_count;
multiboot_uint32_t mods_addr;
uint mods_count;
uint mods_addr;
union
{
@ -169,54 +169,54 @@ struct multiboot_info
} u;
/* Memory Mapping buffer */
multiboot_uint32_t mmap_length;
multiboot_uint32_t mmap_addr;
uint mmap_length;
uint mmap_addr;
/* Drive Info buffer */
multiboot_uint32_t drives_length;
multiboot_uint32_t drives_addr;
uint drives_length;
uint drives_addr;
/* ROM configuration table */
multiboot_uint32_t config_table;
uint config_table;
/* Boot Loader Name */
multiboot_uint32_t boot_loader_name;
uint boot_loader_name;
/* APM table */
multiboot_uint32_t apm_table;
uint 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;
uint vbe_control_info;
uint vbe_mode_info;
ushort vbe_mode;
ushort vbe_interface_seg;
ushort vbe_interface_off;
ushort vbe_interface_len;
multiboot_uint64_t framebuffer_addr;
multiboot_uint32_t framebuffer_pitch;
multiboot_uint32_t framebuffer_width;
multiboot_uint32_t framebuffer_height;
multiboot_uint8_t framebuffer_bpp;
ullong framebuffer_addr;
uint framebuffer_pitch;
uint framebuffer_width;
uint framebuffer_height;
uchar framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_uint8_t framebuffer_type;
uchar framebuffer_type;
union
{
struct
{
multiboot_uint32_t framebuffer_palette_addr;
multiboot_uint16_t framebuffer_palette_num_colors;
uint framebuffer_palette_addr;
ushort framebuffer_palette_num_colors;
};
struct
{
multiboot_uint8_t framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position;
multiboot_uint8_t framebuffer_green_mask_size;
multiboot_uint8_t framebuffer_blue_field_position;
multiboot_uint8_t framebuffer_blue_mask_size;
uchar framebuffer_red_field_position;
uchar framebuffer_red_mask_size;
uchar framebuffer_green_field_position;
uchar framebuffer_green_mask_size;
uchar framebuffer_blue_field_position;
uchar framebuffer_blue_mask_size;
};
};
};
@ -224,51 +224,51 @@ typedef struct multiboot_info multiboot_info_t;
struct multiboot_color
{
multiboot_uint8_t red;
multiboot_uint8_t green;
multiboot_uint8_t blue;
uchar red;
uchar green;
uchar blue;
};
struct multiboot_mmap_entry
{
multiboot_uint32_t size;
multiboot_uint64_t addr;
multiboot_uint64_t len;
uint size;
ullong addr;
ullong 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;
uint 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;
uint mod_start;
uint mod_end;
/* Module command line */
multiboot_uint32_t cmdline;
uint cmdline;
/* padding to take it to 16 bytes (must be zero) */
multiboot_uint32_t pad;
uint 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;
multiboot_uint16_t cseg_16;
multiboot_uint16_t dseg;
multiboot_uint16_t flags;
multiboot_uint16_t cseg_len;
multiboot_uint16_t cseg_16_len;
multiboot_uint16_t dseg_len;
ushort version;
ushort cseg;
uint offset;
ushort cseg_16;
ushort dseg;
ushort flags;
ushort cseg_len;
ushort cseg_16_len;
ushort dseg_len;
};
#endif /* ! ASM_FILE */

View File

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

View File

@ -37,6 +37,11 @@
//
enum { KTABSIZE = 4 };
//
// Upper bound on what a single KernLog() can write
//
enum { KLOG_MAX_BUFSIZE = 4096 };
//
// The VGA colors
//
@ -75,46 +80,35 @@ struct Terminal_t
TermColor_t bgColor;
// Defined in driver
error_t (*ClearTermUnlocked)(Terminal_t *);
error_t (*PutOnTermUnlocked)(Terminal_t *, char);
error_t (*PrintOnTermUnlocked)(Terminal_t *, const char *);
error_t (*clear)(Terminal_t *);
error_t (*putchar)(Terminal_t *, char);
};
//------------------------------------------//
void InitTerms(void);
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 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 *, ...);
//------------------------------------------//
extern Terminal_t *stdOut;
#define GetStdOut() (stdOut)
#define SetStdOut(x) (stdOut = (x))
// Debug purposes
volatile ushort *vga;
extern Terminal_t *StdOut;
extern Terminal_t *StdDbg;
//------------------------------------------//
#ifndef _NO_DEBUG
extern Terminal_t *stdDbg;
#define GetStdDbg() (stdDbg)
#define SetStdDbg(x) (stdDbg = (x))
error_t DebugLog(const char *, ...);
#else // _NO_DEBUG
#define GetStdDbg() NULL
#define SetStdDbg(x) ((void)0)
#define DebugLog(fmt, ...) EOK
#endif
//------------------------------------------//

View File

@ -21,12 +21,90 @@
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <multiboot/multiboot.h>
#include <kernel/term.h>
#include <kernel/panic.h>
#include <kernel/mm.h>
//
// BootInfo_t initialization. It is necessary because grub will potentially be
// wiped since it is below 1MB.... And we must reorganize all that stuff.
//
void InitBootInfo(multiboot_info_t *mbi)
{
extern uint MB_header;
char *okStr = "available";
char *noStr = "unavailable";
// We need the multiboot structure
KalAlwaysAssert(mbi);
//Retrieves the bootloader flags to ensure infos are valid
GetBootInfo(btldr).grubFlags = mbi->flags;
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).modulesAddr = (void*)(ullong)mbi->mods_addr;
}
//Retrieves the drives informations
if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_DRIVE_INFO) {
GetBootInfo(drives).bufferLength = mbi->drives_length;
GetBootInfo(drives).bufferAddr = (void*)(ullong)mbi->drives_addr;
GetBootInfo(drives).bufferValid = 1;
}
if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOTDEV) {
GetBootInfo(drives).bootDrv = mbi->boot_device;
GetBootInfo(drives).drvValid = 1;
}
//Retrieves the memory informations
if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEMORY) {
GetBootInfo(memory).lowMemory = mbi->mem_lower;
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).mapLength = mbi->mmap_length;
GetBootInfo(memory).mapValid = 1;
}
// XXX assign video infos, but unused at this time
// Retrieves the firmware infos
if (GetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) {
GetBootInfo(firmware).romTable = mbi->config_table;
GetBootInfo(firmware).romValid = 1;
}
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);
}
extern void testf(void);
//
// Entry point of the Kaleid kernel
@ -39,21 +117,21 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic)
// Kernel terminals
InitTerms();
// We're out
StartPanic( "We were loaded by : %s\n\n\n"
"We get\n"
" *mbInfo : %p\n"
" mbMagic : %x\n"
" mbBootdrv : %x\n"
" *mbMmap : %p\n"
" `-length : %d\n"
"\nGoodbye World :(",
//Hello world because why not
KernLog("%c%c%c OS/K\n\n", 219, 219, 219);
mbInfo->boot_loader_name,
mbInfo,
mbMagic,
mbInfo->boot_device,
mbInfo->mmap_addr,
mbInfo->mmap_length
);
KalAlwaysAssert(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC);
KernLog("[Init] We have magic : %x\n\n", mbMagic);
//Initialize the BootInfo_t structure
InitBootInfo(mbInfo);
//Memory mapping
error_t mapBad = InitMemoryMap();
if (mapBad)
StartPanic("[Init] The memory map failed to initialize. Error : %d", mapBad);
// We're out
KernLog("\n[Init] Evil never dies !");
CrashSystem(); //yay
}

View File

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

View File

@ -28,22 +28,22 @@ extern void VGA_Init(void);
extern Terminal_t VGA_Terminal;
//
// Initialize standard output
// Initializes standard output
//
void InitTerms(void)
{
KalAssert(!GetStdOut() && !GetStdDbg());
KalAssert(!StdOut && !StdDbg);
VGA_Init();
SetStdDbg(&VGA_Terminal);
SetStdOut(&VGA_Terminal);
StdDbg = &VGA_Terminal;
StdOut = &VGA_Terminal;
ClearTerm(GetStdOut());
ClearTerm(StdOut);
}
//
// Fill terminal with spaces
// Fills terminal with spaces
//
error_t ClearTerm(Terminal_t *term)
{
@ -52,15 +52,15 @@ error_t ClearTerm(Terminal_t *term)
if (term == NULL) return EINVAL;
KalAssert(term->initDone == INITOK);
AquireLock(&term->lock);
retcode = term->ClearTermUnlocked(term);
AcquireLock(&term->lock);
retcode = term->clear(term);
ReleaseLock(&term->lock);
return retcode;
}
//
// Change the color code
// Changes the color code
//
error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor)
{
@ -70,7 +70,7 @@ error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor)
if (term == NULL)
return EINVAL;
AquireLock(&term->lock);
AcquireLock(&term->lock);
term->fgColor = fgColor;
term->bgColor = bgColor;
@ -81,38 +81,134 @@ error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor)
}
//
// Write 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 retcode;
error_t rc;
if (term == NULL) return EINVAL;
KalAssert(term->initDone == INITOK);
AquireLock(&term->lock);
retcode = term->PutOnTermUnlocked(term, ch);
AcquireLock(&term->lock);
rc = PutOnTermUnlocked(term, ch);
ReleaseLock(&term->lock);
return retcode;
return rc;
}
//
// Print 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 retcode = EOK;
error_t rc = EOK;
if (term == NULL) return EINVAL;
KalAssert(term->initDone == INITOK);
AquireLock(&term->lock);
while (*str && retcode == EOK) {
retcode = term->PutOnTermUnlocked(term, *str++);
}
AcquireLock(&term->lock);
rc = PrintOnTermUnlocked(term, str);
ReleaseLock(&term->lock);
return retcode;
return rc;
}
//
// Prints formatted string on standard output
// Prints at most KLOG_MAX_BUFSIZE characters
//
error_t KernLog(const char *fmt, ...)
{
va_list ap;
char logbuf[KLOG_MAX_BUFSIZE];
va_start(ap, fmt);
vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap);
va_end(ap);
return PrintOnTerm(StdOut, logbuf);
}
#ifndef _NO_DEBUG
//
// Prints formatted string on debug output
// Prints at most KLOG_MAX_BUFSIZE characters
//
error_t DebugLog(const char *fmt, ...)
{
va_list ap;
char logbuf[KLOG_MAX_BUFSIZE];
va_start(ap, fmt);
vsnprintf(logbuf, KLOG_MAX_BUFSIZE, fmt, ap);
va_end(ap);
return PrintOnTerm(StdDbg, logbuf);
}
#endif

View File

@ -37,7 +37,7 @@
#define VGA_ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8)
//
// Clear terminal
// Clears terminal
//
error_t VGA_ClearTermUnlocked(Terminal_t *term)
{
@ -55,73 +55,19 @@ error_t VGA_ClearTermUnlocked(Terminal_t *term)
}
//
// Write a single character on the terminal
// Writes a single character on the terminal
//
error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch)
{
uint i;
size_t prevY;
ushort *buffer = (ushort *)term->data;
const size_t offset = VGA_ComputeOffset(term, term->currentX, term->currentY);
buffer[offset] = VGA_ComputeEntry(ch, VGA_ComputeColorCode(term->fgColor, term->bgColor));
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;
const size_t offset = VGA_ComputeOffset(term, term->currentX, term->currentY);
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;
}
//
// Print 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
// XXX custom sizes
//
Terminal_t VGA_Terminal = {
.initDone = FALSE,
@ -140,9 +86,8 @@ Terminal_t VGA_Terminal = {
.fgColor = KTERM_COLOR_LGREY,
.bgColor = KTERM_COLOR_BLACK,
.ClearTermUnlocked = VGA_ClearTermUnlocked,
.PutOnTermUnlocked = VGA_PutOnTermUnlocked,
.PrintOnTermUnlocked = VGA_PrintOnTermUnlocked,
.clear = VGA_ClearTermUnlocked,
.putchar = VGA_PutOnTermUnlocked,
};

View File

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

129
kaleid/kernel/mm/heap.c Normal file
View File

@ -0,0 +1,129 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Early and very dumb heap managment //
// //
// //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kernel/heap.h>
// Least address out of the heap
static void *_heap_end;
// Maximal value of the heap
static size_t _heap_max;
// Lock NOT used internally, but used by KalAllocMemory() & co.
static Lock_t _heap_lock = INITLOCK(KLOCK_SPINLOCK);
// Debugging stub
size_t GetAvailZoneSize(void *x) { (void)x; return 8 * MB; }
//
// Initializes heap managment
//
void InitHeap(void)
{
assert(_heap_end == NULL);
_heap_end = (void *)_HEAP_START;
_heap_max = lmin(8 * MB, GetAvailZoneSize((void *)_HEAP_START));
}
//
// Acquires control of the heap's lock
//
void LockHeap(void)
{
AcquireLock(&_heap_lock);
}
//
// Releases control of the heap's lock
//
void UnlockHeap(void)
{
ReleaseLock(&_heap_lock);
}
//
// Returns the heap's current size
//
size_t GetHeapSize(void)
{
return (size_t)_heap_end - _HEAP_START;
}
//
// Returns the heap's maximum size
//
size_t GetMaxHeapSize(void)
{
return _heap_max;
}
//
// Changes the heap's maximal size
//
error_t SetMaxHeapSize(size_t new)
{
if (new > GetAvailZoneSize((void *)_HEAP_START)) {
return ENOMEM;
}
if (new < (size_t)_heap_end - _HEAP_START) {
return EADDRINUSE;
}
_heap_max = new;
return EOK;
}
//
// Extends the heap's size
//
error_t GrowHeap(size_t req)
{
assert(req % alignof(QWORD));
if ((size_t)_heap_end + req > _HEAP_START + _heap_max) {
return ENOMEM;
}
_heap_end += req;
return EOK;
}
//
// Reduces the heap's size
//
error_t ShrinkHeap(size_t req)
{
assert(req % alignof(QWORD));
if (req > (size_t)_heap_end - _HEAP_START) {
return EADDRINUSE;
}
_heap_end -= req;
return EOK;
}

71
kaleid/kernel/mm/malloc.c Normal file
View File

@ -0,0 +1,71 @@
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Early and very dumb memory managment //
// //
// //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kernel/heap.h>
#include <extras/malloc.h>
error_t KalAllocMemory(void **ptr, size_t req, int flags, size_t align)
{
error_t rc;
size_t brk;
if (align == 0) align = M_DEFAULT_ALIGNMENT;
if (align < M_MINIMAL_ALIGNMENT) {
return EALIGN;
}
LockHeap();
brk = _HEAP_START + GetHeapSize();
req = _ALIGN_UP(req + brk, align) - brk;
rc = GrowHeap(req);
UnlockHeap();
if (rc) {
if ((flags & M_CANFAIL) != 0)
return rc;
StartPanic("Out of memory");
}
if (flags & M_ZEROED) {
memzero(*ptr, req);
}
*ptr = (void *)brk;
return rc;
}
//
// Frees allocated memory
//
error_t KalFreeMemory(void *ptr)
{
(void)ptr;
return EOK;
}

46
kaleid/kernel/mm/map.c Normal file
View File

@ -0,0 +1,46 @@
//----------------------------------------------------------------------------//
// 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 //
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kernel/mm.h>
#include <kernel/term.h>
error_t InitMemoryMap(void)
{
if (!GetBootInfo(memory).memValid && GetBootInfo(memory).mapValid)
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;
}
void *GetMemoryMap(void)
{
return (void*)0;
}