aboutsummaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/gdt.c51
-rw-r--r--src/kernel/gen_gdt.c11
-rw-r--r--src/kernel/kernel.c28
3 files changed, 76 insertions, 14 deletions
diff --git a/src/kernel/gdt.c b/src/kernel/gdt.c
new file mode 100644
index 0000000..cf0f487
--- /dev/null
+++ b/src/kernel/gdt.c
@@ -0,0 +1,51 @@
+#include "gdt.h"
+#include <stdint.h>
+
+uint8_t make_access(uint8_t DPL, uint8_t type, uint8_t exec, uint8_t direction,
+ uint8_t read_write) {
+ uint8_t access = 0;
+ access |= (1 << 7);
+ access |= (DPL << 5);
+ access |= (type << 4);
+ access |= (exec << 3);
+ access |= (direction << 2);
+ access |= (read_write << 1); // 10
+ return access;
+}
+
+uint16_t make_code(uint8_t priv, uint8_t dc, uint8_t rw) {
+ uint16_t access = 0;
+ access |= (1 << 7);
+ access |= (priv << 5);
+ access |= (0b11 << 3);
+ access |= (dc << 2);
+ access |= (rw << 1); // 10
+ access <<= 8;
+ access |= FLAG;
+ return access;
+}
+
+uint16_t make_data(uint8_t priv, uint8_t dc, uint8_t rw) {
+ uint16_t access = 0;
+ access |= (1 << 7);
+ access |= (priv << 5);
+ access |= (0b10 << 3);
+ access |= (dc << 2);
+ access |= (rw << 1); // 10
+ access <<= 8;
+ access |= FLAG;
+ return access;
+}
+
+Segment_Descriptor_t make_descriptor(uint32_t base, uint32_t limit,
+ uint16_t access_flag) {
+ uint16_t lim_low = limit;
+ uint16_t base_low = base;
+ uint8_t base_mid = (base >> 16);
+ uint8_t access_byte = access_flag >> 8;
+ uint8_t lim_flag = ((access_flag << 4) | (limit >> 16));
+ uint8_t base_high = (base >> 24);
+ return (Segment_Descriptor_t){
+ lim_low, base_low, base_mid, access_byte, lim_flag, base_high,
+ };
+}
diff --git a/src/kernel/gen_gdt.c b/src/kernel/gen_gdt.c
new file mode 100644
index 0000000..05eedaa
--- /dev/null
+++ b/src/kernel/gen_gdt.c
@@ -0,0 +1,11 @@
+#include "gdt.h"
+
+GDT_t *table = 0x0;
+GDTR_t gdtr = {0, 0};
+void get_gdtr() {
+ *table = (GDT_t){make_descriptor(0, 0, 0),
+ make_descriptor(0x0000, 0xFFFFF, make_code(0, 0, 1)),
+ make_descriptor(0x0000, 0xFFFFF, make_data(0, 0, 1))};
+ gdtr.size = sizeof(Segment_Descriptor_t) * 3 - 1;
+ gdtr.offset = 0x0;
+}
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index 40438ec..01c017b 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -10,20 +10,20 @@
#error "Must use ix86-elf compiler"
#endif
-// Color Constants
-
void kernel_main(void) {
- print_clear();
- for (int r = 0; r < 24; r++) {
- for (int c = 0; c < 80; c += 3) {
- int color = (r + c) % 15 + 1;
- print_set_color(color, PRINT_COLOR_BLACK);
- printf(":3 ");
+ print_clear();
+ for (int r = 0; r < 24; r++) {
+ for (int c = 0; c < 80; c += 3) {
+ int color = (r + c) % 15 + 1;
+ print_set_color(color, PRINT_COLOR_BLACK);
+ printf(":3 ");
+ }
+ printf("%n");
}
- printf("%n");
- }
- print_set_color(PRINT_COLOR_YELLOW, PRINT_COLOR_BLACK);
- printf("printf\n\tint: %d\n\tstring: %s\n\tchar: %c\n\tpercent: "
- "%%\n\tnothing: %n",
- 99, "World! ", 't');
+ print_set_color(PRINT_COLOR_YELLOW, PRINT_COLOR_BLACK);
+ printf("printf\n\tint: %d\n\tstring: %s\n\tchar: %c\n\tpercent: "
+ "%%\n\tnothing: %n",
+ 99, "World! ", 't');
+
+ // printf("\n0x%d\n", *((int *)(0x0010)));
}