diff options
Diffstat (limited to 'i686')
-rw-r--r-- | i686/Makefile | 2 | ||||
-rw-r--r-- | i686/gdt.h | 2 | ||||
-rw-r--r-- | i686/test/gdt.c | 20 | ||||
-rw-r--r-- | i686/test_gdt.cc | 25 |
4 files changed, 28 insertions, 21 deletions
diff --git a/i686/Makefile b/i686/Makefile index ba780a9..ede39f0 100644 --- a/i686/Makefile +++ b/i686/Makefile @@ -9,5 +9,7 @@ arch.SRCS = boot.S init.s \ gdt.c lgdt.c \ lidt.c isr.c +TESTS += test_gdt + include ../rules.mk @@ -16,7 +16,7 @@ struct __attribute__((packed)) Access { }; _Static_assert(sizeof(struct Access) == 1, "access byte size"); -static const struct Access null_access = {false, false, false, false, false, false, false}; +static const struct Access null_access = {false, false, false, false, false, Ring0, false}; static const struct Access ktext_access = {.readwrite = true, .executable = true, .segment = true, .present = true}; static const struct Access kdata_access = {.readwrite = true, .segment = true, .present = true}; diff --git a/i686/test/gdt.c b/i686/test/gdt.c deleted file mode 100644 index 2947b42..0000000 --- a/i686/test/gdt.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "gdt.h" -#include <assert.h> -#include <stdlib.h> - -int -main() -{ - assert(*(uint8_t *)&null_access == 0x00); - assert(*(uint8_t *)&ktext_access == 0x9a); - assert(*(uint8_t *)&kdata_access == 0x92); - - struct SegmentDescriptor_t d; - SegmentDescriptor(&d, 0, 0, 0); - assert(*(uint64_t *)&d == 0); - - assert(ktextDescriptor == 0x10); - assert(kdataDescriptor == 0x18); - - return EXIT_SUCCESS; -} diff --git a/i686/test_gdt.cc b/i686/test_gdt.cc new file mode 100644 index 0000000..d596c3a --- /dev/null +++ b/i686/test_gdt.cc @@ -0,0 +1,25 @@ +#include <gtest/gtest.h> + +#define _Static_assert static_assert +#include "gdt.c" +#include "gdt.h" + +TEST(i686GDT, KnownAccessByteValues) +{ + EXPECT_EQ(*(uint8_t *)&null_access, 0x00); + EXPECT_EQ(*(uint8_t *)&ktext_access, 0x9a); + EXPECT_EQ(*(uint8_t *)&kdata_access, 0x92); +} + +TEST(i686GDT, NullSegmentDescriptor) +{ + struct SegmentDescriptor_t d; + SegmentDescriptor(&d, 0, 0, 0); + EXPECT_EQ(*(uint64_t *)&d, 0); +} + +TEST(i686GDT, SegmentIndex) +{ + EXPECT_EQ(ktextDescriptor, 0x10); + EXPECT_EQ(kdataDescriptor, 0x18); +} |