void Pl_Execute_A_Continuation(CodePtr codep) { Save_Machine_Regs(p_buff_save); cont_jmp = codep; longjmp(*p_jumper, 3); }
static void Call_Prolog_Success(void) { #ifdef M_ix86_darwin /* see comment in Ma2Asm/ix86_any.c */ asm("subl $4,%esp"); #elif defined(M_x86_64) /* see comment in Ma2Asm/x86_64_any.c */ asm("subq $8,%rsp"); #endif Save_Machine_Regs(p_buff_save); longjmp(*p_jumper, 1); }
/*-------------------------------------------------------------------------* * CALL_NEXT * * * * Call_Next saves the context with setjmp. Since Call_Prolog can be nested* * we handle a stack of jumpers (i.e. contexts) directely in the C stack. * * The global variables p_jumper is the top of the stack and points to the * * current jumper. Similarly for the stack of machine register save buffers* *-------------------------------------------------------------------------*/ static Bool Call_Next(CodePtr codep) { int jmp_val; jmp_buf *old_jumper = p_jumper; jmp_buf new_jumper; WamWord *old_buff_save = p_buff_save; WamWord buff_save_machine_regs[NB_OF_USED_MACHINE_REGS + 1]; /* +1 if = 0 */ #if 0 WamWord buff_save_all_regs[NB_OF_REGS]; #endif p_jumper = &new_jumper; p_buff_save = buff_save_machine_regs; #if 0 Save_All_Regs(buff_save_all_regs); #endif Save_Machine_Regs(buff_save_machine_regs); jmp_val = setjmp(*p_jumper); Restore_Machine_Regs(buff_save_machine_regs); if (jmp_val == 0) /* normal call to codep */ Pl_Call_Compiled(codep); if (jmp_val == 3) /* return with a continuation in jmp_val */ Pl_Call_Compiled(cont_jmp); /* normal return */ p_jumper = old_jumper; p_buff_save = old_buff_save; if (jmp_val < 0) /* false: restore WAM registers */ { #if 0 Restore_All_Regs(buff_save_all_regs); #endif return FALSE; } return jmp_val; /* 1 (TRUE) or 3 (exception) */ }
void Pl_Exit_With_Exception(void) { Save_Machine_Regs(p_buff_save); longjmp(*p_jumper, 2); }
/*-------------------------------------------------------------------------* * PL_START_PROLOG * * * *-------------------------------------------------------------------------*/ int Pl_Start_Prolog(int argc, char *argv[]) { int i, x; char *p; setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); /* make sure floats come out right... */ Pl_Init_Machine(); pl_os_argc = argc; pl_os_argv = argv; Set_Line_Buf(stdout); Set_Line_Buf(stderr); for (i = 0; i < NB_OF_STACKS; i++) { if (pl_fd_init_solver == NULL && strcmp(pl_stk_tbl[i].name, "cstr") == 0) { /* FD solver not linked */ pl_stk_tbl[i].size = 0; continue; } if ((pl_stk_tbl[i].size = KBytes_To_Wam_Words(*(pl_stk_tbl[i].p_def_size))) == 0) pl_stk_tbl[i].size = pl_stk_tbl[i].default_size; if (!pl_fixed_sizes && *pl_stk_tbl[i].env_var_name) { p = (char *) getenv(pl_stk_tbl[i].env_var_name); if (p && *p) { sscanf(p, "%d", &x); pl_stk_tbl[i].size = KBytes_To_Wam_Words(x); } } } Pl_M_Allocate_Stacks(); Save_Machine_Regs(init_buff_regs); #ifndef NO_MACHINE_REG_FOR_REG_BANK Init_Reg_Bank(Global_Stack); /* allocated X regs + other non alloc regs */ Global_Stack += REG_BANK_SIZE; /* at the beginning of the heap */ Global_Size -= REG_BANK_SIZE; #endif /* must be changed to store global info (see the debugger) */ heap_actual_start = Global_Stack; Pl_Init_Atom(); Pl_Init_Pred(); Pl_Init_Oper(); #ifndef NO_USE_LINEDIT if (pl_le_initialize != NULL) pl_use_gui = (*pl_le_initialize)(); else #endif pl_use_gui = 0; if (pl_init_stream_supp) (*pl_init_stream_supp)(); Pl_Reset_Prolog(); Pl_Fd_Init_Solver(); Pl_Find_Linked_Objects(); return nb_user_directives; }
/*-------------------------------------------------------------------------* * CTRL_C_MANAGER * * * *-------------------------------------------------------------------------*/ void Pl_Save_Regs_For_Signal(void) { Save_Machine_Regs(buff_save_machine_regs); }
/*-------------------------------------------------------------------------* * PL_START_PROLOG * * * *-------------------------------------------------------------------------*/ int Pl_Start_Prolog(int argc, char *argv[]) { int i, x; char *p; void (*copy_of_pl_init_stream_supp)() = Pl_Dummy_Ptr(pl_init_stream_supp); #if defined(_WIN32) || defined(__CYGWIN__) DWORD y; #endif Set_Locale(); pl_os_argc = argc; pl_os_argv = argv; pl_home = Get_Prolog_Path(argv[0], &pl_devel_mode); Pl_Init_Machine(); Set_Line_Buf(stdout); Set_Line_Buf(stderr); for (i = 0; i < NB_OF_STACKS; i++) { if (pl_fd_init_solver == NULL && strcmp(pl_stk_tbl[i].name, "cstr") == 0) { /* FD solver not linked */ pl_stk_tbl[i].size = 0; continue; } if ((pl_stk_tbl[i].size = KBytes_To_Wam_Words(*(pl_stk_tbl[i].p_def_size))) == 0) pl_stk_tbl[i].size = pl_stk_tbl[i].default_size; if (!pl_fixed_sizes && *pl_stk_tbl[i].env_var_name) { p = (char *) getenv(pl_stk_tbl[i].env_var_name); if (p && *p) { sscanf(p, "%d", &x); pl_stk_tbl[i].size = KBytes_To_Wam_Words(x); } #if defined(_WIN32) || defined(__CYGWIN__) if (Read_Windows_Registry(pl_stk_tbl[i].env_var_name, REG_DWORD, &y, sizeof(x))) pl_stk_tbl[i].size = KBytes_To_Wam_Words(y); #endif } } /* similar treatment for max_atom */ if ((pl_max_atom = pl_def_max_atom) == 0) pl_max_atom = DEFAULT_MAX_ATOM; if (!pl_fixed_sizes) { p = (char *) getenv(ENV_VAR_MAX_ATOM); if (p && *p) { sscanf(p, "%d", &x); pl_max_atom = x; } #if defined(_WIN32) || defined(__CYGWIN__) if (Read_Windows_Registry(ENV_VAR_MAX_ATOM, REG_DWORD, &y, sizeof(x))) pl_max_atom = y; #endif } Pl_Allocate_Stacks(); Save_Machine_Regs(init_buff_regs); #ifndef NO_MACHINE_REG_FOR_REG_BANK Init_Reg_Bank(Global_Stack); /* allocated X regs + other non alloc regs */ Global_Stack += REG_BANK_SIZE; /* at the beginning of the heap */ Global_Size -= REG_BANK_SIZE; #endif /* must be changed to store global info (see the debugger) */ heap_actual_start = Global_Stack; Pl_Init_Atom(); Pl_Init_Pred(); Pl_Init_Oper(); pl_le_mode = 0; /* not compiled with linedit or deactivated (using env var) */ #ifndef NO_USE_LINEDIT if (pl_le_initialize != NULL) pl_le_mode = (*pl_le_initialize)(); #endif if (copy_of_pl_init_stream_supp) (*copy_of_pl_init_stream_supp)(); Pl_Reset_Prolog(); Pl_Fd_Init_Solver(); Pl_Find_Linked_Objects(); return nb_user_directives; }
/*-------------------------------------------------------------------------* * MAIN * * * *-------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { int i = 0; #if defined(FC_USED_TO_COMPILE_CORE) #ifdef FAST printf("check running with FC (fast call)\n"); #else printf("check running without FC (NO fast call)\n"); #endif #elif !defined(FC_USED_TO_COMPILE_CORE) #ifdef FAST #error FAST defined but cannot compile for FC #endif #else #warning WITH FC #endif #ifdef _WIN32 setbuf(stdout, NULL); setbuf(stderr, NULL); #endif #if 1 pl_foreign_double[0] = 1.2e30; pl_foreign_double[47] = -1.234567; #endif Save_Machine_Regs(init_buff_regs); #ifndef NO_MACHINE_REG_FOR_REG_BANK pl_reg_bank = stack; B = stack + NB_OF_X_REGS + 100; #else B = stack; #endif E = B + 1024; printf("pl_reg_bank=&X(0):%#" PL_FMT_x " B:%#" PL_FMT_x " E:%#" PL_FMT_x " &Y(0):%#" PL_FMT_x "\n", (PlULong) pl_reg_bank, (PlULong) B, (PlULong) E, (PlULong) &Y(E, 0)); printf("stack:%#" PL_FMT_x "\n", (PlULong) stack); // { PlLong *disp_stack(); printf("rsp : %p\n", disp_stack()); } while (tbl[i++]) { printf("test %d: ", i); (*tbl[i - 1]) (); printf("test %d OK\n", i); } Restore_Machine_Regs(init_buff_regs); printf("MA checks suceeded\n"); return 0; }