zoukankan      html  css  js  c++  java
  • OpenRISC自定义指令GCC修改

    This short tutorial shows how to use the custom instructions defined by OpenRISC architecture. The OpenRISC architecture specify some custom instructions that can be designed specifically to your processor.

     
    Although the title says that we will make changes to GCC, in fact we will make changes to the binutils package used by GCC. This package contains the assembler used by GCC - the GAS . The toolchain distributed by opencores already defines all custom instructions, but do not defines any layout for each one. In other words, as soon as you download the toolchain, you can write some assembly code using custom instructions, like this:
     
    in main(){
    printf("hello world "); 
    __asm__ ("l.nop  "
                 "l.cust1 ") ;
    return 0; 
    }
     
    This code builds correctly. But, as you can see, you cannot specify registers as arguments to the l.cust1 instruction because no arguments are defined in the binutils package. If you want to add arguments (register, immediate), you must change just one file in binutils package.
    Supose that we want to define one custom instruction like this:
     
    l.cust1 $reg1, $reg2
     
    So, open <rootdir>/binutils-2.20.1/opcodes/or32-opc.c and find an array that defines all instructions opcode and layout. You can make a search for l.cust1 and find this occurrence:
     
    ...
    { "l.jr", "rB", "01 0x1 ----- ----- BBBB B--- ---- ----", EF(l_jr), OR32_IF_DELAY, it_jump },
    { "l.jalr", "rB", "01 0x2 ----- ----- BBBB B--- ---- ----", EF(l_jalr), OR32_IF_DELAY, it_jump },
    { "l.maci", "rA,I", "01 0x3 ----- AAAAA IIII IIII IIII IIII", EF(l_mac), 0, it_mac },
    { "l.cust1", "", "01 0xC ----- ----- ---- ---- ---- ----", EF(l_cust1), 0, it_unknown },
    { "l.cust2", "", "01 0xD ----- ----- ---- ---- ---- ----", EF(l_cust2), 0, it_unknown },
    { "l.cust3", "", "01 0xE ----- ----- ---- ---- ---- ----", EF(l_cust3), 0, it_unknown },
    { "l.cust4", "", "01 0xF ----- ----- ---- ---- ---- ----", EF(l_cust4), 0, it_unknown },
    ...
     
    As you can see, this specification does not accept arguments. Change this line to:
     
    { "l.cust1", "rA, rB", "01 0xC ----- AAAAA BBBB B--- ---- ----", EF(l_cust1), 0, it_unknown },
     
    Now, rebuild the entire toochain as described at opencores site. When finished, you can now build this code:
     
    in main(){
    printf("hello world "); 
    __asm__ ("l.nop  "
    "l.cust1 r1, r2  ") ;
    return 0; 
    }
     
    And that's it. You can define different layouts based on other instructions, using more registers or immediate as argument.
     
    REFERENCES
     
    [1] Adding custom instructions for GCC & GAS - http://hi.baidu.com/j_fo/blog/item/7888347a9fba99e92e73b3c0.html
    [3] Integrating Custom Instruction Specifications into C Development Process. Jack Whitham and Neil Audsley. Department of Computer Science - University of York.
  • 相关阅读:
    Java 第二题
    第6次作业--static关键字、对象
    20194643 自动生成四则运算第一版报告
    软件工程 第一次作业
    MySQL主从复制与读写分离原理
    垂直拆分、读写分离、水平拆分(分库分表)详解
    MySQL InnoDB 索引原理
    MySQL架构体系&SQL查询执行全过程解析
    最全MySQL锁详解:表/行/页锁、共享/排它锁、悲观/乐观锁等
    MySQL事务ACID与隔离级别详解
  • 原文地址:https://www.cnblogs.com/lyuyangly/p/7110848.html
Copyright © 2011-2022 走看看