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. JS 判断浏览器类型,获取位置信息,让手机震动

    判断是否是安卓 var isAndroid = /Android/i.test(navigator.userAgent); 判断是否是IOS系统 var isIOS = /iPhone|iPad|iP ...

  2. [Codeforces995C]Leaving the Bar 瞎搞

    大致题意: 给出平面上n个向量,对于每个向量可以选择正的V或负的-V,求按照选择的向量走完,最后距离原点<=1.5*1e6的一个选择方案 非正解!!!!!!!!!! 先按距离原点距离由远到近贪心 ...

  3. Python并发编程-SocketServer多线程版

    #server.py import socket from threading import Thread def chat(conn): conn.send(b'hello') msg = conn ...

  4. XML XSD XSL区别与联系

    XML: XML(Extensible Markup Language)即可扩展标记语言,它与HTML一样,都是SGML(Standard Generalized Markup Language,标准 ...

  5. POJ3687 Katu Puzzle

    好好写2-sat 如果a1-->b1矛盾则连边a1-->b2和b1-->a2 我定了一个ccnt和cnt变量,结果少打一个c,wa了好多次(lll¬ω¬) By:大奕哥 #inclu ...

  6. 91网漏洞打包#越权+爆破+存储xss可打cookie

    漏洞一.主站存在登录口爆破 抓包,爆破一下 爆破成功 漏洞二.检测app时一处存储xss 在app登录后 我要提问那里插入xss 然后弹窗 可以打到cookie 漏洞三.app个人资料处平行越权可查看 ...

  7. [CC-ANUCBC]Cards, bags and coins

    [CC-ANUCBC]Cards, bags and coins 题目大意: 给你\(n(n\le10^5)\)个数,\(q(q\le30)\)次询问,问从中选取若干个数使得这些数之和为\(m(m\l ...

  8. JAVA对数字证书的常用操作(转载)

    一:需要包含的包 import java.security. * ; import java.io. * ; import java.util. * ; import java.security. * ...

  9. [转]Android:异步处理之AsyncTask的应用(二)

    2014-11-07     既然UI老人家都这么忙了,我们这些开发者肯定不能不识趣的去添乱阻塞UI线程什么的,否则UI界面万一停止响应了呢——这不是招骂的节奏么?!所以我们知道用Handler+Th ...

  10. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题

    A. Bear and Three Balls 题目连接: http://www.codeforces.com/contest/653/problem/A Description Limak is a ...