aboutsummaryrefslogtreecommitdiffstats
path: root/com32/mboot/mem.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-05-29 15:10:27 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-05-29 15:10:27 -0700
commitdacaf2280abb2ffee5035280270fa9e41e0d8775 (patch)
tree47727279c9ea6def65e303c1562e213bf8fad809 /com32/mboot/mem.c
parent1f25a809ac1cfc7343754a4f5bbfe55b2ac21590 (diff)
downloadsyslinux-dacaf2280abb2ffee5035280270fa9e41e0d8775.tar.gz
syslinux-dacaf2280abb2ffee5035280270fa9e41e0d8775.tar.xz
syslinux-dacaf2280abb2ffee5035280270fa9e41e0d8775.zip
Run Nindent on com32/mboot/mem.c
Automatically reformat com32/mboot/mem.c using Nindent. Do this for all files except HDT, gPXE and externally maintained libraries (zlib, tinyjpeg, libpng). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32/mboot/mem.c')
-rw-r--r--com32/mboot/mem.c273
1 files changed, 136 insertions, 137 deletions
diff --git a/com32/mboot/mem.c b/com32/mboot/mem.c
index 07ccb627..6a31fac0 100644
--- a/com32/mboot/mem.c
+++ b/com32/mboot/mem.c
@@ -39,168 +39,167 @@
#include <com32.h>
struct e820_entry {
- uint64_t start;
- uint64_t len;
- uint32_t type;
+ uint64_t start;
+ uint64_t len;
+ uint32_t type;
};
#define RANGE_ALLOC_BLOCK 128
-static int mboot_scan_memory(struct AddrRangeDesc **ardp, uint32_t *dosmem)
+static int mboot_scan_memory(struct AddrRangeDesc **ardp, uint32_t * dosmem)
{
- com32sys_t ireg, oreg;
- struct e820_entry *e820buf = __com32.cs_bounce;
- struct AddrRangeDesc *ard;
- size_t ard_count, ard_space;
-
- /* Use INT 12h to get DOS memory */
- __intcall(0x12, &__com32_zero_regs, &oreg);
- *dosmem = oreg.eax.w[0] << 10;
- if (*dosmem < 32*1024 || *dosmem > 640*1024) {
- /* INT 12h reports nonsense... now what? */
- uint16_t ebda_seg = *(uint16_t *)0x40e;
- if (ebda_seg >= 0x8000 && ebda_seg < 0xa000)
- *dosmem = ebda_seg << 4;
- else
- *dosmem = 640*1024; /* Hope for the best... */
- }
-
- /* Allocate initial space */
- *ardp = ard = malloc(RANGE_ALLOC_BLOCK * sizeof *ard);
- if (!ard)
- return 0;
-
- ard_count = 0;
- ard_space = RANGE_ALLOC_BLOCK;
-
- /* First try INT 15h AX=E820h */
- memset(&ireg, 0, sizeof ireg);
- ireg.eax.l = 0xe820;
- ireg.edx.l = 0x534d4150;
- /* ireg.ebx.l = 0; */
- ireg.ecx.l = sizeof(*e820buf);
- ireg.es = SEG(e820buf);
- ireg.edi.w[0] = OFFS(e820buf);
- memset(e820buf, 0, sizeof *e820buf);
-
- do {
- __intcall(0x15, &ireg, &oreg);
-
- if ((oreg.eflags.l & EFLAGS_CF) ||
- (oreg.eax.l != 0x534d4150) ||
- (oreg.ecx.l < 20))
- break;
+ com32sys_t ireg, oreg;
+ struct e820_entry *e820buf = __com32.cs_bounce;
+ struct AddrRangeDesc *ard;
+ size_t ard_count, ard_space;
+
+ /* Use INT 12h to get DOS memory */
+ __intcall(0x12, &__com32_zero_regs, &oreg);
+ *dosmem = oreg.eax.w[0] << 10;
+ if (*dosmem < 32 * 1024 || *dosmem > 640 * 1024) {
+ /* INT 12h reports nonsense... now what? */
+ uint16_t ebda_seg = *(uint16_t *) 0x40e;
+ if (ebda_seg >= 0x8000 && ebda_seg < 0xa000)
+ *dosmem = ebda_seg << 4;
+ else
+ *dosmem = 640 * 1024; /* Hope for the best... */
+ }
- if (ard_count >= ard_space) {
- ard_space += RANGE_ALLOC_BLOCK;
- *ardp = ard = realloc(ard, ard_space*sizeof *ard);
- if (!ard)
+ /* Allocate initial space */
+ *ardp = ard = malloc(RANGE_ALLOC_BLOCK * sizeof *ard);
+ if (!ard)
+ return 0;
+
+ ard_count = 0;
+ ard_space = RANGE_ALLOC_BLOCK;
+
+ /* First try INT 15h AX=E820h */
+ memset(&ireg, 0, sizeof ireg);
+ ireg.eax.l = 0xe820;
+ ireg.edx.l = 0x534d4150;
+ /* ireg.ebx.l = 0; */
+ ireg.ecx.l = sizeof(*e820buf);
+ ireg.es = SEG(e820buf);
+ ireg.edi.w[0] = OFFS(e820buf);
+ memset(e820buf, 0, sizeof *e820buf);
+
+ do {
+ __intcall(0x15, &ireg, &oreg);
+
+ if ((oreg.eflags.l & EFLAGS_CF) ||
+ (oreg.eax.l != 0x534d4150) || (oreg.ecx.l < 20))
+ break;
+
+ if (ard_count >= ard_space) {
+ ard_space += RANGE_ALLOC_BLOCK;
+ *ardp = ard = realloc(ard, ard_space * sizeof *ard);
+ if (!ard)
+ return ard_count;
+ }
+
+ ard[ard_count].size = 20;
+ ard[ard_count].BaseAddr = e820buf->start;
+ ard[ard_count].Length = e820buf->len;
+ ard[ard_count].Type = e820buf->type;
+ ard_count++;
+
+ ireg.ebx.l = oreg.ebx.l;
+ } while (oreg.ebx.l);
+
+ if (ard_count)
return ard_count;
+
+ ard[0].size = 20;
+ ard[0].BaseAddr = 0;
+ ard[0].Length = *dosmem << 10;
+ ard[0].Type = 1;
+
+ /* Next try INT 15h AX=E801h */
+ ireg.eax.w[0] = 0xe801;
+ __intcall(0x15, &ireg, &oreg);
+
+ if (!(oreg.eflags.l & EFLAGS_CF) && oreg.ecx.w[0]) {
+ ard[1].size = 20;
+ ard[1].BaseAddr = 1 << 20;
+ ard[1].Length = oreg.ecx.w[0] << 10;
+ ard[1].Type = 1;
+
+ if (oreg.edx.w[0]) {
+ ard[2].size = 20;
+ ard[2].BaseAddr = 16 << 20;
+ ard[2].Length = oreg.edx.w[0] << 16;
+ ard[2].Type = 1;
+ return 3;
+ } else {
+ return 2;
+ }
}
- ard[ard_count].size = 20;
- ard[ard_count].BaseAddr = e820buf->start;
- ard[ard_count].Length = e820buf->len;
- ard[ard_count].Type = e820buf->type;
- ard_count++;
-
- ireg.ebx.l = oreg.ebx.l;
- } while (oreg.ebx.l);
-
- if (ard_count)
- return ard_count;
-
- ard[0].size = 20;
- ard[0].BaseAddr = 0;
- ard[0].Length = *dosmem << 10;
- ard[0].Type = 1;
-
- /* Next try INT 15h AX=E801h */
- ireg.eax.w[0] = 0xe801;
- __intcall(0x15, &ireg, &oreg);
-
- if (!(oreg.eflags.l & EFLAGS_CF) && oreg.ecx.w[0]) {
- ard[1].size = 20;
- ard[1].BaseAddr = 1 << 20;
- ard[1].Length = oreg.ecx.w[0] << 10;
- ard[1].Type = 1;
-
- if (oreg.edx.w[0]) {
- ard[2].size = 20;
- ard[2].BaseAddr = 16 << 20;
- ard[2].Length = oreg.edx.w[0] << 16;
- ard[2].Type = 1;
- return 3;
- } else {
- return 2;
+ /* Finally try INT 15h AH=88h */
+ ireg.eax.w[0] = 0x8800;
+ if (!(oreg.eflags.l & EFLAGS_CF) && oreg.eax.w[0]) {
+ ard[1].size = 20;
+ ard[1].BaseAddr = 1 << 20;
+ ard[1].Length = oreg.ecx.w[0] << 10;
+ ard[1].Type = 1;
+ return 2;
}
- }
-
- /* Finally try INT 15h AH=88h */
- ireg.eax.w[0] = 0x8800;
- if (!(oreg.eflags.l & EFLAGS_CF) && oreg.eax.w[0]) {
- ard[1].size = 20;
- ard[1].BaseAddr = 1 << 20;
- ard[1].Length = oreg.ecx.w[0] << 10;
- ard[1].Type = 1;
- return 2;
- }
-
- return 1; /* ... problematic ... */
+
+ return 1; /* ... problematic ... */
}
void mboot_make_memmap(void)
{
- int i, nmap;
- struct AddrRangeDesc *ard;
- uint32_t lowmem, highmem;
- uint32_t highrsvd;
+ int i, nmap;
+ struct AddrRangeDesc *ard;
+ uint32_t lowmem, highmem;
+ uint32_t highrsvd;
- /* Always report DOS memory as "lowmem", this may be overly conservative
- (e.g. if we're dropping PXE), but it should be *safe*... */
+ /* Always report DOS memory as "lowmem", this may be overly conservative
+ (e.g. if we're dropping PXE), but it should be *safe*... */
- nmap = mboot_scan_memory(&ard, &lowmem);
+ nmap = mboot_scan_memory(&ard, &lowmem);
- highmem = 0x100000;
- highrsvd = 0xfff00000;
+ highmem = 0x100000;
+ highrsvd = 0xfff00000;
- again:
- for (i = 0; i < nmap; i++) {
- uint64_t start, end;
+again:
+ for (i = 0; i < nmap; i++) {
+ uint64_t start, end;
- start = ard[i].BaseAddr;
- end = start + ard[i].Length;
+ start = ard[i].BaseAddr;
+ end = start + ard[i].Length;
- if (end < start)
- end = ~0ULL;
+ if (end < start)
+ end = ~0ULL;
- if (start & 0xffffffff00000000ULL)
- continue; /* Not interested in 64-bit memory */
+ if (start & 0xffffffff00000000ULL)
+ continue; /* Not interested in 64-bit memory */
- if (start < highmem)
- start = highmem;
+ if (start < highmem)
+ start = highmem;
- if (end <= start)
- continue;
+ if (end <= start)
+ continue;
- if (ard[i].Type == 1 && start == highmem) {
- highmem = end;
- goto again;
- } else if (ard[i].Type != 1 && start < highrsvd)
- highrsvd = start;
- }
+ if (ard[i].Type == 1 && start == highmem) {
+ highmem = end;
+ goto again;
+ } else if (ard[i].Type != 1 && start < highrsvd)
+ highrsvd = start;
+ }
- if (highmem > highrsvd)
- highmem = highrsvd;
+ if (highmem > highrsvd)
+ highmem = highrsvd;
- mbinfo.mem_lower = lowmem >> 10;
- mbinfo.mem_upper = (highmem - 0x100000) >> 10;
- mbinfo.flags |= MB_INFO_MEMORY;
+ mbinfo.mem_lower = lowmem >> 10;
+ mbinfo.mem_upper = (highmem - 0x100000) >> 10;
+ mbinfo.flags |= MB_INFO_MEMORY;
- /* The spec says this address should be +4, but Grub disagrees */
- mbinfo.mmap_addr = map_data(ard, nmap*sizeof *ard, 4, false);
- if (mbinfo.mmap_addr) {
- mbinfo.mmap_length = nmap*sizeof *ard;
- mbinfo.flags |= MB_INFO_MEM_MAP;
- }
+ /* The spec says this address should be +4, but Grub disagrees */
+ mbinfo.mmap_addr = map_data(ard, nmap * sizeof *ard, 4, false);
+ if (mbinfo.mmap_addr) {
+ mbinfo.mmap_length = nmap * sizeof *ard;
+ mbinfo.flags |= MB_INFO_MEM_MAP;
+ }
}