Skip to content

2. Memory

Mokha Lee edited this page Jun 6, 2024 · 7 revisions

ROM space

ROM space distribution is configured in config-memmap.h

Address Size Usage
0x0B2A604 0xD5DFC Kernel
0x0EFB2E0 0xE4D20 Data
0x1000000 --- reserved for DEMO

For kernel, we mainly use free-space starting from 0xB2A604.

In order to co-work on FEBuilderGBA and make DEMO based on kernel, we need also put some inportant data at the fixed location:

a). Magic pattern

A serial of characters is set at the head of kernel free-space (0xB2A604), which can make it as an identifier for FEBuilder patch.

b). Pointer list

There is a pointer list after magic pattern, start at 0xB2A614 with size = 0x400. Both wizardry c-hacks and FEBuilder Patches may find the data via such list, so that you can expand the data via FEB.

c). Text table

TextTable is repointed at a fixed location behind the pointer list, 0xB2AA14 (the very beginning of main space) with size = 0x2000 * sizeof(uintptr_t) free space allocated. If you want to make DEMO based on kernel, it is recommanded to directly use the kernel allocated text table rather than re-repoint it by such operations:

#include "fe8-kernel-beta.ref.event" // auto generated by kernel
#define TextTable NewTextTable
#include "Tools/Tool Helpers.txt"    // EventAssembler helper

Font space

Free space at 0x0EFB2E0 is used to insert UTF8 characters for multi-languge support. You can config whether to install them through CONFIG_USE_UTF8_GLYPH.

RAM space

RAM space distribution is configured in config-memmap.s

Address Size Usage
0x02026E30 0x2028 Kernel
0x0203F000 0x1000 reserved for DEMO

Since all source codes are all compiled at once, CHAX can offer a better Free-RAM-Space control method. Free-RAM-Space, unused memory from vanilla is collected by wizardries and now can be refered by StanH's DOC. Here we mainly use space start at 0x02026E30 with size 0x2028, which is the debug print buffer in vanilla (and unused).

In kernel, free-ram space is alloced from the bottom to the top:

0x02026E30, FreeRamSpaceTop

<--- gKernelUsedFreeRamSpaceTop
<------------
<!used kernel space>
0x02028E58, FreeRamSpaceBottom

Developed should ensure that the free-ram space not overflowed, which means asseration (gKernelUsedFreeRamSpaceTop > FreeRamSpaceTop) should be valid. We have also add a detection for RAM space overflow, CHAX may auto detect on overflow error on game-init.

Example

Here is an example to alloc ram spaces in kernel:

Suppose you want a 4 Byte RAM space (u8 NewAlloc4Bytes[4])

  1. Get intoconfig-memmap.s
  2. Insert new allocation
_kernel_malloc NewAlloc4Bytes, 4

Warning

Make sure that the allocated space should be 32bits alligned

  1. Declare such variable in your own C file, extern u8 NewAlloc4Bytes[4];
Clone this wiki locally