mem.h 774 B

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