ChinOS
内核library
在微内核操作系统中,内核中通常也是需要使用到一些C库,例如:
- stdio:printf/scanf
- string:memset/memcpy
- other
所以本节,我们需要向内核中移植一个微版的libc库
uart驱动
串口基本已经独立于芯片IP为单独外设,一般SOC会集成PL011或者DW8250/16550等UART模块
uart输出
void uart_init(unsigned long base)
{
pl011_dev.base = base;
}
void uart_putchar(char c)
{
if (c == '\n') {
uart_putchar('\r');
}
while ((getreg64(pl011_dev.base + UARTFR) & UARTFR_TXFF) != 0);
putreg64(c, pl011_dev.base + UARTDR);
}
uart初始化
通过uart_init把QEMU-virt pl011的串口MMIO地址进行初始化
void BOOTPHYSIC boot_setup_mmu(void)
{
uart_init(UART_PBASE);
kprintf("hallo world\n");
while(1);
}
fpu初始化
在libc中,我们会使用除法,需要提前开启FPU
// 使能浮点单元
#ifdef CONFIG_ARCH_FPU
bl fpu_init
#endif
QEMU仿真
./simulate