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