Maybe I shall past some code:
Code: Select all
Boot32:
extern CrKrnlMemMap
mov esp, stack+4096
call CrKrnlMemMap
extern PML4
mov eax, PML4
mov cr3, eax
mov eax, cr4
or eax, 0xA0
mov cr4, eax
mov ecx, 0xC0000080
rdmsr
or eax, 0x100
wrmsr
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
lgdt [gdt_descriptor]
mov ax, 0x10
mov ds, ax
mov ss, ax
jmp 0x08:Here
Here:
mov eax, 0xb8000
mov bl, 0x41
mov byte [eax], bl
jmp Here
section .data
align 4
dw 0
gdt_descriptor:
dw 3*8-1
dd gdt
gdt:
dd 0,0
dd 0,0x00209800
dd 0,0x00009000
section .bss
stack:
resb 4096
Code: Select all
#include "Paging32.h"
void StPML4Entry(struct PML4Table *PML4,
long long Address,
void *PhysAddress,
long Present,
long ReadWrite,
long UserSystem)
{
PML4->Table[(Address>>39)&0x1FF] =
(long)PhysAddress |
Present |
(ReadWrite<<1) |
(UserSystem<<2);
}
void StPDPEntry(struct PDPTable *PDP,
long long Address,
void *PhysAddress,
long Present,
long ReadWrite,
long UserSystem)
{
PDP->Table[(Address>>30)&0x1FF] =
(long)PhysAddress |
Present |
(ReadWrite<<1) |
(UserSystem<<2);
}
void StPDEntry(struct PDTable *PD,
long long Address,
void *PhysAddress,
long Present,
long ReadWrite,
long UserSystem)
{
PD->Table[(Address>>21)&0x1FF] =
(long)PhysAddress |
Present |
(ReadWrite<<1) |
(UserSystem<<2);
}
void StPTEntry(struct PTTable *PT,
long long Address,
void *PhysAddress,
long Present,
long ReadWrite,
long UserSystem,
long Global)
{
PT->Table[(Address>>12)&0x1FF] =
(long)PhysAddress |
Present |
(ReadWrite<<1) |
(UserSystem<<2) |
(Global<<8);
}
struct PML4Table PML4;
struct PDPTable PDP_32;
struct PDTable PD_32;
struct PTTable PT_32;
void CrKrnlMemMap()
{
long Addr = 0;
long i;
StPML4Entry(&PML4, 0, &PDP_32, 1, 1, 0);
StPDPEntry(&PDP_32, 0, &PD_32, 1, 1, 0);
StPDEntry(&PD_32, 0, &PT_32, 1, 1, 0);
for(i=0; i<512; ++i, Addr += 4096)
StPTEntry(&PT_32, Addr, (void*)Addr, 1, 1, 0, 1);
}
Code: Select all
#ifndef _PAGING32_H_
#define _PAGING32_H_
typedef unsigned long long PageEntry;
struct PML4Table
{
PageEntry Table[512];
} __attribute__ ((aligned (4096)));
void StPML4Entry(struct PML4Table *PML4,
long long Address,
void *PhysAddress,
long Present,
long ReadWrite,
long UserSystem);
struct PDPTable
{
PageEntry Table[512];
} __attribute__ ((aligned (4096)));
void StPDPEntry(struct PDPTable *PDP,
long long Address,
void *PhysAddress,
long Present,
long ReadWrite,
long UserSystem);
struct PDTable
{
PageEntry Table[512];
} __attribute__ ((aligned (4096)));
void StPDEntry(struct PDTable *PD,
long long Address,
void *PhysAddress,
long Present,
long ReadWrite,
long UserSystem);
struct PTTable
{
PageEntry Table[512];
} __attribute__ ((aligned (4096)));
void StPTEntry(struct PTTable *PT,
long long Address,
void *PhysAddress,
long Present,
long ReadWrite,
long UserSystem,
long Global);
#endif