14#define GDT_ACCESSED 0x01
16#define GDT_CONFORMING 0x04
17#define GDT_EXECUTE 0x08
18#define GDT_SYSTEM 0x10
22#define GDT_PRESENT 0x80
135 static ptr_t originalPages[2] = {0, 0};
139 if(!originalPages[0] && !originalPages[1]) {
202 .
limit =
sizeof(gdt) -1,
206 asm(
"lgdt %0"::
"m"(gdtp));
208 asm(
"ltr %%ax"::
"a"(6 << 3));
236 logw(
"sc",
"error adding message queue teardown notify while adding mq %llu to interrupt queues for interrupt %u: $llu",
mq, (
uint64_t)interrupt,
error);
306 asm(
"lidt %0"::
"m"(idtp));
312 asm(
"mov $0xC0000080, %%rcx\n"
315 "wrmsr":::
"rcx",
"rax");
317 write_msr(0xC0000081, 0x001B000800000000);
324 ptr_t iopb_pages[2] = {
334 asm(
"invlpg (%0)"::
"r"(iopb));
335 asm(
"invlpg (%0)"::
"r"(iopb + (4*
KiB)));
354 asm(
"mov %%cr2, %0":
"=r"(fault_address));
380 if((cpu->
rip & 0x0000800000000000) == 0) {
403 size_t user_size =
sizeof(
struct HardwareInterruptUserData);
413 for(
size_t i = 0; i < len; ++i) {
const void * flexarray_getall(flexarray_t array)
flexarray_t new_flexarray(size_t member_size, size_t initial_alloc, allocator_t *alloc)
void flexarray_remove(flexarray_t array, uint64_t idx)
uint64_t flexarray_find(flexarray_t array, void *data)
Will return -1 when not found.
uint64_t flexarray_append(flexarray_t array, void *data)
size_t flexarray_length(flexarray_t array)
#define ALLOCATOR_REGION_KERNEL_HEAP
#define ALLOCATOR_REGION_USER_IOPERM
void * memset(void *dest, int c, size_t size)
#define logw(component, fmt,...)
size_t user_size
Size of the user data.
struct Message::UserData::HardwareInterruptUserData HardwareInterrupt
size_t size
Size of the message, including metadata.
pid_t sender
Sender of the message.
union Message::UserData user_data
size_t user_size
Size of the user data.
enum MessageType type
Type of the message.
uint64_t mq_push(uint64_t mq, struct Message *message)
uint64_t mq_notify_teardown(mq_id_t mq, mq_notifier notifier)
void write_msr(uint32_t msr, uint64_t value)
void panic_cpu(const cpu_state *cpu)
void pic_set_handled(int interrupt)
static cpu_local_data * _cpu0
void set_iopb(struct vm_table *context, ptr_t new_iopb)
static struct idt_entry _idt[256]
static cpu_state * schedule_process(cpu_state *old_cpu)
void _syscall_handler(void)
static void _setup_idt(void)
static void enable_iopb(struct vm_table *context)
static void _set_idt_entry(int index, ptr_t base)
static bool handle_userspace_exception(cpu_state *cpu)
static flexarray_t interrupt_queues[16]
void interrupt_del_queue(uint8_t interrupt, uint64_t mq)
void interrupt_add_queue(uint8_t interrupt, uint64_t mq)
static void interrupt_delall_queue(uint64_t mq)
void sc_handle(cpu_state *cpu)
void scheduler_process_save(cpu_state *cpu)
void schedule_next(cpu_state **cpu, struct vm_table **context)
bool schedule_next_if_needed(cpu_state **cpu, struct vm_table **context)
bool scheduler_handle_pf(ptr_t fault_address, uint64_t error_code)
volatile pid_t scheduler_current_process
void scheduler_kill_current(enum kill_reason reason)
static bool size_t size_t uint64_t * mq
static uint16_t bool uint64_t * error
ptr_t vm_context_alloc_pages(struct vm_table *context, region_t region, size_t num)
struct vm_table * vm_current_context(void)
void vm_context_map(struct vm_table *pml4, ptr_t virtual, ptr_t physical, uint8_t pat)
ptr_t vm_context_get_physical_for_virtual(struct vm_table *context, ptr_t virtual)
void vm_context_activate(struct vm_table *context)
void * vm_alloc(size_t size)
Like malloc but allocates full pages only. 16 byte data overhead.
struct vm_table * VM_KERNEL_CONTEXT
void vm_free(void *ptr)
the matching free() like function for vm_alloc
A paging table, when this is a PML4 it may also be called context.