fix pit_busy_wait; better tasking

main
Clyne 4 weeks ago
parent 35aa65037b
commit bd0acf8836
Signed by: clyne
GPG Key ID: 3267C8EBF3F9AFC7

@ -10,6 +10,8 @@
static VGATerminal vga;
TextOutput& term = vga;
static volatile bool termBusy = false;
void kernel_main(void)
{
term.write("Clyne's kernel, v2024\n\n");
@ -28,18 +30,41 @@ void kernel_main(void)
gdt_initialize();
pic_initialize();
idt_initialize();
pit_initialize(50);
pit_initialize(100);
asm volatile("sti");
tasking_initialize();
term.write("Tasking enabled.\n");
tasking_spawn([] {
for (;;)
for (;;) {
do pit_busy_wait(1);
while (termBusy);
termBusy = true;
term.write('B');
termBusy = false;
}
}, 256);
tasking_spawn([] {
for (;;) {
do pit_busy_wait(1);
while (termBusy);
termBusy = true;
term.write('C');
termBusy = false;
}
}, 256);
for (;;)
for (;;) {
do pit_busy_wait(1);
while (termBusy);
termBusy = true;
term.write('A');
termBusy = false;
}
}
extern "C"

@ -33,7 +33,7 @@ void pit_initialize(std::uint32_t frequency)
void pit_busy_wait(std::int32_t tks)
{
const auto end = ticks + tks;
while (end - ticks > 0)
while (static_cast<std::int32_t>(end - ticks) > 0)
asm volatile("nop");
}

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

@ -46,9 +46,11 @@ void VGATerminal::checkpos() noexcept
void VGATerminal::updatecursor() const noexcept
{
asm volatile("cli");
outb(0x03d4, 0x0f);
outb(0x03d5, static_cast<std::uint8_t>(offset));
outb(0x03d4, 0x0e);
outb(0x03d5, static_cast<std::uint8_t>(offset >> 8));
asm volatile("sti");
}

Loading…
Cancel
Save