Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Towards the compiler #135

Open
schoeberl opened this issue Nov 10, 2022 · 10 comments
Open

Towards the compiler #135

schoeberl opened this issue Nov 10, 2022 · 10 comments

Comments

@schoeberl
Copy link
Member

Not really an issue, but notes (from @Emoun) what needs to be done in the Patmos C source files and in the handbook:

Changes:

  • Can no longer use clang as a linker using the below flags:
    "-fpatmos-nolibsyms", "-fpatmos-noruntimelibs", "-fpatmos_link_object"
    Instead, use "-c" to create object files and then call the linker directly.
  • Removed flag "-fpatmos-skip-opt". Using "-O0" instead.
  • Removed flag "-fpatmos-emit-asm". Using "-S" instead.
  • Multiple "patmos-clang" patmos-specific flags have been removed.
    Instead, call the equivalent "patmos-ld" flags using "-mllvm" prefix:
    "-mpatmos-disable-stack-cache" -> "-mllvm --mpatmos-disable-stack-cache"
    "-mpatmos-disable-function-splitter" -> "-mllvm --mpatmos-disable-function-splitter"
    "-mpatmos-disable-vliw" -> "-mllvm --mpatmos-disable-vliw"
    Note how the flags need 2 "-" instead of the previous 1.
  • Removed flag "-Xgold". Using "-Wl," instead.
  • Removed flag "-Xllc". Using "-mllvm" instead.
  • In inline assembly, input-, ouput-, and clobber registers should no longer have a "$" prefix.
    I.e. instead of "$r1" use "r1" as clobber register.
    In the inline assembly proper, registers need/allow 1 "$" only.
  • Naked functions can only include inline assembly.
    No other code is allowed per the C standard.
    If you want to use C code in a naked function, you can manually call a non-naked function from
    the inline assembly.

Notes:
Handbook says by default clang compiles to bitcode (section 8.2.1). This is wrong.

@schoeberl
Copy link
Member Author

Naked functions are not allowed to have C code? That isn't good. What about the bootloader?

@Emoun
Copy link
Member

Emoun commented Feb 5, 2024

Yes, see here for the definition in RISC-V and here for how microsoft treats them.
We need to stick to convention and also disallow C code in naked functions.

This not an issue, as you can call another function that is implemented in C after you do any needed setup. The std _start function has already been fixed so it uses naked functions correctly. I did not consider that the bootloader also has a start function that is naked, so I'll get that fixed at some point too.

@schoeberl
Copy link
Member Author

The Microsoft statement does not explicitly disallow C code. But I see the point. I guess this is not a C standard, but compiler-specific.

On bootloader: don't you need to start with a naked function anyway as long as no one has setup at least the stack pointer?

@Emoun
Copy link
Member

Emoun commented Feb 7, 2024

Yes, you are right about microsoft, but GCC seems to me to treat C code in naked functions as undefined behavior. I presume clang by extension does the same, but did not find any documentation for this after a quick search.

Our bootloader does start with a naked function that sets up the stack using inline asm.

@schoeberl
Copy link
Member Author

But it calls C functions with C code (the call is C, not inline assembly):

local_mode();

Is this considered OK, then?

@Emoun
Copy link
Member

Emoun commented Feb 7, 2024

No, not in my opinion. That is what I was refering to earlier that I need to fix. Just like I fixed the newlib start function.

@schoeberl
Copy link
Member Author

But there you the call itself in assembler, but the bootloader does not. Could this be the issue with the bootloader?

@Emoun
Copy link
Member

Emoun commented Feb 8, 2024

It definitely needs fixing. I don't think it's the current issue, as I seem to remember the bootloader failing only when downloading a program and not before. But perhaps the issue only manifests at that point but is indeed caused by _start.
We will see when I get to it.

@schoeberl
Copy link
Member Author

I would propose to wrap those three functions into one, so you only need to call one function from assembler.

@Emoun
Copy link
Member

Emoun commented Sep 27, 2024

Add to the list of differences between new and old compiler:

The -mserialize flag is now -mserialize-pml. This is because LLVM now has its own mserialize flag that we shouldn't clash with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants