More fixes to the extlinux installer; change back to writable types
[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                 section .text
21
22 ;
23 ; load_high:    loads (the remainder of) a file into high memory.
24 ;               This routine prints dots for each 64K transferred, and
25 ;               calls abort_check periodically.
26
27 ;               The xfer_buf_seg is used as a bounce buffer.
28 ;
29 ;               The input address (EDI) should be dword aligned, and the final
30 ;               dword written is padded with zeroes if necessary.
31 ;
32 ; Inputs:       SI  = file handle/cluster pointer
33 ;               EDI = target address in high memory
34 ;               EAX = size of remaining file in bytes
35 ;
36 ; Outputs:      SI  = file handle/cluster pointer
37 ;               EDI = first untouched address (not including padding)
38 ;
39 load_high:
40                 push es
41
42                 mov bx,xfer_buf_seg
43                 mov es,bx
44
45 .read_loop:
46                 and si,si                       ; If SI == 0 then we have end of file
47                 jz .eof
48                 push si
49                 mov si,dot_msg
50                 call cwritestr
51                 pop si
52                 call abort_check
53
54                 push eax                        ; <A> Total bytes to transfer
55                 cmp eax,(1 << 16)               ; Max 64K in one transfer
56                 jna .size_ok
57                 mov eax,(1 << 16)
58 .size_ok:
59                 push eax                        ; <B> Bytes transferred this chunk
60                 add eax,SECTOR_SIZE-1
61                 shr eax,SECTOR_SHIFT            ; Convert to sectors
62
63                 ; Now (e)ax contains the number of sectors to get
64                 push edi                        ; <C> Target buffer
65                 mov cx,ax
66                 xor bx,bx                       ; ES:0
67                 call getfssec                   ; Load the data into xfer_buf_seg
68                 pop edi                         ; <C> Target buffer
69                 pop ecx                         ; <B> Byte count this round
70                 push ecx                        ; <B> Byte count this round 
71                 push edi                        ; <C> Target buffer
72 .fix_slop:
73                 test cl,3
74                 jz .noslop
75                 ; The last dword fractional - pad with zeroes
76                 ; Zero-padding is critical for multi-file initramfs.
77                 mov byte [es:ecx],0
78                 inc ecx
79                 jmp short .fix_slop
80 .noslop:
81                 push esi                        ; <D> File handle/cluster pointer
82                 mov esi,(xfer_buf_seg << 4)     ; Source address
83                 call bcopy                      ; Copy to high memory
84                 pop esi                         ; <D> File handle/cluster pointer
85                 pop edi                         ; <C> Target buffer
86                 pop ecx                         ; <B> Byte count this round
87                 pop eax                         ; <A> Total bytes to transfer
88                 add edi,ecx
89                 sub eax,ecx
90                 jnz .read_loop                  ; More to read...
91                 
92 .eof:
93                 pop es
94                 ret
95