Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing programmatic access to program length #236

Open
TheHans255 opened this issue Nov 5, 2023 · 1 comment
Open

Providing programmatic access to program length #236

TheHans255 opened this issue Nov 5, 2023 · 1 comment

Comments

@TheHans255
Copy link

In my platform linker files, how can I get access to the length of the program, or a program section, in order to write it into the final binary?

I'm continuing work on my Apple //e port, and one thing I'll need to do to get HIRES graphics working with ProDOS programs is write a short ASM boot routine that copies the program to a different location in memory, since ProDOS loads programs on top of the HIRES memory pages by default. Hence, I'll need to write the length of the program somewhere in the binary so that this routine knows exactly what range to copy.

It's also possible that I'll need to write a new, platform-specific version of malloc that provides better access to underlying memory pages (since ProDOS requires that its 1024-byte OS buffers for opening files are page-aligned) and makes better use of the available memory space both before and after the program (in particular, the 6K of memory between the text buffer and the HIRES pages). Hence, I'll need access to the program length there as well so that malloc can properly mark the program area as off-limits.

Note that netiher of these are urgent - I have ways of working around the problems a new malloc would solve, and I can write the ASM routine to simply copy the maximum possible range, including empty parts of RAM.

@asiekierka
Copy link
Contributor

Usually, you do this by defining some symbols:

    __program_start = .;
    /* ... program sections ...*/
    __program_end = .;
    __program_length = __program_end - __program_start;

Then, in code:

extern char __program_start, __program_end, __program_length;
/* ... */
printf("program: %04X - %04X (%d bytes)\n", (uint16_t) &__program_end, (uint16_t) &__program_start, (uint16_t) &__program_length);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants