regs.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * code to keep track of registers
  11. */
  12. #include "defs.h"
  13. #include "fns.h"
  14. /*
  15. * translate a name to a magic register offset
  16. */
  17. Reglist*
  18. rname(char *name)
  19. {
  20. Reglist *rp;
  21. for (rp = mach->reglist; rp->rname; rp++)
  22. if (strcmp(name, rp->rname) == 0)
  23. return rp;
  24. return 0;
  25. }
  26. static uint64_t
  27. getreg(Map *map, Reglist *rp)
  28. {
  29. uint64_t v;
  30. uint32_t w;
  31. uint16_t s;
  32. int ret;
  33. v = 0;
  34. ret = 0;
  35. switch (rp->rformat)
  36. {
  37. case 'x':
  38. ret = get2(map, rp->roffs, &s);
  39. v = s;
  40. break;
  41. case 'f':
  42. case 'X':
  43. ret = get4(map, rp->roffs, &w);
  44. v = w;
  45. break;
  46. case 'F':
  47. case 'W':
  48. case 'Y':
  49. ret = get8(map, rp->roffs, &v);
  50. break;
  51. default:
  52. werrstr("can't retrieve register %s", rp->rname);
  53. error("%r");
  54. }
  55. if (ret < 0) {
  56. werrstr("Register %s: %r", rp->rname);
  57. error("%r");
  58. }
  59. return v;
  60. }
  61. uint64_t
  62. rget(Map *map, char *name)
  63. {
  64. Reglist *rp;
  65. rp = rname(name);
  66. if (!rp)
  67. error("invalid register name");
  68. return getreg(map, rp);
  69. }
  70. void
  71. rput(Map *map, char *name, int64_t v)
  72. {
  73. Reglist *rp;
  74. int ret;
  75. rp = rname(name);
  76. if (!rp)
  77. error("invalid register name");
  78. if (rp->rflags & RRDONLY)
  79. error("register is read-only");
  80. switch (rp->rformat)
  81. {
  82. case 'x':
  83. ret = put2(map, rp->roffs, (uint16_t) v);
  84. break;
  85. case 'X':
  86. case 'f':
  87. case 'F':
  88. ret = put4(map, rp->roffs, (int32_t) v);
  89. break;
  90. case 'Y':
  91. ret = put8(map, rp->roffs, v);
  92. break;
  93. default:
  94. ret = -1;
  95. }
  96. if (ret < 0)
  97. error("can't write register");
  98. }
  99. /*
  100. * print the registers
  101. */
  102. void
  103. printregs(int c)
  104. {
  105. Reglist *rp;
  106. int i;
  107. uint64_t v;
  108. for (i = 1, rp = mach->reglist; rp->rname; rp++, i++) {
  109. if ((rp->rflags & RFLT)) {
  110. if (c != 'R')
  111. continue;
  112. if (rp->rformat == '8' || rp->rformat == '3')
  113. continue;
  114. }
  115. v = getreg(cormap, rp);
  116. if(rp->rformat == 'Y')
  117. dprint("%-8s %-20#llux", rp->rname, v);
  118. else
  119. dprint("%-8s %-12#lux", rp->rname, (uint32_t)v);
  120. if ((i % 3) == 0) {
  121. dprint("\n");
  122. i = 0;
  123. }
  124. }
  125. if (i != 1)
  126. dprint("\n");
  127. dprint ("%s\n", machdata->excep(cormap, rget));
  128. printpc();
  129. }