EmbDev.net

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


Author: jie zhou (wxhsdp)
Posted on:

Rate this post
0 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

Author: Johann L. (gjlayde)
Posted on:

Rate this post
0 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.

Author: jie zhou (wxhsdp)
Posted on:

Rate this post
0 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?

Author: Johann L. (gjlayde)
Posted on:

Rate this post
0 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.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.