Nice printk and file organization

This commit is contained in:
giomba 2018-12-28 11:30:39 +01:00
parent f8fd8740c5
commit 50361931df
5 changed files with 57 additions and 52 deletions

15
include/dbg.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef DBG_H
#define DBG_H
extern "C" int printk(const char* msg);
extern "C" int printkl(const char* msg);
namespace dbg {
char* const UART_RBR = (char* const)0x01c28000;
char* const UART_THR = (char* const)0x01c28000;
char* const UART_IER = (char* const)0x01c28004;
char* const UART_LSR = (char* const)0x01c28014;
}
#endif

19
src/dbg.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <dbg.h>
/* Never call this function directly: always use the printk,
* which disables and reenables interrupts */
extern "C" int c_printk(const char* msg) {
while (*msg != '\0') {
while ((*dbg::UART_LSR & 0x20) == 0); /* Wait for transmission */
*dbg::UART_THR = *msg;
msg++;
}
return 0;
}
extern "C" int printkl(const char* msg) {
printk(msg);
printk("\r\n");
return 0;
}

18
src/dbg.s Normal file
View File

@ -0,0 +1,18 @@
.text
.extern c_printk
.global printk
printk:
push {lr}
/* disables IRQ and FIR in CPU */
cpsid if
/* C-Implementation */
bl c_printk
/* enables IRQ and FIR in CPU */
cpsie if
pop {pc}

View File

@ -1,33 +1,11 @@
#define UART_RBR 0x01c28000 #include <dbg.h>
char* const UART_THR = (char* const)0x01c28000;
#define UART_IER 0x01c28004
char* const UART_LSR = (char* const)0x01c28014;
extern "C" int printk(const char*);
/* KERNEL MAIN */
extern "C" int main(int argc, char** argv) { extern "C" int main(int argc, char** argv) {
char letter[2] = "A"; printkl("Welcome to STKARM -- Simple and Trivial Kernel for Advanced Reduced Instruction Set Computer Machines");
for (char c = 'A'; c < 'Z'; c++) { printkl("EOK -- End of Kernel");
letter[0] = c;
printk("HELLO WORLD!");
printk("\t");
printk(letter);
printk("\r\n");
}
return 0;
}
/* Never call this function directly: always use the printk,
* which disables and reenables interrupts */
extern "C" int c_printk(const char* msg) {
while (*msg != '\0') {
while ((*UART_LSR & 0x20) == 0); /* Wait for transmission */
*UART_THR = *msg;
msg++;
}
return 0; return 0;
} }

View File

@ -1,35 +1,10 @@
.text .text
my_string:
.string "HELLO WORLD!\r\n\r\n"
.quad 0x00
.quad 0x5a
.align 4 .align 4
.global _start .global _start
_start: _start:
bl main bl main
endless_busy_loop: endless_busy_loop:
cpsid if cpsid if
b endless_busy_loop b endless_busy_loop
.extern c_printk
.global printk
printk:
push {lr}
/* disables IRQ and FIR in CPU */
cpsid if
bl c_printk
/* enables IRQ and FIR in CPU */
cpsie if
pop {pc}