mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-08 18:19:08 +08:00
2c46bffba0
Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com>
3.6 KiB
3.6 KiB
MetaWare Hostlink IO
Target program can use MetaWare hostlink interface to send messages to nSIM simulator or MDB debugger.
Quick Start
To link with MetaWare hostlink library use -specs=hl.specs
with baremetal
version of GCC for ARC processors - arc-elf32-gcc
for ARCv1/2 targets or
arc64-elf-gcc
for ARCv3 targets.
Consider this sample program named hello.c
:
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
Build and run it for HS3x/4x targets:
$ arc-elf32-gcc -mcpu=hs -specs=hl.specs hello.c -o hello.elf
$ nsimdrv -tcf $NSIM_HOME/etc/tcf/templates/hs48_full.tcf -p nsim_hostlink=1 hello.elf
Hello, World!
Build and run it for HS5x targets:
$ arc64-elf-gcc -mcpu=hs5x -specs=hl.specs hello.c -o hello.elf
$ nsimdrv -tcf $NSIM_HOME/etc/tcf/templates/hs58_full.tcf -p nsim_hostlink=1 hello.elf
Hello, World!
Build and run it for HS6x targets:
$ arc64-elf-gcc -mcpu=hs6x -specs=hl.specs hello.c -o hello.elf
$ nsimdrv -tcf $NSIM_HOME/etc/tcf/templates/hs68_full.tcf -p nsim_hostlink=1 hello.elf
Hello, World!
Contents
hl/hl_gw.*
- Hostlink gateway. This API is used in thehl_api.*
. Please usehl_message()
fromhl_api.*
for hostlink message exchange.hl/hl_api.*
- High-level API to send hostlink messages, as well as functions to work with messages.hl/hl_<syscall>.*
- System calls implementations through hostlink API.arc-timer.*
- Provides API to access ARC timers. Used byhl/hl_clock.c
in_clock()
implementation.arc-main-helper.c
- Provides__setup_argv_and_call_main()
. The function is called from__start()
incrt0.S
. It allows to setupargc
andarvg
as well as some custom things through_setup_low_level()
.hl-setup.c
- Provides_setup_low_level()
for hostlink case. It just configures default timer if it exists. Default timer is used in the hostlinkclock()
implementation.hl-stub.c
- Provides functions which are part of newlib but implemented without hostlink. For example,_kill()
and_getpid()
.sbrk.c
- Provides_sbrk()
. It uses__start_heap
and__end_heap
variables.libcfunc.c
- Additional C system calls.mcount.c
- Profiler support.
How It Works
Simulator looks for __HOSTLINK__
and _hl_blockedPeek()
symbols.
__HOSTLINK__
is the start of shared structure for message exchange and
_hl_blockedPeek()
is a function to be called when program is waiting
for simulator response.
When program wants to send a message it should follow:
- Fill
__HOSTLINK__.payload
with packed data. Packing format is following:{u16 type, u16 size, char data[]}
. Supported types arechar
,short
,int
,string
andint64
.hl_api
provides high-level API to this. - Fill
__HOSTLINK__.pkt_hdr
. Seehl_pkt_init()
fromhl_gw.c
. - Fill
__HOSTLINK__.hdr
. Seehl_send()
fromhl_gw.c
. - Call
_hl_blockedPeek()
to get response. At this point message should be delivered to debugger. Some implementations uses change of__HOSTLINK__.hdr.target2host_addr
as a signal that packet is sent and can be processed. Other implementations wait for_hl_blockedPeek()
to be called. It means that portable implementation must fill__HOSTLINK__.hdr.target2host_addr
at the last step and then call_hl_blockedPeek()
. _hl_blockedPeek()
returns pointer to debugger response which can be processed on target if needed. Because debugger and target share the same buffer the function actually returns__HOSTLINK__.payload
that was filled with packed data (see step 1) by the debugger.