...
 
Commits (3)
......@@ -12,8 +12,8 @@ _start:
.align 4
multiboot_header:
.long 0x1BADB002
.long 0x00010003
.long -(0x1BADB002+0x00010003)
.long 0x00010005
.long -(0x1BADB002+0x00010005)
.long multiboot_header
.long __text_start__
......@@ -21,6 +21,7 @@ multiboot_header:
.long __bss_end__ + 0x80000
.long multiboot_entry
.long 0, 800, 600, 8
multiboot_entry:
cli
......
......@@ -3,6 +3,7 @@
#include "kernlib.hpp"
#include "efi.hpp"
#include "multiboot_info.hpp"
#include "pagetable.hpp"
#include "font-8x16.hpp"
......@@ -203,6 +204,16 @@ void Display::setup() {
instance = new FramebufferDisplay(fb->base, fb->width, fb->height, pixelFormat);
return;
}
const struct Multiboot::Payload *mb = Multiboot::getPayload();
if (mb && (mb->flags & Multiboot::FLAG_VBETAB)) {
const Multiboot::VBEModeInfo *mode = reinterpret_cast<const Multiboot::VBEModeInfo*>(mb->vbe.pmode_info);
if (mode && mode->lfb_ptr) {
instance = new FramebufferDisplay(
reinterpret_cast<void*>(mode->lfb_ptr),
mode->h_res, mode->v_res, PixelFormatBGRX);
return;
}
}
// Fallback
instance = new ConsoleDisplay();
......
......@@ -348,6 +348,18 @@ void Pagetable::init() {
mmap += ent->size + sizeof(ent->size);
}
}
if (multiboot->flags & Multiboot::FLAG_VBETAB) {
if (multiboot->vbe.pcontrol_info < 0x80000)
multiboot->vbe.pcontrol_info += bss_end;
if (multiboot->vbe.pmode_info < 0x80000)
multiboot->vbe.pmode_info += bss_end;
Multiboot::VBEInfo *vbe = reinterpret_cast<Multiboot::VBEInfo*>(multiboot->vbe.pcontrol_info);
map(vbe); map(vbe+1);
const char *vendor = reinterpret_cast<const char*>(vbe->vendor_string);
map(vendor);
Multiboot::VBEModeInfo *mode = reinterpret_cast<Multiboot::VBEModeInfo*>(multiboot->vbe.pmode_info);
map(mode); map(mode + 1);
}
}
}
......
......@@ -17,11 +17,14 @@ static void syscall_puts(uintptr_t strptr) {
static void syscall_exit(int code) {
ProcessManager *manager = ProcessManager::getManager();
Process *process = manager->currentProcess();
void *rsp; asm volatile("mov %%rsp, %q0; and $~0xFFF, %q0":"=r"(rsp));
Pagetable::Entry *pt; asm volatile("mov %%cr3, %q0":"=r"(pt));
Pagetable::Entry *pte = Pagetable::Entry::find(rsp, pt);
asm volatile(
"callq _ZN7Process4exitEi;"
"sti;"
"sti; movq $0, %q2;"
"jmp _ZN14ProcessManager12process_loopEv"
::"D"(process), "S"(code)
::"D"(process), "S"(code), "a"(pte)
);
}
......
......@@ -16,6 +16,7 @@ Process::Process() {
_aslrStack = RAND::get<uintptr_t>(0x40000000llu, 0x80000000llu) << 12;
}
Process::~Process() {
void *rsp; asm volatile("mov %%rsp, %q0; and $~0xFFF, %q0":"=r"(rsp));
if (pagetable != nullptr) {
PTE addr;
for (uintptr_t ptx = 0; ptx < 512; ptx++) {
......@@ -38,10 +39,11 @@ Process::~Process() {
if (!addr.present)
continue;
void *page = addr.getPtr();
if (uintptr_t(page) == ((ptx << (12 + 9 + 9 + 9))
uintptr_t ptaddr = ((ptx << (12 + 9 + 9 + 9))
| (pdx << (12 + 9 + 9))
| (pdpx << (12 + 9)) | (pml4x << (12))))
continue;
| (pdpx << (12 + 9)) | (pml4x << (12)));
if (page == rsp) continue;
if (uintptr_t(page) == ptaddr) continue;
Pagetable::free(page);
}
Pagetable::free(ppml4e);
......@@ -251,11 +253,11 @@ void Process::startup() {
static const uintptr_t KB4 = 0xFFFFFFFFFFFFF000;
for (uintptr_t addr = uintptr_t(gdt.addr) & KB4;
addr < (uintptr_t(gdt.addr) + gdt.limit); addr += 0x1000) {
addPage(addr, reinterpret_cast<void*>(addr), 5);
addPage(addr, reinterpret_cast<void*>(addr), 1);
}
for (uintptr_t addr = uintptr_t(idt.addr) & KB4;
addr < (uintptr_t(idt.addr) + idt.limit); addr += 0x1000) {
addPage(addr, reinterpret_cast<void*>(addr), 5);
addPage(addr, reinterpret_cast<void*>(addr), 1);
}
Interrupts::REC64 *recs = static_cast<Interrupts::REC64*>(idt.addr);
uintptr_t page = 0;
......@@ -265,7 +267,7 @@ void Process::startup() {
| (uintptr_t(recs[i].offset_high) << 32));
if (page != (handler & KB4)) {
page = handler & KB4;
addPage(page, reinterpret_cast<void*>(page), 5);
addPage(page, reinterpret_cast<void*>(page), 1);
}
}
uintptr_t handler, sc_wrapper;
......@@ -273,8 +275,8 @@ void Process::startup() {
asm volatile("lea _ZN7Syscall7wrapperEv(%%rip), %q0":"=r"(sc_wrapper));
handler &= KB4;
sc_wrapper &= KB4;
addPage(handler, reinterpret_cast<void*>(handler), 5);
addPage(sc_wrapper, reinterpret_cast<void*>(sc_wrapper), 5);
addPage(handler, reinterpret_cast<void*>(handler), 1);
addPage(sc_wrapper, reinterpret_cast<void*>(sc_wrapper), 1);
GDT::Entry *gdt_ent = reinterpret_cast<GDT::Entry*>(uintptr_t(gdt.addr) + 8 * 3);
GDT::Entry *gdt_top = reinterpret_cast<GDT::Entry*>(uintptr_t(gdt.addr) + gdt.limit);
......@@ -299,14 +301,14 @@ void Process::startup() {
base = sysent->getBase();
uintptr_t page = base & KB4;
addPage(page, reinterpret_cast<void*>(page), 5);
addPage(page + 0x1000, iomap[0], 5);
addPage(page + 0x2000, iomap[1], 5);
addPage(page, reinterpret_cast<void*>(page), 1);
addPage(page + 0x1000, iomap[0], 1);
addPage(page + 0x2000, iomap[1], 1);
TSS64_ENT *tss = reinterpret_cast<TSS64_ENT*>(base);
uintptr_t stack = tss->ist[0];
page = stack - 0x1000;
addPage(page, reinterpret_cast<void*>(page), 5);
addPage(page, reinterpret_cast<void*>(page), 3);
gdt_ent = reinterpret_cast<GDT::Entry*>(sysent + 1);
}
......