Assemble via ELF, to enable future linking
[syslinux.git] / localboot.inc
blob288d390a31f2bfa4f1a5017a1dd43cb2cf0f8795
1 ; -----------------------------------------------------------------------
2 ;   
3 ;   Copyright 1999-2008 H. Peter Anvin - All Rights Reserved
5 ;   This program is free software; you can redistribute it and/or modify
6 ;   it under the terms of the GNU General Public License as published by
7 ;   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 ;   Boston MA 02110-1301, USA; either version 2 of the License, or
9 ;   (at your option) any later version; incorporated herein by reference.
11 ; -----------------------------------------------------------------------
14 ; localboot.inc
16 ; Boot from a local disk, or invoke INT 18h.
19 %if HAS_LOCALBOOT
22 ; Boot a specified local disk.  AX specifies the BIOS disk number; or
23 ; -1 in case we should execute INT 18h ("next device.")
25                 section .text
27 local_boot:
28                 call vgaclearmode
29                 lss sp,[cs:Stack]               ; Restore stack pointer
30                 xor dx,dx
31                 mov ds,dx
32                 mov es,dx
33                 mov fs,dx
34                 mov gs,dx
35                 mov si,localboot_msg
36                 call writestr
37                 cmp ax,-1
38                 je .int18
40                 ; Load boot sector from the specified BIOS device and jump to it.
41                 mov dl,al
42                 xor dh,dh
43                 push dx
44                 xor ax,ax                       ; Reset drive
45                 int 13h
46                 mov ax,0201h                    ; Read one sector
47                 mov cx,0001h                    ; C/H/S = 0/0/1 (first sector)
48                 mov bx,trackbuf
49                 mov bp,retry_count
50 .again:
51                 pusha
52                 int 13h
53                 popa
54                 jnc .ok
55                 dec bp
56                 jnz .again
57                 jmp kaboom                      ; Failure...    
58 .ok:
59                 pop dx
60                 cli                             ; Abandon hope, ye who enter here
61                 mov si,trackbuf
62                 mov di,07C00h
63                 mov cx,512                      ; Probably overkill, but should be safe
64                 rep movsd
65                 mov ss,cx                       ; SS <- 0
66                 mov sp,7C00h
67                 jmp 0:07C00h                    ; Jump to new boot sector
69 .int18:
70                 int 18h                         ; Hope this does the right thing...
71                 jmp kaboom                      ; If we returned, oh boy...
73                 section .data
74 localboot_msg   db 'Booting from local disk...', CR, LF, 0
76                 section .text
78 %endif ; HAS_LOCALBOOT