Skip to content

Commit 79b1feb

Browse files
atishp04palmer-dabbelt
authored andcommitted
RISC-V: Setup exception vector early
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 <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 925ac7b commit 79b1feb

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

arch/riscv/kernel/head.S

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,16 @@ relocate:
7777
csrw CSR_SATP, a0
7878
.align 2
7979
1:
80-
/* Set trap vector to spin forever to help debug */
81-
la a0, .Lsecondary_park
80+
/* Set trap vector to exception handler */
81+
la a0, handle_exception
8282
csrw CSR_TVEC, a0
8383

84+
/*
85+
* Set sup0 scratch register to 0, indicating to exception vector that
86+
* we are presently executing in kernel.
87+
*/
88+
csrw CSR_SCRATCH, zero
89+
8490
/* Reload the global pointer */
8591
.option push
8692
.option norelax

arch/riscv/kernel/smpboot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ asmlinkage __visible void smp_callin(void)
154154
mmgrab(mm);
155155
current->active_mm = mm;
156156

157-
trap_init();
158157
notify_cpu_starting(curr_cpuid);
159158
update_siblings_masks(curr_cpuid);
160159
set_cpu_online(curr_cpuid, 1);
160+
161161
/*
162162
* Remote TLB flushes are ignored while the CPU is offline, so emit
163163
* a local TLB flush right now just in case.

arch/riscv/kernel/traps.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,7 @@ int is_valid_bugaddr(unsigned long pc)
174174
}
175175
#endif /* CONFIG_GENERIC_BUG */
176176

177+
/* stvec & scratch is already set from head.S */
177178
void trap_init(void)
178179
{
179-
/*
180-
* Set sup0 scratch register to 0, indicating to exception vector
181-
* that we are presently executing in the kernel
182-
*/
183-
csr_write(CSR_SCRATCH, 0);
184-
/* Set the exception vector address */
185-
csr_write(CSR_TVEC, &handle_exception);
186180
}

0 commit comments

Comments
 (0)