2017-11-18 17:36:15 +00:00
|
|
|
/*! \file dmesg.c
|
|
|
|
\brief Kernel debug message buffer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include<stdio.h>
|
|
|
|
#include<string.h>
|
|
|
|
|
2017-11-18 19:56:46 +00:00
|
|
|
#define DMESGLEN 2048
|
2017-11-18 17:36:15 +00:00
|
|
|
|
|
|
|
/* These three buffers are declared to be in the .noinit section so
|
|
|
|
that a reboot will not wipe the buffer. Because the memory will be
|
|
|
|
corrupted when power is lost, we manually wipe the buffer at
|
|
|
|
startup if the magic is corrupted or if the index is unreasonable.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//! Ought to be 0xdeadbeef except after power loss.
|
|
|
|
uint32_t dmesg_magic __attribute__ ((section (".noinit")));
|
2017-11-18 19:56:46 +00:00
|
|
|
//! Index within that buffer.
|
|
|
|
int dmesg_index __attribute__ ((section (".noinit")));
|
|
|
|
|
|
|
|
//! DMESG buffer itself.
|
|
|
|
char *dmesg_buffer=(char*)0x2400;
|
2017-11-18 17:36:15 +00:00
|
|
|
|
|
|
|
//! Writes a character to the dmesg buffer.
|
|
|
|
int putchar(int c){
|
2017-12-06 17:07:07 +00:00
|
|
|
dmesg_index++;
|
|
|
|
while(dmesg_index>DMESGLEN)
|
|
|
|
dmesg_index-=DMESGLEN;
|
|
|
|
return dmesg_buffer[dmesg_index]=(char) c;
|
2017-11-18 17:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Clears the dmesg buffer.
|
|
|
|
void dmesg_clear(){
|
|
|
|
memset(dmesg_buffer, 0, DMESGLEN);
|
|
|
|
dmesg_index=0;
|
|
|
|
dmesg_magic=0xdeadbeef;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! I ain't never initialized a buffer that didn't need initializin'.
|
|
|
|
void dmesg_init(){
|
2017-12-06 17:07:07 +00:00
|
|
|
if(dmesg_magic!=0xdeadbeef){
|
2017-11-18 17:36:15 +00:00
|
|
|
dmesg_clear();
|
2017-12-06 17:07:07 +00:00
|
|
|
printf("Zeroed buffer for bad magic.");
|
|
|
|
}
|
2017-11-18 20:05:15 +00:00
|
|
|
printf("\n\n----\n");
|
2017-11-18 17:36:15 +00:00
|
|
|
}
|