Added dummy HAL and a cross compile build script
This commit is contained in:
parent
d244cb76a6
commit
4bf7f3579a
25 changed files with 661 additions and 9 deletions
49
buildcrosscompiler.sh
Normal file
49
buildcrosscompiler.sh
Normal file
|
@ -0,0 +1,49 @@
|
|||
CROSSPATH=$HOME/opt # You can change it to whatever you want
|
||||
export PATH=$CROSSPATH/bin:$PATH
|
||||
function buildscript() {
|
||||
date "[+%c] " | tr -d '\n' | tee buildlog
|
||||
echo "Building binutils for $1" | tee buildlog
|
||||
mkdir build-binutils
|
||||
cd build-binutils
|
||||
../binutils-2.26/configure --prefix=$CROSSPATH --target=$1 --with-sysroot --disable-nls --disable-werror
|
||||
make -j2
|
||||
make install
|
||||
cd ..
|
||||
rm -rf build-binutils
|
||||
date "[+%c] " | tr -d '\n' | tee buildlog
|
||||
echo "Building gcc for $1" | tee buildlog
|
||||
mkdir build-gcc
|
||||
cd build-gcc
|
||||
../gcc-5.3.0/configure --prefix=$CROSSPATH --target=$1 --disable-nls --enable-languages=c,c++ --without-headers
|
||||
make all-gcc
|
||||
make all-target-libgcc
|
||||
make install-gcc
|
||||
make install-target-libgcc
|
||||
cd ..
|
||||
rm -rf build-gcc
|
||||
date "[+%c] " | tr -d '\n' | tee buildlog
|
||||
echo "Cross-compiler for $1 was built." | tee buildlog
|
||||
}
|
||||
tempdir=$(mktemp -d)
|
||||
cd $tempdir
|
||||
echo "Temponary files are in $tempdir. Build log can be found under $tempdir/buildlog"
|
||||
echo "Downloading GCC, Binutils, MPC, MPFR and GMP"
|
||||
wget ftp://ftp.gnu.org/gnu/gcc/gcc-5.3.0/gcc-5.3.0.tar.bz2 ftp://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.bz2 ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz ftp://ftp.gnu.org/gnu/mpfr/mpfr-3.1.3.tar.xz ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.xz
|
||||
echo "Untaring..."
|
||||
tar -xf gcc-5.3.0.tar.bz2
|
||||
tar -xf binutils-2.26.tar.bz2
|
||||
cd gcc-5.3.0
|
||||
tar -xf mpc-1.0.3.tar.gz
|
||||
mv mpc-1.0.3 mpc
|
||||
tar -xf mpfr-3.1.3.tar.xz
|
||||
mv mpfr-3.1.3 mpfr
|
||||
tar -xf gmp-6.1.0.tar.xz
|
||||
mv gmp-6.1.0 gmp
|
||||
cd ..
|
||||
echo "Preperation done. Beginning the compilation now."
|
||||
buildscript i686-elf #x86 port
|
||||
buildscript arm-none-eabi #ARM ports (3DS, pi)
|
||||
buildscript armeb-eabi #Wii port
|
||||
buildscript ppc-elf #Wii port
|
||||
rm -rf gcc* binutils* mpc* mpfr* gmp*
|
||||
echo "Done! Have fun with your cross compilers!"
|
|
@ -1,8 +1,11 @@
|
|||
include ../kernel.settings
|
||||
SRCS = $(shell find -name '*.cpp' -o -name '*.[cS]')
|
||||
SRCS = $(shell find hal/$(arch) -name '*.cpp' -o -name '*.[cS]')
|
||||
OBJS = $(addsuffix .o,$(basename $(SRCS)))
|
||||
LD = $(PREFIX)g++
|
||||
LDFLAGS = -T kernel.ld -nostdlib -nodefaultlibs -m32 -nostdlib -fno-builtin
|
||||
LDFLAGS = -nostdlib -nodefaultlibs -nostdlib -fno-builtin
|
||||
ifeq ($(arch),x86)
|
||||
LDFLAGS += -m32 -T kernel.ld
|
||||
endif
|
||||
all: hal
|
||||
$(LD) $(LDFLAGS) -o mtgos $(OBJS)
|
||||
hal:
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
all: x86
|
||||
|
||||
x86:
|
||||
make -C x86
|
||||
|
||||
include ../../kernel.settings
|
||||
all:
|
||||
make -C $(arch)
|
||||
clean:
|
||||
rm -rf hal.o
|
||||
make -C x86 clean
|
||||
make -C $(arch) clean
|
||||
|
||||
.PHONY: all x86 clean
|
||||
.PHONY: all clean
|
||||
|
|
26
kernel/hal/dummy/Makefile
Normal file
26
kernel/hal/dummy/Makefile
Normal file
|
@ -0,0 +1,26 @@
|
|||
include ../../../kernel.settings
|
||||
SRCS = $(shell find -name '*.cpp' -o -name '*.[cS]')
|
||||
OBJS = $(addsuffix .o,$(basename $(SRCS)))
|
||||
|
||||
CPP = $(PREFIX)g++
|
||||
CC = $(PREFIX)gcc
|
||||
ASFLAGS =
|
||||
CFLAGS = -Wall -fno-stack-protector -nostdinc -Ic_include/ -ffreestanding -march=native -std=c11 -fno-builtin -Werror -nostdlib -g
|
||||
CPPFLAGS = -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -fno-rtti -fno-exceptions -ffreestanding -march=native -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g
|
||||
LDFLAGS = -r
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CPP) $(CPPFLAGS) -c -o $@ $^
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c -o $@ $^
|
||||
|
||||
%.o: $.S
|
||||
$(CC) $(CFLAGS) -c -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJS)
|
||||
|
||||
.PHONY: clean all
|
0
kernel/hal/dummy/asm/snippets.S
Normal file
0
kernel/hal/dummy/asm/snippets.S
Normal file
15
kernel/hal/dummy/boot/boot.S
Normal file
15
kernel/hal/dummy/boot/boot.S
Normal file
|
@ -0,0 +1,15 @@
|
|||
.section multiboot
|
||||
#define MB_MAGIC 0x1BADB002
|
||||
#define MB_FLAGS 0x0
|
||||
#define MB_CHECKSUM -(MB_MAGIC + MB_FLAGS)
|
||||
.align 4
|
||||
.int MB_MAGIC
|
||||
.int MB_FLAGS
|
||||
.int MB_CHECKSUM
|
||||
.section .text
|
||||
.extern init
|
||||
.global _start
|
||||
_start:
|
||||
.section .bss
|
||||
.space 8192
|
||||
kernel_stack:
|
53
kernel/hal/dummy/c_include/io.h
Normal file
53
kernel/hal/dummy/c_include/io.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
#ifndef _IO_H
|
||||
#define _IO_H
|
||||
#include <stdint.h>
|
||||
static inline void outb(uint16_t port, uint8_t val) __attribute__((always_inline));
|
||||
static inline void outb(uint16_t port, uint8_t val) {
|
||||
asm volatile("outb %0, %1" : : "a"(val), "Nd"(port));
|
||||
}
|
||||
static inline void outw(uint16_t port, uint16_t val) __attribute__((always_inline));
|
||||
static inline void outw(uint16_t port, uint16_t val) {
|
||||
asm volatile("outw %0, %1" : : "a"(val), "Nd"(port));
|
||||
}
|
||||
static inline void outl(uint16_t port, uint32_t val) __attribute__((always_inline));
|
||||
static inline void outl(uint16_t port, uint32_t val) {
|
||||
asm volatile("outl %0, %1" : : "a"(val), "Nd"(port));
|
||||
}
|
||||
static inline uint8_t inb(uint16_t port) __attribute__((always_inline));
|
||||
static inline uint8_t inb(uint16_t port) {
|
||||
uint8_t ret;
|
||||
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
|
||||
return ret;
|
||||
}
|
||||
static inline uint16_t inw(uint16_t port) __attribute__((always_inline));
|
||||
static inline uint16_t inw(uint16_t port) {
|
||||
uint16_t ret;
|
||||
asm volatile("inw %1, %0" : "=a"(ret) : "Nd"(port));
|
||||
return ret;
|
||||
}
|
||||
static inline uint32_t inl(uint16_t port) __attribute__((always_inline));
|
||||
static inline uint32_t inl(uint16_t port) {
|
||||
uint32_t ret;
|
||||
asm volatile("inl %1, %0" : "=a"(ret) : "Nd"(port));
|
||||
return ret;
|
||||
}
|
||||
static inline void io_wait() __attribute__((always_inline));
|
||||
static inline void io_wait() {
|
||||
asm volatile("outb %%al, $0x80" : : "a"(0));
|
||||
}
|
||||
static inline void cli() __attribute__((always_inline));
|
||||
static inline void cli() {
|
||||
asm volatile("cli");
|
||||
}
|
||||
static inline void sti() __attribute__((always_inline));
|
||||
static inline void sti() {
|
||||
asm volatile("sti");
|
||||
}
|
||||
static inline uint64_t rdtsc() __attribute__((always_inline));
|
||||
static inline uint64_t rdtsc()
|
||||
{
|
||||
uint64_t ret;
|
||||
asm volatile ( "rdtsc" : "=A"(ret) );
|
||||
return ret;
|
||||
}
|
||||
#endif
|
9
kernel/hal/dummy/c_include/stdint.h
Normal file
9
kernel/hal/dummy/c_include/stdint.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef signed long long int int64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long int uint64_t;
|
||||
typedef unsigned int uintptr_t;
|
11
kernel/hal/dummy/c_include/string.h
Normal file
11
kernel/hal/dummy/c_include/string.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef _STRING_H
|
||||
#define _STRING_H
|
||||
#ifdef _cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
void memmove(void* dst, void* src, uint32_t size);
|
||||
#ifdef _cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
23
kernel/hal/dummy/include/Multitasking.h
Normal file
23
kernel/hal/dummy/include/Multitasking.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef MULTITASKING_H
|
||||
#define MULTITASKING_H
|
||||
namespace MTGosHAL {
|
||||
|
||||
class Multitasking
|
||||
{
|
||||
public:
|
||||
Multitasking();
|
||||
auto schedule(struct cpu_state* cpu) -> struct cpu_state*;
|
||||
protected:
|
||||
private:
|
||||
auto initTask(uint8_t* stck, void(*entry)()) -> struct cpu_state*;
|
||||
static auto task_a() -> void;
|
||||
static auto task_b() -> void;
|
||||
uint8_t stack_a[4096];
|
||||
uint8_t stack_b[4096];
|
||||
struct cpu_state* task_states[2];
|
||||
int current_task, num_tasks;
|
||||
};
|
||||
|
||||
} // namespace MTGosHAL
|
||||
|
||||
#endif // MULTITASKING_H
|
19
kernel/hal/dummy/include/base.hpp
Normal file
19
kernel/hal/dummy/include/base.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef _BASE_HPP
|
||||
#define _BASE_HPP
|
||||
#include <stdint.h>
|
||||
namespace MTGosHAL {
|
||||
class Output;
|
||||
class Input;
|
||||
class Serial;
|
||||
class Screen;
|
||||
class Keyboard;
|
||||
class Multitasking;
|
||||
enum class BG_color: uint16_t;
|
||||
enum class FG_color: uint16_t;
|
||||
extern Serial debug;
|
||||
extern Screen out;
|
||||
extern Screen err;
|
||||
extern Keyboard in;
|
||||
extern Multitasking tasks;
|
||||
}
|
||||
#endif
|
29
kernel/hal/dummy/include/input.hpp
Normal file
29
kernel/hal/dummy/include/input.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef _INPUT_HPP
|
||||
#define _INPUT_HPP
|
||||
namespace MTGosHAL {
|
||||
class Input {
|
||||
private:
|
||||
virtual auto getChar() -> char = 0;
|
||||
public:
|
||||
auto operator>>(char &input) -> Input & {
|
||||
input=getChar();
|
||||
return *this;
|
||||
}
|
||||
//Note that it receives up to 256 bytes.
|
||||
auto operator>>(char* input) -> Input & {
|
||||
int ptr=0;
|
||||
char tmp='\0';
|
||||
while(ptr<256 && tmp!='\r') {
|
||||
while(!(tmp=getChar()));
|
||||
if(tmp=='\r')
|
||||
input[ptr++]='\0';
|
||||
else
|
||||
input[ptr++]=tmp;
|
||||
}
|
||||
input[255]='\0';
|
||||
return *this;
|
||||
}
|
||||
//TODO: Add more possibilities.
|
||||
};
|
||||
}
|
||||
#endif
|
22
kernel/hal/dummy/include/keyboard.hpp
Normal file
22
kernel/hal/dummy/include/keyboard.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef _KEYBOARD_HPP
|
||||
#define _KEYBOARD_HPP
|
||||
#include <stdint.h>
|
||||
#include <input.hpp>
|
||||
#include <io.h>
|
||||
namespace MTGosHAL {
|
||||
|
||||
class Keyboard: public Input {
|
||||
private:
|
||||
|
||||
//This kernel has a buffer of 16 chars
|
||||
char buf[16];
|
||||
int len;
|
||||
auto getChar() -> char;
|
||||
auto sendCommand(uint8_t command) -> void;
|
||||
bool numlock, capslock, scrolllock, response;
|
||||
public:
|
||||
auto handleIRQ1(struct cpu_state* cpu) -> struct cpu_state*;
|
||||
Keyboard();
|
||||
};
|
||||
}
|
||||
#endif // -Wno-pmf-conversions
|
41
kernel/hal/dummy/include/keycodes.hpp
Normal file
41
kernel/hal/dummy/include/keycodes.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#ifndef _KEYCODES_HPP
|
||||
#define _KEYCODES_HPP
|
||||
bool keydowns[0x69];
|
||||
uint8_t keyboardKeycodes[2][128] {
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
|
||||
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x00, 0x00, 0x54, 0x55,
|
||||
0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
}, {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x57, 0x58, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00,
|
||||
0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5B,
|
||||
0x5C, 0x5D, 0x00, 0x5E, 0x00, 0x5F, 0x00, 0x60,
|
||||
0x61, 0x62, 0x63, 0x64, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x64, 0x65, 0x66, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
17
kernel/hal/dummy/include/keymap_DE.hpp
Normal file
17
kernel/hal/dummy/include/keymap_DE.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef _KEYMAP_DE_HPP
|
||||
#define _KEYMAP_DE_HPP
|
||||
#include <keycodes.hpp>
|
||||
#define SHIFT 1
|
||||
#define CTRL 2
|
||||
#define ALT 4
|
||||
char keymap[8][0x80] = {
|
||||
"\0\0001234567890\xe1\0\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\000789-456+1230,<\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // No modifier
|
||||
"\0\000!\"\0$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Shift modifier
|
||||
"\0\0001234567890\xe1\0\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,<\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control modifier
|
||||
"\0\000!\"\0$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Shift modifiers
|
||||
"\0\0001234567890\xe1\0\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,<\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Alt modifier
|
||||
"\0\000!\"\0$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Alt+Shift modifiers
|
||||
"\0\0001\xFD\x33\xAC\xAB\xAA{[]}\\\xa7\b\0@w\xEErtzui\xEDp\x81~\n\0\x91sdfghjkl\x94^\0#\xAF\xAE\x9Bvbn\xe6,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,|\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Alt modifiers
|
||||
"\0\000\xAD\"\x9C\x0F%&/(\xF1\xF8\xA8`\b\0\xEAW\xEERT\x9DUIOP\xF8*\n\0\x92SD\xA6GHJ&L\x99\x8e\xF8\0|YXCVBN\xF8;\xF6_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,|\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Shift modifiers
|
||||
};
|
||||
#endif
|
46
kernel/hal/dummy/include/output.hpp
Normal file
46
kernel/hal/dummy/include/output.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef _OUTPUT_HPP
|
||||
#define _OUTPUT_HPP
|
||||
#include <base.hpp>
|
||||
#include <stdint.h>
|
||||
namespace MTGosHAL {
|
||||
|
||||
enum class Base : int {
|
||||
BINARY=2,
|
||||
TERNARY,
|
||||
BASE4,
|
||||
BASE5,
|
||||
BASE6,
|
||||
BASE7,
|
||||
OCTAL,
|
||||
BASE9,
|
||||
DECIMAL,
|
||||
BASE11,
|
||||
BASE12,
|
||||
BASE13,
|
||||
BASE14,
|
||||
BASE15,
|
||||
HEXADECIMAL
|
||||
};
|
||||
/* abstract */ class Output {
|
||||
private:
|
||||
virtual auto putChar(char c) -> void = 0;
|
||||
auto puts(const char* s) -> void;
|
||||
int base=10;
|
||||
public:
|
||||
template <typename T>
|
||||
auto operator<<(T output) -> Output & {
|
||||
puts(output); //kernel won't compile if class cannot be converted into string
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
template <>
|
||||
auto Output::operator<<<Base>(Base output) -> Output &;
|
||||
template <>
|
||||
auto Output::operator<<<int>(int output) -> Output &;
|
||||
template <>
|
||||
auto Output::operator<<<char>(char output) -> Output &;
|
||||
template <>
|
||||
auto Output::operator<<<char*>(char* output) -> Output &;
|
||||
}
|
||||
#endif
|
31
kernel/hal/dummy/include/serial.hpp
Normal file
31
kernel/hal/dummy/include/serial.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef _SERIAL_HPP
|
||||
#define _SERIAL_HPP
|
||||
#include <output.hpp>
|
||||
#include <input.hpp>
|
||||
#include <textDISP.hpp>
|
||||
#include <io.h>
|
||||
#define SERIAL_IER 1
|
||||
#define SERIAL_IIR 2
|
||||
#define SERIAL_FCR 2
|
||||
#define SERIAL_LCR 3
|
||||
#define SERIAL_MCR 4
|
||||
#define SERIAL_LSR 5
|
||||
#define SERIAL_MSR 6
|
||||
namespace MTGosHAL {
|
||||
class Serial: public Output, public Input {
|
||||
private:
|
||||
uint16_t port;
|
||||
uint64_t waittimes;
|
||||
uint64_t transmits;
|
||||
bool works;
|
||||
auto isTransmitEmpty() -> int;
|
||||
auto putChar(char chr) -> void;
|
||||
auto serial_received() -> int;
|
||||
auto getChar() -> char;
|
||||
public:
|
||||
Serial();
|
||||
auto debug() -> void;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
70
kernel/hal/dummy/include/textDISP.hpp
Normal file
70
kernel/hal/dummy/include/textDISP.hpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#ifndef _TEXTDISP_H
|
||||
#define _TEXTDISP_H
|
||||
#include <stdint.h>
|
||||
#include <output.hpp>
|
||||
#define SCREEN_WIDTH 80
|
||||
#define SCREEN_HEIGHT 24
|
||||
namespace MTGosHAL {
|
||||
enum class BG_color : uint16_t {
|
||||
BLACK=0x0000,
|
||||
BLUE=0x1000,
|
||||
GREEN=0x2000,
|
||||
CYAN=0x3000,
|
||||
RED=0x4000,
|
||||
MAGENTA=0x5000,
|
||||
BROWN=0x6000,
|
||||
LIGHT_GREY=0x7000,
|
||||
GREY=0x8000,
|
||||
LIGHT_BLUE=0x9000,
|
||||
LIGHT_GREEN=0xA000,
|
||||
LIGHT_CYAN=0xB000,
|
||||
LIGHT_RED=0xC000,
|
||||
LIGHT_MAGENTA=0xD000,
|
||||
YELLOW=0xE000,
|
||||
WHITE=0xF000
|
||||
};
|
||||
enum class FG_color : uint16_t {
|
||||
BLACK=0x000,
|
||||
BLUE=0x100,
|
||||
GREEN=0x200,
|
||||
CYAN=0x300,
|
||||
RED=0x400,
|
||||
MAGENTA=0x500,
|
||||
BROWN=0x600,
|
||||
LIGHT_GREY=0x700,
|
||||
GREY=0x800,
|
||||
LIGHT_BLUE=0x900,
|
||||
LIGHT_GREEN=0xA00,
|
||||
LIGHT_CYAN=0xB00,
|
||||
LIGHT_RED=0xC00,
|
||||
LIGHT_MAGENTA=0xD00,
|
||||
YELLOW=0xE00,
|
||||
WHITE=0xF00
|
||||
};
|
||||
class Screen: public Output {
|
||||
private:
|
||||
FG_color fg;
|
||||
BG_color bg;
|
||||
uint16_t* vmem=(uint16_t*)0xB8000;
|
||||
auto putChar(char c) -> void;
|
||||
public:
|
||||
Screen() {
|
||||
clrscr();
|
||||
}
|
||||
template <typename T>
|
||||
auto operator<< (T output) -> Screen & {
|
||||
Output::operator<<<T>(output);
|
||||
return *this;
|
||||
}
|
||||
auto clrscr() -> void;
|
||||
auto scroll() -> void;
|
||||
auto setColor(FG_color fg) -> Screen &;
|
||||
auto setColor(BG_color bg) -> Screen &;
|
||||
auto setColor(FG_color fg, BG_color bg) -> Screen &;
|
||||
};
|
||||
template <>
|
||||
auto Screen::operator<<<FG_color>(FG_color fg) -> Screen &;
|
||||
template <>
|
||||
auto Screen::operator<<<BG_color>(BG_color bg) -> Screen &;
|
||||
}
|
||||
#endif
|
36
kernel/hal/dummy/init/Multitasking.cpp
Normal file
36
kernel/hal/dummy/init/Multitasking.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <base.hpp>
|
||||
#include <textDISP.hpp>
|
||||
#include <Multitasking.h>
|
||||
#include <serial.hpp>
|
||||
/*auto schedule(struct cpu_state* cpu) -> struct cpu_state* {
|
||||
return MTGosHAL::tasks.schedule(cpu);
|
||||
}*/
|
||||
namespace MTGosHAL {
|
||||
|
||||
Multitasking::Multitasking(): current_task(-1), num_tasks(2)
|
||||
{
|
||||
task_states[0] = initTask(stack_a, task_a);
|
||||
task_states[1] = initTask(stack_b, task_b);
|
||||
}
|
||||
auto Multitasking::initTask(uint8_t* stck, void(* entry)()) -> struct cpu_state*
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto Multitasking::task_a() -> void
|
||||
{
|
||||
while(true)
|
||||
out << "A";
|
||||
}
|
||||
|
||||
auto Multitasking::task_b() -> void
|
||||
{
|
||||
while(true)
|
||||
out << "B";
|
||||
}
|
||||
auto Multitasking::schedule(struct cpu_state* cpu) -> struct cpu_state*
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace MTGosHAL
|
32
kernel/hal/dummy/init/init.cpp
Normal file
32
kernel/hal/dummy/init/init.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <base.hpp>
|
||||
#include <output.hpp>
|
||||
#include <serial.hpp>
|
||||
#include <textDISP.hpp>
|
||||
#include <keyboard.hpp>
|
||||
#include <Multitasking.h>
|
||||
extern "C" void intr_stub_0(void);
|
||||
namespace MTGosHAL {
|
||||
Serial debug;
|
||||
Screen out;
|
||||
Screen err;
|
||||
Keyboard in;
|
||||
Multitasking tasks;
|
||||
void main() {
|
||||
out << BG_color::BLACK << FG_color::WHITE << "Loading MTGos...\n";
|
||||
err << BG_color::BLACK << FG_color::RED;
|
||||
debug << "Hello debugger! This is MTGos v00r01\nThese logs are probably very long, so please redirect the output to a file.\n";
|
||||
for(;;);
|
||||
}
|
||||
}
|
||||
typedef void (*constructor)();
|
||||
extern "C" constructor start_ctors;
|
||||
extern "C" constructor end_ctors;
|
||||
extern "C" void init() {
|
||||
for(constructor* i = &start_ctors; i != &end_ctors; ++i)
|
||||
(*i)();
|
||||
MTGosHAL::main();
|
||||
}
|
||||
extern "C" void __cxa_pure_virtual() {
|
||||
MTGosHAL::debug << "A pure virtual function just got called.\n";
|
||||
}
|
||||
|
20
kernel/hal/dummy/io/keyboard.cpp
Normal file
20
kernel/hal/dummy/io/keyboard.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <base.hpp>
|
||||
#include <output.hpp>
|
||||
#include <serial.hpp>
|
||||
#include <keyboard.hpp>
|
||||
#include <keymap_DE.hpp>
|
||||
auto handleIRQ(struct cpu_state* cpu) -> struct cpu_state* {
|
||||
return cpu;
|
||||
}
|
||||
namespace MTGosHAL {
|
||||
auto Keyboard::getChar() -> char {
|
||||
return '\0';
|
||||
}
|
||||
auto Keyboard::sendCommand(uint8_t command) -> void {
|
||||
}
|
||||
auto Keyboard::handleIRQ1(struct cpu_state* cpu) -> struct cpu_state* {
|
||||
return cpu;
|
||||
}
|
||||
Keyboard::Keyboard(): numlock(true), capslock(false), scrolllock(false), response(false) {
|
||||
}
|
||||
}
|
39
kernel/hal/dummy/io/output.cpp
Normal file
39
kernel/hal/dummy/io/output.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <base.hpp>
|
||||
#include <output.hpp>
|
||||
#include <serial.hpp>
|
||||
#include <textDISP.hpp>
|
||||
namespace MTGosHAL {
|
||||
auto Output::puts(const char* s) -> void {
|
||||
int i=0;
|
||||
while(s[i]!='\0')
|
||||
putChar(s[i++]);
|
||||
}
|
||||
template <>
|
||||
auto Output::operator<<<Base>(Base output) -> Output & {
|
||||
base=static_cast<int>(output);
|
||||
return *this;
|
||||
}
|
||||
template <>
|
||||
auto Output::operator<<<int>(int output) -> Output & {
|
||||
const char* chars="0123456789ABCDEF";
|
||||
char buf[33];
|
||||
buf[32]='\0';
|
||||
char* ptr=buf+31;
|
||||
do {
|
||||
*(ptr--)=chars[output%base];
|
||||
output/=base;
|
||||
} while(output && (ptr!=buf));
|
||||
puts(ptr+1);
|
||||
return *this;
|
||||
}
|
||||
template <>
|
||||
auto Output::operator<<<char>(char output) -> Output & {
|
||||
putChar(output);
|
||||
return *this;
|
||||
}
|
||||
template <>
|
||||
auto Output::operator<<<char*>(char* output) -> Output & {
|
||||
puts(output);
|
||||
return *this;
|
||||
}
|
||||
}
|
19
kernel/hal/dummy/io/serial.cpp
Normal file
19
kernel/hal/dummy/io/serial.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <base.hpp>
|
||||
#include <serial.hpp>
|
||||
namespace MTGosHAL {
|
||||
auto Serial::isTransmitEmpty() -> int {
|
||||
return 0;
|
||||
}
|
||||
auto Serial::putChar(char chr) -> void {
|
||||
}
|
||||
auto Serial::serial_received() -> int {
|
||||
return 0;
|
||||
}
|
||||
auto Serial::getChar() -> char {
|
||||
return '\0';
|
||||
}
|
||||
Serial::Serial(): works(true) {
|
||||
}
|
||||
auto Serial::debug() -> void {
|
||||
}
|
||||
}
|
32
kernel/hal/dummy/io/textDISP.cpp
Normal file
32
kernel/hal/dummy/io/textDISP.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <base.hpp>
|
||||
#include <textDISP.hpp>
|
||||
int x=0, y=0;
|
||||
namespace MTGosHAL {
|
||||
auto Screen::putChar(char c) -> void {
|
||||
}
|
||||
auto Screen::clrscr() -> void {
|
||||
}
|
||||
auto Screen::scroll() -> void {
|
||||
}
|
||||
template <>
|
||||
auto Screen::operator<<<FG_color>(FG_color fg) -> Screen &{
|
||||
this->fg=fg;
|
||||
return *this;
|
||||
}
|
||||
template <>
|
||||
auto Screen::operator<<<BG_color>(BG_color bg) -> Screen &{
|
||||
this->bg=bg;
|
||||
return *this;
|
||||
}
|
||||
auto Screen::setColor(FG_color fg) -> Screen &{
|
||||
this->fg=fg;
|
||||
return *this;
|
||||
}
|
||||
auto Screen::setColor(BG_color bg) -> Screen &{
|
||||
this->bg=bg;
|
||||
return *this;
|
||||
}
|
||||
auto Screen::setColor(FG_color fg, BG_color bg) -> Screen &{
|
||||
return (*this).setColor(fg).setColor(bg);
|
||||
}
|
||||
}
|
12
kernel/hal/dummy/string.c
Normal file
12
kernel/hal/dummy/string.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <string.h>
|
||||
__attribute__((optimize(0))) void memmove(void* dst, void* src, uint32_t size) {
|
||||
uint8_t* from=(uint8_t*)src;
|
||||
uint8_t* to=(uint8_t*)dst;
|
||||
if((src<dst)&&((src+size)>dst)) {
|
||||
for(int i=size-1;i>=0;i--)
|
||||
to[i]=from[i]; //This would get optimized by gcc to memmove(dst, src, size); if optimizations are enabled.
|
||||
} else if(src != dst) {
|
||||
for(int i=0;i<size;i++)
|
||||
to[i]=from[i]; //This would get optimized by gcc to memmove(dst, src, size); if optimizations are enabled.
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue