将页计数移入架构支持中(因为不同的架构分页机制不同)

This commit is contained in:
pointer-to-bios 2024-02-19 01:03:27 +08:00
parent 0613dadeaf
commit c52d9f4960
3 changed files with 52 additions and 39 deletions

View File

@ -7,9 +7,9 @@
/**
* @name MEMM_PAGE_SIZE
* @addindex
*
*
*
*
*
* @if arch == x86_64 then
* 4096
* @endif
@ -28,7 +28,7 @@ extern u64 PML4[512];
/**
* @name MEMM_PAGE_TABLE_FLAGS_MASK
* @addindex x86_64
*
*
* 使12`0xfff`
*/
#define MEMM_PAGE_TABLE_FLAGS_MASK ((u64)0xfff)
@ -36,7 +36,7 @@ extern u64 PML4[512];
/**
* @name MEMM_xx_ALIGN_MASK
* @addindex x86_64
*
*
*
* `xx``x86_64``4K``2M``1G`n位总为0的情况
* `4K``0xfff``2M``0x1fffff``1G``0x3fffffff`
@ -48,9 +48,9 @@ extern u64 PML4[512];
/**
* @name MEMM_ENTRY_FLAG_xx
* @addindex x86_64
*
*
*
*
*
* ```c
* #define MEMM_ENTRY_FLAG_PRESENT ((u64)1)
* #define MEMM_ENTRY_FLAG_WRITE ((u64)1 << 1)
@ -65,7 +65,7 @@ extern u64 PML4[512];
* #define MEMM_PTE_ENTRY_FLAG_PAT ((u64)1 << 7)
* #define MEMM_ENTRY_FLAG_XD ((u64)1 << 63)
* ```
*
*
* `MEMM_PTE_ENTRY_FLAG_PAT``pte``pte`
*/
#define MEMM_ENTRY_FLAG_PRESENT ((u64)1)
@ -84,9 +84,9 @@ extern u64 PML4[512];
/**
* @name memm_entry_flag_get(entry, flag)
* @addindex x86_64
*
*
*
*
*
* `flag``MEMM_ENTRY_FLAG_xx`
*/
#define memm_entry_flag_get(entry, flag) \
@ -95,13 +95,13 @@ extern u64 PML4[512];
/**
* @name MEMM_ENTRY_ADDRESS_MASK, MEMM_BP_ENTRY_ADDRESS_MASK
* @addindex x86_64
*
*
* ********
*
*
* `BP`
*
*
*
*
*
* ```c
* #define MEMM_ENTRY_ADDRESS_MASK ((u64)0x000ffffffffff000)
* #define MEMM_BP_ENTRY_ADDRESS_MASK ((u64)0x000fffffffffe000)
@ -113,7 +113,7 @@ extern u64 PML4[512];
/**
* @name memm_entry_get_address(entry)
* @addindex x86_64
*
*
*
*/
#define memm_entry_get_address(entry) \
@ -138,7 +138,7 @@ extern u64 PML4[512];
/**
* @name MEMM_LA_xxxxI
* @addindex x86_64
*
*
* 4线`xxxx``PML4E``PDPTE``PDE``PE`
*/
#define MEMM_LA_PML4EI
@ -149,9 +149,9 @@ extern u64 PML4[512];
/**
* @name memm_la_get_entry_index(addr, entry)
* @addindex x86_64
*
*
* 线`addr``entry`
*
*
* `entry``MEMM_LA_xxxxI`
*/
#define memm_la_get_entry_index(addr, entry) \
@ -160,7 +160,7 @@ extern u64 PML4[512];
/**
* @name MEMM_LA_xxx_PAGE_OFFSET
* @addindex x86_64
*
*
* 线`xxx``4KB``2MB``1GB`
*/
#define MEMM_LA_1GB_PAGE_OFFSET
@ -170,9 +170,9 @@ extern u64 PML4[512];
/**
* @name memm_la_get_offset(addr, page_type)
* @addindex x86_64
*
*
* 线
*
*
* `page_type``MEMM_LA_xxx_PAGE_OFFSET`
*/
#define memm_la_get_offset(addr, page_type) \
@ -180,20 +180,20 @@ extern u64 PML4[512];
/**
* @name memm_map_pageframes_to
*
*
* ```c
* bool memm_map_pageframes_to(
* u64 target, u64 physical,
* usize size,
* bool user, bool write);
* ```
*
*
* **canonical**
*
*
* `target``physical`MEMM_PAGE_SIZE对齐的
*
*
* MEMM_PAGE_SIZE对齐的canonical型地址都会返回false
*
*
* 1GB的一半且地址1GB对齐1GB页
* 2MB的一半且地址2MB对齐2MB页
* 4KB页
@ -206,7 +206,7 @@ bool memm_map_pageframes_to(
/**
* @name reload_pml4
* @addindex x86_64
*
*
* ```c
* void reload_pml4();
* ```
@ -216,9 +216,9 @@ extern void reload_pml4();
/**
* @name is_user_address(addr)
* @addindex
*
*
* `addr`
*
*
* @if arch == x86_64
* `canonical`
* @endif
@ -229,7 +229,7 @@ extern void reload_pml4();
/**
* @name is_cannonical(addr)
* @addindex x86_64
*
*
* `addr`cannonical型地址
*/
#define is_cannonical(addr) \
@ -238,9 +238,9 @@ extern void reload_pml4();
/**
* @name memm_get_page_align(addr)
* @addindex x86_64
*
*
* `addr``memm_page_size`
*
*
* `addr`*4KB对齐**4KB对齐时*`MEMM_PAGE_SIZE_4K`
*/
#define memm_get_page_align(addr) \
@ -250,4 +250,21 @@ extern void reload_pml4();
? MEMM_PAGE_SIZE_2M \
: MEMM_PAGE_SIZE_4K))
/**
* @name memm_page_counter
* @addindex
*
*
*
* @if arch == x86_64
* 使`4KB``2MB``1GB`
* @endif
*/
typedef struct __memm_page_counter
{
usize mapped_4k_page;
usize mapped_2m_page;
usize mapped_1g_page;
} memm_page_counter;
#endif

View File

@ -186,11 +186,7 @@ typedef struct __mem_manager_t
// 已经映射的页数量。若不是最小的页会被视作多个最小页计数。
usize mapped_page_amount;
#ifdef __x86_64__
usize mapped_4k_page;
usize mapped_2m_page;
usize mapped_1g_page;
#endif
memm_page_counter platformed_page_counter;
// 页地图。每个bit都表示这个页是否被映射。
u8 *page_map;

View File

@ -126,11 +126,11 @@ bool memm_map_pageframes_to(
switch (align)
{
case MEMM_PAGE_SIZE_4K:
mm->mapped_4k_page++;
mm->platformed_page_counter.mapped_4k_page++;
case MEMM_PAGE_SIZE_2M:
mm->mapped_2m_page++;
mm->platformed_page_counter.mapped_2m_page++;
case MEMM_PAGE_SIZE_1G:
mm->mapped_1g_page++;
mm->platformed_page_counter.mapped_1g_page++;
}
for (usize i = physical / MEMM_PAGE_SIZE; i < physical / MEMM_PAGE_SIZE + align; i++)
{