Skip to content

Commit

Permalink
RISC-V: Setup exception vector early
Browse files Browse the repository at this point in the history
The trap vector is set only in trap_init which may be too late in some
cases. Early ioremap/efi spits many warning messages which may be useful.

Setup the trap vector early so that any warning/bug can be handled before
generic code invokes trap_init.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
  • Loading branch information
Atish Patra authored and Palmer Dabbelt committed Jul 30, 2020
1 parent 925ac7b commit 79b1feb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 8 additions & 2 deletions arch/riscv/kernel/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ relocate:
csrw CSR_SATP, a0
.align 2
1:
/* Set trap vector to spin forever to help debug */
la a0, .Lsecondary_park
/* Set trap vector to exception handler */
la a0, handle_exception
csrw CSR_TVEC, a0

/*
* Set sup0 scratch register to 0, indicating to exception vector that
* we are presently executing in kernel.
*/
csrw CSR_SCRATCH, zero

/* Reload the global pointer */
.option push
.option norelax
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/kernel/smpboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ asmlinkage __visible void smp_callin(void)
mmgrab(mm);
current->active_mm = mm;

trap_init();
notify_cpu_starting(curr_cpuid);
update_siblings_masks(curr_cpuid);
set_cpu_online(curr_cpuid, 1);

/*
* Remote TLB flushes are ignored while the CPU is offline, so emit
* a local TLB flush right now just in case.
Expand Down
8 changes: 1 addition & 7 deletions arch/riscv/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,7 @@ int is_valid_bugaddr(unsigned long pc)
}
#endif /* CONFIG_GENERIC_BUG */

/* stvec & scratch is already set from head.S */
void trap_init(void)
{
/*
* Set sup0 scratch register to 0, indicating to exception vector
* that we are presently executing in the kernel
*/
csr_write(CSR_SCRATCH, 0);
/* Set the exception vector address */
csr_write(CSR_TVEC, &handle_exception);
}

0 comments on commit 79b1feb

Please sign in to comment.