Rewrote physical memory allocator
The physical memory allocator now uses a buddy allocator instead of a stack. Also moved some of the platform-independent context code to kernel.c.
This commit is contained in:
@@ -35,8 +35,9 @@ struct boot_info_t
|
||||
{
|
||||
char *bootloader;
|
||||
char *parameters;
|
||||
size_t module_count;
|
||||
size_t memory_size;
|
||||
struct memory_map_t map;
|
||||
size_t module_count;
|
||||
struct module_t modules[module_limit];
|
||||
};
|
||||
|
||||
@@ -94,9 +95,9 @@ unsigned long kernel_current_pid();
|
||||
|
||||
struct process_context_t *kernel_current_context();
|
||||
|
||||
enum error_t kernel_store_active_context(struct process_context_t *context, size_t size);
|
||||
enum error_t kernel_store_active_context(struct process_context_t *context);
|
||||
|
||||
enum error_t kernel_spawn_process(void *program_entry, int priority, physaddr_t address_space);
|
||||
unsigned long kernel_spawn_process(void *program_entry, int priority, physaddr_t address_space);
|
||||
|
||||
struct process_context_t *kernel_advance_scheduler();
|
||||
|
||||
@@ -108,11 +109,11 @@ enum error_t kernel_remove_port(unsigned long id);
|
||||
|
||||
unsigned long kernel_get_port_owner(unsigned long id);
|
||||
|
||||
enum error_t kernel_send_message(int recipient, struct message_t *message);
|
||||
enum error_t kernel_send_message(unsigned long recipient, struct message_t *message);
|
||||
|
||||
enum error_t kernel_queue_sender(int recipient);
|
||||
enum error_t kernel_queue_sender(unsigned long recipient);
|
||||
|
||||
enum error_t kernel_queue_message(int recipient, struct message_t *message);
|
||||
enum error_t kernel_queue_message(unsigned long recipient, struct message_t *message);
|
||||
|
||||
int receive_message(struct message_t *buffer, int flags);
|
||||
|
||||
|
||||
@@ -8,10 +8,24 @@
|
||||
extern const size_t page_size;
|
||||
|
||||
/**
|
||||
* @brief Pop the topmost address from the stack and returns that value.
|
||||
* @brief
|
||||
*
|
||||
* If the stack is empty, this function will instead return a status code. This
|
||||
* can be identified by testing the least signifigant bits of the return value.
|
||||
* @param size
|
||||
* @return physaddr_t
|
||||
*/
|
||||
physaddr_t reserve_region(size_t size);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param location
|
||||
* @param size
|
||||
* @return int
|
||||
*/
|
||||
int free_region(physaddr_t location, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Reserves a single page and returns its physical address.
|
||||
*
|
||||
* @param stack
|
||||
* @return physaddr_t
|
||||
@@ -19,9 +33,7 @@ extern const size_t page_size;
|
||||
physaddr_t reserve_page();
|
||||
|
||||
/**
|
||||
* @brief Pushes `location` onto the stack.
|
||||
*
|
||||
* If there is no room on the stack, the stack will be unaffected.
|
||||
* @brief Marks the page at the given location as free.
|
||||
*
|
||||
* @param stack
|
||||
* @param location
|
||||
@@ -41,22 +53,25 @@ size_t free_page_count();
|
||||
*
|
||||
* @return void*
|
||||
*/
|
||||
void *page_stack_bottom();
|
||||
void *page_map_base();
|
||||
|
||||
/**
|
||||
* @brief Get the location of the top of the page stack.
|
||||
*
|
||||
* @return void*
|
||||
*/
|
||||
void *page_stack_top();
|
||||
void *page_map_end();
|
||||
|
||||
/**
|
||||
* @brief Push all available pages in `map` onto the stack
|
||||
* @brief Constructs the bitmaps used by the physical memory allocator.
|
||||
*
|
||||
* @param stack
|
||||
* @param map
|
||||
* @param base
|
||||
* @param memory_size
|
||||
* @param block_size
|
||||
* @return enum error_t
|
||||
*/
|
||||
int initialize_page_stack(struct memory_map_t *map, physaddr_t *stack_base);
|
||||
enum error_t initialize_page_map(struct memory_map_t *map, void *base, size_t memory_size, unsigned long block_size);
|
||||
|
||||
/**
|
||||
* @brief Create a new top-level page table and map the kernel in it.
|
||||
|
||||
@@ -1,19 +1,35 @@
|
||||
#pragma once
|
||||
#ifndef _QUARK_CONTEXT_H
|
||||
#define _QUARK_CONTEXT_H
|
||||
|
||||
struct process_context_t;
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined __i386__ || defined __x86_64__
|
||||
#define DEFAULT_FLAGS 0x3200
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Allocates a new process context and initializes it with the given
|
||||
* program counter.
|
||||
* @brief Stores the context of a particular process. The contents of this
|
||||
* struct are platform-specific.
|
||||
*
|
||||
* @param task_entry
|
||||
* @return void*
|
||||
*/
|
||||
void *initialize_context(void *pc);
|
||||
struct process_context_t
|
||||
{
|
||||
|
||||
void destroy_context(void *ctx);
|
||||
#if defined __i386__
|
||||
uint32_t gp_registers[8];
|
||||
uint32_t ss;
|
||||
uint32_t cs;
|
||||
uint32_t eip;
|
||||
uint32_t flags;
|
||||
#elif defined __x86_64__
|
||||
uint64_t gp_registers[16];
|
||||
uint64_t ss;
|
||||
uint64_t cs;
|
||||
uint64_t rip;
|
||||
uint64_t flags;
|
||||
#endif
|
||||
|
||||
void save_context(struct process_context_t *context);
|
||||
};
|
||||
|
||||
void load_context(struct process_context_t *context);
|
||||
|
||||
@@ -24,3 +40,5 @@ void set_context_stack(struct process_context_t *context, void *stack);
|
||||
void set_context_flags(struct process_context_t *context, unsigned long flags);
|
||||
|
||||
void set_context_return(struct process_context_t *context, unsigned long value);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define PCB_LOCATION 0x800
|
||||
|
||||
struct process_context_t
|
||||
{
|
||||
uint32_t eax;
|
||||
uint32_t ebx;
|
||||
uint32_t ecx;
|
||||
uint32_t edx;
|
||||
uint32_t edi;
|
||||
uint32_t esi;
|
||||
uint32_t ebp;
|
||||
uint32_t ss;
|
||||
uint32_t esp;
|
||||
uint32_t cs;
|
||||
uint32_t eip;
|
||||
uint32_t flags;
|
||||
};
|
||||
Reference in New Issue
Block a user