mm.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. *
  29. * we should initiallize this as late as we can, after maps okay.
  30. * */
  31. struct page {
  32. /* number of this page */
  33. __archptr_t pnr;
  34. /* for cow, the reference count. we won't free if count-- */
  35. __uint32_t count;
  36. struct page *next;
  37. };
  38. /* okay, that's may only in the x86, but... */
  39. struct zone {
  40. __uint32_t total_pages;
  41. #define ZONETYPE_RAM 1
  42. #define ZONETYPE_OTHER 0
  43. __uint32_t type;
  44. void *start_addr;
  45. struct page *pages;
  46. };
  47. #define kmem_zones ((struct zone *) &_end)
  48. #define kmem_pages ((struct page *) (kmem_zones[2]))
  49. /* they're really early but fast. actually, most free() did nothing
  50. *
  51. * WARNING that you should't use align, because we didn't save old
  52. * freeptr and it will be cracked by it: not freeable */
  53. void *early_kmalloc(int nbytes, int align);
  54. int early_free(void *p, int nbytes);
  55. #endif
  56. #endif