]>
git.proxmox.com Git - qemu.git/blob - exec.c
4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 /* XXX: pack the flags in the low bits of the pointer ? */
31 typedef struct PageDesc
{
32 struct TranslationBlock
*first_tb
;
37 #define L1_BITS (32 - L2_BITS - TARGET_PAGE_BITS)
39 #define L1_SIZE (1 << L1_BITS)
40 #define L2_SIZE (1 << L2_BITS)
42 unsigned long real_host_page_size
;
43 unsigned long host_page_bits
;
44 unsigned long host_page_size
;
45 unsigned long host_page_mask
;
47 static PageDesc
*l1_map
[L1_SIZE
];
51 /* NOTE: we can always suppose that host_page_size >=
53 real_host_page_size
= getpagesize();
54 if (host_page_size
== 0)
55 host_page_size
= real_host_page_size
;
56 if (host_page_size
< TARGET_PAGE_SIZE
)
57 host_page_size
= TARGET_PAGE_SIZE
;
59 while ((1 << host_page_bits
) < host_page_size
)
61 host_page_mask
= ~(host_page_size
- 1);
64 /* dump memory mappings */
65 void page_dump(FILE *f
)
67 unsigned long start
, end
;
68 int i
, j
, prot
, prot1
;
71 fprintf(f
, "%-8s %-8s %-8s %s\n",
72 "start", "end", "size", "prot");
76 for(i
= 0; i
<= L1_SIZE
; i
++) {
81 for(j
= 0;j
< L2_SIZE
; j
++) {
87 end
= (i
<< (32 - L1_BITS
)) | (j
<< TARGET_PAGE_BITS
);
89 fprintf(f
, "%08lx-%08lx %08lx %c%c%c\n",
90 start
, end
, end
- start
,
91 prot
& PAGE_READ
? 'r' : '-',
92 prot
& PAGE_WRITE
? 'w' : '-',
93 prot
& PAGE_EXEC
? 'x' : '-');
108 static inline PageDesc
*page_find_alloc(unsigned long address
)
113 index
= address
>> TARGET_PAGE_BITS
;
114 lp
= &l1_map
[index
>> L2_BITS
];
117 /* allocate if not found */
118 p
= malloc(sizeof(PageDesc
) * L2_SIZE
);
119 memset(p
, 0, sizeof(sizeof(PageDesc
) * L2_SIZE
));
122 return p
+ (index
& (L2_SIZE
- 1));
125 int page_get_flags(unsigned long address
)
130 index
= address
>> TARGET_PAGE_BITS
;
131 p
= l1_map
[index
>> L2_BITS
];
134 return p
[index
& (L2_SIZE
- 1)].flags
;
137 void page_set_flags(unsigned long start
, unsigned long end
, int flags
)
142 start
= start
& TARGET_PAGE_MASK
;
143 end
= TARGET_PAGE_ALIGN(end
);
144 for(addr
= start
; addr
< end
; addr
+= TARGET_PAGE_SIZE
) {
145 p
= page_find_alloc(addr
);