aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-02-09 20:44:43 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-02-09 20:44:43 +0200
commita487d6ccee43bd6cd5ec648e8b97712595f681a7 (patch)
tree4b48fa9a6d409726e8619265efe2d2acd33bcf3f /src
parentAdd more comments to GDT code (diff)
downloadkernel.cpp-a487d6ccee43bd6cd5ec648e8b97712595f681a7.tar.xz
Add some compiler warnings
Diffstat (limited to 'src')
-rw-r--r--src/gdt.h6
-rw-r--r--src/gdt/segmentdescriptor.cc3
-rw-r--r--src/kernel/dump_multiboot.cc23
-rw-r--r--src/makefile1
-rw-r--r--src/memory.cc5
-rw-r--r--src/vga.cc31
-rw-r--r--src/vga.h19
7 files changed, 58 insertions, 30 deletions
diff --git a/src/gdt.h b/src/gdt.h
index 244908b..274cb6a 100644
--- a/src/gdt.h
+++ b/src/gdt.h
@@ -49,16 +49,16 @@ public:
SegmentDescriptor() { access.present = false; };
template <uint32_t limit>
- static SegmentDescriptor make(uint32_t base, Access a) {
+ static SegmentDescriptor make(uint32_t base, Access type) {
static_assert(limit <= 0xffffu || (limit & 0xfff) == 0xfff);
- return SegmentDescriptor(base, limit, a);
+ return SegmentDescriptor(base, limit, type);
}
[[nodiscard]] uint32_t base() const;
[[nodiscard]] uint32_t limit() const;
private:
- SegmentDescriptor(uint32_t base, uint32_t limit, Access a);
+ SegmentDescriptor(uint32_t base, uint32_t limit, Access type);
/*
* |31| | | | | | |24|23|22|21|20|19| | |16|15| | |12|11| | | 8| 7| | | | | | | 0|
diff --git a/src/gdt/segmentdescriptor.cc b/src/gdt/segmentdescriptor.cc
index 94205c8..baf4753 100644
--- a/src/gdt/segmentdescriptor.cc
+++ b/src/gdt/segmentdescriptor.cc
@@ -1,6 +1,7 @@
#include "../gdt.h"
-GDT::SegmentDescriptor::SegmentDescriptor(uint32_t base, uint32_t limit, GDT::SegmentDescriptor::Access a) : access(a) {
+GDT::SegmentDescriptor::SegmentDescriptor(uint32_t base, uint32_t limit, GDT::SegmentDescriptor::Access type)
+ : access(type) {
// store base
base_15_0 = base & 0xffff;
base_23_16 = (base >> 16) & 0xff;
diff --git a/src/kernel/dump_multiboot.cc b/src/kernel/dump_multiboot.cc
index 60b4b91..219d64f 100644
--- a/src/kernel/dump_multiboot.cc
+++ b/src/kernel/dump_multiboot.cc
@@ -6,11 +6,11 @@ extern "C" void dump_multiboot(uint32_t mb_magic, uint32_t mb_addr) {
printk("multiboot addr: ", uhex{mb_addr}, !(mb_addr & 7) ? " is aligned" : " is not aligned", '\n');
struct multiboot_tag* tag;
- const uint32_t size = *(unsigned*)mb_addr;
+ const uint32_t size = *reinterpret_cast<uint32_t*>(mb_addr);
printk("Announced mbi size ", size, '\n');
- for (tag = (struct multiboot_tag*)(mb_addr + 8); tag->type != MULTIBOOT_TAG_TYPE_END;
- tag = (struct multiboot_tag*)((multiboot_uint8_t*)tag + ((tag->size + 7) & ~7))) {
+ for (tag = reinterpret_cast<multiboot_tag*>(mb_addr + 8); tag->type != MULTIBOOT_TAG_TYPE_END;
+ tag = reinterpret_cast<multiboot_tag*>(reinterpret_cast<uint8_t*>(tag) + ((tag->size + 7u) & ~7u))) {
switch (tag->type) {
case MULTIBOOT_TAG_TYPE_CMDLINE: {
auto* t = reinterpret_cast<multiboot_tag_string*>(tag);
@@ -37,11 +37,14 @@ extern "C" void dump_multiboot(uint32_t mb_magic, uint32_t mb_addr) {
multiboot_memory_map_t* mmap;
printk("memory map\n");
- for (mmap = t->entries; (multiboot_uint8_t*)mmap < (multiboot_uint8_t*)tag + tag->size;
- mmap = (multiboot_memory_map_t*)((unsigned long)mmap + ((struct multiboot_tag_mmap*)tag)->entry_size)) {
- printk(" base_addr = ", uhex{(unsigned)(mmap->addr >> 32)}, ' ', uhex{(unsigned)(mmap->addr & 0xffffffff)});
- printk(" length = ", (unsigned)(mmap->len >> 32), ' ', (unsigned)(mmap->len & 0xffffffff));
- printk(" type = ", (unsigned)mmap->type, '\n');
+ for (mmap = t->entries; reinterpret_cast<uint8_t*>(mmap) < reinterpret_cast<uint8_t*>(tag) + tag->size;
+ mmap = reinterpret_cast<multiboot_memory_map_t*>(reinterpret_cast<uint32_t>(mmap) +
+ reinterpret_cast<multiboot_tag_mmap*>(tag)->entry_size)) {
+ printk(" base_addr = ", uhex{static_cast<uint32_t>(mmap->addr >> 32)}, ' ',
+ uhex{static_cast<uint32_t>(mmap->addr & 0xffffffff)});
+ printk(" length = ", static_cast<uint32_t>(mmap->len >> 32), ' ',
+ static_cast<uint32_t>(mmap->len & 0xffffffff));
+ printk(" type = ", mmap->type, '\n');
}
} break;
@@ -51,6 +54,6 @@ extern "C" void dump_multiboot(uint32_t mb_magic, uint32_t mb_addr) {
} // switch(tag->type)
} // for(each tag)
- tag = (struct multiboot_tag*)((multiboot_uint8_t*)tag + ((tag->size + 7) & ~7));
- printk("Total mbi size ", (unsigned)tag - mb_addr, '\n');
+ tag = reinterpret_cast<multiboot_tag*>(reinterpret_cast<uint8_t*>(tag) + ((tag->size + 7u) & ~7u));
+ printk("Total mbi size ", reinterpret_cast<uint32_t>(tag) - mb_addr, '\n');
}
diff --git a/src/makefile b/src/makefile
index 7b97382..25c58be 100644
--- a/src/makefile
+++ b/src/makefile
@@ -3,6 +3,7 @@ AS_OBJ += src/boot.o
CXX_OBJ += src/kernel.o \
src/kernel/dump_gdt.o \
src/kernel/dump_multiboot.o \
+ src/memory.o \
src/vga.o \
src/gdt.o \
src/gdt/segmentdescriptor.o
diff --git a/src/memory.cc b/src/memory.cc
new file mode 100644
index 0000000..0dbf3d0
--- /dev/null
+++ b/src/memory.cc
@@ -0,0 +1,5 @@
+#include <stdlib.h>
+
+void operator delete(void*) {
+ printk("Calling delete\n");
+}
diff --git a/src/vga.cc b/src/vga.cc
index 83d0060..6b64b98 100644
--- a/src/vga.cc
+++ b/src/vga.cc
@@ -1,23 +1,30 @@
#include "vga.h"
#include <string.h>
-constexpr uint8_t vga_entry_color(VGA::vga_color fg, VGA::vga_color bg) {
- return fg | bg << 4;
-}
-
-constexpr uint16_t vga_entry(unsigned char uc, uint8_t color) {
- return (uint16_t)uc | (uint16_t)color << 8;
-}
+static_assert(sizeof(VGA::Entry) == 2);
-VGA::VGA(vga_color fg, vga_color bg, uint32_t address) {
- color = vga_entry_color(fg, bg);
- buffer = (uint16_t*)address;
+VGA::VGA(vga_color fg, vga_color bg, uint32_t address) : color_fg(fg), color_bg(bg) {
+ buffer = reinterpret_cast<Entry*>(address);
// clear buffer
for (size_t y = 0; y < max_rows; y++) {
for (size_t x = 0; x < max_columns; x++) {
const size_t index = y * max_columns + x;
- buffer[index] = vga_entry(' ', color);
+ buffer[index].c = ' ';
+ buffer[index].fg = color_fg;
+ buffer[index].bg = color_bg;
+ }
+ }
+}
+
+void VGA::set_color(vga_color fg, vga_color bg) {
+ color_fg = fg;
+ color_bg = bg;
+ for (size_t y = 0; y < max_rows; y++) {
+ for (size_t x = 0; x < max_columns; x++) {
+ const size_t index = y * max_columns + x;
+ buffer[index].fg = color_fg;
+ buffer[index].bg = color_bg;
}
}
}
@@ -30,7 +37,7 @@ void VGA::write(char c) {
break;
default: {
const size_t index = row * max_columns + column;
- buffer[index] = vga_entry(c, (color == 0) ? this->color : color);
+ buffer[index].c = c;
++column;
}
}
diff --git a/src/vga.h b/src/vga.h
index 3052dbc..32c152f 100644
--- a/src/vga.h
+++ b/src/vga.h
@@ -4,7 +4,7 @@
class VGA : public Console {
public:
/* Hardware text mode color constants. */
- enum vga_color {
+ enum vga_color : uint8_t {
VGA_COLOR_BLACK = 0,
VGA_COLOR_BLUE = 1,
VGA_COLOR_GREEN = 2,
@@ -26,14 +26,25 @@ public:
VGA(vga_color fg = VGA_COLOR_BLACK, vga_color bg = VGA_COLOR_LIGHT_GREY, uint32_t address = 0xB8000);
~VGA() = default;
+ void set_color(vga_color fg, vga_color bg);
+
void write(char c) override;
void write(ViewIterator& iter) override;
- void set_color(vga_color fg, vga_color bg) { color = (fg | bg << 4); }
+
+ struct Entry {
+ char c;
+ vga_color fg : 4;
+ vga_color bg : 4;
+ } __attribute((packed));
private:
const size_t max_columns = 80, max_rows = 25;
size_t column = 0, row = 0;
- uint8_t color;
- uint16_t* buffer;
+
+ vga_color color_fg;
+ vga_color color_bg;
+
+ Entry* buffer;
};
+