MOS Source Code
Loading...
Searching...
No Matches
sbi-call.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
4
5#include <mos/types.h>
6#include <mos_string.h>
7
8typedef struct
9{
10 long error;
11 long value;
12} sbiret_t;
13
14static sbiret_t sbi_ecall(int ext, int fid, ulong arg0, ulong arg1, ulong arg2, ulong arg3, ulong arg4, ulong arg5)
15{
16 sbiret_t ret;
17
18 register ptr_t a0 __asm__("a0") = (ptr_t) (arg0);
19 register ptr_t a1 __asm__("a1") = (ptr_t) (arg1);
20 register ptr_t a2 __asm__("a2") = (ptr_t) (arg2);
21 register ptr_t a3 __asm__("a3") = (ptr_t) (arg3);
22 register ptr_t a4 __asm__("a4") = (ptr_t) (arg4);
23 register ptr_t a5 __asm__("a5") = (ptr_t) (arg5);
24 register ptr_t a6 __asm__("a6") = (ptr_t) (fid);
25 register ptr_t a7 __asm__("a7") = (ptr_t) (ext);
26 __asm__ volatile("ecall" : "+r"(a0), "+r"(a1) : "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6), "r"(a7) : "memory");
27 ret.error = a0;
28 ret.value = a1;
29
30 return ret;
31}
32
33// Function Name SBI Version FID EID
34// sbi_debug_console_write 2 0 0x4442434E
35// sbi_debug_console_read 2 1 0x4442434E
36// sbi_debug_console_write_byte 2 2 0x4442434E
37
38#define SBI_DEBUG_CONSOLE_EID 0x4442434E
39#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1
40
41void sbi_putchar(char ch)
42{
43 sbi_ecall(SBI_EXT_0_1_CONSOLE_PUTCHAR, 0, ch, 0, 0, 0, 0, 0);
44}
45
46size_t sbi_putstring(const char *str)
47{
48 size_t len = strlen(str);
49 for (size_t i = 0; i < len; i++)
50 sbi_putchar(str[i]);
51
52 return len;
53}
static size_t strlen(const char *s)
Definition pb_syshdr.h:80
size_t sbi_putstring(const char *str)
Definition sbi-call.c:46
#define SBI_EXT_0_1_CONSOLE_PUTCHAR
Definition sbi-call.c:39
static sbiret_t sbi_ecall(int ext, int fid, ulong arg0, ulong arg1, ulong arg2, ulong arg3, ulong arg4, ulong arg5)
Definition sbi-call.c:14
void sbi_putchar(char ch)
Definition sbi-call.c:41
long error
Definition sbi-call.c:10
long value
Definition sbi-call.c:11
unsigned long ulong
Definition types.h:22
unsigned long ptr_t
Definition types.h:25