Get super basic ring3 task switching working

* It looks like UEFI enables SSE, so we need to tell clang -mno-sse for
  now to not use XMM* until we're ready to save them.
* SYSCALL is working from ring3 tasks, calling console printf!
This commit is contained in:
Justin C. Miller
2018-05-21 01:00:34 -07:00
parent e6f819ed90
commit 2597e2002b
4 changed files with 19 additions and 57 deletions

View File

@@ -113,7 +113,6 @@ print_stacktrace(int skip = 0)
addr_t addr_t
isr_handler(addr_t return_rsp, cpu_state regs) isr_handler(addr_t return_rsp, cpu_state regs)
{ {
log::debug(logs::task, "Starting RSP %016lx", return_rsp);
console *cons = console::get(); console *cons = console::get();
switch (static_cast<isr>(regs.interrupt & 0xff)) { switch (static_cast<isr>(regs.interrupt & 0xff)) {
@@ -284,10 +283,8 @@ isr_handler(addr_t return_rsp, cpu_state regs)
print_stacktrace(2); print_stacktrace(2);
while(1) asm("hlt"); while(1) asm("hlt");
} }
*reinterpret_cast<uint32_t *>(0xffffff80fee000b0) = 0; *reinterpret_cast<uint32_t *>(0xffffff80fee000b0) = 0;
log::debug(logs::task, "Returning RSP %016lx", return_rsp);
return return_rsp; return return_rsp;
} }

View File

@@ -80,19 +80,10 @@ gdt_load:
pop rax pop rax
%endmacro %endmacro
%macro load_kernel_segments 0
mov ax, 0x10 ; load the kernel data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
%endmacro
extern isr_handler extern isr_handler
global isr_handler_prelude global isr_handler_prelude
isr_handler_prelude: isr_handler_prelude:
push_all_and_segments push_all_and_segments
;load_kernel_segments
mov rdi, rsp mov rdi, rsp
call isr_handler call isr_handler
@@ -108,7 +99,6 @@ extern irq_handler
global irq_handler_prelude global irq_handler_prelude
irq_handler_prelude: irq_handler_prelude:
push_all_and_segments push_all_and_segments
load_kernel_segments
call irq_handler call irq_handler
@@ -205,45 +195,18 @@ global taskA
taskA: taskA:
push rbp push rbp
mov rbp, rsp mov rbp, rsp
push 0x123456789abcdef0 mov rax, 0xaaaaaaaaaaaaaaaa
push 0x0fedcba987654321
.loop:
syscall
jmp .loop
global taskB
taskB:
push rbp
mov rbp, rsp
mov rax, 0xbbbbbbbbbbbbbbbb
.loop: .loop:
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
syscall syscall
nop
nop
nop
nop
nop
nop
jmp .loop jmp .loop

View File

@@ -18,11 +18,7 @@ char taskBstack3[stack_size];
uint64_t taskAcount = 0; uint64_t taskAcount = 0;
extern "C" void taskA(); extern "C" void taskA();
extern "C" void taskB();
void taskB()
{
while (1);
}
scheduler::scheduler(lapic *apic) : scheduler::scheduler(lapic *apic) :
@@ -68,6 +64,8 @@ create_process(uint16_t pid, void *stack0, void *stack3, void (*rip)())
void void
scheduler::start() scheduler::start()
{ {
log::info(logs::task, "Starting scheduler.");
m_apic->enable_timer(isr::isrTimer, 128, quantum, false); m_apic->enable_timer(isr::isrTimer, 128, quantum, false);
m_processes.append({0, 0}); // The kernel idle task m_processes.append({0, 0}); // The kernel idle task

View File

@@ -29,7 +29,11 @@ def build(bld):
return node.path_from(node.ctx.launch_node()) return node.path_from(node.ctx.launch_node())
def run(self): def run(self):
from subprocess import check_output from subprocess import check_output
args = self.env.objdump + ["--source", "-D", self.inputs[0].abspath()] args = self.env.objdump + [
"--source",
"-D",
"-M", "intel",
self.inputs[0].abspath()]
with file(self.outputs[0].abspath(), 'w') as output: with file(self.outputs[0].abspath(), 'w') as output:
output.write(check_output(args)) output.write(check_output(args))