[Pdbg] [PATCH 2/3] libpdg: Add option to write to / read from cache inhibited memory
Alistair Popple
alistair at popple.id.au
Thu May 17 16:01:20 AEST 2018
Thanks Rashmica, this looks pretty good. One minor note below but otherwise I
think this is fine as is.
> diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
> index f2b5de7..8601361 100644
> --- a/libpdbg/libpdbg.h
> +++ b/libpdbg/libpdbg.h
> @@ -120,8 +120,8 @@ int htm_status(struct pdbg_target *target);
> int htm_reset(struct pdbg_target *target, uint64_t *base, uint64_t *size);
> int htm_dump(struct pdbg_target *target, uint64_t size, const char *filename);
>
> -int adu_getmem(struct pdbg_target *target, uint64_t addr, uint8_t *ouput, uint64_t size);
> -int adu_putmem(struct pdbg_target *target, uint64_t addr, uint8_t *input, uint64_t size);
> +int adu_getmem(struct pdbg_target *target, uint64_t addr, uint8_t *ouput, uint64_t size, int ci);
> +int adu_putmem(struct pdbg_target *target, uint64_t addr, uint8_t *input, uint64_t size, int ci);
Technically this is a change to the existing API/ABI for the library which will
break existing programs/binaries. For a bigger project we'd probably want to
avoid this, but at the moment the only real user of libpdbg is pdbg itself so I
don't think we have to worry too much.
- Alistair
> int opb_read(struct pdbg_target *target, uint32_t addr, uint32_t *data);
> int opb_write(struct pdbg_target *target, uint32_t addr, uint32_t data);
> diff --git a/libpdbg/operations.h b/libpdbg/operations.h
> index d6c947f..7ee4cb2 100644
> --- a/libpdbg/operations.h
> +++ b/libpdbg/operations.h
> @@ -32,8 +32,8 @@
> #define FSI2PIB_BASE 0x1000
>
> /* Alter display unit functions */
> -int adu_getmem(struct pdbg_target *target, uint64_t addr, uint8_t *output, uint64_t size);
> -int adu_putmem(struct pdbg_target *target, uint64_t start_addr, uint8_t *input, uint64_t size);
> +int adu_getmem(struct pdbg_target *target, uint64_t addr, uint8_t *output, uint64_t size, int ci);
> +int adu_putmem(struct pdbg_target *target, uint64_t start_addr, uint8_t *input, uint64_t size, int ci);
>
> /* Functions to ram instructions */
> #define THREAD_STATUS_DISABLED PPC_BIT(0)
> diff --git a/libpdbg/target.h b/libpdbg/target.h
> index eba26cb..d60c586 100644
> --- a/libpdbg/target.h
> +++ b/libpdbg/target.h
> @@ -103,8 +103,8 @@ struct htm {
>
> struct adu {
> struct pdbg_target target;
> - int (*getmem)(struct adu *, uint64_t, uint64_t *);
> - int (*putmem)(struct adu *, uint64_t, uint64_t, int);
> + int (*getmem)(struct adu *, uint64_t, uint64_t *, int);
> + int (*putmem)(struct adu *, uint64_t, uint64_t, int, int);
> };
> #define target_to_adu(x) container_of(x, struct adu, target)
>
> diff --git a/src/mem.c b/src/mem.c
> index 815c1c7..be45434 100644
> --- a/src/mem.c
> +++ b/src/mem.c
> @@ -26,7 +26,7 @@
> #include "main.h"
>
> #define PUTMEM_BUF_SIZE 1024
> -static int getmem(uint64_t addr, uint64_t size)
> +static int getmem(uint64_t addr, uint64_t size, int ci)
> {
> struct pdbg_target *target;
> uint8_t *buf;
> @@ -37,7 +37,7 @@ static int getmem(uint64_t addr, uint64_t size)
> if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED)
> continue;
>
> - if (!adu_getmem(target, addr, buf, size)) {
> + if (!adu_getmem(target, addr, buf, size, ci)) {
> if (write(STDOUT_FILENO, buf, size) < 0)
> PR_ERROR("Unable to write stdout.\n");
> else
> @@ -51,7 +51,7 @@ static int getmem(uint64_t addr, uint64_t size)
> return rc;
>
> }
> -static int putmem(uint64_t addr)
> +static int putmem(uint64_t addr, int ci)
> {
> uint8_t *buf;
> int read_size, rc = 0;
> @@ -67,7 +67,7 @@ static int putmem(uint64_t addr)
> assert(buf);
> do {
> read_size = read(STDIN_FILENO, buf, PUTMEM_BUF_SIZE);
> - if (adu_putmem(adu_target, addr, buf, read_size)) {
> + if (adu_putmem(adu_target, addr, buf, read_size, ci)) {
> rc = 0;
> printf("Unable to write memory.\n");
> break;
> @@ -84,6 +84,7 @@ int handle_mem(int optind, int argc, char *argv[])
> {
> uint64_t addr;
> char *endptr;
> + int ci = 0;
>
> if (optind + 1 >= argc) {
> printf("%s: command '%s' requires an address\n", argv[0], argv[optind]);
> @@ -91,31 +92,37 @@ int handle_mem(int optind, int argc, char *argv[])
> }
>
> errno = 0;
> - addr = strtoull(argv[optind + 1], &endptr, 0);
> +
> + if (strcmp(argv[optind +1], "-ci") == 0) {
> + /* Set cache-inhibited flag */
> + ci = 1;
> + }
> +
> + addr = strtoull(argv[optind + 1 + ci], &endptr, 0);
> if (errno || *endptr != '\0') {
> printf("%s: command '%s' couldn't parse address '%s'\n",
> - argv[0], argv[optind], argv[optind + 1]);
> + argv[0], argv[optind], argv[optind + 1 + ci]);
> return -1;
> }
>
> if (strcmp(argv[optind], "getmem") == 0) {
> uint64_t size;
>
> - if (optind + 2 >= argc) {
> + if (optind + 2 + ci >= argc) {
> printf("%s: command '%s' requires data\n", argv[0], argv[optind]);
> return -1;
> }
>
> errno = 0;
> - size = strtoull(argv[optind + 2], &endptr, 0);
> + size = strtoull(argv[optind + 2 + ci], &endptr, 0);
> if (errno || *endptr != '\0') {
> printf("%s: command '%s' couldn't parse data '%s'\n",
> - argv[0], argv[optind], argv[optind + 1]);
> + argv[0], argv[optind], argv[optind + 1 + ci]);
> return -1;
> }
>
> - return getmem(addr, size);
> + return getmem(addr, size, ci);
> }
>
> - return putmem(addr);
> + return putmem(addr, ci);
> }
>
More information about the Pdbg
mailing list