From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id DC2113857BB3 for ; Sun, 13 Nov 2022 23:02:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DC2113857BB3 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x433.google.com with SMTP id b185so9473388pfb.9 for ; Sun, 13 Nov 2022 15:02:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=L5THJQxkgZkrvWYyWdOc1/tHnnAUUTk57qrEWNE6/po=; b=bbv1N+9vl0wWWZ46uviXvBFsslFbhFuzfwArToZuiEl1hcAAlmu/CzwSr/EGjARoT/ a768Z9yN9o6piPpKlF6Ex74F60kwyUIqVmywykxzPxS37SgaBZyWfRWOuTp5FxmYBJ// yB4U8D2c7PXKtVg4wTbFONROL+/Z5M7mzj3aTuaam7pRA2kYWlSwH9zJu2lHKUe9duZ9 vqP+q6WOBLM7zAJ8XEOoCokzEWE24dJoyBuFSl/5L7KjwB7d8LGohv632c1GcZOeihep XyD12kMwq5MPWv22YLoEqEtL5/i5DnEfryiQTfvbDVuu1+uxo01HVFirp7ozeycNv662 WK0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=L5THJQxkgZkrvWYyWdOc1/tHnnAUUTk57qrEWNE6/po=; b=NeZQ9rSpCWkNZfmXYwfc8OAzI+qftDVfTTBwm7RtQ7yBxfDfodE/fJtEW7P2HvSvEx mB4Gw/OzS5l7pWECJOUuvhowa5gxXAyC8Kt/vVTAbxct+oLrqU5cUL92vU1AjPZm2SHf P4BGt3IgGHl8I0gmtTqaFv8CgRWH2xNmSL0YC9wIoidstwWjaXXx6HqZcsczgWogd2AO DqNvXSAvfTB3TbZvbdvb7lq92R6JOpk1siYNxyqnK4Z5Y++Vk0H1xvq7uk1AxvX/e3o5 wWiPinvqCE4ky9njwBEf/xTs7IxDy/IlOrO/2cqe0Wp49p+MdkKDGUfBRwsxt4Ug8Uia eEVA== X-Gm-Message-State: ANoB5pnq4RJoIN7J37v6kJ3bx0Cu1RZkZYUTHPY0gkhM955spHMy2c88 PT4WdLmn4esfpQ6YPRhLUTMzf7mm9TzOaULGBBgm/V81BZs= X-Google-Smtp-Source: AA0mqf7ePST4m8WEi65LetiexxPHuTX5QPpD9IDT5CHntrcskMyx3VYyDQc98byPqEvl55JrlBXm082OFLGZxn1yWDw= X-Received: by 2002:a63:cc0e:0:b0:473:e501:8c03 with SMTP id x14-20020a63cc0e000000b00473e5018c03mr9701635pgf.539.1668380521611; Sun, 13 Nov 2022 15:02:01 -0800 (PST) MIME-Version: 1.0 From: Maxim Blinov Date: Sun, 13 Nov 2022 23:01:50 +0000 Message-ID: Subject: Coercing GDB to disassemble Intel 16-bit code To: gdb@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi all, I was hacking some MBR bootloader code today, but I've hit an annoyance: GDB isn't over-keen on disassembling the code as 16-bit intel code. The target is qemu-system-i386, launched to wait on a GDB connection over tcp:9000. Below is my GDB session to illustrate: (gdb) tar rem :9000 Remote debugging using :9000 warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x0000fff0 in ?? () (gdb) b *0x7c00 Breakpoint 1 at 0x7c00 (gdb) c Continuing. Thread 1 hit Breakpoint 1, 0x00007c00 in ?? () (gdb) set architecture i8086 The target architecture is set to "i8086". (gdb) disas /r 0x7c00,+20 Dump of assembler code from 0x7c00 to 0x7c14: => 0x00007c00: e8 00 00 eb 3b call 0x3beb7c05 0x00007c05: 00 00 add %al,(%eax) 0x00007c07: 00 10 add %dl,(%eax) 0x00007c09: 00 00 add %al,(%eax) 0x00007c0b: 00 c7 add %al,%bh 0x00007c0d: 02 00 add (%eax),%al 0x00007c0f: 00 ac 71 00 00 d2 7b add %ch,0x7bd20000(%ecx,%esi,2) End of assembler dump. (gdb) Infact most of that is bogus anyway (the `add`'s are just trying to disassembly zeroes): but the very first `call` should be to 0x7c05, not 0x3beb7c05! Infact GDB has merged two instructions into one. Objdump gives the correct disassembly, as below: $ objdump -m i8086 -b binary --adjust-vma=0x7c00 -D bootsect.img | head -n 100 ... 00007c00 <.data>: 7c00: e8 00 00 call 0x7c03 7c03: eb 3b jmp 0x7c40 7c05: 00 00 add %al,(%bx,%si) 7c07: 00 10 add %dl,(%bx,%si) 7c09: 00 00 add %al,(%bx,%si) ... Any ideas?