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 * Bostom 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);
73 static inline int get_e801(void)
78 memset(®s, 0, sizeof regs);
80 regs.eax.w[0] = 0xe801;
81 syscall(0x15, ®s, ®s);
83 if ( !(err = regs.eflags.l & 1) ) {
84 if ( regs.eax.w[0] ) {
85 insertrange(0x100000, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1);
87 if ( regs.ebx.w[0] ) {
88 insertrange(0x1000000, (uint64_t)((uint32_t)regs.ebx.w[0] << 16), 1);
95 static inline int get_88(void)
100 memset(®s, 0, sizeof regs);
102 regs.eax.b[1] = 0x88;
103 syscall(0x15, ®s, ®s);
106 if ( !(err = regs.eflags.l & 1) ) {
107 if ( regs.eax.w[0] ) {
108 insertrange(0x100000, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1);
115 uint32_t dos_mem = 0; /* 0-1MB */
116 uint32_t low_mem = 0; /* 1-16MB */
117 uint32_t high_mem = 0; /* 16+ MB */
125 puts("MEMDISK: Unable to obtain memory map\n");
132 #define PW(x) (1ULL << (x))
136 struct e820range *ep;
138 dos_mem = low_mem = high_mem = 0;
140 /* Derive "dos mem", "high mem", and "low mem" from the range array */
141 for ( ep = ranges ; ep->type != -1 ; ep++ ) {
142 if ( ep->type == 1 ) {
143 /* Only look at memory ranges */
144 if ( ep->start == 0 ) {
145 if ( ep[1].start > PW(20) )
148 dos_mem = ep[1].start;
150 if ( ep->start <= PW(20) && ep[1].start > PW(20) ) {
151 if ( ep[1].start > PW(24) )
152 low_mem = PW(24) - PW(20);
154 low_mem = ep[1].start - PW(20);
156 if ( ep->start <= PW(24) && ep[1].start > PW(24) ) {
157 if ( ep[1].start > PW(32) )
158 high_mem = PW(32) - PW(24);
160 high_mem = ep[1].start - PW(24);