aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/paging
diff options
context:
space:
mode:
authorMarvin Borner2019-11-24 23:34:32 +0100
committerMarvin Borner2019-11-24 23:34:32 +0100
commitbb57b124d1bb385d41747f50be7dd4f3625539c1 (patch)
treefe461afad63df40571784565e8d435cba8c8e59c /src/kernel/paging
parentf9c50b9ff23e9a3e8db5826fef7a6e7ebb8af21d (diff)
Major coding style reformatting -> Kernighan & Ritchie
This project now (hopefully) uses the same style recommended by Kernighan and Ritchie and used in the Linux Kernel
Diffstat (limited to 'src/kernel/paging')
-rw-r--r--src/kernel/paging/paging.c66
1 files changed, 42 insertions, 24 deletions
diff --git a/src/kernel/paging/paging.c b/src/kernel/paging/paging.c
index 09cbbc0..4c8cb44 100644
--- a/src/kernel/paging/paging.c
+++ b/src/kernel/paging/paging.c
@@ -8,7 +8,8 @@ int paging_enabled = 0;
uint32_t page_directory[1024] __attribute__((aligned(4096)));
uint32_t page_tables[1024][1024] __attribute__((aligned(4096)));
-void paging_install() {
+void paging_install()
+{
for (uint32_t i = 0; i < 1024; i++) {
for (uint32_t j = 0; j < 1024; j++) {
page_tables[i][j] = ((j * 0x1000) + (i * 0x400000)) | PT_RW;
@@ -24,50 +25,58 @@ void paging_install() {
paging_enable();
serial_write_dec(memory_get_all() >> 10);
- vga_log("Installed paging", 5);
+
+ vga_log("Installed paging", 4);
}
-void paging_disable() {
+void paging_disable()
+{
uint32_t cr0;
- asm volatile("mov %%cr0, %0": "=r"(cr0));
+ asm ("mov %%cr0, %0": "=r"(cr0));
cr0 &= 0x7fffffff;
- asm volatile("mov %0, %%cr0"::"r"(cr0));
+ asm ("mov %0, %%cr0"::"r"(cr0));
paging_enabled = 0;
}
-void paging_enable() {
- asm volatile("mov %0, %%cr3"::"r"(page_directory));
+void paging_enable()
+{
+ asm ("mov %0, %%cr3"::"r"(page_directory));
uint32_t cr0;
- asm volatile("mov %%cr0, %0": "=r"(cr0));
+ asm ("mov %%cr0, %0": "=r"(cr0));
cr0 |= 0x80000000;
- asm volatile("mov %0, %%cr0"::"r"(cr0));
+ asm ("mov %0, %%cr0"::"r"(cr0));
paging_enabled = 1;
}
-inline void invlpg(uint32_t addr) {
- asm volatile("invlpg (%0)"::"r" (addr) : "memory");
+inline void invlpg(uint32_t addr)
+{
+ asm ("invlpg (%0)"::"r" (addr) : "memory");
}
-void paging_map(uint32_t phy, uint32_t virt, uint16_t flags) {
+void paging_map(uint32_t phy, uint32_t virt, uint16_t flags)
+{
uint32_t pdi = virt >> 22;
uint32_t pti = virt >> 12 & 0x03FF;
page_tables[pdi][pti] = phy | flags;
invlpg(virt);
}
-uint32_t paging_get_physical_addr(uint32_t virt) {
+uint32_t paging_get_physical_addr(uint32_t virt)
+{
uint32_t pdi = virt >> 22;
uint32_t pti = (virt >> 12) & 0x03FF;
return page_tables[pdi][pti] & 0xFFFFF000;
}
-uint16_t paging_get_flags(uint32_t virt) {
+uint16_t paging_get_flags(uint32_t virt)
+{
uint32_t pdi = virt >> 22;
uint32_t pti = (virt >> 12) & 0x03FF;
return page_tables[pdi][pti] & 0xFFF;
}
-void paging_set_flag_up(uint32_t virt, uint32_t count, uint32_t flag) {
+void paging_set_flag_up(uint32_t virt, uint32_t count, uint32_t flag)
+{
uint32_t page_n = virt / 4096;
for (uint32_t i = page_n; i < page_n + count; i++) {
page_tables[i / 1024][i % 1024] |= flag;
@@ -75,7 +84,8 @@ void paging_set_flag_up(uint32_t virt, uint32_t count, uint32_t flag) {
}
}
-void paging_set_flag_down(uint32_t virt, uint32_t count, uint32_t flag) {
+void paging_set_flag_down(uint32_t virt, uint32_t count, uint32_t flag)
+{
uint32_t page_n = virt / 4096;
for (uint32_t i = page_n; i < page_n + count; i++) {
page_tables[i / 1024][i % 1024] &= ~flag;
@@ -83,23 +93,28 @@ void paging_set_flag_down(uint32_t virt, uint32_t count, uint32_t flag) {
}
}
-void paging_set_present(uint32_t virt, uint32_t count) {
+void paging_set_present(uint32_t virt, uint32_t count)
+{
paging_set_flag_up(virt, count, PT_PRESENT);
}
-void paging_set_absent(uint32_t virt, uint32_t count) {
+void paging_set_absent(uint32_t virt, uint32_t count)
+{
paging_set_flag_down(virt, count, PT_PRESENT);
}
-void paging_set_used(uint32_t virt, uint32_t count) {
+void paging_set_used(uint32_t virt, uint32_t count)
+{
paging_set_flag_up(virt, count, PT_USED);
}
-void paging_set_free(uint32_t virt, uint32_t count) {
+void paging_set_free(uint32_t virt, uint32_t count)
+{
paging_set_flag_down(virt, count, PT_USED);
}
-void paging_set_user(uint32_t virt, uint32_t count) {
+void paging_set_user(uint32_t virt, uint32_t count)
+{
uint32_t page_n = virt / 4096;
for (uint32_t i = page_n; i < page_n + count; i += 1024) {
page_directory[i / 1024] |= PD_ALL_PRIV;
@@ -107,7 +122,8 @@ void paging_set_user(uint32_t virt, uint32_t count) {
paging_set_flag_up(virt, count, PT_ALL_PRIV);
}
-uint32_t paging_find_pages(uint32_t count) {
+uint32_t paging_find_pages(uint32_t count)
+{
uint32_t continous = 0;
uint32_t startDir = 0;
uint32_t startPage = 0;
@@ -128,13 +144,15 @@ uint32_t paging_find_pages(uint32_t count) {
return 0;
}
-uint32_t paging_alloc_pages(uint32_t count) {
+uint32_t paging_alloc_pages(uint32_t count)
+{
uint32_t ptr = paging_find_pages(count);
paging_set_used(ptr, count);
return ptr;
}
-uint32_t paging_get_used_pages() {
+uint32_t paging_get_used_pages()
+{
uint32_t n = 0;
for (uint32_t i = 0; i < 1024; i++) {
for (uint32_t j = 0; j < 1024; j++) {