rmap_chain.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* test long rmap chains */
  2. #include "libcflat.h"
  3. #include "fwcfg.h"
  4. #include "vm.h"
  5. #include "smp.h"
  6. int main (void)
  7. {
  8. int i;
  9. int nr_pages;
  10. void *target_page, *virt_addr;
  11. setup_vm();
  12. nr_pages = fwcfg_get_u64(FW_CFG_RAM_SIZE) / PAGE_SIZE;
  13. nr_pages -= 1000;
  14. target_page = alloc_page();
  15. virt_addr = (void *) 0xfffffa000;
  16. for (i = 0; i < nr_pages; i++) {
  17. install_page(phys_to_virt(read_cr3()), virt_to_phys(target_page),
  18. virt_addr);
  19. virt_addr += PAGE_SIZE;
  20. }
  21. printf("created %d mappings\n", nr_pages);
  22. virt_addr = (void *) 0xfffffa000;
  23. for (i = 0; i < nr_pages; i++) {
  24. unsigned long *touch = virt_addr;
  25. *touch = 0;
  26. virt_addr += PAGE_SIZE;
  27. }
  28. printf("instantiated mappings\n");
  29. virt_addr += PAGE_SIZE;
  30. install_pte(phys_to_virt(read_cr3()), 1, virt_addr,
  31. 0 | PT_PRESENT_MASK | PT_WRITABLE_MASK, target_page);
  32. *(unsigned long *)virt_addr = 0;
  33. printf("PASS\n");
  34. return 0;
  35. }