i386_copy.c revision 38764
138712Smsmith/* 238712Smsmith * mjs copyright 338712Smsmith */ 438712Smsmith/* 538712Smsmith * MD primitives supporting placement of module data 638712Smsmith * 738712Smsmith * XXX should check load address/size against memory top. 838712Smsmith */ 938712Smsmith#include <stand.h> 1038712Smsmith 1138712Smsmith#include "libi386.h" 1238712Smsmith 1338712Smsmith#define READIN_BUF 4096 1438712Smsmith 1538712Smsmithint 1638712Smsmithi386_copyin(void *src, vm_offset_t dest, size_t len) 1738712Smsmith{ 1838712Smsmith vpbcopy(src, dest, len); 1938712Smsmith return(len); 2038712Smsmith} 2138712Smsmith 2238712Smsmithint 2338764Smsmithi386_copyout(vm_offset_t src, void *dest, size_t len) 2438764Smsmith{ 2538764Smsmith pvbcopy(src, dest, len); 2638764Smsmith return(len); 2738764Smsmith} 2838764Smsmith 2938764Smsmith 3038764Smsmithint 3138712Smsmithi386_readin(int fd, vm_offset_t dest, size_t len) 3238712Smsmith{ 3338712Smsmith void *buf; 3438712Smsmith size_t resid, chunk, get, got; 3538712Smsmith 3638712Smsmith chunk = min(READIN_BUF, len); 3738712Smsmith buf = malloc(chunk); 3838712Smsmith if (buf == NULL) 3938712Smsmith return(0); 4038712Smsmith 4138712Smsmith for (resid = len; resid > 0; resid -= got, dest += got) { 4238712Smsmith get = min(chunk, resid); 4338712Smsmith got = read(fd, buf, get); 4438712Smsmith if (got <= 0) 4538712Smsmith break; 4638712Smsmith vpbcopy(buf, dest, chunk); 4738712Smsmith } 4838712Smsmith free(buf); 4938712Smsmith if (resid != 0) 5038712Smsmith printf("i386_readin: %d bytes short\n", resid); 5138712Smsmith return(len - resid); 5238712Smsmith} 5338712Smsmith 5438712Smsmith 55