Import backup from 2005-08-18

This commit is contained in:
josh committed 2017-07-25 22:23:50 -04:00
1 parent e1682a2fe7
commit 345ef6c9f3
35 files changed
+804 -89

No files matched your search

+27 -11
View File
@@ -9,6 +9,7 @@ NASM_FLAGS=-f aout
# C/C++ Information:
CPPFLAGS=-fleading-underscore -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -I. -Wall
# -S -masm=intel
CC=gcc
CXX=g++
CXXFLAGS=-fno-rtti -fno-exceptions
@@ -19,16 +20,20 @@ LDFLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
# Files
OBJS=boot.o lang/lang_a.o \
kernel.o mm/mm.o mm/vmm.o lang/conv.o display/kout.o display/display.o \
sys/pic.o char/keyboard.o lang/lang.o \
kernel.o mm/mm.o mm/vmm.o lang/conv.o display/kout.o \
display/display.o sys/pic.o char/keyboard.o lang/lang.o \
sys/pci_classes.o proc/proc.o \
lang/string.o lang/new.o char/misc_char.o char/vconsole.o \
devices.o block/ramdisk.o fs/vfs.o fs/FileSystem.o fs/VFSMount.o \
fs/ext2/ext2.o
CSRC=kernel.c mm/mm.c mm/vmm.c lang/conv.c display/kout.c display/display.c \
sys/pic.c char/keyboard.c lang/lang.c
fs/ext2/ext2.o fs/sysfs/sysfs.o fs/sysfs/sysfs_entry.o \
sys/pci.o
CSRC=kernel.c mm/mm.c mm/vmm.c lang/conv.c display/kout.c \
display/display.c sys/pic.c char/keyboard.c lang/lang.c \
sys/pci_classes.c proc/proc.c
CXXSRC=lang/string.cpp lang/new.cpp char/misc_char.cpp char/vconsole.cpp \
block/ramdisk.cpp devices.cpp fs/vfs.cpp fs/FileSystem.o fs/VFSMount.o \
fs/ext2/ext2.cpp
block/ramdisk.cpp devices.cpp fs/vfs.cpp fs/FileSystem.o fs/VFSMount.o\
fs/ext2/ext2.cpp fs/sysfs/sysfs.cpp fs/sysfs/sysfs_entry.cpp \
sys/pci.cpp
.PHONY: all depend clean html
@@ -46,7 +51,8 @@ lang/lang_a.o: lang/lang.asm
$(NASM) $(NASM_FLAGS) -l lang.lst lang/lang.asm -o lang/lang_a.o
clean:
-rm -f $(OBJS) *.bin *.map *.lst *.out *~ fs/*~ sys/*~ block/*~ char/*~ lang/*~ mm/*~ display/*~
-rm -f $(OBJS) *.bin *.map *.lst *.out
-find . -name '*~' | xargs rm -f
html:
-rm -rf html
@@ -73,6 +79,9 @@ sys/pic.o: hos_defines.h sys/pic.h sys/io.h
char/keyboard.o: hos_defines.h char/keyboard.h sys/io.h functions.h
char/keyboard.o: lang/conv.h display/kout.h display/display.h devices.h
lang/lang.o: lang/lang.h hos_defines.h
sys/pci_classes.o: hos_defines.h sys/pci.h
proc/proc.o: hos_defines.h proc/proc.h mm/mm.h kernel.h multiboot.h mm/vmm.h
proc/proc.o: lang/lang.h
lang/string.o: lang/string.h lang/lang.h hos_defines.h
lang/new.o: hos_defines.h mm/vmm.h multiboot.h
char/misc_char.o: hos_defines.h devices.h char/misc_char.h sys/io.h
@@ -84,6 +93,13 @@ block/ramdisk.o: lang/lang.h block/ramdisk.h devices.h
devices.o: hos_defines.h devices.h char/misc_char.h char/misc_char.h
devices.o: char/vconsole.h block/ramdisk.h
fs/vfs.o: hos_defines.h display/kout.h fs/vfs.h devices.h lang/string.h
fs/vfs.o: fs/ext2/ext2.h fs/vfs.h lang/vector.h
fs/ext2/ext2.o: display/kout.h hos_defines.h fs/ext2/ext2.h fs/vfs.h
fs/ext2/ext2.o: devices.h
fs/vfs.o: fs/FileSystem.h fs/VFSMount.h fs/FileSystem.h fs/vfs.h
fs/vfs.o: fs/ext2/ext2.h lang/vector.h
fs/ext2/ext2.o: display/kout.h hos_defines.h mm/vmm.h multiboot.h lang/lang.h
fs/ext2/ext2.o: fs/ext2/ext2.h fs/vfs.h devices.h
fs/sysfs/sysfs.o: display/kout.h hos_defines.h fs/vfs.h devices.h
fs/sysfs/sysfs.o: fs/sysfs/sysfs.h fs/FileSystem.h lang/vector.h
fs/sysfs/sysfs.o: lang/string.h fs/sysfs/sysfs_entry.h
fs/sysfs/sysfs_entry.o: fs/sysfs/sysfs_entry.h lang/vector.h hos_defines.h
fs/sysfs/sysfs_entry.o: lang/string.h
sys/pci.o: hos_defines.h display/kout.h sys/io.h sys/pci.h lang/vector.h
+20 -9
View File
@@ -9,6 +9,7 @@ NASM_FLAGS=-f aout
# C/C++ Information:
CPPFLAGS=-fleading-underscore -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -I. -Wall
# -S -masm=intel
CC=gcc
CXX=g++
CXXFLAGS=-fno-rtti -fno-exceptions
@@ -19,14 +20,20 @@ LDFLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
# Files
OBJS=boot.o lang/lang_a.o \
kernel.o mm/mm.o mm/vmm.o lang/conv.o display/kout.o display/display.o \
sys/pic.o char/keyboard.o lang/lang.o \
kernel.o mm/mm.o mm/vmm.o lang/conv.o display/kout.o \
display/display.o sys/pic.o char/keyboard.o lang/lang.o \
sys/pci_classes.o proc/proc.o \
lang/string.o lang/new.o char/misc_char.o char/vconsole.o \
devices.o block/ramdisk.o fs/vfs.o fs/ext2/ext2.o
CSRC=kernel.c mm/mm.c mm/vmm.c lang/conv.c display/kout.c display/display.c \
sys/pic.c char/keyboard.c lang/lang.c
devices.o block/ramdisk.o fs/vfs.o fs/FileSystem.o fs/VFSMount.o \
fs/ext2/ext2.o fs/sysfs/sysfs.o fs/sysfs/sysfs_entry.o \
sys/pci.o
CSRC=kernel.c mm/mm.c mm/vmm.c lang/conv.c display/kout.c \
display/display.c sys/pic.c char/keyboard.c lang/lang.c \
sys/pci_classes.c proc/proc.c
CXXSRC=lang/string.cpp lang/new.cpp char/misc_char.cpp char/vconsole.cpp \
block/ramdisk.cpp devices.cpp fs/vfs.cpp fs/ext2/ext2.cpp
block/ramdisk.cpp devices.cpp fs/vfs.cpp fs/FileSystem.o fs/VFSMount.o\
fs/ext2/ext2.cpp fs/sysfs/sysfs.cpp fs/sysfs/sysfs_entry.cpp \
sys/pci.cpp
.PHONY: all depend clean html
@@ -44,7 +51,8 @@ lang/lang_a.o: lang/lang.asm
$(NASM) $(NASM_FLAGS) -l lang.lst lang/lang.asm -o lang/lang_a.o
clean:
-rm -f $(OBJS) *.bin *.map *.lst *.out *~ fs/*~ sys/*~ block/*~ char/*~ lang/*~ mm/*~ display/*~
-rm -f $(OBJS) *.bin *.map *.lst *.out
-find . -name '*~' | xargs rm -f
html:
-rm -rf html
@@ -71,6 +79,8 @@ sys/pic.o: hos_defines.h sys/pic.h sys/io.h
char/keyboard.o: hos_defines.h char/keyboard.h sys/io.h functions.h
char/keyboard.o: lang/conv.h display/kout.h display/display.h devices.h
lang/lang.o: lang/lang.h hos_defines.h
proc/proc.o: hos_defines.h proc/proc.h mm/mm.h kernel.h multiboot.h mm/vmm.h
proc/proc.o: lang/lang.h
lang/string.o: lang/string.h lang/lang.h hos_defines.h
lang/new.o: hos_defines.h mm/vmm.h multiboot.h
char/misc_char.o: hos_defines.h devices.h char/misc_char.h sys/io.h
@@ -82,6 +92,7 @@ block/ramdisk.o: lang/lang.h block/ramdisk.h devices.h
devices.o: hos_defines.h devices.h char/misc_char.h char/misc_char.h
devices.o: char/vconsole.h block/ramdisk.h
fs/vfs.o: hos_defines.h display/kout.h fs/vfs.h devices.h lang/string.h
fs/vfs.o: fs/FileSystem.h fs/VFSMount.h fs/FileSystem.h fs/vfs.h
fs/vfs.o: fs/ext2/ext2.h lang/vector.h
fs/ext2/ext2.o: display/kout.h hos_defines.h fs/ext2/ext2.h fs/vfs.h
fs/ext2/ext2.o: devices.h lang/string.h
fs/ext2/ext2.o: display/kout.h hos_defines.h mm/vmm.h multiboot.h lang/lang.h
fs/ext2/ext2.o: fs/ext2/ext2.h fs/vfs.h devices.h
+2 -1
View File
@@ -14,13 +14,14 @@ extern "C" {
#include "lang/string.h"
#include "fs/vfs.h"
VFSMount::VFSMount(device_t dev, FileSystem *fs, string mountPoint, inode_num_t mountInode)
VFSMount::VFSMount(device_t dev, FileSystem *fs, string mountPoint, inode_num_t mountInode, inode_num_t thisInode)
{
myDev = dev;
myFS = fs;
myRefs = 0;
myMountPoint = mountPoint;
myMountInode = mountInode;
myThisInode = thisInode;
}
VFSMount::~VFSMount()
+3 -3
View File
@@ -14,15 +14,15 @@
class VFSMount
{
protected:
public:
device_t myDev;
FileSystem *myFS;
int myRefs;
string myMountPoint;
inode_num_t myMountInode;
inode_num_t myThisInode;
public:
VFSMount(device_t dev, FileSystem *fs, string mountPoint, inode_num_t mountInode);
VFSMount(device_t dev, FileSystem *fs, string mountPoint, inode_num_t mountInode, inode_num_t thisInode);
~VFSMount();
};
+44
View File
@@ -0,0 +1,44 @@
// sysfs.cpp
// sysfs filesystem driver for HOS
// Author: Josh Holtrop
// Date: 06/27/05
// Modified: 06/27/05
#define _HOS_CPP_ _HOS_CPP_
extern "C" {
#include "display/kout.h"
}
#include "fs/vfs.h"
#include "sysfs.h"
#include "sysfs_entry.h"
int sysfs_init()
{
vfs_register("sysfs", sysfs__mount_func);
return 0;
}
FileSystem *sysfs__mount_func(device_t dev)
{
if (dev)
kprintf("sysfs: warning: device parameter ignored\n");
return new Sysfs();
}
Sysfs::Sysfs()
{
myEntries.add(Sysfs_Entry(SYSFS_FILE, "timer", SYSFS_TIMER));
}
Sysfs::~Sysfs()
{
}
u32_t Sysfs::getRootInodeNumber()
{
return 2;
}
+37
View File
@@ -0,0 +1,37 @@
// sysfs.h
// sysfs filesystem driver for HOS
// Author: Josh Holtrop
// Date: 06/27/05
// Modified: 06/27/05
#ifndef __HOS_SYSFS_H__
#define __HOS_SYSFS_H__ __HOS_SYSFS_H__
#define SYSFS_TIMER 1
#ifdef _HOS_CPP_
#include "fs/FileSystem.h"
#include "fs/vfs.h"
#include "lang/vector.h"
#include "lang/string.h"
#include "sysfs_entry.h"
int sysfs_init();
FileSystem *sysfs__mount_func(device_t dev);
class Sysfs : public FileSystem
{
protected:
vector<Sysfs_Entry> myEntries;
public:
Sysfs();
~Sysfs();
u32_t getRootInodeNumber();
};
#endif
#endif
+22
View File
@@ -0,0 +1,22 @@
// sysfs_entry.cpp
// sysfs filesystem driver for HOS
// Author: Josh Holtrop
// Date: 06/27/05
// Modified: 06/27/05
#define _HOS_CPP_ _HOS_CPP_
#include "sysfs_entry.h"
#include "lang/string.h"
Sysfs_Entry::Sysfs_Entry(int type, string name, int id)
{
myType = type;
myName = name;
myID = id;
}
Sysfs_Entry::~Sysfs_Entry()
{
}
+30
View File
@@ -0,0 +1,30 @@
// sysfs_entry.h
// sysfs filesystem driver for HOS
// Author: Josh Holtrop
// Date: 06/27/05
// Modified: 06/27/05
#ifndef __HOS_SYSFS_ENTRY_H__
#define __HOS_SYSFS_ENTRY_H__ __HOS_SYSFS_ENTRY_H__
#include "lang/vector.h"
#include "lang/string.h"
#define SYSFS_DIR 1
#define SYSFS_FILE 2
class Sysfs_Entry
{
protected:
int myType;
string myName;
int myID;
vector<Sysfs_Entry> myChildren;
public:
Sysfs_Entry(int type, string name, int id);
~Sysfs_Entry();
};
#endif
+16 -9
View File
@@ -19,7 +19,6 @@ extern "C" {
#include "lang/string.h"
#include "devices.h"
inode_num_t rootInode;
vector<VFSMount> *mountPoints;
vector<FSHandle> *fses;
@@ -31,7 +30,7 @@ int vfs_init()
return 0;
}
int vfs_register(char *fs, FileSystem *(*mount_func)(device_t))
int vfs_register(char *fs, mount_func_t mount_func)
{
string fsName(fs);
if (vfs_get_mount_func(fsName))
@@ -57,15 +56,18 @@ int vfs_mount(device_t device, char *fsType, char *mountPoint)
FileSystem *fs = vfs_attempt_mount(device, fsType);
if (fs == NULL)
return -2;
rootInode = fs->getRootInodeNumber();
mountPoints->add(VFSMount(device, fs, mountPt, 0));
mountPoints->add(VFSMount(device, fs, mountPt, 0, fs->getRootInodeNumber()));
return 0;
}
else
{
// TODO: mount a second filesystem
}
return 500;
inode_num_t mtInode = vfs_get_inode(mountPt);
if (mtInode == 0)
return -3;
FileSystem *fs = vfs_attempt_mount(device, fsType);
if (fs == NULL)
return -2;
inode_num_t thisInode = ((u64_t)(mountPoints->size()) << 32) | fs->getRootInodeNumber();
mountPoints->add(VFSMount(device, fs, mountPt, mtInode, thisInode));
return 0;
}
FileSystem *vfs_attempt_mount(device_t device, char *fsType)
@@ -77,6 +79,11 @@ FileSystem *vfs_attempt_mount(device_t device, char *fsType)
return NULL;
}
inode_num_t vfs_get_inode(const string & path)
{
return 0;
}
mount_func_t vfs_get_mount_func(const string & fsName)
{
for (unsigned int i = 0; i < fses->size(); i++)
+23 -4
View File
@@ -34,6 +34,23 @@
#include "hos_defines.h"
#include "devices.h"
typedef struct
{
u16_t type; // file type, of VFS_FILE_TYPE_*
u32_t size;
u32_t inode;
u16_t permissions;
u16_t uid;
u16_t gid;
u32_t atime;
u32_t mtime;
u32_t ctime;
u16_t links;
u32_t dev;
} vfs_stat_t;
typedef u64_t inode_num_t;
#ifdef _HOS_CPP_
@@ -42,6 +59,7 @@ extern "C" {
int vfs_init();
int vfs_mount(device_t device, char *fsType, char *mountPoint);
int vfs_stat(char *name, vfs_stat_t *buff);
#ifdef _HOS_CPP_
}
@@ -50,17 +68,18 @@ int vfs_mount(device_t device, char *fsType, char *mountPoint);
#include "fs/FileSystem.h"
#include "fs/VFSMount.h"
typedef FileSystem *(*mount_func_t)(device_t);
typedef struct
{
string name;
mount_func_t mount_func;
FileSystem *(*mount_func)(device_t);
} FSHandle;
typedef FileSystem *(*mount_func_t)(device_t);
FileSystem *vfs_attempt_mount(device_t device, char *fsType);
int vfs_register(char *fs, FileSystem *(*mount_func)(device_t));
int vfs_register(char *fs, mount_func_t mount_func);
mount_func_t vfs_get_mount_func(const string & fsName);
inode_num_t vfs_get_inode(const string & path);
#endif
+7 -28
View File
@@ -9,6 +9,7 @@ gdtr:
gdt:
dd 0
dd 0
KERNEL_CODE equ $-gdt
dw 0xffff ;limit 15:0
dw 0x0000 ;base 15:0
@@ -16,6 +17,7 @@ KERNEL_CODE equ $-gdt
db 0x9A ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16
db 0x00 ;base 31:24
KERNEL_DATA equ $-gdt
dw 0xffff ;limit 15:0
dw 0x0000 ;base 15:0
@@ -23,6 +25,8 @@ KERNEL_DATA equ $-gdt
db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16
db 0x00 ;base 31:24
USER_CODE equ $-gdt
dw 0xffff ;limit 15:0
dw 0x0000 ;base 15:0
@@ -30,6 +34,7 @@ USER_CODE equ $-gdt
db 0xFA ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16
db 0x00 ;base 31:24
USER_DATA equ $-gdt
dw 0xffff ;limit 15:0
dw 0x0000 ;base 15:0
@@ -37,34 +42,8 @@ USER_DATA equ $-gdt
db 0xF2 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
db 0xCF ;flags ([G][D/B][0][0]) / limit 19:16
db 0x00 ;base 31:24
VESA_CODE equ $-gdt
dw 0xffff ;limit 15:0
dw 0x0000 ;base 15:0
db 0x00 ;base 23:16
db 0x9A ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16
db 0x00 ;base 31:24
VESA_DATA equ $-gdt
dw 0xffff ;limit 15:0
dw 0x0000 ;base 15:0
db 0x00 ;base 23:16
db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16
db 0x00 ;base 31:24
VIDEO_TEXT equ $-gdt
dw 0x7FFF ;limit 15:0
dw 0x8000 ;base 15:0
db 0x0B ;base 23:16
db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16
db 0x00 ;base 31:24
VIDEO_GRAPHICS equ $-gdt
dw 0xFFFF ;limit 15:0
dw 0x0000 ;base 15:0
db 0x0A ;base 23:16
db 0x92 ;access ([P][DPL][1][Executable][Direction/Conforming][Writable/Readable][A])
db 0x40 ;flags ([G][D/B][0][0]) / limit 19:16
db 0x00 ;base 31:24
gdt_end:
+1
View File
@@ -0,0 +1 @@
53 97 193 389 769 1543 3079 6151 12289 24593 49157
+6 -2
View File
@@ -70,11 +70,15 @@ isr_main:
pusha
push ds
push es
push fs
push gs
push esp
push eax ;interrupt number
call _isr
add esp, 4
add esp, 8
pop gs
pop fs
pop es
pop ds
popa
+15 -4
View File
@@ -1,7 +1,7 @@
// kernel.h
// Author: Josh Holtrop
// Date: 08/16/04
// Modified: 03/19/05
// Modified: 08/18/05
// This is the main kernel initialization and boot-strapping file
#include "kernel.h"
@@ -21,6 +21,8 @@
#include "block/ramdisk.h"
#include "fs/vfs.h"
#include "fs/ext2/ext2.h"
#include "sys/pci.h"
#include "proc/proc.h"
mb_info_t mb_info_block;
mb_mmap_t mb_mmap[MAX_MMAP];
@@ -129,6 +131,7 @@ void k_init()
kprintf("Kernel load size: %d (0x%x) bytes (%d kb)\n", kernel_size(), kernel_size(), kernel_size() >> 10);
kprintf("Kernel memory size: %d (0x%x) bytes (%d kb)\n", kernel_size_used(), kernel_size_used(), kernel_size_used() >> 10);
k_check(pci_init(), "pci_init() failed!");
k_check(vfs_init(), "vfs_init() failed!");
int i;
@@ -143,6 +146,13 @@ void k_init()
kprintf("initrd (%dkb) loaded\n", (mb_modules[i].mod_end - mb_modules[i].mod_start) >> 10);
k_check(vfs_mount(DEV(MAJOR_RAMDISK, initrd_minor), "ext2", "/"), "Kernel panic: Could not mount initrd to /!");
}
if (((hos_module_header_t*)(mb_modules[i].mod_start))->mod_type == 2)
{
create_task(mb_modules[i].mod_start,
mb_modules[i].mod_end - mb_modules[i].mod_end,
0,
((hos_module_header_t*)(mb_modules[i].mod_start))->init);
}
}
/* vfs_open_file_t *root = vfs_open_dir("////");
@@ -187,14 +197,14 @@ void k_init()
criticalCounter--;
}
void isr(u32_t num)
void isr(u32_t num, int_stack_t *stack_frame)
{
criticalCounter++;
switch (num)
{
case 0x20: // timer
(*(u16_t *)CONSOLE_MEMORY)++;
timer++;
proc_sched(stack_frame);
pic_eoi();
break;
case 0x21: // keyboard
@@ -202,7 +212,8 @@ void isr(u32_t num)
pic_eoi();
break;
case 0x30:
kprintf("User interrupt requested\n");
if (stack_frame->eax == 1)
kputc(stack_frame->ebx);
break;
default:
kprintf("Unhandled interrupt #%d, CR2 = 0x%x!\n", num, read_cr2());
+28 -3
View File
@@ -1,7 +1,7 @@
// kernel.h
// Author: Josh Holtrop
// Date: 08/16/04
// Modified: 01/04/05
// Modified: 08/18/05
#ifndef __HOS_KERNEL_H__
#define __HOS_KERNEL_H__ __HOS_KERNEL_H__
@@ -9,17 +9,42 @@
#include "hos_defines.h"
#include "multiboot.h"
typedef struct {
typedef struct
{
void *vid_addr; // address of LFB, 0 if console mode
u32_t width; // width in pixels or columns if vid_mem == 0
u32_t height; // height in pixels or columns if vid_mem == 0
u32_t bpp; // bits per pixel - 15/16/24/32
} __attribute__ ((packed)) real_mode_param_t;
pusha
push ds
push es
push fs
push gs
push esp
typedef struct
{
u32_t gs;
u32_t fs;
u32_t es;
u32_t ds;
u32_t edi; /* pusha */
u32_t esi;
u32_t ebp;
u32_t esp;
u32_t ebx;
u32_t edx;
u32_t ecx;
u32_t int_num; /* The eax that pusha pushed is int # */
u32_t eax; /* We saved the real eax manually */
} int_stack_t;
/* returns true to callee if we should jump to a real mode module */
mb_module_t *k_mbsave(mb_info_t *mbinfo, unsigned int mb_magic);
void _init();
void isr();
void isr(u32_t num, int_stack_t *stack_frame);
void k_enter_critical(); // functions for implementing "atomic actions"
void k_leave_critical();
void k_check(int val, char *msg);
+2
View File
@@ -9,6 +9,8 @@
#ifndef __HOS_VECTOR__
#define __HOS_VECTOR__ __HOS_VECTOR__
#include "hos_defines.h"
template<typename type>
class vector
{
+16 -4
View File
@@ -18,7 +18,6 @@ int vmm_coalesceEntry(u32_t queue, HeapEntry_t *newHE);
void vmm_heb_init(HeapEntryBlock_t *heb);
void vmm_addToQueue(u32_t queue, HeapEntry_t *preceeding, HeapEntry_t *he);
int vmm_countHeapEntries(HeapEntry_t *he);
int vmm_unmapp(void *addr);
HeapEntry_t *vmm_followChain(HeapEntry_t *he);
HeapEntry_t *vmm_getUnusedEntry();
HeapEntry_t *vmm_stripUnusedEntry();
@@ -57,10 +56,16 @@ void vmm_init()
/* Allocate a physical page and map the virtual address to it, return physical address allocated or NULL */
int vmm_map(void *virt)
{
u32_t dum;
return vmm_map_addr(virt, &dum);
}
int vmm_map_addr(void *virt, u32_t *phys_addr)
{
if (mm_freepages < 10)
return -1;
return vmm_map1((u32_t)virt, mm_palloc());
return vmm_map1((u32_t)virt, *phys_addr = mm_palloc());
}
@@ -191,6 +196,12 @@ int kfree(void *addr)
// This function allocates a virtual page and maps it to a physical page
void *vmm_palloc()
{
u32_t dum;
return vmm_palloc_addr(&dum);
}
void *vmm_palloc_addr(u32_t *phys_addr)
{
k_enter_critical();
HeapEntry_t *he = heapEntryQueues[VMM_HE_HOLE].head->next;
@@ -201,7 +212,7 @@ void *vmm_palloc()
{
vmm_removeHeapEntry(VMM_HE_HOLE, he);
vmm_addToQueue(VMM_HE_USED, &heapEntryHeadNodes[VMM_HE_USED], he);
if (vmm_map(he->base))
if (vmm_map_addr(he->base, phys_addr))
he->base = NULL;
k_leave_critical();
return he->base;
@@ -220,7 +231,7 @@ void *vmm_palloc()
he->base = wilderness->base + wilderness->length;
he->length = 4096;
vmm_addToQueue(VMM_HE_USED, &heapEntryHeadNodes[VMM_HE_USED], he);
if (vmm_map(he->base))
if (vmm_map_addr(he->base, phys_addr))
he->base = NULL;
k_leave_critical();
return he->base;
@@ -236,6 +247,7 @@ int vmm_pfree(void *addr)
if (vmm_unmapp(addr))
return -1;
mm_pfree(pbase);
return 0;
}
int vmm_unmapp(void *addr)
+3
View File
@@ -40,11 +40,14 @@ typedef struct {
void vmm_init();
void *kmalloc(u32_t size);
int kfree(void *addr);
int vmm_unmapp(void *addr);
void *vmm_palloc();
void *vmm_palloc_addr(u32_t *phys_addr);
int vmm_pfree(void *addr);
void *kcalloc(unsigned int number, unsigned int size);
int vmm_map(void *virt);
int vmm_map_addr(void *virt, u32_t *phys_addr);
int vmm_map1(unsigned int virt, unsigned int physical);
int vmm_mapn(unsigned int virt, unsigned int physical, unsigned int n);
void vmm_unmap1(unsigned int virt);
+149
View File
@@ -0,0 +1,149 @@
// proc.c
// Author: Josh Holtrop
// Date; 08/18/05
// Modified: 08/18/05
extern int mm_freepages;
#include "hos_defines.h"
#include "proc.h"
#include "mm/mm.h"
#include "mm/vmm.h"
#include "lang/lang.h"
#include "kernel.h"
u32_t cur_task = 0;
u32_t n_processes = 0;
process_t *processes[3];
int proc_init()
{
return 0;
}
void proc_sched(int_stack_t *stack_frame)
{
cur_task = (cur_task + 1) & 1;
write_cr3(processes[cur_task]
}
u32_t create_task(void *base, u32_t image_size, u32_t bss_size, void *entry);
{
process_t *proc = create_process(vase, image_size, bss_size, entry);
processes[n_processes] = proc;
return n_processes++;
}
process_t *create_process(void *base, u32_t image_size, u32_t bss_size, void *entry);
{
if (mm_freepages < pages + bsspages + 25)
return 0;
process_t *process = New(process_t); /* Allocate process_t struct */
create_address_space(process);
create_process_stack(process);
int i;
u32_t *ptr32 = process->v_page_dir = vmm_palloc();
for (i = 0; i < 1024; i++)
*ptr32++ = 0;
u32_t code_data_pages = (image_size >> 12) +
((image_size & 0x3FF) ? 1 : 0);
u32_t bss_pages = (bss_size >> 12) + ((bss_size & 0x3FF) ? 1 : 0);
/* Load program at address 0 */
copy_into_address_space(0, base, code_data_pages, process);
zero_address_space(code_data_pages << 12, bss_pages, process);
ptr32 = process->v_page_dir;
for (i = 0; i < 1024; i++)
if (*ptr32)
vmm_unmapp(*ptr32);
vmm_unmapp(process->v_page_dir);
process->v_page_dir = 0;
return process;
}
void create_address_space(process_t *p)
{
/* Allocate a new page directory */
p->page_dir = vmm_palloc_addr(&p->p_page_dir);
int i;
u32_t *ptr32 = p->page_dir;
for (i = 0; i < 768; i++) /* zero 3 gigs */
*ptr32++ = 0;
memcpyd(ptr32, (void *)0xFFFFF000, 256); /* 1 gig kernel mem */
}
void create_process_stack(process_t *p)
{
u32_t p_stack_table, p_stack;
u32_t *v_stack_table = vmm_palloc_addr(&p_stack_table);
void *v_stack = vmm_palloc_addr(&p_stack);
int i;
u32_t *ptr32 = v_stack_table;
for (int i = 0; i < 1023; i++)
*ptr32++ = 0;
v_stack_table[1032] = p_stack | 0x7; /* user permissions */
p->page_dir[511] = p_stack_table | 0x7;
vmm_unmapp(v_stack_table);
vmm_unmapp(v_stack);
p->esp = 0x80000000; /* Stack at 2GB */
}
/* Copy pages into new address space (v_page_dir must be set up) */
void copy_into_address_space(u32_t dest_addr,
void *src_addr,
u32_t pages,
process_t *p)
{
u32_t pde, pte;
void *page;
while (pages)
{
pde = dest_addr >> 22;
pte = (dest_addr >> 12) & 0x3FF;
u32_t p_page_addr;
if (!p->v_page_dir[pde])
{
/* Time for a new page table & page directory entry! */
p->v_page_dir[pde] = vmm_palloc_addr(&p_page_addr);
p->page_dir[pde] = p_page_addr | 0x7;
vmm_unmapp(p->v_page_dir[pde]);
}
page = vmm_palloc_addr(&p_page_addr);
((u32_t *)(p->v_page_dir[pde]))[pte] = p_page_addr | 0x7;
memcpyd(page, src_addr, 1024);
vmm_unmapp(page);
dest_addr += 4096;
src_addr += 4096;
pages--;
}
}
/* Zeros pages into new address space (v_page_dir must be set up) */
void zero_address_space(u32_t dest_addr, u32_t pages, process_t *p)
{
u32_t pde, pte;
void *page;
while (pages)
{
pde = dest_addr >> 22;
pte = (dest_addr >> 12) & 0x3FF;
u32_t p_page_addr;
if (!p->v_page_dir[pde])
{
/* Time for a new page table & page directory entry! */
p->v_page_dir[pde] = vmm_palloc_addr(&p_page_addr);
p->page_dir[pde] = p_page_addr | 0x7;
vmm_unmapp(p->v_page_dir[pde]);
}
page = vmm_palloc_addr(&p_page_addr);
((u32_t *)(p->v_page_dir[pde]))[pte] = p_page_addr | 0x7;
memsetd(page, 0, 1024);
vmm_unmapp(page);
dest_addr += 4096;
pages--;
}
}
u32_t fork(process_t *p)
{
return 0;
}
+37
View File
@@ -0,0 +1,37 @@
// proc.h
// Author: Josh Holtrop
// Date; 08/18/05
// Modified: 08/18/05
#ifndef __HOS_PROC_H__
#define __HOS_PROC_H__ __HOS_PROC_H__
#include "hos_defines.h"
#include "kernel.h"
typedef struct
{
u32_t *page_dir; /* Page directory with physical PT addys */
u32_t *v_page_dir; /* Virtual page table addresses for init */
u32_t p_page_dir; /* Physical address of page directory */
u32_t size; /* Process size, bytes from 0 through bss */
u32_t esp; /* Process stack pointer */
int_stack_frame_t stack_frame;
} process_t;
int proc_init(int_stack_t *stack_frame);
void proc_sched();
u32_t create_task(void *base, u32_t image_size, u32_t bss_size, void *entry);
process_t *create_process(void *base, u32_t image_size, u32_t bss_size, void *entry);
void create_address_space(process_t *p);
void create_process_stack(process_t *p);
void copy_into_address_space(u32_t dest_addr,
void *src_addr,
u32_t pages,
process_t *p);
void zero_address_space(u32_t dest_addr, u32_t pages, process_t *p);
u32_t fork(process_t *p);
#endif
+26 -7
View File
@@ -13,25 +13,44 @@
//inline unsigned char inportb(unsigned short port);
//Writes a byte out to a port
static inline void outportb(unsigned int port, unsigned char value) // Output a byte to a port
static inline void outportb(unsigned int port, unsigned int value) // Output a byte to a port
{
asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
}
//Writes a word out to a port
static inline void outportw(unsigned int port, unsigned int value) // Output a word to a port
{
asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value));
asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value));
}
//Writes a dword out to a port
static inline void outportd(unsigned int port, unsigned int value) // Output a word to a port
{
asm volatile ("outl %%eax,%%dx"::"d" (port), "a" (value));
}
//Reads a byte from a port
static inline unsigned char inportb(unsigned short port)
static inline unsigned char inportb(unsigned int port)
{
unsigned char ret_val;
asm volatile("inb %w1,%b0" : "=a"(ret_val) : "d"(port));
return ret_val;
}
asm volatile("inb %w1,%b0"
: "=a"(ret_val)
: "d"(port));
//Reads a word from a port
static inline unsigned short inportw(unsigned int port)
{
unsigned int ret_val;
asm volatile("inw %w1,%w0" : "=a"(ret_val) : "d"(port));
return ret_val;
}
//Reads a dword from a port
static inline unsigned int inportd(unsigned int port)
{
unsigned int ret_val;
asm volatile("inl %w1,%0" : "=a"(ret_val) : "d"(port));
return ret_val;
}
+61
View File
@@ -0,0 +1,61 @@
// pci.cpp
// Author: Josh Holtrop
// Date: 07/13/05
// Modified: 07/17/05
#define _HOS_CPP_
extern "C" {
#include "hos_defines.h"
#include "display/kout.h"
#include "sys/io.h"
}
#include "pci.h"
#include "lang/vector.h"
vector<pci_header_t> *pci_devices;
int pci_init()
{
pci_devices = new vector<pci_header_t>;
pci_scanBus(0);
return 0;
}
void pci_scanBus(u32_t bus)
{
pci_header_t pciHdr;
u32_t dev, func, off, reg, numFuncs;
for (dev = 0; dev < 32; dev++)
{
numFuncs = 1;
for (func = 0; func < 8; func++)
{
reg = pci_readConfigRegister(bus, dev, func, 0);
if (reg != 0 && reg != 0xFFFFFFFF)
{
for (off = 0; off < 0x40; off += 4)
*((u32_t *)(((u32_t)&pciHdr)+off)) = pci_readConfigRegister(bus, dev, func, off);
pci_devices->add(pciHdr);
if (func == 0 && (pciHdr.header & 0x80))
numFuncs = 8;
kprintf("PCI device %d.%d.%d:\t(%s)\n", bus, dev, func, pci_getDeviceClass(pciHdr.cls, pciHdr.subclass, pciHdr.progif));
if ((pciHdr.header & 0x7F) == 1)
pci_scanBus(pciHdr.h1_bus1);
}
}
}
}
u32_t pci_readConfigRegister(u32_t bus, u32_t dev, u32_t func, u32_t offset)
{
outportd(PCI_CONFIG_ADDRESS,
0x80000000 |
((bus & 0xFF) << 16) |
((dev & 0x1F) << 11) |
((func & 0x7) << 8) |
(offset & 0xFC));
return inportd(PCI_CONFIG_DATA);
}
+75
View File
@@ -0,0 +1,75 @@
// pci.h
// Author: Josh Holtrop
// Date: 07/13/05
// Modified: 07/13/05
#ifndef __HOS_PCI__
#define __HOS_PCI__ __HOS_PCI__
#define PCI_CONFIG_ADDRESS 0xCF8
#define PCI_CONFIG_DATA 0xCFC
#define PCI_HEADER_MF_MASK 0x80
#include "hos_defines.h"
typedef struct
{
u8_t subclass;
u8_t progif;
char *desc;
} pci_class_t;
typedef struct
{
u16_t vendorID; /* 0x00 Vender ID Number */
u16_t deviceID; /* 0x02 Device ID Number */
u16_t command; /* 0x04 Command Register */
u16_t status; /* 0x06 Status Register */
u8_t revision; /* 0x08 Revision ID */
u8_t progif; /* 0x09 Programming Interface */
u8_t subclass; /* 0x0A Subclass Number */
u8_t cls; /* 0x0B PCI Device Class */
u8_t cacheLineSize; /* 0x0C Cache Line Size (for DMA) */
u8_t latency; /* 0x0D Latency Timer (PCI Bus cycles) */
u8_t header; /* 0x0E bit7:multifunc, 0-6: header format */
u8_t bist; /* 0x0F Built-In Self Test Result */
/* Header-specific fields */
u32_t bar0; /* 0x10 */
u32_t bar1; /* 0x14 */
union { /* 0x18 */
u32_t bar2;
struct {
u8_t h1_bus0;
u8_t h1_bus1;
u8_t h1_secBus;
u8_t h1_secLatency;
};
};
u32_t bar3; /* 0x1C */
u32_t bar4; /* 0x20 */
u32_t bar5; /* 0x24 */
u32_t cardbusCIS; /* 0x28 ro */
u16_t ssVendorID; /* 0x2C */
u16_t ssID; /* 0x2E */
u32_t expansionAddr; /* 0x30 */
u32_t reserved[2]; /* 0x34 */
u8_t irq; /* 0x3C IRQ Number, 0 if none */
u8_t intPin; /* 0x3D Interrupt Pin, 0 if none, ro */
u8_t minGrant; /* 0x3E 250ns units, ro */
u8_t maxLatency; /* 0x3F 250ns units, ro */
} pci_header_t;
#ifdef _HOS_CPP_
extern "C" {
#endif
int pci_init();
u32_t pci_readConfigRegister(u32_t bus, u32_t dev, u32_t func, u32_t offset);
char *pci_getDeviceClass(u8_t cls, u8_t sub, u8_t progif);
void pci_scanBus(u32_t bus);
#ifdef _HOS_CPP_
}
#endif
#endif
+112
View File
@@ -0,0 +1,112 @@
// pci_classes.c
// Author: Josh Holtrop
// Date: 07/21/05
// Modified: 07/21/05
// Had to be a C file because g++ doesn't like pci_classes declaration
#include "hos_defines.h"
#include "pci.h"
pci_class_t* pci_classes[] =
{
(pci_class_t[]) {
{1, 1, "Generic PCI VGA Device"},
{0xFF, 0xFF, "Generic PCI Device"}
},
(pci_class_t[]) {
{0, 0, "SCSI Controller"},
{1, 0xFF, "IDE Controller"},
{2, 0, "Floppy Disk Controller"},
{3, 0, "IPI Controller"},
{4, 0, "RAID Controller"},
{0xFF, 0xFF, "Generic Mass Storage Controller"}
},
(pci_class_t[]) {
{0, 0, "Ethernet Controller"},
{1, 0, "Token Ring Network Controller"},
{2, 0, "FDDI Controller"},
{3, 0, "ATM Controller"},
{0xFF, 0xFF, "Generic Network Controller"}
},
(pci_class_t[]) {
{0, 0, "VGA Compatible Controller"},
{0, 1, "8514 Compatible Display Controller"},
{1, 0, "XGA Controller"},
{0xFF, 0xFF, "Generic Display Controller"}
},
(pci_class_t[]) {
{0, 0, "Multimedia Video Device"},
{0, 0, "Multimedia Audio Device"},
{0xFF, 0xFF, "Generic Multimedia Device"}
},
(pci_class_t[]) {
{0, 0, "RAM Controller"},
{1, 0, "Flash Memory Controller"},
{0xFF, 0xFF, "Generic Memory Controller"}
},
(pci_class_t[]) {
{0, 0, "Host/PCI Bridge"},
{1, 0, "PCI/ISA Bridge"},
{2, 0, "PCI/EISA Bridge"},
{3, 0, "PCI/Micro Channel Bridge"},
{4, 0, "PCI/PCI Bridge"},
{5, 0, "PCI/PCMCIA Bridge"},
{6, 0, "PCI/NuBus Bridge"},
{7, 0, "PCI/CardBus Bridge"},
{0xFF, 0xFF, "Generic Bridge"}
},
(pci_class_t[]) {
{0, 0xFF, "Serial Controller"},
{1, 0xFF, "Parallel Port"},
{0xFF, 0xFF, "Generic Communications Device"}
},
(pci_class_t[]) {
{0, 0xFF, "Programmable Interrupt Controller"},
{1, 0xFF, "DMA Controller"},
{2, 0xFF, "System Timer"},
{3, 0xFF, "RTC Controller"},
{0xFF, 0xFF, "Generic System Peripheral"}
},
(pci_class_t[]) {
{0, 0, "Keyboard Controller"},
{1, 0, "Digitizer (Pen)"},
{2, 0, "Mouse Controller"},
{0xFF, 0xFF, ""}
},
(pci_class_t[]) {
{0xFF, 0xFF, "Docking Station"}
},
(pci_class_t[]) {
{0, 0, "386 Processor"},
{1, 0, "486 Processor"},
{2, 0, "Pentium Processor"},
{0x10, 0, "Alpha Processor"},
{0x20, 0, "PowerPC Processor"},
{0x40, 0, "Co-Processor"},
{0xFF, 0xFF, "Generic Processor"}
},
(pci_class_t[]) {
{0, 0, "Firewire (IEEE 1394) Controller"},
{1, 0, "ACCESS Bus Controller"},
{2, 0, "SSA (Serial Storage Architecture) Controller"},
{3, 0, "USB Controller"},
{0xFF, 0xFF, "Generic Serial Bus Controller"}
}
};
char *pci_getDeviceClass(u8_t cls, u8_t sub, u8_t progif)
{
if (cls < sizeof(pci_classes)/sizeof(pci_class_t *))
{
pci_class_t *pcls = pci_classes[cls];
for (;;)
{
if ( (pcls->subclass == 0xFF || pcls->subclass == sub)
&& (pcls->progif == 0xFF || pcls->progif == progif) )
return pcls->desc;
pcls++;
}
}
return "Unknown PCI Device";
}