source: soft/giet_vm/giet_python/mapping.py @ 356

Last change on this file since 356 was 356, checked in by alain, 10 years ago

Bloup...

  • Property svn:executable set to *
File size: 103.0 KB
Line 
1#!/usr/bin/env python
2
3import sys
4
5##########################################################################################
6#   file   : giet_mapping.py
7#   date   : april 2014
8#   author : Alain Greiner
9##########################################################################################
10#  This file contains the classes required to define a mapping for the GIET_VM.
11# - A 'Mapping' contains a set of 'Cluster'   (hardware architecture)
12#                        a set of 'Vseg'      (kernel virtual segments mapping)
13#                        a set of 'Vspace'    (several user applications).
14# - A 'Cluster' contains a set of 'Pseg'      (all physical segments in cluster)
15#                        a set of 'Proc'      (processors in cluster)
16#                        a set of 'Periph'    (peripherals in cluster)
17#                        a set of 'Coproc'    (coprocessors in cluster)
18# - A 'Vspace' contains  a set of 'Vseg'      (user virtual segments mapping)
19#                        a set of 'Task'      (user tasks mapping)
20# - A 'Vseg'   contains  a set of 'Vobj'
21# - A 'Periph' contains  a set of 'Irq'       (only for XCU, ICU and PIC types )
22# - A 'Coproc' contains  a set of 'Cpports'   (one port per MWMR channel)
23##########################################################################################
24# Implementation Note
25# As described above, the various objects are distributed in the PYTHON structure:
26# For example the psegs set is split in several subsets (one subset per cluster),
27# or the tasks set is split in several subsets (one subset per vspace), etc...
28# In the C binary data structure used by the giet_vm, all objects of same type
29# are stored in a linear array (one single array for all psegs for example).
30# For all objects, we compute and store in the  PYTHON object itsel a "global index"
31# corresponding to the index in this global array, and this index can be used as
32# a pseudo-pointer to identify a specific object of a given type.
33##########################################################################################
34
35######################################################################################
36# These global lists must be consistent with enums in mapping_info.h or irq_handler.h
37######################################################################################
38PERIPHTYPES =    [
39                  'CMA',
40                  'DMA',
41                  'FBF',
42                  'ICU',
43                  'IOB',
44                  'IOC',
45                  'MMC',
46                  'MWR',
47                  'NIC',
48                  'ROM',
49                  'SIM',
50                  'TIM',
51                  'TTY',
52                  'XCU',
53                  'PIC',
54                 ]
55
56PERIPHSUBTYPES = [
57                  'BDV',
58                  'HBA',
59                  'SPI',
60                  'NONE',
61                 ]
62
63IRQTYPES =       [
64                  'HWI',
65                  'WTI',
66                  'PTI',
67                 ]
68
69ISRTYPES =       [
70                  'ISR_DEFAULT',
71                  'ISR_TICK',
72                  'ISR_TTY_RX',
73                  'ISR_TTY_TX',
74                  'ISR_BDV',
75                  'ISR_TIMER',
76                  'ISR_WAKUP',
77                  'ISR_NIC_RX',
78                  'ISR_NIC_TX',
79                  'ISR_CMA',
80                  'ISR_MMC',
81                  'ISR_DMA',
82                  'ISR_SPI',
83                 ]
84
85VOBJTYPES =      [
86                  'ELF',
87                  'BLOB',
88                  'PTAB',
89                  'PERI',
90                  'MWMR',
91                  'LOCK',
92                  'BUFFER',
93                  'BARRIER',
94                  'CONST',
95                  'MEMSPACE',
96                  'SCHED',
97                 ]
98
99VSEGMODES =      [
100                  '____',
101                  '___U',
102                  '__W_',
103                  '__WU',
104                  '_X__',
105                  '_X_U',
106                  '_XW_',
107                  '_XWU',
108                  'C___',
109                  'C__U',
110                  'C_W_',
111                  'C_WU',
112                  'CX__',
113                  'CX_U',
114                  'CXW_',
115                  'CXWU',
116                 ]
117
118PSEGTYPES =      [
119                  'RAM',
120                  'ROM',        # deprecated => use PERI
121                  'PERI',
122                 ]
123
124CP_PORT_DIRS =   [
125                  'TO_COPROC',
126                  'FROM_COPROC',
127                 ]
128
129##########################################################################################
130class Mapping( object ):
131##########################################################################################
132    def __init__( self,
133                  name,                          # mapping name
134                  x_size,                        # number of clusters in a row
135                  y_size,                        # number of clusters in a column
136                  procs_max,                     # max number of processors per cluster
137                  x_width = 4,                   # number of bits encoding x coordinate
138                  y_width = 4,                   # number of bits encoding y coordinate
139                  paddr_width = 40,              # number of bits for physical address
140                  coherence = 1,                 # hardware cache coherence when non-zero
141                  irq_per_proc = 1,              # number or IRQs from XCU to processor
142                  use_ramdisk = False,           # use ramdisk when true
143                  x_io = 0,                      # cluster_io x coordinate
144                  y_io = 0,                      # cluster_io y coordinate
145                  peri_increment = 0x10000,      # address increment for globals
146                  reset_address  = 0xBFC00000,   # Processor wired boot_address
147                  ram_base       = 0,            # RAM physical base address in cluster[0,0]
148                  ram_size       = 0 ):          # RAM size in each cluster (bytes)
149
150        self.signature      = 0xDACE2014
151        self.name           = name
152        self.paddr_width    = paddr_width           
153        self.coherence      = coherence
154        self.x_size         = x_size
155        self.y_size         = y_size
156        self.x_width        = x_width
157        self.y_width        = y_width
158        self.irq_per_proc   = irq_per_proc
159        self.procs_max      = procs_max     
160        self.use_ramdisk    = use_ramdisk
161        self.x_io           = x_io
162        self.y_io           = y_io
163        self.peri_increment = peri_increment
164        self.reset_address  = reset_address
165        self.ram_base       = ram_base
166        self.ram_size       = ram_size
167
168
169        self.total_vspaces  = 0
170        self.total_globals  = 0
171        self.total_psegs    = 0
172        self.total_vsegs    = 0
173        self.total_vobjs    = 0
174        self.total_tasks    = 0
175        self.total_procs    = 0
176        self.total_irqs     = 0
177        self.total_coprocs  = 0
178        self.total_cpports  = 0
179        self.total_periphs  = 0
180
181        self.clusters       = []
182        self.globs          = []
183        self.vspaces        = []
184
185        for x in xrange( self.x_size ):
186            for y in xrange( self.y_size ):
187                cluster = Cluster( x , y )
188                cluster.index = (x * self.y_size) + y
189                self.clusters.append( cluster )
190
191        return
192
193    ##########################    add a ram pseg in a cluster
194    def addRam( self, 
195                name,                  # pseg name
196                base,                  # pseg base address
197                size ):                # pseg length (bytes)
198       
199        # check coordinates (obtained from the base address)
200        paddr_lsb_width = self.paddr_width - self.x_width - self.y_width
201        cluster_xy = base >> paddr_lsb_width
202        x = cluster_xy >> (self.y_width);
203        y = cluster_xy & ((1 << self.y_width) - 1) 
204
205        assert (base & 0xFFF) == 0
206
207        assert (x < self.x_size) and (y < self.y_size)
208       
209        assert ( (base & ((1<<paddr_lsb_width)-1)) == self.ram_base )
210
211        assert ( size == self.ram_size )
212
213        cluster_id = (x * self.y_size) + y
214
215        # add one pseg in the mapping
216        pseg = Pseg( name, base, size, x, y, 'RAM' )
217        self.clusters[cluster_id].psegs.append( pseg )
218        pseg.index = self.total_psegs
219        self.total_psegs += 1
220
221        return pseg
222
223    ##############################   add a peripheral and the associated pseg in a cluster
224    def addPeriph( self, 
225                   name,               # associated pseg name
226                   base,               # associated pseg base address
227                   size,               # associated pseg length (bytes)
228                   ptype,              # peripheral type
229                   subtype  = 'NONE',  # peripheral subtype
230                   channels = 1,       # number of channels
231                   arg      = 0 ):     # optional argument (semantic depends on ptype)
232
233        # check cluster coordinates (obtained from the base address)
234        cluster_xy = base >> (self.paddr_width - self.x_width - self.y_width)
235        x = cluster_xy >> (self.y_width);
236        y = cluster_xy & ((1 << self.y_width) - 1) 
237
238        assert (x < self.x_size) and (y < self.y_size)
239
240        assert (base & 0xFFF) == 0
241
242        assert ptype in PERIPHTYPES
243
244        assert subtype in PERIPHSUBTYPES
245
246        cluster_id = (x * self.y_size) + y
247
248        # add one pseg into mapping
249        pseg = Pseg( name, base, size, x, y, 'PERI' )
250        self.clusters[cluster_id].psegs.append( pseg )
251        pseg.index = self.total_psegs
252        self.total_psegs += 1
253
254        # add one periph into mapping
255        periph = Periph( pseg, ptype, subtype, channels, arg ) 
256        self.clusters[cluster_id].periphs.append( periph )
257        periph.index = self.total_periphs
258        self.total_periphs += 1
259
260        return periph
261
262    ################################   add an IRQ in a peripheral
263    def addIrq( self,
264                periph,                # peripheral containing IRQ (PIC or XCU)
265                index,                 # peripheral input port index
266                isrtype,               # ISR type
267                channel = 0 ):         # channel for multi-channels ISR
268
269        assert isrtype in ISRTYPES
270
271        assert index < 32
272
273        # add one irq into mapping 
274        irq = Irq( 'HWI', index , isrtype, channel )
275        periph.irqs.append( irq )
276        irq.index = self.total_irqs
277        self.total_irqs += 1
278
279        return irq
280
281    ##########################    add a processor in a cluster
282    def addProc( self, 
283                 x,                    # cluster x coordinate
284                 y,                    # cluster y coordinate
285                 p ):                  # processor local index
286
287        assert (x < self.x_size) and (y < self.y_size)
288
289        cluster_id = (x * self.y_size) + y
290
291        # add one proc into mapping
292        proc = Processor( x, y, p )
293        self.clusters[cluster_id].procs.append( proc )
294        proc.index = self.total_procs
295        self.total_procs += 1
296
297        return proc
298
299    ##############################    add a coprocessor in a cluster
300    def addCoproc( self, 
301                   name,               # associated pseg name
302                   base,               # associated pseg base address
303                   size ):             # associated pseg length
304       
305        # check cluster coordinates (obtained from the base address)
306        cluster_xy = base >> (self.paddr_width - self.x_width - self.y_width)
307        x = cluster_xy >> (self.y_width);
308        y = cluster_xy & ((1 << self.y_width) - 1) 
309
310        assert (x < self.x_size) and (y < self.y_size)
311
312        cluster_id = (x * self.y_size) + y
313
314        # add one pseg into mapping
315        pseg = Pseg( name, base, size, x, y, 'PERI' )
316        self.clusters[cluster_id].psegs.append( pseg )
317        pseg.index = self.total_psegs
318        self.total_psegs += 1
319
320        # add one coproc into mapping
321        periph = Coproc( pseg ) 
322        self.clusters[cluster_id].coprocs.append( coproc )
323        periph.index = self.total_coprocs
324        self.total_coprocs += 1
325
326        return coproc
327
328    ##################################    add a port in a coprocessor
329    def addPort( self, 
330                 coproc,               # coprocessor containing the port
331                 direction,            # direction (TO_COPROC / FROM_COPROC)
332                 vspacename,           # name of vspace using the coproc
333                 mwmrname ):           # name of the vobj defining the MWMR channel
334
335        assert direction in CP_PORT_DIRS
336
337        # add one cpport into mapping
338        port = Cpport( direction, vspacename, mwmrname )
339        coproc.ports.append( port )
340        port.index = self.total_cpports
341        self.total_cpports += 1
342
343        return port
344
345    ############################    add one (or several) global vseg into mapping
346    def addGlobal( self, 
347                   name,                  # vseg name
348                   vbase,                 # virtual base address
349                   size,                  # vobj length (bytes)
350                   mode,                  # CXWU flags
351                   vtype,                 # vobj type
352                   x,                     # destination x coordinate
353                   y,                     # destination y coordinate
354                   pseg,                  # destination pseg name
355                   identity = False,      # identity mapping required if true
356                   binpath  = '',         # pathname for binary code
357                   local    = False ):    # non shared vseg when true
358
359        assert mode in VSEGMODES
360
361        assert vtype in VOBJTYPES
362
363        assert (vbase & 0xFFF) == 0
364
365        assert (x < self.x_size) and (y < self.y_size)
366
367        # add one vseg into mapping
368        vseg = Vseg( name, vbase, mode, x, y, pseg, 
369                     identity = identity, local = local )
370
371        self.globs.append( vseg )
372        self.total_globals += 1
373        vseg.index = self.total_vsegs
374        self.total_vsegs += 1
375           
376        # add one vobj into mapping
377        vobj = Vobj( name, size, vtype, binpath, 0, 0 )
378        vseg.vobjs.append( vobj )
379        vobj.index = self.total_vobjs
380        self.total_vobjs += 1
381
382        return
383
384    ################################    add a vspace into mapping
385    def addVspace( self, 
386                   name,                # vspace name
387                   startname ):         # name of vobj containing start_vector
388
389        # add one vspace into mapping
390        vspace = Vspace( name, startname )
391        self.vspaces.append( vspace )
392        vspace.index = self.total_vspaces
393        self.total_vspaces += 1
394
395        return vspace
396   
397    #################################   add a private vseg and a vobj in a vspace
398    def addVseg( self,
399                 vspace,                # vspace containing the vseg
400                 name,                  # vseg name
401                 vbase,                 # virtual base address
402                 size,                  # vobj length (bytes)
403                 mode,                  # CXWU flags
404                 vtype,                 # vobj type
405                 x,                     # destination x coordinate
406                 y,                     # destination y coordinate
407                 pseg,                  # destination pseg name
408                 binpath    = '',       # pathname for binary code
409                 align      = 0,        # alignment required
410                 init       = 0,        # initial value
411                 local = False ):       # non shared when true
412
413        assert mode in VSEGMODES
414
415        assert vtype in VOBJTYPES
416
417        assert (x < self.x_size) and (y < self.y_size)
418
419        # add one vseg into mapping
420        vseg = Vseg( name, vbase, mode, x, y, pseg, local = local )
421        vspace.vsegs.append( vseg )
422        vseg.index = self.total_vsegs
423        self.total_vsegs += 1
424
425        # add one vobj into mapping
426        vobj = Vobj( name, size, vtype, binpath, align, init )
427        vseg.vobjs.append( vobj )
428        vobj.index = self.total_vobjs
429        self.total_vobjs += 1
430
431        return vseg
432
433    ################################    add a vobj in a private vseg
434    def addVobj( self, 
435                 vseg,                  # vseg containing vobj
436                 name,                  # vobj name
437                 size,                  # vobj length (bytes)
438                 vtype,                 # vobj type
439                 binpath = '',          # pathname to binary
440                 align   = 0,           # alignment constraint
441                 init    = 0 ):         # initial value
442
443        assert vtype in VOBJTYPES
444
445        # add one vobj into mapping
446        vobj = Vobj( name, size, vtype, binpath, align, init )
447        vseg.vobjs.append( vobj )
448        vobj.index = self.total_vobjs
449        self.total_vobjs += 1
450
451        return vobj
452
453    ################################    add a task in a vspace
454    def addTask( self, 
455                 vspace,                # vspace containing task
456                 name,                  # task name
457                 trdid,                 # task index in vspace
458                 x,                     # destination x coordinate
459                 y,                     # destination y coordinate
460                 lpid,                  # destination processor local index
461                 stackname,             # name of vobj containing stack
462                 heapname,              # name of vobj containing heap
463                 startid,               # index in start_vector
464                 usetty = False,        # request a private TTY channel
465                 usenic = False,        # request a private NIC channel
466                 usecma = False,        # request a private CMA channel
467                 usehba = False,        # request a private HBA channel
468                 usetim = False ):      # request a private TIM channel
469                 
470        assert (x < self.x_size) and (y < self.y_size)
471
472        assert lpid < self.procs_max
473
474        # add one task into mapping
475        task = Task( name, trdid, x, y, lpid, stackname, heapname, startid,
476                     usetty, usenic, usecma, usehba, usetim )
477        vspace.tasks.append( task )
478        task.index = self.total_tasks
479        self.total_tasks += 1
480
481        return task
482
483    #################################
484    def str2bytes( self, nbytes, s ):    # string => nbytes_packed byte array
485
486        byte_stream = bytearray()
487        length = len( s )
488        if length < (nbytes - 1):
489            for b in s:
490                byte_stream.append( b )
491            for x in xrange(nbytes-length):
492                byte_stream.append( '\0' )
493        else:
494            print '[genmap error] in str2bytes() : string %s too long' % s
495            sys.exit(1)
496
497        return byte_stream
498
499    ###################################
500    def int2bytes( self, nbytes, val ):    # integer => nbytes litle endian byte array 
501
502        byte_stream = bytearray()
503        for n in xrange( nbytes ):
504            byte_stream.append( (val >> (n<<3)) & 0xFF )
505
506        return byte_stream
507
508    ################
509    def xml( self ):    # xml file generation for mapping
510
511        s = '<?xml version="1.0"?>\n\n'
512        s += '<mapping_info signature    = "0x%x"\n' % (self.signature)
513        s += '              name         = "%s"\n'   % (self.name)
514        s += '              x_size       = "%d"\n'   % (self.x_size)
515        s += '              y_size       = "%d"\n'   % (self.y_size)
516        s += '              x_width      = "%d"\n'   % (self.x_width)
517        s += '              y_width      = "%d"\n'   % (self.y_width)
518        s += '              irq_per_proc = "%d"\n'   % (self.irq_per_proc)
519        s += '              use_ramdisk  = "%d"\n'   % (self.use_ramdisk)
520        s += '              x_io         = "%d"\n'   % (self.x_io)
521        s += '              y_io         = "%d" >\n' % (self.y_io)
522        s += '\n'
523
524        s += '    <clusterset>\n'
525        for x in xrange ( self.x_size ):
526            for y in xrange ( self.y_size ):
527                cluster_id = (x * self.y_size) + y
528                s += self.clusters[cluster_id].xml()
529        s += '    </clusterset>\n'
530        s += '\n'
531
532        s += '    <globalset>\n'
533        for vseg in self.globs: s += vseg.xml()
534        s += '    </globalset>\n'
535        s += '\n'
536
537        s += '    <vspaceset>\n'
538        for vspace in self.vspaces: s += vspace.xml()
539        s += '    </vspaceset>\n'
540
541        s += '</mapping_info>\n'
542        return s
543
544    #########################
545    def cbin( self, verbose ):     # C binary structure generation for mapping
546
547        byte_stream = bytearray()
548
549        # header
550        byte_stream += self.int2bytes(4,  self.signature)
551        byte_stream += self.int2bytes(4,  self.x_size)         
552        byte_stream += self.int2bytes(4,  self.y_size)       
553        byte_stream += self.int2bytes(4,  self.x_width)     
554        byte_stream += self.int2bytes(4,  self.y_width)   
555        byte_stream += self.int2bytes(4,  self.x_io)     
556        byte_stream += self.int2bytes(4,  self.y_io)   
557        byte_stream += self.int2bytes(4,  self.irq_per_proc)   
558        byte_stream += self.int2bytes(4,  self.use_ramdisk)   
559        byte_stream += self.int2bytes(4,  self.total_globals)   
560        byte_stream += self.int2bytes(4,  self.total_vspaces)   
561        byte_stream += self.int2bytes(4,  self.total_psegs)   
562        byte_stream += self.int2bytes(4,  self.total_vsegs)   
563        byte_stream += self.int2bytes(4,  self.total_vobjs)   
564        byte_stream += self.int2bytes(4,  self.total_tasks)   
565        byte_stream += self.int2bytes(4,  self.total_procs)   
566        byte_stream += self.int2bytes(4,  self.total_irqs)   
567        byte_stream += self.int2bytes(4,  self.total_coprocs)   
568        byte_stream += self.int2bytes(4,  self.total_cpports)   
569        byte_stream += self.int2bytes(4,  self.total_periphs)     
570        byte_stream += self.str2bytes(32, self.name)
571
572        if ( verbose ):
573            print '\n' 
574            print 'name          = %s' % self.name
575            print 'signature     = %x' % self.signature
576            print 'x_size        = %d' % self.x_size
577            print 'y_size        = %d' % self.y_size
578            print 'x_width       = %d' % self.x_width
579            print 'y_width       = %d' % self.y_width
580            print 'x_io          = %d' % self.x_io 
581            print 'y_io          = %d' % self.y_io 
582            print 'irq_per_proc  = %d' % self.irq_per_proc
583            print 'use_ramdisk   = %d' % self.use_ramdisk
584            print 'total_globals = %d' % self.total_globals
585            print 'total_psegs   = %d' % self.total_psegs 
586            print 'total_vsegs   = %d' % self.total_vsegs 
587            print 'total_vobjs   = %d' % self.total_vobjs 
588            print 'total_tasks   = %d' % self.total_tasks 
589            print 'total_procs   = %d' % self.total_procs 
590            print 'total_irqs    = %d' % self.total_irqs   
591            print 'total_coprocs = %d' % self.total_coprocs
592            print 'total_cpports = %d' % self.total_cpports
593            print 'total_periphs = %d' % self.total_periphs
594            print '\n' 
595
596        # clusters array
597        index = 0
598        for cluster in self.clusters:
599            byte_stream += cluster.cbin( self, verbose, index )
600            index += 1
601
602        if ( verbose ): print '\n'
603
604        # psegs array
605        index = 0
606        for cluster in self.clusters:
607            for pseg in cluster.psegs: 
608                byte_stream += pseg.cbin( self, verbose, index, cluster )
609                index += 1
610
611        if ( verbose ): print '\n'
612
613        # vspaces array
614        index = 0
615        for vspace in self.vspaces:   
616            byte_stream += vspace.cbin( self, verbose, index ) 
617            index += 1
618
619        if ( verbose ): print '\n'
620
621        # vsegs array
622        index = 0
623        for vseg in self.globs:
624            byte_stream += vseg.cbin( self, verbose, index )
625            index += 1
626        for vspace in self.vspaces:
627            for vseg in vspace.vsegs: 
628                byte_stream += vseg.cbin( self, verbose, index )
629                index += 1
630
631        if ( verbose ): print '\n'
632
633        # vobjs array
634        index = 0
635        for vseg in self.globs:
636            for vobj in vseg.vobjs:
637                byte_stream += vobj.cbin( self, verbose, index )
638                index += 1
639        for vspace in self.vspaces:
640            for vseg in vspace.vsegs: 
641                for vobj in vseg.vobjs:
642                    byte_stream += vobj.cbin( self, verbose, index ) 
643                    index += 1
644
645        if ( verbose ): print '\n'
646
647        # tasks array
648        index = 0
649        for vspace in self.vspaces:
650            for task in vspace.tasks: 
651                byte_stream += task.cbin( self, verbose, index, vspace )
652                index += 1
653
654        if ( verbose ): print '\n'
655
656        # procs array
657        index = 0
658        for cluster in self.clusters:
659            for proc in cluster.procs: 
660                byte_stream += proc.cbin( self, verbose, index )
661                index += 1
662               
663        if ( verbose ): print '\n'
664
665        # irqs array
666        index = 0 
667        for cluster in self.clusters:
668            for periph in cluster.periphs:
669                for irq in periph.irqs:
670                    byte_stream += irq.cbin( self, verbose, index )
671                    index += 1
672
673        if ( verbose ): print '\n'
674
675        # coprocs array
676        index = 0
677        for cluster in self.clusters:
678            for coproc in cluster.coprocs: 
679                byte_stream += coproc.cbin( self, verbose, index ) 
680                index += 1
681
682        if ( verbose ): print '\n'
683
684        # cpports array
685        index = 0
686        for cluster in self.clusters:
687            for coproc in cluster.coprocs: 
688                for port in coproc.ports:
689                    byte_stream += port.cbin( self, verbose, index )
690                    index += 1
691
692        if ( verbose ): print '\n'
693
694        # periphs array
695        index = 0
696        for cluster in self.clusters:
697            for periph in cluster.periphs: 
698                byte_stream += periph.cbin( self, verbose, index )
699                index += 1
700
701        return byte_stream
702    # end of cbin()
703 
704    #######################
705    def giet_vsegs( self ):      # compute string for giet_vsegs.ld file
706                                 # required by giet_vm compilation
707
708        # search the vsegs required for the giet_vsegs.ld 
709        boot_code_found      = False
710        boot_data_found      = False
711        kernel_uncdata_found = False
712        kernel_data_found    = False
713        kernel_code_found    = False
714        kernel_init_found    = False
715        for vseg in self.globs:
716
717            if ( vseg.name == 'seg_boot_code' ):
718                boot_code_vbase      = vseg.vbase
719                boot_code_size       = vseg.vobjs[0].length
720                boot_code_found      = True
721
722            if ( vseg.name == 'seg_boot_data' ): 
723                boot_data_vbase      = vseg.vbase
724                boot_data_size       = vseg.vobjs[0].length
725                boot_data_found      = True
726
727            if ( vseg.name == 'seg_kernel_uncdata' ):
728                kernel_uncdata_vbase = vseg.vbase
729                kernel_uncdata_size  = vseg.vobjs[0].length
730                kernel_uncdata_found = True
731
732            if ( vseg.name == 'seg_kernel_data' ):
733                kernel_data_vbase    = vseg.vbase
734                kernel_data_size     = vseg.vobjs[0].length
735                kernel_data_found    = True
736
737            if ( vseg.name == 'seg_kernel_code' ):
738                kernel_code_vbase    = vseg.vbase
739                kernel_code_size     = vseg.vobjs[0].length
740                kernel_code_found    = True
741
742            if ( vseg.name == 'seg_kernel_init' ):
743                kernel_init_vbase    = vseg.vbase
744                kernel_init_size     = vseg.vobjs[0].length
745                kernel_init_found    = True
746
747        # check if all required vsegs have been found
748        if ( boot_code_found      == False ): 
749             print '[genmap error] in giet_vsegs() : seg_boot_code vseg missing'
750             sys.exit()
751
752        if ( boot_data_found      == False ): 
753             print '[genmap error] in giet_vsegs() : seg_boot_data vseg missing'
754             sys.exit()
755
756        if ( kernel_data_found    == False ): 
757             print '[genmap error] in giet_vsegs() : seg_kernel_data vseg missing'
758             sys.exit()
759
760        if ( kernel_uncdata_found == False ):
761             print '[genmap error] in giet_vsegs() : seg_kernel_uncdata vseg missing'
762             sys.exit()
763
764        if ( kernel_code_found    == False ):
765             print '[genmap error] in giet_vsegs() : seg_kernel_code vseg missing'
766             sys.exit()
767
768        if ( kernel_init_found    == False ):
769             print '[genmap error] in giet_vsegs() : seg_kernel_init vseg missing'
770             sys.exit()
771
772        # build string
773        s =  '/* Generated by genmap for %s */\n'  % self.name
774        s += '\n'
775
776        s += 'boot_code_vbase      = 0x%x;\n'   % boot_code_vbase
777        s += 'boot_code_size       = 0x%x;\n'   % boot_code_size 
778        s += '\n'
779        s += 'boot_data_vbase      = 0x%x;\n'   % boot_data_vbase
780        s += 'boot_data_size       = 0x%x;\n'   % boot_data_size 
781        s += '\n'
782        s += 'kernel_code_vbase    = 0x%x;\n'   % kernel_code_vbase
783        s += 'kernel_code_size     = 0x%x;\n'   % kernel_code_size 
784        s += '\n'
785        s += 'kernel_data_vbase    = 0x%x;\n'   % kernel_data_vbase
786        s += 'kernel_data_size     = 0x%x;\n'   % kernel_data_size 
787        s += '\n'
788        s += 'kernel_uncdata_vbase = 0x%x;\n'   % kernel_uncdata_vbase
789        s += 'kernel_uncdata_size  = 0x%x;\n'   % kernel_uncdata_size 
790        s += '\n'
791        s += 'kernel_init_vbase    = 0x%x;\n'   % kernel_init_vbase
792        s += 'kernel_init_size     = 0x%x;\n'   % kernel_init_size 
793        s += '\n'
794
795        return s
796       
797    ########################
798    def hard_config( self ):     # compute string for hard_config.h file required by
799                                 # - top.cpp compilation
800                                 # - giet_vm compilation
801                                 # - tsar_preloader compilation
802
803        nb_total_procs = 0
804
805        # for each peripheral type, define default values
806        # for pbase address, size, number of components, and channels
807        nb_cma       = 0
808        cma_channels = 0
809        seg_cma_base = 0xFFFFFFFF
810        seg_cma_size = 0
811
812        nb_dma       = 0
813        dma_channels = 0
814        seg_dma_base = 0xFFFFFFFF
815        seg_dma_size = 0
816
817        nb_fbf       = 0
818        fbf_channels = 0
819        fbf_arg      = 0
820        seg_fbf_base = 0xFFFFFFFF
821        seg_fbf_size = 0
822
823        nb_icu       = 0
824        icu_channels = 0
825        seg_icu_base = 0xFFFFFFFF
826        seg_icu_size = 0
827
828        nb_iob       = 0
829        iob_channels = 0
830        seg_iob_base = 0xFFFFFFFF
831        seg_iob_size = 0
832
833        nb_ioc       = 0
834        ioc_channels = 0
835        seg_ioc_base = 0xFFFFFFFF
836        seg_ioc_size = 0
837
838        nb_mmc       = 0
839        mmc_channels = 0
840        seg_mmc_base = 0xFFFFFFFF
841        seg_mmc_size = 0
842
843        nb_mwr       = 0
844        mwr_channels = 0
845        seg_mwr_base = 0xFFFFFFFF
846        seg_mwr_size = 0
847
848        nb_nic       = 0
849        nic_channels = 0
850        seg_nic_base = 0xFFFFFFFF
851        seg_nic_size = 0
852
853        nb_pic       = 0
854        pic_channels = 0
855        seg_pic_base = 0xFFFFFFFF
856        seg_pic_size = 0
857
858        nb_rom       = 0
859        rom_channels = 0
860        seg_rom_base = 0xFFFFFFFF
861        seg_rom_size = 0
862
863        nb_sim       = 0
864        sim_channels = 0
865        seg_sim_base = 0xFFFFFFFF
866        seg_sim_size = 0
867
868        nb_tim       = 0
869        tim_channels = 0
870        seg_tim_base = 0xFFFFFFFF
871        seg_tim_size = 0
872
873        nb_tty       = 0
874        tty_channels = 0
875        seg_tty_base = 0xFFFFFFFF
876        seg_tty_size = 0
877
878        nb_xcu       = 0
879        xcu_channels = 0
880        xcu_arg      = 0
881        seg_xcu_base = 0xFFFFFFFF
882        seg_xcu_size = 0
883
884        use_bdv = False
885        use_spi = False
886        use_hba = False
887
888        # get peripherals attributes
889        for cluster in self.clusters:
890            for periph in cluster.periphs:
891                if   ( periph.ptype == 'CMA' ): 
892                    seg_cma_base = periph.pseg.base & 0xFFFFFFFF
893                    seg_cma_size = periph.pseg.size
894                    cma_channels = periph.channels
895                    nb_cma +=1
896
897                elif ( periph.ptype == 'DMA' ): 
898                    seg_dma_base = periph.pseg.base & 0xFFFFFFFF 
899                    seg_dma_size = periph.pseg.size
900                    dma_channels = periph.channels
901                    nb_dma +=1
902
903                elif ( periph.ptype == 'FBF' ): 
904                    seg_fbf_base = periph.pseg.base & 0xFFFFFFFF
905                    seg_fbf_size = periph.pseg.size
906                    fbf_channels = periph.channels
907                    fbf_arg      = periph.arg
908                    nb_fbf +=1
909
910                elif ( periph.ptype == 'ICU' ): 
911                    seg_icu_base = periph.pseg.base & 0xFFFFFFFF
912                    seg_icu_size = periph.pseg.size
913                    icu_channels = periph.channels
914                    nb_icu +=1
915
916                elif ( periph.ptype == 'IOB' ):
917                    seg_iob_base = periph.pseg.base & 0xFFFFFFFF
918                    seg_iob_size = periph.pseg.size
919                    iob_channels = periph.channels
920                    nb_iob +=1
921
922                elif ( periph.ptype == 'IOC' ): 
923                    seg_ioc_base = periph.pseg.base & 0xFFFFFFFF
924                    seg_ioc_size = periph.pseg.size
925                    ioc_channels = periph.channels
926                    nb_ioc += 1
927                    if   ( periph.subtype == 'BDV' ): use_bdv = True
928                    elif ( periph.subtype == 'HBA' ): use_hba = True
929                    elif ( periph.subtype == 'SPI' ): use_spi = True
930
931                elif ( periph.ptype == 'MMC' ):
932                    seg_mmc_base = periph.pseg.base & 0xFFFFFFFF
933                    seg_mmc_size = periph.pseg.size
934                    mmc_channels = periph.channels
935                    nb_mmc +=1
936
937                elif ( periph.ptype == 'MWR' ):
938                    seg_mwr_base = periph.pseg.base & 0xFFFFFFFF
939                    seg_wmr_size = periph.pseg.size
940                    mwr_channels = periph.channels
941                    nb_mwr +=1
942
943                elif ( periph.ptype == 'ROM' ):
944                    seg_rom_base = periph.pseg.base & 0xFFFFFFFF
945                    seg_rom_size = periph.pseg.size
946                    rom_channels = periph.channels
947                    nb_rom +=1
948
949                elif ( periph.ptype == 'SIM' ):
950                    seg_sim_base = periph.pseg.base & 0xFFFFFFFF
951                    seg_sim_size = periph.pseg.size
952                    sim_channels = periph.channels
953                    nb_sim +=1
954
955                elif ( periph.ptype == 'NIC' ): 
956                    seg_nic_base = periph.pseg.base & 0xFFFFFFFF
957                    seg_nic_size = periph.pseg.size
958                    nic_channels = periph.channels
959                    nb_nic +=1
960
961                elif ( periph.ptype == 'PIC' ): 
962                    seg_pic_base = periph.pseg.base & 0xFFFFFFFF
963                    seg_pic_size = periph.pseg.size
964                    pic_channels = periph.channels
965                    nb_pic +=1
966   
967                elif ( periph.ptype == 'TIM' ): 
968                    seg_tim_base = periph.pseg.base & 0xFFFFFFFF
969                    seg_tim_size = periph.pseg.size
970                    tim_channels = periph.channels
971                    nb_tim +=1
972   
973                elif ( periph.ptype == 'TTY' ):
974                    seg_tty_base = periph.pseg.base & 0xFFFFFFFF
975                    seg_tty_size = periph.pseg.size
976                    tty_channels = periph.channels
977                    nb_tty +=1
978   
979                elif ( periph.ptype == 'XCU' ): 
980                    seg_xcu_base = periph.pseg.base & 0xFFFFFFFF
981                    seg_xcu_size = periph.pseg.size
982                    xcu_channels = periph.channels
983                    xcu_arg      = periph.arg
984                    nb_xcu +=1
985   
986        # don't mix ICU and XCU
987        assert ( nb_icu*nb_xcu == 0 )   
988
989        # no more than two access to external peripherals
990        assert ( nb_fbf <= 2 ) 
991        assert ( nb_cma <= 2 ) 
992        assert ( nb_ioc <= 2 ) 
993        assert ( nb_nic <= 2 ) 
994        assert ( nb_tim <= 2 ) 
995        assert ( nb_tty <= 2 ) 
996        assert ( nb_pic <= 2 )
997
998        # one and only one type of IOC controller
999        assert ( use_hba or use_bdv or use_spi )
1000        assert ( (use_hba and use_bdv) == False )
1001        assert ( (use_hba and use_spi) == False )
1002        assert ( (use_bdv and use_spi) == False )
1003               
1004        # Compute total number of processors
1005        for cluster in self.clusters:
1006            nb_total_procs += len( cluster.procs )
1007
1008        # Compute physical addresses for BOOT vsegs
1009        boot_mapping_found   = False
1010        boot_code_found      = False
1011        boot_data_found      = False
1012        boot_buffer_found    = False
1013        boot_stack_found     = False
1014
1015        for vseg in self.globs:
1016            if ( vseg.name == 'seg_boot_mapping' ):
1017                boot_mapping_base       = vseg.vbase
1018                boot_mapping_size       = vseg.vobjs[0].length
1019                boot_mapping_identity   = vseg.identity
1020                boot_mapping_found      = True
1021
1022            if ( vseg.name == 'seg_boot_code' ):
1023                boot_code_base          = vseg.vbase
1024                boot_code_size          = vseg.vobjs[0].length
1025                boot_code_identity      = vseg.identity
1026                boot_code_found         = True
1027
1028            if ( vseg.name == 'seg_boot_data' ): 
1029                boot_data_base          = vseg.vbase
1030                boot_data_size          = vseg.vobjs[0].length
1031                boot_data_identity      = vseg.identity
1032                boot_data_found         = True
1033
1034            if ( vseg.name == 'seg_boot_buffer' ):
1035                boot_buffer_base        = vseg.vbase
1036                boot_buffer_size        = vseg.vobjs[0].length
1037                boot_buffer_identity    = vseg.identity
1038                boot_buffer_found       = True
1039
1040            if ( vseg.name == 'seg_boot_stack' ):
1041                boot_stack_base         = vseg.vbase
1042                boot_stack_size         = vseg.vobjs[0].length
1043                boot_stack_identity     = vseg.identity
1044                boot_stack_found        = True
1045
1046        # check that BOOT vsegs are found and identity mapping
1047        if ( (boot_mapping_found == False) or (boot_mapping_identity == False) ):
1048             print '[genmap error] in hard_config() : seg_boot_mapping missing or not ident'
1049             sys.exit()
1050
1051        if ( (boot_code_found == False) or (boot_code_identity == False) ): 
1052             print '[genmap error] in hard_config() : seg_boot_code missing or not ident'
1053             sys.exit()
1054
1055        if ( (boot_data_found == False) or (boot_data_identity == False) ): 
1056             print '[genmap error] in hard_config() : seg_boot_data missing or not ident'
1057             sys.exit()
1058
1059        if ( (boot_buffer_found == False) or (boot_buffer_identity == False) ): 
1060             print '[genmap error] in hard_config() : seg_boot_buffer missing or not ident'
1061             sys.exit()
1062
1063        if ( (boot_stack_found == False) or (boot_stack_identity == False) ):
1064             print '[genmap error] in giet_vsegs() : seg_boot_stack missing or not ident'
1065             sys.exit()
1066
1067        # Search RAMDISK global vseg if required
1068        seg_rdk_base =  0xFFFFFFFF
1069        seg_rdk_size =  0
1070        seg_rdk_found = False
1071
1072        if self.use_ramdisk:
1073            for vseg in self.globs:
1074                if ( vseg.name == 'seg_ramdisk' ):
1075                    seg_rdk_base  = vseg.vbase
1076                    seg_rdk_size  = vseg.vobjs[0].length
1077                    seg_rdk_found = True
1078
1079            if ( seg_rdk_found == False ):
1080                print 'Error in hard_config() "seg_ramdisk" not found'
1081                sys.exit(1)
1082
1083        # build string
1084        s =  '/* Generated by genmap for %s */\n'  % self.name   
1085        s += '\n'
1086        s += '#ifndef HARD_CONFIG_H\n'
1087        s += '#define HARD_CONFIG_H\n'
1088        s += '\n'
1089
1090        s += '/* General platform parameters */\n' 
1091        s += '\n'
1092        s += '#define X_SIZE                 %d\n'    % self.x_size
1093        s += '#define Y_SIZE                 %d\n'    % self.y_size
1094        s += '#define X_WIDTH                %d\n'    % self.x_width
1095        s += '#define Y_WIDTH                %d\n'    % self.y_width
1096        s += '#define X_IO                   %d\n'    % self.x_io
1097        s += '#define Y_IO                   %d\n'    % self.y_io 
1098        s += '#define NB_PROCS_MAX           %d\n'    % self.procs_max
1099        s += '#define IRQ_PER_PROCESSOR      %d\n'    % self.irq_per_proc
1100        s += '#define RESET_ADDRESS          0x%x\n'  % self.reset_address
1101        s += '#define NB_TOTAL_PROCS         %d\n'    % nb_total_procs
1102        s += '\n'
1103
1104        s += '/* Peripherals */\n' 
1105        s += '\n'
1106        s += '#define NB_TTY_CHANNELS        %d\n'    % tty_channels
1107        s += '#define NB_IOC_CHANNELS        %d\n'    % ioc_channels
1108        s += '#define NB_NIC_CHANNELS        %d\n'    % nic_channels
1109        s += '#define NB_CMA_CHANNELS        %d\n'    % cma_channels
1110        s += '#define NB_TIM_CHANNELS        %d\n'    % tim_channels
1111        s += '#define NB_DMA_CHANNELS        %d\n'    % dma_channels
1112        s += '\n'
1113        s += '#define USE_XCU                %d\n'    % ( nb_xcu != 0 )
1114        s += '#define USE_IOB                %d\n'    % ( nb_iob != 0 )
1115        s += '#define USE_PIC                %d\n'    % ( nb_pic != 0 )
1116        s += '#define USE_FBF                %d\n'    % ( nb_fbf != 0 )
1117        s += '\n'
1118        s += '#define USE_IOC_BDV            %d\n'    % use_bdv
1119        s += '#define USE_IOC_SPI            %d\n'    % use_spi
1120        s += '#define USE_IOC_HBA            %d\n'    % use_hba
1121        s += '\n'
1122        s += '#define USE_RAMDISK            %d\n'    % self.use_ramdisk
1123        s += '\n'
1124        s += '#define FBUF_X_SIZE            %d\n'    % fbf_arg
1125        s += '#define FBUF_Y_SIZE            %d\n'    % fbf_arg
1126        s += '\n'
1127        s += '#define XCU_NB_INPUTS          %d\n'    % xcu_arg
1128        s += '\n'
1129
1130        s += '/* base addresses and sizes for physical segments */\n'
1131        s += '\n'
1132        s += '#define SEG_RAM_BASE           0x%x\n'  % self.ram_base           
1133        s += '#define SEG_RAM_SIZE           0x%x\n'  % self.ram_size           
1134        s += '\n'
1135        s += '#define SEG_CMA_BASE           0x%x\n'  % seg_cma_base           
1136        s += '#define SEG_CMA_SIZE           0x%x\n'  % seg_cma_size           
1137        s += '\n'
1138        s += '#define SEG_DMA_BASE           0x%x\n'  % seg_dma_base           
1139        s += '#define SEG_DMA_SIZE           0x%x\n'  % seg_dma_size           
1140        s += '\n'
1141        s += '#define SEG_FBF_BASE           0x%x\n'  % seg_fbf_base           
1142        s += '#define SEG_FBF_SIZE           0x%x\n'  % seg_fbf_size           
1143        s += '\n'
1144        s += '#define SEG_ICU_BASE           0x%x\n'  % seg_icu_base           
1145        s += '#define SEG_ICU_SIZE           0x%x\n'  % seg_icu_size           
1146        s += '\n'
1147        s += '#define SEG_IOB_BASE           0x%x\n'  % seg_iob_base           
1148        s += '#define SEG_IOB_SIZE           0x%x\n'  % seg_iob_size           
1149        s += '\n'
1150        s += '#define SEG_IOC_BASE           0x%x\n'  % seg_ioc_base           
1151        s += '#define SEG_IOC_SIZE           0x%x\n'  % seg_ioc_size           
1152        s += '\n'
1153        s += '#define SEG_MMC_BASE           0x%x\n'  % seg_mmc_base           
1154        s += '#define SEG_MMC_SIZE           0x%x\n'  % seg_mmc_size           
1155        s += '\n'
1156        s += '#define SEG_MWR_BASE           0x%x\n'  % seg_mwr_base           
1157        s += '#define SEG_MWR_SIZE           0x%x\n'  % seg_mwr_size           
1158        s += '\n'
1159        s += '#define SEG_ROM_BASE           0x%x\n'  % seg_rom_base           
1160        s += '#define SEG_ROM_SIZE           0x%x\n'  % seg_rom_size           
1161        s += '\n'
1162        s += '#define SEG_SIM_BASE           0x%x\n'  % seg_sim_base           
1163        s += '#define SEG_SIM_SIZE           0x%x\n'  % seg_sim_size           
1164        s += '\n'
1165        s += '#define SEG_NIC_BASE           0x%x\n'  % seg_nic_base           
1166        s += '#define SEG_NIC_SIZE           0x%x\n'  % seg_nic_size           
1167        s += '\n'
1168        s += '#define SEG_PIC_BASE           0x%x\n'  % seg_pic_base           
1169        s += '#define SEG_PIC_SIZE           0x%x\n'  % seg_pic_size           
1170        s += '\n'
1171        s += '#define SEG_TIM_BASE           0x%x\n'  % seg_tim_base           
1172        s += '#define SEG_TIM_SIZE           0x%x\n'  % seg_tim_size           
1173        s += '\n'
1174        s += '#define SEG_TTY_BASE           0x%x\n'  % seg_tty_base           
1175        s += '#define SEG_TTY_SIZE           0x%x\n'  % seg_tty_size           
1176        s += '\n'
1177        s += '#define SEG_XCU_BASE           0x%x\n'  % seg_xcu_base           
1178        s += '#define SEG_XCU_SIZE           0x%x\n'  % seg_xcu_size           
1179        s += '\n'
1180        s += '#define SEG_RDK_BASE           0x%x\n'  % seg_rdk_base
1181        s += '#define SEG_RDK_SIZE           0x%x\n'  % seg_rdk_size
1182        s += '\n'
1183        s += '#define PERI_CLUSTER_INCREMENT 0x%x\n'  % self.peri_increment
1184        s += '\n'
1185
1186        s += '/* physical base addresses for identity mapped vsegs */\n'
1187        s += '/* used by the GietVM OS                             */\n'
1188        s += '\n'
1189        s += '#define SEG_BOOT_MAPPING_BASE  0x%x\n'  % boot_mapping_base
1190        s += '#define SEG_BOOT_MAPPING_SIZE  0x%x\n'  % boot_mapping_size
1191        s += '\n'
1192        s += '#define SEG_BOOT_CODE_BASE     0x%x\n'  % boot_code_base
1193        s += '#define SEG_BOOT_CODE_SIZE     0x%x\n'  % boot_code_size
1194        s += '\n'
1195        s += '#define SEG_BOOT_DATA_BASE     0x%x\n'  % boot_data_base
1196        s += '#define SEG_BOOT_DATA_SIZE     0x%x\n'  % boot_data_size
1197        s += '\n'
1198        s += '#define SEG_BOOT_BUFFER_BASE   0x%x\n'  % boot_buffer_base
1199        s += '#define SEG_BOOT_BUFFER_SIZE   0x%x\n'  % boot_buffer_size
1200        s += '\n'
1201        s += '#define SEG_BOOT_STACK_BASE    0x%x\n'  % boot_stack_base
1202        s += '#define SEG_BOOT_STACK_SIZE    0x%x\n'  % boot_stack_size
1203        s += '#endif\n'
1204       
1205        return s
1206
1207    # end of hard_config()
1208
1209    #######################
1210    def netbsd_dts( self ):    # compute string for netbsd.dts file generation,
1211                               # used for netbsd configuration 
1212        # header
1213        s =  '/dts-v1/;\n'
1214        s += '\n'
1215        s += '/{\n'
1216        s += '  #address-cells = <2>;\n' 
1217        s += '  #size-cells    = <1>;\n' 
1218
1219        # cpus (for each cluster)
1220        s += '  cpus {\n'
1221        s += '    #address-cells = <1>;\n'
1222        s += '    #size-cells    = <0>;\n'
1223
1224        for cluster in self.clusters:
1225            for proc in cluster.procs:
1226                proc_id = (((cluster.x << self.y_width) + cluster.y) * self.procs_max) + proc.lpid
1227
1228                s += '    Mips,32@0x%x {\n'                % proc_id
1229                s += '      device_type = "cpu";\n'
1230                s += '      icudev_type = "cpu:mips";\n'
1231                s += '      name        = "Mips,32";\n'
1232                s += '      reg         = <0x%x>;\n'     % proc_id
1233                s += '    };\n'
1234                s += '\n'
1235
1236        s += '  };\n'
1237
1238        # rams (for each cluster)
1239        for cluster in self.clusters:
1240            for pseg in cluster.psegs:
1241
1242                if ( pseg.segtype == 'RAM' ):
1243                    msb  = pseg.base >> 32
1244                    lsb  = pseg.base & 0xFFFFFFFF
1245                    size = pseg.size
1246
1247                    s += %s@0x%x {\n' % (pseg.name, pseg.base)
1248                    s += '    cached      = <1>;\n'
1249                    s += '    device_type = "memory";\n'
1250                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1251                    s += '  };\n'
1252
1253        # peripherals (for each cluster)
1254        for cluster in self.clusters:
1255
1256            # research XCU component
1257            found_xcu = False
1258            for periph in cluster.periphs:
1259                if ( (periph.ptype == 'XCU') ): 
1260                    found_xcu = True
1261                    xcu = periph
1262                    msb  = periph.pseg.base >> 32
1263                    lsb  = periph.pseg.base & 0xFFFFFFFF
1264                    size = periph.pseg.size
1265
1266                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1267                    s += '    device_type = "soclib:xicu:root";\n'
1268                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1269                    s += '    input_lines = <%d>;\n'    % periph.arg1 
1270                    s += '    ipis        = <%d>;\n'    % periph.arg2
1271                    s += '    timers      = <%d>;\n'    % periph.arg3
1272
1273                    output_id = 0            # output index from XCU
1274                    for lpid in xrange ( len(cluster.procs) ):        # destination processor index
1275                        for itid in xrange ( self.irq_per_proc ):     # input irq index on processor
1276                            proc_id = (((cluster.x << self.y_width) + cluster.y) * self.procs_max) + lpid
1277                            s += '    out@%d {\n' % output_id
1278                            s += '      device_type = "soclib:xicu:filter";\n'
1279                            s += '      irq         = <&{/cpus/Mips,32@0x%x} %d>;\n' % (proc_id, itid)
1280                            s += '      output_line = <%d>;\n' % output_id
1281                            s += '      parent      = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1282                            s += '    };\n'
1283
1284                            output_id += 1
1285
1286                    s += '  };\n'
1287
1288            # research PIC component
1289            found_pic = False
1290            for periph in cluster.periphs:
1291                if ( periph.ptype == 'PIC' ): 
1292                    found_pic = True
1293                    pic  = periph
1294                    msb  = periph.pseg.base >> 32
1295                    lsb  = periph.pseg.base & 0xFFFFFFFF
1296                    size = periph.pseg.size
1297
1298                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1299                    s += '    device_type = "soclib:pic:root";\n'
1300                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1301                    s += '    input_lines = <%d>;\n'    % periph.channels 
1302                    s += '  };\n'
1303
1304            if ( (found_xcu == False) and (found_pic == False) and (len(cluster.periphs) > 0) ):
1305                print '[genmap error] in netbsd_dts() : No XCU/PIC in cluster(%d,%d)' % (cluster.x, cluster.y)
1306                sys.exit(1)   
1307             
1308            if ( found_pic == True ):  irq_tgt = pic
1309            else:                      irq_tgt = xcu
1310           
1311            # get all others peripherals in cluster
1312            for periph in cluster.periphs:
1313                msb  = periph.pseg.base >> 32
1314                lsb  = periph.pseg.base & 0xFFFFFFFF
1315                size = periph.pseg.size
1316
1317                # research DMA component
1318                if ( periph.ptype == 'DMA' ):
1319
1320                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1321                    s += '    device_type   = "soclib:dma";\n'
1322                    s += '    reg           = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1323                    s += '    channel_count = <%d>;\n' % periph.channels
1324
1325                    # multi-channels : get HWI index (to XCU) for each channel
1326                    for channel in xrange( periph.channels ):
1327                        hwi_id = 0xFFFFFFFF
1328                        for irq in xcu.irqs:
1329                            if ( (irq.isrtype == 'ISR_DMA') and (irq.channel == channel) ): 
1330                                hwi_id = irq.srcid
1331                        if ( hwi_id == 0xFFFFFFFF ):
1332                            print '[genmap error] in netbsd.dts() ISR_DMA channel %d not found' % channel
1333                            sys.exit(1)
1334
1335                        name = '%s@0x%x' % (xcu.pseg.name, xcu.pseg.base)
1336                        s += '    irq@%d{\n' % channel
1337                        s += '      device_type = "soclib:periph:irq";\n'
1338                        s += '      output_line = <%d>;\n' % channel
1339                        s += '      irq         = <&{/%s%d>;\n' % (name, hwi_id)
1340                        s += '      parent      = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1341                        s += '    };\n'
1342
1343                    s += '  };\n'       
1344
1345                # research MMC component
1346                elif ( periph.ptype == 'MMC' ):
1347
1348                    # get irq line index associated to MMC in XCU
1349                    irq_in = 0xFFFFFFFF
1350                    for irq in xcu.irqs:
1351                        if ( irq.isrtype == 'ISR_MMC' ): irq_in = irq.srcid
1352                    if ( irq_in == 0xFFFFFFFF ):
1353                        print '[genmap error] in netbsd.dts() ISR_MMC not found'
1354                        sys.exit(1)
1355
1356                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1357                    s += '    device_type = "soclib:mmc";\n'
1358                    s += '    irq         = <&{/%s@0x%x%d>;\n' % (irq_tgt.pseg.name, irq_tgt.pseg.base, irq_in)
1359                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1360                    s += '  };\n' 
1361
1362                # research FBF component
1363                elif ( periph.ptype == 'FBF' ): 
1364
1365                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1366                    s += '    device_type = "soclib:framebuffer";\n'
1367                    s += '    mode        = <32>;\n'                    # bits par pixel
1368                    s += '    width       = <%d>;\n'    % periph.arg1
1369                    s += '    height      = <%d>;\n'    % periph.arg2 
1370                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1371                    s += '  };\n'
1372
1373                # research IOC component
1374                elif ( periph.ptype == 'IOC' ): 
1375
1376                    if   ( periph.subtype == 'BDV' ):
1377
1378                        # get irq line index associated to bdv
1379                        irq_in = 0xFFFFFFFF
1380                        for irq in irq_tgt.irqs:
1381                            if ( irq.isrtype == 'ISR_BDV' ): irq_in = irq.srcid
1382                        if ( irq_in == 0xFFFFFFFF ):
1383                            print '[genmap error] in netbsd.dts() ISR_BDV not found'
1384                            sys.exit(1)
1385
1386                        s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1387                        s += '    device_type = "soclib:blockdevice";\n'
1388                        s += '    irq         = <&{/%s@0x%x%d>;\n' % (irq_tgt.pseg.name, irq_tgt.pseg.base, irq_in)
1389                        s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1390                        s += '  };\n'
1391
1392                    elif ( periph.subtype == 'HBA' ):
1393                        print '[genmap error] in netbsd_dts() : HBA peripheral not supported by NetBSD'
1394                        sys.exit(1)
1395
1396                    elif ( periph.subtype == 'SPI' ):
1397
1398                        # get irq line index associated to spi
1399                        irq_in = 0xFFFFFFFF
1400                        for irq in irq_tgt.irqs:
1401                            if ( irq.isrtype == 'ISR_SPI' ): irq_in = irq.srcid
1402                        if ( irq_in == 0xFFFFFFFF ):
1403                            print '[genmap error] in netbsd.dts() ISR_SPI not found'
1404                            sys.exit(1)
1405
1406                        s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1407                        s += '    device_type = "soclib:spi";\n'
1408                        s += '    irq         = <&{/%s@0x%x%d>;\n' % (irq_tgt.pseg.name, irq_tgt.pseg.base, irq_in)
1409                        s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1410                        s += '  };\n'
1411
1412                # research ROM component
1413                elif ( periph.ptype == 'ROM' ):
1414
1415                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1416                    s += '    device_type = "rom";\n'
1417                    s += '    cached      = <1>;\n'
1418                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1419                    s += '  };\n'
1420
1421                # research SIM component
1422                elif ( periph.ptype == 'SIM' ):
1423
1424                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1425                    s += '    device_type = "soclib:simhelper";\n'
1426                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1427                    s += '  };\n'
1428
1429                # research TTY component
1430                elif ( periph.ptype == 'TTY' ):
1431
1432                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1433                    s += '    device_type   = "soclib:tty";\n'
1434                    s += '    reg           = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1435                    s += '    channel_count = < %d >;\n' % periph.channels
1436
1437                    # multi-channels : get HWI index (to XCU or PIC) for each channel
1438                    for channel in xrange( periph.channels ):
1439                        hwi_id = 0xFFFFFFFF
1440                        for irq in irq_tgt.irqs:
1441                            if ( (irq.isrtype == 'ISR_TTY_RX') and (irq.channel == channel) ): 
1442                                hwi_id = irq.srcid
1443                        if ( hwi_id == 0xFFFFFFFF ):
1444                            print '[genmap error] in netbsd.dts() ISR_TTY_RX channel %d not found' % channel
1445                            sys.exit(1)
1446
1447                        name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base)
1448                        s += '    irq@%d{\n' % channel
1449                        s += '      device_type = "soclib:periph:irq";\n'
1450                        s += '      output_line = <%d>;\n' % channel
1451                        s += '      irq         = <&{/%s%d>;\n' % (name, hwi_id)
1452                        s += '      parent      = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1453                        s += '    };\n'
1454
1455                    s += '  };\n'
1456   
1457                # research IOB component
1458                elif ( periph.ptype == 'IOB' ):
1459
1460                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1461                    s += '    device_type = "soclib:iob";\n'
1462                    s += '    reg         = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1463                    s += '  };\n'
1464
1465                # research NIC component
1466                elif ( periph.ptype == 'NIC' ): 
1467
1468                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1469                    s += '    device_type   = "soclib:nic";\n'
1470                    s += '    reg           = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1471                    s += '    channel_count = < %d >;\n' % periph.channels
1472
1473                    # multi-channels : get HWI index (to XCU or PIC) for RX & TX IRQs
1474                    # RX IRQ : (2*channel) / TX IRQs : (2*channel + 1)
1475                    for channel in xrange( periph.channels ):
1476                        hwi_id = 0xFFFFFFFF
1477                        for irq in irq_tgt.irqs:
1478                            if ( (irq.isrtype == 'ISR_NIC_RX') and (irq.channel == channel) ): 
1479                                hwi_id = irq.srcid
1480                        if ( hwi_id == 0xFFFFFFFF ):
1481                            print '[genmap error] in netbsd.dts() ISR_NIC_RX channel %d not found' % channel
1482                            sys.exit(1)
1483
1484                        name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base)
1485                        s += '    irq_rx@%d{\n' % channel
1486                        s += '      device_type = "soclib:periph:irq";\n'
1487                        s += '      output_line = <%d>;\n' % (2*channel)
1488                        s += '      irq         = <&{/%s%d>;\n' % (name, hwi_id)
1489                        s += '      parent      = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1490                        s += '    };\n'
1491
1492                        hwi_id = 0xFFFFFFFF
1493                        for irq in irq_tgt.irqs:
1494                            if ( (irq.isrtype == 'ISR_NIC_TX') and (irq.channel == channel) ): 
1495                                hwi_id = irq.srcid
1496                        if ( hwi_id == 0xFFFFFFFF ):
1497                            print '[genmap error] in netbsd.dts() ISR_NIC_TX channel %d not found' % channel
1498                            sys.exit(1)
1499
1500                        name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base)
1501                        s += '    irq_tx@%d{\n' % channel
1502                        s += '      device_type = "soclib:periph:irq";\n'
1503                        s += '      output_line = <%d>;\n' % (2*channel + 1)
1504                        s += '      irq         = <&{/%s%d>;\n' % (name, hwi_id)
1505                        s += '      parent      = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1506                        s += '    };\n'
1507 
1508                    s += '  };\n'
1509
1510                # research CMA component
1511                elif ( periph.ptype == 'CMA' ): 
1512
1513                    s += %s@0x%x {\n'  % (periph.pseg.name, periph.pseg.base)
1514                    s += '    device_type   = "soclib:cma";\n'
1515                    s += '    reg           = <0x%x  0x%x  0x%x>;\n' % (msb, lsb, size)
1516                    s += '    channel_count = < %d >;\n' % periph.channels
1517
1518                    # multi-channels : get HWI index (to XCU or PIC) for each channel
1519                    for channel in xrange( periph.channels ):
1520                        hwi_id = 0xFFFFFFFF
1521                        for irq in irq_tgt.irqs:
1522                            if ( (irq.isrtype == 'ISR_CMA') and (irq.channel == channel) ): 
1523                                hwi_id = irq.srcid
1524                        if ( hwi_id == 0xFFFFFFFF ):
1525                            print '[genmap error] in netbsd.dts() ISR_CMA channel %d not found' % channel
1526                            sys.exit(1)
1527
1528                        name = '%s@0x%x' % (irq_tgt.pseg.name, irq_tgt.pseg.base)
1529                        s += '    irq@%d{\n' % channel
1530                        s += '      device_type = "soclib:periph:irq";\n'
1531                        s += '      output_line = <%d>;\n' % channel
1532                        s += '      irq         = <&{/%s%d>;\n' % (name, hwi_id)
1533                        s += '      parent      = <&{/%s@0x%x}>;\n' % (periph.pseg.name, periph.pseg.base)
1534                        s += '    };\n'
1535
1536                    s += '  };\n'
1537
1538                # research TIM component
1539                elif ( periph.ptype == 'TIM' ): 
1540
1541                    print '[genmap error] in netbsd_dts() : TIM peripheral not supported by NetBSD'
1542                    sys.exit(1)
1543
1544                # research MWR component
1545                elif ( periph.ptype == 'MWR' ):
1546
1547                    print '[genmap error] in netbsd_dts() : MWR peripheral not supported by NetBSD'
1548                    sys.exit(1)
1549
1550                # research ICU component
1551                elif ( periph.ptype == 'ICU' ): 
1552                    print '[genmap error] in netbsd_dts() : ICU peripheral not supported by NetBSD'
1553                    sys.exit(1)
1554
1555        # topology
1556        s += '\n'
1557        s += '  topology {\n'
1558        s += '    #address-cells = <2>;\n'
1559        s += '    #size-cells = <0>;\n'
1560        for cluster in self.clusters:
1561            s += '    cluster@%d,%d {\n' % (cluster.x, cluster.y) 
1562            s += '      reg     = <%d %d>;\n' % (cluster.x, cluster.y)
1563            s += '      devices = <\n'
1564
1565            offset = ((cluster.x << self.y_width) + cluster.y) * self.procs_max
1566            for proc in cluster.procs:
1567                s += '                &{/cpus/Mips,32@0x%x}\n' % (offset + proc.lpid)
1568            for periph in cluster.periphs:
1569                s += '                &{/%s@0x%x}\n' % (periph.pseg.name, periph.pseg.base)
1570
1571            s += '                >;\n'
1572            s += '    };\n'
1573        s += '  };\n'
1574        s += '};\n'
1575
1576        return s
1577        # end netbsd_dts( )
1578
1579    ###########################
1580    def almos_archinfo( self ):    # compute string for arch.info file generation,
1581                                   # used for almos configuration 
1582        # header
1583        s =  '# arch.info file generated by genmap for %s\n' % self.name
1584        s += '\n'
1585        s += '[HEADER]\n'
1586        s += '        REVISION=1\n'
1587        s += '        ARCH=%s\n'            % self.name
1588        s += '        XMAX=%d\n'            % self.x_size
1589        s += '        YMAX=%d\n'            % self.y_size
1590        s += '        CPU_NR=%d\n'          % self.procs_max
1591        s += '\n'
1592
1593        # clusters
1594        cluster_id = 0
1595        for cluster in self.clusters:
1596
1597            ram = None
1598            nb_cpus = len( cluster.procs )
1599            nb_devs = len( cluster.periphs )
1600            if ( len( cluster.coprocs ) != 0 ):
1601                print 'Error in almos_archinfo() coprocessors not supported yet'
1602                sys.exit(1)
1603
1604            # search a RAM
1605            for pseg in cluster.psegs:
1606                if ( pseg.segtype == 'RAM' ): 
1607                    ram     = pseg
1608                    nb_devs += 1
1609
1610            # search XCU to get IRQs indexes if cluster contains peripherals
1611            if ( len( cluster.periphs ) != 0 ):
1612                tty_irq_id = None
1613                bdv_irq_id = None
1614                dma_irq_id = None
1615
1616                for periph in cluster.periphs:
1617                    if ( periph.ptype == 'XCU' ): 
1618                        # scan irqs
1619                        for irq in periph.irqs:
1620                            if ( irq.isrtype == 'ISR_TTY_RX' ) : tty_irq_id = irq.srcid
1621                            if ( irq.isrtype == 'ISR_BDV'    ) : bdv_irq_id = irq.srcid
1622                            if ( irq.isrtype == 'ISR_DMA'    ) : dma_irq_id = irq.srcid
1623
1624            # Build the cluster description
1625            s += '[CLUSTER]\n'
1626            s += '         CID=%d\n'        % cluster_id
1627            s += '         ARCH_CID=0x%x\n' % ((cluster.x << self.y_width) + cluster.y) 
1628            s += '         CPU_NR=%d\n'     % nb_cpus
1629            s += '         DEV_NR=%d\n'     % nb_devs
1630           
1631
1632            # Handling RAM when cluster contain a RAM
1633            if (ram != None ):
1634                base  = ram.base
1635                size  = ram.size
1636                irqid = -1
1637                s += '         DEVID=RAM' 
1638                s += '  BASE=0x%x  SIZE=0x%x  IRQ=-1\n' % ( base, size )
1639
1640            # Handling peripherals
1641            for periph in cluster.periphs:
1642                base  = periph.pseg.base
1643                size  = periph.pseg.size
1644
1645                if   ( periph.ptype == 'XCU' ): 
1646
1647                    s += '         DEVID=XICU' 
1648                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=-1\n' % ( base, size )
1649
1650                elif ( (periph.ptype == 'TTY') 
1651                       and (tty_irq_id != None) ):
1652
1653                    s += '         DEVID=TTY' 
1654                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=%d\n' % ( base, size, tty_irq_id )
1655
1656                elif ( (periph.ptype == 'DMA') 
1657                       and (dma_irq_id != None) ):
1658
1659                    s += '         DEVID=DMA'
1660                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=%d\n' % ( base, size, dma_irq_id )
1661
1662                elif ( periph.ptype == 'FBF' ):
1663
1664                    s += '         DEVID=FB'
1665                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=-1\n' % ( base, size )
1666
1667                elif ( (periph.ptype == 'IOC') and (periph.subtype == 'BDV')
1668                       and (bdv_irq_id != None) ):
1669
1670                    s += '         DEVID=BLKDEV' 
1671                    s += '  BASE=0x%x  SIZE=0x%x  IRQ=%d\n' % ( base, size, bdv_irq_id )
1672
1673                elif ( periph.ptype == 'PIC' ):
1674
1675                        s += '         DEVID=IOPIC' 
1676                        s += '  BASE=0x%x  SIZE=0x%x  IRQ=-1\n' % ( base, size )
1677
1678                else:
1679                    print '# Warning from almos_archinfo() in cluster[%d,%d]' \
1680                          % (cluster.x, cluster.y)
1681                    print '# peripheral type %s/%s not supported yet\n' \
1682                          % ( periph.ptype, periph.subtype )
1683                 
1684            cluster_id += 1
1685
1686        return s
1687
1688    # end of almos_archinfo()
1689
1690
1691
1692
1693
1694
1695
1696
1697###########################################################################################
1698class Cluster ( object ):
1699###########################################################################################
1700    def __init__( self,
1701                  x, 
1702                  y ):
1703       
1704        self.index       = 0             # global index (set by Mapping constructor)
1705        self.x           = x             # x coordinate
1706        self.y           = y             # y coordinate
1707        self.psegs       = []            # filled by addRam() or addPeriph()
1708        self.procs       = []            # filled by addProc()
1709        self.coprocs     = []            # filled by addCoproc()
1710        self.periphs     = []            # filled by addPeriph()
1711
1712        return
1713
1714    ################
1715    def xml( self ):  # xml for a cluster
1716
1717        s = '        <cluster x="%d" y="%d" >\n' % (self.x, self.y)
1718        for pseg in self.psegs:   s += pseg.xml() 
1719        for proc in self.procs:   s += proc.xml()
1720        for copr in self.coprocs: s += copr.xml() 
1721        for peri in self.periphs: s += peri.xml() 
1722        s += '        </cluster>\n'
1723
1724        return s
1725
1726    #############################################
1727    def cbin( self, mapping, verbose, expected ):    # C binary structure for Cluster
1728
1729        if ( verbose ):
1730            print '*** cbin for cluster [%d,%d]' % (self.x, self.y)
1731
1732        # check index
1733        if (self.index != expected):
1734            print '[genmap error] in Cluster.cbin() : cluster global index = %d / expected = %d' \
1735                  % (self.index, expected )
1736            sys.exit(1)
1737
1738        # compute global index for first pseg
1739        if ( len(self.psegs) > 0 ):
1740            pseg_id = self.psegs[0].index
1741        else:
1742            pseg_id = 0
1743
1744        # compute global index for first proc
1745        if ( len(self.procs) > 0 ):
1746            proc_id = self.procs[0].index
1747        else:
1748            proc_id = 0
1749
1750        # compute global index for first coproc
1751        if ( len(self.coprocs) > 0 ):
1752            coproc_id = self.coprocs[0].index
1753        else:
1754            coproc_id = 0
1755
1756        # compute global index for first periph
1757        if ( len(self.periphs) > 0 ):
1758            periph_id = self.periphs[0].index
1759        else:
1760            periph_id = 0
1761
1762        byte_stream = bytearray()
1763        byte_stream += mapping.int2bytes( 4 , self.x )                 # x coordinate
1764        byte_stream += mapping.int2bytes( 4 , self.y )                 # x coordinate
1765        byte_stream += mapping.int2bytes( 4 , len( self.psegs ) )      # number of psegs in cluster
1766        byte_stream += mapping.int2bytes( 4 , pseg_id )                # first pseg global index
1767        byte_stream += mapping.int2bytes( 4 , len( self.procs ) )      # number of procs in cluster
1768        byte_stream += mapping.int2bytes( 4 , proc_id )                # first proc global index
1769        byte_stream += mapping.int2bytes( 4 , len( self.coprocs ) )    # number of coprocs in cluster
1770        byte_stream += mapping.int2bytes( 4 , coproc_id )              # first coproc global index
1771        byte_stream += mapping.int2bytes( 4 , len( self.periphs ) )    # number of periphs in cluster
1772        byte_stream += mapping.int2bytes( 4 , periph_id )              # first periph global index
1773 
1774        if ( verbose ):
1775            print 'nb_psegs   = %d' %  len( self.psegs )
1776            print 'pseg_id    = %d' %  pseg_id
1777            print 'nb_procs   = %d' %  len( self.procs )
1778            print 'proc_id    = %d' %  proc_id
1779            print 'nb_coprocs = %d' %  len( self.coprocs )
1780            print 'coproc_id  = %d' %  coproc_id
1781            print 'nb_periphs = %d' %  len( self.periphs )
1782            print 'periph_id  = %d' %  periph_id
1783
1784        return byte_stream
1785
1786###########################################################################################
1787class Vspace( object ):
1788###########################################################################################
1789    def __init__( self, 
1790                  name, 
1791                  startname ):
1792
1793        self.index     = 0              # global index ( set by addVspace() )
1794        self.name      = name           # vspace name
1795        self.startname = startname      # name of vobj containing the start_vector
1796        self.vsegs     = []             
1797        self.tasks     = []
1798
1799        return
1800
1801    ################
1802    def xml( self ):   # xml for one vspace
1803
1804        s =  '        <vspace name="%s" startname="%s" >\n' % ( self.name, self.startname )
1805        for vseg in self.vsegs: s += vseg.xml()
1806        for task in self.tasks: s += task.xml() 
1807        s += '        </vspace>\n'
1808
1809        return s
1810
1811    #############################################
1812    def cbin( self, mapping, verbose, expected ):   # C binary structure for Vspace
1813
1814        if ( verbose ):
1815            print '*** cbin for vspace %s' % (self.name)
1816
1817        # check index
1818        if (self.index != expected):
1819            print '[genmap error] in Vspace.cbin() : vspace global index = %d / expected = %d' \
1820                  % (self.index, expected )
1821            sys.exit(1)
1822
1823        # compute global index for vobj containing start_vector
1824        vobj_start_id = 0xFFFFFFFF
1825        for vseg in self.vsegs:
1826            if ( vseg.vobjs[0].name == self.startname ):
1827                vobj_start_id = vseg.vobjs[0].index
1828        if ( vobj_start_id == 0xFFFFFFFF ):
1829            print '[genmap error] in Vspace.cbin() : startname %s not found for vspace %s' \
1830                  % ( self.startname, self.name )
1831            sys.exit(1)
1832 
1833        # compute first vseg, vobj, task global index
1834        first_vseg_id = self.vsegs[0].index
1835        first_vobj_id = self.vsegs[0].vobjs[0].index
1836        first_task_id = self.tasks[0].index
1837       
1838        # compute number of vobjs, tasks, vsegs
1839        nb_vsegs = len( self.vsegs )
1840        nb_tasks = len( self.tasks )
1841        nb_vobjs = 0
1842        for vseg in self.vsegs:
1843            nb_vobjs += len( vseg.vobjs )
1844
1845        byte_stream = bytearray()
1846        byte_stream += mapping.str2bytes( 32, self.name )         # vspace name
1847        byte_stream += mapping.int2bytes( 4,  vobj_start_id )     # vobj start_vector
1848        byte_stream += mapping.int2bytes( 4,  nb_vsegs )          # number of vsegs
1849        byte_stream += mapping.int2bytes( 4,  nb_vobjs )          # number of vobjs
1850        byte_stream += mapping.int2bytes( 4,  nb_tasks )          # number of tasks
1851        byte_stream += mapping.int2bytes( 4,  first_vseg_id )     # first vseg global index
1852        byte_stream += mapping.int2bytes( 4,  first_vobj_id )     # first vobj global index
1853        byte_stream += mapping.int2bytes( 4,  first_task_id )     # first task global index
1854
1855        if ( verbose ):
1856            print 'start_id   = %d' %  vobj_start_id
1857            print 'nb_vsegs   = %d' %  nb_vsegs
1858            print 'nb_vobjs   = %d' %  nb_vobjs
1859            print 'nb_tasks   = %d' %  nb_tasks
1860            print 'vseg_id    = %d' %  first_vseg_id
1861            print 'vobj_id    = %d' %  first_vobj_id
1862            print 'task_id    = %d' %  first_task_id
1863
1864        return byte_stream
1865
1866###########################################################################################
1867class Task( object ):
1868###########################################################################################
1869    def __init__( self, 
1870                  name, 
1871                  trdid, 
1872                  x, 
1873                  y,
1874                  p, 
1875                  stackname, 
1876                  heapname, 
1877                  startid,
1878                  usetty = False, 
1879                  usenic = False, 
1880                  usecma = False,
1881                  usehba = False, 
1882                  usetim = False ):
1883
1884        self.index     = 0             # global index value set by addTask()
1885        self.name      = name          # tsk name
1886        self.trdid     = trdid         # task index (unique in vspace)
1887        self.x         = x             # cluster x coordinate
1888        self.y         = y             # cluster y coordinate
1889        self.p         = p             # processor local index 
1890        self.stackname = stackname     # name of vobj containing the stack
1891        self.heapname  = heapname      # name of vobj containing the heap
1892        self.startid   = startid       # index in start_vector
1893        self.usetty    = usetty        # request a private TTY channel
1894        self.usenic    = usenic        # request a private NIC channel
1895        self.usecma    = usecma        # request a private CMA channel
1896        self.usehba    = usehba        # request a private HBA channel
1897        self.usetim    = usetim        # request a private TIM channel
1898        return
1899
1900    ################
1901    def xml( self ):    # xml for one task
1902
1903        s =  '            <task name="%s"' % self.name
1904        s += ' trdid="%d"'                 % self.trdid
1905        s += ' x="%d"'                     % self.x
1906        s += ' y="%d"'                     % self.y
1907        s += ' p="%d"'                     % self.p
1908        s += ' stackname="%s"'             % self.stackname
1909        s += ' heapname="%s"'              % self.heapname
1910        s += ' startid="%d"'               % self.startid
1911        if self.usetty != 0: s += ' usetty="1"' 
1912        if self.usenic != 0: s += ' usenic="1"' 
1913        if self.usecma != 0: s += ' usehba="1"' 
1914        if self.usehba != 0: s += ' usehba="1"' 
1915        if self.usetim != 0: s += ' usehba="1"' 
1916        s += ' />\n'           
1917
1918        return s
1919
1920    #####################################################
1921    def cbin( self, mapping, verbose, expected, vspace ):  # C binary data structure for Task
1922
1923        if ( verbose ):
1924            print '*** cbin for task %s in vspace %s' % (self.name, vspace.name)
1925
1926        # check index
1927        if (self.index != expected):
1928            print '[genmap error] in Task.cbin() : task global index = %d / expected = %d' \
1929                  % (self.index, expected )
1930            sys.exit(1)
1931
1932        # compute cluster global index
1933        cluster_id = (self.x * mapping.y_size) + self.y
1934
1935        # compute vobj local index for stack
1936        vobj_stack_id = 0xFFFFFFFF
1937        for vseg in vspace.vsegs:
1938            if ( vseg.vobjs[0].name == self.stackname ):
1939                vobj_stack_id = vseg.vobjs[0].index
1940        if ( vobj_stack_id == 0xFFFFFFFF ):
1941            print '[genmap error] in Task.cbin() : stackname %s not found for task %s in vspace %s' \
1942                  % ( self.stackname, self.name, vspace.name )
1943            sys.exit(1)
1944
1945        # compute vobj local index for heap
1946        vobj_heap_id = 0xFFFFFFFF
1947        for vseg in vspace.vsegs:
1948            if ( vseg.vobjs[0].name == self.heapname ):
1949                vobj_heap_id = vseg.vobjs[0].index
1950        if ( vobj_heap_id == 0xFFFFFFFF ):
1951            print '[genmap error] in Task.cbin() : heapname %s not found for task %s in vspace %s' \
1952                  % ( self.heapname, self.name, vspace.name )
1953            sys.exit(1)
1954
1955        byte_stream = bytearray()
1956        byte_stream += mapping.str2bytes( 32, self.name )       # task name in vspace
1957        byte_stream += mapping.int2bytes( 4,  cluster_id )      # cluster global index
1958        byte_stream += mapping.int2bytes( 4,  self.p )          # processor local index in cluster
1959        byte_stream += mapping.int2bytes( 4,  self.trdid )      # thread local index in vspace
1960        byte_stream += mapping.int2bytes( 4,  vobj_stack_id )   # stack vobj local index
1961        byte_stream += mapping.int2bytes( 4,  vobj_heap_id )    # heap vobj local index
1962        byte_stream += mapping.int2bytes( 4,  self.startid )    # index in start vector   
1963        byte_stream += mapping.int2bytes( 4,  self.usetty )     # TTY channel required     
1964        byte_stream += mapping.int2bytes( 4,  self.usenic )     # NIC channel required     
1965        byte_stream += mapping.int2bytes( 4,  self.usecma )     # CMA channel required     
1966        byte_stream += mapping.int2bytes( 4,  self.usehba )     # IOC channel required     
1967        byte_stream += mapping.int2bytes( 4,  self.usetim )     # TIM channel required
1968
1969        if ( verbose ):
1970            print 'clusterid  = %d' %  cluster_id
1971            print 'lpid       = %d' %  self.p
1972            print 'trdid      = %d' %  self.trdid
1973            print 'stackid    = %d' %  vobj_stack_id
1974            print 'heapid     = %d' %  vobj_heap_id
1975            print 'startid    = %d' %  self.startid   
1976     
1977        return byte_stream
1978
1979###########################################################################################
1980class Vseg( object ):
1981###########################################################################################
1982    def __init__( self, 
1983                  name, 
1984                  vbase, 
1985                  mode, 
1986                  x, 
1987                  y, 
1988                  psegname, 
1989                  identity = False,
1990                  local    = False ):
1991
1992        assert mode in VSEGMODES
1993
1994        self.index    = 0                   # global index ( set by addVseg() )
1995        self.name     = name                # vseg name
1996        self.vbase    = vbase & 0xFFFFFFFF  # virtual base address in vspace
1997        self.mode     = mode                # CXWU access rights
1998        self.x        = x                   # x coordinate of destination cluster
1999        self.y        = y                   # y coordinate of destination cluster
2000        self.psegname = psegname            # name of pseg in destination cluster
2001        self.identity = identity            # identity mapping required
2002        self.local    = local               # one copy per cluster
2003        self.vobjs    = []
2004        return
2005
2006    ################
2007    def xml( self ):  # xml for one vseg
2008
2009        s =  '            <vseg name="%s" vbase="0x%x" mode="%s" x="%d" y="%d" psegname="%s"' \
2010             % ( self.name, self.vbase, self.mode, self.x, self.y, self.psegname )
2011        if ( self.identity ): s += ' ident="1"'
2012        if ( self.local ):    s += ' local="1"'
2013        s += ' >\n'
2014        for vobj in self.vobjs:  s += vobj.xml()
2015        s += '            </vseg>\n'
2016
2017        return s
2018
2019    #############################################
2020    def cbin( self, mapping, verbose, expected ):    # C binary structure for Vseg
2021
2022        if ( verbose ):
2023            print '*** cbin for vseg[%d] %s' % (self.index, self.name)
2024
2025        # check index
2026        if (self.index != expected):
2027            print '[genmap error] in Vseg.cbin() : vseg global index = %d / expected = %d' \
2028                  % (self.index, expected )
2029            sys.exit(1)
2030
2031        # compute pseg_id
2032        pseg_id = 0xFFFFFFFF
2033        cluster_id = (self.x * mapping.y_size) + self.y
2034        cluster = mapping.clusters[cluster_id]
2035        for pseg in cluster.psegs:
2036            if (self.psegname == pseg.name):
2037                pseg_id = pseg.index
2038        if (pseg_id == 0xFFFFFFFF):
2039            print '[genmap error] in Vseg.cbin() : psegname %s not found for vseg %s in cluster %d' \
2040                  % ( self.psegname, self.name, cluster_id )
2041            sys.exit(1)
2042
2043        # compute numerical value for mode
2044        mode_id = 0xFFFFFFFF
2045        for x in xrange( len(VSEGMODES) ): 
2046            if ( self.mode == VSEGMODES[x] ): 
2047                mode_id = x
2048        if ( mode_id == 0xFFFFFFFF ):
2049            print '[genmap error] in Vseg.cbin() : undefined vseg mode %s' % self.mode
2050            sys.exit(1)
2051
2052        # compute vobj_id
2053        vobj_id = self.vobjs[0].index 
2054
2055        byte_stream = bytearray()
2056        byte_stream += mapping.str2bytes( 32, self.name )       # vseg name
2057        byte_stream += mapping.int2bytes( 4,  self.vbase )      # virtual base address
2058        byte_stream += mapping.int2bytes( 8,  0 )               # physical base address
2059        byte_stream += mapping.int2bytes( 4,  0 )               # vseg size (bytes)
2060        byte_stream += mapping.int2bytes( 4,  pseg_id )         # physical segment global index
2061        byte_stream += mapping.int2bytes( 4,  mode_id )         # CXWU flags
2062        byte_stream += mapping.int2bytes( 4,  len(self.vobjs) ) # number of vobjs in vseg
2063        byte_stream += mapping.int2bytes( 4,  vobj_id )         # first vobj global index
2064        byte_stream += mapping.int2bytes( 4,  0 )               # linked list of vsegs on same pseg
2065        byte_stream += mapping.int2bytes( 1,  0 )               # mapped when non zero
2066        byte_stream += mapping.int2bytes( 1,  self.identity )   # identity mapping when non zero
2067        byte_stream += mapping.int2bytes( 1,  self.local )      # non shared if non zero
2068        byte_stream += mapping.int2bytes( 1,  0 )               # reserved (padding)
2069
2070        if ( verbose ):
2071            print 'vbase      = %x' %  self.vbase
2072            print 'pseg_id    = %d' %  pseg_id
2073            print 'mode       = %s' %  self.mode
2074            print 'nb_vobjs   = %d' %  len(self.vobjs)
2075            print 'vobj_id    = %d' %  vobj_id
2076     
2077        return byte_stream
2078
2079###########################################################################################
2080class Vobj( object ):
2081###########################################################################################
2082    def __init__( self,
2083                  name, 
2084                  length, 
2085                  vtype, 
2086                  binpath = '', 
2087                  align   = 0, 
2088                  init    = 0 ):
2089
2090        assert vtype in ['ELF','BLOB','PTAB','PERI','MWMR','LOCK', \
2091                         'BUFFER','BARRIER','CONST','MEMSPACE','SCHED']
2092
2093        assert (vtype != 'ELF') or (binpath != '')
2094
2095        self.index    = 0        # global index ( set by addVobj() )
2096        self.name     = name     # vobj name (unique in vspace)
2097        self.vtype    = vtype    # vobj type (defined in mapping_info.h)
2098        self.length   = length   # vobj size (bytes)
2099        self.binpath  = binpath  # pathname for (ELF type)
2100        self.align    = align    # required alignment (logarithm of 2)
2101        self.init     = init     # initialisation value (for BARRIER or MWMR types)
2102
2103        return
2104
2105    ################
2106    def xml( self ):  # xml for a vobj
2107
2108        s = '            <vobj name="%s" type="%s" length="0x%x"' \
2109                           % ( self.name, self.vtype, self.length )
2110        if (self.binpath != ''):   s += ' binpath="%s"' % (self.binpath)
2111        if (self.align   != 0 ):   s += ' align="%d"' % (self.align)
2112        if (self.init    != 0 ):   s += ' init="%d"' % (self.init)
2113        s += ' />\n'
2114
2115        return s
2116
2117    #############################################
2118    def cbin( self, mapping, verbose, expected ):    # C binary structure for Vobj
2119
2120        # check index
2121        if (self.index != expected):
2122            print '[genmap error] in Vobj.cbin() : vobj global index = %d / expected = %d' \
2123                  % (self.index, expected )
2124            sys.exit(1)
2125        elif ( verbose ):
2126            print '*** cbin for vobj[%d] %s' % (self.index, self.name)
2127
2128        # compute numerical value for vtype
2129        vtype_int = 0xFFFFFFFF
2130        for x in xrange( len(VOBJTYPES) ): 
2131            if ( self.vtype == VOBJTYPES[x] ): 
2132                vtype_int = x
2133        if ( vtype_int == 0xFFFFFFFF ):
2134            print '[genmap error] in Vobj.cbin() : undefined vobj type %s' % self.vtype
2135            sys.exit(1)
2136
2137        byte_stream = bytearray()
2138        byte_stream += mapping.str2bytes( 32, self.name )       # vobj name
2139        byte_stream += mapping.str2bytes( 64, self.binpath )    # pathname for .elf file
2140        byte_stream += mapping.int2bytes( 4 , vtype_int )       # vobj type
2141        byte_stream += mapping.int2bytes( 4 , self.length )     # vobj size
2142        byte_stream += mapping.int2bytes( 4 , self.align )      # required alignment
2143        byte_stream += mapping.int2bytes( 4 , 0 )               # virtual base address
2144        byte_stream += mapping.int2bytes( 8 , 0 )               # physical base address
2145        byte_stream += mapping.int2bytes( 4 , self.init )       # init value
2146     
2147        if ( verbose ):
2148            print 'binpath    = %s' %  self.binpath
2149            print 'type       = %s' %  self.vtype
2150            print 'length     = %x' %  self.length
2151       
2152        return byte_stream
2153
2154###########################################################################################
2155class Processor ( object ):
2156###########################################################################################
2157    def __init__( self,
2158                  x, 
2159                  y, 
2160                  lpid ):
2161
2162        self.index    = 0      # global index ( set by addProc() )
2163        self.x        = x      # x cluster coordinate
2164        self.y        = y      # y cluster coordinate
2165        self.lpid     = lpid   # processor local index
2166
2167        return
2168
2169    ################
2170    def xml( self ):   # xml for a processor     
2171        return '            <proc index="%d" />\n' % (self.lpid)
2172
2173    #############################################
2174    def cbin( self, mapping, verbose, expected ):    # C binary structure for Proc
2175
2176        if ( verbose ):
2177            print '*** cbin for proc %d in cluster (%d,%d)' % (self.lpid, self.x, self.y)
2178
2179        # check index
2180        if (self.index != expected):
2181            print '[genmap error] in Proc.cbin() : proc global index = %d / expected = %d' \
2182                  % (self.index, expected )
2183            sys.exit(1)
2184
2185        byte_stream = bytearray()
2186        byte_stream += mapping.int2bytes( 4 , self.lpid )       # local index
2187     
2188        return byte_stream
2189
2190###########################################################################################
2191class Pseg ( object ):
2192###########################################################################################
2193    def __init__( self, 
2194                  name, 
2195                  base, 
2196                  size, 
2197                  x,
2198                  y,
2199                  segtype ):
2200
2201        assert( segtype in PSEGTYPES )
2202
2203        self.index    = 0       # global index ( set by addPseg() )
2204        self.name     = name    # pseg name (unique in cluster)
2205        self.base     = base    # physical base address
2206        self.size     = size    # segment size (bytes)
2207        self.x        = x       # cluster x coordinate
2208        self.y        = y       # cluster y coordinate
2209        self.segtype  = segtype # RAM / PERI (defined in mapping_info.h)
2210
2211        return
2212   
2213    ################
2214    def xml( self ):   # xml for a pseg
2215
2216        return '            <pseg name="%s" type="%s" base="0x%x" length="0x%x" />\n' \
2217                % (self.name, self.segtype, self.base, self.size)
2218
2219    ######################################################
2220    def cbin( self, mapping, verbose, expected, cluster ):    # C binary structure for Pseg
2221
2222        if ( verbose ):
2223            print '*** cbin for pseg[%d] %s in cluster[%d,%d]' \
2224                  % (self.index, self.name, cluster.x, cluster.y)
2225
2226        # check index
2227        if (self.index != expected):
2228            print '[genmap error] in Pseg.cbin() : pseg global index = %d / expected = %d' \
2229                  % (self.index, expected )
2230            sys.exit(1)
2231       
2232        # compute numerical value for segtype
2233        segtype_int = 0xFFFFFFFF
2234        for x in xrange( len(PSEGTYPES) ): 
2235            if ( self.segtype == PSEGTYPES[x] ): 
2236                segtype_int = x
2237        if ( segtype_int == 0xFFFFFFFF ):
2238            print '[genmap error] in Pseg.cbin() : undefined segment type %s' % self.segtype
2239            sys.exit(1)
2240
2241        byte_stream = bytearray()
2242        byte_stream += mapping.str2bytes( 32, self.name )      # pseg name
2243        byte_stream += mapping.int2bytes( 8 , self.base )      # physical base address
2244        byte_stream += mapping.int2bytes( 8 , self.size )      # segment length
2245        byte_stream += mapping.int2bytes( 4 , segtype_int )    # segment type
2246        byte_stream += mapping.int2bytes( 4 , cluster.index )  # cluster global index
2247        byte_stream += mapping.int2bytes( 4 , 0 )              # linked list of vsegs
2248
2249        if ( verbose ):
2250            print 'pbase      = %x' %  self.base
2251            print 'size       = %x' %  self.size
2252            print 'type       = %s' %  self.segtype
2253       
2254        return byte_stream
2255
2256###########################################################################################
2257class Periph ( object ):
2258###########################################################################################
2259    def __init__( self, 
2260                  pseg,               # associated pseg
2261                  ptype,              # peripheral type
2262                  subtype  = 'NONE',  # peripheral subtype
2263                  channels = 1,       # for multi-channels peripherals
2264                  arg      = 0 ):     # optional argument (semantic depends on ptype)
2265
2266        assert ptype in PERIPHTYPES
2267
2268        assert subtype in PERIPHSUBTYPES
2269
2270        self.index    = 0            # global index ( set by addPeriph() )
2271        self.channels = channels 
2272        self.ptype    = ptype
2273        self.subtype  = subtype
2274        self.arg      = arg
2275        self.pseg     = pseg
2276        self.irqs     = []
2277        return
2278
2279    ################
2280    def xml( self ):    # xml for a periph
2281
2282        s =  '            <periph type="%s"' % self.ptype
2283        s += ' subtype="%s"'                 % self.subtype
2284        s += ' psegname="%s"'                % self.pseg.name
2285        s += ' channels="%d"'                % self.channels
2286        s += ' arg="%d" >\n'                 % self.arg
2287        if ( (self.ptype == 'PIC') or (self.ptype == 'XCU') or (self.ptype == 'ICU') ):
2288            for irq in self.irqs: s += irq.xml()
2289        s += '            </periph>\n'
2290
2291        return s
2292
2293    #############################################
2294    def cbin( self, mapping, verbose, expected ):    # C binary structure for Periph
2295
2296        if ( verbose ):
2297            print '*** cbin for periph %s in cluster [%d,%d]' \
2298                  % (self.ptype, self.pseg.x, self.pseg.y)
2299
2300        # check index
2301        if (self.index != expected):
2302            print '[genmap error] in Periph.cbin() : periph global index = %d / expected = %d' \
2303                  % (self.index, expected )
2304            sys.exit(1)
2305
2306        # compute pseg global index
2307        pseg_id = self.pseg.index
2308
2309        # compute first irq global index
2310        if ( len(self.irqs) > 0 ):
2311            irq_id = self.irqs[0].index
2312        else:
2313            irq_id = 0
2314
2315        # compute numerical value for ptype
2316        ptype_id = 0xFFFFFFFF
2317        for x in xrange( len(PERIPHTYPES) ): 
2318            if ( self.ptype == PERIPHTYPES[x] ):  ptype_id = x
2319        if ( ptype_id == 0xFFFFFFFF ):
2320            print '[genmap error] in Periph.cbin() : undefined peripheral type %s' % self.ptype
2321            sys.exit(1)
2322
2323        # compute numerical value for subtype
2324        subtype_id = 0xFFFFFFFF
2325        for x in xrange( len(PERIPHSUBTYPES) ): 
2326            if ( self.subtype == PERIPHSUBTYPES[x] ):  subtype_id = x
2327
2328        # compute
2329        byte_stream = bytearray()
2330        byte_stream += mapping.int2bytes( 4 , ptype_id )         # peripheral type     
2331        byte_stream += mapping.int2bytes( 4 , subtype_id )       # peripheral subtype
2332        byte_stream += mapping.int2bytes( 4 , pseg_id )          # pseg global index
2333        byte_stream += mapping.int2bytes( 4 , self.channels )    # number of channels
2334        byte_stream += mapping.int2bytes( 4 , self.arg )         # optionnal argument
2335        byte_stream += mapping.int2bytes( 4 , len( self.irqs ) ) # number of input irqs
2336        byte_stream += mapping.int2bytes( 4 , irq_id )           # first irq global index
2337
2338        if ( verbose ):
2339            print 'ptype      = %d' %  ptype_id
2340            print 'pseg_id    = %d' %  pseg_id
2341            print 'nb_irqs    = %d' %  len( self.irqs )
2342            print 'irq_id     = %d' %  irq_id       
2343        return byte_stream
2344
2345###########################################################################################
2346class Irq ( object ):
2347###########################################################################################
2348    def __init__( self, 
2349                  irqtype,         # input IRQ type : HWI / WTI / PTI (for XCU only)
2350                  srcid,           # input IRQ index (for XCU or PIC)
2351                  isrtype,         # Type of ISR to be executed
2352                  channel = 0 ):   # channel index for multi-channel ISR
2353
2354        assert irqtype in IRQTYPES
2355        assert isrtype in ISRTYPES
2356        assert srcid < 32
2357
2358        self.index   = 0        # global index ( set by addIrq() )
2359        self.irqtype = irqtype  # IRQ type
2360        self.srcid   = srcid    # source IRQ index
2361        self.isrtype = isrtype  # ISR type
2362        self.channel = channel  # channel index (for multi-channels ISR)
2363        return
2364
2365    ################
2366    def xml( self ):   # xml for Irq
2367
2368        return '                <irq srctype="%s" srcid="%d" isr="%s" channel="%d" />\n' \
2369                % ( self.irqtype, self.srcid, self.isrtype, self.channel )
2370
2371    #############################################
2372    def cbin( self, mapping, verbose, expected ):     # C binary structure for Irq
2373
2374        if ( verbose ):
2375            print '*** cbin for irq[%d]' % (self.index) 
2376
2377        # check index
2378        if (self.index != expected):
2379            print '[genmap error] in Irq.cbin() : irq global index = %d / expected = %d' \
2380                  % (self.index, expected )
2381            sys.exit(1)
2382
2383        # compute numerical value for irqtype
2384        irqtype_id = 0xFFFFFFFF
2385        for x in xrange( len(IRQTYPES) ):
2386            if ( self.irqtype == IRQTYPES[x] ): 
2387                irqtype_id = x
2388        if ( irqtype_id == 0xFFFFFFFF ):
2389            print '[genmap error] in Irq.cbin() : undefined irqtype %s' % self.irqtype
2390            sys.exit(1)
2391
2392        # compute numerical value for isrtype
2393        isrtype_id = 0xFFFFFFFF
2394        for x in xrange( len(ISRTYPES) ): 
2395            if ( self.isrtype == ISRTYPES[x] ): 
2396                isrtype_id = x
2397        if ( isrtype_id == 0xFFFFFFFF ):
2398            print '[genmap error] in Irq.cbin() : undefined isrtype %s' % self.isrtype
2399            sys.exit(1)
2400
2401        byte_stream = bytearray()
2402        byte_stream += mapping.int2bytes( 4,  irqtype_id )
2403        byte_stream += mapping.int2bytes( 4,  self.srcid )
2404        byte_stream += mapping.int2bytes( 4,  isrtype_id )
2405        byte_stream += mapping.int2bytes( 4,  self.channel )
2406        byte_stream += mapping.int2bytes( 4,  0 )
2407        byte_stream += mapping.int2bytes( 4,  0 )
2408
2409        if ( verbose ):
2410            print 'irqtype    = %s' %  self.irqtype
2411            print 'srcid      = %d' %  self.srcid
2412            print 'isrtype    = %s' %  self.isrtype
2413            print 'channel    = %d' %  self.channel
2414
2415        return byte_stream
2416
2417###########################################################################################
2418class Coproc ( object ):
2419###########################################################################################
2420    def __init__( self, 
2421                  pseg ):           # associated pseg
2422
2423        self.index    = 0        # global index value set by addCoproc()
2424        self.pseg     = pseg
2425        self.ports    = []
2426
2427        return
2428
2429    ################
2430    def xml( self ):    # xml for Coproc 
2431
2432        print '[genmap error] in Coproc.xml() : not defined yet'
2433        sys.exit(1)
2434
2435        return 
2436
2437    #############################################
2438    def cbin( self, mapping, verbose, expected ):    # C binary structure for Coproc
2439
2440        if ( verbose ):
2441            print '*** cbin for coproc in cluster (%d,%d)' % (self.pseg.x, self.pseg.y)
2442
2443        # check index
2444        if (self.index != expected):
2445            print '[genmap error] in Coproc.cbin() : coproc global index = %d / expected = %d' \
2446                  % (self.index, expected )
2447            sys.exit(1)
2448
2449        # compute pseg global index
2450        pseg_id = self.pseg.index
2451
2452        # compute first port global index
2453        port_id = self.ports[0].index
2454
2455        byte_stream = bytearray()
2456        byte_stream += mapping.str2bytes( 32, self.pseg.name )    # probablement inutile (AG)
2457        byte_stream += mapping.int2bytes( 4 , pseg_id )           # pseg global index
2458        byte_stream += mapping.int2bytes( 4 , len( self.ports ) ) # number of input irqs
2459        byte_stream += mapping.int2bytes( 4 , port_id )           # first port global index
2460       
2461        if ( verbose ):
2462            print 'irqtype    = %s' %  self.irqtype
2463            print 'pseg_id    = %d' %  pseg_id
2464            print 'nb_ports   = %d' %  len( self.ports )
2465            print 'port_id      %d' %  port_id
2466         
2467        return byte_stream
2468
2469###########################################################################################
2470class Cpport ( object ):
2471###########################################################################################
2472    def __init__( self, 
2473                  direction, 
2474                  vspacename, 
2475                  mwmrname ):
2476
2477        self.index      = 0           # global index ( set by addCpport() )
2478        self.direction  = direction   # TO_COPROC / FROM_COPROC
2479        self.vspacename = vspacename  # name of vspace containing mwmr channel
2480        self.mwmrname   = mwmrname    # name of vobj defining mwmr channel
2481
2482        return
2483
2484    ################
2485    def xml( self ):    # xml for Cpport
2486
2487        print '[genmap error] in Cpport.xml() : not defined yet'
2488        sys.exit(1)
2489
2490        return 
2491
2492    #############################################
2493    def cbin( self, mapping, verbose, expected ):    # C binary structure for Cpport
2494
2495        if ( verbose ):
2496            print '*** cbin for cpport[%d]' % (self.index)
2497
2498        # check index
2499        if ( self.index != expected ):
2500            print '[genmap error] in Cpport.cbin() : port global index = %d / expected = %d' \
2501                  % ( self.index, expected )
2502            sys.exit(1)
2503
2504        # compute numerical value for direction
2505        if ( self.direction == 'TO_COPROC' ):
2506             dir_int = 0
2507        else:
2508             dir_int = 1
2509
2510        # compute vspace global index
2511        vspace_id = 0xFFFFFFFF
2512        for vspace in mapping.vspaces:
2513            if ( self.vspacename == vspace.name ): 
2514                vspace_id = vspace.index
2515        if (vspace_id == 0xFFFFFFFF):
2516            print '[genmap error] in Cpport.cbin() : vspace name %s not found' \
2517                  % ( self.vspacename )
2518            sys.exit(1)
2519
2520        # compute mwmr global index
2521        mwmr_id = 0xFFFFFFFF
2522        for vseg in mapping.vspace[vspace_id].vsegs:
2523            for vobj in vseg.vobjs:
2524                if (self.mwmrname == vobj.name): 
2525                    mwmr_id = vobj.index
2526        if (mwmr_id == 0xFFFFFFFF):
2527            print '[genmap error] in Cpport.cbin() : mwmr vobj name %s not found in vspace %s' \
2528                  % ( self.mwmrname, self.vspacename )
2529            sys.exit(1)
2530
2531        byte_stream = bytearray()
2532        byte_stream += mapping.int2bytes( 4 , dir_int )         # pseg global index
2533        byte_stream += mapping.int2bytes( 4 , vspace_id )       # vspace global index 
2534        byte_stream += mapping.int2bytes( 4 , mwmr_id )         # mwmr vobj global index
2535       
2536        if ( verbose ):
2537            print 'direction  = %s' %  self.direction
2538            print 'vspace_id  = %d' %  vspace_id
2539            print 'mwmr_id    = %d' %  mwmr_id
2540
2541        return byte_stream
2542
2543
2544# Local Variables:
2545# tab-width: 4;
2546# c-basic-offset: 4;
2547# c-file-offsets:((innamespace . 0)(inline-open . 0));
2548# indent-tabs-mode: nil;
2549# End:
2550#
2551# vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
2552
Note: See TracBrowser for help on using the repository browser.