Commit 7f7f98734192824c3899458963861f2f62b9ed2c
1 parent
aebcb60e
endianness and portability fixes
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@434 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
56 additions
and
34 deletions
vl.c
... | ... | @@ -3319,6 +3319,12 @@ static void host_alarm_handler(int host_signum, siginfo_t *info, |
3319 | 3319 | } |
3320 | 3320 | } |
3321 | 3321 | |
3322 | +#ifdef CONFIG_SOFTMMU | |
3323 | +void *get_mmap_addr(unsigned long size) | |
3324 | +{ | |
3325 | + return NULL; | |
3326 | +} | |
3327 | +#else | |
3322 | 3328 | unsigned long mmap_addr = PHYS_RAM_BASE; |
3323 | 3329 | |
3324 | 3330 | void *get_mmap_addr(unsigned long size) |
... | ... | @@ -3328,6 +3334,7 @@ void *get_mmap_addr(unsigned long size) |
3328 | 3334 | mmap_addr += ((size + 4095) & ~4095) + 4096; |
3329 | 3335 | return (void *)addr; |
3330 | 3336 | } |
3337 | +#endif | |
3331 | 3338 | |
3332 | 3339 | /* main execution loop */ |
3333 | 3340 | |
... | ... | @@ -3522,7 +3529,7 @@ int main(int argc, char **argv) |
3522 | 3529 | struct sigaction act; |
3523 | 3530 | struct itimerval itv; |
3524 | 3531 | CPUX86State *env; |
3525 | - const char *tmpdir, *initrd_filename; | |
3532 | + const char *initrd_filename; | |
3526 | 3533 | const char *hd_filename[MAX_DISKS]; |
3527 | 3534 | const char *kernel_filename, *kernel_cmdline; |
3528 | 3535 | DisplayState *ds = &display_state; |
... | ... | @@ -3644,32 +3651,47 @@ int main(int argc, char **argv) |
3644 | 3651 | net_init(); |
3645 | 3652 | |
3646 | 3653 | /* init the memory */ |
3647 | - tmpdir = getenv("QEMU_TMPDIR"); | |
3648 | - if (!tmpdir) | |
3649 | - tmpdir = "/tmp"; | |
3650 | - snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/vlXXXXXX", tmpdir); | |
3651 | - if (mkstemp(phys_ram_file) < 0) { | |
3652 | - fprintf(stderr, "Could not create temporary memory file '%s'\n", | |
3653 | - phys_ram_file); | |
3654 | - exit(1); | |
3655 | - } | |
3656 | - phys_ram_fd = open(phys_ram_file, O_CREAT | O_TRUNC | O_RDWR, 0600); | |
3657 | - if (phys_ram_fd < 0) { | |
3658 | - fprintf(stderr, "Could not open temporary memory file '%s'\n", | |
3659 | - phys_ram_file); | |
3660 | - exit(1); | |
3661 | - } | |
3662 | 3654 | total_ram_size = phys_ram_size + vga_ram_size; |
3663 | - ftruncate(phys_ram_fd, total_ram_size); | |
3664 | - unlink(phys_ram_file); | |
3665 | - phys_ram_base = mmap(get_mmap_addr(total_ram_size), | |
3666 | - total_ram_size, | |
3667 | - PROT_WRITE | PROT_READ, MAP_SHARED | MAP_FIXED, | |
3668 | - phys_ram_fd, 0); | |
3669 | - if (phys_ram_base == MAP_FAILED) { | |
3670 | - fprintf(stderr, "Could not map physical memory\n"); | |
3655 | + | |
3656 | +#ifdef CONFIG_SOFTMMU | |
3657 | + phys_ram_base = malloc(total_ram_size); | |
3658 | + if (!phys_ram_base) { | |
3659 | + fprintf(stderr, "Could not allocate physical memory\n"); | |
3671 | 3660 | exit(1); |
3672 | 3661 | } |
3662 | +#else | |
3663 | + /* as we must map the same page at several addresses, we must use | |
3664 | + a fd */ | |
3665 | + { | |
3666 | + const char *tmpdir; | |
3667 | + | |
3668 | + tmpdir = getenv("QEMU_TMPDIR"); | |
3669 | + if (!tmpdir) | |
3670 | + tmpdir = "/tmp"; | |
3671 | + snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/vlXXXXXX", tmpdir); | |
3672 | + if (mkstemp(phys_ram_file) < 0) { | |
3673 | + fprintf(stderr, "Could not create temporary memory file '%s'\n", | |
3674 | + phys_ram_file); | |
3675 | + exit(1); | |
3676 | + } | |
3677 | + phys_ram_fd = open(phys_ram_file, O_CREAT | O_TRUNC | O_RDWR, 0600); | |
3678 | + if (phys_ram_fd < 0) { | |
3679 | + fprintf(stderr, "Could not open temporary memory file '%s'\n", | |
3680 | + phys_ram_file); | |
3681 | + exit(1); | |
3682 | + } | |
3683 | + ftruncate(phys_ram_fd, total_ram_size); | |
3684 | + unlink(phys_ram_file); | |
3685 | + phys_ram_base = mmap(get_mmap_addr(total_ram_size), | |
3686 | + total_ram_size, | |
3687 | + PROT_WRITE | PROT_READ, MAP_SHARED | MAP_FIXED, | |
3688 | + phys_ram_fd, 0); | |
3689 | + if (phys_ram_base == MAP_FAILED) { | |
3690 | + fprintf(stderr, "Could not map physical memory\n"); | |
3691 | + exit(1); | |
3692 | + } | |
3693 | + } | |
3694 | +#endif | |
3673 | 3695 | |
3674 | 3696 | /* open the virtual block devices */ |
3675 | 3697 | for(i = 0; i < MAX_DISKS; i++) { |
... | ... | @@ -3717,14 +3739,14 @@ int main(int argc, char **argv) |
3717 | 3739 | params = (void *)(phys_ram_base + KERNEL_PARAMS_ADDR); |
3718 | 3740 | memset(params, 0, sizeof(struct linux_params)); |
3719 | 3741 | params->mount_root_rdonly = 0; |
3720 | - params->cl_magic = 0xA33F; | |
3721 | - params->cl_offset = params->commandline - (uint8_t *)params; | |
3722 | - params->alt_mem_k = (phys_ram_size / 1024) - 1024; | |
3742 | + stw_raw(¶ms->cl_magic, 0xA33F); | |
3743 | + stw_raw(¶ms->cl_offset, params->commandline - (uint8_t *)params); | |
3744 | + stl_raw(¶ms->alt_mem_k, (phys_ram_size / 1024) - 1024); | |
3723 | 3745 | pstrcat(params->commandline, sizeof(params->commandline), kernel_cmdline); |
3724 | 3746 | params->loader_type = 0x01; |
3725 | 3747 | if (initrd_size > 0) { |
3726 | - params->initrd_start = INITRD_LOAD_ADDR; | |
3727 | - params->initrd_size = initrd_size; | |
3748 | + stl_raw(¶ms->initrd_start, INITRD_LOAD_ADDR); | |
3749 | + stl_raw(¶ms->initrd_size, initrd_size); | |
3728 | 3750 | } |
3729 | 3751 | params->orig_video_lines = 25; |
3730 | 3752 | params->orig_video_cols = 80; |
... | ... | @@ -3735,11 +3757,11 @@ int main(int argc, char **argv) |
3735 | 3757 | |
3736 | 3758 | memset(params->idt_table, 0, sizeof(params->idt_table)); |
3737 | 3759 | |
3738 | - params->gdt_table[2] = 0x00cf9a000000ffffLL; /* KERNEL_CS */ | |
3739 | - params->gdt_table[3] = 0x00cf92000000ffffLL; /* KERNEL_DS */ | |
3760 | + stq_raw(¶ms->gdt_table[2], 0x00cf9a000000ffffLL); /* KERNEL_CS */ | |
3761 | + stq_raw(¶ms->gdt_table[3], 0x00cf92000000ffffLL); /* KERNEL_DS */ | |
3740 | 3762 | /* for newer kernels (2.6.0) CS/DS are at different addresses */ |
3741 | - params->gdt_table[12] = 0x00cf9a000000ffffLL; /* KERNEL_CS */ | |
3742 | - params->gdt_table[13] = 0x00cf92000000ffffLL; /* KERNEL_DS */ | |
3763 | + stq_raw(¶ms->gdt_table[12], 0x00cf9a000000ffffLL); /* KERNEL_CS */ | |
3764 | + stq_raw(¶ms->gdt_table[13], 0x00cf92000000ffffLL); /* KERNEL_DS */ | |
3743 | 3765 | |
3744 | 3766 | env->idt.base = (void *)((uint8_t *)params->idt_table - phys_ram_base); |
3745 | 3767 | env->idt.limit = sizeof(params->idt_table) - 1; |
... | ... | @@ -3844,7 +3866,7 @@ int main(int argc, char **argv) |
3844 | 3866 | timer_ms = itv.it_interval.tv_usec / 1000; |
3845 | 3867 | pit_min_timer_count = ((uint64_t)itv.it_interval.tv_usec * PIT_FREQ) / |
3846 | 3868 | 1000000; |
3847 | - | |
3869 | + | |
3848 | 3870 | if (use_gdbstub) { |
3849 | 3871 | cpu_gdbstub(NULL, main_loop, gdbstub_port); |
3850 | 3872 | } else { | ... | ... |