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\n"); 
__asm__ ("l.nop\n\t "
             "l.cust1\n\t") ;
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\n"); 
__asm__ ("l.nop\n\t "
"l.cust1 r1, r2 \n\t") ;
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.

OpenRISC自定义指令GCC修改的更多相关文章

  1. vue学习-day02(自定义指令,生命周期)

    目录: 1.案例:品牌管理    2.Vue-devtools的两种安装方式    3.过滤器,自定义全局或私有过滤器    4.鼠标按键事件的修饰符    5.自定义全局指令:让文本框获取焦点   ...

  2. AngularJS笔记--自定义指令

    在前端开发中, 我们会遇到很多地方都会用到同一种类型的控件.AngularJS提供了自定义指令功能,我们可以在指令里面定义特定的html模板.提供给前台html调用. 一. 指令的简单定义.  下面定 ...

  3. Angular自定义指令directive:scope属性

    在AngularJS中,除了内置指令如ng-click等,我们还可以自定义指令.自定义指令,是为了扩展DOM元素的功能.代码中,通过指定directive中的restrict属性,来决定这个指令是作为 ...

  4. AngularJs自定义指令详解(6) - controller、require

    在前面文章中提到一旦声明了require,则链接函数具有第四个参数:controller. 可见require和controller是配合使用的. 在自定义指令中使用controller,目的往往是要 ...

  5. 走进AngularJs(五)自定义指令----(下)

    自定义指令学习有段时间了,学了些纸上谈兵的东西,还没有真正的写个指令出来呢...所以,随着学习的接近尾声,本篇除了介绍剩余的几个参数外,还将动手结合使用各参数,写个真正能用的指令出来玩玩. 我们在自定 ...

  6. 走进AngularJs(四)自定义指令----(中)

    上一篇简单介绍了自定义一个指令的几个简单参数,restrict.template.templateUrl.replace.transclude,这几个理解起来相对容易很多,因为它们只涉及到了表现,而没 ...

  7. 走进AngularJs(三)自定义指令-----(上)

    一.有感而发的一些话 在学习ng之前有听前辈说过,angular上手比较难,初学者可能不太适应其语法以及思想.随着对ng探索的一步步深入,也确实感觉到了这一点,尤其是框架内部的某些执行机制,其复杂程度 ...

  8. AngularJS:如何使用自定义指令来取代ng-repeat

    引言 本文主要介绍了另一种即具有与ng-repeat 一样处理大量数据的绑定的功能,又具有超高的性能. 对于处理小数量,ng-repeat是非常有用的,但是如果需要处理非常大的数量集,还是采用自定义的 ...

  9. 带你走近AngularJS - 创建自定义指令

    带你走近AngularJS系列: 带你走近AngularJS - 基本功能介绍 带你走近AngularJS - 体验指令实例 带你走近AngularJS - 创建自定义指令 ------------- ...

随机推荐

  1. Python全栈开发之5、几种常见的排序算法以及collections模块提供的数据结构

    转载请注明出处http://www.cnblogs.com/Wxtrkbc/p/5492298.html 在面试中,经常会遇到一些考排序算法的题,在这里,我就简单了列举了几种最常见的排序算法供大家学习 ...

  2. 用 Python实现一个ftp+CRT(不用ftplib)

    转载请注明出处http://www.cnblogs.com/Wxtrkbc/p/5590004.html  本来最初的想法是实现一个ftp服务器,用来实现用户的登陆注册和文件的断点上传下载等,结果做着 ...

  3. 【转】LoadRunner常见问题整理

    原文出自:http://blog.csdn.net/loadrunn/article/details/7886918 1.LR 脚本为空的解决方法: 1.去掉ie设置中的第三方支持取消掉 2.在系统属 ...

  4. Android 之JSON数据解析

    (以下基本都是郭霖大神<第一行代码>中的知识) JSON数据与xml相比,优势在于体积更小,传输所需的流量少.但是缺点也很明显,就是语义性较差. 下面是一组JSON格式的数据. [{&qu ...

  5. 【Python初级】由判定回文数想到的,关于深浅复制,以及字符串反转的问题

    尝试用Python实现可以说是一个很经典的问题,判断回文数. 让我们再来看看回文数是怎么定义的: 回数是指从左向右读和从右向左读都是一样的数,例如1,121,909,666等 解决这个问题的思路,可以 ...

  6. Redis学习篇(一)之String类型及其操作

    SET 作用: 设置key对应的值, 返回ok 语法: SET key value [EX seconds] [PX milliseconds] [NX] [XX] 如果key已经存在,同名会产生覆盖 ...

  7. CF614A【签到题】

    题目链接[http://codeforces.com/problemset/problem/614/A] 题意:输入三个数l.r.k(1 ≤ l ≤ r ≤ 1018, 2 ≤ k ≤ 109),输出 ...

  8. 【BZOJ 4361】 4361: isn (DP+树状数组+容斥)

    4361: isn Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 218  Solved: 126 Description 给出一个长度为n的序列A( ...

  9. 【BZOJ 3812】 3812: 主旋律 (容斥原理**)

    3812: 主旋律 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 235  Solved: 196 Description 响应主旋律的号召,大家决定 ...

  10. [转]android.support.v4.app.Fragment和android.app.Fragment区别

      1.最低支持版本不同 android.app.Fragment 兼容的最低版本是android:minSdkVersion="11" 即3.0版 android.support ...