Last active
August 29, 2015 14:20
-
-
Save aerodame/beb3845611c107901f3e to your computer and use it in GitHub Desktop.
ThreadOS Kernel Snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.lang.reflect.*; | |
import java.io.*; | |
public class Kernel { | |
// Interrupt requests | |
public final static int INTERRUPT_SOFTWARE = 1; // System calls | |
public final static int INTERRUPT_DISK = 2; // Disk interrupts | |
public final static int INTERRUPT_IO = 3; // Other I/O interrupts | |
// System calls | |
public final static int BOOT = 0; // SysLib.boot( ) | |
... | |
public final static int RAWREAD = 5; // SysLib.rawread(int blk, byte b[]) | |
public final static int RAWWRITE= 6; // SysLib.rawwrite(int blk, byte b[]) | |
public final static int SYNC = 7; // SysLib.sync( ) | |
// Return values | |
public final static int OK = 0; | |
public final static int ERROR = -1; | |
// System thread references | |
private static Scheduler scheduler; | |
private static Disk disk; | |
// The heart of Kernel | |
public static int interrupt( int irq, int cmd, int param, Object args ) { | |
TCB myTcb; | |
switch( irq ) { | |
case INTERRUPT_SOFTWARE: // System calls | |
switch( cmd ) { | |
case BOOT: | |
// instantiate and start a scheduler | |
scheduler = new Scheduler( ); | |
scheduler.start( ); | |
// instantiate and start a disk | |
disk = new Disk( 100 ); | |
disk.start( ); | |
return OK; | |
... | |
case RAWREAD: // read a block of data from disk | |
while ( disk.read( param, ( byte[] )args ) == false ) | |
; // busy wait | |
while ( disk.testAndResetReady( ) == false ) | |
; // another busy wait | |
return OK; | |
case RAWWRITE: // write a block of data to disk | |
while ( disk.write( param, ( byte[] )args ) == false ) | |
; // busy wait | |
while ( disk.testAndResetReady( ) == false ) | |
; // another busy wait | |
return OK; | |
case SYNC: // synchronize disk data to a real file | |
while ( disk.sync( ) == false ) | |
; // busy wait | |
while ( disk.testAndResetReady( ) == false ) | |
; // another busy wait | |
return OK; | |
} | |
return ERROR; | |
case INTERRUPT_DISK: // Disk interrupts | |
case INTERRUPT_IO: // other I/O interrupts (not implemented) | |
} | |
return OK; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment