added clang format

This commit is contained in:
Morten Delenk 2017-04-26 10:27:27 +00:00
parent ba8f73277c
commit dfd6e90200
13 changed files with 366 additions and 390 deletions

22
.clang-format Normal file
View file

@ -0,0 +1,22 @@
---
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
DerivePointerAlignment: false
PointerAlignment: Right
AccessModifierOffset: 0
AlignAfterOpenBracket: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakTemplateDeclarations: true
ColumnLimit: 120
NamespaceIndentation: Inner
Standard: Cpp11
UseTab: Never

View file

@ -14,259 +14,249 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MULTIBOOT_HEADER
#define MULTIBOOT_HEADER 1
/* How many bytes from the start of the file we search for the header. */
#define MULTIBOOT_SEARCH 8192
#define MULTIBOOT_HEADER_ALIGN 4
#define MULTIBOOT_SEARCH 8192
#define MULTIBOOT_HEADER_ALIGN 4
/* The magic field should contain this. */
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
/* This should be in %eax. */
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
/* Alignment of multiboot modules. */
#define MULTIBOOT_MOD_ALIGN 0x00001000
#define MULTIBOOT_MOD_ALIGN 0x00001000
/* Alignment of the multiboot info structure. */
#define MULTIBOOT_INFO_ALIGN 0x00000004
#define MULTIBOOT_INFO_ALIGN 0x00000004
/* Flags set in the 'flags' member of the multiboot header. */
/* Align all boot modules on i386 page (4KB) boundaries. */
#define MULTIBOOT_PAGE_ALIGN 0x00000001
#define MULTIBOOT_PAGE_ALIGN 0x00000001
/* Must pass memory information to OS. */
#define MULTIBOOT_MEMORY_INFO 0x00000002
#define MULTIBOOT_MEMORY_INFO 0x00000002
/* Must pass video information to OS. */
#define MULTIBOOT_VIDEO_MODE 0x00000004
#define MULTIBOOT_VIDEO_MODE 0x00000004
/* This flag indicates the use of the address fields in the header. */
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
/* Flags to be set in the 'flags' member of the multiboot info structure. */
/* is there basic lower/upper memory information? */
#define MULTIBOOT_INFO_MEMORY 0x00000001
#define MULTIBOOT_INFO_MEMORY 0x00000001
/* is there a boot device set? */
#define MULTIBOOT_INFO_BOOTDEV 0x00000002
#define MULTIBOOT_INFO_BOOTDEV 0x00000002
/* is the command-line defined? */
#define MULTIBOOT_INFO_CMDLINE 0x00000004
#define MULTIBOOT_INFO_CMDLINE 0x00000004
/* are there modules to do something with? */
#define MULTIBOOT_INFO_MODS 0x00000008
#define MULTIBOOT_INFO_MODS 0x00000008
/* These next two are mutually exclusive */
/* is there a symbol table loaded? */
#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
/* is there an ELF section header table? */
#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
/* is there a full memory map? */
#define MULTIBOOT_INFO_MEM_MAP 0x00000040
#define MULTIBOOT_INFO_MEM_MAP 0x00000040
/* Is there drive info? */
#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
/* Is there a config table? */
#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
/* Is there a boot loader name? */
#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
/* Is there a APM table? */
#define MULTIBOOT_INFO_APM_TABLE 0x00000400
#define MULTIBOOT_INFO_APM_TABLE 0x00000400
/* Is there video information? */
#define MULTIBOOT_INFO_VBE_INFO 0x00000800
#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
#define MULTIBOOT_INFO_VBE_INFO 0x00000800
#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
#ifndef ASM_FILE
typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_uint64_t;
typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_uint64_t;
struct multiboot_header
{
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic;
struct multiboot_header {
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic;
/* Feature flags. */
multiboot_uint32_t flags;
/* Feature flags. */
multiboot_uint32_t flags;
/* The above fields plus this one must equal 0 mod 2^32. */
multiboot_uint32_t checksum;
/* The above fields plus this one must equal 0 mod 2^32. */
multiboot_uint32_t checksum;
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
multiboot_uint32_t header_addr;
multiboot_uint32_t load_addr;
multiboot_uint32_t load_end_addr;
multiboot_uint32_t bss_end_addr;
multiboot_uint32_t entry_addr;
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
multiboot_uint32_t header_addr;
multiboot_uint32_t load_addr;
multiboot_uint32_t load_end_addr;
multiboot_uint32_t bss_end_addr;
multiboot_uint32_t entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
multiboot_uint32_t mode_type;
multiboot_uint32_t width;
multiboot_uint32_t height;
multiboot_uint32_t depth;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
multiboot_uint32_t mode_type;
multiboot_uint32_t width;
multiboot_uint32_t height;
multiboot_uint32_t depth;
};
/* The symbol table for a.out. */
struct multiboot_aout_symbol_table
{
multiboot_uint32_t tabsize;
multiboot_uint32_t strsize;
multiboot_uint32_t addr;
multiboot_uint32_t reserved;
struct multiboot_aout_symbol_table {
multiboot_uint32_t tabsize;
multiboot_uint32_t strsize;
multiboot_uint32_t addr;
multiboot_uint32_t reserved;
};
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
/* The section header table for ELF. */
struct multiboot_elf_section_header_table
{
multiboot_uint32_t num;
multiboot_uint32_t size;
multiboot_uint32_t addr;
multiboot_uint32_t shndx;
struct multiboot_elf_section_header_table {
multiboot_uint32_t num;
multiboot_uint32_t size;
multiboot_uint32_t addr;
multiboot_uint32_t shndx;
};
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
struct multiboot_info
{
/* Multiboot info version number */
multiboot_uint32_t flags;
struct multiboot_info {
/* Multiboot info version number */
multiboot_uint32_t flags;
/* Available memory from BIOS */
multiboot_uint32_t mem_lower;
multiboot_uint32_t mem_upper;
/* Available memory from BIOS */
multiboot_uint32_t mem_lower;
multiboot_uint32_t mem_upper;
/* "root" partition */
multiboot_uint32_t boot_device;
/* "root" partition */
multiboot_uint32_t boot_device;
/* Kernel command line */
multiboot_uint32_t cmdline;
/* Kernel command line */
multiboot_uint32_t cmdline;
/* Boot-Module list */
multiboot_uint32_t mods_count;
multiboot_uint32_t mods_addr;
/* Boot-Module list */
multiboot_uint32_t mods_count;
multiboot_uint32_t mods_addr;
union
{
multiboot_aout_symbol_table_t aout_sym;
multiboot_elf_section_header_table_t elf_sec;
} u;
union {
multiboot_aout_symbol_table_t aout_sym;
multiboot_elf_section_header_table_t elf_sec;
} u;
/* Memory Mapping buffer */
multiboot_uint32_t mmap_length;
multiboot_uint32_t mmap_addr;
/* Memory Mapping buffer */
multiboot_uint32_t mmap_length;
multiboot_uint32_t mmap_addr;
/* Drive Info buffer */
multiboot_uint32_t drives_length;
multiboot_uint32_t drives_addr;
/* Drive Info buffer */
multiboot_uint32_t drives_length;
multiboot_uint32_t drives_addr;
/* ROM configuration table */
multiboot_uint32_t config_table;
/* ROM configuration table */
multiboot_uint32_t config_table;
/* Boot Loader Name */
multiboot_uint32_t boot_loader_name;
/* Boot Loader Name */
multiboot_uint32_t boot_loader_name;
/* APM table */
multiboot_uint32_t apm_table;
/* APM table */
multiboot_uint32_t apm_table;
/* Video */
multiboot_uint32_t vbe_control_info;
multiboot_uint32_t vbe_mode_info;
multiboot_uint16_t vbe_mode;
multiboot_uint16_t vbe_interface_seg;
multiboot_uint16_t vbe_interface_off;
multiboot_uint16_t vbe_interface_len;
/* Video */
multiboot_uint32_t vbe_control_info;
multiboot_uint32_t vbe_mode_info;
multiboot_uint16_t vbe_mode;
multiboot_uint16_t vbe_interface_seg;
multiboot_uint16_t vbe_interface_off;
multiboot_uint16_t vbe_interface_len;
multiboot_uint64_t framebuffer_addr;
multiboot_uint32_t framebuffer_pitch;
multiboot_uint32_t framebuffer_width;
multiboot_uint32_t framebuffer_height;
multiboot_uint8_t framebuffer_bpp;
multiboot_uint64_t framebuffer_addr;
multiboot_uint32_t framebuffer_pitch;
multiboot_uint32_t framebuffer_width;
multiboot_uint32_t framebuffer_height;
multiboot_uint8_t framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_uint8_t framebuffer_type;
union
{
struct
{
multiboot_uint32_t framebuffer_palette_addr;
multiboot_uint16_t framebuffer_palette_num_colors;
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_uint8_t framebuffer_type;
union {
struct {
multiboot_uint32_t framebuffer_palette_addr;
multiboot_uint16_t framebuffer_palette_num_colors;
};
struct {
multiboot_uint8_t framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position;
multiboot_uint8_t framebuffer_green_mask_size;
multiboot_uint8_t framebuffer_blue_field_position;
multiboot_uint8_t framebuffer_blue_mask_size;
};
};
struct
{
multiboot_uint8_t framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position;
multiboot_uint8_t framebuffer_green_mask_size;
multiboot_uint8_t framebuffer_blue_field_position;
multiboot_uint8_t framebuffer_blue_mask_size;
};
};
};
typedef struct multiboot_info multiboot_info_t;
struct multiboot_color
{
multiboot_uint8_t red;
multiboot_uint8_t green;
multiboot_uint8_t blue;
struct multiboot_color {
multiboot_uint8_t red;
multiboot_uint8_t green;
multiboot_uint8_t blue;
};
struct multiboot_mmap_entry
{
multiboot_uint32_t size;
multiboot_uint64_t addr;
multiboot_uint64_t len;
#define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5
multiboot_uint32_t type;
struct multiboot_mmap_entry {
multiboot_uint32_t size;
multiboot_uint64_t addr;
multiboot_uint64_t len;
#define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5
multiboot_uint32_t type;
} GRUB_PACKED;
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_mod_list
{
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
multiboot_uint32_t mod_start;
multiboot_uint32_t mod_end;
struct multiboot_mod_list {
/* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
multiboot_uint32_t mod_start;
multiboot_uint32_t mod_end;
/* Module command line */
multiboot_uint32_t cmdline;
/* Module command line */
multiboot_uint32_t cmdline;
/* padding to take it to 16 bytes (must be zero) */
multiboot_uint32_t pad;
/* padding to take it to 16 bytes (must be zero) */
multiboot_uint32_t pad;
};
typedef struct multiboot_mod_list multiboot_module_t;
/* APM BIOS info. */
struct multiboot_apm_info
{
grub_uint16_t version;
grub_uint16_t cseg;
grub_uint32_t offset;
grub_uint16_t cseg_16;
grub_uint16_t dseg;
grub_uint16_t flags;
grub_uint16_t cseg_len;
grub_uint16_t cseg_16_len;
grub_uint16_t dseg_len;
struct multiboot_apm_info {
grub_uint16_t version;
grub_uint16_t cseg;
grub_uint32_t offset;
grub_uint16_t cseg_16;
grub_uint16_t dseg;
grub_uint16_t flags;
grub_uint16_t cseg_len;
grub_uint16_t cseg_16_len;
grub_uint16_t dseg_len;
};
#endif /* ! ASM_FILE */

View file

@ -1,10 +1,8 @@
#include <base.hpp>
#include "../../../hw/pc/cgaterm/cgaterm.hpp"
#include <base.hpp>
CGATerm term;
void main();
extern "C" void start() {
main();
}
extern "C" void start() { main(); }
void drivers_init() {
setMainTTY(&term);
--term;

View file

@ -1,69 +1,36 @@
#include "cgaterm.hpp"
#include "cp437.hpp"
CGATerm::CGATerm(): TTY(80, 25) {}
CGATerm::CGATerm() : TTY(80, 25) {}
CGATerm::~CGATerm() {}
auto CGATerm::rgbSupport() -> bool {return false;}
auto CGATerm::rgbSupport() -> bool { return false; }
struct ScreenChar {
unsigned char ch;
char fgcolor:4;
char bgcolor:4;
}__attribute__((packed));
ScreenChar *scr = (ScreenChar*)0xB8000;
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;
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;
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;
scr[y * 80 + x].fgcolor = col;
}

View file

@ -1,10 +1,11 @@
#pragma once
#include <tty.hpp>
class CGATerm: public TTY {
class CGATerm : public TTY {
protected:
virtual auto plotChar(int x, int y, int c) -> void;
virtual auto plotChar(int x, int y, int c) -> void;
public:
CGATerm();
virtual ~CGATerm();
virtual auto rgbSupport() -> bool;
CGATerm();
virtual ~CGATerm();
virtual auto rgbSupport() -> bool;
};

View file

@ -1,10 +1,21 @@
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};
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;
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];
}
int CP437ToUnicode(char c) { return tbl[(unsigned char)c]; }

View file

@ -1,20 +1,15 @@
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
extern "C" void __cxa_pure_virtual() {
//panic("Pure virtual function called.");
// 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 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) {}

View file

@ -1,5 +1,5 @@
#pragma once
#include <tty.hpp>
#include <kobject.hpp>
#include <tty.hpp>
extern TTY *out;
void setMainTTY(Kobject *obj);

View file

@ -1,75 +1,75 @@
#pragma once
enum class kobjectType {
POINTER, //Pointer to non-object
KOBJECT, //garbage collected kobject
POINTER, // Pointer to non-object
KOBJECT, // garbage collected kobject
TTY,
};
class Kref {
public:
kobjectType type;
void *ptr;
unsigned int refctr;
bool mset;
Kref(kobjectType type) {
this->type = type;
refctr = 1;
kobjectType type;
void *ptr;
unsigned int refctr;
bool mset;
Kref(kobjectType type) {
this->type = type;
refctr = 1;
mset = false;
}
template <typename T>
auto set(T *data) -> Kref & {
if (mset) return *this;
ptr = (void *)data;
mset = true;
return *this;
}
template <typename T>
T *get() {
return (T *)ptr;
}
auto operator++(int) -> Kref & {
unsigned int old = refctr;
refctr++;
if (old > refctr) {
// uh-oh this shouldn't happen
// Put panic() here, because this object could lead to kernel execution
// when the refctr overflows.
for (;;)
;
}
return *this;
}
auto operator--(int) -> Kref & {
refctr--;
if (!refctr) {
// delete ptr;
mset = false;
ptr = nullptr;
}
template<typename T>
auto set(T *data) -> Kref & {
if(mset)
return *this;
ptr = (void*)data;
mset=true;
return *this;
}
template<typename T>
T *get() {
return (T*)ptr;
}
auto operator++(int) -> Kref & {
unsigned int old = refctr;
refctr++;
if(old > refctr) {
//uh-oh this shouldn't happen
//Put panic() here, because this object could lead to kernel execution when the refctr overflows.
for(;;);
}
return *this;
}
auto operator--(int) -> Kref & {
refctr--;
if(!refctr) {
//delete ptr;
mset = false;
ptr = nullptr;
}
return *this;
}
return *this;
}
};
class Kobject {
public:
kobjectType type;
unsigned int refctr;
Kobject(kobjectType type):type(type),refctr(1) {}
virtual ~Kobject() {
refctr=0;
kobjectType type;
unsigned int refctr;
Kobject(kobjectType type) : type(type), refctr(1) {}
virtual ~Kobject() { refctr = 0; }
virtual auto operator++() -> Kobject & {
unsigned int tmp = refctr;
refctr++;
if (refctr < tmp) {
// TODO panic("Refcounter overflow");
for (;;)
;
}
virtual auto operator++() -> Kobject & {
unsigned int tmp=refctr;
refctr++;
if(refctr < tmp) {
//TODO panic("Refcounter overflow");
for(;;);
}
return *this;
}
virtual auto operator--() -> Kobject & {
refctr--;
if(refctr == 0) {
//TODO delete this;
return *((Kobject*)nullptr);
}
return *this;
return *this;
}
virtual auto operator--() -> Kobject & {
refctr--;
if (refctr == 0) {
// TODO delete this;
return *((Kobject *)nullptr);
}
return *this;
}
};

View file

@ -18,8 +18,8 @@ enum class Color {
YELLOW,
WHITE
};
class TTY: public Kobject {
protected:
class TTY : public Kobject {
protected:
int x;
int y;
int width;
@ -28,7 +28,8 @@ protected:
unsigned int rgbColor;
bool useRGB;
virtual auto plotChar(int x, int y, int c) -> void;
public:
public:
TTY(int width, int height);
virtual ~TTY();
virtual auto rgbSupport() -> bool;
@ -36,26 +37,25 @@ public:
virtual auto setColor(unsigned int c) -> void;
virtual auto putChar(int c) -> void;
virtual auto puts(const char *s) -> void;
template<typename T>
template <typename T>
auto puti(T x) -> TTY & {
T output = x;
const char* chars="0123456789ABCDEF";
char buf[sizeof(T)*8+1];
buf[sizeof(T)*8]='\0';
char* ptr=buf+sizeof(T)*8-1;
const char *chars = "0123456789ABCDEF";
char buf[sizeof(T) * 8 + 1];
buf[sizeof(T) * 8] = '\0';
char *ptr = buf + sizeof(T) * 8 - 1;
do {
*(ptr--)=chars[output&0xF];
output>>=4;
} while(output && (ptr != buf));
puts(ptr+1);
*(ptr--) = chars[output & 0xF];
output >>= 4;
} while (output && (ptr != buf));
puts(ptr + 1);
return *this;
}
template<typename T>
template <typename T>
auto operator<<(T x) -> TTY & {
puts(x);
return *this;
}
};
template <>
auto TTY::operator<<<int>(int) -> TTY &;
@ -63,4 +63,3 @@ template <>
auto TTY::operator<<<unsigned int>(unsigned int) -> TTY &;
template <>
auto TTY::operator<<<long long>(long long) -> TTY &;

View file

@ -1,14 +1,12 @@
#include <base.hpp>
void drivers_init();
extern "C" void(*start_ctors)();
extern "C" void(*end_ctors)();
extern "C" void(*start_dtors)();
extern "C" void(*end_dtors)();
extern "C" void (*start_ctors)();
extern "C" void (*end_ctors)();
extern "C" void (*start_dtors)();
extern "C" void (*end_dtors)();
void main() {
for(auto ctor=&start_ctors;ctor<&end_ctors;ctor++)
(**ctor)();
for (auto ctor = &start_ctors; ctor < &end_ctors; ctor++) (**ctor)();
drivers_init();
*out << "Hallo!\n";
for(auto dtor=&start_dtors;dtor!=&end_dtors;dtor++)
(**dtor)();
for (auto dtor = &start_dtors; dtor != &end_dtors; dtor++) (**dtor)();
}

View file

@ -2,11 +2,11 @@
TTY *out;
bool tty_set = false;
void setMainTTY(Kobject *obj) {
if(obj->type == kobjectType::TTY) {
if (obj->type == kobjectType::TTY) {
++*obj;
// if(tty_set)
// --*out;
out=(TTY*)obj;
tty_set=true;
// if(tty_set)
// --*out;
out = (TTY *)obj;
tty_set = true;
}
}

View file

@ -1,78 +1,73 @@
#include <tty.hpp>
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(int width, int height)
: x(0), y(0), width(width), height(height), curColor(Color::WHITE), rgbColor(0xFFFFFF), useRGB(false),
Kobject(kobjectType::TTY) {}
TTY::~TTY() {}
auto TTY::plotChar(int x, int y, int c) -> void {}
auto TTY::rgbSupport() -> bool {return true;}
auto TTY::rgbSupport() -> bool { return true; }
auto TTY::setColor(Color c) -> void {
curColor = c;
useRGB=false;
useRGB = false;
}
auto TTY::setColor(unsigned int c) -> void {
rgbColor = c;
useRGB=true;
useRGB = true;
}
auto TTY::putChar(int c) -> void {
auto scroll = [this]()->void {
for(int x=0;x<this->width;x++)
for(int y=0;y<this->height;y++)
this->plotChar(x,y,0);
this->x=this->y=0;
auto scroll = [this]() -> void {
for (int x = 0; x < this->width; x++)
for (int y = 0; y < this->height; y++) this->plotChar(x, y, 0);
this->x = this->y = 0;
};
switch(c) {
case '\n':
x=0;
y++;
if(y>=height)
scroll();
break;
default:
plotChar(x,y,c);
x++;
if(x>width)
y++;
if(y>=height)
scroll();
switch (c) {
case '\n':
x = 0;
y++;
if (y >= height) scroll();
break;
default:
plotChar(x, y, c);
x++;
if (x > width) y++;
if (y >= height) scroll();
}
}
auto TTY::puts(const char *str) -> void {
for(int i=0;str[i];i++) {
//Decode UTF-8
int character=0;
if(str[i]<0x80) {
character=str[i];
for (int i = 0; str[i]; i++) {
// Decode UTF-8
int character = 0;
if (str[i] < 0x80) { character = str[i]; }
// UTF-8 character
if ((str[i] & 0b11000000) == 0b10000000) {
character = 0xFFFD; // ILLEGAL SEQUENCE
}
//UTF-8 character
if((str[i]&0b11000000)==0b10000000) {
character=0xFFFD; //ILLEGAL SEQUENCE
}
//Now count how many bytes follow
int bytesToFollow=0;
if((str[i]&0b11100000)==0b11000000) {
bytesToFollow=1;
character=str[i]&0b11111;
} else if((str[i]&0b11110000)==0b11100000) {
bytesToFollow=2;
character=str[i]&0b1111;
} else if((str[i]&0b11111000)==0b11110000) {
bytesToFollow=3;
character=str[i]&0b111;
} else if(!character)
character=0xFFFD; //ILLEGAL SEQUENCE
while(bytesToFollow) {
// Now count how many bytes follow
int bytesToFollow = 0;
if ((str[i] & 0b11100000) == 0b11000000) {
bytesToFollow = 1;
character = str[i] & 0b11111;
} else if ((str[i] & 0b11110000) == 0b11100000) {
bytesToFollow = 2;
character = str[i] & 0b1111;
} else if ((str[i] & 0b11111000) == 0b11110000) {
bytesToFollow = 3;
character = str[i] & 0b111;
} else if (!character)
character = 0xFFFD; // ILLEGAL SEQUENCE
while (bytesToFollow) {
i++;
if(!str[i]) {
putChar(0xFFFD); //Incomplete
if (!str[i]) {
putChar(0xFFFD); // Incomplete
return;
}
if((str[i]&0b11000000)!=0b10000000) {
putChar(0xFFFD); //ILLEGAL SEQUENCE
if ((str[i] & 0b11000000) != 0b10000000) {
putChar(0xFFFD); // ILLEGAL SEQUENCE
break;
}
character <<= 6;
character |= str[i] & 0b111111;
bytesToFollow--;
}
if(!bytesToFollow)
putChar(character);
if (!bytesToFollow) putChar(character);
}
}