rdb.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include "u.h"
  10. #include "../port/lib.h"
  11. #include "mem.h"
  12. #include "dat.h"
  13. #include "fns.h"
  14. #include "ureg.h"
  15. #define DBG if(0)scrprint
  16. #pragma varargck argpos scrprint 1
  17. static Ureg ureg;
  18. static void
  19. scrprint(char *fmt, ...)
  20. {
  21. char buf[128];
  22. va_list va;
  23. int n;
  24. va_start(va, fmt);
  25. n = vseprint(buf, buf+sizeof buf, fmt, va)-buf;
  26. va_end(va);
  27. putstrn(buf, n);
  28. }
  29. static char*
  30. getline(void)
  31. {
  32. static char buf[128];
  33. int i, c;
  34. for(;;){
  35. for(i=0; i<nelem(buf) && (c=uartgetc()) != '\n'; i++){
  36. DBG("%c...", c);
  37. buf[i] = c;
  38. }
  39. if(i < nelem(buf)){
  40. buf[i] = 0;
  41. return buf;
  42. }
  43. }
  44. }
  45. static void*
  46. addr(char *s, Ureg *ureg, char **p)
  47. {
  48. uint32_t a;
  49. a = strtoul(s, p, 16);
  50. if(a < sizeof(Ureg))
  51. return ((uint8_t*)ureg)+a;
  52. return (void*)a;
  53. }
  54. static void
  55. talkrdb(Ureg *ureg)
  56. {
  57. uint8_t *a;
  58. char *p, *req;
  59. delconsdevs(); /* turn off serial console and kprint */
  60. // scrprint("Plan 9 debugger\n");
  61. iprint("Edebugger reset\n");
  62. for(;;){
  63. req = getline();
  64. switch(*req){
  65. case 'r':
  66. a = addr(req+1, ureg, nil);
  67. DBG("read %#p\n", a);
  68. iprint("R%.8lux %.2ux %.2ux %.2ux %.2ux\n",
  69. strtoul(req+1, 0, 16), a[0], a[1], a[2], a[3]);
  70. break;
  71. case 'w':
  72. a = addr(req+1, ureg, &p);
  73. *(uint32_t*)a = strtoul(p, nil, 16);
  74. iprint("W\n");
  75. break;
  76. /*
  77. * case Tmput:
  78. n = min[4];
  79. if(n > 4){
  80. mesg(Rerr, Ecount);
  81. break;
  82. }
  83. a = addr(min+0);
  84. scrprint("mput %.8lux\n", a);
  85. memmove(a, min+5, n);
  86. mesg(Rmput, mout);
  87. break;
  88. *
  89. */
  90. default:
  91. DBG("unknown %c\n", *req);
  92. iprint("Eunknown message\n");
  93. break;
  94. }
  95. }
  96. }
  97. void
  98. rdb(void)
  99. {
  100. splhi();
  101. iprint("rdb...");
  102. callwithureg(talkrdb);
  103. }