Import backup from 2005-03-21

This commit is contained in:
josh committed 2017-07-25 22:23:50 -04:00
1 parent bb8ff09e3f
commit 14792ef954
24 files changed
+671 -197

No files matched your search

+5 -4
View File
@@ -19,7 +19,7 @@ all: Asm_Kernel C_Kernel
$(LD) $(LD_FLAGS) -Map kernel.map \
boot.o kernel.o lang_a.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 ext2.o lang_c.o -o kernel.bin
devfs.o ext2.o lang_c.o vesafb.o -o kernel.bin
Asm_Kernel:
$(NASM) $(NASM_FLAGS) -l boot.lst boot.asm -o boot.o
@@ -31,10 +31,10 @@ C_Kernel:
$(CC) $(CC_FLAGS) -c mm/vmm.c -o vmm.o
$(CC) $(CC_FLAGS) -c char/parallel.c -o parallel.o
$(CC) $(CC_FLAGS) -c lang/conv.c -o conv.o
$(CC) $(CC_FLAGS) -c kout.c -o kout.o
$(CC) $(CC_FLAGS) -c display/kout.c -o kout.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 display.c -o display.o
$(CC) $(CC_FLAGS) -c display/display.c -o display.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 block/ramdisk.c -o ramdisk.o
@@ -42,11 +42,12 @@ C_Kernel:
$(CC) $(CC_FLAGS) -c fs/vfs.c -o vfs.o
$(CC) $(CC_FLAGS) -c fs/ext2.c -o ext2.o
$(CC) $(CC_FLAGS) -c lang/lang.c -o lang_c.o
$(CC) $(CC_FLAGS) -c display/vesafb.c -o vesafb.o
#################################################
# Clean up the source directory of any binaries #
#################################################
clean:
-rm -f *.o *.bin *.map *.lst *.out *~ fs/*~ sys/*~ block/*~ char/*~ lang/*~ mm/*~
-rm -f *.o *.bin *.map *.lst *.out *~ fs/*~ sys/*~ block/*~ char/*~ lang/*~ mm/*~ display/*~
+2 -2
View File
@@ -9,8 +9,8 @@
#include "functions.h"
#include "lang/conv.h" // asciiSwitchCase()
#include "kout.h"
#include "display.h" // display_activate()
#include "display/kout.h"
#include "display/display.h" // display_activate()
#define KBD_BUFFER_LENGTH 64
+15 -17
View File
@@ -8,7 +8,7 @@
#include "fs/devices.h"
#include "mm/vmm.h"
#include "lang/lang.h"
#include "display.h"
#include "display/display.h"
#include "functions.h"
vconsole_t *vconsoles[VCONSOLE_MAX]; // pointer to virtual console structs
@@ -39,7 +39,7 @@ minor_t vconsole_new(int width, int height)
int i;
for (i = 1; i < VCONSOLE_MAX; i++)
{
if ( (!vconsoles[i]) && ( vconsoles[i] = kcalloc(1, sizeof(vconsole_t)))) //New(vconsole_t) ) )
if ( (!vconsoles[i]) && ( vconsoles[i] = New(vconsole_t) ) )
{
if (( vconsoles[i]->buffer = kmalloc(width * height * 2) ))
{
@@ -47,7 +47,7 @@ minor_t vconsole_new(int width, int height)
vconsoles[i]->height = height;
vconsoles[i]->attribute = vconsoles[i]->foreground = 0x07;
memsetw(vconsoles[i]->buffer, 0x0720, width * height);
// register the device as /dev/console%d
// TODO: register the device as /dev/console%d
return i;
}
else
@@ -65,7 +65,8 @@ minor_t vconsole_new(int width, int height)
int vconsole_draw(minor_t id)
{
if (vconsoles[id])
return display_console_draw(id, vconsoles[id]->cursorPosition, vconsoles[id]->buffer);
return display_console_draw(id, vconsoles[id]->cursorPosition,
vconsoles[id]->buffer, vconsoles[id]->width * vconsoles[id]->height);
return -1;
}
@@ -144,14 +145,11 @@ int vconsole_char_write(minor_t id, int c)
break;
case 's': // push cursor position on an internal stack
if (vconsoles[id]->cursorStackPosition < 16)
vconsoles[id]->cursorStack[vconsoles[id]->cursorStackPosition++] = vconsoles[id]->cursorPosition;
vconsoles[id]->cursorStack[vconsoles[id]->cursorStackPosition++] = vconsoles[id]->cursorPosition;
break;
case 'u': // pop cursor position from stack
if (vconsoles[id]->cursorStackPosition > 0)
{
vconsole_update_cursor(id, vconsoles[id]->cursorStack[--vconsoles[id]->cursorStackPosition]);
}
if (vconsoles[id]->cursorStackPosition > 0)
vconsole_update_cursor(id, vconsoles[id]->cursorStack[--vconsoles[id]->cursorStackPosition]);
break;
case 'm': // set text attributes
for (evalEscapePosition = 0; evalEscapePosition <= vconsoles[id]->escapePosition; evalEscapePosition++)
@@ -261,13 +259,13 @@ void vconsole_update_cursor(minor_t id, u16_t position)
vconsoles[id]->cursorPosition = position;
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;
}
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;
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);
-96
View File
@@ -1,96 +0,0 @@
// 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/lang.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;
}
+126
View File
@@ -0,0 +1,126 @@
// display.c
// Author: Josh Holtrop
// Date: 08/07/04
// Modified: 03/19/05
#include "fs/devices.h"
#include "char/vconsole.h"
#include "display.h"
#include "lang/lang.h"
#include "kernel.h"
#include "display/vesafb.h"
extern real_mode_param_t rm_params; // check if a video mode is activated
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;
int width = 80;
int height = 25;
int displayType = DISPLAY_CONSOLE;
if (rm_params.vid_addr) // framebuffer mode
{
vesafb_init(rm_params.width, rm_params.height, rm_params.bpp);
width = vesafb_getWidth();
height = vesafb_getHeight();
displayType = DISPLAY_FB;
}
if (( vc = vconsole_new(width, height) ))
{
myDisplays[11].type = displayType;
myDisplays[11].id = vc;
display_activeConsole = vc;
}
else
return -1;
int i;
for (i = 0; i < 6; i++)
{
if ((vc = vconsole_new(width, height)))
{
myDisplays[i].type = displayType;
myDisplays[i].id = vc;
}
else
return -2 - i;
}
return 0;
}
// activate the given display
int display_activate(u32_t id)
{
if (id > 11)
return -1;
switch (myDisplays[id].type)
{
case DISPLAY_CONSOLE:
case DISPLAY_FB:
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, int buff_len)
{
if (id == display_activeConsole)
{
int i;
for (i = 0; i < 12; i++)
{
if (myDisplays[i].id == id)
{
if (myDisplays[i].type == DISPLAY_CONSOLE)
{
memcpyw((void *)CONSOLE_MEMORY, buffer, buff_len);
writeCursorPosition(cursorPosition);
return 0;
}
else if (myDisplays[i].type == DISPLAY_FB)
return vesafb_draw(buffer, buff_len, cursorPosition);
return -2;
}
}
}
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)
{
if (myDisplays[id].type == DISPLAY_CONSOLE)
*(u16_t *)(CONSOLE_MEMORY + (position << 1)) = c;
else if (myDisplays[id].type == DISPLAY_FB)
vesafb_draw_char(position, 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)
{
if (myDisplays[id].type == DISPLAY_CONSOLE)
writeCursorPosition(cursorPosition);
else if (myDisplays[id].type == DISPLAY_FB)
vesafb_update_cursor(cursorPosition);
return 0;
}
return -1;
}
+10 -8
View File
@@ -1,7 +1,7 @@
// display.h
// Author: Josh Holtrop
// Date: 08/07/04
// Modified: 08/21/04
// Modified: 03/19/05
#ifndef __HOS_CONSOLE__
#define __HOS_CONSOLE__ __HOS_CONSOLE__
@@ -9,18 +9,20 @@
#include "hos_defines.h"
#include "fs/devices.h"
#define DISPLAY_NULL 0
#define DISPLAY_CONSOLE 1
#define DISPLAY_GRAPHICAL 2
#define DISPLAY_NULL 0
#define DISPLAY_CONSOLE 1
#define DISPLAY_FB 2
#define DISPLAY_GRAPHICAL 3
typedef struct {
int type;
minor_t id;
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_draw(minor_t id, int cursorPosition, u16_t *buffer, int buff_len);
int display_console_put_char(minor_t id, u16_t c, int position);
int display_console_update_cursor(minor_t id, int cursorPosition);
+4 -7
View File
@@ -1,17 +1,14 @@
// kout.c
// Author: Josh Holtrop
// Date: 08/02/04
// Modified: 08/16/04
// Modified: 03/19/05
#include "hos_defines.h"
#include "char/parallel.h"
#include "kout.h"
#include "lang/conv.h"
#include "fs/devices.h"
extern int display_activeConsole;
char buffer[64];
char buffer[64]; // for hex/oct/dec/ascii conversion
// print a character
void putc(int c)
@@ -19,14 +16,14 @@ void putc(int c)
#ifdef PARALLEL_DEBUG
char_write(MAJORC_PARALLEL, 0, c);
#endif
char_write(MAJORC_VCONSOLE, display_activeConsole, c);
char_write(MAJORC_VCONSOLE, 1, c); // write to vconsole with minor 1, first allocated
}
// print a formatted string
void kprintf(char *fmt, ...)
{
u32_t *params = ((u32_t *)(&fmt)) + 1; //points to the first paramater
u32_t *params = ((u32_t *)(&fmt)) + 1; // points to the first paramater
int i;
int special = 0;
for (i = 0; ; i++)
File renamed without changes.
+111
View File
@@ -0,0 +1,111 @@
// vesafb.c
// Author: Josh Holtrop
// Date: 03/19/05
// Modified: 03/19/05
#include "display/display.h"
#include "display/vesafb.h"
#include "lang/lang.h"
#include "hos_defines.h" // BIOS_CHAR_MAP
u16_t *vmem16 = (u16_t *) VESAFB_VID_ADDR;
u32_t *vmem32 = (u32_t *) VESAFB_VID_ADDR;
int vesafb_bpp;
int vesafb_multiplier;
int vesafb_width; // pixels
int vesafb_height;
int vesafb_xres; // characters
int vesafb_yres;
int vesafb_cursor; // -1 to hide, 0+ for cursor position
int vesafb_init(int width, int height, int bpp)
{
switch(vesafb_bpp = bpp)
{
case 15: case 16:
vesafb_multiplier = 2;
break;
case 24:
vesafb_multiplier = 3;
break;
case 32:
vesafb_multiplier = 4;
break;
}
vesafb_width = width;
vesafb_height = height;
vesafb_xres = (width >> 3) & 0xFFF8; // columns divisible by 8
vesafb_yres = height >> 3;
return vesafb_cursor = 0;
}
void vesafb_clear()
{
memset(vmem32, 0, vesafb_width * vesafb_height * vesafb_multiplier);
vesafb_update_cursor(0);
}
void vesafb_update_cursor(int position)
{
vesafb_draw_cursor(vesafb_cursor, 0);
vesafb_draw_cursor(vesafb_cursor = position, 1);
}
void vesafb_draw_cursor(int position, int onoff)
{
int x = (position % vesafb_xres) << 3;
int y = ( (position / vesafb_xres) << 3 ) + 7;
int i;
for (i = 0; i < 7; i++)
vesafb_pset(x + i, y, onoff);
}
void vesafb_pset(int x, int y, int onoff)
{
switch (vesafb_bpp)
{
case 15: case 16:
*(vmem16 + vesafb_width*y + x) = (onoff ? 0xFFFF : 0);
break;
case 24:
*((u32_t *)(((u32_t)vmem32) + 3*vesafb_width*y + 3*x)) = (onoff ? 0x00FFFFFF : 0);
break;
case 32:
*(vmem32 + vesafb_width*y + x) = (onoff ? 0x00FFFFFF : 0);
break;
}
}
int vesafb_getWidth()
{
return vesafb_xres;
}
int vesafb_getHeight()
{
return vesafb_yres;
}
void vesafb_draw_char(int position, u16_t chr)
{
int x = (position % vesafb_xres) << 3;
int y = (position / vesafb_xres) << 3;
int xi, yi;
u8_t *charMap = (u8_t *) ( BIOS_CHAR_MAP + ((chr & 0xFF) << 3) );
for (yi = 0; yi < 7; yi++)
{
for (xi = 0; xi < 7; xi++)
vesafb_pset(x + xi, y + yi, (*charMap & (0x80 >> xi)));
charMap++;
}
}
int vesafb_draw(u16_t *buffer, int buff_len, int cursor_position)
{
int i;
for (i = 0; i < buff_len; i++)
vesafb_draw_char(i, *buffer++);
vesafb_update_cursor(cursor_position);
return 0;
}
+25
View File
@@ -0,0 +1,25 @@
// vesafb.h
// Author: Josh Holtrop
// Date: 03/19/05
// Modified: 03/19/05
#ifndef __HOS_VESAFB__
#define __HOS_VESAFB__ __HOS_VESAFB__
#include "hos_defines.h"
#define VESAFB_VID_ADDR 0xF0000000
int vesafb_init(int width, int height, int bpp);
void vesafb_clear();
void vesafb_update_cursor(int position);
void vesafb_draw_cursor(int position, int onoff);
void vesafb_pset(int x, int y, int onoff);
int vesafb_getWidth();
int vesafb_getHeight();
void vesafb_draw_char(int position, u16_t chr);
int vesafb_draw(u16_t *buffer, int buff_len, int cursor_position);
#endif
+19 -2
View File
@@ -5,7 +5,7 @@
#include "hos_defines.h"
#include "fs/devices.h"
#include "kout.h"
#include "display/kout.h"
#include "ext2.h"
#include "mm/vmm.h"
#include "fs/vfs.h"
@@ -416,6 +416,23 @@ int ext2_resize_inode(vfs_mount_t *mount, u32_t inode_number, u32_t new_size)
return 0;
// TODO: resize
u32_t block_size = 1024 << super->s_log_block_size;
u32_t pointers_per_block = block_size >> 2;
u32_t *pointer_cache1 = kmalloc(3 * block_size);
u32_t *pointer_cache2 = pointer_cache1 + pointers_per_block;
u32_t *pointer_cache3 = pointer_cache2 + pointers_per_block;
u32_t c1_start, c2_start, c3_start;
c1_start = c2_start = c3_start = 0;
while (new_blocks < current_blocks) // delete, decrease current_blocks
{
current_blocks--;
// now delete block number current_blocks
}
while (current_blocks < new_blocks) // add, increase current_blocks
{
}
}
// reserve a node of a inode or block bitmap and mark its entry allocated
@@ -719,7 +736,7 @@ int ext2__read_block_file(vfs_mount_t *mount, vfs_open_file_t *open_file, void *
kfree(block);
return 0; // EOF
}
memcpy(buffer, block + data_offset, 512);
memcpy(buffer, block + data_offset, min(512, bytes_read - data_offset));
kfree(block);
open_block_file->block++;
return min(512, bytes_read - data_offset);
+1 -1
View File
@@ -119,7 +119,7 @@ typedef struct
u32_t i_blocks; // Blocks count
u32_t i_flags; // File flags
u32_t i_reserved1;
u32_t i_block[15]; // Pointers to file blocks
u32_t i_block[15]; // Pointers to blocks (12 direct, single, double, triple indirect)
u32_t i_version; // File version (for NFS)
u32_t i_file_acl; // File ACL
u32_t i_dir_acl; // Directory ACL
+1 -1
View File
@@ -4,7 +4,7 @@
// Modified: 12/21/04
#include "hos_defines.h"
#include "kout.h"
#include "display/kout.h"
#include "fs/vfs.h"
#include "fs/ext2.h"
#include "kernel.h"
+1
View File
@@ -16,6 +16,7 @@
#define HEAP_LENGTH 0x20000000
#define CONSOLE_MEMORY 0xC00B8000
#define BIOS_CHAR_MAP 0xC00FFA6E
#define MAX_MODULES 16
#define MAX_MMAP 16
+20 -20
View File
@@ -1,7 +1,7 @@
// kernel.h
// Author: Josh Holtrop
// Date: 08/16/04
// Modified: 08/28/04
// Modified: 03/19/05
// This is the main kernel initialization and boot-strapping file
#include "kernel.h"
@@ -12,11 +12,11 @@
#include "mm/mm.h"
#include "mm/vmm.h"
#include "char/parallel.h"
#include "kout.h"
#include "lang/conv.h"
#include "char/vconsole.h"
#include "fs/devices.h"
#include "display.h"
#include "display/display.h"
#include "display/kout.h"
#include "sys/io.h"
#include "sys/pic.h"
#include "char/keyboard.h"
@@ -110,11 +110,23 @@ void k_init()
devices_init();
if (real_mode_module)
{
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.vid_addr) // there is video memory to map in
{
u32_t vid_mem = rm_params.width * rm_params.height;
switch (rm_params.bpp)
{
case 15: case 16:
vid_mem <<= 1; break;
case 24:
vid_mem *= 3; break;
case 32:
vid_mem <<= 2; break;
}
vmm_mapn(0xF0000000, (u32_t)rm_params.vid_addr, (vid_mem >> 12) + 1);
}
}
display_init(); //get us some virtual consoles to look at
display_activate(11);
display_init(); // get us some virtual consoles to look at
display_activate(11); // activate kernel dump vconsole
kprintf("HOS v0.16 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);
@@ -174,19 +186,7 @@ void k_init()
}
else
kprintf("Error: Could not open directory\n");
vfs_mount_t *rootm = vfs_get_mount(0);
kprintf("Total/Free inodes: %d/%d\tTotal/Free blocks: %d/%d\n",
vfs_total_inodes(rootm), vfs_free_inodes(rootm), vfs_total_blocks(rootm), vfs_free_blocks(rootm));
u32_t block = vfs_alloc_block(rootm);
kprintf("VFS got block %d\n", block);
kprintf("Total/Free inodes: %d/%d\tTotal/Free blocks: %d/%d\n",
vfs_total_inodes(rootm), vfs_free_inodes(rootm), vfs_total_blocks(rootm), vfs_free_blocks(rootm));
kprintf("Freeing block... %d\n", vfs_free_block(rootm, block));
kprintf("Total/Free inodes: %d/%d\tTotal/Free blocks: %d/%d\n",
vfs_total_inodes(rootm), vfs_free_inodes(rootm), vfs_total_blocks(rootm), vfs_free_blocks(rootm));
kprintf("Freeing block (again)... %d\n", vfs_free_block(rootm, block));
kprintf("Total/Free inodes: %d/%d\tTotal/Free blocks: %d/%d\n",
vfs_total_inodes(rootm), vfs_free_inodes(rootm), vfs_total_blocks(rootm), vfs_free_blocks(rootm));
criticalCounter--;
}
-1
View File
@@ -13,7 +13,6 @@ 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 vid_mem; // amount of memory for video buffer
u32_t bpp; // bits per pixel - 15/16/24/32
} __attribute__ ((packed)) real_mode_param_t;