Lameguy64 / PSn00bSDK

The most powerful open source SDK for the PS1 (as far as open source PS1 SDKs go). Not recommended for beginner use.
Other
838 stars 68 forks source link

_mem_init grabs an extra 64KB of memory #47

Closed matt456 closed 2 years ago

matt456 commented 2 years ago

in start.c:

int ram_used = (0x10000 + exe_size + stack_max_size) & 0xfffffffc;

seems to grab an extra 64KB even though stack_max_size is passed as 0x20000?

Is this deliberate? or just an unwanted knock-on from refactoring? Thanks!

spicyjpeg commented 2 years ago

It is deliberate indeed, albeit not mentioned in the comment (my fault). The first 64 KB of memory at 0x80000000-0x8000ffff are reserved for use by the PS1 kernel and may not be used by executables, so they are subtracted from the total amount of RAM passed to _mem_init(). This does not affect the actual memory location of the heap since it is always placed after the executable, which is in turn always loaded at an address grater than or equal to 0x80010000.

By the way, the reason _mem_init() is currently private/undocumented is because in order to change RAM size (e.g. to use the full 8 MB on a devkit) you also need to set the stack pointer from within _start(), which you can't do in C. To allow custom assembly code to be injected into the entry point, a future release of the SDK will probably add a customizable trampoline that calls _start() as the entry point.

matt456 commented 2 years ago

Thank you for the clarification it makes total sense.

I don't need the default 128kb stack allocation so I'll just call _mem_init again on startup with a smaller value.