- memory detection with BIOS 0x15/0xe820
[bootcensus] / src / mem.c
1 /*
2 pcboot - bootable PC demo/game kernel
3 Copyright (C) 2018  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY, without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #include <stdio.h>
19 #include "panic.h"
20 #include "mem.h"
21
22 struct mem_range {
23         uint32_t start;
24         uint32_t size;
25 };
26
27 #define MAX_MAP_SIZE    16
28 extern struct mem_range boot_mem_map[MAX_MAP_SIZE];
29 extern int boot_mem_map_size;
30
31 void init_mem(void)
32 {
33         int i;
34
35         if(boot_mem_map_size <= 0 || boot_mem_map_size > MAX_MAP_SIZE) {
36                 panic("invalid memory map size reported by the boot loader: %d\n", boot_mem_map_size);
37         }
38
39         printf("Memory map:\n");
40         for(i=0; i<boot_mem_map_size; i++) {
41                 printf(" start: %08x - size: %08x\n", (unsigned int)boot_mem_map[i].start,
42                                 (unsigned int)boot_mem_map[i].size);
43         }
44 }