编写并测试子函数
我正在尝试为 nachOS 编写子函数,但是当我组合它时它不起作用。不知道原因。 细节: 在 ../userprog/syscall.h
添加:
#define SC_Sub 11
int Sub(int a, int b);
在 ../test/
.globl Sub
.ent Sub
Sub:
addiu $2,$0,SC_Sub
syscall
j $31
.end Sub
之后,我
#include "syscall.h"
int main()
{
int result;
result = Sub(100,99);
Halt();
}
在 exception.cc 中编写一个 sub.c:: 我尝试捕获异常:
case SC_Sub:
op1 = machine->ReadRegister(4);
op2 = machine->ReadRegister(5);
result = op1 - op2;
printf("op1:%d\n",op1);
printf("op2:%d\n",op2);
printf("result:%d\n",result);
machine->WriteRegister(2,result);
machine->WriteRegister(PCReg,machine->ReadRegister(PCReg)+4);
break;
要合并,我转到 /code/gmake all
我有错误:(
../../../gnu-decstation-ultrix/decstation-ultrix/2.95.3/gcc -B../../../gnu-decstation-ultrix/ -T script -N sub.o -o sub
../../../gnu-decstation-ultrix/decstation-ultrix/2.95.3/ld: cannot open crt0.o: No such file or directory
make[1]: *** [sub] Error 1
make[1]: Leaving directory `/home/nxqd/Desktop/nachos-3.4/code/test'
gmake: *** [all] Error 2
这是玉米片的文件夹。它不包含我写的“bug”子函数。
http://www.mediafire.com/?g3mnjxz4wdc
enter code here
I'm trying to write sub func for nachOS but when I combines it doesn't work. Don't know the reason.
Details:
In ../userprog/syscall.h
Add :
#define SC_Sub 11
int Sub(int a, int b);
In ../test/
.globl Sub
.ent Sub
Sub:
addiu $2,$0,SC_Sub
syscall
j $31
.end Sub
After that I write a sub.c:
#include "syscall.h"
int main()
{
int result;
result = Sub(100,99);
Halt();
}
in exception.cc:
I try to catch exception:
case SC_Sub:
op1 = machine->ReadRegister(4);
op2 = machine->ReadRegister(5);
result = op1 - op2;
printf("op1:%d\n",op1);
printf("op2:%d\n",op2);
printf("result:%d\n",result);
machine->WriteRegister(2,result);
machine->WriteRegister(PCReg,machine->ReadRegister(PCReg)+4);
break;
To combine I go to /code/gmake all
And I have error :(
../../../gnu-decstation-ultrix/decstation-ultrix/2.95.3/gcc -B../../../gnu-decstation-ultrix/ -T script -N sub.o -o sub
../../../gnu-decstation-ultrix/decstation-ultrix/2.95.3/ld: cannot open crt0.o: No such file or directory
make[1]: *** [sub] Error 1
make[1]: Leaving directory `/home/nxqd/Desktop/nachos-3.4/code/test'
gmake: *** [all] Error 2
This is the folder of nachos . It doesn't contain the "bug" Sub func I write .
http://www.mediafire.com/?g3mnjxz4wdc
enter code here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯.. 嗯,我对 NachOS 一无所知,但我做过一些操作系统开发。
无法打开 crt0.o:没有这样的文件或目录
您是否发送了正确的链接器命令?让我们看看您的链接器脚本。
我假设您已经构建了一个 MIPS 交叉编译器。您是否将其配置为使用标准库?如果没有标准库,是否将其配置为使用默认的crt0?
请注意,crt0 是一个“引导”对象。它包含
__main
,这是操作系统执行的第一件事。然后,该引导对象解析命令行参数和其他初始化内容,然后调用您的main
函数。我不确定 NachOS 中有多少东西,但你甚至可能必须制作自己的 crt0 并将其与链接器脚本链接作为启动映像(不记得确切的名称)hmm.. Well, I know nothing of NachOS but I've done some OS developing.
cannot open crt0.o: No such file or directory
Are you sending the right linker commands? Let us see your linker script.
I'm assuming you've built a MIPS cross compiler. Have you configured it to use a standard library. If there is no standard library, have you configured it to use the default crt0?
Note that crt0 is a "bootstrap" object. It contains
__main
which is the first thing executed by the OS. This bootstrap object then parses command line arguments and other initialization stuff and then calls yourmain
function. I'm not sure how much stuff there is in NachOS, but you may even have to make your own crt0 and link it in with the linker script as the startup image(can't remember the exact name)