Page 1 of 1

GRUB using extended registers in stage1?

Posted: Sun Dec 19, 2010 10:59 am
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...

Re: GRUB using extended registers in stage1?

Posted: Sun Dec 19, 2010 11:04 am
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.

Re: GRUB using extended registers in stage1?

Posted: Sun Dec 19, 2010 11:13 am
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.