Add support for interrupts in 32-bit code.
[wine/wine64.git] / msdos / interrupts.c
blob0802c6999632dc10474d612bb67ec7659f1d1a01
1 /*
2 * Interrupt vectors emulation
4 * Copyright 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <sys/types.h>
22 #include "windef.h"
23 #include "wine/winbase16.h"
24 #include "miscemu.h"
25 #include "msdos.h"
26 #include "module.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(int);
31 static FARPROC16 INT_Vectors[256];
32 static FARPROC48 INT_Vectors48[256];
34 /* Ordinal number for interrupt 0 handler in WPROCS.DLL */
35 #define FIRST_INTERRUPT 100
38 /**********************************************************************
39 * INT_GetPMHandler
41 * Return the protected mode interrupt vector for a given interrupt.
43 FARPROC16 INT_GetPMHandler( BYTE intnum )
45 if (!INT_Vectors[intnum])
47 static HMODULE16 wprocs;
48 if (!wprocs)
50 if (((wprocs = GetModuleHandle16( "wprocs" )) < 32) &&
51 ((wprocs = LoadLibrary16( "wprocs" )) < 32))
53 ERR("could not load wprocs.dll\n");
54 return 0;
57 if (!(INT_Vectors[intnum] = GetProcAddress16( wprocs, (LPCSTR)(FIRST_INTERRUPT + intnum))))
59 WARN("int%x not implemented, returning dummy handler\n", intnum );
60 INT_Vectors[intnum] = GetProcAddress16( wprocs, (LPCSTR)(FIRST_INTERRUPT + 256) );
63 return INT_Vectors[intnum];
67 /**********************************************************************
68 * INT_SetPMHandler
70 * Set the protected mode interrupt handler for a given interrupt.
72 void INT_SetPMHandler( BYTE intnum, FARPROC16 handler )
74 TRACE("Set protected mode interrupt vector %02x <- %04x:%04x\n",
75 intnum, HIWORD(handler), LOWORD(handler) );
76 INT_Vectors[intnum] = handler;
80 /**********************************************************************
81 * INT_GetPMHandler48
83 * Return the protected mode interrupt vector for a given interrupt.
84 * Used to get 48-bit pointer for 32-bit interrupt handlers in DPMI32.
86 FARPROC48 INT_GetPMHandler48( BYTE intnum )
88 if (!INT_Vectors48[intnum].selector)
90 INT_Vectors48[intnum].selector = DOSMEM_dpmi_segments.int48_sel;
91 INT_Vectors48[intnum].offset = 4 * intnum;
93 return INT_Vectors48[intnum];
97 /**********************************************************************
98 * INT_SetPMHandler48
100 * Set the protected mode interrupt handler for a given interrupt.
101 * Used to set 48-bit pointer for 32-bit interrupt handlers in DPMI32.
103 void INT_SetPMHandler48( BYTE intnum, FARPROC48 handler )
105 TRACE("Set 32-bit protected mode interrupt vector %02x <- %04x:%08x\n",
106 intnum, handler.selector, handler.offset );
107 INT_Vectors48[intnum] = handler;
111 /**********************************************************************
112 * INT_DefaultHandler (WPROCS.356)
114 * Default interrupt handler.
116 void WINAPI INT_DefaultHandler( CONTEXT86 *context )