My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /***************************************************************************
  2. * ARM Stack Unwinder, Michael.McTernan.2001@cs.bris.ac.uk
  3. * Updated, adapted and several bug fixes on 2018 by Eduardo José Tagle
  4. *
  5. * This program is PUBLIC DOMAIN.
  6. * This means that there is no copyright and anyone is able to take a copy
  7. * for free and use it as they wish, with or without modifications, and in
  8. * any context, commerically or otherwise. The only limitation is that I
  9. * don't guarantee that the software is fit for any purpose or accept any
  10. * liability for its use or misuse - this software is without warranty.
  11. ***************************************************************************
  12. * File Description: Implementation of the memory tracking sub-system.
  13. **************************************************************************/
  14. #if defined(__arm__) || defined(__thumb__)
  15. #define MODULE_NAME "UNWARMMEM"
  16. #include <stdio.h>
  17. #include "unwarmmem.h"
  18. #include "unwarm.h"
  19. #define M_IsIdxUsed(a, v) !!((a)[v >> 3] & (1 << (v & 0x7)))
  20. #define M_SetIdxUsed(a, v) ((a)[v >> 3] |= (1 << (v & 0x7)))
  21. #define M_ClrIdxUsed(a, v) ((a)[v >> 3] &= ~(1 << (v & 0x7)))
  22. /** Search the memory hash to see if an entry is stored in the hash already.
  23. * This will search the hash and either return the index where the item is
  24. * stored, or -1 if the item was not found.
  25. */
  26. static int16_t memHashIndex(MemData * const memData, const uint32_t addr) {
  27. const uint16_t v = addr % MEM_HASH_SIZE;
  28. uint16_t s = v;
  29. do {
  30. /* Check if the element is occupied */
  31. if (M_IsIdxUsed(memData->used, s)) {
  32. /* Check if it is occupied with the sought data */
  33. if (memData->a[s] == addr) return s;
  34. }
  35. else {
  36. /* Item is free, this is where the item should be stored */
  37. return s;
  38. }
  39. /* Search the next entry */
  40. s++;
  41. if (s > MEM_HASH_SIZE) s = 0;
  42. } while (s != v);
  43. /* Search failed, hash is full and the address not stored */
  44. return -1;
  45. }
  46. bool UnwMemHashRead(MemData * const memData, uint32_t addr,uint32_t * const data, bool * const tracked) {
  47. const int16_t i = memHashIndex(memData, addr);
  48. if (i >= 0 && M_IsIdxUsed(memData->used, i) && memData->a[i] == addr) {
  49. *data = memData->v[i];
  50. *tracked = M_IsIdxUsed(memData->tracked, i);
  51. return true;
  52. }
  53. else {
  54. /* Address not found in the hash */
  55. return false;
  56. }
  57. }
  58. bool UnwMemHashWrite(MemData * const memData, uint32_t addr, uint32_t val, bool valValid) {
  59. const int16_t i = memHashIndex(memData, addr);
  60. if (i < 0) return false; /* Hash full */
  61. /* Store the item */
  62. memData->a[i] = addr;
  63. M_SetIdxUsed(memData->used, i);
  64. if (valValid) {
  65. memData->v[i] = val;
  66. M_SetIdxUsed(memData->tracked, i);
  67. }
  68. else {
  69. #ifdef UNW_DEBUG
  70. memData->v[i] = 0xDEADBEEF;
  71. #endif
  72. M_ClrIdxUsed(memData->tracked, i);
  73. }
  74. return true;
  75. }
  76. void UnwMemHashGC(UnwState * const state) {
  77. const uint32_t minValidAddr = state->regData[13].v;
  78. MemData * const memData = &state->memData;
  79. uint16_t t;
  80. for (t = 0; t < MEM_HASH_SIZE; t++) {
  81. if (M_IsIdxUsed(memData->used, t) && (memData->a[t] < minValidAddr)) {
  82. UnwPrintd3("MemHashGC: Free elem %d, addr 0x%08x\n", t, memData->a[t]);
  83. M_ClrIdxUsed(memData->used, t);
  84. }
  85. }
  86. }
  87. #endif // __arm__ || __thumb__