Changeset 9308


Ignore:
Timestamp:
Apr 27, 2008, 11:06:25 AM (11 years ago)
Author:
gb
Message:

Try to get more things working.

Recognize stylized instruction sequences used for consing on Windows
(with TCR in a GPR.)

Make windows exception handler interact with suspend_tcr() mechanisms.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/win64/lisp-kernel/x86-exceptions.c

    r9296 r9308  
    626626}
    627627
    628 #ifdef WINDOWS
    629628Boolean
    630629handle_fault(TCR *tcr, ExceptionInformation *xp, siginfo_t *info, int old_valence)
    631630{
    632 }
    633 
    634 Boolean
    635 handle_floating_point_exception(TCR *tcr, ExceptionInformation *xp, siginfo_t *info)
    636 {
    637 }
    638 #else
    639 Boolean
    640 handle_fault(TCR *tcr, ExceptionInformation *xp, siginfo_t *info, int old_valence)
    641 {
    642631#ifdef FREEBSD
    643632  BytePtr addr = (BytePtr) xp->uc_mcontext.mc_addr;
    644633#else
     634#ifdef WINDOWS
     635  BytePtr addr = NULL;          /* FIX THIS */
     636#else
    645637  BytePtr addr = (BytePtr) info->si_addr;
     638#endif
    646639#endif
    647640
     
    681674handle_floating_point_exception(TCR *tcr, ExceptionInformation *xp, siginfo_t *info)
    682675{
    683   int code = info->si_code, rfn = 0, skip;
     676  int code, skip;
    684677  pc program_counter = (pc)xpPC(xp);
    685   LispObj rpc = (LispObj) program_counter, xcf, cmain = nrs_CMAIN.vcell,
    686 
     678  LispObj xcf, cmain = nrs_CMAIN.vcell,
    687679    save_rbp = xpGPR(xp,Irbp), save_vsp = xpGPR(xp,Isp);
    688680
     681#ifdef WINDOWS
     682  code = info->ExceptionCode;
     683#else
     684  code = info->si_code;
     685#endif 
    689686  if ((fulltag_of(cmain) == fulltag_misc) &&
    690687      (header_subtag(header_of(cmain)) == subtag_macptr)) {
     
    699696  }
    700697}
    701 #endif
     698
    702699
    703700Boolean
     
    968965  tcr->valence = TCR_STATE_EXCEPTION_WAIT;
    969966
     967#ifdef WINDOWS
     968  if (tcr->flags & (1<<TCR_FLAG_BIT_PENDING_SUSPEND)) {
     969    CLR_TCR_FLAG(tcr, TCR_FLAG_BIT_PENDING_SUSPEND);
     970    SEM_RAISE(tcr->suspend);
     971    SEM_WAIT_FOREVER(tcr->resume);
     972  }
     973#else
    970974  ALLOW_EXCEPTIONS(context);
     975#endif
    971976  return old_valence;
    972977
     
    15081513  TCR *tcr = get_tcr(false);
    15091514  DWORD code = exception_pointers->ExceptionRecord->ExceptionCode;
    1510   int old_valence = tcr->valence,
    1511     signal_number = map_windows_exception_code_to_posix_signal(code);
     1515  int old_valence, signal_number;
    15121516  ExceptionInformation *context = exception_pointers->ContextRecord;
    1513     siginfo_t *info = exception_pointers->ExceptionRecord;
    1514     xframe_list xframes;
    1515 
     1517  siginfo_t *info = exception_pointers->ExceptionRecord;
     1518  xframe_list xframes;
     1519
     1520  old_valence = prepare_to_wait_for_exception_lock(tcr, context);
    15161521  wait_for_exception_lock_in_handler(tcr, context, &xframes);
     1522
     1523  signal_number = map_windows_exception_code_to_posix_signal(code);
    15171524 
    15181525  if (!handle_exception(signal_number, info, context, tcr, old_valence)) {
     
    15441551  EXCEPTION_POINTERS *new_ep;
    15451552
    1546   new_context = ((CONTEXT *)(foreign_rsp&~2))-1;
     1553  new_context = ((CONTEXT *)(foreign_rsp&~15))-1;
    15471554  *new_context = *context;
    15481555  foreign_rsp = (LispObj)new_context;
    1549   new_info = ((siginfo_t *)(foreign_rsp&~2))-1;
     1556  new_info = ((siginfo_t *)(foreign_rsp&~15))-1;
    15501557  *new_info = *original_ep->ExceptionRecord;
    15511558  foreign_rsp = (LispObj)new_info;
    1552   new_ep = ((EXCEPTION_POINTERS *)(foreign_rsp&~2))-1;
     1559  new_ep = ((EXCEPTION_POINTERS *)(foreign_rsp&~15))-1;
    15531560  foreign_rsp = (LispObj)new_ep;
    15541561  new_ep->ContextRecord = new_context;
     
    18851892
    18861893opcode load_allocptr_reg_from_tcr_save_allocptr_instruction[] =
    1887   {0x65,0x48,0x8b,0x1c,0x25,0xd8,0x00,0x00,0x00};
     1894#ifdef WINDOWS
     1895  {0x49,0x8b,0x9b,0xd8,0x00,0x00,0x00}
     1896#else
     1897  {0x65,0x48,0x8b,0x1c,0x25,0xd8,0x00,0x00,0x00}
     1898#endif
     1899;
    18881900opcode compare_allocptr_reg_to_tcr_save_allocbase_instruction[] =
    1889   {0x65,0x48,0x3b,0x1c,0x25,0xe0,0x00,0x00,0x00};
     1901#ifdef WINDOWS
     1902  {0x49,0x3b,0x9b,0xe0,0x00,0x00,0x00}
     1903#else
     1904  {0x65,0x48,0x3b,0x1c,0x25,0xe0,0x00,0x00,0x00}
     1905#endif
     1906
     1907;
    18901908opcode branch_around_alloc_trap_instruction[] =
    18911909  {0x7f,0x02};
     
    18931911  {0xcd,0xc5};
    18941912opcode clear_tcr_save_allocptr_tag_instruction[] =
    1895   {0x65,0x80,0x24,0x25,0xd8,0x00,0x00,0x00,0xf0};
     1913#ifdef WINDOWS
     1914  {0x41,0x80,0xa3,0xd8,0x00,0x00,0x00,0xf0}
     1915#else
     1916  {0x65,0x80,0x24,0x25,0xd8,0x00,0x00,0x00,0xf0}
     1917#endif
     1918;
    18961919opcode set_allocptr_header_instruction[] =
    18971920  {0x48,0x89,0x43,0xf3};
     
    19051928  case 0x7f: return ID_branch_around_alloc_trap_instruction;
    19061929  case 0x48: return ID_set_allocptr_header_instruction;
     1930#ifdef WINDOWS
     1931  case 0x41: return ID_clear_tcr_save_allocptr_tag_instruction;
     1932  case 0x49:
     1933    switch(program_counter[1]) {
     1934    case 0x8b: return ID_load_allocptr_reg_from_tcr_save_allocptr_instruction;
     1935    case 0x3b: return ID_compare_allocptr_reg_to_tcr_save_allocbase_instruction;
     1936    }
     1937#else
    19071938  case 0x65:
    19081939    switch(program_counter[1]) {
     
    19141945      }
    19151946    }
     1947#endif
     1948  default: break;
    19161949  }
    19171950  return ID_unrecognized_alloc_instruction;
    19181951}
    19191952     
    1920 #ifdef WINDOWS 
    1921 void
    1922 pc_luser_xp(ExceptionInformation *xp, TCR *tcr, signed_natural *interrupt_displacement)
    1923 {
    1924 }
    1925 #else
    19261953void
    19271954pc_luser_xp(ExceptionInformation *xp, TCR *tcr, signed_natural *interrupt_displacement)
     
    19812008         attempt. */
    19822009      {
    1983         int flags = (int)xpGPR(xp,Iflags);
     2010        int flags = (int)eflags_register(xp);
    19842011       
    19852012        if ((!(flags & (1 << X86_ZERO_FLAG_BIT))) &&
     
    20232050      }
    20242051      break;
    2025     }
     2052    default:
     2053      break;
     2054    }
     2055
     2056   
    20262057    return;
    20272058  }
     
    20352066      if ((program_counter < &egc_store_node_conditional_success_test) ||
    20362067          ((program_counter == &egc_store_node_conditional_success_test) &&
    2037            !(xpGPR(xp, Iflags) & (1 << X86_ZERO_FLAG_BIT)))) {
     2068           !(eflags_register(xp) & (1 << X86_ZERO_FLAG_BIT)))) {
    20382069        /* Back up the PC, try again */
    20392070        xpPC(xp) = (LispObj) &egc_store_node_conditional;
     
    20862117  }
    20872118}
    2088 #endif
     2119
    20892120
    20902121void
Note: See TracChangeset for help on using the changeset viewer.