From 0bb65f2d94d527ca99209c5d8d2ba3e8a646ff36 Mon Sep 17 00:00:00 2001 From: Nathan Giddings Date: Fri, 17 Jul 2020 10:03:28 -0500 Subject: [PATCH] Reorganized source tree. Started using autotools. --- .gitignore | 23 +++++++++++++++++-- Makefile | 14 ------------ Makefile.am | 1 + configure.ac | 32 +++++++++++++++++++++++++++ src/Makefile | 18 --------------- src/Makefile.am | 8 +++++++ src/cstring.h | 26 ---------------------- src/interrupts/Makefile | 9 -------- src/interrupts/Makefile.am | 6 +++++ src/math.cpp | 27 ---------------------- src/math.h | 22 ------------------ src/mmgr/Makefile.am | 7 ++++++ src/{ => mmgr}/addressspace.cpp | 0 src/{ => mmgr}/addressspace.hpp | 4 ++-- src/{ => mmgr}/buddyallocator.cpp | 20 +++++++++++++++-- src/{ => mmgr}/buddyallocator.hpp | 0 src/{ => mmgr}/memoryallocator.hpp | 2 +- src/{ => mmgr}/memorymap.cpp | 0 src/{ => mmgr}/memorymap.hpp | 2 +- src/mmgr/types.hpp | 15 +++++++++++++ src/{ => mmgr/x86}/pagetableentry.cpp | 0 src/{ => mmgr/x86}/pagetableentry.hpp | 2 +- src/quarkkernel.cpp | 14 +++++------- src/systypes.hpp | 5 +---- src/tty.cpp | 2 +- src/{tty.h => tty.hpp} | 0 src/{cstring.cpp => util.cpp} | 16 +++++--------- src/util.hpp | 16 ++++++++++++++ 28 files changed, 142 insertions(+), 149 deletions(-) delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100644 configure.ac delete mode 100644 src/Makefile create mode 100644 src/Makefile.am delete mode 100755 src/cstring.h delete mode 100644 src/interrupts/Makefile create mode 100644 src/interrupts/Makefile.am delete mode 100755 src/math.cpp delete mode 100755 src/math.h create mode 100644 src/mmgr/Makefile.am rename src/{ => mmgr}/addressspace.cpp (100%) rename src/{ => mmgr}/addressspace.hpp (92%) rename src/{ => mmgr}/buddyallocator.cpp (94%) rename src/{ => mmgr}/buddyallocator.hpp (100%) rename src/{ => mmgr}/memoryallocator.hpp (97%) rename src/{ => mmgr}/memorymap.cpp (100%) rename src/{ => mmgr}/memorymap.hpp (96%) create mode 100644 src/mmgr/types.hpp rename src/{ => mmgr/x86}/pagetableentry.cpp (100%) rename src/{ => mmgr/x86}/pagetableentry.hpp (98%) rename src/{tty.h => tty.hpp} (100%) rename src/{cstring.cpp => util.cpp} (93%) mode change 100755 => 100644 create mode 100644 src/util.hpp diff --git a/.gitignore b/.gitignore index e6d5185..f21de48 100755 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,26 @@ quark.iso -src/quark-kernel -src/interrupts/libinterrupts.a +quark-kernel + +autom4te.cache/ +.deps +aclocal.m4 +ar-lib +compile +config.h +config.h.in +config.log +config.status +configure +depcomp +install-sh +Makefile +Makefile.in +missing +stamp-h1 +*.Po +*.a *.o *~ + rootfs/ test/ \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index d7cdb0d..0000000 --- a/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -.PHONY: all -all: quark.iso - -quark.iso: src/quark-kernel - cp src/quark-kernel rootfs/apps - grub-mkrescue -o $@ rootfs - -src/quark-kernel: - make -C src - -.PHONY: clean -clean: - make -C src clean - rm -f quark.iso diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..f963eff --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src \ No newline at end of file diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..8392083 --- /dev/null +++ b/configure.ac @@ -0,0 +1,32 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.69]) +AC_INIT([quark-kernel], [pre-alpha]) +AM_INIT_AUTOMAKE([-Wall foreign]) +AC_CONFIG_SRCDIR([src/tty.cpp]) +AC_CONFIG_HEADERS([src/config.h]) + +# Checks for programs. +AC_PROG_CXX +AC_PROG_CC +AM_PROG_AS +AM_PROG_AR +AC_PROG_RANLIB + +# Checks for header files. +AC_CHECK_HEADERS([stddef.h stdint.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_CHECK_HEADER_STDBOOL +AC_C_INLINE +AC_TYPE_SIZE_T +AC_TYPE_UINT16_T +AC_TYPE_UINT32_T +AC_TYPE_UINT64_T +AC_TYPE_UINT8_T + +AM_CONDITIONAL([x86], [test $host = i686-elf]) + +AC_CONFIG_FILES([Makefile src/Makefile src/mmgr/Makefile src/interrupts/Makefile]) +AC_OUTPUT diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index e10855e..0000000 --- a/src/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -objs = addressspace.o tty.o buddyallocator.o math.o cstring.o pagetableentry.o multiboot2header.o systeminfo.o memorymap.o pio.o entry.o quarkkernel.o - -CXX = i686-elf-g++ -CC = i686-elf-gcc - -CXXFLAGS = -ffreestanding -mgeneral-regs-only -O0 -Wall -fno-exceptions -fno-rtti -ggdb -LDFLAGS = -T linker.ld -lgcc -nostdlib - -quark-kernel: $(objs) linker.ld interrupts/libinterrupts.a - $(CXX) -o $@ $(LDFLAGS) interrupts/libinterrupts.a $(objs) - -interrupts/libinterrupts.a: - make -C interrupts CXX="$(CXX)" CC="$(CC)" CXXFLAGS="$(CXXFLAGS)" - -.PHONY: clean -clean: - make -C interrupts clean - rm -f $(objs) quark-kernel \ No newline at end of file diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..b9624d1 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,8 @@ +SUBDIRS = interrupts mmgr +noinst_PROGRAMS = quark-kernel +quark_kernel_SOURCES = quarkkernel.cpp tty.cpp systeminfo.cpp util.cpp entry.S pio.S multiboot2header.S +quark_kernel_LDADD = -lgcc mmgr/libmmgr.a interrupts/libinterrupts.a +quark_kernel_CPPFLAGS = -ffreestanding -O0 -Wall -fno-exceptions -fno-rtti -ggdb +quark_kernel_LDFLAGS = -T linker.ld -nostdlib +quark_kernel_DEPENDENCIES = linker.ld + diff --git a/src/cstring.h b/src/cstring.h deleted file mode 100755 index 3ea1763..0000000 --- a/src/cstring.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * cstring.h - * - * Created on: Jun 13, 2019 - * Author: nathan - */ - -#ifndef SRC_CSTRING_H_ -#define SRC_CSTRING_H_ - -#include - -extern "C" -{ - -void* memcpy(void* destination, const void* source, size_t num); - -void* memmove(void* destination, const void* source, size_t num); - -int memcmp(const void* ptr1, const void* ptr2, size_t num); - -void* memset (void* ptr, int value, size_t num); - -} - -#endif /* SRC_CSTRING_H_ */ diff --git a/src/interrupts/Makefile b/src/interrupts/Makefile deleted file mode 100644 index c818c6f..0000000 --- a/src/interrupts/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -objs = x86/inthandlers.o x86/interruptdescriptor.o x86/idt.o x86/interrupts.o -archive = libinterrupts.a - -$(archive): $(objs) - i686-elf-ar rcs $@ $^ - -.PHONY: clean -clean: - rm -f $(archive) $(objs) \ No newline at end of file diff --git a/src/interrupts/Makefile.am b/src/interrupts/Makefile.am new file mode 100644 index 0000000..c9847b1 --- /dev/null +++ b/src/interrupts/Makefile.am @@ -0,0 +1,6 @@ +noinst_LIBRARIES = libinterrupts.a +libinterrupts_a_CPPFLAGS = -ffreestanding -mgeneral-regs-only -O0 -Wall -fno-exceptions -fno-rtti -ggdb + +if x86 +libinterrupts_a_SOURCES = x86/interrupts.cpp x86/inthandlers.cpp x86/interruptdescriptor.cpp x86/idt.S +endif \ No newline at end of file diff --git a/src/math.cpp b/src/math.cpp deleted file mode 100755 index caedfc6..0000000 --- a/src/math.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * math.cpp - * - * Created on: May 23, 2019 - * Author: nathan - */ - -#include "math.h" - -uint32_t ilog2(uint32_t n, bool roundUp) -{ - uint32_t m = n; - uint32_t count = 0; - bool isPowerOfTwo = true; - while(m) - { - if((m & 1) == 1 && m > 1) - { - isPowerOfTwo = false; - } - count++; - m >>= 1; - } - return count - (isPowerOfTwo ? 1 : (roundUp ? 0 : 1)); -} - - diff --git a/src/math.h b/src/math.h deleted file mode 100755 index 150df64..0000000 --- a/src/math.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * math.h - * - * Created on: May 23, 2019 - * Author: nathan - */ - -#ifndef SRC_MATH_H_ -#define SRC_MATH_H_ - -#include - -/** - * Computes the logarithm in base 2 of a given integer, returning an integer as - * the result. For n = -1, returns unsigned -1. - * - * @returns floor(log2(n)), where n > 0. Else unsigned -1. - */ -uint32_t ilog2(uint32_t n, bool roundUp = false); - - -#endif /* SRC_MATH_H_ */ diff --git a/src/mmgr/Makefile.am b/src/mmgr/Makefile.am new file mode 100644 index 0000000..a4fd810 --- /dev/null +++ b/src/mmgr/Makefile.am @@ -0,0 +1,7 @@ +noinst_LIBRARIES = libmmgr.a +libmmgr_a_SOURCES = memorymap.cpp buddyallocator.cpp addressspace.cpp +libmmgr_a_CPPFLAGS = -ffreestanding -O0 -Wall -fno-exceptions -fno-rtti -ggdb + +if x86 +libmmgr_a_SOURCES += x86/pagetableentry.cpp +endif \ No newline at end of file diff --git a/src/addressspace.cpp b/src/mmgr/addressspace.cpp similarity index 100% rename from src/addressspace.cpp rename to src/mmgr/addressspace.cpp diff --git a/src/addressspace.hpp b/src/mmgr/addressspace.hpp similarity index 92% rename from src/addressspace.hpp rename to src/mmgr/addressspace.hpp index b101cd2..eaba986 100755 --- a/src/addressspace.hpp +++ b/src/mmgr/addressspace.hpp @@ -4,8 +4,8 @@ #include #include "memoryallocator.hpp" -#include "pagetableentry.hpp" -#include "systypes.hpp" +#include "x86/pagetableentry.hpp" +#include "types.hpp" namespace kernel { diff --git a/src/buddyallocator.cpp b/src/mmgr/buddyallocator.cpp similarity index 94% rename from src/buddyallocator.cpp rename to src/mmgr/buddyallocator.cpp index c8f9f81..d27e5b3 100755 --- a/src/buddyallocator.cpp +++ b/src/mmgr/buddyallocator.cpp @@ -1,10 +1,26 @@ #include "buddyallocator.hpp" -#include "math.h" -#include "systypes.hpp" +#include "types.hpp" #include "memorymap.hpp" #define roundUp(n, m) ((n % m == 0) ? n : (n + m - (n % m))) +uint32_t ilog2(uint32_t n, bool roundUp) +{ + uint32_t m = n; + uint32_t count = 0; + bool isPowerOfTwo = true; + while(m) + { + if((m & 1) == 1 && m > 1) + { + isPowerOfTwo = false; + } + count++; + m >>= 1; + } + return count - (isPowerOfTwo ? 1 : (roundUp ? 0 : 1)); +} + kernel::BuddyAllocator::BuddyAllocator() { diff --git a/src/buddyallocator.hpp b/src/mmgr/buddyallocator.hpp similarity index 100% rename from src/buddyallocator.hpp rename to src/mmgr/buddyallocator.hpp diff --git a/src/memoryallocator.hpp b/src/mmgr/memoryallocator.hpp similarity index 97% rename from src/memoryallocator.hpp rename to src/mmgr/memoryallocator.hpp index 48ea87c..90b9315 100755 --- a/src/memoryallocator.hpp +++ b/src/mmgr/memoryallocator.hpp @@ -2,7 +2,7 @@ #define __MEMORYALLOCATOR_H_ #include -#include "systypes.hpp" +#include "types.hpp" namespace kernel { diff --git a/src/memorymap.cpp b/src/mmgr/memorymap.cpp similarity index 100% rename from src/memorymap.cpp rename to src/mmgr/memorymap.cpp diff --git a/src/memorymap.hpp b/src/mmgr/memorymap.hpp similarity index 96% rename from src/memorymap.hpp rename to src/mmgr/memorymap.hpp index 853927a..dcfd50a 100644 --- a/src/memorymap.hpp +++ b/src/mmgr/memorymap.hpp @@ -4,7 +4,7 @@ #include #include -#include "systypes.hpp" +#include "types.hpp" namespace kernel { diff --git a/src/mmgr/types.hpp b/src/mmgr/types.hpp new file mode 100644 index 0000000..66a7bc4 --- /dev/null +++ b/src/mmgr/types.hpp @@ -0,0 +1,15 @@ +#ifndef MEM_TYPES_H +#define MEM_TYPES_H + +#include +#include + +#if defined __i386__ +typedef uint32_t physaddr_t; +#elif defined __amd64__ +typedef uint64_t physaddr_t; +#else +typedef uint64_t physaddr_t; +#endif + +#endif diff --git a/src/pagetableentry.cpp b/src/mmgr/x86/pagetableentry.cpp similarity index 100% rename from src/pagetableentry.cpp rename to src/mmgr/x86/pagetableentry.cpp diff --git a/src/pagetableentry.hpp b/src/mmgr/x86/pagetableentry.hpp similarity index 98% rename from src/pagetableentry.hpp rename to src/mmgr/x86/pagetableentry.hpp index 0200953..8070a79 100755 --- a/src/pagetableentry.hpp +++ b/src/mmgr/x86/pagetableentry.hpp @@ -9,7 +9,7 @@ #define SRC_PAGETABLEENTRY_H_ #include -#include "systypes.hpp" +#include "../types.hpp" namespace kernel { diff --git a/src/quarkkernel.cpp b/src/quarkkernel.cpp index d607169..27db887 100755 --- a/src/quarkkernel.cpp +++ b/src/quarkkernel.cpp @@ -3,22 +3,18 @@ #include "systypes.hpp" #include "systeminfo.hpp" -#include "memorymap.hpp" -#include "buddyallocator.hpp" -#include "addressspace.hpp" +#include "mmgr/memorymap.hpp" +#include "mmgr/buddyallocator.hpp" +#include "mmgr/addressspace.hpp" #include "pio.hpp" -#include "tty.h" +#include "tty.hpp" +#include "util.hpp" using namespace kernel; extern SystemInfo system_info; extern MemoryMap::Region memory_map; -extern "C" void __cxa_pure_virtual() -{ - -} - void main(char* cmdline) { TTY tty((char*) 0xC00B8000); diff --git a/src/systypes.hpp b/src/systypes.hpp index cf07e96..be0a7ca 100644 --- a/src/systypes.hpp +++ b/src/systypes.hpp @@ -1,9 +1,6 @@ #ifndef SYSTYPES_H #define SYSTYPES_H -#include -#include - -typedef uint32_t physaddr_t; +#include "mmgr/types.hpp" #endif diff --git a/src/tty.cpp b/src/tty.cpp index dcb80d2..b3132c5 100644 --- a/src/tty.cpp +++ b/src/tty.cpp @@ -1,5 +1,5 @@ #include -#include "tty.h" +#include "tty.hpp" kernel::TTY::TTY(char* vga) { diff --git a/src/tty.h b/src/tty.hpp similarity index 100% rename from src/tty.h rename to src/tty.hpp diff --git a/src/cstring.cpp b/src/util.cpp old mode 100755 new mode 100644 similarity index 93% rename from src/cstring.cpp rename to src/util.cpp index c30febb..fe13afc --- a/src/cstring.cpp +++ b/src/util.cpp @@ -1,13 +1,6 @@ -/* - * cstring.cpp - * - * Created on: Jun 13, 2019 - * Author: nathan - */ - #include -#include -#include "cstring.h" + +#include "util.hpp" void* memcpy(void* destination, const void* source, size_t num) { @@ -82,4 +75,7 @@ void* memset (void* ptr, int value, size_t num) return ptr; } - +void __cxa_pure_virtual() +{ + // do nothing +} \ No newline at end of file diff --git a/src/util.hpp b/src/util.hpp new file mode 100644 index 0000000..acf21d0 --- /dev/null +++ b/src/util.hpp @@ -0,0 +1,16 @@ +#ifndef UTIL_H +#define UTIL_H + +#include + +extern "C" void __cxa_pure_virtual(); + +extern "C" void* memcpy(void* destination, const void* source, size_t num); + +extern "C" void* memmove(void* destination, const void* source, size_t num); + +extern "C" int memcmp(const void* ptr1, const void* ptr2, size_t num); + +extern "C" void* memset(void* ptr, int value, size_t num); + +#endif \ No newline at end of file