@@ -20,31 +20,78 @@ in the case of simplest applications that do not use system IO, there is still
20
20
a need to provide implementation of ``_exit() `` either through linking with some
21
21
libgloss implementation or by implementing it right in the application.
22
22
23
- Because libgloss implementation is often specific to a particular chip (nee
24
- :abbr: `BSP ( board support package ) `), Synopsys provides only two libgloss
25
- implementation as of now - libnsim, that supports nSIM GNU IO Hostlink and
26
- libnosys, which is really an architecture-agnostic implementation, that simply
27
- provides empty stubs for a few of the most used system functions - this is
28
- enough to link an application, however it may not function as expected.
23
+ libgloss implementation is often specific to a particular chip and runtime
24
+ configuration and it is not possible to cover them all in the toolchain
25
+ distribution. However, Synopsys provides several libgloss implementations
26
+ to cover as much usecases as possible. The libgloss implementation can be
27
+ selected with the ``--specs `` gcc option. Consider three most useful libgloss
28
+ implementations.
29
+
30
+ 1. ``nsim.specs `` implements nSIM GNU IO Hostlink. It works via software
31
+ exceptions, just like the syscalls in real OS - when target application needs
32
+ something to be done by the hostlink, it causes a software exception with
33
+ parameters that specify what action is required. nSIM intercepts those
34
+ exceptions and handles them. The advantage of this approach is that same
35
+ application binary can be used with other execution environments, which also
36
+ handle software exceptions - unlike the case where a system function
37
+ implementation is really baked inside the application binary. To use nSIM GNU
38
+ IO hostlink in an application, add option ``--specs=nsim.specs `` to gcc options
39
+ when linking - library ``libnsim.a `` will be linked in and will provide
40
+ implementations to those system level functions. For example, consider simple
41
+ program ``hello.c ``:
42
+
43
+ .. code-block :: c
44
+
45
+ #include <stdio.h>
46
+ int main()
47
+ {
48
+ printf("Hello World!\n");
49
+ return 0;
50
+ }
51
+
52
+ Let's build it for ARC HS with nSIM GNU IO Hostlink support and run in nSIM:
53
+
54
+ .. code-block :: text
29
55
30
- nSIM GNU IO Hostlink works via software exceptions, just like the syscalls in
31
- real OS - when target application needs something to be done by the hostlink,
32
- it causes a software exception with parameters that specify what action is
33
- required. nSIM intercepts those exceptions and handles them. The advantage of
34
- this approach is that same application binary can be used with other execution
35
- environments, which also handle software exceptions - unlike the case where a
36
- system function implementation is really baked inside the application binary.
56
+ $ arc-elf32-gcc -mcpu=hs --specs=nsim.specs ./hello.c -o hello
57
+ $ nsimdrv -prop=nsim_isa_family=av2hs -prop=nsim_emt=1 ./hello
58
+ Hello World!
37
59
38
- To use hostlink in application, add option ``--specs=nsim.specs `` to gcc options
39
- when linking - library libnsim.a will be linked in and will provide
40
- implementations to those system level functions
60
+ Please note ``-prop=nsim_emt=1 `` (emulate traps) option which enables nSIM GNU IO
61
+ Hostlink in nSIM. More details can be found in nSIM documentation.
62
+
63
+ 2. ``hl.specs `` implements Metaware Hostlink. It works via memory mailbox named
64
+ ``__HOSTLINK__ ``. The running application fills this mailbox and then debugger
65
+ or simulator executes requested system call. The advantage of this approach is
66
+ that the binary can be executed in the real hardware under Metaware Debugger.
67
+ If ``__HOSTLINK__ `` symbol is not available (binary is stripped, debugger
68
+ connects to the running target) correct address can be passed to Metaware
69
+ Debugger ``mdb `` through ``-prop=__HOSTLINK__=address `` option. To use Metaware
70
+ Hostlink, add option ``--specs=hl.specs `` to the linker. Let’s build and run
71
+ our ``hello.c `` with Metaware Hostlink:
72
+
73
+ .. code-block :: text
74
+
75
+ $ arc-elf32-gcc -mcpu=hs --specs=hl.specs ./hello.c -o hello
76
+ $ nsimdrv -prop=nsim_isa_family=av2hs -prop=nsim_hlink_gnu_io_ext=1 ./hello
77
+ Hello World!
78
+
79
+ Please note ``-prop=nsim_hlink_gnu_io_ext=1 `` option which enables some
80
+ additional system calls support in nSIM. Also make sure that ``-prop=nsim_emt ``
81
+ option is disabled in nSIM, because only one Hostlink type can be used at the
82
+ same time.
83
+
84
+ 3. ``nosys.specs ``, which is really an architecture-agnostic implementation, that
85
+ simply provides empty stubs for a few of the most used system functions - this is
86
+ enough to link an application, however it may not function as expected.
41
87
42
88
To use a generic libnosys library, add option ``--specs=nosys.specs `` to gcc
43
89
options when linking. Note that one of the important distinction between
44
- libnsim and libnosys is that ``_exit() `` implementation in libnosys is an
45
- infinite loop, while in libnsim it will halt the CPU core. As a result, at the
46
- end of an execution, application with libnosys will spin, while application
47
- with libnsim will halt.
90
+ hostlink libraries and ``libnosys `` is that ``_exit() `` implementation in
91
+ ``libnosys `` is an infinite loop, while in hostlink implementations it will halt
92
+ the CPU core. As a result, at the end of an execution, application with
93
+ ``libnosys `` will spin, while application with hostlink will halt. This spec file
94
+ is the default option.
48
95
49
96
If you are a chip and/or OS developer it is likely that you would want to
50
97
provide a libgloss implementation appropriate for your case, because libnsim.a
0 commit comments