LF OS
Hobby operating system for amd64 with high ambitions
|
#include "sc.h"
#include "msr.h"
#include "string.h"
#include "mm.h"
#include "cpu.h"
#include "scheduler.h"
#include "pic.h"
#include "panic.h"
#include "vm.h"
#include "mq.h"
#include "flexarray.h"
#include "errno.h"
Go to the source code of this file.
Data Structures | |
struct | idt_entry |
struct | gdt_entry |
struct | table_pointer |
struct | tss |
struct | cpu_local_data |
Macros | |
#define | GDT_ACCESSED 0x01 |
#define | GDT_RW 0x02 |
#define | GDT_CONFORMING 0x04 |
#define | GDT_EXECUTE 0x08 |
#define | GDT_SYSTEM 0x10 |
#define | GDT_RING1 0x20 |
#define | GDT_RING2 0x40 |
#define | GDT_RING3 0x60 |
#define | GDT_PRESENT 0x80 |
Functions | |
struct idt_entry | __attribute__ ((packed)) |
void | sc_handle (cpu_state *cpu) |
void | _syscall_handler (void) |
void | reload_cs (void) |
void | idt_entry_0 (void) |
void | idt_entry_1 (void) |
void | idt_entry_2 (void) |
void | idt_entry_3 (void) |
void | idt_entry_4 (void) |
void | idt_entry_5 (void) |
void | idt_entry_6 (void) |
void | idt_entry_7 (void) |
void | idt_entry_8 (void) |
void | idt_entry_9 (void) |
void | idt_entry_10 (void) |
void | idt_entry_11 (void) |
void | idt_entry_12 (void) |
void | idt_entry_13 (void) |
void | idt_entry_14 (void) |
void | idt_entry_15 (void) |
void | idt_entry_16 (void) |
void | idt_entry_17 (void) |
void | idt_entry_18 (void) |
void | idt_entry_19 (void) |
void | idt_entry_20 (void) |
void | idt_entry_21 (void) |
void | idt_entry_22 (void) |
void | idt_entry_23 (void) |
void | idt_entry_24 (void) |
void | idt_entry_25 (void) |
void | idt_entry_26 (void) |
void | idt_entry_27 (void) |
void | idt_entry_28 (void) |
void | idt_entry_29 (void) |
void | idt_entry_30 (void) |
void | idt_entry_31 (void) |
void | idt_entry_32 (void) |
void | idt_entry_33 (void) |
void | idt_entry_34 (void) |
void | idt_entry_35 (void) |
void | idt_entry_36 (void) |
void | idt_entry_37 (void) |
void | idt_entry_38 (void) |
void | idt_entry_39 (void) |
void | idt_entry_40 (void) |
void | idt_entry_41 (void) |
void | idt_entry_42 (void) |
void | idt_entry_43 (void) |
void | idt_entry_44 (void) |
void | idt_entry_45 (void) |
void | idt_entry_46 (void) |
void | idt_entry_47 (void) |
void | set_iopb (struct vm_table *context, ptr_t new_iopb) |
void | init_gdt (void) |
void | interrupt_del_queue (uint8_t interrupt, uint64_t mq) |
static void | interrupt_delall_queue (uint64_t mq) |
void | interrupt_add_queue (uint8_t interrupt, uint64_t mq) |
static void | _set_idt_entry (int index, ptr_t base) |
static void | _setup_idt (void) |
void | init_sc (void) |
static void | enable_iopb (struct vm_table *context) |
static cpu_state * | schedule_process (cpu_state *old_cpu) |
static bool | handle_userspace_exception (cpu_state *cpu) |
__attribute__ ((force_align_arg_pointer)) | |
Variables | |
typedef | __attribute__ |
uint16_t | baseLow |
uint16_t | selector |
uint8_t | ist |
uint8_t | flags |
uint16_t | baseMid |
uint32_t | baseHigh |
uint32_t | _reserved |
uint16_t | limitLow |
uint8_t | type |
uint8_t | size |
uint16_t | limit |
uint64_t | base |
uint32_t | _reserved0 |
uint64_t | rsp0 |
uint64_t | rsp1 |
uint64_t | rsp2 |
uint64_t | _reserved1 |
uint64_t | ist1 |
uint64_t | ist2 |
uint64_t | ist3 |
uint64_t | ist4 |
uint64_t | ist5 |
uint64_t | ist6 |
uint64_t | ist7 |
uint64_t | _reserved2 |
uint16_t | _reserved3 |
uint16_t | iopb_offset |
static cpu_local_data * | _cpu0 |
static struct idt_entry | _idt [256] |
static flexarray_t | interrupt_queues [16] = { 0 } |
struct idt_entry |
struct gdt_entry |
struct table_pointer |
struct tss |
struct cpu_local_data |
__attribute__ | ( | (force_align_arg_pointer) | ) |
Definition at line 375 of file sc.c.
References flexarray_getall(), flexarray_length(), handle_userspace_exception(), Message::UserData::HardwareInterrupt, Message::UserData::HardwareInterruptUserData::interrupt, cpu_state::interrupt, interrupt_queues, mq_push(), MT_HardwareInterrupt, panic_cpu(), pic_set_handled(), cpu_state::rip, schedule_next_if_needed(), schedule_process(), scheduler_process_save(), Message::sender, Message::size, size, Message::type, Message::user_data, user_size, Message::user_size, vm_alloc(), vm_context_activate(), vm_current_context(), and vm_free().
struct idt_entry __attribute__ | ( | (packed) | ) |
|
static |
Definition at line 241 of file sc.c.
References _idt, base, idt_entry::baseHigh, idt_entry::baseLow, idt_entry::baseMid, idt_entry::flags, idt_entry::ist, and idt_entry::selector.
|
static |
Definition at line 250 of file sc.c.
References _idt, _set_idt_entry(), base, idt_entry_0(), idt_entry_1(), idt_entry_10(), idt_entry_11(), idt_entry_12(), idt_entry_13(), idt_entry_14(), idt_entry_15(), idt_entry_16(), idt_entry_17(), idt_entry_18(), idt_entry_19(), idt_entry_2(), idt_entry_20(), idt_entry_21(), idt_entry_22(), idt_entry_23(), idt_entry_24(), idt_entry_25(), idt_entry_26(), idt_entry_27(), idt_entry_28(), idt_entry_29(), idt_entry_3(), idt_entry_30(), idt_entry_31(), idt_entry_32(), idt_entry_33(), idt_entry_34(), idt_entry_35(), idt_entry_36(), idt_entry_37(), idt_entry_38(), idt_entry_39(), idt_entry_4(), idt_entry_40(), idt_entry_41(), idt_entry_42(), idt_entry_43(), idt_entry_44(), idt_entry_45(), idt_entry_46(), idt_entry_47(), idt_entry_5(), idt_entry_6(), idt_entry_7(), idt_entry_8(), idt_entry_9(), table_pointer::limit, and memset().
|
extern |
|
static |
Definition at line 323 of file sc.c.
References _cpu0, ALLOCATOR_REGION_USER_IOPERM, tss::iopb_offset, KiB, cpu_local_data::tss, vm_context_get_physical_for_virtual(), and vm_context_map().
Definition at line 351 of file sc.c.
References DUMP_CPU, cpu_state::error_code, cpu_state::interrupt, kill_reason_abort, kill_reason_segv, logw, cpu_state::rip, scheduler_current_process, scheduler_handle_pf(), and scheduler_kill_current().
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
|
extern |
void init_gdt | ( | void | ) |
Definition at line 154 of file sc.c.
References _cpu0, tss::_reserved1, tss::_reserved2, tss::_reserved3, ALLOCATOR_REGION_KERNEL_HEAP, base, gdt_entry::baseHigh, gdt_entry::baseLow, gdt_entry::baseMid, GDT_ACCESSED, GDT_EXECUTE, GDT_PRESENT, GDT_RING3, GDT_RW, GDT_SYSTEM, tss::iopb_offset, tss::ist1, cpu_local_data::kernel_stack, KiB, table_pointer::limit, gdt_entry::limitLow, memset(), reload_cs(), tss::rsp0, tss::rsp1, tss::rsp2, gdt_entry::size, cpu_local_data::tss, gdt_entry::type, vm_context_alloc_pages(), and VM_KERNEL_CONTEXT.
void init_sc | ( | void | ) |
Definition at line 309 of file sc.c.
References _cpu0, _setup_idt(), _syscall_handler(), and write_msr().
Definition at line 226 of file sc.c.
References EEXIST, error, flexarray_append(), interrupt_delall_queue(), interrupt_queues, kernel_alloc, logw, mq, mq_notify_teardown(), and new_flexarray().
Definition at line 211 of file sc.c.
References flexarray_find(), flexarray_remove(), interrupt_queues, and mq.
|
static |
Definition at line 220 of file sc.c.
References interrupt_del_queue(), interrupt_queues, and mq.
|
extern |
|
extern |
Definition at line 338 of file sc.c.
References enable_iopb(), schedule_next(), and vm_context_activate().
Definition at line 134 of file sc.c.
References _cpu0, ALLOCATOR_REGION_USER_IOPERM, tss::iopb_offset, KiB, cpu_local_data::tss, vm_context_get_physical_for_virtual(), vm_context_map(), and VM_KERNEL_CONTEXT.
|
inline |
Syscall clone (group 0, call 1)
Clone the process into a new process while optionally sharing all memory (which is commonly called a thread then).
[in] | share_memory | Share memory with original process |
[in] | entry | Entrypoint of the child. Special case: NULL, will continue at the same code location (only valid if share_memory == 1) |
[out] | pid | PID of the new process in the old process, 0 in the new process, -1 denotes an error |
Syscall sleep (group 0, call 2)
Sleep for the given time or yield CPU time to another process, if given time is 0
[in] | nanoseconds | Nanoseconds until first normally scheduling the process again |
Syscall get_pid (group 0, call 3)
Return own or parent PID
[in] | parent | If true, returns parent PID. Own PID otherwise |
[out] | pid | Own or parent PID |
Syscall sbrk (group 1, call 0)
Increment the data segment by inc bytes and return the new end of the data segment.
[in] | inc | Minimum number of bytes to add the data segment |
[out] | data_end | Pointer to the last byte in the data segment |
Syscall framebuffer (group 2, call 0)
Take control of the framebuffer (if still in control by kernel)
[out] | framebuffer | Pointer to the framebuffer |
[out] | width | Width of the framebuffer |
[out] | height | Height of the framebuffer |
[out] | stride | Stride (number of bytes per pixel row) of the framebuffer |
[out] | colorFormat | TBD |
Syscall ioperm (group 2, call 1)
Request access to I/O ports, this is i386 and amd64 only
[in] | from | First port for which access is requested |
[in] | num | Number of ports for which access is requested |
[in] | turn_on | Request (true) or drop (false) access to port |
[out] | error | Error code, zero on success |
Syscall interrupt_notify (group 2, call 2)
Request to be notified of hardware interrupts or cancel notifications
[in] | interrupt | Number of the interrupt to be notified for |
[in] | notify | Add notification (true) or cancel (false) |
[in] | queue | Message queue to send notifications to |
[out] | error | Error code, 0 if success |
Syscall create_mutex (group 3, call 0)
This syscall creates a new mutex
[out] | mutex | pthread_mutex_t value for the new mutex |
[out] | error | error code, zero if success |
Syscall destroy_mutex (group 3, call 1)
destroys the given mutex, returns an error if locked
[in] | mutex | mutex to destroy as pthread_mutex_t |
[out] | error | error code, zero if success |
Syscall lock_mutex (group 3, call 2)
Waits for the mutex to be free and locks it or tries to lock it without blocking
[in] | mutex | mutex to lock as pthread_mutex_t |
[in] | trylock | Try to lock instead of block |
[out] | error | error of this operation, zero if success |
Syscall unlock_mutex (group 3, call 3)
Unlocks a mutex
[in] | mutex | mutex to lock as pthread_mutex_t |
[out] | error | error of this operation, zero if success |
Syscall create_condvar (group 3, call 4)
Create a new condvar processes can wait on
[out] | condvar | pthread_cond_t value for the new condvar |
[out] | error | error code, zero if success |
Syscall destroy_condvar (group 3, call 5)
Destroys a given condvar. Errors if processes are waiting on it
[in] | condvar | pthread_cond_t value to destroy |
[out] | error | error code, zero if success |
Syscall signal_condvar (group 3, call 6)
Signals a condvar to unlock up to amount processes
[in] | condvar | condvar to signal |
[in] | amount | maximum amount of processes to unlock |
[out] | error | error code, zero if success |
Syscall wait_condvar (group 3, call 7)
Makes the calling process blocking wait on the condvar
[in] | condvar | condvar to wait on |
[in] | timeout | Wait timeout, not yet implemented |
[out] | error | error code, zero if success |
Syscall mq_create (group 4, call 0)
create a new message queue
[in] | global_read | Allow other processes to read from this queue |
[in] | global_write | Allow other processes to write to this queue |
[in] | message_limit | Max count of messages to store in the queue |
[in] | data_limit | Max amount of data to store in the queue |
[out] | mq | Unique identifier for the new queue |
[out] | error | error code, zero if success |
Syscall mq_destroy (group 4, call 1)
Destroy a given message queue
[in] | mq | ID of the message queue to destroy |
[out] | error | error code, zero if success |
Syscall mq_poll (group 4, call 2)
Retrieve message from given queue
[in] | queue | Message queue ID, 0 is process queue |
[in] | wait | Wait for a message to be available |
[in] | message | Pointer where to store the message, has to be allocated with enough storage |
[out] | error | Error code, 0 on success |
Syscall mq_send (group 4, call 3)
Send message to given queue
[in] | queue | Message queue ID, 0 is process queue |
[in] | process | Recipient process, to send messages to other processes process queue |
[in] | message | Pointer to message from queue |
[out] | error | Error code, 0 if success |
Syscall service_register (group 4, call 4)
Register as implementation of the given service
[in] | uuid | UUID of the service to register for |
[in] | queue | Message queue ID, 0 is process queue |
[out] | error | Error code, 0 if success |
Syscall service_discover (group 4, call 5)
Send message to implementations of given service
[in] | uuid | UUID of the service to discover |
[in] | queue | Message queue ID, 0 is process queue |
[in] | message | Message to send, UUID will be filled in automatically, has to be of type ServiceDiscover |
[out] | error | Error code, 0 if success |
Syscall read (group 5, call 0)
Read nanoseconds since system start
[out] | nanoseconds | Nanoseconds since system start (or rather, since timer initialization) |
Syscall print (group 255, call 0)
Print a message to the screen at a location defined by the kernel
[in] | str | Message to print |
|
static |
|
static |