Fix softkernel uint32_t.

This commit is contained in:
TXuian
2024-05-10 15:40:36 +08:00
parent b6dd58c629
commit 79d741e015
9 changed files with 76 additions and 42 deletions
+10 -10
View File
@@ -57,25 +57,25 @@ Modification:
struct KPage {
struct double_list_node node;
union {
uint32_t order;
uintptr_t order;
struct KPage* page_node;
};
uintptr_t mapped_addr;
};
struct KFreeList {
uint32_t n_free_pages;
uintptr_t n_free_pages;
struct double_list_node list_head;
};
struct KBuddy {
uint32_t n_pages;
uint32_t use_lock;
uintptr_t n_pages;
uintptr_t use_lock;
struct spinlock lock;
struct KFreeList free_list[MAX_BUDDY_ORDER];
struct KPage* first_page;
uint32_t mem_start;
uint32_t mem_end;
uintptr_t mem_start;
uintptr_t mem_end;
struct KPage* pages;
};
@@ -88,15 +88,15 @@ struct KBuddy {
* @param mem_end free memory region end
* @return void
*/
bool KBuddyInit(struct KBuddy* pbuddy, uint32_t mem_start, uint32_t mem_end);
void KBuddySysInit(struct KBuddy* pbuddy, uint32_t mem_start, uint32_t mem_end);
bool KBuddyInit(struct KBuddy* pbuddy, uintptr_t mem_start, uintptr_t mem_end);
void KBuddySysInit(struct KBuddy* pbuddy, uintptr_t mem_start, uintptr_t mem_end);
/*
* Continuous pages alloc by size
* @param sizeuint32_t size of need alloc
* @param sizeuintptr_t size of need alloc
* @return NULL or v_addr (char*) return NULL if alloc failed, or return virtual page's addr
*/
char* KBuddyAlloc(struct KBuddy* pbuddy, uint32_t size);
char* KBuddyAlloc(struct KBuddy* pbuddy, uintptr_t size);
/*
* Continuous pages free from vaddr
@@ -42,8 +42,11 @@ Modification:
#include <stdint.h>
#include "memlayout.h"
#define ELF_MAGIC 0x464C457FU // "\x7FELF" in little endian
#if (ARCH_BIT == 32)
// File header
struct elfhdr {
uint32_t magic; // must equal ELF_MAGIC
@@ -51,9 +54,9 @@ struct elfhdr {
uint16_t type;
uint16_t machine;
uint32_t version;
uint32_t entry;
uint32_t phoff;
uint32_t shoff;
uintptr_t entry;
uintptr_t phoff;
uintptr_t shoff;
uint32_t flags;
uint16_t ehsize;
uint16_t phentsize;
@@ -74,6 +77,37 @@ struct proghdr {
uint32_t flags;
uint32_t align;
};
#elif (ARCH_BIT == 64)
struct elfhdr {
uint magic; // must equal ELF_MAGIC
uchar elf[12];
ushort type;
ushort machine;
uint version;
uint64 entry;
uint64 phoff;
uint64 shoff;
uint flags;
ushort ehsize;
ushort phentsize;
ushort phnum;
ushort shentsize;
ushort shnum;
ushort shstrndx;
};
// Program section header
struct proghdr {
uint32 type;
uint32 flags;
uint64 off;
uint64 vaddr;
uint64 paddr;
uint64 filesz;
uint64 memsz;
uint64 align;
};
#endif
// Values for Proghdr type
#define ELF_PROG_LOAD 1
@@ -32,10 +32,10 @@ Modification:
#include "pagetable.h"
bool module_phymem_init();
char* kalloc(uint32_t size);
char* kalloc(size_t size);
bool kfree(char* vaddr);
char* raw_alloc(uint32_t size);
char* raw_alloc(size_t size);
bool raw_free(char* paddr);
void show_phymem_info();
@@ -39,8 +39,8 @@ Modification:
#include "mmu_common.h"
// clang-format off
#define ALIGNUP(sz, al) (((uint32_t)(sz) + (uint32_t)(al) - 1) & ~((uint32_t)(al) - 1))
#define ALIGNDOWN(sz, al) ((uint32_t)(sz) & ~((uint32_t)(al) - 1))
#define ALIGNUP(sz, al) (((uintptr_t)(sz) + (uintptr_t)(al) - 1) & ~((uintptr_t)(al) - 1))
#define ALIGNDOWN(sz, al) ((uintptr_t)(sz) & ~((uintptr_t)(al) - 1))
#define LEVEL4_PTE_IDX(v) (((uintptr_t)(v) >> LEVEL4_PTE_SHIFT) & (NUM_LEVEL4_PTE - 1))
#define LEVEL4_PTE_ADDR(v) ALIGNDOWN(v, LEVEL4_PTE_SIZE)