English 中文(简体)
Write and test sub func
原标题:

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
",op1);
   printf("op2:%d
",op2);   
   printf("result:%d
",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
问题回答

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 your main 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)





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签