/* * divide ts into chinese, english, or, chiglish words * bm :bitmap initialized on word_set() * ts :input string e.g. 早上天气不错,确被hold姐雷翻了。 * len :input string size * cbk :the function called on words founded */ void word_split(char *bm, char *ts, size_t len, void (*cbk)(char *s, size_t len)) { char *s, *t, *e, *es; unsigned int pos; int r; int i; if (!bm || !ts || !cbk || len <= 0) return; s = ts; while (*s) { es = NULL; t = s; r = len - (s - ts); for (i = 0; i < MAX_PHRASE_S_LEN && r >= 0; ) { e = s + i; BITMAP_POS(s, i, pos); if (BITMAP_GET(bm, pos)) { t = s + i; cbk(s, e - s); } while (*e && e - ts < len) { if ((*e & 0xE0) != 0xE0 || (*(e+1) & 0x80) != 0x80 || (*(e+2) & 0x80) != 0x80) { if (!es) es = e; e++; } else break; } if (e != s + i) { if (i == 0) { t = e; cbk(es, e - es); } i = i + (e - es); r = r - (e - es); } else { i = i + 3; r = r - 3; } } if (t > s) s = t; else s = s + 3; } }
/* * set an chinese word into bitmap * normarlly called mannny times on process initialize * parameters: * bm :bitmap which ts set into * ts :an chinese word, e.g. 天气 */ void word_set(char *bm, char *ts) { unsigned int pos = 0; if (!ts || strlen(ts) > MAX_PHRASE_S_LEN) return; BITMAP_POS(ts, strlen(ts), pos); //char *s = ts; int len = strlen(ts); if (BITMAP_GET(bm, pos)) { //printf("%x seted\n", pos); } //if (pos == 0x24e1373a) printf("%s seted\n", ts); BITMAP_SET(bm, pos); }
void CDECL startap_main(init32_struct_t *p_init32, init64_struct_t *p_init64, mon_startup_struct_t *p_startup, uint32_t entry_point) { uint32_t application_procesors; if (NULL != p_init32) { /* wakeup APs */ application_procesors = ap_procs_startup(p_init32, p_startup); } else { application_procesors = 0; } #ifdef UNIPROC application_procesors = 0; #endif gp_init64 = p_init64; if (BITMAP_GET(p_startup->flags, MON_STARTUP_POST_OS_LAUNCH_MODE) == 0) { /* update the number of processors in mon_startup_struct_t for pre os * launch */ p_startup->number_of_processors_at_boot_time = application_procesors + 1; } application_params.ep = entry_point; application_params.any_data1 = (void *)p_startup; application_params.any_data2 = NULL; application_params.any_data3 = NULL; /* first launch application on AP cores */ if (application_procesors > 0) { ap_procs_run((func_continue_ap_t)start_application, &application_params); } /* and then launch application on BSP */ start_application(0, &application_params); }
int main(int argc, char **argv, char **envp) { char ts[1000]; FILE *fp; size_t len; int cnt; char *bm = calloc(1, 0xFFFFFFFF / 0x8); /* about 512MB */ #if 1 cnt = 0; if ((fp = fopen("dict.txt", "r"))) { while (fgets(ts, 1000, fp)) { len = strlen(ts)-2; ts[len] = '\0'; if (len <= MAX_PHRASE_S_LEN) { cnt++; word_set(bm, ts); } } printf("%d words seted\n", cnt); } else { printf("open dict.txt failed\n"); return 1; } #endif #if 0 word_set(bm, "专场"); word_set(bm, "专机"); #endif if (argc > 1) { memset(words, sizeof(words), 0x0); wpos = 0; struct timeval tv_s, tv_e; unsigned long usec; gettimeofday(&tv_s, NULL); word_split(bm, argv[1], strlen(argv[1]), on_words); gettimeofday(&tv_e, NULL); usec = (tv_e.tv_sec - tv_s.tv_sec) * 1000000ul + (tv_e.tv_usec - tv_s.tv_usec); printf("parse finished in %.6f seconds\n", (double)(usec / 1000000.0)); printf("words:\n"); out_words(); } else { unsigned int i; cnt = 0; for (i = 0; i < 0xFFFFFFFF; i++) { if (BITMAP_GET(bm, i)) cnt++; } printf("%d distinct word\n", cnt); } free(bm); return 0; }
/* * Init guest except of guest memory * Return NULL on error */ static guest_handle_t init_single_guest(uint32_t number_of_host_processors, const mon_guest_startup_t *gstartup, const mon_policy_t *guest_policy) { guest_handle_t guest; uint32_t cpu_affinity = 0; uint32_t bit_number; boolean_t ready_to_run = FALSE; if ((gstartup->size_of_this_struct != sizeof(mon_guest_startup_t)) || (gstartup->version_of_this_struct != MON_GUEST_STARTUP_VERSION)) { MON_LOG(mask_anonymous, level_trace, "ASSERT: unknown guest struct: size: %#x version %d\n", gstartup->size_of_this_struct, gstartup->version_of_this_struct); return NULL; } /* create guest */ guest = guest_register(gstartup->guest_magic_number, gstartup->physical_memory_size, gstartup->cpu_affinity, guest_policy); if (!guest) { MON_LOG(mask_anonymous, level_trace, "Cannot create guest with the following params: \n" "\t\tguest_magic_number = %#x\n" "\t\tphysical_memory_size = %#x\n" "\t\tcpu_affinity = %#x\n", gstartup->guest_magic_number, gstartup->physical_memory_size, gstartup->cpu_affinity); return NULL; } fvs_initialize(guest, number_of_host_processors); vmexit_guest_initialize(guest_get_id(guest)); if (gstartup->devices_count != 0) { MON_LOG(mask_anonymous, level_trace, "ASSERT: devices virtualization is not supported yet\n" "\t\tguest_magic_number = %#x\n" "\t\tdevices_count = %d\n", gstartup->guest_magic_number, gstartup->devices_count); MON_DEADLOOP(); return NULL; } if (gstartup->image_size) { guest_set_executable_image(guest, (const uint8_t *)gstartup->image_address, gstartup->image_size, gstartup->image_offset_in_guest_physical_memory, BITMAP_GET(gstartup->flags, MON_GUEST_FLAG_IMAGE_COMPRESSED) != 0); } if (BITMAP_GET(gstartup->flags, MON_GUEST_FLAG_REAL_BIOS_ACCESS_ENABLE) != 0) { guest_set_real_BIOS_access_enabled(guest); } msr_vmexit_guest_setup(guest); /* setup MSR-related control structure */ /* init cpus. */ /* first init CPUs that has initial state */ cpu_affinity = gstartup->cpu_affinity; if (cpu_affinity == 0) { MON_LOG(mask_anonymous, level_trace, "ASSERT: guest without CPUs:\n" "\t\tguest_magic_number = %#x\n" "\t\tcpu_affinity = %#x\n", gstartup->guest_magic_number, gstartup->cpu_affinity); MON_DEADLOOP(); return NULL; } ready_to_run = (BITMAP_GET(gstartup->flags, MON_GUEST_FLAG_LAUNCH_IMMEDIATELY) != 0); if (cpu_affinity == (uint32_t)-1) { /* special case - run on all existing CPUs */ for (bit_number = 0; bit_number < number_of_host_processors; bit_number++) { add_cpu_to_guest(gstartup, guest, (cpu_id_t)bit_number, ready_to_run); MON_LOG(mask_anonymous, level_trace, "CPU #%d added successfully to the current guest\n", bit_number); } } #ifdef DEBUG guest_register_vmcall_services(guest); #endif return guest; }