1
0
aedrix-kernel/kernel/start_kernel.c

149 lines
3.0 KiB
C

/*
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.
*/
#include <atags.h>
#include <kmalloc.h>
#include <mmu.h>
#include <mm.h>
#include <print.h>
#include <devices/pi_mini_uart.h>
#include <devices/bcm2835_videocore.h>
#include <framebuffer.h>
#include <console.h>
struct fb myfb;
void video(void) {
unsigned int x, y;
bcm2835_videocore_init(&myfb, 16);
for (y = 0; y < myfb.height; y++)
for (x = 0; x < myfb.width; x++)
fb_write_pixel(&myfb, x, y, 0x3f, 0x0, 0x6f);
console_init(&myfb);
}
void test_mm() {
struct page *p, *q;
print("\ntest_mm():\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");
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");
mm_put_free_pages(p);
mm_put_free_pages(q);
}
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();
int main(void) {
char *lower, *upper;
struct atag *atags;
//setup MMU
mmu_reinit();
//initialize the serial console
mini_uart_init();
print_init(&mini_uart_putc);
//setup memory
mm_init();
kmalloc_init();
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));
test_memory();
video();
return 0;
}