Commit Graph

514 Commits

Author SHA1 Message Date
Justin C. Miller
0305830e32 [kernel] fix thread_create handle bug
thread_create was setting the handle it returned to be that of the
parent process, not the thread it created.
2021-01-18 18:24:18 -08:00
Justin C. Miller
9f342dff49 [kernel] fix err_insufficient bug in endpoint
The endpoint syscalls endpoint_recv and endpoint_sendrecv gained new
local stack variables for calling into possibly blocking endpoint
functions, but the len variable was being initialized to 0 instead of
the incoming buffer size.
2021-01-18 18:22:32 -08:00
Justin C. Miller
02766d82eb [kernel] Fix clock::spinwait
spinwait wasn't scaling the target to microseconds
2021-01-18 18:19:18 -08:00
Justin C. Miller
3e372faf5e [kernel] Add fake clock source if there's no HPET
If there's no HPET (or if HPET is left uninitialized for debugging)
default to a fake incrementing counter clock.
2021-01-18 13:49:59 -08:00
Justin C. Miller
786b4ea8c0 [kernel] Don't unmask IOAPIC IRQs immediately
The amount of spurious IRQ activity on real hardware severely slows down
the system (minutes per frame instead of frames per second). There's no
reason to unmask all of them from the get-go before they're set up to be
handled.
2021-01-18 13:49:59 -08:00
Justin C. Miller
20ff0ed30b [kernel] Don't panic on unknown IRQ
On real hardware, spurious IRQs came in before they were set up to be
handled. This should be logged but not fatal.
2021-01-18 13:49:59 -08:00
Justin C. Miller
2a490a1bbc [kernel] Add BGRT ACPI table struct 2021-01-18 13:49:59 -08:00
Justin C. Miller
89391e5be1 [boot] Log address of new table pages
Since it's often needed when debugging between the bootloader and
kernel, log the address of the table pages the bootloader allocated.
2021-01-18 13:49:59 -08:00
Justin C. Miller
c3cb41f78a [boot] Save commented-out mem map dumping code
This is often needed, so I'm commiting it commented out.
2021-01-18 13:49:59 -08:00
Justin C. Miller
c3a0266354 [cpu] Split cpuid validation into separate lib
In order to allow the bootloader to do preliminary CPUID validation
while UEFI is still handling displaying information to the user, split
most of the kernel's CPUID handling into a library to be used by both
kernel and boot.
2021-01-18 13:49:59 -08:00
Justin C. Miller
55a5c97034 [libc] Attempt to speed up memcpy for aligned mem
Copy long-by-long instead of byte-by-byte if both pointers are similarly
aligned.
2021-01-18 13:49:59 -08:00
Justin C. Miller
dcb8a3f3fb [fb] Use double-buffering in fb driver
Allocate and use a back buffer, so that draws to the screen are always a
single memcpy()
2021-01-18 13:49:59 -08:00
Justin C. Miller
3dffe564af [kernel] Set framebuffer to write-combining
Several changes were needed to make this work:

- Update the page_table::flags to understand memory caching types
- Set up the PAT MSR to add the WC option
- Make page-offset area mapped as WT
- Add all the MTRR and PAT MSRs, and log the MTRRs for verification
- Add a vm_area flag for write_combining
2021-01-18 13:49:59 -08:00
Justin C. Miller
1820972fb7 [kenrel] Ensure page tables are zeroed before use
I forgot to zero out pages used for page tables, which didn't come back
to bite me until testing on physical hardware..
2021-01-18 13:49:59 -08:00
Justin C. Miller
67534faa78 [boot] Add scanline size to fb boot message
Scanline size can differ from horizontal resolution in some
framebuffers. This isn't currently handled, but at least log it so
it's visible if this lack of handling is a potential error.
2021-01-18 13:49:59 -08:00
Justin C. Miller
12605843ce [boot] Don't use custom UEFI memory types
The UEFI spec specifically calls out memory types with the high bit set
as being available for OS loaders' custom use. However, it seems many
UEFI firmware implementations don't handle this well. (Virtualbox, and
the firmware on my Intel NUC and Dell XPS laptop to name a few.)

So sadly since we can't rely on this feature of UEFI in all cases, we
can't use it at all. Instead, treat _all_ memory tagged as EfiLoaderData
as possibly containing data that's been passed to the OS by the
bootloader and don't free it yet.

This will need to be followed up with a change that copies anything we
need to save and frees this memory.

See: https://github.com/kiznit/rainbow-os/blob/master/boot/machine/efi/README.md
2021-01-18 13:49:59 -08:00
Justin C. Miller
8dbdebff3f [boot] Don't use custom UEFI memory types
The UEFI spec specifically calls out memory types with the high bit set
as being available for OS loaders' custom use. However, it seems many
UEFI firmware implementations don't handle this well. (Virtualbox, and
the firmware on my Intel NUC and Dell XPS laptop to name a few.)

So sadly since we can't rely on this feature of UEFI in all cases, we
can't use it at all. Instead, treat _all_ memory tagged as EfiLoaderData
as possibly containing data that's been passed to the OS by the
bootloader and don't free it yet.

This will need to be followed up with a change that copies anything we
need to save and frees this memory.

See: https://github.com/kiznit/rainbow-os/blob/master/boot/machine/efi/README.md
2021-01-18 13:49:10 -08:00
Justin C. Miller
61845b8761 [boot] Add framebuffer progress bar
After exiting UEFI, the bootloader had no way of displaying status to
the user. Now it will display a series of small boxes as a progress bar
along the bottom of the screen if a framebuffer exists. Errors or
warnings during a step will cause that step's box to turn red or orange,
and display bars above it to signal the error code.

This caused the simplification of the error handling system (which was
mostly just calling status_line::fail) and added different types of
status objects.
2021-01-18 13:49:10 -08:00
Justin C. Miller
1ba44c99d1 [boot] List the detected framebuffer in boot log
List information about the detected framebuffer device (or lack thereof)
in the bootloader log messages.
2021-01-18 13:49:10 -08:00
Justin C. Miller
6716ab251f [kernel] Clean up process::exit
Make process::exit slightly more resilient to being called again.
2021-01-18 13:49:10 -08:00
Justin C. Miller
e3b9c0140a [fb] Simplify scrollback line counting
Using a start and a count was redundant when we know how many lines are
in the buffer already.
2021-01-18 13:49:10 -08:00
Justin C. Miller
d1c0723b44 [kernel] Fix memory clobbering from endpoint
The endpoint receive syscalls can block and then write to userspace
memory. Since the current address space may be different after blocking,
make sure to only actually write to the user memory after returning to
the syscall handler - pass values that are on the syscall handler stack
deeper into the kernel.
2021-01-18 13:49:10 -08:00
Justin C. Miller
14ed6af433 [kernel] Give processes and threads self handles
It was not consistent how processes got handles to themselves or their
threads, ending up with double entries. Now make such handles automatic
and expose them with new self_handle() methods.
2021-01-18 13:49:10 -08:00
Justin C. Miller
1325706c7c [kutil] Remove uint64_t hash_node specialization
Using a hash of zero to signal an empty slot doesn't play nice with the
hash_node specialization that uses the key for the hash, when 0 is a
common key.

I thought it would be ok, that it'd just be something to remember. But
then I used 0 as a key anyway, so clearly it was a bad idea.
2021-01-18 13:49:10 -08:00
Justin C. Miller
f5ab00a055 [boot] Reduce loader spam
Now that the ELF loader is known to be working correctly, remove its
extra print statements about section loading to keep the bootloader
output to one screen.
2021-01-18 13:49:10 -08:00
Justin C. Miller
dcdfc30c45 [build] Remove fake terminal.elf
A fake terminal.elf (copy of nulldrv.elf) was added to test the loader.
Now that there actually are multiple programs to load, remove the fake
one.
2021-01-18 13:49:10 -08:00
Justin C. Miller
a0d165c79b [scripts] Ignore demangle errors building sym table
For some reason, cxxfilt fails to demangle some names on some systems.
Instead of failing the build process, just skip those symbols.
2021-01-18 13:49:10 -08:00
Justin C. Miller
7b23310d8b [scripts] Allow qemu.sh to not remove VGA device
Added --vga option to qemu.sh to stop it from passing "-vga none" to
qemu. This allows the console version to act like it has a video device.
2021-01-18 13:48:11 -08:00
Justin C. Miller
e477dea5c7 [fb] Output klog to fb if video exists
If there's no video, do as we did before, otherwise route logs to the fb
driver instead. (Need to clean this up to just have a log consumer
general interface?) Also added a "scrollback" class to fb driver and
updated the system_get_log syscall.
2021-01-18 13:48:11 -08:00
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