Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Documentation/admin-guide/boot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ BIOS 入口检查 CPU 能力、建立页表与栈后进入共享 64 位内核。
日志
====

启动日志可镜像到 COM1。``logcolor=0`` 关闭内核颜色,``bootlog-pause=1``
在启动检查点等待输入;普通启动继续进入用户态。文字控制台采用现有
framebuffer 字形、pitch 和原生 RGB 转换,不假设紧密排列的 32 位像素。
内核日志使用 ``[启动后秒数] [等级] [组件] 消息`` 格式。默认保留 INFO、WARN、ERROR 和
FATAL。常见的进程启动、退出、回收及硬件缺席记录仅在 DEBUG 下输出。``debug`` 或 ``loglevel=8`` 开启
DEBUG,``quiet`` 等效于 ``loglevel=4``。``loglevel=N`` 接受 0–8,输出优先级数值小于 N 的记录。FATAL 和
panic 始终保留紧急输出。

``log=screen,serial`` 是默认值。可用 ``log=screen`` 或 ``log=serial`` 只选一个日志目标,也可用
``log=none`` 关闭常规内核日志。``logcolor=0`` 关闭普通日志颜色。``bootlog-pause=1``
在启动检查点等待输入。``syscall-trace=/path/prefix`` 为匹配的程序启用系统调用诊断。

COM1 使用 115200 波特、8N1。早期启动和 panic 使用有界轮询。进入用户态后,内核日志和控制台镜像进入 32 KiB 发送队列,由 IRQ4
批量填充 UART FIFO,定时器负责兜底。队列为 WARN 和 ERROR 预留空间。积压清空后,串口报告丢弃的日志和控制台镜像数量。直接写入
``/dev/ttyS0`` 时,阻塞写等待可用空间,非阻塞写在无法接收任何字节时返回 ``EAGAIN``。关闭或重启系统前会尝试发送队列中的数据。

文字控制台使用现有 framebuffer 字形、pitch 和原生 RGB 转换,可处理带行间填充的帧缓冲。
19 changes: 11 additions & 8 deletions Documentation/locale/en/LC_MESSAGES/admin-guide/boot.po
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ msgstr ""
msgid "日志"
msgstr "Logging"

msgid ""
"启动日志可镜像到 COM1。``logcolor=0`` 关闭内核颜色,``bootlog-pause=1`` 在启动检查点等待输入;普通启动继续进入用户态。文字控制台采用现有 "
"framebuffer 字形、pitch 和原生 RGB 转换,不假设紧密排列的 32 位像素。"
msgstr ""
"Boot logs can be mirrored to COM1. ``logcolor=0`` disables kernel colors, and ``bootlog-pause=1`` "
"waits for input at boot checkpoints; normal boot proceeds into userspace. The text console uses "
"the existing framebuffer glyphs, pitch, and native RGB conversion, without assuming tightly packed"
" 32-bit pixels."
msgid "内核日志使用 ``[启动后秒数] [等级] [组件] 消息`` 格式。默认保留 INFO、WARN、ERROR 和 FATAL。常见的进程启动、退出、回收及硬件缺席记录仅在 DEBUG 下输出。``debug`` 或 ``loglevel=8`` 开启 DEBUG,``quiet`` 等效于 ``loglevel=4``。``loglevel=N`` 接受 0–8,输出优先级数值小于 N 的记录。FATAL 和 panic 始终保留紧急输出。"
msgstr "Kernel records use ``[seconds since boot] [level] [component] message``. INFO, WARN, ERROR, and FATAL are enabled by default. Routine process launches, exits, reaping, and absent hardware are visible at DEBUG. Use ``debug`` or ``loglevel=8`` to enable DEBUG. ``quiet`` is equivalent to ``loglevel=4``. ``loglevel=N`` accepts 0–8 and emits priorities numerically below N. Emergency FATAL and panic output remains enabled."

msgid "``log=screen,serial`` 是默认值。可用 ``log=screen`` 或 ``log=serial`` 只选一个日志目标,也可用 ``log=none`` 关闭常规内核日志。``logcolor=0`` 关闭普通日志颜色。``bootlog-pause=1`` 在启动检查点等待输入。``syscall-trace=/path/prefix`` 为匹配的程序启用系统调用诊断。"
msgstr "``log=screen,serial`` is the default. Use ``log=screen`` or ``log=serial`` for a single log sink, or ``log=none`` to disable regular kernel records. ``logcolor=0`` disables regular log colors. ``bootlog-pause=1`` waits for input at a boot checkpoint. ``syscall-trace=/path/prefix`` enables syscall diagnostics for matching programs."

msgid "COM1 使用 115200 波特、8N1。早期启动和 panic 使用有界轮询。进入用户态后,内核日志和控制台镜像进入 32 KiB 发送队列,由 IRQ4 批量填充 UART FIFO,定时器负责兜底。队列为 WARN 和 ERROR 预留空间。积压清空后,串口报告丢弃的日志和控制台镜像数量。直接写入 ``/dev/ttyS0`` 时,阻塞写等待可用空间,非阻塞写在无法接收任何字节时返回 ``EAGAIN``。关闭或重启系统前会尝试发送队列中的数据。"
msgstr "COM1 uses 115200 baud, 8N1. Early boot and panic use bounded polling. After entering userspace, kernel logs and console mirroring use a 32 KiB transmit queue. IRQ4 fills the UART FIFO in batches, and the timer provides a fallback. The queue reserves space for WARN and ERROR. After the backlog drains, serial output reports the number of dropped records and console chunks. Blocking writes to ``/dev/ttyS0`` wait for space. Nonblocking writes return ``EAGAIN`` when no input bytes fit. Shutdown and reboot attempt to flush the queue."

msgid "文字控制台使用现有 framebuffer 字形、pitch 和原生 RGB 转换,可处理带行间填充的帧缓冲。"
msgstr "The text console uses the existing framebuffer glyphs, pitch, and native RGB conversion and supports framebuffers with row padding."
18 changes: 11 additions & 7 deletions Documentation/locale/ja/LC_MESSAGES/admin-guide/boot.po
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ msgstr ""
msgid "日志"
msgstr "ログ"

msgid ""
"启动日志可镜像到 COM1。``logcolor=0`` 关闭内核颜色,``bootlog-pause=1`` 在启动检查点等待输入;普通启动继续进入用户态。文字控制台采用现有 "
"framebuffer 字形、pitch 和原生 RGB 转换,不假设紧密排列的 32 位像素。"
msgstr ""
"起動ログは COM1 にも出力できます。``logcolor=0`` はカーネルの色表示を無効にし、``bootlog-pause=1`` "
"は起動チェックポイントで入力を待ちます。通常の起動はそのままユーザー空間へ進みます。テキストコンソールは既存の framebuffer 字形、pitch、ネイティブ RGB 変換を使い、32 "
"ビットピクセルが隙間なく並ぶことは前提としません。"
msgid "内核日志使用 ``[启动后秒数] [等级] [组件] 消息`` 格式。默认保留 INFO、WARN、ERROR 和 FATAL。常见的进程启动、退出、回收及硬件缺席记录仅在 DEBUG 下输出。``debug`` 或 ``loglevel=8`` 开启 DEBUG,``quiet`` 等效于 ``loglevel=4``。``loglevel=N`` 接受 0–8,输出优先级数值小于 N 的记录。FATAL 和 panic 始终保留紧急输出。"
msgstr "カーネルログは ``[起動後の秒数] [レベル] [コンポーネント] メッセージ`` の形式を使用します。既定では INFO、WARN、ERROR、FATAL が有効です。通常のプロセス起動、終了、回収、およびハードウェア未検出の記録は DEBUG で確認できます。``debug`` または ``loglevel=8`` で DEBUG を有効にできます。``quiet`` は ``loglevel=4`` と同等です。``loglevel=N`` は 0–8 を受け付け、数値が N 未満の優先度を出力します。FATAL と panic の緊急出力は常に有効です。"

msgid "``log=screen,serial`` 是默认值。可用 ``log=screen`` 或 ``log=serial`` 只选一个日志目标,也可用 ``log=none`` 关闭常规内核日志。``logcolor=0`` 关闭普通日志颜色。``bootlog-pause=1`` 在启动检查点等待输入。``syscall-trace=/path/prefix`` 为匹配的程序启用系统调用诊断。"
msgstr "既定は ``log=screen,serial`` です。``log=screen`` または ``log=serial`` で出力先を一つに絞り、``log=none`` で通常のカーネルログを無効にできます。``logcolor=0`` で通常のログの色を無効にします。``bootlog-pause=1`` は起動中のチェックポイントで入力を待ちます。``syscall-trace=/path/prefix`` は該当するプログラムのシステムコール診断を有効にします。"

msgid "COM1 使用 115200 波特、8N1。早期启动和 panic 使用有界轮询。进入用户态后,内核日志和控制台镜像进入 32 KiB 发送队列,由 IRQ4 批量填充 UART FIFO,定时器负责兜底。队列为 WARN 和 ERROR 预留空间。积压清空后,串口报告丢弃的日志和控制台镜像数量。直接写入 ``/dev/ttyS0`` 时,阻塞写等待可用空间,非阻塞写在无法接收任何字节时返回 ``EAGAIN``。关闭或重启系统前会尝试发送队列中的数据。"
msgstr "COM1 は 115200 ボー、8N1 を使用します。起動初期と panic では上限付きのポーリングを使います。ユーザー空間に移行すると、カーネルログとコンソールの複製は 32 KiB の送信キューに入ります。IRQ4 が UART FIFO にまとめて書き込み、タイマーはその補助を行います。キューには WARN と ERROR 用の領域を確保します。滞留データの送信後、破棄したログとコンソール出力の件数をシリアルに出力します。``/dev/ttyS0`` のブロッキング書き込みは空き領域を待ちます。ノンブロッキング書き込みで入力を 1 バイトも受け付けられない場合は ``EAGAIN`` を返します。シャットダウンと再起動の前に送信キューの排出を試みます。"

msgid "文字控制台使用现有 framebuffer 字形、pitch 和原生 RGB 转换,可处理带行间填充的帧缓冲。"
msgstr "テキストコンソールは既存のフレームバッファーのグリフ、ピッチ、およびネイティブ RGB 変換を使用し、行パディングのあるフレームバッファーに対応します。"
8 changes: 1 addition & 7 deletions arch/x86_64/interrupt/idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,11 @@ struct task *page_fault_dispatch(struct trap_frame *frame)
bugcheck_exception(14, 0, 0, 0, 0, 0, 0, cr2);
}
if ((frame->cs & 3ULL) == 3ULL) {
console_fatal("[reliefnt] page fault unhandled cr2=0x%llx error=0x%llx rip=0x%llx cs=0x%llx\n",
console_debug("[reliefnt] user page fault unhandled cr2=0x%llx error=0x%llx rip=0x%llx cs=0x%llx\n",
(unsigned long long)cr2,
(unsigned long long)frame->error,
(unsigned long long)frame->rip,
(unsigned long long)frame->cs);
console_fatal("[reliefnt] page fault flags present=%u write=%u user=%u reserved=%u fetch=%u\n",
(unsigned)(frame->error & 1u),
(unsigned)((frame->error >> 1) & 1u),
(unsigned)((frame->error >> 2) & 1u),
(unsigned)((frame->error >> 3) & 1u),
(unsigned)((frame->error >> 4) & 1u));
kernel_spin_unlock(&user_page_fault_lock);
memory_wait_cancel(sched_current_task());
signal_user_page_fault(frame, cr2);
Expand Down
9 changes: 9 additions & 0 deletions arch/x86_64/interrupt/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <reliefnt/lock.h>
#include <reliefnt/sched.h>
#include <reliefnt/smp.h>
#include <reliefnt/serial.h>
#include <reliefnt/time.h>
#include <reliefnt/trap.h>
#include <reliefnt/userland.h>
Expand Down Expand Up @@ -83,6 +84,7 @@ static void pic_remap(void)
io_wait();

uint8_t mask1 = (uint8_t)~((1u << 0) | (1u << 1) | (1u << 2));
if (serial_com1_available()) mask1 &= (uint8_t)~(1u << 4);
uint8_t mask2 = (uint8_t)~(1u << 4);
x86_64_outb(mask1, PIC1_DATA);
x86_64_outb(mask2, PIC2_DATA);
Expand Down Expand Up @@ -159,18 +161,21 @@ void irq_init(void)
if (routed) {
pic_mask_all();
irq_uses_ioapic = true;
serial_tx_set_irq(serial_com1_available() && ioapic_route_irq(4u, 0x24u, apic_bsp_id()));
console_info("[reliefnt] IOAPIC owns PIT/keyboard/mouse, PIT=%uHz BSP=%u\n",
(unsigned)RELIEFNT_TICK_HZ, (unsigned)apic_bsp_id());
return;
}
/* Fall back to the LAPIC virtual-wire bridge. This keeps legacy PIC
* delivery alive after SMP enables the BSP local APIC. */
apic_enable_legacy_pic();
serial_tx_set_irq(serial_com1_available());
irq_uses_local_apic = apic_enabled();
console_info("[reliefnt] PIC virtual-wire owns IRQ0/1/12, PIT=%uHz\n",
(unsigned)RELIEFNT_TICK_HZ);
return;
}
serial_tx_set_irq(serial_com1_available());
console_info("[reliefnt] PIC remapped, PIT=%uHz, IRQ0/1/12 enabled\n",
(unsigned)RELIEFNT_TICK_HZ);
}
Expand All @@ -195,6 +200,7 @@ struct task *irq_dispatch(struct trap_frame *frame)
}
if (vector == 0x20) {
time_on_tick();
serial_tx_tick();
if (from_user) {
uint8_t byte;
if (keyboard_led_next(&keyboard_led, input_caps_lock_active() ? 4U : 0U,
Expand Down Expand Up @@ -264,6 +270,9 @@ struct task *irq_dispatch(struct trap_frame *frame)
}
}
irq_send_eoi(1);
} else if (vector == 0x24) {
serial_tx_irq();
irq_send_eoi(4);
} else if (vector == 0x2c) {
driver_manager_mouse_poll();
irq_send_eoi(12);
Expand Down
3 changes: 3 additions & 0 deletions arch/x86_64/platform/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Provides shutdown, reboot, and platform-specific fallback mechanisms.
*/
#include <reliefnt/console.h>
#include <reliefnt/serial.h>
#include <reliefnt/multiboot2.h>
#include <reliefnt/power.h>
#include <reliefnt/paging.h>
Expand Down Expand Up @@ -835,6 +836,7 @@ static int acpi_enable_power_management(void)
void power_reboot(void)
{
console_info("[reliefnt] reboot requested\n");
serial_tx_flush();
for (;;) {
while (x86_64_inb(0x64) & 0x02) {
}
Expand All @@ -849,6 +851,7 @@ void power_reboot(void)
void power_shutdown(void)
{
console_info("[reliefnt] shutdown requested\n");
serial_tx_flush();
if (acpi_enable_power_management()) {
uint16_t sleep_enable = 1U << 13;
uint16_t pm1a = x86_64_inw(acpi_power.pm1a_control);
Expand Down
89 changes: 24 additions & 65 deletions drivers/console/core.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "internal.h"
#include <reliefnt/serial.h>

static void vga_console_ansi_feed(char character);

Expand Down Expand Up @@ -43,8 +44,6 @@ uint32_t fb_row;

uint32_t console_ui_theme = 1u;

bool console_line_start = true;

bool console_service_logs_only;

static bool console_presenting;
Expand Down Expand Up @@ -101,27 +100,21 @@ static void vga_console_ansi_feed(char character)
}
}

void console_emit_raw(char ch)
/** @brief Render one encoded record while the boot console owns the display. */
void console_emit_display(const char *text, size_t length)
{
char s[2] = {ch, 0};
if (console_vga_text_mode) {
log_store(ch);
serial_write(s);
if (!console_service_logs_only) vga_console_boot_byte(ch);
console_line_start = ch == '\n';
return;
}
if (!console_service_logs_only) fb_console_hide_tty_cursor();
log_store(ch);
serial_write(s);
if (vga_console_enabled && !console_service_logs_only) {
vga_putc(ch);
if (console_service_logs_only) return;
if (!console_vga_text_mode) fb_console_hide_tty_cursor();
for (size_t i = 0; i < length; ++i) {
char ch = text[i];
if (console_vga_text_mode) vga_console_boot_byte(ch);
else {
if (vga_console_enabled) vga_console_ansi_feed(ch);
if (ch == '\n') fb_console_ansi_feed('\r');
fb_console_ansi_feed(ch);
}
}
if (!console_service_logs_only) {
if (ch == '\n') fb_console_newline();
else fb_console_putc(ch);
}
console_line_start = ch == '\n';
console_present();
}

/** @brief Draw the cursor and publish an active text grid when not staging. */
Expand Down Expand Up @@ -149,54 +142,20 @@ void console_set_ui_theme(uint32_t theme)
console_ui_theme = theme == 0u ? 0u : 1u;
}

void console_putc(char ch)
{
if (console_line_start) {
console_emit_timestamp();
}
console_emit_raw(ch);
}

void console_write(const char *s)
{
while (s && *s) {
console_putc(*s++);
}
}

/**
* @brief Append raw diagnostic output to the kernel log and serial sink.
* @param s Bytes to write; need not be NUL-terminated.
* @param len Number of bytes to write.
*/
void console_write_len(const char *s, size_t len)
{
for (size_t i = 0; i < len; ++i) {
console_putc(s[i]);
}
}

/**
* @brief Mirror system-console bytes to serial without creating kernel log records.
* @param s Bytes already accepted by the console terminal.
* @param len Number of bytes to mirror; s need not be NUL-terminated.
*/
void console_serial_write_len(const char *s, size_t len)
void console_serial_write_len(const char *text, size_t length)
{
for (size_t i = 0; i < len; ++i) {
char byte[2] = {s[i], 0};
serial_write(byte);
if (!text) return;
char data[512];
/* Do not retain user pointers or run their faults in the TX lock. */
while (length) {
size_t chunk = length < sizeof(data) ? length : sizeof(data);
__builtin_memcpy(data, text, chunk);
serial_tx_record(data, chunk, false);
length -= chunk;
text += chunk;
}
}

void console_printf(const char *fmt, ...)
{
va_list arguments;
va_start(arguments, fmt);
console_vlog(CONSOLE_LOG_INFO, fmt, arguments);
va_end(arguments);
}

void console_enable_framebuffer(void)
{
if (console_vga_text_mode) return;
Expand Down
8 changes: 2 additions & 6 deletions drivers/console/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ extern uint32_t fb_rows;
extern uint32_t fb_col;
extern uint32_t fb_row;
extern uint32_t console_ui_theme;
extern bool console_line_start;
extern bool console_service_logs_only;
extern uint32_t fb_saved_col;
extern uint32_t fb_saved_row;
Expand Down Expand Up @@ -348,25 +347,22 @@ void fb_console_stream_restore(const struct fb_console_state *state);
/** @brief Reset text state and clear the full active rendering surface. */
void fb_console_initialize_fullscreen(void);

void console_emit_raw(char ch);
void console_emit_display(const char *text, size_t length);

/** @brief Draw the cursor and publish an active text grid when not staging. */
void console_present(void);

void console_emit_timestamp(void);

void console_init(void);

void console_log_configure(const char *cmdline);

void console_set_ui_theme(uint32_t theme);

void console_putc(char ch);

void console_write(const char *s);

/**
* @brief Append raw diagnostic output to the kernel log and serial sink.
* @brief Append length-delimited input as INFO records in the kernel log.
* @param s Bytes to write; need not be NUL-terminated.
* @param len Number of bytes to write.
*/
Expand Down
Loading
Loading