aboutsummaryrefslogtreecommitdiff
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
parentAdd more comments to GDT code (diff)
downloadkernel.cpp-a487d6ccee43bd6cd5ec648e8b97712595f681a7.tar.xz
Add some compiler warnings
-rw-r--r--libk/stdlib.h9
-rw-r--r--libk/string.h1
-rw-r--r--libk/string/integerview.cc5
-rw-r--r--makefile3
-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
-rw-r--r--toolchain.makefile10
12 files changed, 78 insertions, 38 deletions
diff --git a/libk/stdlib.h b/libk/stdlib.h
index 1b76b67..7d89a0c 100644
--- a/libk/stdlib.h
+++ b/libk/stdlib.h
@@ -4,11 +4,12 @@
class Console {
public:
- virtual void write(char c) = 0;
- virtual void write(ViewIterator& msg) = 0;
+ virtual ~Console() = default;
+ virtual void write(char c) = 0;
+ virtual void write(ViewIterator& msg) = 0;
- static void set(Console* ptr);
- static Console* get();
+ static void set(Console* ptr);
+ static Console* get();
};
template <typename T>
diff --git a/libk/string.h b/libk/string.h
index 03c0942..30824b8 100644
--- a/libk/string.h
+++ b/libk/string.h
@@ -65,6 +65,7 @@ public:
};
IntegerView(int32_t n);
+ IntegerView(uint32_t n);
IntegerView(HexFormat_int32 f);
IntegerView(HexFormat_uint32 f);
diff --git a/libk/string/integerview.cc b/libk/string/integerview.cc
index beeb561..dc4c80a 100644
--- a/libk/string/integerview.cc
+++ b/libk/string/integerview.cc
@@ -9,7 +9,7 @@ constexpr size_t itoa(T n, char s[]) {
n = -n;
}
- int i = 0;
+ size_t i = 0;
do { /* generate digits in reverse order */
s[i++] = "0123456789abcdef"[n % base]; /* get next digit */
} while ((n /= base) > 0); /* delete it */
@@ -26,6 +26,9 @@ constexpr size_t itoa(T n, char s[]) {
IntegerView::IntegerView(int32_t n) {
length = itoa(n, buffer);
}
+IntegerView::IntegerView(uint32_t n) {
+ length = itoa(n, buffer);
+}
IntegerView::IntegerView(HexFormat_int32 f) {
length = itoa<int32_t, 16>(f.n, buffer);
diff --git a/makefile b/makefile
index 0235442..724c57b 100644
--- a/makefile
+++ b/makefile
@@ -12,6 +12,7 @@ AS_OBJ := $(addprefix $(OBJ_DIR)/, $(AS_OBJ))
CXX_OBJ := $(addprefix $(OBJ_DIR)/, $(CXX_OBJ))
CXX_TEST_OBJ := $(addprefix $(OBJ_DIR)/, $(CXX_TEST_OBJ))
CXX_INCLUDE := $(addprefix -I, $(CXX_INCLUDE))
+CXX_SYSTEM_INCLUDE := $(addprefix -isystem, $(CXX_SYSTEM_INCLUDE))
# $@ is target
# $< is first dependency
@@ -32,7 +33,7 @@ $(AS_OBJ): $(OBJ_DIR)/%.o: %.s
$(CXX_OBJ) $(CXX_TEST_OBJ): $(OBJ_DIR)/%.o : %.cc
@mkdir -p $(@D)
@echo " CXX $^"
- @$(CXX) -target $(TARGET) $(CXX_FLAGS) $(CXX_INCLUDE) -c $^ -o $@
+ @$(CXX) -target $(TARGET) $(CXX_FLAGS) $(CXX_INCLUDE) $(CXX_SYSTEM_INCLUDE) -c $^ -o $@
clean:
rm -rf $(AS_OBJ) $(CXX_OBJ) $(CXX_TEST_OBJ) glitch.elf isodir
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;
};
+
diff --git a/toolchain.makefile b/toolchain.makefile
index f5fb1b1..fe916e4 100644
--- a/toolchain.makefile
+++ b/toolchain.makefile
@@ -9,8 +9,14 @@ LD_FLAGS := -T linker.ld
CXX := clang++
CXX_FLAGS := -std=c++20 -ffreestanding -nostdlib -nostdinc -nostdinc++ \
- -fno-exceptions -fno-rtti -Wall -Wextra -O2
-CXX_INCLUDE := $(CURDIR)/libk $(CURDIR)/grub
+ -fno-exceptions -fno-rtti -Wall -Wextra -Werror=pedantic -O2 \
+ -Werror=date-time \
+ -Werror=shadow-all \
+ -Wnon-virtual-dtor \
+ -Wold-style-cast -Wconversion \
+ -Wconsumed
+CXX_INCLUDE := $(CURDIR)/libk
+CXX_SYSTEM_INCLUDE := $(CURDIR)/grub
#
BOOT := grub-mkrescue