diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-12-10 02:12:39 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-12-10 02:26:12 -0700 |
commit | 22d27936b3d771a36b170b1f4b4ba58badbf3971 (patch) | |
tree | 4c1c0790b7b79e54e44dde00cf488d1620614846 | |
parent | 7bc1e8049dbbf572a773d01547eb9b587b112061 (diff) |
Get lib9p building on rp2040
-rwxr-xr-x | build-aux/stack.c.gen | 48 | ||||
-rw-r--r-- | cmd/sbc_harness/CMakeLists.txt | 1 | ||||
-rw-r--r-- | cmd/sbc_harness/main.c | 29 | ||||
-rw-r--r-- | lib9p/9p.c | 7 | ||||
-rw-r--r-- | lib9p/9p.generated.c | 3 | ||||
-rwxr-xr-x | lib9p/idl.gen | 3 | ||||
-rw-r--r-- | lib9p/internal.h | 5 | ||||
-rw-r--r-- | notes.md | 2 |
8 files changed, 64 insertions, 34 deletions
diff --git a/build-aux/stack.c.gen b/build-aux/stack.c.gen index 86bca26..2ce874d 100755 --- a/build-aux/stack.c.gen +++ b/build-aux/stack.c.gen @@ -164,8 +164,7 @@ def analyze( f"unexpected label value {repr(v)}" ) if m.group("usage_kind") == "dynamic": - pass - #raise ValueError(f"can't handle dynamic stack usage: {repr(elem.attrs.get("title", ""))}") + print(f"// warning: can't handle dynamic stack usage: {repr(elem.attrs.get("title", ""))}") node.location = m.group("location") node.nstatic = int(m.group("nstatic")) node.ndynamic = int(m.group("ndynamic")) @@ -264,32 +263,31 @@ def analyze( ) for grp_name, grp_filter in app_func_filters.items(): - namelen = max( - [len(app_location_xform(name)) for name in graph if grp_filter(name)] - + [len(grp_name) + 4] - ) - numlen = max(len(str(nstatic(name))) for name in graph if name.endswith("_cr")) - sep1 = ("=" * namelen) + " " + "=" * numlen - sep2 = ("-" * namelen) + " " + "-" * numlen - - print("= " + grp_name + " " + sep1[len(grp_name) + 3 :]) - + # Gather the data. nmax = 0 nsum = 0 + rows: dict[str, int] = {} for funcname in graph: if grp_filter(funcname): n = nstatic(funcname) - print( - f"{app_location_xform(funcname).ljust(namelen)} {str(n).rjust(numlen)}" - ) + rows[app_location_xform(funcname)] = n if n > nmax: nmax = n nsum += n + # Figure sizes. + namelen = max([len(k) for k in rows.keys()] + [len(grp_name) + 4]) + numlen = len(str(nsum)) + sep1 = ("=" * namelen) + " " + "=" * numlen + sep2 = ("-" * namelen) + " " + "-" * numlen + + # Print. + print("= " + grp_name + " " + sep1[len(grp_name) + 3 :]) + for name, num in rows.items(): + print(f"{name.ljust(namelen)} {str(num).rjust(numlen)}") print(sep2) print(f"{'Total'.ljust(namelen)} {str(nsum).rjust(numlen)}") print(f"{'Maximum'.ljust(namelen)} {str(nmax).rjust(numlen)}") - print(sep1) for funcname in sorted(missing): @@ -326,7 +324,7 @@ def main( re_call_other = re.compile(r"(?P<func>[^(]+)\(.*") all_nodes: list[Node] = [] - hooks_is_intrhandler: list[typing.Callable([str], bool)] = [] + hooks_is_intrhandler: list[typing.Callable[[str], bool]] = [] hooks_indirect_callees: list[typing.Callable[[str, str], list[str] | None]] = [] hooks_skip_call: list[typing.Callable[[list[str], str], bool]] = [] @@ -379,7 +377,11 @@ def main( hooks_indirect_callees += [sbc_indirect_callees] def sbc_is_thread(name: str) -> bool: - return name.endswith("_cr") or name == "main" + if name.endswith("_cr") and name != "lib9p_srv_read_cr": + return True + if name == "main": + return True + return False def sbc_is_intrhandler(name: str) -> bool: return name in [ @@ -403,8 +405,6 @@ def main( and any(c.endswith(":__assert_msg_fail") for c in chain[:-1]) ): return True - if call == "_cr_select_dequeue": # TODO: FIXME - return True return False hooks_skip_call += [sbc_skip_call] @@ -645,13 +645,6 @@ def main( hooks_indirect_callees += [tud_indirect_callees] - def tud_skip_call(chain: list[str], call: str) -> bool: - if call == "usbd_app_driver_get_cb": # TODO: FIXME - return True - return False - - hooks_skip_call += [tud_skip_call] - # newlib ######################################################### if arg_pico_platform == "rp2040": @@ -671,6 +664,7 @@ def main( synthetic_node("memcpy", 0), # TODO synthetic_node("memset", 0), # TODO synthetic_node("strlen", 0), # TODO + synthetic_node("strnlen", 0), # TODO synthetic_node("strncpy", 0), # TODO # other synthetic_node("random", 0), # TODO diff --git a/cmd/sbc_harness/CMakeLists.txt b/cmd/sbc_harness/CMakeLists.txt index b3aa610..f1b1be2 100644 --- a/cmd/sbc_harness/CMakeLists.txt +++ b/cmd/sbc_harness/CMakeLists.txt @@ -24,6 +24,7 @@ target_link_libraries(sbc_harness_objs libusb libdhcp libhw + lib9p ) pico_minimize_runtime(sbc_harness_objs INCLUDE PRINTF PRINTF_MINIMAL PRINTF_LONG_LONG PRINTF_PTRDIFF_T diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c index fb4b696..bbefe92 100644 --- a/cmd/sbc_harness/main.c +++ b/cmd/sbc_harness/main.c @@ -13,17 +13,21 @@ #include <libhw/rp2040_hwspi.h> #include <libhw/w5500.h> #include <libmisc/hash.h> +#include <libmisc/vcall.h> #include <libusb/usb_common.h> #include <libdhcp/client.h> +#include <lib9p/srv.h> #define LOG_NAME MAIN #include <libmisc/log.h> #include "usb_keyboard.h" +#include "config.h" + #define ARRAY_LEN(arr) (sizeof(arr)/sizeof((arr)[0])) -COROUTINE hello_world_cr(void *_chan) { +static COROUTINE hello_world_cr(void *_chan) { const char *msg = "Hello world!\n"; usb_keyboard_rpc_t *chan = _chan; cr_begin(); @@ -39,7 +43,7 @@ COROUTINE hello_world_cr(void *_chan) { cr_end(); } -COROUTINE dhcp_cr(void *_chip) { +static COROUTINE dhcp_cr(void *_chip) { struct w5500 *chip = _chip; cr_begin(); @@ -53,9 +57,20 @@ struct { struct w5500 dev_w5500; usb_keyboard_rpc_t keyboard_chan; uint16_t usb_serial[sizeof(uint64_t)*2]; /* UTF-16 */ + struct lib9p_srv srv; } globals; +static COROUTINE read9p_cr(void *) { + cr_begin(); + + lib9p_srv_read_cr(&globals.srv, + VCALL(&globals.dev_w5500, tcp_listen, CONFIG_9P_PORT)); + + cr_end(); +} + const char *hexdig = "0123456789ABCDEF"; +static_assert(CONFIG_9P_MAX_REQS*_CONFIG_9P_NUM_SOCKS <= 16); COROUTINE init_cr(void *) { cr_begin(); @@ -103,8 +118,16 @@ COROUTINE init_cr(void *) { /* set up coroutines **************************************************/ coroutine_add("usb_common", usb_common_cr, NULL); coroutine_add("usb_keyboard", usb_keyboard_cr, &globals.keyboard_chan); - //coroutine_add("hello_world", hello_world_cr, &keyboard_chan); + coroutine_add("hello_world", hello_world_cr, &globals.keyboard_chan); coroutine_add_with_stack_size(4*1024, "dhcp", dhcp_cr, &globals.dev_w5500); + for (int i = 0; i < _CONFIG_9P_NUM_SOCKS; i++) { + char name[] = {'r', 'e', 'a', 'd', '-', hexdig[i], '\0'}; + coroutine_add(name, read9p_cr, NULL); + } + for (int i = 0; i < CONFIG_9P_MAX_REQS*_CONFIG_9P_NUM_SOCKS; i++) { + char name[] = {'w', 'r', 'i', 't', 'e', '-', hexdig[i], '\0'}; + coroutine_add(name, lib9p_srv_write_cr, &globals.srv); + } cr_exit(); } @@ -65,8 +65,11 @@ int lib9p_errorf(struct lib9p_ctx *ctx, uint32_t linux_errno, char const *fmt, . } const char *lib9p_msg_type_str(struct lib9p_ctx *ctx, enum lib9p_msg_type typ) { - assert(0 <= typ && typ <= 0xFF); - return _lib9p_versions[ctx->version].msgs[typ].name; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" + assert(0 <= typ && typ <= 0xFF); +#pragma GCC diagnostic pop + return _lib9p_versions[ctx->version].msgs[typ].name; } /* main message functions *****************************************************/ diff --git a/lib9p/9p.generated.c b/lib9p/9p.generated.c index f3a907b..badeb95 100644 --- a/lib9p/9p.generated.c +++ b/lib9p/9p.generated.c @@ -27,7 +27,10 @@ static const char *version_strs[LIB9P_VER_NUM] = { }; const char *lib9p_version_str(enum lib9p_version ver) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" assert(0 <= ver && ver < LIB9P_VER_NUM); +#pragma GCC diagnostic pop return version_strs[ver]; } diff --git a/lib9p/idl.gen b/lib9p/idl.gen index 262e5f0..cca83da 100755 --- a/lib9p/idl.gen +++ b/lib9p/idl.gen @@ -724,7 +724,10 @@ static const char *version_strs[{c_ver_enum('NUM')}] = {{ ret += "};\n" ret += f""" const char *{idprefix}version_str(enum {idprefix}version ver) {{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" assert(0 <= ver && ver < {c_ver_enum('NUM')}); +#pragma GCC diagnostic pop return version_strs[ver]; }} """ diff --git a/lib9p/internal.h b/lib9p/internal.h index 57f7aa7..07bb9d6 100644 --- a/lib9p/internal.h +++ b/lib9p/internal.h @@ -8,7 +8,10 @@ #define _LIB9P_INTERNAL_H_ #include <stddef.h> /* for size_t */ -#include <limits.h> /* for SSIZE_MAX */ +#include <limits.h> /* for SSIZE_MAX, not set by newlib */ +#ifndef SSIZE_MAX +#define SSIZE_MAX (SIZE_MAX >> 1) +#endif #include <lib9p/9p.h> @@ -50,7 +50,7 @@ Which file to include: | `blksize_t` | `<sys/types.h>` | signed | | `pid_t` | `<sys/types.h>` | signed | | `ssize_t` | `<sys/types.h>` | signed | -| `SSIZE_MAX` | `<limits.h>` | | +| `SSIZE_MAX` | `<limits.h>` | not in newlib | | `suseconds_t` | `<sys/types.h>` | signed | | `clock_t` | `<sys/types.h>` | could be float | | `time_t` | `<sys/types.h>` | signed | |