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 ASMFLAGS=-f elf64
LDFLAGS=-melf_x86_64 LDFLAGS=-melf_x86_64
COPTIM=-O2 COPTIM=-O2
CWARNS=-Wall -Wextra # -Werror=implicit-function-declaration CWARNS=-Wall -Wextra -Werror=implicit-function-declaration
CINCLUDES=-Ikaleid/include 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 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 KCC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) -D_OSK_SOURCE -D_KALEID_KERNEL
#Folders #Folders
@ -61,93 +61,103 @@ all : OS/K
## KALEID MAKEFILE ----------------------------------------------------------- # ## KALEID MAKEFILE ----------------------------------------------------------- #
# Common objects # Common objects
kal_com_obj= $(KOBJDIR)/atoi.o $(KOBJDIR)/ctype.o \ kal_com_obj= $(KOBJDIR)/atoi.o $(KOBJDIR)/ctype.o \
$(KOBJDIR)/itoa.o $(KOBJDIR)/memory.o \ $(KOBJDIR)/itoa.o $(KOBJDIR)/mem.o \
$(KOBJDIR)/rand.o $(KOBJDIR)/sprintf.o \ $(KOBJDIR)/rand.o $(KOBJDIR)/sprintf.o \
$(KOBJDIR)/status.o $(KOBJDIR)/string.o \ $(KOBJDIR)/status.o $(KOBJDIR)/string.o \
$(KOBJDIR)/strtol.o $(KOBJDIR)/argv.o \ $(KOBJDIR)/strtol.o $(KOBJDIR)/argv.o \
$(KOBJDIR)/prog.o $(KOBJDIR)/atol.o \ $(KOBJDIR)/prog.o $(KOBJDIR)/atol.o \
$(KOBJDIR)/atou.o $(KOBJDIR)/atoul.o \ $(KOBJDIR)/atou.o $(KOBJDIR)/atoul.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)/memory.o: $(KERNELDIR)/crtlib/memory.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}
# Kernel objects # Kernel objects
kal_kern_obj= $(KOBJDIR)/kernel/cpuid.o $(KOBJDIR)/kernel/init.o \ kal_kern_obj= $(KOBJDIR)/kernel/cpuid.o $(KOBJDIR)/kernel/init.o \
$(KOBJDIR)/kernel/table.o $(KOBJDIR)/kernel/cursor.o \ $(KOBJDIR)/kernel/table.o $(KOBJDIR)/kernel/cursor.o \
$(KOBJDIR)/kernel/term.o $(KOBJDIR)/kernel/vga.o \ $(KOBJDIR)/kernel/term.o $(KOBJDIR)/kernel/vga.o \
$(KOBJDIR)/kernel/panic.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 $@ @$(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 $@
@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 $@ @$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
@ -155,13 +165,13 @@ $(KOBJDIR)/kernel/panic.o: $(KERNELDIR)/kernel/ke/panic.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
@ -172,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
@ -180,19 +190,17 @@ debug: all
install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg
@mkdir -p $(BINDIR)/disk @mkdir -p $(BINDIR)/disk
@echo ${CL2}[$@] ${NC}Installing MBR on image...${CL3} @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 @$(MBRDIR)/grub-install.sh $(BINDIR)/disk.img $(BINDIR)/disk $(MBRDIR)/grub.cfg
@rmdir $(BINDIR)/disk @rmdir $(BINDIR)/disk
@echo ${CL2}[$@] ${CL}Success.${CL3} @echo ${CL2}[$@] ${CL}Success.${CL3}
.PHONY: clean .PHONY: clean
clean: clean:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk -@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rvf ./ProjectTree @rm -Rvf ./ProjectTree
@rm -Rvf $(BINDIR)/*.* @rm -Rvf $(BINDIR)/* $(OBJDIR)/*.o \
@rm -Rvf $(OBJDIR)/*.o $(OBJDIR)/*/*.o $(OBJDIR)/*/*.x86_64 $(OBJDIR)/*/*/*.o
@rm -Rvf $(OBJDIR)/*/*.o
@rm -Rvf $(OBJDIR)/*/*/*.o
@echo ${CL2}[[$@]] ${CL}Cleaned.${CL3} @echo ${CL2}[[$@]] ${CL}Cleaned.${CL3}
$(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64 $(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 -o $(LOBJDIR)/kaleid.x86_64
@echo ${CL2}[$@] ${CL}Success.${CL3} @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} @echo ${CL2}[$@] ${NC}Making loader...${CL3}
@$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(LOBJDIR)/loader.o > /dev/null @$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(LOBJDIR)/loader.o > /dev/null
@echo ${CL2}[$@] ${CL}Success.${CL3} @echo ${CL2}[$@] ${CL}Success.${CL3}
$(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh $(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3} @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 @$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img
@make install_mbr @make install_mbr
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3} @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 OS/K: $(BINDIR)/kaleid $(BINDIR)/disk.img ./ProjectTree
@mkdir -p $(BINDIR)/disk @mkdir -p $(BINDIR)/disk
@echo ${CL2}[[$@]] ${NC}Integrating kernel...${CL3} @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 @$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk
@cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid @cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid
@$(MBRDIR)/umount.sh $(BINDIR)/disk @$(MBRDIR)/umount.sh $(BINDIR)/disk

View File

@ -24,9 +24,7 @@
. .
├── AUTHORS
├── boot ├── boot
│   ├── folder.desc
│   ├── grub │   ├── grub
│   │   ├── create_disk.sh │   │   ├── create_disk.sh
│   │   ├── grub.cfg │   │   ├── grub.cfg
@ -34,72 +32,73 @@
│   │   ├── 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
│   │   ├── init │   │   │   ├── cursor.o
│   │   │   ├── init.o │   │   │   ├── heap.o
│   │   │   └── table.o │   │   │   ├── init.o
│   │   ├── init.o │   │   │   ├── malloc.o
│   │   ├── io │   │   │   ├── map.o
│   │   │   ├── cursor.o │   │   │   ├── panic.o
│   │   │   ├── term.o │   │   │   ├── table.o
│   │   │   └── vga.o │   │   │   ├── term.o
│   │   ├── ke │   │   │   └── vga.o
│   │   │   └── panic.o │   │   ├── argv.o
│   │   ├── panic.o │   │   ├── atoi.o
│   │   ├── table.o │   │   ├── atol.o
│   │   ├── term.o │   │   ├── atoul.o
│   │   └── vga.o │   │   ├── atou.o
│   ├── ltoa.o │   │   ├── ctype.o
│   ├── memory.o │   │   ├── itoa.o
│   ├── prog.o │   │   ├── ltoa.o
│   ├── rand.o │   │   ├── mem.o
│   ├── sprintf.o │   │   ├── prog.o
│   ├── status.o │   │   ├── rand.o
│   ├── string.o │   │   ├── sprintf.o
│   ├── strtol.o │   │   ├── status.o
│   ├── ultoa.o │   │   ├── string.o
│   └── utoa.o │   │   ├── strtol.o
├── ChangeLog │   │   ├── ultoa.o
├── COPYING │   │   └── utoa.o
├── grub.log │   └── kernel.ld
├── kaleid ├── kaleid
│   ├── crtlib │   ├── crtlib
│   │   ├── atoi.c │   │   ├── atoi.c
│   │   ├── ctype.c │   │   ├── ctype.c
│   │   ├── itoa.c │   │   ├── itoa.c
│   │   ├── memory.c │   │   ├── mem.c
│   │   ├── rand.c │   │   ├── rand.c
│   │   ├── sprintf.c │   │   ├── sprintf.c
│   │   ├── status.c │   │   ├── status.c
@ -123,20 +122,20 @@
│   │   │   ├── locks.h │   │   │   ├── locks.h
│   │   │   ├── malloc.h │   │   │   ├── malloc.h
│   │   │   └── prog.h │   │   │   └── prog.h
│   │   ├── kalbase.h
│   │   ├── kaleid.h
│   │   ├── kalext.h
│   │   ├── kernel │   │   ├── kernel
│   │   │   ├── base.h │   │   │   ├── base.h
│   │   │   ├── cpu.h │   │   │   ├── cpu.h
│   │   │   ├── heap.h
│   │   │   ├── iomisc.h │   │   │   ├── iomisc.h
│   │   │   ├── mm.h │   │   │   ├── mm.h
│   │   │   ├── multiboot.h
│   │   │   ├── panic.h │   │   │   ├── panic.h
│   │   │   ├── proc.h │   │   │   ├── proc.h
│   │   │   ├── sched.h │   │   │   ├── sched.h
│   │   │   └── term.h │   │   │   └── term.h
│   │   └── multiboot │   │   ├── kalbase.h
│   │   └── multiboot.h │   │   ├── kaleid.h
│   │   └── kalext.h
│   └── kernel │   └── kernel
│   ├── cpu │   ├── cpu
│   │   └── cpuid.c │   │   └── cpuid.c
@ -151,9 +150,16 @@
│   ├── ke │   ├── ke
│   │   └── panic.c │   │   └── panic.c
│   ├── mm │   ├── mm
│   │   ├── heap.c
│   │   ├── malloc.c
│   │   └── map.c
│   └── 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
@ -161,4 +167,4 @@
├── qemu.log ├── qemu.log
└── Readme.md └── Readme.md
31 directories, 105 files 30 directories, 112 files

Binary file not shown.

View File

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

View File

@ -32,6 +32,7 @@
%include "boot/loader/mem/structures.inc" %include "boot/loader/mem/structures.inc"
global MB_start global MB_start
global MB_header
extern StartKern extern StartKern
[BITS 32] [BITS 32]
@ -43,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]
@ -70,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
; ---------------------------------------------------------------------------- ; ; ---------------------------------------------------------------------------- ;
@ -103,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
@ -114,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]
@ -153,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

@ -23,9 +23,31 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kalbase.h> #include <kalbase.h>
#include <extras/malloc.h>
/* DO NOT compile with strict aliasing on */ /* 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 // // memset() family //
//------------------------------------------// //------------------------------------------//

View File

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

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

@ -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 #ifndef __BEGIN_DECLS
#ifdef __cpluplus #ifdef __cpluplus
# define __EXTERN_C extern "C" # define __EXTERN_C extern "C"

View File

@ -66,7 +66,7 @@ extern error_t __errno;
#define errno __errno #define errno __errno
#endif #endif
#define __get_errno(x) error_t x = errno; #define __get_errno(x) error_t x = errno
#define __set_errno(x) (errno = (x)) #define __set_errno(x) (errno = (x))
#else #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); int rand(void);
void srand(unsigned int); 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 #ifndef __abs_defined
#define __abs_defined #define __abs_defined
static inline int abs(int __x) static inline int abs(int __x)

View File

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

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

@ -35,16 +35,34 @@ extern "C" {
//------------------------------------------// //------------------------------------------//
// // Flags for KalAllocMemory
// ¯\_(ツ)_/¯ enum
// {
#ifndef _STDLIB_H // Return zeroed-out memory
void *malloc(unsigned long); M_ZEROED = 1,
void free(void *);
#endif
#define KalAllocMemory malloc // Crash if allocation fails (ENABLED by default in the kernel)
#define KalFreeMemory free 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 *KalGetProgName(void);
const char *KalGetProgVersion(void); const char *KalGetProgVersion(void);
bool KalSetProgVers(const char *); error_t KalSetProgVers(const char *);
bool KalSetProgName(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 ListHead_t ListHead_t;
typedef struct ListNode_t ListNode_t; typedef struct ListNode_t ListNode_t;
typedef struct Processor_t Processor_t; typedef struct Processor_t Processor_t;
typedef struct BootInfo_t BootInfo_t;
typedef enum ProcState_t ProcState_t; typedef enum ProcState_t ProcState_t;
typedef enum TermColor_t TermColor_t; typedef enum TermColor_t TermColor_t;
typedef enum KernelState_t KernelState_t;
//------------------------------------------// //------------------------------------------//
// Multiprocessor misc. // // Multiprocessor misc. //
@ -61,8 +61,9 @@ typedef enum KernelState_t KernelState_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
#define GetBootInfo(x) bootTab.x
//------------------------------------------// //------------------------------------------//
// //
@ -73,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;
@ -96,11 +94,78 @@ struct Processor_t
ListHead_t *timeCritProcs; 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 int cpuCount;
extern Processor_t cpuTable[NCPUS]; extern Processor_t cpuTable[NCPUS];
extern BootInfo_t bootTab;
//------------------------------------------// //------------------------------------------//
#define DEC_PER_CPU(name, field, type) \ #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/>. // // 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" \ #define cpuid(in, a, b, c, d) asm("cpuid" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "a" (in) \ : "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/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#ifndef _KALKERN_BASE_H #ifndef _KALKERN_BASE_H
#include <kernel/base.h> #include <kernel/base.h>
#endif #endif

View File

@ -21,3 +21,20 @@
// You should have received a copy of the GNU General Public License // // You should have received a copy of the GNU General Public License //
// 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/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 #ifndef ASM_FILE
typedef unsigned char multiboot_uint8_t; typedef unsigned char uchar;
typedef unsigned short multiboot_uint16_t; typedef unsigned short ushort;
typedef unsigned int multiboot_uint32_t; typedef unsigned int uint;
typedef unsigned long long multiboot_uint64_t; typedef unsigned long long ullong;
struct multiboot_header struct multiboot_header
{ {
/* Must be MULTIBOOT_MAGIC - see above. */ /* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic; uint magic;
/* Feature flags. */ /* Feature flags. */
multiboot_uint32_t flags; uint flags;
/* The above fields plus this one must equal 0 mod 2^32. */ /* 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. */ /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
multiboot_uint32_t header_addr; uint header_addr;
multiboot_uint32_t load_addr; uint load_addr;
multiboot_uint32_t load_end_addr; uint load_end_addr;
multiboot_uint32_t bss_end_addr; uint bss_end_addr;
multiboot_uint32_t entry_addr; uint entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
multiboot_uint32_t mode_type; uint mode_type;
multiboot_uint32_t width; uint width;
multiboot_uint32_t height; uint height;
multiboot_uint32_t depth; uint depth;
}; };
/* The symbol table for a.out. */ /* The symbol table for a.out. */
struct multiboot_aout_symbol_table struct multiboot_aout_symbol_table
{ {
multiboot_uint32_t tabsize; uint tabsize;
multiboot_uint32_t strsize; uint strsize;
multiboot_uint32_t addr; uint addr;
multiboot_uint32_t reserved; uint reserved;
}; };
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
/* The section header table for ELF. */ /* The section header table for ELF. */
struct multiboot_elf_section_header_table struct multiboot_elf_section_header_table
{ {
multiboot_uint32_t num; uint num;
multiboot_uint32_t size; uint size;
multiboot_uint32_t addr; uint addr;
multiboot_uint32_t shndx; uint shndx;
}; };
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t; typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
struct multiboot_info struct multiboot_info
{ {
/* Multiboot info version number */ /* Multiboot info version number */
multiboot_uint32_t flags; uint flags;
/* Available memory from BIOS */ /* Available memory from BIOS */
multiboot_uint32_t mem_lower; uint mem_lower;
multiboot_uint32_t mem_upper; uint mem_upper;
/* "root" partition */ /* "root" partition */
multiboot_uint32_t boot_device; uint boot_device;
/* Kernel command line */ /* Kernel command line */
multiboot_uint32_t cmdline; uint cmdline;
/* Boot-Module list */ /* Boot-Module list */
multiboot_uint32_t mods_count; uint mods_count;
multiboot_uint32_t mods_addr; uint mods_addr;
union union
{ {
@ -169,54 +169,54 @@ struct multiboot_info
} u; } u;
/* Memory Mapping buffer */ /* Memory Mapping buffer */
multiboot_uint32_t mmap_length; uint mmap_length;
multiboot_uint32_t mmap_addr; uint mmap_addr;
/* Drive Info buffer */ /* Drive Info buffer */
multiboot_uint32_t drives_length; uint drives_length;
multiboot_uint32_t drives_addr; uint drives_addr;
/* ROM configuration table */ /* ROM configuration table */
multiboot_uint32_t config_table; uint config_table;
/* Boot Loader Name */ /* Boot Loader Name */
multiboot_uint32_t boot_loader_name; uint boot_loader_name;
/* APM table */ /* APM table */
multiboot_uint32_t apm_table; uint apm_table;
/* Video */ /* Video */
multiboot_uint32_t vbe_control_info; uint vbe_control_info;
multiboot_uint32_t vbe_mode_info; uint vbe_mode_info;
multiboot_uint16_t vbe_mode; ushort vbe_mode;
multiboot_uint16_t vbe_interface_seg; ushort vbe_interface_seg;
multiboot_uint16_t vbe_interface_off; ushort vbe_interface_off;
multiboot_uint16_t vbe_interface_len; ushort vbe_interface_len;
multiboot_uint64_t framebuffer_addr; ullong framebuffer_addr;
multiboot_uint32_t framebuffer_pitch; uint framebuffer_pitch;
multiboot_uint32_t framebuffer_width; uint framebuffer_width;
multiboot_uint32_t framebuffer_height; uint framebuffer_height;
multiboot_uint8_t framebuffer_bpp; uchar framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_uint8_t framebuffer_type; uchar framebuffer_type;
union union
{ {
struct struct
{ {
multiboot_uint32_t framebuffer_palette_addr; uint framebuffer_palette_addr;
multiboot_uint16_t framebuffer_palette_num_colors; ushort framebuffer_palette_num_colors;
}; };
struct struct
{ {
multiboot_uint8_t framebuffer_red_field_position; uchar framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size; uchar framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position; uchar framebuffer_green_field_position;
multiboot_uint8_t framebuffer_green_mask_size; uchar framebuffer_green_mask_size;
multiboot_uint8_t framebuffer_blue_field_position; uchar framebuffer_blue_field_position;
multiboot_uint8_t framebuffer_blue_mask_size; uchar framebuffer_blue_mask_size;
}; };
}; };
}; };
@ -224,51 +224,51 @@ typedef struct multiboot_info multiboot_info_t;
struct multiboot_color struct multiboot_color
{ {
multiboot_uint8_t red; uchar red;
multiboot_uint8_t green; uchar green;
multiboot_uint8_t blue; uchar blue;
}; };
struct multiboot_mmap_entry struct multiboot_mmap_entry
{ {
multiboot_uint32_t size; uint size;
multiboot_uint64_t addr; ullong addr;
multiboot_uint64_t len; ullong len;
#define MULTIBOOT_MEMORY_AVAILABLE 1 #define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2 #define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 #define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4 #define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5 #define MULTIBOOT_MEMORY_BADRAM 5
multiboot_uint32_t type; uint type;
} __attribute__((packed)); } __attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t; typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_mod_list struct multiboot_mod_list
{ {
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */ /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
multiboot_uint32_t mod_start; uint mod_start;
multiboot_uint32_t mod_end; uint mod_end;
/* Module command line */ /* Module command line */
multiboot_uint32_t cmdline; uint cmdline;
/* padding to take it to 16 bytes (must be zero) */ /* padding to take it to 16 bytes (must be zero) */
multiboot_uint32_t pad; uint pad;
}; };
typedef struct multiboot_mod_list multiboot_module_t; typedef struct multiboot_mod_list multiboot_module_t;
/* APM BIOS info. */ /* APM BIOS info. */
struct multiboot_apm_info struct multiboot_apm_info
{ {
multiboot_uint16_t version; ushort version;
multiboot_uint16_t cseg; ushort cseg;
multiboot_uint32_t offset; uint offset;
multiboot_uint16_t cseg_16; ushort cseg_16;
multiboot_uint16_t dseg; ushort dseg;
multiboot_uint16_t flags; ushort flags;
multiboot_uint16_t cseg_len; ushort cseg_len;
multiboot_uint16_t cseg_16_len; ushort cseg_16_len;
multiboot_uint16_t dseg_len; ushort dseg_len;
}; };
#endif /* ! ASM_FILE */ #endif /* ! ASM_FILE */

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

@ -37,6 +37,11 @@
// //
enum { KTABSIZE = 4 }; enum { KTABSIZE = 4 };
//
// Upper bound on what a single KernLog() can write
//
enum { KLOG_MAX_BUFSIZE = 4096 };
// //
// The VGA colors // The VGA colors
// //
@ -75,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

@ -21,12 +21,90 @@
// You should have received a copy of the GNU General Public License // // You should have received a copy of the GNU General Public License //
// 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 <multiboot/multiboot.h>
#include <kernel/term.h> #include <kernel/term.h>
#include <kernel/panic.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 // Entry point of the Kaleid kernel
@ -39,21 +117,21 @@ noreturn void StartKern(multiboot_info_t *mbInfo, int mbMagic)
// Kernel terminals // Kernel terminals
InitTerms(); InitTerms();
// We're out //Hello world because why not
StartPanic( "We were loaded by : %s\n\n\n" KernLog("%c%c%c OS/K\n\n", 219, 219, 219);
"We get\n"
" *mbInfo : %p\n"
" mbMagic : %x\n"
" mbBootdrv : %x\n"
" *mbMmap : %p\n"
" `-length : %d\n"
"\nGoodbye World :(",
mbInfo->boot_loader_name, KalAlwaysAssert(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC);
mbInfo, KernLog("[Init] We have magic : %x\n\n", mbMagic);
mbMagic,
mbInfo->boot_device, //Initialize the BootInfo_t structure
mbInfo->mmap_addr, InitBootInfo(mbInfo);
mbInfo->mmap_length
); //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; int cpuCount = 1;
Processor_t cpuTable[NCPUS] = {0}; 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; extern Terminal_t VGA_Terminal;
// //
// Initialize standard output // Initializes standard output
// //
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);
} }
// //
// Fill terminal with spaces // Fills terminal with spaces
// //
error_t ClearTerm(Terminal_t *term) error_t ClearTerm(Terminal_t *term)
{ {
@ -52,15 +52,15 @@ 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;
} }
// //
// Change the color code // Changes the color code
// //
error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor) 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) 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,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 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;
} }
// //
// 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 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;
} }
//
// 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) #define VGA_ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8)
// //
// Clear terminal // Clears terminal
// //
error_t VGA_ClearTermUnlocked(Terminal_t *term) 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) error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch)
{ {
uint i; ushort *buffer = (ushort *)term->data;
size_t prevY; 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; 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 // 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 %s - 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();
} }
@ -80,7 +78,9 @@ noreturn void StartPanic(const char *fmt, ...)
// //
noreturn void CrashSystem(void) noreturn void CrashSystem(void)
{ {
DisableIRQs(); while (1) {
HaltCPU(); 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;
}