mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
Added parsing of memory region capability bits.
This commit is contained in:
@@ -25,6 +25,16 @@ class Container:
|
||||
self.virt_regions = 0
|
||||
self.phys_regions = 0
|
||||
|
||||
def print_self(self):
|
||||
print '\nContainer %d' % self.id
|
||||
print 'Container type: %s' % self.type
|
||||
print 'Container Name: %s' % self.name
|
||||
print 'Container Pager lma: %s' % conv_hex(self.pager_lma)
|
||||
print 'Container Pager vma: %s' % conv_hex(self.pager_vma)
|
||||
print 'Container Pager size: %s' % conv_hex(self.pager_size)
|
||||
print 'Container Virtual regions: %s' % self.virt_regions
|
||||
print 'Container Physical regions: %s' % self.phys_regions
|
||||
|
||||
class configuration:
|
||||
|
||||
def __init__(self):
|
||||
@@ -153,20 +163,6 @@ class configuration:
|
||||
# Make sure elements in order for indexed accessing
|
||||
self.containers.sort(self.compare_containers)
|
||||
|
||||
def container_print(self, c):
|
||||
print '\nContainer %d' % c.id
|
||||
print 'Container type: %s' % c.type
|
||||
print 'Container Name: %s' % c.name
|
||||
print 'Container Pager lma: %s' % conv_hex(c.pager_lma)
|
||||
print 'Container Pager vma: %s' % conv_hex(c.pager_vma)
|
||||
print 'Container Pager size: %s' % conv_hex(c.pager_size)
|
||||
print 'Container Virtual regions: %s' % c.virt_regions
|
||||
print 'Container Physical regions: %s' % c.phys_regions
|
||||
|
||||
def containers_print(self, containers):
|
||||
for c in containers:
|
||||
self.container_print(self, c)
|
||||
|
||||
def config_print(self):
|
||||
print 'Configuration\n'
|
||||
print '-------------\n'
|
||||
@@ -174,7 +170,11 @@ class configuration:
|
||||
print 'Platform: %s' % self.platform
|
||||
print 'Symbols:\n %s' % self.all
|
||||
print 'Containers: %s' % self.ncontainers
|
||||
self.containers_print(self.containers)
|
||||
self.containers_print()
|
||||
|
||||
def containers_print(self):
|
||||
for c in self.containers:
|
||||
c.print_self()
|
||||
|
||||
def configuration_save(config):
|
||||
if not os.path.exists(CONFIG_SHELVE_DIR):
|
||||
|
||||
@@ -29,6 +29,11 @@ def build_parse_options():
|
||||
help = "Reset configuration file settings "
|
||||
"(If you had configured before and changing the "
|
||||
"rule file, this will reset existing values to default)")
|
||||
parser.add_option("-s", "--save-old-config", action = "store_true",
|
||||
default = False, dest = "backup_config",
|
||||
help = "Backs up old configuration file settings to a .saved file"
|
||||
"(Subsequent calls would overwrite. Only meaningful with -r)")
|
||||
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
@@ -45,6 +50,10 @@ def build_parse_options():
|
||||
if autogen_true:
|
||||
generate_container_cml(options.arch, options.ncont)
|
||||
if options.reset_old_config == 1 and os.path.exists(CML2_OLDCONFIG_FILE):
|
||||
print "Moving %s to unused file %s" % (CML2_OLDCONFIG_FILE, CML2_OLDCONFIG_FILE + '.saved')
|
||||
shutil.move(CML2_OLDCONFIG_FILE, CML2_OLDCONFIG_FILE + '.saved')
|
||||
if options.backup_config == 1:
|
||||
print "Backing up %s into %s" % (CML2_OLDCONFIG_FILE, CML2_OLDCONFIG_FILE + '.saved')
|
||||
shutil.move(CML2_OLDCONFIG_FILE, CML2_OLDCONFIG_FILE + '.saved')
|
||||
else:
|
||||
print "Deleting %s" % CML2_OLDCONFIG_FILE
|
||||
os.remove(CML2_OLDCONFIG_FILE)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from os.path import join
|
||||
from config.projpaths import *
|
||||
from config.configuration import *
|
||||
from scripts.bare.bare_generator import *
|
||||
from scripts.conts.generate_kernel_cinfo import *
|
||||
from scripts.kernel.generate_kernel_cinfo import *
|
||||
from config.parse_options import *
|
||||
|
||||
def cml2_header_to_symbols(cml2_header, config):
|
||||
@@ -62,7 +62,7 @@ def configure_kernel(cml_file):
|
||||
bare_cont_gen.bare_container_generate(config)
|
||||
|
||||
# Generate kernel cinfo structure for container definitions
|
||||
generate_kernel_cinfo(config.containers, KERNEL_CINFO_PATH)
|
||||
generate_kernel_cinfo(config, KERNEL_CINFO_PATH)
|
||||
|
||||
if __name__ == "__main__":
|
||||
build_parse_options()
|
||||
|
||||
@@ -57,13 +57,23 @@
|
||||
#define CAP_EXREGS_RW_CPUTIME (1 << 6)
|
||||
|
||||
/* Map capability */
|
||||
#define CAP_MAP_READ (1 << 0)
|
||||
#define CAP_MAP_WRITE (1 << 1)
|
||||
#define CAP_MAP_EXEC (1 << 2)
|
||||
#define CAP_MAP_CACHED (1 << 3)
|
||||
#define CAP_MAP_UNCACHED (1 << 4)
|
||||
#define CAP_MAP_UNMAP (1 << 5)
|
||||
#define CAP_MAP_UTCB (1 << 6)
|
||||
|
||||
/* Shift values */
|
||||
#define CAP_MAP_READ_BIT 0
|
||||
#define CAP_MAP_WRITE_BIT 1
|
||||
#define CAP_MAP_EXEC_BIT 2
|
||||
#define CAP_MAP_CACHED_BIT 3
|
||||
#define CAP_MAP_UNCACHED_BIT 4
|
||||
#define CAP_MAP_UNMAP_BIT 5
|
||||
#define CAP_MAP_UTCB_BIT 6
|
||||
|
||||
#define CAP_MAP_READ (1 << CAP_MAP_READ_BIT)
|
||||
#define CAP_MAP_WRITE (1 << CAP_MAP_WRITE_BIT)
|
||||
#define CAP_MAP_EXEC (1 << CAP_MAP_EXEC_BIT)
|
||||
#define CAP_MAP_CACHED (1 << CAP_MAP_CACHED_BIT)
|
||||
#define CAP_MAP_UNCACHED (1 << CAP_MAP_UNCACHED_BIT)
|
||||
#define CAP_MAP_UNMAP (1 << CAP_MAP_UNMAP_BIT)
|
||||
#define CAP_MAP_UTCB (1 << CAP_MAP_UTCB_BIT)
|
||||
|
||||
/* Ipc capability */
|
||||
#define CAP_IPC_SEND (1 << 0)
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
#define curcont (current->container)
|
||||
|
||||
#define CONFIG_CONTAINER_NAMESIZE 64
|
||||
#define CONFIG_MAX_CAPS_USED 14
|
||||
#define CONFIG_MAX_PAGERS_USED 2
|
||||
#define CONFIG_MAX_CAPS_USED 32
|
||||
#define CONFIG_MAX_PAGERS_USED 4
|
||||
|
||||
/* Container macro. No locks needed! */
|
||||
|
||||
|
||||
@@ -74,25 +74,30 @@ pager_end = \
|
||||
|
||||
cap_virtmem = \
|
||||
'''
|
||||
\t\t\t[%d] = {
|
||||
\t\t\t[%(capidx)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\t.access = (CONFIG_CONT%(cn)d_VIRT%(vn)d_CAP_MAP_READ_ << CAP_MAP_READ_BIT) |
|
||||
\t\t\t\t (CONFIG_CONT%(cn)d_VIRT%(vn)d_CAP_MAP_WRITE_ << CAP_MAP_WRITE_BIT) |
|
||||
\t\t\t\t (CONFIG_CONT%(cn)d_VIRT%(vn)d_CAP_MAP_EXEC_ << CAP_MAP_EXEC_BIT) |
|
||||
\t\t\t\t (CONFIG_CONT%(cn)d_VIRT%(vn)d_CAP_MAP_UNMAP_ << CAP_MAP_UNMAP_BIT) |
|
||||
\t\t\t\t (CONFIG_CONT%(cn)d_VIRT%(vn)d_CAP_MAP_UTCB_ << CAP_MAP_UTCB_BIT),
|
||||
\t\t\t\t.start = __pfn(CONFIG_CONT%(cn)d_VIRT%(vn)d_START),
|
||||
\t\t\t\t.end = __pfn(CONFIG_CONT%(cn)d_VIRT%(vn)d_END),
|
||||
\t\t\t\t.size = __pfn(CONFIG_CONT%(cn)d_VIRT%(vn)d_END - CONFIG_CONT%(cn)d_VIRT%(vn)d_START),
|
||||
\t\t\t},
|
||||
'''
|
||||
|
||||
cap_physmem = \
|
||||
'''
|
||||
\t\t\t[%d] = {
|
||||
\t\t\t[%(capidx)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\t.access = (CONFIG_CONT%(cn)d_PHYS%(pn)d_CAP_MAP_READ_ << CAP_MAP_READ_BIT) |
|
||||
\t\t\t\t (CONFIG_CONT%(cn)d_PHYS%(pn)d_CAP_MAP_WRITE_ << CAP_MAP_WRITE_BIT) |
|
||||
\t\t\t\t (CONFIG_CONT%(cn)d_PHYS%(pn)d_CAP_MAP_EXEC_ << CAP_MAP_EXEC_BIT) |
|
||||
\t\t\t\t (CONFIG_CONT%(cn)d_PHYS%(pn)d_CAP_MAP_UNMAP_ << CAP_MAP_UNMAP_BIT),
|
||||
\t\t\t\t.start = __pfn(CONFIG_CONT%(cn)d_PHYS%(pn)d_START),
|
||||
\t\t\t\t.end = __pfn(CONFIG_CONT%(cn)d_PHYS%(pn)d_END),
|
||||
\t\t\t\t.size = __pfn(CONFIG_CONT%(cn)d_PHYS%(pn)d_END - CONFIG_CONT%(cn)d_PHYS%(pn)d_START),
|
||||
\t\t\t},
|
||||
'''
|
||||
|
||||
@@ -169,10 +174,10 @@ pager_ifdefs_todotext = \
|
||||
|
||||
pager_ifdefs = \
|
||||
'''
|
||||
#if defined(CONFIG_CONT%d_TYPE_LINUX)
|
||||
#define CONFIG_CONT%d_PAGER_LMA (CONFIG_CONT%d_LINUX_PHYS_OFFSET + CONFIG_CONT%d_LINUX_TEXT_OFFSET)
|
||||
#define CONFIG_CONT%d_PAGER_VMA (CONFIG_CONT%d_LINUX_PAGE_OFFSET + CONFIG_CONT%d_LINUX_TEXT_OFFSET)
|
||||
#define CONFIG_CONT%d_PAGER_SIZE CONFIG_CONT%d_LINUX_MAPSIZE
|
||||
#if defined(CONFIG_CONT%(cn)d_TYPE_LINUX)
|
||||
#define CONFIG_CONT%(cn)d_PAGER_LMA (CONFIG_CONT%(cn)d_LINUX_PHYS_OFFSET + CONFIG_CONT%(cn)d_LINUX_TEXT_OFFSET)
|
||||
#define CONFIG_CONT%(cn)d_PAGER_VMA (CONFIG_CONT%(cn)d_LINUX_PAGE_OFFSET + CONFIG_CONT%(cn)d_LINUX_TEXT_OFFSET)
|
||||
#define CONFIG_CONT%(cn)d_PAGER_SIZE CONFIG_CONT%(cn)d_LINUX_MAPSIZE
|
||||
#endif
|
||||
'''
|
||||
def generate_pager_memory_ifdefs(containers):
|
||||
@@ -183,14 +188,16 @@ def generate_pager_memory_ifdefs(containers):
|
||||
if linux == 0:
|
||||
pager_ifdef_string += pager_ifdefs_todotext
|
||||
linux = 1
|
||||
pager_ifdef_string += pager_ifdefs % (c.id, c.id, \
|
||||
c.id, c.id, \
|
||||
c.id, c.id, \
|
||||
c.id, c.id, c.id)
|
||||
pager_ifdef_string += pager_ifdefs % { 'cn' : c.id }
|
||||
return pager_ifdef_string
|
||||
|
||||
def generate_kernel_cinfo(containers, cinfo_path):
|
||||
def generate_kernel_cinfo(config, cinfo_path):
|
||||
containers = config.containers
|
||||
containers.sort()
|
||||
|
||||
print "Generating kernel cinfo..."
|
||||
pager_ifdefs = generate_pager_memory_ifdefs(containers)
|
||||
|
||||
with open(cinfo_path, 'w+') as cinfo_file:
|
||||
fbody = cinfo_file_start % pager_ifdefs
|
||||
total_other_caps = 9
|
||||
@@ -201,18 +208,10 @@ def generate_kernel_cinfo(containers, cinfo_path):
|
||||
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)
|
||||
fbody += cap_virtmem % { 'capidx' : cap_index, 'cn' : c.id, 'vn' : 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)
|
||||
fbody += cap_physmem % { 'capidx' : cap_index, 'cn' : c.id, 'pn' : mem_index }
|
||||
cap_index += 1
|
||||
fbody += cap_all_others % (tuple(range(cap_index, total_caps)))
|
||||
fbody += pager_end
|
||||
@@ -222,11 +221,8 @@ def generate_kernel_cinfo(containers, cinfo_path):
|
||||
|
||||
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]))
|
||||
generate_kernel_cinfo(config, join(PROJROOT, sys.argv[1]))
|
||||
else:
|
||||
generate_kernel_cinfo(containers, join(PROJROOT, 'src/generic/cinfo.c'))
|
||||
generate_kernel_cinfo(config, join(PROJROOT, 'src/generic/cinfo.c'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user