Commit Graph

959 Commits

Author SHA1 Message Date
Justin C. Miller
1ebee17880 [build] Explicitly add c++ standard headers to userspace
This helps language servers not freak out.
2024-08-18 19:40:16 -07:00
Justin C. Miller
4649d5f77b [kernel] Add a _very_ basic TLB shootdown mechanism
This TLB shootdown implementation is pretty janky: When the kernel
unmaps a mapping, it sends an IPI to all other cores and doesn't even
wait to ensure they've finished handling it. Upon getting one of these
IPIs, the core just re-writes cr3 to flush all TLBs.
2024-08-13 19:02:40 -07:00
Justin C. Miller
d3c1d6cc34 [kernel] Add debug names to processes
To make debugging easier, add names to processes. These are arbitrary
and supplied by the caller of process_create. The max is 31 characters
in debug configuration, and 0 in release.
2024-08-12 19:40:20 -07:00
Justin C. Miller
ee24ec8d5c [kernel] Ensure all VMA sizes are multiples of page size
Using a 0 address in vma_create_map or vma_map would run into issues if
VMAs had sizes that didn't end on page boundaries. Since any size that's
not a multiples of the page size is a lie, make vm_area's ctor enforce
page sizing.
2024-08-12 19:28:08 -07:00
Justin C. Miller
372325fab7 [scripts] Fix for missing path seperator in errno.h
Make sure to add a path seperator after the root in
codegen.arch_includes.
2024-08-12 19:26:56 -07:00
Justin C. Miller
8f036d9293 [kernel] Fix the mysterious paging bug!!
There has been a random bug (that occurs frequently outside the debugger
but rarely inside the debugger, of course) that seemed to be caused by
inconsistent page mappings. Sometimes loading an ELF would work. Other
times loading that same ELF, the loader would complain of missing
sections or invalid headers. Worse, occasionally program execution would
jump off into random memory for no reason I could see by examining the
disassembly. This issue has been plauging me FOR A YEAR and I've been
pulling my hair out trying to find it.

https://stackoverflow.com/a/28384866

Eventually this stack overflow answer to a different question about
INVLPG gave me a hint that the 'accessed' flag of page table entries
might not be set on pages even if they end up in the TLB.

Good riddance to this damned bug.
2024-08-11 12:40:13 -07:00
Justin C. Miller
e345cdd1a7 [util] Add util::bitset::set(i, val)
Allow for easier callsite code instead of having to switch calling
set(i) vs clear(i) - now set(i, boolean) is an option.
2024-08-10 23:33:26 -07:00
Justin C. Miller
fca570a163 [scripts] Make j6libc.py into the codegen package
j6libc.py was initially made for libc to generate stdint.h, but it
gained a few things that aren't libc-specific. Move it to a package and
split the int-types-specific code into codegen.int_types.
2024-08-10 23:29:21 -07:00
Justin C. Miller
ff64d1989f [docs] Update docs: kernel mem, process init
Updated documentation: Added documentation on the kernel address space
layout, process initialization, and rebuilt the syscall docs.
2024-08-10 23:11:14 -07:00
Justin C. Miller
d3f5db2479 [crt0] Actually pass argc, argv, envp to main()s
With the new SysV style process init args, it's a bit easier to finally
parse out argc, argv, and envp from the stack and pass them on to main
functions.
2024-08-10 17:37:34 -07:00
Justin C. Miller
fa587060f1 [libj6] Change to a more SysV style process init args
Pull out the old linked list of args structures in favor of doing things
the SysV ABI-specified way.
2024-08-09 19:14:44 -07:00
Justin C. Miller
b137c75eb2 [kernel] Use box-drawing characters in debugcon
Slight change to debugcon display format that replaces | with the
box-drawing character equivalent to seperate area/level from log
messages.
2024-08-08 19:46:32 -07:00
Justin C. Miller
05c1361283 [libc] Implement setjmp/longjmp
Add a very simple setjmp/longjmp implementation. No destructors or other
cleanup is handled.
2024-08-08 19:31:20 -07:00
Justin C. Miller
c6835dad70 [tools] Update telnet to nc in qemu.sh
The telnet utility seems to have stopped existing on my wsl
installation. That's fine, netcat is the more correct tool here anyways.
2024-08-04 12:14:42 -07:00
Justin C. Miller
e7fa1dde97 [ld.so] Mark main module to not run ctors
Forgot to include this in the change for ld.so to run global ctors for
all modules. The main module itself will have its ctors run last, by
crt0, so mark it as not needing ctors in ld.so.
2024-04-30 22:24:34 -07:00
Justin C. Miller
eb62588b79 [6s] Allow 6s to know about filesystems
Added a j6_proto_vfs_tag/_get_tag pair of messages to the VFS protocol
to allow filesystems to label themselves, and gave 6s the concept of
current fs and current working directory.
2024-04-30 22:23:04 -07:00
Justin C. Miller
29332cbd45 [libc] Update errno and strto* files for compatibility
Most of the strto* functions are only stubbed out, but they're there for
things that link to them but don't call them.
2024-04-30 22:20:41 -07:00
Justin C. Miller
172eb70551 [6s] Break out builtin commands into a list of structs
The 6s builtin commands are now in a separate file, with a list of name,
description, and function pointers.
2024-04-29 01:11:15 -07:00
Justin C. Miller
7322df98f5 [ld.so] Call all image global ctors, not just libc
With the move to dynamic executables, crt0's _start was only ever
calling libc's __init_libc, which only ran libc's init_array list. Now
make crt0 itself (which is statically linked into every executable) call
it's own init_array list and have ld.so call every other image's ctor
lists.
2024-04-29 01:07:18 -07:00
70af5a31cd [6s] Add simple command handling
Super simple little strncmp-based command lookup, adding 'help' and
'version' commands to 6s.
v0.8.0
2024-04-28 19:36:27 -07:00
0ab2f59fe8 [libc] Fix a strncmp bug
The strncmp implementation too eagerly advanced the string pointers,
such that it would compare the next characters after the ones that
didn't match.
2024-04-28 19:35:12 -07:00
ab84cdb790 [edit] Change libedit API
The edit::line API now takes a source object for I/O, qnd allows getting
a single command from the editor.
2024-04-28 17:24:15 -07:00
da9041823b [edit] Add line-editing library, libedit
Now used by the 6s shell to enable backspace, return, etc. No cursor
movement yet or anything complex.
2024-04-27 17:53:18 -07:00
2d7cfc6c59 [scripts] Fix mkj6romfs for real
I overwrote it last time.
2024-04-27 16:20:23 -07:00
cee4fe67fc [tools] Let GDB quit easily if inferior already quit
I had defined hook-quit in the GDB script to kill the inferior. But if
the inferior had already terminated, then trying to quit GDB only
printed an error. Now hook-quit is smarter and checks if the inferior is
running before trying to kill it.
2024-04-27 15:41:05 -07:00
53f90f5a1d [scripts] Fix initrd directory compression
The mkj6romfs.py script always wrote uncompessed directory info to the
initrd image, even if compressed was smaller - but it would write the
metadata as if it had compressed it.
2024-04-27 13:55:05 -07:00
bab2dd5c69 [libc] Change exit status from int to long
Slightly breaking the C standard, but in a way that's unlikely to break
things - allow 64-bit process exit status codes.
2024-04-27 12:59:02 -07:00
3b9efc11d0 [drv.uart] Read everything from the channel in uartnnMake sure to keep reading until the channel is empty so output isn't behindnby a keystroke. 2024-04-26 00:32:06 -07:00
182d3b0a6a [kernel] Add the handle_close syscallnnAdd a generic handle_close syscall and use it in j6::channel when failing to open 2024-04-24 15:48:00 -07:00
Justin C. Miller
ed38e989b1 [srv.logger] Update logger for new channel/SLP
Update srv.logger to build correctly with new channel and service
locator changes.
2024-04-23 23:59:06 -07:00
Justin C. Miller
1bc6f422c5 [kernel] Fix a bug with auto-assigned VMA addresses
When calling vma_map or vma_create_map with an address of 0, the kernel would
return colliding addresses.
2024-04-23 23:47:52 -07:00
Justin C. Miller
4909d15c20 [boot] Fix panic handler not installing
The switch to util::bitset introduced a typo that caused panic handlers
to never load.
2024-04-23 23:46:31 -07:00
Justin C. Miller
e725795a17 [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.
2024-04-23 23:32:28 -07:00
Justin C. Miller
d8a21608c3 [docs] Set up github pages workflow
First pass at a GitHub Actions workflow to deploy the docs site.
2024-03-08 01:12:17 -08:00
Justin C. Miller
396fc131e0 [docs] Add sphinx documentation
Add a first pass at documentation with sphinx.
2024-03-07 21:48:25 -08:00
Justin C. Miller
40130076b2 [uart] Fix UART driver hangs
The UART driver would constantly hang in unpredictable spots. Turns out
it could get into a situation where it was stuck in a loop unable to
read more from the receive channel, and/or write to the serial port
buffer. Now we use a ring buffer to read as much as possible from the
receive channel, write as much as possible to the serial port buffer,
and move on without looping.
2024-03-04 19:48:16 -08:00
Justin C. Miller
9f54927a82 [util] Remove enum_bitfields
The enum_bitfields system never worked quite right, and always had edge cases where name
resolution for the SFINAE would fail. Move everything over to use util::bitset, which can
be constexpr and boils down to inline integer bitops in release mode.

Improved util::bitset itself, moving the array-backed base implementation into a new
util::sized_bitset, and making the single-inttype backed implementation the base case.
Also added a distinction between | or |= (which work with real bit values) and + or +=
(which work with bit indexes).
2024-02-25 23:40:14 -08:00
Justin C. Miller
f7ea46e49e [build] Get release mode optimizations working
Added a release config, and fixed a few spots where optimizations broke things:

- Clang was generating incorrect code for run_ctor_list in libc's init.cpp (it
  ignored a check for the end of the list)
- my rep movsb memcpy implementation used incorrect inline asm constraints, so
  it was returning a pointer to the end of the copied range instead of the start.
  Since this function was just inline asm anyway, I rewrote it in asm by hand in
  a new memutils.s file.
2024-02-25 17:09:04 -08:00
Justin C. Miller
bc46c9a7d5 [libj6] Add log area and severity to j6::syslog()
User code can now set the log area and severity of log messages. This also updates the j6_log
syscall to take these parameters, but removes all calls to it except through j6::syslog().
2024-02-24 13:39:24 -08:00
Justin C. Miller
a1e2c58afc [kernel] Add spam logging to trace mailbox calls
Added a new IPC log category, and logging of mailbox calls in it. Also added
some logs in init's service locator to help track down the bug fixed in the
previous commit.
2024-02-21 19:40:28 -08:00
Justin C. Miller
4e73e933db [libj6] Update how init args are passed and used
Now the init args are a linked list - this also means ld.so can use its
own plus those of the program (eg, SLP and VFS handles). __init_libj6
now adds the head of the list to its global init_args structure, and the
j6_find_init_handle function can be used to find a handle in those args
for a given proto.

This fixes situations like the logger using the wrong mailbox for the
service locator and never finding the uart driver.
2024-02-20 20:51:14 -08:00
Justin C. Miller
9f8e75f680 [ld.so] Properly handle stack alignment in ld.so args
Now when loading a process, init will push all the loader args, align
the stack so that the next pointer will have correct alignment, then
push a pointer to the loader args.

Also:
* _ldso_start will pop all loader args off of the stack before jumping
  to the loaded program's entrypoint, as if it had never run.
* The sentinel arg structures have a size instead of being all zeros, so
  that they can be popped off properly when done.
2024-02-20 19:42:12 -08:00
Justin C. Miller
e17119254b [libc] Add enough stubs to support new LLVM 16 sysroot
time.h and wctype.h had "#error not yet implemented" in them. Now time.h is correct (though the functions
are only declared), and wctype.h exists enough to define its types. Also a dlsym stub was added that just
returns 0.
2024-02-19 16:53:36 -08:00
Justin C. Miller
17261622c6 [scripts] Add missing iced-x86 dependency for print_got.py 2024-02-19 16:20:10 -08:00
Justin C. Miller
dff9e53658 [init] Randomize load address of dynamic ELF modules
Update init to use the new xoroshiro RNG to create a random load address for dynamic executables.
Also pass an address past the end of the loader in the loader_arg to use when loading dynamic
dependencies.
2024-02-19 15:00:42 -08:00
Justin C. Miller
0bf709a339 [util] Add xoroshiro256++
Adding xoroshiro256++ psuedorandom number generator
2024-02-19 14:58:20 -08:00
Justin C. Miller
c245949ea4 [ld.so] Add dynamic library linking
ld.so will now go through all DT_NEEDED entries in the dynamic table and load and relocate
those shared libraries as well. Lazy linking of functions via the PLT is not yet supported,
all PLT entries are looked up ahead of time by ld.so.
2024-02-18 17:39:42 -08:00
Justin C. Miller
c27f8baa31 [libj6] Fix the infinite loop in simple_strlen
The simple_strlen function was incrementing n but not advancing the pointer.
2024-02-18 17:29:43 -08:00
Justin C. Miller
f51f519c31 [kernel] Allow passing 0 to vma_resize to query the current size
Passing a size of 0 in to vma_resize will now not attempt to alter the VMA size, but will
still put the size into the passed-in pointer. Using this allows querying the size of a
VMA without changing it.
2024-02-18 17:27:07 -08:00
Justin C. Miller
55a485ee67 [elf] Add get_section_by_name
Add the get_section_by_name function to iterate sections and compare name strings.
2024-02-18 17:22:23 -08:00