2 * hl_write.c -- provide _write().
4 * Copyright (c) 2024 Synopsys Inc.
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
23 #include "hl_toolchain.h"
27 /* Write one chunk to the host file. Implements HL_SYSCALL_WRITE. */
29 _hl_write (int fd
, const char *buf
, size_t nbyte
)
34 volatile __uncached
char *p
;
36 p
= _hl_message (HL_SYSCALL_WRITE
, "ipi:ii",
37 (uint32_t) fd
, /* i */
38 buf
, (uint32_t) nbyte
, /* p */
39 (uint32_t) nbyte
, /* i */
40 (uint32_t *) &n
, /* :i */
41 (uint32_t *) &host_errno
/* :i */);
64 _write (int fd
, const char *buf
, size_t nbyte
)
66 const uint32_t hl_iochunk
= _hl_iochunk_size ();
67 size_t to_write
= nbyte
;
71 while (to_write
> hl_iochunk
)
73 ret
= _hl_write (fd
, buf
+ offset
, hl_iochunk
);
80 if (ret
!= (ssize_t
) hl_iochunk
)
83 to_write
-= hl_iochunk
;
88 ret
= _hl_write (fd
, buf
+ offset
, to_write
);