Add gPXE into the source tree; build unified image
[syslinux.git] / loadhigh.inc
blob630414833dd5f40c2e4e1cf337e2ccb0aa41eaa3
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 ;               Assumes CS == DS.
30 ;               The input address (EDI) should be dword aligned, and the final
31 ;               stretch is padded with zeroes if necessary.
33 ; Inputs:       SI  = file handle/cluster pointer
34 ;               EDI = target address in high memory
35 ;               EAX = maximum number of bytes to load
36 ;               DX  = zero-padding mask (e.g. 0003h for pad to dword)
37 ;               BX  = subroutine to call at the top of each loop
38 ;                     (to print status and check for abort)
39 ;               MyHighMemSize = maximum load address
41 ; Outputs:      SI  = file handle/cluster pointer
42 ;               EBX = first untouched address (not including padding)
43 ;               EDI = first untouched address (including padding)
44 ;               CF  = reached EOF
46 load_high:
47                 push es                         ; <AAA> ES
49                 mov cx,xfer_buf_seg
50                 mov es,cx
51                 mov [PauseBird],bx
53 .read_loop:
54                 and si,si                       ; If SI == 0 then we have end of file
55                 jz .eof
56                 call [PauseBird]
58                 push eax                        ; <A> Total bytes to transfer
59                 cmp eax,(1 << 16)               ; Max 64K in one transfer
60                 jna .size_ok
61                 mov eax,(1 << 16)
62 .size_ok:
63                 push eax                        ; <B> Bytes transferred this chunk
64                 add eax,SECTOR_SIZE-1
65                 shr eax,SECTOR_SHIFT            ; Convert to sectors
67                 ; Now (e)ax contains the number of sectors to get
68                 push edi                        ; <C> Target buffer
69                 mov cx,ax
70                 xor bx,bx                       ; ES:0
71                 call getfssec                   ; Load the data into xfer_buf_seg
72                 pop edi                         ; <C> Target buffer
73                 pushf                           ; <C> EOF status
74                 lea ebx,[edi+ecx]               ; End of data
75 .fix_slop:
76                 test cx,dx
77                 jz .noslop
78                 ; The last dword fractional - pad with zeroes
79                 ; Zero-padding is critical for multi-file initramfs.
80                 mov byte [es:ecx],0
81                 inc cx
82                 jmp short .fix_slop
83 .noslop:
84                 lea eax,[edi+ecx]
85                 cmp eax,[MyHighMemSize]
86                 ja .overflow
88                 push esi                        ; <D> File handle/cluster pointer
89                 mov esi,(xfer_buf_seg << 4)     ; Source address
90                 call bcopy                      ; Copy to high memory
91                 pop esi                         ; <D> File handle/cluster pointer
92                 popf                            ; <C> EOF status
93                 pop ecx                         ; <B> Byte count this round
94                 pop eax                         ; <A> Total bytes to transfer
95                 jc .eof
96                 sub eax,ecx
97                 jnz .read_loop                  ; More to read... (if ZF=1 then CF=0)
98 .eof:
99                 pop es                          ; <AAA> ES
100                 ret
102 .overflow:      mov si,err_nohighmem
103                 jmp abort_load
105 dot_pause:
106                 push ax
107                 mov al,'.'
108                 call writechr
109                 pop ax
110                 jmp abort_check                 ; Handles the return
112                 section .data
113 err_nohighmem   db CR, LF
114                 db 'Not enough memory to load specified image.', CR, LF, 0
116                 section .bss
117                 alignb 2
118 PauseBird       resw 1
120                 section .text