Developing the bootloader assembly

I already made part of my OS in Assembly, but now I want to create my own bootloader for it, instead of using GRUB. When I developed my test OS in Assembly, I remember that I load it as follows:

org 0x7c00 bits 16 ; OS Kernel Here times 510 - ($-$$) db 0 dw 0xAA55 

I already know it. Now I want to use this and execute a β€œreal” OS, which will be a * .bin file recorded in the 2nd sector of the floppy disk. Then i want to know something

  • How can I make a bootloader in Assembly to execute what will be run in the second sector of the floppy disk?
  • Do I need to add anything to the assembly source that will be placed in the second sector of the floppy disk?
+4
source share
1 answer

You use int 0x13 to load into the required number of sectors and move to the location of the new code. In the second step, you have nothing to do, but you must make sure that you set the DS for valid values ​​for wherever you download the code.

An example from my small OS archive:

  /* BIOS loads the sectors into es:bx */ pushw $STAGE1_WORKSEG popw %es movw $STAGE1_OFFSET, %bx read_stage1: /* Try to read in a few sectors */ movb $0x2, %cl /* Sector */ movb $0x0, %ch /* Cylinder */ movb $0x0, %dh /* Head */ movb $0x0, %dl /* Drive */ movb $0x2, %ah /* BIOS read function */ /* How many sectors to load */ movb $STAGE1_SIZE, %al int $0x13 jnc read_stage1_done /* Reset drive */ xorw %ax, %ax int $0x13 jmp read_stage1 read_stage1_done: /* Perform a long jump into stage1 */ ljmp $STAGE1_WORKSEG, $STAGE1_OFFSET call halt halt: /* * Function: halt * Synopsis: Sends the processor into a permanent halted status * Notes: * The only way out of this is to manually reboot */ hlt /* Halt the processor */ jmp halt 

This is in GAS format, so you'll want to reverse the order of the operands because it looks like you are using NASM from the times statement. Variable names must be clear.

If you are developing a hosting OS, then http://forum.osdev.org/ is a good place to get support from others doing the same. This is a little more specialized than stackoverflow, and many OS things can be quite esoteric.

+4
source

Source: https://habr.com/ru/post/1299154/


All Articles