MCPcopy Create free account
hub / github.com/coreboot/coreboot / cbmem_console_snapshot

Function cbmem_console_snapshot

payloads/libpayload/drivers/cbmem_console.c:100–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100char *cbmem_console_snapshot(void)
101{
102 const struct cbmem_console *const console_p = phys_to_virt(cbmem_console_p);
103 char *console_c;
104 uint32_t size, cursor, overflow, newc, oldc;
105
106 if (!console_p) {
107 printf("ERROR: No cbmem console found in coreboot table\n");
108 return NULL;
109 }
110
111 cursor = console_p->cursor & CURSOR_MASK;
112 overflow = console_p->cursor & OVERFLOW;
113 if (!overflow && cursor < console_p->size)
114 size = cursor;
115 else
116 size = console_p->size;
117
118 console_c = malloc(size + 1);
119 if (!console_c) {
120 printf("ERROR: Not enough memory for console (size = %u)\n",
121 size);
122 return NULL;
123 }
124
125 newc = 0;
126 if (overflow) {
127 if (cursor >= size) {
128 printf("ERROR: CBMEM console struct is corrupted\n");
129 free(console_c);
130 return NULL;
131 }
132 for (oldc = cursor; oldc < size; oldc++)
133 snapshot_putc(console_c, &newc, console_p->body[oldc]);
134 }
135 for (oldc = 0; oldc < size && oldc < cursor; oldc++)
136 snapshot_putc(console_c, &newc, console_p->body[oldc]);
137 console_c[newc] = '\0';
138
139 return console_c;
140}

Callers

nothing calls this directly

Calls 4

printfFunction · 0.85
snapshot_putcFunction · 0.85
mallocFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected