• Rise from your gwave!

SH-2 GNU as bug/feature, and a question

Discussion in 'Saturn Dev' started by ExCyber, Sep 19, 2001.

  1. ExCyber

    ExCyber Staff Member

    After having written some SH-2 code, I tried to assemble it with GNU as (specifically, sh-coff-as and sh-elf-as). It gave me the error message

    Error: misaligned offset

    on many lines. As it turns out, these were all instructions that use indirect register addressing with displacement, such as

    mov.l @(3, r15), r1

    The problem lies in the interpretation of the displacement value. According to the SH1/2 programming manual I have, the format of the instruction is (hope this comes out right)

    MOV.L @(disp,Rm),Rn 0101nnnnmmmmdddd (disp x 4 + Rm) -> Rn

    however, gas implements this as

    MOV.L @(disp,Rm),Rn 0101nnnnmmmmdddd (disp + Rm) -> Rn

    So in order to get my code to assemble, I had to multiply all the displacements by four; my suspicions were confirmed when gas managed to stick a 20 into four bits without complaining (though I later verified that it was correct with a hex editor :)).

    Playing with disassemblers to see what the prevailing opinion was didn't help either: sh2d disassembled these to the gas syntax (for compatibility with gas maybe?), while shdis disassembled them to the syntax described in the manual. Is this a bug in gas, or a gas "feature"? Do I just have to put up with doing it the "wrong" way, or is there a good freeware SuperH assembler out there that uses the syntax described in the manual?
     
  2. CyberWarriorX

    CyberWarriorX New Member

    You could always try snasm. Obviously not freeware, but it's something to try.

    Cyber Warrior X
     
  3. ExCyber

    ExCyber Staff Member

    I'd prefer to not do that if I can help it. The assembler would have to be at the very least real (i.e. not crippled) shareware; if I ever release this code, I'd like for people to be able to assemble it without having to "find" a particular commercial assembler. Right now, that means dealing with gas's weirdness I guess... I suppose I should ask about it on the gas ML , maybe there's a few features I don't know about :).
     
  4. RadSil

    RadSil New Member

    Just out of curiousity, what are you coding in asm?

    As for assemblers for SuperH? Unfortunately the only 2 I know of are gas and snasm. I always believed that gas is extraordinarily crappy, seeing how it likes to use weird-ass mangled (IMO) syntax... why can't they go with Hitachi's spec? It's probably a holdover from the differences of AT&T and Intel x86 asm. (#### that Unix-born crap!) Just a thought.

    Of course, snasm has that problem of being commercial, and I think it only does coff format objects anyway....

    I'll look around for you and if I find anything good I'll let you know.
     
  5. ExCyber

    ExCyber Staff Member

    I think it's more likely that its strange syntax is due to weirdness in GCC's code generation; the primary purpose of gas is to assemble the output of gcc, so it wouldn't suprise me if they tweaked the syntax a bit to make it faster or easier to generate somehow. Did I mention that the register names are case-sensitive, and that gas requires them to be lowercase (all references to them in the manual are uppercase IIRC)? Strange beast :p... maybe I could borrow some code from cpp or something and write my own, though that might be a bit of a hassle.
     

Share This Page