aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/lguest/interrupts_and_traps.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/lguest/interrupts_and_traps.c')
-rw-r--r--drivers/lguest/interrupts_and_traps.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/drivers/lguest/interrupts_and_traps.c b/drivers/lguest/interrupts_and_traps.c
index 504091da1737..6e99adbe1946 100644
--- a/drivers/lguest/interrupts_and_traps.c
+++ b/drivers/lguest/interrupts_and_traps.c
@@ -34,7 +34,7 @@ static int idt_type(u32 lo, u32 hi)
34} 34}
35 35
36/* An IDT entry can't be used unless the "present" bit is set. */ 36/* An IDT entry can't be used unless the "present" bit is set. */
37static int idt_present(u32 lo, u32 hi) 37static bool idt_present(u32 lo, u32 hi)
38{ 38{
39 return (hi & 0x8000); 39 return (hi & 0x8000);
40} 40}
@@ -60,7 +60,8 @@ static void push_guest_stack(struct lg_cpu *cpu, unsigned long *gstack, u32 val)
60 * We set up the stack just like the CPU does for a real interrupt, so it's 60 * We set up the stack just like the CPU does for a real interrupt, so it's
61 * identical for the Guest (and the standard "iret" instruction will undo 61 * identical for the Guest (and the standard "iret" instruction will undo
62 * it). */ 62 * it). */
63static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi, int has_err) 63static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi,
64 bool has_err)
64{ 65{
65 unsigned long gstack, origstack; 66 unsigned long gstack, origstack;
66 u32 eflags, ss, irq_enable; 67 u32 eflags, ss, irq_enable;
@@ -184,7 +185,7 @@ void maybe_do_interrupt(struct lg_cpu *cpu)
184 /* set_guest_interrupt() takes the interrupt descriptor and a 185 /* set_guest_interrupt() takes the interrupt descriptor and a
185 * flag to say whether this interrupt pushes an error code onto 186 * flag to say whether this interrupt pushes an error code onto
186 * the stack as well: virtual interrupts never do. */ 187 * the stack as well: virtual interrupts never do. */
187 set_guest_interrupt(cpu, idt->a, idt->b, 0); 188 set_guest_interrupt(cpu, idt->a, idt->b, false);
188 } 189 }
189 190
190 /* Every time we deliver an interrupt, we update the timestamp in the 191 /* Every time we deliver an interrupt, we update the timestamp in the
@@ -244,26 +245,26 @@ void free_interrupts(void)
244/*H:220 Now we've got the routines to deliver interrupts, delivering traps like 245/*H:220 Now we've got the routines to deliver interrupts, delivering traps like
245 * page fault is easy. The only trick is that Intel decided that some traps 246 * page fault is easy. The only trick is that Intel decided that some traps
246 * should have error codes: */ 247 * should have error codes: */
247static int has_err(unsigned int trap) 248static bool has_err(unsigned int trap)
248{ 249{
249 return (trap == 8 || (trap >= 10 && trap <= 14) || trap == 17); 250 return (trap == 8 || (trap >= 10 && trap <= 14) || trap == 17);
250} 251}
251 252
252/* deliver_trap() returns true if it could deliver the trap. */ 253/* deliver_trap() returns true if it could deliver the trap. */
253int deliver_trap(struct lg_cpu *cpu, unsigned int num) 254bool deliver_trap(struct lg_cpu *cpu, unsigned int num)
254{ 255{
255 /* Trap numbers are always 8 bit, but we set an impossible trap number 256 /* Trap numbers are always 8 bit, but we set an impossible trap number
256 * for traps inside the Switcher, so check that here. */ 257 * for traps inside the Switcher, so check that here. */
257 if (num >= ARRAY_SIZE(cpu->arch.idt)) 258 if (num >= ARRAY_SIZE(cpu->arch.idt))
258 return 0; 259 return false;
259 260
260 /* Early on the Guest hasn't set the IDT entries (or maybe it put a 261 /* Early on the Guest hasn't set the IDT entries (or maybe it put a
261 * bogus one in): if we fail here, the Guest will be killed. */ 262 * bogus one in): if we fail here, the Guest will be killed. */
262 if (!idt_present(cpu->arch.idt[num].a, cpu->arch.idt[num].b)) 263 if (!idt_present(cpu->arch.idt[num].a, cpu->arch.idt[num].b))
263 return 0; 264 return false;
264 set_guest_interrupt(cpu, cpu->arch.idt[num].a, 265 set_guest_interrupt(cpu, cpu->arch.idt[num].a,
265 cpu->arch.idt[num].b, has_err(num)); 266 cpu->arch.idt[num].b, has_err(num));
266 return 1; 267 return true;
267} 268}
268 269
269/*H:250 Here's the hard part: returning to the Host every time a trap happens 270/*H:250 Here's the hard part: returning to the Host every time a trap happens
@@ -279,12 +280,12 @@ int deliver_trap(struct lg_cpu *cpu, unsigned int num)
279 * 280 *
280 * This routine indicates if a particular trap number could be delivered 281 * This routine indicates if a particular trap number could be delivered
281 * directly. */ 282 * directly. */
282static int direct_trap(unsigned int num) 283static bool direct_trap(unsigned int num)
283{ 284{
284 /* Hardware interrupts don't go to the Guest at all (except system 285 /* Hardware interrupts don't go to the Guest at all (except system
285 * call). */ 286 * call). */
286 if (num >= FIRST_EXTERNAL_VECTOR && !could_be_syscall(num)) 287 if (num >= FIRST_EXTERNAL_VECTOR && !could_be_syscall(num))
287 return 0; 288 return false;
288 289
289 /* The Host needs to see page faults (for shadow paging and to save the 290 /* The Host needs to see page faults (for shadow paging and to save the
290 * fault address), general protection faults (in/out emulation) and 291 * fault address), general protection faults (in/out emulation) and