Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame^] | 1 | #include "cpu.h" |
| 2 | #include "dlog.h" |
| 3 | #include "irq.h" |
| 4 | #include "vm.h" |
| 5 | |
| 6 | #include "msr.h" |
| 7 | |
| 8 | struct hvc_handler_return { |
| 9 | size_t user_ret; |
| 10 | bool schedule; |
| 11 | }; |
| 12 | |
| 13 | void irq_current(void) |
| 14 | { |
| 15 | dlog("IRQ from current\n"); |
| 16 | for (;;); |
| 17 | } |
| 18 | |
| 19 | void sync_current_exception(uint64_t esr, uint64_t elr) |
| 20 | { |
| 21 | dlog("Exception: esr=%#x, elr=%#x\n", esr, elr); |
| 22 | for (;;); |
| 23 | } |
| 24 | |
| 25 | struct hvc_handler_return hvc_handler(size_t arg1) |
| 26 | { |
| 27 | struct hvc_handler_return ret; |
| 28 | |
| 29 | ret.schedule = true; |
| 30 | |
| 31 | switch (arg1) { |
| 32 | case 0x84000000: /* PSCI_VERSION */ |
| 33 | ret.user_ret = 2; |
| 34 | break; |
| 35 | |
| 36 | case 0x84000006: /* PSCI_MIGRATE */ |
| 37 | ret.user_ret = 2; |
| 38 | break; |
| 39 | |
| 40 | #if 0 |
| 41 | TODO: Remove this. |
| 42 | case 1: /* TODO: Fix. */ |
| 43 | { |
| 44 | extern struct vm vm0; |
| 45 | struct vcpu *vcpu = vm0.vcpus; |
| 46 | vcpu->interrupt = true; |
| 47 | vcpu_ready(vcpu); |
| 48 | dlog("Readying VCPU0 again\n"); |
| 49 | } |
| 50 | ret.user_ret = 0; |
| 51 | break; |
| 52 | #endif |
| 53 | |
| 54 | default: |
| 55 | ret.user_ret = -1; |
| 56 | } |
| 57 | |
| 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | bool sync_lower_exception(uint64_t esr) |
| 62 | { |
| 63 | struct cpu *c = cpu(); |
| 64 | struct vcpu *vcpu = c->current; |
| 65 | |
| 66 | switch (esr >> 26) { |
| 67 | case 0x01: /* EC = 000001, WFI or WFE. */ |
| 68 | /* Check TI bit of ISS. */ |
| 69 | if (esr & 1) |
| 70 | return true; |
| 71 | //vcpu_unready(vcpu); |
| 72 | return true; |
| 73 | |
| 74 | case 0x24: /* EC = 100100, Data abort. */ |
| 75 | dlog("Data abort: pc=0x%x, esr=0x%x, ec=0x%x", vcpu->regs.pc, esr, esr >> 26); |
| 76 | if (!(esr & (1u << 10))) /* Check FnV bit. */ |
| 77 | dlog(", far=0x%x, hpfar=0x%x", read_msr(far_el2), read_msr(hpfar_el2) << 8); |
| 78 | else |
| 79 | dlog(", far=invalid"); |
| 80 | |
| 81 | dlog("\n"); |
| 82 | for (;;); |
| 83 | |
| 84 | default: |
| 85 | dlog("Unknown sync exception pc=0x%x, esr=0x%x, ec=0x%x\n", vcpu->regs.pc, esr, esr >> 26); |
| 86 | for (;;); |
| 87 | } |
| 88 | |
| 89 | /* TODO: For now we always reschedule. But we shoudln't. */ |
| 90 | return true; |
| 91 | } |