Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions arch/arm/cortex_m/link.x
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ SECTIONS
__bss_end = .;
} > RAM AT > RAM

.coredump_bss (NOLOAD) : ALIGN(4096)
{
__coredump_buf_start = .;
*(.coredump_bss .coredump_bss.*)
. = ALIGN(4096);
__coredump_buf_end = .;
} > RAM

.heap (COPY) :
{
. = ALIGN(8);
Expand Down
4 changes: 4 additions & 0 deletions arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

menu "RISCV Configuration"

config 32BIT
bool "32-bit RISC-V"
default n

config NUM_IRQS
int

Expand Down
1 change: 1 addition & 0 deletions kconfig/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ _kconfig_files = [
"//kernel/arch/Kconfig",
"//kernel/kernel/src/boards/${board}/Kconfig",
"//kernel/kernel/src/Kconfig",
"//kernel/kernel/src/coredump/Kconfig",
"//kernel/kernel/src/allocator/Kconfig",
"//kernel/kernel/src/scheduler/Kconfig",
"//kernel/kernel/src/vfs/Kconfig",
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/gd32e507_eval/debug/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CONFIG_ROUND_ROBIN=y
CONFIG_ROBIN_SLICE=10
CONFIG_OVERFLOW_CHECK=y
CONFIG_STACK_HIGHWATER_CHECK=y
CONFIG_ENABLE_COREDUMP=y
#CONFIG_DEBUGGING_SCHEDULER=y
CONFIG_MAIN_THREAD_STACK_SIZE=12288
CONFIG_IDLE_THREAD_STACK_SIZE=2048
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/gd32e507_eval/release/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ CONFIG_TIMER_THREAD_STACK_SIZE=2048
# CONFIG_FDT is not set
# CONFIG_VIRTIO is not set
CONFIG_PROCFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_ENABLE_NET=n

#
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/gd32vw553_eval/coverage/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
CONFIG_NETWORK_STACK_SIZE=24576
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/gd32vw553_eval/debug/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=n
CONFIG_NETWORK_STACK_SIZE=24576
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/gd32vw553_eval/release/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=n
CONFIG_NETWORK_STACK_SIZE=24576
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/qemu_mps2_an385/coverage/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
CONFIG_NETWORK_STACK_SIZE=24576
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/qemu_mps2_an385/debug/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ CONFIG_ENABLE_SYSCALL=y
# CONFIG_VIRTIO is not set
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_COREDUMP=y
CONFIG_ENABLE_VFS=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/qemu_mps2_an385/release/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
CONFIG_NETWORK_STACK_SIZE=24576
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/qemu_mps3_an547/coverage/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ CONFIG_ENABLE_SYSCALL=y
# CONFIG_VIRTIO is not set
CONFIG_SERIAL_RX_FIFO_SIZE=256
CONFIG_SERIAL_TX_FIFO_SIZE=256
CONFIG_ENABLE_COREDUMP=y
# CONFIG_ENABLE_VFS is not set
# CONFIG_ENABLE_NET is not set

Expand Down
1 change: 1 addition & 0 deletions kconfig/config/qemu_mps3_an547/debug/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CONFIG_ROUND_ROBIN=y
CONFIG_ROBIN_SLICE=10
CONFIG_OVERFLOW_CHECK=y
CONFIG_STACK_HIGHWATER_CHECK=y
CONFIG_ENABLE_COREDUMP=y
# CONFIG_DEBUGGING_SCHEDULER is not set
CONFIG_MAIN_THREAD_STACK_SIZE=12288
CONFIG_IDLE_THREAD_STACK_SIZE=2048
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/qemu_mps3_an547/release/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ CONFIG_ENABLE_SYSCALL=y
# CONFIG_VIRTIO is not set
CONFIG_SERIAL_RX_FIFO_SIZE=256
CONFIG_SERIAL_TX_FIFO_SIZE=256
CONFIG_ENABLE_COREDUMP=y
# CONFIG_ENABLE_VFS is not set
# CONFIG_ENABLE_NET is not set

Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/qemu_riscv32/coverage/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
CONFIG_NETWORK_STACK_SIZE=24576
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/qemu_riscv32/debug/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ CONFIG_ENABLE_SYSCALL=y
# CONFIG_VIRTIO is not set
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_ENABLE_VFS=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/qemu_riscv32/release/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
CONFIG_NETWORK_STACK_SIZE=24576
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/qemu_riscv64/coverage/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
CONFIG_NETWORK_STACK_SIZE=24576
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/qemu_riscv64/debug/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ CONFIG_ENABLE_SYSCALL=y
# CONFIG_VIRTIO is not set
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_ENABLE_VFS=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/qemu_riscv64/release/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
CONFIG_NETWORK_STACK_SIZE=24576
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/qemu_virt64_aarch64/coverage/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ CONFIG_VIRTIO=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
CONFIG_NETWORK_STACK_SIZE=32768
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/qemu_virt64_aarch64/debug/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ CONFIG_FDT=y
CONFIG_VIRTIO=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_ENABLE_VFS=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/qemu_virt64_aarch64/release/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ CONFIG_VIRTIO=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
CONFIG_NETWORK_STACK_SIZE=32768
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/raspberry_pico2_cortexm/debug/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CONFIG_ROUND_ROBIN=y
CONFIG_ROBIN_SLICE=10
CONFIG_OVERFLOW_CHECK=y
CONFIG_STACK_HIGHWATER_CHECK=y
CONFIG_ENABLE_COREDUMP=y
#CONFIG_DEBUGGING_SCHEDULER=y
CONFIG_MAIN_THREAD_STACK_SIZE=12288
CONFIG_IDLE_THREAD_STACK_SIZE=2048
Expand Down
1 change: 1 addition & 0 deletions kconfig/config/raspberry_pico2_cortexm/release/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CONFIG_STACK_HIGHWATER_CHECK=y
CONFIG_MAIN_THREAD_STACK_SIZE=12288
CONFIG_IDLE_THREAD_STACK_SIZE=2048
CONFIG_TIMER_THREAD_STACK_SIZE=2048
CONFIG_ENABLE_COREDUMP=y
# CONFIG_FDT is not set
# CONFIG_VIRTIO is not set
CONFIG_PROCFS=y
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/rk3568/coverage/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ CONFIG_VIRTIO=y
CONFIG_SERIAL_RX_FIFO_SIZE=512
CONFIG_SERIAL_TX_FIFO_SIZE=512
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_PROCFS=y
CONFIG_ENABLE_NET=y
CONFIG_NETWORK_STACK_SIZE=32768
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/rk3568/debug/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=256
CONFIG_SERIAL_TX_FIFO_SIZE=256
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_PROCFS=y
# CONFIG_ENABLE_NET is not set

Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/rk3568/release/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ CONFIG_ENABLE_SYSCALL=y
CONFIG_SERIAL_RX_FIFO_SIZE=256
CONFIG_SERIAL_TX_FIFO_SIZE=256
CONFIG_ENABLE_VFS=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_PROCFS=y
# CONFIG_ENABLE_NET is not set

Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/seeed_xiao_esp32c3/debug/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CONFIG_ROUND_ROBIN=n
CONFIG_ROBIN_SLICE=10
CONFIG_OVERFLOW_CHECK=y
CONFIG_STACK_HIGHWATER_CHECK=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
CONFIG_MAIN_THREAD_STACK_SIZE=12288
CONFIG_IDLE_THREAD_STACK_SIZE=2048
CONFIG_TIMER_THREAD_STACK_SIZE=2048
Expand Down
2 changes: 2 additions & 0 deletions kconfig/config/seeed_xiao_esp32c3/release/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ CONFIG_THREAD_PRIORITY_MAX=32
CONFIG_MAIN_THREAD_PRIORITY=32

CONFIG_ENABLE_SYSCALL=y
CONFIG_ENABLE_COREDUMP=y
CONFIG_COREDUMP_MEM_BACKEND=y
# CONFIG_FDT is not set
# CONFIG_VIRTIO is not set
CONFIG_SERIAL_RX_FIFO_SIZE=256
Expand Down
64 changes: 64 additions & 0 deletions kernel/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ _kernel_default_cfgs = [
group("check_kernel") {
testonly = true
deps = [
":run_coredump_test",
":run_integration_test",
":run_unittest",
]
Expand Down Expand Up @@ -221,6 +222,69 @@ run_qemu_check("run_integration_test") {
}
}

build_rust("kernel_coredump_test") {
testonly = true
crate_type = "bin"
sources = [ "tests/coredump_test.rs" ]
edition = "2021"
deps = [
":blueos",
"//external/vendor/semihosting-0.1.20:semihosting",
"//kernel/rsrt",
"//libc",
] + board_deps
if (coverage || profile) {
deps += [ "//external/vendor/minicov-0.3.7:minicov" ]
}
cfgs = _kernel_default_cfgs
linker_script = default_linker_script
if (defined(chip)) {
rustflags += [
"--cfg",
"target_chip=\"${chip}\"",
]
}
}

if (defined(qemu_use_esp32_loader) && qemu_use_esp32_loader) {
gen_esp32_qemu_runner("coredump_test_runner") {
testonly = true
elf = ":kernel_coredump_test"
chip = "${chip}"
bootloader = qemu_esp32_bootloader_bin
partition_table = qemu_esp32_partition_table_bin
qemu = qemu_exe
machine = qemu_machine
qemu_args = qemu_extra_args
net_args = qemu_net_args
block_args = qemu_block_args
semihosting = true
}
} else {
gen_qemu_runner("coredump_test_runner") {
testonly = true
semihosting = true
img = ":kernel_coredump_test"
qemu = qemu_exe
machine = qemu_machine
qemu_args = qemu_extra_args
net_args = qemu_net_args
block_img = "coredump_test_block.img"
block_args = qemu_block_args
}
}

run_qemu_check("run_coredump_test") {
testonly = true
runner = ":coredump_test_runner"
if (coverage) {
img = ":kernel_coredump_test"
checker = "src/coverage.checker"
} else {
checker = "tests/coredump.checker"
}
}

if (defined(use_defmt) && use_defmt) {
gen_probe_runner("unittest_runner") {
testonly = true
Expand Down
2 changes: 2 additions & 0 deletions kernel/src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ menu "os adapter configuration"

endchoice
endmenu # os adapter configuration

rsource "coredump/Kconfig"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz also put the path on the _kconfig_files, otherwise the build system can not trace the changes of coredump/Kconfig

8 changes: 8 additions & 0 deletions kernel/src/arch/aarch64/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ extern "C" fn trap_fiq(context: &mut Context) -> usize {
}

fn show_exception(ec: u64, context: &mut Context) {
#[cfg(enable_coredump)]
crate::coredump::dump_current(&crate::coredump::elf::CoredumpReason {
signo: crate::coredump::signal::aarch64_ec_to_signo(ec),
code: ec as i32,
fault_addr: ESR_EL1.get() as usize,
arch_specific: ec as usize,
});

match ec {
0x00 => panic!("Unknown reason Exceptions\n======== error stack ======== \n{}",context),
0x01 => panic!("WFI or WFE instruction\n======== error stack ======== \n{}",context),
Expand Down
9 changes: 9 additions & 0 deletions kernel/src/arch/arm/hardfault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ impl fmt::Display for HardFaultRegs {
pub extern "C" fn panic_on_hardfault(ctx: &IsrContext) {
super::disable_local_irq();
let fault_regs: HardFaultRegs = HardFaultRegs::from_scb();

#[cfg(enable_coredump)]
crate::coredump::dump_current(&crate::coredump::elf::CoredumpReason {
signo: crate::coredump::signal::arm_cfsr_to_signo(fault_regs.cfsr),
code: fault_regs.cfsr as i32,
fault_addr: fault_regs.mmfar as usize,
arch_specific: fault_regs.cfsr as usize,
});

let xpsr = xpsr::read();
panic!(
"
Expand Down
8 changes: 8 additions & 0 deletions kernel/src/arch/riscv/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ extern "C" fn handle_trap(ctx: &mut Context, mcause: usize, mtval: usize, cont:
might_switch_context(ctx, cont)
}
_ => {
#[cfg(enable_coredump)]
crate::coredump::dump_current(&crate::coredump::elf::CoredumpReason {
signo: crate::coredump::signal::riscv_mcause_to_signo(mcause),
code: mcause as i32,
fault_addr: mtval,
arch_specific: mcause,
});

let t = scheduler::current_thread_ref();
panic!(
"[C#{}:0x{:x}] Unexpected trap: context: {:?}, mcause: 0x{:x}, mtval: 0x{:x}",
Expand Down
Loading