1 #ident "$Id: msetup.c,v 1.12 2004/12/14 22:46:25 hpa Exp $"
2 /* ----------------------------------------------------------------------- *
4 * Copyright 2001-2003 H. Peter Anvin - All Rights Reserved
6 * 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
8 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 * Boston MA 02111-1307, USA; either version 2 of the License, or
10 * (at your option) any later version; incorporated herein by reference.
12 * ----------------------------------------------------------------------- */
17 * Initialization code for memory-based disk
25 static inline int get_e820(void)
36 memset(®s, 0, sizeof regs);
39 regs.eax.l = 0x0000e820;
40 regs.ecx.l = sizeof(*buf);
41 regs.edx.l = 0x534d4150;
42 regs.edi.w[0] = OFFS(buf);
45 syscall(0x15, ®s, ®s);
46 copied = (regs.eflags.l & 1) ? 0 : regs.ecx.l;
48 if ( regs.eax.l != 0x534d4150 || copied < 20 )
51 printf("e820: %08x%08x %08x%08x %d\n",
52 (uint32_t)(buf->base >> 32), (uint32_t)buf->base,
53 (uint32_t)(buf->len >> 32), (uint32_t)buf->len,
56 insertrange(buf->base, buf->len, buf->type);
59 } while ( regs.ebx.l );
64 static inline void get_dos_mem(void)
68 memset(®s, 0, sizeof regs);
69 syscall(0x12, ®s, ®s);
70 insertrange(0, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1);
71 printf(" DOS: %d K\n", regs.eax.w[0]);
74 static inline int get_e801(void)
79 memset(®s, 0, sizeof regs);
81 regs.eax.w[0] = 0xe801;
82 syscall(0x15, ®s, ®s);
84 if ( !(err = regs.eflags.l & 1) ) {
85 if ( regs.eax.w[0] ) {
86 insertrange(0x100000, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1);
88 if ( regs.ebx.w[0] ) {
89 insertrange(0x1000000, (uint64_t)((uint32_t)regs.ebx.w[0] << 16), 1);
92 printf("e801: %04x %04x\n", regs.eax.w[0], regs.ebx.w[0]);
98 static inline int get_88(void)
103 memset(®s, 0, sizeof regs);
105 regs.eax.b[1] = 0x88;
106 syscall(0x15, ®s, ®s);
109 if ( !(err = regs.eflags.l & 1) ) {
110 if ( regs.eax.w[0] ) {
111 insertrange(0x100000, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1);
114 printf(" 88: %04x\n", regs.eax.w[0]);
120 uint32_t dos_mem = 0; /* 0-1MB */
121 uint32_t low_mem = 0; /* 1-16MB */
122 uint32_t high_mem = 0; /* 16+ MB */
130 puts("MEMDISK: Unable to obtain memory map\n");
137 #define PW(x) (1ULL << (x))
141 struct e820range *ep;
143 dos_mem = low_mem = high_mem = 0;
145 /* Derive "dos mem", "high mem", and "low mem" from the range array */
146 for ( ep = ranges ; ep->type != -1 ; ep++ ) {
147 if ( ep->type == 1 ) {
148 /* Only look at memory ranges */
149 if ( ep->start == 0 ) {
150 if ( ep[1].start > PW(20) )
153 dos_mem = ep[1].start;
155 if ( ep->start <= PW(20) && ep[1].start > PW(20) ) {
156 if ( ep[1].start > PW(24) )
157 low_mem = PW(24) - PW(20);
159 low_mem = ep[1].start - PW(20);
161 if ( ep->start <= PW(24) && ep[1].start > PW(24) ) {
162 if ( ep[1].start > PW(32) )
163 high_mem = PW(32) - PW(24);
165 high_mem = ep[1].start - PW(24);