Skip to content

Instantly share code, notes, and snippets.

@cwshu
Last active August 18, 2022 14:21
Show Gist options
  • Save cwshu/122a2b40abe1372c7cc44ef177694635 to your computer and use it in GitHub Desktop.
Save cwshu/122a2b40abe1372c7cc44ef177694635 to your computer and use it in GitHub Desktop.
QEMU breakpoint at start_kernel
# For RISC-V Linux v5.18
# Add Linux symbol (before MMU setup)
add-symbol-file vmlinux -o -0xfffffffeffe00000
# OpenSBI symbol
add-symbol-file fw_jump.elf
# Linux kernel 1st line
br *0x80200000
c
# Tricky routine to set breakpoint just after MMU setup ($pc at 0xffffffff80001160)
# refer to: https://elixir.bootlin.com/linux/v5.18/source/arch/riscv/kernel/head.S#L73
# 1) goto relocate_enable_mmu()
br relocate_enable_mmu
c
# 2) si to instr 'csrw satp,a0'
si 22
# 3) goto return address of relocate_enable_mmu()
# (remove breakpoint / symbol file before MMU setup)
br *$ra
del 1
remove-symbol-file -a 0x0000000080200000
c
# 4) Add Linux symbol (after MMU setup)
add-symbol-file vmlinux
# Normal use: (e.g. start_kernel)
br start_kernel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment