2012-09-26 23:59:58 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
|
|
|
|
|
|
|
|
This file is part of Aedrix.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2012-09-25 22:44:19 -04:00
|
|
|
#include <atags.h>
|
2012-09-28 00:59:25 -04:00
|
|
|
#include <kmalloc.h>
|
2012-09-21 11:52:24 -04:00
|
|
|
#include <mmu.h>
|
2012-09-17 23:33:50 -04:00
|
|
|
#include <mm.h>
|
2012-09-07 23:56:32 -04:00
|
|
|
#include <print.h>
|
|
|
|
#include <framebuffer.h>
|
2012-09-09 01:58:38 -04:00
|
|
|
#include <console.h>
|
2012-09-07 23:56:32 -04:00
|
|
|
|
2012-10-03 00:19:28 -04:00
|
|
|
#ifdef CONFIG_VEXPRESS_A9
|
|
|
|
#include <devices/pl011.h>
|
|
|
|
#include <devices/pl111.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_RPI
|
|
|
|
#include <devices/pi_mini_uart.h>
|
|
|
|
#include <devices/bcm2835_videocore.h>
|
|
|
|
#endif
|
|
|
|
|
2012-09-07 23:56:32 -04:00
|
|
|
struct fb myfb;
|
|
|
|
|
2012-10-02 23:17:25 -04:00
|
|
|
void print_console_logo() {
|
|
|
|
print_func(&console_putc, " _ _ _\n");
|
|
|
|
print_func(&console_putc, " / \\ ___ __| |_ __(_)_ __\n");
|
|
|
|
print_func(&console_putc, " / _ \\ / _ \\/ _` | '__| \\ \\/ /\n");
|
|
|
|
print_func(&console_putc, " / ___ \\ __/ (_| | | | |> <\n");
|
|
|
|
print_func(&console_putc, " /_/ \\_\\___|\\__,_|_| |_/_/\\_\\\n\n");
|
|
|
|
print_func(&console_putc, " Copyright (C) 2012 - Aaron Lindsay\n");
|
|
|
|
}
|
2012-09-17 23:33:50 -04:00
|
|
|
|
2012-10-02 23:17:25 -04:00
|
|
|
void video_init(void) {
|
2012-10-03 00:19:28 -04:00
|
|
|
#ifdef CONFIG_VEXPRESS_A9
|
|
|
|
pl111_init(&myfb, 16);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_RPI
|
2012-10-02 23:17:25 -04:00
|
|
|
bcm2835_videocore_init(&myfb, 16);
|
2012-10-03 00:19:28 -04:00
|
|
|
#endif
|
2012-09-07 23:56:32 -04:00
|
|
|
}
|
2012-09-17 23:33:50 -04:00
|
|
|
|
2012-09-28 00:59:25 -04:00
|
|
|
void test_mm() {
|
2012-09-17 23:33:50 -04:00
|
|
|
struct page *p, *q;
|
2012-09-28 00:59:25 -04:00
|
|
|
|
|
|
|
print("\ntest_mm():\n");
|
|
|
|
|
2012-09-17 23:33:50 -04:00
|
|
|
p = mm_get_free_pages(0);
|
|
|
|
if (p)
|
|
|
|
print("%x, %x\n", p, p->address);
|
|
|
|
else
|
|
|
|
print("Error: failed to allocate memory for p\n");
|
|
|
|
|
|
|
|
q = mm_get_free_pages(4);
|
|
|
|
if (q)
|
|
|
|
print("%x, %x\n", q, q->address);
|
|
|
|
else
|
|
|
|
print("Error: failed to allocate memory for q\n");
|
|
|
|
|
|
|
|
mm_put_free_pages(p);
|
|
|
|
mm_put_free_pages(q);
|
|
|
|
|
|
|
|
q = mm_get_free_pages(1);
|
|
|
|
if (q)
|
|
|
|
print("%x, %x\n", q, q->address);
|
|
|
|
else
|
|
|
|
print("Error: failed to allocate memory for q\n");
|
|
|
|
|
|
|
|
p = mm_get_free_pages(0);
|
|
|
|
if (p)
|
|
|
|
print("%x, %x\n", p, p->address);
|
|
|
|
else
|
|
|
|
print("Error: failed to allocate memory for p\n");
|
2012-09-28 00:59:25 -04:00
|
|
|
mm_put_free_pages(p);
|
|
|
|
mm_put_free_pages(q);
|
2012-09-17 23:33:50 -04:00
|
|
|
|
|
|
|
}
|
2012-09-28 00:59:25 -04:00
|
|
|
|
|
|
|
void test_kmalloc() {
|
|
|
|
void *a, *b, *c, *d;
|
|
|
|
|
|
|
|
print("\ntest_kmalloc():\n");
|
|
|
|
|
|
|
|
a = kmalloc(4);
|
|
|
|
print("a: %x\n", a);
|
|
|
|
b = kmalloc(13);
|
|
|
|
print("b: %x\n", b);
|
|
|
|
c = kmalloc(4);
|
|
|
|
print("c: %x\n", c);
|
|
|
|
d = kmalloc(25);
|
|
|
|
print("d: %x\n", d);
|
|
|
|
|
|
|
|
kfree(c);
|
|
|
|
kfree(b);
|
|
|
|
kfree(a);
|
|
|
|
kfree(d);
|
|
|
|
|
|
|
|
a = kmalloc(13);
|
|
|
|
print("a: %x\n", a);
|
|
|
|
b = kmalloc(4);
|
|
|
|
print("b: %x\n", b);
|
|
|
|
c = kmalloc(25);
|
|
|
|
print("c: %x\n", c);
|
|
|
|
d = kmalloc(7);
|
|
|
|
print("d: %x\n", d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_memory() {
|
|
|
|
test_mm();
|
|
|
|
test_kmalloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
void kmalloc_init();
|
2012-09-07 23:56:32 -04:00
|
|
|
|
2012-09-09 01:58:38 -04:00
|
|
|
int main(void) {
|
2012-09-25 22:44:19 -04:00
|
|
|
char *lower, *upper;
|
|
|
|
struct atag *atags;
|
2012-09-21 11:52:24 -04:00
|
|
|
|
|
|
|
//setup MMU
|
|
|
|
mmu_reinit();
|
|
|
|
|
2012-09-26 23:59:58 -04:00
|
|
|
//initialize the serial console
|
2012-10-03 00:19:28 -04:00
|
|
|
#ifdef CONFIG_VEXPRESS_A9
|
|
|
|
print_init(&pl011_putc);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_RPI
|
2012-09-29 23:29:35 -04:00
|
|
|
mini_uart_init();
|
|
|
|
print_init(&mini_uart_putc);
|
2012-10-03 00:19:28 -04:00
|
|
|
#endif
|
2012-09-07 23:56:32 -04:00
|
|
|
|
2012-09-17 23:33:50 -04:00
|
|
|
//setup memory
|
|
|
|
mm_init();
|
2012-09-28 00:59:25 -04:00
|
|
|
kmalloc_init();
|
2012-09-25 22:44:19 -04:00
|
|
|
|
|
|
|
if (atags_first_mem_region(&atags)) {
|
|
|
|
print("Error: atags must contain at least one memory region\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
lower = (char *)atags->data.mem.start;
|
|
|
|
upper = lower + atags->data.mem.size - 1;
|
|
|
|
declare_memory_region(lower, upper);
|
|
|
|
} while (!atags_next_mem_region(&atags));
|
2012-09-17 23:33:50 -04:00
|
|
|
|
|
|
|
test_memory();
|
|
|
|
|
2012-10-02 23:17:25 -04:00
|
|
|
video_init();
|
|
|
|
console_init(&myfb);
|
|
|
|
print_console_logo();
|
2012-09-07 23:56:32 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|