forked from AdaCore/bb-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcortexm.py
722 lines (578 loc) · 20 KB
/
cortexm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
# This module contains cortex-m bsp support
from support.bsp_sources.archsupport import ArchSupport
from support.bsp_sources.target import Target
class CortexMArch(ArchSupport):
@property
def name(self):
return "cortex-m"
def __init__(self):
super(CortexMArch, self).__init__()
self.add_sources('arch', [
'src/s-macres__cortexm3.adb',
'arm/src/breakpoint_handler-cortexm.S'])
self.add_sources('gnarl', [
'src/s-bbcpsp__cortexm.ads',
'src/s-bbcppr__old.ads',
'src/s-bbcppr__armv7m.adb',
'src/s-bbinte__generic.adb',
'src/s-bbsumu__generic.adb',
'src/s-bcpcst__armvXm.ads'])
class ArmV7MArch(ArchSupport):
@property
def name(self):
return "armv7-m"
@property
def parent(self):
return CortexMArch
def __init__(self):
super(ArmV7MArch, self).__init__()
self.add_sources('gnarl', [
'src/s-bbbosu__armv7m.adb',
'src/s-bcpcst__pendsv.adb'])
class ArmV6MTarget(Target):
@property
def target(self):
return "arm-eabi"
@property
def parent(self):
return CortexMArch
@property
def has_timer_64(self):
return False
@property
def has_single_precision_fpu(self):
return False
@property
def has_double_precision_fpu(self):
return False
@property
def has_small_memory(self):
return True
def __init__(self):
super(ArmV6MTarget, self).__init__()
class ArmV7MTarget(ArmV6MTarget):
@property
def parent(self):
return ArmV7MArch
@property
def has_single_precision_fpu(self):
return True
@property
def system_ads(self):
return {'zfp': 'system-xi-arm.ads',
'ravenscar-sfp': 'system-xi-cortexm4-sfp.ads',
'ravenscar-full': 'system-xi-cortexm4-full.ads'}
def __init__(self):
super(ArmV7MTarget, self).__init__()
class LM3S(ArmV7MTarget):
@property
def name(self):
return 'lm3s'
@property
def loaders(self):
return ('ROM', 'RAM', 'USER')
@property
def has_single_precision_fpu(self):
return False
@property
def has_fpu(self):
# Still add floating point attributes
return True
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-msoft-float',
'-mcpu=cortex-m3')
@property
def readme_file(self):
return 'arm/lm3s/README'
@property
def system_ads(self):
# Only zfp supported here
ret = super(LM3S, self).system_ads
return {'zfp': ret['zfp']}
def __init__(self):
super(LM3S, self).__init__()
self.add_linker_script('arm/lm3s/lm3s-rom.ld', 'ROM')
self.add_linker_script('arm/lm3s/lm3s-ram.ld', 'RAM')
self.add_sources('crt0', [
'arm/lm3s/start-rom.S',
'arm/lm3s/start-ram.S',
'arm/lm3s/setup_pll.adb',
'arm/lm3s/setup_pll.ads',
'src/s-textio__lm3s.adb'])
class SamCommonArchSupport(ArchSupport):
@property
def name(self):
return 'sam'
@property
def parent(self):
return ArmV7MArch
@property
def loaders(self):
return ('ROM', 'SAMBA', 'USER')
def __init__(self):
super(SamCommonArchSupport, self).__init__()
self.add_linker_script('arm/sam/common-SAMBA.ld', loader='SAMBA')
self.add_linker_script('arm/sam/common-ROM.ld', loader='ROM')
self.add_sources('crt0', [
'arm/sam/s-sam4s.ads',
'arm/sam/start-rom.S',
'arm/sam/start-ram.S',
'arm/sam/setup_pll.ads'])
self.add_sources('gnarl', [
'src/s-bbpara__sam4s.ads'])
class Sam(ArmV7MTarget):
@property
def name(self):
return self.board
@property
def parent(self):
return SamCommonArchSupport
@property
def has_single_precision_fpu(self):
if self.board == 'sam4s':
return False
else:
return True
@property
def system_ads(self):
# No runtime full
ret = super(Sam, self).system_ads
return {'zfp': ret['zfp'],
'ravenscar-sfp': ret['ravenscar-sfp']}
@property
def compiler_switches(self):
base = ('-mlittle-endian', '-mthumb', '-mcpu=cortex-m4')
if not self.has_single_precision_fpu:
return base
else:
return base + ('-mhard-float', '-mfpu=fpv4-sp-d16', )
def __init__(self, board):
assert board in ('sam4s', 'samg55'), "Unexpected SAM board %s" % board
self.board = board
super(Sam, self).__init__()
self.add_linker_script(
'arm/sam/%s/memory-map.ld' % self.name,
loader=('SAMBA', 'ROM'))
self.add_sources('crt0', [
'arm/sam/%s/board_config.ads' % self.name,
'arm/sam/%s/setup_pll.adb' % self.name,
'arm/sam/%s/svd/i-sam.ads' % self.name,
'arm/sam/%s/svd/i-sam-efc.ads' % self.name,
'arm/sam/%s/svd/i-sam-pmc.ads' % self.name,
'arm/sam/%s/svd/i-sam-sysc.ads' % self.name,
'src/s-textio__sam4s.adb'])
# FIXME: s-textio.adb is invalid for the g55
# ravenscar support
self.add_sources('gnarl', [
'arm/sam/%s/svd/handler.S' % self.name,
'arm/sam/%s/s-bbbopa.ads' % self.name,
'arm/sam/%s/s-bbmcpa.ads' % self.name,
'arm/sam/%s/svd/a-intnam.ads' % self.name])
class SmartFusion2(ArmV7MTarget):
@property
def name(self):
return 'smartfusion2'
@property
def loaders(self):
return ('ROM', 'USER')
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-msoft-float',
'-mcpu=cortex-m3')
@property
def has_single_precision_fpu(self):
return False
@property
def has_fpu(self):
# Still add floating point attributes
return True
@property
def system_ads(self):
# no zfp nor ravenscar-full rts
ret = super(SmartFusion2, self).system_ads
return {'ravenscar-sfp': ret['ravenscar-sfp']}
def __init__(self):
super(SmartFusion2, self).__init__()
self.add_linker_script('arm/smartfusion2/common-ROM.ld', loader='ROM')
self.add_linker_script('arm/smartfusion2/memory-map.ld', loader='ROM')
self.add_sources('crt0', [
'arm/smartfusion2/start-rom.S',
'arm/smartfusion2/setup_pll.adb',
'arm/smartfusion2/setup_pll.ads',
'arm/smartfusion2/s-sf2.ads',
'arm/smartfusion2/s-sf2.adb',
'arm/smartfusion2/s-sf2uar.ads',
'arm/smartfusion2/s-sf2uar.adb',
'arm/smartfusion2/svd/i-sf2.ads',
'arm/smartfusion2/svd/i-sf2-system_registers.ads',
'arm/smartfusion2/svd/i-sf2-mmuart.ads',
'arm/smartfusion2/svd/i-sf2-gpio.ads',
'arm/smartfusion2/s-textio.adb'])
self.add_sources('gnarl', [
'arm/smartfusion2/s-sf2gpi.ads',
'arm/smartfusion2/s-sf2gpi.adb',
'arm/smartfusion2/svd/handler.S',
'arm/smartfusion2/svd/a-intnam.ads',
'src/s-bbpara__smartfusion2.ads'])
class M1AGL(ArmV6MTarget):
@property
def name(self):
return 'm1agl'
@property
def loaders(self):
return (['ROM', 'RAM'])
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-msoft-float',
'-mcpu=cortex-m1')
@property
def system_ads(self):
return {'zfp': 'system-xi-arm.ads',
'ravenscar-sfp': 'system-xi-m1agl-sfp.ads'}
def __init__(self):
super(M1AGL, self).__init__()
self.add_linker_script('arm/igloo/m1agl/common-ROM.ld', loader='ROM')
self.add_linker_script('arm/igloo/m1agl/common-RAM.ld', loader='RAM')
self.add_linker_script('arm/igloo/m1agl/memory-map.ld',
loader=['ROM', 'RAM'])
self.add_sources('crt0', [
'arm/igloo/m1agl/start-rom.S',
'arm/igloo/m1agl/start-ram.S',
'arm/igloo/m1agl/s-bbbopa.ads',
'arm/igloo/m1agl/s-bbmcpa.ads',
'arm/igloo/m1agl/s-textio.adb',
'arm/src/armv6m_irq_trap_without_os_extensions.S'])
self.add_sources('gnarl', [
'arm/igloo/m1agl/a-intnam.ads',
'arm/igloo/m1agl/svd/i-m1agl.ads',
'arm/igloo/m1agl/svd/i-m1agl-coretimer.ads',
'arm/igloo/m1agl/svd/i-m1agl-coreinterrupt.ads',
'arm/igloo/m1agl/svd/i-m1agl-coreuartapb.ads',
'src/s-bbpara__m1agl.ads',
'src/s-bbbosu__m1agl.adb',
'src/s-bcpcst__m1agl.adb'])
class NRF51(ArmV6MTarget):
@property
def name(self):
return 'nRF51'
@property
def loaders(self):
return (['ROM'])
@property
def has_fpu(self):
return True
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-msoft-float',
'-mcpu=cortex-m0')
@property
def system_ads(self):
return {'zfp': 'system-xi-arm.ads',
'ravenscar-sfp': 'system-xi-armv6m-sfp.ads',
'ravenscar-full': 'system-xi-armv6m-full.ads'}
def __init__(self):
super(NRF51, self).__init__()
self.add_linker_script('arm/nordic/nrf51/common-ROM.ld', loader='ROM')
self.add_sources('crt0', [
'src/s-bbarat.ads',
'src/s-bbarat.adb',
'arm/nordic/nrf51/svd/i-nrf51.ads',
'arm/nordic/nrf51/svd/i-nrf51-clock.ads',
'arm/nordic/nrf51/svd/i-nrf51-rtc.ads',
'arm/nordic/nrf51/svd/i-nrf51-uart.ads',
'arm/nordic/nrf51/svd/handler.S',
'arm/nordic/nrf51/start-rom.S',
'arm/nordic/nrf51/s-bbmcpa.ads'])
self.add_sources('gnarl', [
'arm/nordic/nrf51/svd/a-intnam.ads',
'src/s-bbpara__nrf51.ads',
'src/s-bbbosu__nrf51.adb',
'src/s-bcpcst__pendsv.adb'])
class Microbit(NRF51):
@property
def name(self):
return 'microbit'
@property
def use_semihosting_io(self):
return False
def __init__(self):
super(Microbit, self).__init__()
self.add_linker_script('arm/nordic/nrf51/memory-map_nRF51822xxAA.ld',
loader='ROM')
self.add_sources('crt0',
['arm/nordic/nrf51/s-bbbopa__microbit.ads',
'src/s-textio__microbit.adb'])
class Stm32CommonArchSupport(ArchSupport):
"""Holds sources common to all stm32 boards"""
@property
def name(self):
return 'stm32'
@property
def parent(self):
return ArmV7MArch
@property
def loaders(self):
return ('ROM', 'RAM', 'USER')
@property
def readme_file(self):
return 'arm/stm32/README'
def __init__(self):
super(Stm32CommonArchSupport, self).__init__()
self.add_linker_script('arm/stm32/common-RAM.ld', loader='RAM')
self.add_linker_script('arm/stm32/common-ROM.ld', loader='ROM')
self.add_sources('crt0', [
#'src/s-bbpara__stm32f4.ads',
# 'arm/stm32/s-stm32.ads',
# 'arm/stm32/start-rom.S',
'arm/stm32/start-ram.S',
'arm/stm32/start-common.S'])
class Stm32(ArmV7MTarget):
"""Generic handling of stm32 boards"""
@property
def name(self):
return self.board
@property
def parent(self):
return Stm32CommonArchSupport
@property
def use_semihosting_io(self):
return True
@property
def has_double_precision_fpu(self):
if self.mcu == 'stm32f7x9' or self.mcu == 'stm32h7xx':
return True
else:
return False
@property
def cortex(self):
if self.mcu.startswith('stm32f4'):
return 'cortex-m4'
elif self.mcu.startswith('stm32f7') or self.mcu.startswith('stm32h7'):
return 'cortex-m7'
else:
assert False, "Unexpected MCU %s" % self.mcu
@property
def fpu(self):
if self.cortex == 'cortex-m4':
return 'fpv4-sp-d16'
elif not self.has_double_precision_fpu:
return 'fpv5-sp-d16'
else:
return 'fpv5-d16'
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mhard-float',
'-mcpu=%s' % self.cortex,
'-mfpu=%s' % self.fpu,
'-mthumb')
def __init__(self, board):
self.board = board
if self.board == 'stm32f4':
self.mcu = 'stm32f40x'
elif self.board == 'stm32f429disco':
self.mcu = 'stm32f429x'
elif self.board == 'openmv2':
self.mcu = 'stm32f429x'
elif self.board == 'stm32f469disco':
self.mcu = 'stm32f469x'
elif self.board == 'stm32f746disco':
self.mcu = 'stm32f7x'
elif self.board == 'stm32756geval':
self.mcu = 'stm32f7x'
elif self.board == 'stm32f769disco':
self.mcu = 'stm32f7x9'
elif self.board == 'stm32h743nucleo':
self.mcu = 'stm32h7xx'
else:
assert False, "Unknown stm32 board: %s" % self.board
super(Stm32, self).__init__()
#self.add_linker_script('arm/stm32/common-RAM.ld', loader='RAM')
#self.add_linker_script('arm/stm32/common-ROM.ld', loader='ROM')
if self.mcu.startswith('stm32h7'):
self.add_sources('crt0', [
'arm/stm32/stm32h7xx/setup_pll.adb',
'arm/stm32/stm32h7xx/setup_pll.ads',
'arm/stm32/stm32h7xx/start-rom.S'])
else:
self.add_sources('crt0', [
'src/s-bbpara__stm32f4.ads',
'arm/stm32/setup_pll.adb',
'arm/stm32/setup_pll.ads',
'arm/stm32/s-stm32.ads',
'arm/stm32/start-rom.S'])
self.add_linker_script('arm/stm32/%s/memory-map.ld' % self.mcu,
loader=('RAM', 'ROM'))
# startup code
self.add_sources('crt0', [
'arm/stm32/%s/s-bbbopa.ads' % self.mcu,
'arm/stm32/%s/s-bbmcpa.ads' % self.mcu,
'arm/stm32/%s/s-bbmcpa.adb' % self.mcu,
'arm/stm32/%s/svd/i-stm32.ads' % self.mcu,
'arm/stm32/%s/svd/i-stm32-flash.ads' % self.mcu,
'arm/stm32/%s/svd/i-stm32-gpio.ads' % self.mcu,
'arm/stm32/%s/svd/i-stm32-pwr.ads' % self.mcu,
'arm/stm32/%s/svd/i-stm32-rcc.ads' % self.mcu,
'arm/stm32/%s/svd/i-stm32-syscfg.ads' % self.mcu,
'arm/stm32/%s/svd/i-stm32-usart.ads' % self.mcu])
if self.board == 'stm32f4':
self.add_sources('crt0', [
'arm/stm32/stm32f40x/s-stm32.adb'])
elif self.board == 'stm32f429disco':
self.add_sources('crt0', [
'arm/stm32/stm32f429x/s-stm32.adb'])
elif self.board == 'openmv2':
self.add_sources('crt0', [
'arm/stm32/stm32f429x/s-stm32.adb'])
self.update_pair(
's-bbbopa.ads', 'arm/stm32/%s/s-bbbopa-openmv2.ads' % self.mcu)
elif self.board == 'stm32f469disco':
self.add_sources('crt0', [
'arm/stm32/stm32f429x/s-stm32.adb'])
elif self.board == 'stm32f746disco':
self.add_sources('crt0', [
'arm/stm32/stm32f7x/s-stm32.adb'])
elif self.board == 'stm32756geval':
self.add_sources('crt0', [
'arm/stm32/stm32f7x/s-stm32.adb'])
self.update_pair(
's-bbbopa.ads',
'arm/stm32/%s/s-bbbopa-stm32756geval.ads' % self.mcu)
elif self.board == 'stm32f769disco':
self.add_sources('crt0', [
'arm/stm32/stm32f7x/s-stm32.adb'])
elif self.board == 'stm32h743nucleo':# has specific start script + no setup_pll
self.add_sources('crt0', [
'arm/stm32/stm32h7xx/s-bbpara.ads',
'arm/stm32/stm32h7xx/s-stm32.ads',
'arm/stm32/stm32h7xx/s-stm32.adb'
# 'arm/stm32/stm32h7xx/start-common.S',
# 'arm/stm32/stm32h7xx/start-ram.S',
# 'arm/stm32/stm32h7xx/start-rom.S'
])
# ravenscar support
self.add_sources('gnarl', [
'arm/stm32/%s/svd/handler.S' % self.mcu,
'arm/stm32/%s/svd/a-intnam.ads' % self.mcu])
class CortexM0(ArmV6MTarget):
@property
def name(self):
return 'cortex-m0'
@property
def has_fpu(self):
return True
@property
def use_semihosting_io(self):
return True
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-msoft-float',
'-mcpu=cortex-m0')
@property
def system_ads(self):
return {'zfp': 'system-xi-arm.ads'}
class CortexM0P(CortexM0):
@property
def name(self):
return 'cortex-m0p'
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-msoft-float',
'-mcpu=cortex-m0plus')
class CortexM1(ArmV6MTarget):
@property
def name(self):
return 'cortex-m1'
@property
def has_fpu(self):
return True
@property
def use_semihosting_io(self):
return True
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-msoft-float',
'-mcpu=cortex-m1')
@property
def system_ads(self):
return {'zfp': 'system-xi-arm.ads'}
class CortexM3(ArmV7MTarget):
@property
def name(self):
return 'cortex-m3'
@property
def has_fpu(self):
return True
@property
def use_semihosting_io(self):
return True
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-msoft-float',
'-mcpu=cortex-m3')
@property
def system_ads(self):
return {'zfp': 'system-xi-arm.ads'}
class CortexM4(ArmV7MTarget):
@property
def name(self):
return 'cortex-m4'
@property
def has_fpu(self):
return True
@property
def use_semihosting_io(self):
return True
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-msoft-float',
'-mcpu=cortex-m4')
@property
def system_ads(self):
return {'zfp': 'system-xi-arm.ads'}
class CortexM4F(CortexM4):
@property
def name(self):
return 'cortex-m4f'
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-mhard-float',
'-mcpu=cortex-m4', '-mfpu=fpv4-sp-d16')
class CortexM7F(ArmV7MTarget):
@property
def name(self):
return 'cortex-m7f'
@property
def has_fpu(self):
return True
@property
def use_semihosting_io(self):
return True
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-mhard-float',
'-mcpu=cortex-m7', '-mfpu=fpv5-sp-d16')
@property
def system_ads(self):
return {'zfp': 'system-xi-arm.ads'}
class CortexM7DF(CortexM7F):
@property
def name(self):
return 'cortex-m7df'
@property
def compiler_switches(self):
# The required compiler switches
return ('-mlittle-endian', '-mthumb', '-mhard-float',
'-mcpu=cortex-m7', '-mfpu=fpv5-d16')