|
|
@ -7,6 +7,7 @@ struct Task
|
|
|
|
enum class State {
|
|
|
|
enum class State {
|
|
|
|
Invalid,
|
|
|
|
Invalid,
|
|
|
|
Staging,
|
|
|
|
Staging,
|
|
|
|
|
|
|
|
Staged,
|
|
|
|
Running
|
|
|
|
Running
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -33,14 +34,14 @@ void schedule(const Registers& regs)
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
if (++current >= tasks.size())
|
|
|
|
if (++current >= tasks.size())
|
|
|
|
current = 0;
|
|
|
|
current = 0;
|
|
|
|
} while (tasks[current].state == Task::Invalid);
|
|
|
|
} while (tasks[current].state == Task::Invalid || tasks[current].state == Task::Staging);
|
|
|
|
|
|
|
|
|
|
|
|
asm volatile(R"(
|
|
|
|
asm volatile(R"(
|
|
|
|
mov %0, %%esp
|
|
|
|
mov %0, %%esp
|
|
|
|
mov %1, %%ebp
|
|
|
|
mov %1, %%ebp
|
|
|
|
)" :: "m" (tasks[current].esp), "m" (tasks[current].ebp));
|
|
|
|
)" :: "m" (tasks[current].esp), "m" (tasks[current].ebp));
|
|
|
|
|
|
|
|
|
|
|
|
if (tasks[current].state == Task::Staging) {
|
|
|
|
if (tasks[current].state == Task::Staged) {
|
|
|
|
tasks[current].state = Task::Running;
|
|
|
|
tasks[current].state = Task::Running;
|
|
|
|
asm volatile(R"(
|
|
|
|
asm volatile(R"(
|
|
|
|
pop %eax
|
|
|
|
pop %eax
|
|
|
@ -69,7 +70,7 @@ bool tasking_spawn(void (*entry)(), unsigned ssize)
|
|
|
|
if (i < 0)
|
|
|
|
if (i < 0)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
tasks[i] = Task();
|
|
|
|
tasks[i].state = Task::Staging;
|
|
|
|
|
|
|
|
|
|
|
|
auto stack = reinterpret_cast<std::uint32_t>(new std::uint8_t[ssize]);
|
|
|
|
auto stack = reinterpret_cast<std::uint32_t>(new std::uint8_t[ssize]);
|
|
|
|
const auto stackend = stack + ssize;
|
|
|
|
const auto stackend = stack + ssize;
|
|
|
@ -81,9 +82,11 @@ bool tasking_spawn(void (*entry)(), unsigned ssize)
|
|
|
|
r->cs = 0x8;
|
|
|
|
r->cs = 0x8;
|
|
|
|
asm volatile("pushfl; pop %%eax" : "=a"(r->eflags));
|
|
|
|
asm volatile("pushfl; pop %%eax" : "=a"(r->eflags));
|
|
|
|
|
|
|
|
|
|
|
|
tasks[i].esp = regbase;
|
|
|
|
tasks[i] = Task {
|
|
|
|
tasks[i].ebp = stackend;
|
|
|
|
.esp = regbase,
|
|
|
|
tasks[i].state = Task::Staging;
|
|
|
|
.ebp = stackend,
|
|
|
|
|
|
|
|
.state = Task::Staged
|
|
|
|
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|