Import backup from 2005-03-21

This commit is contained in:
Josh Holtrop 2005-03-21 22:00:00 -05:00
parent bb8ff09e3f
commit 14792ef954
24 changed files with 671 additions and 197 deletions

View File

@ -20,8 +20,10 @@ all:
clean:
-make -C kernel clean
-make -C rmmod clean
-rm -f *~ *.out hos.flp \#* hos_initrd hos_initrd.gz parallel.out
-rm -f *~ *.out hos.flp \#* hos_initrd hos_initrd.gz
apps:
make -C apps
grub:
-mkdir $(FLOPPY_MOUNT)
@ -62,18 +64,13 @@ initrd:
mke2fs -Fv -m0 -r0 -i1024 $(INITRD)
-mkdir $(INITRD_MOUNT)
mount -t ext2 -o loop $(INITRD) $(INITRD_MOUNT)
touch $(INITRD_MOUNT)/hi_there
chmod 527 $(INITRD_MOUNT)/hi_there
chown josh:users $(INITRD_MOUNT)/hi_there
mknod $(INITRD_MOUNT)/rd0 b 5 2
mkdir $(INITRD_MOUNT)/txt
cp Makefile $(INITRD_MOUNT)/txt
ln -s txt/../txt/../txt/../txt/../txt/../txt/../txt/../txt/../txt/.. $(INITRD_MOUNT)/link
ln -s /txt/. $(INITRD_MOUNT)/yoda
mkdir $(INITRD_MOUNT)/bin
cp apps/hash/hash $(INITRD_MOUNT)/bin
ln -s /bin/hash $(INITRD_MOUNT)/bin/init
umount $(INITRD_MOUNT)
rm -rf $(INITRD_MOUNT)
wordcount:
find . -regex '\(.*\.[ch]\)\|\(.*\.asm\)\|\(.*\.inc\)\|\(.*\.cpp\)' | xargs cat | wc -l
find . -regex '\(.*\.[ch]\)\|\(.*\.asm\)\|\(.*\.inc\)\|\(.*\.cpp\)' | xargs cat | wc

3
apps/Makefile Normal file
View File

@ -0,0 +1,3 @@
all:
make -C hash

3
apps/hash/Makefile Normal file
View File

@ -0,0 +1,3 @@
all:
nasm -f bin hash.asm -o hash

1
apps/hash/hash Normal file
View File

@ -0,0 +1 @@
<EFBFBD>0<EFBFBD>

6
apps/hash/hash.asm Normal file
View File

@ -0,0 +1,6 @@
[bits 32]
begin:
int 0x30
ret

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/*~

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

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;
}
@ -148,10 +149,7 @@ int vconsole_char_write(minor_t id, int c)
break;
case 'u': // pop cursor position from stack
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++)

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
kernel/display/display.c Normal file
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;
}

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__
@ -11,16 +11,18 @@
#define DISPLAY_NULL 0
#define DISPLAY_CONSOLE 1
#define DISPLAY_GRAPHICAL 2
#define DISPLAY_FB 2
#define DISPLAY_GRAPHICAL 3
typedef struct {
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);

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++)

111
kernel/display/vesafb.c Normal file
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
kernel/display/vesafb.h Normal file
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

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);

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

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"

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

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;
}
display_init(); //get us some virtual consoles to look at
display_activate(11);
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); // 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--;
}

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;

View File

@ -27,6 +27,8 @@ con_move_cursor: ;con_move_cursor(word location)
con_clear:
pusha
push es
push ds
mov ax, 0xB800
mov es, ax
@ -37,6 +39,8 @@ con_clear:
mov [cursor], word 0
call con_write_cursor
pop ds
pop es
popa
ret
@ -52,9 +56,7 @@ putstring_loop:
or al, al
jz putstring_done
mov ah, 0x07
push ax
call con_putc
add sp, 2
ccall con_putc, ax
jmp putstring_loop
putstring_done:
@ -63,10 +65,93 @@ putstring_done:
ret
con_putHex: ;con_putHex(word hexVal)
push bp
mov bp, sp
pusha
mov ax, [bp + 4]
mov cx, 12
mov dl, 0
con_putHex_loop:
push ax
shr ax, cl
and ax, 0xF
cmp ax, 0
jnz con_putHex_putc
cmp cx, 0
jz con_putHex_putc
cmp dl, 0
jz con_putHex_loop_done
con_putHex_putc:
add ax, '0'
cmp ax, '9'
jbe con_putHex_putc_goon
add ax, 'A'-'9'-1
con_putHex_putc_goon:
mov ah, 0x07
ccall con_putc, ax
mov dl, 1
con_putHex_loop_done:
pop ax
cmp cx, 0
jz con_putHex_done
sub cx, 4
jmp con_putHex_loop
con_putHex_done:
popa
pop bp
ret
con_putDec: ;con_putDec(word dec)
push bp
mov bp, sp
pusha
mov ax, [bp + 4]
mov cx, 10000
mov di, 0
con_putDec_loop:
xor dx, dx
div cx ;remainder in dx, quotient in ax
mov bx, ax
mov ax, dx ;new value is ax % mod
push ax
mov ax, bx
cmp ax, 0
jnz con_putDec_putc
cmp cx, 1
jz con_putDec_putc
cmp di, 0
jz con_putDec_loop_done
con_putDec_putc:
add ax, 0x0730
ccall con_putc, ax
mov di, 1
con_putDec_loop_done:
mov ax, cx
xor dx, dx
mov bx, 10
div bx
mov cx, ax
pop ax
cmp cx, 0
jnz con_putDec_loop
popa
pop bp
ret
con_putc: ;con_putc(char chr)
push bp
mov bp, sp
pusha
push es
mov ax, 0xB800
mov es, ax
@ -86,6 +171,8 @@ putc_return:
putc_update:
mov [cursor], di
call con_write_cursor
pop es
popa
pop bp
ret

View File

@ -5,7 +5,7 @@
; Modified: 01/04/05
%define VIRT_OFFSET 0xC0000000
%define SIZEOF_RMPARAMS 20
%include "rmmod.inc"
; the bootstrap process will jump us to 0x0:0x5010 so we'd better be ready for it
@ -21,6 +21,10 @@
; ecx = where to store real mode parameter table
start:
jmp 0:start_refreshed
%include "conio.inc"
%include "vesa.inc"
start_refreshed:
mov ax, cs ; 0
mov ds, ax
@ -30,30 +34,144 @@ start_refreshed:
mov [dat_rmadd], ecx
mov [dat_retn], ebx
mov ebx, ecx ; clear the rm_params
mov cx, SIZEOF_RMPARAMS
mov ax, 0
clear_rmparams_loop:
mov [ebx], al
inc ebx
loop clear_rmparams_loop
; begin real-mode code initialization, etc...
call con_clear
; ccall vesa_get_info, es, vbe_info_block
jmp no_vesa
ccall vesa_get_info, es, vbe_info_block
cmp ax, 0
jnzfar no_vesa
vesa_present:
ccall con_putstring, txt_vesa
mov ax, [VideoModePtr]
mov es, ax
mov si, [VideoModePtr + 2]
xor ax, ax
mov al, [VbeVersion + 1]
ccall con_putHex, ax
ccall con_putc, '.' | 0x0700
xor ax, ax
mov al, [VbeVersion]
ccall con_putHex, ax
ccall con_putc, 10
xor ax, ax ; clear the scratch mem
mov cx, 129
mov di, scratch_mem
rep stosw
push ds
mov ax, [OemStringPtr + 2]
mov si, [OemStringPtr]
mov ds, ax
mov di, scratch_mem
mov cx, 128
rep movsw ; and copy the string there for display
pop ds
ccall con_putstring, scratch_mem ; write OEM string
ccall con_putc, 10
mov ax, [VideoModePtr + 2]
mov es, ax
mov si, [VideoModePtr]
xor dx, dx
vesa_mode_loop:
mov ax, [es:si] ; get next mode number
cmp ax, 0xFFFF
jzfar vesa_mode_loop_done
ccall vesa_get_mode_info, ds, vbe_mode_info_block, ax
cmp ax, 0
jnzfar vesa_mode_loop_next
mov ax, [ModeAttributes]
and ax, VESA_MODE_SUPPORTED | VESA_MODE_COLOR | VESA_MODE_GRAPHICS | VESA_MODE_LFB
cmp ax, VESA_MODE_SUPPORTED | VESA_MODE_COLOR | VESA_MODE_GRAPHICS | VESA_MODE_LFB
jnzfar vesa_mode_loop_next
mov al, [BitsPerPixel]
cmp al, 15
jz vesa_mode_good
cmp al, 16
jz vesa_mode_good
cmp al, 24
jz vesa_mode_good
cmp al, 32
jnzfar vesa_mode_loop_next
vesa_mode_good:
mov ax, dx
add ax, 0x0700 | 'a'
ccall con_putc, ax
ccall con_putstring, txt_vesa_mode1
ccall con_putDec, word [XResolution]
ccall con_putc, 'x' | 0x0700
ccall con_putDec, word [YResolution]
ccall con_putc, 'x' | 0x0700
xor ax, ax
mov al, [BitsPerPixel]
ccall con_putDec, ax
ccall con_putstring, txt_vesa_mode2
mov ax, [es:si] ; mode number
ccall con_putHex, ax
ccall con_putc, 10
mov bx, dx
shl bx, 1
mov [scratch_mem + bx], ax ; store modes in scratch_mem array
inc dx
vesa_mode_loop_next:
add si, 2
jmp vesa_mode_loop
vesa_mode_loop_done:
ccall con_putstring, txt_vesa_end
vesa_get_key_loop:
call con_getkey
mov ah, 0
cmp ax, '0'
jz vesa_the_end
cmp ax, 'a' ; first choice
jb vesa_get_key_loop
add dx, 'a'
cmp ax, dx ; one past last choice
jae vesa_get_key_loop
; ok, we have a valid video mode selection
sub ax, 'a'
shl ax, 1
mov bx, ax
mov cx, [scratch_mem + bx]
ccall vesa_get_mode_info, ds, vbe_mode_info_block, cx
or cx, 0x4000 ; enable LFB
ccall vesa_set_mode, cx ; turn on mode
mov ebx, [dat_rmadd] ; pass mode info to kernel
mov eax, [PhysBasePtr]
mov [ebx + 0], eax
xor eax, eax
mov al, [BitsPerPixel]
mov [ebx + 12], eax
mov ax, [XResolution]
mov [ebx + 4], eax
mov ax, [YResolution]
mov [ebx + 8], eax
jmp vesa_the_end
jmp end_rmmod
no_vesa:
ccall con_putstring, txt_novesa
call con_getkey
vesa_the_end:
end_rmmod: ; get ready to go back to pmode and return to kernel initialization
; call con_getkey
mov ebx, [dat_retn]
lgdt [gdtrlin32]
mov eax, cr0
@ -77,8 +195,6 @@ offset_continue:
[bits 16]
%include "conio.inc"
;-------------------------------------------------------
gdtrlin32:
dw gdt_endlin32-gdtlin32-1
@ -142,7 +258,10 @@ KERNEL_DATA_BS32 equ $-gdtbs32
gdt_endbs32:
txt_vesa: db "VESA found. Please select:", 10, 0
txt_vesa: db "VESA found. VBE Version: ", 0
txt_vesa_mode1 db ". ", 0
txt_vesa_mode2 db ", mode 0x", 0
txt_vesa_end: db "Enter the letter of your selection or 0 for console mode:", 0
txt_novesa: db "VESA not found, using 80x25 console mode... press any key", 10, 0
dat_rmadd: dd 0
@ -162,4 +281,29 @@ OemProductName: dd 0
OemProductRev: dd 0
Reserved: times 478 db 0
vbe_mode_info_block:
ModeAttributes: dw 0
WinAAttributes: db 0
WinBAttributes: db 0
WinGranularity: dw 0
WinSize: dw 0
WinASegment: dw 0
WinBSegment: dw 0
WinFuncPtr: dd 0
BytesPerScanline: dw 0
XResolution: dw 0
YResolution: dw 0
XCharSize: db 0
YCharSize: db 0
NumberOfPlanes: db 0
BitsPerPixel: db 0
NumberOfBanks: db 0
MemoryModel: db 0
BankSize: db 0
NumberOfImagePages: db 0
Reserved2: times 10 db 0
PhysBasePtr: dd 0
Reserved3: times 212 db 0
scratch_mem:

View File

@ -4,30 +4,82 @@
; Modified: 01/04/05
; real mode vesa functions
; sample bochs VBE modes:
;0x000c6a86 <bogus+ 0>: 0x0100 0x0101 0x0102 0x0103 0x0105 0x0110 0x0111 0x0112
;0x000c6a96 <bogus+ 16>: 0x0113 0x0114 0x0115 0x0116 0x0117 0x0118 0x0142 0x0143
;0x000c6aa6 <bogus+ 32>: 0x0144 0x0146 0xffff
%define VESA_MODE_SUPPORTED 0x01
%define VESA_MODE_COLOR 0x08
%define VESA_MODE_GRAPHICS 0x10
%define VESA_MODE_LFB 0x80
vesa_return: dw 0
vesa_get_info: ;vesa_get_info(word seg, word offset)
push bp
mov bp, sp
pusha
push es
push ds
mov ax, [bp + 4]
mov es, ax
mov di, [bp + 6]
mov ax, 0x4F00
int 0x10
cmp ax, 0x004F
jz vesa_got_info
sub ax, 0x004F
mov [vesa_return], ax
mov [vesa_return], word 1
jmp vesa_get_info_done
vesa_got_info:
mov [vesa_return], word 0
vesa_got_info_done:
pop ds
pop es
popa
pop bp
mov ax, [vesa_return]
ret
vesa_return: dw 0
vesa_get_mode_info: ;vesa_get_info(word seg, word offset, word mode)
push bp
mov bp, sp
pusha
push es
push ds
mov ax, [bp + 4]
mov es, ax
mov di, [bp + 6]
mov cx, [bp + 8]
mov ax, 0x4F01
int 0x10
sub ax, 0x004F
mov [vesa_return], ax
pop ds
pop es
popa
pop bp
mov ax, [vesa_return]
ret
vesa_set_mode: ;vesa_set_mode(word mode)
push bp
mov bp, sp
pusha
push es
push ds
mov bx, [bp + 4]
mov ax, 0x4F02
int 0x10
sub ax, 0x004F
mov [vesa_return], ax
pop ds
pop es
popa
pop bp
mov ax, [vesa_return]
ret