GRUB using extended registers in stage1?

Programming, for all ages and all languages.
Post Reply
Synon
Member
Member
Posts: 169
Joined: Sun Sep 06, 2009 3:54 am
Location: Brighton, United Kingdom

GRUB using extended registers in stage1?

Post by Synon »

I'm writing a bootloader for fun, and I was looking at GRUB's source code for help when I read this code:

Code: Select all

lba_mode:
	/* save the total number of sectors */
	movl	0x10(%si), %ecx

	/* set %si to the disk address packet */
	movw	$ABS(disk_address_packet), %si

	/* set the mode to non-zero */
	movb	$1, -1(%si)
	
	movl	ABS(stage2_sector), %ebx

	/* the size and the reserved byte */
	movw	$0x0010, (%si)

	/* the blocks */
	movw	$1, 2(%si)
	
	/* the absolute address (low 32 bits) */
	movl	%ebx, 8(%si)

	/* the segment of buffer address */
	movw	$STAGE1_BUFFERSEG, 6(%si)

	xorl	%eax, %eax
	movw	%ax, 4(%si)
	movl	%eax, 12(%si)
How can GRUB use extended registers in its stage1? Surely stage1 is not running in protected mode? I don't think you can use extended registers in unreal mode, either, can you? I don't see any code for changing mode, anyway...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: GRUB using extended registers in stage1?

Post by Combuster »

It was and has always been possible to use 32-bit registers in any mode. The assembler will insert the correct opcodes where needed, as long as it knows what mode to assemble for.

A few of the important real-mode bios calls use 32-bit registers too: try asking for available memory.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Synon
Member
Member
Posts: 169
Joined: Sun Sep 06, 2009 3:54 am
Location: Brighton, United Kingdom

Re: GRUB using extended registers in stage1?

Post by Synon »

Combuster wrote:It was and has always been possible to use 32-bit registers in any mode. The assembler will insert the correct opcodes where needed, as long as it knows what mode to assemble for.
Oh, right, thanks. I keep putting it off, but eventually I will read an assembly tutorial. The knowledge I have now has all come from experimentation, searching for tutorials on specific features (it was a while before I bothered to read about segmentation), instruction references and Ralph Brown's Interrupt List. I think I'll read through a tutorial now, before I do something else that's stupid.
Combuster wrote:A few of the important real-mode bios calls use 32-bit registers too: try asking for available memory.
I'll do that once I get stage2 loaded.
Post Reply