Compare commits

...

2 Commits

Author SHA1 Message Date
e71361dcca Nice userspace wrappers for ps2kb driver 2025-09-07 22:24:34 +02:00
659f98910d Terminal lock 2025-09-07 22:23:41 +02:00
7 changed files with 27 additions and 3 deletions

View File

@ -7,7 +7,9 @@
#define kprintf(fmt, ...) \ #define kprintf(fmt, ...) \
do { \ do { \
spinlock_acquire(&TERM.spinlock); \
printf_(fmt, ##__VA_ARGS__); \ printf_(fmt, ##__VA_ARGS__); \
spinlock_release(&TERM.spinlock); \
} while(0) } while(0)
#define ksprintf sprintf_ #define ksprintf sprintf_

View File

@ -32,6 +32,7 @@ void term_doinit(void *addr) {
void term_init(void *addr) { void term_init(void *addr) {
term_doinit(addr); term_doinit(addr);
spinlock_init(&TERM.spinlock);
} }
void term_write_unsafe(const char *s, size_t len) { void term_write_unsafe(const char *s, size_t len) {

View File

@ -7,6 +7,7 @@
typedef struct { typedef struct {
struct flanterm_context *ftctx; struct flanterm_context *ftctx;
SpinLock spinlock;
} Term; } Term;
extern Term TERM; extern Term TERM;

View File

@ -10,6 +10,7 @@ SRCFILES := $(call GRABSRC, \
string \ string \
system \ system \
printf \ printf \
devices \
) )
CFLAGS += -isystem $(ROOT)/share -isystem $(ROOT)/ulib -isystem $(ROOT)/std/include \ CFLAGS += -isystem $(ROOT)/share -isystem $(ROOT)/ulib -isystem $(ROOT)/std/include \

8
ulib/devices/ps2kb.c Normal file
View File

@ -0,0 +1,8 @@
#include <stdint.h>
#include <sysdefs/ipcpipe.h>
#include <system/ipcpipe.h>
int32_t dev_ps2kb_read(int32_t *ch) {
return ipcpipe(1, 0, IPCPIPE_READ, (uint8_t *)ch, sizeof(*ch));
}

10
ulib/devices/ps2kb.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef ULIB_DEVICES_PS2KB_H_
#define ULIB_DEVICES_PS2KB_H_
#include <stdint.h>
#define PS2KB_C(x) ((x) - '@')
int32_t dev_ps2kb_read(int32_t *ch);
#endif // ULIB_DEVICES_PS2KB_H_

View File

@ -7,6 +7,7 @@
#include <ansiq/all.h> #include <ansiq/all.h>
#include <sysdefs/ipcpipe.h> #include <sysdefs/ipcpipe.h>
#include <system/ipcpipe.h> #include <system/ipcpipe.h>
#include <devices/ps2kb.h>
void main(void) { void main(void) {
debugprint(ANSIQ_SCR_CLR_ALL); debugprint(ANSIQ_SCR_CLR_ALL);
@ -28,10 +29,10 @@ void main(void) {
while(1) { while(1) {
int32_t kbchar; int32_t kbchar;
int32_t read = ipcpipe(1, 0, IPCPIPE_READ, (uint8_t *)&kbchar, sizeof(kbchar)); int32_t read = dev_ps2kb_read(&kbchar);
if (read > 0 && (kbchar >= 0x20 && kbchar <= 0x7F)) { if (read > 0 && (kbchar >= 0x20 && kbchar <= 0x7F || kbchar == 0xA)) {
uprintf("%c", (char)kbchar); uprintf("%c", kbchar & 0xFF);
ipcpipe(3, 1, IPCPIPE_WRITE, (uint8_t *)&kbchar, 1); ipcpipe(3, 1, IPCPIPE_WRITE, (uint8_t *)&kbchar, 1);
} }
} }