From 46447d531e054c190025f9da9693c402ce9172b4 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Fri, 22 Feb 2013 14:42:32 +0100 Subject: [PATCH] nova: add syscall pt_ctrl bindings Issue #667 --- base-nova/include/32bit/nova/syscalls.h | 23 +++++++++++++---- base-nova/include/64bit/nova/syscalls.h | 33 ++++++++++++++++++------ base-nova/include/nova/syscall-generic.h | 7 ++--- base-nova/src/core/platform.cc | 3 +++ 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/base-nova/include/32bit/nova/syscalls.h b/base-nova/include/32bit/nova/syscalls.h index 3ea64d541..9d60918e2 100644 --- a/base-nova/include/32bit/nova/syscalls.h +++ b/base-nova/include/32bit/nova/syscalls.h @@ -67,9 +67,9 @@ namespace Nova { ALWAYS_INLINE - inline uint8_t syscall_1(Syscall s, uint8_t flags, mword_t p1) + inline uint8_t syscall_1(Syscall s, uint8_t flags, unsigned sel, mword_t p1) { - mword_t status = eax(s, flags, 0); + mword_t status = eax(s, flags, sel); asm volatile (" mov %%esp, %%ecx;" " call 0f;" @@ -222,9 +222,22 @@ namespace Nova { ALWAYS_INLINE - inline uint8_t create_pt(unsigned pt, unsigned pd, unsigned ec, Mtd mtd, mword_t eip) + inline uint8_t pt_ctrl(mword_t pt, mword_t pt_id) { - return syscall_4(NOVA_CREATE_PT, 0, pt, pd, ec, mtd.value(), eip); + return syscall_1(NOVA_PT_CTRL, 0, pt, pt_id); + } + + + ALWAYS_INLINE + inline uint8_t create_pt(unsigned pt, unsigned pd, unsigned ec, Mtd mtd, + mword_t eip, bool id_equal_pt = true) + { + uint8_t res = syscall_4(NOVA_CREATE_PT, 0, pt, pd, ec, mtd.value(), eip); + + if (!id_equal_pt || res != NOVA_OK) + return res; + + return pt_ctrl(pt, pt); } @@ -238,7 +251,7 @@ namespace Nova { ALWAYS_INLINE inline uint8_t revoke(Crd crd, bool self = true) { - return syscall_1(NOVA_REVOKE, self, crd.value()); + return syscall_1(NOVA_REVOKE, self, 0, crd.value()); } diff --git a/base-nova/include/64bit/nova/syscalls.h b/base-nova/include/64bit/nova/syscalls.h index 2ad00646a..6a87c7132 100644 --- a/base-nova/include/64bit/nova/syscalls.h +++ b/base-nova/include/64bit/nova/syscalls.h @@ -62,9 +62,10 @@ namespace Nova { ALWAYS_INLINE - inline uint8_t syscall_1(Syscall s, uint8_t flags, mword_t p1, mword_t * p2 = 0) + inline uint8_t syscall_1(Syscall s, uint8_t flags, mword_t sel, mword_t p1, + mword_t * p2 = 0) { - mword_t status = rdi(s, flags, 0); + mword_t status = rdi(s, flags, sel); asm volatile ("syscall" : "+D" (status), "+S" (p1) @@ -76,7 +77,8 @@ namespace Nova { ALWAYS_INLINE - inline uint8_t syscall_2(Syscall s, uint8_t flags, mword_t sel, mword_t p1, mword_t p2) + inline uint8_t syscall_2(Syscall s, uint8_t flags, mword_t sel, mword_t p1, + mword_t p2) { mword_t status = rdi(s, flags, sel); @@ -183,9 +185,22 @@ namespace Nova { ALWAYS_INLINE - inline uint8_t create_pt(mword_t pt, mword_t pd, mword_t ec, Mtd mtd, mword_t rip) + inline uint8_t pt_ctrl(mword_t pt, mword_t pt_id) { - return syscall_4(NOVA_CREATE_PT, 0, pt, pd, ec, mtd.value(), rip); + return syscall_1(NOVA_PT_CTRL, 0, pt, pt_id); + } + + + ALWAYS_INLINE + inline uint8_t create_pt(mword_t pt, mword_t pd, mword_t ec, Mtd mtd, + mword_t rip, bool id_equal_pt = true) + { + uint8_t res = syscall_4(NOVA_CREATE_PT, 0, pt, pd, ec, mtd.value(), rip); + + if (!id_equal_pt || res != NOVA_OK) + return res; + + return pt_ctrl(pt, pt); } @@ -199,7 +214,7 @@ namespace Nova { ALWAYS_INLINE inline uint8_t revoke(Crd crd, bool self = true) { - return syscall_1(NOVA_REVOKE, self, crd.value()); + return syscall_1(NOVA_REVOKE, self, 0, crd.value()); } @@ -207,7 +222,7 @@ namespace Nova { inline uint8_t lookup(Crd &crd) { mword_t crd_r; - uint8_t res=syscall_1(NOVA_LOOKUP, 0, crd.value(), &crd_r); + uint8_t res = syscall_1(NOVA_LOOKUP, 0, 0, crd.value(), &crd_r); crd = Crd(crd_r); return res; } @@ -243,8 +258,10 @@ namespace Nova { return syscall_2(NOVA_ASSIGN_PCI, 0, pd, mem, rid); } + ALWAYS_INLINE - inline uint8_t assign_gsi(mword_t sm, mword_t dev, mword_t cpu, mword_t &msi_addr, mword_t &msi_data) + inline uint8_t assign_gsi(mword_t sm, mword_t dev, mword_t cpu, + mword_t &msi_addr, mword_t &msi_data) { msi_addr = dev; msi_data = cpu; diff --git a/base-nova/include/nova/syscall-generic.h b/base-nova/include/nova/syscall-generic.h index 079d397ee..40a96f7cd 100644 --- a/base-nova/include/nova/syscall-generic.h +++ b/base-nova/include/nova/syscall-generic.h @@ -59,9 +59,10 @@ namespace Nova { NOVA_LOOKUP = 0x8, NOVA_EC_CTRL = 0x9, NOVA_SC_CTRL = 0xa, - NOVA_SM_CTRL = 0xb, - NOVA_ASSIGN_PCI = 0xc, - NOVA_ASSIGN_GSI = 0xd, + NOVA_PT_CTRL = 0xb, + NOVA_SM_CTRL = 0xc, + NOVA_ASSIGN_PCI = 0xd, + NOVA_ASSIGN_GSI = 0xe, }; /** diff --git a/base-nova/src/core/platform.cc b/base-nova/src/core/platform.cc index bcdbb9e89..2713f29ba 100644 --- a/base-nova/src/core/platform.cc +++ b/base-nova/src/core/platform.cc @@ -205,6 +205,9 @@ Platform::Platform() : _vm_base(0x1000), _vm_size(0) { Hip *hip = (Hip *)__initial_sp; + /* check for right API version */ + if (hip->api_version != 6) + nova_die(); /* register UTCB of main thread */ __main_thread_utcb = (Utcb *)(__initial_sp - get_page_size());