added CGA terminal
This commit is contained in:
parent
2503a36016
commit
ded713bb4e
13 changed files with 138 additions and 16 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -6,3 +6,5 @@ builddir/
|
||||||
config.cmake
|
config.cmake
|
||||||
config.h
|
config.h
|
||||||
gen*.h
|
gen*.h
|
||||||
|
build/
|
||||||
|
__pycache__/
|
||||||
|
|
|
@ -28,6 +28,12 @@ def get_yes_no(p, default=None):
|
||||||
if (x == "") and default is not None:
|
if (x == "") and default is not None:
|
||||||
return default
|
return default
|
||||||
return x in "yY"
|
return x in "yY"
|
||||||
|
def add_driver(common, name):
|
||||||
|
if common:
|
||||||
|
drivers.append("hw/"+name+"/")
|
||||||
|
else:
|
||||||
|
drivers.append("hw/"+config["SYSTEM"]+"/"+name+"/")
|
||||||
|
drivers=[]
|
||||||
config={}
|
config={}
|
||||||
config["ARCH"] = get_from_list("Architecture", ["x86","x86_64","arm"])
|
config["ARCH"] = get_from_list("Architecture", ["x86","x86_64","arm"])
|
||||||
exec(open("kernel/arch/"+config["ARCH"]+"/config.py").read())
|
exec(open("kernel/arch/"+config["ARCH"]+"/config.py").read())
|
||||||
|
@ -41,6 +47,8 @@ with open("config.cmake", "w") as f:
|
||||||
f.write('SET('+key+' 1)\n')
|
f.write('SET('+key+' 1)\n')
|
||||||
elif val != False:
|
elif val != False:
|
||||||
f.write('SET('+key+' '+str(val)+')\n')
|
f.write('SET('+key+' '+str(val)+')\n')
|
||||||
|
for driver in drivers:
|
||||||
|
f.write("SET(DRIVER_SRCS ${DRIVER_SRCS} "+driver+"*.c "+driver+"*.cpp "+driver+"*.s)\n")
|
||||||
|
|
||||||
with open("config.h", "w") as f:
|
with open("config.h", "w") as f:
|
||||||
for key, val in config.items():
|
for key, val in config.items():
|
||||||
|
|
|
@ -25,12 +25,12 @@ FUNCTION(LOAD_PROFILE ISA PLATFORM)
|
||||||
SET(ISA_LINKER_FLAGS ${ISA_LINKER_FLAGS} PARENT_SCOPE)
|
SET(ISA_LINKER_FLAGS ${ISA_LINKER_FLAGS} PARENT_SCOPE)
|
||||||
SET(PLATFORM_LINKER_FLAGS ${ISA_LINKER_FLAGS} PARENT_SCOPE)
|
SET(PLATFORM_LINKER_FLAGS ${ISA_LINKER_FLAGS} PARENT_SCOPE)
|
||||||
ENDFUNCTION(LOAD_PROFILE)
|
ENDFUNCTION(LOAD_PROFILE)
|
||||||
FILE(GLOB_RECURSE GENERIC_SRCS src/*.c src/*.cpp)
|
FILE(GLOB_RECURSE GENERIC_SRCS src/*.c src/*.cpp ${DRIVER_SRCS})
|
||||||
LOAD_PROFILE(${ARCH} ${SYSTEM})
|
LOAD_PROFILE(${ARCH} ${SYSTEM})
|
||||||
ADD_EXECUTABLE(kernel ${PLATFORM_SRCS} ${ISA_SRCS} ${GENERIC_SRCS})
|
ADD_EXECUTABLE(kernel ${PLATFORM_SRCS} ${ISA_SRCS} ${GENERIC_SRCS})
|
||||||
SET(CMAKE_ASM-ATT_COMPILE_OBJECT
|
SET(CMAKE_ASM-ATT_COMPILE_OBJECT
|
||||||
"<CMAKE_C_COMPILER> -m32 -x assembler-with-cpp -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_ASM_FLAGS} ${PLATFORM_ASM_FLAGS} -c -o <OBJECT> <SOURCE>")
|
"<CMAKE_C_COMPILER> -g -m32 -x assembler-with-cpp -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_ASM_FLAGS} ${PLATFORM_ASM_FLAGS} -c -o <OBJECT> <SOURCE>")
|
||||||
SET(CMAKE_C_FLAGS "-m32 -w -Werror -Wno-unused -Wno-unused-variable -std=c11 -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_C_FLAGS} ${PLATFORM_C_FLAGS}")
|
SET(CMAKE_C_FLAGS "-g -m32 -w -Werror -Wno-unused -Wno-unused-variable -std=c11 -ffreestanding -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_C_FLAGS} ${PLATFORM_C_FLAGS}")
|
||||||
SET(CMAKE_CXX_FLAGS "-m32 -w -Werror -Wno-unused -Wno-unused-variable -fno-rtti -fno-exceptions -std=gnu++17 -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_CXX_FLAGS} ${PLATFORM_CXX_FLAGS}")
|
SET(CMAKE_CXX_FLAGS "-g -m32 -w -Werror -Wno-unused -Wno-unused-variable -ffreestanding -fno-rtti -fno-exceptions -std=gnu++17 -I../../ -I../../libk/include/ -I../../kernel/src/include/ ${ISA_CXX_FLAGS} ${PLATFORM_CXX_FLAGS}")
|
||||||
SET_TARGET_PROPERTIES(kernel PROPERTIES LINK_FLAGS
|
SET_TARGET_PROPERTIES(kernel PROPERTIES LINK_FLAGS
|
||||||
"-T ../../kernel/${PLATFORM_LAYOUT} -N ${ISA_LINKER_FLAGS} ${PLATFORM_LINKER_FLAGS} -nostdlib -nodefaultlibs -lgcc -Wl,--gc-sections")
|
"-T ../../kernel/${PLATFORM_LAYOUT} -N ${ISA_LINKER_FLAGS} ${PLATFORM_LINKER_FLAGS} -nostdlib -nodefaultlibs -lgcc -Wl,--gc-sections")
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
void start() {
|
|
||||||
const char hw[] = "Hello World!";
|
|
||||||
int i;
|
|
||||||
char* video = (char*) 0xb8000;
|
|
||||||
for (i = 0; hw[i] != '\0'; i++) {
|
|
||||||
video[i * 2] = hw[i];
|
|
||||||
video[i * 2 + 1] = 0x07;
|
|
||||||
}
|
|
||||||
}
|
|
6
kernel/arch/x86/pc/start.cpp
Normal file
6
kernel/arch/x86/pc/start.cpp
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#include <tty.hpp>
|
||||||
|
#include "../../../hw/pc/cgaterm/cgaterm.hpp"
|
||||||
|
extern "C" void start() {
|
||||||
|
CGATerm x = CGATerm();
|
||||||
|
x << "Hallo!\n";
|
||||||
|
}
|
69
kernel/hw/pc/cgaterm/cgaterm.cpp
Normal file
69
kernel/hw/pc/cgaterm/cgaterm.cpp
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#include "cgaterm.hpp"
|
||||||
|
#include "cp437.hpp"
|
||||||
|
CGATerm::CGATerm(): TTY(80, 25) {}
|
||||||
|
CGATerm::~CGATerm() {}
|
||||||
|
auto CGATerm::rgbSupport() -> bool {return false;}
|
||||||
|
struct ScreenChar {
|
||||||
|
unsigned char ch;
|
||||||
|
char fgcolor:4;
|
||||||
|
char bgcolor:4;
|
||||||
|
}__attribute__((packed));
|
||||||
|
ScreenChar *scr = (ScreenChar*)0xB8000;
|
||||||
|
auto CGATerm::plotChar(int x, int y, int c) -> void {
|
||||||
|
char ch = unicodeToCP437(c);
|
||||||
|
scr[y*80+x].ch = ch;
|
||||||
|
scr[y*80+x].bgcolor = 0;
|
||||||
|
char col = 0;
|
||||||
|
switch(curColor) {
|
||||||
|
case Color::BLACK:
|
||||||
|
col = 0;
|
||||||
|
break;
|
||||||
|
case Color::BLUE:
|
||||||
|
col = 1;
|
||||||
|
break;
|
||||||
|
case Color::GREEN:
|
||||||
|
col = 2;
|
||||||
|
break;
|
||||||
|
case Color::CYAN:
|
||||||
|
col = 3;
|
||||||
|
break;
|
||||||
|
case Color::RED:
|
||||||
|
col = 4;
|
||||||
|
break;
|
||||||
|
case Color::MAGENTA:
|
||||||
|
col = 5;
|
||||||
|
break;
|
||||||
|
case Color::BROWN:
|
||||||
|
col = 6;
|
||||||
|
break;
|
||||||
|
case Color::LIGHT_GRAY:
|
||||||
|
col = 7;
|
||||||
|
break;
|
||||||
|
case Color::GRAY:
|
||||||
|
col = 8;
|
||||||
|
break;
|
||||||
|
case Color::LIGHT_BLUE:
|
||||||
|
col = 9;
|
||||||
|
break;
|
||||||
|
case Color::LIGHT_GREEN:
|
||||||
|
col = 10;
|
||||||
|
break;
|
||||||
|
case Color::LIGHT_CYAN:
|
||||||
|
col = 11;
|
||||||
|
break;
|
||||||
|
case Color::LIGHT_RED:
|
||||||
|
col = 12;
|
||||||
|
break;
|
||||||
|
case Color::LIGHT_MAGENTA:
|
||||||
|
col = 13;
|
||||||
|
break;
|
||||||
|
case Color::YELLOW:
|
||||||
|
col = 14;
|
||||||
|
break;
|
||||||
|
case Color::WHITE:
|
||||||
|
col = 15;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
scr[y*80+x].fgcolor = col;
|
||||||
|
}
|
||||||
|
|
10
kernel/hw/pc/cgaterm/cgaterm.hpp
Normal file
10
kernel/hw/pc/cgaterm/cgaterm.hpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
#include <tty.hpp>
|
||||||
|
class CGATerm: public TTY {
|
||||||
|
protected:
|
||||||
|
virtual auto plotChar(int x, int y, int c) -> void;
|
||||||
|
public:
|
||||||
|
CGATerm();
|
||||||
|
virtual ~CGATerm();
|
||||||
|
virtual auto rgbSupport() -> bool;
|
||||||
|
};
|
10
kernel/hw/pc/cgaterm/cp437.cpp
Normal file
10
kernel/hw/pc/cgaterm/cp437.cpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
int tbl[] = {0, 9786, 9787, 9829, 9830, 9827, 9824, 8226, 9688, 9675, 9689, 9794, 9792, 9834, 9835, 9788, 9658, 9668, 8597, 8252, 182, 167, 9644, 8616, 8593, 8595, 8594, 8592, 8735, 8596, 9652, 9660, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 8962, 199, 252, 233, 226, 228, 224, 229, 231, 234, 235, 232, 239, 238, 236, 196, 197, 201, 230, 198, 244, 246, 242, 251, 249, 255, 214, 220, 162, 163, 165, 8359, 402, 225, 237, 243, 250, 241, 209, 170, 186, 191, 8976, 172, 189, 188, 161, 171, 187, 9617, 9618, 9619, 9474, 9508, 9569, 9570, 9558, 9557, 9571, 9553, 9559, 9565, 9564, 9563, 9488, 9492, 9524, 9516, 9500, 9472, 9532, 9566, 9567, 9562, 9556, 9577, 9574, 9568, 9552, 9580, 9575, 9576, 9572, 9573, 9561, 9560, 9554, 9555, 9579, 9578, 9496, 9484, 9608, 9604, 9612, 9616, 9600, 945, 223, 915, 960, 931, 963, 181, 964, 934, 920, 937, 948, 8734, 966, 949, 8745, 8801, 177, 8805, 8804, 8992, 8993, 247, 8776, 176, 8729, 183, 8730, 8319, 178, 9632, 160};
|
||||||
|
char unicodeToCP437(int c) {
|
||||||
|
for(int i=0; i<256; i++)
|
||||||
|
if(tbl[i]==c)
|
||||||
|
return (char)i;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int CP437ToUnicode(char c) {
|
||||||
|
return tbl[(unsigned char)c];
|
||||||
|
}
|
2
kernel/hw/pc/cgaterm/cp437.hpp
Normal file
2
kernel/hw/pc/cgaterm/cp437.hpp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
char unicodeToCP437(int c);
|
||||||
|
int CP437ToUnicode(char c);
|
|
@ -1,3 +1,7 @@
|
||||||
config["ENABLE_FRAMEBUFFER"] = get_yes_no("Use VESA Framebuffer?", True)
|
config["ENABLE_FRAMEBUFFER"] = get_yes_no("Use VESA Framebuffer?", True)
|
||||||
if config["ENABLE_FRAMEBUFFER"]:
|
if config["ENABLE_FRAMEBUFFER"]:
|
||||||
config["ENABLE_FRAMEBUFFER_UNICODE"] = get_yes_no("Enable full Unicode BMP font (Adds around 1MB to binary)", False)
|
config["ENABLE_FRAMEBUFFER_UNICODE"] = get_yes_no("Enable full Unicode BMP font (Adds around 1MB to binary)", False)
|
||||||
|
if config["ENABLE_FRAMEBUFFER"]:
|
||||||
|
add_driver(False, "vesafb")
|
||||||
|
else:
|
||||||
|
add_driver(False, "cgaterm")
|
||||||
|
|
20
kernel/src/cppstubs.cpp
Normal file
20
kernel/src/cppstubs.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
extern "C" void __cxa_pure_virtual() {
|
||||||
|
//panic("Pure virtual function called.");
|
||||||
|
}
|
||||||
|
void * operator new(size_t s) {
|
||||||
|
return (void*)1;
|
||||||
|
}
|
||||||
|
void * operator new[](size_t s) {
|
||||||
|
return (void*)1;
|
||||||
|
}
|
||||||
|
void operator delete(void* p) {}
|
||||||
|
void operator delete[](void* p) {}
|
||||||
|
void operator delete(void* p, size_t s) {}
|
||||||
|
void operator delete[](void* p, size_t s) {}
|
||||||
|
void * operator new(size_t s, void* p) {return p;}
|
||||||
|
void * operator new[](size_t s, void* p) {return p;}
|
||||||
|
void operator delete(void *, void *p) {}
|
||||||
|
void operator delete[](void *, void *p) {}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kobject.hpp>
|
#include <kobject.hpp>
|
||||||
enum Color {
|
enum class Color {
|
||||||
BLACK,
|
BLACK,
|
||||||
BLUE,
|
BLUE,
|
||||||
GREEN,
|
GREEN,
|
||||||
|
@ -8,7 +8,7 @@ enum Color {
|
||||||
RED,
|
RED,
|
||||||
MAGENTA,
|
MAGENTA,
|
||||||
BROWN,
|
BROWN,
|
||||||
LIGHT_GREY,
|
LIGHT_GRAY,
|
||||||
GRAY,
|
GRAY,
|
||||||
LIGHT_BLUE,
|
LIGHT_BLUE,
|
||||||
LIGHT_GREEN,
|
LIGHT_GREEN,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include <tty.hpp>
|
#include <tty.hpp>
|
||||||
TTY::TTY(int width, int height): x(0), y(0), width(width), height(height), curColor(WHITE), rgbColor(0xFFFFFF), useRGB(false), Kobject(kobjectType::TTY) {}
|
TTY::TTY(int width, int height): x(0), y(0), width(width), height(height), curColor(Color::WHITE), rgbColor(0xFFFFFF), useRGB(false), Kobject(kobjectType::TTY) {}
|
||||||
TTY::~TTY() {}
|
TTY::~TTY() {}
|
||||||
auto TTY::plotChar(int x, int y, int c) -> void {}
|
auto TTY::plotChar(int x, int y, int c) -> void {}
|
||||||
auto TTY::rgbSupport() -> bool {return true;}
|
auto TTY::rgbSupport() -> bool {return true;}
|
||||||
|
|
Loading…
Reference in a new issue