Commit a575ad5f authored by Eddie Kohler's avatar Eddie Kohler

Add prototypes and stubs for kalloc functions.

parent 76f45c4c
......@@ -27,3 +27,31 @@ x86_64_page* kallocpage() {
page_lock.unlock(irqs);
return p;
}
// init_kalloc
// Initialize stuff needed by `kalloc`. Called from `init_hardware`,
// after `physical_ranges` is initialized.
void init_kalloc() {
// do nothing for now
}
// kalloc(sz)
// Allocate and return a pointer to at least `sz` contiguous bytes
// of memory. Returns `nullptr` if `sz == 0` or on failure.
void* kalloc(size_t sz) {
assert(0 && "kalloc not implemented yet");
}
// kfree(ptr)
// Free a pointer previously returned by `kalloc`, `kallocpage`, or
// `kalloc_pagetable`. Does nothing if `ptr == nullptr`.
void kfree(void* ptr) {
assert(0 && "kfree not implemented yet");
}
// test_kalloc
// Run unit tests on the kalloc system.
void test_kalloc() {
// do nothing for now
}
......@@ -7,7 +7,7 @@
// Grody functions for interacting with x86 hardware.
// hardware_init
// init_hardware
// Initialize hardware. Calls other functions bellow.
static void init_early_memory();
......@@ -16,7 +16,7 @@ static void init_constructors();
static void init_physical_ranges();
static void init_other_processors();
void hardware_init() {
void init_hardware() {
// initialize early-stage virtual memory structures
init_early_memory();
......@@ -33,6 +33,9 @@ void hardware_init() {
// kernel and reserved physical memory
init_physical_ranges();
// initialize kernel allocator
init_kalloc();
// initialize this CPU
ncpu = 1;
cpus[0].init();
......
......@@ -17,7 +17,7 @@ static void process_setup(pid_t pid, const char* program_name);
// string is an optional string passed from the boot loader.
void kernel_start(const char* command) {
hardware_init();
init_hardware();
console_clear();
// Set up process descriptors
......
......@@ -241,16 +241,34 @@ inline T read_unaligned_pa(uint64_t pa) {
}
// hardware_init
// Initialize x86 hardware, including memory, interrupts, and segments.
// All accessible physical memory is initially mapped as readable
// and writable to both kernel and application code.
void hardware_init();
// kallocpage
// Allocate and return a page. Returns `nullptr` on failure.
// Returns a high canonical address.
x86_64_page* kallocpage();
// kalloc(sz)
// Allocate and return a pointer to at least `sz` contiguous bytes
// of memory. Returns `nullptr` if `sz == 0` or on failure.
void* kalloc(size_t sz);
// kfree(ptr)
// Free a pointer previously returned by `kalloc`, `kallocpage`, or
// `kalloc_pagetable`. Does nothing if `ptr == nullptr`.
void kfree(void* ptr);
// init_kalloc
// Initialize stuff needed by `kalloc`. Called from `init_hardware`,
// after `physical_ranges` is initialized.
void init_kalloc();
// test_kalloc
// Run unit tests on the kalloc system.
void test_kalloc();
// timer_init(rate)
// Set the timer interrupt to fire `rate` times a second. Disables the
// timer interrupt if `rate <= 0`.
void timer_init(int rate);
// init_hardware
// Initialize hardware and CPUs.
void init_hardware();
// kernel page table (used for virtual memory)
......@@ -262,6 +280,7 @@ x86_64_pagetable* kalloc_pagetable();
// change current page table
void set_pagetable(x86_64_pagetable* pagetable);
// turn off the virtual machine
void poweroff() __attribute__((noreturn));
......@@ -314,9 +333,6 @@ int check_keyboard();
// `vm_map`.
int program_load(proc* p, int programnumber);
x86_64_page* kallocpage();
void kfree(x86_64_page*);
// log_printf, log_vprintf
// Print debugging messages to the host's `log.txt` file. We run QEMU
// so that messages written to the QEMU "parallel port" end up in `log.txt`.
......
......@@ -34,10 +34,10 @@
#define PTE_PAMASK 0x0007FFFFFFFFF000UL // physical address in non-PS entry
#define PTE_PS_PAMASK 0x0007FFFFFFFFE000UL // physical address in PS entry
#define VA_LOWMIN 0UL // min canonical low address
#define VA_LOWMAX 0x00007FFFFFFFFFFFUL // max canonical low address
#define VA_HIGHMIN 0xFFFF800000000000UL // min canonical high address
#define VA_HIGHMAX 0xFFFFFFFFFFFFFFFFUL // max canonical high address
#define VA_LOWMIN 0UL // min low canonical address
#define VA_LOWMAX 0x00007FFFFFFFFFFFUL // max low canonical address
#define VA_HIGHMIN 0xFFFF800000000000UL // min high canonical address
#define VA_HIGHMAX 0xFFFFFFFFFFFFFFFFUL // max high canonical address
#define VA_NONCANONMAX 0x0000FFFFFFFFFFFFUL // max non-canonical address
// Parts of a paged address: page index, page offset
......
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 to comment