1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*
* Copyright (c) 2025 Ian Marco Moffett and the Osmora Team.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Hyra nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/cdefs.h>
#include <os/trace.h>
#include <mu/panic.h>
/*
* XXX: We could implement panic() as an assembly stub
* that takes a register snapshot and passes it to
* an MI routine which calls into the MD side using
* it as an argument, that could be better...
*/
void
mu_panic_dump(void)
{
static uint64_t cr4, cr3, cr2, cr0;
static uint64_t rax, rbx, rcx, rdx;
static uint64_t r[16], rbp, rsp;
__asmv(
"mov %%cr4, %0\n\t"
"mov %%cr3, %1\n\t"
"mov %%cr2, %2\n\t"
"mov %%cr0, %3"
: "=r" (cr4),
"=r" (cr3),
"=r" (cr2),
"=r" (cr0)
:
: "memory"
);
__asmv(
"mov %%r8, %0\n\t"
"mov %%r9, %1\n\t"
"mov %%r10, %2\n\t"
"mov %%r11, %3\n\t"
"mov %%r12, %4\n\t"
"mov %%r13, %5\n\t"
"mov %%r14, %6\n\t"
"mov %%r15, %7\n\t"
"mov %%rax, %8\n\t"
"mov %%rbx, %8\n\t"
"mov %%rcx, %9\n\t"
"mov %%rdx, %10\n\t"
"mov %%rbp, %11\n\t"
"mov %%rsp, %12"
: "=r" (r[0]),
"=r" (r[1]),
"=r" (r[2]),
"=r" (r[3]),
"=r" (r[4]),
"=r" (r[5]),
"=r" (r[6]),
"=r" (r[7]),
"=r" (rax),
"=r" (rbx),
"=r" (rcx),
"=r" (rdx),
"=r" (rbp),
"=r" (rsp)
:
: "memory"
);
trace(
"CR0=%p CR2=%p\nCR3=%p CR4=%p\n",
cr0, cr2, cr3, cr4
);
trace(
"---------------------------------------------\n"
"RAX=%p RBX=%p\nRCX=%p RDX=%p\n"
"RBP=%p RSP=%p\n",
rax, rbx, rcx, rdx,
rbp, rsp
);
trace(
"---------------------------------------------\n"
"R15=%p R14=%p\nR13=%p R12=%p\nR11=%p R10=%p\n"
"R9=%p R8=%p",
r[7], r[6], r[5],
r[4], r[3], r[2],
r[1], r[0]
);
}
void
mu_panic_hcf(void)
{
for (;;) {
asm volatile("cli; hlt");
}
}
|