Date: Mon, 19 Sep 2011 16:39:42 +0300 From: Andriy Gapon <avg@FreeBSD.org> To: freebsd-hardware@FreeBSD.org Cc: John Baldwin <jhb@FreeBSD.org> Subject: magic constants in btxldr/btxcsu Message-ID: <4E77461E.4050001@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4E77461E.4050001>
