Reorganized source tree. Started using autotools.

This commit is contained in:
2020-07-17 10:03:28 -05:00
parent 36c88daa87
commit 0bb65f2d94
28 changed files with 142 additions and 149 deletions

23
.gitignore vendored
View File

@@ -1,7 +1,26 @@
quark.iso quark.iso
src/quark-kernel quark-kernel
src/interrupts/libinterrupts.a
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 *.o
*~ *~
rootfs/ rootfs/
test/ test/

View File

@@ -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

1
Makefile.am Normal file
View File

@@ -0,0 +1 @@
SUBDIRS = src

32
configure.ac Normal file
View File

@@ -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

View File

@@ -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

8
src/Makefile.am Normal file
View File

@@ -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

View File

@@ -1,26 +0,0 @@
/*
* cstring.h
*
* Created on: Jun 13, 2019
* Author: nathan
*/
#ifndef SRC_CSTRING_H_
#define SRC_CSTRING_H_
#include <stddef.h>
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_ */

View File

@@ -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)

View File

@@ -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

View File

@@ -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));
}

View File

@@ -1,22 +0,0 @@
/*
* math.h
*
* Created on: May 23, 2019
* Author: nathan
*/
#ifndef SRC_MATH_H_
#define SRC_MATH_H_
#include <stdint.h>
/**
* 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_ */

7
src/mmgr/Makefile.am Normal file
View File

@@ -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

View File

@@ -4,8 +4,8 @@
#include <stddef.h> #include <stddef.h>
#include "memoryallocator.hpp" #include "memoryallocator.hpp"
#include "pagetableentry.hpp" #include "x86/pagetableentry.hpp"
#include "systypes.hpp" #include "types.hpp"
namespace kernel { namespace kernel {

View File

@@ -1,10 +1,26 @@
#include "buddyallocator.hpp" #include "buddyallocator.hpp"
#include "math.h" #include "types.hpp"
#include "systypes.hpp"
#include "memorymap.hpp" #include "memorymap.hpp"
#define roundUp(n, m) ((n % m == 0) ? n : (n + m - (n % m))) #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() kernel::BuddyAllocator::BuddyAllocator()
{ {

View File

@@ -2,7 +2,7 @@
#define __MEMORYALLOCATOR_H_ #define __MEMORYALLOCATOR_H_
#include <stddef.h> #include <stddef.h>
#include "systypes.hpp" #include "types.hpp"
namespace kernel namespace kernel
{ {

View File

@@ -4,7 +4,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "systypes.hpp" #include "types.hpp"
namespace kernel namespace kernel
{ {

15
src/mmgr/types.hpp Normal file
View File

@@ -0,0 +1,15 @@
#ifndef MEM_TYPES_H
#define MEM_TYPES_H
#include <stdint.h>
#include <stddef.h>
#if defined __i386__
typedef uint32_t physaddr_t;
#elif defined __amd64__
typedef uint64_t physaddr_t;
#else
typedef uint64_t physaddr_t;
#endif
#endif

View File

@@ -9,7 +9,7 @@
#define SRC_PAGETABLEENTRY_H_ #define SRC_PAGETABLEENTRY_H_
#include <stdint.h> #include <stdint.h>
#include "systypes.hpp" #include "../types.hpp"
namespace kernel { namespace kernel {

View File

@@ -3,22 +3,18 @@
#include "systypes.hpp" #include "systypes.hpp"
#include "systeminfo.hpp" #include "systeminfo.hpp"
#include "memorymap.hpp" #include "mmgr/memorymap.hpp"
#include "buddyallocator.hpp" #include "mmgr/buddyallocator.hpp"
#include "addressspace.hpp" #include "mmgr/addressspace.hpp"
#include "pio.hpp" #include "pio.hpp"
#include "tty.h" #include "tty.hpp"
#include "util.hpp"
using namespace kernel; using namespace kernel;
extern SystemInfo system_info; extern SystemInfo system_info;
extern MemoryMap::Region memory_map; extern MemoryMap::Region memory_map;
extern "C" void __cxa_pure_virtual()
{
}
void main(char* cmdline) void main(char* cmdline)
{ {
TTY tty((char*) 0xC00B8000); TTY tty((char*) 0xC00B8000);

View File

@@ -1,9 +1,6 @@
#ifndef SYSTYPES_H #ifndef SYSTYPES_H
#define SYSTYPES_H #define SYSTYPES_H
#include <stdint.h> #include "mmgr/types.hpp"
#include <stddef.h>
typedef uint32_t physaddr_t;
#endif #endif

View File

@@ -1,5 +1,5 @@
#include <stdbool.h> #include <stdbool.h>
#include "tty.h" #include "tty.hpp"
kernel::TTY::TTY(char* vga) kernel::TTY::TTY(char* vga)
{ {

16
src/cstring.cpp → src/util.cpp Executable file → Normal file
View File

@@ -1,13 +1,6 @@
/*
* cstring.cpp
*
* Created on: Jun 13, 2019
* Author: nathan
*/
#include <stdint.h> #include <stdint.h>
#include <stddef.h>
#include "cstring.h" #include "util.hpp"
void* memcpy(void* destination, const void* source, size_t num) 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; return ptr;
} }
void __cxa_pure_virtual()
{
// do nothing
}

16
src/util.hpp Normal file
View File

@@ -0,0 +1,16 @@
#ifndef UTIL_H
#define UTIL_H
#include <stddef.h>
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