MBR doesn't work on motherboard with UEFI

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
IOne
Posts: 3
Joined: Wed Mar 18, 2015 8:02 am

MBR doesn't work on motherboard with UEFI

Post by IOne »

My MBR doesn't work with the motherboard with UEFI (Intel DH77EB), it nothing prints, but with the old motherboard with BIOS it works.
For example, it's demo MBR does not print's anything with Intel DH77EB.
UEFI Boot is disabled.

What difference between "real" BIOS and BIOS emulation in UEFI?

P.S. I am booting from USB flash, I am write my MBR to flash by Linux dd command.
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: MBR doesn't work on motherboard with UEFI

Post by Octocontrabass »

That demo code is broken. I'm surprised it works on any motherboards.

Find a real MBR that properly sets all segment registers before relying on their values. You'll see that the UEFI BIOS emulation works just as well as a real BIOS.
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

Re: MBR doesn't work on motherboard with UEFI

Post by Muazzam »

Have a look at MBR from my OS:
mbr.asm
(3.59 KiB) Downloaded 63 times
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: MBR doesn't work on motherboard with UEFI

Post by Octocontrabass »

muazzam wrote:Have a look at MBR from my OS:
Your MBR sets up the stack somewhere insane and expects things to work.
IOne
Posts: 3
Joined: Wed Mar 18, 2015 8:02 am

Re: MBR doesn't work on motherboard with UEFI

Post by IOne »

Octocontrabass wrote:That demo code is broken. I'm surprised it works on any motherboards.

Find a real MBR that properly sets all segment registers before relying on their values. You'll see that the UEFI BIOS emulation works just as well as a real BIOS.
It's the beginning of the my MBR (BOOTSTACK=0xFFF0, BOOTSEG=0x1000).
It sets segment registers.

Code: Select all

        .set SIGNATURE,0xaa55
        .set LOAD,0x7c00        # Load address
        .code16
        .text
        .globl start            # Entry point
start:
         jmp    main
        .= start +3 
oem :.ascii "oc2k 210"
secsiz  :.word  0
clsiz   :.byte  0
ressecs :.word  0
fatcnt  :.byte  0
rootsiz :.word  0
totsec  :.word  0
media   :.byte  0
fatsiz  :.word  0
trksecs :.word  0
headcnt :.byte  0   #?????????????????
hidnsec :.word  0
# нестандартные расширения 
        .= start +52
fsec:   .word 0        # первый сектор                  52
        .word 0        #                    
spc :   .word 0        # spt*headcnt                    56
        .word 0        #                        
spt :   .word 0        #                                60
        .word 0        #                        
fsec0:  .word 0        # первый сектор                  64
        .word 0        #                    
drive:  .byte 0        # номер диска например 0x80      68
head:   .byte 0        #                                69
cyl :   .word 0        #                                70
nsec:   .word 0        #                                72
        .word 0        #                                74
startmsg:.ascii "Start \0"  #        80
okmsg:.ascii "Ok \r\n\0"  #        
main:   
    
    movw    $BOOTSEG, %ax           #  ax=0x1000 
    movw    %ax, %es                # es=ax=0x1000 set up %es, (where we will load boot2 to)
    movw    %ax, %ss                # ss=0x1000  
    movw    $BOOTSTACK-64, %sp      # sp=0xfff0-64
    movw    $(LOAD/16),%ax        
    movw    %ax,%ds                 #  data  ds=0x7c0

    movw    $startmsg, %si
    call    message
It's work with motherboards with BIOS, but don't print anything with UEFI. What's wrong?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: MBR doesn't work on motherboard with UEFI

Post by Candy »

You're assuming CS to be 0. You're not guaranteed that - only that CS:IP is 0x7C00 in total.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: MBR doesn't work on motherboard with UEFI

Post by Brendan »

Hi,
IOne wrote:

Code: Select all

main:   
    
    movw    $BOOTSEG, %ax           #  ax=0x1000 
    movw    %ax, %es                # es=ax=0x1000 set up %es, (where we will load boot2 to)
    movw    %ax, %ss                # ss=0x1000  
    movw    $BOOTSTACK-64, %sp      # sp=0xfff0-64
    movw    $(LOAD/16),%ax        
    movw    %ax,%ds                 #  data  ds=0x7c0

    movw    $startmsg, %si
    call    message
It's work with motherboards with BIOS, but don't print anything with UEFI. What's wrong?
What's wrong is that it calls a routine that doesn't exist, and then (if the missing routine returns) nothing stops the CPU from executing garbage that was left in RAM. ;)


Cheers,

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.
IOne
Posts: 3
Joined: Wed Mar 18, 2015 8:02 am

Re: MBR doesn't work on motherboard with UEFI

Post by IOne »

Brendan wrote:
What's wrong is that it calls a routine that doesn't exist, and then (if the missing routine returns) nothing stops the CPU from executing garbage that was left in RAM. ;)


Cheers,

Brendan
Sorry, I am forgot to show "message" source code:

Code: Select all

/*
 * message: write the error message in %ds:%esi to console
 */
message:
    /*
     * Use BIOS "int 10H Function 0Eh" to write character in teletype mode
     *  %ah = 0xe   %al = character
     *  %bh = page  %bl = foreground color (graphics modes)
     */

        push    %ax
        push    %bx
        mov $0x0001, %bx
        cld

nextb:
        lodsb           # load a byte into %al 
        cmpb    $0x0, %al
        je  done
        movb    $0xe, %ah
        int $0x10       # display a byte 
        jmp nextb
done:
        pop %bx
        pop %ax
        ret
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: MBR doesn't work on motherboard with UEFI

Post by Candy »

What happens after "ret" ?
Post Reply