Skip to content

Commit

Permalink
[src/*]: Implement schedYield syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
mogasergiu committed Sep 28, 2021
1 parent 31f171c commit 9655e0d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/kernel/includes/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ namespace TASK {
bool taskReady(uint8_t tid) const;
void printPS() const;
};

extern "C" void schedYield();
}

extern TASK::TaskMgr taskMgr;
Expand Down
4 changes: 1 addition & 3 deletions src/kernel/interrupts/interrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ extern "C" long IntCallbacks::syscallISR(long arg1, ...) {
break;

case SYS_SCHED_YIELD:
TASK::acquireLock(&vgaHandler.vLock);
kpwarn("STUBBED!\n");
TASK::releaseLock(&vgaHandler.vLock);
TASK::schedYield();

break;

Expand Down
15 changes: 15 additions & 0 deletions src/kernel/task/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,21 @@ bool TaskMgr::taskReady(uint8_t tid) const {
return this->tasks[tid] == NULL;
}

extern "C" void TASK::schedYield() {
uintptr_t eax, edx;
TASK::TaskHeader *task;

__asm__ __volatile__(
"rdmsr;"
: "=a" (eax), "=d" (edx)
: "c" (0xc0000101)
);

task = (TASK::TaskHeader*)((edx << 32) + eax);

task->TCB->timeSlices = 0; // yield
}

void TaskMgr::endTask(int8_t pid) {
TaskHeader *task = NULL;

Expand Down
1 change: 1 addition & 0 deletions src/user/libc/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ extern "C" void* mmap(void *addr, size_t length, int prot) {
extern "C" void schedYield() {
__asm__ __volatile__(
"int $0x80;"
"int $0x22;"
:
: "a" (SYS_SCHED_YIELD)
);
Expand Down

0 comments on commit 9655e0d

Please sign in to comment.