diff --git a/Makefile b/Makefile index 71e74a6..a9242fb 100644 --- a/Makefile +++ b/Makefile @@ -25,3 +25,23 @@ tests: make tests -f Makefile.out.2 rm Makefile.out Makefile.out.2 +ASM=nasm +ASMFLAGS= +BOOTFLAGS=-f bin + +BOOTDIR=boot +OBJDIR=build/obj +BINDIR=build/bin + +boot.mbr.asm: $(BOOTDIR)/mbr.asm $(BOOTDIR)/mbr.inc + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin + +boot.loader.asm: $(BOOTDIR)/loader.asm + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin + +bootloader: boot.mbr.asm boot.loader.asm + cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin + cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin + +all: bootloader kernel + diff --git a/Makefile.in b/Makefile.in index 5c26235..3b7a9c6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -22,10 +22,6 @@ CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG) CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) -ASM=nasm -ASMFLAGS= -BOOTFLAGS=-f bin - BINDIR=./build/bin OBJDIR=./build/obj @@ -35,18 +31,6 @@ KERNDIR=kaleid/kernel SYSTDIR=kaleid/system LINXDIR=kaleid/common/test -all: bootloader kernel - -boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin - -boot.loader.s: $(BOOTDIR)/loader.s - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin - -bootloader: boot.mbr.s boot.loader.s - cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin - cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin - //----------------------------------------------------------------------------# // TESTING MAKEFILE diff --git a/Makefile.out.2 b/Makefile.out.2 new file mode 100644 index 0000000..1b457e2 --- /dev/null +++ b/Makefile.out.2 @@ -0,0 +1,103 @@ +# 1 "./Makefile.in" +# 1 "" +# 1 "" +# 31 "" +# 1 "/usr/include/stdc-predef.h" 1 3 4 +# 32 "" 2 +# 1 "./Makefile.in" +# 11 "./Makefile.in" +# 1 "./build/preproc.h" 1 +# 12 "./Makefile.in" 2 + +CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" +CC2NAME=gcc +COPTIM=-O2 +CWARNS=-Wall -Wextra -Wshadow -Wpedantic +CINCLUDES=-isystem./kaleid/include + +CFLAGS1=-std=gnu11 -nostdlib -ffreestanding -mcmodel=large +CFLAGS2=-m64 -masm=intel -mno-red-zone -mno-mmx -mno-sse -mno-sse2 +CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG) + +CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) + +ASM=nasm +ASMFLAGS= +BOOTFLAGS=-f bin + +BINDIR=./build/bin +OBJDIR=./build/obj + +BOOTDIR=boot +COMMDIR=kaleid/common +KERNDIR=kaleid/kernel +SYSTDIR=kaleid/system +LINXDIR=kaleid/common/test + +all: bootloader kernel + +boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin + +boot.loader.s: $(BOOTDIR)/loader.s + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin + +bootloader: boot.mbr.s boot.loader.s + cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin + cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin + + + + +pseudo_kern: + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/pseudo_kernel.s -o $(OBJDIR)/boot/pkernel.bin + +testing: bootloader pseudo_kern + cat $(BINDIR)/bootloader.bin $(OBJDIR)/boot/pkernel.bin > $(BINDIR)/boot.bin + + + + +COBJDIR=$(OBJDIR)/$(COMMDIR) +LOBJDIR=$(OBJDIR)/$(LINXDIR) + +COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o $(COBJDIR)/rand.o $(COBJDIR)/memory.o $(COBJDIR)/arith.o $(COBJDIR)/strtol.o $(COBJDIR)/itoa.o $(COBJDIR)/ltoa.o $(COBJDIR)/utoa.o $(COBJDIR)/ultoa.o $(COBJDIR)/atoi.o $(COBJDIR)/atol.o $(COBJDIR)/atou.o $(COBJDIR)/atoul.o + +TCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) +KCC=$(CC) -T ./build/kernel.ld -D_OSK_SOURCE -D_KALEID_KERNEL + +comm-convert: + $(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/itoa.o -D_NEED_ITOA + $(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/ltoa.o -D_NEED_LTOA + $(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/utoa.o -D_NEED_UTOA + $(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/ultoa.o -D_NEED_ULTOA + $(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atoi.o -D_NEED_ATOI + $(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atol.o -D_NEED_ATOL + $(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atou.o -D_NEED_ATOU + $(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atoul.o -D_NEED_ATOUL + +common: comm-convert + $(KCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o + $(KCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o + $(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o + $(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o + $(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o + $(KCC) -c $(COMMDIR)/strtol.c -o $(COBJDIR)/strtol.o + +tests: common + $(TCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o + $(TCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf + + + + +KOBJDIR=$(OBJDIR)/$(KERNDIR) + +KERNOBJS=$(KOBJDIR)/init/init.o $(KOBJDIR)/init/table.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/ke/terminal.o + +kernel: common + $(KCC) -c $(KERNDIR)/init/init.c -o $(KOBJDIR)/init/init.o + $(KCC) -c $(KERNDIR)/init/table.c -o $(KOBJDIR)/init/table.o + $(KCC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o + $(KCC) -c $(KERNDIR)/ke/terminal.c -o $(KOBJDIR)/ke/terminal.o + $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/kaleid-kernel.elf diff --git a/ProjectTree b/ProjectTree index 90c5627..965face 100644 --- a/ProjectTree +++ b/ProjectTree @@ -60,8 +60,6 @@ src/ | | | + kernel/ | | | - | | - kernel.ld - | | | | | + init/ | | | | | | | - init.c @@ -99,6 +97,8 @@ src/ | | | - preproc.h | - iddtool.h + | | + | - kernel.ld | | | + bin/ | + obj/ diff --git a/Readme.md b/Readme.md index 42e4585..0775db9 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,7 @@ # GNU-GPL OS/K (OS on Kaleid) ### Fully open-source operating system from scratch (WIP), released under the GNU GPL version 3.0 + #### Boot Branch For the project plan, see [OS/K Project](https://github.com/orgs/os-k-team/projects/1) diff --git a/kaleid/common/atoi.c b/kaleid/common/atoi.c index f5a22a6..0ea016c 100644 --- a/kaleid/common/atoi.c +++ b/kaleid/common/atoi.c @@ -15,9 +15,9 @@ // #define _ATOI_IMPL(_Name, _Type, _Func) \ _Type _Name(const char *str) { \ - error_t old = errno; \ + __get_errno(old); \ _Type ret = (_Type)_Func(str, NULL, 0); \ - errno = old; \ + __set_errno(old); \ return ret; \ } diff --git a/kaleid/common/status.c b/kaleid/common/status.c index 457e741..2866833 100644 --- a/kaleid/common/status.c +++ b/kaleid/common/status.c @@ -9,7 +9,7 @@ #include -error_t errno = 0; +error_t __errno = 0; /* static const char *descriptions[] = { @@ -17,7 +17,7 @@ static const char *descriptions[] = { [-FAILED] = "Failed (no precision)", [-NOT_PERMITTED] = "Operation not permitted", [-ACCESS_DENIED] = "Access denied", - + [-BAD_ARGUMENT] = "Bad argument", [-BAD_ARG_RANGE] = "Bad argument (not in range)", [-BAD_ARG_NULL] = "Bad argument (null pointer)", diff --git a/kaleid/common/strtol.c b/kaleid/common/strtol.c index 2e1aad6..7636822 100644 --- a/kaleid/common/strtol.c +++ b/kaleid/common/strtol.c @@ -13,7 +13,7 @@ long strtol(const char *str, char **endp, int base) { (void)str; (void)endp; (void)base; - errno = ENOSYS; + __set_errno(ENOSYS); return 0; } @@ -21,7 +21,7 @@ ulong strtoul(const char *str, char **endp, int base) { (void)str; (void)endp; (void)base; - errno = ENOSYS; + __set_errno(ENOSYS); return 0; } diff --git a/kaleid/include/common/kalcrt.h b/kaleid/include/common/kalcrt.h index 75e34e1..167ab52 100644 --- a/kaleid/include/common/kalcrt.h +++ b/kaleid/include/common/kalcrt.h @@ -43,7 +43,24 @@ typedef struct { long quot, rem; } ldiv_t; // Global variables // //------------------------------------------// -extern error_t errno; +#ifndef _KALEID_KERNEL + +extern error_t __errno; + +#ifndef errno +#define errno __errno +#endif + +#define __get_errno(x) error_t x = errno; +#define __set_errno(x) (errno = (x)) + +#else + +#define errno +#define __get_errno(x) +#define __set_errno(x) + +#endif //------------------------------------------// // Macros // diff --git a/kaleid/include/kernel/kernbase.h b/kaleid/include/kernel/kernbase.h index 171c048..baf8e95 100644 --- a/kaleid/include/kernel/kernbase.h +++ b/kaleid/include/kernel/kernbase.h @@ -184,7 +184,8 @@ void WriteByteOnPort(port_t port, port_t val) static inline uchar ReadByteFromPort(port_t port) { - errno = ENOSYS; + + KalAssert(FALSE && ENOSYS); (void)port; return 0; } @@ -192,7 +193,7 @@ uchar ReadByteFromPort(port_t port) static inline ushort ReadWordFromPort(port_t port) { - errno = ENOSYS; + KalAssert(FALSE && ENOSYS); (void)port; return 0; }