summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.xyz>2021-01-24 21:10:57 -0600
committerDanny Holman <dholman@gymli.xyz>2021-01-24 21:10:57 -0600
commita4534660fecb1b571c24ad82e67bc6c2fb814cb9 (patch)
tree149984cb0e9a32765e63df0f696091817c2b6dd5
parentdd6656f7132d1727a055035ca94945fa4fbaae58 (diff)
x86: reorganize the i386 directory
Add structure to the internals of the x86 directory. Signed-off-by: Danny Holman <dholman@gymli.xyz>
-rw-r--r--Makefile19
-rw-r--r--arch/i386/boot/boot.s (renamed from arch/i386/boot.s)0
-rw-r--r--arch/i386/boot/crti.s (renamed from arch/i386/crti.s)0
-rw-r--r--arch/i386/boot/crtn.s (renamed from arch/i386/crtn.s)0
-rw-r--r--arch/i386/boot/tty.c (renamed from arch/i386/tty.c)0
-rw-r--r--arch/i386/boot/vga.h (renamed from arch/i386/vga.h)0
-rw-r--r--arch/i386/include/gdt.h69
-rw-r--r--arch/i386/kernel/pic.h (renamed from arch/i386/pic.h)0
-rw-r--r--arch/i386/kernel/serial.c (renamed from arch/i386/serial.c)0
-rw-r--r--arch/i386/make.config7
10 files changed, 84 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index c42fa08..fdf693c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,11 @@
CC=i686-elf-gcc
+INCLUDE?=include
CFLAGS?=-O2 -g
LDFLAGS?=
LIBS?=
-CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra -Iinclude
+INCLUDE:=$(INCLUDE)
+CFLAGS:=$(CFLAGS) -ffreestanding -Wall -Wextra -I$(INCLUDE)
LDFLAGS:=$(LDFLAGS)
LIBS:=$(LIBS) -nostdlib -lgcc
@@ -11,7 +13,8 @@ ARCHDIR=arch/i386
include $(ARCHDIR)/make.config
-CFLAGS:=$(CFLAGS) $(KERNEL_ARCH_CFLAGS)
+INCLUDE:=$(INCLUDE) $(KERNEL_ARCH_INCLUDE)
+CFLAGS:=$(CFLAGS) $(KERNEL_ARCH_CFLAGS) -I$(INCLUDE)
LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS)
LIBS:=$(LIBS) $(KERNEL_ARCH_LIBS)
@@ -22,19 +25,19 @@ KERNEL_OBJS=$(KERNEL_ARCH_OBJS) \
kernel/string.o \
kernel/io.o \
-OBJS=$(ARCHDIR)/crti.o \
+OBJS=$(ARCHDIR)/boot/crti.o \
$(ARCHDIR)/crtbegin.o \
$(KERNEL_OBJS) \
$(ARCHDIR)/crtend.o \
- $(ARCHDIR)/crtn.o \
+ $(ARCHDIR)/boot/crtn.o \
LINK_LIST=$(LDFLAGS) \
- $(ARCHDIR)/crti.o \
+ $(ARCHDIR)/boot/crti.o \
$(ARCHDIR)/crtbegin.o \
$(KERNEL_OBJS) \
$(LIBS) \
$(ARCHDIR)/crtend.o \
- $(ARCHDIR)/crtn.o \
+ $(ARCHDIR)/boot/crtn.o \
.PHONY: all clean install install-headers install-kernel
.SUFFIXES: .o .c .s
@@ -42,7 +45,7 @@ LINK_LIST=$(LDFLAGS) \
all: $(KERNEL)
$(KERNEL): $(OBJS) $(ARCHDIR)/linker.ld
- @$(CC) -T $(ARCHDIR)/linker.ld -o $@ $(CFLAGS) $(LINK_LIST)
+ @$(CC) -T $(ARCHDIR)/linker.ld -o $@ $(LINK_LIST)
@echo [LD] $@
$(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
@@ -54,7 +57,7 @@ $(ARCHDIR)/crtbegin.o $(ARCHDIR)/crtend.o:
.s.o:
@$(CC) -MD -c $< -o $@ $(CFLAGS)
- @echo [CC] $@
+ @echo [AS] $@
clean:
$(RM) $(KERNEL)
diff --git a/arch/i386/boot.s b/arch/i386/boot/boot.s
index 56ac227..56ac227 100644
--- a/arch/i386/boot.s
+++ b/arch/i386/boot/boot.s
diff --git a/arch/i386/crti.s b/arch/i386/boot/crti.s
index 4e1e4cb..4e1e4cb 100644
--- a/arch/i386/crti.s
+++ b/arch/i386/boot/crti.s
diff --git a/arch/i386/crtn.s b/arch/i386/boot/crtn.s
index 447afb1..447afb1 100644
--- a/arch/i386/crtn.s
+++ b/arch/i386/boot/crtn.s
diff --git a/arch/i386/tty.c b/arch/i386/boot/tty.c
index 9c3985b..9c3985b 100644
--- a/arch/i386/tty.c
+++ b/arch/i386/boot/tty.c
diff --git a/arch/i386/vga.h b/arch/i386/boot/vga.h
index e89f202..e89f202 100644
--- a/arch/i386/vga.h
+++ b/arch/i386/boot/vga.h
diff --git a/arch/i386/include/gdt.h b/arch/i386/include/gdt.h
new file mode 100644
index 0000000..4ffa155
--- /dev/null
+++ b/arch/i386/include/gdt.h
@@ -0,0 +1,69 @@
+#ifndef GDT_H
+#define GDT_H
+
+#include <stdint.h>
+
+#define SEG_DESCTYPE(x) ((x) << 0x04)
+#define SEG_PRES(x) ((x) << 0x07)
+#define SEG_SAVL(x) ((x) << 0x0C)
+#define SEG_LONG(x) ((x) << 0x0D)
+#define SEG_SIZE(x) ((x) << 0x0E)
+#define SEG_GRAN(x) ((x) << 0x0F)
+#define SEG_PRIV(x) (((x) & 0x03) << 0x05)
+
+#define SEG_DATA_RD 0x00
+#define SEG_DATA_RDA 0x01
+#define SEG_DATA_RDWR 0x02
+#define SEG_DATA_RDWRA 0x03
+#define SEG_DATA_RDEXPD 0x04
+#define SEG_DATA_RDEXPDA 0x05
+#define SEG_DATA_RDWREXD 0x06
+#define SEG_DATA_RDWREXDA 0x07
+#define SEG_CODE_EX 0x08
+#define SEG_CODE_EXA 0x09
+#define SEG_CODE_EXRD 0x0A
+#define SEG_CODE_EXRDA 0x0B
+#define SEG_CODE_EXC 0x0C
+#define SEG_CODE_EXCA 0x0D
+#define SEG_CODE_EXRDC 0x0E
+#define SEG_CODE_EXRDCA 0x0F
+
+#define GDT_CODE_PL0 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
+ SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
+ SEG_PRIV(0) | SEG_CODE_EXRD
+
+#define GDT_DATA_PL0 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
+ SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
+ SEG_PRIV(0) | SEG_CODE_RDWR
+
+#define GDT_CODE_PL3 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
+ SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
+ SEG_PRIV(3) | SEG_DATA_EXRD
+
+#define GDT_DATA_PL3 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
+ SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
+ SEG_PRIV(3) | SEG_DATA_RDWR
+
+struct gdt {
+ uint16_t size;
+ uint32_t offset;
+} __attribute__((packed));
+
+void flush_gdt(void);
+
+uint64_t create_descriptor(uint32_t base, uint32_t limit, uint16_t flag) {
+ uint64_t descriptor;
+
+ descriptor = limit & 0x000F0000;
+ descriptor |= (flag << 8) & 0x00F0FF00;
+ descriptor |= (base >> 16) & 0x000000FF;
+ descriptor |= base & 0xFF000000;
+
+ descriptor <<= 32;
+ descriptor |= base << 16;
+ descriptor |= limit & 0x0000FFFF;
+
+ return descriptor;
+}
+
+#endif
diff --git a/arch/i386/pic.h b/arch/i386/kernel/pic.h
index da4a2ee..da4a2ee 100644
--- a/arch/i386/pic.h
+++ b/arch/i386/kernel/pic.h
diff --git a/arch/i386/serial.c b/arch/i386/kernel/serial.c
index 20bd8f9..20bd8f9 100644
--- a/arch/i386/serial.c
+++ b/arch/i386/kernel/serial.c
diff --git a/arch/i386/make.config b/arch/i386/make.config
index 680760f..3add948 100644
--- a/arch/i386/make.config
+++ b/arch/i386/make.config
@@ -1,7 +1,8 @@
KERNEL_ARCH_CFLAGS=
KERNEL_ARCH_LDFLAGS=
KERNEL_ARCH_LIBS=
+KERNEL_ARCH_INCLUDE=$(ARCHDIR)/include
-KERNEL_ARCH_OBJS=$(ARCHDIR)/boot.o \
- $(ARCHDIR)/tty.o \
- $(ARCHDIR)/serial.o \
+KERNEL_ARCH_OBJS=$(ARCHDIR)/boot/boot.o \
+ $(ARCHDIR)/boot/tty.o \
+ $(ARCHDIR)/kernel/serial.o \