summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-06-24 13:53:31 +0200
committerMichal Idziorek <m.i@gmx.at>2014-06-24 13:53:31 +0200
commita99ca43066ba246475809a0e805bf52e8195debd (patch)
tree1883030e358c15231599160ff1ce027b0cc20d22 /kernel
Initial commit of FoolOS
FoolOS - the most useless OS in history.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/kernel.c99
-rw-r--r--kernel/pic.asm67
2 files changed, 166 insertions, 0 deletions
diff --git a/kernel/kernel.c b/kernel/kernel.c
new file mode 100644
index 0000000..665455d
--- /dev/null
+++ b/kernel/kernel.c
@@ -0,0 +1,99 @@
+#define SCR_WIDTH 80
+#define SCR_HEIGHT 23
+
+#define SCR_CTRL 0x3D4
+#define SCR_DATA 0x3D5
+
+#define SCR_BLACK 0x0
+#define SCR_BLUE 0x1
+#define SCR_GREEN 0x2
+#define SCR_CYAN 0x3
+#define SCR_RED 0x4
+// todo...
+# define SCR_WHITE 0xf
+
+
+
+void print_char(int x, int y, char c, char col)
+{
+ char* video_mem=(char *)0xb8000+(x+y*SCR_WIDTH)*2;
+ video_mem[0]=c;
+ video_mem[1]=col;
+}
+
+float func(float x,float y)
+{
+ return x*x*y;
+}
+
+void clear_screen()
+{
+ int x=0;
+ int y=0;
+
+ for(x=0;x<SCR_WIDTH;x++)
+ for(y=2;y<SCR_HEIGHT;y++)
+ print_char(x,y,'R',SCR_BLACK);
+}
+
+void sleep(int i)
+{
+ int x;
+
+ for(x=0;x<i;x++)
+ {
+ __asm__("nop");
+
+ }
+}
+
+void kernel_main()
+{
+
+ int col=0;
+
+ while(1)
+ {
+
+ print_char(0,0,'*',col++%0xf);
+ int0();
+
+ }
+
+}
+
+void kernel_main_joke()
+{
+
+ float time=0;
+ int col=0;
+ int x;
+
+ while(1)
+ {
+ time++;
+ print_char(0,0,'R',col++%0xf);
+ for(x=0;x<SCR_WIDTH;x++)
+ {
+ print_char(x,(2+(int)func((float)x,0.002*(time/100)))%(SCR_HEIGHT-2),'R',SCR_BLUE);
+ }
+ if(time>300)time=0;
+
+ }
+
+}
+
+int cursor=0;
+void int0()
+{
+ int i=0;
+ char codes[]={ 0x1e,0x30,0x2e,0x23,0x24,0x2b,0x34,0x33,0x43,0x3b,0x42,0x4b,0x3a,0x31,0x44,0x43,0x15,0x2d,0x1b,0x2c,0x3c,0x2a,0x1d,0x22,0x35,0x1a};
+
+ char* int_count=(char *)0x7c00+3;
+
+ for(i=0;i<24;i++){
+ if(codes[i]==*int_count)
+ print_char(10,10,'A'+i,0xf);
+ }
+
+}
diff --git a/kernel/pic.asm b/kernel/pic.asm
new file mode 100644
index 0000000..ecbab64
--- /dev/null
+++ b/kernel/pic.asm
@@ -0,0 +1,67 @@
+;************************************************************************
+; Map the 8259A PIC to use interrupts 32-47 within our interrupt table
+;************************************************************************
+
+%define ICW_1 0x11 ; 00010001 binary. Enables initialization mode and we are sending ICW 4
+
+%define PIC_1_CTRL 0x20 ; Primary PIC control register
+%define PIC_2_CTRL 0xA0 ; Secondary PIC control register
+
+%define PIC_1_DATA 0x21 ; Primary PIC data register
+%define PIC_2_DATA 0xA1 ; Secondary PIC data register
+
+%define IRQ_0 0x20 ; IRQs 0-7 mapped to use interrupts 0x20-0x27
+%define IRQ_8 0x28 ; IRQs 8-15 mapped to use interrupts 0x28-0x36
+
+MapPIC:
+
+; Send ICW 1 - Begin initialization -------------------------
+
+ ; Setup to initialize the primary PIC. Send ICW 1
+
+ mov al, ICW_1
+ out PIC_1_CTRL, al
+
+; Send ICW 2 - Map IRQ base interrupt numbers ---------------
+
+ ; Remember that we have 2 PICs. Because we are cascading with this second PIC, send ICW 1 to second PIC command register
+
+ out PIC_2_CTRL, al
+
+ ; send ICW 2 to primary PIC
+
+ mov al, IRQ_0
+ out PIC_1_DATA, al
+
+ ; send ICW 2 to secondary controller
+
+ mov al, IRQ_8
+ out PIC_2_DATA, al
+
+; Send ICW 3 - Set the IR line to connect both PICs ---------
+
+ ; Send ICW 3 to primary PIC
+
+ mov al, 0x4 ; 0x04 => 0100, second bit (IR line 2)
+ out PIC_1_DATA, al ; write to data register of primary PIC
+
+ ; Send ICW 3 to secondary PIC
+
+ mov al, 0x2 ; 010=> IR line 2
+ out PIC_2_DATA, al ; write to data register of secondary PIC
+
+; Send ICW 4 - Set x86 mode --------------------------------
+
+ mov al, 1 ; bit 0 enables 80x86 mode
+
+ ; send ICW 4 to both primary and secondary PICs
+
+ out PIC_1_DATA, al
+ out PIC_2_DATA, al
+
+; All done. Null out the data registers
+
+ mov al, 0
+ out PIC_1_DATA, al
+ out PIC_2_DATA, al
+