Esempio n. 1
0
/**
 * Examine address space, create virtual physical memory and map it.
 */
static void
page_init (void)
{
    int i;
    int freemem_size = 0;

    /* Construct page descriptor table.
     * mem => memory not reserved or occupied by kernel code
     * freemem => memory available after page descriptor table is built
     */

    /* all pages from 0x100000 to the top should have an entry in page descriptor table */
    for (i = 0; i < e820map.nr_map; i++) {
        mem_size += (uint32_t)(e820map.map[i].size);
        if (e820map.map[i].type == E820_ARM)
            freemem_size += e820map.map[i].size;
    }

    pages = (struct Page *)(uint32_t)(e820map.map[e820map.nr_map-1].addr);
    npage = (mem_size) / PGSIZE;
    for (i = 0; i < npage; i++) {
        SetPageReserved (pages + i);
    }

    uintptr_t freemem = PADDR(ROUNDUP((uintptr_t)pages + sizeof(struct Page) * npage, PGSIZE));
    uint32_t freemem_npage = freemem_size / PGSIZE - npage * sizeof (struct Page) / PGSIZE;
    init_memmap(pa2page(freemem), freemem_npage);
}
Esempio n. 2
0
static void
page_init(void) {
	int i;
	/* struct e820map *memmap = (struct e820map *)0x0; */
	/* uint32_t maxpa = 0; */
	
	/* kprintf("e820map:\n"); */
	/* int i; */
    /* for (i = 0; i < memmap->nr_map; i ++) { */
    /*     uint64_t begin = memmap->map[i].addr, end = begin + memmap->map[i].size; */
    /*     kprintf("  memory: %08llx, [%08llx, %08llx], type = %d.\n", */
    /*             memmap->map[i].size, begin, end - 1, memmap->map[i].type); */
    /*     if (memmap->map[i].type == E820_ARM) { */
    /*         if (maxpa < end && begin < KMEMSIZE) { */
    /*             maxpa = end; */
    /*         } */
    /*     } */
    /* } */
    /* if (maxpa > KMEMSIZE) { */
    /*     maxpa = KMEMSIZE; */
    /* } */

    extern char end[];

    npage = RAM_SIZE / PGSIZE;
    pages = (struct Page *)ROUNDUP((void *)end, PGSIZE);

    for (i = 0; i < npage; i ++) {
        SetPageReserved(pages + i);
    }

    uintptr_t freemem = PADDR((uintptr_t)pages + sizeof(struct Page) * npage);
	uint32_t free_begin = ROUNDUP(freemem, PGSIZE), free_end = RAM_SIZE;
	init_memmap (pa2page(free_begin), (free_end - free_begin) / PGSIZE);

	kprintf ("free memory: [0x%x, 0x%x)\n", free_begin, free_end);

    /* for (i = 0; i < memmap->nr_map; i ++) { */
    /*     uint64_t begin = memmap->map[i].addr, end = begin + memmap->map[i].size; */
    /*     if (memmap->map[i].type == E820_ARM) { */
    /*         if (begin < freemem) { */
    /*             begin = freemem; */
    /*         } */
    /*         if (end > KMEMSIZE) { */
    /*             end = KMEMSIZE; */
    /*         } */
    /*         if (begin < end) { */
    /*             begin = ROUNDUP(begin, PGSIZE); */
    /*             end = ROUNDDOWN(end, PGSIZE); */
    /*             if (begin < end) { */
    /*                 init_memmap(pa2page(begin), (end - begin) / PGSIZE); */
    /*             } */
    /*         } */
    /*     } */
    /* } */
}
Esempio n. 3
0
File: pmm.c Progetto: TySag/project
/* pmm_init - initialize the physical memory management */
static void page_init(void)
{
	struct e820map *memmap = (struct e820map *)(0x8000 + KERNBASE);
	uint64_t maxpa = 0;

	kprintf("e820map:\n");
	int i;
	for (i = 0; i < memmap->nr_map; i++) {
		uint64_t begin = memmap->map[i].addr, end =
		    begin + memmap->map[i].size;
		kprintf("  memory: %08llx, [%08llx, %08llx], type = %d.\n",
			memmap->map[i].size, begin, end - 1,
			memmap->map[i].type);
		if (memmap->map[i].type == E820_ARM) {
			if (maxpa < end && begin < KMEMSIZE) {
				maxpa = end;
			}
		}
	}
	if (maxpa > KMEMSIZE) {
		maxpa = KMEMSIZE;
	}

	extern char end[];

	npage = maxpa / PGSIZE;
	pages = (struct Page *)ROUNDUP((void *)end, PGSIZE);

	for (i = 0; i < npage; i++) {
		SetPageReserved(pages + i);
	}

	uintptr_t freemem =
	    PADDR((uintptr_t) pages + sizeof(struct Page) * npage);

	for (i = 0; i < memmap->nr_map; i++) {
		uint64_t begin = memmap->map[i].addr, end =
		    begin + memmap->map[i].size;
		if (memmap->map[i].type == E820_ARM) {
			if (begin < freemem) {
				begin = freemem;
			}
			if (end > KMEMSIZE) {
				end = KMEMSIZE;
			}
			if (begin < end) {
				begin = ROUNDUP(begin, PGSIZE);
				end = ROUNDDOWN(end, PGSIZE);
				if (begin < end) {
					init_memmap(pa2page(begin),
						    (end - begin) / PGSIZE);
				}
			}
		}
	}
}
Esempio n. 4
0
void main(int argc, char * argv[]) 
{
	//Set up gpio to be pointer to chunk of memory that includes I/O.
	//gets around virtual memory issues too.
	gpio=init_memmap();
	
	set_dir(38,OUT);
	while(1)
	{
		set_pin(38);
		clear_pin(38);
	}
}
Esempio n. 5
0
/* pmm_init - initialize the physical memory management */
static void
page_init(void) {
	extern char realend[];
    struct e820map *memmap = (struct e820map *)(0xf0000000);

    memmap->nr_map=1;
    memmap->map[0].type=E820_ARM;
    memmap->map[0].size=KMEMSIZE;
    memmap->map[0].addr=realend;

    uint32_t maxpa = 0;
    //cprintf("KMEMSIZE=%x\n",KMEMSIZE);

    cprintf("e820map:\n");
    int i;
    for (i = 0; i < memmap->nr_map; i ++) {
        uint64_t begin = memmap->map[i].addr, end = begin + memmap->map[i].size;
        cprintf("  memory: %08llx, [%08llx, %08llx], type = %d.\n",
                memmap->map[i].size, begin, end - 1, memmap->map[i].type);
        if (memmap->map[i].type == E820_ARM) {
            if (maxpa < end && begin < KMEMSIZE) {
            	//cprintf("end")
                maxpa = end;
            }
        }
    }
    if (maxpa > KMEMSIZE) {
        maxpa = KMEMSIZE;
    }
    //cprintf("maxpa=%x\n",maxpa);
    //extern char end[];

    npage = maxpa / PGSIZE;
    pages = (struct Page *)ROUNDUP((void *)realend, PGSIZE);
    //cprintf("npage=%d\n",npage);

    for (i = 0; i < npage; i ++) {
        SetPageReserved(pages + i);
    }

    uintptr_t freemem = PADDR((uintptr_t)pages + sizeof(struct Page) * npage);
    cprintf("realend=%08x,freemem=%08x\n",realend,freemem);
    for (i = 0; i < memmap->nr_map; i ++) {
        uint32_t begin = memmap->map[i].addr, end = begin + memmap->map[i].size;
        if (memmap->map[i].type == E820_ARM) {
            if (begin < freemem) {
                begin = freemem;
            }
            if (end > KMEMSIZE) {
                end = KMEMSIZE;
            }
            if (begin < end) {
                begin = ROUNDUP(begin, PGSIZE);
                end = ROUNDDOWN(end, PGSIZE);
                if (begin < end) {
                    init_memmap(pa2page(begin), (end - begin) / PGSIZE);
                }//default_pmm_manager
            }
        }
    }
    //struct Page* pg=alloc_page();
    //cprintf("pg=%08x\n",page2pa(pg));
}