Please read the assembly language
provided before reading this section. The file bootblock_examples.s also
contains several x86 assembly language examples.
Loading a segment:offset
The project will require you to load a number into a segment register to
setup the stack and data segments. The code segment register (CS) cannot be loaded
directly, but instead only indirectly through a JMP type instruction. When
loading a value into the stack segment register (SS), interrupts are disabled
for the next instruction, thus allowing you to set the stack pointer (SP). As
an example of setting up the segment registers for data, consider the following
string copy:
# Setup the registers - see chapter 3 of Intel ISA reference volume 2
movw DATA_SEGMENT, %ax
movw %ax, %ds
movw OTHER_DATA_SEGMENT, %ax
movw %ax, %es
movw STRING_FROM_ADDRESS, %si
movw STRING_TO_ADDRESS, %di
# Move a byte from one string to the other - implictly DS:SI to ES:DI
movsb
# The values in %si and %di are automatically incremented/decremented based on
the DF flag.
For your design review you are required to implement routines that print to the screen. During booting, you can write directly to the screen by writing to the display RAM which is mapped starting at 0xb800:0000. Each location on the screen requires two bytes---one to specify the attribute (Use 0x07) and the second for the character itself. The text screen is 80x25 characters. So, to write to i-th row and j-th column, you write the 2 bytes starting at offset ((i-1)*80+(j-1))*2.
So, the following code sequence writes the character 'K' (ascii
0x4b) to the top left corner of the screen.
movw $0xb800,%bx
movw %bx,%es
movw $0x074b,%es:(0x0)
This code sequence is very useful for debugging.