#include <sys/promif.h>
#include <sys/promimpl.h>
int
prom_open(char *path)
{
cell_t ci[5];
promif_owrap_t *ow;
#ifdef PROM_32BIT_ADDRS
char *opath = NULL;
size_t len;
if ((uintptr_t)path > (uint32_t)-1) {
opath = path;
len = prom_strlen(opath) + 1;
path = promplat_alloc(len);
if (path == NULL)
return (0);
(void) prom_strcpy(path, opath);
}
#endif
ow = promif_preout();
promif_preprom();
ci[0] = p1275_ptr2cell("open");
ci[1] = (cell_t)1;
ci[2] = (cell_t)1;
ci[3] = p1275_ptr2cell(path);
ci[4] = (cell_t)0;
(void) p1275_cif_handler(&ci);
promif_postprom();
promif_postout(ow);
#ifdef PROM_32BIT_ADDRS
if (opath != NULL)
promplat_free(path, len);
#endif
return (p1275_cell2int(ci[4]));
}
int
prom_seek(int fd, unsigned long long offset)
{
cell_t ci[7];
ci[0] = p1275_ptr2cell("seek");
ci[1] = (cell_t)3;
ci[2] = (cell_t)1;
ci[3] = p1275_uint2cell((uint_t)fd);
ci[4] = p1275_ull2cell_high(offset);
ci[5] = p1275_ull2cell_low(offset);
ci[6] = (cell_t)-1;
promif_preprom();
(void) p1275_cif_handler(&ci);
promif_postprom();
return (p1275_cell2int(ci[6]));
}
ssize_t
prom_read(ihandle_t fd, caddr_t buf, size_t len, uint_t startblk, char devtype)
{
cell_t ci[7];
promif_owrap_t *ow;
#ifdef PROM_32BIT_ADDRS
caddr_t obuf = NULL;
if ((uintptr_t)buf > (uint32_t)-1) {
obuf = buf;
buf = promplat_alloc(len);
if (buf == NULL)
return (-1);
}
#endif
ow = promif_preout();
promif_preprom();
ci[0] = p1275_ptr2cell("read");
ci[1] = (cell_t)3;
ci[2] = (cell_t)1;
ci[3] = p1275_size2cell((uint_t)fd);
ci[4] = p1275_ptr2cell(buf);
ci[5] = p1275_uint2cell(len);
ci[6] = (cell_t)-1;
(void) p1275_cif_handler(&ci);
promif_postprom();
promif_postout(ow);
#ifdef PROM_32BIT_ADDRS
if (obuf != NULL) {
promplat_bcopy(buf, obuf, len);
promplat_free(buf, len);
}
#endif
return (p1275_cell2size(ci[6]));
}
ssize_t
prom_write(ihandle_t fd, caddr_t buf, size_t len, uint_t startblk, char devtype)
{
cell_t ci[7];
promif_owrap_t *ow;
ssize_t rlen;
#ifdef PROM_32BIT_ADDRS
caddr_t obuf = NULL;
static char smallbuf[256];
ASSERT(buf);
#endif
if (promif_redirect != NULL && fd == prom_stdout_ihandle()) {
ow = promif_preout();
rlen = promif_redirect(promif_redirect_arg, (uchar_t *)buf,
len);
promif_postout(ow);
return (rlen);
}
#ifdef PROM_32BIT_ADDRS
if ((uintptr_t)buf > (uint32_t)-1) {
if (len > sizeof (smallbuf)) {
obuf = buf;
buf = promplat_alloc(len);
if (buf == NULL) {
return (-1);
}
promplat_bcopy(obuf, buf, len);
}
}
#endif
ow = promif_preout();
promif_preprom();
#ifdef PROM_32BIT_ADDRS
if ((uintptr_t)buf > (uint32_t)-1) {
if (len <= sizeof (smallbuf)) {
promplat_bcopy(buf, smallbuf, len);
buf = smallbuf;
}
}
#endif
ci[0] = p1275_ptr2cell("write");
ci[1] = (cell_t)3;
ci[2] = (cell_t)1;
ci[3] = p1275_uint2cell((uint_t)fd);
ci[4] = p1275_ptr2cell(buf);
ci[5] = p1275_size2cell(len);
ci[6] = (cell_t)-1;
(void) p1275_cif_handler(&ci);
rlen = p1275_cell2size(ci[6]);
promif_postprom();
promif_postout(ow);
#ifdef PROM_32BIT_ADDRS
if (obuf != NULL)
promplat_free(buf, len);
#endif
return (rlen);
}
int
prom_close(int fd)
{
cell_t ci[4];
promif_owrap_t *ow;
ci[0] = p1275_ptr2cell("close");
ci[1] = (cell_t)1;
ci[2] = (cell_t)0;
ci[3] = p1275_uint2cell((uint_t)fd);
ow = promif_preout();
promif_preprom();
(void) p1275_cif_handler(&ci);
promif_postprom();
promif_postout(ow);
return (0);
}