Files
jak-project/game/kernel/common/kmalloc.h
T
water111 4f537d4a71 [jak3] Set up ckernel (#3308)
This sets up the C Kernel for Jak 3, and makes it possible to build and
load code built with `goalc --jak3`.

There's not too much interesting here, other than they switched to a
system where symbol IDs (unique numbers less than 2^14) are generated at
compile time, and those get included in the object file itself.

This is kind of annoying, since it means all tools that produce a GOAL
object file need to work together to assign unique symbol IDs. And since
the symbol IDs can't conflict, and are only a number between 0 and 2^14,
you can't just hash and hope for no collisions.

We work around this by ignoring the IDs and re-assigning our own. I
think this is very similar to what the C Kernel did on early builds of
Jak 3 which supported loading old format level files, which didn't have
the IDs included.

As far as I can tell, this shouldn't cause any problems. It defeats all
of their fancy tricks to save memory by not storing the symbol string,
but we don't care.
2024-01-16 19:24:02 -05:00

36 lines
1.1 KiB
C++

#pragma once
#include "common/common_types.h"
#include "game/kernel/common/Ptr.h"
/*!
* A kheap has a top/bottom linear allocator
*/
struct kheapinfo {
Ptr<u8> base; //! beginning of heap
Ptr<u8> top; //! current location of bottom of top allocations
Ptr<u8> current; //! current location of top of bottom allocations
Ptr<u8> top_base; //! end of heap
};
// Kernel heaps
extern Ptr<kheapinfo> kglobalheap;
extern Ptr<kheapinfo> kdebugheap;
extern bool kheaplogging;
// flags for kmalloc/ksmalloc
constexpr u32 KMALLOC_TOP = 0x2000; //! Flag to allocate temporary memory from heap top
constexpr u32 KMALLOC_MEMSET = 0x1000; //! Flag to clear memory
constexpr u32 KMALLOC_ALIGN_256 = 0x100;
constexpr u32 KMALLOC_ALIGN_64 = 0x40;
constexpr u32 KMALLOC_ALIGN_16 = 0x10;
void kmalloc_init_globals_common();
Ptr<u8> ksmalloc(Ptr<kheapinfo> heap, s32 size, u32 flags, char const* name);
Ptr<kheapinfo> kheapstatus(Ptr<kheapinfo> heap);
Ptr<kheapinfo> kinitheap(Ptr<kheapinfo> heap, Ptr<u8> mem, s32 size);
u32 kheapused(Ptr<kheapinfo> heap);
Ptr<u8> kmalloc(Ptr<kheapinfo> heap, s32 size, u32 flags, char const* name);
void kfree(Ptr<u8> a);