mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
Added autogeneration of cinfo.c with memory capabilities
Also fixed a bug with configurator in that the containers were not sorted properly and consequently an already filled in container was getting overwritten by the new one. modified: config/configuration.py modified: configure.py new file: generate_kernel_cinfo.py deleted: src/generic/cinfo.c
This commit is contained in:
@@ -4,11 +4,11 @@ import os, sys, shelve, shutil, re
|
||||
from projpaths import *
|
||||
|
||||
class Container:
|
||||
def __init__(self):
|
||||
def __init__(self, id):
|
||||
self.dirname = None
|
||||
self.name = None
|
||||
self.type = None
|
||||
self.id = None
|
||||
self.id = id
|
||||
self.pager_lma = None
|
||||
self.pager_vma = None
|
||||
self.pager_size = None
|
||||
@@ -124,33 +124,48 @@ class configuration:
|
||||
|
||||
# Check and store info on this parameter
|
||||
self.get_container_parameter(id, param, val)
|
||||
#self.containers_print(self.containers)
|
||||
|
||||
# Used for sorting container members,
|
||||
# with this we are sure containers are sorted by id value
|
||||
@staticmethod
|
||||
def compare_containers(cont, cont2):
|
||||
if cont.id < cont2.id:
|
||||
return -1
|
||||
if cont.id == cont2.id:
|
||||
print "compare_containers: Error, containers have same id."
|
||||
exit(1)
|
||||
if cont.id > cont2.id:
|
||||
return 1
|
||||
|
||||
def check_add_container(self, id):
|
||||
for cont in self.containers:
|
||||
if id == cont.id:
|
||||
return
|
||||
|
||||
# New container created. TODO: Pass id to constructor
|
||||
container = Container()
|
||||
container.id = id
|
||||
container = Container(id)
|
||||
self.containers.append(container)
|
||||
|
||||
# Make sure elements in order for indexed accessing
|
||||
self.containers.sort()
|
||||
self.containers.sort(self.compare_containers)
|
||||
|
||||
|
||||
def containers_print(self, containers):
|
||||
for c in containers:
|
||||
print '\nContainer %d' % c.id
|
||||
print 'Container type: %s' % string.ljust(c.type, 10)
|
||||
print 'Container lma: %s' % string.ljust('%s - %s' % (c.lma_start, c.lma_end), 10)
|
||||
print 'Container vma: %s' % string.ljust('%s - %s' % (c.vma_start, c.vma_end), 10)
|
||||
print 'Container type: %s' % c.type
|
||||
print 'Container Name: %s' % c.name
|
||||
print 'Container Pager lma: %s' % c.pager_lma
|
||||
print 'Container Pager vma: %s' % c.pager_vma
|
||||
print 'Container Pager size: %s' % c.pager_size
|
||||
print 'Container Virtual regions: %s' % c.virt_regions
|
||||
print 'Container Physical regions: %s' % c.phys_regions
|
||||
|
||||
def config_print(self):
|
||||
print 'Configuration\n'
|
||||
print '-------------\n'
|
||||
print 'Arch: %s' % string.ljust('%s, %s' % (self.arch, self.subarch), 16)
|
||||
print 'Platform: %s' % string.ljust(self.platform, 16)
|
||||
print 'Arch: %s, %s' % (self.arch, self.subarch)
|
||||
print 'Platform: %s' % self.platform
|
||||
print 'Symbols:\n %s' % self.all
|
||||
print 'Containers: %s' % self.ncontainers
|
||||
self.containers_print(self.containers)
|
||||
@@ -158,6 +173,8 @@ class configuration:
|
||||
def configuration_save(config):
|
||||
if not os.path.exists(CONFIG_SHELVE_DIR):
|
||||
os.mkdir(CONFIG_SHELVE_DIR)
|
||||
if os.path.exists(CONFIG_SHELVE):
|
||||
shutil.rmtree(CONFIG_SHELVE)
|
||||
|
||||
config_shelve = shelve.open(CONFIG_SHELVE)
|
||||
config_shelve["configuration"] = config
|
||||
@@ -168,7 +185,6 @@ def configuration_save(config):
|
||||
config_shelve["all_symbols"] = config.all
|
||||
config_shelve.close()
|
||||
|
||||
|
||||
def configuration_retrieve():
|
||||
# Get configuration information
|
||||
config_shelve = shelve.open(CONFIG_SHELVE)
|
||||
|
||||
@@ -56,8 +56,6 @@ def configure_kernel(cml_file):
|
||||
bare_cont_gen = BareContGenerator()
|
||||
bare_cont_gen.bare_container_generate(config)
|
||||
|
||||
#config.config_print()
|
||||
|
||||
if __name__ == "__main__":
|
||||
configure_kernel(join(CML2_CONFIG_SRCDIR, "arm.cml"))
|
||||
|
||||
|
||||
135
generate_kernel_cinfo.py
Executable file
135
generate_kernel_cinfo.py
Executable file
@@ -0,0 +1,135 @@
|
||||
#! /usr/bin/env python2.6
|
||||
# -*- mode: python; coding: utf-8; -*-
|
||||
#
|
||||
# Codezero -- a microkernel for embedded systems.
|
||||
#
|
||||
# Copyright © 2009 B Labs Ltd
|
||||
#
|
||||
import os, sys, shelve, glob
|
||||
from os.path import join
|
||||
|
||||
PROJRELROOT = '.'
|
||||
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
|
||||
sys.path.append(os.path.abspath("../"))
|
||||
|
||||
from config.projpaths import *
|
||||
from config.configuration import *
|
||||
|
||||
|
||||
cinfo_file_start = \
|
||||
'''/*
|
||||
* Autogenerated container descriptions
|
||||
* defined for the current build.
|
||||
*
|
||||
* Copyright (C) 2009 Bahadir Balban
|
||||
*/
|
||||
#include <l4/generic/container.h>
|
||||
#include <l4/generic/resource.h>
|
||||
#include <l4/generic/capability.h>
|
||||
#include <l4/generic/cap-types.h>
|
||||
|
||||
/*
|
||||
* FIXME:
|
||||
* Add irqs, exceptions
|
||||
*/
|
||||
|
||||
struct container_info cinfo[] = {
|
||||
'''
|
||||
cinfo_file_end = \
|
||||
'''
|
||||
};
|
||||
'''
|
||||
|
||||
cinfo_start = \
|
||||
'''
|
||||
\t[%d] = {
|
||||
\t.name = "%s",
|
||||
\t.npagers = 1,
|
||||
\t.pager = {
|
||||
'''
|
||||
|
||||
cinfo_end = \
|
||||
'''
|
||||
\t\t},
|
||||
\t},
|
||||
'''
|
||||
|
||||
pager_start = \
|
||||
'''
|
||||
\t\t[0] = {
|
||||
\t\t\t.pager_lma = __pfn(CONFIG_CONT%d_PAGER_LMA),
|
||||
\t\t\t.pager_vma = __pfn(CONFIG_CONT%d_PAGER_VMA),
|
||||
\t\t\t.pager_size = __pfn(CONFIG_CONT%d_PAGER_SIZE),
|
||||
\t\t\t.ncaps = %d,
|
||||
\t\t\t.caps = {
|
||||
'''
|
||||
pager_end = \
|
||||
'''
|
||||
\t\t\t},
|
||||
\t\t},
|
||||
'''
|
||||
|
||||
cap_virtmem = \
|
||||
'''
|
||||
\t\t\t[%d] = {
|
||||
\t\t\t\t.type = CAP_TYPE_MAP | CAP_RTYPE_VIRTMEM,
|
||||
\t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE
|
||||
\t\t\t\t | CAP_MAP_EXEC | CAP_MAP_UNMAP,
|
||||
\t\t\t\t.start = __pfn(CONFIG_CONT%d_VIRT%d_START),
|
||||
\t\t\t\t.end = __pfn(CONFIG_CONT%d_VIRT%d_END),
|
||||
\t\t\t\t.size = __pfn(CONFIG_CONT%d_VIRT%d_END - CONFIG_CONT%d_VIRT%d_START),
|
||||
\t\t\t},
|
||||
'''
|
||||
|
||||
cap_physmem = \
|
||||
'''
|
||||
\t\t\t[%d] = {
|
||||
\t\t\t\t.type = CAP_TYPE_MAP | CAP_RTYPE_PHYSMEM,
|
||||
\t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE
|
||||
\t\t\t\t | CAP_MAP_EXEC | CAP_MAP_UNMAP,
|
||||
\t\t\t\t.start = __pfn(CONFIG_CONT%d_PHYS%d_START),
|
||||
\t\t\t\t.end = __pfn(CONFIG_CONT%d_PHYS%d_END),
|
||||
\t\t\t\t.size = __pfn(CONFIG_CONT%d_PHYS%d_END - CONFIG_CONT%d_PHYS%d_START),
|
||||
\t\t\t},
|
||||
'''
|
||||
|
||||
def generate_kernel_cinfo(containers, cinfo_path):
|
||||
with open(cinfo_path, 'w+') as cinfo_file:
|
||||
fbody = cinfo_file_start
|
||||
for c in containers:
|
||||
print "Container %s: %s" % (c.id, c.name)
|
||||
# Currently only these are considered as capabilities
|
||||
total_caps = c.virt_regions + c.phys_regions
|
||||
fbody += cinfo_start % (c.id, c.name)
|
||||
fbody += pager_start % (c.id, c.id, c.id, total_caps)
|
||||
cap_index = 0
|
||||
for mem_index in range(c.virt_regions):
|
||||
fbody += cap_virtmem % \
|
||||
(cap_index, c.id, \
|
||||
mem_index, c.id, \
|
||||
mem_index, c.id, \
|
||||
mem_index, c.id, mem_index)
|
||||
cap_index += 1
|
||||
for mem_index in range(c.phys_regions):
|
||||
fbody += cap_physmem % \
|
||||
(cap_index, c.id, \
|
||||
mem_index, c.id, \
|
||||
mem_index, c.id, \
|
||||
mem_index, c.id, mem_index)
|
||||
cap_index += 1
|
||||
fbody += pager_end
|
||||
fbody += cinfo_end
|
||||
fbody += cinfo_file_end
|
||||
cinfo_file.write(fbody)
|
||||
|
||||
if __name__ == "__main__":
|
||||
config = configuration_retrieve()
|
||||
config.config_print()
|
||||
containers = config.containers
|
||||
containers.sort()
|
||||
if len(sys.argv) > 1:
|
||||
generate_kernel_cinfo(containers, join(PROJROOT, sys.argv[1]))
|
||||
else:
|
||||
generate_kernel_cinfo(containers, join(PROJROOT, 'src/generic/cinfo.c'))
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Autogenerated container descriptions
|
||||
* defined for the current build.
|
||||
*
|
||||
* Copyright (C) 2009 Bahadir Balban
|
||||
*/
|
||||
#include <l4/generic/container.h>
|
||||
#include <l4/generic/resource.h>
|
||||
#include <l4/generic/capability.h>
|
||||
#include <l4/generic/cap-types.h>
|
||||
|
||||
/*
|
||||
* FIXME:
|
||||
* Add irqs, exceptions
|
||||
*/
|
||||
|
||||
#define CONFIG_CONT0_PAGER_START CONFIG_CONT0_PHYS_START
|
||||
|
||||
struct container_info cinfo[] = {
|
||||
[0] = {
|
||||
.name = "Codezero POSIX Services",
|
||||
.npagers = 1,
|
||||
.pager = {
|
||||
[0] = {
|
||||
.pager_lma = __pfn(CONFIG_CONT0_PAGER_START),
|
||||
.pager_vma = __pfn(0xE0000000),
|
||||
.pager_size = __pfn(0xa2000),
|
||||
.ncaps = 14,
|
||||
.caps = {
|
||||
[0] = {
|
||||
.type = CAP_TYPE_MAP | CAP_RTYPE_VIRTMEM,
|
||||
.access = CAP_MAP_READ | CAP_MAP_WRITE
|
||||
| CAP_MAP_EXEC | CAP_MAP_UNMAP,
|
||||
.start = __pfn(0xE0000000),
|
||||
.end = __pfn(0xF0000000),
|
||||
.size = __pfn(0x10000000),
|
||||
},
|
||||
[1] = {
|
||||
.type = CAP_TYPE_MAP | CAP_RTYPE_VIRTMEM,
|
||||
.access = CAP_MAP_READ | CAP_MAP_WRITE
|
||||
| CAP_MAP_EXEC | CAP_MAP_UNMAP,
|
||||
.start = __pfn(0x10000000),
|
||||
.end = __pfn(0x20000000),
|
||||
.size = __pfn(0x10000000),
|
||||
},
|
||||
[2] = {
|
||||
.type = CAP_TYPE_MAP | CAP_RTYPE_VIRTMEM,
|
||||
.access = CAP_MAP_READ | CAP_MAP_WRITE
|
||||
| CAP_MAP_EXEC | CAP_MAP_UNMAP,
|
||||
.start = __pfn(0x20000000),
|
||||
.end = __pfn(0x30000000),
|
||||
.size = __pfn(0x10000000),
|
||||
},
|
||||
[3] = {
|
||||
.type = CAP_TYPE_MAP | CAP_RTYPE_VIRTMEM,
|
||||
.access = CAP_MAP_READ | CAP_MAP_WRITE
|
||||
| CAP_MAP_EXEC | CAP_MAP_UNMAP
|
||||
| CAP_MAP_UTCB,
|
||||
.start = __pfn(0xF8000000),
|
||||
.end = __pfn(0xF9000000),
|
||||
.size = __pfn(0x1000000),
|
||||
},
|
||||
|
||||
[4] = {
|
||||
.type = CAP_TYPE_MAP | CAP_RTYPE_PHYSMEM,
|
||||
.access = CAP_MAP_CACHED | CAP_MAP_UNCACHED
|
||||
| CAP_MAP_READ | CAP_MAP_WRITE
|
||||
| CAP_MAP_EXEC | CAP_MAP_UNMAP,
|
||||
.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,
|
||||
.access = CAP_IPC_SEND | CAP_IPC_RECV
|
||||
| CAP_IPC_FULL | CAP_IPC_SHORT
|
||||
| CAP_IPC_EXTENDED,
|
||||
.start = 0, .end = 0, .size = 0,
|
||||
},
|
||||
[6] = {
|
||||
.type = CAP_TYPE_TCTRL | CAP_RTYPE_CONTAINER,
|
||||
.access = CAP_TCTRL_CREATE | CAP_TCTRL_DESTROY
|
||||
| CAP_TCTRL_SUSPEND | CAP_TCTRL_RESUME
|
||||
| CAP_TCTRL_RECYCLE,
|
||||
.start = 0, .end = 0, .size = 0,
|
||||
},
|
||||
[7] = {
|
||||
.type = CAP_TYPE_EXREGS | CAP_RTYPE_CONTAINER,
|
||||
.access = CAP_EXREGS_RW_PAGER
|
||||
| CAP_EXREGS_RW_UTCB | CAP_EXREGS_RW_SP
|
||||
| CAP_EXREGS_RW_PC | CAP_EXREGS_RW_REGS,
|
||||
.start = 0, .end = 0, .size = 0,
|
||||
},
|
||||
[8] = {
|
||||
.type = CAP_TYPE_QUANTITY
|
||||
| CAP_RTYPE_THREADPOOL,
|
||||
.access = 0, .start = 0, .end = 0,
|
||||
.size = 64,
|
||||
},
|
||||
[9] = {
|
||||
.type = CAP_TYPE_QUANTITY | CAP_RTYPE_SPACEPOOL,
|
||||
.access = 0, .start = 0, .end = 0,
|
||||
.size = 64,
|
||||
},
|
||||
[10] = {
|
||||
.type = CAP_TYPE_QUANTITY | CAP_RTYPE_CPUPOOL,
|
||||
.access = 0, .start = 0, .end = 0,
|
||||
.size = 50, /* Percentage */
|
||||
},
|
||||
[11] = {
|
||||
.type = CAP_TYPE_QUANTITY | CAP_RTYPE_MUTEXPOOL,
|
||||
.access = 0, .start = 0, .end = 0,
|
||||
.size = 100,
|
||||
},
|
||||
[12] = {
|
||||
/* For pmd accounting */
|
||||
.type = CAP_TYPE_QUANTITY | CAP_RTYPE_MAPPOOL,
|
||||
.access = 0, .start = 0, .end = 0,
|
||||
/* Function of mem regions, nthreads etc. */
|
||||
.size = (64 * 30 + 100),
|
||||
},
|
||||
[13] = {
|
||||
/* For cap spliting, creating, etc. */
|
||||
.type = CAP_TYPE_QUANTITY | CAP_RTYPE_CAPPOOL,
|
||||
.access = 0, .start = 0, .end = 0,
|
||||
/* This may be existing caps X 2 etc. */
|
||||
.size = 30,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user