Update all syscall
And add PutInt() and GetInt()
This commit is contained in:
parent
2b7c7ee780
commit
2a3198c949
7 changed files with 95 additions and 31 deletions
|
@ -69,7 +69,8 @@ int copyStringFromMachine(int from, char *to, unsigned size)
|
|||
int res;
|
||||
|
||||
// Need to read size-1 to put final /0 if needed
|
||||
while((i<size-1) && (machine->ReadMem(from+i,1,&res))){
|
||||
while((i < size) && (machine->ReadMem(from+i,1,&res))){
|
||||
DEBUG('s', "\n ->copyFromMachine keycode:%d", res);
|
||||
*(to+i) = (char)res;
|
||||
if ((char)res == '\0'){
|
||||
return i;
|
||||
|
@ -83,7 +84,8 @@ int copyStringFromMachine(int from, char *to, unsigned size)
|
|||
int copyStringToMachine(int to, char* from, unsigned size)
|
||||
{
|
||||
unsigned i;
|
||||
for (i=0; i < size - 1; i++) {
|
||||
for (i=0; i < size ; i++) {
|
||||
DEBUG('s', "\n ->copyToMachine keycode:%d", (int)from[i]);
|
||||
if (from[i] == '\0') {
|
||||
break;
|
||||
}
|
||||
|
@ -134,14 +136,11 @@ ExceptionHandler (ExceptionType which)
|
|||
int readsize;
|
||||
int addr_start = machine->ReadRegister(4);
|
||||
do {
|
||||
char* read = new char[MAX_STRING_SIZE];
|
||||
char *read = new char[MAX_STRING_SIZE + 1];
|
||||
readsize = copyStringFromMachine( addr_start, read, MAX_STRING_SIZE);
|
||||
DEBUG('s', "\nRead buffer:%s, size:%d\n", read, readsize);
|
||||
consoledriver->PutString(read);
|
||||
// beware, the last element of our buffer was added by
|
||||
// copyStringFromMachine(), we need to remove one memory case
|
||||
// or the first char of our next read will be
|
||||
// forgotten
|
||||
addr_start += readsize - 1;
|
||||
addr_start += readsize ;
|
||||
delete [] read;
|
||||
} while(readsize == MAX_STRING_SIZE);
|
||||
break;
|
||||
|
@ -151,32 +150,55 @@ ExceptionHandler (ExceptionType which)
|
|||
DEBUG ('s', "GetChar.\n");
|
||||
// Get the char input an write it to the register n.2
|
||||
int c = consoledriver->GetChar();
|
||||
machine->WriteRegister((2), c);
|
||||
machine->WriteRegister(2, c);
|
||||
break;
|
||||
}
|
||||
|
||||
case SC_GetString:
|
||||
{
|
||||
DEBUG ('s', "GetString.\n");
|
||||
DEBUG('s', "Begin GetString.\n");
|
||||
int writesize = 0;
|
||||
int addr = machine->ReadRegister(4);
|
||||
int size = machine->ReadRegister(5);
|
||||
DEBUG ('s', "size:%d\n", size);
|
||||
DEBUG('s', "size:%d\n", size);
|
||||
do {
|
||||
char* write = new char[MAX_STRING_SIZE];
|
||||
consoledriver->GetString(write, MAX_STRING_SIZE);
|
||||
DEBUG('s', "write:%s:\n", write);
|
||||
writesize = copyStringToMachine(addr, write, MAX_STRING_SIZE);
|
||||
// Do not process char before size
|
||||
// but for now we don't have any method to determine if
|
||||
// string passed to our function est bigger than expected (size)
|
||||
int n_char = ( size < MAX_STRING_SIZE) ? size : MAX_STRING_SIZE;
|
||||
|
||||
// allocate on byte more than buffer to put our \0 if needed
|
||||
char *write = new char[n_char + 1];
|
||||
consoledriver->GetString(write, n_char);
|
||||
writesize = copyStringToMachine(addr, write, n_char);
|
||||
addr += writesize;
|
||||
DEBUG('s', "Writed:%d\n", writesize);
|
||||
size = size - writesize;
|
||||
DEBUG('s', "writed:%s, size:%d, remain:%d\n", write, writesize, size);
|
||||
delete [] write;
|
||||
} while( writesize == MAX_STRING_SIZE - 1 );
|
||||
} while( size > 0 && writesize == MAX_STRING_SIZE );
|
||||
DEBUG('s', "End GetString\n");
|
||||
break;
|
||||
}
|
||||
case SC_PutInt:
|
||||
{
|
||||
DEBUG('s', "PutInt.\n");
|
||||
int n = machine->ReadRegister(4);
|
||||
DEBUG('s', "PutInt parameter: %d\n", n);
|
||||
consoledriver->PutInt(n);
|
||||
}
|
||||
break;
|
||||
case SC_GetInt:
|
||||
{
|
||||
DEBUG('s', "GetInt\n");
|
||||
int n = consoledriver->GetInt();
|
||||
DEBUG('s', "Number entered: %d\n", n);
|
||||
machine->WriteRegister(2,n);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
{
|
||||
printf("Unimplemented system call %d\n", type);
|
||||
printf("Unimplemented system call %d\n", type);
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue