NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32_semihosting.h
Go to the documentation of this file.
1// ================================================================================ //
2// The NEORV32 RISC-V Processor - https://github.com/stnolting/neorv32 //
3// Copyright (c) NEORV32 contributors. //
4// Copyright (c) 2020 - 2025 Stephan Nolting. All rights reserved. //
5// Licensed under the BSD-3-Clause license, see LICENSE for details. //
6// SPDX-License-Identifier: BSD-3-Clause //
7// ================================================================================ //
8
13
14#ifndef NEORV32_SEMIHOSTING_H
15#define NEORV32_SEMIHOSTING_H
16
17#include <stdint.h>
18
19
20/**********************************************************************/
50
51
52
53/**********************************************************************/
58enum SEMIHOST_OPEN_MODE_enum {
59 SEMIHOSTING_OPEN_R = 0,
60 SEMIHOSTING_OPEN_RB = 1,
61 SEMIHOSTING_OPEN_R_PLUS = 2,
62 SEMIHOSTING_OPEN_RB_PLUS = 3,
63 SEMIHOSTING_OPEN_W = 4,
64 SEMIHOSTING_OPEN_WB = 5,
65 SEMIHOSTING_OPEN_W_PLUS = 6,
66 SEMIHOSTING_OPEN_WB_PLUS = 7,
67 SEMIHOSTING_OPEN_A = 8,
68 SEMIHOSTING_OPEN_AB = 9,
69 SEMIHOSTING_OPEN_A_PLUS = 10,
70 SEMIHOSTING_OPEN_AB_PLUS = 11
71};
73
74
75/**********************************************************************/
79void neorv32_semihosting_putc(char c);
80void neorv32_semihosting_puts(const char* pnt);
82//
83int neorv32_semihosting_open(char *path, int mode);
84int neorv32_semihosting_close(int file);
85int neorv32_semihosting_write(int file, char *buffer, int len);
86int neorv32_semihosting_read(int file, char *buffer, int len);
87int neorv32_semihosting_istty(int file);
88int neorv32_semihosting_seek(int file, int pos);
89int neorv32_semihosting_flen(int file);
91int neorv32_semihosting_system(char *cmd);
93
94
95/**********************************************************************/
102inline int __attribute__ ((always_inline)) neorv32_semihosting_req(int id, void* arg) {
103
104 register int value asm ("a0") = id;
105 register void* data asm ("a1") = arg;
106 asm volatile (
107 " .option push \n"
108 " .option norvc \n" // we need 32-bit instruction words here
109 " .align 4 \n" // this has to be aligned
110 " slli x0, x0, 0x1f \n" // magic triplet: entry NOP
111 " ebreak \n" // magic triplet: break to debugger
112 " srai x0, x0, 0x07 \n" // magic triplet: exit NOP
113 " .option pop \n"
114 : "=r" (value) : "0" (value), "r" (data) : "memory"
115 );
116 return value;
117}
118
119
120#endif // NEORV32_SEMIHOSTING_H
int neorv32_semihosting_istty(int file)
Definition neorv32_semihosting.c:119
int neorv32_semihosting_open(char *path, int mode)
Definition neorv32_semihosting.c:56
void neorv32_semihosting_puts(const char *pnt)
Definition neorv32_semihosting.c:32
int neorv32_semihosting_flen(int file)
Definition neorv32_semihosting.c:147
void neorv32_semihosting_putc(char c)
Definition neorv32_semihosting.c:22
SEMIHOSTING_SYS_enum
Definition neorv32_semihosting.h:26
@ SEMIHOSTING_SYS_TICKFREQ
Definition neorv32_semihosting.h:48
@ SEMIHOSTING_SYS_TMPNAME
Definition neorv32_semihosting.h:37
@ SEMIHOSTING_SYS_EXCEPTION
Definition neorv32_semihosting.h:46
@ SEMIHOSTING_SYS_WRITE
Definition neorv32_semihosting.h:31
@ SEMIHOSTING_SYS_FLEN
Definition neorv32_semihosting.h:36
@ SEMIHOSTING_SYS_GET_CMDLINE
Definition neorv32_semihosting.h:44
@ SEMIHOSTING_SYS_ELLAPSED
Definition neorv32_semihosting.h:47
@ SEMIHOSTING_SYS_REMOVE
Definition neorv32_semihosting.h:38
@ SEMIHOSTING_SYS_SEEK
Definition neorv32_semihosting.h:35
@ SEMIHOSTING_SYS_TIME
Definition neorv32_semihosting.h:41
@ SEMIHOSTING_SYS_CLOCK
Definition neorv32_semihosting.h:40
@ SEMIHOSTING_SYS_WRITEC
Definition neorv32_semihosting.h:29
@ SEMIHOSTING_SYS_ERRNO
Definition neorv32_semihosting.h:43
@ SEMIHOSTING_SYS_ISTTY
Definition neorv32_semihosting.h:34
@ SEMIHOSTING_SYS_HEAPINFO
Definition neorv32_semihosting.h:45
@ SEMIHOSTING_SYS_WRITE0
Definition neorv32_semihosting.h:30
@ SEMIHOSTING_SYS_READ
Definition neorv32_semihosting.h:32
@ SEMIHOSTING_SYS_SYSTEM
Definition neorv32_semihosting.h:42
@ SEMIHOSTING_SYS_CLOSE
Definition neorv32_semihosting.h:28
@ SEMIHOSTING_SYS_READC
Definition neorv32_semihosting.h:33
@ SEMIHOSTING_SYS_OPEN
Definition neorv32_semihosting.h:27
@ SEMIHOSTING_SYS_RENAME
Definition neorv32_semihosting.h:39
int neorv32_semihosting_time(void)
Definition neorv32_semihosting.c:159
int neorv32_semihosting_system(char *cmd)
Definition neorv32_semihosting.c:172
int neorv32_semihosting_close(int file)
Definition neorv32_semihosting.c:71
int neorv32_semihosting_read(int file, char *buffer, int len)
Definition neorv32_semihosting.c:103
int neorv32_semihosting_seek(int file, int pos)
Definition neorv32_semihosting.c:133
int neorv32_semihosting_write(int file, char *buffer, int len)
Definition neorv32_semihosting.c:86
char neorv32_semihosting_getc(void)
Definition neorv32_semihosting.c:44
int neorv32_semihosting_req(int id, void *arg)
Definition neorv32_semihosting.h:102