a basic kernel made to x86
- 4 KiB pages (PTE) for each section (.text, .rodata, .data, .bss etc).
- minimal structure
- fill keyboard buffer with scancodes
- spinlock or disable IRQ while writing to the buffer (avoiding race condition)
0xb8000as always- due to VA == PA -> VGA is virtually mapped to
~0xffffffff000b8000
- kernel thread creation
- cooperative (non-preemptive) round-robin scheduling
- context switching in System V ABI–oriented (x86_64)
- wait queues
- counting semaphores
- a dedicated idle thread
- all threads share the same address space and heap
- UNUSED -> slot available
- RUNNABLE -> eligible to run
- RUNNING -> currently executing
- BLOCKED -> sleeping on a wait queue
- ZOMBIE -> finished execution, pending cleanup
- O(1) enqueue
- O(1) next-thread selection
- TODO priority handling
- cooperative only
- every thread yields explicitly via
kthread_yield()
- made by
void context_switch(uint64_t** old_sp, uint64_t* new_sp) - push callee-saved registers
- store current
RSPinto*old_sp - load
new_spintoRSP - restore registers
retinto the new thread context
| top |
|---|
| r15 |
| r14 |
| r13 |
| r12 |
| rbx |
| rbp |
| return -> kthread_entry |
| arg |
| fn |
| bottom |
- SP is aligned to 16 bytes
- (console driver) vga_putc() e vga_popc() -> who actually handles with the screen
- (keyboard driver) consumes the scancodes from the keyboard buffer populated by the ISR
- ldisc_input applies terminal methods (echo, canonical/non-canonical, backspace, etc) and handles with ASCII
- holds the input buffer that will be consumed by stdin (when tty->line_ready == true)
- fd 0
- bufferized -> ring buffer
- free for read(0)
- is connected to TTY -> sleeps and reads the input buffer when it is woken up
- fd 1
- bufferized -> ring buffer
