aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAge
* chore: update dummy task exampleHEADmasterTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* interrupt: add irq_save/restore helpersTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* dev: add x86 PIT (programmable interrupt timer)Tianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* chore: cleanup sched codeTianhao Wang2024-06-11
|
* proc: VecDequeue round-robin schedulerTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* fix asm object build commandsTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* proc: basic task/stack creationTianhao Wang2024-06-11
| | | | Now we can do a simple context swap (without scheduler though)
* chore: cleanupsTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* chore: update 3rd-party licensesTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* chore: format asm codeTianhao Wang2024-06-11
| | | | | | | | | | | | | | mostly fixing identation and tabstop: 0. line width is 80 chars 1. tab is 8 chars wide (tabstop = 8) 2. leading indentation and only leading indentations are __hard_tabs__ 3. non-leading tabs are expanded into spaces 4. instrs are always indented 1 level, and only 1 level 5. the first operand (if any) starts at the next tabstop after the instruction, but the tab inbetween is expanded to spaces (3) Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* proc: basic infra for multithreadingTianhao Wang2024-06-11
| | | | | | | including task and scheduler wrapper, context swap assembly, and some notes... The lifetime of task is tricky, I'll fix it later Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* io: add serial output through port 0x3f8 (qemu)Tianhao Wang2024-06-11
| | | | | not yet wrapped with fmt macros because I want some thing stateless. (i.e. I don't want to pass `&mut self` to write_str...).
* interrupt: set up dummy pagefault handlerTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* mm: use linked-list-allocator as kmallocTianhao Wang2024-06-11
| | | | | | | | | | | | | | | | | | | | | | | | I'll implement my own allocator later. Currently using linked-list allocator [1] to manage the kernel heap (as in kmalloc, not vmalloc). It manages the ID-mapped region (from VA 0xffff_8000_0000_0000). This allocator is initialized to use the _largest_ physical memory block. If the kernel image (text and data) live in this zone then skip the occupied part. Key difference between kmalloc and vmalloc: - kmalloc pretty much manages the physical memory: the allocated address are within the id-mapped region (see above) therefore the allocated memory must also be contigous in physical memory. Such memory MUST NOT page fault. This is prone to fragmentation, so do not use kmalloc to allocate big objects (e.g. bigger than one 4k page). - vmalloc manages kernel heap memory and the mapping is managed by paging. Such memory could trigger pagefault in kernel mode. Note that the kmalloc conflicts with the previous used stack based PMA as they operates on the same VM zone. References: [1] https://github.com/rust-osdev/linked-list-allocator Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* chore: update readmeTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* chore: add page fault test codeTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* chore: add todoTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* proc: add basic task structTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* interrupt: better trampolines for interruptsTianhao Wang2024-06-11
| | | | | | | | | | | 1. define trampolines for both exceptions with error code (automatically pushed to stack) and those without. 2. do not repeat vectors for unused IRQ numbers: we need 48, no need to fill in 256. 3. also pass the pointer to trap frame (on the stack) to the handler code Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* proc: interrupt: define context and trap frameTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* toolchain: replace xbuild with build-stdTianhao Wang2024-06-11
| | | | | | | | | | | for a no_std build with custom target, we need to build the rust compoments including core, alloc and compiler builtins. Previously we do this with the cargo xbuild tool. however it has some bugs with newer toolchains. The official build-std feature is not stable but looks promising! Also we could reduce a lot of build dependencies. References: https://github.com/rust-in-action/code/issues/14 Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* docs: add notes on calling convTianhao Wang2024-06-11
|
* mm: use id mapped vaddr of free_page_stackTianhao Wang2024-06-11
|
* build: include Cargo.lock in vcsTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* pic: replace hardcoded values, add docsTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* docs: add notes on interrupt (vectors) and PICTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* toolchain: bump rust toolchain versionTianhao Wang2024-06-11
| | | | | | | | | | | | | | | | | | | 1. allow unexpected cfgs in lib.rs, in this case "no_global_oom_handling" is cause warnings [1] 2. for large code models the compiler (rust linkers) now put code and data in `.ltext`, `.ldata`, `.lbss`, `.lrodata` instead of the same `.text` , `.data` ... etc. We are adjusting accordingly in the linker script. 3. unsafe assertions identified undefined behaviours, in this case a repr(C) struct was not mared as repr(packed), therefore having an unexpected size. The unsafe assertions was not enabled by default in debug builds so the idt setup code with from_raw_parts_mut() has been working on UB. Glad we can catch this.... related: [1] https://github.com/rust-lang/rust/pull/123501 related: [2] https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html#asserting-unsafe-preconditions
* idt: mm: move idt and vectors also to upper memoryTianhao Wang2024-06-11
|
* chore: add v2p and p2v conversion wrt. id mappingTianhao Wang2024-06-11
| | | | Also renamed a few symbols to avoid confusion.
* fix kernel mapping start addressTianhao Wang2024-06-11
| | | | | should be 0xffff_8020_0000_0000, but I used the id mapping by mistake (0xffff_8000_0000_0000)
* chore: cleanupTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* chore: remove unused depsTianhao Wang2024-06-11
|
* debug: add basic setup for qemu/gdbTianhao Wang2024-06-11
|
* mm: fully map the kernel to high memoryTianhao Wang2024-06-11
|
* mm: provide high memory kernel mapping in asm code.Tianhao Wang2024-06-11
| | | | | | | | | | | | | | | | | we use the first pml4 entry (+one pdp table) to map phy 0~512G to virt 0~512G for init code. This doesn't change. For the kernel to work in higher half memory, we also need to create mapping for it. We take the 256th entry of pml4 entry (hence one additional pdp table). Entry 0~63 are mapped to to the physical memory (with offset 0xffff_8000_0000_0000) Entry 64~127 are not used Entry 128~191 are mapped to the kernel image (text and code) (with offset 0xffff_8020_0000_0000) details in docs/mem_layout.txt
* docs: memory layoutTianhao Wang2024-06-11
|
* chore: cleanup startup codeTianhao Wang2024-06-11
|
* mm: add basic paging infra from x86_64 crateTianhao Wang2024-06-11
| | | | | | | | | | the x86_64 crate is pretty solid and has a permissive license (Apache/MIT), but I want to make this myself in the future to "experience" the unsafe rust further....Also it has too many abstractions, which is justified as a library, but not ideal for a from sctrach toy OS as it hides the lower end. Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* mm: fix Range type and addr roundingTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* mm: explicitly clear unused entries in init tableTianhao Wang2024-06-11
|
* mm: add stack based PMATianhao Wang2024-06-11
| | | | | | | use 8MiB reserved array to manage up to 4GiB of physical memory (4K Pages only) Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* makefile: default to cargo debug buildTianhao Wang2024-06-11
| | | | | | | we should define debug and release targets, but hardcoding in makefile for now. Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* multiboot: docs and cleanupTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* multiboot: parse mmap blocksTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* multiboot: get memory info from MB infoTianhao Wang2024-06-11
| | | | Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* multiboot: basic support for multiboot infoTianhao Wang2024-06-11
| | | | | | | | well, it's not trivial to use bios function because thanks to grub + multiboot, we are already in protected mode when the startup code takes control. Also the MB info is easier to play with than BIOS (or ACPI) Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* keyboard: pad key translation tableTianhao Wang2024-06-11
| | | | | | | | some keys such as the Win key has larger scancode, causing out-of-bound read in the translation table. As a temp fix pad the tables with 0 up to 100 chars. Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
* update attributionsTianhao Wang2024-06-11
|
* fix io blocking bug in kbdctlTianhao Wang2024-06-11
|
* choreTianhao Wang2024-06-11
|