summaryrefslogtreecommitdiffstats
path: root/meta-xilinx-demos/recipes-examples/peekpoke/files/peek.c
diff options
context:
space:
mode:
authorMark Hatle <mark.hatle@amd.com>2024-11-11 11:24:08 -0700
committerMark Hatle <mark.hatle@amd.com>2024-11-11 11:24:08 -0700
commitee6e2f1f4fc8d438bfde7634e31657b52970fda9 (patch)
tree38b5366d82e15538ab3c5e4f9a3dd1dcac26ff20 /meta-xilinx-demos/recipes-examples/peekpoke/files/peek.c
parent03d3b2ce359a1c2959f04588cf2c4a1b0dcb4de8 (diff)
parent7c79383570dc4182bb21cdee68598ccf47403150 (diff)
downloadmeta-xilinx-ee6e2f1f4fc8d438bfde7634e31657b52970fda9.tar.gz
Merge remote-tracking branch 'origin/rel-v2024.2' into scarthgap-next
Signed-off-by: Mark Hatle <mark.hatle@amd.com>
Diffstat (limited to 'meta-xilinx-demos/recipes-examples/peekpoke/files/peek.c')
-rw-r--r--meta-xilinx-demos/recipes-examples/peekpoke/files/peek.c76
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
38void 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
46int 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}