arch/mips/kernel/relocate.c
Source file repositories/reference/linux-study-clean/arch/mips/kernel/relocate.c
File Facts
- System
- Linux kernel
- Corpus path
arch/mips/kernel/relocate.c- Extension
.c- Size
- 11910 bytes
- Lines
- 480
- Domain
- Architecture Layer
- Bucket
- arch/mips
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/bootinfo.hasm/cacheflush.hasm/fw/fw.hasm/sections.hasm/setup.hasm/timex.hlinux/elf.hlinux/kernel.hlinux/libfdt.hlinux/of_fdt.hlinux/panic_notifier.hlinux/sched/task.hlinux/start_kernel.hlinux/string.hlinux/printk.h
Detected Declarations
function plat_post_relocationfunction get_synci_stepfunction sync_icachefunction apply_r_mips_64_relfunction apply_r_mips_32_relfunction apply_r_mips_26_relfunction apply_r_mips_hi16_relfunction reloc_handlerfunction do_relocationsfunction relocate_exception_tablefunction rotate_xorfunction get_random_bootfunction kaslr_disabledfunction relocation_addr_validfunction update_kaslr_offsetfunction relocate_kernelfunction show_kernel_relocationfunction kernel_location_notifier_fnfunction register_kernel_offset_dumper
Annotated Snippet
#include <linux/start_kernel.h>
#include <linux/string.h>
#include <linux/printk.h>
#define RELOCATED(x) ((void *)((long)x + offset))
extern u32 _relocation_start[]; /* End kernel image / start relocation table */
extern u32 _relocation_end[]; /* End relocation table */
extern long __start___ex_table; /* Start exception table */
extern long __stop___ex_table; /* End exception table */
extern void __weak plat_fdt_relocated(void *new_location);
/*
* This function may be defined for a platform to perform any post-relocation
* fixup necessary.
* Return non-zero to abort relocation
*/
int __weak plat_post_relocation(long offset)
{
return 0;
}
static inline u32 __init get_synci_step(void)
{
u32 res;
__asm__("rdhwr %0, $1" : "=r" (res));
return res;
}
static void __init sync_icache(void *kbase, unsigned long kernel_length)
{
void *kend = kbase + kernel_length;
u32 step = get_synci_step();
do {
__asm__ __volatile__(
"synci 0(%0)"
: /* no output */
: "r" (kbase));
kbase += step;
} while (step && kbase < kend);
/* Completion barrier */
__sync();
}
static void __init apply_r_mips_64_rel(u32 *loc_new, long offset)
{
*(u64 *)loc_new += offset;
}
static void __init apply_r_mips_32_rel(u32 *loc_new, long offset)
{
*loc_new += offset;
}
static int __init apply_r_mips_26_rel(u32 *loc_orig, u32 *loc_new, long offset)
{
unsigned long target_addr = (*loc_orig) & 0x03ffffff;
if (offset % 4) {
pr_err("Dangerous R_MIPS_26 REL relocation\n");
return -ENOEXEC;
}
/* Original target address */
target_addr <<= 2;
target_addr += (unsigned long)loc_orig & 0xf0000000;
/* Get the new target address */
target_addr += offset;
if ((target_addr & 0xf0000000) != ((unsigned long)loc_new & 0xf0000000)) {
pr_err("R_MIPS_26 REL relocation overflow\n");
return -ENOEXEC;
}
target_addr -= (unsigned long)loc_new & 0xf0000000;
target_addr >>= 2;
*loc_new = (*loc_new & ~0x03ffffff) | (target_addr & 0x03ffffff);
return 0;
}
Annotation
- Immediate include surface: `asm/bootinfo.h`, `asm/cacheflush.h`, `asm/fw/fw.h`, `asm/sections.h`, `asm/setup.h`, `asm/timex.h`, `linux/elf.h`, `linux/kernel.h`.
- Detected declarations: `function plat_post_relocation`, `function get_synci_step`, `function sync_icache`, `function apply_r_mips_64_rel`, `function apply_r_mips_32_rel`, `function apply_r_mips_26_rel`, `function apply_r_mips_hi16_rel`, `function reloc_handler`, `function do_relocations`, `function relocate_exception_table`.
- Atlas domain: Architecture Layer / arch/mips.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.