Yep,
here is my boot loader which successfully loads a 32 bit executable in binary format

,
but now I want to load an elf32-i386 from the second sector and I don't know how to make the entry.
Code: Select all
.section .rodata
bootmsg:
.asciz "loading..."
bootmsgend:
bootmsglen:
.word (bootmsgend - bootmsg)
errmsg:
.asciz "disk error!"
errmsgend:
errmsglen:
.word (errmsgend - errmsg)
gdt:
# Null Descriptor at 0x0
.word 0x0000
.word 0x0000
.byte 0x00
.byte 0x00
.byte 0x00
.byte 0x00
# Code Descriptor at 0x8
.word 0xffff
.word 0x0500
.byte 0x00
.byte 0x9a
.byte 0xcf
.byte 0x00
# Data Descriptor at 0x10
.word 0xffff
.word 0x0500
.byte 0x00
.byte 0x92
.byte 0xcf
.byte 0x00
gdt_end:
gdtptr:
.word (gdt_end - gdt - 1)
.long gdt
.section .text
.globl Start
Start:
.code16
SaveDriveNumber:
movb %dl, 0x7bff # Copy DL to memory 0x7bff
SetVideoMode:
clrb %ah # Set Video Mode
movb $0x03, %al # 3rd Mode -> 80x25
int $0x10 # Video Interrupt
ClearScreen:
movb $0x06, %ah # Clear Screen
clrb %al # Lines to scroll (0 = clear -> CX & DX)
movb $0x0f, %bh # Color Black White
clrw %cx # Upper Left Corner
movb $25, %dh # 25 Lines
movb $80, %dl # 80 Columns
int $0x10 # Video Interrupt
PrintBootMsg:
clrw %ax # Set AX to 0x0
movw %ax, %es # Set Extra Segment to 0x0
movw $bootmsg, %bp # Set base pointer to msg location
movb $0x13, %ah # Print String
movb $0x01, %al # Char only - Cursor moved
clrb %bh # Page Number
movb $0x09, %bl # Color Black Blue
movw bootmsglen, %cx # Message Length
movb $1, %dh # Row 1
movb $1, %dl # Column 1
int $0x10 # Video Interrupt
SetA20:
cli # Disable Interrupts
inb $0x92, %al # Enable A20 Gate
testb $0x2, %al # to access to more than
outb %al, $0x92 # 1 Mega Byte of memory
sti # Enable Interrupts
ResetDisk:
clrb %ah # Reset Disk
movb 0x7bff, %dl # Drive (from Memory Loacation)
int $0x13 # Disk Interrupt
jc PrintErrorMsg # If CF set jump to PrintErrorMsg
LoadFromDisk:
movw $0x0050, %ax # Set AX to 0x0050
movw %ax, %es # Set Extra Segment to 0x0050
movb $0x02, %ah # Read Disk Sectors
movb $0x01, %al # Read one sector only (512 bytes per sector)
clrw %bx # Offset 0 - Start of Segment
clrb %ch # Track 0
movb $0x02, %cl # Sector 2
clrb %dh # Head 0
movb 0x7bff, %dl # Drive (from Memory Loacation)
int $0x13 # Disk Interrupt
jc PrintErrorMsg # If CF set jump to PrintErrorMsg
cli # Disable Interrupts
LoadGDT:
lgdt gdtptr # Load Global Descriptor Table
EnterProtectedMode:
movl %cr0, %eax # Read from Control Register CR0
orl $1, %eax # Set Protected Mode Bit
movl %eax, %cr0 # Write to Control Register CR
SetupSelectors:
movw $0x0010, %ax # Selector 0x0010
movw %ax, %ds # Set Data Segment
movw %ax, %es # Set Extra Segment
movw %ax, %fs # Set Data2 Segment
movw %ax, %gs # Set Data3 Segment
movw %ax, %ss # Set Stack Segment
ljmp $0x8, $0x0 # Far Jump
PrintErrorMsg:
clrw %ax # Set AX to 0x0
movw %ax, %es # Set Extra Segment to 0x0
movw $errmsg, %bp # Set base pointer to msg location
movb $0x13, %ah # Print String
movb $0x01, %al # Char only - Cursor moved
clrb %bh # Page Number
movb $0x04, %bl # Color Black Red
movw errmsglen, %cx # Message Length
movb $3, %dh # Row 3
movb $1, %dl # Column 1
int $0x10 # Print Message
cli # Disable Interrupts
Hang:
hlt # Halt CPU
jmp Hang # Infinit loop if Halt does not work