mem.h 843 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <types/stdint.h>
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. // don't forget to add the initial 1m to the total
  7. struct mem_size_info {
  8. uint16_t n_1k_blks; // memory between 1m and 16m in 1k blocks
  9. uint16_t n_64k_blks; // memory above 16m in 64k blocks
  10. };
  11. extern struct mem_size_info asm_mem_size_info;
  12. // TODO: decide heap start address according
  13. // to user's memory size
  14. #define HEAP_START ((void*)0x01000000)
  15. struct mem_blk_flags {
  16. uint8_t is_free;
  17. uint8_t has_next;
  18. uint8_t _unused2;
  19. uint8_t _unused3;
  20. };
  21. struct mem_blk {
  22. size_t size;
  23. struct mem_blk_flags flags;
  24. // the first byte of the memory space
  25. // the minimal allocated space is 4 bytes
  26. uint8_t data[4];
  27. };
  28. void init_heap(void);
  29. void* k_malloc(size_t size);
  30. void k_free(void* ptr);
  31. #ifdef __cplusplus
  32. }
  33. #endif