Commit graph

471 commits

Author SHA1 Message Date
Andreas Kling bb9766ee17 Tweak default hostname. 2018-11-17 00:23:39 +01:00
Andreas Kling 9d05f6b7a7 Make bash-2.05b build with minimal changes.
This is really neat. :^)
2018-11-17 00:14:07 +01:00
Andreas Kling 2cf477a151 Add fcntl() F_DUPFD which is slightly different from dup2(). 2018-11-16 22:14:40 +01:00
Andreas Kling 6cedb88153 Don't unblock a blocked process when it ignores a signal. 2018-11-16 21:14:25 +01:00
Andreas Kling a788e85c09 Refactor TTY signal generation a bit.
We now respect the VINTR and VQUIT control characters in the termios.
2018-11-16 20:18:58 +01:00
Andreas Kling 4e2c2b9748 Minor TTY tweak. 2018-11-16 18:12:22 +01:00
Andreas Kling d2046e79cf Add a DoubleBuffer thingy to allow TTY read/write to be interleaved.
I feel like this concept might be useful in more places. It's very naive
right now and uses dynamically growing buffers. It should really use static
size buffers and never kmalloc().
2018-11-16 17:57:00 +01:00
Andreas Kling 52d1822c3c Add templated helpers for read/write validation, and one for strings, too. 2018-11-16 16:26:20 +01:00
Andreas Kling 8a286b9244 Improve syscall address validation a bit. 2018-11-16 16:10:59 +01:00
Andreas Kling 084287ca45 Reimplement tcsetattr/tcgetattr as ioctls. 2018-11-16 15:41:48 +01:00
Andreas Kling c99f8af66d Add ioctl() and reimplement tcsetpgrp/tcsetpgrp as ioctls. 2018-11-16 13:13:50 +01:00
Andreas Kling 2529925fe9 Some more renaming:
FileSystem -> FS
SyntheticFileSystem -> SynthFS
ProcFileSystem -> ProcFS
Ext2FileSystem -> Ext2FS
Ext2Inode -> Ext2FSInode
2018-11-15 17:13:10 +01:00
Andreas Kling 8fa2d7104a More VFS cleanup. 2018-11-15 16:04:25 +01:00
Andreas Kling 396a32835b A pass of style/naming cleanup in VFS. 2018-11-15 15:10:30 +01:00
Andreas Kling 457a5df7d5 Rename:
VirtualFileSystem -> VFS
VirtualFileSystem::Node -> Vnode
2018-11-15 14:43:10 +01:00
Andreas Kling c735c56e4c More work on CoreInode. 2018-11-13 23:44:54 +01:00
Andreas Kling 26852a8363 Add metadata to CoreInode. 2018-11-13 13:32:16 +01:00
Andreas Kling 10c470e95f Make page_in_from_vnode 2x faster.
...by adding a new class called Ext2Inode that inherits CoreInode.
The idea is that a vnode will wrap a CoreInode rather than InodeIdentifier.
Each CoreInode subclass can keep whatever caches they like.

Right now, Ext2Inode caches the list of block indices since it can be very
expensive to retrieve.
2018-11-13 13:02:39 +01:00
Andreas Kling 97c799576a Add close-on-exec flag for file descriptors.
I was surprised to find that dup()'ed fds don't share the close-on-exec flag.
That means it has to be stored separately from the FileDescriptor object.
2018-11-13 01:36:31 +01:00
Andreas Kling 19b9401487 Reduce kmalloc() traffic in directory iteration.
Pass the file name in a stack-allocated buffer instead of using an AK::String
when iterating directories. This dramatically reduces the amount of cycles
spent traversing the filesystem.
2018-11-13 00:17:30 +01:00
Andreas Kling 5e8e554f94 Add a braindead 10x speedup to kmalloc().
Skip over entirely full buckets when scanning for a big-enough memory slot.
This means I can postpone writing a better kmalloc() for a while longer! :^)
2018-11-12 15:29:46 +01:00
Andreas Kling dea474dfd5 Make loading /bin/bash ~250x faster.
The ELF loader was doing huge amounts of unnecessary work.
Got rid of the "export symbols" and relocation passes since we don't need them.
They were useful things when bringing up the ELF loading code.

Also added a simple TSC-based Stopwatch RAII thingy to help debug performance issues.
2018-11-12 13:45:15 +01:00
Andreas Kling 1cf20a2fe2 Some minor termios debugging output. 2018-11-12 12:27:28 +01:00
Andreas Kling f1404aa948 Add primitive FIFO and hook it up to sys$pipe().
It's now possible to do this in bash:

cat kernel.map | fgrep List

This is very cool! :^)
2018-11-12 01:28:46 +01:00
Andreas Kling 18e3ddf605 Add a naive /bin/fgrep for testing pipes. 2018-11-11 20:42:41 +01:00
Andreas Kling d5d45d1088 Rage hacking to get bash to run. It finally runs. So cool! :^) 2018-11-11 15:38:07 +01:00
Andreas Kling f394e3486a Stub out a bunch more functions to get closer to that sweet bash build. 2018-11-11 10:38:33 +01:00
Andreas Kling 7cc4caee4f Add ispunct() to LibC + some minor cleanups. 2018-11-11 00:44:04 +01:00
Andreas Kling 3b2f172d48 A bunch of compat work (mostly stubs but some real implementations, too.)
Another pass at getting bash-1.14.7 to build. Not that many symbols remain.
2018-11-11 00:20:53 +01:00
Andreas Kling 6a0a2c9ab4 Some improvements to signals.
- Add sigprocmask() and sigpending().
- Forked children inherit signal dispositions and masks.
- Exec clears signal dispositions and masks.
2018-11-10 23:30:41 +01:00
Andreas Kling c97a5862ce Remove MM::allocate_physical_pages() since it wasn't used.
Everyone was allocating one page at a time with allocate_physical_page().
2018-11-10 22:14:41 +01:00
Andreas Kling 36b3dc6c32 Add /proc/PID/cwd, a symlink to the process's current directory. 2018-11-10 18:16:21 +01:00
Andreas Kling a768c2b919 Rename ProcessInspectionScope to ProcessInspectionHandle.
It might be useful to pass these things around.
2018-11-10 16:50:42 +01:00
Andreas Kling 2ac5e14c08 Merge VGA into VirtualConsole. 2018-11-10 16:26:18 +01:00
Andreas Kling b8264e7d47 Merge Disk namespace into the IDEDiskDevice class. 2018-11-10 15:15:31 +01:00
Andreas Kling cba05ce75e Before sys$write returns, check for pending unmasked signals.
If there is one, put the process into a new BlockedSignal state which makes
the next scheduler iteration dispatch the signal.
2018-11-10 02:43:33 +01:00
Andreas Kling 8605711f4b Make /bin/clear work again.
After I made stdio buffered, we were dropping anything unflushed on exit.
Since /bin/clear just prints out some escape sequences without a newline,
the entire buffer was being discarded.

Also add VirtualConsole::clear() that handles clearing of background VC's.
2018-11-10 00:56:10 +01:00
Andreas Kling 3e3de67f02 Use the VGA start address for fast VirtualConsole scrolling.
Instead of memcpy'ing the entire screen every time we press enter at the
bottom, use the VGA start address register to make a "view" onto the
underlying memory that moves downward as we scroll.

Eventually we run out of memory and have to reset to the start of the
buffer. That's when we memcpy everything. It would be cool if there was
some way to get the hardware to act like a ring buffer with automatic
wrapping here but I don't know how to do that.
2018-11-09 21:18:03 +01:00
Andreas Kling 8a865c11ec Pre-size the ksyms vector for speedier loading.
Also show loading progress on the screen because it looks neat.
2018-11-09 20:40:39 +01:00
Andreas Kling de38e63d3e Run QEMU with the possibility to attach gdb. 2018-11-09 18:35:32 +01:00
Andreas Kling 985074c790 Okay, now *actually* plug the leaks in exec().
I didn't even put the { } properly around everything that would leak.
Let's make sure this works correctly by splitting out the work into a
helper called do_exec().
2018-11-09 18:00:50 +01:00
Andreas Kling e0ca6bb97e Add /proc/vnodes, listing basic info about all open vnodes. 2018-11-09 17:46:55 +01:00
Andreas Kling ebf308d413 Make kernel build with clang.
It's a bit faster than g++ and seems to generate perfectly fine code.
The kernel is also roughly 10% smaller(!)
2018-11-09 12:22:31 +01:00
Andreas Kling 8249c086c3 Get rid of redundant sys$spawn now that we have fork+exec. 2018-11-09 10:22:27 +01:00
Andreas Kling e9cdb6bb9b Fix all current build warnings in LibC. 2018-11-09 10:09:46 +01:00
Andreas Kling 47b7eeda44 Fix all current build warnings in the kernel. 2018-11-09 10:03:21 +01:00
Andreas Kling e71cb1c56b Fix some paging related bugs exposed by the spawn stress test.
- Process::exec() needs to restore the original paging scope when called
  on a non-current process.
- Add missing InterruptDisabler guards around g_processes access.
- Only flush the TLB when modifying the active page tables.
2018-11-09 01:25:31 +01:00
Andreas Kling 7b96218389 Fix VMO leak in Process::exec().
Gotta make sure things get cleaned up before we yield-teleport in exec().
Also VMOs and regions are now viewable through /proc/mm and /proc/regions.
2018-11-08 22:25:29 +01:00
Andreas Kling cd1e7419f0 Teach Process::exec() about the magic of file-backed VMO's.
This is really sweet! :^) The four instances of /bin/sh spawned at
startup now share their read-only text pages.

There are problems and limitations here, and plenty of room for
improvement. But it kinda works.
2018-11-08 21:20:09 +01:00
Andreas Kling 992769c9d4 Make Process::for_each...() functions inline and allocation-free.
AK::Function is very handy, but costs us an 8-byte allocation.
Let's not have kmalloc() calls in the scheduler hot path.
2018-11-08 16:09:05 +01:00
Andreas Kling 3b2dcd5929 Add a VMO pointer to VNode.
This way, if anyone tries to map an already mapped file, we share the VMO.
2018-11-08 15:39:26 +01:00
Andreas Kling 862f108cb5 Refactor the virtual memory object model a bit:
Process now has a number of Regions.
Each Region is backed by a VMObject.
A VMObject can be file-backed or anonymous. These can be shared.
2018-11-08 14:42:16 +01:00
Andreas Kling 3c8064a787 Support basic mmap'ing of a file!
All right, we can now mmap() a file and it gets magically paged in from fs
in response to an NP page fault. This is really cool :^)

I need to refactor this to support sharing of read-only file-backed pages,
but it's cool to just have something working.
2018-11-08 12:59:16 +01:00
Andreas Kling fdbd9f1e27 Start working on memory-mapped files.
First of all, change sys$mmap to take a struct SC_mmap_params since our
sycsall calling convention can't handle more than 3 arguments.

This exposed a bug in Syscall::invoke() needing to use clobber lists.
It was a bit confusing to debug. :^)
2018-11-08 11:40:58 +01:00
Andreas Kling 71a2942a0a Make it run in QEMU.
Looks like the problem was the weirdly-sized floppy image file.
I guess QEMU was inferring the floppy disk geometry from the image size.
2018-11-08 02:03:19 +01:00
Andreas Kling da3857b0c2 Add some simple write buffering to LibC's stdio.
Plumb it all the way to the VirtualConsole. Also fix /bin/cat to write()
the whole chunks we get from read() directly to stdout.
2018-11-08 01:23:47 +01:00
Andreas Kling e287f8ef3a The colonel task already had a halt loop.
Also don't reap() current in the scheduler, just wait until it's not current.
2018-11-08 00:30:35 +01:00
Andreas Kling ac1d12465f Move timer tick handling into Scheduler. 2018-11-08 00:26:04 +01:00
Andreas Kling 27fded7002 Unbreak signal delivery to userspace again.
My my, this code is quite fickle.
2018-11-08 00:08:50 +01:00
Andreas Kling 1dbc340da8 Get rid of the undertaker and have waitpid() be the reaper.
For dead orphans, the scheduler calls reap().
2018-11-07 23:59:49 +01:00
Andreas Kling f792349853 Unbreak sys$sigreturn() after colonel process changes. 2018-11-07 23:21:32 +01:00
Andreas Kling 43f40a3050 Finally unbreak the colonel process and make it the true idle process. 2018-11-07 23:14:56 +01:00
Andreas Kling 440029c9d1 Reduce number of passes in the scheduler by 2. 2018-11-07 22:24:20 +01:00
Andreas Kling 39d2fcbbee Move the scheduler code to its own class.
This is very mechanical.
2018-11-07 22:15:02 +01:00
Andreas Kling 6304c771dd Some refactor and style tweaks. 2018-11-07 21:38:18 +01:00
Andreas Kling 03a8357e84 Implement sending signals to blocked-in-kernel processes.
This is dirty but pretty cool! If we have a pending, unmasked signal for
a process that's blocked inside the kernel, we set up alternate stacks
for that process and unblock it to execute the signal handler.

A slightly different return trampoline is used here: since we need to
get back into the kernel, a dedicated syscall is used (sys$sigreturn.)

This restores the TSS contents of the process to the state it was in
while we were originally blocking in the kernel.

NOTE: There's currently only one "kernel resume TSS" so signal nesting
definitely won't work.
2018-11-07 21:19:47 +01:00
Andreas Kling c8b308910e Signals to processes in userspace now work again.
Ugh, how am I going to dispatch signals to processes in the kernel?
2018-11-07 19:03:44 +01:00
Andreas Kling dd887e158b Add a /proc/PID/regs that shows register state from the process's TSS. 2018-11-07 18:40:29 +01:00
Andreas Kling 678882e020 Rework process states to make a bit more sense.
Processes are either alive (with many substates), dead or forgiven.
A dead process is forgiven when the parent waitpid()s on it.
Dead orphans are also forgiven.

There's a lot of work to be done around this.
2018-11-07 18:34:37 +01:00
Andreas Kling 71bffa9864 Fix whiny build. 2018-11-07 16:38:45 +01:00
Andreas Kling 981a3ae4b3 Make VFS test environment build again. 2018-11-07 12:05:51 +01:00
Andreas Kling 83172e6a4b Rename FileHandle to FileDescriptor. 2018-11-07 11:37:54 +01:00
Andreas Kling e088121b3a Fix sys$sigaction() to return the old action metadata if requested. 2018-11-07 10:48:44 +01:00
Andreas Kling d7a41579e5 Miscellaneous compat work while seeing if GNU coreutils would build. 2018-11-07 10:23:16 +01:00
Andreas Kling a7f1d892a9 Add some basic setgroups(), getgroups() and initgroups().
Also teach /bin/id to print the user's supplemental groups.
2018-11-07 01:38:51 +01:00
Andreas Kling 7c3746592b Add strsignal() and improve sharing signal numbers between LibC and kernel. 2018-11-06 15:45:16 +01:00
Andreas Kling 8d1f8b2518 Add sys_nerr and sys_errlist.
Also keep the canonical errno list in LibC for now. The kernel gets it
from there. This makes building 3rd party code easier.

..also fix broken strchr().
2018-11-06 14:42:28 +01:00
Andreas Kling b2d23f83ab Add umask(). 2018-11-06 13:47:56 +01:00
Andreas Kling 77fe8e8363 Add getppid(). 2018-11-06 13:33:57 +01:00
Andreas Kling 3024167cbd Change syscall naming scheme. 2018-11-06 13:33:54 +01:00
Andreas Kling 153ea704af Add some basic signal support.
It only works for sending a signal to a process that's in userspace code.

We implement reception by synthesizing a PUSHA+PUSHF in the receiving process
(operating on values in the TSS.)
The TSS CS:EIP is then rerouted to the signal handler and a tiny return
trampoline is constructed in a dedicated region in the receiving process.

Also hacked up /bin/kill to be able to send arbitrary signals (kill -N PID)
2018-11-06 10:56:41 +01:00
Andreas Kling 52d502e11f Remove some no longer used files. 2018-11-05 19:20:10 +01:00
Andreas Kling 9f2b9c82bf More work towards getting bash to build.
Implemented some syscalls: dup(), dup2(), getdtablesize().
FileHandle is now a retainable, since that's needed for dup()'ed fd's.
I didn't really test any of this beyond a basic smoke check.
2018-11-05 19:01:59 +01:00
Andreas Kling 82f84bab11 More random compat hacking towards getting bash to build.
I'm now at the build stage where it complains about a bajillion missing
symbols. This is a good place to be!
2018-11-05 18:21:42 +01:00
Andreas Kling e4611248c4 Add geteuid() and getegid().
There's no support for set-uid or set-gid executables yet so these don't
actually do anything. It's just nice to get the boilerplate stuff in.
2018-11-05 15:05:27 +01:00
Andreas Kling 9e62eb4856 Only COW on fault if the physical page has retain_count > 1.
This makes COW pages lazily-but-transparently revert back to read/write.
2018-11-05 14:11:21 +01:00
Andreas Kling 2d045d2a64 Implement COW pages! :^)
sys$fork() now clones all writable regions with per-page COW bits.
The pages are then mapped read-only and we handle a PF by COWing the pages.

This is quite delightful. Obviously there's lots of work to do still,
and it needs better data structures, but the general concept works.
2018-11-05 13:48:07 +01:00
Andreas Kling e85c22fe58 Tidy up the page fault code a bit in preparation. 2018-11-05 10:29:19 +01:00
Andreas Kling 72cdc62155 Replace zones with individually tracked physical pages.
It's just a simple struct { ref_count, paddr }.
This will allow me to implement lazy zeroing and COW pages.
2018-11-05 10:23:00 +01:00
Andreas Kling 422b5403e5 Merge ExecSpace into ELFLoader. 2018-11-04 13:52:53 +01:00
Andreas Kling 8b4b684d6d Move assertion failures out-of-line to reduce binary bloat. 2018-11-04 13:12:58 +01:00
Andreas Kling 7fe4063323 Region::clone() should share the zone if it's read-only.
This avoids copying the .text and .rodata segments in fork().
The next step is copy-on-write support for the writable regions.
2018-11-03 23:20:49 +01:00
Andreas Kling da13c9a264 Map pages in read-only ELF sections as non-writable.
This is so cool! :^) Now you'll crash if you try to write into your
.text or .rodata segments.
2018-11-03 11:36:45 +01:00
Andreas Kling aa6d06b47e Use ELF program headers to load executables smarter.
This turned out way better than the old code. ELF loading is now quite
straightforward, and we don't need the weird concept of subregions anymore.

Next step is to respect the is_writable flag.
2018-11-03 11:29:30 +01:00
Andreas Kling dd060d0fa8 Share code between spawn() and exec() implementations.
Okay, now there's only one ELF loading client in the process launch code.
2018-11-03 10:55:02 +01:00
Andreas Kling c5eec9cbfc Factor out the "non-syscall" parts of sys$execve() into exec().
..to prepare for sharing code with createUserProcess().
2018-11-03 10:20:23 +01:00
Andreas Kling 20fb1fc377 Fix some bugs in execve() and make sh use it for process launching.
Interrupting children of sh now always works with ^C :^)
2018-11-03 02:08:06 +01:00
Andreas Kling 202bdb553c Implemented sys$execve().
It's really crufty, but it basically works!
2018-11-03 01:51:42 +01:00
Andreas Kling b59ce22fc5 Fix dumb-but-hard-to-find bug in paging.
This was the fix:

-process.m_page_directory[0] = m_kernel_page_directory[0];
-process.m_page_directory[1] = m_kernel_page_directory[1];
+process.m_page_directory->entries[0] = m_kernel_page_directory->entries[0];
+process.m_page_directory->entries[1] = m_kernel_page_directory->entries[1];

I spent a good two hours scratching my head, not being able to figure out why
user process page directories felt they had ownership of page tables in the
kernel page directory.

It was because I was copying the entire damn kernel page directory into
the process instead of only sharing the two first PDE's. Dang!
2018-11-03 00:35:57 +01:00
Andreas Kling 8accc92c3c Implement fork()!
This is quite cool! The syscall entry point plumbs the register dump
down to sys$fork(), which uses it to set up the child process's TSS
in order to resume execution right after the int 0x80 fork() call. :^)

This works pretty well, although there is some problem with the kernel
alias mappings used to clone the parent process's regions. If I disable
the MM::release_page_directory() code, there's no problem. Probably there's
a premature freeing of a physical page somehow.
2018-11-02 20:41:58 +01:00
Andreas Kling 10b666f69a Basic ^C interrupt implementation.
For testing, I made cat put itself into a new process group.
This should eventually be done by sh between fork() and exec().
2018-11-02 14:06:48 +01:00
Andreas Kling 621217ffeb Add tcsetpgrp()+tcgetpgrp().
One more step on the path to being able to ^C a runaway process. :^)
2018-11-02 13:14:25 +01:00
Andreas Kling d8f0dd6f3b Start working on sessions and process groups. 2018-11-02 12:56:51 +01:00
Andreas Kling 05565bad58 Make IO helpers inline and use immediate-encoded ports when possible. 2018-11-02 10:14:26 +01:00
Andreas Kling 812e7940e2 Add a simple /proc/cpuinfo that includes some info from CPUID. 2018-11-02 10:14:21 +01:00
Andreas Kling 90ddbca127 Free physical pages allocated for a process's page directory on exit.
Also use a ProcessPagingScope instead of region aliasing to implement
create-process ELF loading.
2018-11-01 23:08:10 +01:00
Andreas Kling c70afd045e Use a freelist for GDT entries.
Tweak the kmalloc space layout a bit. Get the spawn stress test up
and running again.
2018-11-01 16:23:12 +01:00
Andreas Kling 3a901ae36d Way tighter locking in process creation.
We no longer disable interrupts around the whole affair.
Since MM manages per-process data structures, this works quite smoothly now.
Only procfs had to be tweaked with an InterruptDisabler.
2018-11-01 14:41:49 +01:00
Andreas Kling 52607aa086 Allow processes to go into a BeingInspected state (used by procfs.)
This ensures that the process won't get scheduled, and so inspecting
it is safe and easy without blocking interrupts.
2018-11-01 14:21:02 +01:00
Andreas Kling dfaa2b6b02 Convert VirtualConsole to the new coding style.
I'm still playing around with finding a style that I like.
This is starting to feel pleasing to the eye. I guess this is how long
it took me to break free from the habit of my previous Qt/WK coding style.
2018-11-01 14:11:22 +01:00
Andreas Kling fd03776443 Add a /proc/PID/fds text files that lists all the fds open in a process. 2018-11-01 14:00:28 +01:00
Andreas Kling 065f0aee35 Preallocate the maximum number of FileHandle pointers (fds) in every process.
This could even use a more specific data structure since it doesn't need the
grow/shrink capabilities of a vector.
2018-11-01 13:39:28 +01:00
Andreas Kling fce81d376c Move Region and Subregion out of Process and make them free classes. 2018-11-01 13:21:02 +01:00
Andreas Kling 3e532ac7b6 Process now maps regions immediately when they are allocated.
This avoids having to do a separate MM.mapRegionsForTask() pass.

Also, more Task => Process renaming that I apparently hadn't saved yet.
2018-11-01 13:15:46 +01:00
Andreas Kling 4e60551aec Rename Task to Process. 2018-11-01 13:10:12 +01:00
Andreas Kling 8525cdd6a2 Fix crash when process spawn fails. 2018-11-01 12:55:06 +01:00
Andreas Kling c178d7a9e3 Remove some unused MM functions.
These were just Q&D hacks I used while bringing up the paging code.
2018-11-01 12:51:54 +01:00
Andreas Kling 0f70b9105f Implement address validation by querying the task's page directory.
This is way better than walking the region lists. I suppose we could
even let the hardware trigger a page fault and handle that. That'll
be the next step in the evolution here I guess.
2018-11-01 12:45:51 +01:00
Andreas Kling f76fcd1e62 Do a bit less work in every context switch. 2018-11-01 11:57:36 +01:00
Andreas Kling 5891691640 Fix /proc/PID/stack in the new per-process page directory world.
I added an RAII helper called OtherTaskPagingScope. While present,
it switches the kernel over to using another task's page directory.
This is perfect for e.g walking the stack in /proc/PID/stack.
2018-11-01 11:44:21 +01:00
Andreas Kling c45f166c63 More work on per-process page directories. It basically works now!
I spent some time stuck on a problem where processes would clobber each
other's stacks. Took me a moment to figure out that their stacks
were allocated in the sub-4MB linear address range which is shared
between all processes. Oops!
2018-11-01 11:36:25 +01:00
Andreas Kling 1da0a7c949 Give each task its own page directory.
This isn't finished but I'll commit as I go. We need to get to where context
switching only needs to change CR3 and everything's ready to go.

My basic idea is:
- The first 4 kB is off-limits. This catches null dereferences.
- Up to the 4 MB mark is identity-mapped and kernel-only.
- The rest is available to everyone!

While the first 4 MB is only available to the kernel, it's still mapped in
every process, for convenience when entering the kernel.
2018-11-01 09:01:51 +01:00
Andreas Kling a685809e75 Waiters should be notified when a waitee is killed.
Ran into a horrendous bug where VirtualConsole would overrun its buffer
and scribble right into some other object if we were interrupted while
processing a character. Slapped an InterruptDisabler onto onChar for now.

This provokes an interesting question though.. if a process is killed
while its in kernel space, how the heck do we release any locks it held?
I'm sure there are many different solutions to this problem, but I'll
have to think about it.
2018-11-01 01:05:59 +01:00
Andreas Kling 9a086b2d35 Add a kmalloc_eternal() for things that will never be destroyed. 2018-10-31 23:19:15 +01:00
Andreas Kling d980ddc745 Fix busted display of tty names in /proc/summary. 2018-10-31 22:43:49 +01:00
Andreas Kling c7d5ce6b5a Add a /bin/tty command that prints the current tty.
Also fix ttyname() syscall to include "/dev/" in the name.
2018-10-31 21:46:05 +01:00
Andreas Kling 8f6998c902 Add SpinLock to IDE disk access.
This forces serialization of accesses. This driver needs to be redesigned.
2018-10-31 21:33:27 +01:00
Andreas Kling dec5683e9c Snazz up the kprintf() output a bit by giving it its own color. 2018-10-31 20:14:23 +01:00
Andreas Kling 9886b27d9c Add getpwent() family of functions to LibC.
Also add a little /etc/passwd database. There's just me in there.
2018-10-31 19:54:25 +01:00
Andreas Kling 819ce91395 Enough compatibility work to make figlet build and run!
I ran out of steam writing library routines and imported two
BSD-licensed libc routines: sscanf() and getopt().

I will most likely rewrite them sooner or later. For now
I just wanted to see figlet running.
2018-10-31 17:52:59 +01:00
Andreas Kling 9160fd0d47 More LibC portability work while trying to get figlet building. 2018-10-31 10:14:56 +01:00
Andreas Kling 511ed4c4de Snazz up the sh prompt a bit. Add the current tty to it. 2018-10-31 01:21:56 +01:00
Andreas Kling 3218f00099 Implement basic sys$kill() and add a /bin/kill
All it can do right now is send SIGKILL which just murders the target task.
2018-10-31 01:06:57 +01:00
Andreas Kling 7be30a2fa8 Fuck it, add a 4th virtual console. :^) 2018-10-31 00:27:34 +01:00
Andreas Kling 4dec23b487 Add assertion that RTC year is >= 2018. 2018-10-31 00:27:28 +01:00
Andreas Kling 555c10a1f8 Minor cleanup. 2018-10-31 00:26:22 +01:00
Andreas Kling 72e75c52e3 Pass the register dump to syscall_entry() via an argument.
I'm not sure why this was using a global, but it was very racy and made
processes walk over each other when multiple processes were doing
syscalls simultaneously.
2018-10-31 00:23:46 +01:00
Andreas Kling b4f3bc078f Minor VGA cleanup. 2018-10-30 23:49:06 +01:00
Andreas Kling b833aa4162 Fix bug where Console::the() was initialized too late.
Yet another problem due to lack of BSS zeroing in the kernel loader...
2018-10-30 23:02:06 +01:00
Andreas Kling 00c21d1590 Add sys$ttyname_r and ttyname_r() + ttyname().
And print a greeting when sh starts up so we know which TTY we're on.
2018-10-30 22:03:02 +01:00
Andreas Kling 1b81813a66 Fix crashy bug where we'd try to deactivate VC -1 on boot. 2018-10-30 16:16:20 +01:00
Andreas Kling 7a7956a595 Virtual consoles kinda work!
We now make three VirtualConsoles at boot: tty0, tty1, and tty2.
We launch an instance of /bin/sh in each one.
You switch between them with Alt+1/2/3

How very very cool :^)
2018-10-30 15:33:37 +01:00
Andreas Kling 68739dc43e Start working on virtual consoles/TTYs.
This is a mess right now, but I'd rather commit as I go.
2018-10-30 13:59:29 +01:00
Andreas Kling bd2b5327d0 Basic support the backspace key.
This doesn't mean we get any line editing just yet. But the keyboard device
now recognizes the backspace key, and the console device knows what to do
with the backspace characters.
2018-10-30 11:55:58 +01:00
Andreas Kling 29035ffde7 Hang if a task crashes while it's already crashing.. 2018-10-30 00:12:08 +01:00
Andreas Kling 0f20be05a6 Implement sys$getcwd properly.
Also fixed broken strcpy that didn't copy the null terminator.
2018-10-30 00:06:31 +01:00
Andreas Kling 4259ffb080 Improve ps output. 2018-10-29 23:02:07 +01:00
Andreas Kling b1ff62f605 Okay let's just not have this broken locking at all right now.
I think I should just protect access to shared data structures
and eventually do read/write atomicity locks at the inode level.
2018-10-29 22:43:39 +01:00
Andreas Kling e6284a8774 Fix broken SpinLock.
The SpinLock was all backwards and didn't actually work. Fixing it exposed
how wrong most of the locking here is.

I need to come up with a better granularity here.
2018-10-29 22:04:26 +01:00
Andreas Kling bea106fdb2 Fix up VFS::resolveSymbolicLink() to use a base inode instead of a base path.
Also more VFS error plumbing.
2018-10-28 14:25:51 +01:00
Andreas Kling 97726862dd Add basic symlink support.
- sys$readlink + readlink()
- Add a /proc/PID/exe symlink to the process's executable.
- Print symlink contents in ls output.
- Some work on plumbing options into VFS::open().
2018-10-28 14:11:51 +01:00
Andreas Kling 1d4af51250 Add a VFS::absolutePath(InodeIdentifier).
This is pretty inefficient for ext2fs. We walk the entire block group
containing the inode, searching through every directory for an entry
referencing this inode.

It might be a good idea to cache this information somehow. I'm not sure
how often we'll be searching for it.

Obviously there are multiple caching layers missing in the file system.
2018-10-28 12:20:25 +01:00
Andreas Kling 3f050c1972 Add zone dump to /proc/mm.
Sweet, now we can look at all the zones (physical memory) currently in play.

Building the procfs files with ksprintf and rickety buffer presizing feels
pretty shoddy but I'll fix it up eventually.
2018-10-28 10:39:27 +01:00
Andreas Kling c76dc9a047 Add /proc/mm and a /bin/mm utility that just dumps it.
This shows some info about the MM. Right now it's just the zone count
and the number of free physical pages. Lots more can be added.

Also added "exit" to sh so we can nest shells and exit from them.

I also noticed that we were leaking all the physical pages, so fixed that.
2018-10-28 10:28:21 +01:00
Andreas Kling 0a6a2521e8 Add subregions to /proc/PID/vm 2018-10-28 10:03:54 +01:00
Andreas Kling 1d5afbdffc Add sys$set_mmap_name and use it from LibC's malloc.
It's nice to be able to identify mmap's in /proc/PID/vm.
2018-10-28 09:57:22 +01:00
Andreas Kling e904f193c1 Canonicalize the path used by sh.
With a bunch of LibC work to support the feature. LibC now initializes
AK::StringImpl by default. It's now fine to use AK in LibC/Userland! :^)
2018-10-28 09:36:21 +01:00
Andreas Kling 43475f248b Add save/unsave cursor escape sequences.
Also added a little terminal test program called /bin/tst.
2018-10-28 01:44:53 +02:00
Andreas Kling ea6221dd06 Stop committing changes to _fs_contents and generate it in the sync script. 2018-10-28 01:21:15 +02:00
Andreas Kling dd3244137e Add basic support for ANSI color escape sequences. 2018-10-28 00:56:19 +02:00
Andreas Kling 8289a5c93c Implement 'H' and 'J' escape sequences. 2018-10-27 23:42:20 +02:00
Andreas Kling cc7e3519a6 Add a /bin/clear that prints the clear terminal escape sequence.
It doesn't work yet, but it will!
2018-10-27 17:39:08 +02:00
Andreas Kling 8f91a47aeb Add some basic field width support to printf().
Use it to make "ls" output a bit better. Also sys$spawn now fails with EACCES
if the path is not a file that's executable by the current uid/gid.
2018-10-27 16:43:03 +02:00
Andreas Kling de2fb183cc Rename "kernel map" concept to just "ksyms" 2018-10-27 15:02:39 +02:00
Andreas Kling 9a71c7759a Implement loading of linked ELF executables.
This took me a couple hours. :^)

The ELF loading code now allocates a single region for the entire
file and creates virtual memory mappings for the sections as needed.

Very nice!
2018-10-27 14:56:52 +02:00
Andreas Kling 99ee6acd69 Enable A20 line at boot. 2018-10-27 14:09:33 +02:00
Andreas Kling ec07761d0f Implement waitpid() support for getting the waitee's exit code. 2018-10-27 01:24:22 +02:00
Andreas Kling 5cfeeede7c Remove the obsolete "Userspace" stuff. 2018-10-27 00:41:23 +02:00
Andreas Kling 42c88b5f2d Turn off the floppy drive after the boot loader is finished. 2018-10-27 00:40:42 +02:00
Andreas Kling 3db8d7ae1a Use Unix::stat for sys$lstat(). 2018-10-27 00:29:31 +02:00
Andreas Kling 509e5f9952 Add some basic address validation to syscalls.
This is extremely ineffcient, but it doesn't really matter yet.
2018-10-27 00:29:24 +02:00
Andreas Kling 2716a9e2d7 Greatly improve /proc/PID/stack by tracing the ebp frame chain.
I also added a generator cache to FileHandle. This way, multiple
reads to a generated file (i.e in a synthfs) can transparently
handle multiple calls to read() without the contents changing
between calls.

The cache is discarded at EOF (or when the FileHandle is destroyed.)
2018-10-27 00:14:24 +02:00
Andreas Kling c928b06218 Add a very hackish /proc/PID/stack.
It walks the stack and identifies anything that looks like a kernel symbol.
This could be a lot more sophisticated.
2018-10-26 22:33:15 +02:00
Andreas Kling 81627cf7d5 Add a simple /proc/mounts that enumerates the current VFS mounts. 2018-10-26 18:43:25 +02:00
Andreas Kling a447359916 Add a /proc/kmalloc stats file. 2018-10-26 18:28:25 +02:00
Andreas Kling edb81a635c Fix bug where you couldn't "cd .." into the root of a mounted fs. 2018-10-26 18:19:31 +02:00
Andreas Kling a32b3a3ddf Implement /proc/PID/vm.
Refactored SyntheticFileSystem to maintain an arbitrary directory structure.
ProcFileSystem creates a directory entry in /proc for each new process.
2018-10-26 17:44:19 +02:00
Andreas Kling 10347b9ae8 Add ASSERT_INTERRUPTS_DISABLED in Task::fromPID(). 2018-10-26 15:11:29 +02:00
Andreas Kling 63e5583c18 Properly null-terminate the argv list created by sh. 2018-10-26 15:04:20 +02:00
Andreas Kling 1c45b28da6 Add sys$uname() and a /bin/uname utility. 2018-10-26 14:57:26 +02:00
Andreas Kling 384e2f24d4 Add per-task limit for open fd's. Hard-coded at 16 for now. 2018-10-26 14:30:38 +02:00
Andreas Kling 2749e7f1c2 Implement sys$chdir() and teach sh+ls to cd around and browse different dirs. 2018-10-26 14:24:11 +02:00
Andreas Kling 0af9254812 If spawning a task fails after we did a partial ELF load, remap current.
This is an annoying issue. It'd be nice if this code didn't have to worry
about preserving the calling task's mappings.
2018-10-26 12:22:22 +02:00
Andreas Kling 546ddd7de0 Remove logspam in /dev/{full,null,zero} now that they work just fine.
Also don't echo anything to console when putch'ing '\0'.
2018-10-26 11:27:42 +02:00
Andreas Kling 6312c3f253 Fix mixup between /dev/null and /dev/zero device registration. 2018-10-26 11:25:46 +02:00
Andreas Kling df87dda63c Implement argc/argv support for spawned tasks.
Celebrate the new functionality with a simple /bin/cat implementation. :^)
2018-10-26 11:16:56 +02:00
Andreas Kling 53abfa7ea1 Add sys$gethostname and /bin/hostname 2018-10-26 09:54:29 +02:00
Andreas Kling 3faaa3e04a Add /bin/false and /bin/true for fun. :^) 2018-10-25 21:39:37 +02:00
Andreas Kling dc6f57f19c Add gettimeofday() syscall and LibC wrappers gettimeofday() and time().
This only has second accuracy right now, I'll work out subseconds later.
2018-10-25 17:36:18 +02:00
Andreas Kling 5978185242 Add a "sleep" syscall that sleeps for N seconds. 2018-10-25 13:56:03 +02:00
Andreas Kling c6f2890d8e Implement a basic way for read() to block.
FileHandle gets a hasDataAvailableForRead() getter.
If this returns true in sys$read(), the task will block(BlockedRead) + yield.
The fd blocked on is stored in Task::m_fdBlockedOnRead.
The scheduler then looks at the state of that fd during the unblock phase.

This makes "sh" restful. :^)

There's still some problem with the kernel not surviving the colonel task
getting scheduled. I need to figure that out and fix it.
2018-10-25 13:09:56 +02:00
Andreas Kling ba56f4afde If no context switch occurs, add 1 to the timesScheduled() for current.
This seems like more accurate accounting.
2018-10-25 12:45:29 +02:00
Andreas Kling 571dc8234f Make the stage2 init task sleep dreamily when finished.
Something is off about scheduling, I don't think the kernel is handing
out all the available time to processes that are available to run.
2018-10-25 12:40:17 +02:00
Andreas Kling 82bbfa8496 Keyboard should support the space character (jeez!) 2018-10-25 12:10:25 +02:00
Andreas Kling 260b14e505 Implement errno in LibC.
This also meant I had to implement BSS (SHT_NOBITS) sections in ELFLoader.
I also added an strerror() so we can print out what the errors are.
2018-10-25 12:06:50 +02:00
Andreas Kling 434b6a8688 Unify the Task constructors.
There's now Task::create() and Task::createKernelTask().
2018-10-25 11:17:47 +02:00
Andreas Kling dff516f6d0 Remove unused Task states. 2018-10-25 10:51:51 +02:00
Andreas Kling 4bd69d4352 Remove old DatBuffer class.
(also increase the number of sectors loaded by the bootloader in the
since I just noticed we were at the limit. This is not the ideal way
of doing this.)
2018-10-25 10:50:30 +02:00
Andreas Kling de7c54545a Remove age-old IPC stuff that wasn't working anyway.
I'll make a fresh start with IPC code when I get there.
2018-10-25 10:39:39 +02:00
Andreas Kling ce126120d1 Add a few more InterruptDisablers. 2018-10-25 10:33:10 +02:00
Andreas Kling 1c49b34b93 Selectively disable interrupts in MM.
Also added an ASSERT_INTERRUPTS_DISABLED() macro.
2018-10-25 10:15:28 +02:00
Andreas Kling 86a547dcac Add parent PIDs to /proc/summary 2018-10-25 10:15:13 +02:00
Andreas Kling 16f318408d ELFLoader should fail with an error message for unresolved symbols. 2018-10-25 10:02:04 +02:00
Andreas Kling ec1d16b307 Add a "pwd" utility to userland.
It's implemented as a separate process. How cute is that.
Tasks now have a current working directory. Spawned tasks inherit their
parent task's working directory.
Currently everyone just uses "/" as there's no way to chdir().
2018-10-24 14:28:22 +02:00
Andreas Kling 5f36a5f22e Add an lstat() syscall and use it to make "ls" nicer. 2018-10-24 13:19:36 +02:00
Andreas Kling bca4b71bfa Lots of hacking to make a very simple "ls" utility.
I added a dead-simple malloc that only allows allocations < 4096 bytes.
It just forwards the request to mmap() every time.

I also added simplified versions of opendir() and readdir().
2018-10-24 12:50:07 +02:00
Andreas Kling 0c5bbac86e Add an InterruptDisabler helper class and use that for kmalloc.
The naive spinlock was not nearly enough to protect kmalloc from
reentrancy problems.

I don't want to deal with coming up with a fancy lock for kmalloc
right now, so I made an InterruptDisabler thingy instead.
It does CLI and then STI iff interrupts were previously enabled.
2018-10-24 11:07:53 +02:00
Andreas Kling 9a296d63f3 Add simplified mmap() and munmap() syscalls. 2018-10-24 09:48:41 +02:00
Andreas Kling a5caf7ca99 Make the kmalloc global stats variable volatile.
I know I'm praying for cargo here, but this does fix a weird issue
where logging the sum_alloc and sum_free globals wouldn't display
symmetric values all the time.
2018-10-24 01:04:06 +02:00
Andreas Kling 82dae8fc90 Add a kmalloc lock. This definitely reduces flakiness. 2018-10-24 00:51:19 +02:00
Andreas Kling 8e27cf2428 Cleanup. 2018-10-24 00:51:09 +02:00
Andreas Kling b40c851fce Unbreak crashy user process test. 2018-10-24 00:35:07 +02:00
Andreas Kling 3253a23b91 Add a simplified waitpid() so that sh can wait on spawned commands. 2018-10-24 00:20:34 +02:00
Andreas Kling 018da1be11 Generalize the SpinLock and move it to AK.
Add a separate lock to protect the VFS. I think this might be a good idea.
I'm not sure it's a good approach though. I'll fiddle with it as I go along.

It's really fun to figure out all these things on my own.
2018-10-23 23:34:05 +02:00
Andreas Kling e4bfcd2346 Add "times scheduled" field to /proc/summary 2018-10-23 15:59:38 +02:00
Andreas Kling 44045b258c Teach MM to flush individual TLB entries only. 2018-10-23 15:53:11 +02:00
Andreas Kling 3676214a62 Remove remains of the old "panel" task.
...and grow the console by 1 row! :^)
2018-10-23 15:47:03 +02:00
Andreas Kling d90d125dfe Add an undertaker task that is responsible for destroying dead tasks. 2018-10-23 15:43:05 +02:00
Andreas Kling ccd15e0590 Various things:
- putch syscall now directly calls Console::putChar().
- /proc/summary includes some info about kmalloc stats.
- Syscall entry is guarded by a simple spinlock.
- Unmap regions for crashed tasks.
2018-10-23 15:19:02 +02:00
Andreas Kling d133a2845f Add missing TLB flushes. 2018-10-23 13:03:11 +02:00
Andreas Kling 77821da42f Also send console output to port 0xe9 (bochs console.)
This is very handy for debugging.
2018-10-23 13:02:38 +02:00
Andreas Kling 63e253bac9 Generate a basic /proc/summary file with some info about all tasks. 2018-10-23 12:44:46 +02:00
Andreas Kling ed2422d7af Start adding a basic /proc filesystem and a "ps" utility. 2018-10-23 12:04:03 +02:00
Andreas Kling 98f76f0153 Flush the TLB after modifying page tables.
This is a very inefficient naive implementation, but it gets us going.
Mapping tasks in and out of a shared address space now totally works.
2018-10-23 11:03:56 +02:00
Andreas Kling fe237ee215 Lots of hacking:
- Turn Keyboard into a CharacterDevice (85,1) at /dev/keyboard.
- Implement MM::unmapRegionsForTask() and MM::unmapRegion()
- Save SS correctly on interrupt.
- Add a simple Spawn syscall for launching another process.
- Move a bunch of IO syscall debug output behind DEBUG_IO.
- Have ASSERT do a "cli" immediately when failing.
  This makes the output look proper every time.
- Implement a bunch of syscalls in LibC.
- Add a simple shell ("sh"). All it can do now is read a line
  of text from /dev/keyboard and then try launching the specified
  executable by calling spawn().

There are definitely bugs in here, but we're moving on forward.
2018-10-23 10:12:50 +02:00
Andreas Kling b824f15619 Launching an arbitrary ELF executable from disk works! :^)
This is so cool! It's a bit messy now with two Task constructors,
but eventually they should fold into a single constructor somehow.
2018-10-22 15:43:02 +02:00
Andreas Kling befeabd8fe Okay, with some mucking around, there is now a /bin/id and it runs!
It statically links against everything in LibC that it needs.
This will work just fine for a long time to come!
2018-10-22 14:41:54 +02:00
Andreas Kling 63764b3a65 Import very modest Userland. 2018-10-22 14:06:22 +02:00
Andreas Kling 85bcf2ed0f Add getgid() and getpid() syscalls. Prep for LibC. 2018-10-22 13:55:11 +02:00
Andreas Kling bae59609e3 Move kprintf to its own file. It has nothing to do with VGA anymore. 2018-10-22 13:20:35 +02:00
Andreas Kling 702d308e67 Oops, StringImpl's "the empty string" global was not always initialized.
These "oops forgot to initialize" bugs are getting annoying...
2018-10-22 13:10:08 +02:00
Andreas Kling c5e55f4737 Use UD2 instead of CLI;HLT for CRASH().
This way the kernel prints out a nice register dump so we can find
out where we crashed.
2018-10-22 13:07:06 +02:00
Andreas Kling a9ca75c98b Add IRQHandler class that can be subclasses to handle an IRQ.
Also move Keyboard to a class implementation using this pattern.
2018-10-22 12:58:29 +02:00
Andreas Kling 8f941561b4 Add ALWAYS_INLINE macro. 2018-10-22 12:55:59 +02:00
Andreas Kling e4afa2a041 Tweak _test.o to use the putch() syscall.
It's still running in kernel space. Once I make it possible for ELFLoader
to set up a ring 3 task, we'll really be cooking!
2018-10-22 11:53:59 +02:00
Andreas Kling 3a3c57357c Add a sys$exit and make init_stage2 call it when finished. 2018-10-22 11:43:55 +02:00
Andreas Kling 79ffdb7205 A lot of hacking:
- More work on funneling console output through Console.
- init() now breaks off into a separate task ASAP.
- ..this leaves the "colonel" task as a simple hlt idle loop.
- Mask all IRQs on startup (except IRQ2 for slave passthru)
- Fix underallocation bug in Task::allocateRegion().
- Remember how many times each Task has been scheduled.

The panel and scheduling banner are disabled until I get things
working nicely in the (brave) new Console world.
2018-10-22 11:15:16 +02:00
Andreas Kling 09fc9c0698 Make Console::m_rows/m_columns const for now. 2018-10-21 23:48:50 +02:00
Andreas Kling e38f40a83c Add an InlineLinkedList::containsSlow(T*) helper. 2018-10-21 23:48:27 +02:00
Andreas Kling fc88368582 Have Console::write() directly call vga_putch. 2018-10-21 22:44:26 +02:00
Andreas Kling a70bfb87d5 Add a Console device and start refactoring screen output. 2018-10-21 21:59:43 +02:00
Andreas Kling d5ec18027e Protect the first 4 KB of memory.
This makes null pointers crashy, tremendously useful :^)
2018-10-21 21:59:11 +02:00
Andreas Kling dd6706a1a1 Fix null deref in contextSwitch(). 2018-10-21 21:57:43 +02:00
Andreas Kling 2f99ff801e Move post-boot kernel stack pointer to 0x4000. 2018-10-21 21:51:12 +02:00
Andreas Kling 46ff281695 Turn the syscall interrupt into a trap (by switching the gate type.)
This leaves interrupts enabled while we're in the kernel, which is
precisely what we want.

This uncovered a horrendous problem with kernel tasks silently
overflowing their stacks. For now I've simply increased the stack size
but I need a more MMU-y solution for this eventually.
2018-10-19 11:31:18 +02:00
Andreas Kling 97e0d75bcb ELFLoader works inside the kernel!
We load /_hello.o which just prints out a simple message.
It executes inside the kernel itself, so no fancy userspace process
or anything, but this is still so cool!
2018-10-18 15:46:08 +02:00
Andreas Kling 6ab0649ad6 ksprintf() should null-terminate strings. 2018-10-18 15:24:07 +02:00
Andreas Kling c149d2a8f0 Build ELFLoader into Kernel. 2018-10-18 15:03:10 +02:00
Andreas Kling 3649638259 Add Regions concept to Task. 2018-10-18 14:55:20 +02:00
Andreas Kling 5b10846bed Add a simple ELF binary called _test.o to the test fs. 2018-10-18 13:16:30 +02:00