b7caec47c6c0e62b6adaad21361fdfbe8e17f260
[profile/ivi/syslinux.git] / loadhigh.inc
1 ;; $Id$
2 ;; -----------------------------------------------------------------------
3 ;;   
4 ;;   Copyright 1994-2002 H. Peter Anvin - All Rights Reserved
5 ;;
6 ;;   This program is free software; you can redistribute it and/or modify
7 ;;   it under the terms of the GNU General Public License as published by
8 ;;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
10 ;;   (at your option) any later version; incorporated herein by reference.
11 ;;
12 ;; -----------------------------------------------------------------------
13
14 ;;
15 ;; loadhigh.inc
16 ;; 
17 ;; Load a file into high memory
18 ;;
19
20 ;
21 ; load_high:    loads (the remainder of) a file into high memory.
22 ;               This routine prints dots for each 64K transferred, and
23 ;               calls abort_check periodically.
24
25 ;               The xfer_buf_seg is used as a bounce buffer.
26 ;
27 ;               The input address (EDI) should be dword aligned, and the final
28 ;               dword written is padded with zeroes if necessary.
29 ;
30 ; Inputs:       SI  = file handle/cluster pointer
31 ;               EDI = target address in high memory
32 ;               EAX = size of remaining file in bytes
33 ;
34 ; Outputs:      SI  = file handle/cluster pointer
35 ;               EDI = first untouched address (not including padding)
36 ;
37 load_high:
38                 push es
39
40                 mov bx,xfer_buf_seg
41                 mov es,bx
42
43 .read_loop:
44                 and si,si                       ; If SI == 0 then we have end of file
45                 jz .eof
46                 push si
47                 mov si,dot_msg
48                 call cwritestr
49                 pop si
50                 call abort_check
51
52                 push eax                        ; <A> Total bytes to transfer
53                 cmp eax,(1 << 16)               ; Max 64K in one transfer
54                 jna .size_ok
55                 mov eax,(1 << 16)
56 .size_ok:
57                 push eax                        ; <B> Bytes transferred this chunk
58                 add eax,SECTOR_SIZE-1
59                 shr eax,SECTOR_SHIFT            ; Convert to sectors
60
61                 ; Now (e)ax contains the number of sectors to get
62                 push edi                        ; <C> Target buffer
63                 mov cx,ax
64                 xor bx,bx                       ; ES:0
65                 call getfssec                   ; Load the data into xfer_buf_seg
66                 pop edi                         ; <C> Target buffer
67                 pop ecx                         ; <B> Byte count this round
68                 push ecx                        ; <B> Byte count this round 
69                 push edi                        ; <C> Target buffer
70 .fix_slop:
71                 test cl,3
72                 jz .noslop
73                 ; The last dword fractional - pad with zeroes
74                 ; Zero-padding is critical for multi-file initramfs.
75                 mov byte [es:ecx],0
76                 inc ecx
77                 jmp short .fix_slop
78 .noslop:
79                 push esi                        ; <D> File handle/cluster pointer
80                 mov esi,(xfer_buf_seg << 4)     ; Source address
81                 call bcopy                      ; Copy to high memory
82                 pop esi                         ; <D> File handle/cluster pointer
83                 pop edi                         ; <C> Target buffer
84                 pop ecx                         ; <B> Byte count this round
85                 pop eax                         ; <A> Total bytes to transfer
86                 add edi,ecx
87                 sub eax,ecx
88                 jnz .read_loop                  ; More to read...
89                 
90 .eof:
91                 pop es
92                 ret
93