]>
Commit | Line | Data |
---|---|---|
25402f5d HL |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r | |
6d0ca257 | 4 | Portions Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>\r |
25402f5d HL |
5 | \r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "CpuDxe.h"\r | |
17 | \r | |
18 | #include <Chipset/AArch64.h>\r | |
19 | \r | |
20 | VOID\r | |
21 | ExceptionHandlersStart (\r | |
22 | VOID\r | |
23 | );\r | |
24 | \r | |
25 | VOID\r | |
26 | ExceptionHandlersEnd (\r | |
27 | VOID\r | |
28 | );\r | |
29 | \r | |
30 | VOID\r | |
31 | CommonExceptionEntry (\r | |
32 | VOID\r | |
33 | );\r | |
34 | \r | |
35 | VOID\r | |
36 | AsmCommonExceptionEntry (\r | |
37 | VOID\r | |
38 | );\r | |
39 | \r | |
40 | \r | |
6a343fac G |
41 | EFI_EXCEPTION_CALLBACK gExceptionHandlers[MAX_AARCH64_EXCEPTION + 1];\r |
42 | EFI_EXCEPTION_CALLBACK gDebuggerExceptionHandlers[MAX_AARCH64_EXCEPTION + 1];\r | |
25402f5d HL |
43 | \r |
44 | \r | |
45 | \r | |
46 | /**\r | |
47 | This function registers and enables the handler specified by InterruptHandler for a processor\r | |
48 | interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the\r | |
49 | handler for the processor interrupt or exception type specified by InterruptType is uninstalled.\r | |
50 | The installed handler is called once for each processor interrupt or exception.\r | |
51 | \r | |
52 | @param InterruptType A pointer to the processor's current interrupt state. Set to TRUE if interrupts\r | |
53 | are enabled and FALSE if interrupts are disabled.\r | |
54 | @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r | |
55 | when a processor interrupt occurs. If this parameter is NULL, then the handler\r | |
56 | will be uninstalled.\r | |
57 | \r | |
58 | @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r | |
59 | @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r | |
60 | previously installed.\r | |
61 | @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r | |
62 | previously installed.\r | |
63 | @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported.\r | |
64 | \r | |
65 | **/\r | |
66 | EFI_STATUS\r | |
67 | RegisterInterruptHandler (\r | |
68 | IN EFI_EXCEPTION_TYPE InterruptType,\r | |
69 | IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r | |
70 | )\r | |
71 | {\r | |
6a343fac | 72 | if (InterruptType > MAX_AARCH64_EXCEPTION) {\r |
25402f5d HL |
73 | return EFI_UNSUPPORTED;\r |
74 | }\r | |
75 | \r | |
76 | if ((InterruptHandler != NULL) && (gExceptionHandlers[InterruptType] != NULL)) {\r | |
77 | return EFI_ALREADY_STARTED;\r | |
78 | }\r | |
79 | \r | |
80 | gExceptionHandlers[InterruptType] = InterruptHandler;\r | |
81 | \r | |
82 | return EFI_SUCCESS;\r | |
83 | }\r | |
84 | \r | |
85 | \r | |
86 | \r | |
87 | VOID\r | |
88 | EFIAPI\r | |
89 | CommonCExceptionHandler (\r | |
90 | IN EFI_EXCEPTION_TYPE ExceptionType,\r | |
91 | IN OUT EFI_SYSTEM_CONTEXT SystemContext\r | |
92 | )\r | |
93 | {\r | |
94 | if (ExceptionType <= MAX_AARCH64_EXCEPTION) {\r | |
95 | if (gExceptionHandlers[ExceptionType]) {\r | |
96 | gExceptionHandlers[ExceptionType] (ExceptionType, SystemContext);\r | |
97 | return;\r | |
98 | }\r | |
99 | } else {\r | |
100 | DEBUG ((EFI_D_ERROR, "Unknown exception type %d from %016lx\n", ExceptionType, SystemContext.SystemContextAArch64->ELR));\r | |
101 | ASSERT (FALSE);\r | |
102 | }\r | |
103 | \r | |
104 | DefaultExceptionHandler (ExceptionType, SystemContext);\r | |
105 | }\r | |
106 | \r | |
107 | \r | |
108 | \r | |
109 | EFI_STATUS\r | |
110 | InitializeExceptions (\r | |
111 | IN EFI_CPU_ARCH_PROTOCOL *Cpu\r | |
112 | )\r | |
113 | {\r | |
114 | EFI_STATUS Status;\r | |
115 | BOOLEAN IrqEnabled;\r | |
116 | BOOLEAN FiqEnabled;\r | |
117 | \r | |
118 | Status = EFI_SUCCESS;\r | |
119 | ZeroMem (gExceptionHandlers,sizeof(*gExceptionHandlers));\r | |
120 | \r | |
121 | //\r | |
122 | // Disable interrupts\r | |
123 | //\r | |
124 | Cpu->GetInterruptState (Cpu, &IrqEnabled);\r | |
125 | Cpu->DisableInterrupt (Cpu);\r | |
126 | \r | |
127 | //\r | |
128 | // EFI does not use the FIQ, but a debugger might so we must disable\r | |
129 | // as we take over the exception vectors.\r | |
130 | //\r | |
131 | FiqEnabled = ArmGetFiqState ();\r | |
132 | ArmDisableFiq ();\r | |
133 | \r | |
6d0ca257 OM |
134 | // The AArch64 Vector table must be 2k-byte aligned - if this assertion fails ensure 'Align=4K'\r |
135 | // is defined into your FDF for this module.\r | |
136 | ASSERT (((UINTN)ExceptionHandlersStart & ARM_VECTOR_TABLE_ALIGNMENT) == 0);\r | |
25402f5d | 137 | \r |
6d0ca257 OM |
138 | // We do not copy the Exception Table at PcdGet32(PcdCpuVectorBaseAddress). We just set Vector\r |
139 | // Base Address to point into CpuDxe code.\r | |
25402f5d HL |
140 | ArmWriteVBar ((UINTN)ExceptionHandlersStart);\r |
141 | \r | |
142 | if (FiqEnabled) {\r | |
143 | ArmEnableFiq ();\r | |
144 | }\r | |
145 | \r | |
146 | if (IrqEnabled) {\r | |
147 | //\r | |
148 | // Restore interrupt state\r | |
149 | //\r | |
150 | Status = Cpu->EnableInterrupt (Cpu);\r | |
151 | }\r | |
152 | \r | |
153 | return Status;\r | |
154 | }\r |