mm.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* include/kernel/mm.h
  2. *
  3. * This file is part of evx.
  4. *
  5. * evx is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * evx is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with evx. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #ifndef __MM_H
  19. #define __MM_H
  20. #ifndef __ASSEMBLER__
  21. #include <sys/types.h>
  22. #include <arch/archinfo.h>
  23. /* a descriptor for each page to describe a page, hopely be smallest
  24. * and this is create only for the buddy memory management system. we
  25. * can't implement that without this, because we need more memory when
  26. * inserting.
  27. *
  28. * we should initiallize this as late as we can, after maps okay.
  29. * */
  30. struct page {
  31. /* for cow, the reference count. we won't free if count-- */
  32. __uint32_t count;
  33. struct page *next;
  34. };
  35. /* okay, that's may only in the x86, but... */
  36. struct zone {
  37. __uint32_t total_pages;
  38. #define ZONETYPE_RAM 1
  39. #define ZONETYPE_OTHER 0
  40. __uint32_t type;
  41. void *start_addr;
  42. struct page *pages;
  43. };
  44. /* sets by arch_mm_init */
  45. extern struct page *first_usable_ram;
  46. #define kmem_zones ((struct zone *) kernel_end)
  47. #define kmem_pages ((struct page *) (kmem_zones + 2))
  48. /* they're really early but fast. actually, most free() did nothing
  49. *
  50. * WARNING that you should't use align, because we didn't save old
  51. * freeptr and it will be cracked by it: not freeable */
  52. void *early_kmalloc(int nbytes, int align);
  53. int early_free(void *p, int nbytes);
  54. #endif
  55. #endif