[6s] Add 6s shell, make channels full-duplex

This commit adds the 6s shell, and a bunch of supporting work for it.
Major changes include:

- New shell.yaml manifest to give 6s control of the TTY instead of
  srv.logger
- Changes to mailbox syscalls to add max handles array size separate
  from input size. Also reversed the meaning of the similar data size
  argument in those syscalls. (Using the second arg as the max array
  size and the first as the current valid size allows for the auto
  verify code to verify handles properly, and simplifies user-side
  code.)
- New util::unique_ptr smart pointer class similar to std::unique_ptr
- New ipc::message format that uses util::unique_ptr to manage ownership
  and lifetimes and avoid extra copying.
- The service locator protocol now supports multiple handles per entry
- Channels got a major overhaul. They are now split into two VMAs, each
  containing a mutex, a condition, and a util::bip_buffer. The order of
  the VMAs determines which end of the pipe you're on. (ie, the creator
  swaps them before handing them to the other thread.) Their API also
  changed to be similar to that of util::bip_buffer, to avoid extra
  copies.
- util::bip_buffer now keeps its state and its buffer together, so that
  there are no pointers. This allows multiple processes to share them in
  shared memory, like in channels.
- The UART driver changed from keeping buffers for the serial ports to
  just keeping a channel, and the serial port objects read/write
  directly from/to the channel.

Known issues:

- The shell doesn't actually do anything yet. It echos its input back to
  the serial line and injects a prompt on new lines.
- The shell is one character behind in printing back to the serial line.
This commit is contained in:
Justin C. Miller
2024-04-23 23:32:28 -07:00
parent d8a21608c3
commit e725795a17
30 changed files with 727 additions and 323 deletions

View File

@@ -32,9 +32,13 @@ handle_load_request(j6romfs::fs &fs, const char *path, j6_handle_t &vma)
void
sanitize(char *s, size_t len)
{
if (len >= buffer_size) len--;
if (!s) return;
if (len >= buffer_size)
len = buffer_size - 1;
for (size_t i = 0; i < len; ++i)
if (!s || !*s) return;
if (!s[i]) return;
s[len] = 0;
}
@@ -44,17 +48,18 @@ initfs_start(j6romfs::fs &fs, j6_handle_t mb)
uint64_t tag = 0;
char *buffer = new char [buffer_size];
size_t out_len = buffer_size;
size_t out_len = 0;
uint64_t reply_tag = 0;
size_t handles_count = 1;
static constexpr size_t max_handles = 1;
size_t handles_count = 0;
j6_handle_t give_handle = j6_handle_invalid;
uint64_t proto_id;
j6_status_t s = j6_mailbox_respond(mb, &tag,
buffer, &out_len, 0,
&give_handle, &handles_count,
buffer, &out_len, buffer_size,
&give_handle, &handles_count, max_handles,
&reply_tag, j6_flag_block);
while (initfs_running) {
@@ -63,8 +68,6 @@ initfs_start(j6romfs::fs &fs, j6_handle_t mb)
return;
}
size_t data_out = 0;
switch (tag) {
case j6_proto_vfs_load:
sanitize(buffer, out_len);
@@ -72,23 +75,25 @@ initfs_start(j6romfs::fs &fs, j6_handle_t mb)
if (s != j6_status_ok) {
tag = j6_proto_base_status;
*reinterpret_cast<j6_status_t*>(buffer) = s;
data_out = sizeof(j6_status_t);
out_len = sizeof(j6_status_t);
break;
}
handles_count = 1;
tag = j6_proto_vfs_file;
break;
default:
tag = j6_proto_base_status;
*reinterpret_cast<j6_status_t*>(buffer) = j6_err_invalid_arg;
data_out = sizeof(j6_status_t);
out_len = sizeof(j6_status_t);
give_handle = j6_handle_invalid;
handles_count = 0;
}
out_len = buffer_size;
s = j6_mailbox_respond(mb, &tag,
buffer, &out_len, data_out,
&give_handle, &handles_count,
buffer, &out_len, buffer_size,
&give_handle, &handles_count, max_handles,
&reply_tag, j6_flag_block);
}
}