RV32 SoC DS UG
High-Perf RV32 SoC DS UG
RV64 SoC DS UG API and Examples
Embedded IDE UG
Loading...
Searching...
No Matches
semihosting.h
Go to the documentation of this file.
1
2// Copyright (C) 2013-2023 Efinix Inc. All rights reserved.
3//
4// This document contains proprietary information which is
5// protected by copyright. All rights are reserved. This notice
6// refers to original work by Efinix, Inc. which may be derivitive
7// of other work distributed under license of the authors. In the
8// case of derivative work, nothing in this notice overrides the
9// original author's license agreement. Where applicable, the
10// original license agreement is included in it's original
11// unmodified form immediately below this header.
12//
13// WARRANTY DISCLAIMER.
14// THE DESIGN, CODE, OR INFORMATION ARE PROVIDED “AS IS” AND
15// EFINIX MAKES NO WARRANTIES, EXPRESS OR IMPLIED WITH
16// RESPECT THERETO, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES,
17// INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18// MERCHANTABILITY, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR
19// PURPOSE. SOME STATES DO NOT ALLOW EXCLUSIONS OF AN IMPLIED
20// WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO LICENSEE.
21//
22// LIMITATION OF LIABILITY.
23// NOTWITHSTANDING ANYTHING TO THE CONTRARY, EXCEPT FOR BODILY
24// INJURY, EFINIX SHALL NOT BE LIABLE WITH RESPECT TO ANY SUBJECT
25// MATTER OF THIS AGREEMENT UNDER TORT, CONTRACT, STRICT LIABILITY
26// OR ANY OTHER LEGAL OR EQUITABLE THEORY (I) FOR ANY INDIRECT,
27// SPECIAL, INCIDENTAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES OF ANY
28// CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF
29// GOODWILL, DATA OR PROFIT, WORK STOPPAGE, OR COMPUTER FAILURE OR
30// MALFUNCTION, OR IN ANY EVENT (II) FOR ANY AMOUNT IN EXCESS, IN
31// THE AGGREGATE, OF THE FEE PAID BY LICENSEE TO EFINIX HEREUNDER
32// (OR, IF THE FEE HAS BEEN WAIVED, $100), EVEN IF EFINIX SHALL HAVE
33// BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO
34// NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
35// CONSEQUENTIAL DAMAGES, SO THIS LIMITATION AND EXCLUSION MAY NOT
36// APPLY TO LICENSEE.
37//
39
40#ifndef EFX_SEMIHOSTING_H
41#define EFX_SEMIHOSTING_H
42
43
44#include "bsp.h"
45#include "vexriscv.h"
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51#define RISCV_SEMIHOSTING_CALL_NUMBER 7
83
84static inline int __attribute__ ((always_inline)) call_host(int reason, void* arg) {
85 register int value asm ("a0") = reason;
86 register void* ptr asm ("a1") = arg;
87 asm volatile (
88 " .option push \n"
89 // Force non-compressed RISC-V instructions
90 " .option norvc \n"
91 // Force 16-byte alignment to make sure that the 3 instructions fall
92 // within the same virtual page.
93 // Note: align 4 means, align by 2 to the power of 4!
94 " .align 4 \n"
95 " slli x0, x0, 0x1f \n"
96 " ebreak \n"
97 " srai x0, x0, %[swi] \n"
98 " .option pop \n"
99 " nop \n"
100 : "=r" (value) /* Outputs */
101 : "0" (value), "r" (ptr), [swi] "i" (RISCV_SEMIHOSTING_CALL_NUMBER) /* Inputs */
102 : "memory" /* Clobbers */
103 );
104 return value;
105}
106
107static void sh_write0(char* buf)
108{
109 // Print zero-terminated string
110 call_host(SEMIHOSTING_SYS_WRITE0, (void*) buf);
111}
112
113static void sh_writec(char c)
114{
115 // Print single character
116 call_host(SEMIHOSTING_SYS_WRITEC, (void*)&c);
117}
118
119static char sh_readc(void)
120{
121 // Read character - Blocking operation!
122 return call_host(SEMIHOSTING_SYS_READC, (void*)0);
123}
124
125#ifdef __cplusplus
126}
127#endif // C_plusplus
128
129#endif // EFX_SEMIHOSTING_H
Board Support Package API definitions.
#define RISCV_SEMIHOSTING_CALL_NUMBER
Definition semihosting.h:51
semihosting_operation_numbers
Definition semihosting.h:52
@ SEMIHOSTING_SYS_TICKFREQ
Definition semihosting.h:76
@ SEMIHOSTING_SYS_EXIT
Definition semihosting.h:62
@ SEMIHOSTING_SYS_ISERROR
Definition semihosting.h:67
@ SEMIHOSTING_SYS_WRITE
Definition semihosting.h:79
@ SEMIHOSTING_SYS_FLEN
Definition semihosting.h:64
@ SEMIHOSTING_SYS_GET_CMDLINE
Definition semihosting.h:65
@ SEMIHOSTING_SYS_EXIT_EXTENDED
Definition semihosting.h:63
@ SEMIHOSTING_SYS_REMOVE
Definition semihosting.h:72
@ SEMIHOSTING_SYS_SEEK
Definition semihosting.h:74
@ SEMIHOSTING_SYS_TMPNAM
Definition semihosting.h:78
@ SEMIHOSTING_SYS_TIME
Definition semihosting.h:77
@ SEMIHOSTING_SYS_CLOCK
Definition semihosting.h:59
@ SEMIHOSTING_SYS_WRITEC
Definition semihosting.h:80
@ SEMIHOSTING_SYS_ERRNO
Definition semihosting.h:61
@ SEMIHOSTING_SYS_ISTTY
Definition semihosting.h:68
@ SEMIHOSTING_SYS_HEAPINFO
Definition semihosting.h:66
@ SEMIHOSTING_SYS_WRITE0
Definition semihosting.h:81
@ SEMIHOSTING_SYS_ELAPSED
Definition semihosting.h:60
@ SEMIHOSTING_SYS_READ
Definition semihosting.h:70
@ SEMIHOSTING_SYS_SYSTEM
Definition semihosting.h:75
@ SEMIHOSTING_SYS_CLOSE
Definition semihosting.h:58
@ SEMIHOSTING_SYS_READC
Definition semihosting.h:71
@ SEMIHOSTING_SYS_OPEN
Definition semihosting.h:69
@ SEMIHOSTING_SYS_RENAME
Definition semihosting.h:73
@ SEMIHOSTING_ENTER_SVC
Definition semihosting.h:56