Reorganized source tree. Started using autotools.
This commit is contained in:
18
src/Makefile
18
src/Makefile
@@ -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
8
src/Makefile.am
Normal 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
|
||||
|
||||
@@ -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_ */
|
||||
@@ -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)
|
||||
6
src/interrupts/Makefile.am
Normal file
6
src/interrupts/Makefile.am
Normal 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
|
||||
27
src/math.cpp
27
src/math.cpp
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
22
src/math.h
22
src/math.h
@@ -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
7
src/mmgr/Makefile.am
Normal 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
|
||||
@@ -4,8 +4,8 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "memoryallocator.hpp"
|
||||
#include "pagetableentry.hpp"
|
||||
#include "systypes.hpp"
|
||||
#include "x86/pagetableentry.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
namespace kernel {
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define __MEMORYALLOCATOR_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include "systypes.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
namespace kernel
|
||||
{
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "systypes.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
namespace kernel
|
||||
{
|
||||
15
src/mmgr/types.hpp
Normal file
15
src/mmgr/types.hpp
Normal 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
|
||||
@@ -9,7 +9,7 @@
|
||||
#define SRC_PAGETABLEENTRY_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "systypes.hpp"
|
||||
#include "../types.hpp"
|
||||
|
||||
namespace kernel {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#ifndef SYSTYPES_H
|
||||
#define SYSTYPES_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef uint32_t physaddr_t;
|
||||
#include "mmgr/types.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <stdbool.h>
|
||||
#include "tty.h"
|
||||
#include "tty.hpp"
|
||||
|
||||
kernel::TTY::TTY(char* vga)
|
||||
{
|
||||
|
||||
16
src/cstring.cpp → src/util.cpp
Executable file → Normal file
16
src/cstring.cpp → src/util.cpp
Executable file → Normal file
@@ -1,13 +1,6 @@
|
||||
/*
|
||||
* cstring.cpp
|
||||
*
|
||||
* Created on: Jun 13, 2019
|
||||
* Author: nathan
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#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
|
||||
}
|
||||
16
src/util.hpp
Normal file
16
src/util.hpp
Normal 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
|
||||
Reference in New Issue
Block a user