PUBLIC static FIASCO_INIT_CPU void Kmem::init_cpu(Cpu &cpu) { void *cpu_mem = Kmem_alloc::allocator()->unaligned_alloc(1024); printf("Allocate cpu_mem @ %p\n", cpu_mem); // now initialize the global descriptor table cpu.init_gdt(__alloc(&cpu_mem, Gdt::gdt_max), user_max()); // Allocate the task segment as the last thing from cpu_page_vm // because with IO protection enabled the task segment includes the // rest of the page and the following IO bitmap (2 pages). // // Allocate additional 256 bytes for emergency stack right beneath // the tss. It is needed if we get an NMI or debug exception at // entry_sys_fast_ipc/entry_sys_fast_ipc_c/entry_sys_fast_ipc_log. Address tss_mem = alloc_tss(sizeof(Tss) + 256); assert(tss_mem + sizeof(Tss) + 256 < Mem_layout::Io_bitmap); tss_mem += 256; // this is actually tss_size + 1, including the io_bitmap_delimiter byte size_t tss_size; tss_size = Mem_layout::Io_bitmap + (Mem_layout::Io_port_max / 8) - tss_mem; assert(tss_size < 0x100000); // must fit into 20 Bits cpu.init_tss(tss_mem, tss_size); // force GDT... to memory before loading the registers asm volatile ( "" : : : "memory" ); // set up the x86 CPU's memory model cpu.set_gdt(); cpu.set_ldt(0); cpu.set_ds(Gdt::data_segment()); cpu.set_es(Gdt::data_segment()); cpu.set_ss(Gdt::gdt_data_kernel | Gdt::Selector_kernel); cpu.set_fs(Gdt::gdt_data_user | Gdt::Selector_user); cpu.set_gs(Gdt::gdt_data_user | Gdt::Selector_user); cpu.set_cs(); // and finally initialize the TSS cpu.set_tss(); init_cpu_arch(cpu, &cpu_mem); }
static void target_func(double* p, double *f, double* g, int n, void* data) { int i; lbfgsb_param *param = (lbfgsb_param*)data; double weight = 0, error = 0, consts = 0.0, consts2 = 0.0; double sum = 0.0; for(i = 0; i < param->moneyness_size; i++) { double x = param->log_moneyness[i]; double sig = param->quotes[i]; double var_vec = sig*sig; double var_cal = svi(p, x); error += exp(x*3.0) * pow(var_cal - var_vec, 2); consts += user_min(var_cal, 0.0) * -0.1; } // calculate constraints 1 consts = exp(user_max(p[1] * (1.0 + fabs(p[4])) * param->T - 4.0, 0.0) ) - 1.0; consts2= exp(consts) - 1.0; *f = error + consts + consts2; }