Commit Graph

859 Commits

Author SHA1 Message Date
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
Justin C. Miller
531e160136 [util] Fix node_map growth
When node_map grew, it was not properly applying the fixup routine to
non-moved elements. This fixes the grow algorithm to:

1. Realloc the array and set all new slots to empty/invalid
2. Check each old slot and remove/reinsert the item if it exists and its
   optimal slot is later in the array than its current slot
3. Reverse-iterate the original slots and call fixup() on empty slots to
   keep items from being located after a more-optimal empty slot

Also fixed the fixup() function to not need to be called in a loop
anymore, as it's only used the one way - on a given empty slot, looping
until it hits an empty slot or optimally-placed item.
2022-10-10 20:58:31 -07:00
Justin C. Miller
ba0ce13fe3 [util] Add util allocator.h interface
The allocator is a interface for types that expose allocator functions
for use in container templates like node_map (usage coming soon).

Also added an implementation for the kernel heap allocator.
2022-10-10 20:54:30 -07:00
Justin C. Miller
48e3f9f9d2 [kernel] Fix freelist-clobber bug in heap allocator
The heap_allocator::get_free(order) function returns a reference to the
head pointer of the given freelist, so that it can be manipulated.
However, split_off was also taking a reference to a pointer for an out
param - passing the freelist pointer in here caused split_off to modify
the freelist.

I cleaned up a bunch of the places the freelist pointers were being
touched to make the usage more explicit.
2022-10-10 20:50:08 -07:00
Justin C. Miller
19791d1d7f [debug] Add gdb pretty-printers: vectors, handle sets, cap table
Adding pretty printers to aid in debugging:
* For the cap_table type so that `p g_cap_table` displays a neat table
* For node_sets of handles to easily see what handles a process owns
* For util::vector to include its contents in the output
2022-10-09 22:07:53 -07:00
Justin C. Miller
d04b2ae315 [tools] Allow struct types in definitions
Allow struct type names in definitions, which result in struct buffer
pointers in generated code.
2022-10-06 23:15:20 -07:00
Justin C. Miller
6b20f1fb19 [kernel] Make sure high bits are 0 writing SFMASK MSR
QEMU handles bits bring written in the (reserved) high bits of SFMASK
just fine, but KVM gives a #GP exception.
2022-10-04 20:10:41 -07:00
Justin C. Miller
e90647d498 [kernel] Change heap alloc for better alignment
Created a new util/node_map.h that implements a map that grows in-place.
Now this is used for tracking blocks' size orders, instead of a header
at the start of the memory block. This allows the whole buddy block to
be allocated, allowing for page-aligned (or greater) blocks to be
requested from the heap.
2022-10-02 17:32:26 -07:00
Justin C. Miller
11b61ab345 [kernel] Change kernel log levels
The kernel log levels are now numerically reversed so that more-verbose
levels can be added to the end. Replaced 'debug' with 'verbose', and
added new 'spam' level.
2022-09-25 17:25:43 -07:00
Justin C. Miller
7b8fd76af0 [libj6] Move caps.h to cap_flags.h
This file is just the generated cap flag constants. Move it to not
collide with more capability code to be added.
2022-09-25 17:23:14 -07:00
Justin C. Miller
a2b876825a [kernel] Move mispalced slab_allocated.h
slab_allocated.h had accidentally been placed in src/kernel/objects
2022-09-25 17:15:00 -07:00
Justin C. Miller
9f981ada41 [kernel] Save rsp0 to a process' TSS too
On task switch a process' rsp0 value in its TSS was not getting updated.
2022-09-16 19:39:32 -07:00