tags:

views:

130

answers:

1

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
A: 

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)

Earlz
I'm just a very beginner in OS writing ( Just in school ) . But I don't think the problem is at crt0.o .linker script ? You mean the coff , noff in nachos ?
nXqd
`gcc -B../../../gnu-decstation-ultrix/ -T script -N sub.o -o sub` the `-T script` means it is including the linker script `script`. Let us see that file(maybe thats part of the problem) also, just edit your question with that file because comments don't have formatting
Earlz
Thanks , just edit :)
nXqd