aboutsummaryrefslogtreecommitdiff
path: root/sw/devmem3.c
blob: 3c3fa16670006230ad289c4c1c04848b37fa788a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <stdlib.h>

#include "novena-eim.h"

int
main(int argc, char *argv[])
{
    off_t offset;
    uint32_t value, result;

    if (argc < 3 || argc > 4) {
    usage:
	fprintf(stderr, "usage: %s offset r\n", argv[0]);
	fprintf(stderr, "usage: %s offset w value\n", argv[0]);
	exit(EXIT_FAILURE);
    }

    if (eim_setup() != 0) {
        fprintf(stderr, "EIM setup failed\n");
	exit(EXIT_FAILURE);
    }

    offset = (off_t)strtoul(argv[1], NULL, 0);
    if (argv[2][0] == 'r') {
	eim_read_32(offset, &result);
	printf("%08x\n", result);
    }
    else if (argv[2][0] == 'w') {
	value = strtoul(argv[3], NULL, 0);
	eim_write_32(offset, &value);
    }
    else {
	fprintf(stderr, "unknown command '%s'\n", argv[2]);
	goto usage;
    }

    exit(EXIT_SUCCESS);
}