user_space #4

Merged
mathieu merged 40 commits from user_space into master 2021-11-04 16:17:36 +01:00
6 changed files with 37 additions and 37 deletions
Showing only changes of commit ca4b318df6 - Show all commits

View File

@ -52,7 +52,7 @@ void print_handler(struct cpu_state *frame, ulong intr)
void pagefault_handler(struct cpu_state *frame, ulong intr)
{
struct kthread *current = getCurrentThread();
struct thread *current = getCurrentThread();
printf("page fault while in thread %s code at 0x%x when trying to access 0x%x err_code 0x%x\n", current->name,
cpu_context_get_PC(frame), cpu_context_get_EX_faulting_vaddr(frame), cpu_context_get_EX_err(frame));
VGAPrintf(RED, BLACK, 0, VGA_HEIGHT - 1, "PAGE FAULT %d", intr);

View File

@ -7,8 +7,8 @@
#include "time.h"
#include "vga.h"
static struct kthread *currentThread;
static struct kthread *threadWithTimeout;
static struct thread *currentThread;
static struct thread *threadWithTimeout;
void kthreadExit()
{
@ -16,8 +16,8 @@ void kthreadExit()
disable_IRQs(flags);
struct kthread *current = currentThread;
struct kthread *next = kthreadSelectNext();
struct thread *current = currentThread;
struct thread *next = kthreadSelectNext();
if (next == current)
assert("cannot exit thread");
@ -35,7 +35,7 @@ void kthreadExit()
int kthreadSetup(vaddr_t mainStack, size_t mainStackSize)
{
struct kthread *current = (struct kthread *)malloc(sizeof(struct kthread));
struct thread *current = (struct thread *)malloc(sizeof(struct thread));
strzcpy(current->name, "[KINIT]", KTHREAD_NAME_MAX_LENGTH);
current->stackAddr = mainStack;
current->stackSize = mainStackSize;
@ -48,9 +48,9 @@ int kthreadSetup(vaddr_t mainStack, size_t mainStackSize)
return 0;
}
struct kthread *kthreadCreate(const char *name, cpu_kstate_function_arg1_t func, void *args)
struct thread *kthreadCreate(const char *name, cpu_kstate_function_arg1_t func, void *args)
{
struct kthread *thread = (struct kthread *)malloc(sizeof(struct kthread));
struct thread *thread = (struct thread *)malloc(sizeof(struct thread));
if (!thread)
return NULL;
@ -87,7 +87,7 @@ free_mem:
return NULL;
}
void kthreadDelete(struct kthread *thread)
void kthreadDelete(struct thread *thread)
{
uint32_t flags;
disable_IRQs(flags);
@ -101,9 +101,9 @@ void kthreadDelete(struct kthread *thread)
restore_IRQs(flags);
}
struct kthread *kthreadSelectNext()
struct thread *kthreadSelectNext()
{
struct kthread *nextThread;
struct thread *nextThread;
int idx;
list_foreach(currentThread->next, nextThread, idx)
{
@ -117,7 +117,7 @@ struct kthread *kthreadSelectNext()
struct cpu_state *kthreadSwitch(struct cpu_state *prevCpu)
{
uint32_t flags;
struct kthread *nextThread;
struct thread *nextThread;
disable_IRQs(flags);
@ -134,7 +134,7 @@ struct cpu_state *kthreadSwitch(struct cpu_state *prevCpu)
int kthreadOnJieffiesTick()
{
struct kthread *nextThread;
struct thread *nextThread;
int idx;
uint32_t flags;
disable_IRQs(flags);
@ -162,7 +162,7 @@ int kthreadOnJieffiesTick()
return 0;
}
int kthreadUnsched(struct kthread *th)
int kthreadUnsched(struct thread *th)
{
list_delete(currentThread, th);
@ -170,7 +170,7 @@ int kthreadUnsched(struct kthread *th)
}
// Must be called with IRQ disabled
int kthreadWait(struct kthread *current, struct kthread *next, unsigned long msec)
int kthreadWait(struct thread *current, struct thread *next, unsigned long msec)
{
if (current == next) {
assertmsg(0, "Cannot yield from %s to %s\n", current->name, next->name);
@ -197,8 +197,8 @@ int kthreadYield()
uint32_t flags;
disable_IRQs(flags);
struct kthread *next = kthreadSelectNext();
struct kthread *current = currentThread;
struct thread *next = kthreadSelectNext();
struct thread *current = currentThread;
if (current == next) {
restore_IRQs(flags);
@ -222,7 +222,7 @@ int kthreadYield()
int kthreadMsleep(unsigned long msec)
{
uint32_t flags;
struct kthread *next, *current;
struct thread *next, *current;
disable_IRQs(flags);
@ -245,12 +245,12 @@ int kthreadMsleep(unsigned long msec)
return current->sleepHaveTimeouted == 1;
}
struct kthread *getCurrentThread()
struct thread *getCurrentThread()
{
return currentThread;
}
int kthreadAddThread(struct kthread *th)
int kthreadAddThread(struct thread *th)
{
if (th->state == READY)
return 0;

View File

@ -15,7 +15,7 @@ typedef enum {
EXITING
} kthread_state;
struct kthread {
struct thread {
char name[KTHREAD_NAME_MAX_LENGTH];
struct cpu_state *cpuState;
kthread_state state;
@ -23,25 +23,25 @@ struct kthread {
size_t stackSize;
unsigned long jiffiesSleeping;
int sleepHaveTimeouted;
struct kthread *next;
struct kthread *prev;
struct kthread *timeNext;
struct kthread *timePrev;
struct thread *next;
struct thread *prev;
struct thread*timeNext;
struct thread *timePrev;
};
int kthreadSetup(vaddr_t mainStack, size_t mainStackSize);
void kthreadExit();
struct kthread *kthreadCreate(const char *name, cpu_kstate_function_arg1_t func, void *args);
void kthreadDelete(struct kthread *thread);
struct thread *kthreadCreate(const char *name, cpu_kstate_function_arg1_t func, void *args);
void kthreadDelete(struct thread *thread);
struct kthread *kthreadSelectNext();
struct thread *kthreadSelectNext();
struct cpu_state *kthreadSwitch(struct cpu_state *prevCpu);
int kthreadYield();
int kthreadWait(struct kthread *current, struct kthread *next, unsigned long msec);
int kthreadUnsched(struct kthread *th);
int kthreadWait(struct thread *current, struct thread *next, unsigned long msec);
int kthreadUnsched(struct thread *th);
int kthreadMsleep(unsigned long msec);
int kthreadOnJieffiesTick();
struct kthread *getCurrentThread();
int kthreadAddThread(struct kthread *th);
struct thread *getCurrentThread();
int kthreadAddThread(struct thread *th);

View File

@ -51,7 +51,7 @@ int mutexFree(struct mutex *m)
int mutexLock(struct mutex *m)
{
uint32_t flags;
struct kthread *current;
struct thread *current;
disable_IRQs(flags);
current = getCurrentThread();

View File

@ -25,7 +25,7 @@ int waitQueueFree(struct wait_queue *wq)
int wakeUp(struct wait_queue *wq)
{
struct kthread *th;
struct thread *th;
uint32_t flags;
disable_IRQs(flags);
@ -46,7 +46,7 @@ int wait(struct wait_queue *wq)
int waitTimeout(struct wait_queue *wq, unsigned long msec)
{
struct kthread *current, *next;
struct thread *current, *next;
uint32_t flags;
int ret;

View File

@ -3,7 +3,7 @@
#include "kthread.h"
struct wait_queue {
struct kthread *thread;
struct thread *thread;
struct wait_queue *next;
struct wait_queue *prev;
};
@ -35,6 +35,6 @@ struct semaphore {
};
struct mutex {
struct kthread *owner;
struct thread *owner;
struct wait_queue *wait;
};