From: chaac@nic.fi
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] Move assembly code out of the kernel
Date: Thu, 31 Jul 2008 16:55:11 +0300 (EEST) [thread overview]
Message-ID: <23656916.573861217512511895.JavaMail.chaac@nic.fi> (raw)
Bean [bean123ch@gmail.com] kirjoitti:
> Hi,
>
> Currently, most assembly code are in startup.S. This is normally used
> to ensure that the function address are below 1m, which is required if
> it would switch to real mode and call bios services. However, this
> make the kernel larger. For example, the biosdisk functions are only
> used by biodisk module, they should not be placed inside the kernel.
>
> This patch support splitting such code from startup.S. For example, we
> create a new module biosdisk_stub.mod for assembly code of biosdisk.
> Instead of call prot_to_real and real_to_prot, we call
> grub_call_real_stub to enter real mode. grub_call_real_stub would copy
> the code to real mode and do the mode switch.
>
> To avoid unnecessary memory transfer, grub_call_real_stub would not
> erase the real mode stub when it's done, so that it can be used
> directly next time. When the stub area is full, it zero it out and
> start anew. The area uses a simple verification method so that the old
> mapping is invalidated, the code would need be copied again on their
> next use.
>
> The patch shows how to do it for the biosdisk module, here is the new
> grub_biosdisk_rw_int13_extensions function.
>
> REAL_STUB_START(grub_biosdisk_rw_int13_extensions)
> movb %dh, %ah
> movw %cx, %ds
> int $0x13 /* do the operation */
> movb %ah, %dl /* save return value */
> lret
> REAL_STUB_END(grub_biosdisk_rw_int13_extensions)
>
> FUNCTION(grub_biosdisk_rw_int13_extensions)
> pushl %ebp
> pushl %esi
>
> /* compute the address of disk_address_packet */
> movw %cx, %si
> xorw %cx, %cx
> shrl $4, %ecx /* save the segment to cx */
>
> /* ah */
> movb %al, %dh
>
> leal grub_biosdisk_rw_int13_extensions_stub, %eax
> call EXT_C(grub_call_real_stub)
>
> movb %dl, %al /* return value in %eax */
>
> popl %esi
> popl %ebp
>
> ret
>
> Real mode code is enclosed between REAL_STUB_START and REAL_STUB_END,
> no need to use .code16 and .code32 as it's handled by the macro. In
> the main function, use
>
> leal grub_biosdisk_rw_int13_extensions_stub, %eax
> call EXT_C(grub_call_real_stub)
>
> to invoke grub_call_real_stub. grub_biosdisk_rw_int13_extensions_stub
> is defined in the REAL_STUB_START macro.
>
> This same method can be applied to loaders, vbe, etc. In fact, almost
> all function behind grub_call_real_stub can be moved out of startup.S.
I have made generic function that does basically the same thing for bios service 0x10 (video). In that modification you prepare registers structure that will be configured during real mode switching. I am yet to commit it for review, but I think it would be more generic way to do this. When I come back from my holiday I will commit the code for review.
So please wait a bit before committing this :)
Thanks,
Vesa Jääskeläinen
next reply other threads:[~2008-07-31 13:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-31 13:55 chaac [this message]
2008-08-17 11:31 ` [PATCH] Move assembly code out of the kernel Vesa Jääskeläinen
2008-08-17 16:55 ` Bean
2008-08-24 9:37 ` Vesa Jääskeläinen
-- strict thread matches above, loose matches on Subject: below --
2008-07-30 21:20 Bean
2008-07-31 7:46 ` Bean
2008-07-31 11:22 ` Robert Millan
2008-07-31 13:56 ` Bean
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=23656916.573861217512511895.JavaMail.chaac@nic.fi \
--to=chaac@nic.fi \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.