mirror of
https://git.stationery.faith/corn/corn.git
synced 2024-11-24 11:52:18 +00:00
follow the corn style guide
This commit is contained in:
parent
ef384ad9a7
commit
b5b904cfc9
21 changed files with 166 additions and 203 deletions
|
@ -110,7 +110,7 @@ long long int atoll(const char* s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a integer to asci inside a string with a given radix (base).
|
* Converts a integer to asci inside a string with a given radix (base).
|
||||||
* @param n - the number to conver
|
* @param n - the number to convert
|
||||||
* @param buffer - the string buffer
|
* @param buffer - the string buffer
|
||||||
* @param radix - the base to convert
|
* @param radix - the base to convert
|
||||||
*/
|
*/
|
||||||
|
@ -118,7 +118,7 @@ char *itoa(int n, char *buffer, int radix);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a long to asci inside a string with a given radix (base).
|
* Converts a long to asci inside a string with a given radix (base).
|
||||||
* @param n - the number to conver
|
* @param n - the number to convert
|
||||||
* @param buffer - the string buffer
|
* @param buffer - the string buffer
|
||||||
* @param radix - the base to convert
|
* @param radix - the base to convert
|
||||||
*/
|
*/
|
||||||
|
@ -134,7 +134,7 @@ char *lltoa(long long int n, char *buffer, int radix);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a unsigned integer to asci inside a string with a given radix (base).
|
* Converts a unsigned integer to asci inside a string with a given radix (base).
|
||||||
* @param n - the number to conver
|
* @param n - the number to convert
|
||||||
* @param buffer - the string buffer
|
* @param buffer - the string buffer
|
||||||
* @param radix - the base to convert
|
* @param radix - the base to convert
|
||||||
*/
|
*/
|
||||||
|
@ -142,7 +142,7 @@ char *utoa(unsigned int n, char *buffer, int radix);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a unsigned long to asci inside a string with a given radix (base).
|
* Converts a unsigned long to asci inside a string with a given radix (base).
|
||||||
* @param n - the number to conver
|
* @param n - the number to convert
|
||||||
* @param buffer - the string buffer
|
* @param buffer - the string buffer
|
||||||
* @param radix - the base to convert
|
* @param radix - the base to convert
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,46 +7,46 @@
|
||||||
/**
|
/**
|
||||||
* Initalize system memory allocator
|
* Initalize system memory allocator
|
||||||
*/
|
*/
|
||||||
extern void memory_init(struct memory_map *map);
|
void memory_init(struct memory_map *map);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disabled cpu interupts to not interfere with
|
* Disabled cpu interupts to not interfere with
|
||||||
* current memory allocations.
|
* current memory allocations.
|
||||||
*/
|
*/
|
||||||
extern void memory_lock(void);
|
void memory_lock(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reenabled cpu interupts
|
* Reenabled cpu interupts
|
||||||
*/
|
*/
|
||||||
extern void memory_unlock(void);
|
void memory_unlock(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns how much memory the system has
|
* @returns how much memory the system has
|
||||||
*/
|
*/
|
||||||
extern uint64_t memory_total(void);
|
uint64_t memory_total(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns how much memory is free
|
* @returns how much memory is free
|
||||||
*/
|
*/
|
||||||
extern uint64_t memory_free(void);
|
uint64_t memory_free(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns how much memory is used
|
* @returns how much memory is used
|
||||||
*/
|
*/
|
||||||
extern uint64_t memory_used(void);
|
uint64_t memory_used(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates a single page in memory.
|
* Allocates a single page in memory.
|
||||||
* @returns the page if allocated or NULL on failure
|
* @returns the page if allocated or NULL on failure
|
||||||
*/
|
*/
|
||||||
extern void *alloc_page(void);
|
void *alloc_page(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocats count pages in memory
|
* Allocats count pages in memory
|
||||||
* @param count - the number of continious pages to allocate
|
* @param count - the number of continious pages to allocate
|
||||||
* @returns the pages if allocated or NULL on failure
|
* @returns the pages if allocated or NULL on failure
|
||||||
*/
|
*/
|
||||||
extern void *alloc_pages(int count);
|
void *alloc_pages(int count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees a signle page in memory.
|
* Frees a signle page in memory.
|
||||||
|
@ -54,7 +54,7 @@ extern void *alloc_pages(int count);
|
||||||
* Freeing in the middle of a block is allowed.
|
* Freeing in the middle of a block is allowed.
|
||||||
* @param page - the pointer to the page
|
* @param page - the pointer to the page
|
||||||
*/
|
*/
|
||||||
extern void free_page(void *page);
|
void free_page(void *page);
|
||||||
// TODO: implement free_page
|
// TODO: implement free_page
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +64,7 @@ extern void free_page(void *page);
|
||||||
* free_pages will from *page to end of block allocated.
|
* free_pages will from *page to end of block allocated.
|
||||||
* @param page - the pointer to the page
|
* @param page - the pointer to the page
|
||||||
*/
|
*/
|
||||||
extern void free_pages(void *page);
|
void free_pages(void *page);
|
||||||
// TODO: implement freeing in middle of block
|
// TODO: implement freeing in middle of block
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,21 +76,21 @@ extern void free_pages(void *page);
|
||||||
* @param writable - if this memory should be writable
|
* @param writable - if this memory should be writable
|
||||||
* @param user - if this memory should be user writable
|
* @param user - if this memory should be user writable
|
||||||
*/
|
*/
|
||||||
extern void *mmap(void *addr, size_t len);
|
void *mmap(void *addr, size_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unmaps mapped address from the mmap function
|
* Unmaps mapped address from the mmap function
|
||||||
* @param addr - the address returned from mmap
|
* @param addr - the address returned from mmap
|
||||||
* @param len - the length allocated
|
* @param len - the length allocated
|
||||||
*/
|
*/
|
||||||
extern void unmap(void *addr);
|
void unmap(void *addr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates size_t bytes in memory
|
* Allocates size_t bytes in memory
|
||||||
* @param size - the amount of bytes to allocate
|
* @param size - the amount of bytes to allocate
|
||||||
* @retruns the address allocated or NULL on failure
|
* @retruns the address allocated or NULL on failure
|
||||||
*/
|
*/
|
||||||
extern void *kalloc(size_t size);
|
void *kalloc(size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reallocates a given allocated ptr to a new size of bytes in memory.
|
* Reallocates a given allocated ptr to a new size of bytes in memory.
|
||||||
|
@ -99,10 +99,10 @@ extern void *kalloc(size_t size);
|
||||||
* @param size - the amount of bytes to set the pointer to
|
* @param size - the amount of bytes to set the pointer to
|
||||||
* @returns the address allocated or NULL on failure
|
* @returns the address allocated or NULL on failure
|
||||||
*/
|
*/
|
||||||
extern void *krealloc(void *ptr, size_t size);
|
void *krealloc(void *ptr, size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees a allocated pointer in memory
|
* Frees a allocated pointer in memory
|
||||||
* @param ptr - the pointer to free
|
* @param ptr - the pointer to free
|
||||||
*/
|
*/
|
||||||
extern void kfree(void *ptr);
|
void kfree(void *ptr);
|
||||||
|
|
|
@ -8,23 +8,23 @@
|
||||||
* Allocates a single physical page in memory
|
* Allocates a single physical page in memory
|
||||||
* @preturns the physical address of the page
|
* @preturns the physical address of the page
|
||||||
*/
|
*/
|
||||||
extern void *alloc_phys_page(void);
|
void *alloc_phys_page(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates count physical pages in memory
|
* Allocates count physical pages in memory
|
||||||
* @returns the physical address of the first page
|
* @returns the physical address of the first page
|
||||||
*/
|
*/
|
||||||
extern void *alloc_phys_pages(int count);
|
void *alloc_phys_pages(int count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees a single physical page in memory
|
* Frees a single physical page in memory
|
||||||
* @param ptr - the physical address of the page
|
* @param ptr - the physical address of the page
|
||||||
*/
|
*/
|
||||||
extern void free_phys_page(void *ptr);
|
void free_phys_page(void *ptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees count physical pages in memory
|
* Frees count physical pages in memory
|
||||||
* @param ptr - the physical address of the first page
|
* @param ptr - the physical address of the first page
|
||||||
* @param count - the number of pages in the list
|
* @param count - the number of pages in the list
|
||||||
*/
|
*/
|
||||||
extern void free_phys_pages(void *ptr, int count);
|
void free_phys_pages(void *ptr, int count);
|
||||||
|
|
|
@ -13,81 +13,73 @@
|
||||||
#define MBOOT_OLD_RSDP 14
|
#define MBOOT_OLD_RSDP 14
|
||||||
#define MBOOT_NEW_RSDP 15
|
#define MBOOT_NEW_RSDP 15
|
||||||
|
|
||||||
extern char symtab;
|
|
||||||
#define kaddr(addr) ((uintptr_t)(&addr))
|
|
||||||
|
|
||||||
typedef uint8_t mboot_uint8_t;
|
|
||||||
typedef uint16_t mboot_uint16_t;
|
|
||||||
typedef uint32_t mboot_uint32_t;
|
|
||||||
typedef uint64_t mboot_uint64_t;
|
|
||||||
|
|
||||||
struct mboot_info {
|
struct mboot_info {
|
||||||
mboot_uint32_t total_size;
|
uint32_t total_size;
|
||||||
mboot_uint32_t reserved;
|
uint32_t reserved;
|
||||||
char tags[];
|
char tags[];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mboot_tag {
|
struct mboot_tag {
|
||||||
mboot_uint32_t type;
|
uint32_t type;
|
||||||
mboot_uint32_t size;
|
uint32_t size;
|
||||||
char data[];
|
char data[];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mboot_tag_elf_sections {
|
struct mboot_tag_elf_sections {
|
||||||
mboot_uint32_t type;
|
uint32_t type;
|
||||||
mboot_uint32_t size;
|
uint32_t size;
|
||||||
mboot_uint16_t num;
|
uint16_t num;
|
||||||
mboot_uint16_t entsize;
|
uint16_t entsize;
|
||||||
mboot_uint16_t shndx;
|
uint16_t shndx;
|
||||||
mboot_uint16_t reserved;
|
uint16_t reserved;
|
||||||
char sections[];
|
char sections[];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mboot_tag_elf_sections_entry {
|
struct mboot_tag_elf_sections_entry {
|
||||||
mboot_uint32_t sh_name;
|
uint32_t sh_name;
|
||||||
mboot_uint32_t sh_type;
|
uint32_t sh_type;
|
||||||
mboot_uint64_t sh_flags;
|
uint64_t sh_flags;
|
||||||
mboot_uint64_t sh_addr;
|
uint64_t sh_addr;
|
||||||
mboot_uint64_t sh_offset;
|
uint64_t sh_offset;
|
||||||
mboot_uint64_t sh_size;
|
uint64_t sh_size;
|
||||||
mboot_uint32_t sh_link;
|
uint32_t sh_link;
|
||||||
mboot_uint32_t sh_info;
|
uint32_t sh_info;
|
||||||
mboot_uint64_t sh_addralign;
|
uint64_t sh_addralign;
|
||||||
mboot_uint64_t sh_entsize;
|
uint64_t sh_entsize;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mboot_mmap_entry {
|
struct mboot_mmap_entry {
|
||||||
mboot_uint64_t addr;
|
uint64_t addr;
|
||||||
mboot_uint64_t len;
|
uint64_t len;
|
||||||
mboot_uint32_t type;
|
uint32_t type;
|
||||||
mboot_uint32_t zero;
|
uint32_t zero;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mboot_tag_mmap {
|
struct mboot_tag_mmap {
|
||||||
mboot_uint32_t type;
|
uint32_t type;
|
||||||
mboot_uint32_t size;
|
uint32_t size;
|
||||||
mboot_uint32_t entry_size;
|
uint32_t entry_size;
|
||||||
mboot_uint32_t entry_version;
|
uint32_t entry_version;
|
||||||
struct mboot_mmap_entry entries[];
|
struct mboot_mmap_entry entries[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct mboot_tag_old_rsdp {
|
struct mboot_tag_old_rsdp {
|
||||||
mboot_uint32_t type;
|
uint32_t type;
|
||||||
mboot_uint32_t size;
|
uint32_t size;
|
||||||
mboot_uint8_t rsdp[];
|
uint8_t rsdp[];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mboot_tag_new_rsdp {
|
struct mboot_tag_new_rsdp {
|
||||||
mboot_uint32_t type;
|
uint32_t type;
|
||||||
mboot_uint32_t size;
|
uint32_t size;
|
||||||
mboot_uint8_t rsdp[];
|
uint8_t rsdp[];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mboot_tag_cmdline {
|
struct mboot_tag_cmdline {
|
||||||
mboot_uint32_t type;
|
uint32_t type;
|
||||||
mboot_uint32_t size;
|
uint32_t size;
|
||||||
mboot_uint8_t cmdline[];
|
uint8_t cmdline[];
|
||||||
};
|
};
|
||||||
|
|
||||||
static void read_symbols(
|
static void read_symbols(
|
||||||
|
@ -100,7 +92,7 @@ static void read_symbols(
|
||||||
// struct mboot_elf_section_header *section =
|
// struct mboot_elf_section_header *section =
|
||||||
// (struct mboot_elf_section_header *) (layout->elf_section_headers);
|
// (struct mboot_elf_section_header *) (layout->elf_section_headers);
|
||||||
//
|
//
|
||||||
// for (mboot_uint32_t i = 0; i < layout->num; i++) {
|
// for (uint32_t i = 0; i < layout->num; i++) {
|
||||||
// char buf[20];
|
// char buf[20];
|
||||||
//
|
//
|
||||||
// ultoa(i, buf, 10);
|
// ultoa(i, buf, 10);
|
||||||
|
@ -134,7 +126,7 @@ static void read_cmdline(
|
||||||
struct boot_info *shim_info,
|
struct boot_info *shim_info,
|
||||||
struct mboot_tag_cmdline *cmdline
|
struct mboot_tag_cmdline *cmdline
|
||||||
) {
|
) {
|
||||||
mboot_uint32_t size = cmdline->size - 8;
|
uint32_t size = cmdline->size - 8;
|
||||||
if (size >= CMDLINE_MAX)
|
if (size >= CMDLINE_MAX)
|
||||||
size = CMDLINE_MAX; // truncate :(
|
size = CMDLINE_MAX; // truncate :(
|
||||||
memcpy(shim_info->cmdline, cmdline->cmdline, size);
|
memcpy(shim_info->cmdline, cmdline->cmdline, size);
|
||||||
|
|
|
@ -68,25 +68,18 @@ static struct pdpte *pdpt_mapped = (void *) (uintptr_t) 0x201000;
|
||||||
static struct pde *pd_mapped = (void *) (uintptr_t) 0x202000;
|
static struct pde *pd_mapped = (void *) (uintptr_t) 0x202000;
|
||||||
static struct pte *pt_mapped = (void *) (uintptr_t) 0x203000;
|
static struct pte *pt_mapped = (void *) (uintptr_t) 0x203000;
|
||||||
|
|
||||||
static inline void
|
static inline void invlpg(void *addr) {
|
||||||
invlpg(void *addr)
|
|
||||||
{
|
|
||||||
__asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
|
__asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void load_addr(void *phys_addr) {
|
||||||
load_addr(void *phys_addr)
|
|
||||||
{
|
|
||||||
static struct pte *pt = &paging_pt[4];
|
static struct pte *pt = &paging_pt[4];
|
||||||
pt->address = (uint64_t)phys_addr >> 12;
|
pt->address = (uint64_t)phys_addr >> 12;
|
||||||
pt->flags = F_PRESENT | F_WRITEABLE;
|
pt->flags = F_PRESENT | F_WRITEABLE;
|
||||||
invlpg(addr_mapped);
|
invlpg(addr_mapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void load_pml4(void *phys) {
|
||||||
load_pml4(
|
|
||||||
void *phys
|
|
||||||
) {
|
|
||||||
static struct pte *pt = &paging_pt[0];
|
static struct pte *pt = &paging_pt[0];
|
||||||
if ((uint64_t)phys >> 12 == pt->address)
|
if ((uint64_t)phys >> 12 == pt->address)
|
||||||
return;
|
return;
|
||||||
|
@ -95,10 +88,7 @@ load_pml4(
|
||||||
invlpg(pml4_mapped);
|
invlpg(pml4_mapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void load_pdpt(void *phys) {
|
||||||
load_pdpt(
|
|
||||||
void *phys
|
|
||||||
) {
|
|
||||||
static struct pte *pt = &paging_pt[1];
|
static struct pte *pt = &paging_pt[1];
|
||||||
if ((uint64_t)phys >> 12 == pt->address)
|
if ((uint64_t)phys >> 12 == pt->address)
|
||||||
return;
|
return;
|
||||||
|
@ -107,10 +97,7 @@ load_pdpt(
|
||||||
invlpg(pdpt_mapped);
|
invlpg(pdpt_mapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void load_pd(void *phys) {
|
||||||
load_pd(
|
|
||||||
void *phys
|
|
||||||
) {
|
|
||||||
static struct pte *pt = &paging_pt[2];
|
static struct pte *pt = &paging_pt[2];
|
||||||
if ((uint64_t)phys >> 12 == pt->address)
|
if ((uint64_t)phys >> 12 == pt->address)
|
||||||
return;
|
return;
|
||||||
|
@ -119,10 +106,7 @@ load_pd(
|
||||||
invlpg(pdpt_mapped);
|
invlpg(pdpt_mapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void load_pt(void *phys) {
|
||||||
load_pt(
|
|
||||||
void *phys
|
|
||||||
) {
|
|
||||||
static struct pte *pt = &paging_pt[3];
|
static struct pte *pt = &paging_pt[3];
|
||||||
if ((uint64_t)phys >> 12 == pt->address)
|
if ((uint64_t)phys >> 12 == pt->address)
|
||||||
return;
|
return;
|
||||||
|
@ -135,8 +119,7 @@ load_pt(
|
||||||
#define PAG_CANNOT_ALLOC 1
|
#define PAG_CANNOT_ALLOC 1
|
||||||
#define PAG_NOT_PRESENT 2
|
#define PAG_NOT_PRESENT 2
|
||||||
|
|
||||||
static int
|
static int select_pdpt(
|
||||||
select_pdpt(
|
|
||||||
void *virt,
|
void *virt,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
struct pml4e *root,
|
struct pml4e *root,
|
||||||
|
@ -165,8 +148,7 @@ select_pdpt(
|
||||||
return PAG_SUCCESS;
|
return PAG_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int select_pd(
|
||||||
select_pd(
|
|
||||||
void *virt,
|
void *virt,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
struct pdpte *pdpt,
|
struct pdpte *pdpt,
|
||||||
|
@ -195,8 +177,7 @@ select_pd(
|
||||||
return PAG_SUCCESS;
|
return PAG_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int select_pt(
|
||||||
select_pt(
|
|
||||||
void *virt,
|
void *virt,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
struct pde *pd,
|
struct pde *pd,
|
||||||
|
@ -225,8 +206,7 @@ select_pt(
|
||||||
return PAG_SUCCESS;
|
return PAG_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void select_page(
|
||||||
select_page(
|
|
||||||
void *virt,
|
void *virt,
|
||||||
struct pte *pt,
|
struct pte *pt,
|
||||||
struct pte **res
|
struct pte **res
|
||||||
|
@ -238,8 +218,7 @@ select_page(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void try_unmap_pml4(void) {
|
||||||
try_unmap_pml4(void) {
|
|
||||||
for (int i = 0; i < 512; i++) {
|
for (int i = 0; i < 512; i++) {
|
||||||
if (pml4_mapped[i].flags & F_PRESENT)
|
if (pml4_mapped[i].flags & F_PRESENT)
|
||||||
return;
|
return;
|
||||||
|
@ -252,8 +231,7 @@ try_unmap_pml4(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void try_unmap_pdpt(void) {
|
||||||
try_unmap_pdpt(void) {
|
|
||||||
for (int i = 0; i < 512; i++) {
|
for (int i = 0; i < 512; i++) {
|
||||||
if (pdpt_mapped[i].flags & F_PRESENT)
|
if (pdpt_mapped[i].flags & F_PRESENT)
|
||||||
return;
|
return;
|
||||||
|
@ -267,8 +245,7 @@ try_unmap_pdpt(void) {
|
||||||
try_unmap_pml4();
|
try_unmap_pml4();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void try_unmap_pd(void) {
|
||||||
try_unmap_pd(void) {
|
|
||||||
for (int i = 0; i < 512; i++) {
|
for (int i = 0; i < 512; i++) {
|
||||||
if (pd_mapped[i].flags & F_PRESENT)
|
if (pd_mapped[i].flags & F_PRESENT)
|
||||||
return;
|
return;
|
||||||
|
@ -282,8 +259,7 @@ try_unmap_pd(void) {
|
||||||
try_unmap_pdpt();
|
try_unmap_pdpt();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void try_unmap_pt(void) {
|
||||||
try_unmap_pt(void) {
|
|
||||||
for (int i = 0; i < 512; i++) {
|
for (int i = 0; i < 512; i++) {
|
||||||
if (pt_mapped[i].flags & F_PRESENT)
|
if (pt_mapped[i].flags & F_PRESENT)
|
||||||
return;
|
return;
|
||||||
|
@ -297,12 +273,10 @@ try_unmap_pt(void) {
|
||||||
try_unmap_pd();
|
try_unmap_pd();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void unmap_page(
|
||||||
unmap_page(
|
|
||||||
struct pml4e *root,
|
struct pml4e *root,
|
||||||
void *virt
|
void *virt
|
||||||
) {
|
) {
|
||||||
|
|
||||||
struct pdpte *pdpt;
|
struct pdpte *pdpt;
|
||||||
struct pde *pd;
|
struct pde *pd;
|
||||||
struct pte *pt;
|
struct pte *pt;
|
||||||
|
@ -331,13 +305,11 @@ unmap_page(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void unmap_pages(
|
||||||
unmap_pages(
|
|
||||||
struct pml4e *root,
|
struct pml4e *root,
|
||||||
void *virt_start,
|
void *virt_start,
|
||||||
long page_count
|
long page_count
|
||||||
) {
|
) {
|
||||||
|
|
||||||
uint64_t pml4_o = -1,
|
uint64_t pml4_o = -1,
|
||||||
pdpt_o = -1,
|
pdpt_o = -1,
|
||||||
pd_o = -1;
|
pd_o = -1;
|
||||||
|
@ -397,14 +369,12 @@ unmap_pages(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int map_page(
|
||||||
map_page(
|
|
||||||
struct pml4e *root,
|
struct pml4e *root,
|
||||||
void *virt,
|
void *virt,
|
||||||
void *phys,
|
void *phys,
|
||||||
unsigned int flags
|
unsigned int flags
|
||||||
) {
|
) {
|
||||||
|
|
||||||
struct pdpte *pdpt;
|
struct pdpte *pdpt;
|
||||||
struct pde *pd;
|
struct pde *pd;
|
||||||
struct pte *pt;
|
struct pte *pt;
|
||||||
|
@ -430,15 +400,13 @@ map_page(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int map_pages(
|
||||||
map_pages(
|
|
||||||
struct pml4e *root,
|
struct pml4e *root,
|
||||||
void *virt_start,
|
void *virt_start,
|
||||||
void *phys_start,
|
void *phys_start,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
long page_count
|
long page_count
|
||||||
) {
|
) {
|
||||||
|
|
||||||
uint64_t pml4_o = -1,
|
uint64_t pml4_o = -1,
|
||||||
pdpt_o = -1,
|
pdpt_o = -1,
|
||||||
pd_o = -1;
|
pd_o = -1;
|
||||||
|
@ -502,7 +470,6 @@ failed:
|
||||||
}
|
}
|
||||||
|
|
||||||
void paging_init(void) {
|
void paging_init(void) {
|
||||||
|
|
||||||
kernel_pml4[0].flags = F_PRESENT | F_WRITEABLE;
|
kernel_pml4[0].flags = F_PRESENT | F_WRITEABLE;
|
||||||
kernel_pml4[0].address = (uint64_t)(&kernel_pdpt_0) >> 12;
|
kernel_pml4[0].address = (uint64_t)(&kernel_pdpt_0) >> 12;
|
||||||
|
|
||||||
|
|
14
src/lib.c
14
src/lib.c
|
@ -45,13 +45,15 @@ int strncmp(const char *restrict lhs, const char *restrict rhs, unsigned long n)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strcpy(char *restrict dest, const char *restrict src) {
|
char *strcpy(char *restrict dest, const char *restrict src) {
|
||||||
for(; (*dest = *src); dest++, src++);
|
char *d = dest;
|
||||||
|
for (; (*d = *src); d++, src++);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strncpy(char *restrict dest, const char *restrict src, unsigned long n) {
|
char *strncpy(char *restrict dest, const char *restrict src, unsigned long n) {
|
||||||
for(; (*dest = *src) && n; dest++, src++, n--);
|
char *d = dest;
|
||||||
memset(dest, 0, n);
|
for (; (*d = *src) && n; d++, src++, n--);
|
||||||
|
memset(d, 0, n);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,13 +218,14 @@ end:
|
||||||
for (; n; n /= radix) { \
|
for (; n; n /= radix) { \
|
||||||
*buffer++ = itoc(n % radix); \
|
*buffer++ = itoc(n % radix); \
|
||||||
} \
|
} \
|
||||||
|
char *buf_end = buffer; \
|
||||||
*buffer-- = '\0'; \
|
*buffer-- = '\0'; \
|
||||||
while (buffer > start) { \
|
while (buffer > start) { \
|
||||||
char tmp = *start; \
|
char tmp = *start; \
|
||||||
*start++ = *buffer; \
|
*start++ = *buffer; \
|
||||||
*buffer-- = tmp; \
|
*buffer-- = tmp; \
|
||||||
} \
|
} \
|
||||||
return buffer; \
|
return buf_end; \
|
||||||
}
|
}
|
||||||
|
|
||||||
UXTOA(int, utoa)
|
UXTOA(int, utoa)
|
||||||
|
@ -244,13 +247,14 @@ UXTOA(long long int, ulltoa)
|
||||||
for (; n; n /= radix) { \
|
for (; n; n /= radix) { \
|
||||||
*buffer++ = itoc(n % radix); \
|
*buffer++ = itoc(n % radix); \
|
||||||
} \
|
} \
|
||||||
|
char *buf_end = buffer; \
|
||||||
*buffer-- = '\0'; \
|
*buffer-- = '\0'; \
|
||||||
while (buffer > start) { \
|
while (buffer > start) { \
|
||||||
char tmp = *start; \
|
char tmp = *start; \
|
||||||
*start++ = *buffer; \
|
*start++ = *buffer; \
|
||||||
*buffer-- = tmp; \
|
*buffer-- = tmp; \
|
||||||
} \
|
} \
|
||||||
return buffer; \
|
return buf_end; \
|
||||||
}
|
}
|
||||||
|
|
||||||
XTOA(int, itoa)
|
XTOA(int, itoa)
|
||||||
|
|
Loading…
Reference in a new issue