a5addcdf8c16be5ac60fdafea6d236ff14bdda3f
[reactos.git] / hal / halx86 / up / pic.S
1 /*
2 * FILE: hal/halx86/up/pic.S
3 * COPYRIGHT: See COPYING in the top level directory
4 * PURPOSE: HAL PIC Management and Control Code
5 * PROGRAMMER: Thomas Faber (thomas.faber@reactos.org)
6 */
7
8 /* INCLUDES ******************************************************************/
9
10 #include <asm.inc>
11
12 #include <ks386.inc>
13
14 /* GLOBALS *******************************************************************/
15
16 .data
17 ASSUME CS:NOTHING, DS:NOTHING, ES:NOTHING, FS:NOTHING, GS:NOTHING
18
19 /* FUNCTIONS *****************************************************************/
20
21 .code
22
23 MACRO(DEFINE_END_INTERRUPT_WRAPPER, WrapperName, HandlerName)
24 EXTERN @&HandlerName&@8:PROC
25 PUBLIC _&WrapperName&@8
26 .PROC _&WrapperName&@8
27 FPO 0, 2, 0, 0, 0, FRAME_FPO
28
29 /* Call the C function with the same arguments we got */
30 mov ecx, [esp+4]
31 mov edx, [esp+8]
32 call @&HandlerName&@8
33
34 /* Check if we got a pointer back */
35 test eax, eax
36 jnz WrapperName&_CallIntHandler
37
38 /* No? Just return */
39 ret 8
40
41 WrapperName&_CallIntHandler:
42 /* We got a pointer to call. Since it won't return, free up our stack
43 space. Otherwise we could end up with some nasty deep recursion.
44 The next function takes the trap frame as its (fastcall) argument. */
45 mov ecx, [esp+8]
46 add esp, 12
47 jmp eax
48 .ENDP
49 ENDM
50
51 MACRO(DEFINE_INTERRUPT_WRAPPER, WrapperName, HandlerName)
52 EXTERN _&HandlerName:PROC
53 PUBLIC _&WrapperName
54 .PROC _&WrapperName
55 FPO 0, 0, 0, 0, 0, FRAME_FPO
56
57 /* Call the C function */
58 call _&HandlerName
59
60 /* Check if we got a pointer back */
61 test eax, eax
62 jnz WrapperName&_CallIntHandler
63
64 /* No? Just return */
65 ret
66
67 WrapperName&_CallIntHandler:
68 /* Optimize the tail call to avoid stack overflow */
69 jmp eax
70 .ENDP
71 ENDM
72
73
74 DEFINE_END_INTERRUPT_WRAPPER HalpEndSoftwareInterrupt, HalpEndSoftwareInterrupt2
75 DEFINE_END_INTERRUPT_WRAPPER HalEndSystemInterrupt, HalEndSystemInterrupt2
76
77 DEFINE_INTERRUPT_WRAPPER HalpDispatchInterrupt, HalpDispatchInterrupt2
78 DEFINE_INTERRUPT_WRAPPER HalpHardwareInterruptLevel, HalpHardwareInterruptLevel2
79
80 END