ChanServ changed the topic of #rust-embedded to: Welcome to the Rust Embedded IRC channel! Bridged to #rust-embedded:matrix.org and logged at https://libera.irclog.whitequark.org/rust-embedded, code of conduct at https://www.rust-lang.org/conduct.html
IlPalazzo-ojiisa has quit [Quit: Leaving.]
cr1901 has quit [Remote host closed the connection]
starblue has quit [Ping timeout: 240 seconds]
cr1901 has joined #rust-embedded
starblue has joined #rust-embedded
cr1901 has quit [Remote host closed the connection]
cr1901 has joined #rust-embedded
cr1901 has quit [Remote host closed the connection]
cr1901 has joined #rust-embedded
cr1901 has quit [Remote host closed the connection]
cr1901 has joined #rust-embedded
cr1901 has quit [Remote host closed the connection]
cr1901 has joined #rust-embedded
cr1901 has quit [Remote host closed the connection]
cr1901 has joined #rust-embedded
cr1901 has quit [Remote host closed the connection]
duderonomy has quit [Remote host closed the connection]
duderonomy has joined #rust-embedded
cr1901 has joined #rust-embedded
cr1901 has quit [Remote host closed the connection]
cr1901 has joined #rust-embedded
emerent has quit [Ping timeout: 255 seconds]
emerent has joined #rust-embedded
crabbedhaloablut has joined #rust-embedded
neceve has joined #rust-embedded
andresovela[m] has quit [Quit: Idle timeout reached: 172800s]
neceve has quit [Ping timeout: 240 seconds]
IlPalazzo-ojiisa has joined #rust-embedded
jannic[m] has joined #rust-embedded
<jannic[m]> <dirbaio[m]> "how does that work, and could..." <- The startup process in std applications is nicely explained in https://os.phil-opp.com/freestanding-rust-binary/. Not sure if everything in that article is still up to date, but I don't think the general approach has changed in the meantime.... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/xyZTvgUEslVxDoeDZdQDQeWo>)
<jannic[m]> This is still using the linker script and the asm.S from cortex-m-rt.
<adamgreig[m]> I think in principle it should be an extern C main but it probably doesn't make much odds here
<adamgreig[m]> (also c-m-rt doesn't have asm.S any more, it's a global_asm!() call, but same deal)
<adamgreig[m]> But I guess the question is whether we could co-opt Rust's knowledge of std main() to allow an embedded program using cmrt to just write fn main()->! and not need no_main nor the macro
<adamgreig[m]> Which would be cool...
lulf[m] has quit [Quit: Idle timeout reached: 172800s]
lkostka[m] has quit [Quit: Idle timeout reached: 172800s]
K900 has quit [Quit: Idle timeout reached: 172800s]
diondokter[m] has quit [Quit: Idle timeout reached: 172800s]
mameluc[m] has quit [Quit: Idle timeout reached: 172800s]
waveguide[m] has quit [Quit: Idle timeout reached: 172800s]
Lumpio[m] has quit [Quit: Idle timeout reached: 172800s]
<JamesMunns[m]> I think you could `extern "rust"` it if cmrt provides the start? It's not checked then though, I think it's possible to declare `fn main () -> !;` in one place and define it as `fn main() -> () { ... }` in another
StephenD[m] has quit [Quit: Idle timeout reached: 172800s]
firefrommoonligh has quit [Quit: Idle timeout reached: 172800s]
FlixtheNewbie[m] has quit [Quit: Idle timeout reached: 172800s]
<thejpster[m]> OK, clearly we need to work on our documentation. the entry macro does several things:
<thejpster[m]> 1. it ensures *your* main function has the right type. If you have a no-mangle `pub fn extern "C" main(arguments: &[u8])` you will have a bad time (because you will not get that argument, and you are not supposed to return).
<thejpster[m]> 2. It hides the 'real main' function and your main function so that you cannot re-enter main from your program.
<thejpster[m]> 3. It remaps `static mut` variables to be `&mut` refs to those statics, which are safe to use. This is because 2 ensures you can't re-enter your main function and thus those references are indeed exclusive.
<thejpster[m]> You can't use the start lang-item becuase it's not stable. And so a macro was invented. This is mostly covered in the embedonomicon, but that talks about it in abstract terms and doesn't refer to the entry macro specifically.
<thejpster[m]> Providing your own fn extern "C" main() is probably the preferred approach if you are using CRT1 to boot your chip. cortex-m-rt eschews crt1, I guess in the name of "it's better if people don't need gcc", but some people are using things that are not cortex-m and the start-up is a PITA and they want their gcc to do the hard work for them. So we should probably have an example for that. My LEON3 demo does this, for example
<thejpster[m]> (github.com/ferrous-systems/sparc-experiments).
<thejpster[m]> jannic: I wouldn't rely on being able to call an extern "Rust" function from the asm start-up code. The Rust ABI is not specified and who knows what assumptions the compiler makes about the caller pushing things. You need to make your main extern "C".
<jannic[m]> That's true. While there aren't so many useful calling conventions for a function that doesn't take arguments and never returns, it's obviously better to use the right calling conventions from the start.
<adamgreig[m]> If we taught Rust how to start cmrt, you could conceivably have fn main() just like you for hosted platforms, with rust abi, since the rust provided ASM would call it correctly
<adamgreig[m]> It's not like we're eschewing "crt1" though, we'd need to link in some specific startup code from arm or cmsis or something if we didn't provide our own, not just something from gcc
<adamgreig[m]> If we dropped the static mut transform then I don't think we'd need the non-reentrancy either which might be less surprising to people, but it's what we have at the moment
<jannic[m]> Sometimes it's convenient to know that some code runs exactly once, and first after boot, to do some initialization that would be unsound if done later. Not an unsolvable problem, of course.
<adamgreig[m]> Yea, it doesn't really cost us anything to keep it I don't think, beyond a tiny bit of documentation complexity
d3zd3z[m] has quit [Quit: Idle timeout reached: 172800s]
starblue has quit [Ping timeout: 255 seconds]
burrbull[m] has quit [Quit: Idle timeout reached: 172800s]
neceve has joined #rust-embedded
jessebraham[m] has quit [Quit: Idle timeout reached: 172800s]
IlPalazzo-ojiisa has quit [Quit: Leaving.]
starblue has joined #rust-embedded
Guest7221 has left #rust-embedded [Error from remote client]
M9names[m] has quit [Quit: Idle timeout reached: 172800s]
ChaeyoungLee[m] has quit [Quit: Idle timeout reached: 172800s]
neceve has quit [Ping timeout: 258 seconds]
Guest7221 has joined #rust-embedded
starblue has quit [Ping timeout: 258 seconds]
starblue has joined #rust-embedded
notgull has quit [Ping timeout: 260 seconds]
notgull has joined #rust-embedded
crabbedhaloablut has quit []