why doesn't my loop work in 64 bit nasm for efi

48 Views Asked by At

I'm writing a basic bootloader for my laptop, which uses uefi, I have got booting from the usb working, printing working, exits working, everything but a simple loop.

This the the loop:

mov r10, 0x05
.loop1:

        ;Print a string
        mov rcx, [CONOUT]
        lea rdx, [done]
        call [CONOUT_PRINT_STRING]

        ;Wait a bit so that the user can read the string
        mov rcx, 100000
        call [BOOT_SERVICES_STALL]

    ;Compare the values to determine whether we should look again
    dec r10
    cmp r10, qword 0
    jne .loop1

The calls are just basic efi system table calls, nothing special. I've tried with all the registers, yet they all seem to not work, I've also tried pushing the value of r10 before any calls, and popping it before the decrement, but that just stops it printing anything. I would assume a stack alignment issue, but I've already got an apparently working fix for that (as seen below), so i have no idea what to do now.

sub rsp, 6*8+8 ; Copied from Charles AP's implementation, fix stack alignment issue (Thanks Charles AP!)

Sorry for rambling and thanks in advance :)

0

There are 0 best solutions below