Add memory initialization to start_kernel.c
This commit is contained in:
parent
0b3865d16a
commit
563ad96efb
@ -1,3 +1,4 @@
|
|||||||
|
#include <mm.h>
|
||||||
#include <print.h>
|
#include <print.h>
|
||||||
#include <devices/pl011.h>
|
#include <devices/pl011.h>
|
||||||
|
|
||||||
@ -5,21 +6,66 @@
|
|||||||
#include <framebuffer.h>
|
#include <framebuffer.h>
|
||||||
#include <console.h>
|
#include <console.h>
|
||||||
|
|
||||||
|
extern const unsigned int kernel_end;
|
||||||
|
|
||||||
struct fb myfb;
|
struct fb myfb;
|
||||||
|
|
||||||
void video(void) {
|
void video(void) {
|
||||||
// unsigned int x, y;
|
unsigned int x, y;
|
||||||
pl111_init(&myfb, 24);
|
pl111_init(&myfb, 24);
|
||||||
// x = 0, y = 0;
|
x = 0, y = 0;
|
||||||
// for (y=0; y<480; y++)
|
for (y=0; y<480; y++)
|
||||||
// for (x=0; x<640; x++)
|
for (x=0; x<640; x++)
|
||||||
// fb_write_pixel(&myfb, x, y, 0x3f, 0x0, 0x6f);
|
fb_write_pixel(&myfb, x, y, 0x3f, 0x0, 0x6f);
|
||||||
|
|
||||||
console_init(&myfb);
|
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) {
|
int main(void) {
|
||||||
|
char *lower;
|
||||||
print_init(&pl011_putc); //initialize the serial console
|
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();
|
video();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user