1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/*
* plex86: run multiple x86 operating systems concurrently
* Copyright (C) 1999-2001 Kevin P. Lawton
*
* io_pro.c: IO protection mechanisms.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "plex86.h"
#include "monitor.h"
void
IOPermCheck(vm_t *vm, Bit32u port, unsigned len)
{
if ( vm->guest_cpu.cr0.fields.pe &&
(vm->guest_cpu.veflags.fields.vm ||
(G_CPL(vm) > G_GetIOPL(vm))) ) {
Bit16u io_base, permission16;
unsigned bit_index, i;
if ( (vm->guest_cpu.tr_cache.valid==0) ||
(vm->guest_cpu.tr_cache.desc.type!=9) ) {
monpanic(vm, "IOPermCheck: TR not valid 32bit TSS\n");
goto no_permission;
}
if (vm->guest_cpu.tr_cache.limit_scaled < 103) {
monpanic(vm, "IOPermCheck: TR.limit < 103\n");
}
access_linear(vm, vm->guest_cpu.tr_cache.base + 102, 2, 0, OP_READ,
&io_base);
if (io_base <= 103) {
monpanic(vm, "IOPermCheck: TR:io_base <= 103\n");
}
if (io_base > vm->guest_cpu.tr_cache.limit_scaled) {
monprint(vm, "IOPermCheck: CPL > IOPL: no IO bitmap defined #GP(0)\n");
goto no_permission;
}
access_linear(vm, vm->guest_cpu.tr_cache.base + io_base + port/8,
2, 0, OP_READ, &permission16);
bit_index = port & 0x07;
permission16 >>= bit_index;
for (i=0; i<len; i++) {
if (permission16 & 0x01)
goto no_permission;
permission16 >>= 1;
}
}
return;
no_permission:
exception(vm, ExceptionGP, 0);
}
|