1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
9 * ----------------------------------------------------------------------- */
12 * arch/i386/boot/memory.c
14 * Memory detection code
19 #define SMAP 0x534d4150 /* ASCII "SMAP" */
21 static int detect_memory_e820(void)
26 struct e820entry *desc = boot_params.e820_map;
29 size = sizeof(struct e820entry);
31 asm("int $0x15; setc %0"
32 : "=am" (err), "+b" (next), "+d" (id), "+c" (size),
34 : "D" (desc), "a" (0xe820));
36 if (err || id != SMAP)
39 boot_params.e820_entries++;
41 } while (next && boot_params.e820_entries < E820MAX);
43 return boot_params.e820_entries;
46 static int detect_memory_e801(void)
53 asm("stc; int $0x15; setc %0"
54 : "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx));
59 /* Do we really need to do this? */
66 return -1; /* Bogus! */
68 /* This ignores memory above 16MB if we have a memory hole
69 there. If someone actually finds a machine with a memory
70 hole at 16MB and no support for 0E820h they should probably
71 generate a fake e820 map. */
72 boot_params.alt_mem_k = (ax == 15*1024) ? (dx << 6)+ax : ax;
77 static int detect_memory_88(void)
83 asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
85 boot_params.screen_info.ext_mem_k = ax;
90 int detect_memory(void)
92 if (detect_memory_e820() > 0)
95 if (!detect_memory_e801())
98 return detect_memory_88();