Skip to content

[Bug] Interactive Keyboard Input Causes System Crash #3

@Shashank0701-byte

Description

@Shashank0701-byte

Description

When attempting to use interactive keyboard input in the shell, the system experiences a crash/reboot upon any keypress. The keyboard interrupt fires correctly, but processing the input causes system instability.

Current Behavior

  • ✅ OS boots successfully
  • ✅ Shell displays correctly with prompt
  • ✅ Keyboard interrupts fire (IRQ1)
  • ❌ Any keypress causes screen flicker and system reset

Expected Behavior

User should be able to type commands in the shell, with characters echoing to screen and command execution on Enter.

Technical Details

Environment:

  • Architecture: x86 (32-bit)
  • Emulator: QEMU (qemu-system-i386)
  • Compiler: GCC with -m32 -ffreestanding
  • Assembler: NASM

Relevant Code:

  • Keyboard driver: kernel/keyboard.c
  • Interrupt handler: kernel/isr.asm (IRQ1)
  • Shell loop: kernel/shell.c

What Works:

  • Keyboard interrupt (IRQ1) fires correctly
  • Scancode reading from port 0x60
  • Buffer management (tested in isolation)
  • Shell command parsing (tested with simulated input)

What Fails:

  • System crashes when putchar() is called from any context after keyboard interrupt
  • Issue persists whether using direct echo or buffer-based approach
  • Crash occurs even with interrupt protection (CLI/STI)

Debugging Attempted

  1. ✅ Verified IDT setup and IRQ remapping
  2. ✅ Tested with minimal interrupt handler (just read scancode + EOI)
  3. ✅ Tried buffer-based approach (interrupt adds to buffer, main loop reads)
  4. ✅ Disabled hardware cursor updates
  5. ✅ Simplified IRQ handler to remove argument passing
  6. ✅ Tested with both GRUB/Multiboot and custom bootloader

Hypothesis

Possible causes:

  • Stack corruption in interrupt handler
  • Calling convention mismatch (Windows GCC vs standard)
  • Race condition between interrupt handler and main loop
  • VGA memory access issue from interrupt context

Next Steps

  • Use GDB with QEMU to identify exact crash location
  • Add serial port debugging for interrupt handler tracing
  • Test with different compiler flags
  • Review ISR assembly for register preservation issues

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions