Import backup from 2003-12-20

This commit is contained in:
Josh Holtrop 2003-12-20 22:00:00 -05:00
parent 5ccfd0fc74
commit 3bb1e5fffc
8 changed files with 74 additions and 213 deletions

View File

@ -40,84 +40,6 @@ _read_cr3:
ret
;copies 32bpp video buffer memory to LFB
;extern dword video_copyBuffer32(dword src, dword dest, dword pixelcount);
[global _video_copyBuffer32]
_video_copyBuffer32:
push ebp
mov ebp, esp
push esi
push edi
push ecx
mov esi, [ebp+8]
mov edi, [ebp+12]
mov ecx, [ebp+16]
rep movsd
pop ecx
pop edi
pop esi
pop ebp
ret
;copies 24bpp video buffer memory to LFB
;extern dword video_copyBuffer24(dword src, dword dest, dword pixelcount);
[global _video_copyBuffer24]
_video_copyBuffer24:
push ebp
mov ebp, esp
push esi
push edi
push ecx
mov esi, [ebp+8]
mov edi, [ebp+12]
mov ecx, [ebp+16]
_video_copyBuffer24_loop:
movsd
dec edi
loop _video_copyBuffer24_loop
pop ecx
pop edi
pop esi
pop ebp
ret
;copies 16bpp video buffer memory to LFB
;extern dword video_copyBuffer16(dword src, dword dest, dword pixelcount);
[global _video_copyBuffer16]
_video_copyBuffer16:
push ebp
mov ebp, esp
push esi
push edi
push ecx
push ebx
mov esi, [ebp+8]
mov edi, [ebp+12]
mov ecx, [ebp+16]
_video_copyBuffer16_loop:
lodsd ;eax = 32bpp color
shr eax, 3
mov ebx, eax
and ebx, 0x1F
shr eax, 2
and eax, 0xFFFFFFE0
or ebx, eax
and ebx, 0x7FF
shr eax, 3
and eax, 0xF800
or ebx, eax
mov eax, ebx
stosw ;store ax
loop _video_copyBuffer16_loop
pop ebx
pop ecx
pop edi
pop esi
pop ebp
ret

View File

@ -1,5 +1,5 @@
%define VERSION "0.1.2" ;HOS version
%define VERSION "0.12" ;HOS version
%define BOOT_FAT_SEG 0x07E0 ;right after boot sector
%define BOOT_ROOT_SEG 0x0900 ;right after FAT

View File

@ -58,29 +58,13 @@ void k_init()
printf("HOS 0.12 - Kernel Size: %d kb\n", kernel_size()/1024);
printf("Memory available to OS: %d MB (Bytes: %d)\n", mm_totalmem/0x100000, mm_totalmem);
printf("Freem memory: %d bytes\n", mm_freemem());
/* int fx;
int fy = 30;
int fc;
int fr;
word *vidmem = (word *)0xB8000;
for (fr = 0; fr < 25; fr++)
{
fx = 300;
for (fc = 0; fc < 80; fc++)
{
video_renderChar(fx, fy, (char)vidmem[fr*80+fc], 0xFFFFFF);
fx += 8;
}
fy += 10;
} */
printf("Free memory: %d bytes\n", mm_freemem());
dword key = 0;
for (;;)
{
key = kbdWaitKey();
if (((key & 0xFF00) >> 8) != 2) //key is not a control key
// if (((key & 0xFF00) >> 8) != 2) //key is not a control key
putc(key);
}
}

27
mm.c
View File

@ -4,10 +4,15 @@
// 0x368000 is first available byte (this is right after the kernel @ 1mb and the initrd @ 2mb, 1440kb.
//Pointer to the first pageblock in the linked list
pageblock *first_pageblock = (pageblock *) 0;
//The total amount of physical memory available (bytes)
dword mm_totalmem = 0x100000; //start counting from 1mb
//The highest physical address
dword mm_highestAddress = 0;
//This function initializes the memory manager's linked list, filling it with the
// memory areas returned by bios interrupt 0x8E20
void mm_init()
{
dword *memmap_entries = (dword *) 0x9040A;
@ -66,7 +71,7 @@ void mm_init()
//This function initializes a pageblock to be full of empty pointers
void mm_init_pageblockpage(pageblock *pbp)
{
int a;
@ -83,6 +88,10 @@ void mm_init_pageblockpage(pageblock *pbp)
}
//This function allocates a certain number of physical pages for a particular process
//Returns:
// 0 - no free mem, invalied PID
// void* - physical address of allocated pages
void *mm_palloc(dword numpages, dword proc_pid)
{
if (proc_pid < PID_KERNEL)
@ -119,6 +128,7 @@ void *mm_palloc(dword numpages, dword proc_pid)
}
//This method returns the number of free pageblock entries at the end of the linked list
dword mm_freeentries()
{
pageblock *pb = first_pageblock;
@ -134,6 +144,10 @@ dword mm_freeentries()
}
//This method creates a new page used to hold more pageblock entries at the end of the linked list
//Returns:
// 0 - no free pages
// pageblock* - address of pageblock page
pageblock *mm_new_pageblock_page() //as of 09/26/03 this method leaks 4kb main memory per call, unrecoverable
{
pageblock *pb = first_pageblock;
@ -155,6 +169,11 @@ pageblock *mm_new_pageblock_page() //as of 09/26/03 this method leaks 4kb main
}
//This method frees a physical page
//Returns:
// 2 - pointer to free was a null pointer
// 1 - address not found
// 0 - all went well
int mm_pfree(void *ptr)
{
if (ptr == 0)
@ -176,6 +195,7 @@ int mm_pfree(void *ptr)
}
//This method returns a pointer to the last pageblock in the linked list
pageblock *mm_lastpageblockentry()
{
pageblock *pb = first_pageblock;
@ -188,6 +208,8 @@ pageblock *mm_lastpageblockentry()
}
//This method returns the next available-for-use pageblock entry
// or 0, if they are all used
pageblock *mm_nextpageblockentry()
{
pageblock *pb = first_pageblock;
@ -202,6 +224,7 @@ pageblock *mm_nextpageblockentry()
}
//This method returns the amount of free physical RAM
dword mm_freemem()
{
dword amount = 0;
@ -217,6 +240,8 @@ dword mm_freemem()
}
//This method "walks" through the linked list of pageblock entries and
// combines any two entries that are adjacent and of the same type
void mm_coalesce(pageblock *pb)
{
pageblock *pbc = first_pageblock;

View File

@ -3,6 +3,7 @@
// Author: Josh Holtrop
//This method initializes the ps/2 mouse
void mouse_init()
{
outportb(0x64, 0x20); //tell keyboard controller we are going to read keyboard controller command byte
@ -23,7 +24,7 @@ void mouse_init()
}
//This method is called when a mouse interrupt occurs
void isr_mouse()
{
byte inb = inportb(0x60); //read mouse byte
@ -50,15 +51,14 @@ void isr_mouse()
mouse_y = video_mode.YResolution - 1;
if (mouse_inbuffer[0] & 0x01) //left button
{
video_pset(mouse_x, mouse_y, 0x00FFFFFF);
video_pset(mouse_x, mouse_y, 0x00FF8800);
printf("X: %d, Y: %d\n", mouse_x, mouse_y);
}
else
{
video_pset(mouse_x, mouse_y, 0x00000000);
video_pset(mouse_x, mouse_y, 0x00FFFFFF);
printf("X: %d, Y: %d\n", mouse_x, mouse_y);
}
video_copyBuffer();
}
}

View File

@ -33,7 +33,7 @@ brFSID DB 'FAT12 ' ; 0036h - File System ID
;------------------------------------------------------------------------
start:
jmp 0:jmphere ;ensure that cs=0 and ip=0x7c...
jmp 0:jmphere ;ensure that cs=0 and ip=0x7c00...
jmphere:
;dl=drive number, save it!
xor ax, ax
@ -88,7 +88,7 @@ unreal:
pop es ;segments back, with 4gb limits!
sti
;now lets read in the FAT and root directory so we can search for the kernel file...
;now lets read in the FAT and root directory so we can search for the stage2 file...
mov ax, 0x0209 ;FAT1
mov cx, 0x0002
xor dh, dh

128
video.c
View File

@ -8,70 +8,20 @@ void video_init(ModeInfoBlock *mib)
{
video_mode = *mib;
//Get a buffer region in memory for double-buffering video memory in 32bpp
vid_Buffer = mm_palloc((4*video_mode.XResolution*video_mode.YResolution)/4096+1, PID_KERNEL);
if ((dword)vid_Buffer == 0)
switch(video_mode.BitsPerPixel)
{
printf("ERROR - COULD NOT ALLOCATE MEMORY FOR VIDEO DOUBLE-BUFFER!!\n");
halt();
case 16:
vid_ptr16 = (word *) video_mode.PhysBasePtr;
video_psetp = &video_psetp16;
break;
case 24:
vid_ptr24 = (byte *) video_mode.PhysBasePtr;
video_psetp = &video_psetp24;
break;
case 32:
video_psetp = &video_psetp32;
vid_ptr32 = (dword *) video_mode.PhysBasePtr;
}
dword tot = ((video_mode.XResolution) * (video_mode.YResolution));
int a;
for (a = 0; a < tot; a++)
{
if (a < (tot / 4))
vid_Buffer[a] = 0x00FF0000;
else if (a < (tot / 2))
vid_Buffer[a] = 0x0000FF00;
else if (a < ((tot * 3) / 4))
vid_Buffer[a] = 0x000000FF;
else
vid_Buffer[a] = 0x00FFFFFF;
}
int VXR = video_mode.XResolution;
int VYR = video_mode.YResolution;
video_rectf(VXR*3/11, 0, VXR*4/11, VYR-1, 0x00000088); //test rectangles, draws "HOS"
video_rectf(VXR*7/11, 0, VXR*8/11, VYR-1, 0x00000088);
video_rectf(VXR/11, 0, VXR*2/11, VYR*2/5, 0x00000088);
video_rectf(VXR/11, VYR*3/5, VXR*2/11, VYR-1, 0x00000088);
video_rectf(VXR*5/11, VYR/5, VXR*6/11, VYR*4/5, 0x00000088);
video_rectf(VXR*9/11, VYR/5, VXR-1, VYR*2/5, 0x00000088);
video_rectf(VXR*8/11, VYR*3/5, VXR*10/11, VYR*4/5, 0x00000088);
int b;
for (a = 0; a < 256; a++)
{
for (b = 0; b < 256; b++)
{
video_pset(a+5, b+30, (a<<16)|(b<<8));
video_pset(a+270, b+30, (a<<8)|(b));
video_pset(a+535, b+30, (a<<16)|(b));
video_pset(a+5, b+290, (a<<16)|(b<<8)|0x000000ff);
video_pset(a+270, b+290, (a<<8)|(b)|0x00ff0000);
video_pset(a+535, b+290, (a<<16)|(b)|0x0000ff00);
}
}
int fx;
int fy = 25;
int fc;
int fr;
for (fr = 0; fr < 16; fr++)
{
fx = 15;
for (fc = 0; fc < 16; fc++)
{
video_renderChar(fx, fy, fr*16+fc, 0xFFFFFF);
fx += 8;
}
fy += 10;
}
video_copyBuffer();
}
//Renders a character using stdfont[] as a bitmask
@ -110,7 +60,7 @@ void video_horiz(int y, int x1, int x2, dword color)
int pixel = y*video_mode.XResolution+x1;
for (; x1 <= x2; x1++)
{
vid_Buffer[pixel++] = color;
video_psetp(pixel++, color);
}
}
@ -134,7 +84,7 @@ void video_vert(int x, int y1, int y2, dword color)
int pixel = y1*video_mode.XResolution+x;
for (; y1 <= y2; y1++)
{
vid_Buffer[pixel] = color;
video_psetp(pixel, color);
pixel+=video_mode.XResolution;
}
}
@ -166,48 +116,28 @@ inline void video_pset(int x, int y, dword color)
{
if ((x < 0) || (x > video_mode.XResolution) || (y < 0) || (y > video_mode.YResolution))
return;
vid_Buffer[y*video_mode.XResolution+x] = color;
video_psetp(y*video_mode.XResolution+x, color);
}
//Copies double-buffer to VESA Linear Frame Buffer
void video_copyBuffer()
//Draws a pixel at the specified pixel position
void video_psetp16(int pixel, dword color)
{
switch (video_mode.BitsPerPixel)
{
case 32:
video_copyBuffer32((dword)vid_Buffer, video_mode.PhysBasePtr, video_mode.XResolution*video_mode.YResolution);
break;
case 24:
video_copyBuffer24((dword)vid_Buffer, video_mode.PhysBasePtr, video_mode.XResolution*video_mode.YResolution);
break;
case 16:
video_copyBuffer16((dword)vid_Buffer, video_mode.PhysBasePtr, video_mode.XResolution*video_mode.YResolution);
break;
vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<5) | ((((color>>16)&0xFF)>>3)<<11);
}
/*int pixel;
dword color;
for (pixel = 0; pixel < video_mode.XResolution*video_mode.YResolution; pixel++)
//Draws a pixel at the specified pixel position
void video_psetp24(int pixel, dword color)
{
switch(video_mode.BitsPerPixel)
{
case 16:
color = vid_Buffer[pixel];
((word *)video_mode.PhysBasePtr)[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>2)<<5) | ((((color>>16)&0xFF)>>3)<<11);
//vid_ptr16[pixel] = ((color&0xFF)>>3) | ((((color>>8)&0xFF)>>3)<<5) | ((((color>>16)&0xFF)>>3)<<10); //15 bit mode?
break;
case 24:
color = vid_Buffer[pixel];
((byte *)video_mode.PhysBasePtr)[pixel*3] = color & 0xFF;
((byte *)video_mode.PhysBasePtr)[pixel*3+1] = (color>>8) & 0xFF;
((byte *)video_mode.PhysBasePtr)[pixel*3+2] = (color>>16) & 0xFF;
break;
case 32:
color = vid_Buffer[pixel];
((dword *)video_mode.PhysBasePtr)[pixel] = color;
vid_ptr24[pixel*3] = color & 0xFF;
vid_ptr24[pixel*3+1] = (color>>8) & 0xFF;
vid_ptr24[pixel*3+2] = (color>>16) & 0xFF;
}
} */
//Draws a pixel at the specified pixel position
void video_psetp32(int pixel, dword color)
{
vid_ptr32[pixel] = color;
}

14
video.h
View File

@ -8,14 +8,11 @@ void video_vert(int x, int y1, int y2, dword color);
void video_rect(int x1, int y1, int x2, int y2, dword color);
void video_rectf(int x1, int y1, int x2, int y2, dword color);
inline void video_pset(int x, int y, dword color);
void video_psetp(int pixel, dword color);
void video_copyBuffer();
void video_psetp16(int pixel, dword color);
void video_psetp24(int pixel, dword color);
void video_psetp32(int pixel, dword color);
void video_renderChar(int x, int y, int character, dword color);
extern dword video_copyBuffer16(dword src, dword dest, dword pixelcount);
extern dword video_copyBuffer24(dword src, dword dest, dword pixelcount);
extern dword video_copyBuffer32(dword src, dword dest, dword pixelcount);
typedef struct{
word ModeAttributes;
byte WinAAttributes;
@ -56,7 +53,10 @@ typedef struct{
} ModeInfoBlock;
ModeInfoBlock video_mode;
dword *vid_Buffer;
byte *vid_ptr24;
word *vid_ptr16;
dword *vid_ptr32;
void (*video_psetp)(int, dword); //function pointer to set a pixel