OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [scripts/] [cml/] [generate_container_cml.py] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#! /usr/bin/env python2.6
2
# -*- mode: python; coding: utf-8; -*-
3
#
4
#  Codezero -- a microkernel for embedded systems.
5
#
6
#  Copyright © 2009  B Labs Ltd
7
#
8
import os, sys, shelve, glob
9
from os.path import join
10
from string import Template
11
 
12
PROJRELROOT = '../../'
13
 
14
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
15
sys.path.append(os.path.abspath("../"))
16
 
17
from config.projpaths import *
18
from config.configuration import *
19
 
20
containers_menu = \
21
'''
22
menu containers_menu
23
        CAPABILITIES
24
    CONTAINERS%
25
'''
26
 
27
default_number_of_containers = \
28
'''
29
default CONTAINERS from 1
30
'''
31
 
32
containers_constraint = \
33
'''
34
unless CONTAINERS > %d suppress cont%d_menu
35
'''
36
 
37
def add_container_constraint(cid):
38
    cml_string = ""
39
    if cid == 0:
40
        return ""
41
    cml_string = containers_constraint % (cid, cid)
42
    return cml_string
43
 
44
device_suppress_rule = \
45
'''
46
when CONT${CONTID}_CAP_DEVICE_${DEVNAME}_USE == y suppress
47
'''
48
 
49
device_suppress_sym = \
50
'''\tcont${CONTID}_cap_device_${DEVNAME_LOWER}
51
'''
52
 
53
devices = ['UART1', 'UART2', 'UART3', 'TIMER1',
54
           'KEYBOARD0', 'MOUSE0', 'CLCD0']
55
 
56
#
57
# When a symbol is used by a single container, sometimes it is
58
# necessary to hide it in other containers. This cannot be
59
# achieved statically but rather needs to be autogenerated
60
# depending on the number of containers used.
61
#
62
def generate_container_suppress_rules(ncont):
63
    finalstr = ''
64
    # For each device on the platform
65
    for devname in devices:
66
        # Generate rule for each container
67
        for cont in range(ncont):
68
            # Create string templates
69
            rule_templ = Template(device_suppress_rule)
70
            sym_templ = Template(device_suppress_sym)
71
 
72
            rulestr = rule_templ.substitute(CONTID = cont, DEVNAME = devname)
73
            symstr = ''
74
            # Fill for each container
75
            for other_cont in range(ncont):
76
                if other_cont == cont:
77
                    continue
78
                symstr += sym_templ.substitute(CONTID = other_cont, DEVNAME_LOWER = devname.lower())
79
            finalstr += rulestr + symstr + "\n"
80
    return finalstr
81
 
82
def generate_container_cml(arch, ncont):
83
    print "Autogenerating new rule file"
84
    fbody = ""
85
    with open(join(CML2_CONFIG_SRCDIR, arch + '.ruleset')) as in_ruleset:
86
        fbody += in_ruleset.read()
87
 
88
    # Add container visibility constraint
89
    for cont in range(ncont):
90
        fbody += add_container_constraint(cont)
91
 
92
    # Generate the containers menu with as many entries as containers
93
    fbody += containers_menu
94
    for cont in range(ncont):
95
        fbody += '\tcont%d_menu\n' % cont
96
 
97
    fbody += default_number_of_containers
98
 
99
    # Generate inter-container suppression rules for as many rules as containers
100
    fbody += generate_container_suppress_rules(ncont)
101
 
102
    # Write each container's rules
103
    for cont in range(ncont):
104
        with open(CML2_CONT_DEFFILE, "rU") as contdefs:
105
            defbody = contdefs.read()
106
            defbody = defbody.replace("%\n", "%%\n")
107
            fbody += defbody % { 'cn' : cont }
108
 
109
    # Write the result to output rules file.
110
    with open(CML2_AUTOGEN_RULES, "w+") as out_cml:
111
        out_cml.write(fbody)
112
    return CML2_AUTOGEN_RULES
113
 
114
if __name__ == "__main__":
115
    generate_container_cml('arm', 4)
116
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.