本文整理汇总了C++中write_cr3函数的典型用法代码示例。如果您正苦于以下问题:C++ write_cr3函数的具体用法?C++ write_cr3怎么用?C++ write_cr3使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_cr3函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: efi_thunk_set_virtual_address_map
efi_status_t efi_thunk_set_virtual_address_map(
void *phys_set_virtual_address_map,
unsigned long memory_map_size,
unsigned long descriptor_size,
u32 descriptor_version,
efi_memory_desc_t *virtual_map)
{
efi_status_t status;
unsigned long flags;
u32 func;
efi_sync_low_kernel_mappings();
local_irq_save(flags);
efi_scratch.prev_cr3 = read_cr3();
write_cr3((unsigned long)efi_scratch.efi_pgt);
__flush_tlb_all();
func = (u32)(unsigned long)phys_set_virtual_address_map;
status = efi64_thunk(func, memory_map_size, descriptor_size,
descriptor_version, virtual_map);
write_cr3(efi_scratch.prev_cr3);
__flush_tlb_all();
local_irq_restore(flags);
return status;
}
示例2: page_arch_init
void page_arch_init(void)
{
if (config.cpu_active > 1) {
write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
return;
}
uintptr_t cur;
unsigned int identity_flags =
PAGE_GLOBAL | PAGE_CACHEABLE | PAGE_EXEC | PAGE_WRITE | PAGE_READ;
page_mapping_operations = &pt_mapping_operations;
page_table_lock(AS_KERNEL, true);
/*
* PA2KA(identity) mapping for all low-memory frames.
*/
for (cur = 0; cur < min(config.identity_size, config.physmem_end);
cur += FRAME_SIZE)
page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, identity_flags);
page_table_unlock(AS_KERNEL, true);
exc_register(14, "page_fault", true, (iroutine_t) page_fault);
write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
}
示例3: set_pte_v2p
void set_pte_v2p(u32int vaddr, u32int pfn)
{
u32int pd_index, pt_index;
u32int pde;
u32int pte;
u32int *page_table;
printf_bochs("create vaddr:%x to pfn: %x\n", vaddr, pfn);
pd_index = vaddr / 0x400000;
pt_index = vaddr / 0x1000 % 1024;
printf_bochs("pd_index:%x pt_index:%x\n", pd_index, pt_index);
pde = page_directory[pd_index];
if(!pde) {
u32int page_table_pfn;
page_table_pfn = alloc_page_pfn();;
// ocassionally frame for page table has not been mapped.
set_pte_v2p(page_table_pfn<<12, page_table_pfn);
pde = page_table_pfn << 12 | 0x23;
page_directory[pd_index] = pde;
page_table = (u32int*)(page_table_pfn<<12);
} else {
page_table = (u32int*)(pde & 0xFFFFF000);
}
pte = pfn << 12 | 0x23;
page_table[pt_index] = pte;
write_cr3(read_cr3());
}
示例4: efi_call_phys_prolog
pgd_t * __init efi_call_phys_prolog(void)
{
unsigned long vaddress;
pgd_t *save_pgd;
int pgd;
int n_pgds;
if (!efi_enabled(EFI_OLD_MEMMAP)) {
save_pgd = (pgd_t *)read_cr3();
write_cr3((unsigned long)efi_scratch.efi_pgt);
goto out;
}
early_code_mapping_set_exec(1);
n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE);
save_pgd = kmalloc_array(n_pgds, sizeof(*save_pgd), GFP_KERNEL);
for (pgd = 0; pgd < n_pgds; pgd++) {
save_pgd[pgd] = *pgd_offset_k(pgd * PGDIR_SIZE);
vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
}
out:
__flush_tlb_all();
return save_pgd;
}
示例5: schedule
int schedule(long system_timer_ms)
{
TRACE_MSG(("called system timer: %s", current_process->name));
///check to see if the process is finished with its timeslice
if (current_process->timetorun-- <= 0)
{
///reset the current process' time to run count
current_process->timetorun = (current_process->priority)*PRIORITY_TO_TIMETORUN;
///look through the process queue until a non-sleeping thread is found
processes = processes->next;
while (processes->pid->sleep > 0)
{
processes->pid->sleep--;
processes = processes->next;
}
///when found, point current_process to the
///non-sleeping thread
current_process = processes->pid;
TRACE_MSG(("switched process: %s [stack: @0x%x]", current_process->name, current_process->esp));
//change cr3
write_cr3(current_process->cr3);
}
///the new esp must be passed back to the scheduler isr!
return current_process->esp;
}
示例6: pfint
/*-------------------------------------------------------------------------
* pfint - paging fault ISR
*-------------------------------------------------------------------------
*/
SYSCALL pfint()
{
kprintf("---------ISR----------\n");
unsigned int pfaddr = read_cr2();// faulted address
//Check that pfaddr is a legal address ????
unsigned int pdbaddr = read_cr3()&(~0xfff); //page directory base address
unsigned int p = pfaddr >> 22; // upper ten bits of faulted address
unsigned int q = (pfaddr >> 12)&0x3ff; // middle ten bits of faulted address
unsigned int offset = pfaddr & 0xfff; // last twelve bits
pd_t * pt = (pd_t *)pdbaddr + p ; //pth page table
//kprintf("%x\n",*pt);
if(pt->pd_pres == 0) // if page table is not present
{
int frm_num = get_frm(1,FR_TBL,pfaddr>>12);
//kprintf("%d\n",frm_num);
if(frm_num == SYSERR)
return SYSERR;
pt->pd_base = (0x00400000 + frm_num*4096) >> 12;
pt->pd_pres = 1;
write_cr3(pdbaddr);
kprintf("faulted addr: %x xth page table: %x, content: %x\n",pfaddr,pt,p);
return OK;
}
示例7: write_cr3
void PageTable::load()
{
write_cr3((unsigned long)page_directory);
//current_page_table = this;
Console::putui((unsigned int)read_cr3());
Console::puts("load Hello \n");
}
示例8: pci_enumerate
void pci_enumerate(void) {
uint64_t ecam_address = segment_groups[0];
// TODO: factor out temporary mappings
extern uint64_t kernel_pml4[], pd_map[];
for (int i = 0; i < 8; i += 2) {
pd_map[1 + i / 2] =
ecam_address | PAGE_PRESENT | PAGE_WRITE | PAGE_CACHE_UC | PAGE_LARGE | PAGE_GLOBAL;
}
write_cr3(PHYS_KERNEL(kernel_pml4));
ecam = (volatile void*)0xffffffffc0200000;
struct pci_function *root = function_address(0, 0, 0);
if ((root->header_type & 0x80) == 0) {
enumerate_bus(0);
} else {
for (uint8_t function_id = 0; function_id < 8; function_id++) {
struct pci_function *bus = function_address(0, 0, function_id);
if (bus->vendor_id != 0xffff) {
break;
}
enumerate_bus(function_id);
}
}
}
示例9: x86_create_initial_map
static int __init x86_create_initial_map()
{
unsigned long phy= 0;
unsigned long *p = (unsigned long *)FAK_ARCH_X86_INIT_PGTABLE; //The kernel topmost table
int i;
for (i = 0; i < 1024; i++) p[i] = 0;
/*
Kernel part in 4mb page;
*/
for (i = 0; i < 1024; i++)
{
if (i == get_loaded_base() / 0x400000) phy = 0; //如果到了内核的地址,还是从0开始映射,因为内核装的物理地址实际是在开头;
p[i] = phy | 0x83; //0x183 is the global
phy += 0x400000;
}
write_cr3((unsigned long)p);
phy = read_cr4();
phy |= X86_CR4_PSE | X86_CR4_PGE; //允许4MB页
write_cr4(phy);
phy = read_cr0();
phy |= X86_CR0_PG; //打开页表;
phy &= ~(X86_CR0_CD | X86_CR0_NW); //允许缓存;
write_cr0(phy);
return 0;
}
示例10: write_cr3
/* Enable paging on the CPU. Typically, a CPU start with paging disabled, and
memory is accessed by addressing physical memory directly. After paging is
enabled, memory is addressed logically. */
void PageTable::enable_paging() {
//write the page_directory address into CR3
write_cr3((unsigned long)current_page_table->get_page_directory());
//set paging bit in CR0 to 1
write_cr0(read_cr0() | 0x80000000);
}
示例11: initialize_tlbstate_and_flush
/*
* Call this when reinitializing a CPU. It fixes the following potential
* problems:
*
* - The ASID changed from what cpu_tlbstate thinks it is (most likely
* because the CPU was taken down and came back up with CR3's PCID
* bits clear. CPU hotplug can do this.
*
* - The TLB contains junk in slots corresponding to inactive ASIDs.
*
* - The CPU went so far out to lunch that it may have missed a TLB
* flush.
*/
void initialize_tlbstate_and_flush(void)
{
int i;
struct mm_struct *mm = this_cpu_read(cpu_tlbstate.loaded_mm);
u64 tlb_gen = atomic64_read(&init_mm.context.tlb_gen);
unsigned long cr3 = __read_cr3();
/* Assert that CR3 already references the right mm. */
WARN_ON((cr3 & CR3_ADDR_MASK) != __pa(mm->pgd));
/*
* Assert that CR4.PCIDE is set if needed. (CR4.PCIDE initialization
* doesn't work like other CR4 bits because it can only be set from
* long mode.)
*/
WARN_ON(boot_cpu_has(X86_FEATURE_PCID) &&
!(cr4_read_shadow() & X86_CR4_PCIDE));
/* Force ASID 0 and force a TLB flush. */
write_cr3(build_cr3(mm->pgd, 0));
/* Reinitialize tlbstate. */
this_cpu_write(cpu_tlbstate.last_user_mm_ibpb, LAST_USER_MM_IBPB);
this_cpu_write(cpu_tlbstate.loaded_mm_asid, 0);
this_cpu_write(cpu_tlbstate.next_asid, 1);
this_cpu_write(cpu_tlbstate.ctxs[0].ctx_id, mm->context.ctx_id);
this_cpu_write(cpu_tlbstate.ctxs[0].tlb_gen, tlb_gen);
for (i = 1; i < TLB_NR_DYN_ASIDS; i++)
this_cpu_write(cpu_tlbstate.ctxs[i].ctx_id, 0);
}
示例12: paging_init
void __init paging_init()
{
init_rootmap();
kprintf("# root pgdir=%x\n", root_map.m_pgdir);
kprintf("# root pgtable=%x\n", root_map.m_pgtable);
write_cr3((u32)root_map.m_pgdir);
write_cr0(read_cr0() | 0x80000000);
}
示例13: loader
uint32_t loader() {
Elf32_Ehdr *elf;
Elf32_Phdr *ph = NULL;
uint8_t buf[4096];
#ifdef HAS_DEVICE
ide_read(buf, ELF_OFFSET_IN_DISK, 4096);
#else
ramdisk_read(buf, ELF_OFFSET_IN_DISK, 4096);
#endif
elf = (void*)buf;
/* TODO: fix the magic number with the correct one */
const uint32_t elf_magic = 0x7f454c46;
uint32_t *p_magic = (void *)buf;
nemu_assert(*p_magic == elf_magic);
/* Load each program segment */
for(; true; ) {
/* Scan the program header table, load each segment into memory */
if(ph->p_type == PT_LOAD) { //PT_LOAT=1, Loadable program segment
/* TODO: read the content of the segment from the ELF file
* to the memory region [VirtAddr, VirtAddr + FileSiz)
*/
/* TODO: zero the memory region
* [VirtAddr + FileSiz, VirtAddr + MemSiz)
*/
#ifdef IA32_PAGE
/* Record the program break for future use. */
extern uint32_t brk;
uint32_t new_brk = ph->p_vaddr + ph->p_memsz - 1;
if(brk < new_brk) { brk = new_brk; }
#endif
}
}
volatile uint32_t entry = elf->e_entry;
#ifdef IA32_PAGE
mm_malloc(KOFFSET - STACK_SIZE, STACK_SIZE);
#ifdef HAS_DEVICE
create_video_mapping();
#endif
write_cr3(get_ucr3());
#endif
return entry;
}
示例14: init_page
/* set up page tables for kernel */
void init_page(void) {
CR0 cr0;
CR3 cr3;
PDE *pdir = (PDE *)va_to_pa(kpdir);
PTE *ptable = (PTE *)va_to_pa(kptable);
uint32_t pdir_idx;
/* make all PDEs invalid */
memset(pdir, 0, NR_PDE * sizeof(PDE));
/* fill PDEs */
for (pdir_idx = 0; pdir_idx < PHY_MEM / PT_SIZE; pdir_idx ++) {
pdir[pdir_idx].val = make_pde(ptable);
pdir[pdir_idx + KOFFSET / PT_SIZE].val = make_pde(ptable);
ptable += NR_PTE;
}
/* fill PTEs */
/* We use inline assembly here to fill PTEs for efficiency.
* If you do not understand it, refer to the C code below.
*/
asm volatile ("std;\
1: stosl;\
subl %0, %%eax;\
jge 1b;\
cld" : :
"i"(PAGE_SIZE), "a"((PHY_MEM - PAGE_SIZE) | 0x7), "D"(ptable - 1));
/*
===== referenced code for the inline assembly above =====
uint32_t pframe_addr = PHY_MEM - PAGE_SIZE;
ptable --;
// fill PTEs reversely
for (; pframe_addr >= 0; pframe_addr -= PAGE_SIZE) {
ptable->val = make_pte(pframe_addr);
ptable --;
}
*/
/* make CR3 to be the entry of page directory */
cr3.val = 0;
cr3.page_directory_base = ((uint32_t)pdir) >> 12;
write_cr3(cr3.val);
/* set PG bit in CR0 to enable paging */
cr0.val = read_cr0();
cr0.paging = 1;
write_cr0(cr0.val);
}
示例15: init_paging
/* Paging Initialization
*/
void init_paging()
{
map_mem();
printf("before: %b,%b ---",read_cr0(),read_cr3());
write_cr3((unsigned long)page_directory);
unsigned long cr0 = read_cr0();
cr0 = cr0 | 0x8000000;
write_cr0(cr0);
printf(" after: %b,%b\n",read_cr0(),read_cr3());
}