Commit Graph

755 Commits

Author SHA1 Message Date
41eac2764a [kernel] Fix threads and procs never deleting
A check was added in scheduler::prune() which defers deleting threads
and processes if they're the current ones. However, they were still
getting removed from the block list, so they were being leaked.
2020-09-23 00:15:23 -07:00
113d14c440 [kernel] Get rid of page_manager
page_manager is dead - final uses replaced in vm_space (page_in and
clear). Removed the header and cpp, and other lingering references.
2020-09-20 16:16:23 -07:00
abe523be77 [kernel] Remove page_manager::map_pages
The last use of page_manager::map_pages was during loading of ELF
binaries. Switched to vm_space::allow instead.
2020-09-20 14:06:06 -07:00
1b392a0551 [kernel] Move page mapping into vm_space
vm_space no longer relies on page_manager to map pages during a page
fault. Other changes that come with this commit:

- C++ standard has been changed to C++17
- enum bitfield operators became constexpr
- enum bifrield operators can take a mix of ints and enum arguments
- added page table flags enum instead of relying on ints
- remove page_table::unmap_table and page_table::unmap_pages
2020-09-20 10:52:57 -07:00
deb2fa0a09 [kernel] Use kernel proc space as kernel space
As mentioned in the last commit, with processes owning spaces, there was
a weird extra space in the "kernel" process that owns the kernel
threads. Now we use that space as the global kernel space, and don't
create a separate one.
2020-09-18 01:58:46 -07:00
671a0ce0fb [kernel] Move pml4 create/delete into vm_space
vm_space and page_table continue to take over duties from
page_manager:

- creation and deletion of address spaces / pml4s
- cross-address-space copies for endpoints
- taking over pml4 ownership from process

Also fixed the bug where the wrong process was being set in the cpu
data.

To solve: now the kernel process has its own vm_space which is not
g_kernel_space.
2020-09-18 01:22:49 -07:00
ac67111b83 [kernel] Move the page table cache into page_table
Further chipping away at page_manager: the cache of pages to be used as
page tables gets moved to a static in page_table.
2020-09-17 21:30:05 -07:00
09575370ce [kernel] Remove unecessary functions from page manager
In preparation for removing more from page manager, removed several
unecessary functions and all their callsites.
2020-09-17 01:33:10 -07:00
9aa08a70cf [kernel] Begin replacing page_manager with vm_space
This is the first commit of several reworking the VM system. The main
focus is replacing page_manager's global functionality with objects
representing individual VM spaces. The main changes in this commit were:

- Adding the (as yet unused) vm_area object, which will be the main
  point of control for programs to allocate or share memory.
- Replace the old vm_space with a new one based on state in its page
  tables. They will also be containers for vm_areas.
- vm_space takes over from page_manager as the page fault handler
- Commented out the page walking in memory_bootstrap; I'll probably need
  to recreate this functionality, but it was broken as it was.
- Split out the page_table.h implementations from page_manager.cpp into
  the new page_table.cpp, updated it, and added page_table::iterator as
  well.
2020-09-17 00:48:17 -07:00
ca7f78565d [tools] Add the j6bt command to gdb functions
Added the command j6bt (and renamed popc_stack to j6stack) to make
tracking kernel callstacks across interrupts easier.
2020-09-16 23:58:28 -07:00
dcb4d1823f [kutil] Update map iteration
Add an iterator type to kutil::map, and allow for each loops. Also
unify the compare() signature expected by sorting containers, and fixes
to adding and sorting in kutil::vector.
2020-09-15 00:21:28 -07:00
e8564c755b [kernel] Move vm_space into kernel
The vm_space code should not have been in kutil, moving it to kernel.
2020-09-13 16:11:24 -07:00
9dee5e4138 [kernel] Use map for process handles
Replace linearly-indexed vector of handles with new kutil::map. Also
provide thread::current() and process::current() accessors so that every
syscall doesn't need to include the scheduler to deduce the current
process.
2020-09-13 15:54:47 -07:00
245f260d67 [kutil] Allow for specialization in kutil::map
Restructure kutil::map to allow specialization to alter storage as well
as the public API.
2020-09-13 15:53:28 -07:00
5f27727e52 [tests] Upgrade Catch2 to version 2.13.1 2020-09-13 02:19:57 -07:00
1238608430 [kutil] Add kutil::map hash map
Added the kutil::map collection, an open addressing, robinhood hash map
with backwards shift deletes. Also added hash.h with templated
implementations of the FNV-1a 64 bit hash function, and pulled the log2
function out of the heap_allocator code into the new util.h.
2020-09-12 00:31:38 -07:00
71cd7af17b [kutil] Add sorted insert to kutil::vector
Added a sorted insert to vector, as well as cleaning up and extending
the removal functions.
2020-09-07 16:59:21 -07:00
8490472581 [kutil] Fix failing heap allocator tests
The tests clearly haven't even been built in a while. I've added a
helper script to the project root. Also added a kassert() handler that
will allow tests to catch or fail on asserts.
2020-09-07 16:56:07 -07:00
8534d8d3c5 [kernel] Add endpoint object and related syscalls
The endpoint object adds synchronous IPC. Also added the wait-type of
'object' to threads.
2020-09-07 01:09:56 -07:00
53d260cc6e [kernel] Allow unmapping non-fully-mapped areas
The buffer cache will try to clean up a returned buffer by unmapping it,
but it may have only been committed without ever getting mapped. Allow
for page_out to handle non-fully mapped regions.
2020-09-06 16:31:02 -07:00
53a4682418 [kernel] Fix current thread deletion bug
Defer from calling process::thread_exited() in scheduler::prune() if the
thread in question is the currently-executing thread, so that we don't
blow away the stack we're executing on. The next call to prune will pick
up the exited thread.
2020-09-06 15:01:24 -07:00
42455873ff [kernel] Make stdout channel available to processes
The "fake" stdout channel is now being passed in the new j6_process_init
structure to processes, and nulldrv now uses it to print a message to
the console.
2020-08-30 18:47:14 -07:00
724b846ee4 [kernel] Make channels stream based
Multiple changes regarding channels. Mainly channels are now stream
based and can handle partial reads or writes. Channels now use the
kernel buffers area with the related buffer_cache. Added a fake stdout
stream channel and kernel task to read its contents to the screen in
preparation for handing channels as stdin/stdout to processes.
2020-08-30 18:04:19 -07:00
f27b133089 [kernel] Rename stack_cache to buffer_cache
Renamed and genericized the stack_cache class to manage any address
range area of buffers or memory regions. Removed singleton and created
some globals that map to different address regions (kernel stacks,
kernel buffers).

Tags: vmem virtual memeory
2020-08-30 17:59:13 -07:00
773617cbf3 [libc] Created syscall trampolines in libc
Using syscalls.inc (moved to src/include) generate trampoline functions
for directly calling syscalls with libc functions.
2020-08-23 18:14:45 -07:00
44e29b3c4a [build] Fix dump_cc_run not creating bash scripts
It was the difference between > and >>
2020-08-23 17:43:18 -07:00
95a35cd0bf [libc] Bring libc in-tree
Moving libc from its separate repo into this one, minor resulting build
fixes, and a hacky way to add -I for libc headers in builds.
2020-08-23 17:21:08 -07:00
28b800a497 [kernel] Initialize logger task after symbols init
In case something blows up when initializing kernel tasks, make sure
symbol table init is done beforehand.
2020-08-23 17:18:45 -07:00
838776d7df [kernel] Fix bug in vmem commit
When committing an area of vmem and splitting from a larger block, the
block that is returned was set to the unknown state, and the leading
block was incorrectly set to the desired state.

Also remove extra unused thread ctor.
2020-08-23 17:11:46 -07:00
e19fa377d7 [kernel] Remove old unused process.*
These files are not included in the build, but had not been removed.
2020-08-23 17:10:14 -07:00
d63a30728c [kernel] Add get_caller function
Added a function to get the callsite of the current function invocation.
2020-08-22 16:34:58 -07:00
4819920b4e [kutil] Add unreserve/uncommit to vm_space
Added the functionality for unreseve and uncommit to vm_space. Also
added the documented but not implemented ability to pass a 0 address to
get any address region with the given size.
2020-08-16 17:19:17 -07:00
bbb9aae198 [kernel] Use symbol table in stack traces
Now using the symbol table built by build_symbol_table.py in the kernel
when printing stack traces.
2020-08-09 17:27:51 -07:00
0d94776c46 [build] Remove makest from build script
Removing the outdated reference to makest from the build scripts, which
should have been removed as part of the build_symbol_table.py change.
2020-08-09 17:23:14 -07:00
565a5ee960 [makerd] Fix argc bug
Makerd was improperly checking argc for its usage.
2020-08-06 21:12:36 -07:00
e7f9d8f1d7 [scripts] Add symbol table building script
Create a script that builds a simple-to-read symbol table from the
output of `nm`. Include running that script over the kernel in the
build, and including that output in the initrd.

Tags: callstack debugging
2020-08-06 21:11:19 -07:00
55bc49598e [kernel] Assert all PDs exist in kernel space
The bootloader now creates all PD tables in kernel space, so remove
memory_bootstrap.cpp code that dealt with cases where there was no PD
for a given range, and kassert that all PDs exist.

Also deal with the case where the final PD exists, which never committed
the last address range.
2020-08-06 19:07:51 -07:00
579eaaf4a0 [kernel] Move kernel stacks out of the heap
We were previously allocating kernel stacks as large objects on the
heap. Now keep track of areas of the kernel stack area that are in use,
and allocate them from there. Also required actually implementing
vm_space::commit(). This still needs more work.
2020-08-02 18:15:28 -07:00
b98334db28 [kernel] Don't keep creating new processes for kernel tasks
The scheduler was making new process objects every time it made kernel
task threads. Don't do that.
2020-08-02 18:13:09 -07:00
e1b1b5d357 [kernel] Don't double-construct the scheduler
The scheduler singleton was getting constructed twice, once at static
time and then again in main(). Make the singleton a pointer so we only
construct it once.
2020-08-02 18:11:09 -07:00
cf582c4ce4 [boot] Add PD tables for all kernel PML4 entries
Process PML4s all point their high (kernelspace) entries at the same set
of PDs, but that copying only happens on process creation. New PDs added
to the kernel PML4 won't get shared among other PML4s. This change
instantiates empty PDs for all PML4 entries in the higher half to make
sure this can't happen.
2020-08-02 18:06:41 -07:00
911b4c0b10 [kutil] Fix a bug with order ignoring header size
When moving heap allocation order calculation to use __builtin_clz, we
based that calculation off of the length requested, not the totla length
including the memory header size.
2020-08-02 16:54:06 -07:00
94c1f0d3fc [kutil] Calculate block-size order with clz
Previously we were using a less efficient loop method of finding the
appropriate block size order, now we use __builtin_clz, which should use
the CPU's clz instruction if it's available.
2020-07-30 19:54:25 -07:00
73221dfe34 [kutil] Rename 'size' to 'order' when meaning 2^N
Heap allocator is a buddy allocator that deals with power-of-two block
sizes. Previously it referred to both a number of bytes and an order of
magnitude as a 'size'. Rename functions and variables referring to
orders of magnitude to 'order'.

Tags: pedantry
2020-07-30 19:41:41 -07:00
4ffd4949ca [kernel] Clean up threads' kernel stacks on exit
Add a destructor to threads in order to deallocate their kernel stacks.
2020-07-30 19:32:31 -07:00
3f137805bc [kutil] Tracks allocated size in heap allocator
Add a member that keeps track of allocated size to the heap allocator.
This isn't exposed, but is handy for debugging.
2020-07-30 19:30:53 -07:00
6a00057817 [kernel] Remove process startup_bonus to timeslice
Previously we added startup_bonus to work around a segfault happening
when we preemted a newly created process instead of letting it give up
the CPU. Bug is not longer occuring, though that makes me nervous.
2020-07-30 19:11:51 -07:00
58bc5acb1e [kernel] Add object_signal system call
Add a system call to assert signals on a given object, only within the
range of user-settable signals. Also made object_wait return
immediately if any of the given signals are already set.
2020-07-26 18:03:30 -07:00
d3e9d92466 [kernel] Add channel objects
Add the channel object for sending messages between threads. Currently
no good of passing channels to other threads, but global variables in a
single process work. Currently channels are slow and do double copies,
need to refine more.

Tags: ipc
2020-07-26 17:29:11 -07:00
ae3290c53d [kernel] Add userspace threading
Implement the syscalls necessary for threads to create other threads in
their same process. This involved rearranging a number of syscalls, as
well as implementing object_wait and a basic implementation of a
process' list of handles.
2020-07-26 16:02:38 -07:00