diff options
author | Marvin Borner | 2020-08-09 16:51:01 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-09 16:51:01 +0200 |
commit | 162d024a53e1e31e00ff0b6f47dd4590edebc551 (patch) | |
tree | 711d3886c300dfaddffdafaa89b690b45eb2101d | |
parent | 79f2fa136f26a0b87917336e089485712ee49bd6 (diff) |
Heavy restructuring of libc, kernel and apps
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | apps/Makefile | 4 | ||||
-rw-r--r-- | apps/a.c | 9 | ||||
-rw-r--r-- | apps/b.c | 9 | ||||
-rw-r--r-- | apps/init.c | 9 | ||||
-rw-r--r-- | kernel/Makefile (renamed from src/Makefile) | 42 | ||||
-rw-r--r-- | kernel/config.h (renamed from src/config.h) | 0 | ||||
-rw-r--r-- | kernel/drivers/cpu.c (renamed from src/drivers/cpu.c) | 0 | ||||
-rw-r--r-- | kernel/drivers/ide.c (renamed from src/drivers/ide.c) | 0 | ||||
-rw-r--r-- | kernel/drivers/interrupts.asm (renamed from src/drivers/interrupts.asm) | 0 | ||||
-rw-r--r-- | kernel/drivers/interrupts.c (renamed from src/drivers/interrupts.c) | 0 | ||||
-rw-r--r-- | kernel/drivers/keyboard.c (renamed from src/drivers/keyboard.c) | 0 | ||||
-rw-r--r-- | kernel/drivers/serial.c (renamed from src/drivers/serial.c) | 0 | ||||
-rw-r--r-- | kernel/drivers/timer.c (renamed from src/drivers/timer.c) | 0 | ||||
-rw-r--r-- | kernel/drivers/vesa.c (renamed from src/drivers/vesa.c) | 0 | ||||
-rw-r--r-- | kernel/entry.asm (renamed from src/entry.asm) | 0 | ||||
-rw-r--r-- | kernel/features/fs.c (renamed from src/features/fs.c) | 0 | ||||
-rw-r--r-- | kernel/features/gui.c (renamed from src/features/gui.c) | 0 | ||||
-rw-r--r-- | kernel/features/load.c (renamed from src/features/load.c) | 0 | ||||
-rw-r--r-- | kernel/features/proc.asm (renamed from src/features/proc.asm) | 0 | ||||
-rw-r--r-- | kernel/features/proc.c (renamed from src/features/proc.c) | 0 | ||||
-rw-r--r-- | kernel/features/psf.c (renamed from src/features/psf.c) | 0 | ||||
-rw-r--r-- | kernel/features/syscall.c (renamed from src/features/syscall.c) | 0 | ||||
-rw-r--r-- | kernel/inc/boot.h (renamed from src/inc/boot.h) | 0 | ||||
-rw-r--r-- | kernel/inc/cpu.h (renamed from src/inc/cpu.h) | 0 | ||||
-rw-r--r-- | kernel/inc/fs.h (renamed from src/inc/fs.h) | 0 | ||||
-rw-r--r-- | kernel/inc/gui.h (renamed from src/inc/gui.h) | 0 | ||||
-rw-r--r-- | kernel/inc/ide.h (renamed from src/inc/ide.h) | 0 | ||||
-rw-r--r-- | kernel/inc/interrupts.h (renamed from src/inc/interrupts.h) | 0 | ||||
-rw-r--r-- | kernel/inc/keyboard.h (renamed from src/inc/keyboard.h) | 0 | ||||
-rw-r--r-- | kernel/inc/load.h (renamed from src/inc/load.h) | 0 | ||||
-rw-r--r-- | kernel/inc/proc.h (renamed from src/inc/proc.h) | 0 | ||||
-rw-r--r-- | kernel/inc/psf.h (renamed from src/inc/psf.h) | 0 | ||||
-rw-r--r-- | kernel/inc/serial.h (renamed from src/inc/serial.h) | 0 | ||||
-rw-r--r-- | kernel/inc/syscall.h (renamed from src/inc/syscall.h) | 0 | ||||
-rw-r--r-- | kernel/inc/timer.h (renamed from src/inc/timer.h) | 0 | ||||
-rw-r--r-- | kernel/inc/vesa.h (renamed from src/inc/vesa.h) | 0 | ||||
-rw-r--r-- | kernel/main.c (renamed from src/main.c) | 0 | ||||
-rw-r--r-- | lib/Makefile | 24 | ||||
-rw-r--r-- | lib/conv.c (renamed from src/lib/conv.c) | 0 | ||||
-rw-r--r-- | lib/inc/arg.h (renamed from src/lib/inc/arg.h) | 0 | ||||
-rw-r--r-- | lib/inc/assert.h (renamed from src/lib/inc/assert.h) | 0 | ||||
-rw-r--r-- | lib/inc/conv.h (renamed from src/lib/inc/conv.h) | 0 | ||||
-rw-r--r-- | lib/inc/def.h (renamed from src/lib/inc/def.h) | 0 | ||||
-rw-r--r-- | lib/inc/math.h (renamed from src/lib/inc/math.h) | 0 | ||||
-rw-r--r-- | lib/inc/mem.h (renamed from src/lib/inc/mem.h) | 6 | ||||
-rw-r--r-- | lib/inc/print.h (renamed from src/lib/inc/print.h) | 2 | ||||
-rw-r--r-- | lib/inc/str.h (renamed from src/lib/inc/str.h) | 4 | ||||
-rw-r--r-- | lib/math.c (renamed from src/lib/math.c) | 0 | ||||
-rw-r--r-- | lib/mem.c (renamed from src/lib/mem.c) | 0 | ||||
-rw-r--r-- | lib/print.c (renamed from src/lib/print.c) | 4 | ||||
-rw-r--r-- | lib/str.c (renamed from src/lib/str.c) | 0 |
52 files changed, 61 insertions, 60 deletions
@@ -3,8 +3,12 @@ all: compile clean compile: - @$(MAKE) --no-print-directory -C src/ + @$(MAKE) --no-print-directory -C lib/ + @echo "Compiled libc" + @$(MAKE) --no-print-directory -C kernel/ + @echo "Compiled kernel" @$(MAKE) --no-print-directory -C apps/ + @echo "Compiled apps" clean: - @find src/ apps/ \( -name "*.o" -or -name "*.elf" -or -name "*.bin" \) -type f -delete + @find kernel/ apps/ lib/ \( -name "*.o" -or -name "*.a" -or -name "*.elf" -or -name "*.bin" \) -type f -delete diff --git a/apps/Makefile b/apps/Makefile index 91d7920..8c5ecac 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -5,12 +5,12 @@ CC = ../cross/opt/bin/i686-elf-gcc LD = ../cross/opt/bin/i686-elf-ld OC = ../cross/opt/bin/i686-elf-objcopy -CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -ffunction-sections -fno-builtin -std=c99 -m32 -pedantic-errors -I../src/lib/inc/ -fPIE +CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -ffunction-sections -fno-builtin -std=c99 -m32 -pedantic-errors -I../lib/inc/ -fPIE all: $(COBJS) %.o: %.c @mkdir -p ../build/apps/ @$(CC) -c $(CFLAGS) $< -o $@ - @$(LD) -o $(@:.o=.elf) -Tlink.ld $@ + @$(LD) -o $(@:.o=.elf) -Tlink.ld -L../build/ $@ -lc @$(OC) -O binary $(@:.o=.elf) ../build/apps/$(@:.o=) @@ -1,14 +1,7 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include <def.h> - -u32 strlen(const char *s) -{ - const char *ss = s; - while (*ss) - ss++; - return ss - s; -} +#include <str.h> u8 inb(u16 port) { @@ -1,14 +1,7 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include <def.h> - -u32 strlen(const char *s) -{ - const char *ss = s; - while (*ss) - ss++; - return ss - s; -} +#include <str.h> u8 inb(u16 port) { diff --git a/apps/init.c b/apps/init.c index 4a557a8..c35f26f 100644 --- a/apps/init.c +++ b/apps/init.c @@ -1,14 +1,7 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include <def.h> - -u32 strlen(const char *s) -{ - const char *ss = s; - while (*ss) - ss++; - return ss - s; -} +#include <str.h> u8 inb(u16 port) { diff --git a/src/Makefile b/kernel/Makefile index e917981..bbf13af 100644 --- a/src/Makefile +++ b/kernel/Makefile @@ -1,26 +1,21 @@ # MIT License, Copyright (c) 2020 Marvin Borner COBJS = main.o \ - drivers/vesa.o \ - drivers/cpu.o \ - drivers/serial.o \ - drivers/interrupts.o \ - drivers/interrupts_asm.o \ - drivers/keyboard.o \ - drivers/ide.o \ - drivers/timer.o \ - features/fs.o \ - features/psf.o \ - features/gui.o \ - features/load.o \ - features/proc.o \ - features/proc_asm.o \ - features/syscall.o \ - lib/str.o \ - lib/mem.o \ - lib/math.o \ - lib/conv.o \ - lib/print.o + drivers/vesa.o \ + drivers/cpu.o \ + drivers/serial.o \ + drivers/interrupts.o \ + drivers/interrupts_asm.o \ + drivers/keyboard.o \ + drivers/ide.o \ + drivers/timer.o \ + features/fs.o \ + features/psf.o \ + features/gui.o \ + features/load.o \ + features/proc.o \ + features/proc_asm.o \ + features/syscall.o CC = ../cross/opt/bin/i686-elf-gcc LD = ../cross/opt/bin/i686-elf-ld OC = ../cross/opt/bin/i686-elf-objcopy @@ -29,8 +24,7 @@ AS = nasm # Flags to make the binary smaller TODO: Remove after indirect pointer support! CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os -# TODO: Use lib as external library -CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-ekernel_main -Ilib/inc/ -Iinc/ +CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Wl,-ekernel_main -I../lib/inc/ -Iinc/ ASFLAGS = -f elf32 -O3 @@ -45,5 +39,5 @@ all: compile compile: $(COBJS) @mkdir -p ../build/ @$(AS) -f bin entry.asm -o ../build/boot.bin - @$(LD) -N -ekernel_main -Ttext 0x00050000 -o ../build/kernel.bin $(COBJS) --oformat binary - @$(CC) $(CFLAGS) -o ../build/debug.o $(COBJS) + @$(LD) -N -ekernel_main -Ttext 0x00050000 -o ../build/kernel.bin -L../build/ $+ -lc --oformat binary + @$(CC) $(CFLAGS) -o ../build/debug.o -L../build/ $+ -lc diff --git a/src/config.h b/kernel/config.h index 29c0e23..29c0e23 100644 --- a/src/config.h +++ b/kernel/config.h diff --git a/src/drivers/cpu.c b/kernel/drivers/cpu.c index 5c27c51..5c27c51 100644 --- a/src/drivers/cpu.c +++ b/kernel/drivers/cpu.c diff --git a/src/drivers/ide.c b/kernel/drivers/ide.c index fe3955c..fe3955c 100644 --- a/src/drivers/ide.c +++ b/kernel/drivers/ide.c diff --git a/src/drivers/interrupts.asm b/kernel/drivers/interrupts.asm index 59c323c..59c323c 100644 --- a/src/drivers/interrupts.asm +++ b/kernel/drivers/interrupts.asm diff --git a/src/drivers/interrupts.c b/kernel/drivers/interrupts.c index 0b94208..0b94208 100644 --- a/src/drivers/interrupts.c +++ b/kernel/drivers/interrupts.c diff --git a/src/drivers/keyboard.c b/kernel/drivers/keyboard.c index 38ff1f7..38ff1f7 100644 --- a/src/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c diff --git a/src/drivers/serial.c b/kernel/drivers/serial.c index dcee4dd..dcee4dd 100644 --- a/src/drivers/serial.c +++ b/kernel/drivers/serial.c diff --git a/src/drivers/timer.c b/kernel/drivers/timer.c index a3b4137..a3b4137 100644 --- a/src/drivers/timer.c +++ b/kernel/drivers/timer.c diff --git a/src/drivers/vesa.c b/kernel/drivers/vesa.c index 9402664..9402664 100644 --- a/src/drivers/vesa.c +++ b/kernel/drivers/vesa.c diff --git a/src/entry.asm b/kernel/entry.asm index ac70091..ac70091 100644 --- a/src/entry.asm +++ b/kernel/entry.asm diff --git a/src/features/fs.c b/kernel/features/fs.c index ab2a6eb..ab2a6eb 100644 --- a/src/features/fs.c +++ b/kernel/features/fs.c diff --git a/src/features/gui.c b/kernel/features/gui.c index d080cb1..d080cb1 100644 --- a/src/features/gui.c +++ b/kernel/features/gui.c diff --git a/src/features/load.c b/kernel/features/load.c index cc1a094..cc1a094 100644 --- a/src/features/load.c +++ b/kernel/features/load.c diff --git a/src/features/proc.asm b/kernel/features/proc.asm index 3d6bbc4..3d6bbc4 100644 --- a/src/features/proc.asm +++ b/kernel/features/proc.asm diff --git a/src/features/proc.c b/kernel/features/proc.c index a14aaea..a14aaea 100644 --- a/src/features/proc.c +++ b/kernel/features/proc.c diff --git a/src/features/psf.c b/kernel/features/psf.c index adf2aa2..adf2aa2 100644 --- a/src/features/psf.c +++ b/kernel/features/psf.c diff --git a/src/features/syscall.c b/kernel/features/syscall.c index 3d012cf..3d012cf 100644 --- a/src/features/syscall.c +++ b/kernel/features/syscall.c diff --git a/src/inc/boot.h b/kernel/inc/boot.h index 1a41c32..1a41c32 100644 --- a/src/inc/boot.h +++ b/kernel/inc/boot.h diff --git a/src/inc/cpu.h b/kernel/inc/cpu.h index eb09291..eb09291 100644 --- a/src/inc/cpu.h +++ b/kernel/inc/cpu.h diff --git a/src/inc/fs.h b/kernel/inc/fs.h index 775a1ce..775a1ce 100644 --- a/src/inc/fs.h +++ b/kernel/inc/fs.h diff --git a/src/inc/gui.h b/kernel/inc/gui.h index 760bcb9..760bcb9 100644 --- a/src/inc/gui.h +++ b/kernel/inc/gui.h diff --git a/src/inc/ide.h b/kernel/inc/ide.h index 9d753ae..9d753ae 100644 --- a/src/inc/ide.h +++ b/kernel/inc/ide.h diff --git a/src/inc/interrupts.h b/kernel/inc/interrupts.h index e943e5a..e943e5a 100644 --- a/src/inc/interrupts.h +++ b/kernel/inc/interrupts.h diff --git a/src/inc/keyboard.h b/kernel/inc/keyboard.h index f0effc7..f0effc7 100644 --- a/src/inc/keyboard.h +++ b/kernel/inc/keyboard.h diff --git a/src/inc/load.h b/kernel/inc/load.h index 60fecf9..60fecf9 100644 --- a/src/inc/load.h +++ b/kernel/inc/load.h diff --git a/src/inc/proc.h b/kernel/inc/proc.h index 39ba704..39ba704 100644 --- a/src/inc/proc.h +++ b/kernel/inc/proc.h diff --git a/src/inc/psf.h b/kernel/inc/psf.h index 63a3d1e..63a3d1e 100644 --- a/src/inc/psf.h +++ b/kernel/inc/psf.h diff --git a/src/inc/serial.h b/kernel/inc/serial.h index 6511952..6511952 100644 --- a/src/inc/serial.h +++ b/kernel/inc/serial.h diff --git a/src/inc/syscall.h b/kernel/inc/syscall.h index 3f89365..3f89365 100644 --- a/src/inc/syscall.h +++ b/kernel/inc/syscall.h diff --git a/src/inc/timer.h b/kernel/inc/timer.h index 7c4f077..7c4f077 100644 --- a/src/inc/timer.h +++ b/kernel/inc/timer.h diff --git a/src/inc/vesa.h b/kernel/inc/vesa.h index e34cdc0..e34cdc0 100644 --- a/src/inc/vesa.h +++ b/kernel/inc/vesa.h diff --git a/src/main.c b/kernel/main.c index 17d6267..17d6267 100644 --- a/src/main.c +++ b/kernel/main.c diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000..ad430d6 --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,24 @@ +# MIT License, Copyright (c) 2020 Marvin Borner + +COBJS = str.o \ + mem.o \ + math.o \ + conv.o \ + print.o +CC = ../cross/opt/bin/i686-elf-gcc +LD = ../cross/opt/bin/i686-elf-ld +OC = ../cross/opt/bin/i686-elf-ar + +# Flags to make the binary smaller TODO: Remove after indirect pointer support! +CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os + +CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Iinc/ + +all: compile + +%.o: %.c + @$(CC) -c $(CFLAGS) $< -o $@ + +compile: $(COBJS) + @mkdir -p ../build/ + @$(AR) qc ../build/libc.a $(COBJS) diff --git a/src/lib/conv.c b/lib/conv.c index 3bde4ec..3bde4ec 100644 --- a/src/lib/conv.c +++ b/lib/conv.c diff --git a/src/lib/inc/arg.h b/lib/inc/arg.h index 73e592d..73e592d 100644 --- a/src/lib/inc/arg.h +++ b/lib/inc/arg.h diff --git a/src/lib/inc/assert.h b/lib/inc/assert.h index 2cb095b..2cb095b 100644 --- a/src/lib/inc/assert.h +++ b/lib/inc/assert.h diff --git a/src/lib/inc/conv.h b/lib/inc/conv.h index d878deb..d878deb 100644 --- a/src/lib/inc/conv.h +++ b/lib/inc/conv.h diff --git a/src/lib/inc/def.h b/lib/inc/def.h index 42939a0..42939a0 100644 --- a/src/lib/inc/def.h +++ b/lib/inc/def.h diff --git a/src/lib/inc/math.h b/lib/inc/math.h index 268e3e7..268e3e7 100644 --- a/src/lib/inc/math.h +++ b/lib/inc/math.h diff --git a/src/lib/inc/mem.h b/lib/inc/mem.h index 2aaf4d8..e700e42 100644 --- a/src/lib/inc/mem.h +++ b/lib/inc/mem.h @@ -5,12 +5,12 @@ #include <def.h> +u32 HEAP; +u32 HEAP_START; + #define malloc(n) ((void *)((HEAP += n) - n)) // TODO: Implement real/better malloc/free #define free(x) -extern u32 HEAP; -extern u32 HEAP_START; - void *memcpy(void *dst, const void *src, u32 n); void *memset(void *dst, int c, u32 n); int memcmp(const void *s1, const void *s2, u32 n); diff --git a/src/lib/inc/print.h b/lib/inc/print.h index 1a2419b..925a5bd 100644 --- a/src/lib/inc/print.h +++ b/lib/inc/print.h @@ -4,7 +4,7 @@ #ifndef PRINT_H #define PRINT_H -#include <arg.h> +#include "arg.h" int printf(const char *format, ...); int vprintf(const char *format, va_list ap); diff --git a/src/lib/inc/str.h b/lib/inc/str.h index f4c63b1..65774e7 100644 --- a/src/lib/inc/str.h +++ b/lib/inc/str.h @@ -1,7 +1,7 @@ // MIT License, Copyright (c) 2020 Marvin Borner -#ifndef STRING_H -#define STRING_H +#ifndef STR_H +#define STR_H #include <def.h> diff --git a/src/lib/math.c b/lib/math.c index 9cd9cea..9cd9cea 100644 --- a/src/lib/math.c +++ b/lib/math.c diff --git a/src/lib/mem.c b/lib/mem.c index 00b9735..00b9735 100644 --- a/src/lib/mem.c +++ b/lib/mem.c diff --git a/src/lib/print.c b/lib/print.c index b9cddfa..738e42f 100644 --- a/src/lib/print.c +++ b/lib/print.c @@ -2,7 +2,7 @@ #include <conv.h> #include <def.h> #include <mem.h> -#include <serial.h> +/* #include <serial.h> */ #include <str.h> static void append(char *dest, char *src, int index) @@ -80,7 +80,7 @@ int vprintf(const char *format, va_list ap) char buf[1024]; memset(buf, 0, 1024); int len = vsprintf(buf, format, ap); - serial_print(buf); // TODO: Remove temporary serial print + /* serial_print(buf); // TODO: Remove temporary serial print */ return len; } diff --git a/src/lib/str.c b/lib/str.c index d1ee325..d1ee325 100644 --- a/src/lib/str.c +++ b/lib/str.c |