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

GCC compatability #16

Open
TheThirdOne opened this issue Apr 4, 2019 · 7 comments
Open

GCC compatability #16

TheThirdOne opened this issue Apr 4, 2019 · 7 comments

Comments

@TheThirdOne
Copy link
Owner

I would like for GCC generated assembly to be able to be directly compiled (with libc features replaced). A fair number of small features need to be added to make that possible.

  • .section .rodata should not have no effect
    • put it in .data at least
    • maybe add a .rodata section
  • Allow .align n in .text
    • should work properly with n >= 4
    • n < 4 can just be made into n = 4
  • Allow .type
    • probably just ignore it for now
  • Extra psuedo-instructions
    • add sp,sp, -32
    • lui a5, %hi(.LC0)
    • addi a0,a5,%lo(.LC0)
    • jr ra
@mvlamar
Copy link

mvlamar commented Jul 27, 2019

Hi,
I think putting the following lines in PseudoOps.txt may solve some GCC incompatibility issues.

lui t1,%hi(label) ;lui RG1,LH4 ;#Load Upper Address : Set t1 to upper 20-bit label's address
addi t1,t2,%lo(label) ;addi RG1,RG2,LL5 ;#Load Lower Address : Set t1 to t2 + lower 12-bit label's address
lw t1,%lo(label)(t2) ;lw RG1,LL4(RG7) ;#Load from Address
flw f1,%lo(label)(t2) ;flw RG1,LL4(RG7) ;#Load from Address

@TheThirdOne
Copy link
Owner Author

@mvlamar, thats a pretty good suggestion. I got stuck thinking about how to make it work in any part of the assembler, but just supporting the most common cases should get it most of the way there.

In the program I just compiled and looked through and %hi and %lo only appear with with lui and addi. Do you have an example C program where when compiled to assembly where %lo is used with lw?

@mvlamar
Copy link

mvlamar commented Jul 29, 2019

Hi Benjamin,
This is a very simple example. Compile with -O0.

 static int i0=0x12345678;
 static float f0=1.5;

 void main(void){	
    int i1=i0;
    float f1=f0;
 }

@TheThirdOne
Copy link
Owner Author

Thanks for the example. I'll try to add the the psuedo-instructions you suggested.

TheThirdOne added a commit that referenced this issue Jul 31, 2019
The added ones come directly from mvlamar's suggestion on #16

I added TokenTypes.HI and LO to make sure that they weren't intepretted as macros by the tokenizer.
TheThirdOne added a commit that referenced this issue Jul 31, 2019
This covers the remaining issues listed in #16.
@TheThirdOne
Copy link
Owner Author

Aside from some simple pseudo instructions, the only issue I am aware of is the .comm directive. It is very similar to the .extern that is already implemented so it should be simple to add.

TheThirdOne added a commit that referenced this issue Oct 7, 2019
.section was sometimes followed by a quoted section name so that is not accepted
 by rars. .sdata was also used which RARS now treats as just .data

This made the main issue of moving code over the lack of a C standard library.
I am unsure if multiple C files can be assembled together effectively.

Not GCC, but progress towards #16
@phummel
Copy link
Contributor

phummel commented Apr 14, 2020

This isn't directly related, but I think gcc used .equ instead of .eqv

@TheThirdOne
Copy link
Owner Author

I don't think that GCC outputs assembly using .equ, but it does seem like that would be a directive you find find in existing handwritten code.

It seems that GCC handles both in a similar way. I'm not sure if they are exactly the same though. I'll look into it and if they are exactly the same, add it into RARS.

marcelachim pushed a commit to marcelachim/rars that referenced this issue Dec 20, 2024
Build test and publish with Github Actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants