Pager works until end of init_physmem_secondary

This commit is contained in:
Bahadir Balban
2009-08-09 17:22:13 +03:00
parent a45b5676ab
commit 02a3f1ac91
33 changed files with 607 additions and 556 deletions

View File

@@ -8,50 +8,79 @@
*/
#include <l4/api/capability.h>
#include <l4/generic/tcb.h>
#include <l4/generic/physmem.h>
#include <l4/generic/space.h>
#include <l4/generic/capability.h>
#include <l4/generic/container.h>
#include <l4/api/errno.h>
#include INC_API(syscall.h)
/* Error-checked kernel data request call */
int __sys_capability_control(unsigned int req, unsigned int flags, void *userbuf)
int task_read_capabilities(void *userbuf)
{
int err = 0;
#if 0
int copy_size, copy_offset = 0;
struct capability *cap;
int err;
/*
* Currently only pagers can
* read their own capabilities
*/
if (current != current->pager->tcb)
return -EPERM;
/* Determine size of pager capabilities */
copy_size = current->cap_list_ptr->ncaps * sizeof(*cap);
/* Validate user buffer for this copy size */
if ((err = check_access((unsigned long)userbuf, copy_size,
MAP_USR_RW_FLAGS, 1)) < 0)
return err;
/* Copy capabilities from list to buffer */
list_foreach_struct(cap,
&current->cap_list_ptr->caps,
list) {
memcpy(userbuf + copy_offset, cap, sizeof(*cap));
copy_offset += sizeof(*cap);
}
return 0;
}
/*
* Read, manipulate capabilities. Currently only capability read support.
*/
int sys_capability_control(unsigned int req, unsigned int flags, void *userbuf)
{
int err;
switch(req) {
case KDATA_PAGE_MAP:
// printk("Handling KDATA_PAGE_MAP request.\n");
if (check_access(vaddr, sizeof(page_map), MAP_USR_RW_FLAGS, 1) < 0)
return -EINVAL;
memcpy(dest, &page_map, sizeof(page_map));
/* Return number of capabilities the thread has */
case CAP_CONTROL_NCAPS:
if (current != current->pager->tcb)
return -EPERM;
if ((err = check_access((unsigned long)userbuf, sizeof(int),
MAP_USR_RW_FLAGS, 1)) < 0)
return err;
/* Copy ncaps value */
*((int *)userbuf) = current->cap_list_ptr->ncaps;
break;
case KDATA_BOOTDESC:
// printk("Handling KDATA_BOOTDESC request.\n");
if (check_access(vaddr, bootdesc->desc_size, MAP_USR_RW_FLAGS, 1) < 0)
return -EINVAL;
memcpy(dest, bootdesc, bootdesc->desc_size);
break;
case KDATA_BOOTDESC_SIZE:
// printk("Handling KDATA_BOOTDESC_SIZE request.\n");
if (check_access(vaddr, sizeof(unsigned int), MAP_USR_RW_FLAGS, 1) < 0)
return -EINVAL;
*(unsigned int *)dest = bootdesc->desc_size;
/* Return all capabilities as an array of capabilities */
case CAP_CONTROL_READ_CAPS:
err = task_read_capabilities(userbuf);
break;
default:
printk("Unsupported kernel data request.\n");
err = -1;
/* Invalid request id */
return -EINVAL;
}
#endif
return err;
return 0;
}
int sys_capability_control(unsigned int req, unsigned int flags, void *userbuf)
{
return __sys_capability_control(req, flags, userbuf);
}

View File

@@ -4,7 +4,7 @@
Import('env')
# The set of source files associated with this SConscript file.
src_local = ['head.S', 'vectors.S', 'syscall.S', 'exception.c', 'bootdesc.c']
src_local = ['head.S', 'vectors.S', 'syscall.S', 'exception.c']
obj = env.Object(src_local)
Return('obj')

View File

@@ -1,46 +0,0 @@
/*
* Reading of bootdesc forged at build time.
*
* Copyright (C) 2007 Bahadir Balban
*/
#include <l4/lib/printk.h>
#include <l4/lib/string.h>
#include <l4/generic/space.h>
#include INC_ARCH(linker.h)
#include INC_ARCH(bootdesc.h)
#include INC_GLUE(memory.h)
#include INC_PLAT(printascii.h)
#include INC_SUBARCH(mm.h)
struct bootdesc *bootdesc;
#if 0
void copy_bootdesc()
{
struct bootdesc *new = kzalloc(bootdesc->desc_size);
memcpy(new, bootdesc, bootdesc->desc_size);
remove_mapping((unsigned long)bootdesc);
bootdesc = new;
}
void read_bootdesc(void)
{
/*
* End of the kernel image is where bootdesc resides. Note this is
* not added to the page_map because it's meant to be discarded.
*/
// add_mapping(virt_to_phys(_end), (unsigned long)_end, PAGE_SIZE,
// MAP_USR_DEFAULT_FLAGS);
/* Get original bootdesc */
bootdesc = (struct bootdesc *)_end;
/* Determine end of physical memory used by loaded images. */
for (int i = 0; i < bootdesc->total_images; i++)
if (bootdesc->images[i].phys_end > __svc_images_end)
__svc_images_end = bootdesc->images[i].phys_end;
}
#endif

View File

@@ -4,7 +4,7 @@
Import('env')
# The set of source files associated with this SConscript file.
src_local = ['physmem.c', 'irq.c', 'scheduler.c', 'time.c', 'tcb.c', 'space.c', 'bootm.c', 'resource.c', 'container.c', 'capability.c']
src_local = ['irq.c', 'scheduler.c', 'time.c', 'tcb.c', 'space.c', 'bootm.c', 'resource.c', 'container.c', 'capability.c']
obj = env.Object(src_local)
Return('obj')

View File

@@ -17,15 +17,19 @@
* Add irqs, exceptions
*/
#define CONFIG_CONT0_PAGER_START 0x40000
#define CONFIG_CONT0_PHYS_END 0x1000000
#define CONFIG_CONT0_PHYS_START CONFIG_CONT0_PAGER_START
struct container_info cinfo[] = {
[0] = {
.name = "Codezero POSIX Services",
.npagers = 1,
.pager = {
[0] = {
.pager_lma = __pfn(0x38000),
.pager_lma = __pfn(CONFIG_CONT0_PAGER_START),
.pager_vma = __pfn(0xE0000000),
.pager_size = __pfn(0x96000),
.pager_size = __pfn(0x9F000),
.ncaps = 14,
.caps = {
[0] = {
@@ -67,8 +71,8 @@ struct container_info cinfo[] = {
.access = CAP_MAP_CACHED | CAP_MAP_UNCACHED
| CAP_MAP_READ | CAP_MAP_WRITE
| CAP_MAP_EXEC | CAP_MAP_UNMAP,
.start = __pfn(0x38000),
.end = __pfn(0x1000000), /* 16 MB for all posix services */
.start = __pfn(CONFIG_CONT0_PHYS_START),
.end = __pfn(CONFIG_CONT0_PHYS_END), /* 16 MB for all posix services */
},
[5] = {
.type = CAP_TYPE_IPC | CAP_RTYPE_CONTAINER,
@@ -269,9 +273,13 @@ int init_first_pager(struct pager *pager,
mutex_init(&space->lock);
space->pgd = current_pgd;
/* Initialize container relationships */
task->space = space;
task->container = cont;
pager->tcb = task;
task->pager = pager;
task->container = cont;
link_init(&task->cap_list.caps); /* TODO: Do this in tcb_alloc_init */
task->cap_list_ptr = &pager->cap_list;
/* Map the task's space */
add_mapping_pgd(pager->start_lma, pager->start_vma,
@@ -314,9 +322,12 @@ int init_pager(struct pager *pager, struct container *cont)
task->space = address_space_create(0);
task->container = cont;
/* Initialize container relationships */
pager->tcb = task;
task->pager = pager;
task->container = cont;
link_init(&task->cap_list.caps); /* TODO: Do this in tcb_alloc_init */
task->cap_list_ptr = &pager->cap_list;
add_mapping_pgd(pager->start_lma, pager->start_vma,
page_align_up(pager->memsize),

View File

@@ -1,93 +0,0 @@
/*
* Global physical memory descriptions.
*
* Copyright (C) 2007 Bahadir Balban
*/
#include <l4/generic/physmem.h>
#include <l4/generic/resource.h>
#include <l4/generic/tcb.h>
#include <l4/lib/list.h>
#include <l4/lib/spinlock.h>
#include INC_SUBARCH(mm.h)
#include INC_GLUE(memlayout.h)
#include INC_GLUE(memory.h)
#include INC_PLAT(offsets.h)
#include INC_PLAT(printascii.h)
#include INC_ARCH(linker.h)
struct page_bitmap page_map;
static void init_page_map(unsigned long start, unsigned long end)
{
page_map.pfn_start = __pfn(start);
page_map.pfn_end = __pfn(end);
set_page_map(start, __pfn(end - 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(unsigned long start, int numpages, int val)
{
unsigned long pfn_start = __pfn(start);
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;
}
/* Describes physical memory boundaries of the system. */
struct memdesc physmem;
/* Fills in the physmem structure with free physical memory information */
void physmem_init()
{
unsigned long start = (unsigned long)_start_kernel;
unsigned long end = (unsigned long)_end_kernel;
/* Initialise page map */
init_page_map(PHYS_MEM_START, PHYS_MEM_END);
/* Mark kernel areas as used */
set_page_map(virt_to_phys(start), __pfn(end - start), 1);
/* Map initial pgd area as used */
start = (unsigned long)__pt_start;
end = (unsigned long)__pt_end;
set_page_map(virt_to_phys(TASK_PGD(current)), __pfn(end - start), 1);
physmem.start = PHYS_MEM_START;
physmem.end = PHYS_MEM_END;
physmem.free_cur = __svc_images_end;
physmem.free_end = PHYS_MEM_END;
physmem.numpages = (PHYS_MEM_START - PHYS_MEM_END) / PAGE_SIZE;
}
void memory_init()
{
//init_pgalloc();
}

View File

@@ -8,7 +8,6 @@
#include <l4/lib/string.h>
#include <l4/lib/idpool.h>
#include <l4/generic/platform.h>
#include <l4/generic/physmem.h>
#include <l4/generic/scheduler.h>
#include <l4/generic/space.h>
#include <l4/generic/tcb.h>
@@ -17,7 +16,6 @@
#include <l4/generic/container.h>
#include INC_ARCH(linker.h)
#include INC_ARCH(asm.h)
#include INC_ARCH(bootdesc.h)
#include INC_SUBARCH(mm.h)
#include INC_SUBARCH(mmu_ops.h)
#include INC_GLUE(memlayout.h)

View File

@@ -6,7 +6,6 @@
#include <l4/lib/list.h>
#include <l4/lib/string.h>
#include <l4/lib/printk.h>
#include <l4/generic/physmem.h>
#include <l4/generic/space.h>
#include <l4/generic/tcb.h>
#include INC_SUBARCH(mm.h)