My bootloader appears to relocate itself and run correctly, is anyone able (and willing, thanks in advance ) to verify that the code does what I think it does?
https://github.com/schilds/Serial-BootL ... loader.asm
It should relocate some of itself (the main loop and some functions) to just before where it used to be (i.e. just before the boot sector, 0x7c00). The function of the relocated main loop should be to read and parse bytes from the serial port, store them to the (now free to overwrite) boot sector and then execute them.
Basically I've written the relocation as if it were position independent (i.e. works with just a simple copy), but I'm not actually sure that it is. How do I know whether the assembler is creating absolute or relative jumps/calls?
relocating bootloader
- Combuster
- 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: relocating bootloader
You can always disassemble the output and check the jump opcodes to see if they are absolute (FF) or relative (EB/E9). Most assemblers default to the latter though because it's always the shorter encoding.
Re: relocating bootloader
Hi,
For example:
Cheers,
Brendan
You forgot to make sure that the "direction" flag is clear. If the BIOS left it set, then the copy will work backwards and copy the wrong thing.schilds wrote:My bootloader appears to relocate itself and run correctly, is anyone able (and willing, thanks in advance ) to verify that the code does what I think it does?
https://github.com/schilds/Serial-BootL ... loader.asm
It's much easier to do the reverse. For example, use "org 0x7A00" at the start so that after relocation everything is as the assembler expects, and do the relocation first so that you don't need to care about "position independent" for almost all of your code.schilds wrote:Basically I've written the relocation as if it were position independent (i.e. works with just a simple copy), but I'm not actually sure that it is. How do I know whether the assembler is creating absolute or relative jumps/calls?
For example:
Code: Select all
org 0x7A00
bits 16
start:
jmp .initialise
;Put a BPB here, if necessary
.initialise:
xor ax,ax
mov es,ax
mov ds,ax
cli
mov ss,ax
mov sp,0x7A00
sti
cld
mov cx,512/2
mov si,0x7C00
mov di,0x7A00
rep movsw
jmp 0x0000:main
main:
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: relocating bootloader
Oooh, neat.
Thanks guys.
Thanks guys.