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,9 +14,11 @@
* 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
@ -96,8 +98,7 @@ typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_uint64_t;
struct multiboot_header
{
struct multiboot_header {
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic;
@ -122,8 +123,7 @@ struct multiboot_header
};
/* The symbol table for a.out. */
struct multiboot_aout_symbol_table
{
struct multiboot_aout_symbol_table {
multiboot_uint32_t tabsize;
multiboot_uint32_t strsize;
multiboot_uint32_t addr;
@ -132,8 +132,7 @@ struct multiboot_aout_symbol_table
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
/* The section header table for ELF. */
struct multiboot_elf_section_header_table
{
struct multiboot_elf_section_header_table {
multiboot_uint32_t num;
multiboot_uint32_t size;
multiboot_uint32_t addr;
@ -141,8 +140,7 @@ struct multiboot_elf_section_header_table
};
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
struct multiboot_info
{
struct multiboot_info {
/* Multiboot info version number */
multiboot_uint32_t flags;
@ -160,8 +158,7 @@ struct multiboot_info
multiboot_uint32_t mods_count;
multiboot_uint32_t mods_addr;
union
{
union {
multiboot_aout_symbol_table_t aout_sym;
multiboot_elf_section_header_table_t elf_sec;
} u;
@ -200,15 +197,12 @@ struct multiboot_info
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_uint8_t framebuffer_type;
union
{
struct
{
union {
struct {
multiboot_uint32_t framebuffer_palette_addr;
multiboot_uint16_t framebuffer_palette_num_colors;
};
struct
{
struct {
multiboot_uint8_t framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position;
@ -220,15 +214,13 @@ struct multiboot_info
};
typedef struct multiboot_info multiboot_info_t;
struct multiboot_color
{
struct multiboot_color {
multiboot_uint8_t red;
multiboot_uint8_t green;
multiboot_uint8_t blue;
};
struct multiboot_mmap_entry
{
struct multiboot_mmap_entry {
multiboot_uint32_t size;
multiboot_uint64_t addr;
multiboot_uint64_t len;
@ -241,8 +233,7 @@ struct multiboot_mmap_entry
} GRUB_PACKED;
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_mod_list
{
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;
@ -256,8 +247,7 @@ struct multiboot_mod_list
typedef struct multiboot_mod_list multiboot_module_t;
/* APM BIOS info. */
struct multiboot_apm_info
{
struct multiboot_apm_info {
grub_uint16_t version;
grub_uint16_t cseg;
grub_uint32_t offset;

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

@ -15,55 +15,22 @@ auto CGATerm::plotChar(int x, int y, int c) -> void {
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;
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;
}

View file

@ -3,6 +3,7 @@
class CGATerm : public TTY {
protected:
virtual auto plotChar(int x, int y, int c) -> void;
public:
CGATerm();
virtual ~CGATerm();

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;
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,14 +1,10 @@
#include <stdint.h>
#include <stddef.h>
#include <stdint.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 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) {}
@ -17,4 +13,3 @@ 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

@ -17,8 +17,7 @@ class Kref {
}
template <typename T>
auto set(T *data) -> Kref & {
if(mset)
return *this;
if (mset) return *this;
ptr = (void *)data;
mset = true;
return *this;
@ -32,8 +31,10 @@ class Kref {
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(;;);
// Put panic() here, because this object could lead to kernel execution
// when the refctr overflows.
for (;;)
;
}
return *this;
}
@ -52,15 +53,14 @@ class Kobject {
kobjectType type;
unsigned int refctr;
Kobject(kobjectType type) : type(type), refctr(1) {}
virtual ~Kobject() {
refctr=0;
}
virtual ~Kobject() { refctr = 0; }
virtual auto operator++() -> Kobject & {
unsigned int tmp = refctr;
refctr++;
if (refctr < tmp) {
// TODO panic("Refcounter overflow");
for(;;);
for (;;)
;
}
return *this;
}

View file

@ -28,6 +28,7 @@ protected:
unsigned int rgbColor;
bool useRGB;
virtual auto plotChar(int x, int y, int c) -> void;
public:
TTY(int width, int height);
virtual ~TTY();
@ -55,7 +56,6 @@ public:
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

@ -5,10 +5,8 @@ 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

@ -1,5 +1,7 @@
#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; }
@ -14,33 +16,27 @@ auto TTY::setColor(unsigned int c) -> void {
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);
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();
if (y >= height) scroll();
break;
default:
plotChar(x, y, c);
x++;
if(x>width)
y++;
if(y>=height)
scroll();
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];
}
if (str[i] < 0x80) { character = str[i]; }
// UTF-8 character
if ((str[i] & 0b11000000) == 0b10000000) {
character = 0xFFFD; // ILLEGAL SEQUENCE
@ -72,7 +68,6 @@ auto TTY::puts(const char *str) -> void {
character |= str[i] & 0b111111;
bytesToFollow--;
}
if(!bytesToFollow)
putChar(character);
if (!bytesToFollow) putChar(character);
}
}