add some asserts
This commit is contained in:
parent
605507a688
commit
39c778d2f0
7 changed files with 34 additions and 6 deletions
3
Makefile
3
Makefile
|
|
@ -16,7 +16,7 @@ define DEFAULT_VAR =
|
|||
endef
|
||||
|
||||
# User controllable CFLAGS.
|
||||
CFLAGS ?= -g -O2 -pipe -Wall -Wextra
|
||||
CFLAGS ?= -g -O0 -pipe -Wall -Wextra
|
||||
|
||||
# User controllable linker flags. We set none by default.
|
||||
LDFLAGS ?=
|
||||
|
|
@ -30,6 +30,7 @@ override CFLAGS += \
|
|||
-fno-lto \
|
||||
-fno-pie \
|
||||
-fno-pic \
|
||||
-DKDEBUG \
|
||||
-m64 \
|
||||
-march=x86-64 \
|
||||
-mabi=sysv \
|
||||
|
|
|
|||
10
dev/pci.c
10
dev/pci.c
|
|
@ -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;
|
||||
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);
|
||||
tmp = (uint16_t)((inl(PCIPM_CONFIG_DATA) >> ((offset & 2) << 3)) & 0xFFFF);
|
||||
|
|
@ -26,10 +26,12 @@ static void pci_print_bus(uint8_t bus)
|
|||
continue;
|
||||
|
||||
uint8_t class = pci_config_read_word(bus, slot, 0, 0xA);
|
||||
uint8_t subclass = (pci_config_read_word(bus, slot, 0, 0xA) >> 8);
|
||||
uint8_t prog_if = (pci_config_read_word(bus, slot, 0, 0x8) >> 8);
|
||||
if(class == 0xFF)
|
||||
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
17
include/assert.h
Normal 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_ */
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <kernel/bitwise.h>
|
||||
|
||||
|
|
@ -20,6 +21,8 @@
|
|||
#define MB (1024 * KB)
|
||||
#define GB (1024 * MB)
|
||||
|
||||
void yield();
|
||||
|
||||
typedef uintptr_t paddr_t;
|
||||
|
||||
#endif /* _COMMON_H_ */
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ void kmain(void)
|
|||
console_init();
|
||||
acpi_init();
|
||||
|
||||
pci_init();
|
||||
|
||||
_pic_init();
|
||||
|
||||
void *kstack = buddy_alloc(KSTACK_SIZE);
|
||||
|
|
@ -74,8 +76,6 @@ void kmain(void)
|
|||
|
||||
void kmain_post_stack_init()
|
||||
{
|
||||
pci_init();
|
||||
|
||||
printf("\n\n# ");
|
||||
yield();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ printf_reverse:
|
|||
printf_out(buf[(n - 1) - j]);
|
||||
ret++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
printf_out(c);
|
||||
|
|
|
|||
|
|
@ -219,6 +219,9 @@ void buddy_free(void *ptr)
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* should never happen */
|
||||
assert(0);
|
||||
}
|
||||
|
||||
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) {
|
||||
pml4 = alloc_page();
|
||||
assert(pml4 != NULL);
|
||||
memset(pml4, 0, 0x1000);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue