Fix naming convention deviations

This commit is contained in:
pjht 2020-07-25 18:00:53 -05:00
parent ee7ce4dabe
commit b83a5505c3
12 changed files with 145 additions and 145 deletions

View File

@ -37,16 +37,16 @@ typedef struct {
static idt_gate_t idt[IDT_ENTRIES]; //!< The IDT
static idt_register_t idt_reg; //!< The value to load into the IDTR
#define low_16(address) (uint16_t)((address) & 0xFFFF) //!< Macro to get the low 16 bits of an address
#define high_16(address) (uint16_t)(((address) >> 16) & 0xFFFF) //!< Macro to get the high 16 bits of an address
#define LOW_16(address) (uint16_t)((address) & 0xFFFF) //!< Macro to get the low 16 bits of an address
#define HIGH_16(address) (uint16_t)(((address) >> 16) & 0xFFFF) //!< Macro to get the high 16 bits of an address
void idt_set_gate(int n,uint32_t handler) {
idt[n].low_offset=low_16(handler);
idt[n].low_offset=LOW_16(handler);
idt[n].sel=0x08;
idt[n].always0=0;
idt[n].flags=0xEE;
idt[n].high_offset=high_16(handler);
idt[n].high_offset=HIGH_16(handler);
}
void load_idt() {

View File

@ -202,7 +202,7 @@ void isr_handler(registers_t* r) {
case 80:
switch (r->eax) {
case SYSCALL_CREATEPROC:
tasking_createTask((void*)r->ebx,(void*)r->ecx,0,r->edx,(void*)r->esi,r->edx,(void*)r->edi,0);
tasking_create_task((void*)r->ebx,(void*)r->ecx,0,r->edx,(void*)r->esi,r->edx,(void*)r->edi,0);
break;
case SYSCALL_YIELD:
tasking_yield();
@ -220,7 +220,7 @@ void isr_handler(registers_t* r) {
r->ebx=(uint32_t)tasking_get_errno_address();
break;
case SYSCALL_GET_PID:
r->ebx=(pid_t)tasking_getPID();
r->ebx=(pid_t)tasking_get_PID();
break;
case SYSCALL_ALLOC_MEM:
if ((void*)r->ecx==NULL) {
@ -230,7 +230,7 @@ void isr_handler(registers_t* r) {
}
break;
case SYSCALL_PRIV_MAP_PAGES:
if (tasking_isPrivleged()) {
if (tasking_is_privleged()) {
r->ebx=0;
return;
}
@ -261,7 +261,7 @@ void isr_handler(registers_t* r) {
memcpy((char*)r->ebx,initrd,initrd_sz);
break;
case SYSCALL_NEW_THREAD: {
uint32_t tid=tasking_new_thread((void*)r->ebx,tasking_getPID(),1,(void*)r->edx);
uint32_t tid=tasking_new_thread((void*)r->ebx,tasking_get_PID(),1,(void*)r->edx);
if ((uint32_t*)r->ecx!=NULL) {
*((uint32_t*)r->ecx)=tid;
}

View File

@ -33,7 +33,7 @@ static uint32_t kern_page_tables[NUM_KERN_FRAMES] __attribute__((aligned(4096)))
static uint32_t kstack_page_tables[218*1024] __attribute__((aligned(4096))); //!< Page tables for thread kernel stacks
static uint32_t kmalloc_page_tables[4*1024] __attribute__((aligned(4096))); //!< Page tables for the kmalloc heap
static uint32_t* pagdirmap=(uint32_t*)0xFFFFF000; //!< Pointer to the page directory entries in the recursive mapping
static uint32_t* pagtblmap=(uint32_t*)0xFFC00000; //!< Pointer to the page table entries in the recursive mapping
static uint32_t* page_table_map=(uint32_t*)0xFFC00000; //!< Pointer to the page table entries in the recursive mapping
/**
* Checks whether a page is present
* \param page The page number to check
@ -45,7 +45,7 @@ static char is_page_present(size_t page) {
if ((pagdirmap[table]&0x1)==0) {
return 0;
}
return pagtblmap[page+1024*table]&0x1;
return page_table_map[page+1024*table]&0x1;
}
void map_pages(void* virt_addr_ptr,void* phys_addr_ptr,int num_pages,char usr,char wr) {
@ -63,7 +63,7 @@ void map_pages(void* virt_addr_ptr,void* phys_addr_ptr,int num_pages,char usr,ch
int flags=1;
flags=flags|((wr&1)<<1);
flags=flags|((usr&1)<<2);
pagtblmap[table_entry+1024*dir_entry]=phys_addr|flags;
page_table_map[table_entry+1024*dir_entry]=phys_addr|flags;
table_entry++;
if (table_entry==1024) {
table_entry=0;
@ -135,7 +135,7 @@ void* virt_to_phys(void* virt_addr_arg) {
if ((pagdirmap[dir_idx]&0x1)==0) {
return 0;
}
return (void*)((pagtblmap[tbl_idx+1024*dir_idx]&0xFFFFFC00)+offset);
return (void*)((page_table_map[tbl_idx+1024*dir_idx]&0xFFFFFC00)+offset);
}
@ -173,8 +173,8 @@ void unmap_pages(void* start_virt,int num_pages) {
int dir_entry=(virt_addr&0xFFC00000)>>22;
int table_entry=(virt_addr&0x3FF000)>>12;
for (int i=0;i<=num_pages;i++) {
if (pagtblmap[dir_entry]&0x1) {
pagtblmap[table_entry+1024*dir_entry]=0;
if (page_table_map[dir_entry]&0x1) {
page_table_map[table_entry+1024*dir_entry]=0;
invl_page(start_virt+(i*1024));
table_entry++;
if (table_entry==1024) {

View File

@ -7,14 +7,14 @@
static char configured[]={0,0,0,0}; //!< What serial ports have been detected and configured
static int data_ports[4]={0x3f8,0x2f8,0x3e8,0x2e8}; //!< List of the data ports for all the potential serial ports
#define data_port(com) (data_ports[com]) //!< Returns the data port of a serial port
#define int_port(com) (data_port(com)+1) //!< Returns the interrupt config port of a serial port
#define fifo_port(com) (data_port(com)+2) //!< Returns the fifo config port of a serial port
#define line_cmd_port(com) (data_port(com)+3) //!< Returns the line cmd port of a serial port
#define modem_cmd_port(com) (data_port(com)+4) //!< Returns the modem cmd port of a serial port
#define line_stat_port(com) (data_port(com)+5) //!< Returns the line status port of a serial port
#define scratch_port(com) (data_port(com)+7) //!< Returns the scratch port of a serial port
#define is_transmit_fifo_empty(com) (port_byte_in(line_stat_port(com))&0x20) //!< Returns whether the trasmit FIFO is empty.
#define DATA_PORT(com) (data_ports[com]) //!< Returns the data port of a serial port
#define INT_PORT(com) (DATA_PORT(com)+1) //!< Returns the interrupt config port of a serial port
#define FIFO_PORT(com) (DATA_PORT(com)+2) //!< Returns the fifo config port of a serial port
#define LINE_CMD_PORT(com) (DATA_PORT(com)+3) //!< Returns the line cmd port of a serial port
#define MODEM_CMD_PORT(com) (DATA_PORT(com)+4) //!< Returns the modem cmd port of a serial port
#define LINE_STAT_PORT(com) (DATA_PORT(com)+5) //!< Returns the line status port of a serial port
#define SCRATCH_PORT(com) (DATA_PORT(com)+7) //!< Returns the scratch port of a serial port
#define IS_TRANSMIT_FIFO_EMPTY(com) (port_byte_in(LINE_STAT_PORT(com))&0x20) //!< Returns whether the trasmit FIFO is empty.
/**
* Configure a serial port with a specified baud rate.
@ -23,18 +23,18 @@ static int data_ports[4]={0x3f8,0x2f8,0x3e8,0x2e8}; //!< List of the data ports
*/
static void configure(int com, int rate) {
configured[com]=1;
port_byte_out(line_cmd_port(com),0x80); // Enable DLAB
port_byte_out(data_port(com),((115200/rate)>>8)&0xFF); //Write high byte of divisor
port_byte_out(data_port(com),(115200/rate)&0xFF); //Write low byte of divisor
port_byte_out(line_cmd_port(com),0x03); //Disable DLAB and set 8N1 trasmission mode
port_byte_out(fifo_port(com),0xC7); //Enable & clear FIFOs and set Data Ready interrupt level to 14.
port_byte_out(modem_cmd_port(com),0x03); //Enable DTR and RTS
port_byte_out(int_port(com),0x0); //Disable interrupts
port_byte_out(LINE_CMD_PORT(com),0x80); // Enable DLAB
port_byte_out(DATA_PORT(com),((115200/rate)>>8)&0xFF); //Write high byte of divisor
port_byte_out(DATA_PORT(com),(115200/rate)&0xFF); //Write low byte of divisor
port_byte_out(LINE_CMD_PORT(com),0x03); //Disable DLAB and set 8N1 trasmission mode
port_byte_out(FIFO_PORT(com),0xC7); //Enable & clear FIFOs and set Data Ready interrupt level to 14.
port_byte_out(MODEM_CMD_PORT(com),0x03); //Enable DTR and RTS
port_byte_out(INT_PORT(com),0x0); //Disable interrupts
}
void serial_init() {
port_byte_out(scratch_port(0),0xaa);
if (port_byte_in(scratch_port(0))==0xaa) {
port_byte_out(SCRATCH_PORT(0),0xaa);
if (port_byte_in(SCRATCH_PORT(0))==0xaa) {
configure(0,9600);
}
}
@ -42,6 +42,6 @@ void serial_init() {
void serial_putc(char c) {
if (!configured[0]) return;
if (c=='\n') serial_putc('\r');
while(!is_transmit_fifo_empty(0));
port_byte_out(data_port(0),c);
while(!IS_TRANSMIT_FIFO_EMPTY(0));
port_byte_out(DATA_PORT(0),c);
}

View File

@ -1,7 +1,7 @@
section .text
global switch_to_thread_asm
extern load_address_space
extern currentThread
extern current_thread
extern tss
;WARNING: Caller is expected to disable IRQs before calling, and enable IRQs again after function returns
@ -20,13 +20,13 @@ switch_to_thread_asm:
push edi
push ebp
mov edi,[currentThread] ;edi = address of the previous thread's data structure
mov edi,[current_thread] ;edi = address of the previous thread's data structure
mov [edi],esp ;Save ESP for the thread's kernel stack in the thread's data structure
;Load next thread's state
mov esi,[esp+(4+1)*4] ;esi = address of the next thread's data structure
mov [currentThread],esi ;Set the current thread to the thread we are switching to
mov [current_thread],esi ;Set the current thread to the thread we are switching to
mov esp,[esi] ;Load ESP for next thread's kernel stack from the thread's data structure
mov eax,[esi+8] ;eax = address of page directory for next thread

View File

@ -32,13 +32,13 @@ typedef struct {
static idt_gate_t idt[IDT_ENTRIES];
static idt_register_t idt_reg;
#define low_16(address) (uint16_t)((address) & 0xFFFF)
#define LOW_16(address) (uint16_t)((address) & 0xFFFF)
#define middle_16(address) (uint16_t)(((address) >> 16) & 0xFFFF)
#define high_32(address) (uint32_t)(((address) >> 32) & 0xFFFFFFFF)
void idt_set_gate(int n,uint64_t handler) {
idt[n].low_offset=low_16(handler);
idt[n].low_offset=LOW_16(handler);
idt[n].sel=KERNEL_CS;
idt[n].always0=0;
idt[n].flags=0xEE;

View File

@ -171,7 +171,7 @@ void isr_handler(registers_t* r) {
// if (r->eax==1) {
// tasking_yield();
// } else if (r->eax==2) {
// tasking_createTask((void*)r->ebx);
// tasking_create_task((void*)r->ebx);
// } else if (r->eax==3) {
// r->ebx=(uint64_t)alloc_pages(r->ebx);
// } else if (r->eax==4) {

View File

@ -43,6 +43,6 @@
// if (func_idx==-1) {
// serial_printf("No such rpc function %s for PID %d",name,pid);
// }
// void* copieddata=address_spaces_put_data(currentThread->cr3,data,size);
// void* copieddata=address_spaces_put_data(current_thread->cr3,data,size);
// tasking_new_thread(info->funcs[func_idx].code,pid,1,copieddata);
// }

View File

@ -19,9 +19,9 @@ pid_t next_pid=0; //!< PID to use for the next created process
size_t num_procs=0; //!< Number of non-exited processes
Process* processes[MAX_PROCS]; //!< Array pf processes by PID
char proc_schedule_bmap[MAX_PROCS/8]; //!< Bitmap of what processes are scheduled
Thread* currentThread; //!< Currently running thread
static Thread* readyToRunHead=NULL; //!< Head of the linked list of ready to run threads
static Thread* readyToRunTail=NULL; //!< Tail of the linked list of ready to run threads
Thread* current_thread; //!< Currently running thread
static Thread* ready_to_run_head=NULL; //!< Head of the linked list of ready to run threads
static Thread* ready_to_run_tail=NULL; //!< Tail of the linked list of ready to run threads
/**
* Check whether a process is scheduled
@ -59,7 +59,7 @@ static void unmark_proc_scheduled(pid_t index) {
proc_schedule_bmap[byte]=proc_schedule_bmap[byte]&(~(1<<bit));
}
void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,void* param1_arg,char param2_exists,void* param2_arg,char isThread) {
void tasking_create_task(void* eip,void* cr3,char kmode,char param1_exists,void* param1_arg,char param2_exists,void* param2_arg,char isThread) {
if (next_pid>MAX_PROCS && !isThread) {
serial_printf("Failed to create a process, as 32k processes have been created already.\n");
halt(); //Cannot ever create more than 32k processes, as I don't currently reuse PIDs.
@ -88,8 +88,8 @@ void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,void*
thread->cr3=proc->firstThread->cr3;
} else {
proc=kmalloc(sizeof(Process));
if (currentThread) {
proc->priv=currentThread->process->priv;
if (current_thread) {
proc->priv=current_thread->process->priv;
} else {
proc->priv=1;
}
@ -119,20 +119,20 @@ void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,void*
thread->nextThreadInProcess=NULL;
thread->prevThreadInProcess=NULL;
if (!is_proc_scheduled(proc->pid)) {
if (readyToRunTail) {
if (ready_to_run_tail) {
thread->state=THREAD_READY;
readyToRunTail->nextReadyToRun=thread;
thread->prevReadyToRun=readyToRunTail;
readyToRunTail=thread;
ready_to_run_tail->nextReadyToRun=thread;
thread->prevReadyToRun=ready_to_run_tail;
ready_to_run_tail=thread;
mark_proc_scheduled(proc->pid);
} else if (currentThread) {
} else if (current_thread) {
thread->state=THREAD_READY;
readyToRunHead=thread;
readyToRunTail=thread;
ready_to_run_head=thread;
ready_to_run_tail=thread;
mark_proc_scheduled(proc->pid);
} else {
thread->state=THREAD_RUNNING;
currentThread=thread;
current_thread=thread;
}
}
}
@ -143,23 +143,23 @@ void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,void*
}
void tasking_init() {
tasking_createTask(NULL,get_cr3(),1,0,0,0,0,0);
tasking_create_task(NULL,get_cr3(),1,0,0,0,0,0);
}
char tasking_isPrivleged() {
return currentThread->process->priv;
char tasking_is_privleged() {
return current_thread->process->priv;
}
pid_t tasking_getPID() {
return currentThread->process->pid;
pid_t tasking_get_PID() {
return current_thread->process->pid;
}
int* tasking_get_errno_address() {
return &currentThread->errno;
return &current_thread->errno;
}
pid_t tasking_new_thread(void* start,pid_t pid,char param_exists,void* param_arg) {
tasking_createTask(start,NULL,0,param_exists,param_arg,0,(void*)pid,1);
tasking_create_task(start,NULL,0,param_exists,param_arg,0,(void*)pid,1);
return processes[pid]->firstThread->tid;
}
@ -169,57 +169,57 @@ pid_t tasking_new_thread(void* start,pid_t pid,char param_exists,void* param_arg
*/
void switch_to_thread(Thread* thread) {
// Unlink the thread from the list of ready-to-run threads
if (thread!=readyToRunHead) {
if (thread!=ready_to_run_head) {
thread->prevReadyToRun->nextReadyToRun=thread->nextReadyToRun;
if (thread->nextReadyToRun) {
thread->nextReadyToRun->prevReadyToRun=thread->prevReadyToRun;
}
} else {
readyToRunHead=thread->nextReadyToRun;
if (readyToRunHead==NULL) {
readyToRunTail=NULL;
ready_to_run_head=thread->nextReadyToRun;
if (ready_to_run_head==NULL) {
ready_to_run_tail=NULL;
}
}
unmark_proc_scheduled(thread->process->pid);
thread->prevReadyToRun=NULL;
thread->nextReadyToRun=NULL;
if (currentThread->state==THREAD_RUNNING) {
currentThread->state=THREAD_READY;
if (current_thread->state==THREAD_RUNNING) {
current_thread->state=THREAD_READY;
}
Thread* currentThreadNextReady=currentThread->nextThreadInProcess;
while ((currentThreadNextReady&&currentThreadNextReady->state!=THREAD_READY)||(currentThreadNextReady&&SAME_THREAD(thread,currentThreadNextReady))) {
currentThreadNextReady=currentThreadNextReady->nextThreadInProcess;
Thread* current_threadNextReady=current_thread->nextThreadInProcess;
while ((current_threadNextReady&&current_threadNextReady->state!=THREAD_READY)||(current_threadNextReady&&SAME_THREAD(thread,current_threadNextReady))) {
current_threadNextReady=current_threadNextReady->nextThreadInProcess;
}
if (!currentThreadNextReady) {
currentThreadNextReady=currentThread->process->firstThread;
while ((currentThreadNextReady&&currentThreadNextReady->state!=THREAD_READY)||(currentThreadNextReady&&SAME_THREAD(thread,currentThreadNextReady))) {
currentThreadNextReady=currentThreadNextReady->nextThreadInProcess;
if (!current_threadNextReady) {
current_threadNextReady=current_thread->process->firstThread;
while ((current_threadNextReady&&current_threadNextReady->state!=THREAD_READY)||(current_threadNextReady&&SAME_THREAD(thread,current_threadNextReady))) {
current_threadNextReady=current_threadNextReady->nextThreadInProcess;
}
}
if (!currentThreadNextReady) {
if (!current_threadNextReady) {
//This process is fully blocked, try the process of the thread we're yielding to
currentThreadNextReady=thread->nextThreadInProcess;
while ((currentThreadNextReady&&currentThreadNextReady->state!=THREAD_READY)||(currentThreadNextReady&&SAME_THREAD(thread,currentThreadNextReady))) {
currentThreadNextReady=currentThreadNextReady->nextThreadInProcess;
current_threadNextReady=thread->nextThreadInProcess;
while ((current_threadNextReady&&current_threadNextReady->state!=THREAD_READY)||(current_threadNextReady&&SAME_THREAD(thread,current_threadNextReady))) {
current_threadNextReady=current_threadNextReady->nextThreadInProcess;
}
if (!currentThreadNextReady) {
currentThreadNextReady=thread->process->firstThread;
while ((currentThreadNextReady&&currentThreadNextReady->state!=THREAD_READY)||(currentThreadNextReady&&SAME_THREAD(thread,currentThreadNextReady))) {
currentThreadNextReady=currentThreadNextReady->nextThreadInProcess;
if (!current_threadNextReady) {
current_threadNextReady=thread->process->firstThread;
while ((current_threadNextReady&&current_threadNextReady->state!=THREAD_READY)||(current_threadNextReady&&SAME_THREAD(thread,current_threadNextReady))) {
current_threadNextReady=current_threadNextReady->nextThreadInProcess;
}
}
}
if (currentThreadNextReady && !is_proc_scheduled(currentThread->process->pid)) {
if (current_threadNextReady && !is_proc_scheduled(current_thread->process->pid)) {
// Link the thread onto the list of ready to run threads
if (readyToRunTail) {
currentThreadNextReady->prevReadyToRun=readyToRunTail;
readyToRunTail->nextThreadInProcess=currentThreadNextReady;
readyToRunTail=currentThreadNextReady;
if (ready_to_run_tail) {
current_threadNextReady->prevReadyToRun=ready_to_run_tail;
ready_to_run_tail->nextThreadInProcess=current_threadNextReady;
ready_to_run_tail=current_threadNextReady;
} else {
readyToRunHead=currentThreadNextReady;
readyToRunTail=currentThreadNextReady;
ready_to_run_head=current_threadNextReady;
ready_to_run_tail=current_threadNextReady;
}
mark_proc_scheduled(currentThread->process->pid);
mark_proc_scheduled(current_thread->process->pid);
}
serial_printf("Switching to PID %d TID %d.\n",thread->process->pid,thread->tid);
switch_to_thread_asm(thread);
@ -227,14 +227,14 @@ void switch_to_thread(Thread* thread) {
void tasking_yield() {
serial_printf("Attempting to yield\n");
if (readyToRunHead) {
serial_printf("Attempting to switch to PID %d TID %d\n",readyToRunHead->process->pid,readyToRunHead->tid);
switch_to_thread(readyToRunHead);
if (ready_to_run_head) {
serial_printf("Attempting to switch to PID %d TID %d\n",ready_to_run_head->process->pid,ready_to_run_head->tid);
switch_to_thread(ready_to_run_head);
} else {
if (NUM_UNBLOCKED_THREADS(currentThread->process)>1) {
if (NUM_UNBLOCKED_THREADS(current_thread->process)>1) {
serial_printf("The ready to run list is empty, and the current process has other unblocked threads? This is an invalid state! Halting!\n");
halt();
} else if (NUM_UNBLOCKED_THREADS(currentThread->process)==1) {
} else if (NUM_UNBLOCKED_THREADS(current_thread->process)==1) {
serial_printf("Yield failed, no other ready processes\n");
return;
} else {
@ -244,30 +244,30 @@ void tasking_yield() {
} else {
serial_printf("All threads in all processes blocked, waiting for an IRQ which unblocks a thread\n");
// All threads in all processes blocked, so wait for an IRQ whose handler unblocks a thread.
do { wait_for_unblocked_thread_asm(); } while (readyToRunHead==NULL);
do { wait_for_unblocked_thread_asm(); } while (ready_to_run_head==NULL);
}
serial_printf("Attempting to switch to PID %d TID %d\n",readyToRunHead->process->pid,readyToRunHead->tid);
switch_to_thread(readyToRunHead);
serial_printf("Attempting to switch to PID %d TID %d\n",ready_to_run_head->process->pid,ready_to_run_head->tid);
switch_to_thread(ready_to_run_head);
}
}
}
void tasking_block(ThreadState newstate) {
if (readyToRunHead&&SAME_THREAD(readyToRunHead,currentThread)) {
readyToRunHead=readyToRunHead->nextReadyToRun;
if (readyToRunHead==NULL) {
readyToRunTail=NULL;
void tasking_block(thread_state newstate) {
if (ready_to_run_head&&SAME_THREAD(ready_to_run_head,current_thread)) {
ready_to_run_head=ready_to_run_head->nextReadyToRun;
if (ready_to_run_head==NULL) {
ready_to_run_tail=NULL;
}
}
if (readyToRunTail&&SAME_THREAD(readyToRunTail,currentThread)) {
readyToRunTail=readyToRunTail->prevReadyToRun;
if (readyToRunTail==NULL) {
readyToRunHead=NULL;
if (ready_to_run_tail&&SAME_THREAD(ready_to_run_tail,current_thread)) {
ready_to_run_tail=ready_to_run_tail->prevReadyToRun;
if (ready_to_run_tail==NULL) {
ready_to_run_head=NULL;
}
}
if (readyToRunHead&&readyToRunHead->nextReadyToRun) {
for (Thread* thread=readyToRunHead->nextReadyToRun;thread!=NULL;thread=thread->nextReadyToRun) {
if (SAME_THREAD(thread,currentThread)) {
if (ready_to_run_head&&ready_to_run_head->nextReadyToRun) {
for (Thread* thread=ready_to_run_head->nextReadyToRun;thread!=NULL;thread=thread->nextReadyToRun) {
if (SAME_THREAD(thread,current_thread)) {
thread->prevReadyToRun->nextReadyToRun=thread->nextReadyToRun;
if (thread->nextReadyToRun) {
thread->nextReadyToRun->prevReadyToRun=thread->prevReadyToRun;
@ -276,8 +276,8 @@ void tasking_block(ThreadState newstate) {
}
}
}
for (Thread* thread=currentThread->process->firstThread;thread!=NULL;thread=thread->nextThreadInProcess) {
if (thread->tid==currentThread->tid) {
for (Thread* thread=current_thread->process->firstThread;thread!=NULL;thread=thread->nextThreadInProcess) {
if (thread->tid==current_thread->tid) {
thread->state=newstate;
}
}
@ -303,36 +303,36 @@ void tasking_unblock(pid_t pid,pid_t tid) {
thread->state=THREAD_READY;
if (!is_proc_scheduled(thread->process->pid)) {
// Link the thread onto the list of ready to run threads
if (readyToRunTail) {
thread->prevReadyToRun=readyToRunTail;
readyToRunTail->nextThreadInProcess=thread;
readyToRunTail=thread;
if (ready_to_run_tail) {
thread->prevReadyToRun=ready_to_run_tail;
ready_to_run_tail->nextThreadInProcess=thread;
ready_to_run_tail=thread;
} else {
readyToRunHead=thread;
readyToRunTail=thread;
ready_to_run_head=thread;
ready_to_run_tail=thread;
}
mark_proc_scheduled(thread->process->pid);
}
}
void tasking_exit(int code) {
serial_printf("PID %d is exiting with code %d.\n",currentThread->process->pid,code);
if (readyToRunHead&&SAME_PROC(readyToRunHead,currentThread)) {
readyToRunHead=readyToRunHead->nextReadyToRun;
if (readyToRunHead==NULL) {
readyToRunTail=NULL;
serial_printf("PID %d is exiting with code %d.\n",current_thread->process->pid,code);
if (ready_to_run_head&&SAME_PROC(ready_to_run_head,current_thread)) {
ready_to_run_head=ready_to_run_head->nextReadyToRun;
if (ready_to_run_head==NULL) {
ready_to_run_tail=NULL;
}
}
if (readyToRunTail&&SAME_PROC(readyToRunTail,currentThread)) {
readyToRunTail=readyToRunTail->prevReadyToRun;
if (readyToRunTail==NULL) {
readyToRunHead=NULL;
if (ready_to_run_tail&&SAME_PROC(ready_to_run_tail,current_thread)) {
ready_to_run_tail=ready_to_run_tail->prevReadyToRun;
if (ready_to_run_tail==NULL) {
ready_to_run_head=NULL;
}
}
if (readyToRunHead&&readyToRunHead->nextReadyToRun) {
for (Thread* thread=readyToRunHead->nextReadyToRun;thread!=NULL;thread=thread->nextReadyToRun) {
if (SAME_PROC(thread,currentThread)) {
if (ready_to_run_head&&ready_to_run_head->nextReadyToRun) {
for (Thread* thread=ready_to_run_head->nextReadyToRun;thread!=NULL;thread=thread->nextReadyToRun) {
if (SAME_PROC(thread,current_thread)) {
thread->prevReadyToRun->nextReadyToRun=thread->nextReadyToRun;
if (thread->nextReadyToRun) {
thread->nextReadyToRun->prevReadyToRun=thread->prevReadyToRun;
@ -341,11 +341,11 @@ void tasking_exit(int code) {
}
}
}
unmark_proc_scheduled(currentThread->process->pid);
for (Thread* thread=currentThread->process->firstThread;thread!=NULL;thread=thread->nextThreadInProcess) {
unmark_proc_scheduled(current_thread->process->pid);
for (Thread* thread=current_thread->process->firstThread;thread!=NULL;thread=thread->nextThreadInProcess) {
thread->state=THREAD_EXITED;
}
currentThread->process->numThreadsBlocked=currentThread->process->numThreads;
current_thread->process->numThreadsBlocked=current_thread->process->numThreads;
num_procs--;
tasking_yield();
}

View File

@ -13,12 +13,12 @@
/**
* Represents the state of a thread
*/
typedef enum ThreadState {
typedef enum thread_state {
THREAD_RUNNING, //!< The state of a running thread
THREAD_READY, //!< The state of a ready to run thread
THREAD_EXITED, //!< The state of an exited thread
THREAD_BLOCKED //!< The state of a generically blocked thread
} ThreadState;
} thread_state;
#endif
@ -44,7 +44,7 @@ typedef struct Thread {
void* kernel_esp_top; //!< The top of the thread's kernel stack.
void* cr3; //!< The address space of this thread. (it is in here and not in the process to simplify the task switch asembly)
pid_t tid; //!< The TID of this thread.
ThreadState state; //!< The state of this thread. (running,ready to run,blocked,etc.)
thread_state state; //!< The state of this thread. (running,ready to run,blocked,etc.)
int errno; //!< The errno value for this thread.
struct Thread* nextThreadInProcess; //!< The next thread in the process.
struct Thread* prevThreadInProcess; //!< The previous thread in the process.
@ -53,7 +53,7 @@ typedef struct Thread {
Process* process; //!< The thread's process.
} Thread;
extern Thread* currentThread;
extern Thread* current_thread;
/**
* Create a task
@ -66,7 +66,7 @@ extern Thread* currentThread;
* \param param2_arg The thread's start function second parameter/
* \param isThread Whether we are creating a new process or a thread in a process. If we are creating a theead, param2_arg becomes the PID for the newly created thread, and param2_exists must be 0.
*/
void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,void* param1_arg,char param2_exists,void* param2_arg,char isThread);
void tasking_create_task(void* eip,void* cr3,char kmode,char param1_exists,void* param1_arg,char param2_exists,void* param2_arg,char isThread);
/**
* Initialize tasking
*/
@ -74,11 +74,11 @@ void tasking_init();
/**
* Check whether the current process is privleged
*/
char tasking_isPrivleged();
char tasking_is_privleged();
/**
* Get the PID of the current thread.
*/
pid_t tasking_getPID();
pid_t tasking_get_PID();
/**
* Get the adddress of errno for the current thread
*/
@ -103,7 +103,7 @@ void tasking_exit(int code);
* Block the current thread & yield
* \param newstate The state to block it in
*/
void tasking_block(ThreadState newstate);
void tasking_block(thread_state newstate);
/**
* Unblock a thread
* \param pid The PID that contains the thread to unblock

View File

@ -36,7 +36,7 @@ __attribute__((noreturn)) void exit(int code) {
}
void blockThread(ThreadState state) {
void blockThread(thread_state state) {
asm volatile(" \
mov $" QU(SYSCALL_BLOCK) ", %%eax; \
int $80; \

View File

@ -5,12 +5,12 @@
#include <sys/types.h>
#ifndef KERN_TASKING_H
typedef enum ThreadState {
typedef enum thread_state {
THREAD_RUNNING,
THREAD_READY,
THREAD_EXITED,
THREAD_BLOCKED
} ThreadState;
} thread_state;
#endif
@ -19,7 +19,7 @@ void yieldToPID(pid_t pid);
void createProcCr3(void* start,void* cr3);
void createProcCr3Param(void* start,void* cr3,void* param1,void* param2);
char isPrivleged(pid_t pid);
void blockThread(ThreadState state);
void blockThread(thread_state state);
void unblockThread(pid_t pid,pid_t tid);