2 * -----------------------------------------------------------------------
4 * Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
5 * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
10 * Boston MA 02111-1307, USA; either version 2 of the License, or
11 * (at your option) any later version; incorporated herein by reference.
13 * ----------------------------------------------------------------------- */
18 * An alternate interface to getfssec.
20 * Inputs: SI = file handle/cluster pointer
21 * EDI = target address in high memory
22 * EAX = maximum number of bytes to load
23 * DX = zero-padding mask (e.g. 0003h for pad to dword)
24 * BX = 16-bit subroutine to call at the top of each loop
25 * (to print status and check for abort)
26 * EBP = maximum load address
28 * Outputs: SI = file handle/cluster pointer
29 * EBX = first untouched address (not including padding)
30 * EDI = first untouched address (including padding)
32 * OF = ran out of high memory
40 #define MAX_CHUNK (1 << 20) /* 1 MB */
42 void pm_load_high(com32sys_t
*regs
)
55 zero_mask
= regs
->edx
.w
[0];
56 buf
= (char *)regs
->edi
.l
;
57 limit
= (char *)(regs
->ebp
.l
& ~zero_mask
);
58 file
= handle_to_file(regs
->esi
.w
[0]);
61 regs
->eflags
.l
&= ~(EFLAGS_CF
|EFLAGS_OF
|EFLAGS_AF
|
62 EFLAGS_PF
|EFLAGS_ZF
|EFLAGS_SF
);
64 sector_mask
= SECTOR_SIZE(fs
) - 1;
70 if (buf
+ SECTOR_SIZE(fs
) > limit
) {
71 /* Can't fit even one more sector in... */
72 regs
->eflags
.l
|= EFLAGS_OF
;
79 call16((void (*)(void))(size_t)regs
->ebx
.w
[0], &zero_regs
, NULL
);
80 chunk
= min(chunk
, MAX_CHUNK
);
83 if (chunk
> (((char *)limit
- buf
) & ~sector_mask
))
84 chunk
= ((char *)limit
- buf
) & ~sector_mask
;
86 sectors
= (chunk
+ sector_mask
) >> SECTOR_SHIFT(fs
);
87 bytes_read
= fs
->fs_ops
->getfssec(file
, buf
, sectors
, &have_more
);
89 if (bytes_read
> chunk
)
97 * If we reach EOF, the filesystem driver will have already closed
98 * the underlying file... this really should be cleaner.
102 regs
->eflags
.l
|= EFLAGS_CF
;
107 pad
= (size_t)buf
& zero_mask
;
111 regs
->ebx
.l
= (size_t)buf
;
112 regs
->edi
.l
= (size_t)buf
+ pad
;