[HAL] Reset the stack pointer to the stack frame when calling second-entry interrupt...
[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, reset the stack to
43 the location of the stack frame. This frees up our own stack as well
44 as that of the functions above us, and avoids an overflow due to
45 excessive recursion.
46 The next function takes the trap frame as its (fastcall) argument. */
47 mov ecx, [esp+8]
48 mov esp, ecx
49 mov ebp, esp
50 jmp eax
51 .ENDP
52 ENDM
53
54 MACRO(DEFINE_INTERRUPT_WRAPPER, WrapperName, HandlerName)
55 EXTERN _&HandlerName:PROC
56 PUBLIC _&WrapperName
57 .PROC _&WrapperName
58 FPO 0, 0, 0, 0, 0, FRAME_FPO
59
60 /* Call the C function */
61 call _&HandlerName
62
63 /* Check if we got a pointer back */
64 test eax, eax
65 jnz WrapperName&_CallIntHandler
66
67 /* No? Just return */
68 ret
69
70 WrapperName&_CallIntHandler:
71 /* Optimize the tail call to avoid stack overflow */
72 jmp eax
73 .ENDP
74 ENDM
75
76
77 DEFINE_END_INTERRUPT_WRAPPER HalpEndSoftwareInterrupt, HalpEndSoftwareInterrupt2
78 DEFINE_END_INTERRUPT_WRAPPER HalEndSystemInterrupt, HalEndSystemInterrupt2
79
80 DEFINE_INTERRUPT_WRAPPER HalpDispatchInterrupt, HalpDispatchInterrupt2
81 DEFINE_INTERRUPT_WRAPPER HalpHardwareInterruptLevel, HalpHardwareInterruptLevel2
82
83 END