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.
  • 相关阅读:
    六:观察者模式
    聊一聊如何接入支付宝
    每天学点SpringCloud(八):使用Apollo做配置中心
    每天学点SpringCloud(七):路由器和过滤器-Zuul
    每天学点SpringCloud(六):Hystrix使用
    每天学点SpringCloud(五):如何使用高可用的Eureka
    每天学点SpringCloud(四):Feign的使用及自定义配置
    每天学点SpringCloud(三):自定义Eureka集群负载均衡策略
    每天学点SpringCloud(二):服务注册与发现Eureka
    每天学点SpringCloud(一):使用SpringBoot2.0.3整合SpringCloud
  • 原文地址:https://www.cnblogs.com/lyuyangly/p/7110848.html
Copyright © 2011-2022 走看看