Commit Graph

437 Commits

Author SHA1 Message Date
Justin C. Miller
194527e0fe Fix address-marking bugs
* Non-blocksize-aligned regions could fail to be found. Have the
  bootloader load them aligned.
* Consolidating used frame blocks in the bootstrap means these would
  have been impossible to free as address space
* mark_permanent wasn't actually removing blocks from the free list
2019-03-03 01:42:32 -08:00
Justin C. Miller
28cf5562ac Use the address_manager to place allocations 2019-02-28 00:37:00 -08:00
Justin C. Miller
8cdc39fdee Switch page_manager to use frame_allocator.
Removed the frame allocation logic from page_manager and replaced it
with using an instance of frame_allocator instead. This had several
major ripple effects:

- memory_initalize() had to change to support this new world
  - Where to map used blocks is now passed as a flag, since blocks don't
    track their virtual address anymore
  - Instead of the complicated "find N contiguous pages that can be
    mapped in with one page table", we now just have the bootloader give
    us some (currently 64) pages to use both for tables and scratch
    space.
  - frame_allocator initialization was split into two steps to allow
    mapping used blocks before std::move()ing them over
2019-02-28 00:37:00 -08:00
Justin C. Miller
626eec4a31 Frame allocator class added 2019-02-28 00:37:00 -08:00
Justin C. Miller
a9ac30b991 Allow heap_manager to use non-contiguous blocks.
* Heap manager can now manage non-contiguous blocks of memory (currently
  all sized at the max block size only)
* Fix a bug where heap manager would try to buddy-merge max-sized blocks
2019-02-28 00:37:00 -08:00
Justin C. Miller
bbd31929ba Rename memory_manager to heap_manager 2019-02-28 00:37:00 -08:00
Justin C. Miller
341ba5146a Forgot to comment third arg for gdt_write 2019-02-17 23:38:40 -08:00
Justin C. Miller
aca442ee87 First pass at message syscalls 2019-02-07 18:19:22 -08:00
Justin C. Miller
8e85ae5318 Added getpid system call 2019-02-07 17:52:57 -08:00
Justin C. Miller
8c32471e0d Pass CPU state as a pointer
Previously CPU statue was passed on the stack, but the compiler is
allowed to clobber values passed to it on the stack in the SysV x86 ABI.
So now leave the state on the stack but pass a pointer to it into the
ISR functions.
2019-02-07 17:47:42 -08:00
Justin C. Miller
d19cedb12a adding kernel crti/crtn but ctors/dtors not called yet 2019-02-03 18:59:09 -08:00
Justin C. Miller
579f6f64e6 First step of moving bootloader to C++ 2019-02-03 01:38:12 -08:00
Justin C. Miller
38a1197d9e Removing old waf build scripts and vendored libcxx 2019-02-02 21:39:19 -08:00
Justin C. Miller
bc01a37452 Ninja-based buildsystem now building a running kernel! 2019-02-02 21:35:39 -08:00
Justin C. Miller
523d0b3b8c sysroot and cross-compiler based build WIP 2019-01-17 00:51:45 -08:00
Justin C. Miller
d8399e3c07 Fix for page faults under KVM
Under KVM we were hitting what look like out-of-order and/or issues
during initialization when writing to the page tables and then
immediately writing to the mapped memory.  Adding a memory barrier and
an io_wait() in memory_bootstrap.cpp fixed it.
2018-09-21 20:34:26 -07:00
Justin C. Miller
cef0a71bce Use uintptr_t instead of addr_t
They're never actually going to change independently, and it's also
brining in kutil headers more places than they should be.
2018-09-20 09:37:30 -07:00
Justin C. Miller
a9d72b8102 Fixing APIC timer log message 2018-09-18 17:33:11 -07:00
Justin C. Miller
d469482a7f Better spurious interrupt handling 2018-09-16 23:50:54 -07:00
Justin C. Miller
c67c1bd6a2 Give processes multiple quanta before rescheduling 2018-09-16 23:34:42 -07:00
Justin C. Miller
5e6769036c APIC timer calibration
Now the APIC timer is calibrated against the PIT, and the interval for
timer_enable takes a number of microseconds instead of raw ticks and a
divisor.
2018-09-16 18:56:01 -07:00
Justin C. Miller
482b9f50fc Initial process waiting/waking
Processes can now wait on signals/children/time. There is no clock
currently so "time" is just a monotonically increating tick count. Added
a SLEEP syscall to test this waiting/waking.
2018-09-16 12:22:52 -07:00
Justin C. Miller
1308864061 MSR and syscall changes
- Moved MSR code to separate files with an enum class
- Implemented syscall_enable in C++ using new MSR calls
2018-09-15 00:37:49 -07:00
Justin C. Miller
62c559043d Pause syscall and int 0xee interrupt syscalls
The syscall/sysret instructions don't swap stacks. This was bad but
passable until syscalls caused the scheduler to run, and scheduling a
task that paused due to interrupt.

Adding a new (hopefully temporary) syscall interrupt `int 0xee` to allow
me to test syscalls without stack issues before I tackle the
syscall/sysret issue.

Also implemented a basic `pause` syscall that causes the calling process
to become unready. Because nothing can wake a process yet, it never
returns.
2018-09-12 20:59:08 -07:00
Justin C. Miller
5808599005 Getting rid of 'boogity!'.. end of an era.
Since I'm doing a lot of work on task scheduling, 'boogity!' simply
isn't the "we're all good and we're done!" message that it used to be.
2018-09-12 20:51:50 -07:00
Justin C. Miller
fafe582802 Initial priority-based scheduler
- Scheduler now has multiple linked_lists of processes at different
  priorities
- Process structure improvements
- scheduler::tick() and scheduler::schedule() separation
2018-09-11 22:37:00 -07:00
Justin C. Miller
593cda3ee8 Convert page_block to use kutil::linked_list
- Created a new linked_list-based slab allocator
- Simplified memory bootstrap code by using the slab allocator and
  linked_lists
2018-09-11 20:46:48 -07:00
Justin C. Miller
e7a509176d Move makerd to TOML-based manifest
Added the cpptoml library (and license), and moved to using that for
the initrd manifest. It's now possible to specify the `executable`
flag for files, and the kernel correctly only launches new processes
for the initrd files marked `executable`.
2018-09-08 12:54:35 -07:00
Justin C. Miller
3a39d9440a Made syscall ids 64 bits in rax 2018-09-07 10:29:22 -07:00
Justin C. Miller
cabfec3f1e Clearing up kutil/kernel memory code separation 2018-09-07 10:08:47 -07:00
Justin C. Miller
f146a96298 Cleaning up interrupts.s and adding missing IRQs 2018-09-06 09:48:18 -07:00
Justin C. Miller
585abe9a18 Simple ELF program loader
Now any initrd file is treated like a program image and passed to the
loader to load as a process. Very rudimentary elf loading just allocates
pages, copies sections, and sets the ELF's entrypoint as the RIP to
iretq to.
2018-09-06 01:35:56 -07:00
Justin C. Miller
3f264b4490 Add syscall enum, clean up handler debug prints 2018-09-05 22:49:56 -07:00
Justin C. Miller
1758ee4215 Initial ramdisk support
- Create initrd library to support definitions and loading
- Allow tools compiled for the host machine to be built by wscript
- Create makerd tool to build initrd from manifest
- Move screenfont to initrd, so don't load framebuffer initially
2018-09-05 22:45:30 -07:00
Justin C. Miller
dc40c2f6ad Changes from the reorg branch
Add CR4 options: global pages, FXSAVE, PCIDs
Better page manager page-in flags
Remove obsolete rflags-saving in create_process
2018-09-05 22:26:23 -07:00
Justin C. Miller
2fb92e8592 Move AHCI driver into separate drivers/ directory 2018-09-05 22:17:56 -07:00
Justin C. Miller
5d861d243a Loading processes from within their memory space
The scheduler's create_process now sets up the stack to iretq into a
load_process function, which will load the process image into memory
from within the process' own virtual memory space. Currently this
loading is just copying the old 'taskA' function from kernel space.
2018-09-05 10:09:00 -07:00
Justin C. Miller
f1b84ab370 Default to non-user in all kernel pages now
This causes the user tasks to just PF, so we'll need to actually have a
real loader now.
2018-09-04 09:27:57 -07:00
Justin C. Miller
d5b8902d8f Moving the rest (except ACPI tables) to high mem
Also the debug messaging to verify it.
2018-09-03 15:15:19 -07:00
Justin C. Miller
799fbbdd10 _Actually_ move the kernel to the last TiB.
More work on process page tables, including only mapping the last 2 pml4
entries (the highest 1TiB of the address space, ie, kernel space) into a
new table.

Includes the work of actually moving the kernel there, which I had
apparently done in name only previously. Oops.
2018-09-01 14:54:12 -07:00
Justin C. Miller
647801f096 Initial work on swapping page tables per process 2018-08-29 15:49:02 -07:00
Justin C. Miller
cd09c17d71 Commented out CPUID log messages, they're never differnet under qemu 2018-08-27 06:41:09 -07:00
Justin C. Miller
f74f3f03d1 Include prog_if in PCI device class log message 2018-08-27 06:40:30 -07:00
Justin C. Miller
23006b2b43 Fixed number of args in ahci interrupt log call 2018-08-27 06:39:31 -07:00
Justin C. Miller
7f69a6c9b1 Clean up AHCI: volatile, and sata_reset 2018-05-22 00:31:01 -07:00
Justin C. Miller
1726d10554 Unify syscall/interrupt handling of rsp 2018-05-21 22:57:43 -07:00
Justin C. Miller
e187679f93 Add 2 more chars to log names 2018-05-21 09:07:53 -07:00
Justin C. Miller
2597e2002b Get super basic ring3 task switching working
* It looks like UEFI enables SSE, so we need to tell clang -mno-sse for
  now to not use XMM* until we're ready to save them.
* SYSCALL is working from ring3 tasks, calling console printf!
2018-05-21 09:07:53 -07:00
Justin C. Miller
e6f819ed90 Fix non-packed TSS struct 2018-05-21 09:07:53 -07:00
Justin C. Miller
0c8bcb2400 Add get_rip/get_rsp helpers 2018-05-21 09:07:53 -07:00