From 356c3d72a2be0cdf968bf63e28337fb17d555617 Mon Sep 17 00:00:00 2001 From: "brice.boisson" Date: Tue, 5 Sep 2023 16:47:54 +0900 Subject: [PATCH] Add: paging structure --- .gitignore | 3 +- src/Makefile | 1 + src/paging.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/paging.h | 24 +++++++++++++++ 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/paging.c create mode 100644 src/paging.h diff --git a/.gitignore b/.gitignore index 89547ba..c03e5e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -log.txt \ No newline at end of file +log.txt +.vscode \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index 10cdb72..9d4f0d3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,6 +13,7 @@ OBJS = \ pic_controler.o \ userland.o \ launch_process.o \ + paging.o \ DEPS = $(OBJS:.o=.d) diff --git a/src/paging.c b/src/paging.c new file mode 100644 index 0000000..dd728e4 --- /dev/null +++ b/src/paging.c @@ -0,0 +1,84 @@ +#include "paging.h" + +struct page_directory_entry page_dir[1024]; +struct page_table_entry page_table[1024]; + +struct page_directory_param { + u8 P; + u8 R_W; + u8 U; + u8 PWT; + u8 PCD; + u8 A; + u8 PS; + u32 address; +}; + +struct page_table_param { + u8 P; + u8 R_W; + u8 U; + u8 PWT; + u8 PCD; + u8 A; + u8 D; + u8 PAT; + u8 G; + u32 address; +}; + +struct page_directory_entry create_page_directory_entry(struct page_directory_param param) +{ + struct page_directory_entry page_dir; + + page_dir.flags = 2; + + page_dir.available = (u8) 10; + + page_dir.address = (u32) 24; + + return page_dir; +} + +struct page_table_entry create_page_table_entry(struct page_table_param param) +{ + struct page_table_entry page_table; + + page_table.flags = 2; + + page_table.g = (u8) 10; + + page_table.available = (u8) 0; + + page_table.address = (u32) 24; + + return page_table; +} + +int make_page(void) +{ + page_table[0] = create_page_table_entry((struct page_table_param) { + .P = 1, .R_W = 1, .U = 1, .PWT = 1, .PCD = 1, + .A = 0, .D = 0, .PAT = 0, .G = 0, + .address = 0}); + + for (int i = 1; i < 1024; i++) + { + page_table[i] = create_page_table_entry((struct page_table_param) { + .P = 0, .R_W = 0, .U = 0, .PWT = 0, .PCD = 0, + .A = 0, .D = 0, .PAT = 0, .G = 0, + .address = 0}); + } + + page_dir[0] = create_page_directory_entry((struct page_directory_param) { + .P = 1, .R_W = 1, .U = 1, .PWT = 1, .PCD = 1, + .A = 0, .PS = 0, .address = page_table}); + for (int i = 1; i < 1024; i++) + { + page_dir[i] = create_page_directory_entry((struct page_directory_param) { + .P = 0, .R_W = 0, .U = 0, .PWT = 0, .PCD = 0, + .A = 0, .PS = 0, .address = 0}); + } + + return 0; +} diff --git a/src/paging.h b/src/paging.h new file mode 100644 index 0000000..af9c942 --- /dev/null +++ b/src/paging.h @@ -0,0 +1,24 @@ +#ifndef PAGING_H +#define PAGING_H + +#include + +struct page_directory_entry { + u8 flags; + u8 available : 4; + u32 address : 20; +} __attribute__((packed)); + +struct page_table_entry { + u8 flags; + u8 g : 1; + u8 available : 3; + u32 address : 20; +} __attribute__((packed)); + +int make_page(void); + +extern struct page_directory_entry page_dir[1024]; +extern struct page_table_entry page_table[1024]; + +#endif /* !PAGING_H */