From a2c3566b918a6209b869f5d6b38dfa8ca3fecffe Mon Sep 17 00:00:00 2001 From: msdx321 Date: Fri, 19 Mar 2021 00:24:28 +0800 Subject: [PATCH 01/19] libc: Fix library output name Signed-off-by: msdx321 --- src/components/lib/libc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/lib/libc/Makefile b/src/components/lib/libc/Makefile index aab9da8279..3893faea59 100644 --- a/src/components/lib/libc/Makefile +++ b/src/components/lib/libc/Makefile @@ -7,7 +7,7 @@ # # NOTE: libc is special-cased and the compilation is orchestrated # directly. It should have no dependencies. -LIBRARY_OUTPUT = c crypt m thread resolv rt +LIBRARY_OUTPUT = c crypt m pthread resolv rt # The .o files that are mandatorily linked into dependents. This is # rarely used, and only when normal .a linking rules will avoid # linking some necessary objects. This list is of names (for example, From cd5b02f20d8ca816c55cc48d84e054a97d7860a5 Mon Sep 17 00:00:00 2001 From: msdx321 Date: Wed, 3 Mar 2021 01:46:50 +0800 Subject: [PATCH 02/19] posix: Nuke SL Signed-off-by: msdx321 --- src/components/lib/posix/Makefile | 4 +- src/components/lib/posix/posix.c | 152 ++++++++---------------------- 2 files changed, 40 insertions(+), 116 deletions(-) diff --git a/src/components/lib/posix/Makefile b/src/components/lib/posix/Makefile index a9f2c943a4..c46ae1f62f 100644 --- a/src/components/lib/posix/Makefile +++ b/src/components/lib/posix/Makefile @@ -18,10 +18,10 @@ OBJECT_OUTPUT = posix INCLUDE_PATHS = . # The interfaces this component is dependent on for compilation (this # is a list of directory names in interface/) -INTERFACE_DEPENDENCIES = +INTERFACE_DEPENDENCIES = capmgr # The library dependencies this component is reliant on for # compilation/linking (this is a list of directory names in lib/) -LIBRARY_DEPENDENCIES = component kernel sl +LIBRARY_DEPENDENCIES = component kernel # Note: Both the interface and library dependencies should be # *minimal*. That is to say that removing a dependency should cause # the build to fail. The build system does not validate this diff --git a/src/components/lib/posix/posix.c b/src/components/lib/posix/posix.c index 73166a7524..1d13555497 100644 --- a/src/components/lib/posix/posix.c +++ b/src/components/lib/posix/posix.c @@ -12,9 +12,12 @@ #include #include #include +#include +/* #include #include #include +*/ volatile int* null_ptr = NULL; #define ABORT() do {int i = *null_ptr;} while(0) @@ -31,7 +34,7 @@ libc_syscall_override(cos_syscall_t fn, int syscall_num) cos_syscalls[syscall_num] = fn; } -struct sl_lock stdout_lock = SL_LOCK_STATIC_INIT(); +//struct sl_lock stdout_lock = SL_LOCK_STATIC_INIT(); ssize_t write_bytes_to_stdout(const char *buf, size_t count) @@ -46,9 +49,9 @@ cos_write(int fd, const void *buf, size_t count) { /* You shouldn't write to stdin anyway, so don't bother special casing it */ if (fd == 1 || fd == 2) { - sl_lock_take(&stdout_lock); + //sl_lock_take(&stdout_lock); write_bytes_to_stdout((const char *) buf, count); - sl_lock_release(&stdout_lock); + //sl_lock_release(&stdout_lock); return count; } else { printc("fd: %d not supported!\n", fd); @@ -60,13 +63,13 @@ ssize_t cos_writev(int fd, const struct iovec *iov, int iovcnt) { if (fd == 1 || fd == 2) { - sl_lock_take(&stdout_lock); + //sl_lock_take(&stdout_lock); int i; ssize_t ret = 0; for(i=0; ici, length); + //addr = (void *)cos_page_bump_allocn(&cos_defcompinfo_curr_get()->ci, length); + addr = (void *)memmgr_heap_page_allocn(length / PAGE_SIZE); if (!addr){ ret = (void *) -1; } else { @@ -170,7 +174,8 @@ cos_mprotect(void *addr, size_t len, int prot) pid_t cos_gettid(void) { - return (pid_t) sl_thdid(); + //return (pid_t) sl_thdid(); + return 0; } int @@ -221,16 +226,20 @@ cos_nanosleep(const struct timespec *req, struct timespec *rem) return -1; } - wakeup_deadline = sl_now() + sl_usec2cyc(time_to_microsec(req)); - completed_successfully = sl_thd_block_timeout(0, wakeup_deadline); - wakeup_time = sl_now(); + //wakeup_deadline = sl_now() + sl_usec2cyc(time_to_microsec(req)); + wakeup_deadline = 0; + //completed_successfully = sl_thd_block_timeout(0, wakeup_deadline); + completed_successfully = 0; + //wakeup_time = sl_now(); + wakeup_time = 0; if (completed_successfully || wakeup_time > wakeup_deadline) { return 0; } else { errno = EINTR; if (rem) { - remaining_microseconds = sl_cyc2usec(wakeup_deadline - wakeup_time); + //remaining_microseconds = sl_cyc2usec(wakeup_deadline - wakeup_time); + remaining_microseconds = 0; remaining_seconds = remaining_microseconds / 1000000; remaining_nano_seconds = (remaining_microseconds - remaining_seconds * 1000000) * 1000; *rem = (struct timespec) { @@ -263,23 +272,27 @@ cos_set_tid_address(int *tidptr) * }; */ -void* backing_data[SL_MAX_NUM_THDS]; +//void* backing_data[SL_MAX_NUM_THDS]; +void* backing_data[1]; static void setup_thread_area(struct sl_thd *thread, void* data) { struct cos_compinfo *ci = cos_compinfo_get(cos_defcompinfo_curr_get()); - thdid_t thdid = sl_thd_thdid(thread); + //thdid_t thdid = sl_thd_thdid(thread); + thdid_t thdid = 0; backing_data[thdid] = data; - cos_thd_mod(ci, sl_thd_thdcap(thread), &backing_data[thdid]); + //cos_thd_mod(ci, sl_thd_thdcap(thread), &backing_data[thdid]); + cos_thd_mod(ci, 0, &backing_data[thdid]); } int cos_set_thread_area(void* data) { - setup_thread_area(sl_thd_curr(), data); + //setup_thread_area(sl_thd_curr(), data); + setup_thread_area(0, data); return 0; } @@ -291,11 +304,13 @@ cos_clone(int (*func)(void *), void *stack, int flags, void *arg, pid_t *ptid, v return -1; } - struct sl_thd * thd = sl_thd_alloc((cos_thd_fn_t) func, arg); + //struct sl_thd * thd = sl_thd_alloc((cos_thd_fn_t) func, arg); + struct sl_thd * thd = 0; if (tls) { setup_thread_area(thd, tls); } - return sl_thd_thdid(thd); + //return sl_thd_thdid(thd); + return 0; } #define FUTEX_WAIT 0 @@ -316,13 +331,13 @@ cos_clone(int (*func)(void *), void *stack, int flags, void *arg, pid_t *ptid, v struct futex_data { int *uaddr; - struct ps_list_head waiters; + void* waiters; }; struct futex_waiter { thdid_t thdid; - struct ps_list list; + void* list; }; #define FUTEX_COUNT 20 @@ -331,30 +346,12 @@ struct futex_data futexes[FUTEX_COUNT]; struct futex_data * lookup_futex(int *uaddr) { - int last_free = -1; - int i; - - for (i = 0; i < FUTEX_COUNT; i++) { - if (futexes[i].uaddr == uaddr) { - return &futexes[i]; - } else if (futexes[i].uaddr == 0) { - last_free = i; - } - } - if (last_free >= 0) { - futexes[last_free] = (struct futex_data) { - .uaddr = uaddr - }; - ps_list_head_init(&futexes[last_free].waiters); - return &futexes[last_free]; - } - printc("Out of futex ids!"); assert(0); } /* TODO: Cleanup empty futexes */ -struct sl_lock futex_lock = SL_LOCK_STATIC_INIT(); +//struct sl_lock futex_lock = SL_LOCK_STATIC_INIT(); /* * precondition: futex_lock is taken @@ -362,57 +359,12 @@ struct sl_lock futex_lock = SL_LOCK_STATIC_INIT(); int cos_futex_wait(struct futex_data *futex, int *uaddr, int val, const struct timespec *timeout) { - cycles_t deadline; - microsec_t wait_time; - struct futex_waiter waiter = (struct futex_waiter) { - .thdid = sl_thdid() - }; - - if (*uaddr != val) return EAGAIN; - - ps_list_init_d(&waiter); - ps_list_head_append_d(&futex->waiters, &waiter); - - if (timeout != NULL) { - wait_time = time_to_microsec(timeout); - deadline = sl_now() + sl_usec2cyc(wait_time); - } - - do { - /* No race here, we'll enter the awoken state if things go wrong */ - sl_lock_release(&futex_lock); - if (timeout == NULL) { - sl_thd_block(0); - } else { - sl_thd_block_timeout(0, deadline); - } - sl_lock_take(&futex_lock); - /* We continue while the waiter is in the list, and the deadline has not elapsed */ - } while(!ps_list_singleton_d(&waiter) && (timeout == NULL || sl_now() < deadline)); - - /* If our waiter is still in the list (meaning we quit because the deadline elapsed), - * then we remove it from the list. */ - if (!ps_list_singleton_d(&waiter)) { - ps_list_rem_d(&waiter); - } - /* We exit the function with futex_lock taken */ return 0; } int cos_futex_wake(struct futex_data *futex, int wakeup_count) { - struct futex_waiter *waiter, *tmp; - int awoken = 0; - - ps_list_foreach_del_d(&futex->waiters, waiter, tmp) { - if (awoken >= wakeup_count) { - return awoken; - } - ps_list_rem_d(waiter); - sl_thd_wakeup(waiter->thdid); - awoken += 1; - } - return awoken; + return 0; } int @@ -420,35 +372,7 @@ cos_futex(int *uaddr, int op, int val, const struct timespec *timeout, /* or: uint32_t val2 */ int *uaddr2, int val3) { - int result = 0; - struct futex_data *futex; - - sl_lock_take(&futex_lock); - - /* TODO: Consider whether these options have sensible composite interpretations */ - op &= ~FUTEX_PRIVATE; - assert(!(op & FUTEX_CLOCK_REALTIME)); - - futex = lookup_futex(uaddr); - switch (op) { - case FUTEX_WAIT: - result = cos_futex_wait(futex, uaddr, val, timeout); - if (result != 0) { - errno = result; - result = -1; - } - break; - case FUTEX_WAKE: - result = cos_futex_wake(futex, val); - break; - default: - printc("Unsupported futex operation"); - assert(0); - } - - sl_lock_release(&futex_lock); - - return result; + return 0; } @@ -462,7 +386,7 @@ pre_syscall_default_setup() cos_defcompinfo_init(); cos_meminfo_init(&(ci->mi), BOOT_MEM_KM_BASE, COS_MEM_KERN_PA_SZ, BOOT_CAPTBL_SELF_UNTYPED_PT); - sl_init(SL_MIN_PERIOD_US); + //sl_init(SL_MIN_PERIOD_US); } void From 0707a4ca7a97048a40ebeb7e34bd94d8a1a460bf Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 1 Mar 2021 22:37:01 +0800 Subject: [PATCH 03/19] lib: sqlite: Initial import Signed-off-by: msdx321 --- .gitmodules | 3 + src/components/lib/sqlite/Makefile | 88 ++++++++++++++++++++++++++++++ src/components/lib/sqlite/doc.md | 9 +++ src/components/lib/sqlite/sqlite | 1 + 4 files changed, 101 insertions(+) create mode 100644 src/components/lib/sqlite/Makefile create mode 100644 src/components/lib/sqlite/doc.md create mode 160000 src/components/lib/sqlite/sqlite diff --git a/.gitmodules b/.gitmodules index b5d218ff5b..99048a39b1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "src/components/lib/ck/ck"] path = src/components/lib/ck/ck url = https://github.com/gwsystems/ck.git +[submodule "src/components/lib/sqlite/sqlite"] + path = src/components/lib/sqlite/sqlite + url = https://github.com/msdx321/sqlite.git diff --git a/src/components/lib/sqlite/Makefile b/src/components/lib/sqlite/Makefile new file mode 100644 index 0000000000..132ec74f75 --- /dev/null +++ b/src/components/lib/sqlite/Makefile @@ -0,0 +1,88 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The library names associated with .a files output that are linked +# (via, for example, -lsqlite) into dependents. This list should be +# "sqlite" for output files such as libsqlite.a. +LIBRARY_OUTPUT = sqlite3 +# The .o files that are mandatorily linked into dependents. This is +# rarely used, and only when normal .a linking rules will avoid +# linking some necessary objects. This list is of names (for example, +# sqlite) which will generate sqlite.lib.o. Do NOT include the list of .o +# files here. Please note that using this list is *very rare* and +# should only be used when the .a support above is not appropriate. +OBJECT_OUTPUT = +# The path within this directory that holds the .h files for +# dependents to compile with (./ by default). Will be fed into the -I +# compiler arguments. +INCLUDE_PATHS = sqlite/ +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = component posix libc +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +# There are two different *types* of Makefiles for libraries. +# 1. Those that are Composite-specific, and simply need an easy way to +# compile and itegrate their code. +# 2. Those that aim to integrate external libraries into +# Composite. These focus on "driving" the build process of the +# external library, then pulling out the resulting files and +# directories. These need to be flexible as all libraries are +# different. + +# Type 1, Composite library: This is the default Makefile for +# libraries written for composite. Get rid of this if you require a +# custom Makefile (e.g. if you use an existing +# (non-composite-specific) library. An example of this is `kernel`. +# include Makefile.lib + +## Type 2, external library: If you need to specialize the Makefile +## for an external library, you can add the external code as a +## subdirectory, and drive its compilation, and integration with the +## system using a specialized Makefile. The Makefile must generate +## lib$(LIBRARY_OUTPUT).a and $(OBJECT_OUTPUT).lib.o, and have all of +## the necessary include paths in $(INCLUDE_PATHS). +## +## To access the Composite Makefile definitions, use the following. An +## example of a Makefile written in this way is in `ps/`. +# +# include Makefile.src Makefile.comp Makefile.dependencies +# .PHONY: all clean init distclean +## Fill these out with your implementation +# all: +# clean: +# +## Default rules: +# init: clean all +# distclean: clean + +include Makefile.src Makefile.comp Makefile.dependencies + +.PHONY: all clean init distclean config clean_lib +CINC_ENV = $(CINC) $(DEPENDENCY_INCPATH) +CFLAGS = $(CINC_ENV) +export CINC_ENV +export CFLAGS + +all: + $(info Building sqlite library...) + make -s -C sqlite libsqlite3.a + @cp sqlite/libsqlite3.a . + +clean_lib: + make -s -C sqlite clean + +clean: clean_lib config + +config: + $(info Configuring the sqlite library) + make -s -C sqlite sqlite3.h + +init: clean config +distclean: clean diff --git a/src/components/lib/sqlite/doc.md b/src/components/lib/sqlite/doc.md new file mode 100644 index 0000000000..de3ed3f615 --- /dev/null +++ b/src/components/lib/sqlite/doc.md @@ -0,0 +1,9 @@ +## sqlite + +This is the skeleton library used by the `mklib.sh` script to aid in the creation of a new library. +It provides no functionality, and should never be depended on! +This documentation should be *replaced* in the documentation for a new library. + +### Description + +### Usage and Assumptions diff --git a/src/components/lib/sqlite/sqlite b/src/components/lib/sqlite/sqlite new file mode 160000 index 0000000000..60405cd15c --- /dev/null +++ b/src/components/lib/sqlite/sqlite @@ -0,0 +1 @@ +Subproject commit 60405cd15cdd085745101a29112043299d439cfa From 1ea129f5d1f652aa1b597aeb05f5d1959b29fecf Mon Sep 17 00:00:00 2001 From: msdx321 Date: Fri, 19 Mar 2021 00:16:57 +0800 Subject: [PATCH 04/19] sqlite: Update to latest Signed-off-by: msdx321 --- src/components/lib/sqlite/sqlite | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/lib/sqlite/sqlite b/src/components/lib/sqlite/sqlite index 60405cd15c..70b1757c56 160000 --- a/src/components/lib/sqlite/sqlite +++ b/src/components/lib/sqlite/sqlite @@ -1 +1 @@ -Subproject commit 60405cd15cdd085745101a29112043299d439cfa +Subproject commit 70b1757c562a9fa24f6af02faf4730666f40a180 From 8c79591e61c2d80120f16a18f6450da7b5d75b56 Mon Sep 17 00:00:00 2001 From: msdx321 Date: Fri, 19 Mar 2021 00:10:29 +0800 Subject: [PATCH 05/19] sqlite_tests: Add initial test Signed-off-by: msdx321 --- composition_scripts/sqlite_tests.toml | 29 ++++++++++++ .../tests/sqlite_tests/Makefile | 18 ++++++++ .../implementation/tests/sqlite_tests/doc.md | 9 ++++ .../tests/sqlite_tests/sqlite_tests.c | 44 +++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 composition_scripts/sqlite_tests.toml create mode 100644 src/components/implementation/tests/sqlite_tests/Makefile create mode 100644 src/components/implementation/tests/sqlite_tests/doc.md create mode 100644 src/components/implementation/tests/sqlite_tests/sqlite_tests.c diff --git a/composition_scripts/sqlite_tests.toml b/composition_scripts/sqlite_tests.toml new file mode 100644 index 0000000000..21e90f1ee2 --- /dev/null +++ b/composition_scripts/sqlite_tests.toml @@ -0,0 +1,29 @@ +[system] +description = "Simple test of sqlite." + +[[components]] +name = "booter" +img = "no_interface.llbooter" +implements = [{interface = "init"}, {interface = "addr"}] +deps = [{srv = "kernel", interface = "init", variant = "kernel"}] +constructor = "kernel" + +[[components]] +name = "capmgr" +img = "capmgr.simple" +deps = [{srv = "booter", interface = "init"}, {srv = "booter", interface = "addr"}] +implements = [{interface = "capmgr"}, {interface = "init"}, {interface = "memmgr"}, {interface = "capmgr_create"}] +constructor = "booter" + +[[components]] +name = "sched" +img = "sched.root_fprr" +deps = [{srv = "capmgr", interface = "init"}, {srv = "capmgr", interface = "capmgr"}, {srv = "capmgr", interface = "memmgr"}] +implements = [{interface = "sched"}, {interface = "init"}] +constructor = "booter" + +[[components]] +name = "sqlite_tests" +img = "tests.sqlite_tests" +deps = [{srv = "sched", interface = "init"}, {srv = "sched", interface = "sched"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "capmgr", interface = "memmgr"}, {srv = "capmgr", interface = "capmgr"}] +constructor = "booter" \ No newline at end of file diff --git a/src/components/implementation/tests/sqlite_tests/Makefile b/src/components/implementation/tests/sqlite_tests/Makefile new file mode 100644 index 0000000000..b733ee092b --- /dev/null +++ b/src/components/implementation/tests/sqlite_tests/Makefile @@ -0,0 +1,18 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The set of interfaces that this component exports for use by other +# components. This is a list of the interface names. +INTERFACE_EXPORTS = +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = component sqlite +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +include Makefile.subsubdir diff --git a/src/components/implementation/tests/sqlite_tests/doc.md b/src/components/implementation/tests/sqlite_tests/doc.md new file mode 100644 index 0000000000..68560c8d20 --- /dev/null +++ b/src/components/implementation/tests/sqlite_tests/doc.md @@ -0,0 +1,9 @@ +## tests + +This is the skeleton interface used by the `mkcomponent.sh` script to aid in the creation of a new component. +It provides no functionality, and should never be depended on! +This documentation should be *replaced* in the documentation for a new component. + +### Description + +### Usage and Assumptions diff --git a/src/components/implementation/tests/sqlite_tests/sqlite_tests.c b/src/components/implementation/tests/sqlite_tests/sqlite_tests.c new file mode 100644 index 0000000000..6df2b86ce8 --- /dev/null +++ b/src/components/implementation/tests/sqlite_tests/sqlite_tests.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +void +cos_init(void) +{ +} + +int result_print(void *v, int argc, char **argv, + char **col_name) { + for (int i = 0; i < argc; i++) { + printc("%s = %s\n", col_name[i], argv[i] ? argv[i] : "NULL"); + } + + return 0; +} + +int +main(void) +{ + printc("Calling sqlite functions\n"); + + sqlite3 *db; + char *err_msg = 0; + char *sql = "CREATE TABLE TestTable(Id INTEGER PRIMARY KEY, Value TEXT);" + "INSERT INTO TestTable(Value) VALUES ('TestItem1');" + "INSERT INTO TestTable(Value) VALUES ('TestItem2');" + "INSERT INTO TestTable(Value) VALUES ('TestItem3');" + "INSERT INTO TestTable(Value) VALUES ('TestItem4');" + "INSERT INTO TestTable(Value) VALUES ('TestItem5');"; + + sqlite3_open(":memory:", &db); + + sqlite3_exec(db, sql, 0, 0, &err_msg); + + sql = "SELECT * FROM TestTable WHERE Id == 3"; + sqlite3_exec(db, sql, result_print, 0, &err_msg); + + sqlite3_close(db); + + while(1); +} From 9d9dc43e83ea181581d6ef6726bc5f9474d1c537 Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:05:21 +0800 Subject: [PATCH 06/19] .gitmodules: Update Signed-off-by: msdx321 --- .gitmodules | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index b5d218ff5b..baf7f416fa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,9 @@ [submodule "src/components/lib/ps/ps"] path = src/components/lib/ps/ps - url = https://github.com/gwsystems/ps.git + url = https://github.com/msdx321/ps.git [submodule "src/components/lib/ck/ck"] path = src/components/lib/ck/ck url = https://github.com/gwsystems/ck.git +[submodule "src/components/lib/lwext4/lwext4"] + path = src/components/lib/lwext4/lwext4 + url = https://github.com/msdx321/lwext4.git From cccfa8203e12d6694d97cbb24c6290ec15fb767d Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:06:12 +0800 Subject: [PATCH 07/19] libc: Fix compile Signed-off-by: msdx321 --- src/components/lib/libc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/lib/libc/Makefile b/src/components/lib/libc/Makefile index aab9da8279..3893faea59 100644 --- a/src/components/lib/libc/Makefile +++ b/src/components/lib/libc/Makefile @@ -7,7 +7,7 @@ # # NOTE: libc is special-cased and the compilation is orchestrated # directly. It should have no dependencies. -LIBRARY_OUTPUT = c crypt m thread resolv rt +LIBRARY_OUTPUT = c crypt m pthread resolv rt # The .o files that are mandatorily linked into dependents. This is # rarely used, and only when normal .a linking rules will avoid # linking some necessary objects. This list is of names (for example, From dac0a2b13cf55dc5708383163f360ffd6818cc11 Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:06:48 +0800 Subject: [PATCH 08/19] capmgr: Return mapped mem properly Signed-off-by: msdx321 --- src/components/implementation/capmgr/simple/capmgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/implementation/capmgr/simple/capmgr.c b/src/components/implementation/capmgr/simple/capmgr.c index 3ba4944ebf..17fd7a6556 100644 --- a/src/components/implementation/capmgr/simple/capmgr.c +++ b/src/components/implementation/capmgr/simple/capmgr.c @@ -221,7 +221,7 @@ memmgr_heap_page_allocn(unsigned long num_pages) p = mm_page_allocn(c, num_pages); if (!p) return 0; - return (vaddr_t)p->page; + return (vaddr_t)p->mappings[0].addr; } cbuf_t From 564b08da69dd431b5be02c5789d0da221f2c7c78 Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:07:07 +0800 Subject: [PATCH 09/19] ps: Set to my fork Signed-off-by: msdx321 --- src/components/lib/ps/ps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/lib/ps/ps b/src/components/lib/ps/ps index 71a9f77d02..2b9701a76f 160000 --- a/src/components/lib/ps/ps +++ b/src/components/lib/ps/ps @@ -1 +1 @@ -Subproject commit 71a9f77d02eb338906e1ca94377a49174457214f +Subproject commit 2b9701a76f966cdcf9955be79397deb1db5253dd From 0a8176a9f6147a68a50e18ed594703e985e5ed66 Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:07:25 +0800 Subject: [PATCH 10/19] posix: Make it work for now Signed-off-by: msdx321 --- src/components/lib/posix/posix.c | 154 ++++++++----------------------- 1 file changed, 39 insertions(+), 115 deletions(-) diff --git a/src/components/lib/posix/posix.c b/src/components/lib/posix/posix.c index 73166a7524..937278d527 100644 --- a/src/components/lib/posix/posix.c +++ b/src/components/lib/posix/posix.c @@ -12,9 +12,12 @@ #include #include #include +#include +/* #include #include #include +*/ volatile int* null_ptr = NULL; #define ABORT() do {int i = *null_ptr;} while(0) @@ -31,7 +34,7 @@ libc_syscall_override(cos_syscall_t fn, int syscall_num) cos_syscalls[syscall_num] = fn; } -struct sl_lock stdout_lock = SL_LOCK_STATIC_INIT(); +//struct sl_lock stdout_lock = SL_LOCK_STATIC_INIT(); ssize_t write_bytes_to_stdout(const char *buf, size_t count) @@ -46,9 +49,9 @@ cos_write(int fd, const void *buf, size_t count) { /* You shouldn't write to stdin anyway, so don't bother special casing it */ if (fd == 1 || fd == 2) { - sl_lock_take(&stdout_lock); + //sl_lock_take(&stdout_lock); write_bytes_to_stdout((const char *) buf, count); - sl_lock_release(&stdout_lock); + //sl_lock_release(&stdout_lock); return count; } else { printc("fd: %d not supported!\n", fd); @@ -60,13 +63,13 @@ ssize_t cos_writev(int fd, const struct iovec *iov, int iovcnt) { if (fd == 1 || fd == 2) { - sl_lock_take(&stdout_lock); + //sl_lock_take(&stdout_lock); int i; ssize_t ret = 0; for(i=0; ici, length); + //addr = (void *)cos_page_bump_allocn(&cos_defcompinfo_curr_get()->ci, length); + addr = (void *)memmgr_heap_page_allocn(length / PAGE_SIZE); if (!addr){ ret = (void *) -1; } else { @@ -170,7 +174,8 @@ cos_mprotect(void *addr, size_t len, int prot) pid_t cos_gettid(void) { - return (pid_t) sl_thdid(); + //return (pid_t) sl_thdid(); + return 0; } int @@ -221,16 +226,20 @@ cos_nanosleep(const struct timespec *req, struct timespec *rem) return -1; } - wakeup_deadline = sl_now() + sl_usec2cyc(time_to_microsec(req)); - completed_successfully = sl_thd_block_timeout(0, wakeup_deadline); - wakeup_time = sl_now(); + //wakeup_deadline = sl_now() + sl_usec2cyc(time_to_microsec(req)); + wakeup_deadline = 0; + //completed_successfully = sl_thd_block_timeout(0, wakeup_deadline); + completed_successfully = 0; + //wakeup_time = sl_now(); + wakeup_time = 0; if (completed_successfully || wakeup_time > wakeup_deadline) { return 0; } else { errno = EINTR; if (rem) { - remaining_microseconds = sl_cyc2usec(wakeup_deadline - wakeup_time); + //remaining_microseconds = sl_cyc2usec(wakeup_deadline - wakeup_time); + remaining_microseconds = 0; remaining_seconds = remaining_microseconds / 1000000; remaining_nano_seconds = (remaining_microseconds - remaining_seconds * 1000000) * 1000; *rem = (struct timespec) { @@ -263,23 +272,27 @@ cos_set_tid_address(int *tidptr) * }; */ -void* backing_data[SL_MAX_NUM_THDS]; +//void* backing_data[SL_MAX_NUM_THDS]; +void* backing_data[1]; static void setup_thread_area(struct sl_thd *thread, void* data) { struct cos_compinfo *ci = cos_compinfo_get(cos_defcompinfo_curr_get()); - thdid_t thdid = sl_thd_thdid(thread); + //thdid_t thdid = sl_thd_thdid(thread); + thdid_t thdid = 0; backing_data[thdid] = data; - cos_thd_mod(ci, sl_thd_thdcap(thread), &backing_data[thdid]); + //cos_thd_mod(ci, sl_thd_thdcap(thread), &backing_data[thdid]); + cos_thd_mod(ci, 0, &backing_data[thdid]); } int cos_set_thread_area(void* data) { - setup_thread_area(sl_thd_curr(), data); + //setup_thread_area(sl_thd_curr(), data); + setup_thread_area(0, data); return 0; } @@ -291,11 +304,13 @@ cos_clone(int (*func)(void *), void *stack, int flags, void *arg, pid_t *ptid, v return -1; } - struct sl_thd * thd = sl_thd_alloc((cos_thd_fn_t) func, arg); + //struct sl_thd * thd = sl_thd_alloc((cos_thd_fn_t) func, arg); + struct sl_thd * thd = 0; if (tls) { setup_thread_area(thd, tls); } - return sl_thd_thdid(thd); + //return sl_thd_thdid(thd); + return 0; } #define FUTEX_WAIT 0 @@ -316,13 +331,13 @@ cos_clone(int (*func)(void *), void *stack, int flags, void *arg, pid_t *ptid, v struct futex_data { int *uaddr; - struct ps_list_head waiters; + void* waiters; }; struct futex_waiter { thdid_t thdid; - struct ps_list list; + void* list; }; #define FUTEX_COUNT 20 @@ -331,30 +346,12 @@ struct futex_data futexes[FUTEX_COUNT]; struct futex_data * lookup_futex(int *uaddr) { - int last_free = -1; - int i; - - for (i = 0; i < FUTEX_COUNT; i++) { - if (futexes[i].uaddr == uaddr) { - return &futexes[i]; - } else if (futexes[i].uaddr == 0) { - last_free = i; - } - } - if (last_free >= 0) { - futexes[last_free] = (struct futex_data) { - .uaddr = uaddr - }; - ps_list_head_init(&futexes[last_free].waiters); - return &futexes[last_free]; - } - printc("Out of futex ids!"); assert(0); } /* TODO: Cleanup empty futexes */ -struct sl_lock futex_lock = SL_LOCK_STATIC_INIT(); +//struct sl_lock futex_lock = SL_LOCK_STATIC_INIT(); /* * precondition: futex_lock is taken @@ -362,57 +359,12 @@ struct sl_lock futex_lock = SL_LOCK_STATIC_INIT(); int cos_futex_wait(struct futex_data *futex, int *uaddr, int val, const struct timespec *timeout) { - cycles_t deadline; - microsec_t wait_time; - struct futex_waiter waiter = (struct futex_waiter) { - .thdid = sl_thdid() - }; - - if (*uaddr != val) return EAGAIN; - - ps_list_init_d(&waiter); - ps_list_head_append_d(&futex->waiters, &waiter); - - if (timeout != NULL) { - wait_time = time_to_microsec(timeout); - deadline = sl_now() + sl_usec2cyc(wait_time); - } - - do { - /* No race here, we'll enter the awoken state if things go wrong */ - sl_lock_release(&futex_lock); - if (timeout == NULL) { - sl_thd_block(0); - } else { - sl_thd_block_timeout(0, deadline); - } - sl_lock_take(&futex_lock); - /* We continue while the waiter is in the list, and the deadline has not elapsed */ - } while(!ps_list_singleton_d(&waiter) && (timeout == NULL || sl_now() < deadline)); - - /* If our waiter is still in the list (meaning we quit because the deadline elapsed), - * then we remove it from the list. */ - if (!ps_list_singleton_d(&waiter)) { - ps_list_rem_d(&waiter); - } - /* We exit the function with futex_lock taken */ return 0; } int cos_futex_wake(struct futex_data *futex, int wakeup_count) { - struct futex_waiter *waiter, *tmp; - int awoken = 0; - - ps_list_foreach_del_d(&futex->waiters, waiter, tmp) { - if (awoken >= wakeup_count) { - return awoken; - } - ps_list_rem_d(waiter); - sl_thd_wakeup(waiter->thdid); - awoken += 1; - } - return awoken; + return 0; } int @@ -420,35 +372,7 @@ cos_futex(int *uaddr, int op, int val, const struct timespec *timeout, /* or: uint32_t val2 */ int *uaddr2, int val3) { - int result = 0; - struct futex_data *futex; - - sl_lock_take(&futex_lock); - - /* TODO: Consider whether these options have sensible composite interpretations */ - op &= ~FUTEX_PRIVATE; - assert(!(op & FUTEX_CLOCK_REALTIME)); - - futex = lookup_futex(uaddr); - switch (op) { - case FUTEX_WAIT: - result = cos_futex_wait(futex, uaddr, val, timeout); - if (result != 0) { - errno = result; - result = -1; - } - break; - case FUTEX_WAKE: - result = cos_futex_wake(futex, val); - break; - default: - printc("Unsupported futex operation"); - assert(0); - } - - sl_lock_release(&futex_lock); - - return result; + return 0; } @@ -462,7 +386,7 @@ pre_syscall_default_setup() cos_defcompinfo_init(); cos_meminfo_init(&(ci->mi), BOOT_MEM_KM_BASE, COS_MEM_KERN_PA_SZ, BOOT_CAPTBL_SELF_UNTYPED_PT); - sl_init(SL_MIN_PERIOD_US); + //sl_init(SL_MIN_PERIOD_US); } void @@ -517,4 +441,4 @@ libc_initialization_handler() { printc("libc_init\n"); libc_init(); -} +} \ No newline at end of file From 2690e4f51e6573a7b194a457eac4e5aeab16726b Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:07:49 +0800 Subject: [PATCH 11/19] blockdev: Add blockdev interface Signed-off-by: msdx321 --- src/components/interface/blockdev/Makefile | 30 ++++++++ src/components/interface/blockdev/blockdev.h | 18 +++++ src/components/interface/blockdev/doc.md | 9 +++ .../interface/blockdev/stubs/Makefile | 1 + .../interface/blockdev/stubs/c_stub.c | 68 +++++++++++++++++++ .../interface/blockdev/stubs/s_stub.c | 29 ++++++++ .../interface/blockdev/stubs/stubs.S | 5 ++ 7 files changed, 160 insertions(+) create mode 100644 src/components/interface/blockdev/Makefile create mode 100644 src/components/interface/blockdev/blockdev.h create mode 100644 src/components/interface/blockdev/doc.md create mode 100644 src/components/interface/blockdev/stubs/Makefile create mode 100644 src/components/interface/blockdev/stubs/c_stub.c create mode 100644 src/components/interface/blockdev/stubs/s_stub.c create mode 100644 src/components/interface/blockdev/stubs/stubs.S diff --git a/src/components/interface/blockdev/Makefile b/src/components/interface/blockdev/Makefile new file mode 100644 index 0000000000..64a3f7cc19 --- /dev/null +++ b/src/components/interface/blockdev/Makefile @@ -0,0 +1,30 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The library names associated with .a files output that are linked +# (via, for example, -lblockdev) into dependents. This list should be +# "blockdev" for output files such as libblockdev.a. +LIBRARY_OUTPUT = +# The .o files that are mandatorily linked into dependents. This is +# rarely used, and only when normal .a linking rules will avoid +# linking some necessary objects. This list is of names (for example, +# blockdev) which will generate blockdev.lib.o. Do NOT include the list of .o +# files here. Please note that using this list is *very rare* and +# should only be used when the .a support above is not appropriate. +OBJECT_OUTPUT = +# The path within this directory that holds the .h files for +# dependents to compile with (./ by default). Will be fed into the -I +# compiler arguments. It is unlikely you want to change this. +INCLUDE_PATHS = . +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = memmgr +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = stubs +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +include Makefile.subdir diff --git a/src/components/interface/blockdev/blockdev.h b/src/components/interface/blockdev/blockdev.h new file mode 100644 index 0000000000..2ed36417b9 --- /dev/null +++ b/src/components/interface/blockdev/blockdev.h @@ -0,0 +1,18 @@ +#ifndef BLOCKDEV_H +#define BLOCKDEV_H + +#include +#include + +unsigned long blockdev_bread(void *buf, unsigned long offset, unsigned long length); +unsigned long COS_STUB_DECL(blockdev_bread)(void *buf, unsigned long offset, unsigned long length); + +unsigned long blockdev_bwrite(const void *buf, unsigned long offset, unsigned long length); +unsigned long COS_STUB_DECL(blockdev_bwrite)(const void *buf, unsigned long offset, unsigned long length); + +CCTOR int __blockdev_c_smem_init(); + +int __blockdev_s_smem_init(cbuf_t cid); +int COS_STUB_DECL(__blockdev_s_smem_init)(cbuf_t cid); + +#endif /* BLOCKDEV_H */ diff --git a/src/components/interface/blockdev/doc.md b/src/components/interface/blockdev/doc.md new file mode 100644 index 0000000000..ae384d6e63 --- /dev/null +++ b/src/components/interface/blockdev/doc.md @@ -0,0 +1,9 @@ +## blockdev + +This is the skeleton interface used by the `mkinterface.sh` script to aid in the creation of a new interface. +It provides no functionality, and should never be depended on! +This documentation should be *replaced* in the documentation for a new interface. + +### Description + +### Usage and Assumptions diff --git a/src/components/interface/blockdev/stubs/Makefile b/src/components/interface/blockdev/stubs/Makefile new file mode 100644 index 0000000000..169aa4a0c8 --- /dev/null +++ b/src/components/interface/blockdev/stubs/Makefile @@ -0,0 +1 @@ +include Makefile.subsubdir diff --git a/src/components/interface/blockdev/stubs/c_stub.c b/src/components/interface/blockdev/stubs/c_stub.c new file mode 100644 index 0000000000..2eb13bc446 --- /dev/null +++ b/src/components/interface/blockdev/stubs/c_stub.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +vaddr_t *__blockdev_c_smem_pool; + +CCTOR int +__blockdev_c_smem_init() +{ + int ret; + cbuf_t cid; + vaddr_t p; + + cid = memmgr_shared_page_allocn(1, &p); + + ret = memmgr_shared_page_map(cid, &__blockdev_c_smem_pool); + if (!ret) { return ret; } + + ret = __blockdev_s_smem_init(cid); + if (ret) { return ret; } + + return 0; +} + +COS_CLIENT_STUB(unsigned long, blockdev_bread) +(struct usr_inv_cap *uc, const void *buf, unsigned long offset, unsigned long length) +{ + word_t unused; + int c; + unsigned long ret; + + for (c = 0; length > 0; length--, c++) { + ret = cos_sinv_2rets(uc->cap_no, 0, offset + c, 1, 0, &unused, &unused); + if (ret) { + BUG(); + return ret; + } + + // printc("read stub buf: %s\n", __blockdev_c_smem_pool); + // printc("read offset: %lu\n", offset + c); + memcpy((char *)buf + c * 4096, __blockdev_c_smem_pool, 4096); + } + + return 0; +} + +COS_CLIENT_STUB(unsigned long, blockdev_bwrite) +(struct usr_inv_cap *uc, const void *buf, unsigned long offset, unsigned long length) +{ + word_t unused; + int c; + unsigned long ret; + + for (c = 0; length > 0; length--, c++) { + memcpy(__blockdev_c_smem_pool, (char *)buf + c * 4096, 4096); + // printc("write stub buf: %s\n", __blockdev_c_smem_pool); + // printc("write offset: %lu\n", offset + c); + + ret = cos_sinv_2rets(uc->cap_no, 0, offset + c, 1, 0, &unused, &unused); + if (ret) { + BUG(); + return ret; + } + } + + return 0; +} \ No newline at end of file diff --git a/src/components/interface/blockdev/stubs/s_stub.c b/src/components/interface/blockdev/stubs/s_stub.c new file mode 100644 index 0000000000..8c9c188f69 --- /dev/null +++ b/src/components/interface/blockdev/stubs/s_stub.c @@ -0,0 +1,29 @@ +#include +#include + +vaddr_t *__blockdev_s_smem_pool[64]; + +COS_SERVER_3RET_STUB(unsigned long, blockdev_bread) +{ + compid_t token; + token = (compid_t)cos_inv_token(); + + return blockdev_bread(__blockdev_s_smem_pool[token], p1, p2); +} + +COS_SERVER_3RET_STUB(unsigned long, blockdev_bwrite) +{ + compid_t token; + token = (compid_t)cos_inv_token(); + + return blockdev_bwrite(__blockdev_s_smem_pool[token], p1, p2); +} + +int +__blockdev_s_smem_init(cbuf_t cid) +{ + compid_t token; + token = (compid_t)cos_inv_token(); + + return memmgr_shared_page_map(cid, (vaddr_t *)&__blockdev_s_smem_pool[token]); +} diff --git a/src/components/interface/blockdev/stubs/stubs.S b/src/components/interface/blockdev/stubs/stubs.S new file mode 100644 index 0000000000..5944b80362 --- /dev/null +++ b/src/components/interface/blockdev/stubs/stubs.S @@ -0,0 +1,5 @@ +#include + +cos_asm_stub_indirect(blockdev_bread) +cos_asm_stub_indirect(blockdev_bwrite) +cos_asm_stub(__blockdev_s_smem_init) \ No newline at end of file From e8581adcb3cd151cb8e68916a14778e651188434 Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:08:21 +0800 Subject: [PATCH 12/19] blockdev: Add ramdisk implementation Signed-off-by: msdx321 --- .../implementation/blockdev/Makefile | 18 ++++++++ .../implementation/blockdev/ramdisk/Makefile | 18 ++++++++ .../implementation/blockdev/ramdisk/doc.md | 9 ++++ .../implementation/blockdev/ramdisk/ramdisk.c | 45 +++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 src/components/implementation/blockdev/Makefile create mode 100644 src/components/implementation/blockdev/ramdisk/Makefile create mode 100644 src/components/implementation/blockdev/ramdisk/doc.md create mode 100644 src/components/implementation/blockdev/ramdisk/ramdisk.c diff --git a/src/components/implementation/blockdev/Makefile b/src/components/implementation/blockdev/Makefile new file mode 100644 index 0000000000..d3faae6683 --- /dev/null +++ b/src/components/implementation/blockdev/Makefile @@ -0,0 +1,18 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The set of interfaces that this component exports for use by other +# components. This is a list of the interface names. +INTERFACE_EXPORTS = blockdev +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = memmgr +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = component +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +include Makefile.subdir diff --git a/src/components/implementation/blockdev/ramdisk/Makefile b/src/components/implementation/blockdev/ramdisk/Makefile new file mode 100644 index 0000000000..c153a72d8b --- /dev/null +++ b/src/components/implementation/blockdev/ramdisk/Makefile @@ -0,0 +1,18 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The set of interfaces that this component exports for use by other +# components. This is a list of the interface names. +INTERFACE_EXPORTS = blockdev +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = memmgr +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = component +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +include Makefile.subsubdir diff --git a/src/components/implementation/blockdev/ramdisk/doc.md b/src/components/implementation/blockdev/ramdisk/doc.md new file mode 100644 index 0000000000..52c8ca940d --- /dev/null +++ b/src/components/implementation/blockdev/ramdisk/doc.md @@ -0,0 +1,9 @@ +## blockdev + +This is the skeleton interface used by the `mkcomponent.sh` script to aid in the creation of a new component. +It provides no functionality, and should never be depended on! +This documentation should be *replaced* in the documentation for a new component. + +### Description + +### Usage and Assumptions diff --git a/src/components/implementation/blockdev/ramdisk/ramdisk.c b/src/components/implementation/blockdev/ramdisk/ramdisk.c new file mode 100644 index 0000000000..6fc148dba5 --- /dev/null +++ b/src/components/implementation/blockdev/ramdisk/ramdisk.c @@ -0,0 +1,45 @@ +#include +#include +#include + +#define BLOCKDEV_RAMDISK_BSIZE 4096 +#define BLOCKDEV_RAMDISK_SIZE 16 * 1024 * 1024 + +typedef struct block { + char c[BLOCKDEV_RAMDISK_BSIZE]; +} blk; + +blk *ram_backend; + +unsigned int +blockdev_bread(void *buf, unsigned long offset, unsigned long length) +{ + memcpy(buf, &ram_backend[offset], length * BLOCKDEV_RAMDISK_BSIZE); + return 0; +} + +unsigned int +blockdev_bwrite(const void *buf, unsigned long offset, unsigned long length) +{ + memcpy(&ram_backend[offset], buf, length * BLOCKDEV_RAMDISK_BSIZE); + return 0; +} + +void +cos_init(void) +{ + ram_backend = (blk *)memmgr_heap_page_allocn(BLOCKDEV_RAMDISK_SIZE / 4096); + return; +} + +void +cos_parallel_init(coreid_t cid, int init_core, int ncores) +{ + return; +} + +void +parallel_main(coreid_t cid) +{ + return; +} \ No newline at end of file From 89da24f5c9c1a9479d86fa779bb41110f3d39e9a Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:08:49 +0800 Subject: [PATCH 13/19] ramdisk: Add a small test Signed-off-by: msdx321 --- composition_scripts/ramdisk_test.toml | 36 +++++++++++++++++++ .../tests/ramdisk_tests/Makefile | 18 ++++++++++ .../implementation/tests/ramdisk_tests/doc.md | 9 +++++ .../tests/ramdisk_tests/ramdisk_tests.c | 26 ++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 composition_scripts/ramdisk_test.toml create mode 100644 src/components/implementation/tests/ramdisk_tests/Makefile create mode 100644 src/components/implementation/tests/ramdisk_tests/doc.md create mode 100644 src/components/implementation/tests/ramdisk_tests/ramdisk_tests.c diff --git a/composition_scripts/ramdisk_test.toml b/composition_scripts/ramdisk_test.toml new file mode 100644 index 0000000000..6932b3328f --- /dev/null +++ b/composition_scripts/ramdisk_test.toml @@ -0,0 +1,36 @@ +[system] +description = "Simplest system with both capability manager and scheduler, from unit_schedcomp.sh" + +[[components]] +name = "booter" +img = "no_interface.llbooter" +implements = [{interface = "init"}, {interface = "addr"}] +deps = [{srv = "kernel", interface = "init", variant = "kernel"}] +constructor = "kernel" + +[[components]] +name = "capmgr" +img = "capmgr.simple" +deps = [{srv = "booter", interface = "init"}, {srv = "booter", interface = "addr"}] +implements = [{interface = "capmgr"}, {interface = "init"}, {interface = "memmgr"}, {interface = "capmgr_create"}] +constructor = "booter" + +[[components]] +name = "sched" +img = "sched.root_fprr" +deps = [{srv = "capmgr", interface = "init"}, {srv = "capmgr", interface = "capmgr"}, {srv = "capmgr", interface = "memmgr"}] +implements = [{interface = "sched"}, {interface = "init"}] +constructor = "booter" + +[[components]] +name = "blockdev" +img = "blockdev.ramdisk" +deps = [{srv = "sched", interface = "init"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "capmgr", interface = "memmgr"}] +implements = [{interface = "blockdev"}] +constructor = "booter" + +[[components]] +name = "ramdisk_tests" +img = "tests.ramdisk_tests" +deps = [{srv = "sched", interface = "init"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "blockdev", interface = "blockdev"}, {srv = "capmgr", interface = "memmgr"}] +constructor = "booter" \ No newline at end of file diff --git a/src/components/implementation/tests/ramdisk_tests/Makefile b/src/components/implementation/tests/ramdisk_tests/Makefile new file mode 100644 index 0000000000..a771892429 --- /dev/null +++ b/src/components/implementation/tests/ramdisk_tests/Makefile @@ -0,0 +1,18 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The set of interfaces that this component exports for use by other +# components. This is a list of the interface names. +INTERFACE_EXPORTS = +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = blockdev +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = component +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +include Makefile.subsubdir diff --git a/src/components/implementation/tests/ramdisk_tests/doc.md b/src/components/implementation/tests/ramdisk_tests/doc.md new file mode 100644 index 0000000000..68560c8d20 --- /dev/null +++ b/src/components/implementation/tests/ramdisk_tests/doc.md @@ -0,0 +1,9 @@ +## tests + +This is the skeleton interface used by the `mkcomponent.sh` script to aid in the creation of a new component. +It provides no functionality, and should never be depended on! +This documentation should be *replaced* in the documentation for a new component. + +### Description + +### Usage and Assumptions diff --git a/src/components/implementation/tests/ramdisk_tests/ramdisk_tests.c b/src/components/implementation/tests/ramdisk_tests/ramdisk_tests.c new file mode 100644 index 0000000000..4ec2d3c671 --- /dev/null +++ b/src/components/implementation/tests/ramdisk_tests/ramdisk_tests.c @@ -0,0 +1,26 @@ +#include +#include +#include + +int +main(void) +{ + char buf[8192] = {0, }; + + strcpy(buf, "Hello World!!!"); + strcpy(buf + 4096, "World Hello!!!"); + + blockdev_bwrite(buf, 0, 2); + + memset(buf, 0, 8192); + + blockdev_bread(buf, 0, 2); + + printc("%s\n", buf); + printc("%s\n", buf + 4096); + + printc("Test finished\n"); + + while(1) { + } +} From dd5410f8ef7f0e0c1985c08d97aa155ffb96064c Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:10:09 +0800 Subject: [PATCH 14/19] filesystem: Add filesystem interface Signed-off-by: msdx321 --- src/components/interface/filesystem/Makefile | 30 ++++++++ src/components/interface/filesystem/doc.md | 9 +++ .../interface/filesystem/filesystem.h | 54 +++++++++++++ .../interface/filesystem/stubs/Makefile | 1 + .../interface/filesystem/stubs/c_stub.c | 77 +++++++++++++++++++ .../interface/filesystem/stubs/s_stub.c | 46 +++++++++++ .../interface/filesystem/stubs/stubs.S | 11 +++ 7 files changed, 228 insertions(+) create mode 100644 src/components/interface/filesystem/Makefile create mode 100644 src/components/interface/filesystem/doc.md create mode 100644 src/components/interface/filesystem/filesystem.h create mode 100644 src/components/interface/filesystem/stubs/Makefile create mode 100644 src/components/interface/filesystem/stubs/c_stub.c create mode 100644 src/components/interface/filesystem/stubs/s_stub.c create mode 100644 src/components/interface/filesystem/stubs/stubs.S diff --git a/src/components/interface/filesystem/Makefile b/src/components/interface/filesystem/Makefile new file mode 100644 index 0000000000..a6352067c5 --- /dev/null +++ b/src/components/interface/filesystem/Makefile @@ -0,0 +1,30 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The library names associated with .a files output that are linked +# (via, for example, -lfilesystem) into dependents. This list should be +# "filesystem" for output files such as libfilesystem.a. +LIBRARY_OUTPUT = +# The .o files that are mandatorily linked into dependents. This is +# rarely used, and only when normal .a linking rules will avoid +# linking some necessary objects. This list is of names (for example, +# filesystem) which will generate filesystem.lib.o. Do NOT include the list of .o +# files here. Please note that using this list is *very rare* and +# should only be used when the .a support above is not appropriate. +OBJECT_OUTPUT = +# The path within this directory that holds the .h files for +# dependents to compile with (./ by default). Will be fed into the -I +# compiler arguments. It is unlikely you want to change this. +INCLUDE_PATHS = . +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = memmgr +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = stubs +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +include Makefile.subdir diff --git a/src/components/interface/filesystem/doc.md b/src/components/interface/filesystem/doc.md new file mode 100644 index 0000000000..fe18bc357e --- /dev/null +++ b/src/components/interface/filesystem/doc.md @@ -0,0 +1,9 @@ +## filesystem + +This is the skeleton interface used by the `mkinterface.sh` script to aid in the creation of a new interface. +It provides no functionality, and should never be depended on! +This documentation should be *replaced* in the documentation for a new interface. + +### Description + +### Usage and Assumptions diff --git a/src/components/interface/filesystem/filesystem.h b/src/components/interface/filesystem/filesystem.h new file mode 100644 index 0000000000..0920c525ee --- /dev/null +++ b/src/components/interface/filesystem/filesystem.h @@ -0,0 +1,54 @@ +#ifndef FILESYSTEM_H +#define FILESYSTEM_H + +#include +#include + +word_t filesystem_fopen(const char *path, const char *flags); +word_t COS_STUB_DECL(filesystem_fopen)(const char *path, const char *flags); + +int filesystem_fclose(word_t fd); +int COS_STUB_DECL(filesystem_fclose)(word_t fd); + +int filesystem_ftruncate(word_t fd, unsigned long size); +int COS_STUB_DECL(filesystem_ftruncate)(word_t fd, unsigned long size); + +size_t filesystem_fread(word_t fd, void *buf, size_t size); +size_t COS_STUB_DECL(filesystem_fread)(word_t fd, void *buf, size_t size); + +size_t filesystem_fwrite(word_t fd, void *buf, size_t size); +size_t COS_STUB_DECL(filesystem_fwrite)(word_t fd, void *buf, size_t size); + +int filesystem_fseek(word_t fd, long offset, unsigned long origin); +int COS_STUB_DECL(filesystem_fseek)(word_t fd, long offset, unsigned long origin); + +unsigned long filesystem_ftell(word_t fd); +unsigned long COS_STUB_DECL(filesystem_ftell)(word_t fd); + +unsigned long filesystem_fsize(word_t fd); +unsigned long COS_STUB_DECL(filesystem_fsize)(word_t fd); + +/* +int fs_dir_rm(const char *path); +int COS_STUB_DECL(fs_dir_rm)(const char *path); + +int fs_dir_mv(const char *path, const char *new_path); +int COS_STUB_DECL(fs_dir_mv)(const char *path, const char *new_path); + +int fs_dir_mk(const char *path); +int COS_STUB_DECL(fs_dir_mk)(const char *path); + +int fs_dir_open(void *dir, const char *path); +int COS_STUB_DECL(fs_dir_open)(void *dir, const char *path); + +int fs_dir_close(void *dir); +int COS_STUB_DECL(fs_dir_close)(void *dir); +*/ + +CCTOR int __filesystem_c_smem_init(); + +int __filesystem_s_smem_init(cbuf_t cid); +int COS_STUB_DECL(__filesystem_s_smem_init)(cbuf_t cid); + + +#endif /* FILESYSTEM_H */ diff --git a/src/components/interface/filesystem/stubs/Makefile b/src/components/interface/filesystem/stubs/Makefile new file mode 100644 index 0000000000..169aa4a0c8 --- /dev/null +++ b/src/components/interface/filesystem/stubs/Makefile @@ -0,0 +1 @@ +include Makefile.subsubdir diff --git a/src/components/interface/filesystem/stubs/c_stub.c b/src/components/interface/filesystem/stubs/c_stub.c new file mode 100644 index 0000000000..c195118bfe --- /dev/null +++ b/src/components/interface/filesystem/stubs/c_stub.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include + +vaddr_t *__filesystem_c_smem_pool; + +CCTOR int +__filesystem_c_smem_init() +{ + int ret; + cbuf_t cid; + vaddr_t p; + + cid = memmgr_shared_page_allocn(2, &p); + + ret = memmgr_shared_page_map(cid, &__filesystem_c_smem_pool); + if (!ret) { return ret; } + + ret = __filesystem_s_smem_init(cid); + if (ret) { return ret; } + + return 0; +} + +COS_CLIENT_STUB(word_t, filesystem_fopen)(struct usr_inv_cap *uc, const char *path, const char *flags) +{ + word_t unused; + + memcpy(__filesystem_c_smem_pool, path, 4096); + memcpy((char *)__filesystem_c_smem_pool + 4096, flags, 4096); + + return cos_sinv_2rets(uc->cap_no, 0, 0, 0, 0, &unused, &unused); +} + +COS_CLIENT_STUB(size_t, filesystem_fread)(struct usr_inv_cap *uc, word_t fd, void *buf, size_t size) +{ + word_t unused; + int c, s; + unsigned long ret; + + for (c = 0, s = size; s > 0; s -= 4096, c++) { + // to be fix + ret = cos_sinv_2rets(uc->cap_no, fd, 0, 4096, 0, &unused, &unused); + if (!ret) { + //BUG(); + return ret; + } + + // printc("read stub buf: %s\n", __blockdev_c_smem_pool); + // printc("read offset: %lu\n", offset + c); + memcpy((char *)buf + c * 4096, __filesystem_c_smem_pool, 4096); + } + + return ret; +} + +COS_CLIENT_STUB(int, filesystem_fwrite)(struct usr_inv_cap *uc, word_t fd, void *buf, size_t size) +{ + word_t unused; + int c, s; + unsigned long ret; + + + for (c = 0, s = size; s > 0; s -= 4096, c++) { + // to be fix + memcpy(__filesystem_c_smem_pool, (char *)buf + c * 4096, 4096); + + ret = cos_sinv_2rets(uc->cap_no, fd, 0, 4096, 0, &unused, &unused); + if (!ret) { + //BUG(); + return ret; + } + } + + return ret; +} \ No newline at end of file diff --git a/src/components/interface/filesystem/stubs/s_stub.c b/src/components/interface/filesystem/stubs/s_stub.c new file mode 100644 index 0000000000..53e7c701ac --- /dev/null +++ b/src/components/interface/filesystem/stubs/s_stub.c @@ -0,0 +1,46 @@ +#include +#include + +vaddr_t *__filesystem_s_smem_pool[64]; + +COS_SERVER_3RET_STUB(word_t, filesystem_fopen) +{ + compid_t token; + token = (compid_t)cos_inv_token(); + + return filesystem_fopen((const char *)__filesystem_s_smem_pool[token], + (const char *)__filesystem_s_smem_pool[token] + 4096); +} + +COS_SERVER_3RET_STUB(int, filesystem_fread) +{ + compid_t token; + size_t ret; + + token = (compid_t)cos_inv_token(); + + ret = filesystem_fread(p0, __filesystem_s_smem_pool[token], p2); + + return ret; +} + +COS_SERVER_3RET_STUB(int, filesystem_fwrite) +{ + compid_t token; + size_t ret; + + token = (compid_t)cos_inv_token(); + + ret = filesystem_fwrite(p0, __filesystem_s_smem_pool[token], p2); + + return ret; +} + +int +__filesystem_s_smem_init(cbuf_t cid) +{ + compid_t token; + token = (compid_t)cos_inv_token(); + + return memmgr_shared_page_map(cid, (vaddr_t *)&__filesystem_s_smem_pool[token]); +} \ No newline at end of file diff --git a/src/components/interface/filesystem/stubs/stubs.S b/src/components/interface/filesystem/stubs/stubs.S new file mode 100644 index 0000000000..9177647353 --- /dev/null +++ b/src/components/interface/filesystem/stubs/stubs.S @@ -0,0 +1,11 @@ +#include + +cos_asm_stub_indirect(filesystem_fopen) +cos_asm_stub(filesystem_fclose) +cos_asm_stub(filesystem_ftruncate) +cos_asm_stub_indirect(filesystem_fread) +cos_asm_stub_indirect(filesystem_fwrite) +cos_asm_stub(filesystem_fseek) +cos_asm_stub(filesystem_ftell) +cos_asm_stub(filesystem_fsize) +cos_asm_stub(__filesystem_s_smem_init) \ No newline at end of file From 0ee4ec150b2bc7047761b436dcfde164e57f717f Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:10:25 +0800 Subject: [PATCH 15/19] filesystem: Add ext4 implementation Signed-off-by: msdx321 --- .../implementation/filesystem/Makefile | 18 +++ .../implementation/filesystem/ext4/Makefile | 18 +++ .../implementation/filesystem/ext4/doc.md | 9 ++ .../implementation/filesystem/ext4/ext4.c | 126 ++++++++++++++++++ .../filesystem/ext4/ext4_blockdev.c | 47 +++++++ .../implementation/filesystem/ext4/ps_os.c | 8 ++ 6 files changed, 226 insertions(+) create mode 100644 src/components/implementation/filesystem/Makefile create mode 100644 src/components/implementation/filesystem/ext4/Makefile create mode 100644 src/components/implementation/filesystem/ext4/doc.md create mode 100644 src/components/implementation/filesystem/ext4/ext4.c create mode 100644 src/components/implementation/filesystem/ext4/ext4_blockdev.c create mode 100644 src/components/implementation/filesystem/ext4/ps_os.c diff --git a/src/components/implementation/filesystem/Makefile b/src/components/implementation/filesystem/Makefile new file mode 100644 index 0000000000..36f305c30f --- /dev/null +++ b/src/components/implementation/filesystem/Makefile @@ -0,0 +1,18 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The set of interfaces that this component exports for use by other +# components. This is a list of the interface names. +INTERFACE_EXPORTS = filesystem +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = blockdev +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = component +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +include Makefile.subdir diff --git a/src/components/implementation/filesystem/ext4/Makefile b/src/components/implementation/filesystem/ext4/Makefile new file mode 100644 index 0000000000..bc2fd58f76 --- /dev/null +++ b/src/components/implementation/filesystem/ext4/Makefile @@ -0,0 +1,18 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The set of interfaces that this component exports for use by other +# components. This is a list of the interface names. +INTERFACE_EXPORTS = filesystem +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = blockdev memmgr +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = component lwext4 posix libc ps +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +include Makefile.subsubdir diff --git a/src/components/implementation/filesystem/ext4/doc.md b/src/components/implementation/filesystem/ext4/doc.md new file mode 100644 index 0000000000..6a6930d86b --- /dev/null +++ b/src/components/implementation/filesystem/ext4/doc.md @@ -0,0 +1,9 @@ +## filesystem + +This is the skeleton interface used by the `mkcomponent.sh` script to aid in the creation of a new component. +It provides no functionality, and should never be depended on! +This documentation should be *replaced* in the documentation for a new component. + +### Description + +### Usage and Assumptions diff --git a/src/components/implementation/filesystem/ext4/ext4.c b/src/components/implementation/filesystem/ext4/ext4.c new file mode 100644 index 0000000000..b59e4e03bf --- /dev/null +++ b/src/components/implementation/filesystem/ext4/ext4.c @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include + +extern struct ext4_blockdev *ext4_blockdev_get(void); +static struct ext4_blockdev *bd; + +static struct ext4_fs fs; +static int fs_type = F_SET_EXT4; +static struct ext4_mkfs_info info = { + .block_size = 4096, + .journal = true, +}; +static struct ext4_bcache *bc; + +struct ps_ns *ns[64]; + +PS_NSSLAB_CREATE(fd, sizeof(struct ext4_file), 2, 9, 6); + +word_t +filesystem_fopen(const char *path, const char *flags) +{ + ps_desc_t fd; + ext4_file *file; + compid_t token; + + token = (compid_t)cos_inv_token(); + + fd = -1; + file = ps_nsptr_alloc_fd(ns[token], &fd); + int ret = ext4_fopen(file, path, flags); + //printc("ret %d\n", ret); + + //printc("mp %p\n", file->mp); + + return (word_t)fd; +} + +int +filesystem_fclose(word_t fd) +{ + compid_t token; + token = (compid_t)cos_inv_token(); + + return ext4_fclose(ps_nsptr_lkup_fd(ns[token], fd)); +} + +int +filesystem_ftruncate(word_t fd, unsigned long size) +{ + compid_t token; + token = (compid_t)cos_inv_token(); + + return ext4_ftruncate(ps_nsptr_lkup_fd(ns[token], fd), size); +} + +size_t +filesystem_fread(word_t fd, void *buf, size_t size) +{ + size_t rcnt; + compid_t token; + token = (compid_t)cos_inv_token(); + + int ret = ext4_fread(ps_nsptr_lkup_fd(ns[token], fd), buf, size, &rcnt); + //printc("fread ret %d rcnt %d\n", ret, rcnt); + + return rcnt; +} + +size_t +filesystem_fwrite(word_t fd, void *buf, size_t size) +{ + size_t wcnt; + compid_t token; + + token = (compid_t)cos_inv_token(); + + //printc("fwrite writing %s\n", buf); + + int ret = ext4_fwrite(ps_nsptr_lkup_fd(ns[token], fd), buf, size, &wcnt); + //printc("fwrite ret %d wcnt %d\n", ret, wcnt); + + return wcnt; +} + +int +filesystem_fseek(word_t fd, long offset, unsigned long origin) +{ + compid_t token; + token = (compid_t)cos_inv_token(); + + return ext4_fseek(ps_nsptr_lkup_fd(ns[token], fd), offset, origin); +} + +unsigned long +filesystem_ftell(word_t fd) +{ + compid_t token; + token = (compid_t)cos_inv_token(); + + return ext4_ftell(ps_nsptr_lkup_fd(ns[token], fd)); +} + +unsigned long +filesystem_fsize(word_t fd) +{ + compid_t token; + token = (compid_t)cos_inv_token(); + + return ext4_fsize(ps_nsptr_lkup_fd(ns[token], fd)); +} + +void +cos_init(void) +{ + for (int i = 0; i < 64; i++) { ns[i] = ps_nsptr_create_slab_fd(); } + + bd = ext4_blockdev_get(); + // ext4_dmask_set(DEBUG_ALL); + + ext4_mkfs(&fs, bd, &info, fs_type); + ext4_device_register(bd, "ext4_fs"); + ext4_mount("ext4_fs", "/", false); +} diff --git a/src/components/implementation/filesystem/ext4/ext4_blockdev.c b/src/components/implementation/filesystem/ext4/ext4_blockdev.c new file mode 100644 index 0000000000..d51c2bbe41 --- /dev/null +++ b/src/components/implementation/filesystem/ext4/ext4_blockdev.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +#define EXT4_BLOCKDEV_BSIZE 4096 // 4KiB +#define EXT4_BLOCKDEV_SIZE 16 * 1024 * 1024 // 16KiB + +static int __blockdev_open(struct ext4_blockdev *bdev); +static int __blockdev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, uint32_t blk_cnt); +static int __blockdev_bwrite(struct ext4_blockdev *bdev, const void *buf, uint64_t blk_id, uint32_t blk_cnt); +static int __blockdev_close(struct ext4_blockdev *bdev); + +EXT4_BLOCKDEV_STATIC_INSTANCE(ext4_blockdev, EXT4_BLOCKDEV_BSIZE, EXT4_BLOCKDEV_SIZE / EXT4_BLOCKDEV_BSIZE, + __blockdev_open, __blockdev_bread, __blockdev_bwrite, __blockdev_close, 0, 0); + +static int +__blockdev_open(struct ext4_blockdev *bdev) +{ + return EOK; +} + +static int +__blockdev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, uint32_t blk_cnt) +{ + blockdev_bread(buf, blk_id, blk_cnt); + return EOK; +} + +static int +__blockdev_bwrite(struct ext4_blockdev *bdev, const void *buf, uint64_t blk_id, uint32_t blk_cnt) +{ + blockdev_bwrite(buf, blk_id, blk_cnt); + return EOK; +} + +static int +__blockdev_close(struct ext4_blockdev *bdev) +{ + return EOK; +} + +struct ext4_blockdev * +ext4_blockdev_get(void) +{ + return &ext4_blockdev; +} \ No newline at end of file diff --git a/src/components/implementation/filesystem/ext4/ps_os.c b/src/components/implementation/filesystem/ext4/ps_os.c new file mode 100644 index 0000000000..9ad11851a3 --- /dev/null +++ b/src/components/implementation/filesystem/ext4/ps_os.c @@ -0,0 +1,8 @@ +#include + +void * +ps_plat_alloc(size_t sz, coreid_t coreid) +{ + (void)coreid; + return (void *)memmgr_heap_page_allocn(sz / 4096); +} \ No newline at end of file From 0adc1387b68f1ed6d00acbdfe25139672665a2cd Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:10:50 +0800 Subject: [PATCH 16/19] ext4: Add a small test Signed-off-by: msdx321 --- composition_scripts/ext4_test.toml | 43 +++++++++++++++++++ .../implementation/tests/ext4_tests/Makefile | 18 ++++++++ .../implementation/tests/ext4_tests/doc.md | 9 ++++ .../tests/ext4_tests/ext4_tests.c | 27 ++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 composition_scripts/ext4_test.toml create mode 100644 src/components/implementation/tests/ext4_tests/Makefile create mode 100644 src/components/implementation/tests/ext4_tests/doc.md create mode 100644 src/components/implementation/tests/ext4_tests/ext4_tests.c diff --git a/composition_scripts/ext4_test.toml b/composition_scripts/ext4_test.toml new file mode 100644 index 0000000000..c17a2a5fa9 --- /dev/null +++ b/composition_scripts/ext4_test.toml @@ -0,0 +1,43 @@ +[system] +description = "Simplest system with both capability manager and scheduler, from unit_schedcomp.sh" + +[[components]] +name = "booter" +img = "no_interface.llbooter" +implements = [{interface = "init"}, {interface = "addr"}] +deps = [{srv = "kernel", interface = "init", variant = "kernel"}] +constructor = "kernel" + +[[components]] +name = "capmgr" +img = "capmgr.simple" +deps = [{srv = "booter", interface = "init"}, {srv = "booter", interface = "addr"}] +implements = [{interface = "capmgr"}, {interface = "init"}, {interface = "memmgr"}, {interface = "capmgr_create"}] +constructor = "booter" + +[[components]] +name = "sched" +img = "sched.root_fprr" +deps = [{srv = "capmgr", interface = "init"}, {srv = "capmgr", interface = "capmgr"}, {srv = "capmgr", interface = "memmgr"}] +implements = [{interface = "sched"}, {interface = "init"}] +constructor = "booter" + +[[components]] +name = "blockdev" +img = "blockdev.ramdisk" +deps = [{srv = "sched", interface = "init"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "capmgr", interface = "memmgr"}] +implements = [{interface = "blockdev"}] +constructor = "booter" + +[[components]] +name = "filesystem" +img = "filesystem.ext4" +deps = [{srv = "sched", interface = "init"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "blockdev", interface = "blockdev"}, {srv = "capmgr", interface = "memmgr"}] +implements = [{interface = "filesystem"}] +constructor = "booter" + +[[components]] +name = "ext4_tests" +img = "tests.ext4_tests" +deps = [{srv = "sched", interface = "init"}, {srv = "capmgr", interface = "capmgr_create"}, {srv = "filesystem", interface = "filesystem"}, {srv = "capmgr", interface = "memmgr"}] +constructor = "booter" \ No newline at end of file diff --git a/src/components/implementation/tests/ext4_tests/Makefile b/src/components/implementation/tests/ext4_tests/Makefile new file mode 100644 index 0000000000..f4255c6981 --- /dev/null +++ b/src/components/implementation/tests/ext4_tests/Makefile @@ -0,0 +1,18 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The set of interfaces that this component exports for use by other +# components. This is a list of the interface names. +INTERFACE_EXPORTS = +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = filesystem +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = component +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +include Makefile.subsubdir diff --git a/src/components/implementation/tests/ext4_tests/doc.md b/src/components/implementation/tests/ext4_tests/doc.md new file mode 100644 index 0000000000..68560c8d20 --- /dev/null +++ b/src/components/implementation/tests/ext4_tests/doc.md @@ -0,0 +1,9 @@ +## tests + +This is the skeleton interface used by the `mkcomponent.sh` script to aid in the creation of a new component. +It provides no functionality, and should never be depended on! +This documentation should be *replaced* in the documentation for a new component. + +### Description + +### Usage and Assumptions diff --git a/src/components/implementation/tests/ext4_tests/ext4_tests.c b/src/components/implementation/tests/ext4_tests/ext4_tests.c new file mode 100644 index 0000000000..5f3b3ac1cc --- /dev/null +++ b/src/components/implementation/tests/ext4_tests/ext4_tests.c @@ -0,0 +1,27 @@ +#include +#include +#include + +int +main(void) +{ + char buf[128]; + + printc("ext4_tests: opening a test file.\n"); + + int fd = filesystem_fopen("/test.txt", "w+"); + + printc("ext4_tests: writing hello world into the file\n"); + + filesystem_fwrite(fd, "Hello World!", 64); + + printc("ext4_tests: reading from the file\n"); + + filesystem_fseek(fd, 0, 0); + filesystem_fread(fd, buf, 64); + + printc("ext4_tests: readed %s\n", buf); + + while (1) + ; +} From f9914ab2054ef9ff114858511f136d28116e694d Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:13:25 +0800 Subject: [PATCH 17/19] lwext4: Add as a lib Signed-off-by: msdx321 --- src/components/lib/lwext4/Makefile | 88 ++++++++++++++++++++++++++++++ src/components/lib/lwext4/doc.md | 9 +++ src/components/lib/lwext4/lwext4 | 1 + 3 files changed, 98 insertions(+) create mode 100644 src/components/lib/lwext4/Makefile create mode 100644 src/components/lib/lwext4/doc.md create mode 160000 src/components/lib/lwext4/lwext4 diff --git a/src/components/lib/lwext4/Makefile b/src/components/lib/lwext4/Makefile new file mode 100644 index 0000000000..4be363789d --- /dev/null +++ b/src/components/lib/lwext4/Makefile @@ -0,0 +1,88 @@ +# Required variables used to drive the compilation process. It is OK +# for many of these to be empty. +# +# The library names associated with .a files output that are linked +# (via, for example, -llwext4) into dependents. This list should be +# "lwext4" for output files such as liblwext4.a. +LIBRARY_OUTPUT = lwext4 +# The .o files that are mandatorily linked into dependents. This is +# rarely used, and only when normal .a linking rules will avoid +# linking some necessary objects. This list is of names (for example, +# lwext4) which will generate lwext4.lib.o. Do NOT include the list of .o +# files here. Please note that using this list is *very rare* and +# should only be used when the .a support above is not appropriate. +OBJECT_OUTPUT = +# The path within this directory that holds the .h files for +# dependents to compile with (./ by default). Will be fed into the -I +# compiler arguments. +INCLUDE_PATHS = lwext4/include +# The interfaces this component is dependent on for compilation (this +# is a list of directory names in interface/) +INTERFACE_DEPENDENCIES = +# The library dependencies this component is reliant on for +# compilation/linking (this is a list of directory names in lib/) +LIBRARY_DEPENDENCIES = component +# Note: Both the interface and library dependencies should be +# *minimal*. That is to say that removing a dependency should cause +# the build to fail. The build system does not validate this +# minimality; that's on you! + +# There are two different *types* of Makefiles for libraries. +# 1. Those that are Composite-specific, and simply need an easy way to +# compile and itegrate their code. +# 2. Those that aim to integrate external libraries into +# Composite. These focus on "driving" the build process of the +# external library, then pulling out the resulting files and +# directories. These need to be flexible as all libraries are +# different. + +# Type 1, Composite library: This is the default Makefile for +# libraries written for composite. Get rid of this if you require a +# custom Makefile (e.g. if you use an existing +# (non-composite-specific) library. An example of this is `kernel`. +# include Makefile.lib + +## Type 2, external library: If you need to specialize the Makefile +## for an external library, you can add the external code as a +## subdirectory, and drive its compilation, and integration with the +## system using a specialized Makefile. The Makefile must generate +## lib$(LIBRARY_OUTPUT).a and $(OBJECT_OUTPUT).lib.o, and have all of +## the necessary include paths in $(INCLUDE_PATHS). +## +## To access the Composite Makefile definitions, use the following. An +## example of a Makefile written in this way is in `ps/`. +# +# include Makefile.src Makefile.comp Makefile.dependencies +# .PHONY: all clean init distclean +## Fill these out with your implementation +# all: +# clean: +# +## Default rules: +# init: clean all +# distclean: clean + +include Makefile.src Makefile.comp Makefile.dependencies + +.PHONY: all clean init distclean config clean_lib +CINC_ENV = $(CINC) $(DEPENDENCY_INCPATH) +CFLAGS = $(CINC_ENV) +export CINC_ENV +export CFLAGS + +all: + $(info Building lwext4 library...) + make -s -C lwext4 generic + make -s -C lwext4/build_generic lwext4 + @cp lwext4/build_generic/src/liblwext4.a . + +clean_lib: + make -s -C lwext4 clean + +clean: clean_lib config + +config: + $(info Configuring the lwext4 library) + +init: clean config +distclean: clean diff --git a/src/components/lib/lwext4/doc.md b/src/components/lib/lwext4/doc.md new file mode 100644 index 0000000000..70a73b1d4f --- /dev/null +++ b/src/components/lib/lwext4/doc.md @@ -0,0 +1,9 @@ +## lwext4 + +This is the skeleton library used by the `mklib.sh` script to aid in the creation of a new library. +It provides no functionality, and should never be depended on! +This documentation should be *replaced* in the documentation for a new library. + +### Description + +### Usage and Assumptions diff --git a/src/components/lib/lwext4/lwext4 b/src/components/lib/lwext4/lwext4 new file mode 160000 index 0000000000..d9ab1d9468 --- /dev/null +++ b/src/components/lib/lwext4/lwext4 @@ -0,0 +1 @@ +Subproject commit d9ab1d9468170b9f93db0db51d588e3beeee5e7b From 0b7f9e4a0c4d947f2c2da5fadd08567e476428cf Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:16:37 +0800 Subject: [PATCH 18/19] .gitignore: Update Signed-off-by: msdx321 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ef3b6a9bcc..cc59d51696 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ src/components/lib/ck/share doc/dev_manual/composite_dev_manual.pdf doc/dev_manual/resources/*.pdf system_binaries/cos_build-* +.vscode From 7c5069d94c63547ded48f3db5199cdd1843d7f9e Mon Sep 17 00:00:00 2001 From: msdx321 Date: Mon, 9 Aug 2021 11:26:32 +0800 Subject: [PATCH 19/19] ps: Fix merge error Signed-off-by: msdx321 --- src/components/lib/ps/ps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/lib/ps/ps b/src/components/lib/ps/ps index 71a9f77d02..2b9701a76f 160000 --- a/src/components/lib/ps/ps +++ b/src/components/lib/ps/ps @@ -1 +1 @@ -Subproject commit 71a9f77d02eb338906e1ca94377a49174457214f +Subproject commit 2b9701a76f966cdcf9955be79397deb1db5253dd