arch_mm.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* arch/x86/kernel/archx86_mm32.c
  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. #include <kernel/init.h>
  19. #include <kernel/module.h>
  20. #include <kernel/mm.h>
  21. #include <arch/archinfo.h>
  22. #include <arch/mm.h>
  23. #include <arch/string.h>
  24. #include <sys/types.h>
  25. extern char cano_putc(int);
  26. /* the most important work is: get total size of ram,
  27. * and initiallize page structures */
  28. int arch_mm_init(void) {
  29. struct e820_entry *e;
  30. struct zone *z;
  31. struct page *p;
  32. int i;
  33. __archptr_t addr;
  34. /* put them there, after that, are the page structures. */
  35. z = (struct zone *) &_end;
  36. p = (struct page *) ((struct zone *) &_end + 5);
  37. memset(z, 0, sizeof(struct zone) * 5);
  38. z[0].type = ZONETYPE_RAM;
  39. for (i = 1; i < 5; i++)
  40. z[i].type = ZONETYPE_OTHER;
  41. for (e = E820_ADDR; e < E820_ADDR + 32; e++) {
  42. if (e->type > E820_TYPE_MAX || !e->type)
  43. break;
  44. addr = PAGE_ALIGN(e->addr);
  45. if (z[e->type].start_addr > (void *) addr)
  46. z[e->type].start_addr = (void *) addr;
  47. z[e->type].total_pages++;
  48. /* now initiallize page structures */
  49. for (i = 0; i < PAGE_NR(e->len); i++) {
  50. p->pnr = PAGE_NR(addr);
  51. p->count = 0;
  52. p->next = p + 1;
  53. ++p;
  54. }
  55. }
  56. cano_putc('O');
  57. return 0;
  58. }
  59. arch_init(arch_mm_init);