Commit 92a31b1fff09bed823865262d4b3c8e7b246c812

Authored by bellard
1 parent 0a962c02

64 bit support


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1282 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 132 additions and 56 deletions
linux-user/elfload.c
@@ -306,14 +306,14 @@ extern unsigned long x86_stack_size; @@ -306,14 +306,14 @@ extern unsigned long x86_stack_size;
306 static int load_aout_interp(void * exptr, int interp_fd); 306 static int load_aout_interp(void * exptr, int interp_fd);
307 307
308 #ifdef BSWAP_NEEDED 308 #ifdef BSWAP_NEEDED
309 -static void bswap_ehdr(Elf32_Ehdr *ehdr) 309 +static void bswap_ehdr(struct elfhdr *ehdr)
310 { 310 {
311 bswap16s(&ehdr->e_type); /* Object file type */ 311 bswap16s(&ehdr->e_type); /* Object file type */
312 bswap16s(&ehdr->e_machine); /* Architecture */ 312 bswap16s(&ehdr->e_machine); /* Architecture */
313 bswap32s(&ehdr->e_version); /* Object file version */ 313 bswap32s(&ehdr->e_version); /* Object file version */
314 - bswap32s(&ehdr->e_entry); /* Entry point virtual address */  
315 - bswap32s(&ehdr->e_phoff); /* Program header table file offset */  
316 - bswap32s(&ehdr->e_shoff); /* Section header table file offset */ 314 + bswaptls(&ehdr->e_entry); /* Entry point virtual address */
  315 + bswaptls(&ehdr->e_phoff); /* Program header table file offset */
  316 + bswaptls(&ehdr->e_shoff); /* Section header table file offset */
317 bswap32s(&ehdr->e_flags); /* Processor-specific flags */ 317 bswap32s(&ehdr->e_flags); /* Processor-specific flags */
318 bswap16s(&ehdr->e_ehsize); /* ELF header size in bytes */ 318 bswap16s(&ehdr->e_ehsize); /* ELF header size in bytes */
319 bswap16s(&ehdr->e_phentsize); /* Program header table entry size */ 319 bswap16s(&ehdr->e_phentsize); /* Program header table entry size */
@@ -323,30 +323,30 @@ static void bswap_ehdr(Elf32_Ehdr *ehdr) @@ -323,30 +323,30 @@ static void bswap_ehdr(Elf32_Ehdr *ehdr)
323 bswap16s(&ehdr->e_shstrndx); /* Section header string table index */ 323 bswap16s(&ehdr->e_shstrndx); /* Section header string table index */
324 } 324 }
325 325
326 -static void bswap_phdr(Elf32_Phdr *phdr) 326 +static void bswap_phdr(struct elf_phdr *phdr)
327 { 327 {
328 bswap32s(&phdr->p_type); /* Segment type */ 328 bswap32s(&phdr->p_type); /* Segment type */
329 - bswap32s(&phdr->p_offset); /* Segment file offset */  
330 - bswap32s(&phdr->p_vaddr); /* Segment virtual address */  
331 - bswap32s(&phdr->p_paddr); /* Segment physical address */  
332 - bswap32s(&phdr->p_filesz); /* Segment size in file */  
333 - bswap32s(&phdr->p_memsz); /* Segment size in memory */ 329 + bswaptls(&phdr->p_offset); /* Segment file offset */
  330 + bswaptls(&phdr->p_vaddr); /* Segment virtual address */
  331 + bswaptls(&phdr->p_paddr); /* Segment physical address */
  332 + bswaptls(&phdr->p_filesz); /* Segment size in file */
  333 + bswaptls(&phdr->p_memsz); /* Segment size in memory */
334 bswap32s(&phdr->p_flags); /* Segment flags */ 334 bswap32s(&phdr->p_flags); /* Segment flags */
335 - bswap32s(&phdr->p_align); /* Segment alignment */ 335 + bswaptls(&phdr->p_align); /* Segment alignment */
336 } 336 }
337 337
338 -static void bswap_shdr(Elf32_Shdr *shdr) 338 +static void bswap_shdr(struct elf_shdr *shdr)
339 { 339 {
340 bswap32s(&shdr->sh_name); 340 bswap32s(&shdr->sh_name);
341 bswap32s(&shdr->sh_type); 341 bswap32s(&shdr->sh_type);
342 - bswap32s(&shdr->sh_flags);  
343 - bswap32s(&shdr->sh_addr);  
344 - bswap32s(&shdr->sh_offset);  
345 - bswap32s(&shdr->sh_size); 342 + bswaptls(&shdr->sh_flags);
  343 + bswaptls(&shdr->sh_addr);
  344 + bswaptls(&shdr->sh_offset);
  345 + bswaptls(&shdr->sh_size);
346 bswap32s(&shdr->sh_link); 346 bswap32s(&shdr->sh_link);
347 bswap32s(&shdr->sh_info); 347 bswap32s(&shdr->sh_info);
348 - bswap32s(&shdr->sh_addralign);  
349 - bswap32s(&shdr->sh_entsize); 348 + bswaptls(&shdr->sh_addralign);
  349 + bswaptls(&shdr->sh_entsize);
350 } 350 }
351 351
352 static void bswap_sym(Elf32_Sym *sym) 352 static void bswap_sym(Elf32_Sym *sym)
monitor.c
@@ -38,7 +38,8 @@ @@ -38,7 +38,8 @@
38 * 'F' filename 38 * 'F' filename
39 * 'B' block device name 39 * 'B' block device name
40 * 's' string (accept optional quote) 40 * 's' string (accept optional quote)
41 - * 'i' integer 41 + * 'i' 32 bit integer
  42 + * 'l' target long (32 or 64 bit)
42 * '/' optional gdb-like print format (like "/10x") 43 * '/' optional gdb-like print format (like "/10x")
43 * 44 *
44 * '?' optional type (for 'F', 's' and 'i') 45 * '?' optional type (for 'F', 's' and 'i')
@@ -463,7 +464,7 @@ static void memory_dump(int count, int format, int wsize, @@ -463,7 +464,7 @@ static void memory_dump(int count, int format, int wsize,
463 v = lduw_raw(buf + i); 464 v = lduw_raw(buf + i);
464 break; 465 break;
465 case 4: 466 case 4:
466 - v = ldl_raw(buf + i); 467 + v = (uint32_t)ldl_raw(buf + i);
467 break; 468 break;
468 case 8: 469 case 8:
469 v = ldq_raw(buf + i); 470 v = ldq_raw(buf + i);
@@ -495,18 +496,31 @@ static void memory_dump(int count, int format, int wsize, @@ -495,18 +496,31 @@ static void memory_dump(int count, int format, int wsize,
495 } 496 }
496 } 497 }
497 498
498 -static void do_memory_dump(int count, int format, int size, int addr) 499 +#if TARGET_LONG_BITS == 64
  500 +#define GET_TLONG(h, l) (((uint64_t)(h) << 32) | (l))
  501 +#else
  502 +#define GET_TLONG(h, l) (l)
  503 +#endif
  504 +
  505 +static void do_memory_dump(int count, int format, int size,
  506 + uint32_t addrh, uint32_t addrl)
499 { 507 {
  508 + target_long addr = GET_TLONG(addrh, addrl);
500 memory_dump(count, format, size, addr, 0); 509 memory_dump(count, format, size, addr, 0);
501 } 510 }
502 511
503 -static void do_physical_memory_dump(int count, int format, int size, int addr) 512 +static void do_physical_memory_dump(int count, int format, int size,
  513 + uint32_t addrh, uint32_t addrl)
  514 +
504 { 515 {
  516 + target_long addr = GET_TLONG(addrh, addrl);
505 memory_dump(count, format, size, addr, 1); 517 memory_dump(count, format, size, addr, 1);
506 } 518 }
507 519
508 -static void do_print(int count, int format, int size, int val) 520 +static void do_print(int count, int format, int size, unsigned int valh, unsigned int vall)
509 { 521 {
  522 + target_long val = GET_TLONG(valh, vall);
  523 +#if TARGET_LONG_BITS == 32
510 switch(format) { 524 switch(format) {
511 case 'o': 525 case 'o':
512 term_printf("%#o", val); 526 term_printf("%#o", val);
@@ -525,6 +539,26 @@ static void do_print(int count, int format, int size, int val) @@ -525,6 +539,26 @@ static void do_print(int count, int format, int size, int val)
525 term_printc(val); 539 term_printc(val);
526 break; 540 break;
527 } 541 }
  542 +#else
  543 + switch(format) {
  544 + case 'o':
  545 + term_printf("%#llo", val);
  546 + break;
  547 + case 'x':
  548 + term_printf("%#llx", val);
  549 + break;
  550 + case 'u':
  551 + term_printf("%llu", val);
  552 + break;
  553 + default:
  554 + case 'd':
  555 + term_printf("%lld", val);
  556 + break;
  557 + case 'c':
  558 + term_printc(val);
  559 + break;
  560 + }
  561 +#endif
528 term_printf("\n"); 562 term_printf("\n");
529 } 563 }
530 564
@@ -859,11 +893,11 @@ static term_cmd_t term_cmds[] = { @@ -859,11 +893,11 @@ static term_cmd_t term_cmds[] = {
859 { "gdbserver", "i?", do_gdbserver, 893 { "gdbserver", "i?", do_gdbserver,
860 "[port]", "start gdbserver session (default port=1234)", }, 894 "[port]", "start gdbserver session (default port=1234)", },
861 #endif 895 #endif
862 - { "x", "/i", do_memory_dump, 896 + { "x", "/l", do_memory_dump,
863 "/fmt addr", "virtual memory dump starting at 'addr'", }, 897 "/fmt addr", "virtual memory dump starting at 'addr'", },
864 - { "xp", "/i", do_physical_memory_dump, 898 + { "xp", "/l", do_physical_memory_dump,
865 "/fmt addr", "physical memory dump starting at 'addr'", }, 899 "/fmt addr", "physical memory dump starting at 'addr'", },
866 - { "p|print", "/i", do_print, 900 + { "p|print", "/l", do_print,
867 "/fmt expr", "print expression value (use $reg for CPU register access)", }, 901 "/fmt expr", "print expression value (use $reg for CPU register access)", },
868 { "i", "/ii.", do_ioport_read, 902 { "i", "/ii.", do_ioport_read,
869 "/fmt addr", "I/O port read" }, 903 "/fmt addr", "I/O port read" },
@@ -908,21 +942,25 @@ static term_cmd_t info_cmds[] = { @@ -908,21 +942,25 @@ static term_cmd_t info_cmds[] = {
908 static const char *pch; 942 static const char *pch;
909 static jmp_buf expr_env; 943 static jmp_buf expr_env;
910 944
  945 +#define MD_TLONG 0
  946 +#define MD_I32 1
  947 +
911 typedef struct MonitorDef { 948 typedef struct MonitorDef {
912 const char *name; 949 const char *name;
913 int offset; 950 int offset;
914 - int (*get_value)(struct MonitorDef *md, int val); 951 + target_long (*get_value)(struct MonitorDef *md, int val);
  952 + int type;
915 } MonitorDef; 953 } MonitorDef;
916 954
917 #if defined(TARGET_I386) 955 #if defined(TARGET_I386)
918 -static int monitor_get_pc (struct MonitorDef *md, int val) 956 +static target_long monitor_get_pc (struct MonitorDef *md, int val)
919 { 957 {
920 - return cpu_single_env->eip + (long)cpu_single_env->segs[R_CS].base; 958 + return cpu_single_env->eip + cpu_single_env->segs[R_CS].base;
921 } 959 }
922 #endif 960 #endif
923 961
924 #if defined(TARGET_PPC) 962 #if defined(TARGET_PPC)
925 -static int monitor_get_ccr (struct MonitorDef *md, int val) 963 +static target_long monitor_get_ccr (struct MonitorDef *md, int val)
926 { 964 {
927 unsigned int u; 965 unsigned int u;
928 int i; 966 int i;
@@ -934,7 +972,7 @@ static int monitor_get_ccr (struct MonitorDef *md, int val) @@ -934,7 +972,7 @@ static int monitor_get_ccr (struct MonitorDef *md, int val)
934 return u; 972 return u;
935 } 973 }
936 974
937 -static int monitor_get_msr (struct MonitorDef *md, int val) 975 +static target_long monitor_get_msr (struct MonitorDef *md, int val)
938 { 976 {
939 return (cpu_single_env->msr[MSR_POW] << MSR_POW) | 977 return (cpu_single_env->msr[MSR_POW] << MSR_POW) |
940 (cpu_single_env->msr[MSR_ILE] << MSR_ILE) | 978 (cpu_single_env->msr[MSR_ILE] << MSR_ILE) |
@@ -953,7 +991,7 @@ static int monitor_get_msr (struct MonitorDef *md, int val) @@ -953,7 +991,7 @@ static int monitor_get_msr (struct MonitorDef *md, int val)
953 (cpu_single_env->msr[MSR_LE] << MSR_LE); 991 (cpu_single_env->msr[MSR_LE] << MSR_LE);
954 } 992 }
955 993
956 -static int monitor_get_xer (struct MonitorDef *md, int val) 994 +static target_long monitor_get_xer (struct MonitorDef *md, int val)
957 { 995 {
958 return (cpu_single_env->xer[XER_SO] << XER_SO) | 996 return (cpu_single_env->xer[XER_SO] << XER_SO) |
959 (cpu_single_env->xer[XER_OV] << XER_OV) | 997 (cpu_single_env->xer[XER_OV] << XER_OV) |
@@ -961,29 +999,29 @@ static int monitor_get_xer (struct MonitorDef *md, int val) @@ -961,29 +999,29 @@ static int monitor_get_xer (struct MonitorDef *md, int val)
961 (cpu_single_env->xer[XER_BC] << XER_BC); 999 (cpu_single_env->xer[XER_BC] << XER_BC);
962 } 1000 }
963 1001
964 -static int monitor_get_decr (struct MonitorDef *md, int val) 1002 +static target_long monitor_get_decr (struct MonitorDef *md, int val)
965 { 1003 {
966 return cpu_ppc_load_decr(cpu_single_env); 1004 return cpu_ppc_load_decr(cpu_single_env);
967 } 1005 }
968 1006
969 -static int monitor_get_tbu (struct MonitorDef *md, int val) 1007 +static target_long monitor_get_tbu (struct MonitorDef *md, int val)
970 { 1008 {
971 return cpu_ppc_load_tbu(cpu_single_env); 1009 return cpu_ppc_load_tbu(cpu_single_env);
972 } 1010 }
973 1011
974 -static int monitor_get_tbl (struct MonitorDef *md, int val) 1012 +static target_long monitor_get_tbl (struct MonitorDef *md, int val)
975 { 1013 {
976 return cpu_ppc_load_tbl(cpu_single_env); 1014 return cpu_ppc_load_tbl(cpu_single_env);
977 } 1015 }
978 #endif 1016 #endif
979 1017
980 #if defined(TARGET_SPARC) 1018 #if defined(TARGET_SPARC)
981 -static int monitor_get_psr (struct MonitorDef *md, int val) 1019 +static target_long monitor_get_psr (struct MonitorDef *md, int val)
982 { 1020 {
983 return GET_PSR(cpu_single_env); 1021 return GET_PSR(cpu_single_env);
984 } 1022 }
985 1023
986 -static int monitor_get_reg(struct MonitorDef *md, int val) 1024 +static target_long monitor_get_reg(struct MonitorDef *md, int val)
987 { 1025 {
988 return cpu_single_env->regwptr[val]; 1026 return cpu_single_env->regwptr[val];
989 } 1027 }
@@ -993,9 +1031,9 @@ static MonitorDef monitor_defs[] = { @@ -993,9 +1031,9 @@ static MonitorDef monitor_defs[] = {
993 #ifdef TARGET_I386 1031 #ifdef TARGET_I386
994 1032
995 #define SEG(name, seg) \ 1033 #define SEG(name, seg) \
996 - { name, offsetof(CPUState, segs[seg].selector) },\ 1034 + { name, offsetof(CPUState, segs[seg].selector), NULL, MD_I32 },\
997 { name ".base", offsetof(CPUState, segs[seg].base) },\ 1035 { name ".base", offsetof(CPUState, segs[seg].base) },\
998 - { name ".limit", offsetof(CPUState, segs[seg].limit) }, 1036 + { name ".limit", offsetof(CPUState, segs[seg].limit), NULL, MD_I32 },
999 1037
1000 { "eax", offsetof(CPUState, regs[0]) }, 1038 { "eax", offsetof(CPUState, regs[0]) },
1001 { "ecx", offsetof(CPUState, regs[1]) }, 1039 { "ecx", offsetof(CPUState, regs[1]) },
@@ -1005,6 +1043,16 @@ static MonitorDef monitor_defs[] = { @@ -1005,6 +1043,16 @@ static MonitorDef monitor_defs[] = {
1005 { "ebp|fp", offsetof(CPUState, regs[5]) }, 1043 { "ebp|fp", offsetof(CPUState, regs[5]) },
1006 { "esi", offsetof(CPUState, regs[6]) }, 1044 { "esi", offsetof(CPUState, regs[6]) },
1007 { "edi", offsetof(CPUState, regs[7]) }, 1045 { "edi", offsetof(CPUState, regs[7]) },
  1046 +#ifdef TARGET_X86_64
  1047 + { "r8", offsetof(CPUState, regs[8]) },
  1048 + { "r9", offsetof(CPUState, regs[9]) },
  1049 + { "r10", offsetof(CPUState, regs[10]) },
  1050 + { "r11", offsetof(CPUState, regs[11]) },
  1051 + { "r12", offsetof(CPUState, regs[12]) },
  1052 + { "r13", offsetof(CPUState, regs[13]) },
  1053 + { "r14", offsetof(CPUState, regs[14]) },
  1054 + { "r15", offsetof(CPUState, regs[15]) },
  1055 +#endif
1008 { "eflags", offsetof(CPUState, eflags) }, 1056 { "eflags", offsetof(CPUState, eflags) },
1009 { "eip", offsetof(CPUState, eip) }, 1057 { "eip", offsetof(CPUState, eip) },
1010 SEG("cs", R_CS) 1058 SEG("cs", R_CS)
@@ -1157,15 +1205,28 @@ static void expr_error(const char *fmt) @@ -1157,15 +1205,28 @@ static void expr_error(const char *fmt)
1157 longjmp(expr_env, 1); 1205 longjmp(expr_env, 1);
1158 } 1206 }
1159 1207
1160 -static int get_monitor_def(int *pval, const char *name) 1208 +static int get_monitor_def(target_long *pval, const char *name)
1161 { 1209 {
1162 MonitorDef *md; 1210 MonitorDef *md;
  1211 + void *ptr;
  1212 +
1163 for(md = monitor_defs; md->name != NULL; md++) { 1213 for(md = monitor_defs; md->name != NULL; md++) {
1164 if (compare_cmd(name, md->name)) { 1214 if (compare_cmd(name, md->name)) {
1165 if (md->get_value) { 1215 if (md->get_value) {
1166 *pval = md->get_value(md, md->offset); 1216 *pval = md->get_value(md, md->offset);
1167 } else { 1217 } else {
1168 - *pval = *(uint32_t *)((uint8_t *)cpu_single_env + md->offset); 1218 + ptr = (uint8_t *)cpu_single_env + md->offset;
  1219 + switch(md->type) {
  1220 + case MD_I32:
  1221 + *pval = *(int32_t *)ptr;
  1222 + break;
  1223 + case MD_TLONG:
  1224 + *pval = *(target_long *)ptr;
  1225 + break;
  1226 + default:
  1227 + *pval = 0;
  1228 + break;
  1229 + }
1169 } 1230 }
1170 return 0; 1231 return 0;
1171 } 1232 }
@@ -1182,11 +1243,11 @@ static void next(void) @@ -1182,11 +1243,11 @@ static void next(void)
1182 } 1243 }
1183 } 1244 }
1184 1245
1185 -static int expr_sum(void); 1246 +static target_long expr_sum(void);
1186 1247
1187 -static int expr_unary(void) 1248 +static target_long expr_unary(void)
1188 { 1249 {
1189 - int n; 1250 + target_long n;
1190 char *p; 1251 char *p;
1191 1252
1192 switch(*pch) { 1253 switch(*pch) {
@@ -1259,10 +1320,11 @@ static int expr_unary(void) @@ -1259,10 +1320,11 @@ static int expr_unary(void)
1259 } 1320 }
1260 1321
1261 1322
1262 -static int expr_prod(void) 1323 +static target_long expr_prod(void)
1263 { 1324 {
1264 - int val, val2, op;  
1265 - 1325 + target_long val, val2;
  1326 + int op;
  1327 +
1266 val = expr_unary(); 1328 val = expr_unary();
1267 for(;;) { 1329 for(;;) {
1268 op = *pch; 1330 op = *pch;
@@ -1289,9 +1351,10 @@ static int expr_prod(void) @@ -1289,9 +1351,10 @@ static int expr_prod(void)
1289 return val; 1351 return val;
1290 } 1352 }
1291 1353
1292 -static int expr_logic(void) 1354 +static target_long expr_logic(void)
1293 { 1355 {
1294 - int val, val2, op; 1356 + target_long val, val2;
  1357 + int op;
1295 1358
1296 val = expr_prod(); 1359 val = expr_prod();
1297 for(;;) { 1360 for(;;) {
@@ -1316,9 +1379,10 @@ static int expr_logic(void) @@ -1316,9 +1379,10 @@ static int expr_logic(void)
1316 return val; 1379 return val;
1317 } 1380 }
1318 1381
1319 -static int expr_sum(void) 1382 +static target_long expr_sum(void)
1320 { 1383 {
1321 - int val, val2, op; 1384 + target_long val, val2;
  1385 + int op;
1322 1386
1323 val = expr_logic(); 1387 val = expr_logic();
1324 for(;;) { 1388 for(;;) {
@@ -1335,7 +1399,7 @@ static int expr_sum(void) @@ -1335,7 +1399,7 @@ static int expr_sum(void)
1335 return val; 1399 return val;
1336 } 1400 }
1337 1401
1338 -static int get_expr(int *pval, const char **pp) 1402 +static int get_expr(target_long *pval, const char **pp)
1339 { 1403 {
1340 pch = *pp; 1404 pch = *pp;
1341 if (setjmp(expr_env)) { 1405 if (setjmp(expr_env)) {
@@ -1596,8 +1660,9 @@ static void monitor_handle_command(const char *cmdline) @@ -1596,8 +1660,9 @@ static void monitor_handle_command(const char *cmdline)
1596 } 1660 }
1597 break; 1661 break;
1598 case 'i': 1662 case 'i':
  1663 + case 'l':
1599 { 1664 {
1600 - int val; 1665 + target_long val;
1601 while (isspace(*p)) 1666 while (isspace(*p))
1602 p++; 1667 p++;
1603 if (*typestr == '?' || *typestr == '.') { 1668 if (*typestr == '?' || *typestr == '.') {
@@ -1630,9 +1695,20 @@ static void monitor_handle_command(const char *cmdline) @@ -1630,9 +1695,20 @@ static void monitor_handle_command(const char *cmdline)
1630 if (get_expr(&val, &p)) 1695 if (get_expr(&val, &p))
1631 goto fail; 1696 goto fail;
1632 add_num: 1697 add_num:
1633 - if (nb_args >= MAX_ARGS)  
1634 - goto error_args;  
1635 - args[nb_args++] = (void *)val; 1698 + if (c == 'i') {
  1699 + if (nb_args >= MAX_ARGS)
  1700 + goto error_args;
  1701 + args[nb_args++] = (void *)(int)val;
  1702 + } else {
  1703 + if ((nb_args + 1) >= MAX_ARGS)
  1704 + goto error_args;
  1705 +#if TARGET_LONG_BITS == 64
  1706 + args[nb_args++] = (void *)(int)((val >> 32) & 0xffffffff);
  1707 +#else
  1708 + args[nb_args++] = (void *)0;
  1709 +#endif
  1710 + args[nb_args++] = (void *)(int)(val & 0xffffffff);
  1711 + }
1636 } 1712 }
1637 break; 1713 break;
1638 case '-': 1714 case '-':