TheThirdOne / rars

RARS -- RISC-V Assembler and Runtime Simulator
Other
1.21k stars 231 forks source link

GCC compatability #16

Open TheThirdOne opened 5 years ago

TheThirdOne commented 5 years ago

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.

mvlamar commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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

TheThirdOne commented 5 years ago

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.

phummel commented 4 years ago

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

TheThirdOne commented 4 years ago

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.