001 /* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013 package org.jikesrvm.runtime; 014 015 import org.jikesrvm.annotations.GenerateImplementation; 016 import org.jikesrvm.annotations.SysCallTemplate; 017 import org.jikesrvm.scheduler.RVMThread; 018 import org.vmmagic.pragma.Uninterruptible; 019 import org.vmmagic.unboxed.Address; 020 import org.vmmagic.unboxed.Word; 021 import org.vmmagic.unboxed.Extent; 022 import org.vmmagic.unboxed.Offset; 023 024 /** 025 * Support for lowlevel (i.e. non-JNI) invocation of C functions with 026 * static addresses. 027 * <p> 028 * All methods of this class have the following signature: 029 * <pre> 030 * public abstract <TYPE> NAME(<args to pass to sysNAME via native calling convention>) 031 * </pre> 032 * which will call the corresponding method in system call trampoline 033 * with the added function address from the boot image. 034 * <p> 035 * NOTE: From the standpoint of the rest of the VM, an invocation 036 * to a method of SysCall is uninterruptible. 037 * <p> 038 * NOTE: There must be a matching field NAMEIP in BootRecord.java 039 * for each method declared here. 040 */ 041 @Uninterruptible 042 @GenerateImplementation("org.jikesrvm.runtime.SysCallImpl") 043 public abstract class SysCall { 044 045 /** 046 * Actual implementation of the SysCall class. The implementation 047 * is generated from the code in this class during the build process. 048 */ 049 public static final SysCall sysCall; 050 051 static { 052 try { 053 sysCall = (SysCall)Class.forName("org.jikesrvm.runtime.SysCallImpl").newInstance(); 054 } catch (final Exception e) { 055 throw new Error(e); 056 } 057 } 058 059 // lowlevel write to console 060 @SysCallTemplate 061 public abstract void sysConsoleWriteChar(char v); 062 063 @SysCallTemplate 064 public abstract void sysConsoleWriteInteger(int value, int hexToo); 065 066 @SysCallTemplate 067 public abstract void sysConsoleWriteLong(long value, int hexToo); 068 069 @SysCallTemplate 070 public abstract void sysConsoleWriteDouble(double value, int postDecimalDigits); 071 072 // startup/shutdown 073 @SysCallTemplate 074 public abstract void sysExit(int value); 075 @SysCallTemplate 076 public abstract int sysArg(int argno, byte[] buf, int buflen); 077 078 // misc. info on the process -- used in startup/shutdown 079 @SysCallTemplate 080 public abstract int sysGetenv(byte[] varName, byte[] buf, int limit); 081 082 // memory 083 @SysCallTemplate 084 public abstract void sysCopy(Address dst, Address src, Extent cnt); 085 086 @SysCallTemplate 087 public abstract Address sysMalloc(int length); 088 089 @SysCallTemplate 090 public abstract Address sysCalloc(int length); 091 092 @SysCallTemplate 093 public abstract void sysFree(Address location); 094 095 @SysCallTemplate 096 public abstract void sysZeroNT(Address dst, Extent cnt); 097 098 @SysCallTemplate 099 public abstract void sysZero(Address dst, Extent cnt); 100 101 @SysCallTemplate 102 public abstract void sysZeroPages(Address dst, int cnt); 103 104 @SysCallTemplate 105 public abstract void sysSyncCache(Address address, int size); 106 107 /* 108 * Interface to performance events 109 */ 110 @SysCallTemplate 111 public abstract int sysPerfEventInit(int events); 112 @SysCallTemplate 113 public abstract int sysPerfEventCreate(int id, byte[] name); 114 @SysCallTemplate 115 public abstract void sysPerfEventEnable(); 116 @SysCallTemplate 117 public abstract void sysPerfEventDisable(); 118 @SysCallTemplate 119 public abstract int sysPerfEventRead(int id, long[] values); 120 121 // files 122 @SysCallTemplate 123 public abstract int sysStat(byte[] name, int kind); 124 125 @SysCallTemplate 126 public abstract int sysReadByte(int fd); 127 128 @SysCallTemplate 129 public abstract int sysWriteByte(int fd, int data); 130 131 @SysCallTemplate 132 public abstract int sysReadBytes(int fd, Address buf, int cnt); 133 134 @SysCallTemplate 135 public abstract int sysWriteBytes(int fd, Address buf, int cnt); 136 137 @SysCallTemplate 138 public abstract int sysBytesAvailable(int fd); 139 140 @SysCallTemplate 141 public abstract int sysSyncFile(int fd); 142 143 @SysCallTemplate 144 public abstract int sysSetFdCloseOnExec(int fd); 145 146 @SysCallTemplate 147 public abstract int sysAccess(byte[] name, int kind); 148 149 // mmap - memory mapping 150 @SysCallTemplate 151 public abstract Address sysMMap(Address start, Extent length, int protection, int flags, int fd, Offset offset); 152 153 @SysCallTemplate 154 public abstract Address sysMMapErrno(Address start, Extent length, int protection, int flags, int fd, Offset offset); 155 156 @SysCallTemplate 157 public abstract int sysMProtect(Address start, Extent length, int prot); 158 159 @SysCallTemplate 160 public abstract int sysGetPageSize(); 161 162 // threads 163 @SysCallTemplate 164 public abstract int sysNumProcessors(); 165 166 /** 167 * Create a native thread (aka "unix kernel thread", "pthread"). 168 * @param tr 169 * @param ip 170 * @param fp 171 * @return native thread's o/s handle 172 */ 173 @SysCallTemplate 174 public abstract Word sysThreadCreate(Address tr, Address ip, Address fp); 175 176 /** 177 * Tells you if the current system supportes sysNativeThreadBind(). 178 * @return 1 if it's supported, 0 if it isn't 179 */ 180 @SysCallTemplate 181 public abstract int sysThreadBindSupported(); 182 183 @SysCallTemplate 184 public abstract void sysThreadBind(int cpuId); 185 186 @SysCallTemplate 187 public abstract void sysThreadYield(); 188 189 @SysCallTemplate 190 public abstract Word sysGetThreadId(); 191 192 @SysCallTemplate 193 public abstract void sysSetupHardwareTrapHandler(); 194 195 // This implies that the RVMThread is somehow pinned, or else the 196 // pthread key value gets moved. (hence RVMThread is @NonMoving) 197 @SysCallTemplate 198 public abstract int sysStashVMThread(RVMThread vmThread); 199 @SysCallTemplate 200 public abstract void sysThreadTerminate(); 201 /** 202 * Allocate the space for a pthread_mutex (using malloc) and initialize 203 * it using pthread_mutex_init with the recursive mutex options. Note: 204 * it is perfectly OK for the C/C++ code that implements this syscall to 205 * use some other locking mechanism (for example, on systems that don't 206 * have recursive mutexes you could imagine the recursive feature to be 207 * emulated). 208 */ 209 @SysCallTemplate 210 public abstract Word sysMonitorCreate(); 211 /** 212 * Destroy the monitor pointed to by the argument and free its memory 213 * by calling free. 214 */ 215 @SysCallTemplate 216 public abstract void sysMonitorDestroy(Word monitor); 217 @SysCallTemplate 218 public abstract void sysMonitorEnter(Word monitor); 219 @SysCallTemplate 220 public abstract void sysMonitorExit(Word monitor); 221 @SysCallTemplate 222 public abstract void sysMonitorTimedWaitAbsolute(Word monitor, long whenWakeupNanos); 223 @SysCallTemplate 224 public abstract void sysMonitorWait(Word monitor); 225 @SysCallTemplate 226 public abstract void sysMonitorBroadcast(Word monitor); 227 // arithmetic 228 @SysCallTemplate 229 public abstract long sysLongDivide(long x, long y); 230 231 @SysCallTemplate 232 public abstract long sysLongRemainder(long x, long y); 233 234 @SysCallTemplate 235 public abstract float sysLongToFloat(long x); 236 237 @SysCallTemplate 238 public abstract double sysLongToDouble(long x); 239 240 @SysCallTemplate 241 public abstract int sysFloatToInt(float x); 242 243 @SysCallTemplate 244 public abstract int sysDoubleToInt(double x); 245 246 @SysCallTemplate 247 public abstract long sysFloatToLong(float x); 248 249 @SysCallTemplate 250 public abstract long sysDoubleToLong(double x); 251 252 @SysCallTemplate 253 public abstract double sysDoubleRemainder(double x, double y); 254 255 /** 256 * Used to parse command line arguments that are 257 * doubles and floats early in booting before it 258 * is safe to call Float.valueOf or Double.valueOf. 259 * 260 * This aborts in case of errors, with an appropriate error message. 261 * 262 * NOTE: this does not support the full Java spec of parsing a string 263 * into a float. 264 * @param buf a null terminated byte[] that can be parsed 265 * by strtof() 266 * @return the floating-point value produced by the call to strtof() on buf. 267 */ 268 @SysCallTemplate 269 public abstract float sysPrimitiveParseFloat(byte[] buf); 270 271 /** 272 * Used to parse command line arguments that are 273 * bytes and ints early in booting before it 274 * is safe to call Byte.parseByte or Integer.parseInt. 275 * 276 * This aborts in case of errors, with an appropriate error message. 277 * 278 * @param buf a null terminated byte[] that can be parsed 279 * by strtol() 280 * @return the int value produced by the call to strtol() on buf. 281 */ 282 @SysCallTemplate 283 public abstract int sysPrimitiveParseInt(byte[] buf); 284 285 /** Parse memory sizes passed as command-line arguments. 286 */ 287 @SysCallTemplate 288 public abstract long sysParseMemorySize(byte[] sizeName, byte[] sizeFlag, byte[] defaultFactor, int roundTo, 289 byte[] argToken, byte[] subArg); 290 291 // time 292 @SysCallTemplate 293 public abstract long sysCurrentTimeMillis(); 294 295 @SysCallTemplate 296 public abstract long sysNanoTime(); 297 298 @SysCallTemplate 299 public abstract void sysNanoSleep(long howLongNanos); 300 301 // shared libraries 302 @SysCallTemplate 303 public abstract Address sysDlopen(byte[] libname); 304 305 @SysCallTemplate 306 public abstract Address sysDlsym(Address libHandler, byte[] symbolName); 307 308 // system startup pthread sync. primitives 309 @SysCallTemplate 310 public abstract void sysCreateThreadSpecificDataKeys(); 311 312 // system calls for alignment checking 313 @SysCallTemplate 314 public abstract void sysEnableAlignmentChecking(); 315 316 @SysCallTemplate 317 public abstract void sysDisableAlignmentChecking(); 318 319 @SysCallTemplate 320 public abstract void sysReportAlignmentChecking(); 321 322 @SysCallTemplate 323 public abstract Address gcspyDriverAddStream(Address driver, int id); 324 325 @SysCallTemplate 326 public abstract void gcspyDriverEndOutput(Address driver); 327 328 @SysCallTemplate 329 public abstract void gcspyDriverInit(Address driver, int id, Address serverName, Address driverName, Address title, 330 Address blockInfo, int tileNum, Address unused, int mainSpace); 331 332 @SysCallTemplate 333 public abstract void gcspyDriverInitOutput(Address driver); 334 335 @SysCallTemplate 336 public abstract void gcspyDriverResize(Address driver, int size); 337 338 @SysCallTemplate 339 public abstract void gcspyDriverSetTileNameRange(Address driver, int i, Address start, Address end); 340 341 @SysCallTemplate 342 public abstract void gcspyDriverSetTileName(Address driver, int i, Address start, long value); 343 344 @SysCallTemplate 345 public abstract void gcspyDriverSpaceInfo(Address driver, Address info); 346 347 @SysCallTemplate 348 public abstract void gcspyDriverStartComm(Address driver); 349 350 @SysCallTemplate 351 public abstract void gcspyDriverStream(Address driver, int id, int len); 352 353 @SysCallTemplate 354 public abstract void gcspyDriverStreamByteValue(Address driver, byte value); 355 356 @SysCallTemplate 357 public abstract void gcspyDriverStreamShortValue(Address driver, short value); 358 359 @SysCallTemplate 360 public abstract void gcspyDriverStreamIntValue(Address driver, int value); 361 362 @SysCallTemplate 363 public abstract void gcspyDriverSummary(Address driver, int id, int len); 364 365 @SysCallTemplate 366 public abstract void gcspyDriverSummaryValue(Address driver, int value); 367 368 @SysCallTemplate 369 public abstract void gcspyIntWriteControl(Address driver, int id, int tileNum); 370 371 @SysCallTemplate 372 public abstract Address gcspyMainServerAddDriver(Address addr); 373 374 @SysCallTemplate 375 public abstract void gcspyMainServerAddEvent(Address server, int event, Address name); 376 377 @SysCallTemplate 378 public abstract Address gcspyMainServerInit(int port, int len, Address name, int verbose); 379 380 @SysCallTemplate 381 public abstract int gcspyMainServerIsConnected(Address server, int event); 382 383 @SysCallTemplate 384 public abstract Address gcspyMainServerOuterLoop(); 385 386 @SysCallTemplate 387 public abstract void gcspyMainServerSafepoint(Address server, int event); 388 389 @SysCallTemplate 390 public abstract void gcspyMainServerSetGeneralInfo(Address server, Address info); 391 392 @SysCallTemplate 393 public abstract void gcspyMainServerStartCompensationTimer(Address server); 394 395 @SysCallTemplate 396 public abstract void gcspyMainServerStopCompensationTimer(Address server); 397 398 @SysCallTemplate 399 public abstract void gcspyStartserver(Address server, int wait, Address serverOuterLoop); 400 401 @SysCallTemplate 402 public abstract void gcspyStreamInit(Address stream, int id, int dataType, Address name, int minValue, int maxValue, 403 int zeroValue, int defaultValue, Address pre, Address post, int presentation, 404 int paintStyle, int maxStreamIndex, int red, int green, int blue); 405 406 @SysCallTemplate 407 public abstract void gcspyFormatSize(Address buffer, int size); 408 409 @SysCallTemplate 410 public abstract int gcspySprintf(Address str, Address format, Address value); 411 } 412