From 588b3f06ba4b29a583526eed766dab64fdd8f2a2 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 13 Aug 2003 22:01:00 -0400 Subject: [PATCH] Import backup from 2003-08-13_2 --- Functions.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ functions.h | 21 +++++++++++++++ k_defines.h | 35 +++++++++++++++++++++++++ kernel.asm | 2 +- kernel.c | 31 ++++++++++++++-------- 5 files changed, 152 insertions(+), 11 deletions(-) create mode 100644 Functions.c create mode 100644 functions.h create mode 100644 k_defines.h diff --git a/Functions.c b/Functions.c new file mode 100644 index 0000000..b64a250 --- /dev/null +++ b/Functions.c @@ -0,0 +1,74 @@ +//Functions.c +//05/07/03 Josh Holtrop +//for HOS + + +inline void outportb(unsigned int port, unsigned char value) // Output a byte to a port +{ + asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value)); +}; + +inline void outportw(unsigned int port, unsigned int value) // Output a word to a port +{ + asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value)); +}; + +inline UCHAR inportb(unsigned short port) +{ + unsigned char ret_val; + + asm volatile("inb %w1,%b0" + : "=a"(ret_val) + : "d"(port)); + return ret_val; +}; + +void enable_ints() +{ + asm("sti"); +}; + +void disable_ints() +{ + asm("cli"); +}; + +void remap_pics(int pic1, int pic2) +{ + UCHAR a1, a2; + + a1 = inportb(PIC1_DATA); + a2 = inportb(PIC2_DATA); + + outportb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4); + outportb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4); + outportb(PIC1_DATA, pic1); + outportb(PIC2_DATA, pic2); + outportb(PIC1_DATA, 4); + outportb(PIC2_DATA, 2); + outportb(PIC1_DATA, ICW4_8086); + outportb(PIC2_DATA, ICW4_8086); + + outportb(PIC1_DATA, a1); + outportb(PIC2_DATA, a2); +}; + +inline void restart() +{ + outportb (0x64, 0xfe); + for (;;) + { + } +} + +inline void eoi() +{ + outportb(0x20, 0x20); //EOI +} + + + + + + + diff --git a/functions.h b/functions.h new file mode 100644 index 0000000..d6644c8 --- /dev/null +++ b/functions.h @@ -0,0 +1,21 @@ +//functions.h +//05/07/03 Josh Holtrop +//for HOS + + + +inline void outportb(unsigned int port, unsigned char value); +inline void outportw(unsigned int port, unsigned int value); +inline UCHAR inportb(unsigned short port); +void enable_ints(); +void disable_ints(); +inline void restart(); +void remap_pics(int pic1, int pic2); +inline void eoi(); + + + + + + + diff --git a/k_defines.h b/k_defines.h new file mode 100644 index 0000000..a2c0112 --- /dev/null +++ b/k_defines.h @@ -0,0 +1,35 @@ +//k_defines.h +//03/17/03 Josh Holtrop + +#define PIC1 0x20 +#define PIC2 0xA0 +#define PIC1_COMMAND PIC1 +#define PIC1_DATA (PIC1+1) +#define PIC2_COMMAND PIC2 +#define PIC2_DATA (PIC2+1) +#define PIC_EOI 0x20 + +#define ICW1_ICW4 0x01 /* ICW4 (not) needed */ +#define ICW1_SINGLE 0x02 /* Single (cascade) mode */ +#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */ +#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */ +#define ICW1_INIT 0x10 /* Initialization - required! */ + +#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */ +#define ICW4_AUTO 0x02 /* Auto (normal) EOI */ +#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */ +#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */ +#define ICW4_SFNM 0x10 /* Special fully nested (not) */ + +#define BLUE_TXT 0x01 +#define RED_TXT 0x04 +#define WHITE_TXT 0x07 +#define CYAN_TXT 0x0B +#define YELLOW_TXT 0x0E +#define BRWHITE_TXT 0x0F + +#define UCHAR unsigned char +#define USHORT unsigned short +#define UINT unsigned int + + diff --git a/kernel.asm b/kernel.asm index 6e88aa8..7f32c79 100644 --- a/kernel.asm +++ b/kernel.asm @@ -51,7 +51,7 @@ newgdtcontinue: mov esp, 0x1ffffc ;stack just under 2mb, moves downward lidt [idtr] ;load idt - jmp _k_init + call _k_init hlt ;halt processor when k_init is done jmp $ ;shouldn't get here... diff --git a/kernel.c b/kernel.c index 298c8e6..ba4795f 100644 --- a/kernel.c +++ b/kernel.c @@ -1,22 +1,33 @@ +//kernel.c +//08/13/03 Josh Holtrop +//Holtrop's Operating System + +#include "k_defines.h" +#include "functions.h" void isr(int num); void k_init(); +#include "functions.c" + + void k_init() { - char *vidmem = (char *) 0xB8000; - char welcome[] = "Welcome to HOS kernel. You are now in protected mode."; - char *chrptr = welcome; - while (*chrptr != 0) - { - *vidmem++ = *chrptr++; - *vidmem++ = 15; - } - + remap_pics(0x20, 0x28); + //set timer : 2e9c = 100hz + outportb(0x43, 0x34); + outportb(0x40, 0x9c); //lsb + outportb(0x40, 0x2e); //msb + enable_ints(); } void isr(int num) { - + if (num == 0x20) + { + (*(char*)0xB8000)++; + *(char*)0xB8001 = 7; + } + eoi(); }