Trust uboot's device list only if it does not look suspicious.
[AROS.git] / test / kernel / mmap.c
blobf62a87eb757eb7940962e7363acf1cce9957266c
1 #include <aros/kernel.h>
2 #include <aros/multiboot.h>
3 #include <proto/exec.h>
4 #include <proto/kernel.h>
5 #include <proto/utility.h>
6 #include <proto/kernel.h>
8 #include <stdio.h>
10 int __nocommandline = 1;
12 static const char *types[] =
14 "Unknown ",
15 "Avalable ",
16 "Reserved ",
17 "ACPI Data",
18 "ACPI NVS "
21 int main(void)
23 struct TagItem *tags;
24 struct mb_mmap *mmap;
25 IPTR len;
26 APTR KernelBase = OpenResource("kernel.resource");
28 if (!KernelBase)
30 printf("Failed to open kernel.resource!\n");
31 return 20;
34 tags = KrnGetBootInfo();
35 if (!tags)
37 printf("No boot information from the bootstrap!\n");
38 return 20;
41 mmap = (struct mb_mmap *)GetTagData(KRN_MMAPAddress, 0, tags);
42 len = GetTagData(KRN_MMAPLength, 0, tags);
44 if (!mmap || !len)
46 printf("No memory map provided by the bootstrap!\n");
47 return 20;
50 printf("Memory map at 0x%p, length %lu:\n", mmap, len);
51 while (len >= sizeof(struct mb_mmap))
53 unsigned int type = mmap->type;
54 unsigned long long memaddr = mmap->addr;
55 unsigned long long memlen = mmap->len;
57 if (type > MMAP_TYPE_ACPINVS)
58 type = 0;
60 #if __WORDSIZE < 64
61 memaddr |= (unsigned long long)mmap->addr_high << 32;
62 memlen |= (unsigned long long)mmap->len_high << 32;
63 #endif
65 printf("Entry size %d type %d <%s> addr 0x%016llx len 0x%016llx\n", mmap->size, mmap->type, types[type], memaddr, memlen);
67 len -= mmap->size + 4;
68 mmap = (struct mb_mmap *)(mmap->size + (unsigned long)mmap + 4);
71 return 0;