i have a problem with my paging setup.
i used this tutorial, too.
but when i call the paging_install() funktion, bochs crashes.
here is my code:00016344393-e-@0000071a-[CPU0 ] interrupt(): gate descriptor is not valid sys seg
00016344393-e-@0000071a-[CPU0 ] interrupt(): gate descriptor is not valid sys seg
00016344393-i-@0000071a-[CPU0 ] protected mode
00016344393-i-@0000071a-[CPU0 ] CS.d_b = 32 bit
00016344393-i-@0000071a-[CPU0 ] SS.d_b = 32 bit
00016344393-i-@0000071a-[CPU0 ] | EAX=80000011 EBX=00000400 ECX=00000000 EDX=00000000
00016344393-i-@0000071a-[CPU0 ] | ESP=000104c7 EBP=000104c7 ESI=003f6000 EDI=00000010
00016344393-i-@0000071a-[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf af PF cf
00016344393-i-@0000071a-[CPU0 ] | SEG selector base limit G D
00016344393-i-@0000071a-[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00016344393-i-@0000071a-[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00016344393-i-@0000071a-[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00016344393-i-@0000071a-[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00016344393-i-@0000071a-[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00016344393-i-@0000071a-[CPU0 ] | FS:0000( 0000| 0| 0) 000ffff0 0000ffff 0 0
00016344393-i-@0000071a-[CPU0 ] | GS:0000( 0000| 0| 0) 00000000 0000ffff 0 0
00016344393-i-@0000071a-[CPU0 ] | EIP=0000071a (0000071a)
00016344393-i-@0000071a-[CPU0 ] | CR0=0x80000011 CR1=0 CR2=0x80000011
00016344393-i-@0000071a-[CPU0 ] | CR3=0x00120000 CR4=0x00000000
00016344393-i-@0000071a-[CPU0 ] >> add byte ptr ds:[eax], al : 0000
00016344393-e-@0000071a-[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
paging.h
Code: Select all
#ifndef __PAGING_H_
#define __PAGING_H_
/* ***************************************************************************** */
typedef struct _PageTableEntry { /* */
unsigned int present : 1; /* */
unsigned int read_write : 1; /* */
unsigned int level : 1; /* */
unsigned int reserved_1 : 2; /* */
unsigned int accessed : 1; /* */
unsigned int dirty : 1; /* */
unsigned int reserved_2 : 2; /* */
unsigned int available : 3; /* */
unsigned int address :20; /* */
} PageTableEntry, *pPageTableEntry;
/* ***************************************************************************** */
#define PAGE_NOT_PRESENT 0x00
#define PAGE_READ 0x00
#define PAGE_LEVEL_SUPERVISOR 0x00
#define PAGE_PRESENT 0x01
#define PAGE_READ_AND_WRITE 0x01
#define PAGE_LEVEL_USER 0x01
/* ***************************************************************************** */
pPageTableEntry PageDirectory;
pPageTableEntry PageTable;
/* ***************************************************************************** */
void paging_install();
void CreatePageTableEntry( unsigned int num, unsigned long address, unsigned int level,
unsigned int read_write, unsigned int present, unsigned int available );
void CreatePageDirectoryEntry( unsigned int num, unsigned long address, unsigned int level,
unsigned int read_write, unsigned int present, unsigned int available );
/* ***************************************************************************** */
#endif
Code: Select all
#include "paging.h"
/* ***************************************************************************** */
// pPageTableEntry PageDirectory = (pPageTableEntry) 0x00120000;
// pPageTableEntry PageTable = (pPageTableEntry) 0x00120100;
/* ***************************************************************************** */
void paging_install() {
unsigned long tmp_address = 0;
unsigned int i;
PageDirectory = (pPageTableEntry) 0x00120000;
PageTable = (pPageTableEntry) 0x00121000;
// map the first 4MB of memory
for( i; i < 1024; i++, tmp_address += 4096 ) {
CreatePageTableEntry( i,
tmp_address,
PAGE_LEVEL_SUPERVISOR,
PAGE_READ_AND_WRITE,
PAGE_PRESENT,
0 );
}
CreatePageDirectoryEntry( 0,
(unsigned long) PageTable,
PAGE_LEVEL_SUPERVISOR,
PAGE_READ_AND_WRITE,
PAGE_PRESENT,
0 );
for( i=1; i < 1024; i++ ) {
CreatePageDirectoryEntry( i,
0,
PAGE_LEVEL_SUPERVISOR,
PAGE_READ_AND_WRITE,
PAGE_NOT_PRESENT,
0 );
};
write_cr3( (unsigned long) PageDirectory );
write_cr0( read_cr0() | 0x80000000 );
}
/* ***************************************************************************** */
void CreatePageTableEntry( unsigned int num,
unsigned long address,
unsigned int level,
unsigned int read_write,
unsigned int present,
unsigned int available ) {
PageTable[num].address = (address & 0x0FFFFF);
PageTable[num].level = (level & 0x000001);
PageTable[num].read_write = (read_write & 0x000001);
PageTable[num].present = (present & 0x000001);
PageTable[num].available = (available & 0x000007);
}
/* ***************************************************************************** */
void CreatePageDirectoryEntry( unsigned int num,
unsigned long address,
unsigned int level,
unsigned int read_write,
unsigned int present,
unsigned int available ) {
PageDirectory[num].address = (address & 0x0FFFFF);
PageDirectory[num].level = (level & 0x000001);
PageDirectory[num].read_write = (read_write & 0x000001);
PageDirectory[num].present = (present & 0x000001);
PageDirectory[num].available = (available & 0x000007);
}
/* ***************************************************************************** */
but wheres my error?
could the pagedirectory or pagetable address
be unvalid?
thanks
Uni_Sol