Adds a status bar.

This commit is contained in:
Felix Queißner 2015-08-16 00:45:12 +02:00
parent fc3f73fe16
commit 2faadc29e9
9 changed files with 126 additions and 13 deletions

View file

@ -64,8 +64,8 @@ obj/stdlib.o: src/stdlib.c include/stdlib.h include/varargs.h \
$(CC) $(FLAGS) $(CCFLAGS) -o $@ -c src/stdlib.c
# src/timer.c
obj/timer.o: src/timer.c include/timer.h include/interrupts.h \
include/cpustate.h
obj/timer.o: src/timer.c include/timer.h include/kernel.h \
include/interrupts.h include/cpustate.h
$(CC) $(FLAGS) $(CCFLAGS) -o $@ -c src/timer.c
# src/vmm.c

View file

@ -5,7 +5,7 @@ extern "C" {
#endif
#define CONSOLE_WIDTH 80
#define CONSOLE_HEIGHT 25
#define CONSOLE_HEIGHT 24
#define COLOR_BLACK 0x0
#define COLOR_BLUE 0x1
@ -23,6 +23,12 @@ extern "C" {
#define COLOR_YELLOW 0xE
#define COLOR_WHITE 0xF
/**
* @brief Sets the console status bar
* @param text
*/
void console_setstate(const char *text);
/**
* @brief Sets the cursor position.
* @param x Distance of the cursor from the left border.

View file

@ -25,6 +25,13 @@ time_t __cdecl timer_get();
*/
void __cdecl timer_set(time_t time);
/**
* @brief Adds a callback to the timer.
* @param interval The period time when the callback is called.
* @param callback The callback that is called.
*/
void __cdecl timer_add_callback(time_t interval, void (*callback)(time_t));
/**
* @brief Waits until a certain time elapsed.
* @param ticks The number of ticks to wait

View file

@ -5,7 +5,10 @@ BEGIN
0 -> i;
# Print numbers from 1 to 5
WHILE ((i + 1) -> i) <= 5 DO
BEGIN
printInt(i);
sleep(20);
END
END
PUB fun() -> i : INT

View file

@ -28,6 +28,21 @@ static ConsoleState state = csDefault;
static ConsoleChar *screen = (ConsoleChar*)0xB8000;
static ConsoleChar *statusbar = (ConsoleChar*)(0xB8000 + 0x02 * CONSOLE_WIDTH * CONSOLE_HEIGHT);
void console_setstate(const char *text)
{
for(size_t i = 0; i < CONSOLE_WIDTH; i++) {
statusbar[i].c = ' ';
statusbar[i].color = 0x70;
}
ConsoleChar *ptr = statusbar;
while(*text) {
(ptr++)->c = *text++;
}
}
void ksetpos(int x, int y)
{
if((x >= 0) && (x < CONSOLE_WIDTH))

View file

@ -18,6 +18,41 @@ void die(const char *msg)
}
}
extern size_t mallocCount;
extern size_t freeCount;
extern size_t allocatedMemory;
void update_statusbar(time_t t)
{
size_t a, b;
static char tmp[64];
static char buffer[CONSOLE_WIDTH];
memset(buffer, ' ', sizeof(char) * CONSOLE_WIDTH);
memcpy(&buffer[0], "Malloc: ", 8);
b = 8;
a = strlen(itoa(freeCount, tmp, 10));
memcpy(&buffer[8], tmp, a);
b += a;
buffer[b] = '/'; b++;
a = strlen(itoa(mallocCount, tmp, 10));
memcpy(&buffer[b], tmp, a);
b += a;
b += 2;
a = strlen(itoa(allocatedMemory, tmp, 10));
memcpy(&buffer[b], tmp, a);
b += a;
memcpy(&buffer[b], " Byte", 5);
console_setstate(buffer);
}
static void debug_test()
{
char buffer[64];
@ -31,12 +66,13 @@ static void debug_test()
kprintf("This %s %c test line.\n", "is", 'a');
kprintf("Numbers: %d %i %x %b\n", 15, 15, 15, 15);
/*
///*
kputs("scroll-test:\n");
for(int i = 0; i < 100; i++)
for(int i = 0; i < 10; i++)
{
kprintf("They see me scrolling, they hating! %i\n", i);
}
}
/*
for(int i = 0; i < 272; i++)
{
kprintf("x");
@ -136,7 +172,7 @@ void init(const MultibootStructure *mbHeader)
putsuccess();
kputs("Prepare heap memory:");
for(uintptr_t ptr = 0x400000; ptr < 0x800000; ptr += 4096)
for(uintptr_t ptr = 0x400000; ptr < 0x800000; ptr += 4096)
{
vmm_map(ptr, (uintptr_t)pmm_alloc(), VM_PROGRAM);
}
@ -148,11 +184,11 @@ void init(const MultibootStructure *mbHeader)
kputs("Initialize C++ objects: ");
cpp_init();
putsuccess();
putsuccess();
double f = 1.0;
timer_add_callback(1, update_statusbar);
int i = (int)f;
debug_test();
vm_start();
@ -171,3 +207,8 @@ int main(int argc, char **argv)
void __init_array_start() { }
void __init_array_end() { }

View file

@ -85,7 +85,11 @@ void intr_routine(CpuState *state)
if(handler != nullptr) {
handler(state);
} else {
kprintf("\n\x12\x04Exception [%d] %s!\x12\0x7\n", state->intr, name);
kprintf("\n\x12\x04 Exception [%d] %s!\x12\0x07 \n", state->intr, name);
kprintf(
"EIP: %x"
"",
state->eip);
while(1)
{
__asm__ volatile("cli; hlt");

View file

@ -41,6 +41,9 @@ struct __freelist {
struct __freelist *nx;
};
size_t mallocCount = 0, freeCount = 0;
size_t allocatedMemory = 0;
size_t __malloc_margin = 32;
char * const __malloc_heap_start = (char *)0x400000;
char * const __malloc_heap_end = (char *)0x800000;
@ -50,6 +53,8 @@ struct __freelist *__flp;
void *malloc(size_t len)
{
allocatedMemory += len;
mallocCount++;
struct __freelist *fp1, *fp2, *sfp1, *sfp2;
char *cp;
size_t s, avail;
@ -168,6 +173,7 @@ void *malloc(size_t len)
void free(void *p)
{
freeCount++;
struct __freelist *fp1, *fp2, *fpnew;
char *cp1, *cp2, *cpnew;

View file

@ -1,12 +1,31 @@
#include <timer.h>
#include <stdio.h>
#include <kernel.h>
#include <interrupts.h>
#include "timer.h"
#include "interrupts.h"
#define CALLBACK_COUNT 64
static volatile time_t ticks = 0;
static struct {
time_t interval;
void (*callback)(time_t);
} callbacks[CALLBACK_COUNT];
static void timer_irq()
{
ticks++;
irq_disable();
for(size_t i = 0; i < CALLBACK_COUNT; i++) {
if(callbacks[i].callback != nullptr) {
if((ticks % callbacks[i].interval) == 0) {
callbacks[i].callback(ticks);
}
return;
}
}
irq_enable();
}
void timer_init()
@ -25,6 +44,18 @@ void timer_set(time_t time)
ticks = time;
}
void timer_add_callback(time_t interval, void (*callback)(time_t))
{
for(size_t i = 0; i < CALLBACK_COUNT; i++) {
if(callbacks[i].callback == nullptr) {
callbacks[i].interval = interval;
callbacks[i].callback = callback;
return;
}
}
die("no timer callbacks left.");
}
void sleep(time_t t)
{
uint64_t end = timer_get() + t;