Support LOCALBOOT (ISOLINUX-style) in SYSLINUX/EXTLINUX
[syslinux.git] / loadhigh.inc
blobb2e87f236d3f27c040b4ce90fc6e3827ea07c7c4
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
4 ;;
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., 53 Temple Place Ste 330,
8 ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
9 ;;   (at your option) any later version; incorporated herein by reference.
11 ;; -----------------------------------------------------------------------
14 ;; loadhigh.inc
16 ;; Load a file into high memory
19                 section .text
22 ; load_high:    loads (the remainder of) a file into high memory.
23 ;               This routine prints dots for each 64K transferred, and
24 ;               calls abort_check periodically.
26 ;               The xfer_buf_seg is used as a bounce buffer.
28 ;               The input address (EDI) should be dword aligned, and the final
29 ;               stretch is padded with zeroes if necessary.
31 ; Inputs:       SI  = file handle/cluster pointer
32 ;               EDI = target address in high memory
33 ;               EAX = size of remaining file in bytes
34 ;               DX  = zero-padding mask (e.g. 0003h for pad to dword)
35 ;               BX  = subroutine to call at the top of each loop
36 ;                     (to print status and check for abort)
38 ; Outputs:      SI  = file handle/cluster pointer
39 ;               EDI = first untouched address (not including padding)
41 load_high:
42                 push es                         ; <AAA> ES
44                 mov cx,xfer_buf_seg
45                 mov es,cx
47 .read_loop:
48                 and si,si                       ; If SI == 0 then we have end of file
49                 jz .eof
50                 call bx
51                 push bx                         ; <AA> Pausebird function
53                 push eax                        ; <A> Total bytes to transfer
54                 cmp eax,(1 << 16)               ; Max 64K in one transfer
55                 jna .size_ok
56                 mov eax,(1 << 16)
57 .size_ok:
58                 push eax                        ; <B> Bytes transferred this chunk
59                 add eax,SECTOR_SIZE-1
60                 shr eax,SECTOR_SHIFT            ; Convert to sectors
62                 ; Now (e)ax contains the number of sectors to get
63                 push edi                        ; <C> Target buffer
64                 mov cx,ax
65                 xor bx,bx                       ; ES:0
66                 call getfssec                   ; Load the data into xfer_buf_seg
67                 pop edi                         ; <C> Target buffer
68                 pop ecx                         ; <B> Byte count this round
69                 push ecx                        ; <B> Byte count this round
70                 push edi                        ; <C> Target buffer
71 .fix_slop:
72                 test cx,dx
73                 jz .noslop
74                 ; The last dword fractional - pad with zeroes
75                 ; Zero-padding is critical for multi-file initramfs.
76                 mov byte [es:ecx],0
77                 inc ecx
78                 jmp short .fix_slop
79 .noslop:
80                 push esi                        ; <D> File handle/cluster pointer
81                 mov esi,(xfer_buf_seg << 4)     ; Source address
82                 call bcopy                      ; Copy to high memory
83                 pop esi                         ; <D> File handle/cluster pointer
84                 pop edi                         ; <C> Target buffer
85                 pop ecx                         ; <B> Byte count this round
86                 pop eax                         ; <A> Total bytes to transfer
87                 add edi,ecx
88                 sub eax,ecx
89                 pop bx                          ; <AA> Pausebird function
90                 jnz .read_loop                  ; More to read...
93 .eof:
94                 pop es                          ; <AAA> ES
95                 ret
97 dot_pause:
98                 push ax
99                 mov al,'.'
100                 call writechr
101                 pop ax
102                 jmp abort_check                 ; Handles the return