Backtraces in UEFI

25 views
Skip to first unread message

Warkentin, Andrei

unread,
Apr 25, 2023, 4:44:04 PM4/25/23
to fw-ex...@riscv.org
Hi folks,

I've been playing around with getting useful backtraces in UEFI. Things seem to work, although I see compiler behavior that isn't spec compliant (leaf functions populate a frame differently, saving s0 in the ra slot). I wanted to try out Clang but I don't see this as being a supported Tiano config for RISC-V at the moment?

Feedback welcome...

https://github.com/andreiw/edk2-rv-wip/commits/backtrace

This follows the Arm backtrace code from a presentation standpoint, e.g.:

FS0:\> mm fffffffffffffff
!!!! RISCV64 Exception Type - 0000000000000005(EXCEPT_RISCV_LOAD_ACCESS_FAULT) !!!!
t0 = 0x00000000000001000 t1 = 0x00000000083FFF210
t2 = 0x00000000000001000 t3 = 0x0FFFFFFFF837DCA9E
t4 = 0x0000000000000E874 t5 = 0x00000000000004D82
t6 = 0x00000000000000000 s0 = 0x00000000083FFF5C0
s1 = 0x00000000000000013 s2 = 0x00000000022000000
s3 = 0x000000000BFE00000 s4 = 0x00000000000000000
s5 = 0x00000000000000000 s6 = 0x08000000A00006800
s7 = 0x0000000000000007F s8 = 0x00000000080019038
s9 = 0x0000000008003D6A8 s10 = 0x00000000000000000
s11 = 0x00000000000000000 a0 = 0x00000000083FFF6B0
a1 = 0x00FFFFFFFFFFFFFFF a2 = 0x00000000000000001
a3 = 0x00000000083FFF6B1 a4 = 0x00FFFFFFFFFFFFFFF
a5 = 0x00000000083FFF6B0 a6 = 0x00000000083FFF6B0
a7 = 0x00000000000000000 zero = 0x00000000000000000
ra = 0x000000000BE19AD3A sp = 0x0AF0000008328002E
gp = 0x00000000000000000 tp = 0x00000000080049000
sepc = 0x000000000BE19B246 sstatus = 0x08000000200006120
stval = 0x00FFFFFFFFFFFFFFF
PC 0x0000BE19B246 (0x0000BE185000+0x00016246) [ 0] Shell.dll
PC 0x0000BE19AD3A (0x0000BE185000+0x00015D3A) [ 0] Shell.dll
PC 0x0000BE19AD3A (0x0000BE185000+0x00015D3A) [ 0] Shell.dll
PC 0x0000BE1E81D4 (0x0000BE185000+0x000631D4) [ 0] Shell.dll
PC 0x0000BE1E93E6 (0x0000BE185000+0x000643E6) [ 0] Shell.dll
PC 0x0000BE1B1842 (0x0000BE185000+0x0002C842) [ 0] Shell.dll
PC 0x0000BE18A3F2 (0x0000BE185000+0x000053F2) [ 0] Shell.dll
PC 0x0000BE18A560 (0x0000BE185000+0x00005560) [ 0] Shell.dll
PC 0x0000BE18A820 (0x0000BE185000+0x00005820) [ 0] Shell.dll
PC 0x0000BE18AB5E (0x0000BE185000+0x00005B5E) [ 0] Shell.dll
PC 0x0000BE18AC54 (0x0000BE185000+0x00005C54) [ 0] Shell.dll
PC 0x0000BE188A30 (0x0000BE185000+0x00003A30) [ 0] Shell.dll
PC 0x0000BE187438 (0x0000BE185000+0x00002438) [ 0] Shell.dll
PC 0x0000BE18610A (0x0000BE185000+0x0000110A) [ 0] Shell.dll
PC 0x0000BE185298 (0x0000BE185000+0x00000298) [ 0] Shell.dll
PC 0x00008325F914 (0x00008325A000+0x00005914) [ 1] DxeCore.dll
PC 0x0000BFCF59C2 (0x0000BFCE6000+0x0000F9C2) [ 2] BdsDxe.dll
PC 0x0000BFCE7104 (0x0000BFCE6000+0x00001104) [ 2] BdsDxe.dll
PC 0x0000BFCE8484 (0x0000BFCE6000+0x00002484) [ 2] BdsDxe.dll
PC 0x00008325B5D8 (0x00008325A000+0x000015D8) [ 3] DxeCore.dll
PC 0x00008325A6A2 (0x00008325A000+0x000006A2) [ 3] DxeCore.dll
PC 0x00008325A266 (0x00008325A000+0x00000266) [ 3] DxeCore.dll
PC 0x000022008004
PC 0x0000220081C2
PC 0x00002200245A

[ 0] /home/andreiw/src/edk2/Build/RiscVVirtQemu/DEBUG_GCC5/RISCV64/ShellPkg/Application/Shell/Shell/DEBUG/Shell.dll
[ 1] /home/andreiw/src/edk2/Build/RiscVVirtQemu/DEBUG_GCC5/RISCV64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll
[ 2] /home/andreiw/src/edk2/Build/RiscVVirtQemu/DEBUG_GCC5/RISCV64/MdeModulePkg/Universal/BdsDxe/BdsDxe/DEBUG/BdsDxe.dll
[ 3] /home/andreiw/src/edk2/Build/RiscVVirtQemu/DEBUG_GCC5/RISCV64/MdeModulePkg/Core/Dxe/DxeMain/DEBUG/DxeCore.dll


A

Tuan Phan

unread,
Apr 25, 2023, 6:08:31 PM4/25/23
to Warkentin, Andrei, fw-ex...@riscv.org
Hi Andrei,
I had the same observation when adding exception handler for Riscv like you did. Although it seems to work with gcc but there is no specs specifying how the frame buffer and ra should be used in riscv. 

Our compiler team seems doesn’t care as they want us to use dwarf for backtrace purpose but not sure if any effort to support it in edk2 for gcc. Clang may already supports it but not sure.

I guess we can solve this issue based on compiler case by case.

--
You received this message because you are subscribed to the Google Groups "RISC-V Firmware Exchange" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fw-exchange...@riscv.org.
To view this discussion on the web visit https://groups.google.com/a/riscv.org/d/msgid/fw-exchange/PH8PR11MB685604513636AF0DD4857CAB83649%40PH8PR11MB6856.namprd11.prod.outlook.com.

Warkentin, Andrei

unread,
May 1, 2023, 12:07:39 PM5/1/23
to Tuan Phan, fw-ex...@riscv.org

I would suggest a compiler option to guarantee stack frame compliance. It’s not a reasonable suggestion to bloat UEFI binaries with CFI data and a parser.

 

A

Reply all
Reply to author
Forward
0 new messages