summaryrefslogtreecommitdiff
path: root/kernel/src/arch
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/arch')
-rw-r--r--kernel/src/arch/x86_64/assembly.hpp20
-rw-r--r--kernel/src/arch/x86_64/drivers/pci.cpp3
-rw-r--r--kernel/src/arch/x86_64/drivers/tsc.cpp7
-rw-r--r--kernel/src/arch/x86_64/panic.cpp12
-rw-r--r--kernel/src/arch/x86_64/x86_64.cpp2
5 files changed, 37 insertions, 7 deletions
diff --git a/kernel/src/arch/x86_64/assembly.hpp b/kernel/src/arch/x86_64/assembly.hpp
index e030e84..c1659fd 100644
--- a/kernel/src/arch/x86_64/assembly.hpp
+++ b/kernel/src/arch/x86_64/assembly.hpp
@@ -1,5 +1,6 @@
#pragma once
#include <cstdint>
+#include <klibc/string.hpp>
namespace assembly {
inline static std::uint64_t rdmsr(std::uint32_t msr) {
@@ -28,4 +29,23 @@ namespace assembly {
__asm__ volatile ("rdtsc" : "=a"(lo), "=d"(hi));
return ((uint64_t)hi << 32) | lo;
}
+
+ inline static bool is_qemu() {
+ uint32_t a,b,c,d;
+
+ cpuid(0x40000000, 0, &a, &b, &c, &d);
+
+ char hypervisorSignature[13];
+ ((uint32_t *)hypervisorSignature)[0] = b;
+ ((uint32_t *)hypervisorSignature)[1] = c;
+ ((uint32_t *)hypervisorSignature)[2] = d;
+ hypervisorSignature[12] = '\0';
+
+ if (klibc::memcmp(hypervisorSignature, (void*)"TCGTCGTCGTCG", 12) == 0 || klibc::memcmp(hypervisorSignature, (void*)"KVMKVMKVM\0\0\0", 12) == 0) {
+ return true;
+ }
+
+ return false;
+ }
+
}; \ No newline at end of file
diff --git a/kernel/src/arch/x86_64/drivers/pci.cpp b/kernel/src/arch/x86_64/drivers/pci.cpp
index 88d5f36..db259f8 100644
--- a/kernel/src/arch/x86_64/drivers/pci.cpp
+++ b/kernel/src/arch/x86_64/drivers/pci.cpp
@@ -2,6 +2,7 @@
#include <cstdint>
pci_driver_t pci_drivers[256];
+int last_pci_drv = 0;
pci_t __pci_load(std::uint8_t bus, std::uint8_t num, std::uint8_t function) {
pci_t pciData;
@@ -19,6 +20,7 @@ void x86_64::pci::reg(void (*pcidrv)(pci_t, std::uint8_t, std::uint8_t, std::uin
pci_drivers[i]._class = _class;
pci_drivers[i].subclass = subclass;
pci_drivers[i].pcidrv = pcidrv;
+ return;
}
}
}
@@ -27,7 +29,6 @@ void __pci_launch(pci_t pci, std::uint8_t bus, std::uint8_t device, std::uint8_t
for (std::uint16_t i = 0; i < 256; i++) {
if (pci_drivers[i].used && pci_drivers[i]._class == pci._class && pci_drivers[i].subclass == pci.subclass) {
pci_drivers[i].pcidrv(pci, bus, device, function);
- return;
}
}
}
diff --git a/kernel/src/arch/x86_64/drivers/tsc.cpp b/kernel/src/arch/x86_64/drivers/tsc.cpp
index 4203d76..f381173 100644
--- a/kernel/src/arch/x86_64/drivers/tsc.cpp
+++ b/kernel/src/arch/x86_64/drivers/tsc.cpp
@@ -14,10 +14,17 @@ static inline uint64_t rdtsc() {
return ((uint64_t)hi << 32) | lo;
}
+bool is_disabled_tsc = false;
+
void drivers::tsc::init() {
+ if(is_disabled_tsc == true)
+ return;
+
if(time::timer == nullptr) {
log("tsc", "can't initialize without timer !");
+ is_disabled_tsc = true;
+ return;
}
uint64_t tsc_start, tsc_end;
diff --git a/kernel/src/arch/x86_64/panic.cpp b/kernel/src/arch/x86_64/panic.cpp
index df923df..ba59a38 100644
--- a/kernel/src/arch/x86_64/panic.cpp
+++ b/kernel/src/arch/x86_64/panic.cpp
@@ -18,14 +18,14 @@ void print_regs(x86_64::idt::int_frame_t* ctx) {
ctx->rsp, cr2, ctx->cr3, ctx->vec, ctx->err_code, ctx->cs,ctx->ss);
klibc::printf("\n\r Stacktrace\n\r\n\r");
- stackframe_t* rbp = (stackframe_t*)ctx->rbp;
+ //stackframe_t* rbp = (stackframe_t*)ctx->rbp;
klibc::printf("[0] - 0x%016llX (current rip)\n\r",ctx->rip);
- for (int i = 1; i < 5 && rbp; ++i) {
- std::uint64_t ret_addr = rbp->rip;
- klibc::printf("[%d] - 0x%016llX\n\r", i, ret_addr);
- rbp = (stackframe_t*)rbp->rbp;
- }
+ // for (int i = 1; i < 5 && rbp; ++i) {
+ // std::uint64_t ret_addr = rbp->rip;
+ // klibc::printf("[%d] - 0x%016llX\n\r", i, ret_addr);
+ // rbp = (stackframe_t*)rbp->rbp;
+ // }
}
diff --git a/kernel/src/arch/x86_64/x86_64.cpp b/kernel/src/arch/x86_64/x86_64.cpp
index 1389351..7653346 100644
--- a/kernel/src/arch/x86_64/x86_64.cpp
+++ b/kernel/src/arch/x86_64/x86_64.cpp
@@ -16,6 +16,7 @@
#include <utils/gobject.hpp>
#include <arch/x86_64/cpu/sse.hpp>
#include <arch/x86_64/drivers/pvclock.hpp>
+#include <utils/assert.hpp>
namespace arch {
[[gnu::weak]] void disable_interrupts() {
@@ -74,6 +75,7 @@ namespace arch {
drivers::hpet::init();
drivers::tsc::init();
drivers::pvclock::bsp_init();
+ assert(time::timer != nullptr, "can't init orange without timer !");
x86_64::gdt::init();
x86_64::idt::init();
x86_64::lapic::init(1500);