mirror of
https://github.com/drasko/codezero.git
synced 2026-11-30 12:53:54 +01:00
Changes in merged posix pager mm0 initialization.
- Moved rootfs from being embedded to mm0 image to being an independent image. - MM0 boots up to start_init_process with updated boot convention.
This commit is contained in:
@@ -12,7 +12,15 @@
|
||||
extern unsigned long _end[];
|
||||
extern unsigned long pager_offset;
|
||||
|
||||
void read_bootdesc(struct initdata *initdata)
|
||||
struct svc_image *bootdesc_get_image_byname(char *name)
|
||||
{
|
||||
for (int i = 0; i < initdata.bootdesc->total_images; i++)
|
||||
if (!strncmp(initdata.bootdesc->images[i].name, name, strlen(name)))
|
||||
return &initdata.bootdesc->images[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
void read_boot_params()
|
||||
{
|
||||
int npages;
|
||||
struct bootdesc *bootdesc;
|
||||
@@ -24,16 +32,15 @@ void read_bootdesc(struct initdata *initdata)
|
||||
|
||||
/* Check if bootdesc is on an unmapped page */
|
||||
if (is_page_aligned(bootdesc))
|
||||
l4_map_helper(bootdesc - pager_offset, PAGE_SIZE);
|
||||
l4_map_helper(bootdesc - pager_offset, 1);
|
||||
|
||||
/* Allocate bootdesc sized structure */
|
||||
initdata->bootdesc = alloc_bootmem(bootdesc->desc_size, 0);
|
||||
initdata.bootdesc = alloc_bootmem(bootdesc->desc_size, 0);
|
||||
|
||||
/* Copy bootdesc to initdata */
|
||||
memcpy(initdata->bootdesc, bootdesc,
|
||||
memcpy(initdata.bootdesc, bootdesc,
|
||||
bootdesc->desc_size);
|
||||
|
||||
if (npages > 0)
|
||||
l4_unmap_helper((void *)page_align_up(_end),
|
||||
PAGE_SIZE * npages);
|
||||
l4_unmap_helper((void *)page_align_up(_end), npages);
|
||||
}
|
||||
|
||||
@@ -12,74 +12,3 @@
|
||||
#include <l4/generic/cap-types.h> /* TODO: Move this to API */
|
||||
#include <lib/malloc.h>
|
||||
|
||||
struct cap_list capability_list;
|
||||
|
||||
__initdata static struct capability *caparray;
|
||||
__initdata static int total_caps = 0;
|
||||
|
||||
/* Copy all init-memory allocated capabilities */
|
||||
void copy_boot_capabilities(struct initdata *initdata)
|
||||
{
|
||||
struct capability *cap;
|
||||
|
||||
for (int i = 0; i < total_caps; i++) {
|
||||
cap = kzalloc(sizeof(struct capability));
|
||||
|
||||
/* This copies kernel-allocated unique cap id as well */
|
||||
memcpy(cap, &caparray[i], sizeof(struct capability));
|
||||
|
||||
/* Initialize capability list */
|
||||
link_init(&cap->list);
|
||||
|
||||
/* Add capability to global cap list */
|
||||
list_insert(&capability_list.caps, &cap->list);
|
||||
}
|
||||
}
|
||||
|
||||
int read_kernel_capabilities(struct initdata *initdata)
|
||||
{
|
||||
int ncaps;
|
||||
int err;
|
||||
|
||||
/* Read number of capabilities */
|
||||
if ((err = l4_capability_control(CAP_CONTROL_NCAPS, 0, &ncaps)) < 0) {
|
||||
printf("l4_capability_control() reading # of capabilities failed.\n"
|
||||
"Could not complete CAP_CONTROL_NCAPS request.\n");
|
||||
goto error;
|
||||
}
|
||||
total_caps = ncaps;
|
||||
|
||||
/* Allocate array of caps from boot memory */
|
||||
caparray = alloc_bootmem(sizeof(struct capability) * ncaps, 0);
|
||||
|
||||
/* Read all capabilities */
|
||||
if ((err = l4_capability_control(CAP_CONTROL_READ_CAPS, 0, caparray)) < 0) {
|
||||
printf("l4_capability_control() reading of capabilities failed.\n"
|
||||
"Could not complete CAP_CONTROL_READ_CAPS request.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Set up initdata pointer to important capabilities */
|
||||
initdata->bootcaps = caparray;
|
||||
for (int i = 0; i < ncaps; i++) {
|
||||
/*
|
||||
* TODO: There may be multiple physmem caps!
|
||||
* This really needs to be considered as multiple
|
||||
* membanks!!!
|
||||
*/
|
||||
if ((caparray[i].type & CAP_RTYPE_MASK)
|
||||
== CAP_RTYPE_PHYSMEM) {
|
||||
initdata->physmem = &caparray[i];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
printf("%s: Error, pager has no physmem capability defined.\n",
|
||||
__TASKNAME__);
|
||||
goto error;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
BUG();
|
||||
}
|
||||
|
||||
|
||||
@@ -589,8 +589,6 @@ int vfs_write(unsigned long vnum, unsigned long file_offset,
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Writes updated file stats back to vfs. (e.g. new file size) */
|
||||
int vfs_update_file_stats(struct vm_file *f)
|
||||
{
|
||||
|
||||
+276
-158
@@ -3,15 +3,20 @@
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Bahadir Balban
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <mm/alloc_page.h>
|
||||
#include <lib/malloc.h>
|
||||
#include <lib/bit.h>
|
||||
#include <l4lib/arch/syscalls.h>
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/utcb.h>
|
||||
|
||||
#include <l4/lib/list.h>
|
||||
#include <l4/generic/cap-types.h> /* TODO: Move this to API */
|
||||
#include <l4/api/capability.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <mm/alloc_page.h>
|
||||
#include <lib/malloc.h>
|
||||
#include <lib/bit.h>
|
||||
|
||||
#include <task.h>
|
||||
#include <shm.h>
|
||||
#include <file.h>
|
||||
@@ -21,22 +26,30 @@
|
||||
#include <utcb.h>
|
||||
#include <bootm.h>
|
||||
#include <vfs.h>
|
||||
#include <init.h>
|
||||
#include <memory.h>
|
||||
#include <capability.h>
|
||||
|
||||
/* A separate list than the generic file list that keeps just the boot files */
|
||||
LINK_DECLARE(boot_file_list);
|
||||
|
||||
extern unsigned long _start_init[];
|
||||
extern unsigned long _end_init[];
|
||||
|
||||
/* Kernel data acquired during initialisation */
|
||||
__initdata struct initdata initdata;
|
||||
|
||||
void print_bootdesc(struct bootdesc *bd)
|
||||
{
|
||||
for (int i = 0; i < bd->total_images; i++) {
|
||||
printf("Task Image: %d\n", i);
|
||||
printf("Name: %s\n", bd->images[i].name);
|
||||
printf("Start: 0x%x\n", bd->images[i].phys_start);
|
||||
printf("End: 0x%x\n", bd->images[i].phys_end);
|
||||
}
|
||||
}
|
||||
|
||||
/* Physical memory descriptors */
|
||||
struct memdesc physmem; /* Initial, primitive memory descriptor */
|
||||
struct membank membank[1]; /* The memory bank */
|
||||
struct page *page_array; /* The physical page array based on mem bank */
|
||||
|
||||
|
||||
/* Capability descriptor list */
|
||||
struct cap_list capability_list;
|
||||
|
||||
__initdata static struct capability *caparray;
|
||||
__initdata static int total_caps = 0;
|
||||
|
||||
|
||||
void print_pfn_range(int pfn, int size)
|
||||
{
|
||||
@@ -45,36 +58,6 @@ void print_pfn_range(int pfn, int size)
|
||||
printf("Used: 0x%x - 0x%x\n", addr, end);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void print_page_map(struct page_bitmap *map)
|
||||
{
|
||||
unsigned int start_pfn = 0;
|
||||
unsigned int total_used = 0;
|
||||
int numpages = 0;
|
||||
|
||||
// printf("Page map: 0x%x-0x%x\n", map->pfn_start << PAGE_BITS, map->pfn_end << PAGE_BITS);
|
||||
for (int i = 0; i < (PHYSMEM_TOTAL_PAGES >> 5); i++) {
|
||||
for (int x = 0; x < WORD_BITS; x++) {
|
||||
if (map->map[i] & (1 << x)) { /* A used page found? */
|
||||
if (!start_pfn) /* First such page found? */
|
||||
start_pfn = (WORD_BITS * i) + x;
|
||||
total_used++;
|
||||
numpages++; /* Increase number of pages */
|
||||
} else { /* Either used pages ended or were never found */
|
||||
if (start_pfn) { /* We had a used page */
|
||||
/* Finished end of used range.
|
||||
* Print and reset. */
|
||||
//print_pfn_range(start_pfn, numpages);
|
||||
start_pfn = 0;
|
||||
numpages = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%s: Pagemap: Total of %d used physical pages. %d Kbytes used.\n", __TASKNAME__, total_used, total_used << 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* A specialised function for setting up the task environment of mm0.
|
||||
* Essentially all the memory regions are set up but a new task isn't
|
||||
@@ -133,115 +116,83 @@ int mm0_task_init(struct vm_file *f, unsigned long task_start,
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct vm_file *initdata_next_bootfile(struct initdata *initdata)
|
||||
/* Copy all init-memory allocated capabilities */
|
||||
void copy_boot_capabilities()
|
||||
{
|
||||
struct vm_file *file, *n;
|
||||
list_foreach_removable_struct(file, n,
|
||||
&initdata->boot_file_list,
|
||||
list) {
|
||||
list_remove_init(&file->list);
|
||||
return file;
|
||||
struct capability *cap;
|
||||
|
||||
for (int i = 0; i < total_caps; i++) {
|
||||
cap = kzalloc(sizeof(struct capability));
|
||||
|
||||
/* This copies kernel-allocated unique cap id as well */
|
||||
memcpy(cap, &caparray[i], sizeof(struct capability));
|
||||
|
||||
/* Initialize capability list */
|
||||
link_init(&cap->list);
|
||||
|
||||
/* Add capability to global cap list */
|
||||
list_insert(&capability_list.caps, &cap->list);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads boot files from init data, determines their task ids if they
|
||||
* match with particular servers, and starts the tasks.
|
||||
*/
|
||||
int start_boot_tasks(struct initdata *initdata)
|
||||
int read_pager_capabilities()
|
||||
{
|
||||
struct vm_file *file = 0, *fs0_file = 0, *mm0_file = 0, *n;
|
||||
struct tcb *fs0_task;
|
||||
struct svc_image *img;
|
||||
struct task_ids ids;
|
||||
struct link other_files;
|
||||
int total = 0;
|
||||
int ncaps;
|
||||
int err;
|
||||
|
||||
link_init(&other_files);
|
||||
/* Read number of capabilities */
|
||||
if ((err = l4_capability_control(CAP_CONTROL_NCAPS, 0, &ncaps)) < 0) {
|
||||
printf("l4_capability_control() reading # of capabilities failed.\n"
|
||||
"Could not complete CAP_CONTROL_NCAPS request.\n");
|
||||
goto error;
|
||||
}
|
||||
total_caps = ncaps;
|
||||
|
||||
/* Separate out special server tasks and regular files */
|
||||
do {
|
||||
file = initdata_next_bootfile(initdata);
|
||||
/* Allocate array of caps from boot memory */
|
||||
caparray = alloc_bootmem(sizeof(struct capability) * ncaps, 0);
|
||||
|
||||
if (file) {
|
||||
BUG_ON(file->type != VM_FILE_BOOTFILE);
|
||||
img = file->priv_data;
|
||||
if (img->name[0] == 'm' &&
|
||||
img->name[1] == 'm' &&
|
||||
img->name[2] == '0')
|
||||
mm0_file = file;
|
||||
else if (img->name[0] == 'f' &&
|
||||
img->name[1] == 's' &&
|
||||
img->name[2] == '0')
|
||||
fs0_file = file;
|
||||
else
|
||||
list_insert(&file->list, &other_files);
|
||||
} else
|
||||
break;
|
||||
} while (1);
|
||||
|
||||
if (!mm0_file || !fs0_file) {
|
||||
printf("%s: FATAL: Could not find images for %s, and/or %s\n",
|
||||
__PAGERNAME__, __PAGERNAME__, __VFSNAME__);
|
||||
BUG();
|
||||
/* Read all capabilities */
|
||||
if ((err = l4_capability_control(CAP_CONTROL_READ_CAPS, 0, caparray)) < 0) {
|
||||
printf("l4_capability_control() reading of capabilities failed.\n"
|
||||
"Could not complete CAP_CONTROL_READ_CAPS request.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* MM0 needs partial initialisation since it's already running. */
|
||||
// printf("%s: Initialising mm0 tcb.\n", __TASKNAME__);
|
||||
ids.tid = PAGER_TID;
|
||||
ids.spid = PAGER_TID;
|
||||
ids.tgid = PAGER_TID;
|
||||
|
||||
if (mm0_task_init(mm0_file, INITTASK_AREA_START,
|
||||
INITTASK_AREA_END, &ids) < 0)
|
||||
BUG();
|
||||
total++;
|
||||
|
||||
/* Initialise vfs with its predefined id */
|
||||
ids.tid = VFS_TID;
|
||||
ids.spid = VFS_TID;
|
||||
ids.tgid = VFS_TID;
|
||||
|
||||
// printf("%s: Initialising fs0\n",__TASKNAME__);
|
||||
BUG_ON((IS_ERR(fs0_task = boottask_exec(fs0_file, USER_AREA_START,
|
||||
USER_AREA_END, &ids))));
|
||||
total++;
|
||||
|
||||
/* Initialise other tasks */
|
||||
list_foreach_removable_struct(file, n, &other_files, list) {
|
||||
ids.tid = TASK_ID_INVALID;
|
||||
ids.spid = TASK_ID_INVALID;
|
||||
ids.tgid = TASK_ID_INVALID;
|
||||
list_remove_init(&file->list);
|
||||
BUG_ON(IS_ERR(boottask_exec(file, USER_AREA_START,
|
||||
USER_AREA_END, &ids)));
|
||||
total++;
|
||||
}
|
||||
|
||||
if (!total) {
|
||||
printf("%s: Could not start any tasks.\n",
|
||||
__TASKNAME__);
|
||||
BUG();
|
||||
/* Set up initdata pointer to important capabilities */
|
||||
initdata.bootcaps = caparray;
|
||||
for (int i = 0; i < ncaps; i++) {
|
||||
/*
|
||||
* TODO: There may be multiple physmem caps!
|
||||
* This really needs to be considered as multiple
|
||||
* membanks!!!
|
||||
*/
|
||||
if ((caparray[i].type & CAP_RTYPE_MASK)
|
||||
== CAP_RTYPE_PHYSMEM) {
|
||||
initdata.physmem = &caparray[i];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
printf("%s: Error, pager has no physmem capability defined.\n",
|
||||
__TASKNAME__);
|
||||
goto error;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern unsigned long _start_init[];
|
||||
extern unsigned long _end_init[];
|
||||
error:
|
||||
BUG();
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy all necessary data from initmem to real memory,
|
||||
* release initdata and any init memory used
|
||||
*/
|
||||
void copy_release_initdata(struct initdata *initdata)
|
||||
void release_initdata()
|
||||
{
|
||||
/*
|
||||
* Copy boot capabilities to a list of
|
||||
* real capabilities
|
||||
*/
|
||||
copy_boot_capabilities(initdata);
|
||||
copy_boot_capabilities();
|
||||
|
||||
/* Free and unmap init memory:
|
||||
*
|
||||
@@ -255,48 +206,215 @@ void copy_release_initdata(struct initdata *initdata)
|
||||
self_tid());
|
||||
}
|
||||
|
||||
|
||||
void init_mm(struct initdata *initdata)
|
||||
static void init_page_map(struct page_bitmap *pmap, unsigned long pfn_start, unsigned long pfn_end)
|
||||
{
|
||||
/* Initialise the page and bank descriptors */
|
||||
init_physmem_primary(initdata);
|
||||
pmap->pfn_start = pfn_start;
|
||||
pmap->pfn_end = pfn_end;
|
||||
set_page_map(pmap, pfn_start, pfn_end - pfn_start, 0);
|
||||
}
|
||||
|
||||
init_physmem_secondary(initdata, membank);
|
||||
/*
|
||||
* Marks pages in the global page_map as used or unused.
|
||||
*
|
||||
* @start = start page address to set, inclusive.
|
||||
* @numpages = number of pages to set.
|
||||
*/
|
||||
int set_page_map(struct page_bitmap *page_map, unsigned long pfn_start,
|
||||
int numpages, int val)
|
||||
{
|
||||
unsigned long pfn_end = pfn_start + numpages;
|
||||
unsigned long pfn_err = 0;
|
||||
|
||||
/* Initialise the page allocator on first bank. */
|
||||
init_page_allocator(membank[0].free, membank[0].end);
|
||||
|
||||
/* Initialise the zero page */
|
||||
init_devzero();
|
||||
|
||||
/* Initialise in-memory boot files */
|
||||
init_boot_files(initdata);
|
||||
|
||||
if (shm_pool_init() < 0) {
|
||||
printf("SHM initialisation failed.\n");
|
||||
BUG();
|
||||
if (page_map->pfn_start > pfn_start || page_map->pfn_end < pfn_start) {
|
||||
pfn_err = pfn_start;
|
||||
goto error;
|
||||
}
|
||||
if (page_map->pfn_end < pfn_end || page_map->pfn_start > pfn_end) {
|
||||
pfn_err = pfn_end;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (utcb_pool_init() < 0) {
|
||||
printf("SHM initialisation failed.\n");
|
||||
BUG();
|
||||
if (val)
|
||||
for (int i = pfn_start; i < pfn_end; i++)
|
||||
page_map->map[BITWISE_GETWORD(i)] |= BITWISE_GETBIT(i);
|
||||
else
|
||||
for (int i = pfn_start; i < pfn_end; i++)
|
||||
page_map->map[BITWISE_GETWORD(i)] &= ~BITWISE_GETBIT(i);
|
||||
return 0;
|
||||
error:
|
||||
BUG_MSG("Given page area is out of system page_map range: 0x%lx\n",
|
||||
pfn_err << PAGE_BITS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Allocates page descriptors and initialises them using page_map information */
|
||||
void init_physmem_secondary(struct membank *membank)
|
||||
{
|
||||
struct page_bitmap *pmap = initdata.page_map;
|
||||
int npages = pmap->pfn_end - pmap->pfn_start;
|
||||
|
||||
/* Allocation marks for the struct page array; npages, start, end */
|
||||
int pg_npages, pg_spfn, pg_epfn;
|
||||
unsigned long ffree_addr;
|
||||
|
||||
/*
|
||||
* Means the page array won't map one to one to pfns. That's ok,
|
||||
* but we dont allow it for now.
|
||||
*/
|
||||
// BUG_ON(pmap->pfn_start);
|
||||
|
||||
membank[0].start = __pfn_to_addr(pmap->pfn_start);
|
||||
membank[0].end = __pfn_to_addr(pmap->pfn_end);
|
||||
|
||||
/* First find the first free page after last used page */
|
||||
for (int i = 0; i < npages; i++)
|
||||
if ((pmap->map[BITWISE_GETWORD(i)] & BITWISE_GETBIT(i)))
|
||||
membank[0].free = (i + 1) * PAGE_SIZE;
|
||||
BUG_ON(membank[0].free >= membank[0].end);
|
||||
|
||||
/*
|
||||
* One struct page for every physical page. Calculate how many pages
|
||||
* needed for page structs, start and end pfn marks.
|
||||
*/
|
||||
pg_npages = __pfn(page_align_up((sizeof(struct page) * npages)));
|
||||
|
||||
/* These are relative pfn offsets to the start of the memory bank */
|
||||
|
||||
/* FIXME:
|
||||
* 1.) These values were only right when membank started from pfn 0.
|
||||
* 2.) Use set_page_map to set page map below instead of manually.
|
||||
*/
|
||||
pg_spfn = __pfn(membank[0].free);
|
||||
pg_epfn = pg_spfn + pg_npages;
|
||||
|
||||
/* Use free pages from the bank as the space for struct page array */
|
||||
membank[0].page_array = l4_map_helper((void *)membank[0].free,
|
||||
pg_npages);
|
||||
/* Update free memory left */
|
||||
membank[0].free += pg_npages * PAGE_SIZE;
|
||||
|
||||
/* Update page bitmap for the pages used for the page array */
|
||||
for (int i = pg_spfn; i < pg_epfn; i++)
|
||||
pmap->map[BITWISE_GETWORD(i)] |= BITWISE_GETBIT(i);
|
||||
|
||||
/* Initialise the page array */
|
||||
for (int i = 0; i < npages; i++) {
|
||||
link_init(&membank[0].page_array[i].list);
|
||||
|
||||
/* Set use counts for pages the kernel has already used up */
|
||||
if (!(pmap->map[BITWISE_GETWORD(i)] & BITWISE_GETBIT(i)))
|
||||
membank[0].page_array[i].refcnt = -1;
|
||||
else /* Last page used +1 is free */
|
||||
ffree_addr = (i + 1) * PAGE_SIZE;
|
||||
}
|
||||
|
||||
/* First free address must come up the same for both */
|
||||
BUG_ON(ffree_addr != membank[0].free);
|
||||
|
||||
/* Set global page array to this bank's array */
|
||||
page_array = membank[0].page_array;
|
||||
|
||||
/* Test that page/phys macros work */
|
||||
BUG_ON(phys_to_page(page_to_phys(&page_array[5])) != &page_array[5])
|
||||
}
|
||||
|
||||
|
||||
void init_pager(void)
|
||||
/* Fills in the physmem structure with free physical memory information */
|
||||
void init_physmem_primary()
|
||||
{
|
||||
unsigned long pfn_start, pfn_end, pfn_images_end = 0;
|
||||
struct bootdesc *bootdesc = initdata.bootdesc;
|
||||
|
||||
/* Allocate page map structure */
|
||||
initdata.page_map = alloc_bootmem(sizeof(struct page_bitmap) +
|
||||
((initdata.physmem->end -
|
||||
initdata.physmem->start)
|
||||
>> 5) + 1, 0);
|
||||
|
||||
/* Initialise page map from physmem capability */
|
||||
init_page_map(initdata.page_map,
|
||||
initdata.physmem->start,
|
||||
initdata.physmem->end);
|
||||
|
||||
/* Mark pager and other boot task areas as used */
|
||||
for (int i = 0; i < bootdesc->total_images; i++) {
|
||||
pfn_start =
|
||||
__pfn(page_align_up(bootdesc->images[i].phys_start));
|
||||
pfn_end = __pfn(page_align_up(bootdesc->images[i].phys_end));
|
||||
if (pfn_end > pfn_images_end)
|
||||
pfn_images_end = pfn_end;
|
||||
set_page_map(initdata.page_map, pfn_start,
|
||||
pfn_end - pfn_start, 1);
|
||||
}
|
||||
|
||||
physmem.start = initdata.physmem->start;
|
||||
physmem.end = initdata.physmem->end;
|
||||
|
||||
physmem.free_cur = pfn_images_end;
|
||||
physmem.free_end = physmem.end;
|
||||
physmem.numpages = __pfn(physmem.end - physmem.start);
|
||||
}
|
||||
|
||||
void init_physmem(void)
|
||||
{
|
||||
init_physmem_primary();
|
||||
|
||||
init_physmem_secondary(membank);
|
||||
|
||||
init_page_allocator(membank[0].free, membank[0].end);
|
||||
}
|
||||
|
||||
void init_execve(char *path)
|
||||
{
|
||||
/*
|
||||
* Find executable, and execute it by creating a new process
|
||||
* rather than replacing the current image (which is the pager!)
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
* To be removed later: This file copies in-memory elf image to the
|
||||
* initialized and formatted in-memory memfs filesystem.
|
||||
*/
|
||||
void copy_init_process(void)
|
||||
{
|
||||
//int fd = sys_open(find_task(self_tid()), "/test0", O_WRITE, 0)
|
||||
|
||||
//sys_write(find_task(self_tid()), fd, __test0_start, __test0_end - __test0_start);
|
||||
|
||||
//sys_close(find_task(self_tid()), fd);
|
||||
|
||||
}
|
||||
|
||||
void start_init_process(void)
|
||||
{
|
||||
/* Copy raw test0 elf image from memory to memfs first */
|
||||
copy_init_process();
|
||||
|
||||
init_execve("/test0");
|
||||
}
|
||||
|
||||
void init(void)
|
||||
{
|
||||
read_pager_capabilities();
|
||||
|
||||
pager_address_pool_init();
|
||||
|
||||
read_kernel_capabilities(&initdata);
|
||||
read_boot_params();
|
||||
|
||||
read_bootdesc(&initdata);
|
||||
init_physmem();
|
||||
|
||||
init_mm(&initdata);
|
||||
init_devzero();
|
||||
|
||||
start_boot_tasks(&initdata);
|
||||
shm_pool_init();
|
||||
|
||||
copy_release_initdata(&initdata);
|
||||
utcb_pool_init();
|
||||
|
||||
vfs_init();
|
||||
|
||||
start_init_process();
|
||||
|
||||
release_initdata();
|
||||
|
||||
mm0_test_global_vm_integrity();
|
||||
}
|
||||
|
||||
@@ -19,157 +19,4 @@
|
||||
#include <physmem.h>
|
||||
#include <bootm.h>
|
||||
|
||||
struct memdesc physmem; /* Initial, primitive memory descriptor */
|
||||
struct membank membank[1]; /* The memory bank */
|
||||
struct page *page_array; /* The physical page array based on mem bank */
|
||||
|
||||
|
||||
static void init_page_map(struct page_bitmap *pmap, unsigned long pfn_start, unsigned long pfn_end)
|
||||
{
|
||||
pmap->pfn_start = pfn_start;
|
||||
pmap->pfn_end = pfn_end;
|
||||
set_page_map(pmap, pfn_start, pfn_end - pfn_start, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Marks pages in the global page_map as used or unused.
|
||||
*
|
||||
* @start = start page address to set, inclusive.
|
||||
* @numpages = number of pages to set.
|
||||
*/
|
||||
int set_page_map(struct page_bitmap *page_map, unsigned long pfn_start,
|
||||
int numpages, int val)
|
||||
{
|
||||
unsigned long pfn_end = pfn_start + numpages;
|
||||
unsigned long pfn_err = 0;
|
||||
|
||||
if (page_map->pfn_start > pfn_start || page_map->pfn_end < pfn_start) {
|
||||
pfn_err = pfn_start;
|
||||
goto error;
|
||||
}
|
||||
if (page_map->pfn_end < pfn_end || page_map->pfn_start > pfn_end) {
|
||||
pfn_err = pfn_end;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (val)
|
||||
for (int i = pfn_start; i < pfn_end; i++)
|
||||
page_map->map[BITWISE_GETWORD(i)] |= BITWISE_GETBIT(i);
|
||||
else
|
||||
for (int i = pfn_start; i < pfn_end; i++)
|
||||
page_map->map[BITWISE_GETWORD(i)] &= ~BITWISE_GETBIT(i);
|
||||
return 0;
|
||||
error:
|
||||
BUG_MSG("Given page area is out of system page_map range: 0x%lx\n",
|
||||
pfn_err << PAGE_BITS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Allocates page descriptors and initialises them using page_map information */
|
||||
void init_physmem_secondary(struct initdata *initdata, struct membank *membank)
|
||||
{
|
||||
struct page_bitmap *pmap = initdata->page_map;
|
||||
int npages = pmap->pfn_end - pmap->pfn_start;
|
||||
|
||||
/* Allocation marks for the struct page array; npages, start, end */
|
||||
int pg_npages, pg_spfn, pg_epfn;
|
||||
unsigned long ffree_addr;
|
||||
|
||||
/*
|
||||
* Means the page array won't map one to one to pfns. That's ok,
|
||||
* but we dont allow it for now.
|
||||
*/
|
||||
// BUG_ON(pmap->pfn_start);
|
||||
|
||||
membank[0].start = __pfn_to_addr(pmap->pfn_start);
|
||||
membank[0].end = __pfn_to_addr(pmap->pfn_end);
|
||||
|
||||
/* First find the first free page after last used page */
|
||||
for (int i = 0; i < npages; i++)
|
||||
if ((pmap->map[BITWISE_GETWORD(i)] & BITWISE_GETBIT(i)))
|
||||
membank[0].free = (i + 1) * PAGE_SIZE;
|
||||
BUG_ON(membank[0].free >= membank[0].end);
|
||||
|
||||
/*
|
||||
* One struct page for every physical page. Calculate how many pages
|
||||
* needed for page structs, start and end pfn marks.
|
||||
*/
|
||||
pg_npages = __pfn(page_align_up((sizeof(struct page) * npages)));
|
||||
|
||||
/* These are relative pfn offsets to the start of the memory bank */
|
||||
|
||||
/* FIXME:
|
||||
* 1.) These values were only right when membank started from pfn 0.
|
||||
* 2.) Use set_page_map to set page map below instead of manually.
|
||||
*/
|
||||
pg_spfn = __pfn(membank[0].free);
|
||||
pg_epfn = pg_spfn + pg_npages;
|
||||
|
||||
/* Use free pages from the bank as the space for struct page array */
|
||||
membank[0].page_array = l4_map_helper((void *)membank[0].free,
|
||||
pg_npages);
|
||||
/* Update free memory left */
|
||||
membank[0].free += pg_npages * PAGE_SIZE;
|
||||
|
||||
/* Update page bitmap for the pages used for the page array */
|
||||
for (int i = pg_spfn; i < pg_epfn; i++)
|
||||
pmap->map[BITWISE_GETWORD(i)] |= BITWISE_GETBIT(i);
|
||||
|
||||
/* Initialise the page array */
|
||||
for (int i = 0; i < npages; i++) {
|
||||
link_init(&membank[0].page_array[i].list);
|
||||
|
||||
/* Set use counts for pages the kernel has already used up */
|
||||
if (!(pmap->map[BITWISE_GETWORD(i)] & BITWISE_GETBIT(i)))
|
||||
membank[0].page_array[i].refcnt = -1;
|
||||
else /* Last page used +1 is free */
|
||||
ffree_addr = (i + 1) * PAGE_SIZE;
|
||||
}
|
||||
|
||||
/* First free address must come up the same for both */
|
||||
BUG_ON(ffree_addr != membank[0].free);
|
||||
|
||||
/* Set global page array to this bank's array */
|
||||
page_array = membank[0].page_array;
|
||||
|
||||
/* Test that page/phys macros work */
|
||||
BUG_ON(phys_to_page(page_to_phys(&page_array[5])) != &page_array[5])
|
||||
}
|
||||
|
||||
|
||||
/* Fills in the physmem structure with free physical memory information */
|
||||
void init_physmem_primary(struct initdata *initdata)
|
||||
{
|
||||
unsigned long pfn_start, pfn_end, pfn_images_end = 0;
|
||||
struct bootdesc *bootdesc = initdata->bootdesc;
|
||||
|
||||
/* Allocate page map structure */
|
||||
initdata->page_map = alloc_bootmem(sizeof(struct page_bitmap) +
|
||||
((initdata->physmem->end -
|
||||
initdata->physmem->start)
|
||||
>> 5) + 1, 0);
|
||||
|
||||
/* Initialise page map from physmem capability */
|
||||
init_page_map(initdata->page_map,
|
||||
initdata->physmem->start,
|
||||
initdata->physmem->end);
|
||||
|
||||
/* Mark pager and other boot task areas as used */
|
||||
for (int i = 0; i < bootdesc->total_images; i++) {
|
||||
pfn_start =
|
||||
__pfn(page_align_up(bootdesc->images[i].phys_start));
|
||||
pfn_end = __pfn(page_align_up(bootdesc->images[i].phys_end));
|
||||
if (pfn_end > pfn_images_end)
|
||||
pfn_images_end = pfn_end;
|
||||
set_page_map(initdata->page_map, pfn_start,
|
||||
pfn_end - pfn_start, 1);
|
||||
}
|
||||
|
||||
physmem.start = initdata->physmem->start;
|
||||
physmem.end = initdata->physmem->end;
|
||||
|
||||
physmem.free_cur = pfn_images_end;
|
||||
physmem.free_end = physmem.end;
|
||||
physmem.numpages = __pfn(physmem.end - physmem.start);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user