diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/sbc_harness/CMakeLists.txt | 42 | ||||
-rw-r--r-- | cmd/sbc_harness/config/config.h | 64 | ||||
-rw-r--r-- | cmd/sbc_harness/config/tusb_config.h | 110 | ||||
-rw-r--r-- | cmd/sbc_harness/main.c | 87 | ||||
-rw-r--r-- | cmd/sbc_harness/usb_keyboard.c | 115 | ||||
-rw-r--r-- | cmd/sbc_harness/usb_keyboard.h | 20 | ||||
-rw-r--r-- | cmd/srv9p/CMakeLists.txt | 25 | ||||
-rw-r--r-- | cmd/srv9p/config/config.h | 53 | ||||
-rw-r--r-- | cmd/srv9p/main.c | 116 | ||||
-rw-r--r-- | cmd/srv9p/static/Documentation/x | 1 | ||||
-rw-r--r-- | cmd/srv9p/static/README.md | 1 | ||||
-rw-r--r-- | cmd/srv9p/static9p.c | 242 | ||||
-rw-r--r-- | cmd/srv9p/static9p.h | 47 |
13 files changed, 0 insertions, 923 deletions
diff --git a/cmd/sbc_harness/CMakeLists.txt b/cmd/sbc_harness/CMakeLists.txt deleted file mode 100644 index 2018cf7..0000000 --- a/cmd/sbc_harness/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# cmd/sbc_harness/CMakeLists.txt - Build script for main sbc_harness.uf2 firmware file -# -# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> -# SPDX-License-Identifier: AGPL-3.0-or-later - -if (PICO_PLATFORM STREQUAL "rp2040") - -# Compile ###################################################################### - -add_library(sbc_harness_objs - main.c - usb_keyboard.c -) -target_include_directories(sbc_harness_objs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/config) -target_include_directories(sbc_harness_objs PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(sbc_harness_objs - pico_stdlib - hardware_flash - - libmisc - libusb - #libdhcp - libhw -) -pico_enable_stdio_usb(sbc_harness_objs 0) -pico_enable_stdio_uart(sbc_harness_objs 1) -pico_enable_stdio_semihosting(sbc_harness_objs 0) -pico_enable_stdio_rtt(sbc_harness_objs 0) - -# Analyze the stack ############################################################ - -add_stack_analysis(sbc_harness_stack.c sbc_harness_objs) - -# Link ######################################################################### - -add_executable(sbc_harness) -target_link_libraries(sbc_harness sbc_harness_objs) -target_sources(sbc_harness PRIVATE sbc_harness_stack.c) -pico_add_extra_outputs(sbc_harness) # create .map/.bin/.hex/.uf2 files in addition to .elf -pico_set_program_url(sbc_harness "https://git.lukeshu.com/sbc-harness") - -endif() diff --git a/cmd/sbc_harness/config/config.h b/cmd/sbc_harness/config/config.h deleted file mode 100644 index 5ee8634..0000000 --- a/cmd/sbc_harness/config/config.h +++ /dev/null @@ -1,64 +0,0 @@ -/* config.h - Compile-time configuration for sbc_harness - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#ifndef _CONFIG_H_ -#define _CONFIG_H_ - -/* W5500 **********************************************************************/ - -/** - * How many W5500 chips we have. - */ -#define CONFIG_W5500_NUM 1 - -/* 9P *************************************************************************/ - -#define CONFIG_9P_PORT 564 -/** - * This max-msg-size is sized so that a Twrite message can return - * 8KiB of data. - * - * This is the same as the default in Plan 9 4e's lib9p; it has the - * comment that "24" is "ample room for Twrite/Rread header - * (iounit)". In fact, the Twrite header is only 23 bytes - * ("size[4] Twrite[1] tag[2] fid[4] offset[8] count[4]") and the - * Rread header is even shorter at 11 bytes ("size[4] Rread[1] - * tag[2] count[4]"), so "24" appears to be the size of the Twrite - * header rounded up to a nice round number. - * - * In older versions of 9P ("9P1"), the max message size was - * defined as part of the protocol specification rather than - * negotiated. In Plan 9 1e it was (8*1024)+128, and was bumped to - * (8*1024)+160 in 2e and 3e. - */ -#define CONFIG_9P_MAX_MSG_SIZE ((4*1024)+24) -/** - * Maximum host-data-structure size. A message may be larger in - * unmarshaled-host-structures than marshaled-net-bytes due to (1) - * struct padding, (2) nul-terminator byes for strings. - */ -#define CONFIG_9P_MAX_HOSTMSG_SIZE CONFIG_9P_MAX_MSG_SIZE+16 -#define CONFIG_9P_MAX_FIDS 16 -#define CONFIG_9P_MAX_REQS 2 -#define CONFIG_9P_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */ - -/* COROUTINE ******************************************************************/ - -#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE 512 -#define CONFIG_COROUTINE_MEASURE_STACK 1 /* bool */ -#define CONFIG_COROUTINE_PROTECT_STACK 1 /* bool */ -#define CONFIG_COROUTINE_DEBUG 0 /* bool */ -#define CONFIG_COROUTINE_VALGRIND 0 /* bool */ - -#define _CONFIG_9P_NUM_SOCKS 7 -#define CONFIG_COROUTINE_NUM ( \ - 1 /* usb_common */ + \ - 1 /* usb_keyboard */ + \ - CONFIG_W5500_NUM /* irq handler */ + \ - _CONFIG_9P_NUM_SOCKS /* 9P accept()+read() */ + \ - (CONFIG_9P_MAX_REQS*_CONFIG_9P_NUM_SOCKS) /* 9P work+write() */ ) - -#endif /* _CONFIG_H_ */ diff --git a/cmd/sbc_harness/config/tusb_config.h b/cmd/sbc_harness/config/tusb_config.h deleted file mode 100644 index aeff31c..0000000 --- a/cmd/sbc_harness/config/tusb_config.h +++ /dev/null @@ -1,110 +0,0 @@ -/* tusb_config.h - Compile-time configuration for the TinyUSB library - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - * - * SPDX-License-Identifier: MIT - * The MIT License (MIT) - * - * Copyright (c) 2019 Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#ifndef _TUSB_CONFIG_H_ -#define _TUSB_CONFIG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -//-------------------------------------------------------------------- -// TinyUSB Device (TUD) initialization for rp2040-based boards -//-------------------------------------------------------------------- - -// Which USB port to use for the RootHub. -// The rp2040 only has 1 port, so it's gotta be port #0. -#define BOARD_TUD_RHPORT 0 - -// RHPort max operational speed. -// Use OPT_MODE_DEFAULT_SPEED for max speed supported by MCU. -#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED - -//-------------------------------------------------------------------- -// Configuration: common -//-------------------------------------------------------------------- - -// defined by compiler flags -#ifndef CFG_TUSB_MCU -#error CFG_TUSB_MCU must be defined -#endif - -// Conditional because it might be defined with `-D` on the command -// line if `cmake -DCMAKE_BUILD_TYPE=Debug`. -#ifndef CFG_TUSB_DEBUG -#define CFG_TUSB_DEBUG 0 -#endif - -// USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. -// Tinyusb use follows macros to declare transferring memory so that they can be put -// into those specific section. -// e.g -// - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) -// - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) -#define CFG_TUSB_MEM_SECTION /* blank */ -#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) - -#define CFG_TUD_ENABLED 1 -#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED - -//-------------------------------------------------------------------- -// Configuration: TinyUSB Device (TUD) -//-------------------------------------------------------------------- - -// control endpoint max packet size (only 8, 16, 32, or 64 are valid) -#define CFG_TUD_ENDPOINT0_SIZE 64 - -// Which of TinyUSB's built-in class drivers to enable. -// -// If a class takes an int, that's the maximum number of interfaces of -// that type that may be listed in the same configuration descriptor. -#define CFG_TUD_CDC 0 // int : Communications Device Class (e.g. ttyUSB) https://www.usb.org/sites/default/files/CDC1.2_WMC1.1_012011.zip -#define CFG_TUD_MSC 0 // bool: Mass Storage Class https://www.usb.org/sites/default/files/Mass_Storage_Specification_Overview_v1.4_2-19-2010.pdf -#define CFG_TUD_HID 1 // int : Human Interface Device https://www.usb.org/sites/default/files/hid1_11.pdf -#define CFG_TUD_AUDIO 0 // int : Audio https://www.usb.org/sites/default/files/audio10.pdf -#define CFG_TUD_VIDEO 0 // int : Video https://www.usb.org/sites/default/files/USB_Video_Class_1_5.zip -#define CFG_TUD_MIDI 0 // int : Musical Instrument Digital Interface https://www.usb.org/sites/default/files/USB%20MIDI%20v2_0.pdf -#define CFG_TUD_VENDOR 0 // int : ??? -#define CFG_TUD_USBTMC 0 // bool: Test & Measurement Class https://www.usb.org/sites/default/files/USBTMC_1_006a.zip -#define CFG_TUD_DFU_RUNTIME 0 // bool: Device Firmware Upgrade https://www.usb.org/sites/default/files/DFU_1.1.pdf -#define CFG_TUD_DFU 0 // bool: Device Firmware Upgrade https://www.usb.org/sites/default/files/DFU_1.1.pdf -#define CFG_TUD_ECM_RNDIS 0 // bool: net -#define CFG_TUD_NCM 0 // bool: net -#define CFG_TUD_BTH 0 // bool: Bluetooth - -// HID buffer size Should be sufficient to hold ID (if any) + Data -#define CFG_TUD_HID_EP_BUFSIZE 8 - -//-------------------------------------------------------------------- -#ifdef __cplusplus -} -#endif - -#endif /* _TUSB_CONFIG_H_ */ diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c deleted file mode 100644 index b9c5330..0000000 --- a/cmd/sbc_harness/main.c +++ /dev/null @@ -1,87 +0,0 @@ -/* sbc_harness/main.c - Main entry point and event loop for sbc-harness - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#include <string.h> /* libc: for strlen() */ -#include <stdio.h> /* libc: for printf() */ - -#include <pico/stdlib.h> /* pico-sdk:pico_stdlib: for stdio_uart_init() */ -#include <hardware/flash.h> /* pico-sdk:hardware_flash: for flash_get_unique_id() */ - -#include <libcr/coroutine.h> -#include <libhw/rp2040_hwspi.h> -#include <libhw/w5500.h> -#include <libmisc/hash.h> -#include <libusb/usb_common.h> - -#include "usb_keyboard.h" - -COROUTINE hello_world_cr(void *_chan) { - const char *msg = "Hello world!\n"; - usb_keyboard_rpc_t *chan = _chan; - cr_begin(); - - for (size_t i = 0;; i = (i+1) % strlen(msg)) { - int result = usb_keyboard_rpc_send_req(chan, (uint32_t)msg[i]); - if (result < 1) { - printf("error!\n"); - break; - } - } - - cr_end(); -} - -int main() { - /* initialization *****************************************************/ - stdio_uart_init(); - - /* NOR flash chips have a (bog-?)standard "RUID" "Read Unique - * ID" instruction; use our flash chip's unique ID as the - * basis for our serial numbers. */ - uint64_t flash_id64; - static_assert(sizeof(flash_id64) == FLASH_UNIQUE_ID_SIZE_BYTES); - flash_get_unique_id((uint8_t *)&flash_id64); - uint32_t flash_id32 = hash(&flash_id64, sizeof(flash_id64)); - static_assert(sizeof(flash_id32) == sizeof(hash(NULL, 0))); - uint8_t flash_id24[3] = { - (uint8_t)((flash_id32 >> 16) & 0xFF), - (uint8_t)((flash_id32 >> 8) & 0xFF), - (uint8_t)((flash_id32 >> 0) & 0xFF), - }; - - struct rp2040_hwspi dev_spi; - struct w5500 dev_w5500; - rp2040_hwspi_init(&dev_spi, "W5500", RP2040_HWSPI_0, - SPI_MODE_0, /* the W5500 supports mode 0 or mode 3 */ - 80*1000*1000, /* run at the W5500's max rate of 80MHz */ - 16, /* PIN_MISO */ - 19, /* PIN_MOSI */ - 18, /* PIN_CLK */ - 17); /* PIN_CS */ - w5500_init(&dev_w5500, "W5500", &dev_spi, - 21, /* PIN_INTR */ - 20, /* PIN_RESET */ - ((struct net_eth_addr){{ - /* vendor ID: "Wiznet" */ - 0x00, 0x08, 0xDC, - /* serial number */ - flash_id24[0], flash_id24[1], flash_id24[2], - }})); - - usb_common_earlyinit(); - usb_keyboard_init(); - usb_common_lateinit(); - - /* set up coroutines **************************************************/ - coroutine_add(usb_common_cr, NULL); - usb_keyboard_rpc_t keyboard_chan = {0}; - coroutine_add(usb_keyboard_cr, &keyboard_chan); - //coroutine_add(hello_world_cr, &keyboard_chan); - //coroutine_add(dhcp_client_cr, NULL); - - /* event loop *********************************************************/ - coroutine_main(); -} diff --git a/cmd/sbc_harness/usb_keyboard.c b/cmd/sbc_harness/usb_keyboard.c deleted file mode 100644 index 3500e31..0000000 --- a/cmd/sbc_harness/usb_keyboard.c +++ /dev/null @@ -1,115 +0,0 @@ -/* sbc_harness/usb_keyboard.c - Implementation of a USB keyboard device - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#include <tusb.h> - -#include <libusb/tusb_helpers.h> /* for TUD_ENDPOINT_IN */ -#include <libusb/usb_common.h> - -#include "usb_keyboard.h" - -#define UNUSED(name) /* name __attribute__ ((unused)) */ - -/** - * A USB-HID "Report Descriptor" (see USB-HID 1.11 §6.2.2 "Report - * Descriptor") describing a keyboard. - */ -static uint8_t const hid_report_descriptor_keyboard[] = { TUD_HID_REPORT_DESC_KEYBOARD() }; - -static uint8_t kbd_ifc = 0; - -void usb_keyboard_init() { - if (kbd_ifc) - return; - usb_common_earlyinit(); - - kbd_ifc = usb_add_interface(cfgnum_std, TUD_HID_DESC_LEN, (uint8_t[]){ - /* USB-HID input-only descriptor for inclusion in the config descriptor; consisting of 3 parts: - * 1. an interface descriptor (USB 2.0 §9.6.5 "Interface"), - * 2. a class-specific (class=HID) descriptor of type HID (USB-HID 1.11 §6.2.1 "HID Descriptor"), - * 3. an endpoint descriptor for inputs (USB 2.0 §9.6.6 "Endpoint"). - * The TUD_HID_DESCRIPTOR() macro takes care of this for us. */ - TUD_HID_DESCRIPTOR( - 0, /* interface : bInterfaceNumber ; Number of this interface (0-indexed) */ - STRID_KBD_IFC, /* interface : iInterface ; Index of string descriptor describing this interface */ - HID_ITF_PROTOCOL_KEYBOARD, /* interface : bInterfaceProtocol ; see USB-HID 1.11 §4.3 "Protocols" */ - sizeof(hid_report_descriptor_keyboard), /* hid : wDescriptorLength ; Total size of report descriptor */ - TUD_ENDPOINT_IN | 1, /* endpoint : bEndpointAddress ; Direction | endpoint number (arbitrary?) */ - CFG_TUD_HID_EP_BUFSIZE, /* endpoint : wMaxPacketSize ; Maximum packet size this endpoint is capable of sending or receiving */ - 10), /* endpoint : bInterval ; poll interval (in milliseconds?) */ - }); -} - -static uint8_t ascii2keycode[128][2] = { HID_ASCII_TO_KEYCODE }; - -COROUTINE usb_keyboard_cr(void *_chan) { - usb_keyboard_rpc_t *chan = _chan; - cr_begin(); - - uint8_t report_id = 0; - uint8_t modifier = 0; - uint8_t keycodes[6] = {0}; - for (;;) { - while (!tud_hid_n_ready(kbd_ifc)) - cr_yield(); - - if (usb_keyboard_rpc_can_recv_req(chan)) { - usb_keyboard_rpc_req_t req = usb_keyboard_rpc_recv_req(chan); - uint32_t rune = req.req; - - modifier = ascii2keycode[rune][0] ? KEYBOARD_MODIFIER_LEFTSHIFT : 0; - keycodes[0] = ascii2keycode[rune][1]; - tud_hid_n_keyboard_report(kbd_ifc, report_id, modifier, keycodes); - - while (!tud_hid_n_ready(kbd_ifc)) - cr_yield(); - - modifier = 0; - keycodes[0] = 0; - tud_hid_n_keyboard_report(kbd_ifc, report_id, modifier, keycodes); - - usb_keyboard_rpc_send_resp(req, 1); - } else { - modifier = 0; - keycodes[0] = 0; - tud_hid_n_keyboard_report(kbd_ifc, report_id, modifier, keycodes); - } - } - - cr_end(); -} - -/** - * Return a pointer to the HID "Report Descriptor" (see USB-HID 1.11 - * §6.2.2 "Report Descriptor") for the given index. - */ -uint8_t const *tud_hid_descriptor_report_cb(uint8_t index) { - static uint8_t const *reports[] = { - hid_report_descriptor_keyboard, - }; - if (index >= TU_ARRAY_SIZE(reports)) - return NULL; - return reports[index]; -} - -uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) -{ - // TODO not Implemented - (void) instance; - (void) report_id; - (void) report_type; - (void) buffer; - (void) reqlen; - - return 0; -} - -// Invoked when received SET_REPORT control request or -// received data on OUT endpoint ( Report ID = 0, Type = 0 ) -void tud_hid_set_report_cb(uint8_t UNUSED(instance), uint8_t UNUSED(report_id), hid_report_type_t UNUSED(report_type), uint8_t const *UNUSED(buffer), uint16_t UNUSED(bufsize)) -{ - // TODO not implemented -} diff --git a/cmd/sbc_harness/usb_keyboard.h b/cmd/sbc_harness/usb_keyboard.h deleted file mode 100644 index 210014d..0000000 --- a/cmd/sbc_harness/usb_keyboard.h +++ /dev/null @@ -1,20 +0,0 @@ -/* sbc_harness/usb_keyboard.h - Implementation of a USB keyboard device - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#ifndef _SBC_HARNESS_USB_KEYBOARD_H_ -#define _SBC_HARNESS_USB_KEYBOARD_H_ - -#include <stdint.h> /* for uint32_t */ - -#include <libcr/coroutine.h> /* for COROUTINE */ -#include <libcr_ipc/rpc.h> /* for CR_RPC_DECLARE */ - -CR_RPC_DECLARE(usb_keyboard_rpc, uint32_t, int) - -void usb_keyboard_init(void); -COROUTINE usb_keyboard_cr(void *arg); - -#endif /* _SBC_HARNESS_USB_KEYBOARD_H_ */ diff --git a/cmd/srv9p/CMakeLists.txt b/cmd/srv9p/CMakeLists.txt deleted file mode 100644 index b747882..0000000 --- a/cmd/srv9p/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# cmd/srv9p/CMakeLists.txt - Build script for srv9p test/dev executable -# -# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> -# SPDX-License-Identifier: AGPL-3.0-or-later - -if (PICO_PLATFORM STREQUAL "host") - -add_executable(srv9p - main.c - static9p.c -) -target_embed_sources(srv9p static.h - static/README.md - static/Documentation/x -) -target_include_directories(srv9p PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) -target_include_directories(srv9p PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/config) -target_link_libraries(srv9p - libcr - libcr_ipc - libmisc - lib9p -) - -endif() diff --git a/cmd/srv9p/config/config.h b/cmd/srv9p/config/config.h deleted file mode 100644 index a184e6f..0000000 --- a/cmd/srv9p/config/config.h +++ /dev/null @@ -1,53 +0,0 @@ -/* config.h - Compile-time configuration for srv9p - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#ifndef _CONFIG_H_ -#define _CONFIG_H_ - -#define CONFIG_NETIO_NUM_CONNS 8 - -#define CONFIG_9P_PORT 564 -/** - * This max-msg-size is sized so that a Twrite message can return - * 8KiB of data. - * - * This is the same as the default in Plan 9 4e's lib9p; it has the - * comment that "24" is "ample room for Twrite/Rread header - * (iounit)". In fact, the Twrite header is only 23 bytes - * ("size[4] Twrite[1] tag[2] fid[4] offset[8] count[4]") and the - * Rread header is even shorter at 11 bytes ("size[4] Rread[1] - * tag[2] count[4]"), so "24" appears to be the size of the Twrite - * header rounded up to a nice round number. - * - * In older versions of 9P ("9P1"), the max message size was - * defined as part of the protocol specification rather than - * negotiated. In Plan 9 1e it was (8*1024)+128, and was bumped to - * (8*1024)+160 in 2e and 3e. - */ -#define CONFIG_9P_MAX_MSG_SIZE ((4*1024)+24) -/** - * Maximum host-data-structure size. A message may be larger in - * unmarshaled-host-structures than marshaled-net-bytes due to (1) - * struct padding, (2) nul-terminator byes for strings. - */ -#define CONFIG_9P_MAX_HOSTMSG_SIZE CONFIG_9P_MAX_MSG_SIZE+16 -#define CONFIG_9P_MAX_FIDS 16 -#define CONFIG_9P_MAX_REQS 2 -#define CONFIG_9P_MAX_ERR_SIZE 128 /* 128 is what Plan 9 4e uses */ -#define CONFIG_9P_ENABLE_9P2000_u -/*#define CONFIG_9P_ENABLE_9P2000_e*/ - -#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (32*1024) -#define CONFIG_COROUTINE_MEASURE_STACK 1 /* bool */ -#define CONFIG_COROUTINE_PROTECT_STACK 1 /* bool */ -#define CONFIG_COROUTINE_DEBUG 0 /* bool */ -#define CONFIG_COROUTINE_VALGRIND 1 /* bool */ -#define CONFIG_COROUTINE_NUM (1 /* usb_common */ +\ - 1 /* usb_keyboard */ +\ - CONFIG_NETIO_NUM_CONNS /* accept+read */ +\ - (CONFIG_9P_MAX_REQS*CONFIG_NETIO_NUM_CONNS) /* work+write */ ) - -#endif /* _CONFIG_H_ */ diff --git a/cmd/srv9p/main.c b/cmd/srv9p/main.c deleted file mode 100644 index d30c4f9..0000000 --- a/cmd/srv9p/main.c +++ /dev/null @@ -1,116 +0,0 @@ -/* srv9p/main.c - Main entry point for test 9P server - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#include <error.h> -#include <stdio.h> - -#include <lib9p/srv.h> -#include <libcr/coroutine.h> -#include <libhw/generic/net.h> -#include <libhw/host_net.h> - -#include "static9p.h" -#include "static.h" - -/* configuration **************************************************************/ - -#include "config.h" - -#ifndef CONFIG_NETIO_NUM_CONNS - #error config.h must define CONFIG_NETIO_NUM_CONNS -#endif - -/* implementation *************************************************************/ - -#define UNUSED(name) /* name __attribute__((unused)) */ - -/* file tree ******************************************************************/ - -#define FILE_COMMON(NAME) { \ - .vtable = &static_file_vtable, \ - \ - .u_name = "root", .u_num = 0, /* owner user */ \ - .g_name = "root", .g_num = 0, /* owner group */ \ - .m_name = "root", .m_num = 0, /* last-modified-by user */ \ - \ - .pathnum = __COUNTER__, \ - .name = NAME, \ - .perm = 0444, \ - .atime = 1728337905, \ - .mtime = 1728337904, \ - } - -#define DIR_COMMON(NAME) { \ - .vtable = &static_dir_vtable, \ - \ - .u_name = "root", .u_num = 0, /* owner user */ \ - .g_name = "root", .g_num = 0, /* owner group */ \ - .m_name = "root", .m_num = 0, /* last-modified-by user */ \ - \ - .pathnum = __COUNTER__, \ - .name = NAME, \ - .perm = 0555, \ - .atime = 1728337905, \ - .mtime = 1728337904, \ - } - -#define STATIC_FILE(STRNAME, SYMNAME) \ - &((static struct static_file){ \ - ._static_common = FILE_COMMON(STRNAME), \ - .data_start = _binary_static_##SYMNAME##_start, \ - .data_end = _binary_static_##SYMNAME##_end, \ - }) - -static struct static_dir root = { - ._static_common = DIR_COMMON(""), - .members = { - &((static struct static_dir){ - ._static_common = DIR_COMMON("Documentation"), - .members = { - STATIC_FILE("x", Documentation_x), - NULL - }, - }), - STATIC_FILE("README.md", README_md), - NULL, - }, -}; - -static implements_lib9p_srv_file *get_root(struct lib9p_srv_ctx *UNUSED(ctx), char *UNUSED(treename)) { - return &root; -} - -/* main ***********************************************************************/ - -static COROUTINE read_cr(void *_srv) { - struct lib9p_srv *srv = _srv; - assert(srv); - - cr_begin(); - - struct hostnet_tcp_listener listener; - hostnet_tcp_listener_init(&listener, 9000); - - lib9p_srv_read_cr(srv, &listener); - - cr_end(); -} - -int main() { - struct lib9p_srv srv = { - .rootdir = get_root, - }; - - for (int i = 0; i < CONFIG_NETIO_NUM_CONNS; i++) - if (!coroutine_add(read_cr, &srv)) - error(1, 0, "coroutine_add(read_cr, &srv)"); - for (int i = 0; i < 2*CONFIG_NETIO_NUM_CONNS; i++) - if (!coroutine_add(lib9p_srv_write_cr, &srv)) - error(1, 0, "coroutine_add(lib9p_srv_write_cr, &srv)"); - - coroutine_main(); - return 1; -} diff --git a/cmd/srv9p/static/Documentation/x b/cmd/srv9p/static/Documentation/x deleted file mode 100644 index 257cc56..0000000 --- a/cmd/srv9p/static/Documentation/x +++ /dev/null @@ -1 +0,0 @@ -foo diff --git a/cmd/srv9p/static/README.md b/cmd/srv9p/static/README.md deleted file mode 100644 index af5626b..0000000 --- a/cmd/srv9p/static/README.md +++ /dev/null @@ -1 +0,0 @@ -Hello, world! diff --git a/cmd/srv9p/static9p.c b/cmd/srv9p/static9p.c deleted file mode 100644 index 3632c26..0000000 --- a/cmd/srv9p/static9p.c +++ /dev/null @@ -1,242 +0,0 @@ -/* srv9p/static9p.c - Serve static files over 9P - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#include <assert.h> - -#include <libmisc/vcall.h> - -#include "static9p.h" - -#define UNUSED(name) /* name __attribute__((unused)) */ -#define p9_str(cstr) ((struct lib9p_s){ .len = strlen(cstr), .utf8 = cstr }) -#define p9_nulstr ((struct lib9p_s){ .len = 0, .utf8 = NULL }) - -/* common *********************************************************************/ - -static implements_lib9p_srv_file *static_common_clone(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx) { - _static_common *self = VCALL_SELF(_static_common, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - return self; -} - -static void static_common_free(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx) { - _static_common *self = VCALL_SELF(_static_common, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - /* do nothing */ -} - -static uint32_t static_common_io(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, lib9p_o_t UNUSED(flags)) { - _static_common *self = VCALL_SELF(_static_common, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - return 0; -} - -static void static_common_wstat(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, - struct lib9p_stat UNUSED(new)) { - _static_common *self = VCALL_SELF(_static_common, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem"); -} - -static void static_common_remove(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx) { - _static_common *self = VCALL_SELF(_static_common, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem"); -} - -/* dir ************************************************************************/ - -static struct lib9p_stat static_dir_stat(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx) { - struct static_dir *self = VCALL_SELF(struct static_dir, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - return (struct lib9p_stat){ - .kern_type = 0, - .kern_dev = 0, - .file_qid = { - .type = LIB9P_QT_DIR, - .vers = 1, - .path = self->pathnum, - }, - .file_mode = LIB9P_DM_DIR | (self->perm & 0555), - .file_atime = self->atime, - .file_mtime = self->mtime, - .file_size = 0, - .file_name = p9_str(self->name), - .file_owner_uid = p9_str(self->u_name), - .file_owner_gid = p9_str(self->g_name), - .file_last_modified_uid = p9_str(self->m_name), - .file_extension = p9_nulstr, - .file_owner_n_uid = self->u_num, - .file_owner_n_gid = self->g_num, - .file_last_modified_n_uid = self->m_num, - }; -} - -static implements_lib9p_srv_file *static_dir_dopen(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, - char *childname) { - struct static_dir *self = VCALL_SELF(struct static_dir, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - for (size_t i = 0; self->members[i]; i++) { - implements_lib9p_srv_file *filep = self->members[i]; - struct lib9p_stat stat = VCALL(filep, stat, ctx); - if (lib9p_ctx_has_error(&ctx->basectx)) - break; - lib9p_assert_stat(stat); - if (strcmp(stat.file_name.utf8, childname) == 0) - return filep; - } - lib9p_error(&ctx->basectx, - LINUX_ENOENT, "no such file or directory"); - return NULL; -} - -static implements_lib9p_srv_file *static_dir_dcreate(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, - char *UNUSED(childname), - lib9p_dm_t UNUSED(perm), lib9p_o_t UNUSED(flags)) { - struct static_dir *self = VCALL_SELF(struct static_dir, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem"); - return NULL; -} - -static size_t static_dir_dread(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, - uint8_t *buf, - uint32_t byte_count, - size_t _obj_offset) { - struct static_dir *self = VCALL_SELF(struct static_dir, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - uint32_t byte_offset = 0; - size_t obj_offset = _obj_offset; - while (self->members[obj_offset]) { - implements_lib9p_srv_file *filep = self->members[obj_offset]; - struct lib9p_stat stat = VCALL(filep, stat, ctx); - if (lib9p_ctx_has_error(&ctx->basectx)) - break; - lib9p_assert_stat(stat); - uint32_t nbytes = lib9p_marshal_stat(&ctx->basectx, byte_count-byte_offset, &stat, - &buf[byte_offset]); - if (!nbytes) { - if (obj_offset == _obj_offset) - lib9p_error(&ctx->basectx, - LINUX_ERANGE, "stat object does not fit into negotiated max message size"); - break; - } - byte_offset += nbytes; - obj_offset++; - } - return obj_offset - _obj_offset; -} - -struct lib9p_srv_file_vtable static_dir_vtable = { - .clone = static_common_clone, - .free = static_common_free, - - .io = static_common_io, - .stat = static_dir_stat, - .wstat = static_common_wstat, - .remove = static_common_remove, - - .dopen = static_dir_dopen, - .dcreate = static_dir_dcreate, - - .dread = static_dir_dread, -}; - -/* file ***********************************************************************/ - -static inline size_t static_file_size(struct static_file *file) { - assert(file); - -#if __unix__ - assert(file->data_start); -#endif - if (!file->data_end) - return file->data_size; - return (size_t)((uintptr_t)file->data_end - (uintptr_t)file->data_start); -} - -static struct lib9p_stat static_file_stat(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx) { - struct static_file *self = VCALL_SELF(struct static_file, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - return (struct lib9p_stat){ - .kern_type = 0, - .kern_dev = 0, - .file_qid = { - .type = LIB9P_QT_FILE, - .vers = 1, - .path = self->pathnum, - }, - .file_mode = self->perm & 0444, - .file_atime = self->atime, - .file_mtime = self->mtime, - .file_size = (uint64_t)static_file_size(self), - .file_name = p9_str(self->name), - .file_owner_uid = p9_str(self->u_name), - .file_owner_gid = p9_str(self->g_name), - .file_last_modified_uid = p9_str(self->m_name), - .file_extension = p9_nulstr, - .file_owner_n_uid = self->u_num, - .file_owner_n_gid = self->g_num, - .file_last_modified_n_uid = self->m_num, - }; -} - -static uint32_t static_file_pread(implements_lib9p_srv_file *_self, struct lib9p_srv_ctx *ctx, - void *buf, - uint32_t byte_count, - uint64_t byte_offset) { - struct static_file *self = VCALL_SELF(struct static_file, implements_lib9p_srv_file, _self); - assert(self); - assert(ctx); - - size_t data_size = static_file_size(self); - - if (byte_offset > (uint64_t)data_size) { - lib9p_error(&ctx->basectx, - LINUX_EINVAL, "offset is past end-of-file length"); - return 0; - } - - size_t beg_off = (size_t)byte_offset; - size_t end_off = beg_off + (size_t)byte_count; - if (end_off > data_size) - end_off = data_size; - memcpy(buf, &self->data_start[beg_off], end_off-beg_off); - return (uint32_t)(end_off-beg_off); -} - -struct lib9p_srv_file_vtable static_file_vtable = { - .clone = static_common_clone, - .free = static_common_free, - - .io = static_common_io, - .stat = static_file_stat, - .wstat = static_common_wstat, - .remove = static_common_remove, - - .pread = static_file_pread, - .pwrite = NULL, -}; diff --git a/cmd/srv9p/static9p.h b/cmd/srv9p/static9p.h deleted file mode 100644 index 7a3d476..0000000 --- a/cmd/srv9p/static9p.h +++ /dev/null @@ -1,47 +0,0 @@ -/* srv9p/static9p.h - Serve static files over 9P - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#ifndef _SRV9P_STATIC9P_H_ -#define _SRV9P_STATIC9P_H_ - -#include <lib9p/srv.h> - -typedef struct { - implements_lib9p_srv_file; - - char *u_name; - uint32_t u_num; - char *g_name; - uint32_t g_num; - char *m_name; - uint32_t m_num; - - uint64_t pathnum; - char *name; - lib9p_dm_t perm; - uint32_t atime, mtime; -} _static_common; - -struct static_dir { - _static_common; - - /* NULL-terminated */ - implements_lib9p_srv_file *members[]; -}; - - -struct static_file { - _static_common; - - char *data_start; /* must not be NULL */ - char *data_end; /* may be NULL, in which case data_size is used */ - size_t data_size; /* only used if .data_end==NULL */ -}; - -extern struct lib9p_srv_file_vtable static_dir_vtable; -extern struct lib9p_srv_file_vtable static_file_vtable; - -#endif /* _SRV9P_STATIC9P_H_ */ |