qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Re: [Qemu-devel] adding support for above 2giga for qemu. ( include patchs )
@ 2007-08-14 16:11 Izik Eidus
  2007-08-14 19:51 ` Blue Swirl
  2007-08-16 18:41 ` Blue Swirl
  0 siblings, 2 replies; 6+ messages in thread
From: Izik Eidus @ 2007-08-14 16:11 UTC (permalink / raw)
  To: qemu-devel

well, i used kind of older patch from you,
for to get it to work in pc, you have to change the cmos
and the vga page0, and page1 as well...

anyway you have anyidea why it is working with kvm above 4giga and not
with qemu??? can you look at how i did the mapping in qemu?

^ permalink raw reply	[flat|nested] 6+ messages in thread
* [Qemu-devel] adding support for above 2giga for qemu. ( include patchs )
@ 2007-08-14 11:22 Izik Eidus
  2007-08-14 14:50 ` Blue Swirl
  0 siblings, 1 reply; 6+ messages in thread
From: Izik Eidus @ 2007-08-14 11:22 UTC (permalink / raw)
  To: qemu-devel


[-- Attachment #1.1: Type: text/plain, Size: 927 bytes --]

hey,
i have wrote a patch to qemu to allow it to run with above the 2giga limitations we have now.
i tested it on qemu that used kvm with 14giga of ram, and it was tested at other place with 32giga of ram to the guest ( 32bits, and 64bits).

the patch that i send here, is patch to qemu without kvm,
it include patch to the bochs bios, and patch to the qemu.
part of the patch to qemu fix the typedefs varibles to unsigned long, and it is based on patch i saw at this list
that target sparc.

for some reason the mapping that i do inside qemu with cpu_register_physical_memory dont work, and with this patchs
qemu could not work with more than 3.75giga of ram. ( with kvm it does working... )

this is request for comment, i probbley doing something wrong inside qemu, so anyone have idea how to solve it
please comment :)


anyway for to make it easy to run i put here compiled patched bios.

have fun! :-)

[-- Attachment #1.2: Type: text/html, Size: 1399 bytes --]

[-- Attachment #2: bochs_bios_ram_patch --]
[-- Type: application/octet-stream, Size: 7259 bytes --]

Index: rombios.c
===================================================================
RCS file: /cvsroot/bochs/bochs/bios/rombios.c,v
retrieving revision 1.182
diff -u -r1.182 rombios.c
--- rombios.c	1 Aug 2007 17:09:51 -0000	1.182
+++ rombios.c	14 Aug 2007 10:33:39 -0000
@@ -4077,24 +4077,32 @@
 }
 #endif
 
+struct MemoryMap {
+    Bit32u start;
+    Bit16u extra_start;
+    Bit32u end;
+    Bit8u extra_end;
+};
+
+typedef struct MemoryMap *MemoryMap_t;
 
-void set_e820_range(ES, DI, start, end, type)
+void set_e820_range(ES, DI, MemMap, type)
      Bit16u ES;
      Bit16u DI;
-     Bit32u start;
-     Bit32u end;
+     MemoryMap_t MemMap;
      Bit16u type;
 {
-    write_word(ES, DI, start);
-    write_word(ES, DI+2, start >> 16);
-    write_word(ES, DI+4, 0x00);
-    write_word(ES, DI+6, 0x00);
-
-    end -= start;
-    write_word(ES, DI+8, end);
-    write_word(ES, DI+10, end >> 16);
-    write_word(ES, DI+12, 0x0000);
-    write_word(ES, DI+14, 0x0000);
+    write_word(ES, DI, MemMap->start);
+    write_word(ES, DI+2, MemMap->start >> 16);
+    write_word(ES, DI+4, MemMap->extra_start);
+    write_word(ES, DI+6, 0x0);
+
+    MemMap->end -= MemMap->start;
+    MemMap->extra_end -= MemMap->extra_start;
+    write_word(ES, DI+8, MemMap->end);
+    write_word(ES, DI+10, MemMap->end >> 16);
+    write_word(ES, DI+12, MemMap->extra_end);
+    write_word(ES, DI+14, 0x0);
 
     write_word(ES, DI+16, type);
     write_word(ES, DI+18, 0x0);
@@ -4105,8 +4113,11 @@
   pushad_regs_t regs; // REGS pushed via pushad
   Bit16u ES, DS, FLAGS;
 {
+  struct MemoryMap MemMap;
   Bit32u  extended_memory_size=0; // 64bits long
+  Bit32u  extra_lowbits_memory_size=0;
   Bit16u  CX,DX;
+  Bit8u  extra_highbits_memory_size=0;
 
 BX_DEBUG_INT15("int15 AX=%04x\n",regs.u.r16.ax);
 
@@ -4179,11 +4190,21 @@
                     extended_memory_size *= 1024;
                 }
 
+                extra_lowbits_memory_size = inb_cmos(0x5c);
+                extra_lowbits_memory_size <<= 8;
+                extra_lowbits_memory_size |= inb_cmos(0x5b);
+                extra_lowbits_memory_size *= 64;
+                extra_lowbits_memory_size *= 1024;
+                extra_highbits_memory_size = inb_cmos(0x5d);
+                
                 switch(regs.u.r16.bx)
                 {
                     case 0:
-                        set_e820_range(ES, regs.u.r16.di,
-                                       0x0000000L, 0x0009fc00L, 1);
+                        MemMap.start = 0x0000000L;
+                        MemMap.extra_start = 0;
+                        MemMap.end = 0x0009fc00L;
+                        MemMap.extra_end = 0;
+                        set_e820_range(ES, regs.u.r16.di, &MemMap, 1);
                         regs.u.r32.ebx = 1;
                         regs.u.r32.eax = 0x534D4150;
                         regs.u.r32.ecx = 0x14;
@@ -4191,8 +4212,11 @@
                         return;
                         break;
                     case 1:
-                        set_e820_range(ES, regs.u.r16.di,
-                                       0x0009fc00L, 0x000a0000L, 2);
+                        MemMap.start = 0x0009fc00L;
+                        MemMap.extra_start = 0;
+                        MemMap.end = 0x000a0000L;
+                        MemMap.extra_end = 0;
+                        set_e820_range(ES, regs.u.r16.di, &MemMap, 2);
                         regs.u.r32.ebx = 2;
                         regs.u.r32.eax = 0x534D4150;
                         regs.u.r32.ecx = 0x14;
@@ -4200,18 +4224,23 @@
                         return;
                         break;
                     case 2:
-                        set_e820_range(ES, regs.u.r16.di,
-                                       0x000e8000L, 0x00100000L, 2);
-                        regs.u.r32.ebx = 3;
+                        MemMap.start = 0x000e8000L;
+                        MemMap.extra_start = 0;
+                        MemMap.end = 0x00100000L;
+                        MemMap.extra_end = 0;
+                        set_e820_range(ES, regs.u.r16.di, &MemMap, 2);
                         regs.u.r32.eax = 0x534D4150;
                         regs.u.r32.ecx = 0x14;
                         CLEAR_CF();
                         return;
                         break;
                     case 3:
+                        MemMap.start = 0x00100000L;
+                        MemMap.extra_start = 0;
+                        MemMap.end = extended_memory_size - ACPI_DATA_SIZE;
+                        MemMap.extra_end = 0;
                         set_e820_range(ES, regs.u.r16.di,
-                                       0x00100000L,
-                                       extended_memory_size - ACPI_DATA_SIZE, 1);
+                                       &MemMap, 1);
                         regs.u.r32.ebx = 4;
                         regs.u.r32.eax = 0x534D4150;
                         regs.u.r32.ecx = 0x14;
@@ -4219,9 +4248,12 @@
                         return;
                         break;
                     case 4:
+                        MemMap.start = extended_memory_size - ACPI_DATA_SIZE;
+                        MemMap.extra_start = 0;
+                        MemMap.end = extended_memory_size;
+                        MemMap.extra_end = 0;
                         set_e820_range(ES, regs.u.r16.di,
-                                       extended_memory_size - ACPI_DATA_SIZE,
-                                       extended_memory_size, 3); // ACPI RAM
+                                       &MemMap, 3); // ACPI RAM
                         regs.u.r32.ebx = 5;
                         regs.u.r32.eax = 0x534D4150;
                         regs.u.r32.ecx = 0x14;
@@ -4230,8 +4262,26 @@
                         break;
                     case 5:
                         /* 256KB BIOS area at the end of 4 GB */
-                        set_e820_range(ES, regs.u.r16.di,
-                                       0xfffc0000L, 0x00000000L, 2);
+                        MemMap.start = 0xfffc0000L;
+                        MemMap.extra_start = 0;
+                        MemMap.end = 0x00000000L;
+                        MemMap.extra_end = 0;
+                        set_e820_range(ES, regs.u.r16.di, &MemMap, 2);
+                        if (extra_highbits_memory_size || extra_lowbits_memory_size)
+                                regs.u.r32.ebx = 6;
+                        else 
+                                regs.u.r32.ebx = 0;
+                        regs.u.r32.eax = 0x534D4150;
+                        regs.u.r32.ecx = 0x14;
+                        CLEAR_CF();
+                        return;
+                    case 6:
+                        /* Maping of memory above 4 GB */
+                        MemMap.start = 0x0;
+                        MemMap.extra_start = 0x1;
+                        MemMap.end = extra_lowbits_memory_size + MemMap.start;
+                        MemMap.extra_end = extra_highbits_memory_size + MemMap.extra_start;
+                        set_e820_range(ES, regs.u.r16.di, &MemMap, 1);
                         regs.u.r32.ebx = 0;
                         regs.u.r32.eax = 0x534D4150;
                         regs.u.r32.ecx = 0x14;

[-- Attachment #3: qemu_ram_patch --]
[-- Type: application/octet-stream, Size: 9017 bytes --]

? .cpu-all.h.swp
? .cpu-exec.c.swp
? .exec-all.h.swp
? .exec.c.swp
? .vl.c.swp
? hw/.cirrus_vga.c.swp
? hw/.pc.c.swp
? hw/.vga.c.swp
? hw/.vga_int.h.swp
Index: cpu-all.h
===================================================================
RCS file: /sources/qemu/qemu/cpu-all.h,v
retrieving revision 1.74
diff -u -r1.74 cpu-all.h
--- cpu-all.h	29 Jul 2007 17:57:24 -0000	1.74
+++ cpu-all.h	14 Aug 2007 10:14:28 -0000
@@ -770,7 +770,7 @@
 
 /* memory API */
 
-extern int phys_ram_size;
+extern unsigned long phys_ram_size;
 extern int phys_ram_fd;
 extern uint8_t *phys_ram_base;
 extern uint8_t *phys_ram_dirty;
@@ -797,7 +797,7 @@
                                   unsigned long size,
                                   unsigned long phys_offset);
 uint32_t cpu_get_physical_page_desc(target_phys_addr_t addr);
-ram_addr_t qemu_ram_alloc(unsigned int size);
+ram_addr_t qemu_ram_alloc(unsigned long size);
 void qemu_ram_free(ram_addr_t addr);
 int cpu_register_io_memory(int io_index,
                            CPUReadMemoryFunc **mem_read,
Index: exec.c
===================================================================
RCS file: /sources/qemu/qemu/exec.c,v
retrieving revision 1.103
diff -u -r1.103 exec.c
--- exec.c	1 Jul 2007 18:21:11 -0000	1.103
+++ exec.c	14 Aug 2007 10:14:28 -0000
@@ -72,9 +72,11 @@
 #define TARGET_VIRT_ADDR_SPACE_BITS 42
 #elif defined(TARGET_PPC64)
 #define TARGET_PHYS_ADDR_SPACE_BITS 42
-#else
+#elif USE_KQEMU
 /* Note: for compatibility with kqemu, we use 32 bits for x86_64 */
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
+#else
+#define TARGET_PHYS_ADDR_SPACE_BITS 42
 #endif
 
 TranslationBlock tbs[CODE_GEN_MAX_BLOCKS];
@@ -86,7 +88,7 @@
 uint8_t code_gen_buffer[CODE_GEN_BUFFER_SIZE] __attribute__((aligned (32)));
 uint8_t *code_gen_ptr;
 
-int phys_ram_size;
+unsigned long phys_ram_size;
 int phys_ram_fd;
 uint8_t *phys_ram_base;
 uint8_t *phys_ram_dirty;
@@ -111,7 +113,7 @@
 
 typedef struct PhysPageDesc {
     /* offset in host memory of the page + io_index in the low 12 bits */
-    uint32_t phys_offset;
+    unsigned long phys_offset;
 } PhysPageDesc;
 
 #define L2_BITS 10
@@ -122,7 +124,7 @@
  */
 #define L1_BITS (TARGET_VIRT_ADDR_SPACE_BITS - L2_BITS - TARGET_PAGE_BITS)
 #else
-#define L1_BITS (32 - L2_BITS - TARGET_PAGE_BITS)
+#define L1_BITS (42 - L2_BITS - TARGET_PAGE_BITS)
 #endif
 
 #define L1_SIZE (1 << L1_BITS)
@@ -211,7 +213,7 @@
     memset(l1_phys_map, 0, L1_SIZE * sizeof(void *));
 }
 
-static inline PageDesc *page_find_alloc(unsigned int index)
+static inline PageDesc *page_find_alloc(unsigned long index)
 {
     PageDesc **lp, *p;
 
@@ -2029,7 +2031,7 @@
 }
 
 /* XXX: better than nothing */
-ram_addr_t qemu_ram_alloc(unsigned int size)
+ram_addr_t qemu_ram_alloc(unsigned long size)
 {
     ram_addr_t addr;
     if ((phys_ram_alloc_offset + size) >= phys_ram_size) {
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.323
diff -u -r1.323 vl.c
--- vl.c	29 Jul 2007 17:57:25 -0000	1.323
+++ vl.c	14 Aug 2007 10:14:29 -0000
@@ -116,7 +116,11 @@
 //#define DEBUG_UNUSED_IOPORT
 //#define DEBUG_IOPORT
 
+#if HOST_LONG_BITS < 64
 #define PHYS_RAM_MAX_SIZE (2047 * 1024 * 1024)
+#else
+#define PHYS_RAM_MAX_SIZE (2047 * 1024 * 1024 * 1024ULL)
+#endif
 
 #ifdef TARGET_PPC
 #define DEFAULT_RAM_SIZE 144
@@ -151,7 +155,7 @@
 const char* keyboard_layout = NULL;
 int64_t ticks_per_sec;
 int boot_device = 'c';
-int ram_size;
+unsigned long ram_size;
 int pit_min_timer_count = 0;
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
@@ -7471,7 +7475,7 @@
                 help(0);
                 break;
             case QEMU_OPTION_m:
-                ram_size = atoi(optarg) * 1024 * 1024;
+                ram_size = (unsigned long)atoi(optarg) * 1024 * 1024;
                 if (ram_size <= 0)
                     help(1);
                 if (ram_size > PHYS_RAM_MAX_SIZE) {
Index: vl.h
===================================================================
RCS file: /sources/qemu/qemu/vl.h,v
retrieving revision 1.259
diff -u -r1.259 vl.h
--- vl.h	31 Jul 2007 23:28:53 -0000	1.259
+++ vl.h	14 Aug 2007 10:14:30 -0000
@@ -145,7 +145,7 @@
 
 void main_loop_wait(int timeout);
 
-extern int ram_size;
+extern unsigned long ram_size;
 extern int bios_size;
 extern int rtc_utc;
 extern int cirrus_vga_enabled;
@@ -707,7 +707,7 @@
 
 #ifndef QEMU_TOOL
 
-typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size, 
+typedef void QEMUMachineInitFunc(unsigned long ram_size, int vga_ram_size, 
                                  int boot_device,
              DisplayState *ds, const char **fd_filename, int snapshot,
              const char *kernel_filename, const char *kernel_cmdline,
Index: hw/pc.c
===================================================================
RCS file: /sources/qemu/qemu/hw/pc.c,v
retrieving revision 1.81
diff -u -r1.81 pc.c
--- hw/pc.c	6 Jun 2007 16:26:13 -0000	1.81
+++ hw/pc.c	14 Aug 2007 10:14:30 -0000
@@ -152,7 +152,7 @@
 }
 
 /* hd_table must contain 4 block drivers */
-static void cmos_init(int ram_size, int boot_device, BlockDriverState **hd_table)
+static void cmos_init(unsigned long ram_size, unsigned long above_bios_ram_size, int boot_device, BlockDriverState **hd_table)
 {
     RTCState *s = rtc_state;
     int val;
@@ -174,6 +174,11 @@
     rtc_set_memory(s, 0x30, val);
     rtc_set_memory(s, 0x31, val >> 8);
 
+    val = (unsigned int)above_bios_ram_size / 65536;
+    rtc_set_memory(s, 0x5b, val);
+    rtc_set_memory(s, 0x5c, val >> 8);
+    rtc_set_memory(s, 0x5d, above_bios_ram_size/0x100000000);
+
     if (ram_size > (16 * 1024 * 1024))
         val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536);
     else
@@ -659,7 +664,7 @@
 }
 
 /* PC hardware initialisation */
-static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
+static void pc_init1(unsigned long ram_size, int vga_ram_size, int boot_device,
                      DisplayState *ds, const char **fd_filename, int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename,
@@ -667,7 +672,7 @@
 {
     char buf[1024];
     int ret, linux_boot, i;
-    ram_addr_t ram_addr, vga_ram_addr, bios_offset, vga_bios_offset;
+    ram_addr_t ram_addr, vga_ram_addr, bios_offset, vga_bios_offset, above_bios_mem_size = 0;
     int bios_size, isa_bios_size, vga_bios_size;
     PCIBus *pci_bus;
     int piix3_devfn = -1;
@@ -676,6 +681,10 @@
     qemu_irq *cpu_irq;
     qemu_irq *i8259;
 
+    if (ram_size >= 0xf0000000) {
+        above_bios_mem_size = ram_size - 0xf0000000;
+        ram_size = 0xf0000000;
+    }
     linux_boot = (kernel_filename != NULL);
 
     /* init CPUs */
@@ -695,8 +704,10 @@
     }
 
     /* allocate RAM */
-    ram_addr = qemu_ram_alloc(ram_size);
+    ram_addr = qemu_ram_alloc(ram_size + above_bios_mem_size);
     cpu_register_physical_memory(0, ram_size, ram_addr);
+    if(above_bios_mem_size > 0)
+        cpu_register_physical_memory(0x100000000, above_bios_mem_size, ram_addr + ram_size);
 
     /* allocate VGA RAM */
     vga_ram_addr = qemu_ram_alloc(vga_ram_size);
@@ -894,7 +905,7 @@
 
     floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd_table);
 
-    cmos_init(ram_size, boot_device, bs_table);
+    cmos_init(ram_size - 128 * 1024 * 1024, above_bios_mem_size, boot_device, bs_table);
 
     if (pci_enabled && usb_enabled) {
         usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
@@ -933,7 +944,7 @@
 #endif
 }
 
-static void pc_init_pci(int ram_size, int vga_ram_size, int boot_device,
+static void pc_init_pci(unsigned long ram_size, int vga_ram_size, int boot_device,
                         DisplayState *ds, const char **fd_filename, 
                         int snapshot, 
                         const char *kernel_filename, 
@@ -947,7 +958,7 @@
              initrd_filename, 1);
 }
 
-static void pc_init_isa(int ram_size, int vga_ram_size, int boot_device,
+static void pc_init_isa(unsigned long ram_size, int vga_ram_size, int boot_device,
                         DisplayState *ds, const char **fd_filename, 
                         int snapshot, 
                         const char *kernel_filename, 
Index: hw/vga.c
===================================================================
RCS file: /sources/qemu/qemu/hw/vga.c,v
retrieving revision 1.55
diff -u -r1.55 vga.c
--- hw/vga.c	10 Jun 2007 17:01:00 -0000	1.55
+++ hw/vga.c	14 Aug 2007 10:14:30 -0000
@@ -1415,10 +1415,11 @@
 static void vga_draw_graphic(VGAState *s, int full_update)
 {
     int y1, y, update, page_min, page_max, linesize, y_start, double_scan, mask;
-    int width, height, shift_control, line_offset, page0, page1, bwidth;
+    int width, height, shift_control, line_offset, bwidth;
     int disp_width, multi_scan, multi_run;
     uint8_t *d;
     uint32_t v, addr1, addr;
+    unsigned long page0, page1;
     vga_draw_line_func *vga_draw_line;
     
     full_update |= update_basic_params(s);

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-08-16 18:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-14 16:11 [Qemu-devel] adding support for above 2giga for qemu. ( include patchs ) Izik Eidus
2007-08-14 19:51 ` Blue Swirl
2007-08-16 18:41 ` Blue Swirl
2007-08-16 18:45   ` Izik Eidus
  -- strict thread matches above, loose matches on Subject: below --
2007-08-14 11:22 Izik Eidus
2007-08-14 14:50 ` Blue Swirl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).