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