librfn
An ad-hoc utility library
regdump.c
Go to the documentation of this file.
1 /*
2  * regdump.c
3  *
4  * Part of librfn (a general utility library from redfelineninja.org.uk)
5  *
6  * Copyright (C) 2014 Daniel Thompson <daniel@redfelineninja.org.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  */
13 
14 #include <librfn/regdump.h>
15 
16 #include <stdio.h>
17 #include <librfn/bitops.h>
18 
19 int fregdump_single(FILE *f, uintreg_t reg, const regdump_desc_t *desc,
20  int *state)
21 {
22  int i = (*state)++;
23 
24  if (0 == i) {
25  fprintf(f, "Register: %s\n", desc[0].name);
26  } else {
27  int shift = ctz(desc[i].mask);
28  fprintf(f, "\t%-16s: 0x%" PRIxreg "\n", desc[i].name,
29  (reg & desc[i].mask) >> shift);
30  }
31 
32  if (!desc[*state].name)
33  *state = 0;
34 
35  return *state;
36 }
37 
38 void fregdump(FILE *f, uintreg_t reg, const regdump_desc_t *desc)
39 {
41  while (fregdump_single(f, reg, desc, &state))
42  ;
43 }
44 
45 int regdump_single(uintreg_t reg, const regdump_desc_t *desc, int *state)
46 {
47  return fregdump_single(stdout, reg, desc, state);
48 }
49 
50 void regdump(uintreg_t reg, const regdump_desc_t *desc)
51 {
52  fregdump(stdout, reg, desc);
53 }
Register description structure.
Definition: regdump.h:55
uint32_t uintreg_t
Definition: regdump.h:33
int ctz(uint32_t x)
Definition: bitops.c:46
#define PRIxreg
Definition: regdump.h:34
fibre_state_t state
Definition: fibre.c:30
int fregdump_single(FILE *f, uintreg_t reg, const regdump_desc_t *desc, int *state)
Dump single line of register output to file.
Definition: regdump.c:19
void fregdump(FILE *f, uintreg_t reg, const regdump_desc_t *desc)
Dump the current register status to file.
Definition: regdump.c:38
void regdump(uintreg_t reg, const regdump_desc_t *desc)
Dump the current register status to stdout.
Definition: regdump.c:50
#define REGDUMP_STATE_VAR_INIT
Static initializer for re-entrancy state variable.
Definition: regdump.h:63
int regdump_single(uintreg_t reg, const regdump_desc_t *desc, int *state)
Dump single line of register output to stdout.
Definition: regdump.c:45