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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [hal/] [common/] [v2_0/] [doc/] [porting.sgml] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1254 phoenix
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
<!-- <index></index> -->    Porting Guide
34
 
35
36
 
37
38
Introduction
39
 
40
41
eCos has been designed to be fairly easy to port to new targets. A
42
target is a specific platform (board) using a given architecture (CPU
43
type). The porting is facilitated by the hierarchical layering of the
44
eCos sources - all architecture and platform specific code is
45
implemented in a HAL (hardware abstraction layer).
46
47
 
48
49
By porting the eCos HAL to a new target the core functionality of eCos
50
(infra, kernel, uITRON, etc) will be able to run on the target. It may
51
be necessary to add further platform specific code such as serial
52
drivers, display drivers, ethernet drivers, etc. to get a fully
53
capable system.
54
55
 
56
57
This document is intended as a help to the HAL porting process. Due to
58
the nature of a porting job, it is impossible to give a complete
59
description of what has to be done for each and every potential
60
target. This should not be considered a clear-cut recipe - you will
61
probably need to make some implementation decisions, tweak a few
62
things, and just plain have to rely on common sense.
63
64
 
65
66
However, what is covered here should be a large part of the
67
process. If you get stuck, you are advised to read the
68
69
ecos-discuss archive
70
71
where you may find discussions which apply to the problem at
72
hand. You are also invited to ask questions on the
73
74
ecos-discuss mailing list
75
76
to help you resolve problems - but as is always the case
77
with community lists, do not consider it an oracle for any and all
78
questions. Use common sense - if you ask too many questions which
79
could have been answered by reading the
80
81
url="http://sourceware.cygnus.com/ecos/docs-latest/">documentation,
82
FAQ or
83
84
source code
85
, you are likely to be ignored.
86
87
 
88
89
This document will be continually improved by Red Hat engineers as
90
time allows. Feedback and help with improving the document is sought,
91
so if you have any comments at all, please do not hesitate to post
92
them on
93
94
ecos-discuss
95
96
(please prefix the subject with [porting]).
97
98
 
99
100
At the moment this document is mostly an outline. There are many
101
details to fill in before it becomes complete. Many places you'll just
102
find a list of keywords / concepts that should be described (please
103
post on ecos-discuss if there are areas you think are not covered).
104
105
 
106
107
All pages or sections where the caption ends in [TBD] contain little
108
more than key words and/or random thoughts - there has been no work
109
done as such on the content. The word FIXME may appear in the text to
110
highlight places where information is missing.
111
112
 
113
114
 
115
116
117
 
118
119
HAL Structure
120
 
121
122
In order to write an eCos HAL it's a good idea to have at least a
123
passing understanding of how the HAL interacts with the rest of the
124
system.
125
126
 
127
128
 
129
130
HAL Classes
131
 
132
133
The eCos HAL consists of four HAL sub-classes. This table gives a
134
brief description of each class and partly reiterates the description
135
in . The links
136
refer to the on-line CVS tree (specifically to the sub-HALs used by
137
the PowerPC MBX target).
138
139
 
140
141
142
143
144
HAL type
145
Description
146
Functionality Overview
147
148
149
150
151
152
Common HAL (hal/common)
153
154
Configuration options and functionality shared by all HALs.
155
Generic debugging functionality, driver API, eCos/ROM monitor
156
      calling interface, and tests.
157
158
159
  Architecture HAL (hal/<architecture>/arch)
160
  Functionality specific to the given architecture. Also default
161
  implementations of some functionality which can be overridden by
162
  variant or platform HALs.
163
  Architecture specific debugger functionality (handles single
164
     stepping, exception-to-signal conversion, etc.),
165
     exception/interrupt vector definitions and handlers, cache
166
     definition and control macros, context switching code, assembler
167
     functions for early system initialization, configuration options,
168
     and possibly tests. 
169
170
171
  Variant HAL (hal/<architecture>/<variant>)
172
  Some CPU architectures consist of a number variants, for example
173
     MIPS CPUs come in both 32 and 64 bit versions, and some variants
174
     have embedded features additional to the CPU core.
175
176
  Variant extensions to the architecture code (cache,
177
     exception/interrupt), configuration options, possibly drivers for
178
     variant on-core devices, and possibly tests.
179
180
181
  Platform HAL (hal/<architecture>/<platform>)
182
  Contains functionality and configuration options specific to the
183
      platform.
184
185
  Early platform initialization code, platform memory layout
186
     specification, configuration options (processor speed, compiler
187
     options), diagnostic IO functions, debugger IO functions,
188
     platform specific extensions to architecture or variant code
189
     (off-core interrupt controller), and possibly tests.
190
191
192
  Auxiliary HAL (hal/<architecture>/<module>)
193
  Some variants share common modules on the core. Motorola's PowerPC
194
      QUICC is an example of such a module.
195
196
  Module specific functionality (interrupt controller, simple
197
      device drivers), possibly tests.
198
199
200
201
202
203
 
204
205
 
206
207
208
 
209
210
File Descriptions
211
 
212
213
Listed below are the files found in various HALs, with a short
214
description of what each file contains. When looking in existing HALs
215
beware that they do not necessarily follow this naming scheme.
216
If you are writing a new HAL, please try to follow it as
217
closely as possible. Still, no two targets are the same, so sometimes
218
it makes sense to use additional files.
219
220
 
221
222
 
223
224
Common HAL
225
 
226
227
228
229
230
File
231
Description
232
233
234
235
 
236
237
include/dbg-thread-syscall.h
238
  Defines the thread debugging syscall function. This is used by
239
  the ROM monitor to access the thread debugging API in the RAM
240
  application.  .
241
242
243
include/dbg-threads-api.h
244
  Defines the thread debugging API. .
246
247
248
include/drv_api.h
249
  Defines the driver API.
250
251
252
include/generic-stub.h
253
  Defines the generic stub features.
254
255
256
include/hal_if.h
257
  Defines the ROM/RAM calling interface API.
258
259
260
include/hal_misc.h
261
  Defines miscellaneous helper functions shared by all HALs.
262
263
264
include/hal_stub.h
265
  Defines eCos mappings of GDB stub features.
266
267
268
src/dbg-threads-syscall.c
269
  Thread debugging implementation.
270
271
272
src/drv_api.c
273
  Driver API implementation. Depending on configuration this
274
  provides either wrappers for the kernel API, or a minimal
275
  implementation of these features. This allows drivers to be written
276
  relying only on HAL features.
277
278
279
src/dummy.c
280
  Empty dummy file ensuring creation of libtarget.a.
281
282
283
src/generic-stub.c
284
  Generic GDB stub implementation. This provides the
285
  communication protocol used to communicate with GDB over a serial
286
  device or via the network.
287
288
289
src/hal_if.c
290
  ROM/RAM calling interface implementation. Provides wrappers from
291
  the calling interface API to the eCos features used for the
292
  implementation.
293
294
295
src/hal_misc.c
296
  Various helper functions shared by all platforms and
297
  architectures.
298
299
300
src/hal_stub.c
301
  Wrappers from eCos HAL features to the features required by the
302
  generic GDB stub.
303
304
305
src/stubrom/stubrom.c
306
  The file used to build eCos GDB stub images. Basically a
307
  cyg_start function with a hard coded breakpoint.
308
309
310
src/thread-packets.c
311
  More thread debugging related functions.
312
313
314
src/thread-pkts.h
315
  Defines more thread debugging related function.
316
317
318
319
320
 
321
322
 
323
324
325
 
326
327
Architecture HAL
328
 
329
Some architecture HALs may add extra files for architecture
330
specific serial drivers, or for handling interrupts and exceptions if it
331
makes sense.
332
 
333
Note that many of the definitions in these files are only
334
conditionally defined - if the equivalent variant or platform headers
335
provide the definitions, those override the generic architecture
336
definitions.
337
 
338
339
340
341
342
File
343
Description
344
345
346
347
 
348
349
include/arch.inc
350
  Various assembly macros used during system initialization.
351
352
353
include/basetype.h
354
  Endian, label, alignment, and type size definitions. These
355
  override common defaults in CYGPKG_INFRA.
356
357
358
include/hal_arch.h
359
  Saved register frame format, various thread, register and stack
360
  related macros.
361
362
363
include/hal_cache.h
364
  Cache definitions and cache control macros.
365
366
367
include/hal_intr.h
368
  Exception and interrupt definitions. Macros for configuring and
369
  controlling interrupts. eCos real-time clock control macros.
370
371
372
include/hal_io.h
373
  Macros for accessing IO devices.
374
375
376
include/<arch>_regs.h
377
  Architecture register definitions.
378
379
380
include/<arch>_stub.h
381
  Architecture stub definitions. In particular the register frame
382
  layout used by GDB. This may differ from the one used by eCos.
383
384
385
include/<arch>.inc
386
  Architecture convenience assembly macros.
387
388
389
src/<arch>.ld
390
  Linker macros.
391
392
393
src/context.S
394
  Functions handling context switching and setjmp/longjmp.
395
396
397
src/hal_misc.c
398
  Exception and interrupt handlers in C. Various other utility
399
  functions.
400
401
402
src/hal_mk_defs.c
403
  Used to export definitions from C header files to assembler
404
  header files.
405
406
407
src/hal_intr.c
408
  Any necessary interrupt handling functions.
409
410
411
src/<arch>stub.c
412
  Architecture stub code. Contains functions for translating eCos
413
  exceptions to UNIX signals and functions for single-stepping.
414
415
416
src/vectors.S
417
  Exception, interrupt and early initialization code.
418
419
420
421
422
 
423
 
424
425
 
426
427
428
 
429
430
Variant HAL
431
 
432
Some variant HALs may add extra files for variant specific serial
433
drivers, or for handling interrupts/exceptions if it makes sense.
434
 
435
Note that these files may be mostly empty if the CPU variant can be
436
controlled by the generic architecture macros. The definitions present
437
are only conditionally defined - if the equivalent platform headers
438
provide the definitions, those override the variant definitions.
439
 
440
441
442
443
444
File
445
Description
446
447
448
449
 
450
451
include/var_arch.h
452
  Saved register frame format, various thread, register and stack
453
  related macros.
454
455
456
include/var_cache.h
457
  Cache related macros.
458
459
460
include/var_intr.h
461
  Interrupt related macros.
462
463
464
include/var_regs.h
465
  Extra register definitions for the CPU variant.
466
467
468
include/variant.inc
469
  Various assembly macros used during system initialization.
470
471
472
src/var_intr.c
473
  Interrupt functions if necessary.
474
475
476
src/var_misc.c
477
  hal_variant_init function and any necessary extra functions.
478
479
480
src/variant.S
481
  Interrupt handler table definition.
482
483
484
src/<arch>_<variant>.ld
485
  Linker macros.
486
487
488
489
490
 
491
492
 
493
494
495
 
496
497
Platform HAL
498
 
499
Extras files may be added for platform specific serial
500
drivers. Extra files for handling interrupts and exceptions will be
501
present if it makes sense.
502
 
503
504
505
506
507
File
508
Description
509
510
511
512
 
513
514
include/hal_diag.h
515
  Defines functions used for HAL diagnostics output. This would
516
  normally be the ROM calling interface wrappers, but may also be the
517
  low-level IO functions themselves, saving a little overhead.
518
519
520
include/platform.inc
521
 
522
  Platform initialization code. This includes memory controller,
523
  vectors, and monitor initialization. Depending on the architecture,
524
  other things may need defining here as well: interrupt decoding,
525
  status register initialization value, etc.
526
 
527
528
529
include/plf_cache.h
530
  Platform specific cache handling.
531
532
533
include/plf_intr.h
534
  Platform specific interrupt handling.
535
536
537
include/plf_io.h
538
  PCI IO definitions and macros. May also be used to override
539
  generic HAL IO macros if the platform endianness differs from that of
540
  the CPU.
541
542
543
include/plf_stub.h
544
  Defines stub initializer and board reset details.
545
546
547
src/hal_diag.c
548
  May contain the low-level device drivers. But these may also
549
  reside in plf_stub.c
550
551
552
src/platform.S
553
  Memory controller setup macro, and if necessary interrupt
554
  springboard code.
555
556
557
src/plf_misc.c
558
  Platform initialization code.
559
560
561
src/plf_mk_defs.c
562
  Used to export definitions from C header files to assembler
563
  header files.
564
565
566
src/plf_stub.c
567
  Platform specific stub initialization and possibly the low-level
568
  device driver.
569
570
571
572
573
 
574
The platform HAL also contains files specifying the platform's
575
memory layout. These files are located in
576
include/pkgconf.
577
 
578
579
 
580
581
582
 
583
584
Auxiliary HAL
585
 
586
Auxiliary HALs contain whatever files are necessary to provide the
587
required functionality. There are no predefined set of files required
588
in an auxiliary HAL.
589
 
590
591
 
592
593
 
594
595
 
596
597
 
598
599
 
600
601
602
 
603
604
Virtual Vectors (eCos/ROM Monitor Calling Interface)
605
 
606
607
Some eCos platforms have supported full debugging capabilities via
608
CygMon since day one. Platforms of the architectures PowerPC, ARM, and
609
SH do not provide those features unless a GDB stub is included in the
610
application.
611
612
 
613
614
This is going to change. All platforms will (eventually) support
615
all the debugging features by relying on a ROM/RAM calling interface
616
(also referred to as virtual vector table) provided by the ROM
617
monitor. This calling interface is based on the tables used by libbsp
618
and is thus backwards compatible with the existing CygMon supported
619
platforms.
620
621
 
622
623
 
624
625
Virtual Vectors
626
 
627
What are virtual vectors, what do they do, and why are they
628
needed?
629
630
 
631
632
"Virtual vectors" is the name of a table located at a static
633
location in the target address space. This table contains 64 vectors
634
that point to service functions or data.
635
636
 
637
The fact that the vectors are always placed at the same location in
638
the address space means that both ROM and RAM startup configurations
639
can access these and thus the services pointed to.
640
 
641
The primary goal is to allow services to be provided by ROM
642
configurations (ROM monitors such as RedBoot in particular) with
643
clients in RAM configurations being able to use these
644
services.
645
 
646
Without the table of pointers this would be impossible since the
647
ROM and RAM applications would be linked separately - in effect having
648
separate name spaces - preventing direct references from one to the
649
other.
650
 
651
This decoupling of service from client is needed by RedBoot,
652
allowing among other things debugging of applications which do not
653
contain debugging client code (stubs).
654
 
655
656
 
657
658
Initialization (or Mechanism vs. Policy)
659
 
660
Virtual vectors are a mechanism for decoupling services
661
from clients in the address space.
662
 
663
The mechanism allows services to be implemented by a ROM
664
monitor, a RAM application, to be switched out at run-time, to be
665
disabled by installing pointers to dummy functions, etc.
666
 
667
The appropriate use of the mechanism is specified loosely by a
668
policy. The general policy dictates that the vectors are
669
initialized in whole by ROM monitors (built for ROM or RAM), or by
670
stand-alone applications.
671
 
672
For configurations relying on a ROM monitor environment, the policy
673
is to allow initialization on a service by service basis. The default
674
is to initialize all services, except COMMS services since these are
675
presumed to already be carrying a communication session to the
676
debugger / console which was used for launching the application.  This
677
means that the bulk of the code gets tested in normal builds, and not
678
just once in a blue moon when building new stubs or a ROM
679
configuration.
680
 
681
The configuration options are written to comply with this policy by
682
default, but can be overridden by the user if desired. Defaults
683
are:
684
 
685
686
For application development: the ROM monitor provides
687
debugging and diagnostic IO services, the RAM application relies
688
on these by default.
689
690
691
For production systems: the application contains all the
692
necessary services.
693
694
 
695
696
 
697
698
 
699
700
701
 
702
703
Pros and Cons of Virtual Vectors
704
 
705
706
There are pros and cons associated with the use of virtual
707
vectors. We do believe that the pros generally outweigh the cons by a
708
great margin, but there may be situations where the opposite is
709
true.
710
711
 
712
713
The use of the services are implemented by way of macros, meaning
714
that it is possible to circumvent the virtual vectors if
715
desired. There is (as yet) no implementation for doing this, but it is
716
possible.
717
718
 
719
Here is a list of pros and cons:
720
 
721
722
Pro: Allows debugging without including stubs
723
 
724
      This is the primary reason for using virtual vectors. It
725
          allows the ROM monitor to provide most of the debugging
726
          infrastructure, requiring only the application to provide
727
          hooks for asynchronous debugger interrupts and for accessing
728
          kernel thread information.
729
 
730
Pro: Allows debugging to be initiated from arbitrary
731
       channel
732
 
733
       While this is only true where the application does not
734
           actively override the debugging channel setup, it is a very
735
           nice feature during development. In particular it makes it
736
           possible to launch (and/or debug) applications via Ethernet
737
           even though the application configuration does not contain
738
           networking support.
739
 
740
Pro: Image smaller due to services being provided by ROM
741
       monitor
742
 
743
      All service functions except HAL IO are included in the
744
           default configuration. But if these are all disabled the
745
           image for download will be a little smaller. Probably
746
           doesn't matter much for regular development, but it is a
747
           worthwhile saving for the 20000 daily tests run in the Red
748
           Hat eCos test farm.
749
 
750
Con: The vectors add a layer of indirection, increasing application
751
       size and reducing performance.
752
 
753
      The size increase is a fraction of what is required to
754
           implement the services. So for RAM configurations there is
755
           a net saving, while for ROM configurations there is a small
756
           overhead.
757
 
758
      The performance loss means little for most of the
759
           services (of which the most commonly used is diagnostic IO
760
           which happens via polled routines
761
           anyway).
762
763
 
764
Con: The layer of indirection is another point of
765
       failure.
766
 
767
       The concern primarily being that of vectors being
768
           trashed by rogue writes from bad code, causing a complete
769
           loss of the service and possibly a crash.  But this does
770
           not differ much from a rogue write to anywhere else in the
771
           address space which could cause the same amount of
772
           mayhem. But it is arguably an additional point of failure
773
           for the service in question.
774
 
775
Con: All the indirection stuff makes it harder to bring a HAL
776
       up
777
 
778
       This is a valid concern. However, seeing as most of the
779
           code in question is shared between all HALs and should
780
           remain unchanged over time, the risk of it being broken
781
           when a new HAL is being worked on should be
782
           minimal.
783
 
784
       When starting a new port, be sure to implement the HAL
785
           IO drivers according to the scheme used in other drivers,
786
           and there should be no problem.
787
 
788
       However, it is still possible to circumvent the vectors
789
           if they are suspect of causing problems: simply change the
790
           HAL_DIAG_INIT and HAL_DIAG_WRITE_CHAR macros to use the raw
791
           IO functions.
792
793
 
794
795
 
796
797
798
 
799
800
Available services
801
 
802
803
The hal_if.h file in the common HAL defines the
804
complete list of available services. A few worth mentioning in
805
particular:
806
 
807
808
 COMMS services. All HAL IO happens via the communication
809
        channels.
810
811
 uS delay. Fine granularity (busy wait) delay function.
812
813
 Reset. Allows a software initiated reset of the board.
814
815
816
 
817
818
 
819
820
 
821
822
 
823
824
825
 
826
827
The COMMS channels
828
 
829
As all HAL IO happens via the COMMS channels these deserve to be
830
described in a little more detail. In particular the controls of where
831
diagnostic output is routed and how it is treated to allow for display
832
in debuggers.
833
 
834
835
 
836
837
Console and Debugging Channels
838
 
839
There are two COMMS channels - one for console IO and one for
840
debugging IO. They can be individually configured to use any of the
841
actual IO ports (serial or Ethernet) available on the platform.
842
 
843
The console channel is used for any IO initiated by calling the
844
diag_*() functions. Note that these should only be used during
845
development for debugging, assertion and possibly tracing
846
messages. All proper IO should happen via proper devices. This means
847
it should be possible to remove the HAL device drivers from production
848
configurations where assertions are disabled.
849
 
850
The debugging channel is used for communication between the
851
debugger and the stub which remotely controls the target for the
852
debugger (the stub runs on the target). This usually happens via some
853
protocol, encoding commands and replies in some suitable form.
854
 
855
Having two separate channels allows, e.g., for simple logging
856
without conflicts with the debugger or interactive IO which some
857
debuggers do not allow.
858
 
859
860
 
861
862
863
 
864
865
Mangling
866
 
867
As debuggers usually have a protocol using specialized commands
868
when communicating with the stub on the target, sending out text as
869
raw ASCII from the target on the same channel will either result in
870
protocol errors (with loss of control over the target) or the text may
871
just be ignored as junk by the debugger.
872
 
873
To get around this, some debuggers have a special command for text
874
output. Mangling is the process of encoding diagnostic ASCII text
875
output in the form specified by the debugger protocol.
876
 
877
When it is necessary to use mangling, i.e. when writing console
878
output to the same port used for debugging, a mangler function is
879
installed on the console channel which mangles the text and passes it
880
on to the debugger channel.
881
 
882
883
 
884
885
886
 
887
888
Controlling the Console Channel
889
 
890
Console output configuration is either inherited from the ROM
891
monitor launching the application, or it is specified by the
892
application. This is controlled by the new option
893
CYGSEM_HAL_VIRTUAL_VECTOR_INHERIT_CONSOLE which
894
defaults to enabled when the configuration is set to use a ROM
895
monitor.
896
 
897
If the user wants to specify the console configuration in the
898
application image, there are two new options that are used for
899
this.
900
 
901
Defaults are to direct diagnostic output via a mangler to the
902
debugging channel (CYGDBG_HAL_DIAG_TO_DEBUG_CHAN
903
enabled). The mangler type is controlled by the option
904
CYGSEM_HAL_DIAG_MANGLER. At present there are only
905
two mangler types:
906
 
907
908
GDB
909
 
910
   This causes a mangler appropriate for debugging with GDB to be
911
       installed on the console channel.
912
 
913
None
914
 
915
    This causes a NULL mangler to be installed on the console
916
        channel.  It will redirect the IO to/from the debug channel
917
        without mangling of the data. This option differs from setting
918
        the console channel to the same IO port as the debugging
919
        channel in that it will keep redirecting data to the debugging
920
        channel even if that is changed to some other port.
921
 
922
923
 
924
Finally, by disabling CYGDBG_HAL_DIAG_TO_DEBUG_CHAN, the diagnostic
925
output is directed in raw form to the specified console IO port.
926
 
927
In summary this results in the following common configuration
928
scenarios for RAM startup configurations:
929
 
930
931
 For regular debugging with diagnostic output appearing in the
932
     debugger, mangling is enabled and stubs disabled.
933
 
934
     Diagnostic output appears via the debugging channel as
935
     initiated by the ROM monitor, allowing for correct behavior
936
     whether the application was launched via serial or Ethernet, from
937
     the RedBoot command line or from a debugger.
938
939
 
940
 For debugging with raw diagnostic output, mangling is
941
     disabled.
942
 
943
      Debugging session continues as initiated by the ROM monitor,
944
     whether the application was launched via serial or
945
     Ethernet. Diagnostic output is directed at the IO port configured
946
     in the application configuration.
947
 
948
     
949
     Note:
950
      There is one caveat to be aware of. If the
951
       application uses proper devices (be it serial or Ethernet) on
952
       the same ports as those used by the ROM monitor, the
953
       connections initiated by the ROM monitor will be
954
       terminated.
955
     
956
957
 
958
959
 
960
And for ROM startup configurations:
961
 
962
963
 Production configuration with raw output and no debugging
964
     features (configured for RAM or ROM), mangling is disabled, no
965
     stubs are included.
966
 
967
     Diagnostic output appears (in unmangled form) on the specified
968
     IO port.
969
970
 
971
 RedBoot configuration, includes debugging features and necessary
972
     mangling.
973
 
974
     Diagnostic and debugging output port is auto-selected by the
975
     first connection to any of the supported IO ports. Can change
976
     from interactive mode to debugging mode when a debugger is
977
     detected - when this happens a mangler will be installed as
978
     required.
979
980
 
981
 GDB stubs configuration (obsoleted by RedBoot configuration),
982
     includes debugging features, mangling is hardwired to GDB
983
     protocol.
984
 
985
     Diagnostic and debugging output is hardwired to configured IO
986
     ports, mangling is hardwired.
987
988
 
989
990
991
 
992
993
994
 
995
996
Footnote: Design Reasoning for Control of Console Channel
997
 
998
The current code for controlling the console channel is a
999
replacement for an older implementation which had some shortcomings
1000
which addressed by the new implementation.
1001
 
1002
This is what the old implementation did: on initialization it would
1003
check if the CDL configured console channel differed from the active
1004
debug channel - and if so, set the console channel, thereby disabling
1005
mangling.
1006
 
1007
The idea was that whatever channel was configured to be used for
1008
console (i.e., diagnostic output) in the application was what should
1009
be used. Also, it meant that if debug and console channels were
1010
normally the same, a changed console channel would imply a request for
1011
unmangled output.
1012
 
1013
But this prevented at least two things:
1014
 
1015
1016
 It was impossible to inherit the existing connection by which
1017
     the application was launched (either by RedBoot commands via
1018
     telnet, or by via a debugger).
1019
 
1020
     This was mostly a problem on targets supporting Ethernet
1021
     access since the diagnostic output would not be returned via the
1022
     Ethernet connection, but on the configured serial port.
1023
 
1024
     The problem also occurred on any targets with multiple serial
1025
     ports where the ROM monitor was configured to use a different
1026
     port than the CDL defaults.
1027
1028
 
1029
 Proper control of when to mangle or just write out raw ASCII
1030
        text.
1031
 
1032
     Sometimes it's desirable to disable mangling, even if the
1033
     channel specified is the same as that used for debugging. This
1034
     usually happens if GDB is used to download the application, but
1035
     direct interaction with the application on the same channel is
1036
     desired (GDB protocol only allows output from the target, no
1037
     input).
1038
1039
1040
 
1041
1042
 
1043
1044
 
1045
1046
 
1047
1048
1049
 
1050
1051
The calling Interface API
1052
 
1053
The calling interface API is defined by hal_if.h and hal_if.c in
1054
hal/common.
1055
 
1056
The API provides a set of services. Different platforms, or
1057
different versions of the ROM monitor for a single platform, may
1058
implement fewer or extra service. The table has room for growth, and
1059
any entries which are not supported map to a NOP-service (when called
1060
it returns 0 (false)).
1061
1062
 
1063
A client of a service should either be selected by configuration,
1064
or have suitable fall back alternatives in case the feature is not
1065
implemented by the ROM monitor.
1066
1067
 
1068
1069
Note:
1070
1071
Checking for unimplemented service when this may be a data
1072
field/pointer instead of a function: suggest reserving the last entry
1073
in the table as the NOP-service pointer. Then clients can compare a
1074
service entry with this pointer to determine whether it's initialized
1075
or not.
1076
1077
1078
 
1079
The header file cyg/hal/hal_if.h defines
1080
 the table layout and accessor macros (allowing primitive type
1081
 checking and alternative implementations should it become necessary).
1082
1083
 
1084
The source file hal_if.c defines the table
1085
 initialization function. All HALs should call this during platform
1086
 initialization - the table will get initialized according to
1087
 configuration.  Also defined here are wrapper functions which map
1088
 between the calling interface API and the API of the used eCos
1089
 functions.
1090
1091
 
1092
1093
 
1094
1095
Implemented Services
1096
 
1097
This is a brief description of the services, some of which are
1098
described in further detail below.
1099
 
1100
1101
VERSION
1102
        Version of table. Serves as a way to check for how many
1103
        features are available in the table. This is the index of the
1104
        last service in the table.
1105
KILL_VECTOR
1106
        [Presently unused by the stub code, but initialized] This
1107
        vector defines a function to execute when the system receives
1108
        a kill signal from the debugger. It is initialized with the
1109
        reset function (see below), but the application (or eCos) can
1110
        override it if necessary.
1111
CONSOLE_PROCS
1112
        The communication procedure table used for console IO
1113
        (see .
1114
DEBUG_PROCS
1115
        The communication procedure table used for debugger IO
1116
        (see ).
1117
FLUSH_DCACHE
1118
        Flushes the data cache for the specified
1119
        region. Some implementations may flush the entire data cache.
1120
FLUSH_ICACHE
1121
        Flushes (invalidates) the instruction cache
1122
        for the specified region. Some implementations may flush the
1123
        entire instruction cache.
1124
SET_DEBUG_COMM
1125
        Change debugging communication channel.
1126
SET_CONSOLE_COMM
1127
        Change console communication channel.
1128
DBG_SYSCALL
1129
        Vector used to communication between debugger functions in
1130
        ROM and in RAM. RAM eCos configurations may install a function
1131
        pointer here which the ROM monitor uses to get thread
1132
        information from the kernel running in RAM.
1133
RESET
1134
        Resets the board on call. If it is not possible to reset
1135
        the board from software, it will jump to the ROM entry point
1136
        which will perform a "software" reset of the board.
1137
CONSOLE_INTERRUPT_FLAG
1138
        Set if a debugger interrupt request was detected while
1139
        processing console IO. Allows the actual breakpoint action to
1140
        be handled after return to RAM, ensuring proper backtraces
1141
        etc.
1142
DELAY_US
1143
        Will delay the specified number of microseconds. The
1144
        precision is platform dependent to some extend - a small value
1145
        (<100us) is likely to cause bigger delays than requested.
1146
FLASH_CFG_OP
1147
        For accessing configuration settings kept in flash memory.
1148
INSTALL_BPT_FN
1149
        Installs a breakpoint at the specified address. This is
1150
        used by the asynchronous breakpoint support
1151
        (see ).
1152
1153
1154
 
1155
1156
1157
 
1158
1159
Compatibility
1160
 
1161
When a platform is changed to support the calling interface,
1162
applications will use it if so configured. That means that if an
1163
application is run on a platform with an older ROM monitor, the
1164
service is almost guaranteed to fail.
1165
1166
 
1167
For this reason, applications should only use Console Comm for HAL
1168
diagnostics output if explicitly configured to do so
1169
(CYGSEM_HAL_VIRTUAL_VECTOR_DIAG).
1170
1171
 
1172
As for asynchronous GDB interrupts, the service will always be
1173
used. This is likely to cause a crash under older ROM monitors, but
1174
this crash may be caught by the debugger. The old workaround still
1175
applies: if you need asynchronous breakpoints or thread debugging
1176
under older ROM monitors, you may have to include the debugging
1177
support when configuring eCos.
1178
1179
 
1180
1181
 
1182
1183
1184
 
1185
1186
Implementation details
1187
 
1188
During the startup of a ROM monitor, the calling table will be
1189
initialized. This also happens if eCos is configured not to rely on
1190
a ROM monitor.
1191
1192
 
1193
1194
Note:
1195
 There is reserved space (256 bytes) for the vector
1196
table whether it gets used or not. This may be something that we want
1197
to change if we ever have to shave off every last byte for a given
1198
target.
1199
1200
1201
 
1202
If thread debugging features are enabled, the function for accessing
1203
the thread information gets registered in the table during startup of
1204
a RAM startup configuration.
1205
1206
 
1207
Further implementation details are described where the service itself
1208
is described.
1209
 
1210
1214
 
1215
1216
 
1217
1218
1219
 
1220
1221
New Platform Ports
1222
 
1223
The hal_platform_init() function must call
1224
hal_if_init().
1225
1226
 
1227
The HAL serial driver must, when called via
1228
cyg_hal_plf_comms_init() must initialize the
1229
communication channels.
1230
1231
 
1232
The reset() function defined in
1233
hal_if.c will attempt to do a hardware reset, but
1234
if this fails it will fall back to simply jumping to the reset
1235
entry-point. On most platforms the startup initialization will go a
1236
long way to reset the target to a sane state (there will be
1237
exceptions, of course). For this reason, make sure to define
1238
HAL_STUB_PLATFORM_RESET_ENTRY in plf_stub.h.
1239
1240
 
1241
All debugging features must be in place in order for the debugging
1242
services to be functional. See general platform porting notes.
1243
1244
 
1245
1246
 
1247
1248
1249
 
1250
1251
New architecture ports
1252
 
1253
There are no specific requirements for a new architecture port in
1254
order to support the calling interface, but the basic debugging
1255
features must be in place. See general architecture porting notes.
1256
1257
1258
 
1259
1260
 
1261
1262
 
1263
1264
1265
 
1266
1267
IO channels
1268
 
1269
 
1270
The calling interface provides procedure tables for all IO channels on
1271
the platform. These are used for console (diagnostic) and debugger IO,
1272
allowing a ROM monitor to provided all the needed IO routines. At
1273
the same time, this makes it easy to switch console/debugger channels
1274
at run-time (the old implementation had hardwired drivers for console
1275
and debugger IO, preventing these to change at run-time).
1276
1277
 
1278
The hal_if provides wrappers which interface these services to the
1279
eCos infrastructure diagnostics routines. This is done in a way which
1280
ensures proper string mangling of the diagnostics output when required
1281
(e.g. O-packetization when using a GDB compatible ROM monitor).
1282
1283
 
1284
1285
 
1286
1287
Available Procedures
1288
 
1289
This is a brief description of the procedures
1290
 
1291
1292
CH_DATA
1293
Pointer to the controller IO base (or a pointer to a per-device
1294
    structure if more data than the IO base is required). All the
1295
    procedures below are called with this data item as the first
1296
    argument.
1297
 
1298
WRITE
1299
        Writes the buffer to the device.
1300
READ
1301
        Fills a buffer from the device.
1302
PUTC
1303
        Write a character to the device.
1304
GETC
1305
        Read a character from the device.
1306
CONTROL
1307
        Device feature control. Second argument specifies function:
1308
  
1309
    SETBAUD
1310
        Changes baud rate.
1311
    GETBAUD
1312
        Returns the current baud rate.
1313
    INSTALL_DBG_ISR
1314
        [Unused]
1315
    REMOVE_DBG_ISR
1316
        [Unused]
1317
    IRQ_DISABLE
1318
        Disable debugging receive interrupts on the device.
1319
    IRQ_ENABLE
1320
        Enable debugging receive interrupts on the device.
1321
    DBG_ISR_VECTOR
1322
        Returns the ISR vector used by the device for debugging
1323
        receive interrupts.
1324
    SET_TIMEOUT
1325
        Set GETC timeout in milliseconds.
1326
    FLUSH_OUTPUT
1327
        Forces driver to flush data in its buffers. Note
1328
            that this may not affect hardware buffers
1329
        (e.g. FIFOs).
1330
   
1331
   
1332
 
1333
DBG_ISR
1334
        ISR used to handle receive interrupts from the
1335
        device (see ).
1336
GETC_TIMEOUT
1337
        Read a character from the device with timeout.
1338
1339
 
1340
1341
 
1342
1343
1344
 
1345
Usage
1346
 
1347
The standard eCos diagnostics IO functions use the channel
1348
procedure table when CYGSEM_HAL_VIRTUAL_VECTOR_DIAG is enabled. That
1349
means that when you use diag_printf (or the libc printf function) the
1350
stream goes through the selected console procedure table. If you use
1351
the virtual vector function SET_CONSOLE_COMM you can change the device
1352
which the diagnostics output goes to at run-time.
1353
 
1354
You can also use the table functions directly if desired
1355
(regardless of the CYGSEM_HAL_VIRTUAL_VECTOR_DIAG setting - assuming
1356
the ROM monitor provides the services). Here is a small example which
1357
changes the console to use channel 2, fetches the comm procs pointer
1358
and calls the write function from that table, then restores the
1359
console to the original channel:
1360
 
1361
1362
#define T "Hello World!\n"
1363
 
1364
int
1365
main(void)
1366
{
1367
    hal_virtual_comm_table_t* comm;
1368
    int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
1369
 
1370
    CYGACC_CALL_IF_SET_CONSOLE_COMM(2);
1371
 
1372
    comm = CYGACC_CALL_IF_CONSOLE_PROCS();
1373
    CYGACC_COMM_IF_WRITE(*comm, T, strlen(T));
1374
 
1375
    CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);
1376
}
1377
1378
 
1379
Beware that if doing something like the above, you should only do
1380
it to a channel which does not have GDB at the other end: GDB ignores
1381
raw data, so you would not see the output.
1382
 
1383
1384
 
1385
1386
1387
 
1388
1389
Compatibility
1390
 
1391
The use of this service is controlled by the option
1392
CYGSEM_HAL_VIRTUAL_VECTOR_DIAG which is disabled per default on most
1393
older platforms (thus preserving backwards compatibility with older
1394
stubs). On newer ports, this option should always be set.
1395
1396
1397
 
1398
1399
1400
 
1401
Implementation Details
1402
 
1403
There is an array of procedure tables (raw comm channels) for each
1404
IO device of the platform which get initialized by the ROM monitor, or
1405
optionally by a RAM startup configuration (allowing the RAM
1406
configuration to take full control of the target).  In addition to
1407
this, there's a special table which is used to hold mangler
1408
procedures.
1409
 
1410
The vector table defines which of these channels are selected for
1411
console and debugging IO respectively: console entry can be empty,
1412
point to mangler channel, or point to a raw channel. The debugger
1413
entry should always point to a raw channel.
1414
 
1415
During normal console output (i.e., diagnostic output) the console
1416
table will be used to handle IO if defined. If not defined, the debug
1417
table will be used.
1418
 
1419
This means that debuggers (such as GDB) which require text streams
1420
to be mangled (O-packetized in the case of GDB), can rely on the ROM
1421
monitor install mangling IO routines in the special mangler table and
1422
select this for console output. The mangler will pass the mangled data
1423
on to the selected debugging channel.
1424
 
1425
If the eCos configuration specifies a different console channel
1426
from that used by the debugger, the console entry will point to the
1427
selected raw channel, thus overriding any mangler provided by the ROM
1428
monitor.
1429
 
1430
See hal_if_diag_* routines in hal_if.c for more details of the stream
1431
path of diagnostic output. See cyg_hal_gdb_diag_*() routines in
1432
hal_stub.c for the mangler used for GDB communication.
1433
 
1434
1437
 
1438
1439
 
1440
1441
1442
 
1443
1444
New Platform Ports
1445
 
1446
Define CDL options CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS,
1447
CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL, and
1448
CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL.
1449
1450
 
1451
If CYGSEM_HAL_VIRTUAL_VECTOR_DIAG is set, make sure the infra diag
1452
code uses the hal_if diag functions:
1453
 
1454
1455
 #define HAL_DIAG_INIT() hal_if_diag_init()
1456
 #define HAL_DIAG_WRITE_CHAR(_c_) hal_if_diag_write_char(_c_)
1457
 #define HAL_DIAG_READ_CHAR(_c_) hal_if_diag_read_char(&_c_)
1458
1459
 
1460
In addition to the above functions, the platform HAL must also
1461
provide a function cyg_hal_plf_comms_init which initializes the
1462
drivers and the channel procedure tables.
1463
1464
 
1465
Most of the other functionality in the table is more or less
1466
possible to copy unchanged from existing ports. Some care is necessary
1467
though to ensure the proper handling of interrupt vectors and timeouts
1468
for various devices handled by the same driver. See PowerPC/Cogent
1469
platform HAL for an example implementation.
1470
 
1471
1472
Note:
1473
 When vector table console code is not used,
1474
the platform HAL must map the HAL_DIAG_INIT, HAL_DIAG_WRITE_CHAR and
1475
HAL_DIAG_READ_CHAR macros directly to the low-level IO functions,
1476
hardwired to use a compile-time configured channel.
1477
1478
 
1479
1480
Note:
1481
 On old ports the hardwired HAL_DIAG_INIT,
1482
HAL_DIAG_WRITE_CHAR and
1483
HAL_DIAG_READ_CHAR implementations will also
1484
contain code to O-packetize the output for GDB. This should
1485
not be adopted for new ports! On new ports the
1486
ROM monitor is guaranteed to provide the necessary mangling via the
1487
vector table. The hardwired configuration should be reserved for ROM
1488
startups where achieving minimal image size is crucial.
1489
1490
1491
 
1492
1493
 
1494
1495
 
1496
1497
 
1498
1499
 
1500
 
1501
1502
 
1503
1504
1505
 
1506
1507
HAL Coding Conventions
1508
 
1509
 
1510
1511
To get changes and larger submissions included into the eCos source
1512
repository, we ask that you adhere to a set of coding conventions.
1513
The conventions are defined as an attempt to make a consistent
1514
tree. Consistency makes it easier for people to read, understand and
1515
maintain the code, which is important when many people work on the
1516
same project.
1517
1518
 
1519
1520
The below is only a brief, and probably incomplete, summary of the
1521
rules. Please look through files in the area where you are making
1522
changes to get a feel for any additional conventions. Also feel free
1523
to ask on the list if you have specific questions.
1524
1525
 
1526
 
1527
1528
Implementation issues
1529
 
1530
1531
There are a few implementation issues that should be kept in mind:
1532
1533
 
1534
1535
HALs
1536
        HALs must be written in C and assembly only. C++ must not
1537
        be used. This is in part to keep the HALs simple since this is
1538
        usually the first part of eCos a newcomer will see, and in
1539
        part to maintain the existing de facto standard.
1540
 
1541
IO access
1542
        Use HAL IO access macros for code that might be reused on
1543
        different platforms than the one you are writing it for.
1544
 
1545
MMU
1546
        If it is necessary to use the MMU (e.g., to prevent
1547
        caching of IO areas), use a simple 1-1 mapping of memory if
1548
        possible. On most platforms where using the MMU is necessary,
1549
        it will be possible to achieve the 1-1 mapping using the MMU's
1550
        provision for mapping large continuous areas (hardwired TLBs or
1551
        BATs). This reduces the footprint (no MMU table) and avoids
1552
        execution overhead (no MMU-related exceptions).
1553
 
1554
Assertions
1555
        The code should contain assertions to validate argument
1556
        values, state information and any assumptions the code may be
1557
        making. Assertions are not enabled in production builds, so
1558
        liberally sprinkling assertions throughout the code is
1559
        good.
1560
 
1561
Testing
1562
        The ability to test your code is very important. In
1563
        general, do not add new code to the eCos runtime unless you
1564
        also add a new test to exercise that code. The test also
1565
        serves as an example of how to use the new code.
1566
 
1567
1568
 
1569
1570
 
1571
1572
Source code details
1573
 
1574
1575
Line length
1576
        Keep line length below 78 columns whenever possible.
1577
 
1578
Comments
1579
        Whenever possible, use // comments instead of /**/.
1580
 
1581
Indentation
1582
        Use spaces instead of TABs. Indentation level is 4. Braces
1583
        start on the same line as the expression. See below for emacs
1584
        mode details.
1585
 
1586
1587
;;=================================================================
1588
;; eCos C/C++ mode Setup.
1589
;;
1590
;; bsd mode: indent = 4
1591
;; tail comments are at col 40.
1592
;; uses spaces not tabs in C
1593
 
1594
(defun ecos-c-mode ()
1595
  "C mode with adjusted defaults for use with the eCos sources."
1596
  (interactive)
1597
  (c++-mode)
1598
  (c-set-style "bsd")
1599
  (setq comment-column 40)
1600
  (setq indent-tabs-mode nil)
1601
  (show-paren-mode 1)
1602
  (setq c-basic-offset 4)
1603
 
1604
  (set-variable 'add-log-full-name "Your Name")
1605
  (set-variable 'add-log-mailing-address "Your email address"))
1606
 
1607
(defun ecos-asm-mode ()
1608
  "ASM mode with adjusted defaults for use with the eCos sources."
1609
  (interactive)
1610
  (setq comment-column 40)
1611
  (setq indent-tabs-mode nil)
1612
  (asm-mode)
1613
  (setq c-basic-offset 4)
1614
 
1615
  (set-variable 'add-log-full-name "Your Name")
1616
  (set-variable 'add-log-mailing-address "Your email address"))
1617
 
1618
(setq auto-mode-alist
1619
      (append '(("/local/ecc/.*\\.C$"   . ecos-c-mode)
1620
                ("/local/ecc/.*\\.cc$"  . ecos-c-mode)
1621
                ("/local/ecc/.*\\.cpp$" . ecos-c-mode)
1622
                ("/local/ecc/.*\\.inl$" . ecos-c-mode)
1623
                ("/local/ecc/.*\\.c$"   . ecos-c-mode)
1624
                ("/local/ecc/.*\\.h$"   . ecos-c-mode)
1625
                ("/local/ecc/.*\\.S$"   . ecos-asm-mode)
1626
                ("/local/ecc/.*\\.inc$" . ecos-asm-mode)
1627
                ("/local/ecc/.*\\.cdl$" . tcl-mode)
1628
                ) auto-mode-alist))
1629
1630
1631
1632
1633
1634
 
1635
1636
 
1637
Nested Headers
1638
 
1639
In order to allow platforms to define all necessary details, while
1640
still maintaining the ability to share code between common platforms,
1641
all HAL headers are included in a nested fashion.
1642
 
1643
The architecture header (usually hal_XXX.h) includes the
1644
variant equivalent of the header (var_XXX.h) which in turn
1645
includes the platform equivalent of the header
1646
(plf_XXX.h).
1647
 
1648
All definitions that may need to be overridden by a platform are
1649
then only conditionally defined, depending on whether a lower layer
1650
has already made the definition:
1651
 
1652
1653
hal_intr.h:     #include <var_intr.h>
1654
 
1655
                #ifndef MACRO_DEFINED
1656
                # define MACRO ...
1657
                # define MACRO_DEFINED
1658
                #endif
1659
 
1660
 
1661
 
1662
var_intr.h:     #include <plf_intr.h>
1663
 
1664
                #ifndef MACRO_DEFINED
1665
                # define MACRO ...
1666
                # define MACRO_DEFINED
1667
                #endif
1668
 
1669
 
1670
plf_intr.h:
1671
 
1672
                # define MACRO ...
1673
                # define MACRO_DEFINED
1674
1675
 
1676
This means a platform can opt to rely on the variant or
1677
architecture implementation of a feature, or implement it itself.
1678
 
1679
1680
 
1681
1682
 
1683
1684
1685
 
1686
1687
Platform HAL Porting
1688
 
1689
1690
This is the type of port that takes the least effort. It basically
1691
consists of describing the platform (board) for the HAL: memory
1692
layout, early platform initialization, interrupt controllers, and a
1693
simple serial device driver.
1694
1695
 
1696
1697
Doing a platform port requires a preexisting architecture and
1698
possibly a variant HAL port.
1699
1700
 
1701
1702
 
1703
1704
HAL Platform Porting Process
1705
 
1706
1707
 
1708
1709
Brief overview
1710
 
1711
The easiest way to make a new platform HAL is simply to copy an
1712
existing platform HAL of the same architecture/variant and change all
1713
the files to match the new one. In case this is the first platform for
1714
the architecture/variant, a platform HAL from another architecture
1715
should be used as a template.
1716
1717
 
1718
1719
The best way to start a platform port is to concentrate on getting
1720
RedBoot to run. RedBoot is a simpler environment than full eCos, it
1721
does not use interrupts or threads, but covers most of the
1722
basic startup requirements.
1723
1724
 
1725
1726
RedBoot normally runs out of FLASH or ROM and provides program loading
1727
and debugging facilities.  This allows further HAL development to
1728
happen using RAM startup configurations, which is desirable for the
1729
simple reason that downloading an image which you need to test is
1730
often many times faster than either updating a flash part, or indeed,
1731
erasing and reprogramming an EPROM.
1732
1733
 
1734
There are two approaches to getting to this first goal:
1735
1736
 
1737
1738
1739
1740
The board is equipped with a ROM monitor which allows "load and go" of
1741
ELF, binary, S-record or some other image type which can be created
1742
using objcopy. This allows you to develop
1743
RedBoot by downloading and running the code (saving time).
1744
1745
 
1746
1747
When the stub is running it is a good idea to examine the various
1748
hardware registers to help you write the platform initialization code.
1749
1750
 
1751
1752
Then you may have to fiddle a bit going through step two (getting it
1753
to run from ROM startup). If at all possible, preserve the original
1754
ROM monitor so you can revert to it if necessary.
1755
1756
1757
 
1758
1759
1760
The board has no ROM monitor. You need to get the platform
1761
initialization and stub working by repeatedly making changes, updating
1762
flash or EPROM and testing the changes. If you are lucky, you have a
1763
JTAG or similar CPU debugger to help you. If not, you will probably
1764
learn to appreciate LEDs. This approach may also be needed during the
1765
initial phase of moving RedBoot from RAM startup to ROM, since it is
1766
very unlikely to work first time.
1767
1768
1769
1770
 
1771
1772
 
1773
1774
1775
 
1776
1777
Step-by-step
1778
 
1779
Given that no two platforms are exactly the same, you may have to
1780
deviate from the below. Also, you should expect a fair amount of
1781
fiddling - things almost never go right the first time. See the hints
1782
section below for some suggestions that might help debugging.
1783
1784
 
1785
The description below is based on the HAL layout used in the MIPS,
1786
PC and MN10300 HALs. Eventually all HALs should be converted to look like
1787
these - but in a transition period there will be other HALs which look
1788
substantially different. Please try to adhere to the following as much is
1789
possible without causing yourself too much grief integrating with a
1790
HAL which does not follow this layout.
1791
1792
 
1793
1794
 
1795
1796
Minimal requirements
1797
 
1798
1799
These are the changes you must make before you attempt to build
1800
RedBoot. You are advised to read all the sources though.
1801
1802
 
1803
1804
Copy an existing platform HAL from the same or another
1805
    architecture. Rename the files as necessary to follow the
1806
    standard: CDL and MLT related files should contain the
1807
    <arch>_<variant>_<platform> triplet.
1808
1809
 
1810
Adjust CDL options. Primarily option naming, real-time
1811
    clock/counter, and CYGHWR_MEMORY_LAYOUT variables, but also other
1812
    options may need editing. Look through the architecture/variant
1813
    CDL files to see if there are any requirements/features which
1814
    where not used on the platform you copied. If so, add appropriate
1815
    ones. See  for more
1816
    details.
1817
1818
 
1819
Add the necessary packages and target descriptions to the
1820
    top-level ecos.db file. See 
1821
    linkend="hal-porting-ecos-database">. Initially, the target entry
1822
    should only contain the HAL packages. Other hardware support
1823
    packages will be added later.
1824
1825
 
1826
Adjust the MLT files in
1827
    include/pkgconf to match the memory layout on
1828
    the platform. For initial testing it should be enough to just hand
1829
    edit .h and .ldi files, but eventually you should generate all
1830
    files using the memory layout editor in the configuration
1831
    tool. See  for
1832
    more details.
1833
1834
 
1835
1836
    
1837
    Edit the misc/redboot_<STARTUP>.ecm for
1838
    the startup type you have chosen to begin with. Rename any
1839
    platform specific options and remove any that do not apply. In the
1840
    cdl_configuration section, comment out any
1841
    extra packages that are added, particularly packages such as
1842
    CYGPKG_IO_FLASH and
1843
    CYGPKG_IO_ETH_DRIVERS. These are not needed for
1844
    initial porting and will be added back later.
1845
    
1846
1847
 
1848
If the default IO macros are not correct, override them in
1849
    plf_io.h. This may be necessary if the platform uses a different
1850
    endianness from the default for the CPU.
1851
1852
 
1853
Leave out/comment out code that enables caches and/or MMU if
1854
    possible. Execution speed will not be a concern until the port is
1855
    feature complete.
1856
1857
 
1858
Implement a simple serial driver (polled mode only). Make sure the
1859
    initialization function properly hooks the procedures up in the
1860
    virtual vector IO channel tables. RedBoot will call the serial
1861
    driver via these tables.
1862
    
1863
    By copying an existing platform HAL most of this code will be
1864
    already done, and will only need the platform specific hardware
1865
    access code to be written.
1866
    
1867
1868
 
1869
Adjust/implement necessary platform
1870
    initialization. This can be found in
1871
    platform.inc and
1872
    platform.S files (ARM:
1873
    hal_platform_setup.h and
1874
    <platform>_misc.c, PowerPC:
1875
    <platform>.S). This step can be
1876
    postponed if you are doing a RAM startup RedBoot first and the
1877
    existing ROM monitor handles board initialization.
1878
1879
 
1880
Define HAL_STUB_PLATFORM_RESET
1881
    (optionally empty) and
1882
    HAL_STUB_PLATFORM_RESET_ENTRY so that RedBoot
1883
    can reset-on-detach - this is very handy, often removing the need
1884
    for physically resetting the board between downloads.
1885
1886
 
1887
1888
 
1889
You should now be able to build RedBoot. For ROM startup:
1890
1891
 
1892
1893
% ecosconfig new <target_name> redboot
1894
% ecosconfig import $(ECOS_REPOSITORY)/hal/<architecture>/<platform>/<version>/misc/redboot_ROM.ecm
1895
% ecosconfig tree
1896
% make
1897
1898
 
1899
You may have to make further changes than suggested above to get
1900
the make command to succeed. But when it does, you should find a
1901
RedBoot image in install/bin. To program this image into flash or
1902
EPROM, you may need to convert to some other file type, and possibly
1903
adjust the start address. When you have the correct
1904
objcopy command to do this, add it to the
1905
CYGBLD_BUILD_GDB_STUBS custom build rule in the
1906
platform CDL file.
1907
1908
 
1909
Having updated the flash/EPROM on the board, you should see output
1910
on the serial port looking like this when powering on the board:
1911
1912
 
1913
1914
RedBoot(tm) bootstrap and debug environment [ROMRAM]
1915
Non-certified release, version UNKNOWN - built 15:42:24, Mar 14 2002
1916
 
1917
Platform: <PLATFORM> (<ARCHITECTURE> <VARIANT>)
1918
Copyright (C) 2000, 2001, 2002, Red Hat, Inc.
1919
 
1920
RAM: 0x00000000-0x01000000, 0x000293e8-0x00ed1000 available
1921
FLASH: 0x24000000 - 0x26000000, 256 blocks of 0x00020000 bytes each.
1922
RedBoot>
1923
1924
 
1925
If you do not see this output, you need to go through all your
1926
changes and figure out what's wrong. If there's a user programmable
1927
LED or LCD on the board it may help you figure out how far RedBoot
1928
gets before it hangs. Unfortunately there's no good way to describe
1929
what to do in this situation - other than that you have to play with
1930
the code and the board.
1931
1932
 
1933
1934
 
1935
1936
 
1937
1938
Adding features
1939
 
1940
Now you should have a basic RedBoot running on the board. This
1941
means you have a the correct board initialization and a working serial
1942
driver. It's time to flesh out the remaining HAL features.
1943
1944
 
1945
1946
Reset. As mentioned above it is desirable to get the board to
1947
reset when GDB disconnects. When GDB disconnects it sends RedBoot
1948
a kill-packet, and RedBoot first calls HAL_STUB_PLATFORM_RESET(),
1949
attempting to perform a software-invoked reset. Most embedded
1950
CPUs/boards have a watchdog which is capable of triggering a reset.
1951
If your target does not have a watchdog, leave
1952
HAL_STUB_PLATFORM_RESET() empty and rely on the fallback approach.
1953
1954
 
1955
If HAL_STUB_PLATFORM_RESET() did not cause a reset, RedBoot will
1956
jump to HAL_STUB_PLATFORM_RESET_ENTRY - this should be the address
1957
where the CPU will start execution after a reset. Re-initializing the
1958
board and drivers will usually be good enough to make a
1959
hardware reset unnecessary.
1960
1961
 
1962
After the reset caused by the kill-packet, the target will be ready
1963
for GDB to connect again. During a days work, this will save you from
1964
pressing the reset button many times.
1965
1966
 
1967
Note that it is possible to disconnect from the board without
1968
causing it to reset by using the GDB command "detach".
1969
1970
 
1971
1972
Single-stepping is necessary for both instruction-level debugging
1973
and for breakpoint support. Single-stepping support should already be
1974
in place as part of the architecture/variant HAL, but you want to give
1975
it a quick test since you will come to rely on it.
1976
1977
 
1978
1979
Real-time clock interrupts drive the eCos scheduler clock. Many
1980
embedded CPUs have an on-core timer (e.g. SH) or decrementer
1981
(e.g. MIPS, PPC) that can be used, and in this case it will already be
1982
supported by the architecture/variant HAL. You only have to calculate
1983
and enter the proper CYGNUM_HAL_RTC_CONSTANTS
1984
definitions in the platform CDL file.
1985
1986
 
1987
On some targets it may be necessary to use a platform-specific
1988
timer source for driving the real-time clock. In this case you also
1989
have to enter the proper CDL definitions, but must also define
1990
suitable versions of the HAL_CLOCK_XXXX macros.
1991
1992
 
1993
1994
Interrupt decoding usually differs between platforms because the
1995
number and type of devices on the board differ. In
1996
plf_intr.h (ARM:
1997
hal_platform_ints.h) you must either extend or
1998
replace the default vector definitions provided by the architecture
1999
or variant interrupt headers. You may also have to define
2000
HAL_INTERRUPT_XXXX control macros.
2001
2002
 
2003
2004
Caching may also differ from architecture/variant definitions.
2005
This maybe just the cache sizes, but there can also be bigger
2006
differences for example if the platform supports 2nd level caches.
2007
2008
 
2009
When cache definitions are in place, enable the caches on
2010
startup. First verify that the system is stable for RAM startups, then
2011
build a new RedBoot and install it. This will test if caching, and in
2012
particular the cache sync/flush operations, also work for ROM startup.
2013
2014
 
2015
2016
Asynchronous breakpoints allow you to stop application execution
2017
and enter the debugger. Asynchronous breakpoint details are described
2018
in .
2019
2020
 
2021
2022
 
2023
You should now have a completed platform HAL port. Verify its
2024
stability and completeness by running all the eCos tests and fix any
2025
problems that show up (you have a working RedBoot now, remember! That
2026
means you can debug the code to see why it fails).
2027
2028
 
2029
Given the many configuration options in eCos, there may be hidden
2030
bugs or missing features that do not show up even if you run all the
2031
tests successfully with a default configuration. A comprehensive test
2032
of the entire system will take many configuration permutations and
2033
many many thousands of tests executed.
2034
2035
 
2036
2037
 
2038
2039
 
2040
2041
2042
 
2043
2044
Hints
2045
 
2046
2047
 
2048
2049
    JTAG or similar CPU debugging hardware can greatly reduce the time
2050
    it takes to write a HAL port since you always have full visibility
2051
    of what the CPU is doing.
2052
    
2053
2054
 
2055
2056
    LEDs can be your friends if you don't have a JTAG
2057
    device. Especially in the start of the porting effort if you don't
2058
    already have a working ROM monitor on the target. Then you have to
2059
    get a basic RedBoot working while basically being blindfolded. The
2060
    LED can make it little easier, as you'll be able to do limited
2061
    tracking of program flow and behavior by switching the LED on and
2062
    off. If the board has multiple LEDs you can show a number (using
2063
    binary notation with the LEDs) and sprinkle code which sets
2064
    different numbers throughout the code.
2065
2066
 
2067
2068
    Debugging the interrupt processing is possible if you are
2069
    careful with the way you program the very early interrupt entry
2070
    handling. Write it so that as soon as possible in the interrupt
2071
    path, taking a trap (exception) does not harm execution. See the
2072
    SH vectors.S code for an example. Look for
2073
    cyg_hal_default_interrupt_vsr and the label
2074
    cyg_hal_default_interrupt_vsr_bp_safe, which
2075
    marks the point after which traps/single-stepping is safe.
2076
    
2077
 
2078
    Being able to display memory content, CPU registers,
2079
    interrupt controller details at the time of an interrupt can save
2080
    a lot of time.
2081
2082
 
2083
2084
    Using assertions is a good idea. They can sometimes reveal subtle
2085
    bugs or missing features long before you would otherwise have
2086
    found them, let alone notice them.
2087
    
2088
 
2089
    The default eCos configuration does not use assertions, so you
2090
    have to enable them by switching on the option CYGPKG_INFRA_DEBUG
2091
    in the infra package.
2092
2093
 
2094
2095
    The idle loop can be used to help debug the system.
2096
    
2097
 
2098
    Triggering clock from the idle loop is a neat trick for
2099
    examining system behavior either before interrupts are fully
2100
    working, or to speed up "the clock".
2101
    
2102
 
2103
    Use the idle loop to monitor and/or print out variables or
2104
    hardware registers.
2105
2106
 
2107
2108
hal_mk_defs is used in some of the
2109
HALs (ARM, SH) as a way to generate assembler symbol definitions from
2110
C header files without imposing an assembler/C syntax separation in
2111
the C header files.
2112
2113
 
2114
2118
 
2119
2120
 
2121
2122
 
2123
2124
 
2125
2126
 
2127
2128
2129
 
2130
2131
HAL Platform CDL
2132
 
2133
The platform CDL both contains details necessary for the building
2134
of eCos, and platform-specific configuration options. For this reason
2135
the options differ between platforms, and the below is just a brief
2136
description of the most common options.
2137
 
2138
 See  Components Writers Guide
2139
for more details on CDL. Also have a quick look around in
2140
existing platform CDL files to get an idea of what is possible and how
2141
various configuration issues can be represented with CDL.
2142
 
2143
2144
 
2145
2146
eCos Database
2147
 
2148
2149
The eCos configuration system is made aware of a package by
2150
adding a package description in ecos.db. As an
2151
example we use the TX39/JMR3904 platform:
2152
2153
 
2154
2155
package CYGPKG_HAL_MIPS_TX39_JMR3904 {
2156
        alias           { "Toshiba JMR-TX3904 board" hal_tx39_jmr3904 tx39_jmr3904_hal }
2157
        directory       hal/mips/jmr3904
2158
        script          hal_mips_tx39_jmr3904.cdl
2159
        hardware
2160
        description "
2161
           The JMR3904 HAL package should be used when targeting the
2162
           actual hardware. The same package can also be used when
2163
           running on the full simulator, since this provides an
2164
           accurate simulation of the hardware including I/O devices.
2165
           To use the simulator in this mode the command
2166
           `target sim --board=jmr3904' should be used from inside gdb."
2167
}
2168
2169
 
2170
This contains the title and description presented in the
2171
Configuration Tool when the package is selected. It also specifies
2172
where in the tree the package files can be found (directory)
2173
and the name of the CDL file which contains the package details
2174
(script).
2175
2176
 
2177
2178
To be able to build and test a configuration for the new target, there
2179
also needs to be a target entry in the
2180
ecos.db file.
2181
2182
 
2183
2184
target jmr3904 {
2185
        alias           { "Toshiba JMR-TX3904 board" jmr tx39 }
2186
        packages        { CYGPKG_HAL_MIPS
2187
                          CYGPKG_HAL_MIPS_TX39
2188
                          CYGPKG_HAL_MIPS_TX39_JMR3904
2189
        }
2190
        description "
2191
           The jmr3904 target provides the packages needed to run
2192
           eCos on a Toshiba JMR-TX3904 board. This target can also
2193
           be used when running in the full simulator, since the simulator provides an
2194
           accurate simulation of the hardware including I/O devices.
2195
           To use the simulator in this mode the command
2196
           `target sim --board=jmr3904' should be used from inside gdb."
2197
}
2198
2199
 
2200
 
2201
2202
The important part here is the packages section
2203
which defines the various hardware specific packages that contribute
2204
to support for this target. In this case the MIPS architecture
2205
package, the TX39 variant package, and the JMR-TX3904 platform
2206
packages are selected. Other packages, for serial drivers, ethernet
2207
drivers and FLASH memory drivers may also appear here.
2208
2209
 
2210
2211
 
2212
2213
2214
 
2215
2216
CDL File Layout
2217
 
2218
2219
All the platform options are contained in a CDL package named
2220
CYGPKG_HAL_<architecture>_<variant>_<platform>.
2221
They all share more or less the same cdl_package
2222
details:
2223
2224
 
2225
2226
cdl_package CYGPKG_HAL_MIPS_TX39_JMR3904 {
2227
    display       "JMR3904 evaluation board"
2228
    parent        CYGPKG_HAL_MIPS
2229
    requires      CYGPKG_HAL_MIPS_TX39
2230
    define_header hal_mips_tx39_jmr3904.h
2231
    include_dir   cyg/hal
2232
    description   "
2233
           The JMR3904 HAL package should be used when targeting the
2234
           actual hardware. The same package can also be used when
2235
           running on the full simulator, since this provides an
2236
           accurate simulation of the hardware including I/O devices.
2237
           To use the simulator in this mode the command
2238
           `target sim --board=jmr3904' should be used from inside gdb."
2239
 
2240
    compile       platform.S plf_misc.c plf_stub.c
2241
 
2242
    define_proc {
2243
        puts $::cdl_system_header "#define CYGBLD_HAL_TARGET_H   <pkgconf/hal_mips_tx39.h>"
2244
        puts $::cdl_system_header "#define CYGBLD_HAL_PLATFORM_H <pkgconf/hal_mips_tx39_jmr3904.h>"
2245
    }
2246
 
2247
    ...
2248
}
2249
2250
 
2251
This specifies that the platform package should be parented under
2252
the MIPS packages, requires the TX39 variant HAL and all configuration
2253
settings should be saved in
2254
cyg/hal/hal_mips_tx39_jmt3904.h.
2255
2256
 
2257
The compile line specifies which files should be built
2258
when this package is enabled, and the define_proc defines
2259
some macros that are used to access the variant or architecture (the
2260
_TARGET_ name is a bit of a misnomer) and platform
2261
configuration options. 
2262
 
2263
2264
 
2265
2266
2267
 
2268
2269
Startup Type
2270
 
2271
eCos uses an option to select between a set of valid startup
2272
configurations. These are normally RAM, ROM and possibly ROMRAM. This
2273
setting is used to select which linker map to use (i.e., where to link
2274
eCos and the application in the memory space), and how the startup
2275
code should behave.
2276
 
2277
2278
cdl_component CYG_HAL_STARTUP {
2279
    display       "Startup type"
2280
    flavor        data
2281
    legal_values  {"RAM" "ROM"}
2282
    default_value {"RAM"}
2283
        no_define
2284
        define -file system.h CYG_HAL_STARTUP
2285
    description   "
2286
       When targeting the JMR3904 board it is possible to build
2287
       the system for either RAM bootstrap, ROM bootstrap, or STUB
2288
       bootstrap. RAM bootstrap generally requires that the board
2289
       is equipped with ROMs containing a suitable ROM monitor or
2290
       equivalent software that allows GDB to download the eCos
2291
       application on to the board. The ROM bootstrap typically
2292
       requires that the eCos application be blown into EPROMs or
2293
       equivalent technology."
2294
}
2295
2296
 
2297
The no_define and define
2298
pair is used to make the setting of this option appear in the file
2299
system.h instead of the default specified in the
2300
header.
2301
 
2302
2303
 
2304
2305
2306
 
2307
2308
Build options
2309
 
2310
2311
A set of options under the components
2312
CYGBLD_GLOBAL_OPTIONS and
2313
CYGHWR_MEMORY_LAYOUT specify how eCos should be
2314
built: what tools and compiler options should be used, and which
2315
linker fragments should be used.
2316
2317
 
2318
2319
 
2320
cdl_component CYGBLD_GLOBAL_OPTIONS {
2321
    display "Global build options"
2322
    flavor  none
2323
    parent  CYGPKG_NONE
2324
    description   "
2325
            Global build options including control over
2326
            compiler flags, linker flags and choice of toolchain."
2327
 
2328
 
2329
    cdl_option CYGBLD_GLOBAL_COMMAND_PREFIX {
2330
        display "Global command prefix"
2331
        flavor  data
2332
        no_define
2333
        default_value { "mips-tx39-elf" }
2334
        description "
2335
            This option specifies the command prefix used when
2336
            invoking the build tools."
2337
    }
2338
 
2339
    cdl_option CYGBLD_GLOBAL_CFLAGS {
2340
        display "Global compiler flags"
2341
        flavor  data
2342
        no_define
2343
        default_value { "-Wall -Wpointer-arith -Wstrict-prototypes -Winline -Wundef -Woverloaded-virtual -g -O2 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fvtable-gc -finit-priority" }
2344
        description   "
2345
            This option controls the global compiler flags which
2346
            are used to compile all packages by
2347
            default. Individual packages may define
2348
            options which override these global flags."
2349
    }
2350
 
2351
    cdl_option CYGBLD_GLOBAL_LDFLAGS {
2352
        display "Global linker flags"
2353
        flavor  data
2354
        no_define
2355
        default_value { "-g -nostdlib -Wl,--gc-sections -Wl,-static" }
2356
        description   "
2357
            This option controls the global linker flags. Individual
2358
            packages may define options which override these global flags."
2359
    }
2360
}
2361
 
2362
cdl_component CYGHWR_MEMORY_LAYOUT {
2363
    display "Memory layout"
2364
    flavor data
2365
    no_define
2366
    calculated { CYG_HAL_STARTUP == "RAM" ? "mips_tx39_jmr3904_ram" : \
2367
                                            "mips_tx39_jmr3904_rom" }
2368
 
2369
    cdl_option CYGHWR_MEMORY_LAYOUT_LDI {
2370
        display "Memory layout linker script fragment"
2371
        flavor data
2372
        no_define
2373
        define -file system.h CYGHWR_MEMORY_LAYOUT_LDI
2374
        calculated { CYG_HAL_STARTUP == "RAM" ? "<pkgconf/mlt_mips_tx39_jmr3904_ram.ldi>" : \
2375
                                                "<pkgconf/mlt_mips_tx39_jmr3904_rom.ldi>" }
2376
    }
2377
 
2378
    cdl_option CYGHWR_MEMORY_LAYOUT_H {
2379
        display "Memory layout header file"
2380
        flavor data
2381
        no_define
2382
        define -file system.h CYGHWR_MEMORY_LAYOUT_H
2383
        calculated { CYG_HAL_STARTUP == "RAM" ? "<pkgconf/mlt_mips_tx39_jmr3904_ram.h>" : \
2384
                                                "<pkgconf/mlt_mips_tx39_jmr3904_rom.h>" }
2385
    }
2386
}
2387
 
2388
2389
 
2390
2391
 
2392
2393
2394
 
2395
2396
Common Target Options
2397
 
2398
All platforms also specify real-time clock details:
2399
 
2400
2401
# Real-time clock/counter specifics
2402
cdl_component CYGNUM_HAL_RTC_CONSTANTS {
2403
    display       "Real-time clock constants."
2404
    flavor        none
2405
 
2406
    cdl_option CYGNUM_HAL_RTC_NUMERATOR {
2407
        display       "Real-time clock numerator"
2408
        flavor        data
2409
        calculated    1000000000
2410
    }
2411
    cdl_option CYGNUM_HAL_RTC_DENOMINATOR {
2412
        display       "Real-time clock denominator"
2413
        flavor        data
2414
        calculated    100
2415
    }
2416
    # Isn't a nice way to handle freq requirement!
2417
    cdl_option CYGNUM_HAL_RTC_PERIOD {
2418
        display       "Real-time clock period"
2419
        flavor        data
2420
        legal_values  { 15360 20736 }
2421
        calculated     { CYGHWR_HAL_MIPS_CPU_FREQ == 50 ? 15360 : \
2422
                         CYGHWR_HAL_MIPS_CPU_FREQ == 66 ? 20736 : 0 }
2423
    }
2424
}
2425
2426
 
2427
 The NUMERATOR divided by the
2428
DENOMINATOR gives the number of nanoseconds per
2429
tick. The PERIOD is the divider to be programmed
2430
into a hardware timer that is driven from an appropriate hardware
2431
clock, such that the timer overflows once per tick (normally
2432
generating a CPU interrupt to mark the end of a tick). The tick
2433
default rate is typically 100Hz.
2434
 
2435
 
2436
Platforms that make use of the virtual vector
2437
ROM calling interface (see ) will also
2438
specify details necessary to define configuration channels (these
2439
options are from the SH/EDK7707 HAL) :
2440
 
2441
2442
cdl_option CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS {
2443
    display      "Number of communication channels on the board"
2444
    flavor       data
2445
    calculated   1
2446
}
2447
 
2448
cdl_option CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL {
2449
    display          "Debug serial port"
2450
    flavor data
2451
    legal_values     0 to CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS-1
2452
    default_value    0
2453
    description      "
2454
       The EDK/7708 board has only one serial port. This option
2455
       chooses which port will be used to connect to a host
2456
       running GDB."
2457
}
2458
 
2459
cdl_option CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL {
2460
    display          "Diagnostic serial port"
2461
    flavor data
2462
    legal_values     0 to CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS-1
2463
    default_value    0
2464
    description      "
2465
       The EDK/7708 board has only one serial port.  This option
2466
       chooses which port will be used for diagnostic output."
2467
}
2468
2469
 
2470
The platform usually also specify an option controlling the ability
2471
 to co-exist with a ROM monitor:
2472
 
2473
2474
cdl_option CYGSEM_HAL_USE_ROM_MONITOR {
2475
    display       "Work with a ROM monitor"
2476
    flavor        booldata
2477
    legal_values  { "Generic" "CygMon" "GDB_stubs" }
2478
    default_value { CYG_HAL_STARTUP == "RAM" ? "CygMon" : 0 }
2479
    parent        CYGPKG_HAL_ROM_MONITOR
2480
    requires      { CYG_HAL_STARTUP == "RAM" }
2481
    description   "
2482
        Support can be enabled for three different varieties of ROM monitor.
2483
        This support changes various eCos semantics such as the encoding
2484
        of diagnostic output, or the overriding of hardware interrupt
2485
        vectors.
2486
        Firstly there is \"Generic\" support which prevents the HAL
2487
        from overriding the hardware vectors that it does not use, to
2488
        instead allow an installed ROM monitor to handle them. This is
2489
        the most basic support which is likely to be common to most
2490
        implementations of ROM monitor.
2491
        \"CygMon\" provides support for the Cygnus ROM Monitor.
2492
        And finally, \"GDB_stubs\" provides support when GDB stubs are
2493
        included in the ROM monitor or boot ROM."
2494
}
2495
2496
 
2497
Or the ability to be configured as a ROM monitor:
2498
 
2499
2500
cdl_option CYGSEM_HAL_ROM_MONITOR {
2501
    display       "Behave as a ROM monitor"
2502
    flavor        bool
2503
    default_value 0
2504
    parent        CYGPKG_HAL_ROM_MONITOR
2505
    requires      { CYG_HAL_STARTUP == "ROM" }
2506
    description   "
2507
        Enable this option if this program is to be used as a ROM monitor,
2508
        i.e. applications will be loaded into RAM on the board, and this
2509
        ROM monitor may process exceptions or interrupts generated from the
2510
        application. This enables features such as utilizing a separate
2511
        interrupt stack when exceptions are generated."
2512
}
2513
2514
 
2515
The latter option is accompanied by a special build rule that
2516
extends the generic ROM monitor build rule in the common HAL:
2517
 
2518
2519
cdl_option CYGBLD_BUILD_GDB_STUBS {
2520
    display "Build GDB stub ROM image"
2521
    default_value 0
2522
    requires { CYG_HAL_STARTUP == "ROM" }
2523
    requires CYGSEM_HAL_ROM_MONITOR
2524
    requires CYGBLD_BUILD_COMMON_GDB_STUBS
2525
    requires CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
2526
    requires ! CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
2527
    requires ! CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT
2528
    requires ! CYGDBG_HAL_COMMON_INTERRUPTS_SAVE_MINIMUM_CONTEXT
2529
    requires ! CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM
2530
    no_define
2531
    description "
2532
        This option enables the building of the GDB stubs for the
2533
        board. The common HAL controls takes care of most of the
2534
        build process, but the final conversion from ELF image to
2535
        binary data is handled by the platform CDL, allowing
2536
        relocation of the data if necessary."
2537
 
2538
    make -priority 320 {
2539
        <PREFIX>/bin/gdb_module.bin : <PREFIX>/bin/gdb_module.img
2540
        $(OBJCOPY) -O binary $< $@
2541
    }
2542
}
2543
2544
 
2545
2546
Most platforms support RedBoot, and some options are needed to
2547
configure for RedBoot.
2548
2549
 
2550
2551
    cdl_component CYGPKG_REDBOOT_HAL_OPTIONS {
2552
        display       "Redboot HAL options"
2553
        flavor        none
2554
        no_define
2555
        parent        CYGPKG_REDBOOT
2556
        active_if     CYGPKG_REDBOOT
2557
        description   "
2558
            This option lists the target's requirements for a valid Redboot
2559
            configuration."
2560
 
2561
        cdl_option CYGBLD_BUILD_REDBOOT_BIN {
2562
            display       "Build Redboot ROM binary image"
2563
            active_if     CYGBLD_BUILD_REDBOOT
2564
            default_value 1
2565
            no_define
2566
            description "This option enables the conversion of the Redboot ELF
2567
                         image to a binary image suitable for ROM programming."
2568
 
2569
            make -priority 325 {
2570
                <PREFIX>/bin/redboot.bin : <PREFIX>/bin/redboot.elf
2571
                $(OBJCOPY) --strip-debug $< $(@:.bin=.img)
2572
                $(OBJCOPY) -O srec $< $(@:.bin=.srec)
2573
                $(OBJCOPY) -O binary $< $@
2574
            }
2575
        }
2576
    }
2577
2578
 
2579
2580
The important part here is the make command in the
2581
CYGBLD_BUILD_REDBOOT_BIN option which emits
2582
makefile commands to translate the .elf file
2583
generated by the link phase into both a binary file and an S-Record
2584
file. If a different format is required by a PROM programmer or ROM
2585
monitor, then different output formats would need to be generated here.
2586
2587
 
2588
2589
 
2590
2591
 
2592
2593
 
2594
2595
2596
 
2597
2598
Platform Memory Layout
2599
 
2600
The platform memory layout is defined using the Memory
2601
Configuration Window  in the Configuration Tool.
2602
 
2603
2604
If you do not have access to a Windows machine, you can
2605
hand edit the .h and .ldi files to match the
2606
properties of your platform. If you want to contribute your port back
2607
to the eCos community, ask someone on the list to make proper memory
2608
map files for you.
2609
2610
 
2611
2612
Layout Files
2613
 
2614
The memory configuration details are saved in three files:
2615
 
2616
2617
2618
.mlt
2619
        This is the Configuration Tool save-file. It is only used
2620
        by the Configuration Tool.
2621
2622
2623
.ldi
2624
        This is the linker script fragment. It defines the memory
2625
        and location of sections by way of macros defined in the
2626
        architecture or variant linker script.
2627
2628
2629
.h
2630
        This file describes some of the memory region details as C
2631
        macros, allowing eCos or the application adapt the memory
2632
        layout of a specific configuration.
2633
2634
2635
 
2636
These three files are generated for each startup-type, since the
2637
memory details usually differ.
2638
 
2639
2640
 
2641
2642
Reserved Regions
2643
 
2644
Some areas of the memory space are reserved for specific
2645
purposes, making room for exception vectors and various tables. RAM
2646
startup configurations also need to reserve some space at the bottom
2647
of the memory map for the ROM monitor.
2648
 
2649
These reserved areas are named with the prefix "reserved_" which is
2650
handled specially by the Configuration Tool: instead of referring to a
2651
linker macro, the start of the area is labeled and a gap left in the
2652
memory map.
2653
 
2654
2655
 
2656
 
2657
2658
 
2659
2660
2661
 
2662
2663
Platform Serial Device Support
2664
 
2665
2666
The first step is to set up the CDL definitions. The configuration
2667
options that need to be set are the following:
2668
2669
 
2670
2671
  
2672
    CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS
2673
    The number of channels, usually 0, 1 or 2.
2674
  
2675
 
2676
  
2677
    CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL
2678
    The channel to use for GDB.
2679
  
2680
 
2681
  
2682
    CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL_BAUD
2683
    Initial baud rate for debug channel.
2684
  
2685
 
2686
  
2687
    CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL
2688
    The channel to use for the
2689
    console.
2690
  
2691
 
2692
  
2693
    CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD
2694
    The initial baud rate for the console
2695
    channel.
2696
  
2697
 
2698
  
2699
    CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_DEFAULT
2700
    The default console channel.
2701
  
2702
2703
 
2704
2705
The code in hal_diag.c need to be converted to
2706
support the new serial device.
2707
If this the same as a device already supported, copy that.
2708
2709
 
2710
2711
The following functions and types need to be rewritten to support a new serial
2712
device.
2713
2714
 
2715
2716
  
2717
    struct channel_data_t;
2718
    
2719
      
2720
      Structure containing base address, timeout and ISR vector number
2721
      for each serial device supported. Extra fields my be added if
2722
      necessary for the device. For example some devices have
2723
      write-only control registers, so keeping a shadow of the last
2724
      value written here can be useful.
2725
      
2726
    
2727
  
2728
 
2729
  
2730
    xxxx_ser_channels[];
2731
    
2732
        
2733
        Array of channel_data_t, initialized with parameters of each
2734
        channel. The index into this array is the channel number used
2735
        in the CDL options above and is used by the virtual vector
2736
        mechanism to refer to each channel.
2737
        
2738
    
2739
  
2740
 
2741
  
2742
    void cyg_hal_plf_serial_init_channel(void
2743
           *__ch_data)
2744
    
2745
        
2746
        Initialize the serial device. The parameter is actually a pointer to a
2747
        channel_data_t and should be cast back to
2748
        this type before use. This function should use the CDL
2749
        definition for the baud rate for the channel it is initializing.
2750
        
2751
    
2752
  
2753
 
2754
  
2755
    void cyg_hal_plf_serial_putc(void * __ch_data,
2756
                    char *c)
2757
    
2758
        
2759
        Send a character to the serial device. This function should
2760
        poll for the device being ready to send and then write the character.
2761
        Since this is intended to be a diagnostic/debug channel, it is
2762
        often also a good idea to poll for end of transmission
2763
        too. This ensures that as much data gets out of the system as
2764
        possible.
2765
        
2766
    
2767
  
2768
 
2769
  
2770
    bool cyg_hal_plf_serial_getc_nonblock(void*
2771
                    __ch_data, cyg_uint8* ch)
2772
    
2773
        
2774
        This function tests the device and if a character is
2775
        available, places it in *ch and returns
2776
        TRUE. If no character is available, then
2777
        the function returns FALSE immediately.
2778
        
2779
    
2780
  
2781
 
2782
  
2783
    int cyg_hal_plf_serial_control(void *__ch_data,
2784
                    __comm_control_cmd_t __func,
2785
                    ...)
2786
     
2787
        
2788
        This is an IOCTL-like function for controlling various aspects
2789
        of the serial device. The only part in which you may need to
2790
        do some work initially is in the
2791
        __COMMCTL_IRQ_ENABLE and
2792
        __COMMCTL_IRQ_DISABLE cases to
2793
        enable/disable interrupts.
2794
        
2795
    
2796
  
2797
 
2798
  
2799
    int cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc,
2800
                       CYG_ADDRWORD __vector, CYG_ADDRWORD
2801
                       __data)
2802
    
2803
        
2804
        This interrupt handler, called from the spurious interrupt
2805
        vector, is specifically for dealing with
2806
        Ctrl-C interrupts from GDB. When called
2807
        this function should do the following:
2808
        
2809
        
2810
          Check for an incoming character. The code here is very
2811
          similar to that in
2812
          cyg_hal_plf_serial_getc_nonblock().
2813
          
2814
        
2815
        
2816
          
2817
          Read the character and call
2818
          cyg_hal_is_break().
2819
          
2820
        
2821
        
2822
          
2823
          If result is true, set *__ctrlc to
2824
          1.
2825
          
2826
        
2827
        
2828
          
2829
          Return CYG_ISR_HANDLED.
2830
          
2831
        
2832
        
2833
      
2834
    
2835
  
2836
 
2837
  
2838
    void cyg_hal_plf_serial_init()
2839
    
2840
        
2841
        Initialize each of the serial channels.
2842
        First call cyg_hal_plf_serial_init_channel() for each channel.
2843
        Then call the CYGACC_COMM_IF_* macros for
2844
        each channel. This latter set of calls are identical for all
2845
        channels, so the best way to do this is to copy and edit an
2846
        existing example.
2847
        
2848
    
2849
  
2850
2851
 
2852
2853
 
2854
2855
 
2856
2857
 
2858
2859
2860
 
2861
2862
Variant HAL Porting
2863
 
2864
2865
A variant port can be a fairly limited job, but can also
2866
require quite a lot of work. A variant HAL describes how a specific
2867
CPU variant differs from the generic CPU architecture. The variant HAL
2868
can re-define cache, MMU, interrupt, and other features which override
2869
the default implementation provided by the architecture HAL.
2870
2871
 
2872
2873
Doing a variant port requires a preexisting architecture HAL port. It
2874
is also likely that a platform port will have to be done at the same
2875
time if it is to be tested.
2876
2877
 
2878
2879
 
2880
2881
HAL Variant Porting Process
2882
 
2883
The easiest way to make a new variant HAL is simply to copy an
2884
existing variant HAL and change all the files to match the new
2885
variant. If this is the first variant for an architecture, it may be
2886
hard to decide which parts should be put in the variant - knowledge of
2887
other variants of the architecture is required.
2888
 
2889
Looking at existing variant HALs (e.g., MIPS tx39, tx49) may be a
2890
help - usually things such as caching, interrupt and exception
2891
handling differ between variants. Initialization code, and code for
2892
handling various core components (FPU, DSP, MMU, etc.) may also differ
2893
or be missing altogether on some variants. Linker scripts may also require
2894
specific variant versions.
2895
 
2896
2897
Note
2898
Some CPU variants may require specific compiler
2899
support. That support must be in place before you can undertake the
2900
eCos variant port.
2901
2902
 
2903
 
2904
 
2905
2906
 
2907
2908
2909
 
2910
2911
HAL Variant CDL
2912
 
2913
2914
The CDL in a variant HAL tends to depend on the exact functionality
2915
supported by the variant. If it implements some of the devices
2916
described in the platform HAL, then the CDL for those will be here
2917
rather than there (for example the real-time clock).
2918
2919
 
2920
2921
There may also be CDL to select options in the architecture HAL to
2922
configure it to a particular architectural variant.
2923
2924
 
2925
2926
Each variant needs an entry in the ecos.db
2927
file. This is the one for the SH3:
2928
2929
 
2930
2931
package CYGPKG_HAL_SH_SH3 {
2932
    alias         { "SH3 architecture" hal_sh_sh3 }
2933
    directory     hal/sh/sh3
2934
    script        hal_sh_sh3.cdl
2935
    hardware
2936
    description   "
2937
        The SH3 (SuperH 3) variant HAL package provides generic
2938
        support for SH3 variant CPUs."
2939
}
2940
2941
 
2942
2943
As you can see, it is very similar to the platform entry.
2944
2945
 
2946
2947
The variant CDL file will contain a package entry named for the
2948
architecture and variant, matching the package name in the
2949
ecos.db file. Here is the initial part of the
2950
MIPS VR4300 CDL file:
2951
2952
 
2953
2954
cdl_package CYGPKG_HAL_MIPS_VR4300 {
2955
    display       "VR4300 variant"
2956
    parent        CYGPKG_HAL_MIPS
2957
    implements    CYGINT_HAL_MIPS_VARIANT
2958
    hardware
2959
    include_dir   cyg/hal
2960
    define_header hal_mips_vr4300.h
2961
    description   "
2962
           The VR4300 variant HAL package provides generic support
2963
           for this processor architecture. It is also necessary to
2964
           select a specific target platform HAL package."
2965
2966
 
2967
2968
This defines the package, placing it under the MIPS architecture
2969
package in the hierarchy. The implements line
2970
indicates that this is a MIPS variant. The architecture package uses
2971
this to check that exactly one variant is configured in.
2972
2973
 
2974
2975
The variant defines some options that cause the architecture HAL to
2976
configure itself to support this variant.
2977
2978
 
2979
2980
    cdl_option CYGHWR_HAL_MIPS_64BIT {
2981
        display    "Variant 64 bit architecture support"
2982
        calculated 1
2983
    }
2984
 
2985
    cdl_option CYGHWR_HAL_MIPS_FPU {
2986
        display    "Variant FPU support"
2987
        calculated 1
2988
    }
2989
 
2990
    cdl_option CYGHWR_HAL_MIPS_FPU_64BIT {
2991
        display    "Variant 64 bit FPU support"
2992
        calculated 1
2993
    }
2994
2995
 
2996
2997
These tell the architecture that this is a 64 bit MIPS architecture,
2998
that it has a floating point unit, and that we are going to use it in
2999
64 bit mode rather than 32 bit mode.
3000
3001
 
3002
3003
The CDL file finishes off with some build options.
3004
3005
 
3006
3007
    define_proc {
3008
        puts $::cdl_header "#include <pkgconf/hal_mips.h>"
3009
    }
3010
 
3011
    compile       var_misc.c
3012
 
3013
    make {
3014
        <PREFIX>/lib/target.ld: <PACKAGE>/src/mips_vr4300.ld
3015
        $(CC) -E -P -Wp,-MD,target.tmp -DEXTRAS=1 -xc $(INCLUDE_PATH) $(CFLAGS) -o $@ $<
3016
        @echo $@ ": \\" > $(notdir $@).deps
3017
        @tail +2 target.tmp >> $(notdir $@).deps
3018
        @echo >> $(notdir $@).deps
3019
        @rm target.tmp
3020
    }
3021
 
3022
    cdl_option CYGBLD_LINKER_SCRIPT {
3023
        display "Linker script"
3024
        flavor data
3025
        no_define
3026
        calculated  { "src/mips_vr4300.ld" }
3027
    }
3028
 
3029
}
3030
3031
 
3032
3033
The define_proc causes the architecture
3034
configuration file to be included into the configuration file for the
3035
variant. The compile causes the single source file
3036
for this variant, var_misc.c to be compiled. The
3037
make command emits makefile rules to combine the
3038
linker script with the .ldi file to generate
3039
target.ld. Finally, in the MIPS HALs, the main
3040
linker script is defined in the variant, rather than the architecture,
3041
so CYGBLD_LINKER_SCRIPT is defined here.
3042
3043
 
3044
3045
 
3046
3047
3048
 
3049
3050
Cache Support
3051
 
3052
3053
The main area where the variant is likely to be involved is in cache
3054
support. Often the only thing that distinguishes one CPU variant from
3055
another is the size of its caches.
3056
3057
 
3058
3059
In architectures such as the MIPS and PowerPC where cache instructions
3060
are part of the ISA, most of the actual cache operations are
3061
implemented in the architecture HAL. In this case the variant HAL only
3062
needs to define the cache dimensions. The following are the cache
3063
dimensions defined in the MIPS VR4300 variant
3064
var_cache.h.
3065
3066
 
3067
3068
// Data cache
3069
#define HAL_DCACHE_SIZE                 (8*1024)        // Size of data cache in bytes
3070
#define HAL_DCACHE_LINE_SIZE            16              // Size of a data cache line
3071
#define HAL_DCACHE_WAYS                 1               // Associativity of the cache
3072
 
3073
// Instruction cache
3074
#define HAL_ICACHE_SIZE                 (16*1024)       // Size of cache in bytes
3075
#define HAL_ICACHE_LINE_SIZE            32              // Size of a cache line
3076
#define HAL_ICACHE_WAYS                 1               // Associativity of the cache
3077
 
3078
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
3079
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
3080
3081
 
3082
3083
Additional cache macros, or overrides for the defaults, may also
3084
appear in here. While some architectures have instructions for
3085
managing cache lines, overall enable/disable operations may be handled
3086
via variant specific registers. If so then
3087
var_cache.h should also define the
3088
HAL_XCACHE_ENABLE() and
3089
HAL_XCACHE_DISABLE() macros.
3090
3091
 
3092
3093
If there are any generic features that the variant does not support
3094
(cache locking is a typical example) then
3095
var_cache.h may need to disable definitions of
3096
certain operations. It is architecture dependent exactly how this is
3097
done.
3098
3099
 
3100
 
3101
3102
 
3103
3104
 
3105
3106
 
3107
3108
3109
 
3110
3111
 
3112
Architecture HAL Porting
3113
 
3114
3115
A new architecture HAL is the most complex HAL to write, and it the
3116
least easily described. Hence this section is presently nothing more
3117
than a place holder for the future.
3118
3119
 
3120
3121
 
3122
3123
HAL Architecture Porting Process
3124
 
3125
The easiest way to make a new architecture HAL is simply to copy an
3126
existing architecture HAL of an, if possible, closely matching
3127
architecture and change all the files to match the new
3128
architecture. The MIPS architecture HAL should be used if possible, as
3129
it has the appropriate layout and coding conventions. Other HALs
3130
may deviate from that norm in various ways.
3131
 
3132
3133
Note
3134
 eCos is written for GCC. It requires C and C++
3135
compiler support as well as a few compiler features introduced during
3136
eCos development - so compilers older than eCos may not provide these
3137
features. Note that there is no C++ support for any 8 or 16 bit
3138
CPUs. Before you can undertake an eCos port, you need the required
3139
compiler support.
3140
3141
3142
 
3143
3144
The following gives a rough outline of the steps needed to create a
3145
new architecture HAL. The exact order and set of steps needed will
3146
vary greatly from architecture to architecture, so a lot of
3147
flexibility is required. And of course, if the architecture HAL is to
3148
be tested, it is necessary to do variant and  platform ports for the
3149
initial target simultaneously.
3150
3151
 
3152
3153
 
3154
3155
3156
Make a new directory for the new architecture under the
3157
hal directory in the source repository. Make an
3158
arch directory under this and populate this with
3159
the standard set of package directories.
3160
3161
3162
 
3163
3164
3165
Copy the CDL file from an example HAL changing its name to match the
3166
new HAL. Edit the file, changing option names as appropriate. Delete
3167
any options that are specific to the original HAL, and and any new
3168
options that are necessary for the new architecture. This is likely to
3169
be a continuing process during the development of the HAL. See 
3170
linkend="hal-porting-architecture-cdl"> for more details.
3171
3172
3173
 
3174
3175
3176
Copy the hal_arch.h file from an example
3177
HAL. Within this file you need to change or define the following:
3178
3179
3180
 
3181
3182
3183
Define the HAL_SavedRegisters structure. This
3184
may need to reflect the save order of any group register save/restore
3185
instructions, the interrupt and exception save and restore formats,
3186
and the procedure calling conventions. It may also need to cater for
3187
optional FPUs and other functional units. It can be quite difficult to
3188
develop a layout that copes with all requirements.
3189
3190
3191
 
3192
3193
3194
Define the bit manipulation routines,
3195
HAL_LSBIT_INDEX() and
3196
HAL_MSBIT_INDEX(). If the architecture contains
3197
instructions to perform these, or related, operations, then these
3198
should be defined as inline assembler fragments. Otherwise make them
3199
calls to functions.
3200
3201
3202
 
3203
3204
3205
Define HAL_THREAD_INIT_CONTEXT(). This initializes
3206
a restorable CPU context onto a stack pointer so that a later call to
3207
HAL_THREAD_LOAD_CONTEXT() or
3208
HAL_THREAD_SWITCH_CONTEXT() will execute it
3209
correctly. This macro needs to take account of the same optional
3210
features of the architecture as the definition of
3211
HAL_SavedRegisters.
3212
3213
3214
 
3215
3216
3217
Define HAL_THREAD_LOAD_CONTEXT() and
3218
HAL_THREAD_SWITCH_CONTEXT(). These should just be
3219
calls to functions in context.S.
3220
3221
3222
 
3223
3224
3225
Define HAL_REORDER_BARRIER(). This prevents code
3226
being moved by the compiler and is necessary in some order-sensitive
3227
code. This macro is actually defined identically in all architecture,
3228
so it can just be copied.
3229
3230
3231
 
3232
3233
3234
Define breakpoint support. The macro
3235
HAL_BREAKPOINT(label) needs to be an inline assembly
3236
fragment that invokes a breakpoint. The breakpoint instruction should
3237
be labeled with the label
3238
argument. HAL_BREAKINST and
3239
HAL_BREAKINST_SIZE define the breakpoint
3240
instruction for debugging purposes.
3241
3242
3243
 
3244
3245
3246
Define GDB support. GDB views the registers of the target as a linear
3247
array, with each register having a well defined offset. This array may
3248
differ from the ordering defined in
3249
HAL_SavedRegisters. The macros
3250
HAL_GET_GDB_REGISTERS() and
3251
HAL_SET_GDB_REGISTERS() translate between the GDB
3252
array and the HAL_SavedRegisters structure.
3253
The HAL_THREAD_GET_SAVED_REGISTERS() translates a
3254
stack pointer saved by the context switch macros into a pointer to a
3255
HAL_SavedRegisters structure. Usually this is
3256
a one-to-one translation, but this macro allows it to differ if
3257
necessary.
3258
3259
3260
 
3261
3262
3263
Define long jump support. The type hal_jmp_buf and the
3264
functions hal_setjmp() and
3265
hal_longjmp() provide the underlying implementation
3266
of the C library setjmp() and
3267
longjmp().
3268
3269
3270
 
3271
3272
3273
Define idle thread action. Generally the macro
3274
HAL_IDLE_THREAD_ACTION() is defined to call a
3275
function in hal_misc.c.
3276
3277
3278
 
3279
3280
3281
Define stack sizes. The macros
3282
CYGNUM_HAL_STACK_SIZE_MINIMUM and
3283
CYGNUM_HAL_STACK_SIZE_TYPICAL should be defined to
3284
the minimum size for any thread stack and a reasonable default for
3285
most threads respectively. It is usually best to construct these out
3286
of component sizes for the CPU save state and procedure call stack
3287
usage. These definitions should not use anything other than numerical
3288
values since they can be used from assembly code in some HALs.
3289
3290
3291
 
3292
3293
3294
Define memory access macros. These macros provide translation between
3295
cached and uncached and physical memory spaces. They usually consist
3296
of masking out bits of the supplied address and ORing in alternative
3297
address bits.
3298
3299
3300
 
3301
3302
3303
Define global pointer save/restore macros. These really only need
3304
defining if the calling conventions of the architecture require a
3305
global pointer (as does the MIPS architecture), they may be empty
3306
otherwise. If it is necessary to define these, then take a look at the
3307
MIPS implementation for an example.
3308
3309
3310
 
3311
3312
 
3313
3314
 
3315
3316
3317
Copy hal_intr.h from an example HAL. Within this
3318
file you should change or define the following:
3319
3320
 
3321
 
3322
3323
3324
3325
Define the exception vectors. These should be detailed in the
3326
architecture specification. Essentially for each exception entry point
3327
defined by the architecture there should be an entry in the VSR
3328
table. The offsets of these VSR table entries should be defined here
3329
by CYGNUM_HAL_VECTOR_* definitions. The size of the
3330
VSR table also needs to be defined here.
3331
3332
3333
 
3334
3335
3336
Map any hardware exceptions to standard names. There is a group of
3337
exception vector name of the form
3338
CYGNUM_HAL_EXCEPTION_* that define a wide variety
3339
of possible exceptions that many architectures raise. Generic code
3340
detects whether the architecture can raise a given exception by
3341
testing whether a given CYGNUM_HAL_EXCEPTION_*
3342
definition is present. If it is present then its value is the vector
3343
that raises that exception. This does not need to be a one-to-one
3344
correspondence, and several CYGNUM_HAL_EXCEPTION_*
3345
definitions may have the same value.
3346
3347
 
3348
3349
Interrupt vectors are usually defined in the variant or platform
3350
HALs. The interrupt number space may either be continuous with the VSR
3351
number space, where they share a vector table (as in the i386) or may
3352
be a separate space where a separate decode stage is used (as in MIPS
3353
or PowerPC).
3354
3355
 
3356
3357
 
3358
3359
3360
Declare any static data used by the HAL to handle interrupts and
3361
exceptions. This is usually three vectors for interrupts:
3362
hal_interrupt_handlers[],
3363
hal_interrupt_data[] and
3364
hal_interrupt_objects[], which are sized according
3365
to the interrupt vector definitions. In addition a definition for the
3366
VSR table, hal_vsr_table[] should be made. These
3367
vectors are normally defined in either vectors.S
3368
or hal_misc.c.
3369
3370
3371
 
3372
3373
3374
Define interrupt enable/disable macros. These are normally inline
3375
assembly fragments to execute the instructions, or manipulate the CPU
3376
register, that contains the CPU interrupt enable bit.
3377
3378
3379
 
3380
3381
3382
A feature that many HALs support is the ability to execute DSRs on the
3383
interrupt stack. This is not an essential feature, and is better left
3384
unimplemented in the initial porting effort. If this is required, then
3385
the macro HAL_INTERRUPT_STACK_CALL_PENDING_DSRS()
3386
should be defined to call a function in
3387
vectors.S.
3388
3389
3390
 
3391
3392
3393
Define the interrupt and VSR attachment macros. If the same arrays as
3394
for other HALs have been used for VSR and interrupt vectors, then
3395
these macro can be copied across unchanged.
3396
3397
3398
 
3399
3400
 
3401
3402
 
3403
3404
3405
A number of other header files also need to be filled in:
3406
3407
3408
3409
3410
basetype.h. This file defines the basic types
3411
used by eCos, together with the endianness and some other
3412
characteristics. This file only really needs to contain definitions
3413
if the architecture differs significantly from the defaults defined
3414
in cyg_type.h
3415
3416
3417
 
3418
3419
3420
hal_io.h. This file contains macros for accessing
3421
device IO registers. If the architecture uses memory mapped IO, then
3422
these can be copied unchanged from an existing HAL such as MIPS. If
3423
the architecture uses special IO instructions, then these macros must
3424
be defined as inline assembler fragments. See the I386 HAL for an
3425
example. PCI bus access macros are usually defined in the variant or
3426
platform HALs.
3427
3428
3429
 
3430
3431
3432
hal_cache.h. This file contains cache access
3433
macros. If the architecture defines cache instructions, or control
3434
registers, then the access macros should be defined here. Otherwise
3435
they must be defined in the variant or platform HAL. Usually the cache
3436
dimensions (total size, line size, ways etc.) are defined in the
3437
variant HAL.
3438
3439
3440
 
3441
3442
3443
arch.inc and
3444
<architecture>.inc. These files are
3445
assembler headers used by vectors.S and
3446
context.S.
3447
<architecture>.inc is a general purpose
3448
header that should contain things like register aliases, ABI
3449
definitions and macros useful to general assembly
3450
code. If there are no such definitions, then this file need not be
3451
provided. arch.inc contains macros for performing
3452
various eCos related operations such as initializing the CPU, caches,
3453
FPU etc. The definitions here may often be configured or overridden by
3454
definitions in the variant or platform HALs. See the MIPS HAL for an
3455
example of this.
3456
3457
3458
 
3459
3460
 
3461
3462
 
3463
3464
3465
Write vectors.S. This is the most important file
3466
in the HAL. It contains the CPU initialization code, exception and
3467
interrupt handlers. While other HALs should be consulted for
3468
structures and techniques, there is very little here that can be
3469
copied over without major edits.
3470
3471
 
3472
3473
The main pieces of code that need to be defined here are:
3474
3475
 
3476
3477
3478
3479
Reset vector. This usually need to be positioned at the start of the
3480
ROM or FLASH, so should be in a linker section of its own. It can then be
3481
placed correctly by the linker script. Normally this code is little
3482
more than a jump to the label _start.
3483
3484
3485
 
3486
3487
3488
Exception vectors. These are the trampoline routines connected to the
3489
hardware exception entry points that vector through the VSR table. In
3490
many architectures these are adjacent to the reset vector, and should
3491
occupy the same linker section. If the architecture allow the vectors
3492
to be moved then it may be necessary for these trampolines to be
3493
position independent so they can be relocated at runtime.
3494
3495
 
3496
3497
The trampolines should do the minimum necessary to transfer control
3498
from the hardware vector to the VSR pointed to by the matching table
3499
entry. Exactly how this is done depends on the architecture. Usually
3500
the trampoline needs to get some working registers by either saving
3501
them to CPU special registers (e.g. PowerPC SPRs), using reserved
3502
general registers (MIPS K0 and K1), using only memory based
3503
operations (IA32), or just jumping directly (ARM). The VSR table index
3504
to be used is either implicit in the entry point taken (PowerPC, IA32,
3505
ARM), or must be determined from a CPU register (MIPS).
3506
3507
3508
 
3509
3510
3511
Write kernel startup code. This is the location the reset vector jumps
3512
to, and can be in the main text section of the executable, rather than
3513
a special section. The code here should first initialize the CPU and other
3514
hardware subsystems. The best approach is to use a set of macro
3515
calls that are defined either in arch.inc or
3516
overridden in the variant or platform HALs. Other jobs that this code
3517
should do are: initialize stack pointer; copy the data section from
3518
ROM to RAM if necessary; zero the BSS; call variant and platform
3519
initializers; call cyg_hal_invoke_constructors();
3520
call initialize_stub() if necessary. Finally it
3521
should call cyg_start(). See 
3522
linkend="hal-startup"> for details.
3523
3524
3525
 
3526
3527
3528
Write the default exception VSR. This VSR is installed in the VSR
3529
table for all synchronous exception vectors. See 
3530
linkend="hal-default-synchronous-exception-handling"> for details of
3531
what this VSR does.
3532
3533
3534
 
3535
3536
3537
Write the default interrupt VSR. This is installed in all VSR table
3538
entries that correspond to external interrupts. See 
3539
linkend="hal-default-synchronous-exception-handling"> for details of
3540
what this VSR does.
3541
3542
3543
 
3544
3545
3546
Write
3547
hal_interrupt_stack_call_pending_dsrs(). If this
3548
function is defined in hal_arch.h then it should
3549
appear here. The purpose of this function is to call DSRs on the
3550
interrupt stack rather than the current thread's stack. This is not an
3551
essential feature, and may be left until later. However it interacts
3552
with the stack switching that goes on in the interrupt VSR, so it may
3553
make sense to write these pieces of code at the same time to ensure
3554
consistency.
3555
3556
 
3557
3558
When this function is implemented it should do the following:
3559
3560
 
3561
3562
3563
3564
Take a copy of the current SP and then switch to the interrupt stack.
3565
3566
3567
 
3568
3569
3570
Save the old SP, together with the CPU status register (or whatever
3571
register contains the interrupt enable status) and any other
3572
registers that may be corrupted by a function call (such as any link
3573
register) to locations in the interrupt stack.
3574
3575
3576
 
3577
3578
3579
Enable interrupts.
3580
3581
3582
 
3583
3584
3585
Call cyg_interrupt_call_pending_DSRs(). This is a
3586
kernel functions that actually calls any pending DSRs.
3587
3588
3589
 
3590
3591
3592
Retrieve saved registers from the interrupt stack and switch back to
3593
the current thread stack.
3594
3595
3596
 
3597
3598
3599
Merge the interrupt enable state recorded in the save CPU status
3600
register with the current value of the status register to restore the
3601
previous enable state. If the status register does not contain any
3602
other persistent state then this can be a simple restore of the
3603
register. However if the register contains other state bits that might
3604
have been changed by a DSR, then care must be taken not to disturb
3605
these.
3606
3607
3608
 
3609
3610
 
3611
3612
 
3613
 
3614
3615
3616
Define any data items needed. Typically vectors.S
3617
may contain definitions for the VSR table, the interrupt tables and the
3618
interrupt stack. Sometimes these are only default definitions that may
3619
be overridden by the variant or platform HALs.
3620
3621
3622
 
3623
3624
 
3625
3626
 
3627
3628
3629
Write context.S. This file contains the context
3630
switch code. See  for details of
3631
how these functions operate. This file may also contain the
3632
implementation of hal_setjmp() and
3633
hal_longjmp().
3634
3635
3636
 
3637
3638
3639
Write hal_misc.c. This file contains any C
3640
data and functions needed by the HAL. These might include:
3641
3642
 
3643
3644
3645
3646
hal_interrupt_*[]. In some HALs, if these arrays
3647
are not defined in vectors.S then they must be
3648
defined here.
3649
3650
3651
 
3652
3653
3654
cyg_hal_exception_handler(). This function is
3655
called from the exception VSR. It usually does extra decoding of the
3656
exception and invokes any special handlers for things like FPU traps,
3657
bus errors or memory exceptions. If there is nothing special to be
3658
done for an exception, then it either calls into the GDB stubs, by
3659
calling __handle_exception(), or
3660
invokes the kernel by calling
3661
cyg_hal_deliver_exception().
3662
3663
3664
 
3665
3666
3667
hal_arch_default_isr(). The
3668
hal_interrupt_handlers[] array is usually
3669
initialized with pointers to hal_default_isr(),
3670
which is defined in the common HAL. This function handles things like
3671
Ctrl-C processing, but if that is not relevant, then it will call
3672
hal_arch_default_isr(). Normally this function
3673
should just return zero.
3674
3675
3676
 
3677
3678
3679
cyg_hal_invoke_constructors(). This calls the
3680
constructors for all static objects before the program starts. eCos
3681
relies on these being called in the correct order for it to function
3682
correctly. The exact way in which constructors are handled may differ
3683
between architectures, although most use a simple table of function
3684
pointers between labels __CTOR_LIST__ and
3685
__CTOR_END__ which must called in order from the
3686
top down. Generally, this function can be copied directly from an
3687
existing architecture HAL.
3688
3689
3690
 
3691
3692
3693
Bit indexing functions. If the macros
3694
HAL_LSBIT_INDEX() and
3695
HAL_MSBIT_INDEX() are defined as function calls,
3696
then the functions should appear here. The main reason for doing this
3697
is that the architecture does not have support for bit indexing and
3698
these functions must provide the functionality by conventional
3699
means. While the trivial implementation is a simple for loop, it is
3700
expensive and non-deterministic. Better, constant time,
3701
implementations can be found in several HALs (MIPS for example).
3702
3703
3704
 
3705
3706
3707
hal_delay_us(). If the macro
3708
HAL_DELAY_US() is defined in 
3709
class="headerfile">hal_intr.h then it should be defined to
3710
call this function. While most of the time this function is called
3711
with very small values, occasionally (particularly in some ethernet
3712
drivers) it is called with values of several seconds. Hence the
3713
function should take care to avoid overflow in any calculations.
3714
3715
3716
 
3717
3718
3719
hal_idle_thread_action(). This function is called
3720
from the idle thread via the
3721
HAL_IDLE_THREAD_ACTION() macro, if so
3722
defined. While normally this function does nothing, during development
3723
this is often a good place to report various important system
3724
parameters on LCDs, LED or other displays. This function can also
3725
monitor system state and report any anomalies. If the architecture
3726
supports a halt instruction then this is a good
3727
place to put an inline assembly fragment to execute it. It is also a
3728
good place to handle any power saving activity.
3729
3730
3731
 
3732
3733
3734
 
3735
3736
3737
Create the <architecture>.ld file. While
3738
this file may need to be moved to the variant HAL in the future, it
3739
should initially be defined here, and only moved if necessary.
3740
3741
3742
This file defines a set of macros that are used by the platform
3743
.ldi files to generate linker scripts. Most GCC
3744
toolchains are very similar so the correct approach is to copy the
3745
file from an existing architecture and edit it. The main things that
3746
will need editing are the OUTPUT_FORMAT() directive
3747
and maybe the creation or allocation of extra sections to various
3748
macros. Running the target linker with just the
3749
--verbose argument will cause it to output its
3750
default linker script. This can be compared with the
3751
.ld file and appropriate edits made.
3752
3753
3754
 
3755
3756
3757
If GDB stubs are to be supported in RedBoot or eCos, then support must
3758
be included for these. The most important of these are 
3759
class="headerfile">include/<architecture>-stub.h and
3760
src/<architecture>-stub.c. In all existing
3761
architecture HALs these files, and any support files they need, have
3762
been derived from files supplied in libgloss, as
3763
part of the GDB toolchain package. If this is a totally new
3764
architecture, this may not have been done, and they must be created
3765
from scratch.
3766
3767
 
3768
3769
3770
class="headerfile">include/<architecture>-stub.h
3771
contains definitions that are used by the GDB stubs to describe the
3772
size, type, number and names of CPU registers. This information is
3773
usually found in the GDB support files for the architecture. It also
3774
contains prototypes for the functions exported by
3775
src/<architecture>-stub.c; however, since
3776
this is common to all architectures, it can be copied from some other
3777
HAL.
3778
3779
 
3780
3781
src/<architecture>-stub.c implements the
3782
functions exported by the header. Most of this is fairly straight
3783
forward: the implementation in existing HALs should show exactly what
3784
needs to be done. The only complex part is the support for
3785
single-stepping. This is used a lot by GDB, so it cannot be
3786
avoided. If the architecture has support for a trace or single-step
3787
trap then that can be used for this purpose. If it does not then this
3788
must be simulated by planting a breakpoint in the next
3789
instruction. This can be quite involved since it requires some
3790
analysis of the current instruction plus the state of the CPU to
3791
determine where execution is going to go next.
3792
3793
 
3794
3795
 
3796
3797
 
3798
 
3799
3800
 
3801
3802
3803
 
3804
3805
CDL Requirements
3806
 
3807
3808
The CDL needed for any particular architecture HAL depends to a large
3809
extent on the needs of that architecture. This includes issues such as
3810
support for different variants, use of FPUs, MMUs and caches. The
3811
exact split between the architecture, variant and platform HALs for
3812
various features is also somewhat fluid.
3813
3814
 
3815
3816
To give a rough idea about how the CDL for an architecture is
3817
structured, we will take as an example the I386 CDL.
3818
3819
 
3820
3821
This first section introduces the CDL package and placed it under the
3822
main HAL package. Include files from this package will be put in the
3823
include/cyg/hal directory, and definitions from
3824
this file will be placed in
3825
include/pkgconf/hal_i386.h. The
3826
compile line specifies the files in the
3827
src directory that are to be compiled as part of
3828
this package.
3829
3830
 
3831
3832
cdl_package CYGPKG_HAL_I386 {
3833
    display       "i386 architecture"
3834
    parent        CYGPKG_HAL
3835
    hardware
3836
    include_dir   cyg/hal
3837
    define_header hal_i386.h
3838
    description   "
3839
        The i386 architecture HAL package provides generic
3840
        support for this processor architecture. It is also
3841
        necessary to select a specific target platform HAL
3842
        package."
3843
 
3844
    compile       hal_misc.c context.S i386_stub.c hal_syscall.c
3845
3846
 
3847
3848
Next we need to generate some files using non-standard make rules. The
3849
first is vectors.S, which is not put into the
3850
library, but linked explicitly with all applications. The second is
3851
the generation of the target.ld file from
3852
i386.ld and the startup-selected
3853
.ldi file. Both of these are essentially
3854
boilerplate code that can be copied and edited.
3855
3856
 
3857
3858
 
3859
    make {
3860
        <PREFIX>/lib/vectors.o : <PACKAGE>/src/vectors.S
3861
        $(CC) -Wp,-MD,vectors.tmp $(INCLUDE_PATH) $(CFLAGS) -c -o $@ $<
3862
        @echo $@ ": \\" > $(notdir $@).deps
3863
        @tail +2 vectors.tmp >> $(notdir $@).deps
3864
        @echo >> $(notdir $@).deps
3865
        @rm vectors.tmp
3866
    }
3867
 
3868
    make {
3869
        <PREFIX>/lib/target.ld: <PACKAGE>/src/i386.ld
3870
        $(CC) -E -P -Wp,-MD,target.tmp -DEXTRAS=1 -xc $(INCLUDE_PATH) $(CFLAGS) -o $@ $<
3871
        @echo $@ ": \\" > $(notdir $@).deps
3872
        @tail +2 target.tmp >> $(notdir $@).deps
3873
        @echo >> $(notdir $@).deps
3874
        @rm target.tmp
3875
    }
3876
3877
 
3878
3879
The i386 is currently the only architecture that supports SMP. The
3880
following CDL simply enabled the HAL SMP support if
3881
required. Generally this will get enabled as a result of a
3882
requires statement in the kernel. The
3883
requires statement here turns off lazy FPU
3884
switching in the FPU support code, since it is inconsistent with SMP
3885
operation.
3886
3887
 
3888
3889
 
3890
    cdl_component CYGPKG_HAL_SMP_SUPPORT {
3891
        display       "SMP support"
3892
        default_value 0
3893
        requires { CYGHWR_HAL_I386_FPU_SWITCH_LAZY == 0 }
3894
 
3895
        cdl_option CYGPKG_HAL_SMP_CPU_MAX {
3896
            display       "Max number of CPUs supported"
3897
            flavor        data
3898
            default_value 2
3899
        }
3900
    }
3901
3902
 
3903
3904
The i386 HAL has optional FPU support, which is enabled by default. It
3905
can be disabled to improve system performance. There are two FPU
3906
support options: either to save and restore the FPU state on every
3907
context switch, or to only switch the FPU state when necessary.
3908
3909
 
3910
3911
 
3912
    cdl_component CYGHWR_HAL_I386_FPU {
3913
        display       "Enable I386 FPU support"
3914
        default_value 1
3915
        description   "This component enables support for the
3916
                      I386 floating point unit."
3917
 
3918
        cdl_option CYGHWR_HAL_I386_FPU_SWITCH_LAZY {
3919
            display       "Use lazy FPU state switching"
3920
            flavor        bool
3921
            default_value 1
3922
 
3923
            description "
3924
                        This option enables lazy FPU state switching.
3925
                        The default behaviour for eCos is to save and
3926
                        restore FPU state on every thread switch, interrupt
3927
                        and exception. While simple and deterministic, this
3928
                        approach can be expensive if the FPU is not used by
3929
                        all threads. The alternative, enabled by this option,
3930
                        is to use hardware features that allow the FPU state
3931
                        of a thread to be left in the FPU after it has been
3932
                        descheduled, and to allow the state to be switched to
3933
                        a new thread only if it actually uses the FPU. Where
3934
                        only one or two threads use the FPU this can avoid a
3935
                        lot of unnecessary state switching."
3936
        }
3937
    }
3938
3939
 
3940
3941
The i386 HAL also has support for different classes of CPU. In
3942
particular, Pentium class CPUs have extra functional units, and some
3943
variants of GDB expect more registers to be reported. These options
3944
enable these features. Generally these are enabled by
3945
requires statements in variant or platform
3946
packages, or in .ecm files.
3947
3948
 
3949
3950
 
3951
    cdl_component CYGHWR_HAL_I386_PENTIUM {
3952
        display       "Enable Pentium class CPU features"
3953
        default_value 0
3954
        description   "This component enables support for various
3955
                      features of Pentium class CPUs."
3956
 
3957
        cdl_option CYGHWR_HAL_I386_PENTIUM_SSE {
3958
            display       "Save/Restore SSE registers on context switch"
3959
            flavor        bool
3960
            default_value 0
3961
 
3962
            description "
3963
                        This option enables SSE state switching. The default
3964
                        behaviour for eCos is to ignore the SSE registers.
3965
                        Enabling this option adds SSE state information to
3966
                        every thread context."
3967
        }
3968
 
3969
        cdl_option CYGHWR_HAL_I386_PENTIUM_GDB_REGS {
3970
            display       "Support extra Pentium registers in GDB stub"
3971
            flavor        bool
3972
            default_value 0
3973
 
3974
            description "
3975
                        This option enables support for extra Pentium registers
3976
                        in the GDB stub. These are registers such as CR0-CR4, and
3977
                        all MSRs. Not all GDBs support these registers, so the
3978
                        default behaviour for eCos is to not include them in the
3979
                        GDB stub support code."
3980
        }
3981
    }
3982
3983
 
3984
3985
In the i386 HALs, the linker script is provided by the architecture
3986
HAL. In other HALs, for example MIPS, it is provided in the variant
3987
HAL. The following option provides the name of the linker script to
3988
other elements in the configuration system.
3989
3990
 
3991
3992
    cdl_option CYGBLD_LINKER_SCRIPT {
3993
        display "Linker script"
3994
        flavor data
3995
        no_define
3996
        calculated  { "src/i386.ld" }
3997
    }
3998
3999
 
4000
4001
Finally, this interface indicates whether the platform supplied an
4002
implementation of the
4003
hal_i386_mem_real_region_top() function. If it
4004
does then it will contain a line of the form: implements
4005
CYGINT_HAL_I386_MEM_REAL_REGION_TOP. This allows packages
4006
such as RedBoot to detect the presence of this function so that they
4007
may call it.
4008
4009
 
4010
4011
 
4012
    cdl_interface CYGINT_HAL_I386_MEM_REAL_REGION_TOP {
4013
        display  "Implementations of hal_i386_mem_real_region_top()"
4014
    }
4015
 
4016
}
4017
4018
 
4019
4020
 
4021
4022
 
4023
4030
 
4031
4032
 
4033
4034
 
4035
4036
 
4037
4386
 
4387
 

powered by: WebSVN 2.1.0

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