From: Glauber Costa Subject: [PATCH] compute checksum for roms bigger than a segment Date: Mon, 23 Mar 2009 18:55:01 -0300 Message-ID: <1237845301-15796-1-git-send-email-glommer@redhat.com> Cc: kvm@vger.kernel.org, bochs-developers@lists.sourceforge.net To: qemu-devel@nongnu.org Return-path: Received: from mx2.redhat.com ([66.187.237.31]:38097 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756458AbZCWV6p (ORCPT ); Mon, 23 Mar 2009 17:58:45 -0400 Sender: kvm-owner@vger.kernel.org List-ID: Some option roms (e1000 provided by gpxe project as an example) are bigger than a segment. The current algorithm to compute the checksum fails in such case. To proper compute the checksum, this patch deals with the possibility of the rom's size crossing a segment border. We don't need to worry about it crossing more than one segment border, since the option roms format only save one byte to store the image size (thus, maximum size = 0xff = 128k = 2 segments) Signed-off-by: Glauber Costa --- bios/rombios.c | 33 +++++++++++++++++++++++++++------ 1 files changed, 27 insertions(+), 6 deletions(-) diff --git a/bios/rombios.c b/bios/rombios.c index bc43251..6fede17 100644 --- a/bios/rombios.c +++ b/bios/rombios.c @@ -10162,22 +10162,43 @@ no_serial: ret rom_checksum: - push ax - push bx - push cx + pusha + push ds + xor ax, ax xor bx, bx xor cx, cx + xor dx, dx + mov ch, [2] shl cx, #1 + + jnc checksum_loop + mov dx, cx + mov cx, #0xffff + checksum_loop: add al, [bx] inc bx loop checksum_loop + + cmp dx, #0 + je checksum_out + + add al, [bx] + mov cx, dx + mov dx, ds + add dx, #0x1000 + mov ds, dx + xor dx, dx + xor bx, bx + + jmp checksum_loop + +checksum_out: and al, #0xff - pop cx - pop bx - pop ax + pop ds + popa ret -- 1.6.1.2