Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <sys/mman.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7.  
  8. #define PAGESIZE 4096
  9. #define SHIFT_AMOUNT 28
  10.  
  11. /*
  12. output = BASE_ADDR
  13. op1 = BASE_ADDR + sizeof(int)
  14. op2 = BASE_ADDR + 2*sizeof(int)
  15. */
  16. #define BASE_ADDR (0x43C00000)
  17.  
  18.  
  19.  
  20. int main(int argc, char *argv[])
  21. {
  22.     int fd;
  23.     int *ptr;
  24.  
  25.     fd = open("/dev/mem", O_RDWR | O_SYNC);
  26.  
  27.     int32_t op1, op2;
  28.     int32_t mul = (1 << SHIFT_AMOUNT);
  29.     op1 = (0.25 * mul);
  30.     op2 = (1.0 * mul);
  31.  
  32.     int32_t re, im;
  33.     int32_t re_o, im_o;
  34.  
  35.     re = (0.25 * mul);
  36.     im = (1.5 * mul);
  37.  
  38.     //write(fd, op1, sizeof(op1));
  39.     //write(fd, op2, sizeof(op2));
  40.     ptr = (int *) mmap(NULL, PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, BASE_ADDR);
  41.     close(fd);
  42.  
  43.     ptr[2] = re;
  44.     ptr[3] = im;
  45.  
  46.     printf("pointer to mem-mapped file: %p\n", ptr);
  47.     printf("re: %lf\n", ((double)re/mul));
  48.     printf("im: %lf\n", ((double)im/mul));
  49.     printf("re*re: %lf\n", ((double)ptr[4]/mul));
  50.     printf("im*im: %lf\n", ((double)ptr[5]/mul));
  51.     printf("iter_o: %d\n", ptr[6]);
  52.     //printf("%d * %d = %d\n", op1, op2, (op1 + op2))
  53.     //double erg = (double)ptr[0]/mul;
  54.     //printf("erg: %f\n", erg);
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement