Sapphire SoC DS Sapphire SoC UG Sapphire HP SoC DS Sapphire HP SoC UG RISC-V Embedded IDE UG Board Support Package
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
48#define RISCV_SEMIHOSTING_CALL_NUMBER 7
80
81static inline int __attribute__ ((always_inline)) call_host(int reason, void* arg) {
82 register int value asm ("a0") = reason;
83 register void* ptr asm ("a1") = arg;
84 asm volatile (
85 " .option push \n"
86 // Force non-compressed RISC-V instructions
87 " .option norvc \n"
88 // Force 16-byte alignment to make sure that the 3 instructions fall
89 // within the same virtual page.
90 // Note: align 4 means, align by 2 to the power of 4!
91 " .align 4 \n"
92 " slli x0, x0, 0x1f \n"
93 " ebreak \n"
94 " srai x0, x0, %[swi] \n"
95 " .option pop \n"
96 " nop \n"
97 : "=r" (value) /* Outputs */
98 : "0" (value), "r" (ptr), [swi] "i" (RISCV_SEMIHOSTING_CALL_NUMBER) /* Inputs */
99 : "memory" /* Clobbers */
100 );
101 return value;
102}
103
104static void sh_write0(char* buf)
105{
106 // Print zero-terminated string
107 call_host(SEMIHOSTING_SYS_WRITE0, (void*) buf);
108}
109
110static void sh_writec(char c)
111{
112 // Print single character
113 call_host(SEMIHOSTING_SYS_WRITEC, (void*)&c);
114}
115
116static char sh_readc(void)
117{
118 // Read character - Blocking operation!
119 return call_host(SEMIHOSTING_SYS_READC, (void*)0);
120}
121
122
123#endif // EFX_SEMIHOSTING_H
#define RISCV_SEMIHOSTING_CALL_NUMBER
Definition semihosting.h:48
semihosting_operation_numbers
Definition semihosting.h:49
@ SEMIHOSTING_SYS_TICKFREQ
Definition semihosting.h:73
@ SEMIHOSTING_SYS_EXIT
Definition semihosting.h:59
@ SEMIHOSTING_SYS_ISERROR
Definition semihosting.h:64
@ SEMIHOSTING_SYS_WRITE
Definition semihosting.h:76
@ SEMIHOSTING_SYS_FLEN
Definition semihosting.h:61
@ SEMIHOSTING_SYS_GET_CMDLINE
Definition semihosting.h:62
@ SEMIHOSTING_SYS_EXIT_EXTENDED
Definition semihosting.h:60
@ SEMIHOSTING_SYS_REMOVE
Definition semihosting.h:69
@ SEMIHOSTING_SYS_SEEK
Definition semihosting.h:71
@ SEMIHOSTING_SYS_TMPNAM
Definition semihosting.h:75
@ SEMIHOSTING_SYS_TIME
Definition semihosting.h:74
@ SEMIHOSTING_SYS_CLOCK
Definition semihosting.h:56
@ SEMIHOSTING_SYS_WRITEC
Definition semihosting.h:77
@ SEMIHOSTING_SYS_ERRNO
Definition semihosting.h:58
@ SEMIHOSTING_SYS_ISTTY
Definition semihosting.h:65
@ SEMIHOSTING_SYS_HEAPINFO
Definition semihosting.h:63
@ SEMIHOSTING_SYS_WRITE0
Definition semihosting.h:78
@ SEMIHOSTING_SYS_ELAPSED
Definition semihosting.h:57
@ SEMIHOSTING_SYS_READ
Definition semihosting.h:67
@ SEMIHOSTING_SYS_SYSTEM
Definition semihosting.h:72
@ SEMIHOSTING_SYS_CLOSE
Definition semihosting.h:55
@ SEMIHOSTING_SYS_READC
Definition semihosting.h:68
@ SEMIHOSTING_SYS_OPEN
Definition semihosting.h:66
@ SEMIHOSTING_SYS_RENAME
Definition semihosting.h:70
@ SEMIHOSTING_ENTER_SVC
Definition semihosting.h:53