2007-12-15 10:42:17 +00:00
|
|
|
/* -*-Asm-*- */
|
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-03 22:05:07 +00:00
|
|
|
* Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
|
2007-12-15 10:42:17 +00:00
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-07-13 01:55:15 +00:00
|
|
|
#include <config.h>
|
2009-08-14 04:12:22 +00:00
|
|
|
#include <grub/symbol.h>
|
2007-12-15 10:42:17 +00:00
|
|
|
#include <grub/machine/boot.h>
|
|
|
|
#include <grub/machine/kernel.h>
|
2008-01-29 10:59:56 +00:00
|
|
|
#include <multiboot.h>
|
2007-12-15 10:42:17 +00:00
|
|
|
|
|
|
|
.file "lnxboot.S"
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2007-12-15 10:42:17 +00:00
|
|
|
#define CODE_ADDR 0x6000
|
2009-08-14 04:12:22 +00:00
|
|
|
#define CODE_SECTORS 1
|
2007-12-15 10:42:17 +00:00
|
|
|
#define DATA_ADDR ((GRUB_BOOT_MACHINE_KERNEL_ADDR) + 0x200)
|
|
|
|
|
|
|
|
#define BLCK_LENG 0x4000
|
|
|
|
|
|
|
|
.text
|
|
|
|
|
|
|
|
.code16
|
|
|
|
|
|
|
|
.globl start, _start
|
|
|
|
|
|
|
|
data_start:
|
2008-01-29 10:59:56 +00:00
|
|
|
xorl %ebp, %ebp
|
2009-08-14 04:12:22 +00:00
|
|
|
jmp LOCAL(linux_next)
|
2007-12-15 10:42:17 +00:00
|
|
|
|
|
|
|
. = data_start + 0x1F1
|
|
|
|
|
|
|
|
setup_sects:
|
2009-08-14 04:12:22 +00:00
|
|
|
.byte CODE_SECTORS
|
2007-12-15 10:42:17 +00:00
|
|
|
root_flags:
|
|
|
|
.word 0
|
|
|
|
syssize:
|
|
|
|
.word 0
|
|
|
|
swap_dev:
|
|
|
|
.word 0
|
|
|
|
ram_size:
|
|
|
|
.word 0
|
|
|
|
vid_mode:
|
|
|
|
.word 0
|
|
|
|
root_dev:
|
|
|
|
.word 0
|
|
|
|
boot_flag:
|
|
|
|
.word 0xAA55
|
|
|
|
|
|
|
|
start:
|
|
|
|
_start:
|
|
|
|
|
2009-08-14 04:12:22 +00:00
|
|
|
jmp LOCAL(linux_init)
|
2007-12-15 10:42:17 +00:00
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
.ascii "HdrS" /* Header signature. */
|
|
|
|
.word 0x0203 /* Header version number. */
|
2007-12-15 10:42:17 +00:00
|
|
|
|
|
|
|
realmode_swtch:
|
2008-01-29 10:59:56 +00:00
|
|
|
.word 0, 0 /* default_switch, SETUPSEG. */
|
2007-12-15 10:42:17 +00:00
|
|
|
start_sys_seg:
|
2008-01-29 10:59:56 +00:00
|
|
|
.word 0x1000 /* Obsolete. */
|
2007-12-15 10:42:17 +00:00
|
|
|
version_ptr:
|
2008-01-29 10:59:56 +00:00
|
|
|
.word 0 /* Version string ptr. */
|
2007-12-15 10:42:17 +00:00
|
|
|
type_of_loader:
|
2008-01-29 10:59:56 +00:00
|
|
|
.byte 0 /* Filled in by boot loader. */
|
2007-12-15 10:42:17 +00:00
|
|
|
loadflags:
|
2008-01-29 10:59:56 +00:00
|
|
|
.byte 1 /* Please load high. */
|
2007-12-15 10:42:17 +00:00
|
|
|
setup_move_size:
|
2008-01-29 10:59:56 +00:00
|
|
|
.word 0 /* Unused. */
|
2007-12-15 10:42:17 +00:00
|
|
|
code32_start:
|
2008-01-29 10:59:56 +00:00
|
|
|
.long 0x100000 /* 32-bit start address. */
|
2007-12-15 10:42:17 +00:00
|
|
|
ramdisk_image:
|
2008-01-29 10:59:56 +00:00
|
|
|
.long 0 /* Loaded ramdisk image address. */
|
2007-12-15 10:42:17 +00:00
|
|
|
ramdisk_size:
|
2008-01-29 10:59:56 +00:00
|
|
|
.long 0 /* Size of loaded ramdisk. */
|
2007-12-15 10:42:17 +00:00
|
|
|
bootsect_kludge:
|
|
|
|
.word 0, 0
|
|
|
|
heap_end_ptr:
|
|
|
|
.word 0
|
|
|
|
pad1:
|
|
|
|
.word 0
|
|
|
|
cmd_line_ptr:
|
2008-01-29 10:59:56 +00:00
|
|
|
.long 0 /* Command line. */
|
2007-12-15 10:42:17 +00:00
|
|
|
ramdisk_max:
|
2008-01-29 10:59:56 +00:00
|
|
|
.long 0xffffffff /* Highest allowed ramdisk address. */
|
2007-12-15 10:42:17 +00:00
|
|
|
|
|
|
|
gdt:
|
2008-01-29 10:59:56 +00:00
|
|
|
.long 0, 0, 0, 0 /* Must be zero. */
|
|
|
|
.word 0xffff /* 64 K segment size. */
|
2007-12-15 10:42:17 +00:00
|
|
|
gdt_src1:
|
2008-01-29 10:59:56 +00:00
|
|
|
.byte 0, 0 ,0 /* Low 24 bits of source address. */
|
|
|
|
.byte 0x93 /* Access rights. */
|
|
|
|
.byte 0 /* Extended access rights. */
|
2007-12-15 10:42:17 +00:00
|
|
|
gdt_src2:
|
2008-01-29 10:59:56 +00:00
|
|
|
.byte 0 /* High 8 bits of source address. */
|
|
|
|
.word 0xffff /* 64 K segment size. */
|
2007-12-15 10:42:17 +00:00
|
|
|
gdt_dst1:
|
2008-01-29 10:59:56 +00:00
|
|
|
.byte 0, 0, 0 /* Low 24 bits of target address. */
|
|
|
|
.byte 0x93 /* Access rights. */
|
|
|
|
.byte 0 /* Extended access rights. */
|
2007-12-15 10:42:17 +00:00
|
|
|
gdt_dst2:
|
2008-01-29 10:59:56 +00:00
|
|
|
.byte 0 /* High 8 bits of source address. */
|
|
|
|
.long 0, 0, 0, 0 /* More space for the BIOS. */
|
2007-12-15 10:42:17 +00:00
|
|
|
|
|
|
|
reg_edx:
|
2008-03-05 05:09:35 +00:00
|
|
|
.byte 0x80, 0, 0xFF, 0xFF
|
2007-12-15 10:42:17 +00:00
|
|
|
|
|
|
|
data_leng:
|
|
|
|
.long 0
|
|
|
|
|
2009-08-14 04:12:22 +00:00
|
|
|
LOCAL(linux_init):
|
2007-12-15 10:42:17 +00:00
|
|
|
movw %cs:(reg_edx - start), %dx
|
2008-01-29 10:59:56 +00:00
|
|
|
movl %cs:(code32_start - start), %ebp
|
2007-12-15 10:42:17 +00:00
|
|
|
|
2009-08-14 04:12:22 +00:00
|
|
|
LOCAL(linux_next):
|
2007-12-15 10:42:17 +00:00
|
|
|
|
2009-08-14 04:12:22 +00:00
|
|
|
call LOCAL(normalize)
|
2007-12-15 10:42:17 +00:00
|
|
|
|
2009-08-14 04:12:22 +00:00
|
|
|
LOCAL(normalize):
|
2007-12-15 10:42:17 +00:00
|
|
|
popw %bx
|
2009-08-14 04:12:22 +00:00
|
|
|
subw $(LOCAL(normalize) - start), %bx
|
2007-12-15 10:42:17 +00:00
|
|
|
shrw $4, %bx
|
|
|
|
movw %cs, %ax
|
|
|
|
addw %bx, %ax
|
|
|
|
pushw %ax
|
|
|
|
pushw $(real_code - start)
|
2008-01-29 10:59:56 +00:00
|
|
|
lret /* Jump to real_code. */
|
2007-12-15 10:42:17 +00:00
|
|
|
|
|
|
|
real_code:
|
|
|
|
subw $0x20, %ax
|
|
|
|
movw %ax, %ds
|
|
|
|
movw (setup_sects - data_start), %cx
|
|
|
|
shlw $7, %cx
|
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
/* Setup stack. */
|
2007-12-15 10:42:17 +00:00
|
|
|
|
|
|
|
xorw %si, %si
|
|
|
|
movw %si, %ss
|
|
|
|
movw $(CODE_ADDR), %sp
|
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
/* Move itself to 0:CODE_ADDR. */
|
2007-12-15 10:42:17 +00:00
|
|
|
|
|
|
|
cld
|
|
|
|
movw %cs, %ax
|
|
|
|
movw %ax, %ds
|
|
|
|
movw $(CODE_ADDR >> 4), %ax
|
|
|
|
movw %ax, %es
|
|
|
|
movw %si, %di
|
|
|
|
|
|
|
|
rep
|
|
|
|
movsl
|
|
|
|
ljmp $(CODE_ADDR >> 4), $(real_code_2 - start)
|
|
|
|
|
|
|
|
real_code_2:
|
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
xchgl %ebp, %esi
|
|
|
|
orl %esi, %esi
|
2007-12-15 10:42:17 +00:00
|
|
|
jnz 1f
|
2008-01-29 10:59:56 +00:00
|
|
|
movw %ds, %si
|
|
|
|
shll $4, %esi
|
|
|
|
addl %ebp, %esi
|
2007-12-15 10:42:17 +00:00
|
|
|
1:
|
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
pushw %es
|
|
|
|
popw %ds
|
|
|
|
|
2012-01-24 13:39:29 +00:00
|
|
|
movl $0x1000, %ecx
|
2011-03-11 11:51:10 +00:00
|
|
|
addl $0x200, %esi
|
2007-12-15 10:42:17 +00:00
|
|
|
movl $DATA_ADDR, %edi
|
|
|
|
|
2009-08-14 04:12:22 +00:00
|
|
|
call LOCAL(move_memory)
|
2007-12-15 10:42:17 +00:00
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
/* Check for multiboot signature. */
|
2012-01-24 13:39:29 +00:00
|
|
|
movl $DATA_ADDR, %edi
|
|
|
|
3:
|
|
|
|
movl %ss:(%edi), %eax
|
|
|
|
cmpl $MULTIBOOT_HEADER_MAGIC, %eax
|
2008-01-29 10:59:56 +00:00
|
|
|
jz 1f
|
2012-01-24 13:39:29 +00:00
|
|
|
addl $4, %edi
|
|
|
|
cmpl $(DATA_ADDR + 0x1000), %edi
|
|
|
|
jne 3b
|
2007-12-15 10:42:17 +00:00
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
movl (ramdisk_image - start), %esi
|
|
|
|
movl (ramdisk_size - start), %ecx
|
|
|
|
movl $(DATA_ADDR - 0x200), %edi
|
|
|
|
jmp 2f
|
|
|
|
|
|
|
|
1:
|
2007-12-15 10:42:17 +00:00
|
|
|
|
2012-01-24 13:39:29 +00:00
|
|
|
movl $(DATA_ADDR + 0x1000), %edi
|
2011-11-12 18:53:25 +00:00
|
|
|
movl %ss:(DATA_ADDR + GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE), %ecx
|
2012-01-29 22:20:02 +00:00
|
|
|
addl $GRUB_DECOMPRESSOR_I386_PC_MAX_DECOMPRESSOR_SIZE, %ecx
|
2007-12-15 10:42:17 +00:00
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
2:
|
2009-08-14 04:12:22 +00:00
|
|
|
call LOCAL(move_memory)
|
2007-12-15 10:42:17 +00:00
|
|
|
|
2013-09-23 12:31:42 +00:00
|
|
|
movb %dh, %ss:(DATA_ADDR + GRUB_DECOMPRESSOR_I386_PC_BOOT_DEVICE + 2)
|
|
|
|
movb (reg_edx + 2 - start), %dh
|
|
|
|
movb %dh, %ss:(DATA_ADDR + GRUB_DECOMPRESSOR_I386_PC_BOOT_DEVICE + 1)
|
|
|
|
|
2008-03-05 05:09:35 +00:00
|
|
|
movb $0xFF, %dh
|
|
|
|
|
2007-12-15 10:42:17 +00:00
|
|
|
ljmp $(DATA_ADDR >> 4), $0
|
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
/*
|
|
|
|
* Parameters:
|
|
|
|
* esi: source address
|
|
|
|
* edi: target address
|
|
|
|
* ecx: number of bytes
|
|
|
|
*/
|
|
|
|
|
2009-08-14 04:12:22 +00:00
|
|
|
LOCAL(move_memory):
|
2007-12-15 10:42:17 +00:00
|
|
|
incl %ecx
|
|
|
|
andb $0xFE, %cl
|
|
|
|
pushw %dx
|
|
|
|
1:
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
pushl %ecx
|
|
|
|
cmpl $BLCK_LENG, %ecx
|
|
|
|
jbe 2f
|
|
|
|
movl $BLCK_LENG, %ecx
|
|
|
|
2:
|
|
|
|
pushl %ecx
|
|
|
|
|
|
|
|
movl %esi, %eax
|
|
|
|
movw %si, (gdt_src1 - start)
|
|
|
|
shrl $16, %eax
|
|
|
|
movb %al, (gdt_src1 + 2 - start)
|
|
|
|
movb %ah, (gdt_src2 - start)
|
|
|
|
|
|
|
|
movl %edi, %eax
|
|
|
|
movw %di, (gdt_dst1 - start)
|
|
|
|
shrl $16, %eax
|
|
|
|
movb %al, (gdt_dst1 + 2 - start)
|
|
|
|
movb %ah, (gdt_dst2 - start)
|
|
|
|
|
|
|
|
movw $(gdt - start), %si
|
|
|
|
movb $0x87, %ah
|
|
|
|
shrw $1, %cx
|
|
|
|
|
|
|
|
int $0x15
|
|
|
|
|
|
|
|
popl %eax
|
|
|
|
popl %ecx
|
|
|
|
popl %edi
|
|
|
|
popl %esi
|
|
|
|
|
|
|
|
jnc 2f
|
|
|
|
movw $(err_int15_msg - start), %si
|
2009-08-14 04:12:22 +00:00
|
|
|
jmp LOCAL(fail)
|
2007-12-15 10:42:17 +00:00
|
|
|
|
|
|
|
2:
|
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
addl %eax, %esi
|
|
|
|
addl %eax, %edi
|
2007-12-15 10:42:17 +00:00
|
|
|
subl %eax, %ecx
|
|
|
|
jnz 1b
|
|
|
|
|
|
|
|
|
|
|
|
popw %dx
|
|
|
|
ret
|
|
|
|
|
2008-01-29 10:59:56 +00:00
|
|
|
/*
|
|
|
|
* Parameters:
|
|
|
|
* si: message
|
|
|
|
*/
|
|
|
|
|
2009-08-14 04:12:22 +00:00
|
|
|
LOCAL(fail):
|
2007-12-15 10:42:17 +00:00
|
|
|
movb $0x0e, %ah
|
|
|
|
xorw %bx, %bx
|
|
|
|
1:
|
|
|
|
lodsb (%si), %al
|
|
|
|
int $0x10
|
|
|
|
cmpb $0, %al
|
|
|
|
jne 1b
|
|
|
|
1: jmp 1b
|
|
|
|
|
|
|
|
err_int15_msg:
|
|
|
|
.ascii "move memory fails\0"
|
|
|
|
|
2009-08-14 04:12:22 +00:00
|
|
|
. = _start + CODE_SECTORS * 512
|