Import backup from 2003-12-22_2

This commit is contained in:
Josh Holtrop 2003-12-22 22:01:00 -05:00
parent 5048a93ff7
commit 9070a76b18
4 changed files with 79 additions and 125 deletions

View File

@ -1,98 +0,0 @@
//kernel.c
//08/13/03 Josh Holtrop
//Holtrop's Operating System
//Version: 0.12
//Modified: 11/12/03
#include "k_defines.h" //#DEFINE's for kernel
#include "lib/string.h" //library string functions
#include "lib/io.h" //library input/output functions
#include "functions.h" //general functions
#include "video.h" //video functions
#include "mm.h" //physical memory management functions
#include "vmm.h" //virtual memory management & paging functions
#include "keyboard.h" //generic keyboard driver & functions
#include "mouse.h" //generic ps/2 mouse driver & functions
#include "fdc.h" //Floppy Disk Controller functions
#include "stdfont.h" //Standard font bitmask array
void isr(dword num);
void k_init();
extern dword write_cr0(dword cr0);
extern dword read_cr0();
extern dword write_cr3(dword cr3);
extern dword read_cr3();
#include "fdc.c"
#include "mouse.c"
#include "keyboard.c"
#include "mm.c"
#include "vmm.c"
#include "functions.c"
#include "video.c"
dword timer = 0;
dword *videoMode;
//Main kernel initialization method
void k_init()
{
// ===== Initialization
fdc_sendDOR(0x0C); //turn off floppy motor!!
console_cls();
remap_pics(0x20, 0x28);
init_timer();
mm_init();
videoMode = (dword *)0x90002;
if (*videoMode)
video_init((ModeInfoBlock *) 0x90306);
vmm_init();
mouse_init();
vmm_enable_paging();
pic1_mask(0); //unmask IRQ's 0-7
pic2_mask(0); //unmask IRQ's 8-15
enable_ints();
kbd_resetLEDs(); //after enabling interrupts!!
printf("HOS 0.12 - Kernel Size: %d kb\n", kernel_size()/1024);
printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem);
printf("Free memory: %d bytes\n", mm_freemem());
dword key = 0;
for (;;)
{
key = kbdWaitKey();
if ((key & 0xFF) > 2) //key is not a control key
putc(key);
}
}
// main Interrupt Service Routine - handles all interrupts unless caught by kernel.asm
void isr(dword num)
{
switch(num)
{
case 0x20: // IRQ0 - timer interrupt
timer++;
(*(byte *)(0xb8000))++;
eoi();
break;
case 0x21: // IRQ1 - keyboard interrupt
isr_keyboard(); //isr_keybard() takes care of calling eoi()
break;
case 0x2C: // IRQ12 - PS/2 mouse
isr_mouse();
eoi2();
break;
default:
printf("Interrupt %d (0x%x) Unhandled!!\n", num, num);
break;
}
}

View File

@ -1,21 +1,94 @@
//kernel.c
//08/13/03 Josh Holtrop
//Holtrop's Operating System
//Version: 0.12
//Modified: 11/12/03
#include "k_defines.h"
#include "k_defines.h" //#DEFINE's for kernel
#include "lib/string.h" //library string functions
#include "lib/io.h" //library input/output functions
#include "functions.h" //general functions
#include "video.h" //video functions
#include "mm.h" //physical memory management functions
#include "vmm.h" //virtual memory management & paging functions
#include "keyboard.h" //generic keyboard driver & functions
#include "mouse.h" //generic ps/2 mouse driver & functions
#include "fdc.h" //Floppy Disk Controller functions
#include "stdfont.h" //Standard font bitmask array
void isr(dword num);
void k_init();
extern dword write_cr0(dword cr0);
extern dword read_cr0();
extern dword write_cr3(dword cr3);
extern dword read_cr3();
#include "fdc.c"
#include "mouse.c"
#include "keyboard.c"
#include "mm.c"
#include "vmm.c"
#include "functions.c"
#include "video.c"
dword timer = 0;
dword *videoMode;
//Main kernel initialization method
void k_init()
{
// ===== Initialization
fdc_sendDOR(0x0C); //turn off floppy motor!!
mm_init();
vmm_init();
console_cls();
remap_pics(0x20, 0x28);
init_timer();
videoMode = (dword *)0x90002;
if (*videoMode)
video_init((ModeInfoBlock *) 0x90306);
mouse_init();
pic1_mask(0); //unmask IRQ's 0-7
pic2_mask(0); //unmask IRQ's 8-15
enable_ints();
kbd_resetLEDs(); //after enabling interrupts!!
printf("HOS 0.12 - Kernel Size: %d kb\n", kernel_size()/1024);
printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem);
printf("Free memory: %d bytes\n", mm_freemem());
dword key = 0;
for (;;)
{
(*(byte *)0xc00b8000)++;
key = kbdWaitKey();
if ((key & 0xFF) > 2) //key is not a control key
putc(key);
}
}
// main Interrupt Service Routine - handles all interrupts unless caught by kernel.asm
void isr(dword num)
{
switch(num)
{
case 0x20: // IRQ0 - timer interrupt
timer++;
(*(byte *)(0xb8000))++;
eoi();
break;
case 0x21: // IRQ1 - keyboard interrupt
isr_keyboard(); //isr_keybard() takes care of calling eoi()
break;
case 0x2C: // IRQ12 - PS/2 mouse
isr_mouse();
eoi2();
break;
default:
printf("Interrupt %d (0x%x) Unhandled!!\n", num, num);
break;
}
}

26
vmm.c
View File

@ -3,19 +3,12 @@
// Author: Josh Holtrop
// Date: 09/30/03
PageDirectory *vmm_PDBR = 0;
PageDirectory *vmm_PDBR = (PageDirectory *)0x104000;
dword vmm_first_virtual_address = 0;
void vmm_init()
{
if (!(vmm_PDBR = mm_palloc(1, PID_KERNEL)))
{
printf("ERROR! COULD NOT ALLOCATE PAGE FOR INITIAL PAGE DIRECTORY!!\n");
halt();
}
vmm_init_pagetable((dword)vmm_PDBR);
if (mm_totalmem % 4096)
vmm_first_virtual_address = mm_totalmem + (4096 - (mm_totalmem % 4096));
else
@ -24,7 +17,7 @@ void vmm_init()
if (vmm_mapn(0, 0, 0x03, mm_totalmem/4096+1))
{
printf("Could not page in all physical RAM!\n");
halt();
//halt();
}
//we also need to map in the video framebuffer memory:
if (video_mode.PhysBasePtr > 0 && video_mode.BitsPerPixel > 0)
@ -38,13 +31,6 @@ void vmm_init()
}
void vmm_enable_paging()
{
write_cr3((dword)vmm_PDBR);
write_cr0(0x80000000|read_cr0());
}
int vmm_map1(dword virtual, dword physical, dword flags)
{
if (virtual & 0x00000FFF)
@ -72,17 +58,11 @@ int vmm_map1(dword virtual, dword physical, dword flags)
int vmm_mapn(dword virtual, dword physical, dword flags, dword n)
{
int mapped;
int result = 0;
dword va = virtual;
dword pa = physical;
for (mapped = 0; mapped < n; mapped++)
{
if (result = vmm_map1(va, pa, flags))
{
if (mapped > 0)
vmm_unmapn(virtual, mapped);
return result;
}
vmm_map1(va, pa, flags);
va += 4096;
pa += 4096;
}

1
vmm.h
View File

@ -13,7 +13,6 @@ typedef struct {
} PageDirectory;
void vmm_enable_paging();
void vmm_init();
void *malloc(dword bytes);
int free(void *ptr);