Commit Graph

735 Commits

Author SHA1 Message Date
Justin C. Miller
dccb136c99 [fb] Change to embedding PSF file
Moved old PSF parsing code from kernel, and switched to embedding whole
PSF instead of just glyph data to make font class the same code paths
for both cases.
2021-01-18 13:48:11 -08:00
Justin C. Miller
6af29a7181 [fb] Add default hard-coded font
For the fb driver to have a font before loading from disk is available,
create a hard-coded font as a byte array.

To create this, added a new scripts/psf_to_cpp.py which also refactored
out much of scripts/parse_font.py into a new shared module
scripts/fontpsf.py.
2021-01-18 13:48:11 -08:00
7ca3a19eed [kernel] Fix vm_space extra deletion
vm_space::clear() was freeing pages on process exit even when free was
false, and potentially double-freeing some pages.
2021-01-18 13:48:11 -08:00
7fcb4efab6 [kernel] Improve process init
Move process init from each process needing a main.s with _start to
crt0.s in libc. Also change to a sysv-like initial stack with a
j6-specific array of initialization values after the program arguments.
2021-01-18 13:48:11 -08:00
a8024d3dd3 [kernel] Rename kernel entrypoint
The kernel entrypoint being named _start conflicts with userspace
program entrypoints and makes debugging more difficult. Rename it to
_kernel_start.
2021-01-18 13:48:11 -08:00
8bb78c95a8 [tools] Improve j6stack GDB command
Improve the j6stack command in two ways: first, swap the order of the
arguments, as depth is much more likely to be changed. Second, on any
exception accessing memory in the stack, print the exception and
continue instead of failing the whole command.
2021-01-18 13:48:11 -08:00
19cbf1ca67 [fb] Create fb driver
Create a new framebuffer driver. Also hackily passing frame buffer size
in the list of init handles to all processes and mapping the framebuffer
into all processes. Changed bootloader passing frame buffer as a module
to its own struct.
2021-01-18 13:48:11 -08:00
Justin C. Miller
e70eb5a926 Merge branch 'master' of github.com:justinian/jsix 2021-01-06 23:30:53 -08:00
7bdde2d359 [kernel] Fix console line endings
The console's putc() was looking for CRs and if it saw one, appending an
LF. The output was only writing LFs, though, so instead what's needed is
to look for LFs, and if it sees one, insert a CR first.
2020-12-23 12:36:43 -08:00
Justin C. Miller
3daa07e311 [scripts] Fix demangle error
On my laptop, a few symbol names raise errors as invalid when attempting
to demangle them. This should not stop the rest of the symbol table from
building.
2020-11-10 01:31:23 -08:00
Justin C. Miller
47fab631d0 [boot] Fix compile warning about struct init
The buffer structure was getting initialized with out of order members.
2020-11-10 01:29:38 -08:00
2e3d7b1656 [kernel] Minor cleanups that have been sitting
Removal of an unused header and fixing a lint warning that a define
could be unset.
2020-11-10 01:17:58 -08:00
bf600a7608 [kutil] Add djb hash as 32 bit constexpr hash
This didn't end up getting used, but I'm adding it for later use.
2020-11-10 01:15:37 -08:00
6b00805d04 [kutil] Make vector size type templateable
Previously kutil::vector used size_t as its size type. Since most uses
in the kernel will never approach 4 billion items, default the size type
to uint32_t but make it an optional template argument. This saves 8
bytes per vector, which can be non-trivial with lots of vectors.
2020-10-18 20:50:31 -07:00
82b7082fc5 [kernel] Make koid generation per-type
Previously koids were a single global counter tagged with the type in
the top bits. Now there are per-type counters that each increment
separately.
2020-10-18 20:48:09 -07:00
8bb9e22218 [kernel] Move bind_irq syscall to new system object
In order to implement capabilities on system resources like IRQs so that
they may be restricted to drivers only, add a new 'system' kobject type,
and move the bind_irq functionality from endpoint to system.

Also fix some stack bugs passing the initial handles to a program.
2020-10-18 20:45:06 -07:00
2ad90dcb5c [kernel] Remove old unused crti/crtn
These were never used because clang generates .ctors and .dtors instead
of .init and .fini
2020-10-07 20:18:49 -07:00
97ea77bd27 [kernel] Consolodate koid and close syscalls
A number of object types had _close or _koid syscalls. Moved those to be
generic for kobject.
2020-10-05 21:51:42 -07:00
1904e240cf [kernel] Let endpoints get interrupt notifications
- Add a tag field to all endpoint messages, which doubles as a
  notification field
- Add a endpoint_bind_irq syscall to enable an endpoint to listen for
  interrupt notifications. This mechanism needs to change.
- Add a temporary copy of the serial port code to nulldrv, and let it
  take responsibility for COM2
2020-10-05 01:06:49 -07:00
4ccaa2dfea [boot] Load programs in boot, not kernel
Remove ELF and initrd loading from the kernel. The bootloader now loads
the initial programs, as it does with the kernel. Other files that were
in the initrd are now on the ESP, and non-program files are just passed
as modules.
2020-10-04 17:11:03 -07:00
da38006f44 [kernel] Remove obsolete 'mappings' list from VMAs
The vm_area_shared type of VMA used to track mappings in a separate
array, which doubled information and wasted space. This was no longer
used, and is now removed.
2020-09-27 21:47:35 -07:00
87b0a93d32 [kernel] Have thread call scheduler on blocking
Instead of making every callsite that may make a thread do a blocking
operation also invoke the scheduler, move that logic into thread
implementation - if the thread is blocking and is the current thread,
call schedule().

Related changes in this commit:

- Also make exiting threads and processes call the scheduler when
  blocking.
- Threads start blocked, and get automatically added to the scheduler's
  blocked list.
2020-09-27 21:35:15 -07:00
ff78c951f0 [libc] Implement sbrk to allow malloc() to work
Userspace can now allocte via malloc. This is slightly janky because it
relies on a single static handle in the library code.
2020-09-27 17:31:23 -07:00
2d44e8112b [kernel] Remove 'allowed' page table flag
The allowed flag was janky and easy to get lost when doing page table
manipulation. All allocation goes throug vm_area now, so 'allowed' can
be dropped.
2020-09-27 16:06:25 -07:00
f7f8bb3f45 [kernel] Replace buffer_cache with vm_area_buffers
In order to reduce the amount of tracked state, now use the
vm_area_buffers instead of a VMA with buffer_cache on top.
2020-09-27 15:34:24 -07:00
67ebc58812 [kernel] Allow for more than three syscall args
The rcx register is used by the function call ABI for the 4th argument,
but is also clobbered by SYSCALL to hold the IP. The r10 register is
caller-saved but not part of the ABI, so stash rcx there when crossing
the syscall boundary.
2020-09-26 22:01:21 -07:00
13aee1755e [kernel] Spit out vm_area types
The vm_space allow() functionality was a bit janky; using VMAs for all
regions would be a lot cleaner. To that end, this change:

- Adds a "static array" ctor to kutil::vector for setting the kernel
  address space's VMA list. This way a kernel heap VMA can be created
  without the heap already existing.
- Splits vm_area into different subclasses depending on desired behavior
- Splits out the concept of vm_mapper which maps vm_areas to vm_spaces,
  so that some kinds of VMA can be inherently single-space
- Implements VMA resizing so that userspace can grow allocations.
- Obsolete page_table_indices is removed

Also, the following bugs were fixed:

- kutil::map iterators on empty maps no longer break
- memory::page_count was doing page-align, not page-count

See: Github bug #242
See: [frobozz blog post](https://jsix.dev/posts/frobozz/)

Tags:
2020-09-26 21:47:15 -07:00
0e0975e5f6 [kernel] Add VMA interface
Finished the VMA kobject and added the related syscalls. Processes can
now allocate memory! Other changes in this commit:

- stop using g_frame_allocator and add frame_allocator::get()
- make sure to release all handles in the process dtor
- fix kutil::map::iterator never comparing to end()
2020-09-23 00:29:05 -07:00
d4283731e4 [kernel] Add syscall helpers
Added the syscalls/helpers.h file to templatize common kobject syscall
operations. Also moved most syscall implementations to using
process::current() and thread::current() instead of asking the
scheduler.
2020-09-23 00:22:15 -07:00
6780ab1b67 [abi] Add j6_err_exists
This error was used by code that didn't end up getting used, but it's a
useful error to keep around.
2020-09-23 00:18:06 -07:00
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