重构内存分配器、增加中断支持、整理rust运行时环境 #4

Merged
pointer-to-bios merged 39 commits from downstream into main 2024-04-11 00:36:14 +08:00
3 changed files with 52 additions and 39 deletions
Showing only changes of commit c52d9f4960 - Show all commits

View File

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

View File

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

View File

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