56 lines
1.4 KiB
C
56 lines
1.4 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>
|
|
#include <dlmalloc/malloc.h>
|
|
#include <errors.h>
|
|
|
|
#define SUBPROC_PIPE_OUT 0x1f
|
|
|
|
uint64_t PID;
|
|
|
|
void main(void) {
|
|
PID = (uint64_t)processctl(-1, PCTL_GETPID, 0, 0, 0);
|
|
|
|
ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_MAKE, NULL, 0);
|
|
|
|
char *tbargs[] = { "-m", "runfile", "-f", "base:/scripts/init.tb", "-logcmds", "yes" };
|
|
int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)&tbargs, ARRLEN(tbargs));
|
|
ipcpipe(tb, IPCPIPE_OUT, IPCPIPE_REPLACE, (uint8_t *)PID, SUBPROC_PIPE_OUT);
|
|
|
|
ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_MAKE, NULL, 0);
|
|
ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_ADD_BCAST, NULL, 1);
|
|
|
|
#define OUTBUF_MAX 1024
|
|
char *outbuf = dlmalloc(OUTBUF_MAX);
|
|
|
|
processctl(tb, PCTL_RUN, 0, 0, 0);
|
|
|
|
for(;;) {
|
|
string_memset(outbuf, 0, OUTBUF_MAX);
|
|
int32_t nrd = ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_READ, (uint8_t *)outbuf, sizeof(outbuf));
|
|
if (nrd > 0) {
|
|
uprintf("%s", outbuf);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for(;;);
|
|
}
|
|
|