From patchwork Wed Jan 25 11:26:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orit Wasserman X-Patchwork-Id: 137817 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C2BDAB6EF1 for ; Thu, 26 Jan 2012 05:26:21 +1100 (EST) Received: from localhost ([::1]:57950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq7Y2-0005BI-Vn for incoming@patchwork.ozlabs.org; Wed, 25 Jan 2012 13:26:18 -0500 Received: from eggs.gnu.org ([140.186.70.92]:37602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq12X-0003h7-ET for qemu-devel@nongnu.org; Wed, 25 Jan 2012 06:29:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rq12S-0000e4-BV for qemu-devel@nongnu.org; Wed, 25 Jan 2012 06:29:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:7774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq12S-0000dv-4p for qemu-devel@nongnu.org; Wed, 25 Jan 2012 06:29:16 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0PBTEkv032149 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 25 Jan 2012 06:29:14 -0500 Received: from dhcp-1-120.tlv.redhat.com (vpn-203-111.tlv.redhat.com [10.35.203.111]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q0PBSn5u018677; Wed, 25 Jan 2012 06:29:12 -0500 From: Orit Wasserman To: qemu-devel@nongnu.org Date: Wed, 25 Jan 2012 13:26:40 +0200 Message-Id: <1327490809-21393-3-git-send-email-owasserm@redhat.com> In-Reply-To: <1327490809-21393-1-git-send-email-owasserm@redhat.com> References: <1327490809-21393-1-git-send-email-owasserm@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 X-Mailman-Approved-At: Wed, 25 Jan 2012 13:26:03 -0500 Cc: blauwirbel@gmail.com, stefanha@gmail.com, Orit Wasserman , avi@redhat.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH v6 02/11] Add uleb encoding/decoding functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Implement Unsigned Little Endian Base 128. Signed-off-by: Orit Wasserman --- migration.h | 4 ++++ savevm.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/migration.h b/migration.h index 372b066..50dec18 100644 --- a/migration.h +++ b/migration.h @@ -95,4 +95,8 @@ void migrate_add_blocker(Error *reason); */ void migrate_del_blocker(Error *reason); +/* ULEB128 */ +int uleb128_encode_small(uint8_t *out, uint32_t n); +int uleb128_decode_small(const uint8 *in, uint32_t *n); + #endif diff --git a/savevm.c b/savevm.c index 80be1ff..304db31 100644 --- a/savevm.c +++ b/savevm.c @@ -2297,3 +2297,29 @@ void vmstate_register_ram_global(MemoryRegion *mr) { vmstate_register_ram(mr, NULL); } + +/* ULEB128 */ +int uleb128_encode_small(uint8_t *out, uint32_t n) +{ + if (n < 0x80) { + *out++ = n; + return 1; + } else { + *out++ = (n & 0x7f) | 0x80; + *out++ = n >> 7; + } + return 0; +} + +int uleb128_decode_small(const uint8 *in, uint32_t *n) +{ + if (!(*in & 0x80)) { + *n = *in++; + return 1; + } else { + *n = *in++ & 0x7f; + *n |= *in++ << 7; + return 0; + } +} +