summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-07-08 22:24:57 +0200
committerMichal Idziorek <m.i@gmx.at>2014-07-08 22:24:57 +0200
commit1d5e33d5cc2c68dbe63d9a889432316a514a6fd6 (patch)
treea74c1a2e712fd86dbc7a8233641479dd4cdcce13
parent326eef577054dd8996ec5d16c3db58a4d5fe8948 (diff)
added timer config and setup (PIT)
-rw-r--r--Makefile5
-rw-r--r--kernel/console.c13
-rw-r--r--kernel/kernel.c73
-rw-r--r--kernel/timer.c91
4 files changed, 115 insertions, 67 deletions
diff --git a/Makefile b/Makefile
index 297e6a0..4bb9b25 100644
--- a/Makefile
+++ b/Makefile
@@ -41,7 +41,10 @@ interrupts.o: kernel/interrupts.c kernel/interrupts.h
keyboard.o: kernel/keyboard.c
gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
-kernel.bin: kernel_entry.o kernel.o console.o interrupts.o keyboard.o
+timer.o: kernel/timer.c
+ gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
+
+kernel.bin: kernel_entry.o kernel.o console.o interrupts.o keyboard.o timer.o
ld -o $@ -Ttext 0x1000 --oformat binary -melf_i386 $^ -O0
diff --git a/kernel/console.c b/kernel/console.c
index 70076d5..8ca7ae2 100644
--- a/kernel/console.c
+++ b/kernel/console.c
@@ -17,7 +17,7 @@ void print_char(int x, int y, char c)
print_char_col(x,y,c,SCR_WHITE);
}
-void print_single_hex(int i)
+void print_single_num(int i)
{
if(i<10)print_char_col(posx,posy,'0'+i,SCR_GREEN);
else if(i<16)print_char_col(posx,posy,'A'+i-10,SCR_GREEN);
@@ -62,7 +62,7 @@ void scr_clear()
void scr_put_string_nl(char *str)
{
scr_put_string(str);
- scr_nextline;
+ scr_nextline();
}
void scr_nextline()
@@ -83,6 +83,13 @@ void scr_nextline()
char* video_mem2=(char *)SCR_VIDEOMEM+((x)+i*SCR_REAL_WIDTH)*2;
*video_mem=*video_mem2;
*(video_mem+1)=*(video_mem2+1);
+ //clear last line
+ if(i==SCR_HEIGHT-2)
+ {
+ print_char_col(x,i,'@',SCR_LBLUE);
+
+
+ }
}
}
@@ -106,7 +113,7 @@ void scr_put_hex(uint16_t val)
for(i=0;i<4;i++)
{
- print_single_hex((val&0xf000)>>12);
+ print_single_num((val&0xf000)>>12);
val=val << 4;
}
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 7d845c5..3c7b578 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -3,47 +3,10 @@
// TODO: cleanup . how can i compile it without the includes!??
-
-/// PIT /// Timer stuff
-
-/*
- http://www.brokenthorn.com/Resources/OSDevPit.html
-
- vcc/gnd - voltage/ground
-
- D0-D7 - data lines (data bus)
- wr/rd - writing / reading (system control bus)
- cs - ignore wr/rd or not (address bus)
- a0-a1 (address bus)
-
- // the three 16bit down counters/timers/channels
- clk 0-2 (in)
- gate 0-2 (in)
- out 0-2 (out)
-
-
-
-
- //typical
- out1 -> pic interrupt on every tick (system timer)
- out2 - was used for genearting dram memory refresh (Do not use)
- out3 -> pc speaker
-
- gate pins : depend on mode of operation
- we do have modes 0-5.
-
-
- */
-
-
-
-
-
-
-
///////
void int_kb_handler();
+void int_clock_handler();
////////// KERNEL MAIN///// /////
//
@@ -52,7 +15,7 @@ void int_test_handler()
{
__asm__("pusha");
- scr_put_string_nl("inside software interrupt handler 88");
+ scr_put_string("inside software interrupt handler 88");
__asm__("popa");
@@ -61,27 +24,6 @@ void int_test_handler()
}
-// clock handler
-void int_clock_handler()
-{
- __asm__("pusha");
-
- scr_put_string_nl(".");
-
-
- // todo also the other pic!// TODO
- __asm__("mov $0x20, %al");
- __asm__("out %al, $0x20");
- //
-
- __asm__("popa");
- __asm__("leave");
- __asm__("iret");
- __asm__("popa");
- __asm__("leave");
- __asm__("iret");
-
-}
void kernel_main()
{
@@ -91,11 +33,16 @@ void kernel_main()
// hello message
scr_put_string_nl(KERNEL_HELLO_MESSAGE);
- // init interrupt decriptor table
- // install and enable!
+ //pit config
+ timer_init();
+ scr_put_string_nl("Configured PIT Channel 0 : Mode 2 : 1/25 s.");
+
+
+ // init and interrupt decriptor table
int_init(0x08);
int_install();
+ // setup custom interrupts
// remember that we shifted all interrupts with the pic by 32
// so clock = 32 (irq 0)
// keyboard = 22 (irq 1)
@@ -112,12 +59,12 @@ void kernel_main()
// now we can enable interrupts back again
int_enable();
-
scr_put_string_nl("Interrupts are up and running");
// kernel main loop
while(1)
{
+
}
diff --git a/kernel/timer.c b/kernel/timer.c
new file mode 100644
index 0000000..1f97c92
--- /dev/null
+++ b/kernel/timer.c
@@ -0,0 +1,91 @@
+
+/// PIT /// Timer stuff
+
+/*
+ http://www.brokenthorn.com/Resources/OSDevPit.html
+
+ vcc/gnd - voltage/ground
+
+ D0-D7 - data lines (data bus)
+ wr/rd - writing / reading (system control bus)
+ cs - ignore wr/rd or not (address bus)
+ a0-a1 (address bus)
+
+ // the three 16bit down counters/timers/channels
+ clk 0-2 (in)
+ gate 0-2 (in)
+ out 0-2 (out)
+
+ //typical
+ out1 -> pic interrupt on every tick (system timer)
+ out2 - was used for genearting dram memory refresh (Do not use)
+ out3 -> pc speaker
+
+ gate pins : depend on mode of operation
+ we do have modes 0-5.
+ mode0: counts down to zero , triggers interrupt and waits
+ mode1:
+ mode2: rate generator (sys timer)
+ ....
+
+
+ */
+
+#include "kernel.h"
+
+static uint64_t timer64=0;
+static uint8_t timer8=0;
+
+// clock handler
+void int_clock_handler()
+{
+ __asm__("pusha");
+
+
+ timer64++;
+ timer8++;
+
+ // show point once every 1 second
+ if(timer8==25)
+ {
+ scr_put_string(".");
+ timer8=0;
+ }
+
+
+ // todo also the other pic!// TODO
+ __asm__("mov $0x20, %al");
+ __asm__("out %al, $0x20");
+ //
+
+ __asm__("popa");
+ __asm__("leave");
+ __asm__("iret");
+ __asm__("popa");
+ __asm__("leave");
+ __asm__("iret");
+
+}
+
+void timer_init()
+{
+ // config out timer on channel 0 : mode 2 (sys timer)
+ // http://en.wikipedia.org/wiki/Intel_8253#Control_Word_Register
+ // http://www.brokenthorn.com/Resources/OSDevPit.html
+ // int0 will be triggered ~25 times a second.
+
+ __asm__("pusha");
+
+ __asm__("mov %0, %%dx"::"X" (1193180 / 25));
+
+ __asm__("mov $0b00110100, %al");
+ __asm__("out %al,$0x43");
+
+ __asm__("mov %dx,%ax");
+
+ __asm__("out %al, $0x40");
+ __asm__("xchg %ah,%al");
+ __asm__("out %al, $0x40");
+
+ __asm__("popa");
+}