summaryrefslogtreecommitdiff
path: root/src/kernel/idt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/idt.c')
-rw-r--r--src/kernel/idt.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/kernel/idt.c b/src/kernel/idt.c
index b8990f2..9b3ba96 100644
--- a/src/kernel/idt.c
+++ b/src/kernel/idt.c
@@ -35,25 +35,23 @@ struct {
//file handles as (drive_number << 8) + file_id_t
-uint32_t sc_open_file(uint32_t drive_number, char *path) { //not static to ensure sysv abi
+uint32_t sc_open_file(uint32_t drive_number, char *path) {
return (drive_number << 8) + drives[drive_number].get_file(drives + drive_number, path);
- //logf(LOG_INFO, "sc_open_file(%d, \"%s\") -> %d", drive_number, path, handle);
}
-void sc_close_file(uint32_t handle) { //not static to ensure sysv abi
+void sc_close_file(uint32_t handle) {
if (!handle)
return;
drives[handle >> 8].free_file(drives + (handle >> 8), handle & 0xff);
}
-uint32_t sc_file_get_size(uint32_t handle) { //not static to ensure sysv abi
- //logf(LOG_INFO, "sc_file_get_size(%d)", handle);
+uint32_t sc_file_get_size(uint32_t handle) {
if (!handle)
return 0;
return drives[handle >> 8].get_file_length(drives + (handle >> 8), handle & 0xff);
}
-uint32_t sc_file_read(uint32_t handle, uint32_t file_offset, uint32_t count, void *buffer) { //not static to ensure sysv abi
+uint32_t sc_file_read(uint32_t handle, uint32_t file_offset, uint32_t count, void *buffer) {
if (!handle)
return 0;
uint32_t len = sc_file_get_size(handle);
@@ -63,14 +61,14 @@ uint32_t sc_file_read(uint32_t handle, uint32_t file_offset, uint32_t count, voi
return count;
}
-uint32_t sc_start_task(uint32_t drive_number, char *path, const char *pass, uint32_t esi_dummy, uint32_t io_task) { //not static to ensure sysv abi
+uint32_t sc_start_task(uint32_t drive_number, char *path, const char *pass, uint32_t io_task) {
switch_to_kernel_cr3();
uint32_t process_id = try_elf_run(drives + drive_number, vma_to_pma(active_task->page_directory, path), pass, io_task);
switch_to_task_cr3();
return process_id;
}
-void *sc_allocate_ram(uint32_t pages) { //not static to ensure sysv abi
+void *sc_allocate_ram(uint32_t pages) {
return pd_user_allocate_anywhere_writable(active_task->page_directory, pages);
}
@@ -83,7 +81,7 @@ enum mi_arg {
};
__attribute__ ((pure))
-uint32_t sc_memory_info(enum mi_arg arg) { //not static to ensure sysv abi
+uint32_t sc_memory_info(enum mi_arg arg) {
switch (arg) {
case MI_KERNEL_MAX:
return max_kernel_pages;
@@ -100,7 +98,7 @@ uint32_t sc_memory_info(enum mi_arg arg) { //not static to ensure sysv abi
}
}
-void sc_wait_for_task(uint32_t handle) { //not static to ensure sysv abi
+void sc_wait_for_task(uint32_t handle) {
add_wait((struct wait){.mode = PROCESS_END, .task = tasks + handle - 1});
}
@@ -108,11 +106,11 @@ uint32_t sc_enumerate_dir(uint32_t drive_number, const char *path, struct direct
return drives[drive_number].enumerate_dir(drives + drive_number, path, buffer, max_entries);
}
-uint32_t sc_count_of_dir(uint32_t drive_number, const char *path) { //not static to ensure sysv abi
+uint32_t sc_count_of_dir(uint32_t drive_number, const char *path) {
return drives[drive_number].n_dir_entries(drives + drive_number, path);
}
-void sc_get_next_window_action(struct window *w, struct window_action *action) { //not static to ensure sysv abi
+void sc_get_next_window_action(struct window *w, struct window_action *action) {
*action = next_window_action(w);
}
@@ -120,25 +118,27 @@ void sc_wait_window_action() {
add_wait((struct wait){.mode = WINDOW_ACTION});
}
-void sc_wait_ipc(uint32_t task_handle) {
- add_wait((struct wait){.mode = IPC_RECEIVE, .task = tasks + task_handle - 1});
+void sc_wait_ipc_sent(uint32_t task_handle) {
+ add_wait((struct wait){.mode = IPC_SENT, .task = tasks + task_handle - 1});
}
void sc_system_log(const char *sz) {
logf(LOG_USER, "[%s] %s", active_task->name, sz);
}
-void sc_wait_any_ipc() {
- add_wait((struct wait){.mode = IPC_RECEIVE_ANY});
+void sc_wait_any_ipc_sent() {
+ add_wait((struct wait){.mode = IPC_SENT_ANY});
}
void sc_wait_ipc_read(uint32_t handle) {
- add_wait((struct wait){.mode = IPC_SEND, .task = tasks + handle - 1});
+ add_wait((struct wait){.mode = IPC_READ, .task = tasks + handle - 1});
}
+//returns a uint32_t to ensure upper twenty-four bits of
+// eax are set to zero - otherwise userland stuff break
__attribute__ ((pure))
-bool sc_is_task_running(uint32_t handle) {
- return tasks[handle - 1].page_directory;
+uint32_t sc_is_task_running(uint32_t handle) {
+ return tasks[handle - 1].page_directory ? 1 : 0;
}
void const *syscall_table[] = {
@@ -162,8 +162,8 @@ void const *syscall_table[] = {
&push_window_paint,
&sc_get_next_window_action,
&sc_wait_window_action,
- &sc_wait_ipc,
- &sc_wait_any_ipc,
+ &sc_wait_ipc_sent,
+ &sc_wait_any_ipc_sent,
&find_unread_ipc,
&sc_wait_ipc_read,
&sc_is_task_running
@@ -240,17 +240,11 @@ void exception_halt(uint32_t eax, uint32_t ebx, uint32_t ecx,
}
//returns true if stack was expanded
-bool pf_check_stack(uint32_t cr2/*, uint32_t edx, uint32_t ecx, uint32_t eax,
- uint32_t code, uint32_t eip*/) {
-//logf(LOG_INFO, "page fault in %s at 0x%h trying to access 0x%h", active_task->name, eip, cr2);
-//logf(LOG_INFO, "stack bottom is 0x%h", active_task->stack_bottom);
-
+bool pf_check_stack(uint32_t cr2) {
if (cr2 >= active_task->stack_bottom - 0x1000) {
- //logf(LOG_INFO, "expanding stack");
switch_to_kernel_cr3();
pd_user_allocate(active_task->page_directory, active_task->stack_bottom -= 4096, 1, true);
switch_to_task_cr3();
- //logf(LOG_INFO, "new stack bottom is 0x%h", active_task->stack_bottom);
return true;
}
else {