From a487d6ccee43bd6cd5ec648e8b97712595f681a7 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 9 Feb 2021 20:44:43 +0200 Subject: Add some compiler warnings --- src/gdt.h | 6 +++--- src/gdt/segmentdescriptor.cc | 3 ++- src/kernel/dump_multiboot.cc | 23 +++++++++++++---------- src/makefile | 1 + src/memory.cc | 5 +++++ src/vga.cc | 31 +++++++++++++++++++------------ src/vga.h | 19 +++++++++++++++---- 7 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 src/memory.cc (limited to 'src') 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 - 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(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(mb_addr + 8); tag->type != MULTIBOOT_TAG_TYPE_END; + tag = reinterpret_cast(reinterpret_cast(tag) + ((tag->size + 7u) & ~7u))) { switch (tag->type) { case MULTIBOOT_TAG_TYPE_CMDLINE: { auto* t = reinterpret_cast(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(mmap) < reinterpret_cast(tag) + tag->size; + mmap = reinterpret_cast(reinterpret_cast(mmap) + + reinterpret_cast(tag)->entry_size)) { + printk(" base_addr = ", uhex{static_cast(mmap->addr >> 32)}, ' ', + uhex{static_cast(mmap->addr & 0xffffffff)}); + printk(" length = ", static_cast(mmap->len >> 32), ' ', + static_cast(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(reinterpret_cast(tag) + ((tag->size + 7u) & ~7u)); + printk("Total mbi size ", reinterpret_cast(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 + +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 -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(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; }; + -- cgit v1.2.1