Frediano Ziglio
2013-Feb-08 12:58 UTC
[syslinux] [PATCH] 4k_sector: Support dynamic sectors in GPT MBR
This patches add support for dynamic sectors to GPT MBR code. First 3 patches are trick and optimizations to gain some space for the forth patch. I have a modified version of SeaBIOS, some code and some script o test it I'll send on a different mail.
Frediano Ziglio
2013-Feb-08 12:58 UTC
[syslinux] [PATCH 1/4] 4k_sector: Recover 3 bytes avoid a call
after read_sector %edx:%eax are unused or incremented so increment always at end gaining 3 bytes Signed-off-by: Frediano Ziglio <frediano.ziglio at citrix.com> --- mbr/gptmbr.S | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mbr/gptmbr.S b/mbr/gptmbr.S index ae0549f..ef2235d 100644 --- a/mbr/gptmbr.S +++ b/mbr/gptmbr.S @@ -142,7 +142,6 @@ next: pushw %bx get_ptab: call read_sector - call inc64 loopw get_ptab /* Find the boot partition */ @@ -240,16 +239,9 @@ saturate_stosl: ret /* - * Increment %edx:%eax - */ -inc64: - addl $1,%eax - adcl $0,%edx - ret - -/* * read_sector: read a single sector pointed to by %edx:%eax to * %es:%bx. CF is set on error. All registers saved. + * %edx:%eax and %es:%bx are incremented to read next sector */ read_sector: pushal @@ -282,6 +274,15 @@ read_common: popal jc disk_error addb $2, %bh /* bx += 512: point to the next buffer */ + + /* fall through and increment sector number */ + +/* + * Increment %edx:%eax + */ +inc64: + addl $1,%eax + adcl $0,%edx ret disk_error: -- 1.7.9.5
Frediano Ziglio
2013-Feb-08 12:58 UTC
[syslinux] [PATCH 2/4] 4k_sector: Save some bytes adding a function to set bx before read_sector
Mostly of the time bx was set as phdr before calling read_sector so add a specific function to set %bx and call read_sector gaining 2 bytes Signed-off-by: Frediano Ziglio <frediano.ziglio at citrix.com> --- mbr/gptmbr.S | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mbr/gptmbr.S b/mbr/gptmbr.S index ef2235d..f73b472 100644 --- a/mbr/gptmbr.S +++ b/mbr/gptmbr.S @@ -118,9 +118,7 @@ next: xorl %eax,%eax cltd incw %ax /* %edx:%eax = 1 */ - movw $phdr, %bx - pushw %bx /* -8(%bp) phdr == bootsect */ - call read_sector + call read_sector_phdr /* Number of partition sectors */ /* We assume the partition table is 32K or less, and that @@ -215,8 +213,7 @@ found_part: boot: movl (32+20)(%si),%eax movl (36+20)(%si),%edx - popw %bx - call read_sector + call read_sector_phdr cmpw $0xaa55, -2(%bx) jne missing_os /* Not a valid boot sector */ movw %bp, %sp /* driveno == bootsec-6 */ @@ -238,6 +235,11 @@ saturate_stosl: 1: stosl ret +read_sector_phdr: + movw $phdr, %bx + + /* fall through and read sector */ + /* * read_sector: read a single sector pointed to by %edx:%eax to * %es:%bx. CF is set on error. All registers saved. -- 1.7.9.5
Frediano Ziglio
2013-Feb-08 12:58 UTC
[syslinux] [PATCH 3/4] 4k_sector: Reduce size reducing a message
Easy way to reduce code but actually I found the message is readable at the same way as previous. Signed-off-by: Frediano Ziglio <frediano.ziglio at citrix.com> --- mbr/gptmbr.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mbr/gptmbr.S b/mbr/gptmbr.S index f73b472..b0c11b9 100644 --- a/mbr/gptmbr.S +++ b/mbr/gptmbr.S @@ -289,7 +289,7 @@ inc64: disk_error: call error - .ascii "Disk error on boot\r\n" + .ascii "Disk error\r\n" /* * Print error messages. This is invoked with "call", with the -- 1.7.9.5
Frediano Ziglio
2013-Feb-08 12:58 UTC
[syslinux] [PATCH 4/4] 4k_sector: Support sectors >512
If EBIOS is detected for this drive it tries to read sector size and use it. If error or no EBIOS 512 is assumed. Buffer to read sector size is always allocated into the stack. CHS informations are not readed as not needed and save space not restoring %dl for drive number. Signed-off-by: Frediano Ziglio <frediano.ziglio at citrix.com> --- mbr/gptmbr.S | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/mbr/gptmbr.S b/mbr/gptmbr.S index b0c11b9..88d2809 100644 --- a/mbr/gptmbr.S +++ b/mbr/gptmbr.S @@ -77,6 +77,12 @@ next: ADJUST_DRIVE pushw %dx /* 0(%bp) = %dl -> drive number */ + movw %sp, %bp /* %bp -> frame pointer: LEAVE UNCHANGED */ + + /* prepare to read sector size */ + sub $0x1c, %sp /* -28(%bp) == %sp */ + pushw $0x1e /* -30(%bp) == %sp */ + movw $0x200, -6(%bp) /* -6(%bp) sector size */ /* Check to see if we have EBIOS */ pushw %dx /* drive number */ @@ -86,6 +92,8 @@ next: xorb %dh, %dh stc int $0x13 + popw %dx /* restore drive */ + movb $0x08, %ah /* get CHS geometry */ jc 1f cmpw $0xaa55, %bx jne 1f @@ -97,22 +105,28 @@ next: movl $0xeb42b4+((read_common-read_sector_cbios-4) << 24), \ (read_sector_cbios) -1: - popw %dx + /* + * read sector size. + * Should not fail but if it does I assume that at least + * previous 512 value is not overridden + */ + movb $0x48, %ah + movw %sp, %si +1: /* Get (C)HS geometry */ - movb $0x08, %ah int $0x13 + + /* here we computer CHS values or just do some dummy computation for EBIOS */ andw $0x3f, %cx /* Sector count */ - movw %sp, %bp /* %bp -> frame pointer: LEAVE UNCHANGED */ - pushw %cx /* -2(%bp) Save sectors on the stack */ + pushw %cx /* -32(%bp) Save sectors on the stack */ movzbw %dh, %ax /* dh = max head */ incw %ax /* From 0-based max to count */ mulw %cx /* Heads*sectors -> sectors per cylinder */ /* Save sectors/cylinder on the stack */ - pushw %dx /* -4(%bp) High word */ - pushw %ax /* -6(%bp) Low word */ + pushw %dx /* -34(%bp) High word */ + pushw %ax /* -36(%bp) Low word */ /* Load partition table header */ xorl %eax,%eax @@ -121,15 +135,14 @@ next: call read_sector_phdr /* Number of partition sectors */ - /* We assume the partition table is 32K or less, and that - the sector size is 512. */ + /* We assume the partition table is 32K or less */ /* Note: phdr == 6(%bp) */ movw (80+6)(%bp),%cx /* NumberOfPartitionEntries */ movw (84+6)(%bp),%ax /* SizeOfPartitionEntry */ pushw %ax pushw %cx mulw %cx - shrw $9,%ax + divw -6(%bp) /* %dx == 0 here */ xchgw %ax,%cx incw %cx @@ -214,7 +227,7 @@ boot: movl (32+20)(%si),%eax movl (36+20)(%si),%edx call read_sector_phdr - cmpw $0xaa55, -2(%bx) + cmpw $0xaa55, (0x7c00+0x1fe) jne missing_os /* Not a valid boot sector */ movw %bp, %sp /* driveno == bootsec-6 */ popw %dx /* dl -> drive number */ @@ -258,12 +271,12 @@ read_sector: /* This chunk is skipped if we have ebios */ /* Do not clobber %es:%bx or %edx:%eax before this chunk! */ read_sector_cbios: - divl -6(%bp) /* secpercyl */ + divl -36(%bp) /* secpercyl */ shlb $6, %ah movb %ah, %cl movb %al, %ch xchgw %dx, %ax - divb -2(%bp) /* sectors */ + divb -32(%bp) /* sectors */ movb %al, %dh orb %ah, %cl incw %cx /* Sectors are 1-based */ @@ -275,7 +288,7 @@ read_common: leaw 16(%si), %sp /* Drop DAPA */ popal jc disk_error - addb $2, %bh /* bx += 512: point to the next buffer */ + addb -5(%bp), %bh /* bx += sector size: point to the next buffer */ /* fall through and increment sector number */ -- 1.7.9.5
Matt Fleming
2013-Feb-11 11:55 UTC
[syslinux] [PATCH 1/4] 4k_sector: Recover 3 bytes avoid a call
On Fri, 08 Feb, at 12:58:33PM, Frediano Ziglio wrote:> after read_sector %edx:%eax are unused or incremented so increment > always at end gaining 3 bytes > > Signed-off-by: Frediano Ziglio <frediano.ziglio at citrix.com> > --- > mbr/gptmbr.S | 19 ++++++++++--------- > 1 file changed, 10 insertions(+), 9 deletions(-)Seems fine to me. Applied to the elflink branch, thanks! -- Matt Fleming, Intel Open Source Technology Center
Matt Fleming
2013-Feb-11 12:28 UTC
[syslinux] [PATCH 3/4] 4k_sector: Reduce size reducing a message
On Fri, 08 Feb, at 12:58:35PM, Frediano Ziglio wrote:> Easy way to reduce code but actually I found the message is > readable at the same way as previous. > > Signed-off-by: Frediano Ziglio <frediano.ziglio at citrix.com> > --- > mbr/gptmbr.S | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-)Applied, thanks! -- Matt Fleming, Intel Open Source Technology Center