38 lines
1.1 KiB
C
38 lines
1.1 KiB
C
#include <stdint.h>
|
|
#include <string/string.h>
|
|
#include <system/system.h>
|
|
#include <sysdefs/ipcpipe.h>
|
|
#include <sysdefs/processctl.h>
|
|
#include <uprintf.h>
|
|
#include <ansiq/all.h>
|
|
#include <string/char.h>
|
|
#include <util/util.h>
|
|
|
|
void main(void) {
|
|
char *tbargs[] = { "-m", "runfile", "-f", "base:/scripts/init.tb" };
|
|
int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)&tbargs, ARRLEN(tbargs));
|
|
uint64_t selfpid = (uint64_t)processctl(-1, PCTL_GETPID, 0, 0, 0);
|
|
ipcpipe(tb, IPCPIPE_OUT, IPCPIPE_REPLACE, (uint8_t *)selfpid, IPCPIPE_OUT);
|
|
processctl(tb, PCTL_RUN, 0, 0, 0);
|
|
|
|
ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_MAKE, NULL, 0);
|
|
ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_ADD_BCAST, NULL, 1);
|
|
|
|
while(processctl(tb, PCTL_POLLSTATE, 0, 0, 0) != 2) {
|
|
int32_t kbchr;
|
|
int32_t read = ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_READ, (uint8_t *)&kbchr, sizeof(kbchr));
|
|
if (read > 0) {
|
|
uint8_t c = kbchr & 0xff;
|
|
if (string_chr_isascii(c)) {
|
|
if (c != 0) {
|
|
ipcpipe(tb, IPCPIPE_IN, IPCPIPE_WRITE, &c, 1);
|
|
}
|
|
if (string_chr_isprint(c)) {
|
|
uprintf("%c", c);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|