summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-07-08 17:04:11 +0200
committerMichal Idziorek <m.i@gmx.at>2014-07-08 17:04:11 +0200
commitb800448bd50d97aeaa6c51303f7024c0046d77ec (patch)
treecaf7300263169d783c4d868403a3d320396fbea4
parent24c2a30b304ac1285db71375e31f46f85b50b1bc (diff)
moved idt stuff to C successfully
-rw-r--r--Makefile2
-rw-r--r--boot/mbr.asm32
-rw-r--r--kernel/console.c48
-rw-r--r--kernel/console.h2
-rw-r--r--kernel/kernel.c188
-rw-r--r--kernel/kernel.h1
6 files changed, 215 insertions, 58 deletions
diff --git a/Makefile b/Makefile
index 3977d62..872c4e3 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ console.o: kernel/console.c kernel/console.h
gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0
kernel.bin: kernel_entry.o kernel.o console.o
- ld -o $@ -Ttext 0x18f8 --oformat binary -melf_i386 $^ -O0
+ ld -o $@ -Ttext 0x1000 --oformat binary -melf_i386 $^ -O0
dump:
vboxmanage debugvm FoolOs dumpguestcore --filename dump.elf
diff --git a/boot/mbr.asm b/boot/mbr.asm
index 93126b1..1e7c53d 100644
--- a/boot/mbr.asm
+++ b/boot/mbr.asm
@@ -38,7 +38,7 @@ BOOT_DRIVE:
; default interrupt handler
interrupt:
- mov al, 0xA0 ; set bit 4 of OCW 2
+ mov al, 0xA0 ; set bit 4 of OCW 1
out 0xA0, al ; write to primary PIC command register
mov al, 0x20 ; set bit 4 of OCW 2
@@ -46,6 +46,7 @@ interrupt:
iret
+
;handle keyboard interrupt
interrupt2:
@@ -70,6 +71,8 @@ interrupt2:
iret
+;;;;;
+
;lets put our temporary GDT (Global Descriptor Table) here
%include "boot/GDT.asm"
@@ -94,7 +97,7 @@ boot_16:
;remember BOOT_DRIVE (as was set by BIOS)
mov [BOOT_DRIVE],dl
-
+
;print FoolOS version info
mov bx, STR_VERSION
call print_string
@@ -125,7 +128,7 @@ boot_32_pm:
mov al, 0xdd ; command 0xdd: enable a20
out 0x64, al ; send command to controller
- lidt [idt_descriptor] ;load descriptor table!
+ ; lidt [idt_descriptor] ;load descriptor table!
;pollkb example
; pollkb:
@@ -140,7 +143,7 @@ boot_32_pm:
;out 0x61, al
- sti ;enable interrupts
+ ; sti ;enable interrupts
;************************************************************************
; Map the 8259A PIC to use interrupts 32-47 within our interrupt table
@@ -221,17 +224,20 @@ out 0xA1, al ; write the value back into IMR
- call KERNEL_OFFSET+(idt_end-idt_start) ;jump into our Kernel it
+ call KERNEL_OFFSET;+(idt_end-idt_start) ;jump into our Kernel it
; will follow our
; interrupt table
-idt_descriptor:
- dw idt_end-idt_start-1
- dd KERNEL_OFFSET
+;idt_descriptor:
+; dw idt_end-idt_start-1
+; dd KERNEL_OFFSET
;;;; DEBUGGING STUFF
times 8 db '@'
+dw interrupt
+times 8 db '@'
+dw interrupt2
times 8 db '@'
@@ -242,11 +248,11 @@ times 510-($-$$) db 0
dw 0xaa55
;interrupt descriptor table (hardcoded address of interrupts:)
-idt_start:
-times 33 db 0x50,0x7c,0x08,0x00,0x00,10001110b,0x0,0x0
-db 0x59,0x7c,0x08,0x00,0x00,10001110b,0x0,0x0
-times 253 db 0x50,0x7c,0x08,0x00,0x00,10001110b,0x0,0x0
-idt_end:
+;idt_start:
+;times 33 db 0x50,0x7c,0x08,0x00,0x00,10001110b,0x0,0x0
+;db 0x59,0x7c,0x08,0x00,0x00,10001110b,0x0,0x0
+;times 253 db 0x50,0x7c,0x08,0x00,0x00,10001110b,0x0,0x0
+;idt_end:
diff --git a/kernel/console.c b/kernel/console.c
index 48e5ee7..d5d4573 100644
--- a/kernel/console.c
+++ b/kernel/console.c
@@ -7,9 +7,27 @@ static int posy=0;
void print_nextline()
{
+ int i,x;
+
posx=0;
posy++;
- if(posy>SCR_HEIGHT-2)posy=0;
+
+ if(posy>SCR_HEIGHT-2)
+ {
+ for(i=1;i<SCR_HEIGHT-1;i++)
+ {
+
+ for(x=1;x<SCR_WIDTH;x++)
+ {
+ char* video_mem=(char *)SCR_VIDEOMEM+((x)+(i-1)*SCR_WIDTH)*2;
+ char* video_mem2=(char *)SCR_VIDEOMEM+((x)+i*SCR_WIDTH)*2;
+
+ *video_mem=*video_mem2;
+ }
+ }
+
+ posy--;
+ }
}
void print_hex(uint16_t val)
@@ -32,6 +50,34 @@ void print_hex(uint16_t val)
}
+void print_string(char *str)
+{
+
+ while(*str!=0)
+ {
+ print_char(posx++,posy,*(str++));
+ }
+}
+
+void console_clear_screen()
+{
+ int x,y;
+ for(x=0;x<SCR_WIDTH;x++)
+ for(y=0;y<SCR_WIDTH;y++)
+ {
+ print_char_col(x,y," ",SCR_BLACK);
+
+ }
+ posx=posy=0;
+
+}
+
+
+
+
+
+// helper_funcs
+
void print_single_hex(int i)
{
if(i<10)print_char_col(posx,posy,'0'+i,SCR_GREEN);
diff --git a/kernel/console.h b/kernel/console.h
index e304773..b834289 100644
--- a/kernel/console.h
+++ b/kernel/console.h
@@ -18,7 +18,9 @@
//autoscroll
void print_nextline();
+void print_string(char *str);
void print_hex(uint16_t val);
+void console_clear_screen();
//no autoscroll
void print_str(int x,int y,char *str);
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 6719cdc..584b5c8 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -1,11 +1,12 @@
#include <stdint.h>
+#include "kernel.h" // general kernel config
#include "console.h" // this will allow us to write to screen
//// interrupt stuff /////
//
#define INT_MAX 255
-
+//
// interrupt descriptor table
static struct int_desc
@@ -18,31 +19,55 @@ static struct int_desc
} idt[INT_MAX];
-static struct int_desc *idt_old=0x1000;
-
// interrupt descriptor table descriptor
static struct idt_desc
{
uint16_t size;
- uint32_t base;
+ uint16_t baseLo;
+ uint16_t baseHi;
} idtd;
-volatile char col=100;
+int unhandled=0;
+
+char col=100;
char col2=0;
int cursor=0;
char last_code=0;
+uint8_t kb_in;
+
+void int_def_handler()
+{
+ __asm__("pusha");
+
+ unhandled++;
+
+ // todo also the other pic!
+ __asm__("mov $0x20, %al");
+ __asm__("out %al, $0x20");
+
+ __asm__("popa");
+ __asm__("leave");
+ __asm__("iret");
+
+}
-volatile void int_def_handler()
+void int_kb_handler()
{
__asm__("pusha");
- col++;
- print_str(5,5,"Interrupted");
+ __asm__("in $0x60, %al");
+ __asm__("mov %%al, %0"::"m" (kb_in));
+
+ int0(kb_in);
+
+ __asm__("mov $0x20, %al");
+ __asm__("out %al, $0x20");
__asm__("popa");
+ __asm__("leave");
__asm__("iret");
}
@@ -51,40 +76,43 @@ void int_init(uint16_t sel)
{
int i;
+ /*
idtd.size=sizeof(struct int_desc)*INT_MAX-1; // why the -1 ??
idtd.base=(uint32_t)&idt[0];
+ */
for(i=0; i<INT_MAX; i++)
{
- int_install_ir(i, 0b10001110, sel, &int_def_handler);
-// int_install_ir(i, 0b10001110, sel, 0x7c50);
+// if(i==0)int_install_ir(i, 0, 0,0);
+ if(i==33)int_install_ir(i, 0b10001110, sel,&int_kb_handler);
+ else int_install_ir(i, 0b10001110, sel,&int_def_handler);
+ //if(i==0)int_install_ir(i, 0, 0,0);
}
- int_install_ir(0, 0, 0, 0);
-
}
void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr)
{
uint64_t base=(uint64_t)&(*addr);
-// uint32_t base=addr;
- idt_old[irq].addrLo = base & 0xffff;
- idt_old[irq].addrHi = (base >> 16) & 0xffff;
-
- idt_old[irq].addrLo = 0x087c;
- idt_old[irq].addrHi = 0x0;
-
- idt_old[irq].zeros=0;
- idt_old[irq].flags=flags;
- idt_old[irq].sel=sel;
+ idt[irq].addrLo = base & 0xffff;
+ idt[irq].addrHi = (base >> 16) & 0xffff;
+ idt[irq].addrHi = 0x0;
+ idt[irq].zeros=0;
+ idt[irq].flags=flags;
+ idt[irq].sel=sel;
}
void int_install()
{
+
+ idtd.size=8*34;
+ idtd.baseHi=0x0000;
+ idtd.baseLo=&idt[0];
+
__asm__("lidt %0"::"m" (idtd));
}
@@ -101,35 +129,109 @@ void int_enable()
void kernel_main()
{
- char str[]="ABC";
+
+ console_clear_screen();
+
+ //
+ print_string(KERNEL_HELLO_MESSAGE);
+ print_nextline();
+ print_nextline();
+ //
+
+ // address of our initial idt (set up by bootloader)
+ //uint16_t *ptr3=0x1000;
+ uint16_t *ptr3=&idt[0];
+ //uint16_t *ptr3=0x2040;
+
+ // debugging idt:
+ // int_install_ir(34,0x0,0xaabb,0x1234);
+ //int_install_ir(33,0b1000110,0x8,&int_def_handler);
+
+
+ print_string("idt located: ");
+ print_hex(ptr3);
+ print_nextline();
+
+ // init idt;
+ int_init(0x08);
+
+ // first two bytes as chars
+ int offset;
+ for(offset=32;offset<40;offset++)
+ {
+ print_hex(offset-32); //irq
+ print_string(" -> ");
+ print_hex(*(ptr3+offset*4)); //addrLo
+ print_hex(*(ptr3+1+offset*4)); //sel
+ print_hex(*(ptr3+2+offset*4)); //zeros & flags
+ print_hex(*(ptr3+3+offset*4)); //addrHi
+ print_nextline();
+ }
+
+
+ //
+ // print_nextline();
+ // print_nextline();
+
+// print_hex(*ptr2);
+
+ // print_nextline();
+ // print_nextline();
// int_init(0x08); // offset in GDT (CODE_SEG)
- int_install_ir(33,0b1000110,0x8,&int_def_handler);
- int_install_ir(33,0b1000110,0x8,0x087c);
- // int_install();
- // int_enable();
+ // int_install_ir(33,0b1000110,0x8,0x087c);
+
- print_str(0,0,"Interrupts Enabled");
+ //int_install_ir(33, 0b10001110, 0x8, 0x7c50);
+ int_install();
+ int_enable();
+
+
+ //print_str(0,0,"Interrupts Enabled");
+ //
+ /*
+ int irq=32;
+ for (irq=32;irq<32+16;irq++)
+ {
+ print_string("irq:");
+ print_hex(irq);
+
+ print_string(" -> ");
+ print_hex(idt_old[irq].addrLo);
+ print_string(" ");
+ print_hex(idt_old[irq].addrHi);
+ print_string(" ");
+ print_hex(idt_old[irq].sel);
+ print_nextline();
+ }
+*/
while(1)
{
- print_str_col(0,0,str,col);
- print_str_col(0,2,str,col2++);
- int0();
+
+// print_nextline();
+
+// print_str_col(0,0,"ABC",col);
+// print_str_col(1,SCR_HEIGHT,"(*)",col2++);
+
+ //int0();
}
+ print_hex(*(ptr3));
+ print_nextline();
}
-void int0()
+void int0(uint8_t in)
{
int i=0;
- char* int_count=(char *)0x7c00+3;
+ //
+ //print_hex(int_count);
- char make_codes[]={
+ uint8_t make_codes[]={
0x1e, // A
0x30, // B
0x2e, // C
@@ -158,7 +260,7 @@ void int0()
0x2c, // Z
};
- char break_codes[]={
+ uint8_t break_codes[]={
0x9e, // A
0xb0, // B
0xae, // C
@@ -187,24 +289,24 @@ void int0()
0xac, // Z
};
- print_str(6,6,*int_count);
- if(last_code==*int_count)return;
+ //if(last_code==*int_count)return;
for(i=0;i<26;i++)
{
- if(make_codes[i]==*int_count)
+ if(make_codes[i]==in)
{
- print_char_col(cursor,10,'A'+i,0xf);
+ print_char_col(cursor,20,'A'+i,0xf);
}
}
-
+
for(i=0;i<26;i++)
{
- if(break_codes[i]==*int_count)
+ if(break_codes[i]==in)
{
- print_char_col(cursor++,10,'a'+i,SCR_RED);
+ print_char_col(cursor++,20,'a'+i,SCR_RED);
}
}
- last_code=*int_count;
+ last_code=in;
+
}
diff --git a/kernel/kernel.h b/kernel/kernel.h
new file mode 100644
index 0000000..8df13ad
--- /dev/null
+++ b/kernel/kernel.h
@@ -0,0 +1 @@
+#define KERNEL_HELLO_MESSAGE "FoolOs 0.0.1"