Deleted Added
full compact
28c28
< __FBSDID("$FreeBSD: head/sys/boot/i386/libi386/biossmap.c 179631 2008-06-07 03:07:32Z jhb $");
---
> __FBSDID("$FreeBSD: head/sys/boot/i386/libi386/biossmap.c 191111 2009-04-15 17:31:22Z jkim $");
35a36,37
> #include <sys/queue.h>
> #include <sys/stddef.h>
36a39
> #include <machine/psl.h>
42,45c45
< static struct {
< struct bios_smap _smap_entry;
< char pad[8]; /* Bad BIOS writer, no cookie! */
< } smap;
---
> #define V86_CY(x) ((x) & PSL_C)
47,48c47,51
< static struct bios_smap *smapbase;
< static int smaplen;
---
> struct smap_buf {
> struct bios_smap smap;
> uint32_t xattr; /* Extended attribute from ACPI 3.0 */
> STAILQ_ENTRY(smap_buf) bufs;
> };
49a53,58
> #define SMAP_BUFSIZE offsetof(struct smap_buf, bufs)
>
> static struct bios_smap *smapbase;
> static uint32_t *smapattr;
> static u_int smaplen;
>
53c62,66
< int n;
---
> struct smap_buf buf;
> STAILQ_HEAD(smap_head, smap_buf) head =
> STAILQ_HEAD_INITIALIZER(head);
> struct smap_buf *cur, *next;
> u_int n, x;
54a68
> STAILQ_INIT(&head);
56,57c70
< smaplen = 0;
< /* Count up segments in system memory map */
---
> x = 0;
61,63c74,76
< v86.addr = 0x15; /* int 0x15 function 0xe820*/
< v86.eax = 0xe820;
< v86.ecx = sizeof(struct bios_smap);
---
> v86.addr = 0x15;
> v86.eax = 0xe820; /* int 0x15 function 0xe820 */
> v86.ecx = SMAP_BUFSIZE;
65,66c78,79
< v86.es = VTOPSEG(&smap);
< v86.edi = VTOPOFF(&smap);
---
> v86.es = VTOPSEG(&buf);
> v86.edi = VTOPOFF(&buf);
68c81,82
< if ((v86.efl & 1) || (v86.eax != SMAP_SIG))
---
> if (V86_CY(v86.efl) || v86.eax != SMAP_SIG ||
> v86.ecx < sizeof(buf.smap) || v86.ecx > SMAP_BUFSIZE)
69a84,93
>
> next = malloc(sizeof(*next));
> if (next == NULL)
> break;
> next->smap = buf.smap;
> if (v86.ecx == SMAP_BUFSIZE) {
> next->xattr = buf.xattr;
> x++;
> }
> STAILQ_INSERT_TAIL(&head, next, bufs);
72,75c96
< if (n == 0)
< return;
< n += 10; /* spare room */
< smapbase = malloc(n * sizeof(*smapbase));
---
> smaplen = n;
77,92c98,121
< /* Save system memory map */
< v86.ebx = 0;
< do {
< v86.ctl = V86_FLAGS;
< v86.addr = 0x15; /* int 0x15 function 0xe820*/
< v86.eax = 0xe820;
< v86.ecx = sizeof(struct bios_smap);
< v86.edx = SMAP_SIG;
< v86.es = VTOPSEG(&smap);
< v86.edi = VTOPOFF(&smap);
< v86int();
< bcopy(&smap, &smapbase[smaplen], sizeof(struct bios_smap));
< smaplen++;
< if ((v86.efl & 1) || (v86.eax != SMAP_SIG))
< break;
< } while (v86.ebx != 0 && smaplen < n);
---
> if (smaplen > 0) {
> smapbase = malloc(smaplen * sizeof(*smapbase));
> if (smapbase != NULL) {
> n = 0;
> STAILQ_FOREACH(cur, &head, bufs)
> smapbase[n++] = cur->smap;
> }
> if (smaplen == x) {
> smapattr = malloc(smaplen * sizeof(*smapattr));
> if (smapattr != NULL) {
> n = 0;
> STAILQ_FOREACH(cur, &head, bufs)
> smapattr[n++] = cur->xattr &
> SMAP_XATTR_MASK;
> }
> } else
> smapattr = NULL;
> cur = STAILQ_FIRST(&head);
> while (cur != NULL) {
> next = STAILQ_NEXT(cur, bufs);
> free(cur);
> cur = next;
> }
> }
98c127
< int len;
---
> size_t size;
100c129
< if (smapbase == 0 || smaplen == 0)
---
> if (smapbase == NULL || smaplen == 0)
102,103c131,136
< len = smaplen * sizeof(*smapbase);
< file_addmetadata(kfp, MODINFOMD_SMAP, len, smapbase);
---
> size = smaplen * sizeof(*smapbase);
> file_addmetadata(kfp, MODINFOMD_SMAP, size, smapbase);
> if (smapattr != NULL) {
> size = smaplen * sizeof(*smapattr);
> file_addmetadata(kfp, MODINFOMD_SMAP_XATTR, size, smapattr);
> }
111c144
< int i;
---
> u_int i;
113c146
< if (smapbase == 0 || smaplen == 0)
---
> if (smapbase == NULL || smaplen == 0)
115,117c148,160
< for (i = 0; i < smaplen; i++)
< printf("SMAP type=%02x base=%016llx len=%016llx\n",
< smapbase[i].type, smapbase[i].base, smapbase[i].length);
---
> if (smapattr != NULL)
> for (i = 0; i < smaplen; i++)
> printf("SMAP type=%02x base=%016llx len=%016llx attr=%02x\n",
> (unsigned int)smapbase[i].type,
> (unsigned long long)smapbase[i].base,
> (unsigned long long)smapbase[i].length,
> (unsigned int)smapattr[i]);
> else
> for (i = 0; i < smaplen; i++)
> printf("SMAP type=%02x base=%016llx len=%016llx\n",
> (unsigned int)smapbase[i].type,
> (unsigned long long)smapbase[i].base,
> (unsigned long long)smapbase[i].length);