Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1FdL8N-0007Q8-FG for mharc-grub-devel@gnu.org; Tue, 09 May 2006 01:51:47 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FdL8K-0007NE-Pf for grub-devel@gnu.org; Tue, 09 May 2006 01:51:44 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FdL8H-0007Jt-VI for grub-devel@gnu.org; Tue, 09 May 2006 01:51:44 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FdL8H-0007JH-Ly for grub-devel@gnu.org; Tue, 09 May 2006 01:51:41 -0400 Received: from [212.27.42.29] (helo=smtp3-g19.free.fr) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FdL9F-0005fN-2h for grub-devel@gnu.org; Tue, 09 May 2006 01:52:43 -0400 Received: from yoda (std93-4-82-229-216-106.fbx.proxad.net [82.229.216.106]) by smtp3-g19.free.fr (Postfix) with ESMTP id 7D37A478E1 for ; Tue, 9 May 2006 07:51:34 +0200 (CEST) From: =?iso-8859-1?Q?Eric_Salom=E9?= To: "'The development of GRUB 2'" Date: Tue, 9 May 2006 07:51:32 +0200 Message-ID: <000001c6732c$a18d38e0$0b00a8c0@yoda> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0001_01C6733D.65178F80" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 Importance: Normal In-Reply-To: <87irokn1k8.fsf@xs4all.nl> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 Subject: RE : RE : grub-emu state of the art X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 May 2006 05:51:45 -0000 This is a multi-part message in MIME format. ------=_NextPart_000_0001_01C6733D.65178F80 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0002_01C6733D.65191620" ------=_NextPart_001_0002_01C6733D.65191620 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi folks, =20 This email to explain how I worked on grub-emu module loading, the choices I have made (for now) and the diff from grub-1.93 delivery. Marco asked me for details (well, that will make it a pretty long email :-)). =20 I worked only on the i386-pc architecture but I believe same steps will lead to a working grub-emu with module loading on powerpc architecture (though I can't do that myself). =20 I=92ve got results : My modules are loading fine, but That may be by chance :-) (I still have great doubts about memory management). So take a close look at what I=92ve done before agreeing/committing changes and yell if I=92ve done anything foolish. =20 There is still work to do, as you=92ll see : =20 Have it compile :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::: First, I had to deal with the main problem on PC: Current delivery of grub-1.93 requires kernel and modules to be compiled with -mregparm=3D3 -mrtd options.=20 Parameters are passed to functions using registers instead of using memory in stack. Assembler code presume that asm functions are called that way too. This is not the standard way libc functions are used to. =20 Also, note that even with -mregparm=3D3 and -mrtd options, parameters = are passed using stack to functions with an undefined number of parameters (such as grub_printf : Those functions in turn expected their parameters in stack). If you don't provide good prototype to functions in your modules that leads to unexpected results. =20 To have a grub-emu compile with these options : a. Either you need to compile a new "libc" library using same options b. Either you can provide grub-emu source files with a "foolyou" prototype include file for all C functions called in libc (there are currently not too many), saying for example : =20 off_t lseek(int fildes, off_t offset, int whence, ...);=20 =20 The ending ... will ask the C compiler to pass all parameters in stack (the way the libc wants it for all functions).=20 And try to compile (I really didn't try that, I was too afraid the compiler would voice me about mismatchs in prototype between Linux standard include files and my "foolme" prototype file. I believe that things would be worst with time, since other modules to come would like to use more library calls (in libc and in other standard libs). =20 I'd rather made the following choices : --------------------------------------- =20 1. Provide new asm code that support for passing parameters in stack, instead of from registers. 2. Change compile options so that the all Grub 2 delivery would now be using passing parameters using stack (and thus I get ride of libc incompatibility) 3. Keep support for "optimized" code (using -mregparm=3D3 -mrtd) just in case someone feels like he can't live without it ;-). =20 New Makefile (i386-pc.mk) shows : #COMMON_ASFLAGS =3D -nostdinc -fno-builtin -DREGPARM #COMMON_CFLAGS =3D -fno-builtin -mrtd -mregparm=3D3 -m32 =20 COMMON_ASFLAGS =3D -nostdinc -fno-builtin COMMON_CFLAGS =3D $(CFLAGS) -m32 =20 Using the first two lines does create optimized and shorter code for kernel and modules (but you won=92t be able to launch grub-emu). The difference is about 210316 bytes against 212684 (for all the modules I have) : 1 % shorter. =20 Using the last two lines, the good news is you can use same modules for grub 2 and for grub-emu, and it compiles fine. =20 Don=92t forget to add the following lines also, to be sure grub-emu is compiled with the same options as the (COMMON) modules (that=92s only = for ease of mind) : grub_emu_CFLAGS =3D $(COMMON_CFLAGS)=20 grub_emu_LDFLAGS =3D $(COMMON_LDFLAGS) $(LIBCURSES) =20 =20 I provided a new kern/i386/pc/startup.S : #ifdef REGPARM #include "startup.S.regparm" #else #include "startup.S.memparm" #endif =20 startup.S.regparm is the =AB old =BB startup.S file. Startup.S.memparm is the new one passing parameters using stack for global functions called by C. That=92s a =93first trial=94 quickly = written that is not fully optimized but seems to be bug free. =20 Had also to do little changes in normal/i386/pc/setjmp.S (easy to read from the diff I attached to this email) and I guess that this is the only (similar) change that will have to be made in powerpc related files. =20 Include a complete dynamic loader for grub-emu :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::: =20 I didn=92t want to use the standard libld.so to load modules : =20 a) modules are =93relocated=94 ELF files, while dynamic loader on Linux deals with =93shared=94 .so ELF files. b) emulation means we better try to use same code than the one used in Grub 2. =20 So I just let included kern/dl.c to the grub-emu code. =20 Had to get ride of template functions in util/grub-emu.c such as=20 grub_arch_dl_check_header (void *ehdr) grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) And use the real ones (for i386-pc !!) from kern/i386/dl.c. =20 I am also using grub_register_exported_symbols from Grub 2=92s instead = of a null function. =20 Beware : I didn=92t know what to do about grub_arch_modules_addr (void) so I let it return 0 not knowing the consequences. I guess I=92ll have = to come back to that point later on. =20 Makefiles : I don=92t have Ruby running on my pc, so I provided conf/i386-pc.mk diff, but the main thing to be retained is, I just added two dependencies : kern/i386/dl.c and symlist2.c to be compiled with grub-emu. =20 =20 Have a Complete grub-emu (no undefined symbols when loading modules) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::: =20 Well, I guess I was very loosy on that part. The main purpose of my work was to get grub-emu load modules, whether or not it=92s useful somehow. =20 So I kind of =93skip=94 that part and =93gracefully=94 ;-) ended using a symlist2.c file that shows all the work that remains to do : =20 I added two =93null=94 items (function / var), in util/misc.c (but they = may better be in util/grub-emu.c) : int grub_null() { return 0; } =20 int grub_null_var =3D 0; =20 And I just =93connected=94 every undefined symbol in grub-emu to those = two items, using a =93special=94 symlist2.c file (yes I can do such messy = work) : =20 {"grub_vga_set_mode", grub_null}, {"grub_vga_get_font", grub_null}, {"grub_vbe_get_controller_info", grub_null}, {"grub_vbe_get_mode_info", grub_null}, {"grub_vbe_set_mode", grub_null}, {"grub_vbe_get_mode", grub_null}, {"grub_vbe_set_memory_window", grub_null}, {"grub_vbe_get_memory_window", grub_null}, {"grub_vbe_set_scanline_length", grub_null}, {"grub_vbe_get_scanline_length", grub_null}, {"grub_vbe_set_display_start", grub_null}, {"grub_vbe_get_display_start", grub_null}, {"grub_vbe_set_palette_data", grub_null}, =20 I guess that vbe module won=92t be of any use with that =93fixup=94. In fact vbetest command will crash grub-emu. =20 But watch this : =20 {"grub_lower_mem", &grub_null_var}, {"grub_upper_mem", &grub_null_var}, {"grub_os_area_addr", &grub_null_var}, {"grub_os_area_size", &grub_null_var}, {"grub_linux_prot_size", &grub_null_var}, {"grub_linux_tmp_addr", &grub_null_var}, {"grub_linux_real_addr", &grub_null_var}, =20 {"grub_linux_boot_zimage", grub_null}, {"grub_linux_boot_bzimage", grub_null}, {"grub_chainloader_real_boot", grub_null}, {"grub_multiboot_real_boot", grub_null}, =20 =20 Did you say grub-emu main purpose was to boot some kind of OS ? =20 LeftToDo : I guess the makefile for grub-emu has to be changed (a lot ?) and that emulation needs to be completed else have a look of what get me into this and tell me a better fixup.=20 Some functions are only (from I have seen in Grub 2 code) coded in kern/i386/pc/startup.S, and I can=92t include that file into grub-emu. So, either some of the useful functions have to be =93relocated=94 in = some other source file, either these functions needs to have a coding to be used in grub-emu (emulation mode) somewhere within util/. =20 Anyway, for now, modules are loading fine with this =93fixup=94. =20 Loading Modules :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::: =20 I thought I will have to change memory allocation to allow for module loading. Malloc is not what is expected to load code into memory and run it. mmap is the normal way to do that under Linux. =20 In fact, one of my modules loads a sub-module in a very special way (specific dynamic loader), so I needed to code a new function : Grub_mmap(int size) (that takes only one parameter for now) : =20 static char * heapstart=3D(char*) 0x01200000; void * grub_mmap (grub_size_t size) { void * heap; heap=3D(void *)mmap(heapstart, size, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); heapstart+=3Dsize;=20 printf("Using mmap (size %d)\n", size); return heap; } =20 But surprisingly enough, I didn=92t need to use it to load modules with kern/dl.c. =20 Beware : I am still wondering if I am not loading modules on top of the kernel code in grub-emu !?!, though it=92s been a week that I am using loading module with grub-emu and didn=92t crash yet. =20 Getting Crazy enough to fix some code in Grub 2, just in case. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::: =20 Well, at that point, every thing is setup to =93work=94. But it didn=92t at first trial. =20 Had numerous SIGVSEG failed and mess up in malloc/free grub=92s = routines. =20 I tried to debug, finding out where the bug would be located, and finally used a different compiler (went to gcc-4.0), but kept some changes in grub 2=92s code just in case (not knowing if these changes really matter for your compiler). =20 The mess came from two major points of the code (from what I=92ve found out) : =20 Call to (mod->init) (mod); to initiate modules after loading =20 Well, I guess that this is important, especially when you compile with =96mregparm=3D3 =96mrtd to specify if the function you are calling takes = a fixed number of parameters (to be passed by registers) or an undefined number of parameters (to be passed in the stack). If you don=92t specify that, you let the compiler choose his way of doing it =85 and that might well be the wrong way. The function you called should (has to) be prototyped exactly the same. =20 It=92s crucial for this line of code, because the function you call = relies on the fact the parameter mod is a pointer to a module structure. This structure doesn=92t contain a MAGIC number (I believe it should !) = to check on, before doing anything foolish such as =85 doing things on mod->dep. =20 =20 I fixed : static void grub_mod_init (grub_dl_t mod) __attribute__ ((used));=20 =20 (I suppressed __attribute__ =93unused=94 on parameter mod) =20 I gave a patch for this kind of call : =20 typedef void FINIT(void * ); typedef FINIT * PFINIT; ((PFINIT)mod->init) (mod); =20 (just in case, though the compiler should have correctly guessed it from struct grub_dl). =20 but anyway that sort of patch should be applied everywhere you make a *fct() call to something if *fct is not properly prototyped in include files. =20 =20 Call to setjmp(grub_exit_env) In some cases (I didn=92t try to reproduce since I=92ve moved to gcc = 4.0) the setjmp function received *grub_exit_env instead of grub_exit_env. So I=92ve coded this patch : if (grub_setjmp (&grub_exit_env[0]) =3D=3D 0) instead of=20 if (grub_setjmp (grub_exit_env) =3D=3D 0) though it is less portable. =20 Up to you to see if you keep these =93patches=94. I didn=92t tried to reproduce the errors without those patches since I went to gcc 4.0. =20 Some other changes=20 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::: =20 Added a grub_break() function : That=92s temporary to let me set easy breakpoints with gdb, from modules. =20 Added grub_dprintf("symbols", =85) lines to let me see the loading = process and have a table of which section is loaded at where. =20 I=92d like to talk about how to let gdb know about newly loaded modules, but I=92ll answer to Tomas 'Ebi' Ebenlendr=92s email separately.=20 =20 =20 =20 I don=92t like the diff format I sent, so don=92t hesitate to give me = the right command to send you a diff (=93patch=94) with the format you like best. =20 =20 Best regards, _________________________________________ Eric Salom=E9 - Paris, France =20 =20 > -----Message d'origine----- > De : grub-devel-bounces+esalome=3Dctx.net@gnu.org [mailto:grub-devel- > bounces+esalome=3Dctx.net@gnu.org] De la part de Marco Gerards > Envoy=E9 : vendredi 5 mai 2006 13:39 > =C0 : The development of GRUB 2 > Objet : Re: RE : grub-emu state of the art >=20 > Eric Salom=E9 writes: >=20 > > GRUB 2 Wiki > > ToDoList : Implement ModuleLoading in grub-emu >=20 > Right, and I even added this item. Sorry, I just misunderstood your > previous email. >=20 > > I worked on that : Architecture i386/pc - Emulation on Linux/Ubuntu > > grub-emu is loading all current modules, though some won't do anything > > in emulation mode. The modules .mod are the same as those used for boot > > time. >=20 > Nice! >=20 > > Little changes in source code, though I had to adapt asm files to > > passing parameters in stack (I compile without -mregparm=3D3 -mrtd options > > as I didn't want to recompile the whole C library with those passing > > parameters conventions). >=20 > It would be nice to get this to work for the regular modules too. In > that case we do not need two set of modules. Besides that, it should > also work on the PPC, for example. Which is a lot harder. >=20 > BTW, how did you implement this? I once wrote a hack to do exactly > the same by using mmap to allocate executable memory. On the PPC this > memory needs to be allocated close to the grub-emu binary because > otherwise the relocations would fail. >=20 > > ... when I be done with grub 2 debugging I'll just have to recompile > > with these options (if you like them a lot) and it will work just fine > > (boot time only). >=20 > It's not only that we like them. They make the size of the binaries > smaller. And it is a requirement for the assembler code. >=20 > > ToBeAwardedOf: > > Don't use gcc 3.3 with grub 2's current source files : compiled code is > > wrong and subject to unattended results. > > Runs fine with gcc 4.0. I have still a doubt about gcc 3.4. >=20 > Wrong in what way? We have some workaround for specific gcc bugs. > Although these are sometimes hard to locate, sometimes it might be > worth the effort. >=20 > > LeftToDo : > > > > - see if every modification is useful, as I tried a few things before I > > got a good result, and send a diff patch. >=20 > Please describe how things work in detail so we can discuss possible > issues. >=20 > > - I need a "patched" symlist.c to compile with grub-emu (could be > > generated by a script, but I am too lazy). >=20 > :-) >=20 > > - let gdb know about dynamically loaded modules ;-), but I guess it > > won't be the easy part. >=20 > Yeah, I can imagine that. But in case specific modules have to be > debugged, we can just compile them in as happens currently. This is > what I do now. >=20 > The big advantage of having module support in grub-emu is as a > debugging tool for module loading itself. It will make porting GRUB > to another architecture a lot easier. And besides that, debugging > will be a lot easier too. >=20 > Thanks, > Marco >=20 >=20 >=20 >=20 > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel ------=_NextPart_001_0002_01C6733D.65191620 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hi folks,

 

This email to explain how I worked on = grub-emu module loading, the choices I have made (for now) and the diff from grub-1.93 delivery. Marco asked me for details (well, that will make it a pretty = long email :-)).

 

I worked only on the i386-pc architecture but = I believe same steps will lead to a working grub-emu with module loading = on powerpc architecture (though I can't do that myself).

 

I’ve got results : My modules are = loading fine, but That may be by chance J

(I still have great doubts about memory = management).

So take a close look at what I’ve done = before agreeing/committing changes and yell if I’ve done anything foolish.

 

There is still work to do, as you’ll = see :

 

Have it compile

::::::::::::::::::::::::::::::::::::::::::::::= :::::::::::::::::::::::::::::

First, I had to deal with the main problem on = PC:

Current delivery of grub-1.93 requires kernel = and modules to be compiled with -mregparm=3D3 -mrtd options.

Parameters are passed to functions using = registers instead of using memory in stack. Assembler code presume that asm = functions are called that way too.

This is not the standard way libc functions = are used to.

 

Also, note that even with -mregparm=3D3 and = -mrtd options, parameters are passed using stack to functions with an = undefined number of parameters (such as grub_printf : Those functions in turn = expected their parameters in stack). If you don't provide good prototype to = functions in your modules that leads to unexpected results.

 

To have a grub-emu compile with these options = :

=A0a. Either you need to compile a new = "libc" library using same options

=A0b. Either you can provide grub-emu source = files with a "foolyou" prototype include file for all C functions called = in libc (there are currently not too many), saying for example = :

 

off_t lseek(int = fildes, off_t offset, int whence, ...);

 

The ending ... will ask the C compiler to = pass all parameters in stack (the way the libc wants it for all functions). =

And try to compile (I really didn't try that, = I was too afraid the compiler would voice me about mismatchs in prototype = between Linux standard include files and my "foolme" prototype = file.

I believe that things would be worst with = time, since other modules to come would like to use more library calls (in libc and = in other standard libs).

 

I'd rather made the following choices = :

---------------------------------------=

 

1. Provide new asm code that support for = passing parameters in stack, instead of from registers.

2. Change compile options so that the all = Grub 2 delivery would now be using passing parameters using stack (and thus I = get ride of libc incompatibility)

3. Keep support for "optimized" = code (using -mregparm=3D3 -mrtd) just in case someone feels like he can't live = without it ;-).

 

New Makefile = (i386-pc.mk) shows :

#COMMON_ASFLAGS =3D -nostdinc -fno-builtin = -DREGPARM

#COMMON_CFLAGS =3D -fno-builtin -mrtd = -mregparm=3D3 -m32

 

COMMON_ASFLAGS =3D -nostdinc = -fno-builtin

COMMON_CFLAGS =3D $(CFLAGS) = -m32

 

Using the first two lines does create = optimized and shorter code for kernel and modules (but you won’t be able to = launch grub-emu).

The difference is about 210316 bytes against = 212684 (for all the modules I have) : 1 % shorter.

 

Using the last two lines, the good news is = you can use same modules for grub 2 and for grub-emu, and it compiles = fine.

 

Don’t forget to add the following lines = also, to be sure grub-emu is compiled with the same options as the (COMMON) = modules (that’s only for ease of mind) :

grub_emu_CFLAGS =3D $(COMMON_CFLAGS)

grub_emu_LDFLAGS =3D $(COMMON_LDFLAGS) $(LIBCURSES)

 

 

I provided a new kern/i386/pc/startup.S :

#ifdef = REGPARM

#include "startup.S.regparm"

#else

#include "startup.S.memparm"

#endif

 

startup.S.regparm is the = =AB old =BB startup.S file.

Startup.S.memparm is the new one passing = parameters using stack for global functions called by C. That’s a = “first trial” quickly written that is not fully optimized but seems to be = bug free.

=A0

Had also to do little changes in normal/i386/pc/setjmp.S (easy to = read from the diff I attached to this email) and I guess that this is the only = (similar) change that will have to be made in powerpc related files.

 

Include a complete dynamic loader for = grub-emu

::::::::::::::::::::::::::::::::::::::::::::::= :::::::::::::::::::::::::::::

 

I didn’t want to use the standard = libld.so to load modules :

 

a) modules are “relocated” ELF = files, while dynamic loader on Linux deals with “shared” .so ELF = files.

b) emulation means we better try to use same = code than the one used in Grub 2.

 

So I just let included kern/dl.c to the grub-emu code.

 

Had to get ride of template functions in = util/grub-emu.c such as

grub_arch_dl_check_header (void *ehdr)

grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)

And use the real ones (for i386-pc !!) from = kern/i386/dl.c.

 

I am also using = grub_register_exported_symbols from Grub 2’s instead of a null function.

 

Beware : I didn’t know = what to do about grub_arch_modules_addr (void)

=A0so I let it return 0 not knowing = the consequences. I guess I’ll have to come back to that point later = on.

=A0

Makefiles : I don’t have Ruby running = on my pc, so I provided conf/i386-pc.mk diff, but the main thing to be retained = is, I just added two dependencies :

kern/i386/dl.c<= /b> and symlist2.c = to be compiled with grub-emu.

 

 

Have a Complete grub-emu (no undefined = symbols when loading modules)

::::::::::::::::::::::::::::::::::::::::::::::= :::::::::::::::::::::::::::::

 

Well, I guess I was very loosy on that = part.

The main purpose of my work was to get = grub-emu load modules, whether or not it’s useful somehow.

 

So I kind of “skip” that part and “gracefully” ;-) ended using a symlist2.c file that shows all the work that remains to do :

 

I added two “null” items = (function / var), in util/misc.c (but they may better be in util/grub-emu.c) = :

int = grub_null()

{

=A0=A0=A0 return 0;

}

 

int = grub_null_var =3D 0;

 

And I just “connected” every = undefined symbol in grub-emu to those two items, using a “special” = symlist2.c file (yes I can do such messy work) :

 

=A0=A0=A0=A0=A0 {"grub_vga_set_mode", grub_null},

=A0=A0=A0=A0=A0 {"grub_vga_get_font", grub_null},

=A0=A0=A0=A0=A0 {"grub_vbe_get_controller_info", grub_null},

=A0=A0=A0=A0=A0 {"grub_vbe_get_mode_info", grub_null},

=A0=A0=A0=A0=A0 {"grub_vbe_set_mode", grub_null},

=A0=A0=A0=A0=A0 {"grub_vbe_get_mode", grub_null},

=A0=A0=A0=A0=A0 {"grub_vbe_set_memory_window", grub_null},

=A0=A0=A0=A0=A0 {"grub_vbe_get_memory_window", grub_null},

=A0=A0=A0=A0=A0 {"grub_vbe_set_scanline_length", grub_null},

=A0=A0=A0=A0=A0 {"grub_vbe_get_scanline_length", grub_null},

=A0=A0=A0=A0=A0 {"grub_vbe_set_display_start", grub_null},

=A0=A0=A0=A0=A0 {"grub_vbe_get_display_start", grub_null},

=A0=A0=A0=A0 =A0{"grub_vbe_set_palette_data", grub_null},

 

I guess that vbe module won’t be of any = use with that “fixup”.

In fact vbetest command will crash = grub-emu.

 

But watch this :

 

=A0=A0=A0=A0=A0 {"grub_lower_mem", &grub_null_var},

=A0=A0=A0=A0=A0 {"grub_upper_mem", = &grub_null_var},

=A0=A0=A0=A0=A0 {"grub_os_area_addr", = &grub_null_var},

=A0 = =A0=A0=A0=A0{"grub_os_area_size", &grub_null_var},

=A0=A0=A0=A0=A0 {"grub_linux_prot_size", &grub_null_var},

=A0=A0=A0=A0=A0 {"grub_linux_tmp_addr", &grub_null_var},

=A0=A0=A0=A0=A0 {"grub_linux_real_addr", &grub_null_var},

 

=A0=A0=A0=A0=A0 {"grub_linux_boot_zimage", grub_null},

=A0=A0=A0=A0=A0 {"grub_linux_boot_bzimage", grub_null},

=A0=A0=A0=A0=A0 {"grub_chainloader_real_boot", grub_null},

=A0=A0=A0=A0=A0 {"grub_multiboot_real_boot", grub_null},

 

 

Did you say grub-emu main purpose was to boot = some kind of OS ?

 

LeftToDo : I guess the makefile for grub-emu has to be changed (a = lot ?) and that emulation needs to be completed else have a look of what get me = into this and tell me a better fixup.

Some functions are only (from I have seen in = Grub 2 code) coded in kern/i386/pc/startup.S, and I can’t include that = file into grub-emu.

So, either some of the useful functions have = to be “relocated” in some other source file, either these functions needs to have a coding = to be used in grub-emu (emulation mode) somewhere within = util/.

 

Anyway, for now, modules are loading fine = with this “fixup”.

 

Loading Modules

::::::::::::::::::::::::::::::::::::::::::::::= :::::::::::::::::::::::::::::

 

I thought I will have to change memory = allocation to allow for module loading.

Malloc is not what is expected to load code = into memory and run it.

mmap is the normal way to do that under = Linux.

 

In fact, one of my modules loads a sub-module = in a very special way (specific dynamic loader), so I needed to code a new = function :

Grub_mmap(int size) (that takes only one = parameter for now) :

 

static = char * heapstart=3D(char*) 0x01200000;

void = *

grub_mmap (grub_size_t size)

{

=A0=A0=A0 void * heap;

=A0=A0=A0 heap=3D(void *)mmap(heapstart, size,

=A0=A0=A0=A0=A0 =A0=A0=A0 =A0 PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);

=A0=A0=A0 heapstart+=3Dsize;

=A0=A0=A0 printf("Using mmap (size %d)\n", size);

=A0=A0=A0 return heap;

}

 

But surprisingly enough, I didn’t need = to use it to load modules with kern/dl.c.

 

Beware : I am still wondering if I am not loading modules on top = of the kernel code in grub-emu !?!, though it’s been a week that I am = using loading module with grub-emu and didn’t crash yet.

 

Getting Crazy enough to fix some code in Grub = 2, just in case.

::::::::::::::::::::::::::::::::::::::::::::::= :::::::::::::::::::::::::::::

 

Well, at that point, every thing is setup to = “work”.

But it didn’t at first = trial.

 

Had numerous SIGVSEG failed and mess up in = malloc/free grub’s routines.

 

I tried to debug, finding out where the bug = would be located, and finally used a different compiler (went to gcc-4.0), but = kept some changes in grub 2’s code just in case (not knowing if these = changes really matter for your compiler).

 

The mess came from two major points of the = code (from what I’ve found out) :

 

Call to (mod->init) = (mod); to initiate modules after loading

 

Well, I guess that this is important, = especially when you compile with –mregparm=3D3 –mrtd to specify if the = function you are calling takes a fixed number of parameters (to be passed by = registers) or an undefined number of parameters (to be passed in the stack). If you = don’t specify that, you let the compiler choose his way of doing it … = and that might well be the wrong way. The function you called should (has to) be = prototyped exactly the same.

 

It’s crucial for this line of code, = because the function you call relies on the fact the parameter mod is a pointer to a = module structure.

This structure doesn’t contain a MAGIC = number (I believe it should !) to check on, before doing anything foolish such as = … doing things on mod->dep.

=A0

 

I fixed :

static = void grub_mod_init (grub_dl_t mod) __attribute__ ((used));

 

(I suppressed __attribute__ = “unused” on parameter mod)

 

I gave a patch for this kind of call = :

 

typedef void FINIT(void * );

typedef FINIT * PFINIT;

=A0=A0=A0 ((PFINIT)mod->init) (mod);

 

(just in case, though the compiler should = have correctly guessed it from struct grub_dl).

=A0=A0

but anyway that sort of patch should be = applied everywhere you make a *fct() call to something if *fct is not properly prototyped in include files.

 

 

Call to = setjmp(grub_exit_env)

In some cases (I didn’t try to = reproduce since I’ve moved to gcc 4.0) the setjmp function received *grub_exit_env instead of = grub_exit_env. So I’ve coded this patch :

if = (grub_setjmp (&grub_exit_env[0]) =3D=3D 0)

instead of

if = (grub_setjmp (grub_exit_env) =3D=3D 0)

though it is less portable.

 

Up to you to see if you keep these = “patches”. I didn’t tried to reproduce the errors without those patches since = I went to gcc 4.0.

 

Some other changes

::::::::::::::::::::::::::::::::::::::::::::::= :::::::::::::::::::::::::::::::::::

 

Added a grub_break() function : That’s = temporary to let me set easy breakpoints with gdb, from modules.

 

Added grub_dprintf("symbols", = …) lines to let me see the loading process and have a table of which section is = loaded at where.

 

I’d like to talk about how to let gdb know about newly loaded modules, but = I’ll answer to Tomas 'Ebi' = Ebenlendr’s email separately.

 

 

 

I don’t like the diff format I sent, so = don’t hesitate to give me the right command to send you a diff = (“patch”) with the format you like best.

 

 

Best regards,

_______________________________________= __

Eric Salom=E9 - Paris, France

 

 

> -----Message d'origine-----

> De : grub-devel-bounces+esalome=3Dctx.net@gnu.org [mailto:grub-devel-

> bounces+esalome=3Dctx.net@gnu.org] De la part de Marco = Gerards

> Envoy=E9 : vendredi 5 mai 2006 13:39

> =C0 : The development of GRUB 2

> Objet : Re: RE : grub-emu state of = the art

>

> Eric Salom=E9 <esalome@ctx.net> writes:

>

> > GRUB 2 Wiki

> > ToDoList : Implement ModuleLoading = in grub-emu

>

> Right, and I even added this item.=A0 = Sorry, I just misunderstood your

> previous email.

>

> > I worked on that : Architecture = i386/pc - Emulation on Linux/Ubuntu

> > grub-emu is loading all current = modules, though some won't do anything

> > in emulation mode. The modules .mod = are the same as those used for boot

> > time.

>

> Nice!

>

> > Little changes in source code, = though I had to adapt asm files to

> > passing parameters in stack (I = compile without -mregparm=3D3 -mrtd options

> > as I didn't want to recompile the = whole C library with those passing

> > parameters = conventions).

>

> It would be nice to get this to work for = the regular modules too.=A0 In

> that case we do not need two set of = modules.=A0 Besides that, it should

> also work on the PPC, for example.=A0 = Which is a lot harder.

>

> BTW, how did you implement this?=A0 I = once wrote a hack to do exactly

> the same by using mmap to allocate = executable memory.=A0 On the PPC this

> memory needs to be allocated close to = the grub-emu binary because

> otherwise the relocations would = fail.

>

> > ... when I be done with grub 2 = debugging I'll just have to recompile

> > with these options (if you like = them a lot) and it will work just fine

> > (boot time only).

>

> It's not only that we like them.=A0 They = make the size of the binaries

> smaller.=A0 And it is a requirement for = the assembler code.

>

> > ToBeAwardedOf:

> > Don't use gcc 3.3 with grub 2's = current source files : compiled code is

> > wrong and subject to unattended = results.

> > Runs fine with gcc 4.0. I have = still a doubt about gcc 3.4.

>

> Wrong in what way?=A0 We have some = workaround for specific gcc bugs.

> Although these are sometimes hard to = locate, sometimes it might be

> worth the effort.

>

> > LeftToDo :

> >

> > - see if every modification is = useful, as I tried a few things before I

> > got a good result, and send a diff = patch.

>

> Please describe how things work in = detail so we can discuss possible

> issues.

>

> > - I need a "patched" = symlist.c to compile with grub-emu (could be

> > generated by a script, but I am too = lazy).

>

> :-)

>

> > - let gdb know about dynamically = loaded modules ;-), but I guess it

> > won't be the easy = part.

>

> Yeah, I can imagine that.=A0 But in case = specific modules have to be

> debugged, we can just compile them in as = happens currently.=A0 This is

> what I do now.

>

> The big advantage of having module = support in grub-emu is as a

> debugging tool for module loading = itself.=A0 It will make porting GRUB

> to another architecture a lot easier.=A0 = And besides that, debugging

> will be a lot easier = too.

>

> Thanks,

> Marco

>

>

>

>

> = _______________________________________________

> Grub-devel mailing = list

> Grub-devel@gnu.org

> = http://lists.gnu.org/mailman/listinfo/grub-devel

------=_NextPart_001_0002_01C6733D.65191620-- ------=_NextPart_000_0001_01C6733D.65178F80 Content-Type: text/plain; name="diffpatch.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="diffpatch.txt" diff -n -r ./conf/i386-pc.mk ../../src/grub-1.93/conf/i386-pc.mk=0A= a2 3=0A= #COMMON_ASFLAGS =3D -nostdinc -fno-builtin -DREGPARM=0A= #COMMON_CFLAGS =3D -fno-builtin -mrtd -mregparm=3D3 -m32=0A= =0A= d4 1=0A= a4 2=0A= COMMON_CFLAGS =3D $(CFLAGS) -m32=0A= =0A= a6 3=0A= grub_emu_CFLAGS =3D $(COMMON_CFLAGS) =0A= grub_emu_LDFLAGS =3D $(COMMON_LDFLAGS) $(LIBCURSES)=0A= =0A= d786 3=0A= a788 4=0A= util/i386/pc/misc.c grub_emu_init.c \=0A= symlist2.c kern/i386/dl.c=0A= CLEANFILES +=3D grub-emu grub_emu-commands_boot.o = grub_emu-commands_cat.o grub_emu-commands_cmp.o = grub_emu-commands_configfile.o grub_emu-commands_default.o = grub_emu-commands_help.o grub_emu-commands_terminal.o = grub_emu-commands_ls.o grub_emu-commands_test.o = grub_emu-commands_search.o grub_emu-commands_timeout.o = grub_emu-commands_i386_pc_halt.o grub_emu-commands_i386_pc_reboot.o = grub_emu-disk_loopback.o grub_emu-fs_affs.o grub_emu-fs_ext2.o = grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o = grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o = grub_emu-fs_sfs.o grub_emu-fs_ufs.o grub_emu-fs_xfs.o = grub_emu-fs_hfsplus.o grub_emu-io_gzio.o grub_emu-kern_device.o = grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o = grub_emu-kern_err.o grub_emu-normal_execute.o grub_emu-kern_file.o = grub_emu-kern_fs.o grub_emu-normal_lexer.o grub_emu-kern_loader.o = grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_parser.o = grub_emu-grub_script_tab.o grub_emu-kern_partition.o = grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o = grub_emu-normal_cmdline.o grub_emu-normal_command.o = grub_emu-normal_function.o grub_emu-normal_completion.o = grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o = grub_emu-normal_menu_entry.o grub_emu-normal_misc.o = grub_emu-normal_script.o grub_emu-partmap_amiga.o = grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o = grub_emu-partmap_acorn.o grub_emu-partmap_gpt.o grub_emu-util_console.o = grub_emu-util_grub_emu.o grub_emu-util_misc.o = grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o = grub_emu-util_i386_pc_misc.o grub_emu-grub_emu_init.o grub_emu-symlist.o = grub_emu-symlist2.o grub_emu-kern_i386_dl.o=0A= MOSTLYCLEANFILES +=3D grub_emu-commands_boot.d grub_emu-commands_cat.d = grub_emu-commands_cmp.d grub_emu-commands_configfile.d = grub_emu-commands_default.d grub_emu-commands_help.d = grub_emu-commands_terminal.d grub_emu-commands_ls.d = grub_emu-commands_test.d grub_emu-commands_search.d = grub_emu-commands_timeout.d grub_emu-commands_i386_pc_halt.d = grub_emu-commands_i386_pc_reboot.d grub_emu-disk_loopback.d = grub_emu-fs_affs.d grub_emu-fs_ext2.d grub_emu-fs_fat.d = grub_emu-fs_fshelp.d grub_emu-fs_hfs.d grub_emu-fs_iso9660.d = grub_emu-fs_jfs.d grub_emu-fs_minix.d grub_emu-fs_sfs.d = grub_emu-fs_ufs.d grub_emu-fs_xfs.d grub_emu-fs_hfsplus.d = grub_emu-io_gzio.d grub_emu-kern_device.d grub_emu-kern_disk.d = grub_emu-kern_dl.d grub_emu-kern_env.d grub_emu-kern_err.d = grub_emu-normal_execute.d grub_emu-kern_file.d grub_emu-kern_fs.d = grub_emu-normal_lexer.d grub_emu-kern_loader.d grub_emu-kern_main.d = grub_emu-kern_misc.d grub_emu-kern_parser.d grub_emu-grub_script_tab.d = grub_emu-kern_partition.d grub_emu-kern_rescue.d grub_emu-kern_term.d = grub_emu-normal_arg.d grub_emu-normal_cmdline.d = grub_emu-normal_command.d grub_emu-normal_function.d = grub_emu-normal_completion.d grub_emu-normal_context.d = grub_emu-normal_main.d grub_emu-normal_menu.d = grub_emu-normal_menu_entry.d grub_emu-normal_misc.d = grub_emu-normal_script.d grub_emu-partmap_amiga.d = grub_emu-partmap_apple.d grub_emu-partmap_pc.d grub_emu-partmap_sun.d = grub_emu-partmap_acorn.d grub_emu-partmap_gpt.d grub_emu-util_console.d = grub_emu-util_grub_emu.d grub_emu-util_misc.d = grub_emu-util_i386_pc_biosdisk.d grub_emu-util_i386_pc_getroot.d = grub_emu-util_i386_pc_misc.d grub_emu-grub_emu_init.d = grub_emu-symlist2.d grub_emu-kern_i386_dl.d=0A= d790 2=0A= a791 2=0A= grub-emu: grub_emu-symlist2.o grub_emu-commands_boot.o = grub_emu-commands_cat.o grub_emu-commands_cmp.o = grub_emu-commands_configfile.o grub_emu-commands_default.o = grub_emu-commands_help.o grub_emu-commands_terminal.o = grub_emu-commands_ls.o grub_emu-commands_test.o = grub_emu-commands_search.o grub_emu-commands_timeout.o = grub_emu-commands_i386_pc_halt.o grub_emu-commands_i386_pc_reboot.o = grub_emu-disk_loopback.o grub_emu-fs_affs.o grub_emu-fs_ext2.o = grub_emu-fs_fat.o grub_emu-fs_fshelp.o grub_emu-fs_hfs.o = grub_emu-fs_iso9660.o grub_emu-fs_jfs.o grub_emu-fs_minix.o = grub_emu-fs_sfs.o grub_emu-fs_ufs.o grub_emu-fs_xfs.o = grub_emu-fs_hfsplus.o grub_emu-io_gzio.o grub_emu-kern_device.o = grub_emu-kern_disk.o grub_emu-kern_dl.o grub_emu-kern_env.o = grub_emu-kern_err.o grub_emu-normal_execute.o grub_emu-kern_file.o = grub_emu-kern_fs.o grub_emu-normal_lexer.o grub_emu-kern_loader.o = grub_emu-kern_main.o grub_emu-kern_misc.o grub_emu-kern_parser.o = grub_emu-grub_script_tab.o grub_emu-kern_partition.o = grub_emu-kern_rescue.o grub_emu-kern_term.o grub_emu-normal_arg.o = grub_emu-normal_cmdline.o grub_emu-normal_command.o = grub_emu-normal_function.o grub_emu-normal_completion.o = grub_emu-normal_context.o grub_emu-normal_main.o grub_emu-normal_menu.o = grub_emu-normal_menu_entry.o grub_emu-normal_misc.o = grub_emu-normal_script.o grub_emu-partmap_amiga.o = grub_emu-partmap_apple.o grub_emu-partmap_pc.o grub_emu-partmap_sun.o = grub_emu-partmap_acorn.o grub_emu-partmap_gpt.o grub_emu-util_console.o = grub_emu-util_grub_emu.o grub_emu-util_misc.o = grub_emu-util_i386_pc_biosdisk.o grub_emu-util_i386_pc_getroot.o = grub_emu-util_i386_pc_misc.o grub_emu-grub_emu_init.o = grub_emu-kern_i386_dl.o=0A= $(BUILD_CC) -o $@ $^ $(BUILD_CFLAGS) $(BUILD_LDFLAGS) = $(grub_emu_LDFLAGS)=0A= a1024 8=0A= grub_emu-kern_i386_dl.o: kern/i386/dl.c=0A= $(BUILD_CC) -Ikern -I$(srcdir)/kern -I$(srcdir)/kern/i386 = $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=3D1 $(grub_emu_CFLAGS) -c = -o $@ $<=0A= =0A= grub_emu-kern_i386_dl.d: kern/i386/dl.c=0A= set -e; $(BUILD_CC) -Ikern -I$(srcdir)/kern -I$(srcdir)/kern/i386 = $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) -DGRUB_UTIL=3D1 $(grub_emu_CFLAGS) -M = $< | sed 's,dl\.o[ :]*,grub_emu-kern__i386_dl.o $@ : ,g' > $@; [ = -s $@ ] || rm -f $@=0A= =0A= -include grub_emu-kern_i386_dl.d=0A= =0A= a1336 7=0A= grub_emu-symlist2.o: symlist2.c=0A= $(CC) -I. -I$(srcdir)/. $(CPPFLAGS) $(CFLAGS) $(grub_emu_CFLAGS) -c -o = $@ $<=0A= =0A= grub_emu-symlist2.d: symlist2.c=0A= set -e; $(CC) -I. -I$(srcdir)/. $(CPPFLAGS) $(CFLAGS) = $(grub_emu_CFLAGS) -M $< | sed 's,symlist2\.o[ = :]*,grub_emu-symlist2.o $@ : ,g' > $@; [ -s $@ ] || rm -f $@=0A= =0A= -include grub_emu-symlist2.d=0A= d1338 1=0A= diff -n -r ./fs/ext2.c ../../src/grub-1.93/fs/ext2.c=0A= d174 1=0A= a174 1=0A= static grub_dl_t my_mod =3D (grub_dl_t) 0;=0A= diff -n -r ./include/grub/dl.h ../../src/grub-1.93/include/grub/dl.h=0A= d29 1=0A= a29 1=0A= static void grub_mod_init (grub_dl_t mod) __attribute__ ((used)); \=0A= d34 1=0A= a34 1=0A= grub_mod_init (grub_dl_t mod)=0A= diff -n -r ./include/grub/misc.h ../../src/grub-1.93/include/grub/misc.h=0A= a78 1=0A= void EXPORT_FUNC(grub_break) (const char * fct, int i);=0A= diff -n -r ./include/grub/mm.h ../../src/grub-1.93/include/grub/mm.h=0A= a31 1=0A= void *EXPORT_FUNC(grub_mmap) (grub_size_t size);=0A= diff -n -r ./include/grub/util/misc.h = ../../src/grub-1.93/include/grub/util/misc.h=0A= a47 1=0A= void grub_break (const char * fct, int index);=0A= diff -n -r ./kern/dl.c ../../src/grub-1.93/kern/dl.c=0A= d319 1=0A= a319 1=0A= grub_err_t=0A= a361 4=0A= else {=0A= grub_dprintf ("symbols",=0A= "%s: Resolved Symbol %s\n", mod->name, name);=0A= }=0A= d371 1=0A= a371 3=0A= if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) {=0A= grub_dprintf("symbols",=0A= "Err registering %s (%d)\n", name, grub_errno);=0A= a372 4=0A= } else {=0A= grub_dprintf("symbols",=0A= "%s: Registering %s\n", mod->name, name);=0A= }=0A= d379 1=0A= a379 3=0A= if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) {=0A= grub_dprintf("symbols",=0A= "Err registering %s (%d)\n", name, grub_errno);=0A= a380 4=0A= } else {=0A= grub_dprintf("symbols",=0A= "%s: Registering %s\n", mod->name, name);=0A= }=0A= a405 2=0A= typedef void FINIT(void * );=0A= typedef FINIT * PFINIT;=0A= d410 1=0A= a410 1=0A= ((PFINIT)mod->init) (mod);=0A= a514 3=0A= grub_dprintf("symbols", =0A= "%s: Section %d loaded at 0x%x (size %d)\n",=0A= mod->name, seg->section, seg->addr, seg->size);=0A= d535 1=0A= a535 1=0A= /* return 0; */=0A= diff -n -r ./kern/i386/pc/startup.S = ../../src/grub-1.93/kern/i386/pc/startup.S=0A= a19 5=0A= #ifdef REGPARM=0A= #include "startup.S.regparm"=0A= #else=0A= #include "startup.S.memparm"=0A= #endif=0A= d21 2150=0A= Only in ../../src/grub-1.93/kern/i386/pc: startup.S.memparm=0A= Only in ../../src/grub-1.93/kern/i386/pc: startup.S.regparm=0A= diff -n -r ./kern/misc.c ../../src/grub-1.93/kern/misc.c=0A= a877 5=0A= =0A= extern int grub_printf (const char * fmt, ...);=0A= void grub_break (const char * fct, int index) {=0A= grub_printf ("%s: Break at %d\n", fct, index);=0A= }=0A= diff -n -r ./kern/mm.c ../../src/grub-1.93/kern/mm.c=0A= a289 6=0A= void *=0A= grub_mmap (grub_size_t size)=0A= {=0A= return grub_memalign (0, size);=0A= }=0A= =0A= diff -n -r ./normal/i386/setjmp.S = ../../src/grub-1.93/normal/i386/setjmp.S=0A= a29 3=0A= #ifndef REGPARM=0A= movl 4(%esp), %eax /* Get Param */=0A= #endif=0A= a44 4=0A= #ifndef REGPARM=0A= movl 4(%esp), %eax /* Get Param */=0A= movl 8(%esp), %edx /* Get Param */=0A= #endif=0A= diff -n -r ./normal/main.c ../../src/grub-1.93/normal/main.c=0A= d236 1=0A= a236 1=0A= if (grub_setjmp (&grub_exit_env[0]) =3D=3D 0)=0A= Only in ../../src/grub-1.93/: symlist2.c=0A= diff -n -r ./util/grub-emu.c ../../src/grub-1.93/util/grub-emu.c=0A= d59 18=0A= a76 1=0A= return 000;=0A= diff -n -r ./util/misc.c ../../src/grub-1.93/util/misc.c=0A= a214 14=0A= #include =0A= =0A= static char * heapstart=3D(char*) 0x01200000;=0A= void *=0A= grub_mmap (grub_size_t size)=0A= {=0A= void * heap;=0A= heap=3D(void *)mmap(heapstart, size,=0A= PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);=0A= heapstart+=3Dsize; =0A= printf("Using mmap (size %d)\n", size);=0A= return heap;=0A= }=0A= =0A= d218 1=0A= a218 1=0A= if (ptr) free (ptr);=0A= d247 5=0A= a273 7=0A= =0A= int grub_null()=0A= {=0A= return 0;=0A= }=0A= =0A= int grub_null_var =3D 0;=0A= ------=_NextPart_000_0001_01C6733D.65178F80 Content-Type: application/octet-stream; name="startup.S.regparm" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="startup.S.regparm" /*=0A= * GRUB -- GRand Unified Bootloader=0A= * Copyright (C) 1999,2000,2001,2002,2003,2005 Free Software = Foundation, Inc.=0A= *=0A= * This program is free software; you can redistribute it and/or modify=0A= * it under the terms of the GNU General Public License as published by=0A= * the Free Software Foundation; either version 2 of the License, or=0A= * (at your option) any later version.=0A= *=0A= * This program is distributed in the hope that it will be useful,=0A= * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= * GNU General Public License for more details.=0A= *=0A= * You should have received a copy of the GNU General Public License=0A= * along with this program; if not, write to the Free Software=0A= * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=0A= */=0A= =0A= =0A= /*=0A= * Note: These functions defined in this file may be called from C.=0A= * Be careful of that you must not modify some registers. Quote=0A= * from gcc-2.95.2/gcc/config/i386/i386.h:=0A= =0A= 1 for registers not available across function calls.=0A= These must include the FIXED_REGISTERS and also any=0A= registers that can be used without being saved.=0A= The latter must include the registers where values are returned=0A= and the register where structure-value addresses are passed.=0A= Aside from that, you can include as many other registers as you like.=0A= =0A= ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg=0A= { 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }=0A= */=0A= =0A= /*=0A= * Note: GRUB is compiled with the options -mrtd and -mregparm=3D3.=0A= * So the first three arguments are passed in %eax, %edx, and %ecx,=0A= * respectively, and if a function has a fixed number of arguments=0A= * and the number if greater than three, the function must return=0A= * with "ret $N" where N is ((the number of arguments) - 3) * 4.=0A= */=0A= =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= =0A= #define ABS(x) ((x) - EXT_C(start) + GRUB_BOOT_MACHINE_KERNEL_ADDR + = 0x200)=0A= =0A= .file "startup.S"=0A= =0A= .text=0A= =0A= /* Tell GAS to generate 16-bit instructions so that this code works=0A= in real mode. */=0A= .code16=0A= =0A= .globl start, _start=0A= start:=0A= _start:=0A= /*=0A= * Guarantee that "main" is loaded at 0x0:0x8200.=0A= */=0A= ljmp $0, $ABS(codestart)=0A= =0A= /*=0A= * Compatibility version number=0A= *=0A= * These MUST be at byte offset 6 and 7 of the executable=0A= * DO NOT MOVE !!!=0A= */=0A= . =3D EXT_C(start) + 0x6=0A= .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR=0A= =0A= /*=0A= * This is a special data area 8 bytes from the beginning.=0A= */=0A= =0A= . =3D EXT_C(start) + 0x8=0A= =0A= VARIABLE(grub_total_module_size)=0A= .long 0=0A= VARIABLE(grub_kernel_image_size)=0A= .long 0=0A= VARIABLE(grub_compressed_size)=0A= .long 0=0A= VARIABLE(grub_install_dos_part)=0A= .long 0xFFFFFFFF=0A= VARIABLE(grub_install_bsd_part)=0A= .long 0xFFFFFFFF=0A= VARIABLE(grub_prefix)=0A= .string "/boot/grub"=0A= =0A= /*=0A= * Leave some breathing room for the prefix.=0A= */=0A= =0A= . =3D EXT_C(start) + 0x50=0A= =0A= /*=0A= * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB = itself).=0A= * This uses the a.out kludge to load raw binary to the area starting at = 1MB,=0A= * and relocates itself after loaded.=0A= */=0A= multiboot_header:=0A= /* magic */=0A= .long 0x1BADB002=0A= /* flags */=0A= .long (1 << 16)=0A= /* checksum */=0A= .long -0x1BADB002 - (1 << 16)=0A= /* header addr */=0A= .long multiboot_header - _start + 0x100000 + 0x200=0A= /* load addr */=0A= .long 0x100000=0A= /* load end addr */=0A= .long 0=0A= /* bss end addr */=0A= .long 0=0A= /* entry addr */=0A= .long multiboot_entry - _start + 0x100000 + 0x200=0A= =0A= multiboot_entry:=0A= .code32=0A= /* obtain the boot device */=0A= movl 12(%ebx), %edx=0A= =0A= /* relocate the code */=0A= movl $(GRUB_KERNEL_MACHINE_RAW_SIZE + 0x200), %ecx=0A= addl EXT_C(grub_compressed_size) - _start + 0x100000 + 0x200, %ecx=0A= movl $0x100000, %esi=0A= movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %edi=0A= cld=0A= rep=0A= movsb=0A= /* jump to the real address */=0A= movl $multiboot_trampoline, %eax=0A= jmp *%eax=0A= =0A= multiboot_trampoline:=0A= /* fill the boot information */=0A= movl %edx, %eax=0A= shrl $8, %eax=0A= xorl %ebx, %ebx=0A= cmpb $0xFF, %ah=0A= je 1f=0A= movb %ah, %bl=0A= movl %ebx, EXT_C(grub_install_dos_part)=0A= 1:=0A= cmpb $0xFF, %al=0A= je 2f=0A= movb %al, %bl=0A= movl %ebx, EXT_C(grub_install_bsd_part)=0A= 2:=0A= shrl $24, %edx=0A= /* enter the usual booting */=0A= call prot_to_real=0A= .code16=0A= =0A= /* the real mode code continues... */=0A= codestart:=0A= cli /* we're not safe here! */=0A= =0A= /* set up %ds, %ss, and %es */=0A= xorw %ax, %ax=0A= movw %ax, %ds=0A= movw %ax, %ss=0A= movw %ax, %es=0A= =0A= /* set up the real mode/BIOS stack */=0A= movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp=0A= movl %ebp, %esp=0A= =0A= sti /* we're safe again */=0A= =0A= /* save boot drive reference */=0A= ADDR32 movb %dl, EXT_C(grub_boot_drive)=0A= =0A= /* reset disk system (%ah =3D 0) */=0A= int $0x13=0A= =0A= /* transition to protected mode */=0A= DATA32 call real_to_prot=0A= =0A= /* The ".code32" directive takes GAS out of 16-bit mode. */=0A= .code32=0A= =0A= incl %eax=0A= call EXT_C(grub_gate_a20)=0A= =0A= /* decompress the compressed part and put the result at 1MB */=0A= movl $0x100000, %esi=0A= movl $(START_SYMBOL + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi=0A= =0A= pushl %esi=0A= pushl EXT_C(grub_compressed_size)=0A= pushl %edi=0A= call lzo1x_decompress=0A= addl $12, %esp=0A= =0A= /* copy back the decompressed part */=0A= movl %eax, %ecx=0A= cld=0A= rep=0A= movsb=0A= =0A= /* copy modules before cleaning out the bss */=0A= movl EXT_C(grub_total_module_size), %ecx=0A= movl EXT_C(grub_kernel_image_size), %esi=0A= addl %ecx, %esi=0A= addl $START_SYMBOL, %esi=0A= decl %esi=0A= movl $END_SYMBOL, %edi=0A= addl %ecx, %edi=0A= decl %edi=0A= std=0A= rep=0A= movsb=0A= =0A= /* clean out the bss */=0A= movl $BSS_START_SYMBOL, %edi=0A= =0A= /* compute the bss length */=0A= movl $END_SYMBOL, %ecx=0A= subl %edi, %ecx=0A= =0A= /* clean out */=0A= xorl %eax, %eax=0A= cld=0A= rep=0A= stosb=0A= =0A= /*=0A= * Call the start of main body of C code.=0A= */=0A= call EXT_C(grub_main)=0A= =0A= =0A= /*=0A= * This is the area for all of the special variables.=0A= */=0A= =0A= .p2align 2 /* force 4-byte alignment */=0A= =0A= protstack:=0A= .long GRUB_MEMORY_MACHINE_PROT_STACK=0A= =0A= VARIABLE(grub_boot_drive)=0A= .long 0=0A= =0A= VARIABLE(grub_start_addr)=0A= .long START_SYMBOL=0A= =0A= VARIABLE(grub_end_addr)=0A= .long END_SYMBOL=0A= =0A= VARIABLE(grub_apm_bios_info)=0A= .word 0 /* version */=0A= .word 0 /* cseg */=0A= .long 0 /* offset */=0A= .word 0 /* cseg_16 */=0A= .word 0 /* dseg_16 */=0A= .word 0 /* cseg_len */=0A= .word 0 /* cseg_16_len */=0A= .word 0 /* dseg_16_len */=0A= =0A= /*=0A= * This is the Global Descriptor Table=0A= *=0A= * An entry, a "Segment Descriptor", looks like this:=0A= *=0A= * 31 24 19 16 7 0=0A= * ------------------------------------------------------------=0A= * | | |B| |A| | | |1|0|E|W|A| |=0A= * | BASE 31..24 |G|/|L|V| LIMIT |P|DPL| TYPE | BASE 23:16 | 4=0A= * | | |D| |L| 19..16| | |1|1|C|R|A| |=0A= * ------------------------------------------------------------=0A= * | | |=0A= * | BASE 15..0 | LIMIT 15..0 | 0=0A= * | | |=0A= * ------------------------------------------------------------=0A= *=0A= * Note the ordering of the data items is reversed from the above=0A= * description.=0A= */=0A= =0A= .p2align 2 /* force 4-byte alignment */=0A= gdt:=0A= .word 0, 0=0A= .byte 0, 0, 0, 0=0A= =0A= /* -- code segment --=0A= * base =3D 0x00000000, limit =3D 0xFFFFF (4 KiB Granularity), present=0A= * type =3D 32bit code execute/read, DPL =3D 0=0A= */=0A= .word 0xFFFF, 0=0A= .byte 0, 0x9A, 0xCF, 0=0A= =0A= /* -- data segment --=0A= * base =3D 0x00000000, limit 0xFFFFF (4 KiB Granularity), present=0A= * type =3D 32 bit data read/write, DPL =3D 0 =0A= */=0A= .word 0xFFFF, 0=0A= .byte 0, 0x92, 0xCF, 0=0A= =0A= /* -- 16 bit real mode CS --=0A= * base =3D 0x00000000, limit 0x0FFFF (1 B Granularity), present=0A= * type =3D 16 bit code execute/read only/conforming, DPL =3D 0=0A= */=0A= .word 0xFFFF, 0=0A= .byte 0, 0x9E, 0, 0=0A= =0A= /* -- 16 bit real mode DS --=0A= * base =3D 0x00000000, limit 0x0FFFF (1 B Granularity), present=0A= * type =3D 16 bit data read/write, DPL =3D 0=0A= */=0A= .word 0xFFFF, 0=0A= .byte 0, 0x92, 0, 0=0A= =0A= =0A= /* this is the GDT descriptor */=0A= gdtdesc:=0A= .word 0x27 /* limit */=0A= .long gdt /* addr */=0A= =0A= =0A= /*=0A= * These next two routines, "real_to_prot" and "prot_to_real" are = structured=0A= * in a very specific way. Be very careful when changing them.=0A= *=0A= * NOTE: Use of either one messes up %eax and %ebp.=0A= */=0A= =0A= real_to_prot:=0A= .code16=0A= cli=0A= =0A= /* load the GDT register */=0A= DATA32 ADDR32 lgdt gdtdesc=0A= =0A= /* turn on protected mode */=0A= movl %cr0, %eax=0A= orl $GRUB_MEMORY_MACHINE_CR0_PE_ON, %eax=0A= movl %eax, %cr0=0A= =0A= /* jump to relocation, flush prefetch queue, and reload %cs */=0A= DATA32 ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg=0A= =0A= .code32=0A= protcseg:=0A= /* reload other segment registers */=0A= movw $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %ax=0A= movw %ax, %ds=0A= movw %ax, %es=0A= movw %ax, %fs=0A= movw %ax, %gs=0A= movw %ax, %ss=0A= =0A= /* put the return address in a known safe location */=0A= movl (%esp), %eax=0A= movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK=0A= =0A= /* get protected mode stack */=0A= movl protstack, %eax=0A= movl %eax, %esp=0A= movl %eax, %ebp=0A= =0A= /* get return address onto the right stack */=0A= movl GRUB_MEMORY_MACHINE_REAL_STACK, %eax=0A= movl %eax, (%esp)=0A= =0A= /* zero %eax */=0A= xorl %eax, %eax=0A= =0A= /* return on the old (or initialized) stack! */=0A= ret=0A= =0A= =0A= prot_to_real:=0A= /* just in case, set GDT */=0A= lgdt gdtdesc=0A= =0A= /* save the protected mode stack */=0A= movl %esp, %eax=0A= movl %eax, protstack=0A= =0A= /* get the return address */=0A= movl (%esp), %eax=0A= movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK=0A= =0A= /* set up new stack */=0A= movl $GRUB_MEMORY_MACHINE_REAL_STACK, %eax=0A= movl %eax, %esp=0A= movl %eax, %ebp=0A= =0A= /* set up segment limits */=0A= movw $GRUB_MEMORY_MACHINE_PSEUDO_REAL_DSEG, %ax=0A= movw %ax, %ds=0A= movw %ax, %es=0A= movw %ax, %fs=0A= movw %ax, %gs=0A= movw %ax, %ss=0A= =0A= /* this might be an extra step */=0A= /* jump to a 16 bit segment */=0A= ljmp $GRUB_MEMORY_MACHINE_PSEUDO_REAL_CSEG, $tmpcseg=0A= =0A= tmpcseg:=0A= .code16=0A= =0A= /* clear the PE bit of CR0 */=0A= movl %cr0, %eax=0A= andl $(~GRUB_MEMORY_MACHINE_CR0_PE_ON), %eax=0A= movl %eax, %cr0=0A= =0A= /* flush prefetch queue, reload %cs */=0A= DATA32 ljmp $0, $realcseg=0A= =0A= realcseg:=0A= /* we are in real mode now=0A= * set up the real mode segment registers : DS, SS, ES=0A= */=0A= /* zero %eax */=0A= xorl %eax, %eax=0A= =0A= movw %ax, %ds=0A= movw %ax, %es=0A= movw %ax, %fs=0A= movw %ax, %gs=0A= movw %ax, %ss=0A= =0A= /* restore interrupts */=0A= sti=0A= =0A= /* return on new stack! */=0A= DATA32 ret=0A= =0A= .code32=0A= =0A= =0A= /*=0A= * grub_gate_a20(int on)=0A= *=0A= * Gate address-line 20 for high memory.=0A= *=0A= * This routine is probably overconservative in what it does, but so = what?=0A= *=0A= * It also eats any keystrokes in the keyboard buffer. :-(=0A= */=0A= =0A= FUNCTION(grub_gate_a20)=0A= movl %eax, %edx=0A= =0A= gate_a20_test_current_state: =0A= /* first of all, test if already in a good state */=0A= call gate_a20_check_state=0A= cmpb %al, %dl=0A= jnz gate_a20_try_bios=0A= ret=0A= =0A= gate_a20_try_bios:=0A= /* second, try a BIOS call */=0A= pushl %ebp=0A= call prot_to_real=0A= =0A= .code16=0A= movw $0x2400, %ax=0A= testb %dl, %dl=0A= jz 1f=0A= incw %ax=0A= 1: int $0x15=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %ebp=0A= call gate_a20_check_state=0A= cmpb %al, %dl=0A= jnz gate_a20_try_keyboard_controller=0A= ret=0A= =0A= gate_a20_flush_keyboard_buffer:=0A= inb $0x64=0A= andb $0x02, %al=0A= jnz gate_a20_flush_keyboard_buffer=0A= 2: =0A= inb $0x64=0A= andb $0x01, %al=0A= jz 3f=0A= inb $0x60=0A= jmp 2b=0A= 3:=0A= ret=0A= =0A= gate_a20_try_keyboard_controller: =0A= /* third, try the keyboard controller */=0A= call gate_a20_flush_keyboard_buffer=0A= =0A= movb $0xd1, %al=0A= outb $0x64=0A= 4: =0A= inb $0x64=0A= andb $0x02, %al=0A= jnz 4b=0A= =0A= movb $0xdd, %al=0A= testb %dl, %dl=0A= jz 5f=0A= orb $0x02, %al=0A= 5: outb $0x60=0A= call gate_a20_flush_keyboard_buffer=0A= =0A= /* output a dummy command (USB keyboard hack) */=0A= movb $0xff, %al=0A= outb $0x64=0A= call gate_a20_flush_keyboard_buffer=0A= =0A= call gate_a20_check_state=0A= cmpb %al, %dl=0A= jnz gate_a20_try_system_control_port_a=0A= ret=0A= =0A= gate_a20_try_system_control_port_a:=0A= /* fourth, try the system control port A */=0A= inb $0x92=0A= andb $(~0x03), %al=0A= testb %dl, %dl=0A= jz 6f=0A= orb $0x02, %al=0A= 6: outb $0x92=0A= =0A= /* When turning off Gate A20, do not check the state strictly,=0A= because a failure is not fatal usually, and Gate A20 is always=0A= on some modern machines. */=0A= testb %dl, %dl=0A= jz 7f =0A= call gate_a20_check_state=0A= cmpb %al, %dl=0A= /* everything failed, so restart from the beginning */=0A= jnz gate_a20_try_bios=0A= 7: ret=0A= =0A= gate_a20_check_state:=0A= /* iterate the checking for a while */=0A= movl $100, %ecx=0A= 1: =0A= call 3f=0A= cmpb %al, %dl=0A= jz 2f=0A= loop 1b=0A= 2:=0A= ret=0A= 3: =0A= pushl %ebx=0A= pushl %ecx=0A= xorl %eax, %eax=0A= /* compare the byte at 0x8000 with that at 0x108000 */=0A= movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %ebx=0A= pushl %ebx=0A= /* save the original byte in CL */=0A= movb (%ebx), %cl=0A= /* store the value at 0x108000 in AL */=0A= addl $0x100000, %ebx=0A= movb (%ebx), %al=0A= /* try to set one less value at 0x8000 */=0A= popl %ebx=0A= movb %al, %ch=0A= decb %ch=0A= movb %ch, (%ebx)=0A= /* serialize */=0A= outb %al, $0x80=0A= outb %al, $0x80=0A= /* obtain the value at 0x108000 in CH */=0A= pushl %ebx=0A= addl $0x100000, %ebx=0A= movb (%ebx), %ch=0A= /* this result is 1 if A20 is on or 0 if it is off */=0A= subb %ch, %al=0A= xorb $1, %al=0A= /* restore the original */=0A= popl %ebx=0A= movb %cl, (%ebx)=0A= popl %ecx=0A= popl %ebx=0A= ret=0A= =0A= #include "lzo1x.S"=0A= =0A= =0A= /*=0A= * This call is special... it never returns... in fact it should = simply=0A= * hang at this point!=0A= */=0A= =0A= FUNCTION(grub_stop)=0A= call prot_to_real=0A= =0A= /*=0A= * This next part is sort of evil. It takes advantage of the=0A= * byte ordering on the x86 to work in either 16-bit or 32-bit=0A= * mode, so think about it before changing it.=0A= */=0A= =0A= FUNCTION(grub_hard_stop)=0A= hlt=0A= jmp EXT_C(grub_hard_stop)=0A= =0A= =0A= /*=0A= * grub_stop_floppy()=0A= *=0A= * Stop the floppy drive from spinning, so that other software is=0A= * jumped to with a known state.=0A= */=0A= FUNCTION(grub_stop_floppy)=0A= movw $0x3F2, %dx=0A= xorb %al, %al=0A= outb %al, %dx=0A= ret=0A= =0A= /*=0A= * grub_reboot()=0A= *=0A= * Reboot the system. At the moment, rely on BIOS.=0A= */=0A= FUNCTION(grub_reboot)=0A= call prot_to_real=0A= .code16=0A= /* cold boot */=0A= movw $0x0472, %di=0A= movw %ax, (%di)=0A= ljmp $0xFFFF, $0x0000=0A= .code32=0A= =0A= /*=0A= * grub_halt(int no_apm)=0A= *=0A= * Halt the system, using APM if possible. If NO_APM is true, don't use=0A= * APM even if it is available.=0A= */=0A= FUNCTION(grub_halt)=0A= /* see if zero */=0A= testl %eax, %eax=0A= jnz EXT_C(grub_stop)=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= /* detect APM */=0A= movw $0x5300, %ax=0A= xorw %bx, %bx=0A= int $0x15=0A= jc EXT_C(grub_hard_stop)=0A= /* don't check %bx for buggy BIOSes... */=0A= =0A= /* disconnect APM first */=0A= movw $0x5304, %ax=0A= xorw %bx, %bx=0A= int $0x15=0A= =0A= /* connect APM */=0A= movw $0x5301, %ax=0A= xorw %bx, %bx=0A= int $0x15=0A= jc EXT_C(grub_hard_stop)=0A= =0A= /* set APM protocol level - 1.1 or bust. (this covers APM 1.2 also) */=0A= movw $0x530E, %ax=0A= xorw %bx, %bx=0A= movw $0x0101, %cx=0A= int $0x15=0A= jc EXT_C(grub_hard_stop)=0A= =0A= /* set the power state to off */=0A= movw $0x5307, %ax=0A= movw $1, %bx=0A= movw $3, %cx=0A= int $0x15=0A= =0A= /* shouldn't reach here */=0A= jmp EXT_C(grub_hard_stop)=0A= .code32=0A= =0A= =0A= /*=0A= * void grub_chainloader_real_boot (int drive, void *part_addr)=0A= *=0A= * This starts another boot loader.=0A= */=0A= =0A= FUNCTION(grub_chainloader_real_boot)=0A= pushl %edx=0A= pushl %eax=0A= =0A= call EXT_C(grub_dl_unload_all)=0A= =0A= /* set up to pass boot drive */=0A= popl %edx=0A= =0A= /* ESI must point to a partition table entry */=0A= popl %esi=0A= =0A= /* Turn off Gate A20 */=0A= xorl %eax, %eax=0A= call EXT_C(grub_gate_a20)=0A= =0A= call prot_to_real=0A= .code16=0A= ljmp $0, $GRUB_MEMORY_MACHINE_BOOT_LOADER_ADDR=0A= .code32=0A= =0A= =0A= /*=0A= * void grub_linux_boot_zimage (void)=0A= */=0A= VARIABLE(grub_linux_prot_size)=0A= .long 0=0A= VARIABLE(grub_linux_tmp_addr)=0A= .long 0=0A= VARIABLE(grub_linux_real_addr)=0A= .long 0=0A= =0A= FUNCTION(grub_linux_boot_zimage)=0A= /* copy the kernel */=0A= movl EXT_C(grub_linux_prot_size), %ecx=0A= addl $3, %ecx=0A= shrl $2, %ecx=0A= movl $GRUB_LINUX_BZIMAGE_ADDR, %esi=0A= movl $GRUB_LINUX_ZIMAGE_ADDR, %edi=0A= cld=0A= rep=0A= movsl=0A= =0A= FUNCTION(grub_linux_boot_bzimage)=0A= call EXT_C(grub_dl_unload_all)=0A= =0A= movl EXT_C(grub_linux_real_addr), %ebx=0A= =0A= /* copy the real mode code */=0A= movl EXT_C(grub_linux_tmp_addr), %esi=0A= movl %ebx, %edi=0A= movl $GRUB_LINUX_SETUP_MOVE_SIZE, %ecx=0A= cld=0A= rep=0A= movsb=0A= =0A= /* change %ebx to the segment address */=0A= shrl $4, %ebx=0A= movl %ebx, %eax=0A= addl $0x20, %eax=0A= movw %ax, linux_setup_seg=0A= =0A= /* XXX new stack pointer in safe area for calling functions */=0A= movl $0x4000, %esp=0A= call EXT_C(grub_stop_floppy)=0A= =0A= /* final setup for linux boot */=0A= call prot_to_real=0A= .code16=0A= =0A= cli=0A= movw %bx, %ss=0A= movw $GRUB_LINUX_SETUP_STACK, %sp=0A= =0A= movw %bx, %ds=0A= movw %bx, %es=0A= movw %bx, %fs=0A= movw %bx, %gs=0A= =0A= /* ljmp */=0A= .byte 0xea=0A= .word 0=0A= linux_setup_seg:=0A= .word 0=0A= .code32=0A= =0A= =0A= /*=0A= * This starts the multiboot kernel.=0A= */=0A= =0A= FUNCTION(grub_multiboot_real_boot)=0A= /* Push the entry address on the stack. */=0A= pushl %eax=0A= /* Move the address of the multiboot information structure to ebx. */=0A= movl %edx,%ebx=0A= =0A= /* Unload all modules and stop the floppy driver. */=0A= call EXT_C(grub_dl_unload_all)=0A= call EXT_C(grub_stop_floppy)=0A= =0A= /* Interrupts should be disabled. */=0A= cli=0A= =0A= /* Move the magic value into eax and jump to the kernel. */=0A= movl $GRUB_MB_MAGIC2,%eax=0A= popl %ecx=0A= jmp *%ecx=0A= =0A= =0A= /*=0A= * int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap)=0A= *=0A= * Call IBM/MS INT13 Extensions (int 13 %ah=3DAH) for DRIVE. DAP=0A= * is passed for disk address packet. If an error occurs, return=0A= * non-zero, otherwise zero.=0A= */=0A= =0A= FUNCTION(grub_biosdisk_rw_int13_extensions)=0A= pushl %ebp=0A= pushl %esi=0A= =0A= /* compute the address of disk_address_packet */=0A= movw %cx, %si=0A= xorw %cx, %cx=0A= shrl $4, %ecx /* save the segment to cx */=0A= =0A= /* ah */=0A= movb %al, %dh=0A= /* enter real mode */=0A= call prot_to_real=0A= =0A= .code16=0A= movb %dh, %ah=0A= movw %cx, %ds=0A= int $0x13 /* do the operation */=0A= movb %ah, %dl /* save return value */=0A= /* clear the data segment */=0A= xorw %ax, %ax=0A= movw %ax, %ds=0A= /* back to protected mode */=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %dl, %al /* return value in %eax */=0A= =0A= popl %esi=0A= popl %ebp=0A= =0A= ret=0A= =0A= /*=0A= * int grub_biosdisk_rw_standard (int ah, int drive, int coff, int = hoff,=0A= * int soff, int nsec, int segment)=0A= *=0A= * Call standard and old INT13 (int 13 %ah=3DAH) for DRIVE. Read/write=0A= * NSEC sectors from COFF/HOFF/SOFF into SEGMENT. If an error occurs,=0A= * return non-zero, otherwise zero.=0A= */=0A= =0A= FUNCTION(grub_biosdisk_rw_standard)=0A= pushl %ebp=0A= movl %esp, %ebp=0A= =0A= pushl %ebx=0A= pushl %edi=0A= pushl %esi=0A= =0A= /* set up CHS information */=0A= =0A= /* set %ch to low eight bits of cylinder */=0A= xchgb %cl, %ch=0A= /* set bits 6-7 of %cl to high two bits of cylinder */=0A= shlb $6, %cl=0A= /* set bits 0-5 of %cl to sector */=0A= addb 0xc(%ebp), %cl=0A= /* set %dh to head */=0A= movb 0x8(%ebp), %dh=0A= /* set %ah to AH */=0A= movb %al, %ah=0A= /* set %al to NSEC */=0A= movb 0x10(%ebp), %al=0A= /* save %ax in %di */=0A= movw %ax, %di=0A= /* save SEGMENT in %bx */=0A= movw 0x14(%ebp), %bx=0A= =0A= /* enter real mode */=0A= call prot_to_real=0A= =0A= .code16=0A= movw %bx, %es=0A= xorw %bx, %bx=0A= movw $3, %si /* attempt at least three times */=0A= =0A= 1: =0A= movw %di, %ax=0A= int $0x13 /* do the operation */=0A= jnc 2f /* check if successful */=0A= =0A= movb %ah, %bl /* save return value */=0A= /* if fail, reset the disk system */=0A= xorw %ax, %ax=0A= int $0x13=0A= =0A= decw %si=0A= cmpw $0, %si=0A= je 2f=0A= xorb %bl, %bl=0A= jmp 1b /* retry */=0A= 2: =0A= /* back to protected mode */=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %bl, %al /* return value in %eax */=0A= =0A= popl %esi=0A= popl %edi=0A= popl %ebx=0A= popl %ebp=0A= =0A= ret $(4 * 4)=0A= =0A= =0A= /*=0A= * int grub_biosdisk_check_int13_extensions (int drive)=0A= *=0A= * Check if LBA is supported for DRIVE. If it is supported, then return=0A= * the major version of extensions, otherwise zero.=0A= */=0A= =0A= FUNCTION(grub_biosdisk_check_int13_extensions)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= /* drive */=0A= movb %al, %dl=0A= /* enter real mode */=0A= call prot_to_real=0A= =0A= .code16=0A= movb $0x41, %ah=0A= movw $0x55aa, %bx=0A= int $0x13 /* do the operation */=0A= =0A= /* check the result */=0A= jc 1f=0A= cmpw $0xaa55, %bx=0A= jne 1f=0A= =0A= movb %ah, %bl /* save the major version into %bl */=0A= =0A= /* check if AH=3D0x42 is supported */=0A= andw $1, %cx=0A= jnz 2f=0A= =0A= 1:=0A= xorb %bl, %bl=0A= 2:=0A= /* back to protected mode */=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %bl, %al /* return value in %eax */=0A= =0A= popl %ebx=0A= popl %ebp=0A= =0A= ret=0A= =0A= =0A= /*=0A= * int grub_biosdisk_get_diskinfo_int13_extensions (int drive, void = *drp)=0A= *=0A= * Return the geometry of DRIVE in a drive parameters, DRP. If an error=0A= * occurs, then return non-zero, otherwise zero.=0A= */=0A= =0A= FUNCTION(grub_biosdisk_get_diskinfo_int13_extensions)=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %esi=0A= =0A= /* compute the address of drive parameters */=0A= movw %dx, %si=0A= xorw %dx, %dx=0A= shrl $4, %edx=0A= movw %dx, %bx /* save the segment into %bx */=0A= /* drive */=0A= movb %al, %dl=0A= /* enter real mode */=0A= call prot_to_real=0A= =0A= .code16=0A= movb $0x48, %ah=0A= movw %bx, %ds=0A= int $0x13 /* do the operation */=0A= movb %ah, %bl /* save return value in %bl */=0A= /* clear the data segment */=0A= xorw %ax, %ax=0A= movw %ax, %ds=0A= /* back to protected mode */=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %bl, %al /* return value in %eax */=0A= =0A= popl %esi=0A= popl %ebx=0A= popl %ebp=0A= =0A= ret=0A= =0A= =0A= /*=0A= * int grub_biosdisk_get_diskinfo_standard (int drive,=0A= * unsigned long *cylinders, =0A= * unsigned long *heads,=0A= * unsigned long *sectors)=0A= *=0A= * Return the geometry of DRIVE in CYLINDERS, HEADS and SECTORS. If an=0A= * error occurs, then return non-zero, otherwise zero.=0A= */=0A= =0A= FUNCTION(grub_biosdisk_get_diskinfo_standard)=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %edi=0A= =0A= /* push CYLINDERS */=0A= pushl %edx=0A= /* push HEADS */=0A= pushl %ecx=0A= /* SECTORS is on the stack */=0A= =0A= /* drive */=0A= movb %al, %dl=0A= /* enter real mode */=0A= call prot_to_real=0A= =0A= .code16=0A= movb $0x8, %ah=0A= int $0x13 /* do the operation */=0A= /* check if successful */=0A= testb %ah, %ah=0A= jnz 1f=0A= /* bogus BIOSes may not return an error number */=0A= testb $0x3f, %cl /* 0 sectors means no disk */=0A= jnz 1f /* if non-zero, then succeed */=0A= /* XXX 0x60 is one of the unused error numbers */=0A= movb $0x60, %ah=0A= 1:=0A= movb %ah, %bl /* save return value in %bl */=0A= /* back to protected mode */=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= /* pop HEADS */=0A= popl %edi=0A= movb %dh, %al=0A= incl %eax /* the number of heads is counted from zero */=0A= movl %eax, (%edi)=0A= =0A= /* pop CYLINDERS */=0A= popl %edi=0A= movb %ch, %al=0A= movb %cl, %ah=0A= shrb $6, %ah /* the number of cylinders is counted from zero */=0A= incl %eax=0A= movl %eax, (%edi)=0A= =0A= /* SECTORS */=0A= movl 0x10(%esp), %edi=0A= andb $0x3f, %cl=0A= movzbl %cl, %eax=0A= movl %eax, (%edi)=0A= =0A= xorl %eax, %eax=0A= movb %bl, %al /* return value in %eax */=0A= =0A= popl %edi=0A= popl %ebx=0A= popl %ebp=0A= =0A= ret $4=0A= =0A= =0A= /*=0A= * int grub_biosdisk_get_num_floppies (void)=0A= */=0A= FUNCTION(grub_biosdisk_get_num_floppies)=0A= pushl %ebp=0A= =0A= xorl %edx, %edx=0A= call prot_to_real=0A= =0A= .code16=0A= /* reset the disk system first */=0A= int $0x13=0A= 1:=0A= stc=0A= =0A= /* call GET DISK TYPE */=0A= movb $0x15, %ah=0A= int $0x13=0A= =0A= jc 2f=0A= =0A= /* check if this drive exists */ =0A= testb $0x3, %ah=0A= jz 2f=0A= =0A= incb %dl=0A= cmpb $2, %dl=0A= jne 1b=0A= 2:=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movl %edx, %eax=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= *=0A= * grub_get_memsize(i) : return the memory size in KB. i =3D=3D 0 for = conventional=0A= * memory, i =3D=3D 1 for extended memory=0A= * BIOS call "INT 12H" to get conventional memory size=0A= * BIOS call "INT 15H, AH=3D88H" to get extended memory size=0A= * Both have the return value in AX.=0A= *=0A= */=0A= =0A= FUNCTION(grub_get_memsize)=0A= pushl %ebp=0A= =0A= movl %eax, %edx=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= testl %edx, %edx=0A= jnz xext=0A= =0A= int $0x12=0A= jmp xdone=0A= =0A= xext:=0A= movb $0x88, %ah=0A= int $0x15=0A= =0A= xdone:=0A= movw %ax, %dx=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= =0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= *=0A= * grub_get_eisa_mmap() : return packed EISA memory map, lower 16 bits = is=0A= * memory between 1M and 16M in 1K parts, upper 16 bits is=0A= * memory above 16M in 64K parts. If error, return zero.=0A= * BIOS call "INT 15H, AH=3DE801H" to get EISA memory map,=0A= * AX =3D memory between 1M and 16M in 1K parts.=0A= * BX =3D memory above 16M in 64K parts.=0A= *=0A= */=0A= =0A= FUNCTION(grub_get_eisa_mmap)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= movw $0xe801, %ax=0A= int $0x15=0A= =0A= shll $16, %ebx=0A= movw %ax, %bx=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= cmpb $0x86, %bh=0A= je xnoteisa=0A= =0A= movl %ebx, %eax=0A= =0A= xnoteisa:=0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= *=0A= * grub_get_mmap_entry(addr, cont) : address and old continuation value = (zero to=0A= * start), for the Query System Address Map BIOS call.=0A= *=0A= * Sets the first 4-byte int value of "addr" to the size returned by=0A= * the call. If the call fails, sets it to zero.=0A= *=0A= * Returns: new (non-zero) continuation value, 0 if done.=0A= */=0A= =0A= FUNCTION(grub_get_mmap_entry)=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %edi=0A= pushl %esi=0A= =0A= /* push ADDR */=0A= pushl %eax=0A= =0A= /* place address (+4) in ES:DI */=0A= addl $4, %eax=0A= movl %eax, %edi=0A= andl $0xf, %edi=0A= shrl $4, %eax=0A= movl %eax, %esi=0A= =0A= /* set continuation value */=0A= movl %edx, %ebx=0A= =0A= /* set default maximum buffer size */=0A= movl $0x14, %ecx=0A= =0A= /* set EDX to 'SMAP' */=0A= movl $0x534d4150, %edx=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= movw %si, %es=0A= movl $0xe820, %eax=0A= int $0x15=0A= =0A= DATA32 jc xnosmap=0A= =0A= cmpl $0x534d4150, %eax=0A= jne xnosmap=0A= =0A= cmpl $0x14, %ecx=0A= jl xnosmap=0A= =0A= cmpl $0x400, %ecx=0A= jg xnosmap=0A= =0A= jmp xsmap=0A= =0A= xnosmap:=0A= xorl %ecx, %ecx=0A= =0A= xsmap:=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= /* write length of buffer (zero if error) into ADDR */=0A= popl %eax=0A= movl %ecx, (%eax)=0A= =0A= /* set return value to continuation */=0A= movl %ebx, %eax=0A= =0A= popl %esi=0A= popl %edi=0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * void grub_console_real_putchar (int c)=0A= *=0A= * Put the character C on the console. Because GRUB wants to write a=0A= * character with an attribute, this implementation is a bit tricky.=0A= * If C is a control character (CR, LF, BEL, BS), use INT 10, AH =3D 0Eh=0A= * (TELETYPE OUTPUT). Otherwise, save the original position, put a space,=0A= * save the current position, restore the original position, write the=0A= * character and the attribute, and restore the current position.=0A= *=0A= * The reason why this is so complicated is that there is no easy way to=0A= * get the height of the screen, and the TELETYPE OUPUT BIOS call doesn't=0A= * support setting a background attribute.=0A= */=0A= FUNCTION(grub_console_real_putchar)=0A= movl %eax, %edx=0A= pusha=0A= movb EXT_C(grub_console_cur_color), %bl=0A= =0A= call prot_to_real=0A= .code16=0A= movb %dl, %al=0A= xorb %bh, %bh=0A= =0A= /* use teletype output if control character */=0A= cmpb $0x7, %al=0A= je 1f=0A= cmpb $0x8, %al=0A= je 1f=0A= cmpb $0xa, %al=0A= je 1f=0A= cmpb $0xd, %al=0A= je 1f=0A= =0A= /* save the character and the attribute on the stack */=0A= pushw %ax=0A= pushw %bx=0A= =0A= /* get the current position */=0A= movb $0x3, %ah=0A= int $0x10=0A= =0A= /* check the column with the width */=0A= cmpb $79, %dl=0A= jl 2f=0A= =0A= /* print CR and LF, if next write will exceed the width */ =0A= movw $0x0e0d, %ax=0A= int $0x10=0A= movb $0x0a, %al=0A= int $0x10=0A= =0A= /* get the current position */=0A= movb $0x3, %ah=0A= int $0x10=0A= =0A= 2: =0A= /* restore the character and the attribute */=0A= popw %bx=0A= popw %ax=0A= =0A= /* write the character with the attribute */=0A= movb $0x9, %ah=0A= movw $1, %cx=0A= int $0x10=0A= =0A= /* move the cursor forward */=0A= incb %dl=0A= movb $0x2, %ah=0A= int $0x10=0A= =0A= jmp 3f=0A= =0A= 1: movw $1, %bx=0A= movb $0xe, %ah=0A= int $0x10=0A= =0A= 3: DATA32 call real_to_prot=0A= .code32=0A= =0A= popa=0A= ret=0A= =0A= =0A= /*=0A= * int grub_console_getkey (void)=0A= * BIOS call "INT 16H Function 00H" to read character from keyboard=0A= * Call with %ah =3D 0x0=0A= * Return: %ah =3D keyboard scan code=0A= * %al =3D ASCII character=0A= */=0A= =0A= /* this table is used in translate_keycode below */=0A= translation_table:=0A= .word GRUB_CONSOLE_KEY_LEFT, 2=0A= .word GRUB_CONSOLE_KEY_RIGHT, 6=0A= .word GRUB_CONSOLE_KEY_UP, 16=0A= .word GRUB_CONSOLE_KEY_DOWN, 14=0A= .word GRUB_CONSOLE_KEY_HOME, 1=0A= .word GRUB_CONSOLE_KEY_END, 5=0A= .word GRUB_CONSOLE_KEY_DC, 4=0A= .word GRUB_CONSOLE_KEY_BACKSPACE, 8=0A= .word GRUB_CONSOLE_KEY_PPAGE, 7=0A= .word GRUB_CONSOLE_KEY_NPAGE, 3=0A= .word 0=0A= =0A= /*=0A= * translate_keycode translates the key code %dx to an ascii code.=0A= */=0A= .code16=0A= =0A= translate_keycode:=0A= pushw %bx=0A= pushw %si=0A= =0A= movw $ABS(translation_table), %si=0A= =0A= 1: lodsw=0A= /* check if this is the end */=0A= testw %ax, %ax=0A= jz 2f=0A= /* load the ascii code into %ax */=0A= movw %ax, %bx=0A= lodsw=0A= /* check if this matches the key code */=0A= cmpw %bx, %dx=0A= jne 1b=0A= /* translate %dx, if successful */=0A= movw %ax, %dx=0A= =0A= 2: popw %si=0A= popw %bx=0A= ret=0A= =0A= .code32=0A= =0A= FUNCTION(grub_console_getkey)=0A= pushl %ebp=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= int $0x16=0A= =0A= movw %ax, %dx /* real_to_prot uses %eax */=0A= call translate_keycode=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= =0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * int grub_console_checkkey (void)=0A= * if there is a character pending, return it; otherwise return -1=0A= * BIOS call "INT 16H Function 01H" to check whether a character is = pending=0A= * Call with %ah =3D 0x1=0A= * Return:=0A= * If key waiting to be input:=0A= * %ah =3D keyboard scan code=0A= * %al =3D ASCII character=0A= * Zero flag =3D clear=0A= * else=0A= * Zero flag =3D set=0A= */=0A= FUNCTION(grub_console_checkkey)=0A= pushl %ebp=0A= xorl %edx, %edx=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= movb $0x1, %ah=0A= int $0x16=0A= =0A= jz notpending=0A= =0A= movw %ax, %dx=0A= DATA32 jmp pending=0A= =0A= notpending:=0A= decl %edx=0A= =0A= pending:=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movl %edx, %eax=0A= =0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * grub_uint16_t grub_console_getxy (void)=0A= * BIOS call "INT 10H Function 03h" to get cursor position=0A= * Call with %ah =3D 0x03=0A= * %bh =3D page=0A= * Returns %ch =3D starting scan line=0A= * %cl =3D ending scan line=0A= * %dh =3D row (0 is top)=0A= * %dl =3D column (0 is left)=0A= */=0A= =0A= =0A= FUNCTION(grub_console_getxy)=0A= pushl %ebp=0A= pushl %ebx /* save EBX */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= xorb %bh, %bh /* set page to 0 */=0A= movb $0x3, %ah=0A= int $0x10 /* get cursor position */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %dl, %ah=0A= movb %dh, %al=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * void grub_console_gotoxy(grub_uint8_t x, grub_uint8_t y)=0A= * BIOS call "INT 10H Function 02h" to set cursor position=0A= * Call with %ah =3D 0x02=0A= * %bh =3D page=0A= * %dh =3D row (0 is top)=0A= * %dl =3D column (0 is left)=0A= */=0A= =0A= =0A= FUNCTION(grub_console_gotoxy)=0A= pushl %ebp=0A= pushl %ebx /* save EBX */=0A= =0A= movb %dl, %dh /* %dh =3D y */=0A= movb %al, %dl /* %dl =3D x */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= xorb %bh, %bh /* set page to 0 */=0A= movb $0x2, %ah=0A= int $0x10 /* set cursor position */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * void grub_console_cls (void)=0A= * BIOS call "INT 10H Function 09h" to write character and attribute=0A= * Call with %ah =3D 0x09=0A= * %al =3D (character)=0A= * %bh =3D (page number)=0A= * %bl =3D (attribute)=0A= * %cx =3D (number of times)=0A= */=0A= =0A= FUNCTION(grub_console_cls)=0A= pushl %ebp=0A= pushl %ebx /* save EBX */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= /* move the cursor to the beginning */=0A= movb $0x02, %ah=0A= xorb %bh, %bh=0A= xorw %dx, %dx=0A= int $0x10=0A= =0A= /* write spaces to the entire screen */=0A= movw $0x0920, %ax=0A= movw $0x07, %bx=0A= movw $(80 * 25), %cx=0A= int $0x10=0A= =0A= /* move back the cursor */=0A= movb $0x02, %ah=0A= int $0x10=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * void grub_console_setcursor (int on)=0A= * BIOS call "INT 10H Function 01h" to set cursor type=0A= * Call with %ah =3D 0x01=0A= * %ch =3D cursor starting scanline=0A= * %cl =3D cursor ending scanline=0A= */=0A= =0A= console_cursor_state:=0A= .byte 1=0A= console_cursor_shape:=0A= .word 0=0A= =0A= FUNCTION(grub_console_setcursor)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= /* push ON */=0A= pushl %eax=0A= =0A= /* check if the standard cursor shape has already been saved */=0A= movw console_cursor_shape, %ax=0A= testw %ax, %ax=0A= jne 1f=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movb $0x03, %ah=0A= xorb %bh, %bh=0A= int $0x10=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %cx, console_cursor_shape=0A= 1:=0A= /* set %cx to the designated cursor shape */=0A= movw $0x2000, %cx=0A= popl %eax=0A= testl %eax, %eax=0A= jz 2f=0A= movw console_cursor_shape, %cx=0A= 2: =0A= call prot_to_real=0A= .code16=0A= =0A= movb $0x1, %ah=0A= int $0x10 =0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_getrtsecs()=0A= * if a seconds value can be read, read it and return it (BCD),=0A= * otherwise return 0xFF=0A= * BIOS call "INT 1AH Function 02H" to check whether a character is = pending=0A= * Call with %ah =3D 0x2=0A= * Return:=0A= * If RT Clock can give correct values=0A= * %ch =3D hour (BCD)=0A= * %cl =3D minutes (BCD)=0A= * %dh =3D seconds (BCD)=0A= * %dl =3D daylight savings time (00h std, 01h = daylight)=0A= * Carry flag =3D clear=0A= * else=0A= * Carry flag =3D set=0A= * (this indicates that the clock is updating, or=0A= * that it isn't running)=0A= */=0A= FUNCTION(grub_getrtsecs)=0A= pushl %ebp=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= clc=0A= movb $0x2, %ah=0A= int $0x1a=0A= =0A= DATA32 jnc gottime=0A= movb $0xff, %dh=0A= =0A= gottime:=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %dh, %al=0A= =0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * grub_get_rtc()=0A= * return the real time in ticks, of which there are about=0A= * 18-20 per second=0A= */=0A= FUNCTION(grub_get_rtc)=0A= pushl %ebp=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= /* %ax is already zero */=0A= int $0x1a=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movl %ecx, %eax=0A= shll $16, %eax=0A= movw %dx, %ax=0A= =0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * unsigned char grub_vga_set_mode (unsigned char mode)=0A= */=0A= FUNCTION(grub_vga_set_mode)=0A= pushl %ebp=0A= pushl %ebx=0A= movl %eax, %ecx=0A= =0A= call prot_to_real=0A= .code16=0A= /* get current mode */=0A= xorw %bx, %bx=0A= movb $0x0f, %ah=0A= int $0x10=0A= movb %al, %dl=0A= =0A= /* set the new mode */=0A= movb %cl, %al=0A= xorb %ah, %ah=0A= int $0x10=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %dl, %al=0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * unsigned char *grub_vga_get_font (void)=0A= */=0A= FUNCTION(grub_vga_get_font)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= call prot_to_real=0A= .code16=0A= movw $0x1130, %ax=0A= movb $0x06, %bh=0A= int $0x10=0A= movw %es, %bx=0A= movw %bp, %dx=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movzwl %bx, %ecx=0A= shll $4, %ecx=0A= movw %dx, %ax=0A= addl %ecx, %eax=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_controller_info (struct = grub_vbe_info_block *controller_info)=0A= *=0A= * Register allocations for parameters:=0A= * %eax *controller_info=0A= */=0A= FUNCTION(grub_vbe_get_controller_info)=0A= pushl %ebp=0A= pushl %edi=0A= =0A= movw %ax, %di /* Store *controller_info to %edx:%di. */=0A= xorw %ax, %ax=0A= shrl $4, %eax=0A= mov %eax, %edx /* prot_to_real destroys %eax. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= pushw %es=0A= =0A= movw %dx, %es /* *controller_info is now on %es:%di. */=0A= movw $0x4f00, %ax=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= popw %es=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movl %edx, %eax=0A= andl $0x0FFFF, %eax /* Return value in %eax. */=0A= =0A= popl %edi=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_mode_info (grub_uint32_t mode,=0A= * struct grub_vbe_mode_info_block *mode_info)=0A= *=0A= * Register allocations for parameters:=0A= * %eax mode=0A= * %edx *mode_info=0A= */=0A= FUNCTION(grub_vbe_get_mode_info)=0A= pushl %ebp=0A= pushl %edi=0A= =0A= movl %eax, %ecx /* Store mode number to %ecx. */=0A= =0A= movw %dx, %di /* Store *mode_info to %edx:%di. */=0A= xorw %dx, %dx=0A= shrl $4, %edx=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= pushw %es=0A= =0A= movw %dx, %es /* *mode_info is now on %es:%di. */=0A= movw $0x4f01, %ax=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= popw %es=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movl %edx, %eax=0A= andl $0x0FFFF, %eax /* Return value in %eax. */=0A= =0A= popl %edi=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_set_mode (grub_uint32_t mode,=0A= * struct grub_vbe_crtc_info_block *crtc_info)=0A= *=0A= * Register allocations for parameters:=0A= * %eax mode=0A= * %edx *crtc_info=0A= */=0A= FUNCTION(grub_vbe_set_mode)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= movl %eax, %ebx /* Store mode in %ebx. */=0A= =0A= movw %dx, %di /* Store *crtc_info to %edx:%di. */=0A= xorw %dx, %dx=0A= shrl $4, %edx=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= pushw %es=0A= =0A= movw %dx, %es /* *crtc_info is now on %es:%di. */=0A= =0A= movw $0x4f02, %ax=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= popw %es=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_mode (grub_uint32_t *mode)=0A= *=0A= * Register allocations for parameters:=0A= * %eax *mode=0A= */=0A= FUNCTION(grub_vbe_get_mode)=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %eax /* Push *mode to stack. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f03, %ax=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %edi /* Pops *mode from stack to %edi. */=0A= andl $0xFFFF, %ebx=0A= movl %ebx, (%edi)=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_set_memory_window (grub_uint32_t window,=0A= * grub_uint32_t position);=0A= *=0A= * Register allocations for parameters:=0A= * %eax window=0A= * %edx position=0A= */=0A= FUNCTION(grub_vbe_set_memory_window)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= movl %eax, %ebx=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f05, %ax=0A= andw $0x00ff, %bx /* BL =3D window, BH =3D 0, Set memory window. */=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_memory_window (grub_uint32_t window,=0A= * grub_uint32_t *position);=0A= *=0A= * Register allocations for parameters:=0A= * %eax window=0A= * %edx *position=0A= */=0A= FUNCTION(grub_vbe_get_memory_window)=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %edx /* Push *position to stack. */=0A= =0A= movl %eax, %ebx /* Store window in %ebx. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f05, %ax=0A= andw $0x00ff, %bx /* BL =3D window. */=0A= orw $0x0100, %bx /* BH =3D 1, Get memory window. */=0A= int $0x10=0A= =0A= movw %ax, %bx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %edi /* pops *position from stack to %edi. */=0A= andl $0xFFFF, %edx=0A= movl %edx, (%edi) /* Return position to caller. */=0A= =0A= movw %bx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_set_scanline_length (grub_uint32_t length)=0A= *=0A= * Register allocations for parameters:=0A= * %eax length=0A= */=0A= FUNCTION(grub_vbe_set_scanline_length)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= movl %eax, %ecx /* Store length in %ecx. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f06, %ax=0A= movw $0x0002, %bx /* BL =3D 2, Set Scan Line in Bytes. */=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_scanline_length (grub_uint32_t *length)=0A= *=0A= * Register allocations for parameters:=0A= * %eax *length=0A= */=0A= FUNCTION(grub_vbe_get_scanline_length)=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %edx /* Push *length to stack. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f06, %ax=0A= movw $0x0001, %bx /* BL =3D 1, Get Scan Line Length (in bytes). */=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %edi /* Pops *length from stack to %edi. */=0A= andl $0xFFFF, %ebx=0A= movl %ebx, (%edi) /* Return length to caller. */=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_set_display_start (grub_uint32_t x,=0A= * grub_uint32_t y)=0A= *=0A= * Register allocations for parameters:=0A= * %eax x=0A= * %edx y=0A= */=0A= FUNCTION(grub_vbe_set_display_start)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= movl %eax, %ecx /* Store x in %ecx. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f07, %ax=0A= movw $0x0080, %bx /* BL =3D 80h, Set Display Start =0A= during Vertical Retrace. */=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_display_start (grub_uint32_t *x,=0A= * grub_uint32_t *y)=0A= *=0A= * Register allocations for parameters:=0A= * %eax *x=0A= * %edx *y=0A= */=0A= FUNCTION(grub_vbe_get_display_start)=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %eax /* Push *x to stack. */=0A= pushl %edx /* Push *y to stack. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f07, %ax=0A= movw $0x0001, %bx /* BL =3D 1, Get Display Start. */=0A= int $0x10=0A= =0A= movw %ax, %bx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %edi /* Pops *y from stack to %edi. */=0A= andl $0xFFFF, %edx=0A= movl %edx, (%edi) /* Return y-position to caller. */=0A= =0A= popl %edi /* Pops *x from stack to %edi. */=0A= andl $0xFFFF, %ecx=0A= movl %ecx, (%edi) /* Return x-position to caller. */=0A= =0A= movw %bx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_set_palette_data (grub_uint32_t = color_count,=0A= * grub_uint32_t start_index,=0A= * struct grub_vbe_palette_data *palette_data)=0A= *=0A= * Register allocations for parameters:=0A= * %eax color_count=0A= * %edx start_index=0A= * %ecx *palette_data=0A= */=0A= FUNCTION(grub_vbe_set_palette_data)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= movl %eax, %ebx /* Store color_count in %ebx. */=0A= =0A= movw %cx, %di /* Store *palette_data to %ecx:%di. */=0A= xorw %cx, %cx=0A= shrl $4, %ecx=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= pushw %es=0A= =0A= movw %cx, %es /* *palette_data is now on %es:%di. */=0A= movw %bx, %cx /* color_count is now on %cx. */=0A= =0A= movw $0x4f09, %ax=0A= xorw %bx, %bx /* BL =3D 0, Set Palette Data. */=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= popw %es=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= ------=_NextPart_000_0001_01C6733D.65178F80 Content-Type: text/plain; name="diffsym.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="diffsym.txt" a52 3=0A= extern int grub_null();=0A= extern int grub_null_var;=0A= =0A= d138 2=0A= a140 1=0A= {"grub_mmap", grub_mmap},=0A= d174 2=0A= a175 2=0A= {"grub_console_checkkey", grub_checkkey},=0A= {"grub_console_getkey", grub_getkey},=0A= d178 4=0A= a181 5=0A= {"grub_break", grub_break},=0A= {"grub_linux_boot_zimage", grub_null},=0A= {"grub_linux_boot_bzimage", grub_null},=0A= {"grub_chainloader_real_boot", grub_null},=0A= {"grub_multiboot_real_boot", grub_null},=0A= d183 13=0A= a195 13=0A= {"grub_vga_set_mode", grub_null},=0A= {"grub_vga_get_font", grub_null},=0A= {"grub_vbe_get_controller_info", grub_null},=0A= {"grub_vbe_get_mode_info", grub_null},=0A= {"grub_vbe_set_mode", grub_null},=0A= {"grub_vbe_get_mode", grub_null},=0A= {"grub_vbe_set_memory_window", grub_null},=0A= {"grub_vbe_get_memory_window", grub_null},=0A= {"grub_vbe_set_scanline_length", grub_null},=0A= {"grub_vbe_get_scanline_length", grub_null},=0A= {"grub_vbe_set_display_start", grub_null},=0A= {"grub_vbe_get_display_start", grub_null},=0A= {"grub_vbe_set_palette_data", grub_null},=0A= d199 7=0A= a205 7=0A= {"grub_lower_mem", &grub_null_var},=0A= {"grub_upper_mem", &grub_null_var},=0A= {"grub_os_area_addr", &grub_null_var},=0A= {"grub_os_area_size", &grub_null_var},=0A= {"grub_linux_prot_size", &grub_null_var},=0A= {"grub_linux_tmp_addr", &grub_null_var},=0A= {"grub_linux_real_addr", &grub_null_var},=0A= ------=_NextPart_000_0001_01C6733D.65178F80 Content-Type: application/octet-stream; name="startup.S" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="startup.S" /*=0A= * GRUB -- GRand Unified Bootloader=0A= * Copyright (C) 1999,2000,2001,2002,2003,2005 Free Software = Foundation, Inc.=0A= *=0A= * This program is free software; you can redistribute it and/or modify=0A= * it under the terms of the GNU General Public License as published by=0A= * the Free Software Foundation; either version 2 of the License, or=0A= * (at your option) any later version.=0A= *=0A= * This program is distributed in the hope that it will be useful,=0A= * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= * GNU General Public License for more details.=0A= *=0A= * You should have received a copy of the GNU General Public License=0A= * along with this program; if not, write to the Free Software=0A= * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=0A= */=0A= =0A= #ifdef REGPARM=0A= #include "startup.S.regparm"=0A= #else=0A= #include "startup.S.memparm"=0A= #endif=0A= =0A= ------=_NextPart_000_0001_01C6733D.65178F80 Content-Type: application/octet-stream; name="startup.S.memparm" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="startup.S.memparm" /*=0A= * GRUB -- GRand Unified Bootloader=0A= * Copyright (C) 1999,2000,2001,2002,2003,2005 Free Software = Foundation, Inc.=0A= *=0A= * This program is free software; you can redistribute it and/or modify=0A= * it under the terms of the GNU General Public License as published by=0A= * the Free Software Foundation; either version 2 of the License, or=0A= * (at your option) any later version.=0A= *=0A= * This program is distributed in the hope that it will be useful,=0A= * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= * GNU General Public License for more details.=0A= *=0A= * You should have received a copy of the GNU General Public License=0A= * along with this program; if not, write to the Free Software=0A= * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=0A= */=0A= =0A= =0A= /*=0A= * Note: These functions defined in this file may be called from C.=0A= * Be careful of that you must not modify some registers. Quote=0A= * from gcc-2.95.2/gcc/config/i386/i386.h:=0A= =0A= 1 for registers not available across function calls.=0A= These must include the FIXED_REGISTERS and also any=0A= registers that can be used without being saved.=0A= The latter must include the registers where values are returned=0A= and the register where structure-value addresses are passed.=0A= Aside from that, you can include as many other registers as you like.=0A= =0A= ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg=0A= { 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }=0A= */=0A= =0A= /*=0A= * Note: GRUB is compiled with the options -mrtd and -mregparm=3D3.=0A= * So the first three arguments are passed in %eax, %edx, and %ecx,=0A= * respectively, and if a function has a fixed number of arguments=0A= * and the number if greater than three, the function must return=0A= * with "ret $N" where N is ((the number of arguments) - 3) * 4.=0A= */=0A= =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= #include =0A= =0A= #define ABS(x) ((x) - EXT_C(start) + GRUB_BOOT_MACHINE_KERNEL_ADDR + = 0x200)=0A= =0A= .file "startup.S"=0A= =0A= .text=0A= =0A= /* Tell GAS to generate 16-bit instructions so that this code works=0A= in real mode. */=0A= .code16=0A= =0A= .globl start, _start=0A= start:=0A= _start:=0A= /*=0A= * Guarantee that "main" is loaded at 0x0:0x8200.=0A= */=0A= ljmp $0, $ABS(codestart)=0A= =0A= /*=0A= * Compatibility version number=0A= *=0A= * These MUST be at byte offset 6 and 7 of the executable=0A= * DO NOT MOVE !!!=0A= */=0A= . =3D EXT_C(start) + 0x6=0A= .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR=0A= =0A= /*=0A= * This is a special data area 8 bytes from the beginning.=0A= */=0A= =0A= . =3D EXT_C(start) + 0x8=0A= =0A= VARIABLE(grub_total_module_size)=0A= .long 0=0A= VARIABLE(grub_kernel_image_size)=0A= .long 0=0A= VARIABLE(grub_compressed_size)=0A= .long 0=0A= VARIABLE(grub_install_dos_part)=0A= .long 0xFFFFFFFF=0A= VARIABLE(grub_install_bsd_part)=0A= .long 0xFFFFFFFF=0A= VARIABLE(grub_prefix)=0A= .string "/boot/grub"=0A= =0A= /*=0A= * Leave some breathing room for the prefix.=0A= */=0A= =0A= . =3D EXT_C(start) + 0x50=0A= =0A= /*=0A= * Support for booting GRUB from a Multiboot boot loader (e.g. GRUB = itself).=0A= * This uses the a.out kludge to load raw binary to the area starting at = 1MB,=0A= * and relocates itself after loaded.=0A= */=0A= multiboot_header:=0A= /* magic */=0A= .long 0x1BADB002=0A= /* flags */=0A= .long (1 << 16)=0A= /* checksum */=0A= .long -0x1BADB002 - (1 << 16)=0A= /* header addr */=0A= .long multiboot_header - _start + 0x100000 + 0x200=0A= /* load addr */=0A= .long 0x100000=0A= /* load end addr */=0A= .long 0=0A= /* bss end addr */=0A= .long 0=0A= /* entry addr */=0A= .long multiboot_entry - _start + 0x100000 + 0x200=0A= =0A= multiboot_entry:=0A= .code32=0A= /* obtain the boot device */=0A= movl 12(%ebx), %edx=0A= =0A= /* relocate the code */=0A= movl $(GRUB_KERNEL_MACHINE_RAW_SIZE + 0x200), %ecx=0A= addl EXT_C(grub_compressed_size) - _start + 0x100000 + 0x200, %ecx=0A= movl $0x100000, %esi=0A= movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %edi=0A= cld=0A= rep=0A= movsb=0A= /* jump to the real address */=0A= movl $multiboot_trampoline, %eax=0A= jmp *%eax=0A= =0A= multiboot_trampoline:=0A= /* fill the boot information */=0A= movl %edx, %eax=0A= shrl $8, %eax=0A= xorl %ebx, %ebx=0A= cmpb $0xFF, %ah=0A= je 1f=0A= movb %ah, %bl=0A= movl %ebx, EXT_C(grub_install_dos_part)=0A= 1:=0A= cmpb $0xFF, %al=0A= je 2f=0A= movb %al, %bl=0A= movl %ebx, EXT_C(grub_install_bsd_part)=0A= 2:=0A= shrl $24, %edx=0A= /* enter the usual booting */=0A= call prot_to_real=0A= .code16=0A= =0A= /* the real mode code continues... */=0A= codestart:=0A= cli /* we're not safe here! */=0A= =0A= /* set up %ds, %ss, and %es */=0A= xorw %ax, %ax=0A= movw %ax, %ds=0A= movw %ax, %ss=0A= movw %ax, %es=0A= =0A= /* set up the real mode/BIOS stack */=0A= movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp=0A= movl %ebp, %esp=0A= =0A= sti /* we're safe again */=0A= =0A= /* save boot drive reference */=0A= ADDR32 movb %dl, EXT_C(grub_boot_drive)=0A= =0A= /* reset disk system (%ah =3D 0) */=0A= int $0x13=0A= =0A= /* transition to protected mode */=0A= DATA32 call real_to_prot=0A= =0A= /* The ".code32" directive takes GAS out of 16-bit mode. */=0A= .code32=0A= =0A= incl %eax=0A= call EXT_C(grub_gate_a20)=0A= =0A= /* decompress the compressed part and put the result at 1MB */=0A= movl $0x100000, %esi=0A= movl $(START_SYMBOL + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi=0A= =0A= pushl %esi=0A= pushl EXT_C(grub_compressed_size)=0A= pushl %edi=0A= call lzo1x_decompress=0A= addl $12, %esp=0A= =0A= /* copy back the decompressed part */=0A= movl %eax, %ecx=0A= cld=0A= rep=0A= movsb=0A= =0A= /* copy modules before cleaning out the bss */=0A= movl EXT_C(grub_total_module_size), %ecx=0A= movl EXT_C(grub_kernel_image_size), %esi=0A= addl %ecx, %esi=0A= addl $START_SYMBOL, %esi=0A= decl %esi=0A= movl $END_SYMBOL, %edi=0A= addl %ecx, %edi=0A= decl %edi=0A= std=0A= rep=0A= movsb=0A= =0A= /* clean out the bss */=0A= movl $BSS_START_SYMBOL, %edi=0A= =0A= /* compute the bss length */=0A= movl $END_SYMBOL, %ecx=0A= subl %edi, %ecx=0A= =0A= /* clean out */=0A= xorl %eax, %eax=0A= cld=0A= rep=0A= stosb=0A= =0A= /*=0A= * Call the start of main body of C code.=0A= */=0A= call EXT_C(grub_main)=0A= =0A= =0A= /*=0A= * This is the area for all of the special variables.=0A= */=0A= =0A= .p2align 2 /* force 4-byte alignment */=0A= =0A= protstack:=0A= .long GRUB_MEMORY_MACHINE_PROT_STACK=0A= =0A= VARIABLE(grub_boot_drive)=0A= .long 0=0A= =0A= VARIABLE(grub_start_addr)=0A= .long START_SYMBOL=0A= =0A= VARIABLE(grub_end_addr)=0A= .long END_SYMBOL=0A= =0A= VARIABLE(grub_apm_bios_info)=0A= .word 0 /* version */=0A= .word 0 /* cseg */=0A= .long 0 /* offset */=0A= .word 0 /* cseg_16 */=0A= .word 0 /* dseg_16 */=0A= .word 0 /* cseg_len */=0A= .word 0 /* cseg_16_len */=0A= .word 0 /* dseg_16_len */=0A= =0A= /*=0A= * This is the Global Descriptor Table=0A= *=0A= * An entry, a "Segment Descriptor", looks like this:=0A= *=0A= * 31 24 19 16 7 0=0A= * ------------------------------------------------------------=0A= * | | |B| |A| | | |1|0|E|W|A| |=0A= * | BASE 31..24 |G|/|L|V| LIMIT |P|DPL| TYPE | BASE 23:16 | 4=0A= * | | |D| |L| 19..16| | |1|1|C|R|A| |=0A= * ------------------------------------------------------------=0A= * | | |=0A= * | BASE 15..0 | LIMIT 15..0 | 0=0A= * | | |=0A= * ------------------------------------------------------------=0A= *=0A= * Note the ordering of the data items is reversed from the above=0A= * description.=0A= */=0A= =0A= .p2align 2 /* force 4-byte alignment */=0A= gdt:=0A= .word 0, 0=0A= .byte 0, 0, 0, 0=0A= =0A= /* -- code segment --=0A= * base =3D 0x00000000, limit =3D 0xFFFFF (4 KiB Granularity), present=0A= * type =3D 32bit code execute/read, DPL =3D 0=0A= */=0A= .word 0xFFFF, 0=0A= .byte 0, 0x9A, 0xCF, 0=0A= =0A= /* -- data segment --=0A= * base =3D 0x00000000, limit 0xFFFFF (4 KiB Granularity), present=0A= * type =3D 32 bit data read/write, DPL =3D 0 =0A= */=0A= .word 0xFFFF, 0=0A= .byte 0, 0x92, 0xCF, 0=0A= =0A= /* -- 16 bit real mode CS --=0A= * base =3D 0x00000000, limit 0x0FFFF (1 B Granularity), present=0A= * type =3D 16 bit code execute/read only/conforming, DPL =3D 0=0A= */=0A= .word 0xFFFF, 0=0A= .byte 0, 0x9E, 0, 0=0A= =0A= /* -- 16 bit real mode DS --=0A= * base =3D 0x00000000, limit 0x0FFFF (1 B Granularity), present=0A= * type =3D 16 bit data read/write, DPL =3D 0=0A= */=0A= .word 0xFFFF, 0=0A= .byte 0, 0x92, 0, 0=0A= =0A= =0A= /* this is the GDT descriptor */=0A= gdtdesc:=0A= .word 0x27 /* limit */=0A= .long gdt /* addr */=0A= =0A= =0A= /*=0A= * These next two routines, "real_to_prot" and "prot_to_real" are = structured=0A= * in a very specific way. Be very careful when changing them.=0A= *=0A= * NOTE: Use of either one messes up %eax and %ebp.=0A= */=0A= =0A= real_to_prot:=0A= .code16=0A= cli=0A= =0A= /* load the GDT register */=0A= DATA32 ADDR32 lgdt gdtdesc=0A= =0A= /* turn on protected mode */=0A= movl %cr0, %eax=0A= orl $GRUB_MEMORY_MACHINE_CR0_PE_ON, %eax=0A= movl %eax, %cr0=0A= =0A= /* jump to relocation, flush prefetch queue, and reload %cs */=0A= DATA32 ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg=0A= =0A= .code32=0A= protcseg:=0A= /* reload other segment registers */=0A= movw $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %ax=0A= movw %ax, %ds=0A= movw %ax, %es=0A= movw %ax, %fs=0A= movw %ax, %gs=0A= movw %ax, %ss=0A= =0A= /* put the return address in a known safe location */=0A= movl (%esp), %eax=0A= movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK=0A= =0A= /* get protected mode stack */=0A= movl protstack, %eax=0A= movl %eax, %esp=0A= movl %eax, %ebp=0A= =0A= /* get return address onto the right stack */=0A= movl GRUB_MEMORY_MACHINE_REAL_STACK, %eax=0A= movl %eax, (%esp)=0A= =0A= /* zero %eax */=0A= xorl %eax, %eax=0A= =0A= /* return on the old (or initialized) stack! */=0A= ret=0A= =0A= =0A= prot_to_real:=0A= /* just in case, set GDT */=0A= lgdt gdtdesc=0A= =0A= /* save the protected mode stack */=0A= movl %esp, %eax=0A= movl %eax, protstack=0A= =0A= /* get the return address */=0A= movl (%esp), %eax=0A= movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK=0A= =0A= /* set up new stack */=0A= movl $GRUB_MEMORY_MACHINE_REAL_STACK, %eax=0A= movl %eax, %esp=0A= movl %eax, %ebp=0A= =0A= /* set up segment limits */=0A= movw $GRUB_MEMORY_MACHINE_PSEUDO_REAL_DSEG, %ax=0A= movw %ax, %ds=0A= movw %ax, %es=0A= movw %ax, %fs=0A= movw %ax, %gs=0A= movw %ax, %ss=0A= =0A= /* this might be an extra step */=0A= /* jump to a 16 bit segment */=0A= ljmp $GRUB_MEMORY_MACHINE_PSEUDO_REAL_CSEG, $tmpcseg=0A= =0A= tmpcseg:=0A= .code16=0A= =0A= /* clear the PE bit of CR0 */=0A= movl %cr0, %eax=0A= andl $(~GRUB_MEMORY_MACHINE_CR0_PE_ON), %eax=0A= movl %eax, %cr0=0A= =0A= /* flush prefetch queue, reload %cs */=0A= DATA32 ljmp $0, $realcseg=0A= =0A= realcseg:=0A= /* we are in real mode now=0A= * set up the real mode segment registers : DS, SS, ES=0A= */=0A= /* zero %eax */=0A= xorl %eax, %eax=0A= =0A= movw %ax, %ds=0A= movw %ax, %es=0A= movw %ax, %fs=0A= movw %ax, %gs=0A= movw %ax, %ss=0A= =0A= /* restore interrupts */=0A= sti=0A= =0A= /* return on new stack! */=0A= DATA32 ret=0A= =0A= .code32=0A= =0A= =0A= /*=0A= * grub_gate_a20(int on)=0A= *=0A= * Gate address-line 20 for high memory.=0A= *=0A= * This routine is probably overconservative in what it does, but so = what?=0A= *=0A= * It also eats any keystrokes in the keyboard buffer. :-(=0A= */=0A= =0A= FUNCTION(grub_gate_a20)=0A= movl %eax, %edx=0A= =0A= gate_a20_test_current_state: =0A= /* first of all, test if already in a good state */=0A= call gate_a20_check_state=0A= cmpb %al, %dl=0A= jnz gate_a20_try_bios=0A= ret=0A= =0A= gate_a20_try_bios:=0A= /* second, try a BIOS call */=0A= pushl %ebp=0A= call prot_to_real=0A= =0A= .code16=0A= movw $0x2400, %ax=0A= testb %dl, %dl=0A= jz 1f=0A= incw %ax=0A= 1: int $0x15=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %ebp=0A= call gate_a20_check_state=0A= cmpb %al, %dl=0A= jnz gate_a20_try_keyboard_controller=0A= ret=0A= =0A= gate_a20_flush_keyboard_buffer:=0A= inb $0x64=0A= andb $0x02, %al=0A= jnz gate_a20_flush_keyboard_buffer=0A= 2: =0A= inb $0x64=0A= andb $0x01, %al=0A= jz 3f=0A= inb $0x60=0A= jmp 2b=0A= 3:=0A= ret=0A= =0A= gate_a20_try_keyboard_controller: =0A= /* third, try the keyboard controller */=0A= call gate_a20_flush_keyboard_buffer=0A= =0A= movb $0xd1, %al=0A= outb $0x64=0A= 4: =0A= inb $0x64=0A= andb $0x02, %al=0A= jnz 4b=0A= =0A= movb $0xdd, %al=0A= testb %dl, %dl=0A= jz 5f=0A= orb $0x02, %al=0A= 5: outb $0x60=0A= call gate_a20_flush_keyboard_buffer=0A= =0A= /* output a dummy command (USB keyboard hack) */=0A= movb $0xff, %al=0A= outb $0x64=0A= call gate_a20_flush_keyboard_buffer=0A= =0A= call gate_a20_check_state=0A= cmpb %al, %dl=0A= jnz gate_a20_try_system_control_port_a=0A= ret=0A= =0A= gate_a20_try_system_control_port_a:=0A= /* fourth, try the system control port A */=0A= inb $0x92=0A= andb $(~0x03), %al=0A= testb %dl, %dl=0A= jz 6f=0A= orb $0x02, %al=0A= 6: outb $0x92=0A= =0A= /* When turning off Gate A20, do not check the state strictly,=0A= because a failure is not fatal usually, and Gate A20 is always=0A= on some modern machines. */=0A= testb %dl, %dl=0A= jz 7f =0A= call gate_a20_check_state=0A= cmpb %al, %dl=0A= /* everything failed, so restart from the beginning */=0A= jnz gate_a20_try_bios=0A= 7: ret=0A= =0A= gate_a20_check_state:=0A= /* iterate the checking for a while */=0A= movl $100, %ecx=0A= 1: =0A= call 3f=0A= cmpb %al, %dl=0A= jz 2f=0A= loop 1b=0A= 2:=0A= ret=0A= 3: =0A= pushl %ebx=0A= pushl %ecx=0A= xorl %eax, %eax=0A= /* compare the byte at 0x8000 with that at 0x108000 */=0A= movl $GRUB_BOOT_MACHINE_KERNEL_ADDR, %ebx=0A= pushl %ebx=0A= /* save the original byte in CL */=0A= movb (%ebx), %cl=0A= /* store the value at 0x108000 in AL */=0A= addl $0x100000, %ebx=0A= movb (%ebx), %al=0A= /* try to set one less value at 0x8000 */=0A= popl %ebx=0A= movb %al, %ch=0A= decb %ch=0A= movb %ch, (%ebx)=0A= /* serialize */=0A= outb %al, $0x80=0A= outb %al, $0x80=0A= /* obtain the value at 0x108000 in CH */=0A= pushl %ebx=0A= addl $0x100000, %ebx=0A= movb (%ebx), %ch=0A= /* this result is 1 if A20 is on or 0 if it is off */=0A= subb %ch, %al=0A= xorb $1, %al=0A= /* restore the original */=0A= popl %ebx=0A= movb %cl, (%ebx)=0A= popl %ecx=0A= popl %ebx=0A= ret=0A= =0A= #include "lzo1x.S"=0A= =0A= =0A= /*=0A= * This call is special... it never returns... in fact it should = simply=0A= * hang at this point!=0A= */=0A= =0A= FUNCTION(grub_stop)=0A= call prot_to_real=0A= =0A= /*=0A= * This next part is sort of evil. It takes advantage of the=0A= * byte ordering on the x86 to work in either 16-bit or 32-bit=0A= * mode, so think about it before changing it.=0A= */=0A= =0A= FUNCTION(grub_hard_stop)=0A= hlt=0A= jmp EXT_C(grub_hard_stop)=0A= =0A= =0A= /*=0A= * grub_stop_floppy()=0A= *=0A= * Stop the floppy drive from spinning, so that other software is=0A= * jumped to with a known state.=0A= */=0A= FUNCTION(grub_stop_floppy)=0A= movw $0x3F2, %dx=0A= xorb %al, %al=0A= outb %al, %dx=0A= ret=0A= =0A= /*=0A= * grub_reboot()=0A= *=0A= * Reboot the system. At the moment, rely on BIOS.=0A= */=0A= FUNCTION(grub_reboot)=0A= call prot_to_real=0A= .code16=0A= /* cold boot */=0A= movw $0x0472, %di=0A= movw %ax, (%di)=0A= ljmp $0xFFFF, $0x0000=0A= .code32=0A= =0A= /*=0A= * grub_halt(int no_apm)=0A= *=0A= * Halt the system, using APM if possible. If NO_APM is true, don't use=0A= * APM even if it is available.=0A= */=0A= FUNCTION(grub_halt)=0A= /* see if zero */=0A= mov 4(%esp), %eax=0A= testl %eax, %eax=0A= jnz EXT_C(grub_stop)=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= /* detect APM */=0A= movw $0x5300, %ax=0A= xorw %bx, %bx=0A= int $0x15=0A= jc EXT_C(grub_hard_stop)=0A= /* don't check %bx for buggy BIOSes... */=0A= =0A= /* disconnect APM first */=0A= movw $0x5304, %ax=0A= xorw %bx, %bx=0A= int $0x15=0A= =0A= /* connect APM */=0A= movw $0x5301, %ax=0A= xorw %bx, %bx=0A= int $0x15=0A= jc EXT_C(grub_hard_stop)=0A= =0A= /* set APM protocol level - 1.1 or bust. (this covers APM 1.2 also) */=0A= movw $0x530E, %ax=0A= xorw %bx, %bx=0A= movw $0x0101, %cx=0A= int $0x15=0A= jc EXT_C(grub_hard_stop)=0A= =0A= /* set the power state to off */=0A= movw $0x5307, %ax=0A= movw $1, %bx=0A= movw $3, %cx=0A= int $0x15=0A= =0A= /* shouldn't reach here */=0A= jmp EXT_C(grub_hard_stop)=0A= .code32=0A= =0A= =0A= /*=0A= * void grub_chainloader_real_boot (int drive, void *part_addr)=0A= *=0A= * This starts another boot loader.=0A= */=0A= =0A= FUNCTION(grub_chainloader_real_boot)=0A= pushl %edx=0A= pushl %eax=0A= =0A= call EXT_C(grub_dl_unload_all)=0A= =0A= /* set up to pass boot drive */=0A= mov 4(%esp),%edx=0A= =0A= /* ESI must point to a partition table entry */=0A= mov 8(%esp),%esi=0A= =0A= /* Turn off Gate A20 */=0A= xorl %eax, %eax=0A= call EXT_C(grub_gate_a20)=0A= =0A= call prot_to_real=0A= .code16=0A= ljmp $0, $GRUB_MEMORY_MACHINE_BOOT_LOADER_ADDR=0A= .code32=0A= =0A= =0A= /*=0A= * void grub_linux_boot_zimage (void)=0A= */=0A= VARIABLE(grub_linux_prot_size)=0A= .long 0=0A= VARIABLE(grub_linux_tmp_addr)=0A= .long 0=0A= VARIABLE(grub_linux_real_addr)=0A= .long 0=0A= =0A= FUNCTION(grub_linux_boot_zimage)=0A= /* copy the kernel */=0A= movl EXT_C(grub_linux_prot_size), %ecx=0A= addl $3, %ecx=0A= shrl $2, %ecx=0A= movl $GRUB_LINUX_BZIMAGE_ADDR, %esi=0A= movl $GRUB_LINUX_ZIMAGE_ADDR, %edi=0A= cld=0A= rep=0A= movsl=0A= =0A= FUNCTION(grub_linux_boot_bzimage)=0A= call EXT_C(grub_dl_unload_all)=0A= =0A= movl EXT_C(grub_linux_real_addr), %ebx=0A= =0A= /* copy the real mode code */=0A= movl EXT_C(grub_linux_tmp_addr), %esi=0A= movl %ebx, %edi=0A= movl $GRUB_LINUX_SETUP_MOVE_SIZE, %ecx=0A= cld=0A= rep=0A= movsb=0A= =0A= /* change %ebx to the segment address */=0A= shrl $4, %ebx=0A= movl %ebx, %eax=0A= addl $0x20, %eax=0A= movw %ax, linux_setup_seg=0A= =0A= /* XXX new stack pointer in safe area for calling functions */=0A= movl $0x4000, %esp=0A= call EXT_C(grub_stop_floppy)=0A= =0A= /* final setup for linux boot */=0A= call prot_to_real=0A= .code16=0A= =0A= cli=0A= movw %bx, %ss=0A= movw $GRUB_LINUX_SETUP_STACK, %sp=0A= =0A= movw %bx, %ds=0A= movw %bx, %es=0A= movw %bx, %fs=0A= movw %bx, %gs=0A= =0A= /* ljmp */=0A= .byte 0xea=0A= .word 0=0A= linux_setup_seg:=0A= .word 0=0A= .code32=0A= =0A= =0A= /*=0A= * This starts the multiboot kernel.=0A= */=0A= =0A= FUNCTION(grub_multiboot_real_boot)=0A= /* Push the entry address on the stack. */=0A= /* Move the address of the multiboot information structure to ebx. */=0A= movl 8(%esp),%ebx=0A= =0A= /* Unload all modules and stop the floppy driver. */=0A= call EXT_C(grub_dl_unload_all)=0A= call EXT_C(grub_stop_floppy)=0A= =0A= /* Interrupts should be disabled. */=0A= cli=0A= =0A= /* Move the magic value into eax and jump to the kernel. */=0A= movl $GRUB_MB_MAGIC2,%eax=0A= movl 4(%esp),%ecx=0A= jmp *%ecx=0A= =0A= =0A= /*=0A= * int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap)=0A= *=0A= * Call IBM/MS INT13 Extensions (int 13 %ah=3DAH) for DRIVE. DAP=0A= * is passed for disk address packet. If an error occurs, return=0A= * non-zero, otherwise zero.=0A= */=0A= =0A= FUNCTION(grub_biosdisk_rw_int13_extensions)=0A= movw 0x4(%esp), %ax=0A= movw 0x8(%esp), %dx=0A= mov 0xC(%esp), %ecx=0A= pushl %ebp=0A= pushl %esi=0A= =0A= /* compute the address of disk_address_packet */=0A= movw %cx, %si=0A= xorw %cx, %cx=0A= shrl $4, %ecx /* save the segment to cx */=0A= =0A= /* ah */=0A= movb %al, %dh=0A= /* enter real mode */=0A= call prot_to_real=0A= =0A= .code16=0A= movb %dh, %ah=0A= movw %cx, %ds=0A= int $0x13 /* do the operation */=0A= movb %ah, %dl /* save return value */=0A= /* clear the data segment */=0A= xorw %ax, %ax=0A= movw %ax, %ds=0A= /* back to protected mode */=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %dl, %al /* return value in %eax */=0A= =0A= popl %esi=0A= popl %ebp=0A= =0A= ret=0A= =0A= /*=0A= * int grub_biosdisk_rw_standard (int ah, int drive, int coff, int = hoff,=0A= * int soff, int nsec, int segment)=0A= *=0A= * Call standard and old INT13 (int 13 %ah=3DAH) for DRIVE. Read/write=0A= * NSEC sectors from COFF/HOFF/SOFF into SEGMENT. If an error occurs,=0A= * return non-zero, otherwise zero.=0A= */=0A= =0A= FUNCTION(grub_biosdisk_rw_standard)=0A= pushl %ebp=0A= movl %esp, %ebp=0A= =0A= pushl %ebx=0A= pushl %edi=0A= pushl %esi=0A= =0A= /* set up CHS information */=0A= movw 0x8(%ebp), %ax=0A= movw 0xC(%ebp), %dx=0A= movw 0x10(%ebp), %cx=0A= =0A= /* set %ch to low eight bits of cylinder */=0A= xchgb %cl, %ch=0A= /* set bits 6-7 of %cl to high two bits of cylinder */=0A= shlb $6, %cl=0A= /* set bits 0-5 of %cl to sector */=0A= addb 0x18(%ebp), %cl=0A= /* set %dh to head */=0A= movb 0x14(%ebp), %dh=0A= /* set %ah to AH */=0A= movb %al, %ah=0A= /* set %al to NSEC */=0A= movb 0x1c(%ebp), %al=0A= /* save %ax in %di */=0A= movw %ax, %di=0A= /* save SEGMENT in %bx */=0A= movw 0x20(%ebp), %bx=0A= =0A= /* enter real mode */=0A= call prot_to_real=0A= =0A= .code16=0A= movw %bx, %es=0A= xorw %bx, %bx=0A= movw $3, %si /* attempt at least three times */=0A= =0A= 1: =0A= movw %di, %ax=0A= int $0x13 /* do the operation */=0A= jnc 2f /* check if successful */=0A= =0A= movb %ah, %bl /* save return value */=0A= /* if fail, reset the disk system */=0A= xorw %ax, %ax=0A= int $0x13=0A= =0A= decw %si=0A= cmpw $0, %si=0A= je 2f=0A= xorb %bl, %bl=0A= jmp 1b /* retry */=0A= 2: =0A= /* back to protected mode */=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %bl, %al /* return value in %eax */=0A= =0A= popl %esi=0A= popl %edi=0A= popl %ebx=0A= popl %ebp=0A= =0A= ret $(4 * 4)=0A= =0A= =0A= /*=0A= * int grub_biosdisk_check_int13_extensions (int drive)=0A= *=0A= * Check if LBA is supported for DRIVE. If it is supported, then return=0A= * the major version of extensions, otherwise zero.=0A= */=0A= =0A= FUNCTION(grub_biosdisk_check_int13_extensions)=0A= movw 0x4(%esp), %ax=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= /* drive */=0A= movb %al, %dl=0A= /* enter real mode */=0A= call prot_to_real=0A= =0A= .code16=0A= movb $0x41, %ah=0A= movw $0x55aa, %bx=0A= int $0x13 /* do the operation */=0A= =0A= /* check the result */=0A= jc 1f=0A= cmpw $0xaa55, %bx=0A= jne 1f=0A= =0A= movb %ah, %bl /* save the major version into %bl */=0A= =0A= /* check if AH=3D0x42 is supported */=0A= andw $1, %cx=0A= jnz 2f=0A= =0A= 1:=0A= xorb %bl, %bl=0A= 2:=0A= /* back to protected mode */=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %bl, %al /* return value in %eax */=0A= =0A= popl %ebx=0A= popl %ebp=0A= =0A= ret=0A= =0A= =0A= /*=0A= * int grub_biosdisk_get_diskinfo_int13_extensions (int drive, void = *drp)=0A= *=0A= * Return the geometry of DRIVE in a drive parameters, DRP. If an error=0A= * occurs, then return non-zero, otherwise zero.=0A= */=0A= =0A= FUNCTION(grub_biosdisk_get_diskinfo_int13_extensions)=0A= movw 0x4(%esp), %ax=0A= mov 0x8(%esp), %edx=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %esi=0A= =0A= /* compute the address of drive parameters */=0A= movw %dx, %si=0A= xorw %dx, %dx=0A= shrl $4, %edx=0A= movw %dx, %bx /* save the segment into %bx */=0A= /* drive */=0A= movb %al, %dl=0A= /* enter real mode */=0A= call prot_to_real=0A= =0A= .code16=0A= movb $0x48, %ah=0A= movw %bx, %ds=0A= int $0x13 /* do the operation */=0A= movb %ah, %bl /* save return value in %bl */=0A= /* clear the data segment */=0A= xorw %ax, %ax=0A= movw %ax, %ds=0A= /* back to protected mode */=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %bl, %al /* return value in %eax */=0A= =0A= popl %esi=0A= popl %ebx=0A= popl %ebp=0A= =0A= ret=0A= =0A= =0A= /*=0A= * int grub_biosdisk_get_diskinfo_standard (int drive,=0A= * unsigned long *cylinders, =0A= * unsigned long *heads,=0A= * unsigned long *sectors)=0A= *=0A= * Return the geometry of DRIVE in CYLINDERS, HEADS and SECTORS. If an=0A= * error occurs, then return non-zero, otherwise zero.=0A= */=0A= =0A= FUNCTION(grub_biosdisk_get_diskinfo_standard)=0A= movw 0x4(%esp), %ax=0A= mov 0x8(%esp), %edx=0A= mov 0xC(%esp), %ecx=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %edi=0A= =0A= /* push CYLINDERS */=0A= pushl %edx=0A= /* push HEADS */=0A= pushl %ecx=0A= /* SECTORS is on the stack */=0A= =0A= /* drive */=0A= movb %al, %dl=0A= /* enter real mode */=0A= call prot_to_real=0A= =0A= .code16=0A= movb $0x8, %ah=0A= int $0x13 /* do the operation */=0A= /* check if successful */=0A= testb %ah, %ah=0A= jnz 1f=0A= /* bogus BIOSes may not return an error number */=0A= testb $0x3f, %cl /* 0 sectors means no disk */=0A= jnz 1f /* if non-zero, then succeed */=0A= /* XXX 0x60 is one of the unused error numbers */=0A= movb $0x60, %ah=0A= 1:=0A= movb %ah, %bl /* save return value in %bl */=0A= /* back to protected mode */=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= /* pop HEADS */=0A= popl %edi=0A= movb %dh, %al=0A= incl %eax /* the number of heads is counted from zero */=0A= movl %eax, (%edi)=0A= =0A= /* pop CYLINDERS */=0A= popl %edi=0A= movb %ch, %al=0A= movb %cl, %ah=0A= shrb $6, %ah /* the number of cylinders is counted from zero */=0A= incl %eax=0A= movl %eax, (%edi)=0A= =0A= /* SECTORS */=0A= movl 0x1c(%esp), %edi=0A= andb $0x3f, %cl=0A= movzbl %cl, %eax=0A= movl %eax, (%edi)=0A= =0A= xorl %eax, %eax=0A= movb %bl, %al /* return value in %eax */=0A= =0A= popl %edi=0A= popl %ebx=0A= popl %ebp=0A= =0A= ret $4=0A= =0A= =0A= /*=0A= * int grub_biosdisk_get_num_floppies (void)=0A= */=0A= FUNCTION(grub_biosdisk_get_num_floppies)=0A= pushl %ebp=0A= =0A= xorl %edx, %edx=0A= call prot_to_real=0A= =0A= .code16=0A= /* reset the disk system first */=0A= int $0x13=0A= 1:=0A= stc=0A= =0A= /* call GET DISK TYPE */=0A= movb $0x15, %ah=0A= int $0x13=0A= =0A= jc 2f=0A= =0A= /* check if this drive exists */ =0A= testb $0x3, %ah=0A= jz 2f=0A= =0A= incb %dl=0A= cmpb $2, %dl=0A= jne 1b=0A= 2:=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movl %edx, %eax=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= *=0A= * grub_get_memsize(i) : return the memory size in KB. i =3D=3D 0 for = conventional=0A= * memory, i =3D=3D 1 for extended memory=0A= * BIOS call "INT 12H" to get conventional memory size=0A= * BIOS call "INT 15H, AH=3D88H" to get extended memory size=0A= * Both have the return value in AX.=0A= *=0A= */=0A= =0A= FUNCTION(grub_get_memsize)=0A= mov 0x4(%esp), %eax=0A= pushl %ebp=0A= =0A= movl %eax, %edx=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= testl %edx, %edx=0A= jnz xext=0A= =0A= int $0x12=0A= jmp xdone=0A= =0A= xext:=0A= movb $0x88, %ah=0A= int $0x15=0A= =0A= xdone:=0A= movw %ax, %dx=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= =0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= *=0A= * grub_get_eisa_mmap() : return packed EISA memory map, lower 16 bits = is=0A= * memory between 1M and 16M in 1K parts, upper 16 bits is=0A= * memory above 16M in 64K parts. If error, return zero.=0A= * BIOS call "INT 15H, AH=3DE801H" to get EISA memory map,=0A= * AX =3D memory between 1M and 16M in 1K parts.=0A= * BX =3D memory above 16M in 64K parts.=0A= *=0A= */=0A= =0A= FUNCTION(grub_get_eisa_mmap)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= movw $0xe801, %ax=0A= int $0x15=0A= =0A= shll $16, %ebx=0A= movw %ax, %bx=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= cmpb $0x86, %bh=0A= je xnoteisa=0A= =0A= movl %ebx, %eax=0A= =0A= xnoteisa:=0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= *=0A= * grub_get_mmap_entry(addr, cont) : address and old continuation value = (zero to=0A= * start), for the Query System Address Map BIOS call.=0A= *=0A= * Sets the first 4-byte int value of "addr" to the size returned by=0A= * the call. If the call fails, sets it to zero.=0A= *=0A= * Returns: new (non-zero) continuation value, 0 if done.=0A= */=0A= =0A= FUNCTION(grub_get_mmap_entry)=0A= mov 0x4(%esp), %eax=0A= mov 0x8(%esp), %edx=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %edi=0A= pushl %esi=0A= =0A= /* push ADDR */=0A= pushl %eax=0A= =0A= /* place address (+4) in ES:DI */=0A= addl $4, %eax=0A= movl %eax, %edi=0A= andl $0xf, %edi=0A= shrl $4, %eax=0A= movl %eax, %esi=0A= =0A= /* set continuation value */=0A= movl %edx, %ebx=0A= =0A= /* set default maximum buffer size */=0A= movl $0x14, %ecx=0A= =0A= /* set EDX to 'SMAP' */=0A= movl $0x534d4150, %edx=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= movw %si, %es=0A= movl $0xe820, %eax=0A= int $0x15=0A= =0A= DATA32 jc xnosmap=0A= =0A= cmpl $0x534d4150, %eax=0A= jne xnosmap=0A= =0A= cmpl $0x14, %ecx=0A= jl xnosmap=0A= =0A= cmpl $0x400, %ecx=0A= jg xnosmap=0A= =0A= jmp xsmap=0A= =0A= xnosmap:=0A= xorl %ecx, %ecx=0A= =0A= xsmap:=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= /* write length of buffer (zero if error) into ADDR */=0A= popl %eax=0A= movl %ecx, (%eax)=0A= =0A= /* set return value to continuation */=0A= movl %ebx, %eax=0A= =0A= popl %esi=0A= popl %edi=0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * void grub_console_real_putchar (int c)=0A= *=0A= * Put the character C on the console. Because GRUB wants to write a=0A= * character with an attribute, this implementation is a bit tricky.=0A= * If C is a control character (CR, LF, BEL, BS), use INT 10, AH =3D 0Eh=0A= * (TELETYPE OUTPUT). Otherwise, save the original position, put a space,=0A= * save the current position, restore the original position, write the=0A= * character and the attribute, and restore the current position.=0A= *=0A= * The reason why this is so complicated is that there is no easy way to=0A= * get the height of the screen, and the TELETYPE OUPUT BIOS call doesn't=0A= * support setting a background attribute.=0A= */=0A= FUNCTION(grub_console_real_putchar)=0A= mov 0x4(%esp), %eax=0A= movl %eax, %edx=0A= pusha=0A= movb EXT_C(grub_console_cur_color), %bl=0A= =0A= call prot_to_real=0A= .code16=0A= movb %dl, %al=0A= xorb %bh, %bh=0A= =0A= /* use teletype output if control character */=0A= cmpb $0x7, %al=0A= je 1f=0A= cmpb $0x8, %al=0A= je 1f=0A= cmpb $0xa, %al=0A= je 1f=0A= cmpb $0xd, %al=0A= je 1f=0A= =0A= /* save the character and the attribute on the stack */=0A= pushw %ax=0A= pushw %bx=0A= =0A= /* get the current position */=0A= movb $0x3, %ah=0A= int $0x10=0A= =0A= /* check the column with the width */=0A= cmpb $79, %dl=0A= jl 2f=0A= =0A= /* print CR and LF, if next write will exceed the width */ =0A= movw $0x0e0d, %ax=0A= int $0x10=0A= movb $0x0a, %al=0A= int $0x10=0A= =0A= /* get the current position */=0A= movb $0x3, %ah=0A= int $0x10=0A= =0A= 2: =0A= /* restore the character and the attribute */=0A= popw %bx=0A= popw %ax=0A= =0A= /* write the character with the attribute */=0A= movb $0x9, %ah=0A= movw $1, %cx=0A= int $0x10=0A= =0A= /* move the cursor forward */=0A= incb %dl=0A= movb $0x2, %ah=0A= int $0x10=0A= =0A= jmp 3f=0A= =0A= 1: movw $1, %bx=0A= movb $0xe, %ah=0A= int $0x10=0A= =0A= 3: DATA32 call real_to_prot=0A= .code32=0A= =0A= popa=0A= ret=0A= =0A= =0A= /*=0A= * int grub_console_getkey (void)=0A= * BIOS call "INT 16H Function 00H" to read character from keyboard=0A= * Call with %ah =3D 0x0=0A= * Return: %ah =3D keyboard scan code=0A= * %al =3D ASCII character=0A= */=0A= =0A= /* this table is used in translate_keycode below */=0A= translation_table:=0A= .word GRUB_CONSOLE_KEY_LEFT, 2=0A= .word GRUB_CONSOLE_KEY_RIGHT, 6=0A= .word GRUB_CONSOLE_KEY_UP, 16=0A= .word GRUB_CONSOLE_KEY_DOWN, 14=0A= .word GRUB_CONSOLE_KEY_HOME, 1=0A= .word GRUB_CONSOLE_KEY_END, 5=0A= .word GRUB_CONSOLE_KEY_DC, 4=0A= .word GRUB_CONSOLE_KEY_BACKSPACE, 8=0A= .word GRUB_CONSOLE_KEY_PPAGE, 7=0A= .word GRUB_CONSOLE_KEY_NPAGE, 3=0A= .word 0=0A= =0A= /*=0A= * translate_keycode translates the key code %dx to an ascii code.=0A= */=0A= .code16=0A= =0A= translate_keycode:=0A= pushw %bx=0A= pushw %si=0A= =0A= movw $ABS(translation_table), %si=0A= =0A= 1: lodsw=0A= /* check if this is the end */=0A= testw %ax, %ax=0A= jz 2f=0A= /* load the ascii code into %ax */=0A= movw %ax, %bx=0A= lodsw=0A= /* check if this matches the key code */=0A= cmpw %bx, %dx=0A= jne 1b=0A= /* translate %dx, if successful */=0A= movw %ax, %dx=0A= =0A= 2: popw %si=0A= popw %bx=0A= ret=0A= =0A= .code32=0A= =0A= FUNCTION(grub_console_getkey)=0A= pushl %ebp=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= int $0x16=0A= =0A= movw %ax, %dx /* real_to_prot uses %eax */=0A= call translate_keycode=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= =0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * int grub_console_checkkey (void)=0A= * if there is a character pending, return it; otherwise return -1=0A= * BIOS call "INT 16H Function 01H" to check whether a character is = pending=0A= * Call with %ah =3D 0x1=0A= * Return:=0A= * If key waiting to be input:=0A= * %ah =3D keyboard scan code=0A= * %al =3D ASCII character=0A= * Zero flag =3D clear=0A= * else=0A= * Zero flag =3D set=0A= */=0A= FUNCTION(grub_console_checkkey)=0A= pushl %ebp=0A= xorl %edx, %edx=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= movb $0x1, %ah=0A= int $0x16=0A= =0A= jz notpending=0A= =0A= movw %ax, %dx=0A= DATA32 jmp pending=0A= =0A= notpending:=0A= decl %edx=0A= =0A= pending:=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movl %edx, %eax=0A= =0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * grub_uint16_t grub_console_getxy (void)=0A= * BIOS call "INT 10H Function 03h" to get cursor position=0A= * Call with %ah =3D 0x03=0A= * %bh =3D page=0A= * Returns %ch =3D starting scan line=0A= * %cl =3D ending scan line=0A= * %dh =3D row (0 is top)=0A= * %dl =3D column (0 is left)=0A= */=0A= =0A= =0A= FUNCTION(grub_console_getxy)=0A= pushl %ebp=0A= pushl %ebx /* save EBX */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= xorb %bh, %bh /* set page to 0 */=0A= movb $0x3, %ah=0A= int $0x10 /* get cursor position */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %dl, %ah=0A= movb %dh, %al=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * void grub_console_gotoxy(grub_uint8_t x, grub_uint8_t y)=0A= * BIOS call "INT 10H Function 02h" to set cursor position=0A= * Call with %ah =3D 0x02=0A= * %bh =3D page=0A= * %dh =3D row (0 is top)=0A= * %dl =3D column (0 is left)=0A= */=0A= =0A= =0A= FUNCTION(grub_console_gotoxy)=0A= mov 0x4(%esp), %eax=0A= mov 0x8(%esp), %edx=0A= pushl %ebp=0A= pushl %ebx /* save EBX */=0A= =0A= movb %dl, %dh /* %dh =3D y */=0A= movb %al, %dl /* %dl =3D x */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= xorb %bh, %bh /* set page to 0 */=0A= movb $0x2, %ah=0A= int $0x10 /* set cursor position */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * void grub_console_cls (void)=0A= * BIOS call "INT 10H Function 09h" to write character and attribute=0A= * Call with %ah =3D 0x09=0A= * %al =3D (character)=0A= * %bh =3D (page number)=0A= * %bl =3D (attribute)=0A= * %cx =3D (number of times)=0A= */=0A= =0A= FUNCTION(grub_console_cls)=0A= pushl %ebp=0A= pushl %ebx /* save EBX */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= /* move the cursor to the beginning */=0A= movb $0x02, %ah=0A= xorb %bh, %bh=0A= xorw %dx, %dx=0A= int $0x10=0A= =0A= /* write spaces to the entire screen */=0A= movw $0x0920, %ax=0A= movw $0x07, %bx=0A= movw $(80 * 25), %cx=0A= int $0x10=0A= =0A= /* move back the cursor */=0A= movb $0x02, %ah=0A= int $0x10=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * void grub_console_setcursor (int on)=0A= * BIOS call "INT 10H Function 01h" to set cursor type=0A= * Call with %ah =3D 0x01=0A= * %ch =3D cursor starting scanline=0A= * %cl =3D cursor ending scanline=0A= */=0A= =0A= console_cursor_state:=0A= .byte 1=0A= console_cursor_shape:=0A= .word 0=0A= =0A= FUNCTION(grub_console_setcursor)=0A= mov 0x4(%esp), %eax=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= /* push ON */=0A= pushl %eax=0A= =0A= /* check if the standard cursor shape has already been saved */=0A= movw console_cursor_shape, %ax=0A= testw %ax, %ax=0A= jne 1f=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movb $0x03, %ah=0A= xorb %bh, %bh=0A= int $0x10=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %cx, console_cursor_shape=0A= 1:=0A= /* set %cx to the designated cursor shape */=0A= movw $0x2000, %cx=0A= popl %eax=0A= testl %eax, %eax=0A= jz 2f=0A= movw console_cursor_shape, %cx=0A= 2: =0A= call prot_to_real=0A= .code16=0A= =0A= movb $0x1, %ah=0A= int $0x10 =0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_getrtsecs()=0A= * if a seconds value can be read, read it and return it (BCD),=0A= * otherwise return 0xFF=0A= * BIOS call "INT 1AH Function 02H" to check whether a character is = pending=0A= * Call with %ah =3D 0x2=0A= * Return:=0A= * If RT Clock can give correct values=0A= * %ch =3D hour (BCD)=0A= * %cl =3D minutes (BCD)=0A= * %dh =3D seconds (BCD)=0A= * %dl =3D daylight savings time (00h std, 01h = daylight)=0A= * Carry flag =3D clear=0A= * else=0A= * Carry flag =3D set=0A= * (this indicates that the clock is updating, or=0A= * that it isn't running)=0A= */=0A= FUNCTION(grub_getrtsecs)=0A= pushl %ebp=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= clc=0A= movb $0x2, %ah=0A= int $0x1a=0A= =0A= DATA32 jnc gottime=0A= movb $0xff, %dh=0A= =0A= gottime:=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %dh, %al=0A= =0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * grub_get_rtc()=0A= * return the real time in ticks, of which there are about=0A= * 18-20 per second=0A= */=0A= FUNCTION(grub_get_rtc)=0A= pushl %ebp=0A= =0A= call prot_to_real /* enter real mode */=0A= .code16=0A= =0A= /* %ax is already zero */=0A= int $0x1a=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movl %ecx, %eax=0A= shll $16, %eax=0A= movw %dx, %ax=0A= =0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * unsigned char grub_vga_set_mode (unsigned char mode)=0A= */=0A= FUNCTION(grub_vga_set_mode)=0A= mov 0x4(%esp), %eax=0A= pushl %ebp=0A= pushl %ebx=0A= movl %eax, %ecx=0A= =0A= call prot_to_real=0A= .code16=0A= /* get current mode */=0A= xorw %bx, %bx=0A= movb $0x0f, %ah=0A= int $0x10=0A= movb %al, %dl=0A= =0A= /* set the new mode */=0A= movb %cl, %al=0A= xorb %ah, %ah=0A= int $0x10=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movb %dl, %al=0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= =0A= /*=0A= * unsigned char *grub_vga_get_font (void)=0A= */=0A= FUNCTION(grub_vga_get_font)=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= call prot_to_real=0A= .code16=0A= movw $0x1130, %ax=0A= movb $0x06, %bh=0A= int $0x10=0A= movw %es, %bx=0A= movw %bp, %dx=0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movzwl %bx, %ecx=0A= shll $4, %ecx=0A= movw %dx, %ax=0A= addl %ecx, %eax=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_controller_info (struct = grub_vbe_info_block *controller_info)=0A= *=0A= * Register allocations for parameters:=0A= * %eax *controller_info=0A= */=0A= FUNCTION(grub_vbe_get_controller_info)=0A= mov 0x4(%esp), %eax=0A= pushl %ebp=0A= pushl %edi=0A= =0A= movw %ax, %di /* Store *controller_info to %edx:%di. */=0A= xorw %ax, %ax=0A= shrl $4, %eax=0A= mov %eax, %edx /* prot_to_real destroys %eax. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= pushw %es=0A= =0A= movw %dx, %es /* *controller_info is now on %es:%di. */=0A= movw $0x4f00, %ax=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= popw %es=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movl %edx, %eax=0A= andl $0x0FFFF, %eax /* Return value in %eax. */=0A= =0A= popl %edi=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_mode_info (grub_uint32_t mode,=0A= * struct grub_vbe_mode_info_block *mode_info)=0A= *=0A= * Register allocations for parameters:=0A= * %eax mode=0A= * %edx *mode_info=0A= */=0A= FUNCTION(grub_vbe_get_mode_info)=0A= mov 0x4(%esp), %eax=0A= mov 0x8(%esp), %edx=0A= pushl %ebp=0A= pushl %edi=0A= =0A= movl %eax, %ecx /* Store mode number to %ecx. */=0A= =0A= movw %dx, %di /* Store *mode_info to %edx:%di. */=0A= xorw %dx, %dx=0A= shrl $4, %edx=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= pushw %es=0A= =0A= movw %dx, %es /* *mode_info is now on %es:%di. */=0A= movw $0x4f01, %ax=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= popw %es=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movl %edx, %eax=0A= andl $0x0FFFF, %eax /* Return value in %eax. */=0A= =0A= popl %edi=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_set_mode (grub_uint32_t mode,=0A= * struct grub_vbe_crtc_info_block *crtc_info)=0A= *=0A= * Register allocations for parameters:=0A= * %eax mode=0A= * %edx *crtc_info=0A= */=0A= FUNCTION(grub_vbe_set_mode)=0A= mov 0x4(%esp), %eax=0A= mov 0x8(%esp), %edx=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= movl %eax, %ebx /* Store mode in %ebx. */=0A= =0A= movw %dx, %di /* Store *crtc_info to %edx:%di. */=0A= xorw %dx, %dx=0A= shrl $4, %edx=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= pushw %es=0A= =0A= movw %dx, %es /* *crtc_info is now on %es:%di. */=0A= =0A= movw $0x4f02, %ax=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= popw %es=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_mode (grub_uint32_t *mode)=0A= *=0A= * Register allocations for parameters:=0A= * %eax *mode=0A= */=0A= FUNCTION(grub_vbe_get_mode)=0A= mov 0x4(%esp), %eax=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %eax /* Push *mode to stack. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f03, %ax=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %edi /* Pops *mode from stack to %edi. */=0A= andl $0xFFFF, %ebx=0A= movl %ebx, (%edi)=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_set_memory_window (grub_uint32_t window,=0A= * grub_uint32_t position);=0A= *=0A= * Register allocations for parameters:=0A= * %eax window=0A= * %edx position=0A= */=0A= FUNCTION(grub_vbe_set_memory_window)=0A= mov 0x4(%esp), %eax=0A= mov 0x8(%esp), %edx=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= movl %eax, %ebx=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f05, %ax=0A= andw $0x00ff, %bx /* BL =3D window, BH =3D 0, Set memory window. */=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_memory_window (grub_uint32_t window,=0A= * grub_uint32_t *position);=0A= *=0A= * Register allocations for parameters:=0A= * %eax window=0A= * %edx *position=0A= */=0A= FUNCTION(grub_vbe_get_memory_window)=0A= mov 0x4(%esp), %eax=0A= mov 0x8(%esp), %edx=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %edx /* Push *position to stack. */=0A= =0A= movl %eax, %ebx /* Store window in %ebx. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f05, %ax=0A= andw $0x00ff, %bx /* BL =3D window. */=0A= orw $0x0100, %bx /* BH =3D 1, Get memory window. */=0A= int $0x10=0A= =0A= movw %ax, %bx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %edi /* pops *position from stack to %edi. */=0A= andl $0xFFFF, %edx=0A= movl %edx, (%edi) /* Return position to caller. */=0A= =0A= movw %bx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_set_scanline_length (grub_uint32_t length)=0A= *=0A= * Register allocations for parameters:=0A= * %eax length=0A= */=0A= FUNCTION(grub_vbe_set_scanline_length)=0A= mov 0x4(%esp), %eax=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= movl %eax, %ecx /* Store length in %ecx. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f06, %ax=0A= movw $0x0002, %bx /* BL =3D 2, Set Scan Line in Bytes. */=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_scanline_length (grub_uint32_t *length)=0A= *=0A= * Register allocations for parameters:=0A= * %eax *length=0A= */=0A= FUNCTION(grub_vbe_get_scanline_length)=0A= mov 0x4(%esp), %eax=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %edx /* Push *length to stack. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f06, %ax=0A= movw $0x0001, %bx /* BL =3D 1, Get Scan Line Length (in bytes). */=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %edi /* Pops *length from stack to %edi. */=0A= andl $0xFFFF, %ebx=0A= movl %ebx, (%edi) /* Return length to caller. */=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_set_display_start (grub_uint32_t x,=0A= * grub_uint32_t y)=0A= *=0A= * Register allocations for parameters:=0A= * %eax x=0A= * %edx y=0A= */=0A= FUNCTION(grub_vbe_set_display_start)=0A= mov 0x4(%esp), %eax=0A= mov 0x8(%esp), %edx=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= movl %eax, %ecx /* Store x in %ecx. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f07, %ax=0A= movw $0x0080, %bx /* BL =3D 80h, Set Display Start =0A= during Vertical Retrace. */=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_get_display_start (grub_uint32_t *x,=0A= * grub_uint32_t *y)=0A= *=0A= * Register allocations for parameters:=0A= * %eax *x=0A= * %edx *y=0A= */=0A= FUNCTION(grub_vbe_get_display_start)=0A= mov 0x4(%esp), %eax=0A= mov 0x8(%esp), %edx=0A= pushl %ebp=0A= pushl %ebx=0A= pushl %eax /* Push *x to stack. */=0A= pushl %edx /* Push *y to stack. */=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= movw $0x4f07, %ax=0A= movw $0x0001, %bx /* BL =3D 1, Get Display Start. */=0A= int $0x10=0A= =0A= movw %ax, %bx /* real_to_prot destroys %eax. */=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= popl %edi /* Pops *y from stack to %edi. */=0A= andl $0xFFFF, %edx=0A= movl %edx, (%edi) /* Return y-position to caller. */=0A= =0A= popl %edi /* Pops *x from stack to %edi. */=0A= andl $0xFFFF, %ecx=0A= movl %ecx, (%edi) /* Return x-position to caller. */=0A= =0A= movw %bx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= =0A= /*=0A= * grub_vbe_status_t grub_vbe_set_palette_data (grub_uint32_t = color_count,=0A= * grub_uint32_t start_index,=0A= * struct grub_vbe_palette_data *palette_data)=0A= *=0A= * Register allocations for parameters:=0A= * %eax color_count=0A= * %edx start_index=0A= * %ecx *palette_data=0A= */=0A= FUNCTION(grub_vbe_set_palette_data)=0A= mov 0x4(%esp), %eax=0A= mov 0x8(%esp), %edx=0A= mov 0xC(%esp), %ecx=0A= pushl %ebp=0A= pushl %ebx=0A= =0A= movl %eax, %ebx /* Store color_count in %ebx. */=0A= =0A= movw %cx, %di /* Store *palette_data to %ecx:%di. */=0A= xorw %cx, %cx=0A= shrl $4, %ecx=0A= =0A= call prot_to_real=0A= .code16=0A= =0A= pushw %es=0A= =0A= movw %cx, %es /* *palette_data is now on %es:%di. */=0A= movw %bx, %cx /* color_count is now on %cx. */=0A= =0A= movw $0x4f09, %ax=0A= xorw %bx, %bx /* BL =3D 0, Set Palette Data. */=0A= int $0x10=0A= =0A= movw %ax, %dx /* real_to_prot destroys %eax. */=0A= =0A= popw %es=0A= =0A= DATA32 call real_to_prot=0A= .code32=0A= =0A= movw %dx, %ax=0A= andl $0xFFFF, %eax /* Return value in %eax. */=0A= =0A= popl %ebx=0A= popl %ebp=0A= ret=0A= ------=_NextPart_000_0001_01C6733D.65178F80--