xen/riscv: introduce function for physical offset calculation

The function was introduced to calculate and save physical
offset before MMU is enabled because access to start() is
PC-relative and in case of linker_addr != load_addr it will
result in incorrect value in phys_offset.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Oleksii Kurochko authored and Jan Beulich committed 2023-11-02 10:47:58 +01:00
1 parent 86266162fc
commit af670c14e8
3 files changed
+34 -3

No files matched your search

+2
View File
@@ -15,4 +15,6 @@ void setup_initial_pagetables(void);
void enable_mmu(void);
void cont_after_mmu_is_enabled(void);
unsigned long calc_phys_offset(void);
#endif /* _ASM_RISCV_MM_H */
+18 -3
View File
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <xen/cache.h>
#include <xen/compiler.h>
#include <xen/init.h>
#include <xen/kernel.h>
@@ -19,9 +20,10 @@ struct mmu_desc {
pte_t *pgtbl_base;
};
#define PHYS_OFFSET ((unsigned long)_start - XEN_VIRT_START)
#define LOAD_TO_LINK(addr) ((addr) - PHYS_OFFSET)
#define LINK_TO_LOAD(addr) ((addr) + PHYS_OFFSET)
static unsigned long __ro_after_init phys_offset;
#define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset)
#define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset)
/*
* It is expected that Xen won't be more then 2 MB.
@@ -273,3 +275,16 @@ void __init noreturn noinline enable_mmu()
switch_stack_and_jump((unsigned long)cpu0_boot_stack + STACK_SIZE,
cont_after_mmu_is_enabled);
}
/*
* calc_phys_offset() should be used before MMU is enabled because access to
* start() is PC-relative and in case when load_addr != linker_addr phys_offset
* will have an incorrect value
*/
unsigned long __init calc_phys_offset(void)
{
volatile unsigned long load_start = (unsigned long)_start;
phys_offset = load_start - XEN_VIRT_START;
return phys_offset;
}
+14
View File
@@ -29,6 +29,20 @@ ENTRY(start)
jal reset_stack
/*
* save hart_id ( bootcpu_id ) and dtb_base as a0 and a1 register can
* be used by C code
*/
mv s0, a0
mv s1, a1
jal calc_phys_offset
mv s2, a0
/* restore hart_id ( bootcpu_id ) and dtb address */
mv a0, s0
mv a1, s1
tail start_xen
.section .text, "ax", %progbits
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.