This fixes a hard to debug hang that could occur in any stage, but in the end it follows simple rules and is easy to fix.
In long mode the 32bit displacement addressing used on 'mov' and 'lea' instructions is sign-extended. Those instructions can be found using readelf on the stage and searching for relocation type R_X86_64_32S.
The sign extension is no issue when either running in protected mode or the code module and thus the address is below 2GiB. If the address is greater than 2GiB, as usually the case for code in TSEG, the higher address bits [64:32] are all set to 1 and the effective address is pointing to memory not paged. Accessing this memory will cause a page fault, which isn't handled either.
To prevent such problems- disable R_AMD64_32S relocations in rmodtool- add comment explaining why it's not allowed- use the pseudo op movabs, which doesn't use 32bit displacement addressing- Print a useful error message if such a reloc is present in the code
Fixes a crash in TSEG and when in long mode seen on Intel Sandybridge.
d023909b01 treewide: Disable R_AMD64_32S relocation support
src/arch/x86/c_start.S | 13 +++++++++----
src/arch/x86/exit_car.S | 19 ++++++++++++++++---
src/arch/x86/gdt_init.S | 12 ------------
src/cpu/x86/lapic/secondary.S | 6 ++++--
src/cpu/x86/sipi_vector.S | 2 +-
src/cpu/x86/smm/smm_stub.S | 2 +-
util/cbfstool/rmodule.c | 15 ++++++++++++---
7 files changed, 43 insertions(+), 26 deletions(-)