2N/A/* -*-Asm-*- */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2008,2009 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/symbol.h>
2N/A#include <grub/machine/boot.h>
2N/A#include <grub/machine/kernel.h>
2N/A#include <multiboot.h>
2N/A
2N/A .file "cdboot.S"
2N/A
2N/A#define CODE_ADDR 0x6000
2N/A#define DATA_ADDR ((GRUB_BOOT_MACHINE_KERNEL_ADDR) + 0x200)
2N/A
2N/A#define CDSEC_SHIFT 11
2N/A#define CDBLK_LENG 16
2N/A
2N/A .text
2N/A
2N/A .code16
2N/A
2N/A .globl start, _start
2N/A
2N/Astart:
2N/A_start:
2N/A call LOCAL(next)
2N/A
2N/ALOCAL(next):
2N/A jmp 1f
2N/A
2N/A . = start + 8
2N/A
2N/Abi_pvd:
2N/A .long 0 /* LBA of primary volume descriptor. */
2N/Abi_file:
2N/A .long 0 /* LBA of boot file. */
2N/Abi_length:
2N/A .long 0 /* Length of boot file. */
2N/Abi_csum:
2N/A .long 0 /* Checksum of boot file */
2N/Abi_reserved:
2N/A .space (10*4) /* Reserved */
2N/A
2N/A1:
2N/A popw %bx
2N/A
2N/A /* Boot from CDROM. */
2N/A
2N/A xorw %ax, %ax
2N/A movw %ax, %ss
2N/A movw $(CODE_ADDR), %sp
2N/A movw %ax, %ds
2N/A movw %ax, %es
2N/A
2N/A movw $(0x7C00 + err_noboot_msg - start), %si
2N/A movl %cs: bi_length - LOCAL(next)(%bx), %ecx
2N/A orl %ecx, %ecx
2N/A jz LOCAL(fail)
2N/A
2N/A addl $((1 << CDSEC_SHIFT) - 1), %ecx
2N/A shrl $CDSEC_SHIFT, %ecx
2N/A
2N/A movl %cs: bi_file - LOCAL(next)(%bx), %esi
2N/A
2N/A call LOCAL(read_cdrom)
2N/A
2N/A ljmp $(DATA_ADDR >> 4), $0
2N/A
2N/A/*
2N/A * Parameters:
2N/A * esi: start sector
2N/A * ecx: number of sectors
2N/A */
2N/ALOCAL(read_cdrom):
2N/A xorl %eax, %eax
2N/A
2N/A /* Number of blocks to read. */
2N/A pushw $CDBLK_LENG
2N/A
2N/A /* Block number. */
2N/A pushl %eax
2N/A pushl %esi
2N/A
2N/A /* Buffer address. */
2N/A pushw $((DATA_ADDR - 0x400)>> 4)
2N/A pushl %eax
2N/A pushw $0x10
2N/A
2N/A xorl %edi, %edi
2N/A movw %sp, %si
2N/A
2N/A1:
2N/A movw 0x10(%si), %di
2N/A cmpl %ecx, %edi
2N/A jbe 2f
2N/A movl %ecx, %edi
2N/A
2N/A2:
2N/A mov %di, 2(%si)
2N/A
2N/A pushl %ecx
2N/A
2N/A movb $0x42, %ah
2N/A int $0x13
2N/A
2N/A jnc 3f
2N/A
2N/A movb $0x42, %ah /* Try again. */
2N/A int $0x13
2N/A
2N/A jnc 3f
2N/A
2N/A2:
2N/A shrw $1, %di /* Reduce transfer size. */
2N/A jz LOCAL(cdrom_fail)
2N/A movw %di, 0x10(%si)
2N/A movw %di, 2(%si)
2N/A movb $0x42, %ah
2N/A int $0x13
2N/A jc 2b
2N/A
2N/A3:
2N/A
2N/A movw %di, %ax
2N/A shlw $(CDSEC_SHIFT - 4), %ax
2N/A addw %ax, 6(%si)
2N/A addl %edi, 8(%si)
2N/A
2N/A popl %ecx
2N/A subl %edi, %ecx
2N/A jnz 1b
2N/A
2N/A addw $0x12, %sp
2N/A ret
2N/A
2N/ALOCAL(cdrom_fail):
2N/A movw $(0x7C00 + err_cdfail_msg - start), %si
2N/A
2N/ALOCAL(fail):
2N/A movb $0x0e, %ah
2N/A xorw %bx, %bx
2N/A1:
2N/A lodsb (%si), %al
2N/A int $0x10
2N/A cmpb $0, %al
2N/A jne 1b
2N/A1: jmp 1b
2N/A
2N/Aerr_noboot_msg:
2N/A .ascii "no boot info\0"
2N/A
2N/Aerr_cdfail_msg:
2N/A .ascii "cdrom read fails\0"
2N/A
2N/A . = start + 0x1FF
2N/A
2N/A .byte 0