|
| |
![]() |
|
Lab 2: TutorialThis is ONLY a preview of the tutorial. If you would like to view the entire tutorial, you must purchase the tutorial.What is syscall.h ???syscall.h resides in userprog directory and it contains the macros defining the code numbers of system calls and the prototypes of the system calls. The user programs which you will write for your test cases will follow the format of the system calls defined in syscall.h. The implementations of all system calls will go in the exception.cc. Let me give you an explaination of each System call. Create(char* name)Create system call creates a file with the name "name" given as the parameter.
else if ((which == SyscallException) && (type == SC_Create))
{
int virtualaddress = machine->ReadRegister(4);
//This is the argument of the Create system call(in register r4)
//but this is an integer and this is the starting virtual address
//of the name of the file to be created . so it needs to be
// converted to the physical address
// for this you can copy and paste the Translate & ReadMem
// functions of machine class and make use of those functions
// Those functions are implemented in translate.cc in machine
//directory.
...........
.........
Now after you get translated the virtual address to the
physical address , you can get the name of the file
as char* from that physical address
***check whether file already exists or not , If the file
with the same name exists then return and display error
***If not then call
fileSystem->Create(... , ...);
add the name to the list
NOTE: This list should be globally defined
}
...
//----------------------------------------------------------------------
// Create_Syscall
// Create the file with the name in the user buffer pointed to by
// vaddr. The file name is at most MAXFILENAME chars long. No
// way to return errors, though...
//
// "vaddr" -- The filename is stored in the string at this virtual
// address.
//----------------------------------------------------------------------
void Create_Syscall(unsigned int vaddr)
{
// Kernel buffer to put the name in
char *buf = new char[MAXFILENAME];
if (!buf) return;
if ( copyinz(vaddr,MAXFILENAME,buf) == -1 )
{
synchConsole->WriteLine("System Error: Bad pointer passed to Create.\n");
delete buf;
return;
}
// Do some error checking before passing it to the filesystem
if (strcmp(buf, "") == 0)
{
synchConsole->WriteLine("System Error: Invalid name for file.\n");
delete buf;
return;
}
fileSystem->Create(buf,0);
delete buf;
return;
}
This is ONLY a preview of the tutorial. If you would like to view the entire tutorial, you must purchase the tutorial.Each tutorial comes with the following:
This includes both documentation on understanding the concepts for each assignment and how to get started. Topics are accompanied with animations.
|
Nachos Introduction Tutorials |
||||||||||||||||||
| © 1999-2008 - All rights reserved. CS tutorials™ and the logo are registered trademarks of CS tutorials. | |||||||||||||||||||