xref: /reactos/hal/halx86/pic/pic.S (revision 69931a4a)
1/*
2 * PROJECT:     ReactOS Hardware Abstraction Layer
3 * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE:     HAL PIC Management and Control Code
5 * COPYRIGHT:   Copyright 2016-2018 Thomas Faber <thomas.faber@reactos.org>
6 */
7
8/* INCLUDES ******************************************************************/
9
10#include <asm.inc>
11
12#include <ks386.inc>
13
14/* FUNCTIONS *****************************************************************/
15
16.code
17
18MACRO(DEFINE_END_INTERRUPT_WRAPPER, WrapperName, HandlerName)
19EXTERN @&HandlerName&@8:PROC
20PUBLIC _&WrapperName&@8
21.PROC _&WrapperName&@8
22    FPO 0, 2, 0, 0, 0, FRAME_FPO
23
24    /* Call the C function with the same arguments we got */
25    mov ecx, [esp+4]
26    mov edx, [esp+8]
27    call @&HandlerName&@8
28
29    /* Check if we got a pointer back */
30    test eax, eax
31    jnz WrapperName&_CallIntHandler
32
33    /* No? Just return */
34    ret 8
35
36WrapperName&_CallIntHandler:
37    /* We got a pointer to call. Since it won't return, reset the stack to
38       the location of the stack frame. This frees up our own stack as well
39       as that of the functions above us, and avoids an overflow due to
40       excessive recursion.
41       The next function takes the trap frame as its (fastcall) argument. */
42    mov ecx, [esp+8]
43    mov esp, ecx
44    mov ebp, esp
45    jmp eax
46.ENDP
47ENDM
48
49MACRO(DEFINE_INTERRUPT_WRAPPER, WrapperName, HandlerName)
50EXTERN _&HandlerName:PROC
51PUBLIC _&WrapperName
52.PROC _&WrapperName
53    FPO 0, 0, 0, 0, 0, FRAME_FPO
54
55    /* Call the C function */
56    call _&HandlerName
57
58    /* Check if we got a pointer back */
59    test eax, eax
60    jnz WrapperName&_CallIntHandler
61
62    /* No? Just return */
63    ret
64
65WrapperName&_CallIntHandler:
66    /* Optimize the tail call to avoid stack overflow */
67    jmp eax
68.ENDP
69ENDM
70
71
72DEFINE_END_INTERRUPT_WRAPPER HalpEndSoftwareInterrupt, HalpEndSoftwareInterrupt2
73DEFINE_END_INTERRUPT_WRAPPER HalEndSystemInterrupt, HalEndSystemInterrupt2
74
75DEFINE_INTERRUPT_WRAPPER HalpDispatchInterrupt, HalpDispatchInterrupt2
76DEFINE_INTERRUPT_WRAPPER HalpHardwareInterruptLevel, HalpHardwareInterruptLevel2
77
78END
79