Kernel: Fix triple-fault in vitual tty

This was happening when printing non-utf8 data while having virtual tty
as the debug console.
This commit is contained in:
Bananymous 2024-12-09 03:35:51 +02:00
parent 3ae6ffdb01
commit 12a37500b0
2 changed files with 14 additions and 11 deletions

View File

@ -47,6 +47,7 @@
#define BOCHS_BREAK() asm volatile("xchgw %bx, %bx") #define BOCHS_BREAK() asm volatile("xchgw %bx, %bx")
#define DEBUG_VTTY 1
#define DEBUG_PCI 0 #define DEBUG_PCI 0
#define DEBUG_SCHEDULER 0 #define DEBUG_SCHEDULER 0

View File

@ -251,7 +251,7 @@ namespace Kernel
return reset_ansi(); return reset_ansi();
} }
reset_ansi(); reset_ansi();
dprintln("Unsupported ANSI CSI character J"); dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character J");
return; return;
case 'K': // Erase in Line case 'K': // Erase in Line
if (m_ansi_state.nums[0] == -1 || m_ansi_state.nums[0] == 0) if (m_ansi_state.nums[0] == -1 || m_ansi_state.nums[0] == 0)
@ -261,7 +261,7 @@ namespace Kernel
return reset_ansi(); return reset_ansi();
} }
reset_ansi(); reset_ansi();
dprintln("Unsupported ANSI CSI character K"); dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character K");
return; return;
case 'L': // Insert Line case 'L': // Insert Line
if (m_ansi_state.nums[0] == -1) if (m_ansi_state.nums[0] == -1)
@ -297,15 +297,15 @@ namespace Kernel
return reset_ansi(); return reset_ansi();
case 'S': // Scroll Up case 'S': // Scroll Up
reset_ansi(); reset_ansi();
dprintln("Unsupported ANSI CSI character S"); dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character S");
return; return;
case 'T': // Scroll Down case 'T': // Scroll Down
reset_ansi(); reset_ansi();
dprintln("Unsupported ANSI CSI character T"); dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character T");
return; return;
case 'f': // Horizontal Vertical Position case 'f': // Horizontal Vertical Position
reset_ansi(); reset_ansi();
dprintln("Unsupported ANSI CSI character f"); dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character f");
return; return;
case 'm': case 'm':
handle_ansi_csi_color(); handle_ansi_csi_color();
@ -350,7 +350,7 @@ namespace Kernel
return reset_ansi(); return reset_ansi();
} }
reset_ansi(); reset_ansi();
dprintln("invalid ANSI CSI ?"); dprintln_if(DEBUG_VTTY, "invalid ANSI CSI ?");
return; return;
case 'h': case 'h':
case 'l': case 'l':
@ -360,11 +360,11 @@ namespace Kernel
return reset_ansi(); return reset_ansi();
} }
reset_ansi(); reset_ansi();
dprintln("invalid ANSI CSI ?{}{}", m_ansi_state.nums[0], (char)ch); dprintln_if(DEBUG_VTTY, "invalid ANSI CSI ?{}{}", m_ansi_state.nums[0], (char)ch);
return; return;
default: default:
reset_ansi(); reset_ansi();
dprintln("Unsupported ANSI CSI character {}", ch); dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character {}", ch);
return; return;
} }
} }
@ -416,7 +416,9 @@ namespace Kernel
} }
else else
{ {
dprintln("invalid utf8"); reset_ansi();
dprintln_if(DEBUG_VTTY, "invalid utf8");
return;
} }
m_state = State::WaitingUTF8; m_state = State::WaitingUTF8;
return; return;
@ -425,8 +427,8 @@ namespace Kernel
m_state = State::WaitingAnsiCSI; m_state = State::WaitingAnsiCSI;
else else
{ {
dprintln("unsupported byte after ansi escape {2H}", (uint8_t)ch);
reset_ansi(); reset_ansi();
dprintln_if(DEBUG_VTTY, "unsupported byte after ansi escape {2H}", (uint8_t)ch);
} }
return; return;
case State::WaitingAnsiCSI: case State::WaitingAnsiCSI:
@ -436,8 +438,8 @@ namespace Kernel
case State::WaitingUTF8: case State::WaitingUTF8:
if ((ch & 0xC0) != 0x80) if ((ch & 0xC0) != 0x80)
{ {
dprintln("invalid utf8");
m_state = State::Normal; m_state = State::Normal;
dprintln_if(DEBUG_VTTY, "invalid utf8");
return; return;
} }
m_utf8_state.codepoint = (m_utf8_state.codepoint << 6) | (ch & 0x3F); m_utf8_state.codepoint = (m_utf8_state.codepoint << 6) | (ch & 0x3F);