MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / encode_tail

Function encode_tail

crates/asm-to-binary/src/assembler/encode.rs:372–397  ·  view source on GitHub ↗

Encode `tail symbol` -> `auipc t1, %pcrel_hi(symbol); jalr x0, t1, %pcrel_lo(symbol)`.

(
    sec: &mut SectionData,
    symbol: &str,
    current_addr: u64,
    symbols: &super::symbol_table::SymbolTable,
    section_bases: &std::collections::HashMap<SectionKind, u64>,
    relocations: 

Source from the content-addressed store, hash-verified

370fn resolve_absolute_symbol(
371 symbol: &str,
372 symbols: &super::symbol_table::SymbolTable,
373 section_bases: &std::collections::HashMap<SectionKind, u64>,
374) -> Option<u64> {
375 if let Some(&addr) = symbols.all().get(symbol) {
376 for (section_kind, base) in section_bases {
377 let qualified_name = format!("{}@{}", symbol, section_kind.name());
378 if let Some(&offset) = symbols.all().get(&qualified_name) {
379 return Some(*base + offset);
380 }
381 }
382 return Some(addr);
383 }
384 None
385}
386
387// Compute PC-relative (hi20, lo12) for a target address relative to `current_addr`.
388fn pcrel_offsets(target_addr: u64, current_addr: u64) -> (i32, i32) {
389 crate::isa::pcrel_split((target_addr as i64) - (current_addr as i64))
390}
391
392// Encode `call symbol` -> `auipc ra, %pcrel_hi(symbol); jalr ra, ra, %pcrel_lo(symbol)`.
393fn encode_call(
394 sec: &mut SectionData,
395 symbol: &str,
396 current_addr: u64,
397 symbols: &super::symbol_table::SymbolTable,
398 section_bases: &std::collections::HashMap<SectionKind, u64>,
399 relocations: &mut Vec<RelocationRecord>,
400 section_name: &str,

Callers 1

encodeFunction · 0.85

Calls 6

resolve_absolute_symbolFunction · 0.85
pcrel_offsetsFunction · 0.85
push_u32_leMethod · 0.80
current_offsetMethod · 0.80
pushMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected