Throw a memory access exception in PowerPC

I have great source code that runs on PowerPC. I need to transfer it to ARM. But ARM throws an h / w exception for unaligned memory access. So, I want to find all possible instances in which an exception may occur without memory access. I considered the following options.

  • Use -Wcast-align in gcc, which would give warnings for uneven access.
  • Make PowerPC throw an unmanaged exception. For ARM, there is the / proc / cpu / alignment option, with which the user can decide how to handle the exception. But for PowerPC there is no such option.

My questions:

  • Is there a way to get PowerPC to throw an exception without memory access?
  • Is there a better way to find out all occurrences of irrational memory access in the source code?
+5
source share
2 answers
  • It depends on your POWERPC processor. High-performance server processors such as POWER8 will almost never throw alignment exceptions. However, there is often a HID SPR bit to eliminate alignment exceptions more often. In any case, under Linux, the kernel will process them, and the user will not see it, except for loss of performance. You can set prctl (PR_UNALIGN_SIGBUS), and this will force the kernel to generate SIGBUS, rather than processing them.

  • On linux with primary events, you can use alignment-error events. for example, "validation test to authenticate -element". Also, if you enable CONFIG_PPC_EMULATED_STATS, you will get a debugfs entry called "emulated_instructions" that has an entry for non-aligned calls.

+2
source
  • Yes and no. Hardware PowerPC has 32-bit unrelated hardware access that cannot be easily overridden. But if you use bare metal, and not under the OS, you can still force it to throw an exception by matching the memory area as I / O space. This approach is complex, although you may probably be better off analyzing the code manually.

    For 64-bit accesses, most PowerPCs already throw exceptions with constant access, if this applies to your hardware, you can trap it. Again, this should happen in the kernel, so if you are working under the OS, you cannot easily do this (the kernel will handle uneven access to the software without telling you about it).

  • Not really, it can only be really determined at runtime, especially if you do a lot of pointer arithmetic.

+2
source

Source: https://habr.com/ru/post/1202330/


All Articles