2 * Copyright 1997 by UCHIYAMA Yasushi
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of UCHIYAMA Yasushi not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. UCHIYAMA Yasushi makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
14 * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
23 #ifdef HAVE_XORG_CONFIG_H
24 #include <xorg-config.h>
28 #include<device/device.h>
29 #include<mach/machine/mach_i386.h>
36 #include "xf86_OSlib.h"
38 #define BIOS_SIZE 0x20000
41 xf86ReadBIOS(unsigned long Base
, unsigned long Offset
, unsigned char *Buf
,
44 mach_port_t device
, mem_dev
;
45 memory_object_t mem_obj
;
46 vm_address_t addr
= (vm_address_t
) 0; /* serach starting address */
49 err
= get_privileged_ports(NULL
, &device
);
52 FatalError("xf86ReadBIOS() can't get_privileged_ports. (%s)\n",
55 err
= device_open(device
, D_READ
| D_WRITE
, "mem", &mem_dev
);
56 mach_port_deallocate(mach_task_self(), device
);
59 FatalError("xf86ReadBIOS() can't device_open. (%s)\n", strerror(errno
));
62 device_map(mem_dev
, VM_PROT_READ
| VM_PROT_WRITE
, Base
, BIOS_SIZE
,
66 FatalError("xf86ReadBIOS() can't device_map. (%s)\n", strerror(errno
));
68 err
= vm_map(mach_task_self(),
76 VM_PROT_READ
| VM_PROT_WRITE
,
77 VM_PROT_READ
| VM_PROT_WRITE
, VM_INHERIT_SHARE
);
78 mach_port_deallocate(mach_task_self(), mem_obj
);
81 FatalError("xf86ReadBIOS() can't vm_map. (%s)\n", strerror(errno
));
84 memcpy(Buf
, (void *) ((int) addr
+ Offset
), Len
);
86 err
= vm_deallocate(mach_task_self(), addr
, BIOS_SIZE
);
89 FatalError("xf86ReadBIOS() can't vm_deallocate. (%s)\n",