Files
claude-os/src/keyboard.h
AI c25ba1fccd feat: shell (sh) with keyboard driver, SYS_READ, SYS_EXEC
- PS/2 keyboard driver: IRQ1 handler, scancode set 1 translation,
  ring buffer, shift key support
- SYS_READ (fd=0): non-blocking keyboard read for stdin
- SYS_YIELD: calls schedule_tick directly (no nested INT 0x80)
- SYS_EXEC: loads binary from CPIO initrd, replaces process image
- User-space libc: crt0.S (C runtime startup), syscalls.h (inline
  syscall wrappers, basic string functions)
- Shell app (sh): readline with echo/backspace, builtins (cd, env,
  help, exit), fork+exec for external commands
- Updated build_apps.sh: C app support with crt0 linking, libc
  include path, .bss section in objcopy

Tested: shell boots, keyboard input works, hello-world runs via
fork+exec, env shows CWD, exit cleanly terminates.
2026-02-23 13:08:06 +00:00

57 lines
1.3 KiB
C

/**
* @file keyboard.h
* @brief PS/2 keyboard driver.
*
* Handles IRQ1 keyboard interrupts, translates scancodes to ASCII,
* and provides a ring buffer for user-space reading via SYS_READ.
*/
#ifndef KEYBOARD_H
#define KEYBOARD_H
#include <stdint.h>
#include "isr.h"
/** Keyboard input buffer size. */
#define KB_BUFFER_SIZE 256
/**
* Initialize the keyboard driver.
*/
void keyboard_init(void);
/**
* Handle a keyboard IRQ (called from isr_handler for IRQ1).
*
* @param regs Register state (may be used to wake blocked processes).
*/
void keyboard_irq(registers_t *regs);
/**
* Read characters from the keyboard buffer.
* Non-blocking: returns whatever is available, 0 if empty.
*
* @param buf Destination buffer.
* @param count Maximum bytes to read.
* @return Number of bytes read.
*/
uint32_t keyboard_read(char *buf, uint32_t count);
/**
* Check if there is data available in the keyboard buffer.
*
* @return Non-zero if data is available.
*/
int keyboard_has_data(void);
/**
* Block the given process until keyboard data is available.
* Sets the process to BLOCKED state and records it as waiting for keyboard.
* When data arrives, the process will be unblocked.
*
* @param regs Current interrupt frame (for saving process state).
*/
void keyboard_block_for_input(registers_t *regs);
#endif /* KEYBOARD_H */