Class Kernel

java.lang.Object
  |
  +--Kernel

public class Kernel
extends java.lang.Object

A simple kernel simulation.

There is only one public interface to this class: interrupt(). System calls, disk notification, and power on messages all arrive by way of this function.

See the list of SYSCALL_XXX constants to learn what system calls are currently supported.

See Also:
Disk, Library

Field Summary
static int ERROR_BAD_ARGUMENT_TYPE
          An error code indicating that one of the system call parameters made no sense.
static int ERROR_BAD_COMMAND
          An error code indicating that a command passed to SYSCALL_EXEC could not be executed.
static int ERROR_END_OF_FILE
          An error code indicating that end of file was reached.
static int ERROR_IN_CHILD
          An error code indicating that a child program caused an exception and crashed.
static int ERROR_IO
          An error code indicating that somthing went wrong during an I/O operation.
static int ERROR_NO_SUCH_PROCESS
          An error code indicating an attempt to join with a non-existant process
static int ERROR_OUT_OF_RANGE
          An error code indicating that one parameter was too big or too small
static int INTERRUPT_DISK
          An interrupt kind indicating that a disk caused the interrupt.
static int INTERRUPT_POWER_ON
          An interrupt kind indicating that the system just started.
static int INTERRUPT_USER
          An interrupt kind indicating that a user program caused the interrupt.
static int SYSCALL_EXEC
          System call to execute a new program.
static int SYSCALL_GET_TIME
           
static int SYSCALL_INPUT
          System call to read text from the console.
static int SYSCALL_JOIN
          System call to wait for a process to terminate.
static int SYSCALL_OUTPUT
          System call to output text on the console.
 
Constructor Summary
Kernel()
           
 
Method Summary
static int interrupt(int kind, int i1, int i2, java.lang.Object o1, java.lang.Object o2, byte[] a)
          This is the only entry into the kernel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERRUPT_USER

public static final int INTERRUPT_USER
An interrupt kind indicating that a user program caused the interrupt. Other parameters depend on the call number.

INTERRUPT_DISK

public static final int INTERRUPT_DISK
An interrupt kind indicating that a disk caused the interrupt. All other parameters will be null or zero.

INTERRUPT_POWER_ON

public static final int INTERRUPT_POWER_ON
An interrupt kind indicating that the system just started. The Kernel should set up any internal state and begin executing the first program.

SYSCALL_OUTPUT

public static final int SYSCALL_OUTPUT
System call to output text on the console.

SYSCALL_INPUT

public static final int SYSCALL_INPUT
System call to read text from the console. This function returns when the user presses [Enter].

SYSCALL_EXEC

public static final int SYSCALL_EXEC
System call to execute a new program. The new program will run in parallel to the current program.

SYSCALL_JOIN

public static final int SYSCALL_JOIN
System call to wait for a process to terminate. This call will not return until the indicated process has run to completion.

SYSCALL_GET_TIME

public static final int SYSCALL_GET_TIME

ERROR_BAD_ARGUMENT_TYPE

public static final int ERROR_BAD_ARGUMENT_TYPE
An error code indicating that one of the system call parameters made no sense.

ERROR_BAD_COMMAND

public static final int ERROR_BAD_COMMAND
An error code indicating that a command passed to SYSCALL_EXEC could not be executed.

ERROR_OUT_OF_RANGE

public static final int ERROR_OUT_OF_RANGE
An error code indicating that one parameter was too big or too small

ERROR_END_OF_FILE

public static final int ERROR_END_OF_FILE
An error code indicating that end of file was reached.

ERROR_IO

public static final int ERROR_IO
An error code indicating that somthing went wrong during an I/O operation.

ERROR_IN_CHILD

public static final int ERROR_IN_CHILD
An error code indicating that a child program caused an exception and crashed.

ERROR_NO_SUCH_PROCESS

public static final int ERROR_NO_SUCH_PROCESS
An error code indicating an attempt to join with a non-existant process
Constructor Detail

Kernel

public Kernel()
Method Detail

interrupt

public static int interrupt(int kind,
                            int i1,
                            int i2,
                            java.lang.Object o1,
                            java.lang.Object o2,
                            byte[] a)
This is the only entry into the kernel.

A user may call this function to perform a system call. In that case, set kind to INTERRUPT_USER and set i1 to the system call number. Other parameters should be set as the system call requires.

A disk may call this function to indicate the current operation has completed. In that case, kind will be INTERRUPT_DISK and all parameters will be zero or null.
Important: If the Disk calls interrupt(), the Kernel should take care of business and return from the interrupt as soon as possible. All Disk I/O is halted while the interrupt is being processed.

The boot code may call this function to indicate that the computer has been turned on and it is time to start the first program and use the disk. In that case, kind will be INTERRUPT_POWER_ON, o1 will point to the Disk to be used, o2 will be a String containing the name of the shell to use, i1 will indicate the size of the buffer cache, and all other parameters will be zero or null.

Since different system calls require different parameters, this method has a variety of arguments of various types. Any one system call will use at most a few of them. The others should be zero or null.

Parameters:
kind - the kind of system call, one of the INTERRUPT_XXX codes.
i1 - the first integer parameter. If kind == INTERRUPT_USER, i1 should be one of the SYSTEM_XXX codes to indicate which system call is being invoked.
i2 - another integer parameter.
o1 - a parameter of some object type.
o2 - another parameter of some object type.
a - a byte-array parameter (generally used for binary input/output).
Returns:
a negative number indicating an error code, or other values depending on the system call.