Import backup from 2003-08-13_2
This commit is contained in:
parent
75c132cbd4
commit
588b3f06ba
74
Functions.c
Normal file
74
Functions.c
Normal file
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
21
functions.h
Normal file
21
functions.h
Normal file
@ -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();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
35
k_defines.h
Normal file
35
k_defines.h
Normal file
@ -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
|
||||
|
||||
|
@ -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...
|
||||
|
||||
|
31
kernel.c
31
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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user