add some asserts

This commit is contained in:
Michael Shaw 2023-05-04 02:02:17 -04:00
commit 39c778d2f0
7 changed files with 34 additions and 6 deletions

View file

@ -16,7 +16,7 @@ define DEFAULT_VAR =
endef endef
# User controllable CFLAGS. # User controllable CFLAGS.
CFLAGS ?= -g -O2 -pipe -Wall -Wextra CFLAGS ?= -g -O0 -pipe -Wall -Wextra
# User controllable linker flags. We set none by default. # User controllable linker flags. We set none by default.
LDFLAGS ?= LDFLAGS ?=
@ -30,6 +30,7 @@ override CFLAGS += \
-fno-lto \ -fno-lto \
-fno-pie \ -fno-pie \
-fno-pic \ -fno-pic \
-DKDEBUG \
-m64 \ -m64 \
-march=x86-64 \ -march=x86-64 \
-mabi=sysv \ -mabi=sysv \

View file

@ -10,7 +10,7 @@ uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t o
uint32_t lfunc = func; uint32_t lfunc = func;
uint16_t tmp = 0; uint16_t tmp = 0;
addr = (lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xfc) | ((uint32_t)0x80000000); addr = (lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xfc) | 0x80000000;
outl(PCIPM_CONFIG_ADDRESS, addr); outl(PCIPM_CONFIG_ADDRESS, addr);
tmp = (uint16_t)((inl(PCIPM_CONFIG_DATA) >> ((offset & 2) << 3)) & 0xFFFF); tmp = (uint16_t)((inl(PCIPM_CONFIG_DATA) >> ((offset & 2) << 3)) & 0xFFFF);
@ -26,10 +26,12 @@ static void pci_print_bus(uint8_t bus)
continue; continue;
uint8_t class = pci_config_read_word(bus, slot, 0, 0xA); uint8_t class = pci_config_read_word(bus, slot, 0, 0xA);
uint8_t subclass = (pci_config_read_word(bus, slot, 0, 0xA) >> 8); if(class == 0xFF)
uint8_t prog_if = (pci_config_read_word(bus, slot, 0, 0x8) >> 8); continue;
printf(LOG_INFO "PCI device: vendor:%xh class:%xh subclass:%xh prof_if:%xh\n", vendor_id, class, subclass, prog_if); uint8_t subclass = (pci_config_read_word(bus, slot, 0, 0xA) >> 8);
printf(LOG_INFO "PCI device [bus:%xh slot:%xh]: class=%xh sub=%xh\n", bus, slot, class, subclass);
} }
} }

17
include/assert.h Normal file
View file

@ -0,0 +1,17 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _ASSERT_H_
#define _ASSERT_H_
#ifdef KDEBUG
#define assert(expr) \
do { \
if (!(expr)) { \
printf(LOG_ERROR "assertion failed: %s, file %s, line %d\n", #expr, __FILE__, __LINE__); \
yield(); \
} \
} while (0)
#else
#define assert(expr) ((void)0)
#endif
#endif /* _ASSERT_H_ */

View file

@ -10,6 +10,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <assert.h>
#include <kernel/bitwise.h> #include <kernel/bitwise.h>
@ -20,6 +21,8 @@
#define MB (1024 * KB) #define MB (1024 * KB)
#define GB (1024 * MB) #define GB (1024 * MB)
void yield();
typedef uintptr_t paddr_t; typedef uintptr_t paddr_t;
#endif /* _COMMON_H_ */ #endif /* _COMMON_H_ */

View file

@ -65,6 +65,8 @@ void kmain(void)
console_init(); console_init();
acpi_init(); acpi_init();
pci_init();
_pic_init(); _pic_init();
void *kstack = buddy_alloc(KSTACK_SIZE); void *kstack = buddy_alloc(KSTACK_SIZE);
@ -74,8 +76,6 @@ void kmain(void)
void kmain_post_stack_init() void kmain_post_stack_init()
{ {
pci_init();
printf("\n\n# "); printf("\n\n# ");
yield(); yield();
} }

View file

@ -102,6 +102,7 @@ printf_reverse:
printf_out(buf[(n - 1) - j]); printf_out(buf[(n - 1) - j]);
ret++; ret++;
} }
break;
} }
} else { } else {
printf_out(c); printf_out(c);

View file

@ -219,6 +219,9 @@ void buddy_free(void *ptr)
return; return;
} }
} }
/* should never happen */
assert(0);
} }
static void *kmap_alloc_page() static void *kmap_alloc_page()
@ -262,6 +265,7 @@ void kmap(paddr_t paddr, uint64_t vaddr, size_t len, uint64_t attr)
if (pml4 == NULL) { if (pml4 == NULL) {
pml4 = alloc_page(); pml4 = alloc_page();
assert(pml4 != NULL);
memset(pml4, 0, 0x1000); memset(pml4, 0, 0x1000);
} }