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

bootloader: improve exec function #1333

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NickeZ
Copy link
Collaborator

@NickeZ NickeZ commented Dec 2, 2024

Add some comments about what every assembly line does. Mark which c-variables are used and which registers are used so that GCC doesn't do the wrong optimizations.

I think we are a bit naive when we read r0, expecting the value of l_code_addr to be there. According to the ARM calling convention, the first argument should be there. But since we don't even have "noinline", this whole function could be inlined. And the compiler is free to move around ASM blocks (with some constraints) as noted in the quote below.

References:

Re "Basic ASM" (that we use today)

Safely accessing C data and calling functions from basic asm is more complex than it may appear. To access C data, it is better to use extended asm.

Do not expect a sequence of asm statements to remain perfectly consecutive after compilation. If certain instructions need to remain consecutive in the output, put them in a single multi-instruction asm statement. Note that GCC’s optimizers can move asm statements relative to other code, including across jumps.
[...]
GCC does not parse basic asm’s AssemblerInstructions, which means there is no way to communicate to the compiler what is happening inside them. GCC has no visibility of symbols in the asm and may discard them as unreferenced. It also does not know about side effects of the assembler code, such as modifications to memory or registers. Unlike some compilers, GCC assumes that no changes to general purpose registers occur. This assumption may change in a future release.

Considerations

  • Perhaps the "noinline" is not necessary.
  • todo: We should probably also add "memory" to the clobber list.

@NickeZ NickeZ requested a review from benma December 2, 2024 13:14
Add some comments about what every assembly line does. Mark which
c-variables are used and which registers are used so that GCC doesn't
do the wrong optimizations.
@NickeZ NickeZ force-pushed the nickez/bootloader-binexec-refactor branch from 587845c to 03e4f71 Compare December 2, 2024 13:18
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

Successfully merging this pull request may close these issues.

1 participant