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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [common/] [current/] [doc/] [porting.sgml] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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