JVM test

Dependencies:   mbed

Committer:
lynxeyed_atsu
Date:
Mon Aug 26 15:02:07 2013 +0000
Revision:
6:b9d0d96b052f
Parent:
5:047542b65d00
Child:
7:2a384a077520
Fixed to boot class file from flash.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lynxeyed_atsu 5:047542b65d00 1
lynxeyed_atsu 5:047542b65d00 2 #include <stdio.h>
lynxeyed_atsu 5:047542b65d00 3 #include <string.h>
lynxeyed_atsu 5:047542b65d00 4
lynxeyed_atsu 5:047542b65d00 5 #include "ravem.h"
chris 0:cf8a48b1fb23 6
lynxeyed_atsu 5:047542b65d00 7 ///* Main Program */
lynxeyed_atsu 5:047542b65d00 8 int main (void) {
lynxeyed_atsu 5:047542b65d00 9
lynxeyed_atsu 5:047542b65d00 10 hardware_init();
lynxeyed_atsu 5:047542b65d00 11 uart_init(9600);
lynxeyed_atsu 6:b9d0d96b052f 12 bc_init();
lynxeyed_atsu 5:047542b65d00 13 pool_init();
lynxeyed_atsu 5:047542b65d00 14
lynxeyed_atsu 5:047542b65d00 15 uart_print("LPC11U24 mbed JVM Start\r\n");
lynxeyed_atsu 5:047542b65d00 16 uart_print("please wait...\r\n\r\n");
chris 0:cf8a48b1fb23 17
lynxeyed_atsu 5:047542b65d00 18 int32_t thread_count = 0,lp,method_all_end;
lynxeyed_atsu 5:047542b65d00 19 // Initialize Operand Stack and local Register
lynxeyed_atsu 5:047542b65d00 20 class_st *p;
chris 1:eabc6f5b51d6 21
lynxeyed_atsu 5:047542b65d00 22 p = (class_st *)pool_alloc(sizeof(class_st) * 1);
lynxeyed_atsu 5:047542b65d00 23 if(p == NULL)uart_print("error!");
lynxeyed_atsu 5:047542b65d00 24 p[0] = seekCodeArrtibute(p[0], "main", 4); //main_attribute
lynxeyed_atsu 5:047542b65d00 25 p[0].field_mem_reg = NULL;
lynxeyed_atsu 5:047542b65d00 26 p[0].field_num = 0;
lynxeyed_atsu 5:047542b65d00 27 p[0].local_reg = (int *)pool_alloc(sizeof(int) * p[0].local_num);
lynxeyed_atsu 5:047542b65d00 28 p[0].op_stack_type = (int *)pool_alloc(sizeof(int) * p[0].stack_num);
lynxeyed_atsu 5:047542b65d00 29 p[0].op_stack = (int *)pool_alloc(sizeof(int) * p[0].stack_num);
lynxeyed_atsu 5:047542b65d00 30 p[0].op_stack_type[0] = 0;
lynxeyed_atsu 5:047542b65d00 31 p[0].threadCommand = Thread_Active;
lynxeyed_atsu 5:047542b65d00 32 p[0].myThreadNum = 0;
lynxeyed_atsu 5:047542b65d00 33
lynxeyed_atsu 5:047542b65d00 34
lynxeyed_atsu 5:047542b65d00 35 while(1){
lynxeyed_atsu 5:047542b65d00 36 for(lp = 0 ; lp < thread_count + 1 ;lp++){
lynxeyed_atsu 5:047542b65d00 37 if((p[lp].threadCommand == Thread_Active)||
lynxeyed_atsu 5:047542b65d00 38 (p[lp].threadCommand == Thread_inSleep)){
lynxeyed_atsu 5:047542b65d00 39 p[lp] = decodeVM(p[lp]);
lynxeyed_atsu 5:047542b65d00 40 }
lynxeyed_atsu 5:047542b65d00 41 }
lynxeyed_atsu 5:047542b65d00 42 switch(p[0].threadCommand){
lynxeyed_atsu 6:b9d0d96b052f 43 case Thread_getInitMethodWithStack:
lynxeyed_atsu 6:b9d0d96b052f 44 thread_count++;
lynxeyed_atsu 6:b9d0d96b052f 45
lynxeyed_atsu 6:b9d0d96b052f 46 p = (class_st *)pool_realloc((int *)p,sizeof(class_st)*(1 + thread_count));
lynxeyed_atsu 6:b9d0d96b052f 47 if(p == NULL)uart_print("error!");
lynxeyed_atsu 6:b9d0d96b052f 48 p[thread_count] = seekCodeArrtibute(p[thread_count], "<init>", 6); // init
lynxeyed_atsu 6:b9d0d96b052f 49 p[thread_count].field_mem_reg = NULL;
lynxeyed_atsu 6:b9d0d96b052f 50 p[thread_count].field_num = 0;
lynxeyed_atsu 6:b9d0d96b052f 51 p[thread_count].local_reg = (int *)pool_alloc(sizeof(int) * p[thread_count].local_num);
lynxeyed_atsu 6:b9d0d96b052f 52 p[thread_count].op_stack_type = (int *)pool_alloc(sizeof(int) * p[thread_count].stack_num);
lynxeyed_atsu 6:b9d0d96b052f 53 p[thread_count].op_stack = (int *)pool_alloc(sizeof(int) * p[thread_count].stack_num);
lynxeyed_atsu 6:b9d0d96b052f 54 p[thread_count].op_stack_type[0] = 0;
lynxeyed_atsu 6:b9d0d96b052f 55 p[thread_count].threadCommand = Thread_init;
lynxeyed_atsu 6:b9d0d96b052f 56
lynxeyed_atsu 6:b9d0d96b052f 57 // copy stack -> local variable
lynxeyed_atsu 6:b9d0d96b052f 58 for(lp = p[0].threadArg+1; lp != 0 ; lp--){
lynxeyed_atsu 6:b9d0d96b052f 59 p[thread_count].local_reg[lp] = getIntegerFromOperandStack(p[0]);
lynxeyed_atsu 6:b9d0d96b052f 60 }
lynxeyed_atsu 6:b9d0d96b052f 61
lynxeyed_atsu 6:b9d0d96b052f 62 while(p[thread_count].threadCommand != Thread_returned){
lynxeyed_atsu 6:b9d0d96b052f 63 p[thread_count] = decodeVM(p[thread_count]);
lynxeyed_atsu 6:b9d0d96b052f 64 }
lynxeyed_atsu 6:b9d0d96b052f 65
lynxeyed_atsu 6:b9d0d96b052f 66 p[thread_count].threadCommand = Thread_initIsDone;
lynxeyed_atsu 6:b9d0d96b052f 67 p[0].threadCommand = Thread_Active;
lynxeyed_atsu 6:b9d0d96b052f 68 break;
lynxeyed_atsu 6:b9d0d96b052f 69
lynxeyed_atsu 6:b9d0d96b052f 70 case Thread_getStartMethod:
lynxeyed_atsu 6:b9d0d96b052f 71 for(lp = 0 ; lp <= thread_count + 1 ; lp++){
lynxeyed_atsu 6:b9d0d96b052f 72 if(p[lp].threadCommand == Thread_initIsDone)break;
lynxeyed_atsu 6:b9d0d96b052f 73 }
lynxeyed_atsu 6:b9d0d96b052f 74 if(p[lp].threadCommand != Thread_initIsDone){
lynxeyed_atsu 5:047542b65d00 75 thread_count++;
lynxeyed_atsu 6:b9d0d96b052f 76 p = (class_st *)pool_realloc((int *)p,sizeof(class_st)*(1+thread_count));
lynxeyed_atsu 5:047542b65d00 77 if(p == NULL)uart_print("error!");
lynxeyed_atsu 6:b9d0d96b052f 78 lp = thread_count;
lynxeyed_atsu 5:047542b65d00 79
lynxeyed_atsu 5:047542b65d00 80 p[lp] = seekCodeArrtibute(p[lp], "run", 3); // run method(start() calls this method)
lynxeyed_atsu 6:b9d0d96b052f 81
lynxeyed_atsu 6:b9d0d96b052f 82 p[lp].local_reg = (int *)pool_alloc(sizeof(int) * p[lp].local_num);
lynxeyed_atsu 6:b9d0d96b052f 83 if(p[lp].local_reg == NULL)uart_print("error!");
lynxeyed_atsu 6:b9d0d96b052f 84 p[lp].op_stack_type = (int *)pool_alloc(sizeof(int) * p[lp].stack_num);
lynxeyed_atsu 6:b9d0d96b052f 85 if(p[lp].op_stack_type == NULL)uart_print("error!");
lynxeyed_atsu 6:b9d0d96b052f 86 p[lp].op_stack = (int *)pool_alloc( sizeof(int) * p[lp].stack_num);
lynxeyed_atsu 6:b9d0d96b052f 87 if(p[lp].op_stack == NULL)uart_print("error!");
lynxeyed_atsu 5:047542b65d00 88 p[lp].op_stack_type[0] = 0;
lynxeyed_atsu 5:047542b65d00 89 p[lp].threadCommand = Thread_Active;
lynxeyed_atsu 5:047542b65d00 90 p[lp].myThreadNum = lp;
lynxeyed_atsu 5:047542b65d00 91 p[0].threadCommand = Thread_Active;
lynxeyed_atsu 6:b9d0d96b052f 92 break;
lynxeyed_atsu 6:b9d0d96b052f 93 }
lynxeyed_atsu 6:b9d0d96b052f 94
lynxeyed_atsu 6:b9d0d96b052f 95 p[lp] = seekCodeArrtibute(p[lp], "run", 3); // run method(start() calls this method)
lynxeyed_atsu 6:b9d0d96b052f 96 if(p[lp].local_reg == NULL)uart_print("pointr error!\r\n");
lynxeyed_atsu 6:b9d0d96b052f 97 p[lp].local_reg = (int *)pool_realloc(p[lp].local_reg, sizeof(int) * p[lp].local_num);
lynxeyed_atsu 6:b9d0d96b052f 98 if(p[lp].local_reg == NULL)uart_print("pointr error!\r\n");
lynxeyed_atsu 6:b9d0d96b052f 99 p[lp].op_stack_type = (int *)pool_realloc(p[lp].op_stack_type,sizeof(int) * p[lp].stack_num);
lynxeyed_atsu 6:b9d0d96b052f 100 if(p[lp].op_stack_type == NULL)uart_print("pointr error!\r\n");
lynxeyed_atsu 6:b9d0d96b052f 101 p[lp].op_stack = (int *)pool_realloc(p[lp].op_stack, sizeof(int) * p[lp].stack_num);
lynxeyed_atsu 6:b9d0d96b052f 102 if(p[lp].op_stack == NULL)uart_print("pointr error!\r\n");
lynxeyed_atsu 6:b9d0d96b052f 103 p[lp].op_stack_type[0] = 0;
lynxeyed_atsu 6:b9d0d96b052f 104 p[lp].threadCommand = Thread_Active;
lynxeyed_atsu 6:b9d0d96b052f 105 p[lp].myThreadNum = lp;
lynxeyed_atsu 6:b9d0d96b052f 106 p[0].threadCommand = Thread_Active;
lynxeyed_atsu 6:b9d0d96b052f 107
lynxeyed_atsu 6:b9d0d96b052f 108 break;
chris 1:eabc6f5b51d6 109 }
lynxeyed_atsu 5:047542b65d00 110 method_all_end = 0;
lynxeyed_atsu 5:047542b65d00 111 for(lp = 0 ; lp < thread_count + 1 ; lp++){
lynxeyed_atsu 5:047542b65d00 112 if(p[lp].threadCommand != Thread_returned) method_all_end = method_all_end + 1;
lynxeyed_atsu 5:047542b65d00 113 }
lynxeyed_atsu 5:047542b65d00 114 if(method_all_end == 0) break;
chris 1:eabc6f5b51d6 115 }
lynxeyed_atsu 5:047542b65d00 116
lynxeyed_atsu 5:047542b65d00 117 // end
lynxeyed_atsu 5:047542b65d00 118 for(lp = 0; lp < thread_count + 1; lp++){
lynxeyed_atsu 5:047542b65d00 119 pool_free(p[lp].local_reg);
lynxeyed_atsu 5:047542b65d00 120 pool_free(p[lp].op_stack_type);
lynxeyed_atsu 5:047542b65d00 121 pool_free(p[lp].op_stack);
lynxeyed_atsu 5:047542b65d00 122 }
lynxeyed_atsu 6:b9d0d96b052f 123 pool_free((int *)&p);
lynxeyed_atsu 5:047542b65d00 124
lynxeyed_atsu 5:047542b65d00 125 p = NULL;
lynxeyed_atsu 5:047542b65d00 126
lynxeyed_atsu 5:047542b65d00 127 uart_print("\r\n\r\nJVM Fin\r\n");
lynxeyed_atsu 5:047542b65d00 128 while(1);
lynxeyed_atsu 5:047542b65d00 129
lynxeyed_atsu 5:047542b65d00 130 }