Add PIT Timer, IDT Fixes, and Deferred Kernel Timing Output#14
Add PIT Timer, IDT Fixes, and Deferred Kernel Timing Output#14LordHerdier merged 7 commits intomainfrom
Conversation
Modified: exodoom/docker/scripts/build.sh exodoom/src/kernel.c New: exodoom/src/idt.c exodoom/src/idt.h exodoom/src/isr.s exodoom/src/pic.c exodoom/src/pic.h exodoom/src/pit.c exodoom/src/pit.h
Improved upon idt.c such that all flags will no longer be set to present. Improved upon pit.c such that buf is now null terminated. Function names and calls converted to relative naming scheme
- Configured PIT to 1000hz and implemented kernel_get_ticks_ms(). - Implemented kernel_sleep_ms() w/ busy-wait on tick counter. A test case was added to kernel.c to assess the accuracy of kernel sleep timings. - Additionally, all header files created for the IDT set up were changed to include "#pragma once", rather than ifndef -> define -> endif - Github Desktop seems to HATE when files are not ended with a newline, so I went through and added a newline at the end of all the files I created that didn't have one.
Miscellaneous fixes to multiple files and refactored formatting to align with the rest of the project.
Compile error stemming from kernel.c:74, call to non-existent serial_printf() - now using a series of serial_print(). Shadow Variable Bug in pit.c:13 stemming from a re-declaration of divisor variable, leading to the global divisor variable becoming stale - now accurately manipulating global variable. Unused header "serial.h" within pit.c - now removed
- Drop AOUT_KLUDGE flag from Multiboot header; zero reserved fields so GRUB loads the ELF correctly instead of misinterpreting load addresses - Read %cs at runtime in idt_init() rather than hardcoding 0x08, fixing GP-faults on iret out of interrupt handlers - Fix uint32_t overflow in kernel_get_ticks_ms() (ticks*divisor*1000 wrapped at ~3.6s); use (uint64_t)ticks*1000/frequency instead - Move qemu_exit after the ms-printing loop so monotonic counter is visible in CI output - Add serial_print_u32(); remove dead timer_ticks() export - Fix ICW1_ICW4 comment; remove stale docker-test from .PHONY
|
This looks really good! Thank you for all of your work on the interrupt handling! I'm approving this PR to merge with a couple of notes about bugs that will need to be fixed in the future: Bugs
default_stub just does a bare iret, but CPU exception vectors 8, 10–14, 17, 21, 29, and 30 push an error code onto the stack before entering the handler. A bare iret from those vectors pops the error code as the return %eip, misaligns the stack, and will likely triple-fault. The stub is currently installed on all 256 IDT entries, so any one of those exceptions firing (e.g. a page fault during early init) will cause a hard crash instead of a clean fault. Should at minimum have a separate error_stub that pops the error code before iret, and install it on the appropriate vectors. Minor Issues
I'm going to create a couple Jira tasks to tackle these that we can both work on. For now though, this implementation is good! |
This PR introduces PIT-based timing support and integrates it with the kernel, along with fixes to IDT handling and timing correctness.
Features
Key Fixes
IDT segment selector fix:
Timer overflow fix:
PIT divisor bug:
Design Improvements
Other
Result