debuggers.hg

view tools/libxc/xc_core_x86.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children 46f8fc57b1a4
line source
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 *
16 * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
17 * VA Linux Systems Japan K.K.
18 *
19 */
21 #include "xg_private.h"
22 #include "xc_core.h"
24 /* Don't yet support cross-address-size core dump */
25 #define guest_width (sizeof (unsigned long))
27 static int nr_gpfns(int xc_handle, domid_t domid)
28 {
29 return xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &domid) + 1;
30 }
32 int
33 xc_core_arch_auto_translated_physmap(const xc_dominfo_t *info)
34 {
35 return info->hvm;
36 }
38 int
39 xc_core_arch_memory_map_get(int xc_handle, struct xc_core_arch_context *unused,
40 xc_dominfo_t *info, shared_info_t *live_shinfo,
41 xc_core_memory_map_t **mapp,
42 unsigned int *nr_entries)
43 {
44 unsigned long p2m_size = nr_gpfns(xc_handle, info->domid);
45 xc_core_memory_map_t *map;
47 map = malloc(sizeof(*map));
48 if ( map == NULL )
49 {
50 PERROR("Could not allocate memory");
51 return -1;
52 }
54 map->addr = 0;
55 map->size = ((uint64_t)p2m_size) << PAGE_SHIFT;
57 *mapp = map;
58 *nr_entries = 1;
59 return 0;
60 }
62 int
63 xc_core_arch_map_p2m(int xc_handle, xc_dominfo_t *info,
64 shared_info_t *live_shinfo, xen_pfn_t **live_p2m,
65 unsigned long *pfnp)
66 {
67 /* Double and single indirect references to the live P2M table */
68 xen_pfn_t *live_p2m_frame_list_list = NULL;
69 xen_pfn_t *live_p2m_frame_list = NULL;
70 uint32_t dom = info->domid;
71 unsigned long p2m_size = nr_gpfns(xc_handle, info->domid);
72 int ret = -1;
73 int err;
75 if ( p2m_size < info->nr_pages )
76 {
77 ERROR("p2m_size < nr_pages -1 (%lx < %lx", p2m_size, info->nr_pages - 1);
78 goto out;
79 }
81 live_p2m_frame_list_list =
82 xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ,
83 live_shinfo->arch.pfn_to_mfn_frame_list_list);
85 if ( !live_p2m_frame_list_list )
86 {
87 PERROR("Couldn't map p2m_frame_list_list (errno %d)", errno);
88 goto out;
89 }
91 live_p2m_frame_list =
92 xc_map_foreign_pages(xc_handle, dom, PROT_READ,
93 live_p2m_frame_list_list,
94 P2M_FLL_ENTRIES);
96 if ( !live_p2m_frame_list )
97 {
98 PERROR("Couldn't map p2m_frame_list");
99 goto out;
100 }
102 *live_p2m = xc_map_foreign_pages(xc_handle, dom, PROT_READ,
103 live_p2m_frame_list,
104 P2M_FL_ENTRIES);
106 if ( !*live_p2m )
107 {
108 PERROR("Couldn't map p2m table");
109 goto out;
110 }
112 *pfnp = p2m_size;
114 ret = 0;
116 out:
117 err = errno;
119 if ( live_p2m_frame_list_list )
120 munmap(live_p2m_frame_list_list, PAGE_SIZE);
122 if ( live_p2m_frame_list )
123 munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE);
125 errno = err;
126 return ret;
127 }
129 /*
130 * Local variables:
131 * mode: C
132 * c-set-style: "BSD"
133 * c-basic-offset: 4
134 * tab-width: 4
135 * indent-tabs-mode: nil
136 * End:
137 */