diff options
Diffstat (limited to 'meta-xilinx-demos/recipes-examples/peekpoke/files/peek.c')
-rw-r--r-- | meta-xilinx-demos/recipes-examples/peekpoke/files/peek.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/meta-xilinx-demos/recipes-examples/peekpoke/files/peek.c b/meta-xilinx-demos/recipes-examples/peekpoke/files/peek.c new file mode 100644 index 00000000..53bd1d1c --- /dev/null +++ b/meta-xilinx-demos/recipes-examples/peekpoke/files/peek.c | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | * peek utility - for those who remember the good old days! | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 2013 - 2016 Xilinx, Inc. All rights reserved. | ||
6 | * | ||
7 | * Permission is hereby granted, free of charge, to any person | ||
8 | * obtaining a copy of this software and associated documentation | ||
9 | * files (the "Software"), to deal in the Software without restriction, | ||
10 | * including without limitation the rights to use, copy, modify, merge, | ||
11 | * publish, distribute, sublicense, and/or sell copies of the Software, | ||
12 | * and to permit persons to whom the Software is furnished to do so, | ||
13 | * subject to the following conditions: | ||
14 | * | ||
15 | * The above copyright notice and this permission notice shall be included | ||
16 | * in all copies or substantial portions of the Software. | ||
17 | * | ||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
21 | * IN NO EVENT SHALL XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
22 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
24 | * | ||
25 | * Except as contained in this notice, the name of the Xilinx shall not be used | ||
26 | * in advertising or otherwise to promote the sale, use or other dealings in this | ||
27 | * Software without prior written authorization from Xilinx. | ||
28 | * | ||
29 | */ | ||
30 | |||
31 | #include <stdio.h> | ||
32 | #include <stdlib.h> | ||
33 | #include <unistd.h> | ||
34 | #include <sys/mman.h> | ||
35 | #include <fcntl.h> | ||
36 | #include <stdint.h> | ||
37 | |||
38 | void usage(char *prog) | ||
39 | { | ||
40 | printf("usage: %s ADDR\n",prog); | ||
41 | printf("\n"); | ||
42 | printf("ADDR may be specified as hex values\n"); | ||
43 | } | ||
44 | |||
45 | |||
46 | int main(int argc, char *argv[]) | ||
47 | { | ||
48 | int fd; | ||
49 | void *ptr; | ||
50 | uint64_t addr, page_addr, page_offset; | ||
51 | uint64_t page_size=sysconf(_SC_PAGESIZE); | ||
52 | |||
53 | if(argc!=2) { | ||
54 | usage(argv[0]); | ||
55 | exit(-1); | ||
56 | } | ||
57 | |||
58 | fd=open("/dev/mem",O_RDONLY); | ||
59 | if(fd<1) { | ||
60 | perror(argv[0]); | ||
61 | exit(-1); | ||
62 | } | ||
63 | |||
64 | addr=strtoul(argv[1],NULL,0); | ||
65 | page_addr=(addr & ~(page_size-1)); | ||
66 | page_offset=addr-page_addr; | ||
67 | |||
68 | ptr=mmap(NULL,page_size,PROT_READ,MAP_SHARED,fd,(addr & ~(page_size-1))); | ||
69 | if((int64_t)ptr==-1) { | ||
70 | perror(argv[0]); | ||
71 | exit(-1); | ||
72 | } | ||
73 | |||
74 | printf("0x%08lx\n",*((uint64_t *)(ptr+page_offset))); | ||
75 | return 0; | ||
76 | } | ||