mirror of
https://github.com/cccriscv/mini-riscv-os.git
synced 2025-11-16 12:34:33 +00:00
init
This commit is contained in:
22
01-HelloOs/os.c
Normal file
22
01-HelloOs/os.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdint.h>
|
||||
|
||||
// ref: https://www.activexperts.com/serial-port-component/tutorials/uart/
|
||||
#define UART 0x10000000
|
||||
#define UART_THR (uint8_t*)(UART+0x00) // THR:transmitter holding register
|
||||
#define UART_LSR (uint8_t*)(UART+0x05) // LSR:line status register
|
||||
#define UART_LSR_EMPTY_MASK 0x40 // LSR Bit 6: Transmitter empty; both the THR and LSR are empty
|
||||
|
||||
int lib_putc(char ch) {
|
||||
while ((*UART_LSR & UART_LSR_EMPTY_MASK) == 0);
|
||||
return *UART_THR = ch;
|
||||
}
|
||||
|
||||
void lib_puts(char *s) {
|
||||
while (*s) lib_putc(*s++);
|
||||
}
|
||||
|
||||
int os_main(void)
|
||||
{
|
||||
lib_puts("Hello OS!\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user