-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSysLib.java
More file actions
118 lines (97 loc) · 3.18 KB
/
SysLib.java
File metadata and controls
118 lines (97 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.util.*;
public class SysLib {
public static int exec( String args[] ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.EXEC, 0, args );
}
public static int join( ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.WAIT, 0, null );
}
public static int boot( ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.BOOT, 0, null );
}
public static int exit( ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.EXIT, 0, null );
}
public static int sleep( int milliseconds ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.SLEEP, milliseconds, null );
}
public static int disk( ) {
return Kernel.interrupt( Kernel.INTERRUPT_DISK,
0, 0, null );
}
public static int cin( StringBuffer s ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.READ, 0, s );
}
public static int cout( String s ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.WRITE, 1, s );
}
public static int cerr( String s ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.WRITE, 2, s );
}
public static int rawread( int blkNumber, byte[] b ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.RAWREAD, blkNumber, b );
}
public static int rawwrite( int blkNumber, byte[] b ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.RAWWRITE, blkNumber, b );
}
public static int sync( ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.SYNC, 0, null );
}
public static int cread( int blkNumber, byte[] b ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.CREAD, blkNumber, b );
}
public static int cwrite( int blkNumber, byte[] b ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.CWRITE, blkNumber, b );
}
public static int flush( ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.CFLUSH, 0, null );
}
public static int csync( ) {
return Kernel.interrupt( Kernel.INTERRUPT_SOFTWARE,
Kernel.CSYNC, 0, null );
}
public static String[] stringToArgs( String s ) {
StringTokenizer token = new StringTokenizer( s," " );
String[] progArgs = new String[ token.countTokens( ) ];
for ( int i = 0; token.hasMoreTokens( ); i++ ) {
progArgs[i] = token.nextToken( );
}
return progArgs;
}
public static void short2bytes( short s, byte[] b, int offset ) {
b[offset] = (byte)( s >> 8 );
b[offset + 1] = (byte)s;
}
public static short bytes2short( byte[] b, int offset ) {
short s = 0;
s += b[offset] & 0xff;
s <<= 8;
s += b[offset + 1] & 0xff;
return s;
}
public static void int2bytes( int i, byte[] b, int offset ) {
b[offset] = (byte)( i >> 24 );
b[offset + 1] = (byte)( i >> 16 );
b[offset + 2] = (byte)( i >> 8 );
b[offset + 3] = (byte)i;
}
public static int bytes2int( byte[] b, int offset ) {
int n = ((b[offset] & 0xff) << 24) + ((b[offset+1] & 0xff) << 16) +
((b[offset+2] & 0xff) << 8) + (b[offset+3] & 0xff);
return n;
}
}