Skip to content

Commit

Permalink
Add define of new syscalls
Browse files Browse the repository at this point in the history
  • Loading branch information
thangtq139 committed Oct 19, 2017
1 parent 8037348 commit 0676f2d
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 2 deletions.
Binary file modified src/nachos-3.4/code/test/halt
Binary file not shown.
Binary file modified src/nachos-3.4/code/test/matmult
Binary file not shown.
Binary file modified src/nachos-3.4/code/test/shell
Binary file not shown.
Binary file modified src/nachos-3.4/code/test/sort
Binary file not shown.
53 changes: 53 additions & 0 deletions src/nachos-3.4/code/test/start.s
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,59 @@ Yield:
j $31
.end Yield

/************** New inserted code here ****************/

.globl ReadInt
.ent ReadInt
ReadInt:
addiu $2,$0,SC_ReadInt
syscall
j $31
.end ReadInt

.glob PrintInt
.ent PrintInt
PrintInt:
addiu $2,$0,SC_PrintInt
syscall
j $31
.end PrintInt

.glob ReadChar
.ent ReadChar
ReadChar:
addiu $2,$0,SC_ReadChar
syscall
j $31
.end ReadChar

.glob PrintChar
.ent PrintChar
PrintChar:
addiu $2,$0,SC_PrintChar
syscall
j $31
.end PrintChar

.glob ReadString
.ent ReadString
ReadString:
addiu $2,$0,SC_ReadString
syscall
j $31
.end ReadString

.glob PrintString
.ent PrintString
PrintString:
addiu $2,$0,SC_PrintString
syscall
j $31
.end PrintString


/************** Break of new inserted code ************/

/* dummy function to keep gcc happy */
.globl __main
.ent __main
Expand Down
Binary file added src/nachos-3.4/code/userprog/.syscall.h.swp
Binary file not shown.
14 changes: 12 additions & 2 deletions src/nachos-3.4/code/userprog/exception.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,27 @@ ExceptionHandler(ExceptionType which)
case SC_Halt:
interrupt->Halt();
break;
case SC_ReadInt:
break;
case SC_PrintInt:
break;
case SC_ReadChar:
break;
case SC_PrintChar:
break;
case SC_ReadString:
break;
case SC_PrintString:
break;
default:
printf("Unexpected user mode exception %d %d\n", which, type);
ASSERT(FALSE);
break;

}
break;
default:
printf("Unexpected user mode exception %d %d\n", which, type);
ASSERT(FALSE);
break;

}
}
36 changes: 36 additions & 0 deletions src/nachos-3.4/code/userprog/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@
#define SC_Fork 9
#define SC_Yield 10

/******************** New inserted code here *******************/
/* Our new defined system calls, included:
* SC_ReadInt: read an integer from console
* SC_PrintInt: print an integer to console
* SC_ReadChar: read a character from console
* SC_PrintChar: print a character to console
* SC_ReadString: read a string from console
* SC_PrintString: write a string to console
*/

#define SC_ReadInt 11
#define SC_PrintInt 12
#define SC_ReadChar 13
#define SC_PrintChar 14
#define SC_ReadString 15
#define SC_PrintString 16

/******************* Break of new inserted code ***************/


#ifndef IN_ASM

/* The system call interface. These are the operations the Nachos
Expand Down Expand Up @@ -124,6 +144,22 @@ void Fork(void (*func)());
*/
void Yield();

/*********************** New inserted code here *****************/

int ReadInt();

void PrintInt();

char ReadChar();

void PrintChar();

void ReadString(char buffer[], int length);

void PrintString(char buffer[]);

/*********************** Break of new inserted code *************/

#endif /* IN_ASM */

#endif /* SYSCALL_H */

0 comments on commit 0676f2d

Please sign in to comment.