示例#1
0
int TermRead (char *buffer, int bufferSize, int unitID,
                       int *numCharsRead){
	
	//check for illegal arguments
	if (buffer == 0 || bufferSize <= 0 || unitID < 0){
	 	if (debugflaglib4)
			USLOSS_Console("TermRead(): invalid arguments! returning\n");
		return -1;
	}

	 //build sysarg structure to pass to the syscall vec
	systemArgs sysArg;

	CHECKMODE;
	sysArg.number = SYS_TERMREAD;
	sysArg.arg1 = buffer;
	sysArg.arg2 = (void *) ( (long) bufferSize);
	sysArg.arg3 = (void *) ( (long) unitID);

	if (debugflaglib4)
		USLOSS_Console("TermRead(): sysarg built, calling sysvec function\n");
	USLOSS_Syscall(&sysArg);

	int bytesRead = (int ) ((void*) sysArg.arg2);
	*numCharsRead = bytesRead;

	//return (int ) ((void*) sysArg.arg2);

	return 0;
}
示例#2
0
int  DiskRead (void *diskBuffer, int unit, int track, int first, 
                       int sectors, int *status){

	//just checks for obvious illegal values for now, adjust as needed
	if (unit < 0 || unit > 1 || track < 0 || track > 16|| first < 0 || first > 16 || sectors < 0){
		if (debugflaglib4)
			USLOSS_Console("DiskRead(): illegal value(s) given, returning -1\n");
		return -1;
	}

	//build sysarg structure to pass to the syscall vec
	systemArgs sysArg;

	CHECKMODE;
	sysArg.number = SYS_DISKREAD;
	sysArg.arg1 =  diskBuffer;
	sysArg.arg2 = (void *) ( (long) sectors);
	sysArg.arg3 = (void *) ( (long) track);
	sysArg.arg4 = (void *) ( (long) first);
	sysArg.arg5 = (void *) ( (long) unit);
	USLOSS_Syscall(&sysArg);
	*status = 0;
	//once it wakes up, return arg1
	return (int) sysArg.arg1;
}
示例#3
0
文件: libuser.c 项目: awewing/phase5
int
VmDestroy(void) {
    systemArgs     sysArg;

    CHECKMODE;
    sysArg.number = SYS_VMDESTROY;
    USLOSS_Syscall(&sysArg);
    return (int) (long) sysArg.arg1;
} /* VmDestroy */
示例#4
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  SemV
 *
 *  Description: "V" a semaphore.
 *
 *
 *  Arguments:    int semaphore -- semaphore handle
 *                (output value: completion status)
 *
 */
int SemV(int semaphore)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_SEMV;
    sysArg.arg1 = (void *) ( (long) semaphore);
    USLOSS_Syscall(&sysArg);
    return (long) sysArg.arg4;
}
示例#5
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  Mbox_Release
 *
 *  Description: This is the call entry point to release a mailbox
 *
 *  Arguments: int mbox  -- id of the mailbox
 *
 *  Return Value: 0 means success, -1 means error occurs
 *
 */
int Mbox_Release(int mboxID)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_MBOXRELEASE;
    sysArg.arg1 = (void *) (long) mboxID;
    USLOSS_Syscall(&sysArg);
    return (long) sysArg.arg4;
} /* end of Mbox_Release */
示例#6
0
/*
 *  Routine:  SemFree
 *
 *  Description: Free a semaphore.
 *
 *
 *  Arguments:    int semaphore -- semaphore handle
 *                (output value: completion status)
 *
 */
int SemFree(int semaphore)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_SEMFREE;
    sysArg.arg1 = (void *) ( (long) semaphore);
    USLOSS_Syscall(&sysArg);
    return (long) sysArg.arg4;
} /* end of SemFree */
示例#7
0
/*
 *  Routine:  GetTimeofDay
 *
 *  Description: This is the call entry point for getting the time of day.
 *
 *  Arguments:    int *tod  -- pointer to output value
 *                (output value: the time of day)
 *
 */
void GetTimeofDay(int *tod)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_GETTIMEOFDAY;
    USLOSS_Syscall(&sysArg);
    *tod = (long) sysArg.arg1;
    return;
} /* end of GetTimeofDay */
示例#8
0
/*
 *  Routine:  CPUTime
 *
 *  Description: This is the call entry point for the process' CPU time.
 *
 *
 *  Arguments:    int *cpu  -- pointer to output value
 *                (output value: the CPU time of the process)
 *
 */
void CPUTime(int *cpu)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_CPUTIME;
    USLOSS_Syscall(&sysArg);
    *cpu = (long) sysArg.arg1;
    return;
} /* end of CPUTime */
示例#9
0
/*
 *  Routine:  GetPID
 *
 *  Description: This is the call entry point for the process' PID.
 *
 *
 *  Arguments:    int *pid  -- pointer to output value
 *                (output value: the PID)
 *
 */
void GetPID(int *pid)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_GETPID;
    USLOSS_Syscall(&sysArg);
    *pid = (long) sysArg.arg1;
    return;
} /* end of GetPID */
示例#10
0
/*
 *  Routine:  Sleep
 *
 *  Description: This is the call entry point for timed delay.
 *
 *  Arguments:    int seconds -- number of seconds to sleep
 *
 *  Return Value: 0 means success, -1 means error occurs
 *
 */
int Sleep(int seconds)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_SLEEP;
    sysArg.arg1 = (void *) (long) seconds;
    USLOSS_Syscall(&sysArg);
    return (int) (long) sysArg.arg4;
} /* end of Sleep */
示例#11
0
/*
 *  Routine:  Terminate
 *
 *  Description: This is the call entry to terminate
 *               the invoking process and its children
 *
 *  Arguments:   int status -- the commpletion status of the process
 *
 *  Return Value: 0 means success, -1 means error occurs
 */
void Terminate(int status)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_TERMINATE;
    sysArg.arg1 = (void *) ( (long) status);
    USLOSS_Syscall(&sysArg);
    return;

} /* End of Terminate */
示例#12
0
/*
 *  Routine:  SemCreate
 *
 *  Description: Create a semaphore.
 *
 *  Arguments:    int value -- initial semaphore value
 *		  int *semaphore -- semaphore handle
 *                (output value: completion status)
 */
int SemCreate(int value, int *semaphore)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_SEMCREATE;
    sysArg.arg1 = (void *) ( (long) value);
    USLOSS_Syscall(&sysArg);
    *semaphore = (long) sysArg.arg1;
    return (long) sysArg.arg4;
} /* end of SemCreate */
示例#13
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  Mbox_CondReceive
 *
 *  Description: This is the call entry point mailbox conditional
 *               receive.
 *
 *  Arguments:    int mboxID    -- id of the mailbox to receive from
 *                int msgSize   -- size of the message
 *                void *msgPtr  -- message to receive
 *
 *  Return Value: 0 means success, -1 means error occurs, 1 means no
 *                message was available
 *
 */
int Mbox_CondReceive(int mboxID, void *msgPtr, int msgSize)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_MBOXCONDRECEIVE;
    sysArg.arg1 = (void *) (long) mboxID;
    sysArg.arg2 = msgPtr;
    sysArg.arg3 = (void *) (long) msgSize;
    USLOSS_Syscall( &sysArg );
    return ((long) sysArg.arg4);
} /* end of Mbox_CondReceive */
示例#14
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  Mbox_Send
 *
 *  Description: This is the call entry point mailbox send.
 *
 *  Arguments:    int mboxID    -- id of the mailbox to send to
 *                int msgSize   -- size of the message
 *                void *msgPtr  -- message to send
 *
 *  Return Value: 0 means success, -1 means error occurs
 *
 */
int Mbox_Send(int mboxID, void *msgPtr, int msgSize)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_MBOXSEND;
    sysArg.arg1 = (void *) (long) mboxID;
    sysArg.arg2 = msgPtr;
    sysArg.arg3 = (void *) (long) msgSize;
    USLOSS_Syscall(&sysArg);
    return (long) sysArg.arg4;
} /* end of Mbox_Send */
示例#15
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  Mbox_Create
 *
 *  Description: This is the call entry point to create a new mail box.
 *
 *  Arguments:    int   numslots -- number of mailbox slots
 *                int   slotsize -- size of the mailbox buffer
 *                int  *mboxID   -- pointer to output value
 *                (output value: id of created mailbox)
 *
 *  Return Value: 0 means success, -1 means error occurs
 *
 */
int Mbox_Create(int numslots, int slotsize, int *mboxID)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_MBOXCREATE;
    sysArg.arg1 = (void *) (long) numslots;
    sysArg.arg2 = (void *) (long) slotsize;
    USLOSS_Syscall(&sysArg);
    *mboxID = (long) sysArg.arg1;
    return (long) sysArg.arg4;
} /* end of Mbox_Create */
示例#16
0
/*
 *  Routine:  Wait
 *
 *  Description: This is the call entry to wait for a child completion
 *
 *  Arguments:    int *pid -- pointer to output value 1
 *                (output value 1: process id of the completing child)
 *                int *status -- pointer to output value 2
 *                (output value 2: status of the completing child)
 *
 *  Return Value: 0 means success, -1 means error occurs
 */
int Wait(int *pid, int *status)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_WAIT;
    USLOSS_Syscall(&sysArg);
    *pid = (long) sysArg.arg1;
    *status = (long) sysArg.arg2;
    return (long) sysArg.arg4;

} /* End of Wait */
示例#17
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  TermRead
 *
 *  Description: This is the call entry point for terminal input.
 *
 *  Arguments:    char *buffer    -- pointer to the input buffer
 *                int   bufferSize   -- maximum size of the buffer
 *                int   unitID -- terminal unit number
 *                int  *numCharsRead      -- pointer to output value
 *                (output value: number of characters actually read)
 *
 *  Return Value: 0 means success, -1 means error occurs
 *
 */
int TermRead(char *buffer, int bufferSize, int unitID, int *numCharsRead)     
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_TERMREAD;
    sysArg.arg1 = (void *) buffer;
    sysArg.arg2 = (void *) (long) bufferSize;
    sysArg.arg3 = (void *) (long) unitID;
    USLOSS_Syscall(&sysArg);
    *numCharsRead = (long) sysArg.arg2;
    return (long) sysArg.arg4;
} /* end of TermRead */
示例#18
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  DiskSize
 *
 *  Description: This is the call entry point for getting the disk size.
 *
 *  Arguments:    int	unit -- which disk
 *		  int	*sector -- # bytes in a sector
 *		  int	*track -- # sectors in a track
 *		  int   *disk -- # tracks in the disk
 *                (output value: completion status)
 *
 *  Return Value: 0 means success, -1 means error occurs
 *
 */
int DiskSize(int unit, int *sector, int *track, int *disk)
{
    systemArgs sysArg;
    
    CHECKMODE;
    sysArg.number = SYS_DISKSIZE;
    sysArg.arg1 = (void *) (long) unit;
    USLOSS_Syscall(&sysArg);
    *sector = (long) sysArg.arg1;
    *track = (long) sysArg.arg2;
    *disk = (long) sysArg.arg3;
    return (long) sysArg.arg4;
} /* end of DiskSize */
示例#19
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  TermWrite
 *
 *  Description: This is the call entry point for terminal output.
 *
 *  Arguments:    char *buffer    -- pointer to the output buffer
 *                int   bufferSize   -- number of characters to write
 *                int   unitID -- terminal unit number
 *                int  *numCharsWritten      -- pointer to output value
 *                (output value: number of characters actually written)
 *
 *  Return Value: 0 means success, -1 means error occurs
 *
 */
int TermWrite(char *buffer, int bufferSize, int unitID, int *numCharsWritten)    
{
    systemArgs sysArg;
    
    CHECKMODE;
    sysArg.number = SYS_TERMWRITE;
    sysArg.arg1 = (void *) buffer;
    sysArg.arg2 = (void *) (long) bufferSize;
    sysArg.arg3 = (void *) (long) unitID;
    USLOSS_Syscall(&sysArg);
    *numCharsWritten = (long) sysArg.arg2;
    return (long) sysArg.arg4;
} /* end of TermWrite */
示例#20
0
文件: libuser.c 项目: awewing/usloss
/*
 *  Routine:  Spawn
 *
 *  Description: This is the call entry to fork a new user process.
 *
 *  Arguments:    char *name    -- new process's name
 *		  PFV func      -- pointer to the function to fork
 *		  void *arg	-- argument to function
 *                int stacksize -- amount of stack to be allocated
 *                int priority  -- priority of forked process
 *                int  *pid      -- pointer to output value
 *                (output value: process id of the forked process)
 *
 *  Return Value: 0 means success, -1 means error occurs
 */
int Spawn(char *name, int (*func)(char *), char *arg, int stack_size,
          int priority, int *pid)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_SPAWN;
    sysArg.arg1 = (void *) func;
    sysArg.arg2 = arg;
    sysArg.arg3 = (void *) ( (long) stack_size);
    sysArg.arg4 = (void *) ( (long) priority);
    sysArg.arg5 = name;
    USLOSS_Syscall(&sysArg);
    *pid = (int) sysArg.arg1;
    return (int) sysArg.arg4;
} /* end of Spawn */
示例#21
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  DiskWrite
 *
 *  Description: This is the call entry point for disk output.
 *
 *  Arguments:    void* diskBuffer  -- pointer to the output buffer
 *		  int   unit -- which disk to write
 *                int   track  -- first track to write
 *                int   first -- first sector to write
 *		  int	sectors -- number of sectors to write
 *                int   *status    -- pointer to output value
 *                (output value: completion status)
 *
 *  Return Value: 0 means success, -1 means error occurs
 *
 */
int DiskWrite(void *diskBuffer, int unit, int track, int first, int sectors, 
    int *status)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_DISKWRITE;
    sysArg.arg1 = diskBuffer;
    sysArg.arg2 = (void *) (long) sectors;
    sysArg.arg3 = (void *) (long) track;
    sysArg.arg4 = (void *) (long) first;
    sysArg.arg5 = (void *) (long) unit;
    USLOSS_Syscall(&sysArg);
    *status = (long) sysArg.arg1;
    return (long) sysArg.arg4;
} /* end of DiskWrite */
示例#22
0
int  DiskSize (int unit, int *sector, int *track, int *disk){
	if (unit < 0){
		if (debugflaglib4)
			USLOSS_Console("DiskSize(): illegal value(s) given, returning -1\n");
		return -1;
	}
	systemArgs sysArg;

	CHECKMODE;
	sysArg.number = SYS_DISKSIZE;
	sysArg.arg1 = (void *) ( (long) unit);
	USLOSS_Syscall(&sysArg);
	*sector = (int)sysArg.arg1;
	*track = (int)sysArg.arg2;
	*disk = (int)sysArg.arg3; 

	return 0;
}
示例#23
0
/*
 *  Routine:  Spawn
 *
 *  Description: This is the call entry to fork a new user process.
 *
 *  Arguments:    char *name    -- new process's name
 *		  PFV func      -- pointer to the function to fork
 *		  void *arg	-- argument to function
 *                int stacksize -- amount of stack to be allocated
 *                int priority  -- priority of forked process
 *                int  *pid      -- pointer to output value
 *                (output value: process id of the forked process)
 *
 *  Return Value: 0 means success, -1 means error occurs
 */
int Spawn(char *name, int (*func)(char *), char *arg, int stack_size,
	int priority, int *pid)
{
    if (DEBUG3 && debugflaglib3)
            USLOSS_Console("Spawn(): at beginning\n");

    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_SPAWN;
    sysArg.arg1 = (void *) func;
    sysArg.arg2 = arg;
    sysArg.arg3 = (void *) ( (long) stack_size);
    sysArg.arg4 = (void *) ( (long) priority);
    sysArg.arg5 = name;
    USLOSS_Syscall(&sysArg);
    *pid = (long) sysArg.arg1;
    return (long) sysArg.arg4;
} /* end of Spawn */
示例#24
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  Mbox_Receive
 *
 *  Description: This is the call entry point for terminal input.
 *
 *  Arguments:    int mboxID    -- id of the mailbox to receive from
 *                int msgSize   -- size of the message
 *                void *msgPtr  -- message to receive
 *
 *  Return Value: 0 means success, -1 means error occurs
 *
 */
int Mbox_Receive(int mboxID, void *msgPtr, int msgSize)
{
    systemArgs sysArg;

    CHECKMODE;
    sysArg.number = SYS_MBOXRECEIVE;
    sysArg.arg1 = (void *) (long) mboxID;
    sysArg.arg2 = msgPtr;
    sysArg.arg3 = (void *) (long) msgSize;
    USLOSS_Syscall( &sysArg );
        /*
         * This doesn't belong here. The copy should by done by the
         * system call.
         */
        if ( (long) sysArg.arg4 == -1 )
                return (long) sysArg.arg4;
        memcpy( (char*)msgPtr, (char*)sysArg.arg2, (long)sysArg.arg3);
        return 0;

} /* end of Mbox_Receive */
示例#25
0
int  Sleep(int seconds){

	if (seconds <= 0){
		if (debugflaglib4)
			USLOSS_Console("Sleep(): secondsToSleep <= 0, returning -1\n");
		return -1;
	}

	//build sysarg structure to pass to the syscall vec
	systemArgs sysArg;

	CHECKMODE;
	sysArg.number = SYS_SLEEP;
	sysArg.arg1 =  (void *) ( (long) seconds);
	if (debugflaglib4)
		USLOSS_Console("Sleep(): build sysArg, sending to sleep\n");
	USLOSS_Syscall(&sysArg);
	//once it wakes up, just return
	return 0;

}
示例#26
0
文件: libuser.c 项目: awewing/phase5
/*
 *  Routine:  VmInit
 *
 *  Description: Initializes the virtual memory system.
 *
 *  Arguments:    int mappings -- # of mappings in the MMU
 *                int pages -- # pages in the VM region
 *                int frames -- # physical page frames
 *                int pagers -- # pagers to use
 *
 *  Return Value: address of VM region, NULL if there was an error
 *
 */
int VmInit(int mappings, int pages, int frames, int pagers, void **region)
{
    systemArgs     sysArg;

    CHECKMODE;

    sysArg.number = SYS_VMINIT;
    sysArg.arg1 = (void *) (long) mappings;
    sysArg.arg2 = (void *) (long) pages;
    sysArg.arg3 = (void *) (long) frames;
    sysArg.arg4 = (void *) (long) pagers;

    USLOSS_Syscall(&sysArg);

    *region = sysArg.arg1;  // return address of VM Region

    if ((int) sysArg.arg4 == 0) {
        return 0;
    } else {
        return (int) (long) sysArg.arg4;
    }
} /* VmInit */