be685f7
From 664484dc8aa91fff6c8906ede14ce492b7904129 Mon Sep 17 00:00:00 2001
be685f7
From: Glauber Costa <glommer@redhat.com>
be685f7
Date: Wed, 24 Jun 2009 14:31:41 +0100
be685f7
Subject: [PATCH 13/18] compute checksum for roms bigger than a segment
be685f7
be685f7
Some option roms (e1000 provided by gpxe project as an example)
be685f7
are bigger than a segment. The current algorithm to compute the
be685f7
checksum fails in such case. To proper compute the checksum, this
be685f7
patch deals with the possibility of the rom's size crossing a
be685f7
segment border.
be685f7
be685f7
We don't need to worry about it crossing more than one segment
be685f7
border, since the option roms format only save one byte to store
be685f7
the image size (thus, maximum size = 0xff = 128k = 2 segments)
be685f7
be685f7
[ including improvements suggested by malc ]
be685f7
be685f7
Signed-off-by: Glauber Costa <glommer@redhat.com>
be685f7
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
be685f7
---
be685f7
 kvm/bios/rombios.c |   33 +++++++++++++++++++++++++++------
be685f7
 1 files changed, 27 insertions(+), 6 deletions(-)
be685f7
35aa518
diff --git a/kvm/bios/rombios.c b/kvm/bios/rombios.c
Glauber Costa 3afbf09
index c4f6ccd..c4bfe60 100644
35aa518
--- a/kvm/bios/rombios.c
35aa518
+++ b/kvm/bios/rombios.c
Glauber Costa 3afbf09
@@ -10196,22 +10196,43 @@ no_serial:
Glauber Costa 3afbf09
   ret
Glauber Costa 3afbf09
 
Glauber Costa 3afbf09
 rom_checksum:
Glauber Costa 3afbf09
-  push ax
Glauber Costa 3afbf09
-  push bx
Glauber Costa 3afbf09
-  push cx
Glauber Costa 3afbf09
+  pusha
Glauber Costa 3afbf09
+  push ds
Glauber Costa 3afbf09
+
Glauber Costa 3afbf09
   xor  ax, ax
Glauber Costa 3afbf09
   xor  bx, bx
Glauber Costa 3afbf09
   xor  cx, cx
Glauber Costa 3afbf09
+  xor  dx, dx
Glauber Costa 3afbf09
+
Glauber Costa 3afbf09
   mov  ch, [2]
Glauber Costa 3afbf09
   shl  cx, #1
Glauber Costa 3afbf09
+
Glauber Costa 3afbf09
+  jnc checksum_loop
Glauber Costa 3afbf09
+  xchg dx, cx
Glauber Costa 3afbf09
+  dec  cx
Glauber Costa 3afbf09
+
Glauber Costa 3afbf09
 checksum_loop:
Glauber Costa 3afbf09
   add  al, [bx]
Glauber Costa 3afbf09
   inc  bx
Glauber Costa 3afbf09
   loop checksum_loop
Glauber Costa 3afbf09
+
Glauber Costa 3afbf09
+  test dx, dx 
Glauber Costa 3afbf09
+  je checksum_out
Glauber Costa 3afbf09
+
Glauber Costa 3afbf09
+  add  al, [bx]
Glauber Costa 3afbf09
+  mov  cx, dx
Glauber Costa 3afbf09
+  mov  dx, ds
Glauber Costa 3afbf09
+  add  dh, #0x10
Glauber Costa 3afbf09
+  mov  ds, dx
Glauber Costa 3afbf09
+  xor  dx, dx 
Glauber Costa 3afbf09
+  xor  bx, bx
Glauber Costa 3afbf09
+
Glauber Costa 3afbf09
+  jmp  checksum_loop
Glauber Costa 3afbf09
+
Glauber Costa 3afbf09
+checksum_out:
Glauber Costa 3afbf09
   and  al, #0xff
Glauber Costa 3afbf09
-  pop  cx
Glauber Costa 3afbf09
-  pop  bx
Glauber Costa 3afbf09
-  pop  ax
Glauber Costa 3afbf09
+  pop  ds
Glauber Costa 3afbf09
+  popa 
Glauber Costa 3afbf09
   ret
be685f7
 
be685f7
 
be685f7
-- 
be685f7
1.6.2.2
be685f7