Remove redundant syscalls
This commit is contained in:
parent
5717209148
commit
7cde3f4eca
@ -193,20 +193,11 @@ void isr_handler(registers_t* r) {
|
||||
break;
|
||||
case 80:
|
||||
switch (r->eax) {
|
||||
case SYSCALL_CREATEPROC_NEW_ADDR_SPACE:
|
||||
tasking_createTask((void*)r->ebx);
|
||||
break;
|
||||
case SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE:
|
||||
tasking_createTaskCr3KmodeParam((void*)r->ebx,(void*)r->ecx,0,0,0,0,0);
|
||||
break;
|
||||
case SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE_W_ARGS:
|
||||
tasking_createTaskCr3KmodeParam((void*)r->ebx,(void*)r->ecx,0,1,r->edx,1,r->esi);
|
||||
case SYSCALL_CREATEPROC:
|
||||
tasking_createTaskCr3KmodeParam((void*)r->ebx,(void*)r->ecx,0,r->edx,r->esi,r->edx,r->edi);
|
||||
break;
|
||||
case SYSCALL_YIELD:
|
||||
tasking_yield(r);
|
||||
break;
|
||||
case SYSCALL_YIELD_TO_PID:
|
||||
tasking_yieldToPID(r->ebx);
|
||||
tasking_yield(r->ebx);
|
||||
break;
|
||||
case SYSCALL_BLOCK:
|
||||
tasking_block(r->ebx);
|
||||
@ -224,11 +215,11 @@ void isr_handler(registers_t* r) {
|
||||
r->ebx=(pid_t)getPID();
|
||||
break;
|
||||
case SYSCALL_ALLOC_MEM:
|
||||
serial_printf("PID %d is allocating %d pages\n",getPID(),r->ebx);
|
||||
r->ebx=(uint32_t)alloc_pages(r->ebx);
|
||||
break;
|
||||
case SYSCALL_ALLOC_MEM_VIRT:
|
||||
alloc_pages_virt(r->ebx,(void*)r->ecx);
|
||||
if ((void*)r->ecx==NULL) {
|
||||
r->ebx=(uint32_t)alloc_pages(r->ebx);
|
||||
} else {
|
||||
alloc_pages_virt(r->ebx,(void*)r->ecx);
|
||||
}
|
||||
break;
|
||||
case SYSCALL_PRIV_MAP_PAGES:
|
||||
if (!currentTask->priv) {
|
||||
@ -244,10 +235,11 @@ void isr_handler(registers_t* r) {
|
||||
break;
|
||||
case SYSCALL_ADDR_SPACES_COPY_DATA:
|
||||
serial_printf("address_spaces_copy_data(0x%x,0x%x,0x%x,0x%x);\n",(void*)r->ebx,(void*)r->ecx,r->edx,(void*)r->esi);
|
||||
address_spaces_copy_data((void*)r->ebx,(void*)r->ecx,r->edx,(void*)r->esi);
|
||||
break;
|
||||
case SYSCALL_ADDR_SPACES_PUT_DATA:
|
||||
r->ebx=(uint32_t)address_spaces_put_data((void*)r->ebx,(void*)r->ecx,r->edx);
|
||||
if ((void*)r->esi!=NULL) {
|
||||
address_spaces_copy_data((void*)r->ebx,(void*)r->ecx,r->edx,(void*)r->esi);
|
||||
} else {
|
||||
r->ebx=(uint32_t)address_spaces_put_data((void*)r->ebx,(void*)r->ecx,r->edx);
|
||||
}
|
||||
break;
|
||||
case SYSCALL_SERIAL_PRINT:
|
||||
serial_write_string((char*)r->ebx);
|
||||
|
@ -171,44 +171,47 @@ void switch_to_task(Task* task) {
|
||||
switch_to_task_asm(task);
|
||||
}
|
||||
|
||||
void tasking_yield() {
|
||||
serial_printf("Yield called from pid %d\n",currentTask->pid);
|
||||
if (!readyToRunHead) {
|
||||
if (currentTask->state!=TASK_RUNNING) {
|
||||
//This indicates either all tasks are bloked or the os has shutdown. Check which one it is
|
||||
if (running_blocked_tasks==0) {
|
||||
serial_printf("All tasks exited, halting\n");
|
||||
halt(); //never returns, so we dont need an else
|
||||
void tasking_yield(pid_t pid) {
|
||||
if (pid==0) {
|
||||
if (!readyToRunHead) {
|
||||
if (currentTask->state!=TASK_RUNNING) {
|
||||
//This indicates either all tasks are bloked or the os has shutdown. Check which one it is
|
||||
if (running_blocked_tasks==0) {
|
||||
serial_printf("All tasks exited, halting\n");
|
||||
halt(); //never returns, so we dont need an else
|
||||
}
|
||||
serial_printf("All tasks blocked, waiting for interrupt to unblock task\n");
|
||||
// All tasks blocked
|
||||
// Stop running the current task by setting currentTask to null, though put it in a local variable to keep track of it.
|
||||
Task* task=currentTask;
|
||||
currentTask=NULL;
|
||||
// Wait for an IRQ whose handler unblocks a task
|
||||
do {
|
||||
asm volatile("sti");
|
||||
asm volatile("hlt");
|
||||
asm volatile("cli");
|
||||
} while (readyToRunHead==NULL);
|
||||
currentTask=task;
|
||||
} else {
|
||||
serial_printf("Yield failed, no other ready tasks\n");
|
||||
return;
|
||||
}
|
||||
serial_printf("All tasks blocked, waiting for interrupt to unblock task\n");
|
||||
// All tasks blocked
|
||||
// Stop running the current task by setting currentTask to null, though put it in a local variable to keep track of it.
|
||||
Task* task=currentTask;
|
||||
currentTask=NULL;
|
||||
// Wait for an IRQ whose handler unblocks a task
|
||||
do {
|
||||
asm volatile("sti");
|
||||
asm volatile("hlt");
|
||||
asm volatile("cli");
|
||||
} while (readyToRunHead==NULL);
|
||||
currentTask=task;
|
||||
} else {
|
||||
serial_printf("Yield failed, no other ready tasks\n");
|
||||
}
|
||||
switch_to_task(readyToRunHead);
|
||||
} else {
|
||||
serial_printf("Attempting to yield to PID %d",pid);
|
||||
Task* task=tasks[pid];
|
||||
if (!task) {
|
||||
serial_printf("PID %d does not exist.\n",pid);
|
||||
return;
|
||||
}
|
||||
if (task->state!=TASK_READY) {
|
||||
serial_printf("PID %d is blocked");
|
||||
return;
|
||||
}
|
||||
switch_to_task(task);
|
||||
}
|
||||
switch_to_task(readyToRunHead);
|
||||
}
|
||||
|
||||
void tasking_yieldToPID(uint32_t pid) {
|
||||
Task* task=tasks[pid];
|
||||
if (!task) {
|
||||
serial_printf("PID %d does not exist.\n",pid);
|
||||
return;
|
||||
}
|
||||
switch_to_task(task);
|
||||
}
|
||||
|
||||
void tasking_exit(uint8_t code) {
|
||||
serial_printf("PID %d is exiting with code %d.\n",currentTask->pid,code);
|
||||
currentTask->state=TASK_EXITED;
|
||||
@ -221,7 +224,7 @@ void tasking_exit(uint8_t code) {
|
||||
exitedTasksTail=currentTask;
|
||||
}
|
||||
running_blocked_tasks--;
|
||||
tasking_yield();
|
||||
tasking_yield(0);
|
||||
}
|
||||
|
||||
uint32_t getPID() {
|
||||
@ -235,11 +238,11 @@ void tasking_block(TaskState newstate) {
|
||||
}
|
||||
serial_printf("Blocking PID %d with state %d\n",currentTask->pid,currentTask->state);
|
||||
currentTask->state = newstate;
|
||||
tasking_yield();
|
||||
tasking_yield(0);
|
||||
}
|
||||
|
||||
void tasking_unblock(pid_t pid) {
|
||||
serial_printf("Unblocking PID %d (task pid %d)\n",pid,tasks[pid]->pid);
|
||||
serial_printf("Unblocking PID %d\n",pid);
|
||||
tasks[pid]->state=TASK_READY;
|
||||
if(readyToRunHead) {
|
||||
readyToRunTail->next=tasks[pid];
|
||||
|
@ -6,8 +6,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
void tasking_init();
|
||||
void tasking_yield();
|
||||
void tasking_yieldToPID();
|
||||
void tasking_yield(pid_t pid); //set pid to 0 for normal scheduling
|
||||
Task* tasking_createTask(void* eip);
|
||||
Task* tasking_createTaskCr3KmodeParam(void* eip,void* cr3,char kmode,char param1_exists,uint32_t param1_arg,char param2_exists,uint32_t param2_arg);
|
||||
char isPrivleged(uint32_t pid);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/syscalls.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define QUAUX(X) #X
|
||||
#define QU(X) QUAUX(X)
|
||||
@ -9,13 +10,13 @@ void* alloc_memory(uint32_t num_pages) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_ALLOC_MEM) ", %%eax; \
|
||||
int $80; \
|
||||
":"=b"(address):"b"(num_pages));
|
||||
":"=b"(address):"b"(num_pages),"c"(NULL));
|
||||
return address;
|
||||
}
|
||||
|
||||
void alloc_memory_virt(uint32_t num_pages,void* addr) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_ALLOC_MEM_VIRT) ", %%eax; \
|
||||
mov $" QU(SYSCALL_ALLOC_MEM) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(num_pages),"c"(addr));
|
||||
}
|
||||
@ -39,9 +40,9 @@ void copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) {
|
||||
void* put_data(void* cr3, void* data,uint32_t size) {
|
||||
void* virt_addr;
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_ADDR_SPACES_PUT_DATA) ", %%eax; \
|
||||
mov $" QU(SYSCALL_ADDR_SPACES_COPY_DATA) ", %%eax; \
|
||||
int $80; \
|
||||
":"=b"(virt_addr):"b"(cr3),"c"(data),"d"(size));
|
||||
":"=b"(virt_addr):"b"(cr3),"c"(data),"d"(size),"S"(NULL));
|
||||
return virt_addr;
|
||||
}
|
||||
|
||||
|
@ -8,28 +8,28 @@
|
||||
|
||||
void yield() {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_YIELD) ", %eax; \
|
||||
mov $" QU(SYSCALL_YIELD) ", %%eax; \
|
||||
int $80; \
|
||||
");
|
||||
"::"b"(0));
|
||||
}
|
||||
|
||||
void createTaskCr3(void* task,void* cr3) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE) ", %%eax; \
|
||||
mov $" QU(SYSCALL_CREATEPROC) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(task),"c"(cr3));
|
||||
"::"b"(task),"d"(0),"c"(cr3));
|
||||
}
|
||||
|
||||
void createTaskCr3Param(void* task,void* cr3,uint32_t param1,uint32_t param2) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE_W_ARGS) ", %%eax; \
|
||||
mov $" QU(SYSCALL_CREATEPROC) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(task),"c"(cr3),"d"(param1),"S"(param2));
|
||||
"::"b"(task),"c"(cr3),"d"(1),"S"(param1),"D"(param2));
|
||||
}
|
||||
|
||||
void yieldToPID(uint32_t pid) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_YIELD_TO_PID) ", %%eax; \
|
||||
mov $" QU(SYSCALL_YIELD) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(pid));
|
||||
}
|
||||
|
@ -2,24 +2,21 @@
|
||||
|
||||
#define SYSCALLS_H
|
||||
|
||||
#define SYSCALL_CREATEPROC_NEW_ADDR_SPACE 1
|
||||
#define SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE 2
|
||||
#define SYSCALL_CREATEPROC_GIVEN_ADDR_SPACE_W_ARGS 3
|
||||
#define SYSCALL_YIELD 4
|
||||
#define SYSCALL_YIELD_TO_PID 5
|
||||
#define SYSCALL_BLOCK 6
|
||||
#define SYSCALL_UNBLOCK 7
|
||||
#define SYSCALL_EXIT 8
|
||||
#define SYSCALL_GET_ERRNO_ADDR 9
|
||||
#define SYSCALL_GET_PID 10
|
||||
#define SYSCALL_ALLOC_MEM 11
|
||||
#define SYSCALL_ALLOC_MEM_VIRT 12
|
||||
#define SYSCALL_PRIV_MAP_PAGES 13
|
||||
#define SYSCALL_NEW_ADDR_SPACE 14
|
||||
#define SYSCALL_ADDR_SPACES_COPY_DATA 15
|
||||
#define SYSCALL_ADDR_SPACES_PUT_DATA 16
|
||||
#define SYSCALL_SERIAL_PRINT 17
|
||||
#define SYSCALL_GET_INITRD_SZ 18
|
||||
#define SYSCALL_COPY_INITRD 19
|
||||
#define SYSCALL_CREATEPROC 0
|
||||
#define SYSCALL_YIELD 1
|
||||
#define SYSCALL_BLOCK 2
|
||||
#define SYSCALL_UNBLOCK 3
|
||||
#define SYSCALL_EXIT 4
|
||||
#define SYSCALL_GET_ERRNO_ADDR 5
|
||||
#define SYSCALL_GET_PID 6
|
||||
|
||||
#define SYSCALL_ALLOC_MEM 7
|
||||
#define SYSCALL_PRIV_MAP_PAGES 8
|
||||
#define SYSCALL_NEW_ADDR_SPACE 9
|
||||
#define SYSCALL_ADDR_SPACES_COPY_DATA 10
|
||||
|
||||
#define SYSCALL_SERIAL_PRINT 11
|
||||
#define SYSCALL_GET_INITRD_SZ 12
|
||||
#define SYSCALL_COPY_INITRD 13
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user