|
;; $Id: loadhigh.inc,v 1.1 2007-09-01 22:44:05 niro Exp $ |
|
1 |
;; ----------------------------------------------------------------------- |
;; ----------------------------------------------------------------------- |
2 |
;; |
;; |
3 |
;; Copyright 1994-2002 H. Peter Anvin - All Rights Reserved |
;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved |
4 |
|
;; Copyright 2009 Intel Corporation; author: H. Peter Anvin |
5 |
;; |
;; |
6 |
;; This program is free software; you can redistribute it and/or modify |
;; 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 |
;; it under the terms of the GNU General Public License as published by |
13 |
|
|
14 |
;; |
;; |
15 |
;; loadhigh.inc |
;; loadhigh.inc |
16 |
;; |
;; |
17 |
;; Load a file into high memory |
;; Load a file into high memory |
18 |
;; |
;; |
19 |
|
|
23 |
; load_high: loads (the remainder of) a file into high memory. |
; load_high: loads (the remainder of) a file into high memory. |
24 |
; This routine prints dots for each 64K transferred, and |
; This routine prints dots for each 64K transferred, and |
25 |
; calls abort_check periodically. |
; calls abort_check periodically. |
26 |
; |
; |
27 |
; The xfer_buf_seg is used as a bounce buffer. |
; The xfer_buf_seg is used as a bounce buffer. |
28 |
; |
; |
29 |
|
; Assumes CS == DS. |
30 |
|
; |
31 |
; The input address (EDI) should be dword aligned, and the final |
; The input address (EDI) should be dword aligned, and the final |
32 |
; stretch is padded with zeroes if necessary. |
; stretch is padded with zeroes if necessary. |
33 |
; |
; |
34 |
; Inputs: SI = file handle/cluster pointer |
; Inputs: SI = file handle/cluster pointer |
35 |
; EDI = target address in high memory |
; EDI = target address in high memory |
36 |
; EAX = size of remaining file in bytes |
; EAX = maximum number of bytes to load |
37 |
; DX = zero-padding mask (e.g. 0003h for pad to dword) |
; DX = zero-padding mask (e.g. 0003h for pad to dword) |
38 |
|
; BX = subroutine to call at the top of each loop |
39 |
|
; (to print status and check for abort) |
40 |
|
; MyHighMemSize = maximum load address |
41 |
; |
; |
42 |
; Outputs: SI = file handle/cluster pointer |
; Outputs: SI = file handle/cluster pointer |
43 |
; EDI = first untouched address (not including padding) |
; EBX = first untouched address (not including padding) |
44 |
|
; EDI = first untouched address (including padding) |
45 |
|
; CF = reached EOF |
46 |
; |
; |
47 |
load_high: |
load_high: |
48 |
push es |
push es ; <AAA> ES |
49 |
|
|
50 |
mov bx,xfer_buf_seg |
mov cx,xfer_buf_seg |
51 |
mov es,bx |
mov es,cx |
52 |
|
mov [PauseBird],bx |
53 |
|
|
54 |
.read_loop: |
.read_loop: |
55 |
and si,si ; If SI == 0 then we have end of file |
and si,si ; If SI == 0 then we have end of file |
56 |
jz .eof |
jz .eof |
57 |
push si |
call [PauseBird] |
|
mov si,dot_msg |
|
|
call cwritestr |
|
|
pop si |
|
|
call abort_check |
|
58 |
|
|
59 |
push eax ; <A> Total bytes to transfer |
push eax ; <A> Total bytes to transfer |
60 |
cmp eax,(1 << 16) ; Max 64K in one transfer |
cmp eax,(1 << 16) ; Max 64K in one transfer |
71 |
xor bx,bx ; ES:0 |
xor bx,bx ; ES:0 |
72 |
call getfssec ; Load the data into xfer_buf_seg |
call getfssec ; Load the data into xfer_buf_seg |
73 |
pop edi ; <C> Target buffer |
pop edi ; <C> Target buffer |
74 |
pop ecx ; <B> Byte count this round |
pushf ; <C> EOF status |
75 |
push ecx ; <B> Byte count this round |
lea ebx,[edi+ecx] ; End of data |
|
push edi ; <C> Target buffer |
|
76 |
.fix_slop: |
.fix_slop: |
77 |
test cx,dx |
test cx,dx |
78 |
jz .noslop |
jz .noslop |
79 |
; The last dword fractional - pad with zeroes |
; The last dword fractional - pad with zeroes |
80 |
; Zero-padding is critical for multi-file initramfs. |
; Zero-padding is critical for multi-file initramfs. |
81 |
mov byte [es:ecx],0 |
mov byte [es:ecx],0 |
82 |
inc ecx |
inc cx |
83 |
jmp short .fix_slop |
jmp short .fix_slop |
84 |
.noslop: |
.noslop: |
85 |
|
lea eax,[edi+ecx] |
86 |
|
cmp eax,[MyHighMemSize] |
87 |
|
ja .overflow |
88 |
|
|
89 |
push esi ; <D> File handle/cluster pointer |
push esi ; <D> File handle/cluster pointer |
90 |
mov esi,(xfer_buf_seg << 4) ; Source address |
mov esi,(xfer_buf_seg << 4) ; Source address |
91 |
call bcopy ; Copy to high memory |
call bcopy ; Copy to high memory |
92 |
pop esi ; <D> File handle/cluster pointer |
pop esi ; <D> File handle/cluster pointer |
93 |
pop edi ; <C> Target buffer |
popf ; <C> EOF status |
94 |
pop ecx ; <B> Byte count this round |
pop ecx ; <B> Byte count this round |
95 |
pop eax ; <A> Total bytes to transfer |
pop eax ; <A> Total bytes to transfer |
96 |
add edi,ecx |
jc .eof |
97 |
sub eax,ecx |
sub eax,ecx |
98 |
jnz .read_loop ; More to read... |
jnz .read_loop ; More to read... (if ZF=1 then CF=0) |
|
|
|
99 |
.eof: |
.eof: |
100 |
pop es |
pop es ; <AAA> ES |
101 |
ret |
ret |
102 |
|
|
103 |
|
.overflow: mov si,err_nohighmem |
104 |
|
jmp abort_load |
105 |
|
|
106 |
|
section .data |
107 |
|
err_nohighmem db CR, LF |
108 |
|
db 'Not enough memory to load specified image.', CR, LF, 0 |
109 |
|
|
110 |
|
section .bss |
111 |
|
alignb 2 |
112 |
|
PauseBird resw 1 |
113 |
|
|
114 |
|
section .text |