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. 【LOJ】#2351. 「JOI 2017/2018 决赛」毒蛇越狱

    题解 没啥特别好的算法,是个讨论题,由于0 1 ?三类数位中最少的不会超过6 如果1不超过6,那么记录\(f1(S)\)为 \(\sum_{T \subset S} val(T)\)这个可以通过类似F ...

  2. Hibernate (开源对象关系映射框架)

    一.基本介绍1.它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm(对象关系映射)框架,hibernate可以自动生成SQL语句,自动执行: Hibern ...

  3. 转:Linux创建进程

    转:http://www.cnblogs.com/GT_Andy/archive/2011/06/21/2086129.html 我们都知道,进程就是正在执行的程序.而在Linux中,可以使用一个进程 ...

  4. 2017-2018-1 20179202《Linux内核原理与分析》第二周作业

    本周着重学习了汇编指令,并通过反汇编C程序了解栈帧变化. 实践 看了孟老师的演示视频后,我重新写了C程序,如下: int main() { int a=1,b=2; return g(a,b); } ...

  5. Python并发编程-一个简单的爬虫

    一个简单的爬虫 #网页状态码 #200 正常 #404 网页找不到 #502 504 import requests from multiprocessing import Pool def get( ...

  6. Java反射机制Reflection

    Java反射机制 1 .class文件 2 Class类 3 Class类与反射机制 4 Java反射机制的类库支持及简介 5 反射机制的定义与应用 6 反射机制Demo Java反射机制demo(一 ...

  7. Qt Installer Framework实战

    Qt Installer Framework是Qt发布的安装程序支持框架,只需要简单的配置就可以生成安装文件,同时可以通过javascript脚本来定制安装过程. 目录结构 config packag ...

  8. C和指针之学习笔记(4)

    第9章 字符串 字符串的输入与输出 int  ch;  char strings[80];  FILE *input; (1)scanf(“%c”,&ch);   printf(“%c \n” ...

  9. CODEVS1358【DFS/状压DP】

    题目链接[http://codevs.cn/problem/1358/] 题意:这个游戏在一个有10*10个格子的棋盘上进行,初始时棋子位于左上角,终点为右下角,棋盘上每个格子内有一个0到9的数字,每 ...

  10. SCOI2011 棘手的操作

    线段树+并查集,对于每个操作我们只需要维护他在自己子树中的最值和在整个树里的最值,类似于线段树动态开点. #include<bits/stdc++.h> using namespace s ...