memspace.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. MSP430 Emulator
  3. Copyright (C) 2020 Rudolf Geosits (rgeosits@live.esu.edu)
  4. "MSP430 Emulator" is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. "MSP430 Emulator" is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "memspace.h"
  16. uint8_t* MEMSPACE; /* Memory Space */
  17. uint8_t* CODE; // Code Memory
  18. uint8_t* INFO; // Info memory
  19. uint8_t* IVT; /* Interrupt Vector Table {Within ROM} */
  20. uint8_t* ROM; /* Flash/Read-Only memory */
  21. uint8_t* RAM; /* Random Access Memory */
  22. uint8_t* PER16; /* 16-bit peripherals */
  23. uint8_t* PER8; /* 8-bit peripherals */
  24. uint8_t* SFRS; /* Special Function Registers */
  25. /* Initialize Address Space Locations
  26. **
  27. ** Allocate and set MSP430 Memory space
  28. ** Some of these locations vary by model
  29. */
  30. void initialize_msp_memspace()
  31. {
  32. // MSP430g2553 Device Specific ...
  33. // 16 KB / 64 KB Addressable Space
  34. MEMSPACE = (uint8_t *) calloc(1, 0x10000);
  35. //MEMSPACE = (uint8_t*)calloc(1, 0x100000);
  36. // (lower bounds, so increment upwards)
  37. // Info memory from 0x10FF - 0x1000 (256 Bytes)
  38. INFO = MEMSPACE + 0x1000;
  39. // Set it all to 0xFF by default...
  40. memset(INFO, 0xFF, 256);
  41. // Code Memory 0xFFFF - 0xC000;
  42. CODE = MEMSPACE + 0xC000;
  43. // Set it all to 0xFF by default...
  44. memset(CODE, 0xFF, 16384);
  45. // Interrupt Vector Table 0xFFFF - 0xFFC0
  46. IVT = MEMSPACE + 0xFFC0;
  47. // ROM // 0x400 - 0x1FFFF
  48. ROM = MEMSPACE + 0x0400;
  49. // RAM from 0x3FF - 0x200
  50. RAM = MEMSPACE + 0x0200; // 0x200 - 0x3FF
  51. PER16 = MEMSPACE + 0x0100; // 0x0100 - 0x01FF
  52. PER8 = MEMSPACE + 0x0010; // 0x0010 - 0x00FF
  53. SFRS = MEMSPACE + 0x0; // 0x0 - 0x0F
  54. // Setup the calibration data in info memory
  55. const uint16_t CALDCO_16MHZ_VLOC = 0x10F8;
  56. *((uint8_t *) (MEMSPACE + CALDCO_16MHZ_VLOC)) = 0x95;
  57. const uint16_t CALBC1_16MHZ_VLOC = 0x10F9;
  58. *((uint8_t *) (MEMSPACE + CALBC1_16MHZ_VLOC)) = 0x8F;
  59. const uint16_t CALDCO_12MHZ_VLOC = 0x10FA;
  60. *((uint8_t *) (MEMSPACE + CALDCO_12MHZ_VLOC)) = 0x9E;
  61. const uint16_t CALBC1_12MHZ_VLOC = 0x10FB;
  62. *((uint8_t *) (MEMSPACE + CALBC1_12MHZ_VLOC)) = 0x8E;
  63. const uint16_t CALDCO_8MHZ_VLOC = 0x10FC;
  64. *((uint8_t *) (MEMSPACE + CALDCO_8MHZ_VLOC)) = 0x92;
  65. const uint16_t CALBC1_8MHZ_VLOC = 0x10FD;
  66. *((uint8_t *) (MEMSPACE + CALBC1_8MHZ_VLOC)) = 0x8D;
  67. const uint16_t CALDCO_1MHZ_VLOC = 0x10FE;
  68. *((uint8_t *) (MEMSPACE + CALDCO_1MHZ_VLOC)) = 0xD1;
  69. const uint16_t CALBC1_1MHZ_VLOC = 0x10FF;
  70. *((uint8_t *) (MEMSPACE + CALBC1_1MHZ_VLOC)) = 0x86;
  71. }
  72. /*
  73. ** Free MSP430 virtual memory
  74. */
  75. void uninitialize_msp_memspace()
  76. {
  77. free(MEMSPACE);
  78. }