Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5da602b162 | ||
|
|
7a0351e123 | ||
|
|
3dc0fe5e2b | ||
|
|
82da40c9f0 | ||
|
|
8d5b28f823 | ||
|
|
68fd6cad70 | ||
|
|
c3309d4e5d | ||
|
|
06d7cbef47 | ||
|
|
e8b1abb265 |
No files matched your search
+33
-13
@@ -37,21 +37,31 @@ void remap_pics(int pic1, int pic2)
|
|||||||
{
|
{
|
||||||
byte a1, a2;
|
byte a1, a2;
|
||||||
|
|
||||||
a1 = inportb(PIC1_DATA);
|
a1 = inportb(PIC1_DATA); //0x21
|
||||||
a2 = inportb(PIC2_DATA);
|
a2 = inportb(PIC2_DATA); //0xA1
|
||||||
|
|
||||||
outportb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4);
|
outportb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4); //0x20, 0x10+0x01 00010001b
|
||||||
outportb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4);
|
outportb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4); //0xA0, 0x10+0x01 00010001b
|
||||||
outportb(PIC1_DATA, pic1);
|
outportb(PIC1_DATA, pic1); //0x21, pic1
|
||||||
outportb(PIC2_DATA, pic2);
|
outportb(PIC2_DATA, pic2); //0xA1, pic2
|
||||||
outportb(PIC1_DATA, 4);
|
outportb(PIC1_DATA, 4); //0x21, 0x04 00000100b
|
||||||
outportb(PIC2_DATA, 2);
|
outportb(PIC2_DATA, 2); //0xA1, 0x02 00000010b
|
||||||
outportb(PIC1_DATA, ICW4_8086);
|
outportb(PIC1_DATA, ICW4_8086); //0x21, 0x01 00000001b
|
||||||
outportb(PIC2_DATA, ICW4_8086);
|
outportb(PIC2_DATA, ICW4_8086); //0xA1, 0x01 00000001b
|
||||||
|
|
||||||
outportb(PIC1_DATA, a1);
|
outportb(PIC1_DATA, a1); //0x21
|
||||||
outportb(PIC2_DATA, a2);
|
outportb(PIC2_DATA, a2); //0xA1
|
||||||
};
|
}
|
||||||
|
|
||||||
|
inline void pic1_mask(byte mask)
|
||||||
|
{
|
||||||
|
outportb(PIC1_DATA, mask); //0x21, maskfield *OCW1*
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void pic2_mask(byte mask)
|
||||||
|
{
|
||||||
|
outportb(PIC2_DATA, mask); //0xA1, maskfield *OCW1*
|
||||||
|
}
|
||||||
|
|
||||||
inline void restart()
|
inline void restart()
|
||||||
{
|
{
|
||||||
@@ -66,6 +76,16 @@ inline void eoi()
|
|||||||
outportb(0x20, 0x20); //EOI
|
outportb(0x20, 0x20); //EOI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void eoi2()
|
||||||
|
{
|
||||||
|
outportb(0xA0, 0x20);
|
||||||
|
outportb(0x20, 0x20);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ void enable_ints();
|
|||||||
void disable_ints();
|
void disable_ints();
|
||||||
inline void restart();
|
inline void restart();
|
||||||
void remap_pics(int pic1, int pic2);
|
void remap_pics(int pic1, int pic2);
|
||||||
|
inline void pic1_mask(byte mask);
|
||||||
|
inline void pic2_mask(byte mask);
|
||||||
inline void eoi();
|
inline void eoi();
|
||||||
|
inline void eoi2();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
#define FREERAM_START 0x268000
|
#define FREERAM_START 0x268000
|
||||||
|
|
||||||
|
#define KERNEL_PID 0x02
|
||||||
|
|
||||||
typedef unsigned char byte;
|
typedef unsigned char byte;
|
||||||
typedef unsigned short word;
|
typedef unsigned short word;
|
||||||
typedef unsigned int dword;
|
typedef unsigned int dword;
|
||||||
|
|||||||
@@ -14,10 +14,12 @@
|
|||||||
#include "video.h"
|
#include "video.h"
|
||||||
#include "mm.h"
|
#include "mm.h"
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
|
#include "mouse.h"
|
||||||
|
|
||||||
void isr(dword num);
|
void isr(dword num);
|
||||||
void k_init();
|
void k_init();
|
||||||
|
|
||||||
|
#include "mouse.c"
|
||||||
#include "keyboard.c"
|
#include "keyboard.c"
|
||||||
#include "mm.c"
|
#include "mm.c"
|
||||||
#include "functions.c"
|
#include "functions.c"
|
||||||
@@ -27,65 +29,76 @@ dword timer = 0;
|
|||||||
|
|
||||||
void k_init()
|
void k_init()
|
||||||
{
|
{
|
||||||
|
console_cls();
|
||||||
remap_pics(0x20, 0x28);
|
remap_pics(0x20, 0x28);
|
||||||
//set timer : 2e9c = 100hz
|
//set timer : 2e9c = 100hz
|
||||||
outportb(0x43, 0x34);
|
outportb(0x43, 0x34);
|
||||||
outportb(0x40, 0x9c); //lsb
|
outportb(0x40, 0x9c); //lsb
|
||||||
outportb(0x40, 0x2e); //msb
|
outportb(0x40, 0x2e); //msb
|
||||||
video_init((ModeInfoBlock *) 0x90306);
|
video_init((ModeInfoBlock *) 0x90306);
|
||||||
mm_init();
|
video_rectf(VXR*3/11, 0, VXR*4/11, VYR-1, 0x00000088); //test rectangles, draws "HOS"
|
||||||
enable_ints();
|
video_rectf(VXR*7/11, 0, VXR*8/11, VYR-1, 0x00000088);
|
||||||
console_cls();
|
video_rectf(VXR/11, 0, VXR*2/11, VYR*2/5, 0x00000088);
|
||||||
printf("Memory available to OS: %d MB\n (Bytes: %d)", mm_totalmem/0x100000, mm_totalmem);
|
video_rectf(VXR/11, VYR*3/5, VXR*2/11, VYR-1, 0x00000088);
|
||||||
|
video_rectf(VXR*5/11, VYR/5, VXR*6/11, VYR*4/5, 0x00000088);
|
||||||
|
video_rectf(VXR*9/11, VYR/5, VXR-1, VYR*2/5, 0x00000088);
|
||||||
|
video_rectf(VXR*8/11, VYR*3/5, VXR*10/11, VYR*4/5, 0x00000088);
|
||||||
|
|
||||||
for (;;)
|
video_vert(10, 10, 16, 0x00ffff00); //should be yellow 'H'
|
||||||
printf("%c ", kbdWaitKey());
|
video_horiz(13, 10, 14, 0x00ffff00);
|
||||||
/* pageblock *pb = first_pageblock;
|
video_vert(14, 10, 16, 0x00ffff00);
|
||||||
|
|
||||||
|
video_horiz(10, 17, 21, 0x00ffff00);
|
||||||
|
video_vert(19, 10, 16, 0x00ffff00);
|
||||||
|
video_horiz(16, 17, 21, 0x00ffff00);
|
||||||
|
|
||||||
|
int a, b;
|
||||||
|
for (a = 0; a < 256; a++)
|
||||||
|
{
|
||||||
|
for (b = 0; b < 256; b++)
|
||||||
|
{
|
||||||
|
video_pset(a+5, b+30, (a<<16)|(b<<8));
|
||||||
|
video_pset(a+270, b+30, (a<<8)|(b));
|
||||||
|
video_pset(a+535, b+30, (a<<16)|(b));
|
||||||
|
|
||||||
|
video_pset(a+5, b+290, (a<<16)|(b<<8)|0x000000ff);
|
||||||
|
video_pset(a+270, b+290, (a<<8)|(b)|0x00ff0000);
|
||||||
|
video_pset(a+535, b+290, (a<<16)|(b)|0x0000ff00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mm_init();
|
||||||
|
mouse_init();
|
||||||
|
enable_ints();
|
||||||
|
printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem);
|
||||||
|
pic1_mask(0); //unmask IRQ's 0-7
|
||||||
|
pic2_mask(0); //unmask IRQ's 8-15
|
||||||
|
dword key = 0;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (pb->flags == MM_PB_NP)
|
key = kbdWaitKey();
|
||||||
break;
|
putc(key);
|
||||||
printf("\nBase: 0x%x; Limit: 0x%x; Flags: 0x%x, Link: 0x%x", pb->base, pb->length, pb->flags, pb->link);
|
}
|
||||||
pb = (pageblock *) pb->link;
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void isr(dword num)
|
void isr(dword num)
|
||||||
{
|
{
|
||||||
switch(num)
|
switch(num)
|
||||||
{
|
{
|
||||||
case 0x20:
|
case 0x20: // IRQ0 - timer interrupt
|
||||||
timer++;
|
timer++;
|
||||||
(*(byte *)0xb8000)++;
|
(*(byte *)0xb8000)++;
|
||||||
switch(timer)
|
|
||||||
{
|
|
||||||
case 150:
|
|
||||||
video_rectf(VXR*3/11, 0, VXR*4/11, VYR-1, 0x00000088);
|
|
||||||
break;
|
|
||||||
case 200:
|
|
||||||
video_rectf(VXR*7/11, 0, VXR*8/11, VYR-1, 0x00000088);
|
|
||||||
break;
|
|
||||||
case 250:
|
|
||||||
video_rectf(VXR/11, 0, VXR*2/11, VYR*2/5, 0x00000088);
|
|
||||||
break;
|
|
||||||
case 300:
|
|
||||||
video_rectf(VXR/11, VYR*3/5, VXR*2/11, VYR-1, 0x00000088);
|
|
||||||
break;
|
|
||||||
case 350:
|
|
||||||
video_rectf(VXR*5/11, VYR/5, VXR*6/11, VYR*4/5, 0x00000088);
|
|
||||||
break;
|
|
||||||
case 400:
|
|
||||||
video_rectf(VXR*9/11, VYR/5, VXR-1, VYR*2/5, 0x00000088);
|
|
||||||
break;
|
|
||||||
case 450:
|
|
||||||
video_rectf(VXR*8/11, VYR*3/5, VXR*10/11, VYR*4/5, 0x00000088);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
eoi();
|
eoi();
|
||||||
break;
|
break;
|
||||||
case 0x21:
|
case 0x21: // IRQ1 - keyboard interrupt
|
||||||
printf("------------------KEYBOARD ISR--------------------------\n");
|
isr_keyboard(); //isr_keybard() takes care of calling eoi()
|
||||||
isr_keyboard();
|
break;
|
||||||
|
case 0x2C: // IRQ12 - PS/2 mouse
|
||||||
|
isr_mouse();
|
||||||
|
eoi2();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("Interrupt %d (0x%x) Unhandled!!\n", num, num);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-15
@@ -10,8 +10,8 @@ byte kbdAscii = 0;
|
|||||||
byte kbdScan = 0;
|
byte kbdScan = 0;
|
||||||
|
|
||||||
dword kbdBuffer[KBD_BUFFER_LENGTH];
|
dword kbdBuffer[KBD_BUFFER_LENGTH];
|
||||||
byte kbdBufferStart = 0;
|
int kbdBufferStart = 0;
|
||||||
byte kbdBufferLen = 0;
|
int kbdBufferLen = 0;
|
||||||
byte kbdExt = 0;
|
byte kbdExt = 0;
|
||||||
byte kbdExt2 = 0;
|
byte kbdExt2 = 0;
|
||||||
byte ackReason = 0; //used to record the reason why we would get an acknowledge byte (0xFA)
|
byte ackReason = 0; //used to record the reason why we would get an acknowledge byte (0xFA)
|
||||||
@@ -26,11 +26,12 @@ const byte SCAN2ASCIISHIFT[128] = "\000\033!@#$%^&*()_+\010\011QWERTYUIOP{}\n\00
|
|||||||
void isr_keyboard()
|
void isr_keyboard()
|
||||||
{
|
{
|
||||||
kbdScan = inportb(0x60);
|
kbdScan = inportb(0x60);
|
||||||
|
//printf("\nKEYBOARD INTERRUPT: 0x%x", kbdScan);
|
||||||
byte inState = inportb(0x61);
|
byte inState = inportb(0x61);
|
||||||
outportb(0x61, inState|0x80);
|
outportb(0x61, inState|0x80);
|
||||||
outportb(0x61, inState);
|
outportb(0x61, inState);
|
||||||
|
|
||||||
printf("IRQ 1: %x\n", kbdScan);
|
//printf("IRQ 1: %x\n", kbdScan);
|
||||||
|
|
||||||
if (kbdScan == 0xFA) //250 //ACKnowledge
|
if (kbdScan == 0xFA) //250 //ACKnowledge
|
||||||
{
|
{
|
||||||
@@ -188,8 +189,8 @@ void isr_keyboard()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
kbdBuffer[(kbdBufferStart+kbdBufferLen)%KBD_BUFFER_LENGTH] = (dword) ((kbdFlags << 16) | (kbdScan << 8) | kbdAscii);
|
kbdBuffer[(kbdBufferStart+kbdBufferLen++)%KBD_BUFFER_LENGTH] = (dword) ((kbdFlags << 16) | (kbdScan << 8) | kbdAscii);
|
||||||
kbdBufferLen++;
|
// printf("S:%d\tL:%d\tR:%x\n", kbdBufferStart, kbdBufferLen, kbdBuffer[kbdBufferStart]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +198,7 @@ void isr_keyboard()
|
|||||||
|
|
||||||
// if (key == 0xFA) //ACKnowledge
|
// if (key == 0xFA) //ACKnowledge
|
||||||
// outportb(0x60, 0x3);
|
// outportb(0x60, 0x3);
|
||||||
};
|
}
|
||||||
|
|
||||||
inline byte switchCase(byte asciiCode)
|
inline byte switchCase(byte asciiCode)
|
||||||
{
|
{
|
||||||
@@ -213,26 +214,26 @@ dword kbdGetKey()
|
|||||||
if (kbdBufferLen == 0) //buffer empty
|
if (kbdBufferLen == 0) //buffer empty
|
||||||
return 0;
|
return 0;
|
||||||
dword retVal = kbdBuffer[kbdBufferStart];
|
dword retVal = kbdBuffer[kbdBufferStart];
|
||||||
printf("S:%d\tE:%d\tR:%x\n", kbdBufferStart, kbdBufferLen, retVal);
|
|
||||||
kbdBufferStart++;
|
kbdBufferStart++;
|
||||||
kbdBufferLen--;
|
kbdBufferLen--;
|
||||||
if (kbdBufferStart == KBD_BUFFER_LENGTH)
|
if (kbdBufferStart >= KBD_BUFFER_LENGTH)
|
||||||
kbdBufferStart = 0;
|
kbdBufferStart = 0;
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
dword kbdWaitKey()
|
dword kbdWaitKey()
|
||||||
{
|
{
|
||||||
dword retVal = 0;
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
retVal = kbdGetKey();
|
if (kbdBufferLen != 0) //buffer empty
|
||||||
if (retVal != 0)
|
break;
|
||||||
{
|
}
|
||||||
printf("S:%d\tE:%d\tR:%x\n", kbdBufferStart, kbdBufferLen, retVal);
|
dword retVal = kbdBuffer[kbdBufferStart];
|
||||||
|
kbdBufferStart++;
|
||||||
|
kbdBufferLen--;
|
||||||
|
if (kbdBufferStart >= KBD_BUFFER_LENGTH)
|
||||||
|
kbdBufferStart = 0;
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void kbd_resetLEDs()
|
inline void kbd_resetLEDs()
|
||||||
|
|||||||
File renamed without changes.
+5
-3
@@ -25,6 +25,7 @@ _writeCursorPosition:
|
|||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
|
|
||||||
|
push eax
|
||||||
push ebx
|
push ebx
|
||||||
push edx
|
push edx
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ _writeCursorPosition:
|
|||||||
|
|
||||||
pop edx
|
pop edx
|
||||||
pop ebx
|
pop ebx
|
||||||
|
pop eax
|
||||||
pop ebp
|
pop ebp
|
||||||
|
|
||||||
ret
|
ret
|
||||||
@@ -175,7 +177,7 @@ _printf:
|
|||||||
push ebp
|
push ebp
|
||||||
mov ebp, esp
|
mov ebp, esp
|
||||||
pusha
|
pusha
|
||||||
mov ebx, [ebp+8] ;ebx = in format string
|
mov ebx, [ebp+8] ;ebx = position in format string
|
||||||
mov esi, ebp
|
mov esi, ebp
|
||||||
add esi, 12 ;esi = to next variable arg
|
add esi, 12 ;esi = to next variable arg
|
||||||
xor ecx, ecx ;ecx used if we encounter a '%'
|
xor ecx, ecx ;ecx used if we encounter a '%'
|
||||||
@@ -184,10 +186,10 @@ printf_loop:
|
|||||||
inc ebx
|
inc ebx
|
||||||
cmp al, 0
|
cmp al, 0
|
||||||
jzfar printf_done
|
jzfar printf_done
|
||||||
cmp al, '%'
|
|
||||||
jzfar printf_percent
|
|
||||||
cmp ecx, 1
|
cmp ecx, 1
|
||||||
jz printf_special
|
jz printf_special
|
||||||
|
cmp al, '%'
|
||||||
|
jzfar printf_percent
|
||||||
|
|
||||||
push eax
|
push eax
|
||||||
call _putc
|
call _putc
|
||||||
+3
-3
@@ -3,9 +3,9 @@
|
|||||||
#ifndef __HIO_H__
|
#ifndef __HIO_H__
|
||||||
#define __HIO_H__ __HIO_H__
|
#define __HIO_H__ __HIO_H__
|
||||||
|
|
||||||
void writeCursorPosition(word pos);
|
void writeCursorPosition(dword pos);
|
||||||
word getCursorPosition();
|
dword getCursorPosition();
|
||||||
int putc(byte chr);
|
int putc(dword chr);
|
||||||
int printf(char *fmt, ...);
|
int printf(char *fmt, ...);
|
||||||
int puts(char *str);
|
int puts(char *str);
|
||||||
int putDec(int number);
|
int putDec(int number);
|
||||||
File renamed without changes.
File renamed without changes.
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
|
|
||||||
pageblock *first_pageblock = (pageblock *) 0;
|
pageblock *first_pageblock = (pageblock *) 0;
|
||||||
dword mm_totalmem = 0x100000; //assume 1mb
|
dword mm_totalmem = 0x100000; //start counting from 1mb
|
||||||
|
|
||||||
void mm_init()
|
void mm_init()
|
||||||
{
|
{
|
||||||
@@ -26,36 +26,38 @@ void mm_init()
|
|||||||
}
|
}
|
||||||
if (first_pageblock == 0) //no pageblock page set up yet, so set it up here
|
if (first_pageblock == 0) //no pageblock page set up yet, so set it up here
|
||||||
{
|
{
|
||||||
first_pageblock = (pageblock *) maps[a].base.lowdword ;
|
first_pageblock = (pageblock *) maps[a].base.lowdword;
|
||||||
maps[a].base.lowdword += 4096;
|
maps[a].base.lowdword += 4096;
|
||||||
maps[a].limit.lowdword -= 4096;
|
maps[a].limit.lowdword -= 4096;
|
||||||
mm_init_pageblockpage(first_pageblock);
|
mm_init_pageblockpage(first_pageblock);
|
||||||
first_pageblock->base = maps[a].base.lowdword;
|
first_pageblock->base = maps[a].base.lowdword;
|
||||||
first_pageblock->length = maps[a].limit.lowdword / 4096;
|
first_pageblock->length = maps[a].limit.lowdword / 4096;
|
||||||
first_pageblock->flags = MM_PB_AVAIL;
|
first_pageblock->pid = MM_PB_AVAIL;
|
||||||
}
|
}
|
||||||
else //first_pageblock already set up, add on segment
|
else //first_pageblock already set up, add on segment
|
||||||
{
|
{
|
||||||
pageblock *pb = first_pageblock;
|
pageblock *pb = first_pageblock;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (pb->flags == MM_PB_NP)
|
if (pb->pid == MM_PB_NP)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
pb++;
|
pb++;
|
||||||
}
|
}
|
||||||
pb->base = maps[a].base.lowdword;
|
pb->base = maps[a].base.lowdword;
|
||||||
pb->length = maps[a].limit.lowdword / 4096;
|
pb->length = maps[a].limit.lowdword / 4096;
|
||||||
pb->flags = MM_PB_AVAIL;
|
pb->pid = MM_PB_AVAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (first_pageblock == 0)
|
if (first_pageblock == 0)
|
||||||
{
|
{
|
||||||
printf("ERROR! NO INITIAL PAGE BLOCK COULD BE CREATED.");
|
printf("ERROR! NO INITIAL PAGE BLOCK CREATED.");
|
||||||
asm("cli");
|
asm("cli");
|
||||||
asm("hlt");
|
asm("hlt");
|
||||||
|
for (;;)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,27 +66,26 @@ void mm_init()
|
|||||||
|
|
||||||
void mm_init_pageblockpage(pageblock *pbp)
|
void mm_init_pageblockpage(pageblock *pbp)
|
||||||
{
|
{
|
||||||
pageblock *pb = pbp;
|
|
||||||
int a;
|
int a;
|
||||||
for (a=0; a<512; a++)
|
for (a=0; a<256; a++) // 256 pageblock entries * 16 bytes per page block entry = 4096 bytes (1 page of pageblock entries)
|
||||||
{
|
{
|
||||||
pb->base = 0;
|
pbp[a].base = 0;
|
||||||
pb->length = 0;
|
pbp[a].length = 0;
|
||||||
pb->flags = MM_PB_NP;
|
pbp[a].pid = MM_PB_NP;
|
||||||
if (a<511)
|
if (a<255)
|
||||||
pb->link = (dword)pb + sizeof(pageblock);
|
pbp[a].link = (dword)(&pbp[a+1]);
|
||||||
else
|
else
|
||||||
pb->link = 0;
|
pbp[a].link = 0;
|
||||||
pb++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *mm_palloc(dword numpages)
|
void *mm_palloc(dword numpages, dword proc_pid)
|
||||||
{
|
{
|
||||||
|
if (proc_pid < KERNEL_PID)
|
||||||
|
return 0;
|
||||||
pageblock *pb = first_pageblock;
|
pageblock *pb = first_pageblock;
|
||||||
dword freeentries = mm_freeentries();
|
if (mm_freeentries() < 2)
|
||||||
if (freeentries < 2)
|
|
||||||
{
|
{
|
||||||
if(mm_new_pageblock_page() == 0)
|
if(mm_new_pageblock_page() == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -92,7 +93,7 @@ void *mm_palloc(dword numpages)
|
|||||||
pageblock *newentry = mm_nextpageblockentry();
|
pageblock *newentry = mm_nextpageblockentry();
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if ((pb->flags == MM_PB_AVAIL) && (pb->length >= numpages))
|
if ((pb->pid == MM_PB_AVAIL) && (pb->length >= numpages))
|
||||||
break;
|
break;
|
||||||
if (pb->link == 0)
|
if (pb->link == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -100,14 +101,14 @@ void *mm_palloc(dword numpages)
|
|||||||
}
|
}
|
||||||
if (pb->length == numpages) //dont need a new entry, just mark this one as used :)
|
if (pb->length == numpages) //dont need a new entry, just mark this one as used :)
|
||||||
{
|
{
|
||||||
pb->flags = MM_PB_USED;
|
pb->pid = proc_pid;
|
||||||
return pb;
|
return (void *)pb->base;
|
||||||
}
|
}
|
||||||
else //subtract out allocated number of pages from length
|
else //subtract out allocated number of pages from length
|
||||||
{
|
{
|
||||||
newentry->base = pb->base;
|
newentry->base = pb->base;
|
||||||
newentry->length = numpages;
|
newentry->length = numpages;
|
||||||
newentry->flags = MM_PB_USED;
|
newentry->pid = proc_pid;
|
||||||
pb->base += (numpages * 4096);
|
pb->base += (numpages * 4096);
|
||||||
pb->length -= numpages;
|
pb->length -= numpages;
|
||||||
return (void *)newentry->base;
|
return (void *)newentry->base;
|
||||||
@@ -121,7 +122,7 @@ dword mm_freeentries()
|
|||||||
dword counter = 0;
|
dword counter = 0;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (pb->flags == MM_PB_NP)
|
if (pb->pid == MM_PB_NP)
|
||||||
counter++;
|
counter++;
|
||||||
if (pb->link == 0)
|
if (pb->link == 0)
|
||||||
return counter;
|
return counter;
|
||||||
@@ -130,12 +131,12 @@ dword mm_freeentries()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pageblock *mm_new_pageblock_page()
|
pageblock *mm_new_pageblock_page() //as of 09/26/03 this method leaks 4kb main memory per call, unrecoverable
|
||||||
{
|
{
|
||||||
pageblock *pb = first_pageblock;
|
pageblock *pb = first_pageblock;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if ((pb->flags == MM_PB_AVAIL) && (pb->length > 1))
|
if ((pb->pid == MM_PB_AVAIL) && (pb->length > 1))
|
||||||
{
|
{
|
||||||
pageblock *retval = (pageblock *)pb->base;
|
pageblock *retval = (pageblock *)pb->base;
|
||||||
pb->base += 4096;
|
pb->base += 4096;
|
||||||
@@ -153,36 +154,18 @@ pageblock *mm_new_pageblock_page()
|
|||||||
|
|
||||||
int mm_pfree(void *ptr)
|
int mm_pfree(void *ptr)
|
||||||
{
|
{
|
||||||
|
if (ptr == 0)
|
||||||
|
return 2;
|
||||||
pageblock *pb = first_pageblock;
|
pageblock *pb = first_pageblock;
|
||||||
dword tofree = (dword) ptr;
|
dword tofree = (dword) ptr;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if ((pb->base == tofree) && (pb->flags == MM_PB_USED))
|
if (pb->base == tofree) // && (pb->pid == MM_PB_USED))
|
||||||
{
|
{
|
||||||
pb->flags = MM_PB_AVAIL; //found block, mark available / coalesce it
|
pb->pid = MM_PB_AVAIL; //found block, mark available / coalesce it
|
||||||
pageblock *pbc = first_pageblock;
|
mm_coalesce(pb);
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
if (pbc->flags == MM_PB_AVAIL)
|
|
||||||
{
|
|
||||||
if ((pbc->base + (pbc->length * 4096)) == pb->base) //pbc ends where pb starts
|
|
||||||
{
|
|
||||||
pbc->length += pb->length; //extend pbc's length by pb's length
|
|
||||||
pb->flags = MM_PB_NP; //mark pb as an unused entry
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((pb->base + (pb->length * 4096)) == pbc->base) //pb ends where pb starts
|
|
||||||
{
|
|
||||||
pb->length += pbc->length;
|
|
||||||
pbc->flags = MM_PB_NP;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pbc->link == 0) //no entry found to consolidate...
|
|
||||||
return 0;
|
|
||||||
pbc = (pageblock *) pbc->link; //next entry to test
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pb->link == 0)
|
if (pb->link == 0)
|
||||||
return 1;
|
return 1;
|
||||||
pb = (pageblock *) pb->link;
|
pb = (pageblock *) pb->link;
|
||||||
@@ -207,7 +190,7 @@ pageblock *mm_nextpageblockentry()
|
|||||||
pageblock *pb = first_pageblock;
|
pageblock *pb = first_pageblock;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (pb->flags == MM_PB_NP)
|
if (pb->pid == MM_PB_NP)
|
||||||
return pb;
|
return pb;
|
||||||
if (pb->link == 0)
|
if (pb->link == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -222,7 +205,7 @@ dword mm_freemem()
|
|||||||
pageblock *pb = first_pageblock;
|
pageblock *pb = first_pageblock;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (pb->flags == MM_PB_AVAIL)
|
if (pb->pid == MM_PB_AVAIL)
|
||||||
amount += (pb->length)*4096;
|
amount += (pb->length)*4096;
|
||||||
if (pb->link == 0)
|
if (pb->link == 0)
|
||||||
return amount;
|
return amount;
|
||||||
@@ -231,6 +214,35 @@ dword mm_freemem()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mm_coalesce(pageblock *pb)
|
||||||
|
{
|
||||||
|
pageblock *pbc = first_pageblock;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (pbc->pid == pb->pid) //pid fields must match, both same process, both avail, or both not present
|
||||||
|
{
|
||||||
|
if ((pbc->base + (pbc->length * 4096)) == pb->base) //pbc ends where pb starts
|
||||||
|
{
|
||||||
|
pbc->length += pb->length;
|
||||||
|
pb->pid = MM_PB_NP;
|
||||||
|
mm_coalesce(pbc); //recursion: checks for any more page blocks to coalesce if one found
|
||||||
|
return; //exit this recursion...
|
||||||
|
}
|
||||||
|
if ((pb->base + (pb->length * 4096)) == pbc->base) //pb ends where pbc starts
|
||||||
|
{
|
||||||
|
pb->length += pbc->length;
|
||||||
|
pbc->pid = MM_PB_NP;
|
||||||
|
mm_coalesce(pb);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pbc->link == 0)
|
||||||
|
return;
|
||||||
|
pbc = (pageblock *)pbc->link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,26 +10,25 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
dword base;
|
dword base;
|
||||||
dword length; //in pages
|
dword length; //in pages
|
||||||
dword flags;
|
dword pid; //normally PID of process, use NP, AVAIL for special flags
|
||||||
dword link;
|
dword link; //leave dword instead of pointer so i dont have to worry about pointer arithmetic
|
||||||
} __attribute__ ((packed)) pageblock; //16 byte pageblock entry - 512 entries = 1 page
|
} __attribute__ ((packed)) pageblock; //16 byte pageblock entry - 256 entries = 1 page
|
||||||
|
|
||||||
|
|
||||||
void mm_init();
|
void mm_init();
|
||||||
void mm_init_pageblockpage(pageblock *pbp);
|
void mm_init_pageblockpage(pageblock *pbp);
|
||||||
void *mm_palloc(dword numpages);
|
void *mm_palloc(dword numpages, dword proc_pid);
|
||||||
|
void mm_coalesce(pageblock *pb);
|
||||||
int mm_pfree(void *ptr);
|
int mm_pfree(void *ptr);
|
||||||
dword mm_freeentries();
|
dword mm_freeentries();
|
||||||
|
dword mm_freemem();
|
||||||
pageblock *mm_new_pageblock_page();
|
pageblock *mm_new_pageblock_page();
|
||||||
pageblock *mm_lastpageblockentry();
|
pageblock *mm_lastpageblockentry();
|
||||||
pageblock *mm_nextpageblockentry();
|
pageblock *mm_nextpageblockentry();
|
||||||
dword mm_freemem();
|
|
||||||
|
|
||||||
|
|
||||||
#define MM_PB_FLAGMASK 0x03 //00000011
|
|
||||||
#define MM_PB_NP 0x00 //00000000
|
#define MM_PB_NP 0x00 //00000000
|
||||||
#define MM_PB_AVAIL 0x01 //00000001
|
#define MM_PB_AVAIL 0x01 //00000001
|
||||||
#define MM_PB_USED 0x02 //00000010
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
// mouse.c
|
||||||
|
// 10/03/03
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
|
||||||
|
|
||||||
|
void mouse_init()
|
||||||
|
{
|
||||||
|
outportb(0x64, 0x20); //tell keyboard controller we are going to read keyboard controller command byte
|
||||||
|
byte temp = inportb(0x60); //read keyboard controller command byte
|
||||||
|
outportb(0x64, 0x60); //tell keyboard controller we are going to write keyboard controller command byte
|
||||||
|
outportb(0x60, 0x03 | (temp&0x40)); //write keyboard controller command byte: enable mouse/keyboard ints, include original XLATE bit from temp (bit6)
|
||||||
|
|
||||||
|
outportb(0x64, 0xA8); //enable mouse port
|
||||||
|
|
||||||
|
outportb(0x64, 0xD4); //send command to mouse, not kbd
|
||||||
|
outportb(0x60, 0xF4); //enable data reporting
|
||||||
|
|
||||||
|
//outportb(0x64, 0xD4);
|
||||||
|
//outportb(0x60, 0xE7); //scaling 2:1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void isr_mouse()
|
||||||
|
{
|
||||||
|
byte inb = inportb(0x60); //read mouse byte
|
||||||
|
//printf("InB: %x\n", inb);
|
||||||
|
//return;
|
||||||
|
if ((inb == 0xFA) && (mouse_bytesRead < 1)) //ACK
|
||||||
|
return;
|
||||||
|
mouse_inbuffer[mouse_bytesRead] = inb;
|
||||||
|
mouse_bytesRead++;
|
||||||
|
if (mouse_bytesRead == 3) //complete packet received
|
||||||
|
{
|
||||||
|
mouse_bytesRead = 0;
|
||||||
|
int adjx = (char) mouse_inbuffer[1];
|
||||||
|
int adjy = (char) mouse_inbuffer[2];
|
||||||
|
mouse_x += adjx;
|
||||||
|
mouse_y -= adjy; //-= because screen y coordinates are opposite mouse y coordinates
|
||||||
|
if (mouse_inbuffer[0] & 0x01) //left button
|
||||||
|
{
|
||||||
|
video_pset(VXR/2+mouse_x, VYR/2+mouse_y, 0x00FFFFFF);
|
||||||
|
printf("X: %d, Y: %d\n", mouse_x, mouse_y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
video_pset(VXR/2+mouse_x, VYR/2+mouse_y, 0x00000000);
|
||||||
|
printf("X: %d, Y: %d\n", mouse_x, mouse_y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// mouse.h
|
||||||
|
// 10/03/03
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
|
||||||
|
|
||||||
|
int mouse_x = 0;
|
||||||
|
int mouse_y = 0;
|
||||||
|
int mouse_bytesRead = 0;
|
||||||
|
byte mouse_inbuffer[16];
|
||||||
|
|
||||||
|
void mouse_init();
|
||||||
|
void isr_mouse();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
//video.c
|
//video.c
|
||||||
// 08/13/03 Josh Holtrop
|
// 08/13/03 Josh Holtrop
|
||||||
|
|
||||||
ModeInfoBlock video_mode;
|
|
||||||
byte *vid_ptr24;
|
|
||||||
word *vid_ptr16;
|
|
||||||
dword *vid_ptr32;
|
|
||||||
|
|
||||||
void video_init(ModeInfoBlock *mib)
|
void video_init(ModeInfoBlock *mib)
|
||||||
{
|
{
|
||||||
@@ -134,7 +130,7 @@ void video_psetp(int pixel, dword color)
|
|||||||
switch(video_mode.BitsPerPixel)
|
switch(video_mode.BitsPerPixel)
|
||||||
{
|
{
|
||||||
case 16:
|
case 16:
|
||||||
vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<6) | ((((color>>16)&0xFF)>>3)<<11);
|
vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<5) | ((((color>>16)&0xFF)>>3)<<11);
|
||||||
//vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>3)<<5) | ((((color>>16)&0xFF)>>3)<<10);
|
//vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>3)<<5) | ((((color>>16)&0xFF)>>3)<<10);
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
//video.h
|
//video.h
|
||||||
// 08/18/03 Josh Holtrop
|
// 08/18/03 Josh Holtrop
|
||||||
|
|
||||||
|
|
||||||
void video_init();
|
void video_init();
|
||||||
void video_horiz(int y, int x1, int x2, dword color);
|
void video_horiz(int y, int x1, int x2, dword color);
|
||||||
void video_vert(int x, int y1, int y2, dword color);
|
void video_vert(int x, int y1, int y2, dword color);
|
||||||
@@ -52,6 +53,12 @@ typedef struct{
|
|||||||
byte Reserved[206];
|
byte Reserved[206];
|
||||||
} ModeInfoBlock;
|
} ModeInfoBlock;
|
||||||
|
|
||||||
|
ModeInfoBlock video_mode;
|
||||||
|
byte *vid_ptr24;
|
||||||
|
word *vid_ptr16;
|
||||||
|
dword *vid_ptr32;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
// vmm.c
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 09/30/03
|
||||||
|
|
||||||
|
|
||||||
|
void *malloc(dword bytes)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int free(void *ptr);
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user