Commit Graph

920 Commits

Author SHA1 Message Date
Justin C. Miller
094b54d728 [tests] Get mailbox test running again
This commit fixes the mailbox tests in test_runner, which broke when
mailbox was simplified to just use call and respond. It also fixes a
bug the tests uncovered: if the mailbox is closed while a caller is in
the reply map (ie, when its call data has been passed on to a thread
calling respond, but has yet to be responded to itself), that caller is
never awoken.
2023-02-08 23:16:22 -08:00
Justin C. Miller
4125175870 [kernel] Give threads initial arguments
This commit changes the add_user_thunk to point to a new routine,
initialize_user_cpu, which sets all the registers that were previously
unset when starting a new user thread. The values for rdi and rsi are
popped off the initial stack values that add_user_thunk sets up, so that
user thread procs can take up to two arguments.

To suppor this, j6_thread_create gained two new arguments, which are
passed on to the thread.

This also let me finally get rid of the hack of passing an argument in
rsp when starting init.
2023-02-08 23:10:17 -08:00
Justin C. Miller
1cb8f1258d [testapp] Re-add testapp to default manifest
This commit re-adds testapp to the default manifest and does some
housecleaning on the module:

- Remove the old serial.* and io.*
- Update it to use current syscall APIs
- Update it to use libj6's higher-level thread API
2023-02-08 22:44:05 -08:00
Justin C. Miller
f05a1d3310 [kernel] Revive the debugcon logger as a kernel thread
The debugcon logger is now separate from logger::output, and is instead
a kernel-internal thread that watches for logs and prints them to the
deubcon device.
2023-02-08 22:32:01 -08:00
Justin C. Miller
71069cb38b [kernel] Empty wait_queue after calling clear()
Bugfix - wait_queue::clear() was not emptying out its util::deque after
waking all the threads, so it would just grow forever.
2023-02-08 22:29:49 -08:00
Justin C. Miller
393db1e792 [kernel] Switch logger from bip to ring buffer
A bip-buffer is good for producer/consumer systems, but ideally logs
will stay in the buffer until they're ousted because they need to be
overwritten. Now they're a regular ring buffer and every entry has an
incremental id. Consumers pass in the last id they've seen, and will get
the next log in the sequence.
2023-02-07 20:19:02 -08:00
Justin C. Miller
0a097ec7d3 [kernel] Add add_existing() to page_tree
This ended up being unused, but still probably useful: Refactor out the
"find" logic of page_tree::find_or_add (note that this is different than
the "find" logic of page_tree::find, as it potentially modifies the tree
to add a location to accommodate the page being searched for) into a new
page_tree::get_entry method. That was then used to add an add_existing
method for inserting pages into the page_tree.
2023-02-07 19:40:12 -08:00
Justin C. Miller
ada660deeb [kernel] Move log buffer to its own memory section
In prep for the coming change to keep log entries as a true ring buffer,
move the log buffer from bss into its own memory section.

Related changes in this commit:
- New vm_area_ring, which maps a set of pages twice to allow easy linear
  reading of data from a ring buffer when it wraps around the end.
- logger_init() went away, and the logger ctor is called from
  mem::initialize()
- Instead of an event object, the logger just has a bare wait_queue
- util::counted::from template type changed slightly to allow easy
  conversion from an intptr_t as well as a pointer
- Previously added debugcon_logger code removed - this will be added in
  a separate file in a followup commit
2023-02-08 09:21:52 -08:00
Justin C. Miller
118ee73ff1 [srv.init] Iterate and load drivers and services from initrd
Previously we were hard-coding loading specific files (the UART driver
and logging server) from the initrd. Now j6romfs has a for_each() method
to allow iterating all files in a directory, and init loads all programs
from /jsix/drivers and /jsix/services. Eventually this will need more
dynamic loading decisions for drivers but for now it's fine.
v0.7.0
2023-02-07 01:05:38 -08:00
Justin C. Miller
6a6b75b418 [kernel] Conditionally add an isa-debugcon output to logger
There have been a number of incidents lately where I've needed to see
logs but have been working on init, and broken the log output of
srv.logger. This commit adds a debug console output to io port 0x6600
if enabled at the top of logger.cpp.
2023-02-06 20:56:56 -08:00
Justin C. Miller
9297017688 [util] Improve util::counted usage as a bool
I often want to use util::counted as a bool, like with a regular
pointer. There was some basic support for that, but it didn't cover
every case - now it should.
2023-02-06 01:16:26 -08:00
Justin C. Miller
359ee035d8 [kernel] Only accept invalid handles for optional syscall args
The syscall helpers.h get_handle functions should be returing
j6_err_invalid_arg if the handle they're given is j6_handle_invalid,
unless explicitly set to optional.
2023-02-06 01:13:55 -08:00
Justin C. Miller
8966380ef9 [build] Warn on zero-length symbols when building symbol table
Make build_symbol_table.py output statistics on the symbol table it
builds, and emit warnings for zero-length symbols. Also added lengths to
several functions defined in asm that this uncovered.
2023-02-06 00:37:26 -08:00
Justin C. Miller
ab31825ab3 [boot] Restructure boot paging and program loading
Restructuring paging into an object that carries its page cache with it
and makes for simpler code. Program loading is also changed to not copy
the pages loaded from the file into new pages - we can impose a new
constraint that anything loaded by boot have a simple, page-aligned
layout so that we can just map the existing pages into the right
addresses. Also included are some linker script changes to help
accommodate this.
2023-02-05 22:02:41 -08:00
Justin C. Miller
aba45b9b67 [boot] Go back to loading symbol table in boot
The symbol table needs to be passed to the panic handler very early in
the kernel, loading it in init is far less useful. Return it to the boot
directory and remove it from the initrd.
2023-02-04 00:03:03 -08:00
Justin C. Miller
86d458fc6c [util] Move remaining *printf impementations to util::format
I added util::format as a replacement for other printf implementations
last year, but it sat there only being used by the kernel all this time.
Now I've templated it so that it can be used by the bootloader, and
removed printf from panic.serial as well.
2023-02-03 23:42:35 -08:00
Justin C. Miller
eba0127645 [bonnibel] Allow modules to list ld scripts in definition
Previously, to add a custom linker script, a module would need to modify
its variables after the fact to add to ldflags. Now module constructors
take a new keyword `ld_script` and handle the ldflags and dependencies
properly.
2023-01-31 23:57:39 -08:00
Justin C. Miller
61199d2f80 [boot] Don't print 'ok' in status line until success
Previously, status_line would show 'ok' until something went wrong. Now,
show an empty box until either a warning or error happens, or the
cleanup happens without an issue.
2023-01-31 22:40:05 -08:00
Justin C. Miller
72db77fb58 [build] Move configs/ to assets/build/
I was sick of `configs` colliding with `configure`, and these are
(mostly) static asset files anyway, they should live under assets/.
2023-01-30 00:42:35 -08:00
Justin C. Miller
7771584a18 [util] Switch CDB to use util::const_buffer
CDBs can only ever be read-only, so just using const_buffer makes sense.
2023-01-29 22:43:16 -08:00
Justin C. Miller
8b29680850 [init] Load uart and logger from initrd
Load drv.uart.elf and srv.logger.elf from the initrd and start them.
It's extremely manual and hard-coded at the moment, but it works and
they run, getting us back to where we were pre-initrd branch.
2023-01-29 21:35:12 -08:00
Justin C. Miller
933e4e8040 [assets] Update to latest OVMF build
Adding the final builds of OVMF from Gerd Hoffmann's builder, circa July
2022.
2023-01-29 20:33:38 -08:00
Justin C. Miller
5ea5978ee8 [kernel] Hide kernel symbols by default
Using `-fvisibility=hidden` when building the kernel, and then
`--discard-all` when stripping it, we shave almost 100KiB off of the
resulting ELF file.

Also dropped some unused symbols from the linker script, and rearranged
the sections so that the file is able to be mapped directly into memory
instead of having each section copied.
2023-01-29 20:27:21 -08:00
Justin C. Miller
e2e1696b7e [zstd] Move zstd.module to external/
It felt clunky to have zstd.module in src/libraries/zstd by itself, and
doesn't make much sense in src/libraries as it's an external library
anyway.

Now the ./configure script will pick up .module files in the top-level
external directory as well.
2023-01-29 19:18:19 -08:00
Justin C. Miller
6f7dd7fc05 [boot] More initrd format changes
CDB seemed to be too simple for the needs of init, and squashfs is too
laden with design choices to work around Linux's APIs. This commit adds
creation of an initrd image of a new format I've called `j6romfs`.

Note that this commit currently does not work! The initrd-reading code
still needs to be added.
2023-01-29 19:10:12 -08:00
Justin C. Miller
1f15d2ef49 [util] Break out util::const_buffer type
I've been using `const util::buffer` a lot of places where that's not
really what I mean, because I was avoiding having a separate type for
buffers with const pointers. But really this needed to happen.
2023-01-29 19:07:21 -08:00
Justin C. Miller
66abcc57a2 [boot] Build, load, and pass initrd from boot to init
The initrd image is now created by the build system, loaded by the
bootloader, and passed to srv.init, which loads it (but doesn't do
anything with it yet, so this is actually a functional regression).

This simplifies a lot of the modules code between boot and init as well:
Gone are the many subclasses of module and all the data being inline
with the module structs, except for any loaded files. Now the only
modules loaded and passed will be the initrd, and any devices only the
bootloader has knowledge of, like the UEFI framebuffer.
2023-01-28 21:13:52 -08:00
Justin C. Miller
6ef15a2721 [init] Add new initrd format
A new compressed initrd format for srv.init to load drivers, services,
and data from, instead of every file getting loaded by the bootloader.
This will allow for less memory allocated by the bootloader and passed
to init if not every driver or data file is loaded.

Loading, passing, and using the new initrd will be done in a coming
commit.
2023-01-18 10:59:34 -08:00
Justin C. Miller
5a3e0ba541 [definitions] Fix comment to clarify map_phys size units
system_map_phys takes a size in bytes, not pages.
2023-01-17 18:44:16 -07:00
Justin C. Miller
3af2d41a7f [zstd] Add libzstd
Adding libzstd from Zstandard release 1.5.3
2023-01-17 15:34:05 -08:00
Justin C. Miller
1b0c0b6dbe [util] Add missing <new> header
The <new> header was previously in one of the util headers, masking that
it was missing from these files.
2023-01-14 18:33:34 -08:00
Justin C. Miller
e93f48e2f7 [kernel] Track capability reference counts
First pass at reference-counting capabilities.
2023-01-14 15:43:07 -08:00
Justin C. Miller
7150e11ed0 [tools] Add remote option to qemu.sh
I discovered that QEMU has a "remote" option to the `-vnc` switch, which
causes it to reverse-connect to a VNC client on start. I've added this
into qemu.sh as the -r option.
2023-01-14 15:43:07 -08:00
Justin C. Miller
28cd3bb625 [kernel] Rename kernel main.cpp
Having main.cpp in the kernel and in the application being debugged is
annoying when setting breakpoints, so just like with main() vs
kernel_main(), kernel/main.cpp is now kernel/kernel_main.cpp.
2023-01-14 15:43:07 -08:00
Justin C. Miller
6ac4ec601d [kernel] standardize static constexpr order in kobject headers
The kobject headers flip-flopped the class constants between "static
constexpr" and "constexpr static".
2023-01-14 15:43:07 -08:00
Justin C. Miller
99b59393fe [init] Use a real std::unordered_map for the services map
Now that ceil* works in libc, use std::unordered_map instead of
util::node_map to store the protocol to service mapping.
2023-01-14 15:32:42 -08:00
Justin C. Miller
8c1bb593ce [libc] Add ciel, frexpr implementations
The clang __builtin_* functions cannot be relied upon, as they may just
emit a call to the stdlib version. So this commit adds an implementation
for ceil and frexpr, as well as their float versions.
2023-01-12 21:51:36 -08:00
Justin C. Miller
372bc1d2e6 [kernel] Store object ids instead of full koids
In preparation for futexes, I wanted to make kobjects a bit lighter.
Storing 32 bits of object id, and 8 bits of type (and not ending the
class in a ushort for handle count, which meant all kobjects were likely
to have a bunch of pad bytes), the kobject class data is now just one 8
byte word.

Also from this, change logs that mention threads or processes from
printing the full koid to just 2 bytes of object id from both process
and thread, which makes following the logs much easier.
2022-10-20 22:41:16 -07:00
Justin C. Miller
6583744532 [libj6] Add thread wrapper class
This new class makes it easier for user programs to spawn threads. This
change also includes support for .hh files in modules, to differentiate
headers that are C++-only in system libraries.
2022-10-20 22:12:02 -07:00
Justin C. Miller
2703080df2 [kernel] Add thread_join syscall
Thread joining is an important primitive that I seem to have totally
forgotten to implement previously.
2022-10-20 21:58:10 -07:00
Justin C. Miller
194776d226 [kernel] Remove status code from thread exit
The status code from thread exit had too many issues, (eg, how does it
relate to process exit code? what happens when different threads exit
with different exit codes?) and not enough value, so I'm getting rid of
it.
2022-10-20 21:49:40 -07:00
Justin C. Miller
c02aa084d1 [kernel] Allow for not passing handles in new mailbox calls
In the new mailbox structure, passing a j6_handle_invalid with a message
would result in a permission denied result, as the process did not have
a handle "0".
2022-10-14 21:55:46 -07:00
Justin C. Miller
516f4f1920 [boot] Support non-page-aligned program sections in init
When the bootloader loads srv.init's program sections into memory, it
needed to page-align them if they weren't. srv.init's loader itself
handles this case, but the bootloader's did not.
2022-10-14 21:53:30 -07:00
Justin C. Miller
b8323f7e0e [util] Move util::vector to allocator api
Now that the allocator API exists for node_map, have vector use it as
well.
2022-10-14 01:09:28 -07:00
Justin C. Miller
f5f2076db5 [kernel] Lock the heap allocator for part of reallocate
heap_allocator::reallocate relies on the allocate and free methods so
mostly doesn't need locking, but it does touch the tracking map, so
needs to protect that with a lock.
2022-10-14 01:07:37 -07:00
Justin C. Miller
1a04310f80 [kernel] Simplify mailbox code, and messages
A number of simplifications of mailboxes now that the interface is much
simpler, and synchronous.

* call and respond can now only transfer one handle at a time
* mailbox objects got rid of the message queue, and just have
  wait_queues of blocked threads, and a reply_to map.
* threads now have a message_data struct on them for use by mailboxes
2022-10-14 01:02:56 -07:00
Justin C. Miller
e830a3d37b [kernel] Move slab_allocated items to the heap
Allocate the slabs for slab-allocated items to the heap, now that heap
regions are aligned. This also lets the slab sizes be non-page-sized.
2022-10-11 18:52:19 -07:00
Justin C. Miller
c9bcc87511 [kernel] Simplify mailbox interface to call/respond
The only real usage of mailbox was mailbox_call or
mailbox_respond_receive. This change simplifies the interface to just
these syscalls.
2022-10-11 17:42:04 -07:00
Justin C. Miller
9ac4e51224 [kernel] Make capabilities/handles global
Instead of handles / capabilities having numeric ids that are only valid
for the owning process, they are now global in a system capabilities
table. This will allow for specifying capabilities in IPC that doesn't
need to be kernel-controlled.

Processes will still need to be granted access to given capabilities,
but that can become a simpler system call than the current method of
sending them through mailbox messages (and worse, having to translate
every one into a new capability like was the case before). In order to
track which handles a process has access to, a new node_set based on
node_map allows for an efficient storage and lookup of handles.
2022-10-10 21:19:25 -07:00
Justin C. Miller
41bb97b179 [util] Add node_set container
Add a new node_set container that is backed by a node_map internally.
Also switch node_map to use the new allocator interface.
2022-10-10 21:04:51 -07:00