Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR solves the current issue we are suffering with
ps2link
which is not able to load config fromIPCONFIG.DAT
.The reason why config file couldn't be loaded, it is because it fails when using
open
IPCONFIG.DAT
file, as it fails when runningmalloc
.After deeper investigation, I figured out that
heap
wasn't set-up properly.When using the default linkfile we have:
Then during
crt0.c
we are calling to kernel theSetupThread
andSetupHeap
functions, which set the stack and heap respectively.PS2BIOS
when_stack == -1
, it sets thestack
to the end of the memory region (minus stack size + small GAP).Similar stuff happens when
_heap_size == -1
, it sets the heap from_end
to_stack
.At the end we have a picture similar to:
However,
ps2link
is not a common app, it needs to be executed in a custom memory region, we need to make sure that program + stack + heap everything fits within a concrete memory region.With the current
linkfile
used inps2link
we were making one issue:We were using the whole available space for stack (this is right if you know that your program will never use the heap).
The fix that I have applied here is to set a fixed
stack_size
and also calculate manuallystack
pointer. This will force the stack to be in a concrete region, and then let the remaining available memory region to be used asheap
.In order to find how to fix it I have been taking a look at the implementation of the kernel calls from this repo:
https://github.com/AKuHAK/fps2bios/blob/master/kernel/eeload/eekernel.c#L2859-L2914
Also have in mind that
highloading
version won't work properly with ELF using default linkfile, as the ELF's stack memory region will clash withps2link highload
version.Cheers