dipto181

write-back

Mar 21st, 2021
38
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // setup mtrr
  2. int fd_mtrr;
  3. struct mtrr_sentry sentry;
  4. sentry.base = 0x06b100000;
  5. sentry.size = 0x40000;
  6. sentry.type = 6; // "write-back"
  7. if ( ( fd_mtrr = open ("/proc/mtrr", O_WRONLY, 0) ) == -1 ){
  8. if (errno == ENOENT){
  9. fputs ("/proc/mtrr not found: not supported or you don't have a PPro?\n", stderr);
  10. exit (3);
  11. }
  12. fprintf (stderr, "Error opening /proc/mtrr\t%s\n", ERRSTRING);
  13. exit (4);
  14. }
  15. if (ioctl (fd_mtrr, MTRRIOC_ADD_ENTRY, &sentry) == -1){
  16. fprintf (stderr, "Error doing ioctl(2) on /dev/mtrr\t%s\n", ERRSTRING);
  17. exit (5);
  18. }
  19. fprintf (stderr, "MTRR created \n");
  20.  
  21. // mmap structure addres with mtrr
  22. int mm, *map;
  23. mm = open("/dev/mem", O_RDWR);
  24. map = mmap(&env, sizeof(env), PROT_READ | PROT_WRITE, MAP_PRIVATE, mm, sentry.base);
  25. if(map == MAP_FAILED){
  26. printf("Mapping Failed\n");
  27. return 1;
  28. }
  29. fprintf (stderr, "mapping MTRR with env is done \n");
RAW Paste Data