mm.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of Cunix. */
  3. /*
  4. Cunix 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) and later version.
  8. */
  9. /*
  10. Cunix 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. /*
  16. You should have received a copy of the GNU General Public License
  17. along with Cunix. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef INCLUDED_MM_H
  20. #define INCLUDED_MM_H
  21. #include <kernel/types.h>
  22. #include <kernel/errno.h>
  23. #include <lib/bitman.h>
  24. /* we should use &_end, not _end because they're empty symbols. */
  25. /* define in kernel.lds */
  26. extern __uint64_t _text, _etext;
  27. extern __uint64_t _data, _edata;
  28. extern __uint64_t _rodata, _erodata;
  29. extern __uint64_t _bss, _ebss;
  30. extern __uint64_t _end;
  31. struct e820_entry {
  32. __uint64_t addr;
  33. __uint64_t len;
  34. __uint32_t type;
  35. } __attribute__ ((packed));
  36. /* | 1MB | | total pages / 8 | | */
  37. /* | E820 | KERNEL | PAGE BITMAP | HIGH MEMORY | */
  38. struct mm {
  39. __uint64_t total_ram;
  40. __uint64_t total_pages;
  41. __uint64_t usable_pages;
  42. struct e820_entry *e820;
  43. __uint64_t e820_entries;
  44. struct bitmap_manager pages_bitman;
  45. };
  46. extern struct mm mman;
  47. #define E820_ADDR ((struct e820_entry *) 0x0000000000006000)
  48. errno_t mem_init(void);
  49. void *palloc(void);
  50. void pfree(void *addr);
  51. #define PAGE_2M_SIZE 0x200000UL
  52. #define PAGE_2M_SHIFT 21UL
  53. #define PAGE_2M_MASK (~(PAGE_2M_SIZE - 1))
  54. #define PAGE_4K_SIZE 0x1000UL
  55. #define PAGE_4K_SHIFT 12UL
  56. #define PAGE_4K_MASK (~(PAGE_4K_SIZE - 1))
  57. #endif