1998-08-31 21:10:43 +00:00
|
|
|
/*
|
|
|
|
* mjs copyright
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* MD primitives supporting placement of module data
|
|
|
|
*
|
|
|
|
* XXX should check load address/size against memory top.
|
|
|
|
*/
|
|
|
|
#include <stand.h>
|
|
|
|
|
|
|
|
#include "libi386.h"
|
1998-09-17 23:52:16 +00:00
|
|
|
#include "btxv86.h"
|
1998-08-31 21:10:43 +00:00
|
|
|
|
|
|
|
#define READIN_BUF 4096
|
|
|
|
|
|
|
|
int
|
|
|
|
i386_copyin(void *src, vm_offset_t dest, size_t len)
|
|
|
|
{
|
1998-09-17 23:52:16 +00:00
|
|
|
if (dest + len >= memtop)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
bcopy(src, PTOV(dest), len);
|
1998-08-31 21:10:43 +00:00
|
|
|
return(len);
|
|
|
|
}
|
|
|
|
|
1998-09-03 02:10:09 +00:00
|
|
|
int
|
|
|
|
i386_copyout(vm_offset_t src, void *dest, size_t len)
|
|
|
|
{
|
1998-09-17 23:52:16 +00:00
|
|
|
if (src + len >= memtop)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
bcopy(PTOV(src), dest, len);
|
1998-09-03 02:10:09 +00:00
|
|
|
return(len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-31 21:10:43 +00:00
|
|
|
int
|
|
|
|
i386_readin(int fd, vm_offset_t dest, size_t len)
|
|
|
|
{
|
|
|
|
void *buf;
|
|
|
|
size_t resid, chunk, get, got;
|
|
|
|
|
1998-09-17 23:52:16 +00:00
|
|
|
if (dest + len >= memtop)
|
|
|
|
return(0);
|
|
|
|
|
1998-08-31 21:10:43 +00:00
|
|
|
chunk = min(READIN_BUF, len);
|
|
|
|
buf = malloc(chunk);
|
|
|
|
if (buf == NULL)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
for (resid = len; resid > 0; resid -= got, dest += got) {
|
|
|
|
get = min(chunk, resid);
|
|
|
|
got = read(fd, buf, get);
|
|
|
|
if (got <= 0)
|
|
|
|
break;
|
1998-09-28 22:04:54 +00:00
|
|
|
bcopy(buf, PTOV(dest), got);
|
1998-08-31 21:10:43 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
return(len - resid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|