There is no need for custom warnings for many common failures.
Introduce a common warning which is consistent and more visible.
void *dsdt = malloc_high(sizeof(AmlCode));
if (!fadt || !facs || !dsdt) {
- dprintf(1, "Not enough memory for fadt!\n");
+ warn_noalloc();
return NULL;
}
+ sizeof(struct madt_intsrcovr) * 16);
struct multiple_apic_table *madt = malloc_high(madt_size);
if (!madt) {
- dprintf(1, "Not enough memory for madt!\n");
+ warn_noalloc();
return NULL;
}
memset(madt, 0, madt_size);
int length = sizeof(struct acpi_table_header) + 3 + cpu_length;
u8 *ssdt = malloc_high(length);
if (! ssdt) {
- dprintf(1, "No space for ssdt!\n");
+ warn_noalloc();
return NULL;
}
{
struct acpi_20_hpet *hpet = malloc_high(sizeof(*hpet));
if (!hpet) {
- dprintf(1, "Not enough memory for hpet!\n");
+ warn_noalloc();
return NULL;
}
u64 *numadata = malloc_tmphigh(sizeof(u64) * (MaxCountCPUs + nb_numa_nodes));
if (!numadata) {
- dprintf(1, "Not enough memory for read numa data from VM!\n");
+ warn_noalloc();
return NULL;
}
srat = malloc_high(srat_size);
if (!srat) {
- dprintf(1, "Not enough memory for srat table!\n");
+ warn_noalloc();
free(numadata);
return NULL;
}
// Create initial rsdt table
struct rsdp_descriptor *rsdp = malloc_fseg(sizeof(*rsdp));
if (!rsdp) {
- dprintf(1, "Not enough memory for acpi rsdp table!\n");
+ warn_noalloc();
return;
}
u16 len = qemu_cfg_next_acpi_table_len();
void *addr = malloc_high(len);
if (!addr) {
- dprintf(1, "Not enough memory for ext acpi table of size %d!\n"
- , len);
+ warn_noalloc();
continue;
}
ACPI_INIT_TABLE(qemu_cfg_next_acpi_table_load(addr, len));
if (tbl_idx == MAX_ACPI_TABLES) {
- dprintf(1, "Too many external tables!\n");
+ warn_noalloc();
break;
}
}
rsdt = malloc_high(rsdt_len);
if (!rsdt) {
- dprintf(1, "Not enough memory for acpi rsdt table!\n");
+ warn_noalloc();
return;
}
memset(rsdt, 0, rsdt_len);
if ((status & mask) == flags)
return status;
if (check_time(end)) {
- dprintf(1, "IDE time out\n");
+ warn_timeout();
return -1;
}
yield();
break;
// Change drive request failed to take effect - retry.
if (check_time(end)) {
- dprintf(1, "ata_reset slave time out\n");
+ warn_timeout();
goto done;
}
}
// Transfer in progress
if (check_time(end)) {
// Timeout.
- dprintf(1, "IDE DMA timeout\n");
+ warn_timeout();
break;
}
yield();
return orstatus;
}
if (check_time(SpinupEnd)) {
- dprintf(1, "powerup IDE time out\n");
+ warn_timeout();
return -1;
}
yield();
add_ordered_drive(u8 *idmap, u8 *count, struct drive_s *drive_g)
{
if (*count >= ARRAY_SIZE(Drives.idmap[0])) {
- dprintf(1, "No room to map drive %p\n", drive_g);
+ warn_noalloc();
return;
}
u8 *pos = &idmap[*count];
set_cf(regs, 1);
}
-#define warn_invalid(regs) \
- __warn_invalid((regs), __LINE__, __func__)
-#define set_invalid(regs) \
- __set_invalid((regs), __LINE__, __func__)
-#define set_code_invalid(regs, code) \
- __set_code_invalid((regs), (code) | (__LINE__ << 8), __func__)
-
-#define warn_unimplemented(regs) \
- __warn_unimplemented((regs), __LINE__, __func__)
-#define set_unimplemented(regs) \
- __set_unimplemented((regs), __LINE__, __func__)
-#define set_code_unimplemented(regs, code) \
- __set_code_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
-
-// output.c
-void __warn_invalid(struct bregs *regs, int lineno, const char *fname);
-void __warn_unimplemented(struct bregs *regs, int lineno, const char *fname);
-void __set_invalid(struct bregs *regs, int lineno, const char *fname);
-void __set_unimplemented(struct bregs *regs, int lineno, const char *fname);
-void __set_code_invalid(struct bregs *regs, u32 linecode, const char *fname);
-void __set_code_unimplemented(struct bregs *regs, u32 linecode
- , const char *fname);
-
#endif // !__ASSEMBLY__
#endif // bregs.h
return;
void *newpos = malloc_fseg(p->size);
if (!newpos) {
- dprintf(1, "No room to copy PIR table!\n");
+ warn_noalloc();
return;
}
dprintf(1, "Copying PIR from %p to %p\n", pos, newpos);
u16 mpclength = ((struct mptable_config_s *)p->physaddr)->length;
struct mptable_floating_s *newpos = malloc_fseg(length + mpclength);
if (!newpos) {
- dprintf(1, "No room to copy MPTABLE!\n");
+ warn_noalloc();
return;
}
dprintf(1, "Copying MPTABLE from %p/%x to %p\n", pos, p->physaddr, newpos);
}
void *newpos = malloc_fseg(length);
if (!newpos) {
- dprintf(1, "No room to copy ACPI RSDP table!\n");
+ warn_noalloc();
return;
}
dprintf(1, "Copying ACPI RSDP from %p to %p\n", pos, newpos);
CBHDR = *(void **)CBFS_HEADPTR_ADDR;
if (CBHDR->magic != htonl(CBFS_HEADER_MAGIC)) {
- dprintf(1, "Unable to find CBFS (got %x not %x)\n"
- , CBHDR->magic, htonl(CBFS_HEADER_MAGIC));
+ dprintf(1, "Unable to find CBFS (ptr=%p; got %x not %x)\n"
+ , CBHDR, CBHDR->magic, htonl(CBFS_HEADER_MAGIC));
CBHDR = NULL;
return;
}
// Not compressed.
dprintf(3, "Copying data %d@%p to %d@%p\n", size, src, maxlen, dst);
if (size > maxlen) {
- dprintf(1, "File too big to copy\n");
+ warn_noalloc();
return -1;
}
iomemcpy(dst, src, size);
u16 head = regs->dh;
if (count > 128 || count == 0 || sector == 0) {
- dprintf(1, "int13_harddisk: function %02x, parameter out of range!\n"
- , regs->ah);
+ warn_invalid(regs);
disk_ret(regs, DISK_RET_EPARAM);
return;
}
// sanity check on cyl heads, sec
if (cylinder >= nlc || head >= nlh || sector > nlspt) {
- dprintf(1, "int13_harddisk: function %02x, parameters out of"
- " range %04x/%04x/%04x!\n"
- , regs->ah, cylinder, head, sector);
+ warn_invalid(regs);
disk_ret(regs, DISK_RET_EPARAM);
return;
}
dop.command = command;
dop.drive_g = drive_g;
if (dop.lba >= GET_GLOBAL(drive_g->sectors)) {
- dprintf(1, "int13_harddisk: function %02x. LBA out of range\n"
- , regs->ah);
+ warn_invalid(regs);
disk_ret(regs, DISK_RET_EPARAM);
return;
}
insert_e820(int i, u64 start, u64 size, u32 type)
{
if (e820_count >= CONFIG_MAX_E820) {
- dprintf(1, "Overflowed e820 list!\n");
+ warn_noalloc();
return;
}
// Config structure in temp area.
struct mptable_config_s *config = malloc_tmphigh(32*1024);
if (!config) {
- dprintf(1, "No space for temp mptable\n");
+ warn_noalloc();
return;
}
memset(config, 0, sizeof(*config));
struct mptable_config_s *finalconfig = malloc_fseg(length);
struct mptable_floating_s *floating = malloc_fseg(sizeof(*floating));
if (!finalconfig || !floating) {
- dprintf(1, "No room for MPTABLE!\n");
+ warn_noalloc();
free(config);
free(finalconfig);
free(floating);
u32 romsize = rom->size * 512;
if (RomEnd + romsize > max_rom()) {
// Option rom doesn't fit.
- dprintf(1, "Option rom %p doesn't fit.\n", rom);
+ warn_noalloc();
return NULL;
}
dprintf(4, "Copying option rom (size %d) from %p to %x\n"
}
}
+// Report on an allocation failure.
+void
+__warn_noalloc(int lineno, const char *fname)
+{
+ dprintf(1, "WARNING - Unable to allocate resource at %s:%d!\n"
+ , fname, lineno);
+}
+
+// Report on a timeout exceeded.
+void
+__warn_timeout(int lineno, const char *fname)
+{
+ dprintf(1, "WARNING - Timeout at %s:%d!\n", fname, lineno);
+}
+
// Report a handler reporting an invalid parameter to the caller.
void
__set_invalid(struct bregs *regs, int lineno, const char *fname)
}
if (end - *p < sizeof(struct smbios_structure_header)) {
- dprintf(1, "No more memory for additional smbios tables\n");
+ warn_noalloc();
break;
}
/* Read the rest and terminate the entry */
if (end - *p < table.header.length) {
- dprintf(1, "No memory for smbios table %d\n", header->type);
+ warn_noalloc();
*p -= sizeof(struct smbios_structure_header);
continue;
}
return 0;
udelay(50);
}
- dprintf(1, "i8042 timeout on wait read\n");
+ warn_timeout();
return -1;
}
return 0;
udelay(50);
}
- dprintf(1, "i8042 timeout on wait write\n");
+ warn_timeout();
return -1;
}
dprintf(7, "i8042 flushed %x (status=%x)\n", data, status);
}
- dprintf(1, "i8042 timeout on flush\n");
+ warn_timeout();
return -1;
}
}
if (check_time(end)) {
- dprintf(1, "ps2_recvbyte timeout\n");
+ // Don't warn on second byte of a reset
+ if (timeout > 100)
+ warn_timeout();
return -1;
}
yield();
// Allocate ram for image.
void *pos = memalign_tmphigh(PAGE_SIZE, size);
if (!pos) {
- dprintf(3, "Not enough memory for ramdisk\n");
+ warn_noalloc();
return;
}
add_e820((u32)pos, size, E820_RESERVED);
struct smbios_entry_point *ep = malloc_fseg(sizeof(*ep));
void *finaltable = malloc_high(structure_table_length);
if (!ep || !finaltable) {
- dprintf(1, "No space for smbios tables!\n");
+ warn_noalloc();
free(ep);
free(finaltable);
return;
char *start = malloc_tmphigh(TEMPSMBIOSSIZE);
if (! start) {
- dprintf(1, "No memory for temp smbios table\n");
+ warn_noalloc();
return;
}
if (! status & OHCI_HCR)
break;
if (check_time(end)) {
- dprintf(1, "Timeout on ohci software reset\n");
+ warn_timeout();
return -1;
}
}
struct ohci_ed *intr_ed = malloc_high(sizeof(*intr_ed));
struct ohci_ed *control_ed = malloc_high(sizeof(*control_ed));
if (!hcca || !intr_ed || !control_ed) {
- dprintf(1, "No ram for ohci init\n");
+ warn_noalloc();
goto free;
}
memset(hcca, 0, sizeof(*hcca));
if (ed->hwHeadP == ed->hwTailP)
return 0;
if (check_time(end)) {
- dprintf(1, "Timeout on wait_ed %p\n", ed);
+ warn_timeout();
return -1;
}
yield();
struct uhci_qh *data_qh = malloc_high(sizeof(*data_qh));
struct uhci_qh *term_qh = malloc_high(sizeof(*term_qh));
if (!term_td || !fl || !intr_qh || !data_qh || !term_qh) {
+ warn_noalloc();
free(term_td);
free(fl);
free(intr_qh);
free(data_qh);
free(term_qh);
- dprintf(1, "No ram for uhci init\n");
return;
}
if (qh->element & UHCI_PTR_TERM)
return 0;
if (check_time(end)) {
+ warn_timeout();
struct uhci_td *td = (void*)(qh->element & ~UHCI_PTR_BITS);
dprintf(1, "Timeout on wait_qh %p (td=%p s=%x c=%x/%x)\n"
, qh, td, td->status
__attribute__ ((format (printf, 1, 2))) __noreturn;
void printf(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
-void __dprintf(const char *fmt, ...)
- __attribute__ ((format (printf, 1, 2)));
int snprintf(char *str, size_t size, const char *fmt, ...)
__attribute__ ((format (printf, 3, 4)));
+void __dprintf(const char *fmt, ...)
+ __attribute__ ((format (printf, 1, 2)));
+void __debug_enter(struct bregs *regs, const char *fname);
+void __debug_isr(const char *fname);
+void __debug_stub(struct bregs *regs, int lineno, const char *fname);
+void __warn_invalid(struct bregs *regs, int lineno, const char *fname);
+void __warn_unimplemented(struct bregs *regs, int lineno, const char *fname);
+void __warn_noalloc(int lineno, const char *fname);
+void __warn_timeout(int lineno, const char *fname);
+void __set_invalid(struct bregs *regs, int lineno, const char *fname);
+void __set_unimplemented(struct bregs *regs, int lineno, const char *fname);
+void __set_code_invalid(struct bregs *regs, u32 linecode, const char *fname);
+void __set_code_unimplemented(struct bregs *regs, u32 linecode
+ , const char *fname);
+void hexdump(const void *d, int len);
+
#define dprintf(lvl, fmt, args...) do { \
if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
__dprintf((fmt) , ##args ); \
} while (0)
-void __debug_enter(struct bregs *regs, const char *fname);
-void __debug_stub(struct bregs *regs, int lineno, const char *fname);
-void __debug_isr(const char *fname);
#define debug_enter(regs, lvl) do { \
if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
__debug_enter((regs), __func__); \
} while (0)
#define debug_stub(regs) \
__debug_stub((regs), __LINE__, __func__)
-void hexdump(const void *d, int len);
+#define warn_invalid(regs) \
+ __warn_invalid((regs), __LINE__, __func__)
+#define warn_unimplemented(regs) \
+ __warn_unimplemented((regs), __LINE__, __func__)
+#define warn_noalloc() \
+ __warn_noalloc(__LINE__, __func__)
+#define warn_timeout() \
+ __warn_timeout(__LINE__, __func__)
+#define set_invalid(regs) \
+ __set_invalid((regs), __LINE__, __func__)
+#define set_code_invalid(regs, code) \
+ __set_code_invalid((regs), (code) | (__LINE__ << 8), __func__)
+#define set_unimplemented(regs) \
+ __set_unimplemented((regs), __LINE__, __func__)
+#define set_code_unimplemented(regs, code) \
+ __set_code_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
// kbd.c
void kbd_setup(void);