You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.3 KiB

  1. /*
  2. Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
  3. This file is part of Aedrix.
  4. This program 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 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include <atags.h>
  17. #include <mmu.h>
  18. #include <mm.h>
  19. #include <print.h>
  20. #include <devices/pl011.h>
  21. #include <devices/pl111.h>
  22. #include <framebuffer.h>
  23. #include <console.h>
  24. struct fb myfb;
  25. void video(void) {
  26. unsigned int x, y;
  27. pl111_init(&myfb, 24);
  28. x = 0, y = 0;
  29. for (y=0; y<480; y++)
  30. for (x=0; x<640; x++)
  31. fb_write_pixel(&myfb, x, y, 0x3f, 0x0, 0x6f);
  32. console_init(&myfb);
  33. }
  34. void test_memory() {
  35. struct page *p, *q;
  36. p = mm_get_free_pages(0);
  37. if (p)
  38. print("%x, %x\n", p, p->address);
  39. else
  40. print("Error: failed to allocate memory for p\n");
  41. q = mm_get_free_pages(4);
  42. if (q)
  43. print("%x, %x\n", q, q->address);
  44. else
  45. print("Error: failed to allocate memory for q\n");
  46. mm_put_free_pages(p);
  47. mm_put_free_pages(q);
  48. q = mm_get_free_pages(1);
  49. if (q)
  50. print("%x, %x\n", q, q->address);
  51. else
  52. print("Error: failed to allocate memory for q\n");
  53. p = mm_get_free_pages(0);
  54. if (p)
  55. print("%x, %x\n", p, p->address);
  56. else
  57. print("Error: failed to allocate memory for p\n");
  58. }
  59. int main(void) {
  60. char *lower, *upper;
  61. struct atag *atags;
  62. //setup MMU
  63. mmu_reinit();
  64. //initialize the serial console
  65. print_init(&pl011_putc);
  66. //setup memory
  67. mm_init();
  68. if (atags_first_mem_region(&atags)) {
  69. print("Error: atags must contain at least one memory region\n");
  70. return -1;
  71. }
  72. do {
  73. lower = (char *)atags->data.mem.start;
  74. upper = lower + atags->data.mem.size - 1;
  75. declare_memory_region(lower, upper);
  76. } while (!atags_next_mem_region(&atags));
  77. test_memory();
  78. video();
  79. return 0;
  80. }