9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit daeda3a6d49888c30783421f8936bc4ded14812b
parent c7927bc56c328275f45bac41537fcc60b6762bbb
Author: Roberto E. Vargas Caballero <roberto.vargas@midokura.com>
Date:   Sun, 13 Nov 2022 07:52:23 +0100

cfg: Move initial configuration to a blob file

Diffstat:
Minclude/libk.h | 1+
Msrc/libk/Makefile | 1+
Asrc/libk/getline.c | 22++++++++++++++++++++++
Msrc/os9/arch/arm64/main.c | 15---------------
Dsrc/os9/cfg/9fvp | 7-------
Asrc/os9/cfg/9fvp/conf | 8++++++++
Asrc/os9/cfg/9fvp/kernel | 9+++++++++
Dsrc/os9/cfg/9hosted | 9---------
Asrc/os9/cfg/9hosted/conf | 5+++++
Asrc/os9/cfg/9hosted/kernel | 10++++++++++
Dsrc/os9/cfg/9pi3 | 7-------
Asrc/os9/cfg/9pi3/conf | 8++++++++
Asrc/os9/cfg/9pi3/kernel | 9+++++++++
Msrc/os9/dev/Makefile | 8++++----
Msrc/os9/dev/Makefile.drv | 10++++++----
Msrc/os9/dlang.c | 8+++-----
Msrc/os9/hosted/main.c | 13-------------
Msrc/os9/sys.c | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
18 files changed, 164 insertions(+), 77 deletions(-)

diff --git a/include/libk.h b/include/libk.h @@ -19,6 +19,7 @@ extern void kassert(char *exp, char *file, long line); extern int p9todir(Dir *, unsigned char *, int); extern int dirtop9(Dir *, unsigned char *, int); extern int dirstat(char *name, Dir *dir); +extern int getline(Chan *, char *, int); #endif /* external dependencies of the library */ diff --git a/src/libk/Makefile b/src/libk/Makefile @@ -11,6 +11,7 @@ OBJS =\ tokenize.o\ frombytes.o\ fromstring.o\ + getline.o\ tobytes.o\ tostring.o\ kassert.o\ diff --git a/src/libk/getline.c b/src/libk/getline.c @@ -0,0 +1,22 @@ +#include <os9/os9.h> + +#include <libk.h> + +int +getline(Chan *c, char *line, int size) +{ + int n; + char ch; + + for (n = 0; n < size-1; ++n) { + if (devread(c, &ch, 1) < 0) + return -1; + line[n] = ch; + if (ch == '\n') { + line[n+1] = '\0'; + return n; + } + } + + return -1; +} diff --git a/src/os9/arch/arm64/main.c b/src/os9/arch/arm64/main.c @@ -13,21 +13,6 @@ info(void) kprint("os9: version %s\n", OS9VERSION); } -char * -getconf(char *name) -{ - static char constxt[] = - "addin #t0/raw\n" - "addout #t0/raw\n" - "echo on\n" - "cooked on\n"; - - if (strcmp(name, "console") == 0) - return NULL; - - return constxt; -} - int getch(void) { diff --git a/src/os9/cfg/9fvp b/src/os9/cfg/9fvp @@ -1,7 +0,0 @@ -dev - root - uart - pl011 base=0x1C090000,clk=24000000,rate=115200 - pl011 base=0x1c0c0000,clk=24000000,rate=115200 - cons -end diff --git a/src/os9/cfg/9fvp/conf b/src/os9/cfg/9fvp/conf @@ -0,0 +1,8 @@ +write #c/ctl addin #t0/raw +write #c/ctl addout #t0/raw +write #c/ctl echo on +write #c/ctl cooked on +bind #c /dev/cons +bind #p /proc +bind #t0 /dev/uart0 +bind #t1 /dev/uart1 diff --git a/src/os9/cfg/9fvp/kernel b/src/os9/cfg/9fvp/kernel @@ -0,0 +1,9 @@ +dev + root + uart + pl011 base=0x1C090000,clk=24000000,rate=115200 + pl011 base=0x1c0c0000,clk=24000000,rate=115200 + cons +blob + ../cfg/9fvp/conf +end diff --git a/src/os9/cfg/9hosted b/src/os9/cfg/9hosted @@ -1,9 +0,0 @@ -dev - root - uart - dummyuart base=0x1c0c0000,clk=24000000,cfg=b115200 l8 #t0 - dummyuart base=0x1c0c0100,clk=24000000 #t1 - cons - ar - proc -end diff --git a/src/os9/cfg/9hosted/conf b/src/os9/cfg/9hosted/conf @@ -0,0 +1,5 @@ +write #c/ctl addin #t0/raw +write #c/ctl addout #t0/raw +bind #p /proc +bind #c /dev/cons +bind #t0 /dev/uart0 diff --git a/src/os9/cfg/9hosted/kernel b/src/os9/cfg/9hosted/kernel @@ -0,0 +1,10 @@ +dev + root + uart + dummyuart base=0x1c0c0000,clk=24000000,cfg=b115200 l8 #t0 + cons + ar + proc +blob + ../cfg/9hosted/conf +end diff --git a/src/os9/cfg/9pi3 b/src/os9/cfg/9pi3 @@ -1,7 +0,0 @@ -dev - root - uart - pl011 base=0x1C090000,clk=24000000,rate=115200 - pl011 base=0x1c0c0000,clk=24000000,rate=115200 - cons -end diff --git a/src/os9/cfg/9pi3/conf b/src/os9/cfg/9pi3/conf @@ -0,0 +1,8 @@ +write #c/ctl addin #t0/raw +write #c/ctl addout #t0/raw +write #c/ctl echo on +write #c/ctl cooked on +bind #c /dev/cons +bind #p /proc +bind #t0 /dev/uart0 +bind #t1 /dev/uart1 diff --git a/src/os9/cfg/9pi3/kernel b/src/os9/cfg/9pi3/kernel @@ -0,0 +1,9 @@ +dev + root + uart + pl011 base=0x1C090000,clk=24000000,rate=115200 + pl011 base=0x1c0c0000,clk=24000000,rate=115200 + cons +blob + ../cfg/9fvp/conf +end diff --git a/src/os9/dev/Makefile b/src/os9/dev/Makefile @@ -5,8 +5,8 @@ include $(PROJECTDIR)/scripts/rules.mk all clean: devs.mk blobs.mk $(MAKE) -f Makefile.drv $@ -devs.mk: ../cfg/$(OS9) - ./mkdev ../cfg/$(OS9) +devs.mk: ../cfg/$(OS9)/kernel + ./mkdev ../cfg/$(OS9)/kernel -blobs.mk: ../cfg/$(OS9) - ./mkblob ../cfg/$(OS9) +blobs.mk: ../cfg/$(OS9)/kernel + ./mkblob ../cfg/$(OS9)/kernel diff --git a/src/os9/dev/Makefile.drv b/src/os9/dev/Makefile.drv @@ -14,13 +14,15 @@ all: builtin.o builtin.o: $(OBJS) $(LD) $(PROJ_LDFLAGS) -r -o $@ $(OBJS) -devc.c: ../cfg/$(OS9) - ./mkdevc ../cfg/$(OS9) +devc.c: ../cfg/$(OS9)/kernel + ./mkdevc ../cfg/$(OS9)/kernel + +blobfil.h: ../cfg/$(OS9)/kernel devroot.c: blobfil.h blobs.h -blobs.h: ../cfg/$(OS9) - ./mkblobh ../cfg/$(OS9) +blobs.h: ../cfg/$(OS9)/kernel + ./mkblobh ../cfg/$(OS9)/kernel clean: rm -f blobfil.h blobs.h blobs.mk devs.mk devc.c diff --git a/src/os9/dlang.c b/src/os9/dlang.c @@ -111,7 +111,7 @@ do_read(const struct cmd *cmd, struct args *args) return 0; err: - kprint(PREFIX "ERR cat: %e\n"); + kprint(PREFIX "ERR read: %e\n"); return 0; } @@ -132,9 +132,7 @@ do_ls(const struct cmd *cmd, struct args *args) kprint(PREFIX2 "%s\n", dentry.name); } - devclose(c); - - if ( n < 0) + if (devclose(c) || n < 0) goto err; return 0; @@ -172,7 +170,7 @@ do_write(const struct cmd *cmd, struct args *args) return 0; err: - kprint(PREFIX "ERR echo:%e\n"); + kprint(PREFIX "ERR write:%e\n"); return 0; } diff --git a/src/os9/hosted/main.c b/src/os9/hosted/main.c @@ -53,19 +53,6 @@ imach(void) exit(EXIT_FAILURE); } -char * -getconf(char *name) -{ - static char constxt[] = - "addin #t0/raw\n" - "addout #t0/raw\n"; - - if (strcmp(name, "console") != 0) - return NULL; - - return constxt; -} - int main(int argc, char *argv[]) { diff --git a/src/os9/sys.c b/src/os9/sys.c @@ -1,5 +1,8 @@ #include <os9/os9.h> +#include <libk.h> + +#include <ctype.h> #include <string.h> Chan *console; @@ -7,32 +10,94 @@ Chan *console; static void icons(void) { - char *cfg, *p; + if ((console = devopen("#c/raw", O_RDWR)) == NULL) + panic("icons:#c/raw open"); +} + +static void +writeline(char *line) +{ Chan *c; + char *p, *file, *data; + + file = p = line; + while (*p && !isspace(*p)) + ++p; + while (isspace(*p)) + *p++ = '\0'; + data = p; + + if ((c = devopen(file, O_WRITE)) < 0) + panic("writeline:open"); + if (devwrite(c, data, strlen(data)) < 0) + panic("writeline:write"); + devclose(c); +} + +static void +bindline(char *line) +{ + int n; + char *tokens[10]; - if ((cfg = getconf("console")) == NULL) - panic("missed console configuration"); + n = tokenize(line, strlen(line), tokens, NELEM(tokens)); + if (n != 2) + panic("bindline:params"); + if (bind(tokens[0], tokens[1]) < 0) + panic("bindline:bind"); +} + +static void +mountline(char *line) +{ + int n; + char *tokens[10]; + + n = tokenize(line, strlen(line), tokens, NELEM(tokens)); + if (n != 3) + panic("mountline:params"); + if (mount(tokens[0], tokens[1], tokens[2]) < 0) + panic("mountline:mount"); +} - if ((c = devopen("#c/ctl", O_WRITE)) == NULL) - panic("namec:/dev/cons/ctl open"); +static void +iconf(void) +{ + Chan *c; + char line[80], *s, *p; - while ((p =strchr(cfg, '\n')) != NULL) { - if (devwrite(c, cfg, p - cfg) < 0) - panic("writing console configuration"); - cfg = p+1; + if ((c = devopen("/blobs/conf", O_READ)) == NULL) { + kprint("missed kernel namespace configuration\n"); + return; } - if (devclose(c) < 0) - panic("devclose"); + while (getline(c, line, sizeof(line)) > 0) { + for (p = line; isspace(*p); ++p) + ; + s = p; + while (*p && !isspace(*p)) + ++p; + while (isspace(*p)) + *p++ = '\0'; - if ((console = devopen("#c/raw", O_RDWR)) == NULL) - panic("namec:#c/raw open"); + if (strcmp(s, "write") == 0) + writeline(p); + else if (strcmp(s, "bind") == 0) + bindline(p); + else if (strcmp(s, "mount") == 0) + mountline(p); + else + panic("iconf:verb"); + } + + devclose(c); } void isys(void) { idev(); + iconf(); icons(); iproc(); debug();