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
)
53 uint32_t retflags
= 0;
56 zero_mask
= regs
->edx
.w
[0];
57 buf
= (char *)regs
->edi
.l
;
58 limit
= (char *)(regs
->ebp
.l
& ~zero_mask
);
59 file
= handle_to_file(regs
->esi
.w
[0]);
62 sector_mask
= SECTOR_SIZE(fs
) - 1;
68 if (buf
+ SECTOR_SIZE(fs
) > limit
) {
69 /* Can't fit even one more sector in... */
77 call16((void (*)(void))(size_t)regs
->ebx
.w
[0], &zero_regs
, NULL
);
78 chunk
= min(chunk
, MAX_CHUNK
);
81 if (chunk
> (((char *)limit
- buf
) & ~sector_mask
))
82 chunk
= ((char *)limit
- buf
) & ~sector_mask
;
84 sectors
= (chunk
+ sector_mask
) >> SECTOR_SHIFT(fs
);
85 bytes_read
= fs
->fs_ops
->getfssec(file
, buf
, sectors
, &have_more
);
87 if (bytes_read
> chunk
)
95 * If we reach EOF, the filesystem driver will have already closed
96 * the underlying file... this really should be cleaner.
100 retflags
= EFLAGS_CF
;
105 pad
= (size_t)buf
& zero_mask
;
109 regs
->ebx
.l
= (size_t)buf
;
110 regs
->edi
.l
= (size_t)buf
+ pad
;
111 set_flags(regs
, retflags
);