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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [scripts/] [kernel/] [generate_kernel_cinfo.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
 
21
cinfo_file_start = \
22
'''/*
23
 * Autogenerated container descriptions
24
 * defined for the current build.
25
 *
26
 * Copyright (C) 2009 Bahadir Balban
27
 */
28
#include <l4/generic/container.h>
29
#include <l4/generic/resource.h>
30
#include <l4/generic/capability.h>
31
#include <l4/generic/cap-types.h>
32
#include INC_PLAT(platform.h)
33
#include INC_PLAT(irq.h)
34
 
35
%s
36
 
37
/*
38
 * FIXME:
39
 * Add irqs, exceptions
40
 */
41
 
42
__initdata struct container_info cinfo[] = {
43
'''
44
cinfo_file_end = \
45
'''
46
};
47
'''
48
 
49
cinfo_start = \
50
'''
51
\t[%d] = {
52
\t.name = "%s",
53
\t.npagers = 1,
54
\t.pager = {
55
'''
56
 
57
cinfo_end = \
58
'''
59
\t\t},
60
\t},
61
'''
62
 
63
pager_start = \
64
'''
65
\t\t[0] = {
66
\t\t\t.start_address = (CONFIG_CONT%(cn)d_START_PC_ADDR),
67
\t\t\t.pager_lma = __pfn(CONFIG_CONT%(cn)d_PAGER_LOAD_ADDR),
68
\t\t\t.pager_vma = __pfn(CONFIG_CONT%(cn)d_PAGER_VIRT_ADDR),
69
\t\t\t.pager_size = __pfn(page_align_up(CONT%(cn)d_PAGER_MAPSIZE)),
70
\t\t\t.rw_sections_start = %(rw_sec_start)s,
71
\t\t\t.rw_sections_end = %(rw_sec_end)s,
72
\t\t\t.rx_sections_start = %(rx_sec_start)s,
73
\t\t\t.rx_sections_end = %(rx_sec_end)s,
74
\t\t\t.ncaps = %(caps)d,
75
\t\t\t.caps = {
76
'''
77
pager_end = \
78
'''
79
\t\t\t},
80
\t\t},
81
'''
82
 
83
cap_virtmem = \
84
'''
85
\t\t\t[%(capidx)d] = {
86
\t\t\t\t.target = %(cn)d,
87
\t\t\t\t.type = CAP_TYPE_MAP_VIRTMEM | CAP_RTYPE_CONTAINER,
88
\t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC
89
\t\t\t\t\t| CAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB |
90
\t\t\t\t\tCAP_CACHE_INVALIDATE | CAP_CACHE_CLEAN,
91
\t\t\t\t.start = __pfn(CONFIG_CONT%(cn)d_VIRT%(vn)d_START),
92
\t\t\t\t.end = __pfn(CONFIG_CONT%(cn)d_VIRT%(vn)d_END),
93
\t\t\t\t.size = __pfn(CONFIG_CONT%(cn)d_VIRT%(vn)d_END - CONFIG_CONT%(cn)d_VIRT%(vn)d_START),
94
\t\t\t},
95
'''
96
 
97
cap_physmem = \
98
'''
99
\t\t\t[%(capidx)d] = {
100
\t\t\t\t.target = %(cn)d,
101
\t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER,
102
\t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC |
103
\t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP | CAP_MAP_UTCB,
104
\t\t\t\t.start = __pfn(CONFIG_CONT%(cn)d_PHYS%(pn)d_START),
105
\t\t\t\t.end = __pfn(CONFIG_CONT%(cn)d_PHYS%(pn)d_END),
106
\t\t\t\t.size = __pfn(CONFIG_CONT%(cn)d_PHYS%(pn)d_END - CONFIG_CONT%(cn)d_PHYS%(pn)d_START),
107
\t\t\t},
108
'''
109
 
110
 
111
pager_ifdefs_todotext = \
112
'''
113
/*
114
 * TODO:
115
 * This had to be defined this way because in CML2 there
116
 * is no straightforward way to derive symbols from expressions, even
117
 * if it is stated in the manual that it can be done.
118
 * As a workaround, a ternary expression of (? : ) was tried but this
119
 * complains that type deduction could not be done.
120
 */'''
121
 
122
# This will be filled after the containers are compiled
123
# and pager binaries are formed
124
pager_mapsize = \
125
'''
126
#define CONT%d_PAGER_SIZE     %s
127
'''
128
 
129
pager_ifdefs = \
130
'''
131
#if defined(CONFIG_CONT%(cn)d_TYPE_LINUX)
132
    #define CONT%(cn)d_PAGER_MAPSIZE \\
133
                (CONT%(cn)d_PAGER_SIZE + CONFIG_CONT%(cn)d_LINUX_ZRELADDR - \\
134
                 CONFIG_CONT%(cn)d_LINUX_PHYS_OFFSET)
135
#else
136
    #define CONT%(cn)d_PAGER_MAPSIZE (CONT%(cn)d_PAGER_SIZE)
137
#endif
138
'''
139
def generate_pager_memory_ifdefs(config, containers):
140
    pager_ifdef_string = ""
141
    linux = 0
142
    for c in containers:
143
        if c.type == "linux":
144
            if linux == 0:
145
                pager_ifdef_string += pager_ifdefs_todotext
146
                linux = 1
147
        pager_ifdef_string += \
148
            pager_mapsize % (c.id, c.pager_size)
149
        pager_ifdef_string += pager_ifdefs % { 'cn' : c.id }
150
    return pager_ifdef_string
151
 
152
def generate_kernel_cinfo(config, cinfo_path):
153
    containers = config.containers
154
    containers.sort()
155
 
156
    print "Generating kernel cinfo..."
157
    #config.config_print()
158
 
159
    pager_ifdefs = generate_pager_memory_ifdefs(config, containers)
160
 
161
    with open(cinfo_path, 'w+') as cinfo_file:
162
        fbody = cinfo_file_start % pager_ifdefs
163
        for c in containers:
164
            # Currently only these are considered as capabilities
165
            total_caps = c.virt_regions + c.phys_regions + len(c.caps)
166
            fbody += cinfo_start % (c.id, c.name)
167
            fbody += pager_start % { 'cn' : c.id, 'caps' : total_caps,
168
                                     'rw_sec_start' : hex(c.pager_rw_section_start),
169
                                     'rw_sec_end' : hex(c.pager_rw_section_end),
170
                                     'rx_sec_start' : hex(c.pager_rx_section_start),
171
                                     'rx_sec_end' : hex(c.pager_rx_section_end),
172
                                   }
173
            cap_index = 0
174
            for mem_index in range(c.virt_regions):
175
                fbody += cap_virtmem % { 'capidx' : cap_index, 'cn' : c.id, 'vn' : mem_index }
176
                cap_index += 1
177
            for mem_index in range(c.phys_regions):
178
                fbody += cap_physmem % { 'capidx' : cap_index, 'cn' : c.id, 'pn' : mem_index }
179
                cap_index += 1
180
 
181
            for capkey, capstr in c.caps.items():
182
                templ = Template(capstr)
183
                fbody += templ.safe_substitute(idx = cap_index)
184
                cap_index += 1
185
 
186
            fbody += pager_end
187
            fbody += cinfo_end
188
        fbody += cinfo_file_end
189
        cinfo_file.write(fbody)
190
 
191
if __name__ == "__main__":
192
    config = configuration_retrieve()
193
    if len(sys.argv) > 1:
194
        generate_kernel_cinfo(config, join(PROJROOT, sys.argv[1]))
195
    else:
196
        generate_kernel_cinfo(config, join(PROJROOT, 'src/generic/cinfo.c'))
197
 

powered by: WebSVN 2.1.0

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