merge master ok
This commit is contained in:
commit
831591d996
|
@ -0,0 +1,71 @@
|
||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
// 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/>. //
|
||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
;=----------------------------------------------------------------------------=;
|
||||||
|
; GNU GPL OS/K ;
|
||||||
|
; ;
|
||||||
|
; Desc: ;
|
||||||
|
; ;
|
||||||
|
; ;
|
||||||
|
; Copyright © 2018-2019 The OS/K Team ;
|
||||||
|
; ;
|
||||||
|
; This file is part of OS/K. ;
|
||||||
|
; ;
|
||||||
|
; OS/K is free software: you can redistribute it and/or modify ;
|
||||||
|
; it under the terms of the GNU General Public License as published by ;
|
||||||
|
; the Free Software Foundation, either version 3 of the License, or ;
|
||||||
|
; (at your option) any later version. ;
|
||||||
|
; ;
|
||||||
|
; OS/K is distributed in the hope that it will be useful, ;
|
||||||
|
; but WITHOUT ANY WARRANTY; without even the implied warranty of ;
|
||||||
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
|
||||||
|
; GNU General Public License for more details. ;
|
||||||
|
; ;
|
||||||
|
; You should have received a copy of the GNU General Public License ;
|
||||||
|
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
|
||||||
|
;=----------------------------------------------------------------------------=;
|
||||||
|
|
||||||
|
#=----------------------------------------------------------------------------=#
|
||||||
|
# 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/>. #
|
||||||
|
#=----------------------------------------------------------------------------=#
|
|
@ -1,23 +0,0 @@
|
||||||
;=----------------------------------------------------------------------------=;
|
|
||||||
; GNU GPL OS/K ;
|
|
||||||
; ;
|
|
||||||
; Desc: ;
|
|
||||||
; ;
|
|
||||||
; ;
|
|
||||||
; Copyright © 2018-2019 The OS/K Team ;
|
|
||||||
; ;
|
|
||||||
; This file is part of OS/K. ;
|
|
||||||
; ;
|
|
||||||
; OS/K is free software: you can redistribute it and/or modify ;
|
|
||||||
; it under the terms of the GNU General Public License as published by ;
|
|
||||||
; the Free Software Foundation, either version 3 of the License, or ;
|
|
||||||
; (at your option) any later version. ;
|
|
||||||
; ;
|
|
||||||
; OS/K is distributed in the hope that it will be useful, ;
|
|
||||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of ;
|
|
||||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
|
|
||||||
; GNU General Public License for more details. ;
|
|
||||||
; ;
|
|
||||||
; You should have received a copy of the GNU General Public License ;
|
|
||||||
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
|
|
||||||
;=----------------------------------------------------------------------------=;
|
|
23
.stylehlp_c
23
.stylehlp_c
|
@ -1,23 +0,0 @@
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
// 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/>. //
|
|
||||||
//----------------------------------------------------------------------------//
|
|
|
@ -40,4 +40,8 @@
|
||||||
- We have implemented a buffer library for our terminal
|
- We have implemented a buffer library for our terminal
|
||||||
- The stack is now 8MB long and isn't anymore in conflict with the kernel space xD
|
- The stack is now 8MB long and isn't anymore in conflict with the kernel space xD
|
||||||
- The terminal is now better (with sprintf functions)
|
- The terminal is now better (with sprintf functions)
|
||||||
|
2019/04/09 More improvements
|
||||||
|
- The terminal is now buffered (static) and we have made a big reorganization of the project
|
||||||
|
- The Makefile suffered a lot, so we improved it
|
||||||
|
- panic doesn't need to lock the terminal
|
||||||
|
- We have a (basic) heap and memory allocator
|
||||||
|
|
249
Makefile
249
Makefile
|
@ -22,166 +22,84 @@
|
||||||
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
|
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
#=----------------------------------------------------------------------------=#
|
#=----------------------------------------------------------------------------=#
|
||||||
|
|
||||||
|
.PHONY: all test test32 debug gdb install_mbr dust clean OS/K
|
||||||
|
|
||||||
## VARIABLES ----------------------------------------------------------------- #
|
## VARIABLES ----------------------------------------------------------------- #
|
||||||
|
|
||||||
#Programs
|
# Debug
|
||||||
ASM=nasm
|
mode ?= debug
|
||||||
LD=ld
|
|
||||||
CCNAME=x86_64-elf-gcc
|
|
||||||
|
|
||||||
|
# Programs
|
||||||
|
ASM=nasm
|
||||||
|
LD=x86_64-elf-ld
|
||||||
|
OBJCOPY=x86_64-elf-objcopy
|
||||||
|
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=-Iinclude
|
||||||
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11
|
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11
|
||||||
CFLAGS2= -c -g -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fno-strict-aliasing
|
CFLAGS2= -c -mno-red-zone -mno-mmx -mno-sse -mno-sse2
|
||||||
CFLAGS=$(CFLAGS1) $(CFLAGS2)
|
CFLAGS=$(CFLAGS1) $(CFLAGS2)
|
||||||
|
|
||||||
|
ifeq ($(mode), release)
|
||||||
|
CFLAGS += -D_NO_DEBUG
|
||||||
|
dep += dust
|
||||||
|
endif
|
||||||
|
ifeq ($(mode), debug)
|
||||||
|
CFLAGS += -g
|
||||||
|
endif
|
||||||
|
|
||||||
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
|
||||||
MBRDIR=boot/grub
|
MBRDIR=boot/grub
|
||||||
LOADERDIR=boot/loader
|
LOADERDIR=boot/loader
|
||||||
KERNELDIR=kaleid
|
KALEIDDIR=kaleid
|
||||||
|
INCLUDEDIR=include
|
||||||
OBJDIR=build/obj
|
OBJDIR=build/obj
|
||||||
KOBJDIR=build/obj/kaleid
|
KOBJDIR=build/obj/kaleid
|
||||||
LOBJDIR=build/obj/boot
|
LOBJDIR=build/obj/boot
|
||||||
BINDIR=build/bin
|
BINDIR=build/bin
|
||||||
BUILDDIR=build
|
BUILDDIR=build
|
||||||
|
vpath %.c $(KALEIDDIR)
|
||||||
|
|
||||||
#Color codes
|
# Color codes
|
||||||
CL='\033[0;32m'
|
CL='\033[0;32m'
|
||||||
CL2='\033[1;36m'
|
CL2='\033[1;36m'
|
||||||
CL3='\033[0m'
|
CL3='\033[0m'
|
||||||
NC='\033[1;37m'
|
NC='\033[1;37m'
|
||||||
|
|
||||||
|
|
||||||
.PHONY: all
|
## SOURCES INSCRIPTION-------------------------------------------------------- #
|
||||||
all : OS/K
|
|
||||||
|
# Lib C sources
|
||||||
|
LibCSources= libc/atoi.c libc/itoa.c \
|
||||||
|
libc/mem.c libc/ctype.c \
|
||||||
|
libc/rand.c libc/sprintf.c \
|
||||||
|
libc/status.c libc/string.c \
|
||||||
|
libc/strtol.c extras/argv.c \
|
||||||
|
extras/prog.c
|
||||||
|
|
||||||
|
KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
|
||||||
|
|
||||||
|
# Kernel sources
|
||||||
|
KernSources= libbuf/buf.c libbuf/bput.c \
|
||||||
|
libbuf/bprint.c kernel/cpu/cpuid.c \
|
||||||
|
kernel/cpu/idt.c kernel/init/init.c \
|
||||||
|
kernel/init/table.c kernel/io/cursor.c \
|
||||||
|
kernel/ke/log.c kernel/io/vga.c \
|
||||||
|
kernel/ke/panic.c kernel/mm/map.c \
|
||||||
|
kernel/mm/heap.c kernel/mm/malloc.c \
|
||||||
|
kernel/mm/gdt.c kernel/ps/sched.c \
|
||||||
|
|
||||||
|
LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources))
|
||||||
|
|
||||||
|
|
||||||
## KALEID MAKEFILE ----------------------------------------------------------- #
|
## KALEID MAKEFILE ----------------------------------------------------------- #
|
||||||
|
|
||||||
# Common objects
|
all : OS/K $(dep)
|
||||||
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 $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) -D_NEED_ATOI $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(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 $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) -D_NEED_ATOU $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(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 $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(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 $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) -D_NEED_LTOA $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(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 $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) -D_NEED_ULTOA $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(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 $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/sprintf.o: $(KERNELDIR)/crtlib/sprintf.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/status.o: $(KERNELDIR)/crtlib/status.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/string.o: $(KERNELDIR)/crtlib/string.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/strtol.o: $(KERNELDIR)/crtlib/strtol.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/argv.o: $(KERNELDIR)/extras/argv.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(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/log.o $(KOBJDIR)/kernel/vga.o \
|
|
||||||
$(KOBJDIR)/kernel/panic.o $(KOBJDIR)/kernel/map.o \
|
|
||||||
$(KOBJDIR)/kernel/heap.o $(KOBJDIR)/kernel/malloc.o \
|
|
||||||
$(KOBJDIR)/kernel/buf.o $(KOBJDIR)/kernel/sched.o \
|
|
||||||
$(KOBJDIR)/kernel/bput.o $(KOBJDIR)/kernel/bprint.o \
|
|
||||||
$(KOBJDIR)/kernel/gdt.o
|
|
||||||
|
|
||||||
$(KOBJDIR)/kernel/cpuid.o: $(KERNELDIR)/kernel/cpu/cpuid.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/kernel/idt.o: $(KERNELDIR)/kernel/cpu/idt.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(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 $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/kernel/cursor.o: $(KERNELDIR)/kernel/io/cursor.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/kernel/log.o: $(KERNELDIR)/kernel/ke/log.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(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 $(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 $@
|
|
||||||
$(KOBJDIR)/kernel/gdt.o: $(KERNELDIR)/kernel/mm/gdt.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/kernel/buf.o: $(KERNELDIR)/kernel/buf/buf.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/kernel/bput.o: $(KERNELDIR)/kernel/buf/bput.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/kernel/bprint.o: $(KERNELDIR)/kernel/buf/bprint.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
$(KOBJDIR)/kernel/sched.o: $(KERNELDIR)/kernel/proc/sched.c $(KERNELDIR)/include/*/*.h
|
|
||||||
@$(KCC) $< -o $@
|
|
||||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
|
||||||
|
|
||||||
|
|
||||||
## MISC MAKEFILE ------------------------------------------------------------- #
|
## MISC MAKEFILE ------------------------------------------------------------- #
|
||||||
./ProjectTree: ./.stylehlp_sh
|
./ProjectTree: ./.stylehlp_sh
|
||||||
|
@ -189,24 +107,56 @@ $(KOBJDIR)/kernel/sched.o: $(KERNELDIR)/kernel/proc/sched.c $(KERNELDIR)/include
|
||||||
@echo "\n" >> ./ProjectTree
|
@echo "\n" >> ./ProjectTree
|
||||||
@tree --dirsfirst >> ./ProjectTree
|
@tree --dirsfirst >> ./ProjectTree
|
||||||
@echo ${CL2}[$@] ${CL}Generated.${CL3}
|
@echo ${CL2}[$@] ${CL}Generated.${CL3}
|
||||||
|
|
||||||
|
$(KOBJDIR):
|
||||||
|
@mkdir -p $(KOBJDIR)
|
||||||
|
|
||||||
|
## LIB C MAKEFILE ------------------------------------------------------------ #
|
||||||
|
$(KOBJDIR)/libc/atoi.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR)
|
||||||
|
@mkdir -p $(shell dirname $@)
|
||||||
|
@$(KCC) -D_NEED_ATOI $< -o $@.1
|
||||||
|
@$(KCC) -D_NEED_ATOL $< -o $@.2
|
||||||
|
@$(KCC) -D_NEED_ATOU $< -o $@.3
|
||||||
|
@$(KCC) -D_NEED_ATOUL $< -o $@.4
|
||||||
|
@$(LD) -r $@.1 $@.2 $@.3 $@.4 -o $@
|
||||||
|
@rm -f $@.1 $@.2 $@.3 $@.4
|
||||||
|
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
||||||
|
|
||||||
|
$(KOBJDIR)/libc/itoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR)
|
||||||
|
@mkdir -p $(shell dirname $@)
|
||||||
|
@$(KCC) -D_NEED_ITOA $< -o $@.1
|
||||||
|
@$(KCC) -D_NEED_LTOA $< -o $@.2
|
||||||
|
@$(KCC) -D_NEED_UTOA $< -o $@.3
|
||||||
|
@$(KCC) -D_NEED_ULTOA $< -o $@.4
|
||||||
|
@$(LD) -r $@.1 $@.2 $@.3 $@.4 -o $@
|
||||||
|
@rm -f $@.1 $@.2 $@.3 $@.4
|
||||||
|
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
||||||
|
|
||||||
|
$(KOBJDIR)/libc/mem.o: $(KALEIDDIR)/libc/mem.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR)
|
||||||
|
@mkdir -p $(shell dirname $@)
|
||||||
|
@$(KCC) -fno-strict-aliasing $< -o $@
|
||||||
|
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
||||||
|
|
||||||
## MAIN MAKEFILE ------------------------------------------------------------- #
|
## MAIN MAKEFILE ------------------------------------------------------------- #
|
||||||
|
|
||||||
.PHONY: test
|
$(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR)
|
||||||
|
@mkdir -p $(shell dirname $@)
|
||||||
|
@$(KCC) $< -o $@
|
||||||
|
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
@qemu-system-x86_64 -m 4G -hda $(BUILDDIR)/bin/disk.img \
|
@qemu-system-x86_64 -m 4G -hda $(BUILDDIR)/bin/disk.img \
|
||||||
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
|
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
|
||||||
.PHONY: test32
|
|
||||||
test32: all
|
test32: all
|
||||||
@qemu-system-i386 -hda $(BUILDDIR)/bin/disk.img -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
|
@qemu-system-i386 -hda $(BUILDDIR)/bin/disk.img -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
|
||||||
|
|
||||||
.PHONY: debug
|
|
||||||
debug: all
|
debug: all
|
||||||
@qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot \
|
@qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot \
|
||||||
-no-shutdown -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
|
-no-shutdown -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
|
||||||
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > $(BUILDDIR)/kaleid64_disasm.asm
|
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > $(BUILDDIR)/kaleid64_disasm.asm
|
||||||
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > $(BUILDDIR)/kaleid32_disasm.asm
|
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > $(BUILDDIR)/kaleid32_disasm.asm
|
||||||
|
|
||||||
.PHONY: gdb
|
|
||||||
gdb: all
|
gdb: all
|
||||||
@qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot \
|
@qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot \
|
||||||
-no-shutdown -d cpu_reset,guest_errors,pcall,int -s 2> $(BUILDDIR)/qemu.log &
|
-no-shutdown -d cpu_reset,guest_errors,pcall,int -s 2> $(BUILDDIR)/qemu.log &
|
||||||
|
@ -218,7 +168,6 @@ gdb: all
|
||||||
-ex "symbol-file $(BINDIR)/kaleid" \
|
-ex "symbol-file $(BINDIR)/kaleid" \
|
||||||
-ex "break BtStartKern" \
|
-ex "break BtStartKern" \
|
||||||
|
|
||||||
.PHONY: install_mbr
|
|
||||||
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}
|
||||||
|
@ -227,30 +176,31 @@ install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg
|
||||||
@rmdir $(BINDIR)/disk
|
@rmdir $(BINDIR)/disk
|
||||||
@echo ${CL2}[$@] ${CL}Success.${CL3}
|
@echo ${CL2}[$@] ${CL}Success.${CL3}
|
||||||
|
|
||||||
.PHONY: clean
|
dust:
|
||||||
|
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
|
||||||
|
@rm -Rf $(OBJDIR)/*
|
||||||
|
@echo ${CL2}[$@] ${CL}Cleaned.${CL3}
|
||||||
clean:
|
clean:
|
||||||
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
|
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
|
||||||
@rm -Rvf ./ProjectTree
|
@rm -Rvf ./ProjectTree $(BUILDDIR)/*.log
|
||||||
@rm -Rvf $(BINDIR)/* $(OBJDIR)/*.o \
|
@rm -Rvf $(BINDIR)/* $(OBJDIR)/*
|
||||||
$(OBJDIR)/*/*.o $(OBJDIR)/*/*.x86_64 $(OBJDIR)/*/*/*.o
|
@echo ${CL2}[$@] ${CL}Cleaned.${CL3}
|
||||||
@echo ${CL2}[[$@]] ${CL}Cleaned.${CL3}
|
|
||||||
|
|
||||||
$(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64
|
$(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64
|
||||||
@echo ${CL2}[$@] ${NC}Objcopy...${CL3}
|
@echo ${CL2}[$@] ${NC}Objcopy...${CL3}
|
||||||
@x86_64-elf-objcopy -I elf64-x86-64 -O elf32-i386 $(LOBJDIR)/kaleid.x86_64 $(BINDIR)/kaleid
|
@$(OBJCOPY) -I elf64-x86-64 -O elf32-i386 $(LOBJDIR)/kaleid.x86_64 $(BINDIR)/kaleid
|
||||||
@echo ${CL2}[$@] ${CL}Success.${CL3}
|
@echo ${CL2}[$@] ${CL}Success.${CL3}
|
||||||
|
|
||||||
$(LOBJDIR)/kaleid.x86_64: $(kal_kern_obj) $(kal_com_obj) $(LOBJDIR)/loader.o
|
$(LOBJDIR)/kaleid.x86_64: $(LibCObj) $(KernObj) $(LOBJDIR)/loader.o
|
||||||
@echo ${CL2}[$@] ${NC}Linking kernel objects...${CL3}
|
@echo ${CL2}[$@] ${NC}Linking kernel objects...${CL3}
|
||||||
@$(LD) $(LDFLAGS) -T $(BUILDDIR)/kernel.ld \
|
@$(LD) $(LDFLAGS) -T $(BUILDDIR)/kernel.ld \
|
||||||
$(LOBJDIR)/loader.o \
|
$(LOBJDIR)/loader.o $(KernObj) $(LibCObj) \
|
||||||
$(KOBJDIR)/*.o \
|
|
||||||
$(KOBJDIR)/kernel/*.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 $(LOADERDIR)/*/*.inc
|
$(LOBJDIR)/loader.o: $(LOADERDIR)/loader.asm $(LOADERDIR)/*/*.inc
|
||||||
@echo ${CL2}[$@] ${NC}Making loader...${CL3}
|
@echo ${CL2}[$@] ${NC}Making loader...${CL3}
|
||||||
|
@mkdir -p $(shell dirname $@)
|
||||||
@$(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}
|
||||||
|
|
||||||
|
@ -261,10 +211,9 @@ $(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh
|
||||||
@make install_mbr
|
@make install_mbr
|
||||||
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
|
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
|
||||||
|
|
||||||
.PHONY:OS/K
|
|
||||||
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, $(mode) mode.${CL3}
|
||||||
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
|
-@$(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
|
||||||
|
|
207
ProjectTree
207
ProjectTree
|
@ -55,116 +55,127 @@
|
||||||
│ │ │ ├── kaleid.x86_64
|
│ │ │ ├── kaleid.x86_64
|
||||||
│ │ │ └── loader.o
|
│ │ │ └── loader.o
|
||||||
│ │ └── kaleid
|
│ │ └── kaleid
|
||||||
|
│ │ ├── extras
|
||||||
|
│ │ │ ├── argv.o
|
||||||
|
│ │ │ └── prog.o
|
||||||
│ │ ├── kernel
|
│ │ ├── kernel
|
||||||
|
│ │ │ ├── cpu
|
||||||
|
│ │ │ │ ├── cpuid.o
|
||||||
|
│ │ │ │ └── idt.o
|
||||||
|
│ │ │ ├── init
|
||||||
|
│ │ │ │ ├── init.o
|
||||||
|
│ │ │ │ └── table.o
|
||||||
|
│ │ │ ├── io
|
||||||
|
│ │ │ │ ├── cursor.o
|
||||||
|
│ │ │ │ └── vga.o
|
||||||
|
│ │ │ ├── ke
|
||||||
|
│ │ │ │ ├── log.o
|
||||||
|
│ │ │ │ └── panic.o
|
||||||
|
│ │ │ ├── mm
|
||||||
|
│ │ │ │ ├── gdt.o
|
||||||
|
│ │ │ │ ├── heap.o
|
||||||
|
│ │ │ │ ├── malloc.o
|
||||||
|
│ │ │ │ └── map.o
|
||||||
|
│ │ │ └── ps
|
||||||
|
│ │ │ └── sched.o
|
||||||
|
│ │ ├── libbuf
|
||||||
│ │ │ ├── bprint.o
|
│ │ │ ├── bprint.o
|
||||||
│ │ │ ├── bput.o
|
│ │ │ ├── bput.o
|
||||||
│ │ │ ├── buf.o
|
│ │ │ └── buf.o
|
||||||
│ │ │ ├── cpuid.o
|
│ │ └── libc
|
||||||
│ │ │ ├── cursor.o
|
│ │ ├── atoi.o
|
||||||
│ │ │ ├── gdt.o
|
│ │ ├── atoi.o.1
|
||||||
│ │ │ ├── heap.o
|
│ │ ├── atoi.o.2
|
||||||
│ │ │ ├── init.o
|
│ │ ├── atoi.o.3
|
||||||
│ │ │ ├── log.o
|
│ │ ├── atoi.o.4
|
||||||
│ │ │ ├── malloc.o
|
│ │ ├── ctype.o
|
||||||
│ │ │ ├── map.o
|
│ │ ├── itoa.o
|
||||||
│ │ │ ├── panic.o
|
│ │ ├── itoa.o.1
|
||||||
│ │ │ ├── sched.o
|
│ │ ├── itoa.o.2
|
||||||
│ │ │ ├── table.o
|
│ │ ├── itoa.o.3
|
||||||
│ │ │ └── vga.o
|
│ │ ├── itoa.o.4
|
||||||
│ │ ├── argv.o
|
│ │ ├── mem.o
|
||||||
│ │ ├── atoi.o
|
│ │ ├── rand.o
|
||||||
│ │ ├── atol.o
|
│ │ ├── sprintf.o
|
||||||
│ │ ├── atoul.o
|
│ │ ├── status.o
|
||||||
│ │ ├── atou.o
|
│ │ ├── string.o
|
||||||
│ │ ├── ctype.o
|
│ │ └── strtol.o
|
||||||
│ │ ├── itoa.o
|
|
||||||
│ │ ├── ltoa.o
|
|
||||||
│ │ ├── mem.o
|
|
||||||
│ │ ├── prog.o
|
|
||||||
│ │ ├── rand.o
|
|
||||||
│ │ ├── sprintf.o
|
|
||||||
│ │ ├── status.o
|
|
||||||
│ │ ├── string.o
|
|
||||||
│ │ ├── strtol.o
|
|
||||||
│ │ ├── ultoa.o
|
|
||||||
│ │ └── utoa.o
|
|
||||||
│ ├── grub.log
|
│ ├── grub.log
|
||||||
│ └── kernel.ld
|
│ └── kernel.ld
|
||||||
|
├── include
|
||||||
|
│ ├── base
|
||||||
|
│ │ ├── assert.h
|
||||||
|
│ │ ├── bdefs.h
|
||||||
|
│ │ ├── crtlib.h
|
||||||
|
│ │ ├── errno.h
|
||||||
|
│ │ ├── limits.h
|
||||||
|
│ │ ├── masks.h
|
||||||
|
│ │ └── types.h
|
||||||
|
│ ├── extras
|
||||||
|
│ │ ├── argv.h
|
||||||
|
│ │ ├── buf.h
|
||||||
|
│ │ ├── list.h
|
||||||
|
│ │ ├── locks.h
|
||||||
|
│ │ ├── malloc.h
|
||||||
|
│ │ └── prog.h
|
||||||
|
│ ├── kernel
|
||||||
|
│ │ ├── base.h
|
||||||
|
│ │ ├── boot.h
|
||||||
|
│ │ ├── cpu.h
|
||||||
|
│ │ ├── heap.h
|
||||||
|
│ │ ├── iomisc.h
|
||||||
|
│ │ ├── mboot.h
|
||||||
|
│ │ ├── mm.h
|
||||||
|
│ │ ├── panic.h
|
||||||
|
│ │ ├── proc.h
|
||||||
|
│ │ └── sched.h
|
||||||
|
│ ├── kalbase.h
|
||||||
|
│ ├── kaleid.h
|
||||||
|
│ └── kalext.h
|
||||||
├── kaleid
|
├── kaleid
|
||||||
│ ├── crtlib
|
|
||||||
│ │ ├── atoi.c
|
|
||||||
│ │ ├── ctype.c
|
|
||||||
│ │ ├── itoa.c
|
|
||||||
│ │ ├── mem.c
|
|
||||||
│ │ ├── rand.c
|
|
||||||
│ │ ├── sprintf.c
|
|
||||||
│ │ ├── status.c
|
|
||||||
│ │ ├── string.c
|
|
||||||
│ │ └── strtol.c
|
|
||||||
│ ├── extras
|
│ ├── extras
|
||||||
│ │ ├── argv.c
|
│ │ ├── argv.c
|
||||||
│ │ └── prog.c
|
│ │ └── prog.c
|
||||||
│ ├── include
|
│ ├── kernel
|
||||||
│ │ ├── base
|
│ │ ├── cpu
|
||||||
│ │ │ ├── assert.h
|
│ │ │ ├── cpuid.c
|
||||||
│ │ │ ├── bdefs.h
|
│ │ │ └── idt.c
|
||||||
│ │ │ ├── crtlib.h
|
│ │ ├── init
|
||||||
│ │ │ ├── errno.h
|
│ │ │ ├── init.c
|
||||||
│ │ │ ├── limits.h
|
│ │ │ └── table.c
|
||||||
│ │ │ ├── masks.h
|
│ │ ├── io
|
||||||
│ │ │ └── types.h
|
│ │ │ ├── ata.inc
|
||||||
│ │ ├── extras
|
│ │ │ ├── cursor.c
|
||||||
│ │ │ ├── argv.h
|
│ │ │ └── vga.c
|
||||||
│ │ │ ├── list.h
|
│ │ ├── ke
|
||||||
│ │ │ ├── locks.h
|
│ │ │ ├── log.c
|
||||||
│ │ │ ├── malloc.h
|
│ │ │ └── panic.c
|
||||||
│ │ │ └── prog.h
|
│ │ ├── mm
|
||||||
│ │ ├── kernel
|
│ │ │ ├── gdt.c
|
||||||
│ │ │ ├── base.h
|
│ │ │ ├── heap.c
|
||||||
│ │ │ ├── buf.h
|
│ │ │ ├── malloc.c
|
||||||
│ │ │ ├── cpu.h
|
│ │ │ └── map.c
|
||||||
│ │ │ ├── heap.h
|
│ │ └── ps
|
||||||
│ │ │ ├── iomisc.h
|
│ │ └── sched.c
|
||||||
│ │ │ ├── log.h
|
│ ├── libbuf
|
||||||
│ │ │ ├── mboot.h
|
│ │ ├── bprint.c
|
||||||
│ │ │ ├── mm.h
|
│ │ ├── bput.c
|
||||||
│ │ │ ├── panic.h
|
│ │ └── buf.c
|
||||||
│ │ │ ├── proc.h
|
│ └── libc
|
||||||
│ │ │ └── sched.h
|
│ ├── atoi.c
|
||||||
│ │ ├── kalbase.h
|
│ ├── ctype.c
|
||||||
│ │ ├── kaleid.h
|
│ ├── itoa.c
|
||||||
│ │ └── kalext.h
|
│ ├── mem.c
|
||||||
│ └── kernel
|
│ ├── rand.c
|
||||||
│ ├── buf
|
│ ├── sprintf.c
|
||||||
│ │ ├── bprint.c
|
│ ├── status.c
|
||||||
│ │ ├── bput.c
|
│ ├── string.c
|
||||||
│ │ └── buf.c
|
│ └── strtol.c
|
||||||
│ ├── cpu
|
|
||||||
│ │ ├── cpuid.c
|
|
||||||
│ │ └── idt.c
|
|
||||||
│ ├── init
|
|
||||||
│ │ ├── init.c
|
|
||||||
│ │ └── table.c
|
|
||||||
│ ├── io
|
|
||||||
│ │ ├── ata.inc
|
|
||||||
│ │ ├── cursor.c
|
|
||||||
│ │ └── vga.c
|
|
||||||
│ ├── ke
|
|
||||||
│ │ ├── log.c
|
|
||||||
│ │ └── panic.c
|
|
||||||
│ ├── mm
|
|
||||||
│ │ ├── gdt.c
|
|
||||||
│ │ ├── heap.c
|
|
||||||
│ │ ├── malloc.c
|
|
||||||
│ │ └── map.c
|
|
||||||
│ └── proc
|
|
||||||
│ ├── Makefile
|
|
||||||
│ └── sched.c
|
|
||||||
├── AUTHORS
|
├── AUTHORS
|
||||||
├── ChangeLog
|
├── ChangeLog
|
||||||
├── COPYING
|
├── COPYING
|
||||||
├── Makefile
|
├── Makefile
|
||||||
├── ProjectTree
|
├── ProjectTree
|
||||||
└── Readme.md
|
└── README.md
|
||||||
|
|
||||||
28 directories, 114 files
|
37 directories, 116 files
|
||||||
|
|
|
@ -11,6 +11,8 @@ For changelog, see [ChangeLog](ChangeLog)
|
||||||
|
|
||||||
For structure of the sources, see [ProjectTree](ProjectTree)
|
For structure of the sources, see [ProjectTree](ProjectTree)
|
||||||
|
|
||||||
|
For our IRC channel, see `#os.k-devel` on [Freenode](https://webchat.freenode.net)
|
||||||
|
|
||||||
Note that every file within OS/K is written using spaces for tabulation, with each
|
Note that every file within OS/K is written using spaces for tabulation, with each
|
||||||
tabulation being 4 spaces long.
|
tabulation being 4 spaces long.
|
||||||
|
|
||||||
|
@ -20,10 +22,10 @@ To compile this project from sources, you must first install the dependencies
|
||||||
|
|
||||||
```
|
```
|
||||||
apt update && apt upgrade
|
apt update && apt upgrade
|
||||||
apt install grub-pc dosfstools make nasm qemu
|
apt install grub-pc-bin dosfstools make nasm qemu tree
|
||||||
```
|
```
|
||||||
|
|
||||||
You also need to have the [x86-64 ELF gcc cross-compiler](https://www.os-k.eu/build-tools/cross-cc.tar.xz) in `/opt/cross-cc`.
|
You also need to have the [x86-64 ELF gcc cross-compiler](https://www.os-k.eu/build-tools/cross-cc.tar.xz) and its ``bin`` directory in your PATH.
|
||||||
|
|
||||||
To compile, simply use at the root of this project :
|
To compile, simply use at the root of this project :
|
||||||
```
|
```
|
||||||
|
@ -34,3 +36,4 @@ To compile and test, simply use at the root of this project :
|
||||||
```
|
```
|
||||||
make test
|
make test
|
||||||
```
|
```
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
|
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
#=----------------------------------------------------------------------------=#
|
#=----------------------------------------------------------------------------=#
|
||||||
|
|
||||||
set timeout=5
|
set timeout=0
|
||||||
|
|
||||||
set default=0 #Set the default menu entry
|
set default=0 #Set the default menu entry
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,12 @@
|
||||||
// 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 _KALEXTRAS_LOCKS_H
|
||||||
#include <kernel/base.h>
|
#include <extras/locks.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _KALKERN_BUF_H
|
#ifndef _KALEXTRAS_BUF_H
|
||||||
#define _KALKERN_BUF_H
|
#define _KALEXTRAS_BUF_H
|
||||||
|
|
||||||
//
|
//
|
||||||
// Buffer flags
|
// Buffer flags
|
||||||
|
@ -55,6 +55,7 @@ enum
|
||||||
BS_WRONLY, // Only for writing
|
BS_WRONLY, // Only for writing
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct Buffer_t Buffer_t;
|
||||||
typedef error_t (*BFlusher_t)(Buffer_t *);
|
typedef error_t (*BFlusher_t)(Buffer_t *);
|
||||||
|
|
||||||
struct Buffer_t
|
struct Buffer_t
|
|
@ -35,7 +35,7 @@ extern "C" {
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
// Flags for KalAllocMemory
|
// Flags for KalAllocMemoryEx
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
// Return zeroed-out memory
|
// Return zeroed-out memory
|
||||||
|
@ -51,17 +51,18 @@ enum
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
// Default memory allocation alignment (in bytes)
|
// Default memory allocation alignment (in bytes)
|
||||||
// Asking KalAllocMemory for an alignment of 0
|
// Asking KalAllocMemoryEx for an alignment of 0
|
||||||
// will cause it to use this value
|
// will cause it to use this value
|
||||||
M_DEFAULT_ALIGNMENT = alignof(QWORD),
|
M_DEFAULT_ALIGNMENT = alignof(QWORD),
|
||||||
|
|
||||||
// Minimal memory allocation alignment (in bytes)
|
// Minimal memory allocation alignment (in bytes)
|
||||||
// Asking KalAllocMemory for an nonzero alignment
|
// Asking KalAllocMemoryEx for an nonzero alignment
|
||||||
// lower than this value will cause a EALIGN error
|
// lower than this value will cause a EALIGN error
|
||||||
M_MINIMAL_ALIGNMENT = M_DEFAULT_ALIGNMENT
|
M_MINIMAL_ALIGNMENT = M_DEFAULT_ALIGNMENT
|
||||||
};
|
};
|
||||||
|
|
||||||
error_t KalAllocMemory(void **ptr, size_t req, int flags, size_t align);
|
error_t KalAllocMemoryEx(void **ptr, size_t req, int flags, size_t align);
|
||||||
|
error_t KalAllocMemory(void **ptr, size_t req);
|
||||||
error_t KalFreeMemory(void *ptr);
|
error_t KalFreeMemory(void *ptr);
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
|
@ -0,0 +1,137 @@
|
||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
// GNU GPL OS/K //
|
||||||
|
// //
|
||||||
|
// Desc: Kaleid kernel base include file //
|
||||||
|
// //
|
||||||
|
// //
|
||||||
|
// 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 _KALBASE_H
|
||||||
|
#include <kalbase.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#error "Kaleid's kernel won't compile in C++"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _KALKERN_BASE_H
|
||||||
|
#define _KALKERN_BASE_H
|
||||||
|
|
||||||
|
//------------------------------------------//
|
||||||
|
|
||||||
|
typedef struct Lock_t Lock_t;
|
||||||
|
typedef struct Buffer_t Buffer_t;
|
||||||
|
typedef struct Thread_t Thread_t;
|
||||||
|
typedef struct Process_t Process_t;
|
||||||
|
typedef struct BootInfo_t BootInfo_t;
|
||||||
|
typedef struct ListHead_t ListHead_t;
|
||||||
|
typedef struct ListNode_t ListNode_t;
|
||||||
|
typedef struct Processor_t Processor_t;
|
||||||
|
|
||||||
|
typedef enum ProcState_t ProcState_t;
|
||||||
|
|
||||||
|
//------------------------------------------//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Holds all CPU-local variables
|
||||||
|
//
|
||||||
|
struct Processor_t
|
||||||
|
{
|
||||||
|
// CPU number, index in CPU list
|
||||||
|
int index;
|
||||||
|
|
||||||
|
// CPU APIC id
|
||||||
|
int apicId;
|
||||||
|
|
||||||
|
// CPU Vendor String (always 12 characters)
|
||||||
|
char vendorStr[12];
|
||||||
|
|
||||||
|
// CPU Model code (enum in cpu.h)
|
||||||
|
int modelCode;
|
||||||
|
|
||||||
|
// CPU Features flag
|
||||||
|
uint featureFlag;
|
||||||
|
|
||||||
|
// Number of ticks since boot time
|
||||||
|
ulong ticks;
|
||||||
|
|
||||||
|
// Current process & thread
|
||||||
|
Process_t *process;
|
||||||
|
Thread_t *thread;
|
||||||
|
|
||||||
|
// Need re-schedule?
|
||||||
|
bool needReSched;
|
||||||
|
|
||||||
|
// Is preemption ON? ("PREEMPT_ON" in sched.h)
|
||||||
|
ulong preemptCount;
|
||||||
|
|
||||||
|
// List heads for the four priority classes
|
||||||
|
ListHead_t *idlePrioProcs;
|
||||||
|
ListHead_t *reglPrioProcs;
|
||||||
|
ListHead_t *servPrioProcs;
|
||||||
|
ListHead_t *timeCritProcs;
|
||||||
|
};
|
||||||
|
|
||||||
|
//------------------------------------------//
|
||||||
|
|
||||||
|
#ifndef NCPUS
|
||||||
|
#define NCPUS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Current CPU number
|
||||||
|
#define _KeCurCPU 0
|
||||||
|
|
||||||
|
extern int KeCPUCount;
|
||||||
|
extern volatile Processor_t *KeCurCPU;
|
||||||
|
extern Processor_t _KeCPUTable[NCPUS];
|
||||||
|
|
||||||
|
//------------------------------------------//
|
||||||
|
|
||||||
|
#define DEC_PER_CPU(pref, name, field, type) \
|
||||||
|
static inline type pref##Get##name() { return KeGetCurCPU()->field; } \
|
||||||
|
static inline void _##pref##Set##name(type __val) \
|
||||||
|
{ KeGetCurCPU()->field = __val; }
|
||||||
|
|
||||||
|
#define BARRIER() \
|
||||||
|
do { \
|
||||||
|
asm volatile("": : :"memory"); \
|
||||||
|
__sync_synchronize(); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
//------------------------------------------//
|
||||||
|
|
||||||
|
error_t KernLog(const char *, ...);
|
||||||
|
|
||||||
|
#ifndef _NO_DEBUG
|
||||||
|
void DebugLog(const char *, ...);
|
||||||
|
#else
|
||||||
|
#define DebugLog(fmt, ...) ((void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------//
|
||||||
|
|
||||||
|
// Needed by basically everyone
|
||||||
|
#ifndef _KALEXTRAS_LOCKS_H
|
||||||
|
#include <extras/locks.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------//
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -22,88 +22,15 @@
|
||||||
// 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 _KALBASE_H
|
|
||||||
#include <kalbase.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#error "Kaleid's kernel won't compile in C++"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _KALKERN_BASE_H
|
#ifndef _KALKERN_BASE_H
|
||||||
#define _KALKERN_BASE_H
|
#include <kernel/base.h>
|
||||||
|
|
||||||
//------------------------------------------//
|
|
||||||
|
|
||||||
typedef struct Lock_t Lock_t;
|
|
||||||
typedef struct Buffer_t Buffer_t;
|
|
||||||
typedef struct Thread_t Thread_t;
|
|
||||||
typedef struct Process_t Process_t;
|
|
||||||
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;
|
|
||||||
|
|
||||||
//------------------------------------------//
|
|
||||||
// Multiprocessor misc. //
|
|
||||||
//------------------------------------------//
|
|
||||||
|
|
||||||
#ifndef NCPUS
|
|
||||||
#define NCPUS 1
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Current CPU number
|
#ifndef _KALKERN_BOOT_H
|
||||||
#define _KeCurCPU 0
|
#define _KALKERN_BOOT_H
|
||||||
|
|
||||||
// Process_t structure of current CPU
|
|
||||||
#define KeCurCPU (cpuTable[_KeCurCPU])
|
|
||||||
|
|
||||||
// Access the BootInfo_t structure
|
|
||||||
#define BtGetBootInfo(x) (bootTab.x)
|
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
//
|
|
||||||
// Holds all CPU-local variables
|
|
||||||
//
|
|
||||||
struct Processor_t
|
|
||||||
{
|
|
||||||
// CPU number, index in CPU list
|
|
||||||
int index;
|
|
||||||
|
|
||||||
// CPU APIC id
|
|
||||||
int apicId;
|
|
||||||
// CPU Vendor String (always 12 characters)
|
|
||||||
char vendorStr[12];
|
|
||||||
// CPU Model code (enum in cpu.h)
|
|
||||||
int modelCode;
|
|
||||||
// CPU Features flag
|
|
||||||
uint featureFlag;
|
|
||||||
|
|
||||||
// Number of ticks since boot time
|
|
||||||
ulong ticks;
|
|
||||||
|
|
||||||
// Current process & thread
|
|
||||||
Process_t *process;
|
|
||||||
Thread_t *thread;
|
|
||||||
|
|
||||||
// Need re-schedule?
|
|
||||||
bool needReSched;
|
|
||||||
|
|
||||||
// Is preemption ON? ("PREEMPT_ON" in sched.h)
|
|
||||||
ulong preemptCount;
|
|
||||||
|
|
||||||
// List heads for the four priority classes
|
|
||||||
ListHead_t *idlePrioProcs;
|
|
||||||
ListHead_t *reglPrioProcs;
|
|
||||||
ListHead_t *servPrioProcs;
|
|
||||||
ListHead_t *timeCritProcs;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define FB_EGA_TEXT 2
|
#define FB_EGA_TEXT 2
|
||||||
#define FB_INDEXED 0
|
#define FB_INDEXED 0
|
||||||
#define FB_RGB 1
|
#define FB_RGB 1
|
||||||
|
@ -111,7 +38,7 @@ struct Processor_t
|
||||||
|
|
||||||
struct BootInfo_t
|
struct BootInfo_t
|
||||||
{
|
{
|
||||||
// The Bootloader infos (GRUB in our case)
|
// The Bootloader infos
|
||||||
struct {
|
struct {
|
||||||
ushort valid;
|
ushort valid;
|
||||||
uint grubFlags; //flags
|
uint grubFlags; //flags
|
||||||
|
@ -176,28 +103,14 @@ struct BootInfo_t
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
extern volatile int cpuCount;
|
extern volatile BootInfo_t BtBootTab;
|
||||||
extern volatile BootInfo_t bootTab;
|
|
||||||
extern volatile Processor_t cpuTable[NCPUS];
|
|
||||||
|
|
||||||
//------------------------------------------//
|
#define BtLoaderInfo (BtBootTab.btldr)
|
||||||
|
#define BtDrivesInfo (BtBootTab.drives)
|
||||||
#define DEC_PER_CPU(pref, name, field, type) \
|
#define BtMemoryInfo (BtBootTab.memory)
|
||||||
static inline type pref##Get##name() { return KeGetCurCPU().field; } \
|
#define BtVideoInfo (BtBootTab.video)
|
||||||
static inline void _##pref##Set##name(type __val) \
|
#define BtFirmwareInfo (BtBootTab.firmware)
|
||||||
{ KeGetCurCPU().field = __val; }
|
|
||||||
|
|
||||||
#define BARRIER() do{\
|
|
||||||
asm volatile("": : :"memory");__sync_synchronize();}while(0)
|
|
||||||
|
|
||||||
//------------------------------------------//
|
|
||||||
|
|
||||||
// Needed by basically everyone
|
|
||||||
#ifndef _KALEXTRAS_LOCKS_H
|
|
||||||
#include <extras/locks.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -66,7 +66,7 @@ struct GdtEntry_t
|
||||||
uchar access; // determine what ring this segment can be used in
|
uchar access; // determine what ring this segment can be used in
|
||||||
uchar granularity;
|
uchar granularity;
|
||||||
uchar highBase; // last 8 bits
|
uchar highBase; // last 8 bits
|
||||||
} __attribute__((packed));
|
} __attribute__((__packed__));
|
||||||
|
|
||||||
// The gdt pointer
|
// The gdt pointer
|
||||||
struct GdtPtr_t
|
struct GdtPtr_t
|
||||||
|
@ -74,7 +74,7 @@ struct GdtPtr_t
|
||||||
uchar limit; // upper 16 bits
|
uchar limit; // upper 16 bits
|
||||||
ushort base; // address of the first entry
|
ushort base; // address of the first entry
|
||||||
}
|
}
|
||||||
__attribute__((packed));
|
__attribute__((__packed__));
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
#define PANICSTR_SIZE 1024
|
#define PANICSTR_SIZE 1024
|
||||||
extern volatile char KePanicStr[PANICSTR_SIZE];
|
extern volatile bool KeIsPanicking;
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
|
@ -70,15 +70,12 @@ struct Process_t
|
||||||
|
|
||||||
// Scheduler internals
|
// Scheduler internals
|
||||||
ListNode_t *schedNode;
|
ListNode_t *schedNode;
|
||||||
|
|
||||||
// Standard output/debug
|
|
||||||
Terminal_t *stdOut, *stdDbg;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
#define PsCurProc (KeCurCPU.process)
|
#define PsCurProc (KeCurCPU->process)
|
||||||
#define PsCurThread (KeCurCPU.thread)
|
#define PsCurThread (KeCurCPU->thread)
|
||||||
|
|
||||||
//DEC_PER_CPU(Ps, CurProc, process, Process_t *);
|
//DEC_PER_CPU(Ps, CurProc, process, Process_t *);
|
||||||
//DEC_PER_CPU(Ps, CurThread, thread, Thread_t *);
|
//DEC_PER_CPU(Ps, CurThread, thread, Thread_t *);
|
|
@ -61,10 +61,10 @@ extern const char *PsPrioClassesNames[];
|
||||||
// Re-scheduling and preemption
|
// Re-scheduling and preemption
|
||||||
// XXX atomic operations
|
// XXX atomic operations
|
||||||
//
|
//
|
||||||
#define PsRequestReSched() (++KeCurCPU.needReSched)
|
#define PsRequestReSched() (++KeCurCPU->needReSched)
|
||||||
#define PsDisablePreemption() (++KeCurCPU.preemptCount)
|
#define PsDisablePreemption() (++KeCurCPU->preemptCount)
|
||||||
#define PsEnablePreemption() do { assert(KeCurCPU.preemptCount > 0); \
|
#define PsEnablePreemption() do { assert(KeCurCPU->preemptCount > 0); \
|
||||||
--KeCurCPU.preemptCount; } while(0)
|
--KeCurCPU->preemptCount; } while(0)
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
// GNU GPL OS/K //
|
|
||||||
// //
|
|
||||||
// Desc: KernLog() and DebugLog() //
|
|
||||||
// //
|
|
||||||
// //
|
|
||||||
// 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_LOG_H
|
|
||||||
#define _KALKERN_LOG_H
|
|
||||||
|
|
||||||
error_t KernLog(const char *, ...);
|
|
||||||
|
|
||||||
#ifndef _NO_DEBUG
|
|
||||||
void DebugLog(const char *, ...);
|
|
||||||
#else // _NO_DEBUG
|
|
||||||
#define DebugLog(fmt, ...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,373 +0,0 @@
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
// GNU GPL OS/K //
|
|
||||||
// //
|
|
||||||
// Desc: Buffer library //
|
|
||||||
// //
|
|
||||||
// //
|
|
||||||
// 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/buf.h>
|
|
||||||
|
|
||||||
extern error_t bputc(Buffer_t *buf, uchar ch);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Prints formatted string on buf according to fmt
|
|
||||||
//
|
|
||||||
error_t BPrintOnBuf(Buffer_t *buf, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
error_t rc;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
rc = BPrintOnBufV(buf, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Prints 0 for octal, 0x for hexadecimal, 0b for binary
|
|
||||||
//
|
|
||||||
static error_t bprinthash(Buffer_t *buf, int base, int cap)
|
|
||||||
{
|
|
||||||
error_t rc;
|
|
||||||
|
|
||||||
if (base != 2 && base != 8 && base != 16) {
|
|
||||||
return EOK;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = bputc(buf, '0');
|
|
||||||
|
|
||||||
if (!rc && base != 8) {
|
|
||||||
rc = bputc(buf, (base==2 ? 'b' : (cap ? 'X' : 'x')));
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static error_t bdopadding(Buffer_t *buf, size_t width, size_t len,
|
|
||||||
char filler)
|
|
||||||
{
|
|
||||||
error_t rc = EOK;
|
|
||||||
|
|
||||||
for (; !rc && width > len ; width--) {
|
|
||||||
rc = bputc(buf, filler);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define bdoconvrt(pref, type, vtype) do { \
|
|
||||||
type i_##type = (type)va_arg(ap, vtype); \
|
|
||||||
pref##toa(i_##type, s, base); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
// Increase fmt while parsing a modifier
|
|
||||||
#define fmtnext() do{fmt++;if(*fmt==0){rc=EINVAL;goto leave;}}while(0)
|
|
||||||
|
|
||||||
//
|
|
||||||
// Actually does BPrintOnBuf's job
|
|
||||||
// Quite a long function
|
|
||||||
//
|
|
||||||
error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
error_t rc = EOK;
|
|
||||||
int tmpwidth;
|
|
||||||
size_t width;
|
|
||||||
char type;
|
|
||||||
|
|
||||||
uchar uch;
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
// Conversion buffer
|
|
||||||
char convbuf[100];
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
// Flags
|
|
||||||
int plus, minus, space, zero, hash;
|
|
||||||
|
|
||||||
// Length modifiers
|
|
||||||
int l, h, hh;
|
|
||||||
|
|
||||||
// Signed
|
|
||||||
bool sgn;
|
|
||||||
|
|
||||||
// Capital digits
|
|
||||||
bool cap;
|
|
||||||
|
|
||||||
// Base
|
|
||||||
int base;
|
|
||||||
|
|
||||||
assert(buf && buf->initDone == INITOK);
|
|
||||||
|
|
||||||
if (!buf) return EINVAL;
|
|
||||||
if (buf->state != BS_RDWR && buf->state != BS_WRONLY) {
|
|
||||||
return EBADF;
|
|
||||||
}
|
|
||||||
|
|
||||||
ExAcquireLock(&buf->lock);
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
// We come back here after dealing with a modifier
|
|
||||||
loop:
|
|
||||||
|
|
||||||
// Deal with all non-'%' characters
|
|
||||||
for (; *fmt && *fmt != '%' ; fmt++) {
|
|
||||||
rc = bputc(buf, *fmt);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Job's done / something bad happened
|
|
||||||
if (rc || !*fmt) goto leave;
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
//
|
|
||||||
// %[parameter][flags][width|*][.precision][length]type
|
|
||||||
// We aren't dealing with parameters and float stuff just yet
|
|
||||||
//
|
|
||||||
|
|
||||||
// Skip the '%'
|
|
||||||
fmtnext();
|
|
||||||
|
|
||||||
// "%%" modifier
|
|
||||||
if (*fmt == '%') {
|
|
||||||
rc = bputc(buf, '%');
|
|
||||||
|
|
||||||
if (rc > 0) goto leave;
|
|
||||||
else {
|
|
||||||
fmt++;
|
|
||||||
goto loop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset everything
|
|
||||||
width = 0;
|
|
||||||
cap = sgn = 0;
|
|
||||||
l = h = hh = 0;
|
|
||||||
plus = minus = space = zero = hash = 0;
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Flags field
|
|
||||||
//
|
|
||||||
while (1) {
|
|
||||||
if (*fmt == '#') hash++;
|
|
||||||
else if (*fmt == '0') zero++;
|
|
||||||
else if (*fmt == '+') plus++;
|
|
||||||
else if (*fmt == '-') minus++;
|
|
||||||
else if (*fmt == ' ') space++;
|
|
||||||
else break;
|
|
||||||
fmtnext();
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Width field
|
|
||||||
// A width field of zero is ignored
|
|
||||||
//
|
|
||||||
|
|
||||||
// '*' means we should extract it from the argument list
|
|
||||||
if (*fmt == '*') {
|
|
||||||
fmtnext();
|
|
||||||
tmpwidth = va_arg(ap, int);
|
|
||||||
|
|
||||||
// A width below 0 activates the "minus" flag
|
|
||||||
if (tmpwidth < 0) {
|
|
||||||
width = -tmpwidth;
|
|
||||||
minus++;
|
|
||||||
} else {
|
|
||||||
width = tmpwidth;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Extract width field from fmt
|
|
||||||
while (isdigit(*fmt) && width < sizeof(convbuf)-10) {
|
|
||||||
width = 10 * width + (*fmt - '0');
|
|
||||||
fmtnext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (width > sizeof(convbuf)) {
|
|
||||||
rc = EINVAL;
|
|
||||||
goto leave;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Precision field
|
|
||||||
// Ignored until floats are implemented
|
|
||||||
// TODO before floats: %.XXXs
|
|
||||||
//
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Length field
|
|
||||||
//
|
|
||||||
while (1) {
|
|
||||||
if (*fmt == 'l' || *fmt == 'z') l++;
|
|
||||||
else if (*fmt == 'h') h++;
|
|
||||||
else break;
|
|
||||||
fmtnext();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Consistency check
|
|
||||||
assert(!(l > 0 && h > 0));
|
|
||||||
assert(!(l > 2 || h > 2));
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
//
|
|
||||||
// The type field
|
|
||||||
//
|
|
||||||
type = *fmt++;
|
|
||||||
|
|
||||||
// Characters
|
|
||||||
if (type == 'c') {
|
|
||||||
uch = (uchar)va_arg(ap, int);
|
|
||||||
bputc(buf, uch);
|
|
||||||
|
|
||||||
goto loop;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strings
|
|
||||||
else if (type == 's') {
|
|
||||||
s = va_arg(ap, char *);
|
|
||||||
|
|
||||||
if (s == NULL) s = "(null)";
|
|
||||||
|
|
||||||
for (; !rc && *s ; s++) {
|
|
||||||
rc = bputc(buf, (uchar)*s);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc > 0) goto leave;
|
|
||||||
goto loop;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decimal, unsigned decimal, hexadecimal, octal and binary numbers
|
|
||||||
else if (type == 'd' || type == 'i') { base = 10; sgn = 1; }
|
|
||||||
else if (type == 'X') { base = 16; cap = 1; }
|
|
||||||
else if (type == 'x') { base = 16; }
|
|
||||||
else if (type == 'u') { base = 10; }
|
|
||||||
else if (type == 'o') { base = 8; }
|
|
||||||
else if (type == 'b') { base = 2; }
|
|
||||||
|
|
||||||
// Pointers: %p = %#012x
|
|
||||||
// (48-bit pointers have width 12 at least)
|
|
||||||
else if (type == 'p') {
|
|
||||||
type = 'x'; base = 16; zero++; hash++; l++;
|
|
||||||
if (width < 12) width = 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unknown/unsupported modifier
|
|
||||||
else {
|
|
||||||
rc = EINVAL;
|
|
||||||
goto leave;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Numerical conversions
|
|
||||||
//
|
|
||||||
|
|
||||||
// We re-use s to iterate convbuf
|
|
||||||
s = convbuf;
|
|
||||||
|
|
||||||
if (!l) {
|
|
||||||
if (sgn) {
|
|
||||||
if (h == 0) bdoconvrt(i, int, int);
|
|
||||||
if (h == 1) bdoconvrt(i, short, int);
|
|
||||||
if (h == 2) bdoconvrt(i, char, int);
|
|
||||||
} else {
|
|
||||||
if (h == 0) bdoconvrt(u, uint, uint);
|
|
||||||
if (h == 1) bdoconvrt(u, ushort, uint);
|
|
||||||
if (h == 2) bdoconvrt(u, uchar, uint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
if (sgn) bdoconvrt(l, long, long);
|
|
||||||
else bdoconvrt(ul, ulong, ulong);
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Implement flags and %X, and prints
|
|
||||||
//
|
|
||||||
|
|
||||||
// Capital letter digits
|
|
||||||
if (base > 10 && cap) {
|
|
||||||
for (; *s ; s++)
|
|
||||||
if (islower(*s)) *s = toupper(*s);
|
|
||||||
|
|
||||||
// We use this "opportunity" to compute the length of s
|
|
||||||
len = s - convbuf;
|
|
||||||
|
|
||||||
// Reset s
|
|
||||||
s = convbuf;
|
|
||||||
}
|
|
||||||
else len = strlen(s);
|
|
||||||
|
|
||||||
// Adjust width
|
|
||||||
if (sgn && (plus || space)) width--;
|
|
||||||
else if (hash) width -= (base==8 ? 1 : ((base==2||base==16) ? 2 : 0));
|
|
||||||
|
|
||||||
// When padding with spaces, we pad before +/-'s etc
|
|
||||||
if (!minus && !zero && width > len)
|
|
||||||
bdopadding(buf, width, len, ' ');
|
|
||||||
|
|
||||||
// Deal with signs and the hash flag
|
|
||||||
if (*s == '-') { rc = bputc(buf, '-'); s++, len--; }
|
|
||||||
else if (sgn && plus) rc = bputc(buf, '+');
|
|
||||||
else if (sgn && space) rc = bputc(buf, ' ');
|
|
||||||
else bprinthash(buf, base, cap);
|
|
||||||
|
|
||||||
// Deal with padding by zeroes
|
|
||||||
// The 'minus' flag makes no sense with the 'zero' one
|
|
||||||
if (zero && width > len)
|
|
||||||
bdopadding(buf, width, len, '0');
|
|
||||||
|
|
||||||
//
|
|
||||||
// Output the actual number
|
|
||||||
//
|
|
||||||
for (; !rc && *s ; s++) {
|
|
||||||
rc = bputc(buf, (uchar)*s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 'minus' padding, only with spaces
|
|
||||||
if (minus && !zero && width > len)
|
|
||||||
bdopadding(buf, width, base, ' ');
|
|
||||||
|
|
||||||
if (rc > 0) goto leave;
|
|
||||||
|
|
||||||
// Continue parsing fmt
|
|
||||||
goto loop;
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
leave:
|
|
||||||
ExReleaseLock(&buf->lock);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
|
@ -26,11 +26,9 @@
|
||||||
#include <kernel/panic.h>
|
#include <kernel/panic.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
#include <kernel/heap.h>
|
#include <kernel/heap.h>
|
||||||
#include <kernel/buf.h>
|
#include <kernel/boot.h>
|
||||||
#include <kernel/log.h>
|
|
||||||
#include <kernel/mm.h>
|
#include <kernel/mm.h>
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// BootInfo_t initialization. It is necessary because grub will potentially be
|
// BootInfo_t initialization. It is necessary because grub will potentially be
|
||||||
// wiped since it is below 1MB.... And we must reorganize all that stuff.
|
// wiped since it is below 1MB.... And we must reorganize all that stuff.
|
||||||
|
@ -44,69 +42,69 @@ void BtInitBootInfo(multiboot_info_t *mbi)
|
||||||
KalAlwaysAssert(mbi);
|
KalAlwaysAssert(mbi);
|
||||||
|
|
||||||
//Retrieves the bootloader flags to ensure infos are valid
|
//Retrieves the bootloader flags to ensure infos are valid
|
||||||
BtGetBootInfo(btldr).grubFlags = mbi->flags;
|
BtLoaderInfo.grubFlags = mbi->flags;
|
||||||
|
|
||||||
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
|
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
|
||||||
BtGetBootInfo(btldr).grubName = (char*)(ulong)(mbi->boot_loader_name);
|
BtLoaderInfo.grubName = (char*)(ulong)(mbi->boot_loader_name);
|
||||||
BtGetBootInfo(btldr).kernelAddr = (void*)&MB_header;
|
BtLoaderInfo.kernelAddr = (void*)&MB_header;
|
||||||
BtGetBootInfo(btldr).kernelEndAddr = (void*)newKernelEnd;
|
BtLoaderInfo.kernelEndAddr = (void*)newKernelEnd;
|
||||||
BtGetBootInfo(btldr).valid = 1;
|
BtLoaderInfo.valid = 1;
|
||||||
}
|
}
|
||||||
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MODS) {
|
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_MODS) {
|
||||||
BtGetBootInfo(btldr).modulesCount = mbi->mods_count;
|
BtLoaderInfo.modulesCount = mbi->mods_count;
|
||||||
BtGetBootInfo(btldr).modulesAddr = (void*)(ulong)mbi->mods_addr;
|
BtLoaderInfo.modulesAddr = (void*)(ulong)mbi->mods_addr;
|
||||||
}
|
}
|
||||||
//Retrieves the drives informations
|
//Retrieves the drives informations
|
||||||
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_DRIVE_INFO) {
|
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_DRIVE_INFO) {
|
||||||
BtGetBootInfo(drives).bufferLength = mbi->drives_length;
|
BtBootTab.drives.bufferLength = mbi->drives_length;
|
||||||
BtGetBootInfo(drives).bufferAddr = (void*)(ulong)mbi->drives_addr;
|
BtBootTab.drives.bufferAddr = (void*)(ulong)mbi->drives_addr;
|
||||||
BtGetBootInfo(drives).bufferValid = 1;
|
BtBootTab.drives.bufferValid = 1;
|
||||||
}
|
}
|
||||||
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_BOOTDEV) {
|
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_BOOTDEV) {
|
||||||
BtGetBootInfo(drives).bootDrv = mbi->boot_device;
|
BtBootTab.drives.bootDrv = mbi->boot_device;
|
||||||
BtGetBootInfo(drives).drvValid = 1;
|
BtBootTab.drives.drvValid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Retrieves the memory informations
|
//Retrieves the memory informations
|
||||||
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEMORY) {
|
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_MEMORY) {
|
||||||
BtGetBootInfo(memory).lowMemory = mbi->mem_lower;
|
BtMemoryInfo.lowMemory = mbi->mem_lower;
|
||||||
BtGetBootInfo(memory).upMemory = mbi->mem_upper;
|
BtMemoryInfo.upMemory = mbi->mem_upper;
|
||||||
BtGetBootInfo(memory).memValid = 1;
|
BtMemoryInfo.memValid = 1;
|
||||||
}
|
}
|
||||||
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_MEM_MAP) {
|
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_MEM_MAP) {
|
||||||
BtGetBootInfo(memory).mapAddr = (void*)(ulong)mbi->mmap_addr;
|
BtMemoryInfo.mapAddr = (void*)(ulong)mbi->mmap_addr;
|
||||||
BtGetBootInfo(memory).mapLength = mbi->mmap_length;
|
BtMemoryInfo.mapLength = mbi->mmap_length;
|
||||||
BtGetBootInfo(memory).mapValid = 1;
|
BtMemoryInfo.mapValid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves video mode informations
|
// Retrieves video mode informations
|
||||||
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_VBE_INFO) {
|
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_VBE_INFO) {
|
||||||
BtGetBootInfo(video).vbeControl = (void*)(ulong)mbi->vbe_control_info;
|
BtVideoInfo.vbeControl = (void*)(ulong)mbi->vbe_control_info;
|
||||||
BtGetBootInfo(video).vbeModeInfo = (void*)(ulong)mbi->vbe_mode_info;
|
BtVideoInfo.vbeModeInfo = (void*)(ulong)mbi->vbe_mode_info;
|
||||||
BtGetBootInfo(video).vbeMode = mbi->vbe_mode;
|
BtVideoInfo.vbeMode = mbi->vbe_mode;
|
||||||
BtGetBootInfo(video).vbeInterfaceSeg = mbi->vbe_interface_seg;
|
BtVideoInfo.vbeInterfaceSeg = mbi->vbe_interface_seg;
|
||||||
BtGetBootInfo(video).vbeInterfaceOff = mbi->vbe_interface_off;
|
BtVideoInfo.vbeInterfaceOff = mbi->vbe_interface_off;
|
||||||
BtGetBootInfo(video).vbeInterfaceLen = mbi->vbe_interface_len;
|
BtVideoInfo.vbeInterfaceLen = mbi->vbe_interface_len;
|
||||||
BtGetBootInfo(video).vbeValid = 1;
|
BtVideoInfo.vbeValid = 1;
|
||||||
}
|
}
|
||||||
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
|
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
|
||||||
BtGetBootInfo(video).framebufferAddr = (void*)mbi->framebuffer_addr;
|
BtVideoInfo.framebufferAddr = (void*)mbi->framebuffer_addr;
|
||||||
BtGetBootInfo(video).framebufferPitch = mbi->framebuffer_pitch;
|
BtVideoInfo.framebufferPitch = mbi->framebuffer_pitch;
|
||||||
BtGetBootInfo(video).framebufferWidth = mbi->framebuffer_width;
|
BtVideoInfo.framebufferWidth = mbi->framebuffer_width;
|
||||||
BtGetBootInfo(video).framebufferHeight= mbi->framebuffer_height;
|
BtVideoInfo.framebufferHeight= mbi->framebuffer_height;
|
||||||
BtGetBootInfo(video).framebufferBpp = mbi->framebuffer_bpp;
|
BtVideoInfo.framebufferBpp = mbi->framebuffer_bpp;
|
||||||
BtGetBootInfo(video).framebufferType = mbi->framebuffer_type;
|
BtVideoInfo.framebufferType = mbi->framebuffer_type;
|
||||||
BtGetBootInfo(video).fbuValid = 1;
|
BtVideoInfo.fbuValid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves the firmware infos
|
// Retrieves the firmware infos
|
||||||
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) {
|
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_CONFIG_TABLE) {
|
||||||
BtGetBootInfo(firmware).romTable = mbi->config_table;
|
BtFirmwareInfo.romTable = mbi->config_table;
|
||||||
BtGetBootInfo(firmware).romValid = 1;
|
BtFirmwareInfo.romValid = 1;
|
||||||
}
|
}
|
||||||
if (BtGetBootInfo(btldr).grubFlags & MULTIBOOT_INFO_APM_TABLE) {
|
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_APM_TABLE) {
|
||||||
BtGetBootInfo(firmware).apmTable = mbi->apm_table;
|
BtFirmwareInfo.apmTable = mbi->apm_table;
|
||||||
BtGetBootInfo(firmware).apmValid = 1;
|
BtFirmwareInfo.apmValid = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,11 +116,11 @@ void BtInitSanity(uint mbMagic){
|
||||||
if (!(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC))
|
if (!(mbMagic == MULTIBOOT_BOOTLOADER_MAGIC))
|
||||||
KeStartPanic("[Init] Magic number %x is incorrect\n", mbMagic);
|
KeStartPanic("[Init] Magic number %x is incorrect\n", mbMagic);
|
||||||
|
|
||||||
tmp = (BtGetBootInfo(btldr).kernelEndAddr
|
tmp = (BtLoaderInfo.kernelEndAddr
|
||||||
- BtGetBootInfo(btldr).kernelAddr) / KB;
|
- BtLoaderInfo.kernelAddr) / KB;
|
||||||
DebugLog("[Init] Kernel successfully loaded at %p with %x magic\n"
|
DebugLog("[Init] Kernel successfully loaded at %p with %x magic\n"
|
||||||
" and it uses %d Kio\n\n",
|
" and it uses %d Kio\n\n",
|
||||||
BtGetBootInfo(btldr).kernelAddr,
|
BtLoaderInfo.kernelAddr,
|
||||||
mbMagic,tmp);
|
mbMagic,tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,13 +139,13 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic)
|
||||||
// Initialize the BootInfo_t structure
|
// Initialize the BootInfo_t structure
|
||||||
BtInitBootInfo(mbInfo);
|
BtInitBootInfo(mbInfo);
|
||||||
|
|
||||||
// Get ready to print things
|
// Screen I/O available from this point on
|
||||||
IoInitVGABuffer();
|
IoInitVGABuffer();
|
||||||
|
|
||||||
// Sanity checks and hello world
|
// Sanity checks and hello world
|
||||||
BtInitSanity(mbMagic);
|
BtInitSanity(mbMagic);
|
||||||
|
|
||||||
//Memory mapping
|
// Memory & scheduler
|
||||||
MmInitMemoryMap();
|
MmInitMemoryMap();
|
||||||
|
|
||||||
// Several inits
|
// Several inits
|
||||||
|
@ -159,7 +157,8 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic)
|
||||||
|
|
||||||
MmPrintMemoryMap();
|
MmPrintMemoryMap();
|
||||||
|
|
||||||
// We're out
|
//KeStartPanic("Test Panic %d", 4);
|
||||||
PsFiniSched();
|
|
||||||
KeCrashSystem(); //yay
|
// End this machine's suffering
|
||||||
|
KeCrashSystem();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,12 @@
|
||||||
// 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/base.h>
|
#include <kernel/boot.h>
|
||||||
|
|
||||||
volatile int cpuCount = 1;
|
int KeCPUCount = 1;
|
||||||
volatile Processor_t cpuTable[NCPUS] = {0};
|
Processor_t _KeCPUTable[NCPUS] = {0};
|
||||||
|
|
||||||
volatile BootInfo_t bootTab = {0};
|
volatile BootInfo_t BtBootTab = {0};
|
||||||
Terminal_t *StdOut = 0, *StdDbg = 0;
|
volatile bool KeIsPanicking = 0;
|
||||||
|
|
||||||
volatile char KePanicStr[PANICSTR_SIZE] = {0};
|
|
||||||
|
|
||||||
|
volatile Processor_t *KeCurCPU = &_KeCPUTable[0];
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
// 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/buf.h>
|
#include <extras/buf.h>
|
||||||
|
#include <kernel/boot.h>
|
||||||
|
|
||||||
//----------------------------------------------------------//
|
//----------------------------------------------------------//
|
||||||
// Internal functions for VGA terminals //
|
// Internal functions for VGA terminals //
|
||||||
|
@ -41,12 +42,10 @@
|
||||||
//
|
//
|
||||||
error_t bvgaflusher(Buffer_t *buf)
|
error_t bvgaflusher(Buffer_t *buf)
|
||||||
{
|
{
|
||||||
ushort *fbp = BtGetBootInfo(video).framebufferAddr;
|
ushort *fbp = BtVideoInfo.framebufferAddr;
|
||||||
const uchar color = 0xf;
|
const uchar color = 0xf;
|
||||||
|
|
||||||
assert(buf->lastLF == 0);
|
uchar *currentLine = buf->wp - buf->lineLen - buf->lastLF;
|
||||||
|
|
||||||
uchar *currentLine = buf->wp - buf->lineLen;
|
|
||||||
uchar *ptr = (uchar *)lmax((size_t)buf->buf,
|
uchar *ptr = (uchar *)lmax((size_t)buf->buf,
|
||||||
(size_t)currentLine
|
(size_t)currentLine
|
||||||
- (buf->nLines - 1) * buf->lineLen);
|
- (buf->nLines - 1) * buf->lineLen);
|
||||||
|
@ -56,8 +55,8 @@ error_t bvgaflusher(Buffer_t *buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t bufSize = buf->nLines * buf->lineLen;
|
const size_t bufSize = buf->nLines * buf->lineLen;
|
||||||
ushort *fbe = BtGetBootInfo(video).framebufferAddr
|
ushort *fbe = BtVideoInfo.framebufferAddr
|
||||||
+ (bufSize * sizeof(ushort));
|
+ (bufSize * sizeof(ushort));
|
||||||
|
|
||||||
if (fbp < fbe) {
|
if (fbp < fbe) {
|
||||||
const ushort filler = VGA_ComputeEntry(' ', color);
|
const ushort filler = VGA_ComputeEntry(' ', color);
|
||||||
|
@ -75,8 +74,8 @@ error_t IoInitVGABuffer(void)
|
||||||
static char bvgabuffer[1 * MB];
|
static char bvgabuffer[1 * MB];
|
||||||
|
|
||||||
BStdOut = BOpenLineBuf(bvgabuffer, BS_WRONLY,
|
BStdOut = BOpenLineBuf(bvgabuffer, BS_WRONLY,
|
||||||
BtGetBootInfo(video).framebufferWidth,
|
BtVideoInfo.framebufferWidth,
|
||||||
BtGetBootInfo(video).framebufferHeight,
|
BtVideoInfo.framebufferHeight,
|
||||||
8, bvgaflusher);
|
8, bvgaflusher);
|
||||||
|
|
||||||
BStdDbg = BStdOut;
|
BStdDbg = BStdOut;
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
// 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/buf.h>
|
#include <extras/buf.h>
|
||||||
|
#include <kernel/base.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
// Prints formatted string on standard output
|
// Prints formatted string on standard output
|
||||||
|
|
|
@ -22,12 +22,13 @@
|
||||||
// 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/log.h>
|
#include <extras/buf.h>
|
||||||
#include <kernel/buf.h>
|
|
||||||
#include <kernel/proc.h>
|
#include <kernel/proc.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
#include <kernel/panic.h>
|
#include <kernel/panic.h>
|
||||||
|
|
||||||
|
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Failed assert() handler
|
// Failed assert() handler
|
||||||
//
|
//
|
||||||
|
@ -55,21 +56,29 @@ noreturn void KeStartPanic(const char *fmt, ...)
|
||||||
PsCurProc = NULL;
|
PsCurProc = NULL;
|
||||||
if (BStdOut == NULL) KeCrashSystem();
|
if (BStdOut == NULL) KeCrashSystem();
|
||||||
|
|
||||||
|
ExAttemptLock(&BStdOut->lock);
|
||||||
|
|
||||||
if (fmt == NULL) {
|
if (fmt == NULL) {
|
||||||
fmt = "(no message given)";
|
fmt = "(no message given)";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (KePanicStr[0] != 0) {
|
if (KeIsPanicking) {
|
||||||
KernLog("\nDouble panic!");
|
vbprintf(BStdOut, "\nDouble panic!", NULL);
|
||||||
KeHaltCPU();
|
KeHaltCPU();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeIsPanicking = 1;
|
||||||
|
|
||||||
|
// We don't check vbprintf's output
|
||||||
|
// If it fails, what could we do anyway?
|
||||||
|
|
||||||
|
vbprintf(BStdOut, "\nPanic!\n\n", NULL);
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vsnprintf((char *)KePanicStr, PANICSTR_SIZE, fmt, ap);
|
vbprintf(BStdOut, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
KernLog("\nPanic!\n\n");
|
BStdOut->flusher(BStdOut);
|
||||||
KernLog((char *)KePanicStr);
|
|
||||||
|
|
||||||
KeHaltCPU();
|
KeHaltCPU();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
#include <kernel/mm.h>
|
#include <kernel/mm.h>
|
||||||
#include <kernel/log.h>
|
|
||||||
#include <kernel/heap.h>
|
#include <kernel/heap.h>
|
||||||
|
|
||||||
// Least address out of the heap
|
// Least address out of the heap
|
||||||
|
|
|
@ -25,7 +25,12 @@
|
||||||
#include <kernel/heap.h>
|
#include <kernel/heap.h>
|
||||||
#include <extras/malloc.h>
|
#include <extras/malloc.h>
|
||||||
|
|
||||||
error_t KalAllocMemory(void **ptr, size_t req, int flags, size_t align)
|
error_t KalAllocMemory(void **ptr, size_t req)
|
||||||
|
{
|
||||||
|
return KalAllocMemoryEx(ptr, req, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t KalAllocMemoryEx(void **ptr, size_t req, int flags, size_t align)
|
||||||
{
|
{
|
||||||
error_t rc;
|
error_t rc;
|
||||||
size_t brk;
|
size_t brk;
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
#include <kernel/mm.h>
|
#include <kernel/mm.h>
|
||||||
#include <kernel/log.h>
|
#include <kernel/boot.h>
|
||||||
#include <kernel/mboot.h>
|
#include <kernel/mboot.h>
|
||||||
|
|
||||||
// Initializes globally the memory map
|
// Initializes globally the memory map
|
||||||
|
@ -52,19 +52,19 @@ static error_t InitMemoryMap(void)
|
||||||
uint i = 0;
|
uint i = 0;
|
||||||
|
|
||||||
// sanity checks
|
// sanity checks
|
||||||
if (!BtGetBootInfo(memory).memValid && BtGetBootInfo(memory).mapValid)
|
if (!BtMemoryInfo.memValid && BtMemoryInfo.mapValid)
|
||||||
return ENXIO;
|
return ENXIO;
|
||||||
|
|
||||||
if ((BtGetBootInfo(memory).upMemory / (MB/KB)) <= MINIMUM_RAM_SIZE)
|
if ((BtMemoryInfo.upMemory / (MB/KB)) <= MINIMUM_RAM_SIZE)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
// Ok then we can work ------------------------------------------------------ //
|
// Ok then we can work ------------------------------------------------------ //
|
||||||
|
|
||||||
// the memory map provided by GRUB via the BIOS
|
// the memory map provided by GRUB via the BIOS
|
||||||
currentEntry = (multiboot_memory_map_t*)BtGetBootInfo(memory).mapAddr;
|
currentEntry = (multiboot_memory_map_t*)BtMemoryInfo.mapAddr;
|
||||||
// End address of the map
|
// End address of the map
|
||||||
mapEnd = (multiboot_memory_map_t*)
|
mapEnd = (multiboot_memory_map_t*)
|
||||||
((ulong)currentEntry + (ulong)BtGetBootInfo(memory).mapLength);
|
((ulong)currentEntry + (ulong)BtMemoryInfo.mapLength);
|
||||||
|
|
||||||
// fill the map
|
// fill the map
|
||||||
while (currentEntry < mapEnd) {
|
while (currentEntry < mapEnd) {
|
||||||
|
@ -113,7 +113,7 @@ size_t MmGetAvailZoneSize(void *start) {
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
// Because the kernel is the kernel
|
// Because the kernel is the kernel
|
||||||
if (start < BtGetBootInfo(btldr).kernelEndAddr)
|
if (start < BtLoaderInfo.kernelEndAddr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Search the zone where the start address is
|
// Search the zone where the start address is
|
||||||
|
@ -138,8 +138,8 @@ void *MmGetFirstAvailZone(void *start) {
|
||||||
void *current = 0;
|
void *current = 0;
|
||||||
|
|
||||||
// Because the kernel is the kernel
|
// Because the kernel is the kernel
|
||||||
if ((ulong)start < (ulong)BtGetBootInfo(btldr).kernelEndAddr) {
|
if ((ulong)start < (ulong)BtLoaderInfo.kernelEndAddr) {
|
||||||
return MmGetFirstAvailZone(BtGetBootInfo(btldr).kernelEndAddr);
|
return MmGetFirstAvailZone(BtLoaderInfo.kernelEndAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search the zone where the start address is
|
// Search the zone where the start address is
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
|
|
||||||
sched-test:
|
|
||||||
gcc -O0 -Wall -Wextra -I../../include -c ../init/table.c -o table.o
|
|
||||||
gcc -O2 -Wall -Wextra -I../../include -c ./sched.c -o sched.o
|
|
||||||
gcc sched.o table.o -o a.out
|
|
||||||
rm sched.o table.o
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm a.out
|
|
|
@ -25,34 +25,33 @@
|
||||||
#include <extras/list.h>
|
#include <extras/list.h>
|
||||||
#include <kernel/proc.h>
|
#include <kernel/proc.h>
|
||||||
#include <kernel/sched.h>
|
#include <kernel/sched.h>
|
||||||
#include <kernel/log.h>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// For test purpose only
|
// For test purpose only
|
||||||
//
|
//
|
||||||
int procslen = 10;
|
int procslen = 10;
|
||||||
Process_t procs[] = {
|
Process_t procs[] = {
|
||||||
{ 0, 0, 0, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
{ 0, 0, 0, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||||
{ 1, 2, 2, 16, 16, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
{ 1, 2, 2, 16, 16, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||||
{ 2, 3, 3, 31, 31, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
{ 2, 3, 3, 31, 31, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||||
{ 3, 2, 2, 1, 1, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
{ 3, 2, 2, 1, 1, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||||
{ 4, 3, 3, 5, 5, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
{ 4, 3, 3, 5, 5, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||||
{ 5, 0, 0, 30, 30, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
{ 5, 0, 0, 30, 30, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||||
{ 6, 1, 1, 19, 19, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
{ 6, 1, 1, 19, 19, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||||
{ 7, 1, 1, 0, 0, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
{ 7, 1, 1, 0, 0, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||||
{ 8, 3, 3, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
{ 8, 3, 3, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||||
{ 9, 2, 2, 21, 21, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL, NULL, NULL },
|
{ 9, 2, 2, 21, 21, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
#define ReSchedFlag (KeCurCPU.needReSched)
|
#define ReSchedFlag (KeCurCPU->needReSched)
|
||||||
#define PreemptCount (KeCurCPU.preemptCount)
|
#define PreemptCount (KeCurCPU->preemptCount)
|
||||||
|
|
||||||
#define IdlePrioProcs (KeCurCPU.idlePrioProcs)
|
#define IdlePrioProcs (KeCurCPU->idlePrioProcs)
|
||||||
#define ReglPrioProcs (KeCurCPU.reglPrioProcs)
|
#define ReglPrioProcs (KeCurCPU->reglPrioProcs)
|
||||||
#define ServPrioProcs (KeCurCPU.servPrioProcs)
|
#define ServPrioProcs (KeCurCPU->servPrioProcs)
|
||||||
#define TimeCritProcs (KeCurCPU.timeCritProcs)
|
#define TimeCritProcs (KeCurCPU->timeCritProcs)
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
|
@ -324,7 +323,7 @@ void PsInitSched(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Shutdown scheduler
|
// Shutdowns scheduler
|
||||||
//
|
//
|
||||||
void PsFiniSched(void)
|
void PsFiniSched(void)
|
||||||
{
|
{
|
|
@ -0,0 +1,382 @@
|
||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
// GNU GPL OS/K //
|
||||||
|
// //
|
||||||
|
// Desc: Buffer library //
|
||||||
|
// //
|
||||||
|
// //
|
||||||
|
// 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 <extras/buf.h>
|
||||||
|
#include <extras/locks.h>
|
||||||
|
|
||||||
|
error_t bputc(Buffer_t *buf, uchar ch);
|
||||||
|
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prints formatted string on buf according to fmt
|
||||||
|
//
|
||||||
|
error_t BPrintOnBuf(Buffer_t *buf, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
error_t rc;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
ExAcquireLock(&buf->lock);
|
||||||
|
rc = vbprintf(buf, fmt, ap);
|
||||||
|
ExReleaseLock(&buf->lock);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
error_t rc;
|
||||||
|
|
||||||
|
ExAcquireLock(&buf->lock);
|
||||||
|
rc = vbprintf(buf, fmt, ap);
|
||||||
|
ExReleaseLock(&buf->lock);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prints 0 for octal, 0x for hexadecimal, 0b for binary
|
||||||
|
//
|
||||||
|
static error_t bprinthash(Buffer_t *buf, int base, int cap)
|
||||||
|
{
|
||||||
|
error_t rc;
|
||||||
|
|
||||||
|
if (base != 2 && base != 8 && base != 16) {
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = bputc(buf, '0');
|
||||||
|
|
||||||
|
if (!rc && base != 8) {
|
||||||
|
rc = bputc(buf, (base==2 ? 'b' : (cap ? 'X' : 'x')));
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static error_t bdopadding(Buffer_t *buf, size_t width, size_t len,
|
||||||
|
char filler)
|
||||||
|
{
|
||||||
|
error_t rc = EOK;
|
||||||
|
|
||||||
|
for (; !rc && width > len ; width--) {
|
||||||
|
rc = bputc(buf, filler);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CONVBUFSIZE 100
|
||||||
|
|
||||||
|
//
|
||||||
|
// Actually does BPrintOnBuf's job; doesn't lock anything
|
||||||
|
// Quite a long function
|
||||||
|
//
|
||||||
|
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
error_t rc = 0;
|
||||||
|
|
||||||
|
int width, prec, len;
|
||||||
|
char type;
|
||||||
|
|
||||||
|
uchar uch;
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
// Conversion buffer
|
||||||
|
char convbuf[CONVBUFSIZE];
|
||||||
|
|
||||||
|
// Flags
|
||||||
|
int plus, minus, space, zero, hash;
|
||||||
|
|
||||||
|
// Length modifiers
|
||||||
|
int l, h, hh;
|
||||||
|
|
||||||
|
// Signed
|
||||||
|
bool sgn;
|
||||||
|
|
||||||
|
// Capital digits
|
||||||
|
bool cap;
|
||||||
|
|
||||||
|
// Base
|
||||||
|
int base;
|
||||||
|
|
||||||
|
assert(buf && buf->initDone == INITOK);
|
||||||
|
|
||||||
|
if (!buf || !fmt) return EINVAL;
|
||||||
|
if (buf->state != BS_RDWR && buf->state != BS_WRONLY) {
|
||||||
|
return EBADF;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress in format string
|
||||||
|
while (*fmt && !rc) {
|
||||||
|
|
||||||
|
// Deal with all non-'%' characters
|
||||||
|
if (*fmt != '%') {
|
||||||
|
rc = bputc(buf, *fmt);
|
||||||
|
|
||||||
|
fmt++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// %[parameter][flags][width|*][.precision|*][length]type
|
||||||
|
// We aren't dealing with parameters and floating stuff just yet
|
||||||
|
//
|
||||||
|
|
||||||
|
// Skip the '%'
|
||||||
|
fmt++;
|
||||||
|
|
||||||
|
// "%%" modifier
|
||||||
|
if (*fmt == '%') {
|
||||||
|
rc = bputc(buf, '%');
|
||||||
|
|
||||||
|
fmt++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset everything
|
||||||
|
cap = sgn = 0;
|
||||||
|
l = h = hh = 0;
|
||||||
|
width = prec = 0;
|
||||||
|
plus = minus = space = zero = hash = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Flags field
|
||||||
|
//
|
||||||
|
while (*fmt) {
|
||||||
|
if (*fmt == '#') { fmt++; hash++; }
|
||||||
|
else if (*fmt == '0') { fmt++; zero++; }
|
||||||
|
else if (*fmt == '+') { fmt++; plus++; }
|
||||||
|
else if (*fmt == '-') { fmt++; minus++; }
|
||||||
|
else if (*fmt == ' ') { fmt++; space++; }
|
||||||
|
|
||||||
|
// Next field
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Width & precision fields
|
||||||
|
// A width field of zero is ignored
|
||||||
|
//
|
||||||
|
|
||||||
|
// Extracts either width or precision
|
||||||
|
#define bextractwp(name) \
|
||||||
|
do { \
|
||||||
|
if (*fmt == '*') { \
|
||||||
|
fmt++; \
|
||||||
|
name = va_arg(ap, int); \
|
||||||
|
} else { \
|
||||||
|
while (isdigit(*fmt) && name < CONVBUFSIZE) { \
|
||||||
|
name = 10 * name + (*fmt - '0'); \
|
||||||
|
fmt++; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
// Extract width
|
||||||
|
bextractwp(width);
|
||||||
|
|
||||||
|
// A width below 0 activates the "minus" flag
|
||||||
|
if (width < 0) {
|
||||||
|
width = -width;
|
||||||
|
minus++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract precision
|
||||||
|
if (*fmt == '.') {
|
||||||
|
fmt++;
|
||||||
|
bextractwp(prec);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure they're not too big
|
||||||
|
if (width > CONVBUFSIZE || prec > CONVBUFSIZE) {
|
||||||
|
rc = EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Length field
|
||||||
|
//
|
||||||
|
|
||||||
|
while (*fmt) {
|
||||||
|
if (*fmt == 'l' || *fmt == 'z' || *fmt == 't') {
|
||||||
|
fmt++;
|
||||||
|
l++;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (*fmt == 'h') {
|
||||||
|
fmt++;
|
||||||
|
h++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next field
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Consistency check
|
||||||
|
assert(!(l > 0 && h > 0));
|
||||||
|
assert(!(l > 2 || h > 1));
|
||||||
|
|
||||||
|
//
|
||||||
|
// The type field
|
||||||
|
//
|
||||||
|
type = *fmt++;
|
||||||
|
|
||||||
|
// Characters
|
||||||
|
if (type == 'c') {
|
||||||
|
uch = (uchar)va_arg(ap, int);
|
||||||
|
bputc(buf, uch);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings
|
||||||
|
else if (type == 's') {
|
||||||
|
s = va_arg(ap, char *);
|
||||||
|
|
||||||
|
if (s == NULL) s = "(null)";
|
||||||
|
|
||||||
|
// For strings, the precision field gives the maximum
|
||||||
|
// amount of characters to be read from the stream
|
||||||
|
// Zero/nonspecified precision means unlimited amount
|
||||||
|
if (prec == 0) prec = INT_MAX;
|
||||||
|
|
||||||
|
for (; *s && prec-- ; s++) {
|
||||||
|
rc = bputc(buf, (uchar)*s);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decimal, unsigned decimal, hexadecimal, octal and binary numbers
|
||||||
|
else if (type == 'd' || type == 'i') { base = 10; sgn = 1; }
|
||||||
|
else if (type == 'X') { base = 16; cap = 1; }
|
||||||
|
else if (type == 'x') { base = 16; }
|
||||||
|
else if (type == 'u') { base = 10; }
|
||||||
|
else if (type == 'o') { base = 8; }
|
||||||
|
else if (type == 'b') { base = 2; }
|
||||||
|
|
||||||
|
// Pointers: %p = %#012lx
|
||||||
|
// (48-bit pointers have width 12 at least)
|
||||||
|
else if (type == 'p') {
|
||||||
|
type = 'x'; base = 16; zero++; hash++; l++;
|
||||||
|
if (width < 12) width = 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unknown/unsupported modifier
|
||||||
|
// Note: a '\0' after length field falls here
|
||||||
|
else {
|
||||||
|
rc = EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Numerical conversions
|
||||||
|
//
|
||||||
|
|
||||||
|
// We use s to iterate convbuf
|
||||||
|
s = convbuf;
|
||||||
|
|
||||||
|
// FIXME: this works, but is ugly as hell
|
||||||
|
#define bdoconvrt(pref, type, vtype) \
|
||||||
|
do { \
|
||||||
|
type i_##type = (type)va_arg(ap, vtype); \
|
||||||
|
pref##toa(i_##type, s, base); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
if (!l) {
|
||||||
|
if (sgn) {
|
||||||
|
if (h == 0) bdoconvrt(i, int, int);
|
||||||
|
if (h == 1) bdoconvrt(i, short, int);
|
||||||
|
} else {
|
||||||
|
if (h == 0) bdoconvrt(u, uint, uint);
|
||||||
|
if (h == 1) bdoconvrt(u, ushort, uint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
if (sgn) bdoconvrt(l, long, long);
|
||||||
|
else bdoconvrt(ul, ulong, ulong);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Implement flags and %X, and prints
|
||||||
|
//
|
||||||
|
|
||||||
|
// Capital letter digits
|
||||||
|
if (base > 10 && cap) {
|
||||||
|
for (; *s ; s++)
|
||||||
|
if (islower(*s)) *s = toupper(*s);
|
||||||
|
|
||||||
|
// We use this "opportunity" to compute the length of s
|
||||||
|
len = s - convbuf;
|
||||||
|
|
||||||
|
// Reset s
|
||||||
|
s = convbuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute s's length
|
||||||
|
// It will always fit in an int
|
||||||
|
else len = (int)strlen(s);
|
||||||
|
|
||||||
|
// Adjust width
|
||||||
|
if (sgn && (plus || space)) width--;
|
||||||
|
else if (hash) width -= (base==8 ? 1 : ((base==2||base==16) ? 2 : 0));
|
||||||
|
|
||||||
|
// When padding with spaces, we pad before +/-'s etc
|
||||||
|
if (!minus && !zero && width > len)
|
||||||
|
bdopadding(buf, width, len, ' ');
|
||||||
|
|
||||||
|
// Deal with signs and the hash flag
|
||||||
|
if (*s == '-') { rc = bputc(buf, '-'); s++, len--; }
|
||||||
|
else if (sgn && plus) rc = bputc(buf, '+');
|
||||||
|
else if (sgn && space) rc = bputc(buf, ' ');
|
||||||
|
else if (hash) bprinthash(buf, base, cap);
|
||||||
|
|
||||||
|
// Deal with padding by zeroes
|
||||||
|
// The 'minus' flag makes no sense with the 'zero' one
|
||||||
|
if (zero && width > len)
|
||||||
|
bdopadding(buf, width, len, '0');
|
||||||
|
|
||||||
|
//
|
||||||
|
// Output the actual number
|
||||||
|
//
|
||||||
|
for (; !rc && *s ; s++) {
|
||||||
|
rc = bputc(buf, (uchar)*s);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 'minus' padding, only with spaces
|
||||||
|
if (minus && !zero && width > len)
|
||||||
|
bdopadding(buf, width, base, ' ');
|
||||||
|
|
||||||
|
// Carry on to next modifier
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert rc for debugging purposes
|
||||||
|
assert(!rc);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
// 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/buf.h>
|
#include <extras/buf.h>
|
||||||
|
#include <extras/locks.h>
|
||||||
|
|
||||||
error_t bputc(Buffer_t *buf, uchar ch);
|
error_t bputc(Buffer_t *buf, uchar ch);
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
// 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/buf.h>
|
#include <extras/buf.h>
|
||||||
|
#include <extras/locks.h>
|
||||||
#include <extras/malloc.h>
|
#include <extras/malloc.h>
|
||||||
|
|
||||||
Buffer_t *BStdOut, *BStdDbg;
|
Buffer_t *BStdOut, *BStdDbg;
|
||||||
|
@ -57,7 +58,7 @@ error_t BCloseBuf(Buffer_t *buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf->flags & BF_ALLOC) {
|
if (buf->flags & BF_ALLOC) {
|
||||||
free(buf->buf);
|
KalFreeMemory(buf->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->buf = buf->rp = buf->wp = NULL;
|
buf->buf = buf->rp = buf->wp = NULL;
|
||||||
|
@ -110,7 +111,7 @@ Buffer_t *BOpenLineBuf(char *source, int mode,
|
||||||
buf->size = lineLen * nLines * (pbCount + 1);
|
buf->size = lineLen * nLines * (pbCount + 1);
|
||||||
|
|
||||||
if (source == NULL) {
|
if (source == NULL) {
|
||||||
buf->buf = calloc(buf->size, 1);
|
KalAllocMemoryEx((void **)&buf->buf, buf->size, M_ZEROED, 0);
|
||||||
} else {
|
} else {
|
||||||
buf->buf = (uchar *)source;
|
buf->buf = (uchar *)source;
|
||||||
}
|
}
|
|
@ -36,7 +36,7 @@ void *malloc(size_t n)
|
||||||
void *ptr;
|
void *ptr;
|
||||||
error_t rc;
|
error_t rc;
|
||||||
|
|
||||||
rc = KalAllocMemory(&ptr, n, 0, 0);
|
rc = KalAllocMemory(&ptr, n);
|
||||||
if (rc > 0) seterrno(rc);
|
if (rc > 0) seterrno(rc);
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
|
@ -44,9 +44,13 @@ void *malloc(size_t n)
|
||||||
|
|
||||||
void *calloc(size_t n, size_t m)
|
void *calloc(size_t n, size_t m)
|
||||||
{
|
{
|
||||||
char *mem = malloc(n * m);
|
void *ptr;
|
||||||
memzero(mem, n * m);
|
error_t rc;
|
||||||
return mem;
|
|
||||||
|
rc = KalAllocMemoryEx(&ptr, n * m, M_ZEROED, 0);
|
||||||
|
if (rc > 0) seterrno(rc);
|
||||||
|
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(void *ptr)
|
void free(void *ptr)
|
|
@ -31,12 +31,6 @@
|
||||||
//
|
//
|
||||||
// Format str according to fmt using ellipsed arguments
|
// Format str according to fmt using ellipsed arguments
|
||||||
//
|
//
|
||||||
// Standard is dumb so we won't follow it:
|
|
||||||
// 1) we return a size_t instead of int
|
|
||||||
// 2) for (v)snprintf we return the number of characters written
|
|
||||||
// instead of the number of characters that would have been written
|
|
||||||
// given large enough n
|
|
||||||
//
|
|
||||||
size_t sprintf(char *str, const char *fmt, ...)
|
size_t sprintf(char *str, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
Loading…
Reference in New Issue