Skip to content

Commit

Permalink
Make mpentry independent of _start
Browse files Browse the repository at this point in the history
APs enter the kernel at the same point as the BSP, the _start routine.
They then jump to mpentry, but not before storing the kernel's physical
load address in the s9 register. Extract this calculation into its own
routine, so that APs can be instructed to enter directly from mpentry.

Differential Revision:	https://reviews.freebsd.org/D24495
  • Loading branch information
mhorne committed May 1, 2020
1 parent d5cc572 commit df62bf0
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions sys/riscv/riscv/locore.S
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ _start:
lla gp, __global_pointer$
.option pop

/* Get the physical address kernel loaded to */
lla t0, virt_map
ld t1, 0(t0)
sub t1, t1, t0
li t2, KERNBASE
sub s9, t2, t1 /* s9 = physmem base */

/*
* a0 = hart id
* a1 = dtbp
Expand All @@ -87,6 +80,9 @@ _start:
* Page tables
*/
1:
/* Get the kernel's load address */
jal get_physmem

/* Add L1 entry for kernel */
lla s1, pagetable_l1
lla s2, pagetable_l2 /* Link to next level PN */
Expand Down Expand Up @@ -224,6 +220,17 @@ va:
call _C_LABEL(initriscv) /* Off we go */
call _C_LABEL(mi_startup)

/*
* Get the physical address the kernel is loaded to. Returned in s9.
*/
get_physmem:
lla t0, virt_map /* physical address of virt_map */
ld t1, 0(t0) /* virtual address of virt_map */
sub t1, t1, t0 /* calculate phys->virt delta */
li t2, KERNBASE
sub s9, t2, t1 /* s9 = physmem base */
ret

.align 4
initstack:
.space (PAGE_SIZE * KSTACK_PAGES)
Expand Down Expand Up @@ -303,6 +310,9 @@ ENTRY(mpentry)
lla t0, bootstack
ld sp, 0(t0)

/* Get the kernel's load address */
jal get_physmem

/* Setup supervisor trap vector */
lla t0, mpva
sub t0, t0, s9
Expand Down

0 comments on commit df62bf0

Please sign in to comment.