/* u2_wr_init(): ** ** Install an empty wire within `hat_r` and `mat_r` in the loom, ** with memory model `hip`. ** ** Returns ray to wire, which always equalls the passed `mat_r`. */ u2_ray u2_wr_init(c3_m hip_m, u2_ray hat_r, u2_ray mat_r) { u2_ray wir_r; wir_r = u2_rl_init(hip_m, hat_r, mat_r); u2_rail_hat_r(wir_r) += (c3_wiseof(u2_loom_wire) - c3_wiseof(u2_loom_rail)); #if 1 u2_wire_bas_r(wir_r) = 0; #endif u2_wire_kit_r(wir_r) = 0; u2_cs_init(u2_wire_des_r(wir_r)); /* Trace stack, garbage. */ { u2_wire_tax(wir_r) = u2_nul; u2_wire_lan(wir_r) = u2_yes; } /* Permanent basket = 1/16 of address space. */ { u2_ray bas_r; bas_r = u2_rl_leap_part(wir_r, c3__sand, 1, 16, 0); u2_wire_bas_r(wir_r) = bas_r; #if 0 fprintf(stderr, "bas_r %d, hat %d, mat %d, cap %d, rut %d\n", bas_r >> LoomPageWords, u2_rail_hat_r(bas_r) >> LoomPageWords, u2_rail_mat_r(bas_r) >> LoomPageWords, u2_rail_cap_r(bas_r) >> LoomPageWords, u2_rail_rut_r(bas_r) >> LoomPageWords); fprintf(stderr, "wir_r %d, hat %d, mat %d, cap %d, rut %d\n", wir_r >> LoomPageWords, u2_rail_hat_r(wir_r) >> LoomPageWords, u2_rail_mat_r(wir_r) >> LoomPageWords, u2_rail_cap_r(wir_r) >> LoomPageWords, u2_rail_rut_r(wir_r) >> LoomPageWords); #endif // u2_ba_init(wir_r, 0); } #if 1 /* Host control. */ { u2_ho_push(); } #endif /* Basic performance tracking. */ { u2_wire_bex_r(wir_r) = u2_rl_ralloc(wir_r, c3_wiseof(u2_loom_benx)); u2_bx_boot(wir_r); } /* New performance tracking. */ { u2_wire_rac_r(wir_r) = u2_tx_init(wir_r); } /* Global namespace. */ { u2_wire_hev_r(wir_r) = u2_hv_init(wir_r); } /* OS kernel. */ { u2_wire_arv_r(wir_r) = u2_rl_ralloc(wir_r, c3_wiseof(u2_reck)); } return wir_r; }
c3_i main(c3_i argc, c3_c** argv) { // set both logging systems to unit-ed // u2K->inited_t = c3_false; c3_w kno_w; _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); // Parse options. // if ( u2_no == _main_getopt(argc, argv) ) { u2_ve_usage(argc, argv); return 1; } u2_ve_sysopt(); printf("~\n"); printf("welcome.\n"); printf("vere: urbit home is %s\n", u2_Host.cpu_c); printf("vere: hostname is %s\n", u2_Host.ops_u.nam_c); if ( u2_yes == u2_Host.ops_u.dem && u2_no == u2_Host.ops_u.bat ) { printf("Starting daemon\n"); } // Seed prng. Don't panic -- just for fuzz testing and election timeouts. // srand(getpid()); // Instantiate process globals. { u2_wr_check_init(u2_Host.cpu_c); u2_Host.xit_i = 0; if ( (u2_no == u2_Host.ops_u.nuu) && (u2_yes == u2_loom_load()) ) { u2_Host.wir_r = u2_ray_of(0, 0); u2_Wire = u2_Host.wir_r; u2_Host.arv_u = u2_Arv; u2_Arv->ova.egg_u = u2_Arv->ova.geg_u = 0; u2_lo_grab("init", u2_none); // Horrible ancient stuff. // kno_w = u2_Host.arv_u->kno_w; u2_Host.kno_w = kno_w; u2_ho_push(); } else { u2_loom_boot(); u2_Host.wir_r = u2_wr_init(c3__rock, u2_ray_of(0, 0), u2_ray_of(1, 0)); u2_Wire = u2_Host.wir_r; u2_Host.arv_u = u2_Arv; } } // If we have not loaded from checkpoint, build kernel. // if ( 0 != u2_Host.arv_u->ent_d ) { u2_reck_time(u2_Host.arv_u); u2_reck_numb(u2_Host.arv_u); { c3_c* dyt_c = u2_cr_string(u2_Host.arv_u->wen); printf("time: %s\n", dyt_c); free(dyt_c); } } else { // Set outside bail trap. Should not be used, but you never know... // if ( 0 != u2_cm_trap() ) { u2_ve_panic(argc, argv); } else { // Set boot and goal stages. { if ( (0 == u2_Host.ops_u.kno_w) || (u2_Host.ops_u.kno_w > 255) ) { kno_w = DefaultKernel; } else { kno_w = u2_Host.ops_u.kno_w; } } // Load the system. // { u2_Host.kno_w = u2_Host.ops_u.kno_w; u2_reck_boot(u2_Host.arv_u); } u2_cm_done(); } } // Install signal handlers and set buffers. // // Note that we use the sigmask-restoring variant. Essentially, when // we get a signal, we force the system back into the just-booted state. // If anything goes wrong during boot (above), it's curtains. { if ( 0 != sigsetjmp(Signal_buf, 1) ) { switch ( Sigcause ) { case sig_overflow: printf("[stack overflow]\r\n"); break; case sig_interrupt: printf("[interrupt]\r\n"); break; default: printf("[signal error!]\r\n"); break; } Sigcause = sig_none; signal(SIGINT, SIG_DFL); stackoverflow_deinstall_handler(); // Print the trace, do a GC, etc. // // This is half-assed at present, so we exit. // u2_lo_sway(0, u2k(u2_wire_tax(u2_Wire))); u2_lo_bail(u2_Host.arv_u); exit(1); } #if 1 if ( -1 == stackoverflow_install_handler (overflow_handler, Sigstk, SIGSTKSZ) ) { fprintf(stderr, "overflow_handler: install failed\n"); exit(1); } signal(SIGINT, interrupt_handler); signal(SIGIO, SIG_IGN); #endif } u2_lo_grab("main", u2_none); // booted in admin mode: do a task, then exit // booted in user mode: do command loop if (u2_Host.ops_u.adm_c != 0) { if (strcmp(u2_Host.ops_u.adm_c, "edmp") ==0) { u2_egz_admin_dump_egz(); } else if (strcmp(u2_Host.ops_u.adm_c, "etok") ==0) { u2_kafka_admin_egz_to_kafka(); } else if (strcmp(u2_Host.ops_u.adm_c, "ktoe") ==0) { u2_kafka_admin_kafka_to_egz(); } else if (strcmp(u2_Host.ops_u.adm_c, "kcnf") ==0) { u2_lo_loop(); } // do it in the app else { fprintf(stderr, "unsupported admin mode command %s\n", u2_Host.ops_u.adm_c); exit(1); } } else { u2_lo_loop(); } return 0; }