From 5a4cb04bf63427ca046ea0baf40e9f1b46157049 Mon Sep 17 00:00:00 2001 From: Maxim Baryshnikov Date: Tue, 23 Feb 2016 01:38:50 +0100 Subject: [PATCH] hpet_example: #VMEXIT on memory read solved with map_range(). Legacy interrupts doesn't work. --- inmates/demos/x86/hpet-inmate.c | 45 ++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 17 deletions(-) mode change 100644 => 100755 inmates/demos/x86/hpet-inmate.c diff --git a/inmates/demos/x86/hpet-inmate.c b/inmates/demos/x86/hpet-inmate.c old mode 100644 new mode 100755 index 2b0d10c..03a1795 --- a/inmates/demos/x86/hpet-inmate.c +++ b/inmates/demos/x86/hpet-inmate.c @@ -104,21 +104,21 @@ struct acpi_table *acpi_dup_table(struct acpi_table *rsdt, const char signature[ /** * @brief memory compare * @details [long description] - * + * * @param s1 [description] * @param s2 [description] * @param n [description] */ - typedef unsigned long size_t; +typedef unsigned long size_t; static int memcmp(const void *s1, const void *s2, size_t n) { - const char *p1 = s1; - const char *p2 = s2; - int res = 0; - while (n-- && (res == 0)) { - res = *(p1++) - *(p2++); - } - return res; + const char *p1 = s1; + const char *p2 = s2; + int res = 0; + while (n-- && (res == 0)) { + res = *(p1++) - *(p2++); + } + return res; } @@ -198,6 +198,9 @@ struct acpi_table *acpi_dup_table(struct acpi_table *rsdt, const char signature[ /** * HPET defenitions */ + +#define HPET_BASE_QEMU (0x00000000fed00000ULL) + struct address_structure { u8 address_space_id; // 0 - system memory, 1 - system I/O @@ -412,7 +415,7 @@ static void set_timer_periodic(timer_regs * timer, u64 time) timer->comparator_val = time; enable_main_counter(); } - + static void set_timer_one_shot(timer_regs * timer, u64 time) { if (time < (u64) main_counter_tick_period) { @@ -436,17 +439,23 @@ static void set_legacy_mode(void) //------------------------------------------------------ -static void irq_handler(void) +static void irq_handler0(void) { printk("\nTimer 0 says hi!\n"); } +static void irq_handler1(void) +{ + printk("\nTimer 1 says hi!\n"); +} + static void init_apic(void) { //unsigned long apic_freq_khz; int_init(); - int_set_handler(APIC_TIMER_VECTOR, irq_handler); + int_set_handler(APIC_TIMER_VECTOR, irq_handler0); + int_set_handler(APIC_TIMER_VECTOR+8, irq_handler1); //apic_freq_khz = apic_timer_init(APIC_TIMER_VECTOR); //printk("Calibrated APIC frequency: %lu kHz\n", apic_freq_khz); @@ -488,11 +497,12 @@ void inmate_main(void) // } //gen_reg = (gen_regs *) ( (u64) (*acpi_table)->address_st.base_address); - gen_reg = (gen_regs *) ( (u64) 0x00000003f1ff000ULL); - + gen_reg = (gen_regs *) ( (u64) HPET_BASE_QEMU); + printk("\nBase Address for HPET registers : %p\n", gen_reg); + map_range(gen_reg, PAGE_SIZE, MAP_UNCACHED); + u8 comparators_amount = (gen_reg->capat_id_reg & HPET_NUM_TIM_CAP_MASK) >> HPET_NUM_TIM_CAP_SHIFT; - main_counter_tick_period = gen_reg->clock_period; main_counter_reg = (main_val_reg *) @@ -510,7 +520,7 @@ void inmate_main(void) { timer[n] = (timer_regs *) curr_place; printk("\nTimer %u on: %p, ", n, timer[n]); - printk("Timer comparator : 0x%llx\n", timer[n]->comparator_val); + printk("Timer comparator : %lx\n", timer[n]->comparator_val); } set_legacy_mode(); @@ -520,6 +530,7 @@ void inmate_main(void) set_timer_one_shot( timer[1], NANS_TO_FEMPTS(10000000000ULL) / main_counter_tick_period ); init_apic(); + printk("Done preparation..\n"); //------------------------------------------------------- while (!terminate) { @@ -542,7 +553,7 @@ void inmate_main(void) break; } } -job_done: +//job_done: printk("Stopped APIC demo\n"); comm_region->cell_state = JAILHOUSE_CELL_SHUT_DOWN; -- 2.39.2