Use uint8_t for keyboard chars

This commit is contained in:
2025-09-19 21:00:33 +02:00
parent 504bdbd4ba
commit 1af0d1f5bc
3 changed files with 16 additions and 26 deletions

View File

@ -215,13 +215,13 @@ void intr_handleintr(IntrStackFrame *frame) {
break; break;
case INTR_IRQBASE+1: case INTR_IRQBASE+1:
int32_t c = ps2kb_intr(); int32_t c = ps2kb_intr();
intr_eoi(frame->trapnum - INTR_IRQBASE);
if (c >= 0) { if (c >= 0) {
uint8_t *bytes = (uint8_t *)&c; uint8_t b = c;
for (size_t i = 0; i < sizeof(c); i++) { spinlock_acquire(&PS2KB_BUF.spinlock);
rbuf_push(&PS2KB_BUF.rbuf, bytes[i]); rbuf_push(&PS2KB_BUF.rbuf, b);
} spinlock_release(&PS2KB_BUF.spinlock);
} }
intr_eoi(frame->trapnum - INTR_IRQBASE);
break; break;
} }
} else if (frame->trapnum == 0x80) { } else if (frame->trapnum == 0x80) {

View File

@ -22,26 +22,18 @@ void ps2kbproc_init(Proc *proc) {
void ps2kbproc_fn(void) { void ps2kbproc_fn(void) {
for (;;) { for (;;) {
int32_t kbchr = 0; uint8_t b = 0;
uint8_t *buf = (uint8_t *)&kbchr;
size_t total = 0;
spinlock_acquire(&PS2KB_BUF.spinlock); spinlock_acquire(&PS2KB_BUF.spinlock);
for (size_t i = 0; i < sizeof(kbchr); i++) { if (rbuf_pop(&PS2KB_BUF.rbuf, &b) == 0) {
if (rbuf_pop(&PS2KB_BUF.rbuf, &buf[i]) < 0) {
break;
}
total++;
}
spinlock_release(&PS2KB_BUF.spinlock);
if (total == sizeof(kbchr)) {
spinlock_acquire(&PS2KBPROC->bcast_pipes.spinlock); spinlock_acquire(&PS2KBPROC->bcast_pipes.spinlock);
IpcPipe *head = PS2KBPROC->bcast_pipes.list; IpcPipe *head = PS2KBPROC->bcast_pipes.list;
while (head != NULL) { while (head != NULL) {
ipc_pipewrite(head, (uint8_t *)&kbchr, sizeof(kbchr)); ipc_pipewrite(head, &b, 1);
head = head->next; head = head->next;
} }
spinlock_release(&PS2KBPROC->bcast_pipes.spinlock); spinlock_release(&PS2KBPROC->bcast_pipes.spinlock);
} }
spinlock_release(&PS2KB_BUF.spinlock);
} }
} }

View File

@ -109,11 +109,11 @@ void do_mode_interactive(void) {
cursor = 0; cursor = 0;
string_memset(linebuf, 0, LINEBUF_MAX); string_memset(linebuf, 0, LINEBUF_MAX);
int32_t kbchr = 0; uint8_t b = 0;
for (;;) { for (;;) {
int32_t nrd = ipcpipe(PID, IPCPIPE_IN, IPCPIPE_READ, (uint8_t *)&kbchr, sizeof(kbchr)); int32_t nrd = ipcpipe(PID, IPCPIPE_IN, IPCPIPE_READ, &b, 1);
if (nrd > 0) { if (nrd > 0) {
switch (kbchr) { switch (b) {
case C('C'): case C('C'):
case 0xE9: case 0xE9:
uprintf("\n"); uprintf("\n");
@ -126,15 +126,13 @@ void do_mode_interactive(void) {
break; break;
} }
char chr = kbchr & 0xFF; if (b == '\n') {
if (chr == '\n') {
break; break;
} }
if (string_chr_isascii(chr) && chr != 0 && cursor < LINEBUF_MAX) { if (string_chr_isascii(b) && b != 0 && cursor < LINEBUF_MAX) {
linebuf[cursor++] = chr; linebuf[cursor++] = b;
uprintf("%c", chr); uprintf("%c", b);
} }
} }
} }