Import backup from 2003-12-25
This commit is contained in:
parent
528527a7ed
commit
e82bf2ecdf
296
asmfuncs.asm
296
asmfuncs.asm
@ -1,7 +1,16 @@
|
|||||||
; asmfuncs.asm
|
; asmfuncs.asm
|
||||||
; Josh Holtrop
|
; Josh Holtrop
|
||||||
; 10/23/03
|
; Created: 10/23/03
|
||||||
|
; Modified: 12/25/03
|
||||||
|
|
||||||
|
[extern _putc]
|
||||||
|
|
||||||
|
%macro jzfar 1
|
||||||
|
jnz %%skip
|
||||||
|
jmp %1
|
||||||
|
%%skip:
|
||||||
|
|
||||||
|
%endmacro
|
||||||
|
|
||||||
;stores the parameter to the CR0 register
|
;stores the parameter to the CR0 register
|
||||||
;extern dword write_cr0(dword cr0);
|
;extern dword write_cr0(dword cr0);
|
||||||
@ -39,7 +48,9 @@ _read_cr3:
|
|||||||
mov eax, cr3;
|
mov eax, cr3;
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
;this function invalidates the page directory/table entry that
|
||||||
|
; would be used to access the memory address given in the parameter
|
||||||
|
;extern void invlpg(dword addr);
|
||||||
[global _invlpg]
|
[global _invlpg]
|
||||||
_invlpg:
|
_invlpg:
|
||||||
mov eax, [esp+4]
|
mov eax, [esp+4]
|
||||||
@ -47,6 +58,287 @@ _invlpg:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
;void writeCursorPosition(word pos)
|
||||||
|
;
|
||||||
|
[global _writeCursorPosition]
|
||||||
|
_writeCursorPosition:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
|
||||||
|
push eax
|
||||||
|
push ebx
|
||||||
|
push edx
|
||||||
|
|
||||||
|
mov eax, [ebp+8] ;cursor position in ax
|
||||||
|
|
||||||
|
mov bl, al
|
||||||
|
mov dx, 0x03D4
|
||||||
|
mov al, 0x0E
|
||||||
|
out dx, al
|
||||||
|
|
||||||
|
inc dx
|
||||||
|
mov al, ah
|
||||||
|
out dx, al
|
||||||
|
|
||||||
|
dec dx
|
||||||
|
mov al, 0x0F
|
||||||
|
out dx, al
|
||||||
|
|
||||||
|
inc dx
|
||||||
|
mov al, bl
|
||||||
|
out dx, al
|
||||||
|
|
||||||
|
pop edx
|
||||||
|
pop ebx
|
||||||
|
pop eax
|
||||||
|
pop ebp
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
;word getCursorPosition()
|
||||||
|
;
|
||||||
|
[global _getCursorPosition]
|
||||||
|
_getCursorPosition:
|
||||||
|
push ebx
|
||||||
|
push edx
|
||||||
|
|
||||||
|
xor eax, eax
|
||||||
|
mov dx, 0x03D4
|
||||||
|
mov al, 0x0E
|
||||||
|
out dx, al
|
||||||
|
|
||||||
|
inc dx
|
||||||
|
in al, dx
|
||||||
|
mov bl, al
|
||||||
|
|
||||||
|
dec dx
|
||||||
|
mov al, 0x0F
|
||||||
|
out dx, al
|
||||||
|
|
||||||
|
inc dx
|
||||||
|
in al, dx
|
||||||
|
mov ah, bl
|
||||||
|
|
||||||
|
pop edx
|
||||||
|
pop ebx
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
;void console_scroll()
|
||||||
|
;
|
||||||
|
[global _console_scroll]
|
||||||
|
_console_scroll:
|
||||||
|
pusha
|
||||||
|
mov esi, 0xc00b8000+160
|
||||||
|
mov edi, 0xc00b8000
|
||||||
|
mov ecx, 960 ;(2000-80)/2
|
||||||
|
rep movsd
|
||||||
|
mov ax, 0x0720
|
||||||
|
mov ecx, 80
|
||||||
|
rep stosw
|
||||||
|
popa
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
;void console_cls()
|
||||||
|
;
|
||||||
|
[global _console_cls]
|
||||||
|
_console_cls:
|
||||||
|
pusha
|
||||||
|
mov edi, 0xc00b8000
|
||||||
|
mov ax, 0x0720
|
||||||
|
mov ecx, 2000
|
||||||
|
rep stosw
|
||||||
|
push dword 0
|
||||||
|
call _writeCursorPosition
|
||||||
|
add esp, 4
|
||||||
|
popa
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
;int puts(char *str)
|
||||||
|
;
|
||||||
|
[global _puts]
|
||||||
|
_puts:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
push esi
|
||||||
|
push eax
|
||||||
|
mov esi, [ebp+8] ;esi = to string
|
||||||
|
puts_loop:
|
||||||
|
lodsb
|
||||||
|
cmp al, 0
|
||||||
|
jz puts_done
|
||||||
|
push eax
|
||||||
|
call _putc
|
||||||
|
add esp, 4
|
||||||
|
jmp puts_loop
|
||||||
|
|
||||||
|
puts_done:
|
||||||
|
pop eax
|
||||||
|
pop esi
|
||||||
|
pop ebp
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[global _putDecu]
|
||||||
|
_putDecu:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
sub esp, 24
|
||||||
|
mov DWORD [ebp-4], 1
|
||||||
|
mov BYTE [ebp-5], 0
|
||||||
|
L2:
|
||||||
|
mov edx, DWORD [ebp+8]
|
||||||
|
mov eax, -858993459
|
||||||
|
mul edx
|
||||||
|
mov eax, edx
|
||||||
|
shr eax, 3
|
||||||
|
cmp eax, DWORD [ebp-4]
|
||||||
|
jae L4
|
||||||
|
jmp L3
|
||||||
|
L4:
|
||||||
|
mov eax, DWORD [ebp-4]
|
||||||
|
mov edx, eax
|
||||||
|
sal edx, 2
|
||||||
|
add edx, eax
|
||||||
|
lea eax, [edx+edx]
|
||||||
|
mov DWORD [ebp-4], eax
|
||||||
|
jmp L2
|
||||||
|
L3:
|
||||||
|
nop
|
||||||
|
L5:
|
||||||
|
cmp DWORD [ebp-4], 1
|
||||||
|
ja L7
|
||||||
|
jmp L6
|
||||||
|
L7:
|
||||||
|
mov edx, DWORD [ebp+8]
|
||||||
|
mov eax, edx
|
||||||
|
mov edx, 0
|
||||||
|
div DWORD [ebp-4]
|
||||||
|
mov DWORD [ebp-12], eax
|
||||||
|
mov al, BYTE [ebp-12]
|
||||||
|
mov BYTE [ebp-5], al
|
||||||
|
mov eax, 0
|
||||||
|
mov al, BYTE [ebp-5]
|
||||||
|
imul eax, DWORD [ebp-4]
|
||||||
|
sub DWORD [ebp+8], eax
|
||||||
|
mov edx, DWORD [ebp-4]
|
||||||
|
mov eax, -858993459
|
||||||
|
mul edx
|
||||||
|
mov eax, edx
|
||||||
|
shr eax, 3
|
||||||
|
mov DWORD [ebp-4], eax
|
||||||
|
lea eax, [ebp-5]
|
||||||
|
add BYTE [eax], 48
|
||||||
|
sub esp, 12
|
||||||
|
mov eax, 0
|
||||||
|
mov al, BYTE [ebp-5]
|
||||||
|
push eax
|
||||||
|
call _putc
|
||||||
|
add esp, 16
|
||||||
|
jmp L5
|
||||||
|
L6:
|
||||||
|
sub esp, 12
|
||||||
|
mov al, BYTE [ebp+8]
|
||||||
|
add eax, 48
|
||||||
|
and eax, 255
|
||||||
|
push eax
|
||||||
|
call _putc
|
||||||
|
add esp, 16
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[global _putDec]
|
||||||
|
_putDec:
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
sub esp, 24
|
||||||
|
cmp DWORD [ebp+8], 0
|
||||||
|
jns L9
|
||||||
|
sub esp, 12
|
||||||
|
push 45
|
||||||
|
call _putc
|
||||||
|
add esp, 16
|
||||||
|
neg DWORD [ebp+8]
|
||||||
|
L9:
|
||||||
|
mov DWORD [ebp-4], 1
|
||||||
|
mov BYTE [ebp-5], 0
|
||||||
|
L10:
|
||||||
|
mov eax, DWORD [ebp+8]
|
||||||
|
cmp eax, DWORD [ebp-4]
|
||||||
|
jae L12
|
||||||
|
jmp L11
|
||||||
|
L12:
|
||||||
|
mov eax, DWORD [ebp-4]
|
||||||
|
mov edx, eax
|
||||||
|
sal edx, 2
|
||||||
|
add edx, eax
|
||||||
|
lea eax, [edx+edx]
|
||||||
|
mov DWORD [ebp-4], eax
|
||||||
|
jmp L10
|
||||||
|
L11:
|
||||||
|
mov edx, DWORD [ebp-4]
|
||||||
|
mov eax, -858993459
|
||||||
|
mul edx
|
||||||
|
mov eax, edx
|
||||||
|
shr eax, 3
|
||||||
|
mov DWORD [ebp-4], eax
|
||||||
|
L13:
|
||||||
|
cmp DWORD [ebp-4], 1
|
||||||
|
ja L15
|
||||||
|
jmp L14
|
||||||
|
L15:
|
||||||
|
mov edx, DWORD [ebp+8]
|
||||||
|
mov eax, edx
|
||||||
|
mov edx, 0
|
||||||
|
div DWORD [ebp-4]
|
||||||
|
mov DWORD [ebp-12], eax
|
||||||
|
mov al, BYTE [ebp-12]
|
||||||
|
mov BYTE [ebp-5], al
|
||||||
|
mov eax, 0
|
||||||
|
mov al, BYTE [ebp-5]
|
||||||
|
imul eax, DWORD [ebp-4]
|
||||||
|
sub DWORD [ebp+8], eax
|
||||||
|
mov edx, DWORD [ebp-4]
|
||||||
|
mov eax, -858993459
|
||||||
|
mul edx
|
||||||
|
mov eax, edx
|
||||||
|
shr eax, 3
|
||||||
|
mov DWORD [ebp-4], eax
|
||||||
|
lea eax, [ebp-5]
|
||||||
|
add BYTE [eax], 48
|
||||||
|
sub esp, 12
|
||||||
|
mov eax, 0
|
||||||
|
mov al, BYTE [ebp-5]
|
||||||
|
push eax
|
||||||
|
call _putc
|
||||||
|
add esp, 16
|
||||||
|
jmp L13
|
||||||
|
L14:
|
||||||
|
sub esp, 12
|
||||||
|
mov al, BYTE [ebp+8]
|
||||||
|
add eax, 48
|
||||||
|
and eax, 255
|
||||||
|
push eax
|
||||||
|
call _putc
|
||||||
|
add esp, 16
|
||||||
|
leave
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
echo Backing up to .\Backup\%1
|
echo Backing up to .\Backup\%1
|
||||||
|
|
||||||
mkdir .\Backup\%1
|
mkdir .\Backup\%1
|
||||||
mkdir .\Backup\%1\lib
|
|
||||||
|
|
||||||
copy *.h .\Backup\%1
|
copy *.h .\Backup\%1
|
||||||
copy *.c .\Backup\%1
|
copy *.c .\Backup\%1
|
||||||
@ -11,9 +10,3 @@ copy *.asm .\Backup\%1
|
|||||||
copy *.ld .\Backup\%1
|
copy *.ld .\Backup\%1
|
||||||
copy *.bat .\Backup\%1
|
copy *.bat .\Backup\%1
|
||||||
|
|
||||||
copy .\lib\*.h .\Backup\%1\lib
|
|
||||||
copy .\lib\*.c .\Backup\%1\lib
|
|
||||||
copy .\lib\*.inc .\Backup\%1\lib
|
|
||||||
copy .\lib\*.asm .\Backup\%1\lib
|
|
||||||
copy .\lib\*.ld .\Backup\%1\lib
|
|
||||||
copy .\lib\*.bat .\Backup\%1\lib
|
|
||||||
|
45
kernel.c
45
kernel.c
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include "k_defines.h" //#DEFINE's for kernel
|
#include "k_defines.h" //#DEFINE's for kernel
|
||||||
|
|
||||||
#include "lib/io.h" //library input/output functions
|
|
||||||
|
|
||||||
#include "functions.h" //general functions
|
#include "functions.h" //general functions
|
||||||
#include "video.h" //video functions
|
#include "video.h" //video functions
|
||||||
@ -16,14 +15,25 @@
|
|||||||
#include "mouse.h" //generic ps/2 mouse driver & functions
|
#include "mouse.h" //generic ps/2 mouse driver & functions
|
||||||
#include "fdc.h" //Floppy Disk Controller functions
|
#include "fdc.h" //Floppy Disk Controller functions
|
||||||
#include "stdfont.h" //Standard font bitmask array
|
#include "stdfont.h" //Standard font bitmask array
|
||||||
|
#include "kio.h"
|
||||||
|
|
||||||
void isr(dword num);
|
void isr(dword num);
|
||||||
void k_init();
|
void k_init();
|
||||||
|
|
||||||
|
/* These functions are defined in asmfuncs.asm */
|
||||||
extern dword write_cr0(dword cr0);
|
extern dword write_cr0(dword cr0);
|
||||||
extern dword read_cr0();
|
extern dword read_cr0();
|
||||||
extern dword write_cr3(dword cr3);
|
extern dword write_cr3(dword cr3);
|
||||||
extern dword read_cr3();
|
extern dword read_cr3();
|
||||||
|
extern void writeCursorPosition(dword pos);
|
||||||
|
extern dword getCursorPosition();
|
||||||
|
extern void console_scroll();
|
||||||
|
extern void console_cls();
|
||||||
|
extern int puts(char *str);
|
||||||
|
extern int putDec(int number);
|
||||||
|
extern int putDecu(dword number);
|
||||||
|
|
||||||
|
#include "kio.c"
|
||||||
#include "fdc.c"
|
#include "fdc.c"
|
||||||
#include "mouse.c"
|
#include "mouse.c"
|
||||||
#include "keyboard.c"
|
#include "keyboard.c"
|
||||||
@ -33,7 +43,6 @@ extern dword read_cr3();
|
|||||||
#include "video.c"
|
#include "video.c"
|
||||||
|
|
||||||
dword timer = 0;
|
dword timer = 0;
|
||||||
dword callnum = 0;
|
|
||||||
|
|
||||||
//Main kernel initialization method
|
//Main kernel initialization method
|
||||||
void k_init()
|
void k_init()
|
||||||
@ -60,18 +69,42 @@ void k_init()
|
|||||||
{
|
{
|
||||||
dword p;
|
dword p;
|
||||||
for (p = 0; p < video_mode.XResolution*video_mode.YResolution; p++)
|
for (p = 0; p < video_mode.XResolution*video_mode.YResolution; p++)
|
||||||
video_psetp(p, 0x00000088);
|
video_psetp(p, 0x00000055);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dword callnum = 0;
|
||||||
|
dword fa = 0;
|
||||||
|
dword la;
|
||||||
|
dword addr;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
la = addr;
|
||||||
|
addr = (dword)mm_palloc();
|
||||||
|
if (fa == 0)
|
||||||
|
fa = addr;
|
||||||
|
// printf("addr = 0x%x\tcallnum = %u\tfree pages = %u\n", addr, callnum, mm_freemem()>>12);
|
||||||
|
if (!addr)
|
||||||
|
break;
|
||||||
|
callnum++;
|
||||||
|
}
|
||||||
|
printf("#calls = %u\t", callnum);
|
||||||
|
printf("mm_freemem() = %d (0x%x, %x)\n", mm_freemem(), mm_freemem(), mm_freemem());
|
||||||
|
|
||||||
|
callnum = 0;
|
||||||
|
addr = fa;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
dword addr = (dword)mm_palloc();
|
mm_pfree(addr);
|
||||||
|
addr += 4096;
|
||||||
callnum++;
|
callnum++;
|
||||||
printf("addr = 0x%x\tcallnum = %u\tfree pages = %u\n", addr, callnum, mm_freemem()>>12);
|
if (addr > la)
|
||||||
if (!addr)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("#calls = %u\t", callnum);
|
||||||
|
printf("mm_freemem() = %d (0x%x, %x)\n", mm_freemem(), mm_freemem(), mm_freemem());
|
||||||
|
|
||||||
dword key = 0;
|
dword key = 0;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
117
kio.c
Normal file
117
kio.c
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
//kio.c
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Created: 12/25/03
|
||||||
|
// Modified: 12/25/03
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void printf(char *fmt, ...)
|
||||||
|
{
|
||||||
|
dword *params = ((dword *)(&fmt)) + 1; //points to the first paramater
|
||||||
|
int i;
|
||||||
|
int special = 0;
|
||||||
|
for (i = 0; ; i++)
|
||||||
|
{
|
||||||
|
if (special)
|
||||||
|
{
|
||||||
|
special = 0;
|
||||||
|
switch (fmt[i])
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return;
|
||||||
|
case '%':
|
||||||
|
putc('%');
|
||||||
|
break;
|
||||||
|
case 's': case 'S':
|
||||||
|
puts((char *)*params);
|
||||||
|
params++;
|
||||||
|
break;
|
||||||
|
case 'c': case 'C':
|
||||||
|
putc(*params);
|
||||||
|
params++;
|
||||||
|
break;
|
||||||
|
case 'd': case 'D':
|
||||||
|
putDec(*params);
|
||||||
|
params++;
|
||||||
|
break;
|
||||||
|
case 'u': case 'U':
|
||||||
|
putDecu(*params);
|
||||||
|
params++;
|
||||||
|
break;
|
||||||
|
case 'x': case 'X':
|
||||||
|
putHex(*params);
|
||||||
|
params++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (fmt[i])
|
||||||
|
{
|
||||||
|
case '%':
|
||||||
|
special = 1;
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
putc(fmt[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void putc(dword chr)
|
||||||
|
{
|
||||||
|
char charac = (char)chr;
|
||||||
|
word *vidmem = (word *)0xC00B8000;
|
||||||
|
if (charac == '\n')
|
||||||
|
{
|
||||||
|
if (cursorPosition % 80)
|
||||||
|
cursorPosition = cursorPosition + 80 - (cursorPosition % 80);
|
||||||
|
else
|
||||||
|
cursorPosition += 80;
|
||||||
|
}
|
||||||
|
else if (charac == '\t')
|
||||||
|
{
|
||||||
|
if (cursorPosition % 8)
|
||||||
|
cursorPosition = cursorPosition + 8 - (cursorPosition % 8);
|
||||||
|
else
|
||||||
|
cursorPosition += 8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vidmem[cursorPosition] = charac | 0x0700;
|
||||||
|
cursorPosition++;
|
||||||
|
}
|
||||||
|
if (cursorPosition >= 2000)
|
||||||
|
{
|
||||||
|
console_scroll();
|
||||||
|
cursorPosition = 2000-80;
|
||||||
|
}
|
||||||
|
writeCursorPosition(cursorPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int putHex(dword number)
|
||||||
|
{
|
||||||
|
int hitNum = 0;
|
||||||
|
int i;
|
||||||
|
for (i = 7; i >= 0; i--)
|
||||||
|
{
|
||||||
|
dword val = (number >> (i*4)) & 0xF;
|
||||||
|
if ((val != 0) || (i == 0))
|
||||||
|
hitNum = 1;
|
||||||
|
if (hitNum)
|
||||||
|
{
|
||||||
|
val = val + '0';
|
||||||
|
if (val > '9')
|
||||||
|
val = val + ('A' - '9' - 1);
|
||||||
|
putc(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
15
kio.h
Normal file
15
kio.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
//kio.h
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Created: 12/25/03
|
||||||
|
// Modified: 12/25/03
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void printf(char *fmt, ...);
|
||||||
|
void putc(dword chr);
|
||||||
|
int putHex(dword number);
|
||||||
|
|
||||||
|
|
||||||
|
dword cursorPosition = 0; //Caches the current cursor position
|
||||||
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
|||||||
del hlibc.a
|
|
||||||
ar -r hlibc.a *.o
|
|
@ -1 +0,0 @@
|
|||||||
gcc -ffreestanding -fno-builtin -c *.c
|
|
@ -1,2 +0,0 @@
|
|||||||
nasmw -f aout -l io.lst io.asm -o io_a.o
|
|
||||||
nasmw -f aout -l misc.lst misc.asm -o misc.o
|
|
@ -1,7 +0,0 @@
|
|||||||
|
|
||||||
typedef unsigned int dword;
|
|
||||||
typedef unsigned short word;
|
|
||||||
typedef unsigned char byte;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
532
lib/io.asm
532
lib/io.asm
@ -1,532 +0,0 @@
|
|||||||
|
|
||||||
%macro jzfar 1
|
|
||||||
jnz %%skip
|
|
||||||
jmp %1
|
|
||||||
%%skip:
|
|
||||||
|
|
||||||
%endmacro
|
|
||||||
|
|
||||||
[global _writeCursorPosition]
|
|
||||||
[global _getCursorPosition]
|
|
||||||
[global _putc]
|
|
||||||
[global _puts]
|
|
||||||
[global _printf]
|
|
||||||
[global _console_scroll]
|
|
||||||
[global _console_cls]
|
|
||||||
[global _putHex]
|
|
||||||
[global _putDec]
|
|
||||||
[global _putDecu]
|
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
;void writeCursorPosition(word pos)
|
|
||||||
;
|
|
||||||
_writeCursorPosition:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
|
|
||||||
push eax
|
|
||||||
push ebx
|
|
||||||
push edx
|
|
||||||
|
|
||||||
mov eax, [ebp+8] ;cursor position in ax
|
|
||||||
|
|
||||||
mov bl, al
|
|
||||||
mov dx, 0x03D4
|
|
||||||
mov al, 0x0E
|
|
||||||
out dx, al
|
|
||||||
|
|
||||||
inc dx
|
|
||||||
mov al, ah
|
|
||||||
out dx, al
|
|
||||||
|
|
||||||
dec dx
|
|
||||||
mov al, 0x0F
|
|
||||||
out dx, al
|
|
||||||
|
|
||||||
inc dx
|
|
||||||
mov al, bl
|
|
||||||
out dx, al
|
|
||||||
|
|
||||||
pop edx
|
|
||||||
pop ebx
|
|
||||||
pop eax
|
|
||||||
pop ebp
|
|
||||||
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
;word getCursorPosition()
|
|
||||||
;
|
|
||||||
_getCursorPosition:
|
|
||||||
push ebx
|
|
||||||
push edx
|
|
||||||
|
|
||||||
xor eax, eax
|
|
||||||
mov dx, 0x03D4
|
|
||||||
mov al, 0x0E
|
|
||||||
out dx, al
|
|
||||||
|
|
||||||
inc dx
|
|
||||||
in al, dx
|
|
||||||
mov bl, al
|
|
||||||
|
|
||||||
dec dx
|
|
||||||
mov al, 0x0F
|
|
||||||
out dx, al
|
|
||||||
|
|
||||||
inc dx
|
|
||||||
in al, dx
|
|
||||||
mov ah, bl
|
|
||||||
|
|
||||||
pop edx
|
|
||||||
pop ebx
|
|
||||||
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
;int putc(int chr)
|
|
||||||
;
|
|
||||||
_putc:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
push ebx
|
|
||||||
push ecx
|
|
||||||
push edx
|
|
||||||
|
|
||||||
call _getCursorPosition
|
|
||||||
mov ebx, eax
|
|
||||||
mov ecx, ebx
|
|
||||||
|
|
||||||
mov eax, [ebp+8] ;al=character
|
|
||||||
cmp al, 10 ;newline
|
|
||||||
jz putc_newline
|
|
||||||
cmp al, 9 ;tab
|
|
||||||
jz putc_tab
|
|
||||||
|
|
||||||
shl ebx, 1
|
|
||||||
add ebx, 0xc00b8000
|
|
||||||
mov ah, 0x07
|
|
||||||
mov [ebx], ax
|
|
||||||
mov eax, ecx
|
|
||||||
inc eax
|
|
||||||
cmp eax, 2000
|
|
||||||
jnz putc_writeit2
|
|
||||||
call _console_scroll
|
|
||||||
mov eax, 2000-80
|
|
||||||
putc_writeit2:
|
|
||||||
push eax
|
|
||||||
call _writeCursorPosition
|
|
||||||
add esp, 4
|
|
||||||
jmp putc_done
|
|
||||||
|
|
||||||
putc_newline:
|
|
||||||
mov eax, ebx ;eax = cursor position
|
|
||||||
mov ebx, 80
|
|
||||||
xor edx, edx
|
|
||||||
div bx ;ax=dx:ax/bx, dx=remainder
|
|
||||||
mov bx, 80
|
|
||||||
sub bx, dx
|
|
||||||
mov eax, ecx
|
|
||||||
add eax, ebx ;eax = new cursor position
|
|
||||||
cmp eax, 2000
|
|
||||||
jnz putc_newline_writeit2
|
|
||||||
call _console_scroll
|
|
||||||
mov eax, 2000-80 ;beginning of last row
|
|
||||||
putc_newline_writeit2:
|
|
||||||
push eax
|
|
||||||
call _writeCursorPosition
|
|
||||||
add esp, 4
|
|
||||||
jmp putc_done
|
|
||||||
|
|
||||||
putc_tab:
|
|
||||||
mov eax, ebx ;eax = cursor position
|
|
||||||
mov ebx, 8
|
|
||||||
div bl ;al=ax/bl, ah=remainder
|
|
||||||
xor edx, edx
|
|
||||||
mov dl, ah
|
|
||||||
mov bx, 8
|
|
||||||
sub bx, dx
|
|
||||||
mov eax, ecx
|
|
||||||
add eax, ebx ;eax = new cursor position
|
|
||||||
cmp eax, 2000
|
|
||||||
jnz putc_tab_writeit2
|
|
||||||
call _console_scroll
|
|
||||||
mov eax, 2000-80 ;beginning of last row
|
|
||||||
putc_tab_writeit2:
|
|
||||||
push eax
|
|
||||||
call _writeCursorPosition
|
|
||||||
add esp, 4
|
|
||||||
|
|
||||||
putc_done:
|
|
||||||
pop edx
|
|
||||||
pop ecx
|
|
||||||
pop ebx
|
|
||||||
pop ebp
|
|
||||||
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
;void printf(char *fmt, ... )
|
|
||||||
;
|
|
||||||
_printf:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
pusha
|
|
||||||
mov ebx, [ebp+8] ;ebx = position in format string
|
|
||||||
mov esi, ebp
|
|
||||||
add esi, 12 ;esi = to next variable arg
|
|
||||||
xor ecx, ecx ;ecx used if we encounter a '%'
|
|
||||||
printf_loop:
|
|
||||||
mov al, [ebx]
|
|
||||||
inc ebx
|
|
||||||
cmp al, 0
|
|
||||||
jzfar printf_done
|
|
||||||
cmp ecx, 1
|
|
||||||
jz printf_special
|
|
||||||
cmp al, '%'
|
|
||||||
jzfar printf_percent
|
|
||||||
|
|
||||||
push eax
|
|
||||||
call _putc
|
|
||||||
add esp, 4
|
|
||||||
jmp printf_loop
|
|
||||||
|
|
||||||
printf_special:
|
|
||||||
xor ecx, ecx
|
|
||||||
cmp al, 'd'
|
|
||||||
jz printf_decimal
|
|
||||||
cmp al, 'u'
|
|
||||||
jz printf_decimalu
|
|
||||||
cmp al, 'x'
|
|
||||||
jz printf_hex
|
|
||||||
cmp al, '%'
|
|
||||||
jz printf_ppercent
|
|
||||||
cmp al, 's'
|
|
||||||
jz printf_string
|
|
||||||
cmp al, 'c'
|
|
||||||
jz printf_char
|
|
||||||
jmp printf_special_done
|
|
||||||
|
|
||||||
printf_decimal:
|
|
||||||
mov eax, [esi]
|
|
||||||
push eax
|
|
||||||
call _putDec
|
|
||||||
add esp, 4
|
|
||||||
jmp printf_special_done
|
|
||||||
|
|
||||||
printf_decimalu:
|
|
||||||
mov eax, [esi]
|
|
||||||
push eax
|
|
||||||
call _putDecu
|
|
||||||
add esp, 4
|
|
||||||
jmp printf_special_done
|
|
||||||
|
|
||||||
printf_hex:
|
|
||||||
mov eax, [esi]
|
|
||||||
push eax
|
|
||||||
call _putHex
|
|
||||||
add esp, 4
|
|
||||||
jmp printf_special_done
|
|
||||||
|
|
||||||
printf_ppercent:
|
|
||||||
push eax
|
|
||||||
call _putc
|
|
||||||
add esp, 4
|
|
||||||
jmp printf_special_done
|
|
||||||
|
|
||||||
printf_string:
|
|
||||||
mov eax, [esi]
|
|
||||||
push eax
|
|
||||||
call _puts
|
|
||||||
add esp, 4
|
|
||||||
jmp printf_special_done
|
|
||||||
|
|
||||||
printf_char:
|
|
||||||
mov eax, [esi]
|
|
||||||
push eax
|
|
||||||
call _putc
|
|
||||||
add esp, 4
|
|
||||||
jmp printf_special_done
|
|
||||||
|
|
||||||
printf_special_done
|
|
||||||
add esi, 4 ;point to next extra argument
|
|
||||||
jmp printf_loop
|
|
||||||
|
|
||||||
printf_percent:
|
|
||||||
mov ecx, 1
|
|
||||||
jmp printf_loop
|
|
||||||
|
|
||||||
|
|
||||||
printf_done:
|
|
||||||
popa
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
;void console_scroll()
|
|
||||||
;
|
|
||||||
_console_scroll:
|
|
||||||
pusha
|
|
||||||
mov esi, 0xc00b8000+160
|
|
||||||
mov edi, 0xc00b8000
|
|
||||||
mov ecx, 960 ;(2000-80)/2
|
|
||||||
console_scroll_loop:
|
|
||||||
lodsd
|
|
||||||
stosd
|
|
||||||
loop console_scroll_loop
|
|
||||||
mov ax, 0x0720
|
|
||||||
mov ecx, 80
|
|
||||||
console_scroll_loop2:
|
|
||||||
stosw
|
|
||||||
loop console_scroll_loop2
|
|
||||||
popa
|
|
||||||
ret
|
|
||||||
|
|
||||||
;
|
|
||||||
;void console_cls()
|
|
||||||
;
|
|
||||||
_console_cls:
|
|
||||||
pusha
|
|
||||||
mov edi, 0xc00b8000
|
|
||||||
mov ax, 0x0720
|
|
||||||
mov ecx, 2000
|
|
||||||
console_cls_loop:
|
|
||||||
stosw
|
|
||||||
loop console_cls_loop
|
|
||||||
push dword 0
|
|
||||||
call _writeCursorPosition
|
|
||||||
add esp, 4
|
|
||||||
popa
|
|
||||||
ret
|
|
||||||
|
|
||||||
;
|
|
||||||
;int putHex(dword number)
|
|
||||||
;
|
|
||||||
_putHex:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
pusha
|
|
||||||
mov eax, [ebp+8] ;eax = number to print
|
|
||||||
xor ebx, ebx ;we have not printed a character yet
|
|
||||||
mov ecx, 8 ;counter for number of characters
|
|
||||||
|
|
||||||
putHex_loop:
|
|
||||||
push eax
|
|
||||||
push ecx
|
|
||||||
|
|
||||||
dec ecx
|
|
||||||
shl ecx, 2 ;edx=counter*4 (amount to shift by)
|
|
||||||
shr eax, cl
|
|
||||||
and eax, 0x0F
|
|
||||||
cmp cl, 0
|
|
||||||
jz putHex_notzero ;if number is 0
|
|
||||||
cmp al, 0
|
|
||||||
jnz putHex_notzero
|
|
||||||
cmp bl, 0
|
|
||||||
jz putHex_loop_end
|
|
||||||
putHex_notzero:
|
|
||||||
mov bl, 1
|
|
||||||
add eax, '0'
|
|
||||||
cmp eax, '9'
|
|
||||||
jbe putHex_dontadjust
|
|
||||||
add eax, 'A'-'9'-1
|
|
||||||
putHex_dontadjust:
|
|
||||||
push eax
|
|
||||||
call _putc
|
|
||||||
add esp, 4
|
|
||||||
|
|
||||||
putHex_loop_end:
|
|
||||||
pop ecx
|
|
||||||
pop eax
|
|
||||||
loop putHex_loop
|
|
||||||
|
|
||||||
popa
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
;
|
|
||||||
;int puts(char *str)
|
|
||||||
;
|
|
||||||
_puts:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
push esi
|
|
||||||
push eax
|
|
||||||
mov esi, [ebp+8] ;esi = to string
|
|
||||||
puts_loop:
|
|
||||||
lodsb
|
|
||||||
cmp al, 0
|
|
||||||
jz puts_done
|
|
||||||
push eax
|
|
||||||
call _putc
|
|
||||||
add esp, 4
|
|
||||||
jmp puts_loop
|
|
||||||
|
|
||||||
puts_done:
|
|
||||||
pop eax
|
|
||||||
pop esi
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_putDecu:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
sub esp, 24
|
|
||||||
mov DWORD [ebp-4], 1
|
|
||||||
mov BYTE [ebp-5], 0
|
|
||||||
L2:
|
|
||||||
mov edx, DWORD [ebp+8]
|
|
||||||
mov eax, -858993459
|
|
||||||
mul edx
|
|
||||||
mov eax, edx
|
|
||||||
shr eax, 3
|
|
||||||
cmp eax, DWORD [ebp-4]
|
|
||||||
jae L4
|
|
||||||
jmp L3
|
|
||||||
L4:
|
|
||||||
mov eax, DWORD [ebp-4]
|
|
||||||
mov edx, eax
|
|
||||||
sal edx, 2
|
|
||||||
add edx, eax
|
|
||||||
lea eax, [edx+edx]
|
|
||||||
mov DWORD [ebp-4], eax
|
|
||||||
jmp L2
|
|
||||||
L3:
|
|
||||||
nop
|
|
||||||
L5:
|
|
||||||
cmp DWORD [ebp-4], 1
|
|
||||||
ja L7
|
|
||||||
jmp L6
|
|
||||||
L7:
|
|
||||||
mov edx, DWORD [ebp+8]
|
|
||||||
mov eax, edx
|
|
||||||
mov edx, 0
|
|
||||||
div DWORD [ebp-4]
|
|
||||||
mov DWORD [ebp-12], eax
|
|
||||||
mov al, BYTE [ebp-12]
|
|
||||||
mov BYTE [ebp-5], al
|
|
||||||
mov eax, 0
|
|
||||||
mov al, BYTE [ebp-5]
|
|
||||||
imul eax, DWORD [ebp-4]
|
|
||||||
sub DWORD [ebp+8], eax
|
|
||||||
mov edx, DWORD [ebp-4]
|
|
||||||
mov eax, -858993459
|
|
||||||
mul edx
|
|
||||||
mov eax, edx
|
|
||||||
shr eax, 3
|
|
||||||
mov DWORD [ebp-4], eax
|
|
||||||
lea eax, [ebp-5]
|
|
||||||
add BYTE [eax], 48
|
|
||||||
sub esp, 12
|
|
||||||
mov eax, 0
|
|
||||||
mov al, BYTE [ebp-5]
|
|
||||||
push eax
|
|
||||||
call _putc
|
|
||||||
add esp, 16
|
|
||||||
jmp L5
|
|
||||||
L6:
|
|
||||||
sub esp, 12
|
|
||||||
mov al, BYTE [ebp+8]
|
|
||||||
add eax, 48
|
|
||||||
and eax, 255
|
|
||||||
push eax
|
|
||||||
call _putc
|
|
||||||
add esp, 16
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_putDec:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
sub esp, 24
|
|
||||||
cmp DWORD [ebp+8], 0
|
|
||||||
jns L9
|
|
||||||
sub esp, 12
|
|
||||||
push 45
|
|
||||||
call _putc
|
|
||||||
add esp, 16
|
|
||||||
neg DWORD [ebp+8]
|
|
||||||
L9:
|
|
||||||
mov DWORD [ebp-4], 1
|
|
||||||
mov BYTE [ebp-5], 0
|
|
||||||
L10:
|
|
||||||
mov eax, DWORD [ebp+8]
|
|
||||||
cmp eax, DWORD [ebp-4]
|
|
||||||
jae L12
|
|
||||||
jmp L11
|
|
||||||
L12:
|
|
||||||
mov eax, DWORD [ebp-4]
|
|
||||||
mov edx, eax
|
|
||||||
sal edx, 2
|
|
||||||
add edx, eax
|
|
||||||
lea eax, [edx+edx]
|
|
||||||
mov DWORD [ebp-4], eax
|
|
||||||
jmp L10
|
|
||||||
L11:
|
|
||||||
mov edx, DWORD [ebp-4]
|
|
||||||
mov eax, -858993459
|
|
||||||
mul edx
|
|
||||||
mov eax, edx
|
|
||||||
shr eax, 3
|
|
||||||
mov DWORD [ebp-4], eax
|
|
||||||
L13:
|
|
||||||
cmp DWORD [ebp-4], 1
|
|
||||||
ja L15
|
|
||||||
jmp L14
|
|
||||||
L15:
|
|
||||||
mov edx, DWORD [ebp+8]
|
|
||||||
mov eax, edx
|
|
||||||
mov edx, 0
|
|
||||||
div DWORD [ebp-4]
|
|
||||||
mov DWORD [ebp-12], eax
|
|
||||||
mov al, BYTE [ebp-12]
|
|
||||||
mov BYTE [ebp-5], al
|
|
||||||
mov eax, 0
|
|
||||||
mov al, BYTE [ebp-5]
|
|
||||||
imul eax, DWORD [ebp-4]
|
|
||||||
sub DWORD [ebp+8], eax
|
|
||||||
mov edx, DWORD [ebp-4]
|
|
||||||
mov eax, -858993459
|
|
||||||
mul edx
|
|
||||||
mov eax, edx
|
|
||||||
shr eax, 3
|
|
||||||
mov DWORD [ebp-4], eax
|
|
||||||
lea eax, [ebp-5]
|
|
||||||
add BYTE [eax], 48
|
|
||||||
sub esp, 12
|
|
||||||
mov eax, 0
|
|
||||||
mov al, BYTE [ebp-5]
|
|
||||||
push eax
|
|
||||||
call _putc
|
|
||||||
add esp, 16
|
|
||||||
jmp L13
|
|
||||||
L14:
|
|
||||||
sub esp, 12
|
|
||||||
mov al, BYTE [ebp+8]
|
|
||||||
add eax, 48
|
|
||||||
and eax, 255
|
|
||||||
push eax
|
|
||||||
call _putc
|
|
||||||
add esp, 16
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
lib/io.h
18
lib/io.h
@ -1,18 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifndef __HIO_H__
|
|
||||||
#define __HIO_H__ __HIO_H__
|
|
||||||
|
|
||||||
void writeCursorPosition(dword pos);
|
|
||||||
dword getCursorPosition();
|
|
||||||
int putc(dword chr);
|
|
||||||
int printf(char *fmt, ...);
|
|
||||||
int puts(char *str);
|
|
||||||
int putDec(int number);
|
|
||||||
int putDecu(dword number);
|
|
||||||
int putHex(dword number);
|
|
||||||
void console_cls();
|
|
||||||
void console_scroll();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
25
lib/misc.asm
25
lib/misc.asm
@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
;void memcpy(dword src, dword dest, dword length)
|
|
||||||
[global _memcpy]
|
|
||||||
_memcpy:
|
|
||||||
push ebp
|
|
||||||
mov ebp, esp
|
|
||||||
push esi
|
|
||||||
push edi
|
|
||||||
push ecx
|
|
||||||
mov esi, [ebp+8]
|
|
||||||
mov edi, [ebp+12]
|
|
||||||
mov ecx, [ebp+16]
|
|
||||||
|
|
||||||
rep movsb
|
|
||||||
|
|
||||||
pop ecx
|
|
||||||
pop edi
|
|
||||||
pop esi
|
|
||||||
pop ebp
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
#ifndef __HMISC_H__
|
|
||||||
#define __HMISC_H__ __HMISC_H__
|
|
||||||
|
|
||||||
void memcpy(dword src, dword dest, dword length);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
2
link.bat
2
link.bat
@ -1 +1 @@
|
|||||||
ld -nodefaultlibs -nostdlib -T link.ld -o kernel.bin -Map .\lst\LDout.doc ks.o kernel.o asmfuncs.o .\lib\hlibc.a
|
ld -nodefaultlibs -nostdlib -T link.ld -o kernel.bin -Map .\lst\LDout.doc ks.o kernel.o asmfuncs.o
|
3
mm.c
3
mm.c
@ -77,11 +77,10 @@ void *mm_palloc()
|
|||||||
if (!(page_bitmap[bite] & (1 << bit))) //this bite/bit combination is available
|
if (!(page_bitmap[bite] & (1 << bit))) //this bite/bit combination is available
|
||||||
{
|
{
|
||||||
page_bitmap[bite] = page_bitmap[bite] | (1 << bit); //set page as used
|
page_bitmap[bite] = page_bitmap[bite] | (1 << bit); //set page as used
|
||||||
return (void *)((bite << 15) + (bit << 12));
|
return (void *)((bite << 15) | (bit << 12));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bite++;
|
|
||||||
}
|
}
|
||||||
return 0; //no free page
|
return 0; //no free page
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user