Skip to content

Commit 53acb9f

Browse files
committed
修复内核错误无法输出
1 parent 6963e75 commit 53acb9f

File tree

5 files changed

+18
-31
lines changed

5 files changed

+18
-31
lines changed

src/x86_64/core/error_handle.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,27 @@ extern void double_fault_asm(); // df_asm.S
1212
ticketlock error_lock;
1313

1414
void print_register(interrupt_frame_t *frame) {
15-
printe("ss: 0x%p ", frame->ss);
16-
printe("cs: 0x%p ", frame->cs);
17-
printe("rsp: 0x%p \n", frame->rsp);
18-
printe("rip: 0x%p ", frame->rip);
19-
printe("rflags: 0x%p ", frame->rflags);
20-
printe("cr3: 0x%p \n", get_cr3());
15+
printk("ss: 0x%p ", frame->ss);
16+
printk("cs: 0x%p ", frame->cs);
17+
printk("rsp: 0x%p \n", frame->rsp);
18+
printk("rip: 0x%p ", frame->rip);
19+
printk("rflags: 0x%p ", frame->rflags);
20+
printk("cr3: 0x%p \n", get_cr3());
2121
}
2222

2323
void print_task_info(pcb_t pcb) {
2424
if (pcb == NULL)
25-
printe("Current process PID: 0 (Kernel) CPU%d\n", get_current_cpuid());
25+
printk("Current process PID: 0 (Kernel) CPU%d\n", get_current_cpuid());
2626
else
27-
printe("Current process PID: %d (%s) CPU%d\n", pcb->pid, pcb->name, get_current_cpuid());
27+
printk("Current process PID: %d (%s) CPU%d\n", pcb->pid, pcb->name, get_current_cpuid());
2828
}
2929

3030
void kernel_error(const char *msg, uint64_t code, interrupt_frame_t *frame) {
3131
close_interrupt;
32+
init_print_lock();
3233
ticket_lock(&error_lock);
3334
logkf("Kernel Error: %s:0x%x\n", msg, code);
34-
printe("\033[31m:3 Your CP_Kernel ran into a problem.\nERROR CODE >(%s:0x%x)<\033[0m\n", msg,
35+
printk("\033[31m:3 Your CP_Kernel ran into a problem.\nERROR CODE >(%s:0x%x)<\033[0m\n", msg,
3536
code);
3637
print_task_info(get_current_task());
3738
print_register(frame);

src/x86_64/core/mem/page.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static bool is_huge_page(page_table_entry_t *entry) {
2323

2424
__IRQHANDLER static void page_fault_handle(interrupt_frame_t *frame, uint64_t error_code) {
2525
close_interrupt;
26+
init_print_lock();
2627
disable_scheduler();
2728
switch_page_directory(get_kernel_pagedir());
2829
uint64_t faulting_address;
@@ -31,8 +32,8 @@ __IRQHANDLER static void page_fault_handle(interrupt_frame_t *frame, uint64_t er
3132
if (get_current_task() != NULL) {
3233
logkf("Current process PID: %d (%s)\n", get_current_task()->pid, get_current_task()->name);
3334
}
34-
printe("\n");
35-
printe(
35+
printk("\n");
36+
printk(
3637
"\033[31m:3 Your CP_Kernel ran into a problem.\nERROR CODE >(PageFault%s:0x%p)<\033[0m\n",
3738
!(error_code & 0x1) ? "NotPresent"
3839
: error_code & 0x2 ? "WriteError"

src/x86_64/driver/pci/pcnet.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#include "pcnet.h"
2-
#include "acpi.h"
32
#include "io.h"
43
#include "isr.h"
54
#include "kprint.h"
65
#include "pci.h"
76
#include "pcie.h"
87

98
void pcnet_setup() {
10-
pcie_device_t *device = pcie_find_class(0x10220000);
9+
pcie_device_t *device = pcie_find_class(0x020000);
1110
if (device == NULL) {
12-
pci_device_t pci_device = pci_find_class(0x10220000);
11+
pci_device_t pci_device = pci_find_class(0x020000);
1312
if (pci_device == NULL) return;
1413
uint32_t conf = pci_read_command_status(pci_device);
1514
conf |= PCI_COMMAND_MEMORY;

src/x86_64/include/kprint.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,7 @@ void color_printk(size_t fcolor, size_t bcolor, const char *fmt, ...);
5959

6060
#define printk(...) color_printk(WHITE, BLACK, __VA_ARGS__)
6161

62-
/**
63-
* 中断专用输出
64-
* warning: 该函数会强行解开打印锁并越过原子缓冲队列直接向终端打印, 谨慎使用
65-
* @param fmt
66-
* @param ...
67-
*/
68-
void printe(const char *fmt, ...);
62+
void init_print_lock();
6963

7064
/**
7165
* 内核模块用链接输出

src/x86_64/utils/kprint.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,8 @@ void add_color(char *dest, uint32_t color, int is_background) {
1717
strcat(dest, "m");
1818
}
1919

20-
void printe(const char *fmt, ...) {
21-
ticket_unlock(&print_lock);
22-
ticket_lock(&print_lock);
23-
char buf[4096] = {0};
24-
va_list args;
25-
va_start(args, fmt);
26-
stbsp_vsprintf(buf, fmt, args);
27-
va_end(args);
28-
terminal_process(buf);
29-
ticket_unlock(&print_lock);
20+
void init_print_lock() {
21+
ticket_init(&print_lock);
3022
}
3123

3224
void color_printk(size_t fcolor, size_t bcolor, const char *fmt, ...) {

0 commit comments

Comments
 (0)