-
Notifications
You must be signed in to change notification settings - Fork 78
build using -mcmodel = medany #25
Comments
Unfortunately, addresses Nice to see someone putting effort in Kendryte! At the moment I'm working on similar task: support for HiFive Unleashed board, which is also RV64GC. |
Probably you could link it with riscv64-unknown-elf-ld |
@Dantistnfs it may work for you because you don't use |
@Disasm |
I figured out that on K210 it's possible to run code from address I've started working on k210-pac. At the moment, the only peripherals supported are |
we found out that
|
@medusacle Is this behavior reproducible in plain C and official SDK? |
yes, it seems so, the following #include <stdio.h>
#include "sysctl.h"
#include "uarths.h"
#include "sleep.h"
static float fp_const_a = 1.2345f;
int main(void)
{
if (current_coreid() == 0)
{
uarths_init();
usleep(100000);
float *ptr_a = &fp_const_a;
printf("%f at %p\r\n", *ptr_a, ptr_a);
float *alt_a = (float*)(((uintptr_t)&fp_const_a) - 0x40000000);
printf("%f at %p\r\n", *alt_a, alt_a);
}
while (1)
asm volatile ("wfi");
return 0;
} (loading the resulting binary at
(for doubles I was not able to reproduce it here because the SDK is compiled with |
Thanks for investigating the issue! It's a serious argument against using |
As described here by @medusacle: rust-embedded/riscv-rt#25 (comment)
`flw` and `fld` from the 0x4xxxxxxxx range always return 0. This sabotages pretty much all floating point computation. rust-embedded/riscv-rt#25 (comment)
Updated relevant crates to reflect these changes. |
@medusacle Thanks again! This hack with |
Using For example:
Loading the program onto the chip with Anyone else run into that sort of issue? |
happy to hear that !
that's interesting
a small change to the startup code could make sure it jumps to the high address… another less likely cause could be if the upper 32 bits of the |
Yeah, it does seem like the code is probably running at the 'real' addresses from Anyways, it might not be worth digging into too much, because the toolchain should eventually obviate this workaround: rust-lang/rust#59802 |
that way around might work as well, got as far as:
which moves the ELF sections but doesn't move the DWARF data, which seems to have internal pointers, so isn't useful in your case |
i checked and this definitely isn't the case, #![feature(asm)]
#![no_std]
#![no_main]
use core::panic::PanicInfo;
use k210_hal::pac;
use k210_hal::prelude::*;
use k210_hal::stdout::Stdout;
use riscv_rt::entry;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! { loop {} }
extern "C" fn get_pc() -> usize {
let c: usize;
unsafe { asm!("auipc $0,0" : "=r"(c) ::: "volatile"); }
c
}
#[entry]
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();
let clocks = k210_hal::clock::Clocks::new();
let serial = p.UARTHS.constrain(115_200.bps(), &clocks);
let (mut tx, _) = serial.split();
let mut stdout = Stdout(&mut tx);
unsafe {
writeln!(stdout, "initial pc is 0x{:016x}", get_pc()).unwrap();
let mut addr = get_pc as usize;
writeln!(stdout, "function addr is 0x{:016x}", addr).unwrap();
loop {
let func: extern "C" fn() -> usize = core::mem::transmute(addr as *const ());
let pc = func();
writeln!(stdout, "call 0x{:016x} → pc 0x{:016x}", addr, pc).unwrap();
addr = addr.wrapping_add(1<<32);
}
}
} gives: [click for raw output]
|
Interesting, thanks for the information and taking the time to investigate. That's a neat I tried building your example and I see the same thing; it runs from I still haven't gotten GDB to recognize the symbols, but I think there's enough information here to figure it out. Thanks for the example and explanations. |
Add support for pc-relative addressing on 64-bit RISC-V These changes allow Rust to generate position-independent code on `riscv64` targets with code model `medium`. Closes: rust-lang#59802 See also: rust-embedded/riscv-rt#25, rust-embedded/wg#218
Add support for pc-relative addressing on 64-bit RISC-V These changes allow Rust to generate position-independent code on `riscv64` targets with code model `medium`. Closes: #59802 See also: rust-embedded/riscv-rt#25, rust-embedded/wg#218
mcmodel=medium support landed in nightly! rust-lang/rust#62281 |
I'm trying to port this crate to a new board targeting riscv64gc.
The original link script is https://github.com/kendryte/kendryte-standalone-sdk/blob/master/lds/kendryte.ld
My memory.x:
This device don't have flash in its cpu address space. So I replace
FLASH
in link.x toRAM
I try to rebuild asm.S in riscv-rt and riscv
Build and output is
It seems rustc don't have a option to build using -mcmodel=medany and default to -mcmodel = medlow
In sifive's blog,
-mcmodel=medlow
generateR_RISCV_HI20/R_RISCV_LO12_I
and-mcmodel=medany
generateR_RISCV_PCREL_HI20/R_RISCV_PCREL_LO12_I
The text was updated successfully, but these errors were encountered: