EmbDev.net

Forum: ARM programming with GCC/GNU tools how to deal with new instructions gcc does not recognize


von jie z. (wxhsdp)


Rate this post
useful
not useful
Hi, guys

we aim to self make a FPU which has its own instruction set. For easy 
programming, we prefer c language to assembly code.

here's one of our instruction:
c language format: Bload(vd, value1, value2), we make it like a 
funciton. vd is a special register.
binary format: 31-26 opcode, 25-21 index of vd register, 20-16 opcode, 
15-11 index of the general register which keeps value1, 10-5 opcode, 4-0 
index of the general register which keeps value2.

we use gcc-inline-assembly to convert it to binary code. here's the 
solution:
#define Bload(vd, value1, value2)    \
  __asm__(        \
    "add  r16, r0, %0  \n\t"  \
    "add  r14, r0, %1  \n\t"  \
    ".long  %2  \n\t"    \
    :        \
    : "r"(value2), "r"(value1), 
"i"((0x3b<<26)+(vd<<21)+(14<<11)+(0x2c<<5)+16)  \
    : "r14", "r16");
i fix the general registers(r14, r16) which keep value1 and value2. then 
i make the binary code use "i" in inline-assembly. But disadvantage is 
in evidence: gcc does not understand my instruction, so i can not take 
it's advantage, such as selecting the most suitable general register and 
eliminating unnecessary copy from register to register.

what i want is deleting the first two add instruction, let gcc select 
register for me and tell me which register it selected. so i can make my 
own binary code using .long instruction. But i do not want to modify the 
gcc compiler to let it understand my instruction.

Thank you for your help

von Johann L. (gjlayde)


Rate this post
useful
not useful
jie zhou wrote:
> what i want is deleting the first two add instruction, let gcc select
> register for me and tell me which register it selected. so i can make my
> own binary code using .long instruction. But i do not want to modify the
> gcc compiler to let it understand my instruction.

There are several approaches:

(A) You don't need to change GCC. It's sufficient to teach binutils the
    new instructions/instruction formats with the additinal benefit that
    you will see the new instructions in disassembly.

(B) Drag the arithmetic from C-level to (inline) assembly.  You will
    need an output modifier to print a GPR as it's number.  If your GCC
    port does not have it yet: add it.  It's TARGET_PRINT_OPERAND hook
    in your ./gcc/config/target/target.c, see GCC's internals
    documentation.

von jie z. (wxhsdp)


Rate this post
useful
not useful
Johann L. thank you very much for your help

> You don't need to change GCC. It's sufficient to teach binutils the
> new instructions/instruction formats with the additinal benefit that
> you will see the new instructions in disassembly.

i prefer to teaching gnu binutils the new instructions. in fact, i use 
microblaze gnu tools to compile my code. but how to teach gnu binutils? 
can you say some details?

von Johann L. (gjlayde)


Rate this post
useful
not useful
You can find a draft at
http://sourceware.org/binutils/binutils-porting-guide.txt
Look at your backend and other ports to learn more.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.