From owner-freebsd-hardware@FreeBSD.ORG Mon Sep 19 13:49:52 2011 Return-Path: Delivered-To: freebsd-hardware@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4C61C106564A for ; Mon, 19 Sep 2011 13:49:52 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 9B60E8FC18 for ; Mon, 19 Sep 2011 13:49:51 +0000 (UTC) Received: from odyssey.starpoint.kiev.ua (alpha-e.starpoint.kiev.ua [212.40.38.101]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id QAA11825; Mon, 19 Sep 2011 16:39:43 +0300 (EEST) (envelope-from avg@FreeBSD.org) Message-ID: <4E77461E.4050001@FreeBSD.org> Date: Mon, 19 Sep 2011 16:39:42 +0300 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:6.0.2) Gecko/20110907 Thunderbird/6.0.2 MIME-Version: 1.0 To: freebsd-hardware@FreeBSD.org X-Enigmail-Version: undefined Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: John Baldwin Subject: magic constants in btxldr/btxcsu X-BeenThere: freebsd-hardware@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General discussion of FreeBSD hardware List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Sep 2011 13:49:52 -0000 I was looking at how btx works and in particular how arguments are passed from boot2-ish to loader. It seems that the code that implements that logic uses a few integer literals which make the code not quite obvious. For example: movl $0x48,%ecx # Allocate space subl %ecx,%ebp # for bootinfo movl 0x18(%esp,1),%esi # Source: bootinfo cmpl $0x0, %esi # If the bootinfo pointer je start_null_bi # is null, don't copy it movl %ebp,%edi # Destination rep # Copy movsb # it movl %ebp,0x18(%esp,1) # Update pointer #ifdef BTXLDR_VERBOSE movl $m_rel_bi,%esi # Display movl %ebp,%eax # bootinfo call hexout # relocation call putstr # message #endif start_null_bi: movl $0x18,%ecx # Allocate space subl %ecx,%ebp # for arguments leal 0x4(%esp,1),%esi # Source movl %ebp,%edi # Destination rep # Copy movsb # them Once I looked at this code I was able to understand how things work, but finding this code was not easy. So, apparently 0x48 should be a size of bootinfo; 0x18(%esp,1) should be a magic offset of bootinfo pointer in the args on the stack; 0x18 should be a combined size of arguments; 0x4(%esp,1),%esi should be a start of the arguments. Then, there is this: .set ARGADJ,0xfa0 # Argument adjustment It seems that the magic value is constructed as 0x1000 - (0x48 + 0x18), where 0x48 and 0x18 come from the previous snippet. But this is not obvious again. I am not fluent with that code at all to suggest any changes. But maybe these constants could be defined more prominently and somehow bound together. -- Andriy Gapon