Skip to content

Commit 664ea52

Browse files
Merge branch 'arc-dev' into arc-staging
2 parents f00008d + 51d162a commit 664ea52

File tree

2 files changed

+69
-22
lines changed

2 files changed

+69
-22
lines changed

doc/baremetal/hostlink.rst

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,78 @@ in the case of simplest applications that do not use system IO, there is still
2020
a need to provide implementation of ``_exit()`` either through linking with some
2121
libgloss implementation or by implementing it right in the application.
2222

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
2955
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!
3759
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.
4187

4288
To use a generic libnosys library, add option ``--specs=nosys.specs`` to gcc
4389
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.
4895

4996
If you are a chip and/or OS developer it is likely that you would want to
5097
provide a libgloss implementation appropriate for your case, because libnsim.a

release.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ $O/.stamp_elf_le_built: $(TOOLS_ALL_DEPS-y) | $(TOOLS_ALL_ORDER_DEPS-y)
572572
touch $@
573573

574574
$O/.stamp_elf_be_built: $(TOOLS_ALL_DEPS-y) | $(TOOLS_ALL_ORDER_DEPS-y)
575-
$(call copy_prebuilt,arc-arc700-linux-uclibc,$(TOOLS_ELFBE_HOST_DIR))
575+
$(call copy_prebuilt,arceb-multilib-elf32,$(TOOLS_ELFBE_HOST_DIR))
576576
$(call copy_pdf_doc_file,$O/$(TOOLS_ELFBE_HOST_DIR))
577577
touch $@
578578

@@ -764,7 +764,7 @@ linux-images: $O/$(LINUX_IMAGES_DIR)/$(LINUX_AXS103_ROOTFS_TAR)
764764
# Native toolchain build
765765
#
766766
$O/.stamp_glibc_le_hs_native_built: $(TOOLS_ALL_DEPS-y) | $(TOOLS_ALL_ORDER_DEPS-y)
767-
$(call copy_prebuilt,arceb-archs-linux-gnu,$(TOOLS_GLIBC_LE_HS_NATIVE_DIR))
767+
$(call copy_prebuilt,arc-archs-native-gnu,$(TOOLS_GLIBC_LE_HS_NATIVE_DIR))
768768
$(call copy_pdf_doc_file,$O/$(TOOLS_GLIBC_LE_HS_NATIVE_DIR))
769769
touch $@
770770

0 commit comments

Comments
 (0)