ia64/xen-unstable

view tools/libxc/xc_load_aout9.c @ 9488:0a6f5527ca4b

[IA64] set itv handoff as masked and enable reading irr[0-3]

Set initial vcpu itv handoff state to mask the timer vector.
This seems to match hardware and makes logical sense from a
spurious interrupt perspective. Enable vcpu_get_irr[0-3]
functions as they seem to work and have the proper backing.
This enables the check_sal_cache_flush() in arch/ia64/kernel.sal.c
to work unmodified, allowing us to remove the Xen changes from
the file (and thus the file from the sparse tree).

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
author awilliam@xenbuild.aw
date Tue Apr 04 09:39:45 2006 -0600 (2006-04-04)
parents a1fcee3b2abe
children 74ee53209cca
line source
2 #include "xg_private.h"
3 #include "xc_aout9.h"
5 #if defined(__i386__)
6 #define A9_MAGIC I_MAGIC
7 #elif defined(__x86_64__)
8 #define A9_MAGIC S_MAGIC
9 #elif defined(__ia64__)
10 #define A9_MAGIC 0
11 #else
12 #error "Unsupported architecture"
13 #endif
15 #define round_pgup(_p) (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
16 #define KZERO 0x80000000
17 #define KOFFSET(_p) ((_p)&~KZERO)
19 static int parseaout9image(const char *, unsigned long, struct domain_setup_info *);
20 static int loadaout9image(const char *, unsigned long, int, uint32_t, unsigned long *, struct domain_setup_info *);
21 static void copyout(int, uint32_t, unsigned long *, unsigned long, const char *, int);
22 struct Exec *get_header(const char *, unsigned long, struct Exec *);
25 int
26 probe_aout9(
27 const char *image,
28 unsigned long image_size,
29 struct load_funcs *load_funcs)
30 {
31 struct Exec ehdr;
33 if (!get_header(image, image_size, &ehdr)) {
34 ERROR("Kernel image does not have a a.out9 header.");
35 return -EINVAL;
36 }
38 load_funcs->parseimage = parseaout9image;
39 load_funcs->loadimage = loadaout9image;
40 return 0;
41 }
43 static int
44 parseaout9image(
45 const char *image,
46 unsigned long image_size,
47 struct domain_setup_info *dsi)
48 {
49 struct Exec ehdr;
50 unsigned long start, dstart, end;
52 if (!get_header(image, image_size, &ehdr)) {
53 ERROR("Kernel image does not have a a.out9 header.");
54 return -EINVAL;
55 }
57 if (sizeof ehdr + ehdr.text + ehdr.data > image_size) {
58 ERROR("a.out program extends past end of image.");
59 return -EINVAL;
60 }
62 start = ehdr.entry;
63 dstart = round_pgup(start + ehdr.text);
64 end = dstart + ehdr.data + ehdr.bss;
66 dsi->v_start = KZERO;
67 dsi->v_kernstart = start;
68 dsi->v_kernend = end;
69 dsi->v_kernentry = ehdr.entry;
70 dsi->v_end = end;
72 /* XXX load symbols */
74 return 0;
75 }
77 static int
78 loadaout9image(
79 const char *image,
80 unsigned long image_size,
81 int xch, uint32_t dom,
82 unsigned long *parray,
83 struct domain_setup_info *dsi)
84 {
85 struct Exec ehdr;
86 unsigned long start, dstart;
88 if (!get_header(image, image_size, &ehdr)) {
89 ERROR("Kernel image does not have a a.out9 header.");
90 return -EINVAL;
91 }
93 start = ehdr.entry;
94 dstart = round_pgup(start + ehdr.text);
95 copyout(xch, dom, parray, start, image + sizeof ehdr, ehdr.text);
96 copyout(xch, dom, parray, dstart,
97 image + sizeof ehdr + ehdr.text, ehdr.data);
99 /* XXX load symbols */
101 return 0;
102 }
104 /*
105 * copyout data to the domain given an offset to the start
106 * of its memory region described by parray.
107 */
108 static void
109 copyout(
110 int xch, uint32_t dom,
111 unsigned long *parray,
112 unsigned long addr,
113 const char *buf,
114 int sz)
115 {
116 unsigned long pgoff, chunksz, off;
117 void *pg;
119 off = KOFFSET(addr);
120 while (sz > 0) {
121 pgoff = off & (PAGE_SIZE-1);
122 chunksz = sz;
123 if(chunksz > PAGE_SIZE - pgoff)
124 chunksz = PAGE_SIZE - pgoff;
126 pg = xc_map_foreign_range(xch, dom, PAGE_SIZE, PROT_WRITE,
127 parray[off>>PAGE_SHIFT]);
128 memcpy(pg + pgoff, buf, chunksz);
129 munmap(pg, PAGE_SIZE);
131 off += chunksz;
132 buf += chunksz;
133 sz -= chunksz;
134 }
135 }
137 #define swap16(_v) ((((uint16_t)(_v)>>8)&0xff)|(((uint16_t)(_v)&0xff)<<8))
138 #define swap32(_v) (((uint32_t)swap16((uint16_t)(_v))<<16)|(uint32_t)swap16((uint32_t)((_v)>>16)))
140 /*
141 * Decode the header from the start of image and return it.
142 */
143 struct Exec *
144 get_header(
145 const char *image,
146 unsigned long image_size,
147 struct Exec *ehdr)
148 {
149 uint32_t *v, x;
150 int i;
152 if (A9_MAGIC == 0)
153 return 0;
155 if (image_size < sizeof ehdr)
156 return 0;
158 /* ... all big endian words */
159 v = (uint32_t *)ehdr;
160 for (i = 0; i < sizeof(*ehdr); i += 4) {
161 x = *(uint32_t *)&image[i];
162 v[i/4] = swap32(x);
163 }
165 if(ehdr->magic != A9_MAGIC)
166 return 0;
167 return ehdr;
168 }
170 /*
171 * Local variables:
172 * mode: C
173 * c-set-style: "BSD"
174 * c-basic-offset: 4
175 * tab-width: 4
176 * indent-tabs-mode: nil
177 * End:
178 */