duderonomy has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
bitts[m] has joined #rust-embedded
<bitts[m]>
How can I call a function defined in an assembly file that is included with global_asm!? I tried declaring it with extern "C" {}, but linker throws undefined symbol?
<dirbaio[m]>
That's how you do it yep. Here's one example:
<dirbaio[m]>
Maybe .type or .global is required, not sure
<bitts[m]>
I have both .type and .global, but what does options(raw) do? I dont have that..
<dirbaio[m]>
It's so rust doesn't do anything with {} characters in the asm. Handy if you want to include_str a normal .s file without escaping the {}s. That's not what's causing your error..
<diondokter[m]>
Doesn't the asm macro want each instruction in a separate string?
<diondokter[m]>
(Also, if you're on nightly, you could try out the new and improved naked fns)
<dirbaio[m]>
Rust skips linking a crate if you never use it. Do you have the global_asm in the same crate as the extern?
<dirbaio[m]>
If you do then it should be OK because you're useing that crate for sure. If not then you have to make sure to add a dummy use
<bitts[m]>
Yes, the rust code above is all in one file in one crate, then I use arm_get_core_id() from a different crate
<bitts[m]>
diondokter: I'm using global_asm! which can read a standard assembly file. asm! takes separate strings yes
<diondokter[m]>
Ah ok
<bitts[m]>
Tried moving it all to the same crate, no dice.. Weird...
adamgreig[m] has joined #rust-embedded
<adamgreig[m]>
fwiw asm can take one string or multiple strings or whatever too
<adamgreig[m]>
iirc?
<adamgreig[m]>
yea, it's fine, it's just you'd have to put newlines in so it makes for a potentially ugly multi-line string or loads or \r\n
<adamgreig[m]>
the macro just offers the option of doing lots of string literals which it will glue together with newlines in-between
<diondokter[m]>
adamgreig[m]: Ah that's probably it then
<adamgreig[m]>
so like asm!("mov {0}, {1} \r\n add {0}, 5", out(reg) o, in(reg) i); works, and asm!("mov {0}, {1}", "add {0}, 5", out(reg) o, in(reg) i); is the same, or you could put an actual newline and split the literal over multiple lines, but you can't just have mov {0}, {1} add {0}, 5
<bitts[m]>
If it was just that one function I would move it over to hand-coded asm!, but unfortunately there are a bunch of them in multiple files that I would prefer to just use as is
<diondokter[m]>
Maybe you need to mark it as executable?
<bitts[m]>
I already use global_asm! for some boot code, and that works fine, so it is not completely broken.
<bitts[m]>
Not going to object to that, but it is awfully similar to what dirbaio linked to above. But I can try to throw in some of that for sure!
<diondokter[m]>
Oh didn't see that from Dario
<adamgreig[m]>
it's worth a try, I worry the issue is some sort of linker related nuisance where your symbols just aren't ending up where you want them, but I don't see why not
<bitts[m]>
Not sure if being on a mac could have something to do with it?
<adamgreig[m]>
wouldn't expect so
<bitts[m]>
Huh, for the curious, I had based my project off the raspberry-pi os tutorial (https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials) which is makefile based and calls cargo rustc. After setting up a new project using standard .cargo/config.toml etc, the global_asm! works as expected..