Commit Graph

894 Commits

Author SHA1 Message Date
Justin C. Miller
ce27749705 [srv.init] Allow init loader to load dynamic ELFs
Use the `elf::file::valid()` change to allow the loader to load `ET_DYN`
binaries, and add a static offset to all load addresses for them.
2023-08-06 10:42:25 -07:00
Justin C. Miller
b239bb6df2 [util] Fix a non-explicit-typed shift in sized_uint
In basic_types.h, `sized_uint<N>` was shifting a mask by the bit width
of the type, which meant it wouldn't work for 64 bit types.
2023-08-05 17:43:14 -07:00
Justin C. Miller
28379dc0f6 [libj6] Add symbol sizes to syscall stubs
Add extra info to the NASM `global` directive to specify the sizes of
these symbols, mostly so they look right in `nm` or `readelf` and don't
trick me into thinking something is wrong.
2023-08-05 17:40:24 -07:00
Justin C. Miller
c86c0f2ae6 [elf] Allow checking for different file types
Previously `elf::file::valid()` only returned true for ELF files of type
`ET_EXEC`, now allow passing in of an expected file type.
2023-08-05 17:37:45 -07:00
Justin C. Miller
bbe27c6b53 [build] Move init to its own target
In order to allow -fpic and -fpie in the user target, move init to it's
own target -- it needs its own special build rules to make it loadable
by boot.
2023-07-31 00:16:02 -07:00
Justin C. Miller
21916ab869 [build] Refactor build options definitions
Split out build definition YAML files to allow different options based
on config, target, kind of module, and target/kind combination.
2023-07-30 23:44:04 -06:00
Justin C. Miller
778e766f6b [libj6] Fix a memcpy return address bug
My `REP.MOVSB` `memcpy` implementation had marked its C++ variable
constraints as output instead of input, causing the compiler to emit
code to copy the values of `$rsi` and `$rdi` back into the `src` and
`dst` pointers, so after the copy `dst` pointed to the memory just
beyond what had been copied.

Very few places actually used the return value from `memcpy`, so this
went unnoticed for a bit..
2023-07-12 19:46:02 -07:00
Justin C. Miller
5d1fdd0e81 [all] Reference headers in src instead of copying
This is the second of two big changes to clean up includes throughout
the project. Since I've started using clangd with Neovim and using
VSCode's intellisense, my former strategy of copying all header files
into place in `build/include` means that the real files don't show up in
`compile_commands.json` and so display many include errors when viewing
those header files in those tools.

That setup was mostly predicated on a desire to keep directory depths
small, but really I don't think paths like `src/libraries/j6/j6` are
much better than `src/libraries/j6/include/j6`, and the latter doesn't
have the aforementioned issues, and is clearer to the casual observer as
well.

Some additional changes:

- Added a new module flag `copy_headers` for behavior similar to the old
  style, but placing headers in `$module_dir/include` instead of the
  global `build/include`. This was needed for external projects that
  don't follow the same source/headers folder structure - in this case,
  `zstd`.
- There is no longer an associated `headers.*.ninja` for each
  `module.*.ninja` file, as only parsed headers need to be listed; this
  functionality has been moved back into the module's ninja file.
2023-07-12 19:45:43 -07:00
Justin C. Miller
f5208d1641 [all] Remove dependencies on non-freestanding libc
This is the first of two rather big changes to clean up includes
throughout the project. In this commit, the implicit semi-dependency on
libc that bonnibel adds to every module is removed. Previously, I was
sloppy with includes of libc headers and include directory order. Now,
the freestanding headers from libc are split out into libc_free, and an
implicit real dependency is added onto this module, unless `no_libc` is
set to `True`. The full libc needs to be explicitly specified as a
dependency to be used.

Several things needed to change in order to do this:

- Many places use `memset` or `memcpy` that cannot depend on libc. The
  kernel has basic implementations of them itself for this reason. Now
  those functions are moved into the lower-level `j6/memutils.h`, and
  libc merely references them. Other modules are now free to reference
  those functions from libj6 instead.
- The kernel's `assert.h` was renamed kassert.h (matching its `kassert`
  function) so that the new `util/assert.h` can use `__has_include` to
  detect it and make sure the `assert` macro is usable in libutil code.
- Several implementation header files under `__libj6/` also moved under
  the new libc_free.
- A new `include_phase` property has been added to modules for Bonnibel,
  which can be "normal" (default) or "late" which uses `-idirafter`
  instead of `-I` for includes.
- Since `<utility>` and `<new>` are not freestanding, implementations of
  `remove_reference`, `forward`, `move`, and `swap` were added to the
  `util` namespace to replace those from `std`, and `util/new.h` was
  added to declare `operator new` and `operator delete`.
2023-07-12 19:38:31 -07:00
Justin C. Miller
a7beb0df18 [util] Add moving append() call to vector
Add a version of `append()` that takes an rvalue reference.
2023-07-10 01:45:31 -07:00
Justin C. Miller
1ec46ee641 [util] Use chunk_size alias instead of N in deque
Using an alias to increase readability. No functional changes.
2023-07-10 01:44:19 -07:00
Justin C. Miller
3ba0600694 [tools] Add --no-build option to qemu.sh
Add an option to tell qemu.sh not to build before running. Also update
paths to be more explicit about where log files go.
2023-07-10 01:43:07 -07:00
Justin C. Miller
a449a88395 [user] Update logging and return in user apps
Update some userspace apps to return more distinct error messages and
make better use of j6::syslog.
2023-07-10 01:41:55 -07:00
Justin C. Miller
4bf03266a9 [libj6] Account for double-mapped ring buffers in j6::channel
When keeping track of addresses to give to the kernel for channel shared
memory, double the channel's size since the kernel will double-map the
area as a ring buffer.
2023-07-10 01:37:31 -07:00
Justin C. Miller
4bceac3d56 [kernel] Check for null handle arg in mailbox_call
The handle argument to `mailbox_call` is optional, so needs to be
manually checked by the syscall handler before dereferencing.
2023-07-10 01:34:19 -07:00
Justin C. Miller
350396d70f [tools] Commit memory debug (et al) tooling
These are some changes I made to debug tooling while tracking down the
bugfix in the previous commit.

Each `scripts/debug_*_alloc.gdb` script has gdb output a `*_allocs.txt`
file, which in turn can be parsed by the `scripts/parse_*_allocs.py`
script to find errors.
2023-07-10 01:31:07 -07:00
Justin C. Miller
ad3afae315 [kernel] Fix a heap double-allocate bug
In the heap allocator, new blocks allocated directly for an allocate
request (instead of indirectly as part of a block split) would only set
their order in the tracking map, not their free flag. This left
uninitialized data in the block info map, which thus meant it was marked
as free for looking up for merges. (Not for allocations, since the block
didn't actually appear in the free list.)
2023-07-10 01:24:13 -07:00
Justin C. Miller
0dc86f2a0d [misc] Get VSCode running / debugging working
I spent some time getting VSCode debugging working. Now I can use VSCode
on windows to work on jsix in Linux (WSL) and launch and debug it within
QEMU. So many layers but it works pretty nicely!
2023-07-07 16:19:47 -07:00
Justin C. Miller
2b3c276f33 [util] Abstract out radix_tree class from page_tree
Generalized the radix tree code from page_tree as util::radix_tree so
that it can be used elsewhere.
2023-07-04 17:43:23 -07:00
Justin C. Miller
8bf2425c4a [tools] Make qemu.sh debugcon output optional
I got sick of closing the debugcon window all the time when I only need
it sometimes, so it's now gated behind the '-x' option to qemu.sh.
2023-07-04 16:23:47 -07:00
Justin C. Miller
72530ccb15 [misc] Remove vscode artifacts
If I use vscode again at some point and set it up to run jsix nicely
I'll readd.
2023-07-02 17:56:09 -07:00
Justin C. Miller
da14fd123e [kernel] Add MXCSR handling, mask SIMD exceptions
Now threads inherit their MXCSR (sans exception state bits) SIMD
settings from their creator. By default, all exceptions are masked, and
both "to zero" flags are set.
2023-05-21 14:48:27 -07:00
Justin C. Miller
f215b98f74 [panic] Fix display of r14 & r15 in panic display
The register outputs for r14 and r15 when panic printed out any set of
CPU registers was incorrectly reusing r12 & r13 instead.
2023-05-20 13:07:40 -07:00
Justin C. Miller
b5662bfd25 [kernel] Initial XSAVE support implementation
Initial support for XSAVE, but not XSAVEOPT or XSAVEC:

- Enable XSAVE and set up xcr0 for all CPUs
- Allocate XSAVE area for all non-kernel threads
- Call XSAVE and XRSTOR on task switch
2023-05-05 12:04:37 -06:00
Justin C. Miller
3b3857548c [libcpu] Add CPU_FEATURE_WRN
The new CPU_FEATURE_WRN macro in the cpu features list will cause the
kernel to emit a warning but not panic if the feature is missing.
2023-05-01 20:35:12 -06:00
Justin C. Miller
1e2e154747 [libcpu] Fix CPUID register overwriting bug
Well god damnit, when i converted the `cpu::cpu_id::regs` struct to a
union, i was super sloppy and forgot to wrap the existing fields in
their own anonymous struct. I have been wrong about CPUID vales for
ages.
2023-04-30 15:05:23 -06:00
Justin C. Miller
2d8d4fd200 [libc] Fix random SSE alignment GP faults
The libc CRT _start function had a stray pop left in it, which was
causing the stack to never be 16-byte aligned and thus causing crashes
when SSE instructions were called.
2023-04-09 15:20:17 -07:00
Justin C. Miller
459b40ad57 [kernel] Fix merge conflict getting committed in cpu.cpp 2023-03-16 20:08:05 -07:00
Justin C. Miller
90cf1e2220 [tools] Use less for viewing debugcon output in qemu.sh
Allow scrollback and keeping around the pane after qemu exits by using
less as the viewer for the log output.
2023-03-16 20:01:40 -07:00
Justin C. Miller
692e0d8656 [drv.uart] Replace user code with new channels
Move all the user space uses of channels to use j6::channel.
2023-03-16 19:59:28 -07:00
Justin C. Miller
3ab1a6b170 [util] Remove asserts from util::bitset
When used in kernel vs. non-kernel code the assert macros were not
working as expected. Other util code does not use assert like this, so
I'm just dropping it from bitset.
2023-03-16 19:59:28 -07:00
Justin C. Miller
069bc63d1f [kernel] Return j6_err_timed_out when event_wait times out
Previously event_wait was incorrectly returning j6_status_ok when timing
out.
2023-03-16 19:59:28 -07:00
Justin C. Miller
373121c455 [libj6] Take out explicit type IDs from object_types.inc
This caused errors when there were gaps, so don't allow explicit IDs,
and just number types in order.
2023-03-16 19:59:28 -07:00
Justin C. Miller
936b12a977 [kernel] Deal with getting multiple log entries in debugcon
Getting entries from the logger object can return multiple in the same
buffer - debugcon was not accounting for the subsequent entries.
2023-03-16 19:59:28 -07:00
Justin C. Miller
2a4c286f2b [kernel] Fix error when log data wraps ring buffer
The offset wasn't being properly masked.
2023-03-16 19:59:28 -07:00
Justin C. Miller
bfab4f085e [cpu] Rename cpu_id::validate() to cpu_id::features()
Validate wasn't a correct name anymore. Also move the features enum out
of the cpu_id class scope and into the `cpu` namespace directly.
2023-03-16 19:59:24 -07:00
Justin C. Miller
201e7191ef [kernel] Make scheduler run queue's prev be an id, not a pointer
This would lead to errors in GDB's j6threads when the previous thread
had already exited.
2023-03-16 19:56:14 -07:00
Justin C. Miller
9fa588566f [kernel] First steps at removing channel objects
This commit does a number of things to start the transition of channels
from kernel to user space:

- Remove channel objects / syscalls from the kernel
- Add mutex type in libj6
- Add condition type in libj6
- Add a `ring` type flag for VMA syscalls to create ring buffers
- Implement a rudimentary shared memory channel using all of the above
2023-03-16 19:56:14 -07:00
Justin C. Miller
ed95574c24 [kernel] Add (wip) futex syscalls
Add the syscalls j6_futex_wait and j6_futex_wake. Currently marking this
as WIP as they need more testing.

Added to support futexes:
- vm_area and vm_space support for looking up physical address for a
  virtual address
- libj6 mutex implementation using futex system calls
2023-03-16 19:56:14 -07:00
Justin C. Miller
0c777bc62f [util] Add move-assignment operators to node_map, deque
Also add them to wait_queue as a wrapper to calling deque's
move-assignmen operator.
2023-03-16 19:56:14 -07:00
Justin C. Miller
1d7d5e8015 [tools] Allow for pointer-to-integer types in .def files
The upcoming futex syscalls will be easier to use (and to auto verify)
if passed a pointer instead of an address, this allows for changing a
`Primitive` to a `PrimitiveRef` by adding a `*` to the end.
2023-03-16 19:56:14 -07:00
Justin C. Miller
95627ba43c [kernel] Set mxcsr and xcr0 in cpu_early_init
There are some SSE instructions (moveaps, moveups) in userland code that
QEMU software emulation seems to be fine with but generate `#UD` on KVM.
So let's finally get floating-point support working. This is the first
step, just setting the control regs to try to fix that error.
2023-02-23 18:22:22 -08:00
Justin C. Miller
841ac41e36 [tools] Rearrange qemu tmux windows on smaller displays
So I can still use ./qemu.sh --debug on my laptop.
2023-02-22 21:14:10 -08:00
Justin C. Miller
a46d8bce37 [libc] Mark cast_to as always_inline
I've seen the compiler emit a call to cast_to, which it should never do.
2023-02-20 11:36:36 -08:00
Justin C. Miller
4052911ac4 [kernel] Clean up log areas
Removing several log areas that are not used
2023-02-20 11:35:44 -08:00
Justin C. Miller
3a7a18011c [init] Move PCIe probing to srv.init
This was kept in the kernel as a way to keep exercising the code, but it
doesn't belong there. This moves it to init, which doesn't do anything
but probe for devices currently - but at least it's executing the code
in userspace now.
2023-02-20 11:23:49 -08:00
Justin C. Miller
15e2f8abf3 [boot] Stop picking largest video mode
For now, using VNC, I want to keep the framebuffer mode small, so I'm
commenting out the bootloader's loop to pick the biggest video mode.
I'll revisit this as a bootconfig option later.
2023-02-20 11:21:35 -08:00
Justin C. Miller
6b43ddc8d7 [build] Update user build flags
Make symbols hidden by default, explicitly set architecture.
2023-02-20 11:20:46 -08:00
Justin C. Miller
508058c3d7 [uefi_fb] Fix log messages not showing in drv.uefi_fb
Also add drv.uefi_fb to the default manifest.
2023-02-20 11:18:59 -08:00
Justin C. Miller
4c9ff44b1c [init] Switch init to driver_main instead of custom _start
init still uses a custom _start to set up the stack, but then jumps to
_libc_crt0_start. The modules data passed to it is taken from the
j6_init_args instead of having it stashed into a global variable.

Also replace several uses of snprintf/j6_log with j6::syslog.
2023-02-20 11:15:08 -08:00