Import backup from 2004-09-21

This commit is contained in:
Josh Holtrop 2004-09-21 22:00:00 -04:00
parent 78272f6bc3
commit bad7f79ed1
32 changed files with 696 additions and 273 deletions

View File

@ -12,12 +12,12 @@ MAKEFLAGS += --no-print-directory
all: all:
make -C kernel make -C kernel
# make -C rmmod make -C rmmod
clean: clean:
-make -C kernel clean -make -C kernel clean
-make -C rmmod clean -make -C rmmod clean
- rm *~ *.out hos.flp \#* -rm -f *~ *.out hos.flp \#*
grub: grub:
@ -35,6 +35,7 @@ install:
-mkdir $(FLOPPY_MOUNT) -mkdir $(FLOPPY_MOUNT)
mount -t ext2 $(FLOPPY) $(FLOPPY_MOUNT) mount -t ext2 $(FLOPPY) $(FLOPPY_MOUNT)
cp kernel/kernel.bin $(FLOPPY_MOUNT) cp kernel/kernel.bin $(FLOPPY_MOUNT)
cp rmmod/rmmod.bin $(FLOPPY_MOUNT)
cp menu.lst $(FLOPPY_MOUNT)/boot/grub cp menu.lst $(FLOPPY_MOUNT)/boot/grub
umount $(FLOPPY_MOUNT) umount $(FLOPPY_MOUNT)
-rmdir $(FLOPPY_MOUNT) -rmdir $(FLOPPY_MOUNT)
@ -44,6 +45,7 @@ install_img:
cp grub.flp $(FLOPPY_IMAGE) cp grub.flp $(FLOPPY_IMAGE)
mount -t ext2 -o loop $(FLOPPY_IMAGE) $(FLOPPY_MOUNT) mount -t ext2 -o loop $(FLOPPY_IMAGE) $(FLOPPY_MOUNT)
cp kernel/kernel.bin $(FLOPPY_MOUNT) cp kernel/kernel.bin $(FLOPPY_MOUNT)
cp rmmod/rmmod.bin $(FLOPPY_MOUNT)
cp menu.lst $(FLOPPY_MOUNT)/boot/grub cp menu.lst $(FLOPPY_MOUNT)/boot/grub
umount $(FLOPPY_MOUNT) umount $(FLOPPY_MOUNT)
-rmdir $(FLOPPY_MOUNT) -rmdir $(FLOPPY_MOUNT)

View File

@ -1,7 +1,7 @@
# Makefile for HOS # Makefile for HOS
# Josh Holtrop # Josh Holtrop
# Created: 07/08/04 # Created: 07/08/04
# Modified: 07/11/04 # Modified: 08/22/04
# Assembler Information: # Assembler Information:
NASM=nasm NASM=nasm
@ -16,8 +16,10 @@ LD=ld
LD_FLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld LD_FLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
all: Asm_Kernel C_Kernel all: Asm_Kernel C_Kernel
$(LD) $(LD_FLAGS) -Map kernel.map boot.o kernel.o asmfuncs.o mm.o vmm.o parallel.o \ $(LD) $(LD_FLAGS) -Map kernel.map \
conv.o kout.o vconsole.o console.o devices.o pic.o keyboard.o -o kernel.bin boot.o kernel.o asmfuncs.o mm.o vmm.o parallel.o conv.o kout.o \
vconsole.o display.o devices.o pic.o keyboard.o ramdisk.o vfs.o \
devfs.o -o kernel.bin
Asm_Kernel: Asm_Kernel:
$(NASM) $(NASM_FLAGS) -l boot.lst boot.asm -o boot.o $(NASM) $(NASM_FLAGS) -l boot.lst boot.asm -o boot.o
@ -32,14 +34,17 @@ C_Kernel:
$(CC) $(CC_FLAGS) -c kout.c -o kout.o $(CC) $(CC_FLAGS) -c kout.c -o kout.o
$(CC) $(CC_FLAGS) -c char/vconsole.c -o vconsole.o $(CC) $(CC_FLAGS) -c char/vconsole.c -o vconsole.o
$(CC) $(CC_FLAGS) -c fs/devices.c -o devices.o $(CC) $(CC_FLAGS) -c fs/devices.c -o devices.o
$(CC) $(CC_FLAGS) -c console.c -o console.o $(CC) $(CC_FLAGS) -c display.c -o display.o
$(CC) $(CC_FLAGS) -c sys/pic.c -o pic.o $(CC) $(CC_FLAGS) -c sys/pic.c -o pic.o
$(CC) $(CC_FLAGS) -c char/keyboard.c -o keyboard.o $(CC) $(CC_FLAGS) -c char/keyboard.c -o keyboard.o
$(CC) $(CC_FLAGS) -c block/ramdisk.c -o ramdisk.o
$(CC) $(CC_FLAGS) -c fs/devfs.c -o devfs.o
$(CC) $(CC_FLAGS) -c fs/vfs.c -o vfs.o
################################################# #################################################
# Clean up the source directory of any binaries # # Clean up the source directory of any binaries #
################################################# #################################################
clean: clean:
- rm *.o *.bin *.map *.lst *.out *~ fs/*~ sys/*~ block/*~ char/*~ lang/*~ mm/*~ -rm -f *.o *.bin *.map *.lst *.out *~ fs/*~ sys/*~ block/*~ char/*~ lang/*~ mm/*~

100
kernel/block/ramdisk.c Normal file
View File

@ -0,0 +1,100 @@
// ramdisk.c
// Author: Josh Holtrop
// Date: 08/20/04
// Modified: 08/22/04
#include "block/ramdisk.h"
#include "fs/devices.h"
#include "functions.h"
#include "mm/vmm.h"
#include "lang/asmfuncs.h"
ramdisk_t *ramdisks[256];
int ramdisk_init(major_t major)
{
dev_driver_t *ramdisk_driver;
if (( ramdisk_driver = New(dev_driver_t) ))
{
ramdisk_driver->block_read = ramdisk_block_read;
ramdisk_driver->block_write = ramdisk_block_write;
devices_register_major('b', major, ramdisk_driver);
return 0;
}
return -1;
}
minor_t ramdisk_new(u32_t size)
{
int i;
for (i = 0; i < 256; i++)
{
if (!ramdisks[i])
{
void *start;
if (( start = kmalloc(size) ))
{
ramdisks[i] = New(ramdisk_t);
ramdisks[i]->start = start;
ramdisks[i]->size = size;
return i;
}
return -2;
}
}
return -1;
}
minor_t ramdisk_register(void *ramdisk, u32_t size)
{
int i;
for (i = 0; i < 256; i++)
{
if (!ramdisks[i])
{
ramdisks[i] = New(ramdisk_t);
ramdisks[i]->start = ramdisk;
ramdisks[i]->size = size;
return i;
}
}
return -1;
}
int ramdisk_remove(minor_t minor)
{
if (ramdisks[minor])
{
kfree(ramdisks[minor]->start);
kfree(ramdisks[minor]);
ramdisks[minor] = NULL;
return 0;
}
return -1;
}
int ramdisk_block_read(minor_t minor, u32_t blockNum, u32_t count, void *buffer)
{
if (!ramdisks[minor])
return -1;
if ((blockNum << BLOCK_SIZE_LOG) >= ramdisks[minor]->size)
return -2;
void *rdAddr = ramdisks[minor]->start + (blockNum << BLOCK_SIZE_LOG);
u32_t copyLen = min(count << BLOCK_SIZE_LOG, ramdisks[minor]->size - (u32_t)rdAddr);
memcpyd(buffer, rdAddr, copyLen >> 2);
return copyLen;
}
int ramdisk_block_write(minor_t minor, u32_t blockNum, u32_t count, void *buffer)
{
if (!ramdisks[minor])
return -1;
if ((blockNum << BLOCK_SIZE_LOG) >= ramdisks[minor]->size)
return -2;
void *rdAddr = ramdisks[minor]->start + (blockNum << BLOCK_SIZE_LOG);
u32_t copyLen = min(count << BLOCK_SIZE_LOG, ramdisks[minor]->size - (u32_t)rdAddr);
memcpyd(rdAddr, buffer, copyLen >> 2);
return copyLen;
}

25
kernel/block/ramdisk.h Normal file
View File

@ -0,0 +1,25 @@
// ramdisk.h
// Author: Josh Holtrop
// Date: 08/20/04
// Modified: 08/22/04
#ifndef __HOS_RD_H__
#define __HOS_RD_H__ __HOS_RD_H__
#include "hos_defines.h"
#include "fs/devices.h"
typedef struct {
void *start;
u32_t size;
} ramdisk_t;
int ramdisk_init(major_t major);
minor_t ramdisk_new(u32_t size);
minor_t ramdisk_register(void *ramdisk, u32_t size);
int ramdisk_remove(minor_t minor);
int ramdisk_block_read(minor_t minor, u32_t blockNum, u32_t count, void *buffer);
int ramdisk_block_write(minor_t minor, u32_t blockNum, u32_t count, void *buffer);
#endif

View File

@ -1,53 +0,0 @@
#include "block/rd.h"
#include "kernel.h"
ramdisk_t ramdisks[256];
char rd_refs[256]; //number of references to each ramdisk
void rd_init()
{
}
int rd_register(byte *ramdisk, u32_t size)
{
int i;
for (i = 0; i < 256; i++)
{
if (!rd_refs[i])
{
rd_refs[i]++;
ramdisks[i].start = ramdisk;
ramdisks[i].size = size;
return i;
}
}
return -1;
}
int rd_remove(minor_t minor)
{
if (rd_refs[minor] <= 0)
return -1;
rd_refs[minor]--;
if (!rd_refs[minor])
free(ramdisks[minor].start);
}
int rd_read_block(minor_t minor, u32_t blockNum, u32_t count, byte *buffer)
{
if (rd_refs[minor] <= 0)
return -1;
byte *copyFrom = ramdisks[minor] + (blockNum << 9);
if (copyFrom > ramdisks[minor].start + ramdisks[minor].size)
return -1;
}
int rd_write_block(minor_t minor, u32_t blockNum, u32_t count, byte *buffer)
{
}

View File

@ -1,21 +0,0 @@
#ifndef __HOS_RD_H__
#define __HOS_RD_H__ __HOS_RD_H__
#include "kernel.h"
#include "devices.h"
typedef struct {
byte *start;
u32_t size;
} ramdisk_t;
void rd_init();
int rd_register(byte *ramdisk, u32_t size);
int rd_remove(minor_t minor);
int rd_read_block(minor_t minor, u32_t blockNum, u32_t count, byte *buffer);
int rd_write_block(minor_t minor, u32_t blockNum, u32_t count, byte *buffer);
#endif

View File

@ -25,7 +25,7 @@
%define KERNEL_P PHYS_START+0x8000 ;1mb+32kb - the kernel's physical address %define KERNEL_P PHYS_START+0x8000 ;1mb+32kb - the kernel's physical address
%define KERNEL_V KERNEL_P+VIRT_OFFSET ;3gb+1mb+32kb, the virtual address of the kernel %define KERNEL_V KERNEL_P+VIRT_OFFSET ;3gb+1mb+32kb, the virtual address of the kernel
extern _k_init, _isr, _k_mbsave, _end extern _k_init, _isr, _k_mbsave, _end, _rm_params, _initrd
[bits 32] [bits 32]
@ -64,10 +64,6 @@ segmented_start:
mov fs, cx mov fs, cx
mov esp, STACK_V+0x1000 ;ok, now we can access our data mov esp, STACK_V+0x1000 ;ok, now we can access our data
;aloop:
; inc dword [0xC00B8000]
; jmp aloop
;Then the multiboot info structures are saved to local data variables. ;Then the multiboot info structures are saved to local data variables.
add ebx, VIRT_OFFSET add ebx, VIRT_OFFSET
@ -76,13 +72,30 @@ segmented_start:
call _k_mbsave ;save multiboot info structures call _k_mbsave ;save multiboot info structures
add esp, 8 add esp, 8
cmp eax, 0 cmp eax, 0 ; eax = pointer to mb_module_t struct for rmmod
jz pm_return jz pm_return
;go back to real mode to initialize video mode ;go back to real mode to initialize video mode
mov ebx, pm_return mov ebx, eax ; pointer to mb_module_t
mov ecx, [ebx+4] ; end of module
mov eax, [ebx] ; start of module
mov esi, eax ; start of module
sub ecx, eax ; ecx = length of rmmod
shr ecx, 2 ; ecx = length of rmmod in dwords
mov edi, 0xC0005000 ; where to copy rmmod to (0x5000 physical)
rep movsd ; copy rmmod to first 1mb
mov ebx, pm_return ; return address
mov ecx, _rm_params ; put real mode params here (video mode etc...)
sub ecx, VIRT_OFFSET
mov edx, _initrd ; load the 'floppy' image here
sub edx, VIRT_OFFSET
mov eax, cr0
and eax, 0x7FFFFFFE ; leave PM
mov cr0, eax
jmp 0x0:0x5010 ; jump to rmmod
;Next we enable paging with the first 4mb mapped 1:1 virtual:physical ;Next we enable paging with the first 4mb mapped 1:1 virtual:physical
; and with the 4mb starting at 0xC000_0000 mapped to the first 4mb physical. ; and with the 4mb starting at 0xC000_0000 mapped to the first 4mb physical.

View File

@ -5,12 +5,12 @@
#include "hos_defines.h" #include "hos_defines.h"
#include "char/keyboard.h" #include "char/keyboard.h"
#include "sys/io.h" #include "sys/io.h" // inportb, outportb
#include "functions.h" #include "functions.h"
#include "lang/conv.h" // asciiSwitchCase() #include "lang/conv.h" // asciiSwitchCase()
#include "kout.h" #include "kout.h"
#include "console.h" #include "display.h" // display_activate()
#define KBD_BUFFER_LENGTH 64 #define KBD_BUFFER_LENGTH 64
@ -148,8 +148,13 @@ void isr_keyboard()
if (kbdAscii) if (kbdAscii)
kprintf("%c", kbdAscii); kprintf("%c", kbdAscii);
if (kbdScan >= 0x3B && kbdScan <= 0x40) // if (kbdFlags & KBDF_ALT)
console_activate(kbdScan - 0x3A); // {
if (kbdScan >= 0x3B && kbdScan <= 0x44)
display_activate(kbdScan - 0x3B);
if (kbdScan >= 0x57 && kbdScan <= 0x58)
display_activate(kbdScan - 0x4D);
// }
} }
//Gets a key from the buffer, returns 0 if no keys available, returns immediately //Gets a key from the buffer, returns 0 if no keys available, returns immediately

View File

@ -8,12 +8,11 @@
#include "fs/devices.h" #include "fs/devices.h"
#include "mm/vmm.h" #include "mm/vmm.h"
#include "lang/asmfuncs.h" #include "lang/asmfuncs.h"
#include "console.h" #include "display.h"
#include "functions.h" #include "functions.h"
vconsole_t *vconsoles[VCONSOLE_MAX]; // pointer to virtual console structs vconsole_t *vconsoles[VCONSOLE_MAX]; // pointer to virtual console structs
extern int activeConsole; // console subsystem active virtual console number extern int display_activeConsole; // display subsystem active virtual console number
char ansi2vgaAttr[8] = {0, 4, 2, 6, 1, 5, 3, 7}; char ansi2vgaAttr[8] = {0, 4, 2, 6, 1, 5, 3, 7};
void vconsole_put_char(minor_t id, int c); void vconsole_put_char(minor_t id, int c);
@ -62,16 +61,16 @@ minor_t vconsole_new(int width, int height)
} }
// called by console subsystem to draw a virtual console to the screen // called by display subsystem to draw a virtual console to the screen
int vconsole_draw(minor_t id) int vconsole_draw(minor_t id)
{ {
if (vconsoles[id]) if (vconsoles[id])
return console_draw(id, vconsoles[id]->cursorPosition, vconsoles[id]->buffer); return display_console_draw(id, vconsoles[id]->cursorPosition, vconsoles[id]->buffer);
return -1; return -1;
} }
// called by character device driver when a character is written to device w/ minor #id // called by character device interface when a character is written to device w/ minor #id
int vconsole_char_write(minor_t id, int c) int vconsole_char_write(minor_t id, int c)
{ {
if (!vconsoles[id]) if (!vconsoles[id])
@ -108,13 +107,13 @@ int vconsole_char_write(minor_t id, int c)
cursorY = vconsoles[id]->height - 1; cursorY = vconsoles[id]->height - 1;
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX); vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
break; break;
case 'C': // move cursor right n columns case 'C': // move cursor left n columns
cursorX -= vconsoles[id]->escapeValue[0]; cursorX -= vconsoles[id]->escapeValue[0];
if (cursorX < 0) if (cursorX < 0)
cursorX = 0; cursorX = 0;
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX); vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
break; break;
case 'D': // move cursor left n columns case 'D': // move cursor right n columns
cursorX += vconsoles[id]->escapeValue[0]; cursorX += vconsoles[id]->escapeValue[0];
if (cursorX >= vconsoles[id]->width) if (cursorX >= vconsoles[id]->width)
cursorX = vconsoles[id]->width - 1; cursorX = vconsoles[id]->width - 1;
@ -250,8 +249,8 @@ void vconsole_put_char(minor_t id, int c)
break; break;
default: default:
vconsoles[id]->buffer[vconsoles[id]->cursorPosition] = c | (vconsoles[id]->attribute << 8); vconsoles[id]->buffer[vconsoles[id]->cursorPosition] = c | (vconsoles[id]->attribute << 8);
if (id == activeConsole) if (id == display_activeConsole)
console_put_char(id, c | (vconsoles[id]->attribute << 8), vconsoles[id]->cursorPosition); display_console_put_char(id, c | (vconsoles[id]->attribute << 8), vconsoles[id]->cursorPosition);
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + 1); vconsole_update_cursor(id, vconsoles[id]->cursorPosition + 1);
} }
} }
@ -262,17 +261,24 @@ void vconsole_update_cursor(minor_t id, u16_t position)
vconsoles[id]->cursorPosition = position; vconsoles[id]->cursorPosition = position;
if (position >= (vconsoles[id]->width * vconsoles[id]->height)) // time to scroll console if (position >= (vconsoles[id]->width * vconsoles[id]->height)) // time to scroll console
{ {
int i;
for (i = 0; i < vconsoles[id]->cursorStackPosition; i++)
{
vconsoles[id]->cursorStack[i] -= vconsoles[id]->width;
if (vconsoles[id]->cursorStack[i] < 0)
vconsoles[id]->cursorStack[i] = 0;
}
vconsoles[id]->cursorPosition -= vconsoles[id]->width; vconsoles[id]->cursorPosition -= vconsoles[id]->width;
memcpyw(vconsoles[id]->buffer, vconsoles[id]->buffer + vconsoles[id]->width, vconsoles[id]->width * (vconsoles[id]->height - 1)); memcpyw(vconsoles[id]->buffer, vconsoles[id]->buffer + vconsoles[id]->width, vconsoles[id]->width * (vconsoles[id]->height - 1));
memsetw(vconsoles[id]->buffer + (vconsoles[id]->width * (vconsoles[id]->height - 1)), 0x0720, vconsoles[id]->width); memsetw(vconsoles[id]->buffer + (vconsoles[id]->width * (vconsoles[id]->height - 1)), 0x0720, vconsoles[id]->width);
if (activeConsole == id) if (display_activeConsole == id)
{ {
vconsole_draw(id); vconsole_draw(id);
return; return;
} }
} }
if (activeConsole == id) if (display_activeConsole == id)
console_update_cursor(id, position); display_console_update_cursor(id, position);
} }
void vconsole_update_attribute(minor_t id) void vconsole_update_attribute(minor_t id)

View File

@ -18,7 +18,7 @@ typedef struct
u16_t cursorPosition; u16_t cursorPosition;
u16_t width; u16_t width;
u16_t height; u16_t height;
u16_t cursorStack[16]; short cursorStack[16];
u8_t attribute; u8_t attribute;
u8_t foreground; u8_t foreground;

View File

@ -1,82 +0,0 @@
// console.c
// Author: Josh Holtrop
// Date: 08/07/04
// Modified: 08/16/04
#include "fs/devices.h"
#include "char/vconsole.h"
#include "console.h"
#include "lang/asmfuncs.h"
int activeConsole;
int numConsoles;
// initialization routine for console subsystem
int console_init(int num)
{
int i;
activeConsole = 0;
for (i = 0; i < num; i++)
{
minor_t vc = vconsole_new(80, 25);
if (vc)
{
numConsoles++;
if (!activeConsole)
activeConsole = vc;
}
}
if (numConsoles)
return 0;
return -1;
}
// activate a virtual console
int console_activate(minor_t id)
{
if (id > 0 && id <= numConsoles)
{
activeConsole = id;
return vconsole_draw(id);
}
return -1;
}
// routine to refresh a console window
int console_draw(minor_t id, int cursorPosition, u16_t *buffer)
{
if (id == activeConsole)
{
memcpyw((void *)CONSOLE_MEMORY, buffer, 2000);
writeCursorPosition(cursorPosition);
return 0;
}
return -1;
}
// write a character to the screen
int console_put_char(minor_t id, u16_t c, int position)
{
if (id == activeConsole)
{
*(u16_t *)(CONSOLE_MEMORY + (position << 1)) = c;
return 0;
}
return -1;
}
// move the cursor on the screen
int console_update_cursor(minor_t id, int cursorPosition)
{
if (id == activeConsole)
{
writeCursorPosition(cursorPosition);
return 0;
}
return -1;
}

View File

@ -1,19 +0,0 @@
// console.h
// Author: Josh Holtrop
// Date: 08/07/04
#ifndef __HOS_CONSOLE__
#define __HOS_CONSOLE__ __HOS_CONSOLE__
#include "hos_defines.h"
#include "fs/devices.h"
int console_init(int num);
int console_activate(minor_t id);
int console_draw(minor_t id, int cursorPosition, u16_t *buffer);
int console_put_char(minor_t id, u16_t c, int position);
int console_update_cursor(minor_t id, int cursorPosition);
#endif

96
kernel/display.c Normal file
View File

@ -0,0 +1,96 @@
// display.c
// Author: Josh Holtrop
// Date: 08/07/04
// Modified: 08/21/04
#include "fs/devices.h"
#include "char/vconsole.h"
#include "display.h"
#include "lang/asmfuncs.h"
int display_activeConsole = -1; // start with no active console
display_t myDisplays[12]; // f1-f12 change displays
// initialization routine for display subsystem
int display_init()
{
minor_t vc;
if ((vc = vconsole_new(80, 25)))
{
myDisplays[11].type = DISPLAY_CONSOLE;
myDisplays[11].id = vc;
display_activeConsole = vc;
}
int i;
for (i = 0; i < 6; i++)
{
if ((vc = vconsole_new(80, 25)))
{
myDisplays[i].type = DISPLAY_CONSOLE;
myDisplays[i].id = vc;
}
}
return 0;
}
// activate the given display
int display_activate(u32_t id)
{
if (id > 11)
return -1;
switch (myDisplays[id].type)
{
case DISPLAY_CONSOLE:
display_activeConsole = myDisplays[id].id;
return vconsole_draw(display_activeConsole);
case DISPLAY_GRAPHICAL:
default:
return -2;
}
}
// routine to refresh a console window
int display_console_draw(minor_t id, int cursorPosition, u16_t *buffer)
{
if (id == display_activeConsole)
{
int i;
for (i = 0; i < 12; i++)
{
if (myDisplays[i].id == id)
{
memcpyw((void *)CONSOLE_MEMORY, buffer, 2000);
writeCursorPosition(cursorPosition);
return 0;
}
}
}
return -1;
}
// write a character to the screen
int display_console_put_char(minor_t id, u16_t c, int position)
{
if (id == display_activeConsole)
{
*(u16_t *)(CONSOLE_MEMORY + (position << 1)) = c;
return 0;
}
return -1;
}
// move the cursor on the screen
int display_console_update_cursor(minor_t id, int cursorPosition)
{
if (id == display_activeConsole)
{
writeCursorPosition(cursorPosition);
return 0;
}
return -1;
}

29
kernel/display.h Normal file
View File

@ -0,0 +1,29 @@
// display.h
// Author: Josh Holtrop
// Date: 08/07/04
// Modified: 08/21/04
#ifndef __HOS_CONSOLE__
#define __HOS_CONSOLE__ __HOS_CONSOLE__
#include "hos_defines.h"
#include "fs/devices.h"
#define DISPLAY_NULL 0
#define DISPLAY_CONSOLE 1
#define DISPLAY_GRAPHICAL 2
typedef struct {
int type;
minor_t id;
} display_t;
int display_init();
int display_activate(u32_t id);
int display_console_draw(minor_t id, int cursorPosition, u16_t *buffer);
int display_console_put_char(minor_t id, u16_t c, int position);
int display_console_update_cursor(minor_t id, int cursorPosition);
#endif

16
kernel/fs/devfs.c Normal file
View File

@ -0,0 +1,16 @@
// devfs.c
// Author: Josh Holtrop
// Date: 08/22/04
// Modified: 08/22/04
#include "hos_defines.h"
#include "fs/devfs.h"
#include "fs/devices.h"
#include "fs/vfs.h"
void devfs_init(minor_t rd_minor)
{
// vfs_mount(MAJORB_RAMDISK, rd_minor, FS_EXT2, "/dev");
}

15
kernel/fs/devfs.h Normal file
View File

@ -0,0 +1,15 @@
// devfs.h
// Author: Josh Holtrop
// Date: 08/22/04
// Modified: 08/22/04
#ifndef __HOS_DEVFS_H__
#define __HOS_DEVFS_H__ __HOS_DEVFS_H__
#include "hos_defines.h"
#include "fs/devices.h"
void devfs_init(minor_t rd_minor);
#endif

View File

@ -17,6 +17,7 @@ void devices_init()
{ {
parallel_init(MAJORC_PARALLEL); parallel_init(MAJORC_PARALLEL);
vconsole_init(MAJORC_VCONSOLE); vconsole_init(MAJORC_VCONSOLE);
// ramdisk_init(MAJORB_RAMDISK);
} }

View File

@ -1,7 +1,7 @@
// devices.h // devices.h
// Author: Josh Holtrop // Author: Josh Holtrop
// Date: 08/02/04 // Date: 08/02/04
// Modified: 08/16/04 // Modified: 08/22/04
#ifndef __HOS_DEVICES_H__ #ifndef __HOS_DEVICES_H__
#define __HOS_DEVICES_H__ __HOS_DEVICES_H__ #define __HOS_DEVICES_H__ __HOS_DEVICES_H__
@ -12,8 +12,13 @@
#define MAJORC_PARALLEL 6 #define MAJORC_PARALLEL 6
#define MAJORC_KEYBOARD 11 #define MAJORC_KEYBOARD 11
typedef unsigned char major_t; #define MAJORB_RAMDISK 1
typedef unsigned char minor_t;
#define BLOCK_SIZE 512
#define BLOCK_SIZE_LOG 9
typedef short major_t;
typedef short minor_t;
typedef struct { typedef struct {
int (*block_read)(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer); int (*block_read)(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer);

16
kernel/fs/ext2.c Normal file
View File

@ -0,0 +1,16 @@
// ext2.c
// Author: Josh Holtrop
// Date: 08/22/04
// Modified: 08/22/04
#include "hos_defines.h"
#include "fs/devices.h"
#include "kout.h"
void ext2_read_super(major_t major, minor_t minor);
{
ext2_super_block_t *super = kmalloc(1024);
block_read(major, minor, 2, 2, super);
kprintf("Magic: 0x%x\n", super->s_magic);
}

82
kernel/fs/ext2.h Normal file
View File

@ -0,0 +1,82 @@
// ext2.h
// Author: Josh Holtrop
// Date: 08/22/04
// Modified: 08/22/04
#ifndef __HOS_EXT2_H__
#define __HOS_EXT2_H__ __HOS_EXT2_H__
#include "hos_defines.h"
#include "fs/devices.h"
typedef struct {
u32_t s_inodes_count; /* Inodes count */
u32_t s_blocks_count; /* Blocks count */
u32_t s_r_blocks_count; /* Reserved blocks count */
u32_t s_free_blocks_count; /* Free blocks count */
u32_t s_free_inodes_count; /* Free inodes count */
u32_t s_first_data_block; /* First Data Block */
u32_t s_log_block_size; /* Block size */
int s_log_frag_size; /* Fragment size */
u32_t s_blocks_per_group; /* # Blocks per group */
u32_t s_frags_per_group; /* # Fragments per group */
u32_t s_inodes_per_group; /* # Inodes per group */
u32_t s_mtime; /* Mount time */
u32_t s_wtime; /* Write time */
u16_t s_mnt_count; /* Mount count */
short s_max_mnt_count; /* Maximal mount count */
u16_t s_magic; /* Magic signature */
u16_t s_state; /* File system state */
u16_t s_errors; /* Behaviour when detecting errors */
u16_t s_minor_rev_level; /* minor revision level */
u32_t s_lastcheck; /* time of last check */
u32_t s_checkinterval; /* max. time between checks */
u32_t s_creator_os; /* OS */
u32_t s_rev_level; /* Revision level */
u16_t s_def_resuid; /* Default uid for reserved blocks */
u16_t s_def_resgid; /* Default gid for reserved blocks */
/*
* EXT2_DYNAMIC_REV fields...
*/
u32_t s_first_ino; /* First non-reserved inode */
u16_t s_inode_size; /* size of inode structure */
u16_t s_block_group_nr; /* block group # of this superblock */
u32_t s_feature_compat; /* compatible feature set */
u32_t s_feature_incompat; /* incompatible feature set */
u32_t s_feature_ro_compat; /* readonly-compatible feature set */
u8_t s_uuid[16]; /* 128-bit uuid for volume */
char s_volume_name[16]; /* volume name */
char s_last_mounted[64]; /* directory where last mounted */
u32_t s_algorithm_usage_bitmap; /* For compression */
/*
* Performance hints...
*/
u8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
u8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
u16_t s_padding1;
/*
* Journaling information...
*/
u8_t s_journal_uuid[16]; /* uuid of journal superblock */
u32_t s_journal_inum; /* inode number of journal file */
u32_t s_journal_dev; /* device number of journal file */
u32_t s_last_orphan; /* start of list of inodes to delete */
u32_t s_hash_seed[4]; /* HTREE hash seed */
u8_t s_def_hash_version; /* Default hash version to use */
u8_t s_reserved_char_pad;
u16_t s_reserved_word_pad;
u32_t s_default_mount_opts;
u32_t s_first_meta_bg; /* First metablock block group */
u32_t s_reserved[190]; /* Padding to the end of the block */
} ext2_super_block_t;
void ext2_read_super(major_t major, minor_t minor);
#endif

10
kernel/fs/vfs.c Normal file
View File

@ -0,0 +1,10 @@
// vfs.c
// Author: Josh Holtrop
// Date: 08/22/04
// Modified: 08/22/04
#include "hos_defines.h"
#include "fs/vfs.h"
vfs_mount_t *firstMount;

23
kernel/fs/vfs.h Normal file
View File

@ -0,0 +1,23 @@
// vfs.h
// Author: Josh Holtrop
// Date: 08/22/04
// Modified: 08/22/04
#ifndef __HOS_VFS_H__
#define __HOS_VFS_H__ __HOS_VFS_H__
#include "hos_defines.h"
#include "fs/devices.h"
#define FS_EXT2 1
typedef struct {
char *name;
void *super;
void *next;
major_t major;
minor_t minor;
} vfs_mount_t;
#endif

View File

@ -59,8 +59,7 @@ static inline void timer_init(u32_t freq)
outportb(0x40, wait >> 8); //msb outportb(0x40, wait >> 8); //msb
} }
//Returns the size of the kernel (code & data) //Returns the size of the kernel (code & data & bss)
// - this does include the bss section
// - this should be 4kb aligned per the linker script // - this should be 4kb aligned per the linker script
// - this is the amount of RAM the kernel code, data, & bss take // - this is the amount of RAM the kernel code, data, & bss take
static inline u32_t kernel_size_used() static inline u32_t kernel_size_used()
@ -89,6 +88,18 @@ static inline byte byte2bcd(byte bite)
return ((bite / 10) << 4) | (bite % 10); return ((bite / 10) << 4) | (bite % 10);
} }
// get the maximum of two values
static inline u32_t max(u32_t v1, u32_t v2)
{
return ( (v2 > v1) ? v2 : v1 );
}
// get the minimum of two values
static inline u32_t min(u32_t v1, u32_t v2)
{
return ( (v2 > v1) ? v1 : v2 );
}
#endif #endif

View File

@ -1,6 +1,7 @@
// kernel.h // kernel.h
// Author: Josh Holtrop // Author: Josh Holtrop
// Date: 08/16/04 // Date: 08/16/04
// Modified: 08/28/04
// This is the main kernel initialization and boot-strapping file // This is the main kernel initialization and boot-strapping file
#include "kernel.h" #include "kernel.h"
@ -15,29 +16,37 @@
#include "lang/conv.h" #include "lang/conv.h"
#include "char/vconsole.h" #include "char/vconsole.h"
#include "fs/devices.h" #include "fs/devices.h"
#include "console.h" #include "display.h"
#include "sys/io.h" #include "sys/io.h"
#include "sys/pic.h" #include "sys/pic.h"
#include "char/keyboard.h" #include "char/keyboard.h"
#include "fs/devfs.h"
#include "block/ramdisk.h"
#include "fs/vfs.h"
#include "fs/ext2.h"
mb_info_t mb_info_block; mb_info_t mb_info_block;
mb_mmap_t mb_mmap[MAX_MMAP]; mb_mmap_t mb_mmap[MAX_MMAP];
u32_t mmap_entries; u32_t mmap_entries;
mb_module_t mb_modules[MAX_MODULES]; mb_module_t mb_modules[MAX_MODULES];
mb_apm_t mb_apm_table; mb_apm_t mb_apm_table;
byte real_mode_module; mb_module_t *real_mode_module; // pointer to real mode module (if present)
real_mode_param_t rm_params;
char mb_cmdline[256]; char mb_cmdline[256];
int criticalCounter; // semaphore for if interrupts are disabled int criticalCounter; // semaphore for if interrupts are disabled
u32_t timer; u32_t timer; // number of IRQ 0's
minor_t devfs_minor = -1;
minor_t initrd_minor = -1;
byte initrd[2880*512]; // buffer in bss for loading a floppy image
extern u32_t mm_freepages; extern u32_t mm_freepages;
/* This function runs in segmented memory - 0xC000_0000 is mapped to 0x0 but 0x0 /* This function runs in segmented memory - 0xC000_0000 is mapped to 0x0 but 0x0
itself is an invalid linear address. Therefore, the multiboot information addresses itself is an invalid linear address. Therefore, the multiboot information addresses
must be manually adjusted by VIRT_OFFSET to become valid linear addresses. */ must be manually adjusted by VIRT_OFFSET to become valid linear addresses. */
int k_mbsave(mb_info_t *mbinfo, unsigned int mb_magic) mb_module_t *k_mbsave(mb_info_t *mbinfo, unsigned int mb_magic)
{ {
real_mode_module = 0; real_mode_module = NULL;
if (mb_magic != MULTIBOOT_BOOTLOADER_MAGIC) if (mb_magic != MULTIBOOT_BOOTLOADER_MAGIC)
{ {
char *msg = "Bad multiboot magic identifier!"; char *msg = "Bad multiboot magic identifier!";
@ -66,8 +75,8 @@ int k_mbsave(mb_info_t *mbinfo, unsigned int mb_magic)
mb_modules[i].mod_start += VIRT_OFFSET; mb_modules[i].mod_start += VIRT_OFFSET;
mb_modules[i].mod_end += VIRT_OFFSET; mb_modules[i].mod_end += VIRT_OFFSET;
hos_module_header_t *mod = (hos_module_header_t *)mb_modules[i].mod_start; hos_module_header_t *mod = (hos_module_header_t *)mb_modules[i].mod_start;
if (mod->mod_type == MOD_REAL_MODE) if (mod->mod_magic == 0x4D534F48 && mod->mod_type == MOD_REAL_MODE)
real_mode_module = 1; real_mode_module = &mb_modules[i];
} }
} }
if (mb_info_block.flags & MB_BOOTLOADER_MMAP) if (mb_info_block.flags & MB_BOOTLOADER_MMAP)
@ -101,39 +110,25 @@ void k_init()
timer_init(HOS_TIMER_FREQ); timer_init(HOS_TIMER_FREQ);
mm_init(); mm_init();
vmm_init(); vmm_init();
// test the memory manager
/* char *all;
int size = 1;
u32_t add = 1;
for (;;)
{
all = kmalloc(size);
add = (u32_t)all;
if (!add)
break;
u32_t pte = (add >> 12) & 0x3FF;
u32_t pde = add >> 22;
u32_t mapped = *((u32_t *)(0xFFC00000 | (pde << 12) | (pte << 2)));
kprintf("Got address 0x%x mapped to 0x%x size=%d\n", add, mapped, size);
memset(all, 0, size);
size <<= 1;
}*/
devices_init(); devices_init();
console_init(6);
console_activate(1);
kprintf(" \e[31mWe \e[1mcan \e[32mfinally \e[33;45msee\e[0;7m text\e[0m!\n");
u16_t *vidMem = (u16_t *)(CONSOLE_MEMORY + 160);
u16_t i;
for (i = 0; i < 256; i++)
{
*vidMem++ = (i << 8) | '*';
if (((u32_t)vidMem % 32) == 0)
vidMem += 64;
}
if (real_mode_module) if (real_mode_module)
{ {
kprintf("Real mode module present\n"); if (rm_params.vid_mem) // there is video memory to map in
vmm_mapn(0xF0000000, (u32_t)rm_params.vid_addr, (rm_params.vid_mem >> 12) + 1);
if (rm_params.initrd_loaded) // there is an initrd to register
initrd_minor = ramdisk_register(initrd, 2880*512);
} }
display_init(); //get us some virtual consoles to look at
display_activate(11);
kprintf("HOS v0.15 initializing...\n");
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);
if ((devfs_minor = ramdisk_new(4096)) < 0)
{
kprintf("\e31;1mk_init(): Could not obtain minor mumber for devfs ram disk!\n");
halt();
}
devfs_init(devfs_minor);
criticalCounter--; criticalCounter--;
} }

View File

@ -1,3 +1,7 @@
// kernel.h
// Author: Josh Holtrop
// Date: 08/16/04
// Modified: 08/28/04
#ifndef __HOS_KERNEL_H__ #ifndef __HOS_KERNEL_H__
#define __HOS_KERNEL_H__ __HOS_KERNEL_H__ #define __HOS_KERNEL_H__ __HOS_KERNEL_H__
@ -11,16 +15,15 @@ typedef struct {
u32_t height; // height in pixels or columns if vid_mem == 0 u32_t height; // height in pixels or columns if vid_mem == 0
u32_t vid_mem; // amount of memory for video buffer u32_t vid_mem; // amount of memory for video buffer
u32_t bpp; // bits per pixel - 16/24/32 u32_t bpp; // bits per pixel - 16/24/32
byte initrd_loaded; // did we load an initrd?
} __attribute__ ((packed)) real_mode_param_t; } __attribute__ ((packed)) real_mode_param_t;
/* returns true to callee if we should jump to a real mode module */ /* returns true to callee if we should jump to a real mode module */
int k_mbsave(mb_info_t *mbinfo, unsigned int mb_magic); mb_module_t *k_mbsave(mb_info_t *mbinfo, unsigned int mb_magic);
void k_init(); void k_init();
void isr(); void isr();
void k_enter_critical(); // functions for implementing "atomic actions" void k_enter_critical(); // functions for implementing "atomic actions"
void k_leave_critical(); void k_leave_critical();
void BOCHS_DEBUG(u32_t pos, u32_t param);
#endif #endif

View File

@ -9,7 +9,7 @@
#include "lang/conv.h" #include "lang/conv.h"
#include "fs/devices.h" #include "fs/devices.h"
extern int activeConsole; extern int display_activeConsole;
char buffer[64]; char buffer[64];
@ -19,7 +19,7 @@ void putc(int c)
#ifdef PARALLEL_DEBUG #ifdef PARALLEL_DEBUG
char_write(MAJORC_PARALLEL, 0, c); char_write(MAJORC_PARALLEL, 0, c);
#endif #endif
char_write(MAJORC_VCONSOLE, activeConsole, c); char_write(MAJORC_VCONSOLE, display_activeConsole, c);
} }

View File

@ -10,11 +10,6 @@
#include "lang/asmfuncs.h" #include "lang/asmfuncs.h"
#include "mm/mm.h" #include "mm/mm.h"
int vmm_map(void *virt);
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);
void vmm_unmapn(unsigned int virt, unsigned int n);
int vmm_map_range(void *virt_start, void *virt_end, u32_t phys_start); int vmm_map_range(void *virt_start, void *virt_end, u32_t phys_start);
void *vmm_getFreeChunk(u32_t size); void *vmm_getFreeChunk(u32_t size);
void vmm_removeHeapEntry(u32_t queue, HeapEntry_t *he); void vmm_removeHeapEntry(u32_t queue, HeapEntry_t *he);

View File

@ -2,7 +2,7 @@
// Author: Josh Holtrop // Author: Josh Holtrop
// Date: 09/30/03 // Date: 09/30/03
// Rewritten from scratch: 12/23/03, 07/13/04 // Rewritten from scratch: 12/23/03, 07/13/04
// Modified: 07/30/04 // Modified: 08/28/04
#ifndef __HOS_VMM__ #ifndef __HOS_VMM__
#define __HOS_VMM__ __HOS_VMM__ #define __HOS_VMM__ __HOS_VMM__
@ -44,6 +44,12 @@ void *vmm_palloc();
int vmm_pfree(void *addr); int vmm_pfree(void *addr);
void *kcalloc(unsigned int number, unsigned int size); void *kcalloc(unsigned int number, unsigned int size);
int vmm_map(void *virt);
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);
void vmm_unmapn(unsigned int virt, unsigned int n);
#endif #endif

View File

@ -3,7 +3,7 @@
#define __HOS_MODULE_H__ __HOS_MODULE_H__ #define __HOS_MODULE_H__ __HOS_MODULE_H__
#define MOD_REAL_MODE 1 #define MOD_REAL_MODE 1
#define MOD_KERNEL 2 #define MOD_INITRD 2
typedef struct { typedef struct {
unsigned int mod_magic; // "HOSM" = dword value 0x4D534F48 unsigned int mod_magic; // "HOSM" = dword value 0x4D534F48

View File

@ -5,5 +5,5 @@ default 0
title HOS 0.15 title HOS 0.15
root (fd0) root (fd0)
kernel /kernel.bin kernel /kernel.bin
module /rmmod.bin

View File

@ -1,2 +1,7 @@
NASM=nasm
all:
$(NASM) -f bin rmmod.asm -l rmmod.lst -o rmmod.bin
clean: clean:
- rm *~ *.o *.bin *.lst -rm -f *~ *.o *.bin *.lst

View File

@ -0,0 +1,134 @@
; rmmod.asm
; real mode module for HOS
; Author: Josh Holtrop
; Date: 09/20/04
; the bootstrap process will jump us to 0x0:0x5010 so we'd better be ready for it
[org 0x5000]
[bits 16]
;HOS module header, better be 16 bytes!
dd 0x4D534F48 ; magic identifier "HOSM"
dd 1 ; real mode module
dd start ; start address
dd 0 ; reserved
; ebx = return address
; ecx = where to store real mode parameter table
; edx = initrd, where to put ram disk
start:
mov ax, cs ; 0
mov ds, ax
mov es, ax
mov ss, ax
mov esp, 0x7000
mov [dat_rmadd], ecx
mov [dat_initrd], edx
mov [dat_retn], ebx
mov ah, 0 ;reset floppy controller
mov dl, 0
int 0x13
push txt_loading_initrd ;print loading initrd string
push 23*80
call putString
add sp, 4
push es ; draw a red bar to fill in
mov ax, 0xb800
mov es, ax
mov di, 24*160
mov cx, 80
mov ax, 0x04B0
rep stosw
pop es
mov cx, 80 ;80 cylinders to read
xor si, si ;start at cylinder 0
mov edi, [dat_initrd] ;ram disk address
read_cylinder:
push cx
mov bx, 0x1000 ;read sectors from head 0
mov es, bx
xor bx, bx ;es:bx = data buffer for read
mov ax, 0x0212 ;ah = int 0x13 function 2, al = number of sectors to read
mov cx, si ;what cyl. we are on is now in cx
mov ch, cl ;ch = cyl. number
mov cl, 1 ;cl = sector number 1-63
xor dx, dx ;dh = head number
; mov dl, 0 ;dl = drive number
int 0x13
mov bx, 0x1000 ;now read sectors from head 1
mov es, bx
mov bx, 9216 ;es:bx = data buffer for read
mov ax, 0x0212 ;ah = int 0x13 function 2, al = number of sectors to read
mov cx, si ;what cyl. we are on is now in cx
mov ch, cl ;ch = cyl. number
mov cl, 1 ;cl = sector number 1-63
; mov dh, 1 ;dh = head number
; mov dl, 0 ;dl = drive number
mov dx, 0x0100
int 0x13
mov ebx, 0xb8000 ;draw a green block
add bx, si
shl bl, 1
mov word [ds:ebx+160*24], 0x0200+219
push si
mov esi, 0x10000 ;now copy the disk up to where we will keep it
mov cx, 0x2400
rep o32 movsb
pop si ;what cylinder# we are on...
inc si
pop cx
loop read_cylinder
aloop:
jmp aloop
; putString(int position, char *str)
putString:
push bp
mov bp, sp
push ds
push es
push edi
push esi
push eax
mov ax, 0xb800
mov es, ax
xor ax, ax
mov ds, ax
mov ax, [bp + 4]
mov di, ax
shl di, 1
mov ax, [bp + 6]
mov si, ax
putString_loop:
lodsb
stosb
cmp al, 0
jz putString_loop_done
mov al, 0x07
stosb
jmp putString_loop
putString_loop_done:
pop eax
pop esi
pop edi
pop es
pop ds
pop bp
ret
txt_loading_initrd: db "Loading initrd... ", 0
dat_rmadd dd 0
dat_initrd dd 0
dat_retn dd 0