Beispiel #1
0
void install_binary(const byte* ptr)
{
  installedBinary = (byte *)ptr;

  constantTableBase = __get_constant_base();
  staticFieldsBase = __get_static_fields_base();
  entryClassesBase = __get_entry_classes_base();
  classBase = __get_class_base();
  constantValuesBase = __get_constant_values_base();
  gVMOptions = get_master_record()->runtimeOptions;
}
Beispiel #2
0
Datei: load.c Projekt: h-sun/miss
void readBinary (char *fileName)
{
  int pDesc;
  int pLength;
  int pTotal;
  int pNumRead;
  byte *pBinary;

  pDesc = open (fileName, O_RDONLY | O_BINARY);
  if (pDesc == -1)
    abort_tool ("Unable to open %s\n", fileName);
  pLength = lseek (pDesc, 0, SEEK_END);
  lseek (pDesc, 0, SEEK_SET);
  pBinary = (void *) malloc (pLength);
  pTotal = 0;
  while (pTotal < pLength)
  {
    pNumRead = read (pDesc, pBinary + pTotal, pLength - pTotal);
    if (pNumRead == -1)
    {
      printf ("Unexpected EOF\n");
      exit (1);
    }
    pTotal += pNumRead;
  }
  #if DEBUG_STARTUP
  printf ("Installing binary %d\n", (int) pBinary);
  #endif
  install_binary (pBinary);

  #if DEBUG_STARTUP
  printf ("Checking validity of magic number\n");
  #endif
  if (get_master_record()->magicNumber != MAGIC)
  {
    printf ("Fatal: bad magic number: 0x%X. Linked for RCX?"
            "\n", get_master_record()->magicNumber);
    exit(1);
  }
}
Beispiel #3
0
void run(void)
{
  #if DEBUG_RUNS
  int count = 0;
  #endif

  init_poller();

#if EXECUTE_FROM_FLASH
  {
    MasterRecord *mrec = get_master_record();
    int staticSize = mrec->staticStateLength;
    int statusSize = (mrec->lastClass + 1) * sizeof( classStatusBase[0]);

    staticSize = (staticSize + 1) & ~(1);
    statusSize = (statusSize + 3) & ~(3);

    classStaticStateBase = malloc( staticSize * 2);
    classStatusBase = malloc( statusSize);

    memset( classStatusBase, 0, statusSize);
  }
#endif

  // Initialize binary image state
  initialize_binary();

  // Initialize memory
  {
    TWOBYTES size;

    memory_init ();
#if SEGMENTED_HEAP
    size = EXTRA_MEMORY_SIZE;
    region = (byte *) malloc (size * sizeof (TWOBYTES));
    memory_add_region (region, region + size * sizeof (TWOBYTES));
#endif
    size = MEMORY_SIZE;
    region = (byte *) malloc (size * sizeof (TWOBYTES));
    memory_add_region (region, region + size * sizeof (TWOBYTES));
  }

  // Initialize exceptions
  init_exceptions();
  // Create the boot thread (bootThread is a special global)
  bootThread = (Thread *) new_object_for_class (JAVA_LANG_THREAD);
  
  #if DEBUG_THREADS
  printf ("Created bootThread: %d. Initializing...\n", (int) bootThread);
  #endif
  
  #if DEBUG_RUNS
  for (count = 0; count < 100; count++)
  {
  #endif // DEBUG_RUNS

  #if DEBUG_RCX_MEMORY
  {
    TWOBYTES numNodes, biggest, freeMem;	
    scan_memory (&numNodes, &biggest, &freeMem);
    printf ("nodes = %d\n", (int) numNodes);
    printf ("biggest = %d\n", (int) biggest);
    printf ("freeMem = %d\n", (int) freeMem);
  }
  #endif

  init_threads();
  if (!init_thread (bootThread))
  {
    printf ("Unable to initialize threading module.\n");
    exit (1);	  
  }
  // Execute the bytecode interpreter
  set_program_number (0);
  #if DEBUG_STARTUP
  printf ("Engine starting.\n");
  #endif
  engine();
  // Engine returns when all non-daemon threads are dead
  #if DEBUG_STARTUP
  printf ("Engine finished.\n");
  #endif

  #if DEBUG_RUNS
  }
  #endif // DEBUG_RUNS
}