|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectKernel
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.
Disk
,
Library
Nested Class Summary | |
private static class |
Kernel.Launcher
A Launcher instance represents one atomic command being run by the Kernel. |
Field Summary | |
private static BufferedReader |
br
|
private static int |
cacheSize
The size of the disk cache |
private static Disk |
disk
The disk to be used |
static int |
ERROR_BAD_ARGUMENT
An error code indicating that one of the system call parameters made no sense. |
static int |
ERROR_BAD_COMMAND
An error code indicating some unspecified problem running the class passed SYSCALL_EXEC. |
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_CLASS
An error code indicating that the class name passed to SYSCALL_EXEC could not be found. |
static int |
ERROR_NO_MAIN
An error code indicating that the class name passed to SYSCALL_EXEC named a class with no appropriate main() method. |
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_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 | |
private static int |
doExec(String command,
String[] args)
Loads a program and runs it in the background. |
private static int |
doExecAndWait(String command,
String[] args)
Loads a program and runs it. |
private static int |
doInput(StringBuffer sb)
Reads a line from the console into a StringBuffer. |
private static int |
doJoin(int pid)
Waits for a program previous started by doExec to terminate. |
private static int |
doOutput(String msg)
Displays a message on the console. |
private static void |
doPowerOn(int i1,
Object o1,
Object o2)
Performs the actions associated with a POWER_ON interrupt. |
private static void |
doShutdown()
Does any "shutdown" activities required after all activities started by a POWER_ON interrupt have completed. |
static int |
interrupt(int kind,
int i1,
int i2,
Object o1,
Object o2,
byte[] a)
This is the only entry into the kernel. |
Methods inherited from class Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int INTERRUPT_USER
public static final int INTERRUPT_DISK
public static final int INTERRUPT_POWER_ON
public static final int SYSCALL_OUTPUT
public static final int SYSCALL_INPUT
public static final int SYSCALL_EXEC
public static final int SYSCALL_JOIN
public static final int ERROR_BAD_ARGUMENT
public static final int ERROR_NO_CLASS
public static final int ERROR_NO_MAIN
public static final int ERROR_BAD_COMMAND
public static final int ERROR_OUT_OF_RANGE
public static final int ERROR_END_OF_FILE
public static final int ERROR_IO
public static final int ERROR_IN_CHILD
public static final int ERROR_NO_SUCH_PROCESS
private static Disk disk
private static int cacheSize
private static BufferedReader br
Constructor Detail |
public Kernel()
Method Detail |
public static int interrupt(int kind, int i1, int i2, Object o1, Object o2, byte[] a)
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.
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).
private static void doPowerOn(int i1, Object o1, Object o2)
i1
- the first int parameter to the interrupt (the disk cache size)o1
- the first Object parameter to the interrupt (the Disk).o2
- the second Object parameter to the interrupt (the shell
command-line).private static void doShutdown()
private static int doOutput(String msg)
msg
- the message to displayprivate static int doInput(StringBuffer sb)
sb
- a place to put the line of input.private static int doExecAndWait(String command, String[] args)
command
- the program to run.args
- command-line args to pass to the program.
private static int doExec(String command, String[] args)
command
- the program to run.args
- command-line args to pass to the program.
private static int doJoin(int pid)
pid
- the process id of the program.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |