1
0
aedrix-kernel/kernel/start_kernel.c

78 lines
1.5 KiB
C

#include <mmu.h>
#include <mm.h>
#include <print.h>
#include <devices/pl011.h>
#include <devices/pl111.h>
#include <framebuffer.h>
#include <console.h>
extern const unsigned int kernel_end;
struct fb myfb;
void video(void) {
unsigned int x, y;
pl111_init(&myfb, 24);
x = 0, y = 0;
for (y=0; y<480; y++)
for (x=0; x<640; x++)
fb_write_pixel(&myfb, x, y, 0x3f, 0x0, 0x6f);
console_init(&myfb);
}
void test_memory() {
struct page *p, *q;
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");
}
int main(void) {
char *lower;
//setup MMU
mmu_reinit();
print_init(&pl011_putc); //initialize the serial console
//setup memory
mm_init();
mm_add_free_region((void*)0x60000000, (void*)0x7FFFFFFF);
lower = (char*) &kernel_end;
if ((unsigned int)lower % MM_PAGE_SIZE != 0)
lower += (MM_PAGE_SIZE - ((unsigned int)lower % MM_PAGE_SIZE));
mm_add_free_region((void*)lower, (void*)0x9FFFFFFF); //subtract the memory used by the kernel
test_memory();
video();
return 0;
}