bochs log:
EFER = 0x00000000
00096181687i[CPU0 ] | EAX=e0000011 EBX=00010000 ECX=0010f000 EDX=00008a00
00096181687i[CPU0 ] | ESP=0010a9cc EBP=00000000 ESI=00000000 EDI=00000000
00096181687i[CPU0 ] | IOPL=0 ID vip vif ac vm RF nt of df if tf sf zf af PF cf
00096181687i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00096181687i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
00096181687i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00096181687i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00096181687i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00096181687i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00096181687i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00096181687i[CPU0 ] | EIP=00101f53 (00101f53)
00096181687i[CPU0 ] | CR0=0xe0000011 CR2=0x00000000
00096181687i[CPU0 ] | CR3=0x00105980 CR4=0x00000000
00096181687e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
paging code
paging.c
Code: Select all
#define PAGE_DIRECTORY_INDEX(x) (((x) >> 22) & 0x3ff)
#define PAGE_TABLE_INDEX(x) (((x) >> 12) & 0x3ff)
#define PAGE_GET_PHYSICAL_ADDRESS(x) (*x & ~0xfff)
extern set_page_dir(void);
extern enable_paging(void);
page_dir p_dir;
void init_virtual_memory(uint32_t kernel_end){
printf("%X ",&p_dir);
memset(&p_dir, 0, 4096);
for (int i = 0;i<1024;i++){
page_table *table = (page_table *) alloc_block();
memset(table, 0, 4096);
p_dir[i].address = (uint32_t) table;
p_dir[i].rw = 1;
p_dir[i].present = 1;
}
for (int i = 0;i < kernel_end;i += PAGE_SIZE){
map_page(i,i);
}
set_page_dir();
write_port_w(0x8A00,0x8A00); write_port_w(0x8A00,0x08AE0);
enable_paging();
}
void map_page(uint32_t v,uint32_t p){
page_table *table = (p_dir[PAGE_DIRECTORY_INDEX(v)].address);
table[PAGE_TABLE_INDEX(v)]->address = p;
table[PAGE_TABLE_INDEX(v)]->present = 1;
table[PAGE_TABLE_INDEX(v)]->rw = 1;
}
Code: Select all
//! page sizes are 4k
#define PAGE_SIZE 4096
typedef struct page_dir_entry_s{
uint32_t present :1;
uint32_t rw :1;
uint32_t privl :1;
uint32_t write_through :1;
uint32_t cache_disable :1;
uint32_t accessed :1;
uint32_t dirty :1;
uint32_t zero :1;
uint32_t ignored :1;
uint32_t free :3;
uint32_t address :20;
} page_dir_entry;
typedef struct page_table_entry_s{
uint32_t present :1;
uint32_t rw :1;
uint32_t privl :1;
uint32_t write_through :1;
uint32_t cache_disable :1;
uint32_t accessed :1;
uint32_t zero :1;
uint32_t size :1;
uint32_t global :1;
uint32_t free :3;
uint32_t address :20;
} page_table_entry;
typedef page_table_entry page_table[1024];
typedef page_dir_entry page_dir[1024];
void init_virtual_memory(uint32_t kernel_end);
void map_page(uint32_t v,uint32_t p);
Code: Select all
global enable_paging
global set_page_dir
extern p_dir
enable_paging:
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
ret
set_page_dir:
mov eax,p_dir
mov cr3,eax
ret