Commit 9006ccf6 by triazo

Add a symbol pointing to the end of used kernel memory

parent 6c1ebf19
Showing with 35 additions and 5 deletions
...@@ -43,4 +43,8 @@ SECTIONS ...@@ -43,4 +43,8 @@ SECTIONS
/* The compiler may produce other sections, by default it will put them in /* The compiler may produce other sections, by default it will put them in
a segment with the same name. Simply add stuff here as needed. */ a segment with the same name. Simply add stuff here as needed. */
.end BLOCK(4K) : ALIGN(4K)
{
_kernel_end = . ;
}
} }
...@@ -46,9 +46,6 @@ void populate_page_table(page_table_entry* table, void* start, int num, int offs ...@@ -46,9 +46,6 @@ void populate_page_table(page_table_entry* table, void* start, int num, int offs
} }
} }
// TODO: put this as a label at the end of the code, so we can take
// its address
#define KERN_END 0x204000
page_directory_entry* mem_init_kern_tables(multiboot_memory_map* mmap, multiboot_memory_map* mmap_end) page_directory_entry* mem_init_kern_tables(multiboot_memory_map* mmap, multiboot_memory_map* mmap_end)
{ {
...@@ -56,8 +53,8 @@ page_directory_entry* mem_init_kern_tables(multiboot_memory_map* mmap, multiboot ...@@ -56,8 +53,8 @@ page_directory_entry* mem_init_kern_tables(multiboot_memory_map* mmap, multiboot
// Make a page directory structure easily // Make a page directory structure easily
page_directory_entry* kern_page_dir = initiate_directory(); page_directory_entry* kern_page_dir = initiate_directory();
// This line will change with the above TODO // _kern_end is defined in the linker script
page_table_entry* next_table = (page_table_entry*) KERN_END; page_table_entry* next_table = (page_table_entry*) &_kernel_end;
int current_dir_entry = 0; int current_dir_entry = 0;
......
...@@ -27,6 +27,9 @@ typedef uint32_t page_table_entry; ...@@ -27,6 +27,9 @@ typedef uint32_t page_table_entry;
extern void loadPageDirectory(page_directory_entry*); extern void loadPageDirectory(page_directory_entry*);
extern void enablePaging(); extern void enablePaging();
// Defined in linker.ld
extern char _kernel_end[];
// Defined in the file mem.c // Defined in the file mem.c
page_directory_entry* initiate_directory(); page_directory_entry* initiate_directory();
page_directory_entry* mem_init_kern_tables(multiboot_memory_map* mmap, multiboot_memory_map* mmap_end); page_directory_entry* mem_init_kern_tables(multiboot_memory_map* mmap, multiboot_memory_map* mmap_end);
...@@ -38,4 +41,30 @@ void* memory_mark; ...@@ -38,4 +41,30 @@ void* memory_mark;
void* malloc(uint32_t bytes); void* malloc(uint32_t bytes);
// Required for elf loading - virtual memory and stuff
#endif #endif
// TODO:
/*
Two stage memory thing.
Ensure kernel is paged.
Ensure that a space equal to <remaining_memory> / (4096 * 8) is paged. This is for the following struct
Create binary array specifying which pages are used (abstract ownership a bit maybe to pid, or just use bit array)
Place in allocated space
Write allocor for pages. This should be the only way to get ownership of pages.
- takes a page directory and a new address as an argument.
- Sholud be called by the other malloc function, or by construction of page tables
- flips a bit in a binary array
- Also write corresponding free, flip bit and remove entry in page dir/table
Write more versatile malloc/free
- Use struct{void* next, size_t size} before every hunk. Walk list to find total size, use this to determine if more pages are needed. Or something
Problems - how to determine when new pages are needed
- how to load in elf stuff at arbitrary locations
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment