diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/as/Makefile | 2 | ||||
| -rw-r--r-- | src/as/paging.s | 21 | ||||
| -rw-r--r-- | src/c/Makefile | 2 | ||||
| -rw-r--r-- | src/c/irq.c (renamed from src/c/irq_handler.c) | 0 | ||||
| -rw-r--r-- | src/c/kernel.c | 2 | ||||
| -rw-r--r-- | src/c/paging.c | 51 | ||||
| -rw-r--r-- | src/c/tty.c | 5 |
7 files changed, 78 insertions, 5 deletions
diff --git a/src/as/Makefile b/src/as/Makefile index e2c476d..bd5664b 100644 --- a/src/as/Makefile +++ b/src/as/Makefile @@ -1,5 +1,5 @@ .PHONY: all all: $(AS_OBJECTS) -$(BUILD_DIR)/%.o: %.s +$(AS_OBJECT_DIR)/%.o: %.s $(AS) $< -o $@ diff --git a/src/as/paging.s b/src/as/paging.s new file mode 100644 index 0000000..2dd52d3 --- /dev/null +++ b/src/as/paging.s @@ -0,0 +1,21 @@ +.globl loadPageDirectory +loadPageDirectory: + push %ebp + mov %esp, %ebp + mov 8(%esp), %eax + mov %eax, %cr3 + mov %ebp, %esp + pop %ebp + ret + +.text +.globl enablePaging +enablePaging: + push %ebp + mov %esp, %ebp + mov %cr0, %eax + or $0x80000000, %eax + mov %eax, %cr0 + mov %ebp, %esp + pop %ebp + ret diff --git a/src/c/Makefile b/src/c/Makefile index 7c5d1af..9625009 100644 --- a/src/c/Makefile +++ b/src/c/Makefile @@ -1,5 +1,5 @@ .PHONY: all all: $(C_OBJECTS) -$(BUILD_DIR)/%.o: %.c +$(C_OBJECT_DIR)/%.o: %.c $(CC) -c $< -o $@ -std=gnu99 $(CFLAGS) diff --git a/src/c/irq_handler.c b/src/c/irq.c index 6b80a52..6b80a52 100644 --- a/src/c/irq_handler.c +++ b/src/c/irq.c diff --git a/src/c/kernel.c b/src/c/kernel.c index 62f444c..48dbccb 100644 --- a/src/c/kernel.c +++ b/src/c/kernel.c @@ -5,10 +5,12 @@ void init_idt_table(void); void init_keyboard(void); void init_timer(uint32_t frequency); void prompt(void); +void set_paging(); void kernel_main(void) { terminal_initialize(); + set_paging(); init_idt_table(); init_keyboard(); init_timer(50); diff --git a/src/c/paging.c b/src/c/paging.c new file mode 100644 index 0000000..b256b74 --- /dev/null +++ b/src/c/paging.c @@ -0,0 +1,51 @@ +#include"../include/types.h" + +extern void loadPageDirectory(uint32_t*); +extern void enablePaging(); + +uint32_t page_directory[1024] __attribute__((aligned(4096))); + +void set_pd() +{ + //set each entry to not present + for(size_t i=0;i<1024;i++) + { + // This sets the following flags to the pages: + // Supervisor: Only kernel-mode can access them + // Write Enabled: It can be both read from and written to + // Not Present: The page table is not present + page_directory[i] = 0x00000002; + } +} + +uint32_t first_page_table[1024] __attribute__((aligned(4096))); + +void set_pt() +{ + // holds the physical address where we want to start mapping these pages to. + // in this case, we want to map these pages to the very beginning of memory. + unsigned int i; + + //we will fill all 1024 entries in the table, mapping 4 megabytes + for(i = 0; i < 1024; i++) + { + // As the address is page aligned, it will always leave 12 bits zeroed. + // Those bits are used by the attributes ;) + first_page_table[i] = (i * 0x1000) | 3; // attributes: supervisor level, read/write, present. + } +} + +void put_pt() +{ + // attributes: supervisor level, read/write, present + page_directory[0] = ((uint32_t)first_page_table) | 3; +} + +void set_paging() +{ + set_pd(); + set_pt(); + put_pt(); + loadPageDirectory(page_directory); + enablePaging(); +} diff --git a/src/c/tty.c b/src/c/tty.c index 116a15e..c473fa1 100644 --- a/src/c/tty.c +++ b/src/c/tty.c @@ -110,9 +110,8 @@ void neofetch() for(size_t i=0;i<16;i++) { - if(i==0) set_color(i,VGA_COLOR_WHITE); - else set_color(i,VGA_COLOR_BLACK); - printf("@%d ",i); + set_color(0,i); + printf(" ",i); } printf("\n"); |
