155211Smsmith/*-
255211Smsmith * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
355211Smsmith * All rights reserved.
455211Smsmith *
555211Smsmith * Redistribution and use in source and binary forms, with or without
655211Smsmith * modification, are permitted provided that the following conditions
755211Smsmith * are met:
855211Smsmith * 1. Redistributions of source code must retain the above copyright
955211Smsmith *    notice, this list of conditions and the following disclaimer.
1055211Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1155211Smsmith *    notice, this list of conditions and the following disclaimer in the
1255211Smsmith *    documentation and/or other materials provided with the distribution.
1355211Smsmith *
1455211Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1555211Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1655211Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1755211Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1855211Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1955211Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2055211Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2155211Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2255211Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2355211Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2455211Smsmith * SUCH DAMAGE.
2538712Smsmith */
2655211Smsmith
27119482Sobrien#include <sys/cdefs.h>
28119482Sobrien__FBSDID("$FreeBSD: stable/11/stand/i386/libi386/i386_copy.c 153589 2005-12-21 02:17:58Z sobomax $");
29119482Sobrien
3038712Smsmith/*
3138712Smsmith * MD primitives supporting placement of module data
3238712Smsmith *
3338712Smsmith * XXX should check load address/size against memory top.
3438712Smsmith */
3538712Smsmith#include <stand.h>
3638712Smsmith
3738712Smsmith#include "libi386.h"
3839441Smsmith#include "btxv86.h"
3938712Smsmith
4064187Sjhbssize_t
4164187Sjhbi386_copyin(const void *src, vm_offset_t dest, const size_t len)
4238712Smsmith{
4355211Smsmith    if (dest + len >= memtop) {
4455211Smsmith	errno = EFBIG;
4555211Smsmith	return(-1);
4655211Smsmith    }
4739441Smsmith
4839441Smsmith    bcopy(src, PTOV(dest), len);
4938712Smsmith    return(len);
5038712Smsmith}
5138712Smsmith
5264187Sjhbssize_t
5364187Sjhbi386_copyout(const vm_offset_t src, void *dest, const size_t len)
5438764Smsmith{
5555211Smsmith    if (src + len >= memtop) {
5655211Smsmith	errno = EFBIG;
5755211Smsmith	return(-1);
5855211Smsmith    }
5939441Smsmith
6039441Smsmith    bcopy(PTOV(src), dest, len);
6138764Smsmith    return(len);
6238764Smsmith}
6338764Smsmith
6438764Smsmith
6564187Sjhbssize_t
6664187Sjhbi386_readin(const int fd, vm_offset_t dest, const size_t len)
6738712Smsmith{
6838712Smsmith
69153589Ssobomax    if (dest + len >= memtop_copyin) {
70153535Ssobomax	errno = EFBIG;
71153535Ssobomax	return(-1);
72153535Ssobomax    }
7339441Smsmith
74153535Ssobomax    return (read(fd, PTOV(dest), len));
7538712Smsmith}
76