10 #include "sys/cpu_isr.h"
12 #include "sys/unwind.h"
14 #include "sys/scheduler.h"
15 #include <io/status_loggers.h>
17 _Noreturn
void sod_screen_legacy(
registers_t regs,
char* title,
char* msg, uint32_t code) {
18 qemu_err(
"=== ЯДРО УПАЛО =======================================\n");
20 qemu_err(
"| Наименование: %s",title);
21 qemu_err(
"| Код ошибки: %x",code);
22 qemu_err(
"| Сообщение: %s",msg);
23 qemu_err(
"| EAX: %x",regs.eax);
24 qemu_err(
"| EBX: %x",regs.ebx);
25 qemu_err(
"| ECX: %x",regs.ecx);
26 qemu_err(
"| EDX: %x",regs.edx);
27 qemu_err(
"| ESP: %x",regs.esp);
28 qemu_err(
"| EBP: %x",regs.ebp);
29 qemu_err(
"| EIP: %x",regs.eip);
30 qemu_err(
"| EFLAGS: %x",regs.eflags);
32 qemu_err(
"======================================================\n");
47 qemu_note(
"EXIT HERE");
51 __asm__
volatile(
"cli");
52 __asm__
volatile(
"hlt");
55 __asm__
volatile(
"nop");
59 _Noreturn
void bsod_screen(
registers_t regs,
char* title,
char* msg, uint32_t code){
60 qemu_log(
"=== ЯДРО УПАЛО =======================================\n");
62 qemu_log(
"| Наименование: %s",title);
63 qemu_log(
"| Код ошибки: %x",code);
64 qemu_log(
"| Сообщение: %s",msg);
65 qemu_log(
"| EAX: %x",regs.eax);
66 qemu_log(
"| EBX: %x",regs.ebx);
67 qemu_log(
"| ECX: %x",regs.ecx);
68 qemu_log(
"| EDX: %x",regs.edx);
69 qemu_log(
"| ESP: %x",regs.esp);
70 qemu_log(
"| EBP: %x",regs.ebp);
71 qemu_log(
"| EIP: %x",regs.eip);
72 qemu_log(
"| EFLAGS: %x",regs.eflags);
74 qemu_log(
"======================================================\n");
80 __asm__
volatile(
"cli");
81 __asm__
volatile(
"hlt");
84 __asm__
volatile(
"nop");
89 qemu_log(
"EAX = %x", regs.eax);
90 qemu_log(
"EBX = %x", regs.ebx);
91 qemu_log(
"ECX = %x", regs.ecx);
92 qemu_log(
"EDX = %x", regs.edx);
93 qemu_log(
"ESP = %x", regs.esp);
94 qemu_log(
"EBP = %x", regs.ebp);
95 qemu_log(
"EIP = %x", regs.eip);
96 qemu_log(
"EFLAGS = %x", regs.eflags);
101 qemu_log(
"Exception: DIVISION BY ZERO\n");
102 print_regs(regs); bsod_screen(regs,
"CRITICAL_ERROR_DZ_DIVISION_BY_ZERO",
"Деление на ноль",regs.eax);
106 qemu_log(
"FAULT OPERATION CODE...\n");
107 print_regs(regs); bsod_screen(regs,
"CRITICAL_ERROR_UD_FAULT_OPERATION_CODE",
"Невалидный код",regs.eax);
111 qemu_log(
"Exception: DOUBLE EXCEPTION\n");
112 qemu_log(
"Error code: %d", regs.err_code); bsod_screen(regs,
"CRITICAL_ERROR_DF_DOUBLE_EXCEPTION",
"Двойное исключение",regs.err_code);
116 uint32_t ext = regs.err_code & EXT_BIT;
117 uint32_t idt = regs.err_code & IDT_BIT;
118 uint32_t ti = regs.err_code & TI_BIT;
119 uint32_t selector = regs.err_code & ERR_CODE_MASK;
121 qemu_log(
"Exception: INVALID TSS\n");
122 qemu_log(
"cause of error: ");
124 char* msg =
"Недействительный TSS";
126 qemu_log(
"HARDWARE INTERRUPT\n");
127 msg =
"Аппаратное прерывание";
131 qemu_log(
"IDT GATE\n");
136 qemu_log(
"LDT GATE\n");
140 qemu_log(
"Invalid selector: %d", selector);
141 bsod_screen(regs,
"CRITICAL_ERROR_TS_INVALID_TS", msg, selector);
145 uint32_t ext = regs.err_code & EXT_BIT;
146 uint32_t idt = regs.err_code & IDT_BIT;
147 uint32_t ti = regs.err_code & TI_BIT;
148 uint32_t selector = regs.err_code & ERR_CODE_MASK;
150 qemu_log(
"Exception: SEGMENT IS'T AVAILABLE\n");
151 qemu_log(
"cause of error: ");
153 char* msg =
"СЕГМЕНТ НЕДОСТУПЕН";
156 qemu_log(
"HARDWARE INTERRUPT\n");
157 msg =
"Аппаратное прерывание";
162 qemu_log(
"IDT GATE\n");
168 qemu_log(
"LDT GATE\n");
172 qemu_log(
"Invalid selector: %d", selector);
173 bsod_screen(regs,
"CRITICAL_ERROR_NP_SEGMENT_IST_AVAILABLE", msg, selector);
177 qemu_log(
"Exception: STACK ERROR\n");
178 qemu_log(
"Error code: %d ", regs.err_code);
179 bsod_screen(regs,
"CRITICAL_ERROR_SS_STACK_ERROR",
"Ошибка стека",regs.err_code);
183 qemu_log(
"Exception: GENERAL PROTECTION ERROR\n");
184 qemu_log(
"Error code: %d", regs.err_code);
186 bsod_screen(regs,
"CRITICAL_ERROR_GP_GENERAL_PROTECTION",
"Общая ошибка защиты", regs.err_code);
190 uint32_t fault_addr = read_cr2();
191 int present = !(regs.err_code & 0x1);
192 uint32_t rw = regs.err_code & 0x2;
193 uint32_t user = regs.err_code & 0x4;
194 uint32_t reserved = regs.err_code & 0x8;
195 uint32_t
id = regs.err_code & 0x10;
196 qemu_log(
"Page fault: ");
197 char* msg =
"Переполнение памяти буфера";
199 qemu_log(
"NOT PRESENT, ");
200 msg =
"Память по данному адресу недоступна";
203 qemu_log(
"READ ONLY, ");
204 msg =
"Память только для чтения";
207 qemu_log(
"USER MODE, ");
208 msg =
"Память только для пользователя";
211 qemu_log(
"WRITING TO RESERVED BITS, ");
212 msg =
"Попытка записи в зарез. биты";
215 qemu_log(
"EIP error ");
218 qemu_log(
"at address (virtual) %x",fault_addr);
222 tty_printf(
"NOT PRESENT, ");
225 tty_printf(
"READ ONLY, ");
228 tty_printf(
"USER MODE, ");
231 tty_printf(
"WRITING TO RESERVED BITS, ");
234 tty_printf(
"EIP error ");
236 tty_printf(
"at address (virtual) %x",fault_addr);
240 sod_screen_legacy(regs,
"CRITICAL_ERROR_PF_PAGE_FAULT", msg, fault_addr);
244 qemu_log(
"Exception: FPU_FAULT\n");
245 qemu_log(
"Error code: %d ", regs.err_code);
246 bsod_screen(regs,
"CRITICAL_ERROR_FPU_FAULT",
"Ошибка FPU", regs.err_code);
volatile process_t * get_current_proc(void)
Получить текущий обработчик процесса