コード例 #1
0
ファイル: dpmi.c プロジェクト: hallco978/msys
int _go32_dpmi_allocate_real_mode_callback_iret(_go32_dpmi_seginfo *info, _go32_dpmi_registers *regs)
{
  unsigned char *wrapper = (unsigned char *)malloc(sizeof(wrapper_common) + sizeof(wrapper_iret));
  if (wrapper == 0)
    return 0x8015;

  memcpy(wrapper, wrapper_common, sizeof(wrapper_common));
  memcpy(wrapper+sizeof(wrapper_common), wrapper_iret, sizeof(wrapper_iret));
  *(long *)(wrapper+11) = info->pm_offset - (int)wrapper - 15;
  info->size = (int)wrapper;

  r.x.ax = 0x0303;
  r.x.si = (int)wrapper;
  r.x.di = (int)regs;
  s.ds = _go32_my_cs();
  s.es = _go32_my_ds();
  s.fs = 0;
  s.gs = 0;
  int86x(0x31, &r, &r, &s);
  if (r.x.flags & 1)
  {
    return r.x.ax;
  }
  else
  {
    info->rm_segment = r.x.cx;
    info->rm_offset = r.x.dx;
    return 0;
  }
}
コード例 #2
0
ファイル: PS2V2.C プロジェクト: ahelwer/UofC
void mouse_init(void)     /*Note that we are doing NO device initialization. 
			We are assuming that this was done suitably when the system 
			was booted and the standard mouse driver was installed. THis is very poor
			programming practice! CW */
{

 /*  _go32_dpmi_lock_data(mousequeue,200);   I'm not using these in this simple
			demo so they are commented out. CW

   _go32_dpmi_lock_data(&mousequeue,sizeof(mousequeue));*/

   _go32_dpmi_lock_code(NewInt74,(unsigned long)(LOCKint74-NewInt74));

// This ensures that the handler is not placed into paged memory.

   _go32_dpmi_get_protected_mode_interrupt_vector(0x74,&old_handler);
   /* Reads the selector and offset of the old handler into a structure, so
   that it can be restored later. */

   /*Obtains the far pointer for the mouse ISR */

   new_mousehandler.pm_selector=_go32_my_cs();  /* Note that _go32_my_cs()
 				returns the	selector for the program's code.*/

   new_mousehandler.pm_offset=(unsigned long)NewInt74;

   _go32_dpmi_allocate_iret_wrapper(&new_mousehandler);
   /* The wrapper saves the machine state using a series of PUSH instructions. */

   _go32_dpmi_set_protected_mode_interrupt_vector(0x74,&new_mousehandler);

   /* Places the ISR far pointer into a protected mode interrupt table. */

}
コード例 #3
0
ファイル: dpmi.c プロジェクト: hallco978/msys
int _go32_dpmi_chain_protected_mode_interrupt_vector(int vector, _go32_dpmi_seginfo *info)
{
  char *mystack;
  unsigned char *wrapper = (unsigned char *)malloc(sizeof(wrapper_intcommon) + sizeof(wrapper_intchain));
  if (wrapper == 0)
    return 0x8015;
  mystack = (char *)malloc(_interrupt_stack_size);
  if (mystack == 0)
    return 0x8015;

  r.x.ax = 0x0204;
  r.h.bl = vector;
  int86(0x31, &r, &r);

  memcpy(wrapper, wrapper_intcommon, sizeof(wrapper_intcommon));
  memcpy(wrapper+sizeof(wrapper_intcommon), wrapper_intchain, sizeof(wrapper_intchain));
  *(short *)(wrapper+9) = _go32_my_ds();
  *(long *)(wrapper+20) = (int)mystack + _interrupt_stack_size;
  *(long *)(wrapper+36) = info->pm_offset - (int)wrapper - 40;
  *(long *)(wrapper+sizeof(wrapper_intcommon)+3) = (long)wrapper+sizeof(wrapper_intcommon)+8;
  *(long *)(wrapper+sizeof(wrapper_intcommon)+8) = r.x.dx;
  *(short *)(wrapper+sizeof(wrapper_intcommon)+12) = r.x.cx;

  r.x.ax = 0x0205;
  r.h.bl = vector;
  r.x.cx = _go32_my_cs();
  r.x.dx = (int)wrapper;
  int86(0x31, &r, &r);
  return 0;
}
コード例 #4
0
ファイル: joycfg.c プロジェクト: OpenEmu/Atari800-Core
void key_init(void)
{
        lo=hi=0;
	new_key_handler.pm_offset = (int) key_handler;
	new_key_handler.pm_selector = _go32_my_cs();
	_go32_dpmi_get_protected_mode_interrupt_vector(0x9, &old_key_handler);
	_go32_dpmi_allocate_iret_wrapper(&new_key_handler);
	_go32_dpmi_set_protected_mode_interrupt_vector(0x9, &new_key_handler);
}
コード例 #5
0
ファイル: int.c プロジェクト: jcarlosfeup/Arkanoid-LCOM
int set_isr(int irq, void (*isr)(void), 
			    _go32_dpmi_seginfo *prev_isr)
{ 
	int vector = irq_vector(irq);
	if(_go32_dpmi_get_protected_mode_interrupt_vector(vector, prev_isr)) return -1;
		_go32_dpmi_seginfo new_isr;
		new_isr.pm_selector = _go32_my_cs( );
		new_isr.pm_offset=(unsigned long) isr;
	if(_go32_dpmi_set_protected_mode_interrupt_vector(vector, &new_isr)) return -1;
	return 0;
}	
コード例 #6
0
ファイル: MAIN.C プロジェクト: ahelwer/UofC
/**
 * key_init
 * This function initiates the interrupt for the keyboard. This was given 
 * as part of the VBETEST.C example.
 **/
void key_init(void){
//Finds location of old handler
        _go32_dpmi_lock_code(NewInt9, (unsigned long)(LOCKint9 - NewInt9));
        _go32_dpmi_get_protected_mode_interrupt_vector(9, &old_handler);
//Set new handler
        new_handler.pm_offset = (unsigned long)NewInt9;
        new_handler.pm_selector = _go32_my_cs();
//Set in protected mode
        _go32_dpmi_allocate_iret_wrapper(&new_handler);
        _go32_dpmi_set_protected_mode_interrupt_vector(9, &new_handler);
}
コード例 #7
0
ファイル: ints.c プロジェクト: PChambino/bsod-syndrome
int install_asm_irq_handler(int irq, void (*irq_func)(void), _go32_dpmi_seginfo *old_irq) {
	// endereço do handler original
	_go32_dpmi_get_protected_mode_interrupt_vector(IRQ_VECTOR(irq), old_irq);

	// instalação do handler na IDT
	_go32_dpmi_seginfo new_irq;
	new_irq.pm_selector = _go32_my_cs( ); // selector do código
	new_irq.pm_offset = (unsigned long) irq_func; // endereço do novo handler
	_go32_dpmi_set_protected_mode_interrupt_vector(IRQ_VECTOR(irq), &new_irq);

	return 0;
}
コード例 #8
0
ファイル: dostimer.c プロジェクト: nesouri/nosefart
/* Lock code, data, and chain an interrupt handler */
void timer_install(int hertz, timerhandler_t func_ptr)
{
   timer_handler = func_ptr;

   /* Save the old vector, stuff the new one in there */
   _go32_dpmi_get_protected_mode_interrupt_vector(TIMER_INT, &old_handler);
   new_handler.pm_offset = (int) timer_handler;
   new_handler.pm_selector = _go32_my_cs();
   _go32_dpmi_chain_protected_mode_interrupt_vector(TIMER_INT, &new_handler);

   /* Set PIC to fire at desired refresh rate */
   timer_adjust(hertz);
}
コード例 #9
0
ファイル: ints.c プロジェクト: PChambino/bsod-syndrome
int install_c_irq_handler(int irq, void (*irq_func)(void), _go32_dpmi_seginfo *old_irq) {
	// endereço do handler original
	_go32_dpmi_get_protected_mode_interrupt_vector(IRQ_VECTOR(irq), old_irq);

	// instalação do handler na IDT
	_go32_dpmi_seginfo new_irq;
	new_irq.pm_selector = _go32_my_cs( ); // selector do código
	new_irq.pm_offset = (unsigned long) irq_func; // endereço do novo handler
	// prepara funcao assembly para chamar funcao C
	_go32_dpmi_allocate_iret_wrapper(&new_irq);
	_go32_dpmi_set_protected_mode_interrupt_vector(IRQ_VECTOR(irq), &new_irq);

	return 0;
}
コード例 #10
0
void key_init(void)
{
	int i;
	for (i=0;i<256;i++) keypush[i]=0; /*none key is pressed*/
	extended_key_follows=FALSE;
	update_leds();
	raw_key_r=0;raw_key=0;
	new_key_handler.pm_offset = (int) key_handler;
	new_key_handler.pm_selector = _go32_my_cs();
	_go32_dpmi_get_protected_mode_interrupt_vector(0x9, &old_key_handler);
	_go32_dpmi_allocate_iret_wrapper(&new_key_handler);
	_go32_dpmi_set_protected_mode_interrupt_vector(0x9, &new_key_handler);
	keyboard_handler_replaced = TRUE;
}
コード例 #11
0
ファイル: gcctimer.c プロジェクト: adplug/gcctimer
int timer_init(TimerHandler handler)
{
  /* Save old handler */
  _go32_dpmi_get_protected_mode_interrupt_vector(TIMER_INT, &oldhandler);

  /* Setup our handler */
  real_handler = handler;
  myhandler.pm_selector = _go32_my_cs();
  myhandler.pm_offset = (unsigned long)timer_handler;

  /* Allocate an IRET wrapper */
  if(_go32_dpmi_allocate_iret_wrapper(&myhandler))
    return 0;

  /* Set our handler to be the new interrupt handler */
  return _go32_dpmi_set_protected_mode_interrupt_vector(TIMER_INT, &myhandler);
}
コード例 #12
0
ファイル: Interrupcoes.c プロジェクト: carlosmccosta/Arkanoid
int set_isr_c_wrapper(int irq, void (*isr)(void), _go32_dpmi_seginfo *prev_isr) {

    int vector = irq_vector(irq);
    if(_go32_dpmi_get_protected_mode_interrupt_vector(vector, prev_isr))
        return -1;

    _go32_dpmi_seginfo new_isr;
    new_isr.pm_selector = _go32_my_cs();
    new_isr.pm_offset=(unsigned long) isr;

    /* prepara função assembly para chamar função C */
    _go32_dpmi_allocate_iret_wrapper(&new_isr);

    if(_go32_dpmi_set_protected_mode_interrupt_vector(vector, &new_isr))
        return -1;

    return 0;
}
コード例 #13
0
ファイル: serdos.c プロジェクト: haision/GitHub_C
static void install_isr(int portnum, struct port *p, int irq)
{
    int x, baseaddr = p->baseaddr;
    
    p->irq = irq;

    /* Clear pending interrupts.  */
    do {
	inportb(baseaddr + RBR);
	inportb(baseaddr + LSR);
	inportb(baseaddr + MSR);
	x = inportb(baseaddr + IIR);
    } while (!(x & 0x01));  

    /* Calculate vector from IRQ.  */
    if (p->irq <= 7) {
	p->interrupt_enable_mask = ~(1 << p->irq);	/* IMR is inverted */
	p->vector_num = 8 + p->irq;
	p->pic_imr = 0x21;
    }
    else {
	p->interrupt_enable_mask = ~(1 << (p->irq - 8));
	p->vector_num = 0x70 + (p->irq - 8);
	p->pic_imr = 0xa1;
    }

    /* Install ISR into vector.  */
    p->new_vector.pm_selector = _go32_my_cs();
    p->new_vector.pm_offset = (int)isr_wrapper_table[portnum];
    _go32_dpmi_allocate_iret_wrapper(&p->new_vector);

    disable();

    _go32_dpmi_get_protected_mode_interrupt_vector(p->vector_num, &p->old_vector);
    _go32_dpmi_set_protected_mode_interrupt_vector(p->vector_num, &p->new_vector);

    /* Enable interrupts.  */
    outportb(baseaddr + MCR, 0x0f);
    outportb(baseaddr + IER, 0x0f);
    outportb(p->pic_imr, inportb(p->pic_imr) & p->interrupt_enable_mask);
    
    enable();
}
コード例 #14
0
void keyboard_int_install() {
   // retrieve the current (old) keyboard handler
   _go32_dpmi_get_protected_mode_interrupt_vector(9, &OldHandler);

   // lock code and data from being paged
   _go32_dpmi_lock_code(myKeyInt, (long)myKeyInt_Size);
   _go32_dpmi_lock_data(&keyVal, (long)sizeof(keyVal));

   // establish new seginfo struct
   NewHandler.pm_offset = (long)myKeyInt;
   NewHandler.pm_selector = _go32_my_cs();

   // allocate the IRET wrapper
   _go32_dpmi_allocate_iret_wrapper(&NewHandler);

   // install the new keyboard ISR
   _go32_dpmi_set_protected_mode_interrupt_vector(9, &NewHandler);

   printf("new keyboard ISR installed\n");
}
コード例 #15
0
ファイル: mirq.c プロジェクト: fourks/bb.js
PVI MIrq_SetHandler(UBYTE irqno, PVI handler)
{
#ifdef __DJGPP__
    _go32_dpmi_seginfo seginfo;
#endif
    PVI oldvect;
    int vecno = (irqno > 7) ? irqno + 0x68 : irqno + 0x8;
#ifdef __DJGPP__
    _go32_dpmi_get_protected_mode_interrupt_vector(vecno, &seginfo);
    oldvect = seginfo.pm_offset;
    seginfo.pm_offset = handler;
    seginfo.pm_selector = _go32_my_cs();
    _go32_dpmi_allocate_iret_wrapper(&seginfo);
    _go32_dpmi_set_protected_mode_interrupt_vector(vecno, &seginfo);
#else
    oldvect = _dos_getvect(vecno);
    _dos_setvect(vecno, handler);
#endif
    return oldvect;
}
コード例 #16
0
ファイル: display_dos.c プロジェクト: iamgreaser/kevedit
int display_dos_init()
{
    __dpmi_regs r;
    /* Set char-smashed-together mode */
    r.x.ax = 0x1201;
    r.h.bl = 0x30;
    __dpmi_int(0x10, &r);
    r.x.ax = 0x0003;
    __dpmi_int(0x10, &r);

    /* Pointer to video memory */
    videomem = __dpmi_segment_to_descriptor(0xb800);
    /* Block cursor */
    _setcursortype(_SOLIDCURSOR);

    /* No windows by default */
    windows = 0;

    /* Check for Win95/Win98 */
    if (getenv("winbootdir") != NULL)
        windows = 1;
    /* Check for WinNT/Win2k */
    if ((getenv("OS") != NULL) && !strcmp(getenv("OS"), "Windows_NT"))
        windows = 2;

    lshift = rshift = 0;

    /* Save the old handler */
    _go32_dpmi_get_protected_mode_interrupt_vector(KBD_INT, &old_kb_handler);

    /* Create new handler, chain it to old */
    new_kb_handler.pm_offset = (int) kb_isr;
    new_kb_handler.pm_selector = _go32_my_cs();
    _go32_dpmi_chain_protected_mode_interrupt_vector(KBD_INT, &new_kb_handler);

    /* flush the keystroke buffer just in case */
    while (kbhit()) display_dos_getch();

    return -1;
}
コード例 #17
0
ファイル: kbd.c プロジェクト: r-type/vice-libretro
/* Install our custom keyboard interrupt.  */
void kbd_install(void)
{
    int r;
    static _go32_dpmi_seginfo my_kbd_handler_seginfo;

    my_kbd_handler_seginfo.pm_offset = (int)my_kbd_interrupt_handler;
    my_kbd_handler_seginfo.pm_selector = _go32_my_cs();
    r = _go32_dpmi_allocate_iret_wrapper(&my_kbd_handler_seginfo);
    if (r) {
        log_error(LOG_DEFAULT, "Cannot allocate IRET wrapper for the keyboard interrupt.");
        exit(-1);
    }

    r = _go32_dpmi_set_protected_mode_interrupt_vector(9, &my_kbd_handler_seginfo);
    if (r) {
        log_error(LOG_DEFAULT, "Cannot install the keyboard interrupt handler.");
        exit(-1);
    }

    /* Initialize the keyboard matrix.  */
    keyboard_clear_keymatrix();
    /* Reset modifier status.  */
    memset(&modifiers, 0, sizeof(modifiers));
}
コード例 #18
0
ファイル: ser_port.c プロジェクト: dorienh/smmu
void InitPort (void)
{
  int mcr;
  int temp;

  if(port_initted)
    return;
  
  //
  // Reset the output queue
  //

  outque.head = outque.tail = 0;

  //
  // find the irq and io address of the port
  //
  GetUart ();

  //
  // init com port settings
  //
  regs.x.ax = 0xf3;               //f3= 9600 n 8 1
  regs.x.dx = comport - 1;
  int86 (0x14, &regs, &regs);
  
  //
  // check for a 16550
  //
  OUTPUT(uart + FIFO_CONTROL_REGISTER, FCR_FIFO_ENABLE + FCR_TRIGGER_04);
  temp = INPUT(uart + INTERRUPT_ID_REGISTER);
  if ((temp & 0xf8) == 0xc0)
    {
      uart_type = UART_16550;
      usermsg ("UART is a 16550");
    }
  else
    {
      uart_type = UART_8250;
      OUTPUT(uart + FIFO_CONTROL_REGISTER, 0);
      usermsg("UART is an 8250");
    }
  
  //
  // prepare for interrupts
  //

  OUTPUT(uart + INTERRUPT_ENABLE_REGISTER, 0);
  mcr = INPUT(uart + MODEM_CONTROL_REGISTER);
  mcr |= MCR_OUT2;
  mcr &= ~MCR_LOOPBACK;
  OUTPUT(uart + MODEM_CONTROL_REGISTER, mcr);
  
  INPUT(uart);  // Clear any pending interrupts
  INPUT(uart + INTERRUPT_ID_REGISTER);
  
  //
  // hook the irq vector
  //
  irqintnum = irq + 8;
  
  asm("cli"); // disable interrupts

  _go32_dpmi_get_protected_mode_interrupt_vector(irqintnum, &oldirqvect);
  newirqvect.pm_offset = (int)isr_8250;
  newirqvect.pm_selector = _go32_my_cs();
  _go32_dpmi_allocate_iret_wrapper(&newirqvect);
  _go32_dpmi_set_protected_mode_interrupt_vector(irqintnum, &newirqvect);

  asm("sti"); // enable interrupts
	
  OUTPUT(0x20 + 1, INPUT(0x20 + 1) & ~(1<<irq));

  asm("cli"); // disable again

  // enable RX and TX interrupts at the uart
  
  OUTPUT(uart + INTERRUPT_ENABLE_REGISTER,
	 IER_RX_DATA_READY + IER_TX_HOLDING_REGISTER_EMPTY);

  // enable interrupts through the interrupt controller
  
  OUTPUT(0x20, 0xc2);

  // set DTR
  OUTPUT(uart + MODEM_CONTROL_REGISTER
	  , INPUT(uart + MODEM_CONTROL_REGISTER) | MCR_DTR);
  
  asm("sti"); // re-enable

  port_initted = true;
}