Page Table Cloning Frustration
Posted: Fri Nov 04, 2011 5:05 pm
My page table cloning functions just clearly do not work. The first page table will be mapped, but go beyond that and the emulator will triple fault (at least according to my observation). So I guess I'm going to post some code and let you help me figure out where the problem is.
First, my bochs error log:
Then my CloneTable function:
copy_page_phys code.
If you could help me, that would be very much appreciated.
First, my bochs error log:
Code: Select all
...
01131409938i[CPU0 ] CPU is in protected mode (active)
01131409938i[CPU0 ] CS.d_b = 32 bit
01131409938i[CPU0 ] SS.d_b = 32 bit
01131409938i[CPU0 ] EFER = 0x00000000
01131409938i[CPU0 ] | RAX=0000000000400000 RBX=0000000000400000
01131409938i[CPU0 ] | RCX=0000000002805000 RDX=00000000e0000011
01131409938i[CPU0 ] | RSP=00000000dfffff54 RBP=00000000dfffff88
01131409938i[CPU0 ] | RSI=0000000000401000 RDI=0000000002806000
01131409938i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
01131409938i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
01131409938i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
01131409938i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
01131409938i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf af PF cf
01131409938i[CPU0 ] | SEG selector base limit G D
01131409938i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
01131409938i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
01131409938i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
01131409938i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
01131409938i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
01131409938i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
01131409938i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
01131409938i[CPU0 ] | MSR_FS_BASE:0000000000000000
01131409938i[CPU0 ] | MSR_GS_BASE:0000000000000000
01131409938i[CPU0 ] | RIP=0000000000100331 (0000000000100331)
01131409938i[CPU0 ] | CR0=0xe0000011 CR2=0x00000000dfffff50
01131409938i[CPU0 ] | CR3=0x0011f000 CR4=0x00000000
01131409938i[CPU0 ] 0x0000000000100331>> popfd : 9D
01131409938e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
01131409938i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
01131409938i[CPU0 ] cpu hardware reset
01131409938i[APIC0] allocate APIC id=0 (MMIO enabled) to 0xfee00000
01131409938i[CPU0 ] CPUID[0x00000000]: 00000003 756e6547 6c65746e 49656e69
01131409938i[CPU0 ] CPUID[0x00000001]: 00000f20 00000800 00002000 078bfbff
01131409938i[CPU0 ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000
01131409938i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
01131409938i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000
01131409938i[CPU0 ] CPUID[0x80000000]: 80000008 00000000 00000000 00000000
01131409938i[CPU0 ] CPUID[0x80000001]: 00000000 00000000 00000101 2a100800
01131409938i[CPU0 ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020
01131409938i[CPU0 ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75
01131409938i[CPU0 ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020
01131409938i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000
01131409938i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000
01131409938i[CPU0 ] CPUID[0x80000008]: 00003020 00000000 00000000 00000000
01131409938i[PLGIN] reset of 'unmapped' plugin device by virtual method
01131409938i[PLGIN] reset of 'biosdev' plugin device by virtual method
01131409938i[PLGIN] reset of 'speaker' plugin device by virtual method
01131409938i[PLGIN] reset of 'extfpuirq' plugin device by virtual method
01131409938i[PLGIN] reset of 'gameport' plugin device by virtual method
01131409938i[PLGIN] reset of 'pci_ide' plugin device by virtual method
01131409938i[PLGIN] reset of 'acpi' plugin device by virtual method
01131409938i[PLGIN] reset of 'ioapic' plugin device by virtual method
01131409938i[PLGIN] reset of 'keyboard' plugin device by virtual method
01131409938i[PLGIN] reset of 'harddrv' plugin device by virtual method
01131409938i[PLGIN] reset of 'serial' plugin device by virtual method
01131409938i[PLGIN] reset of 'parallel' plugin device by virtual method
01131413244i[BIOS ] $Revision: 1.247 $ $Date: 2010/04/04 19:33:50 $
01131728057i[KBD ] reset-disable command received
01131852371i[VBIOS]
VGABios $Id$
...
Code: Select all
static PageTable* CloneTable(PageTable* src, UInt32* phys) {
#ifdef PAGING_TRACE
kprintf("CloneTable(%x,%x)\n", src, phys);
#endif
PageTable* table = (PageTable*)kmalloc_ap(sizeof(PageTable), true, phys);
memset(table, 0, sizeof(PageTable));
int i;
for(i=0; i<1024; i++) {
// If its 0, continue.
if(!(src->t[i]&0xFFFFF000)) {
continue;
}
// Allocate a new page.
int ip = alloc_frame();
// Map the page into the table
Pointer phys_addr = (Pointer)(ip*0x1000);
table->t[i] = AssemblePTE(phys_addr, (src->t[i]&(0xFFF)));
// Copy the contents of one frame to another. physical addresses only, please.
copy_page_phys((src->t[i]&0xFFFFF000), (table->t[i]&0xFFFFF000));
}
return table;
}
Code: Select all
copy_page_phys:
push ebx
pushf
cli
mov ebx, [esp+12]
mov ecx, [esp+16]
mov edx, cr0
and edx, 0x7fffffff
mov cr0, edx
mov edx, 1024
mov esi, ebx
mov edi, ecx
; ecx = ebx
.loop:
movsd
dec edx
jnz .loop
mov edx, cr0
or edx, 0x80000000
mov cr0, edx
popf
pop ebx
ret