mambo icon indicating copy to clipboard operation
mambo copied to clipboard

status flags currupted by inline hash lookup code

Open amimo opened this issue 5 years ago • 4 comments

It seems like the inline hash lookup code may currupt the status flags.

cmp x0,x1
b label
...
label:
b.eq xx  ;; may be problematic if inline hash lookup is in use?

amimo avatar Jan 11 '20 13:01 amimo

Hi @amimo, the inline hash lookup does not change the status flag. Even when the target is not found, the status of the CPU is stored and later restored when producing a context switch.

GuillermoCallaghan avatar Jan 16 '20 10:01 GuillermoCallaghan

the cmp instruction used by arm32 may change those flags, and i can't found where those flags are saved, except the dispatcher.

  // CMP r6, target
  arm_cmp(&write_p, REG_PROC, r6, target);
  write_p++;

amimo avatar Jan 16 '20 10:01 amimo

Yes the Aarch32 lookup will corrupt the status flags. I haven't found instances of software setting the status flags before taking an indirect branch and then reading them after. This implementation is a bit faster than using CB(N)Z, especially as it would require changing the mode from A32 to T32.

If you find examples of software doing this, we can convert it to the CBZ implementation (which is still much faster than writing to the CPSR).

lgeek avatar Jan 16 '20 11:01 lgeek

Hi @amimo, my bad, because you used X registers in your code example I thought you were talking about the AArch64 implementation of the inline hash lookup.

GuillermoCallaghan avatar Jan 16 '20 14:01 GuillermoCallaghan