2 * hl_read.c -- provide _read().
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 /* Read one chunk. Implements HL_SYSCALL_READ. */
29 _hl_read (int fd
, void *buf
, size_t count
)
34 volatile __uncached
char *p
;
36 p
= _hl_message (HL_SYSCALL_READ
, "ii:i",
37 (uint32_t) fd
, /* i */
38 (uint32_t) count
, /* i */
39 (uint32_t *) &hl_n
/* :i */);
48 p
= _hl_unpack_int (p
, &host_errno
);
49 errno
= p
== NULL
? EIO
: host_errno
;
56 p
= _hl_unpack_ptr (p
, buf
, &n
);
59 if (p
== NULL
|| n
!= (uint32_t) hl_n
)
72 _read (int fd
, void *buf
, size_t count
)
74 const uint32_t hl_iochunk
= _hl_iochunk_size ();
75 size_t to_read
= count
;
79 while (to_read
> hl_iochunk
)
81 ret
= _hl_read (fd
, (char *) buf
+ offset
, hl_iochunk
);
88 if (ret
!= (ssize_t
) hl_iochunk
)
91 to_read
-= hl_iochunk
;
96 ret
= _hl_read (fd
, (char *) buf
+ offset
, to_read
);