65 lines
1.5 KiB
C
65 lines
1.5 KiB
C
/**
|
|
* memory/memory.c
|
|
*
|
|
* The memory management subsystem.
|
|
*
|
|
* (c) 2026 Simon Brooke <simon@journeyman.cc>
|
|
* Licensed under GPL version 2.0, or, at your option, any later version.
|
|
*/
|
|
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
|
|
#include "debug.h"
|
|
|
|
#include "memory/memory.h"
|
|
#include "memory/node.h"
|
|
#include "memory/pointer.h"
|
|
#include "memory/pso.h"
|
|
#include "memory/pso2.h"
|
|
#include "memory/tags.h"
|
|
|
|
#include "payloads/exception.h"
|
|
|
|
#include "ops/bind.h"
|
|
#include "ops/string_ops.h"
|
|
|
|
/**
|
|
* @brief Freelists for each size class.
|
|
*/
|
|
struct pso_pointer freelists[MAX_SIZE_CLASS];
|
|
|
|
/**
|
|
* @brief Flag to prevent re-initialisation.
|
|
*/
|
|
bool memory_initialised = false;
|
|
|
|
|
|
/**
|
|
* @brief Initialise the memory allocation system.
|
|
*
|
|
* Essentially, just set up the freelists; allocating pages will then happen
|
|
* automatically as objects are requested.
|
|
*
|
|
* @param node the index number of the node we are initialising.
|
|
* @return int
|
|
*/
|
|
struct pso_pointer initialise_memory( uint32_t node ) {
|
|
struct pso_pointer result = nil;
|
|
if ( memory_initialised ) {
|
|
result =
|
|
make_exception( c_string_to_lisp_string
|
|
( L"Attenpt to reinitialise memory." ), nil,
|
|
nil );
|
|
} else {
|
|
for ( uint8_t i = 0; i <= MAX_SIZE_CLASS; i++ ) {
|
|
freelists[i] = nil;
|
|
}
|
|
#ifdef DEBUG
|
|
debug_print(L"Memory initialised", DEBUG_BOOTSTRAP, 0);
|
|
#endif
|
|
memory_initialised = true;
|
|
}
|
|
|
|
return t;
|
|
}
|