File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ set(ARCH_OBJECTS
66 profile_intr.asm
77 apic_asm.asm
88 arch_start.asm
9+ exceptions.asm
910 interrupts.asm
1011)
1112
Original file line number Diff line number Diff line change 1+ ; This file is a part of the IncludeOS unikernel - www.includeos.org
2+ ;
3+ ; Copyright 2015 Oslo and Akershus University College of Applied Sciences
4+ ; and Alfred Bratterud
5+ ;
6+ ; Licensed under the Apache License, Version 2.0 (the "License");
7+ ; you may not use this file except in compliance with the License.
8+ ; You may obtain a copy of the License at
9+ ;
10+ ; http://www.apache.org/licenses/LICENSE-2.0
11+ ;
12+ ; Unless required by applicable law or agreed to in writing, software
13+ ; distributed under the License is distributed on an "AS IS" BASIS,
14+ ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ ; See the License for the specific language governing permissions and
16+ ; limitations under the License.
17+ [BITS 32]
18+ extern cpu_exception
19+
20+ SECTION .bss
21+ i386_registers:
22+ resb 4 * 16
23+
24+ %macro CPU_EXCEPT 1
25+ global __cpu_except_% 1 :function
26+ __cpu_except_% 1 :
27+ call save_cpu_regs
28+
29+ ;; new stack frame
30+ push ebp
31+ mov ebp , esp
32+ ;; enter panic
33+ push 0
34+ push % 1
35+ push i386_registers
36+ call cpu_exception
37+ %endmacro
38+
39+ %macro CPU_EXCEPT_CODE 1
40+ global __cpu_except_% 1 :function
41+ __cpu_except_% 1 :
42+ call save_cpu_regs
43+
44+ ;; pop error code
45+ pop edx
46+ ;; new stack frame
47+ push ebp
48+ mov ebp , esp
49+ ;; enter panic
50+ push edx
51+ push % 1
52+ push i386_registers
53+ call cpu_exception
54+ %endmacro
55+
56+ SECTION .text
57+ %define regs(r) [ i386_registers + r ]
58+ save_cpu_regs:
59+ mov regs( 0 ) , eax
60+ mov regs( 4 ) , ebx
61+ mov regs( 8 ) , ecx
62+ mov regs( 12 ) , edx
63+
64+ mov regs( 16 ) , ebp
65+ mov eax , [ esp + 16 ] ;; esp
66+ mov regs( 20 ) , eax
67+ mov regs( 24 ) , esi
68+ mov regs( 28 ) , edi
69+
70+ mov eax , [ esp + 4 ] ;; eip
71+ mov regs( 32 ) , eax
72+ pushf ;; eflags
73+ pop DWORD regs( 36 )
74+ ret
75+
76+ CPU_EXCEPT 0
77+ CPU_EXCEPT 1
78+ CPU_EXCEPT 2
79+ CPU_EXCEPT 3
80+ CPU_EXCEPT 4
81+ CPU_EXCEPT 5
82+ CPU_EXCEPT 6
83+ CPU_EXCEPT 7
84+ CPU_EXCEPT_CODE 8
85+ CPU_EXCEPT 9
86+ CPU_EXCEPT_CODE 10
87+ CPU_EXCEPT_CODE 11
88+ CPU_EXCEPT_CODE 12
89+ CPU_EXCEPT_CODE 13
90+ CPU_EXCEPT_CODE 14
91+ CPU_EXCEPT 15
92+ CPU_EXCEPT 16
93+ CPU_EXCEPT_CODE 17
94+ CPU_EXCEPT 18
95+ CPU_EXCEPT 19
96+ CPU_EXCEPT 20
97+ CPU_EXCEPT_CODE 30
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ set(ARCH_OBJECTS
55 apic_asm.asm
66 apic_longmode.asm
77 arch_start.asm
8+ exceptions.asm
89 interrupts.asm
910 fiber_asm.asm
1011 ist.cpp
Original file line number Diff line number Diff line change 1+ ; This file is a part of the IncludeOS unikernel - www.includeos.org
2+ ;
3+ ; Copyright 2015 Oslo and Akershus University College of Applied Sciences
4+ ; and Alfred Bratterud
5+ ;
6+ ; Licensed under the Apache License, Version 2.0 (the "License");
7+ ; you may not use this file except in compliance with the License.
8+ ; You may obtain a copy of the License at
9+ ;
10+ ; http://www.apache.org/licenses/LICENSE-2.0
11+ ;
12+ ; Unless required by applicable law or agreed to in writing, software
13+ ; distributed under the License is distributed on an "AS IS" BASIS,
14+ ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ ; See the License for the specific language governing permissions and
16+ ; limitations under the License.
17+ [BITS 64]
18+ extern cpu_exception
19+
20+ SECTION .bss
21+ __amd64_registers:
22+ resb 8 * 24
23+
24+ %macro CPU_EXCEPT 1
25+ global __cpu_except_% 1 :function
26+ __cpu_except_% 1 :
27+ call save_cpu_regs
28+
29+ ;; new stack frame
30+ push rbp
31+ mov rbp , rsp
32+ ;; enter panic
33+ mov rdi , __amd64_registers
34+ mov rsi , % 1
35+ mov rdx , 0
36+ call cpu_exception
37+ %endmacro
38+
39+ %macro CPU_EXCEPT_CODE 1
40+ global __cpu_except_% 1 :function
41+ __cpu_except_% 1 :
42+ call save_cpu_regs
43+
44+ ;; pop error code
45+ pop rdx
46+ ;; new stack frame
47+ push rbp
48+ mov rbp , rsp
49+ ;; enter panic
50+ mov rdi , __amd64_registers
51+ mov rsi , % 1
52+ call cpu_exception
53+ %endmacro
54+
55+ SECTION .text
56+ %define regs(r) [ __amd64_registers + r ]
57+ save_cpu_regs:
58+ mov regs( 0 ) , rax
59+ mov regs( 8 ) , rbx
60+ mov regs( 16 ) , rcx
61+ mov regs( 24 ) , rdx
62+ mov regs( 32 ) , rbp
63+
64+ mov regs( 40 ) , r8
65+ mov regs( 48 ) , r9
66+ mov regs( 56 ) , r10
67+ mov regs( 64 ) , r11
68+ mov regs( 72 ) , r12
69+ mov regs( 80 ) , r13
70+ mov regs( 88 ) , r14
71+ mov regs( 96 ) , r15
72+
73+ mov rax , QWORD [ rsp + 32 ]
74+ mov regs( 104 ) , rax
75+ mov regs( 112 ) , rsi
76+ mov regs( 120 ) , rdi
77+ mov rax , QWORD [ rsp + 8 ]
78+ mov regs( 128 ) , rax
79+
80+ pushf
81+ pop QWORD regs( 136 )
82+ mov rax , cr0
83+ mov regs( 144 ) , rax
84+ mov QWORD regs( 152 ) , 0
85+ mov rbx , cr2
86+ mov regs( 160 ) , rbx
87+ mov rcx , cr3
88+ mov regs( 168 ) , rcx
89+ mov rdx , cr4
90+ mov regs( 176 ) , rdx
91+ mov rax , cr8
92+ mov regs( 184 ) , rax
93+ ret
94+
95+ CPU_EXCEPT 0
96+ CPU_EXCEPT 1
97+ CPU_EXCEPT 2
98+ CPU_EXCEPT 3
99+ CPU_EXCEPT 4
100+ CPU_EXCEPT 5
101+ CPU_EXCEPT 6
102+ CPU_EXCEPT 7
103+ CPU_EXCEPT_CODE 8
104+ CPU_EXCEPT 9
105+ CPU_EXCEPT_CODE 10
106+ CPU_EXCEPT_CODE 11
107+ CPU_EXCEPT_CODE 12
108+ CPU_EXCEPT_CODE 13
109+ CPU_EXCEPT_CODE 14
110+ CPU_EXCEPT 15
111+ CPU_EXCEPT 16
112+ CPU_EXCEPT_CODE 17
113+ CPU_EXCEPT 18
114+ CPU_EXCEPT 19
115+ CPU_EXCEPT 20
116+ CPU_EXCEPT_CODE 30
You can’t perform that action at this time.
0 commit comments