Import backup from 2003-09-01_2

This commit is contained in:
Josh Holtrop 2003-09-01 22:01:00 -04:00
parent dae5569216
commit 9076a15f08
6 changed files with 271 additions and 28 deletions

7
defines.h Normal file
View File

@ -0,0 +1,7 @@
typedef unsigned int dword;
typedef unsigned short word;
typedef unsigned char byte;

173
io.asm
View File

@ -14,6 +14,7 @@
[global _console_cls] [global _console_cls]
[global _putHex] [global _putHex]
[global _putDec] [global _putDec]
[global _putDecu]
; ;
@ -173,9 +174,9 @@ _printf:
push ebp push ebp
mov ebp, esp mov ebp, esp
pusha pusha
mov ebx, [ebp+8] ;ebx = ptr in format string mov ebx, [ebp+8] ;ebx = in format string
mov esi, ebp mov esi, ebp
add esi, 12 ;esi = ptr to next variable arg add esi, 12 ;esi = to next variable arg
xor ecx, ecx ;ecx used if we encounter a '%' xor ecx, ecx ;ecx used if we encounter a '%'
printf_loop: printf_loop:
mov al, [ebx] mov al, [ebx]
@ -196,6 +197,8 @@ printf_special:
xor ecx, ecx xor ecx, ecx
cmp al, 'd' cmp al, 'd'
jz printf_decimal jz printf_decimal
cmp al, 'u'
jz printf_decimalu
cmp al, 'x' cmp al, 'x'
jz printf_hex jz printf_hex
cmp al, '%' cmp al, '%'
@ -211,6 +214,13 @@ printf_decimal:
add esp, 4 add esp, 4
jmp printf_special_done jmp printf_special_done
printf_decimalu:
mov eax, [esi]
push eax
call _putDecu
add esp, 4
jmp printf_special_done
printf_hex: printf_hex:
mov eax, [esi] mov eax, [esi]
push eax push eax
@ -330,14 +340,6 @@ putHex_loop_end:
ret ret
;
;int putDec(dword number)
;
_putDec:
ret
; ;
;int puts(char *str) ;int puts(char *str)
; ;
@ -346,7 +348,7 @@ _puts:
mov ebp, esp mov ebp, esp
push esi push esi
push eax push eax
mov esi, [ebp+8] ;esi = ptr to string mov esi, [ebp+8] ;esi = to string
puts_loop: puts_loop:
lodsb lodsb
cmp al, 0 cmp al, 0
@ -367,3 +369,152 @@ puts_done:
_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

3
io.h
View File

@ -8,7 +8,8 @@ word getCursorPosition();
int putc(byte chr); int putc(byte chr);
int printf(char *fmt, ...); int printf(char *fmt, ...);
int puts(char *str); int puts(char *str);
int putDec(dword number); int putDec(int number);
int putDecu(dword number);
int putHex(dword number); int putHex(dword number);
void console_cls(); void console_cls();
void console_scroll(); void console_scroll();

View File

@ -29,8 +29,21 @@ void k_init()
outportb(0x40, 0x2e); //msb outportb(0x40, 0x2e); //msb
enable_ints(); enable_ints();
video_init((ModeInfoBlock *) 0x90306); video_init((ModeInfoBlock *) 0x90306);
console_cls();
mm_init(); mm_init();
console_cls();
printf("Memory available to OS: %d MB", mm_totalmem/0x100000);
pageblock *pb = first_pageblock;
for (;;)
{
if (pb->flags == MM_PB_NP)
break;
printf("\nBase: 0x%x; Limit: 0x%x; Flags: 0x%x, Link: 0x%x", pb->base, pb->length, pb->flags, pb->link);
pb = (pageblock *) pb->link;
}
int a;
for (a = -1024; a < 778; a += 98)
printf("\n%u\t%d\t%x", a, a, a);
//printf("\n%d\t%d", -123, -23456);
} }
void isr(dword num) void isr(dword num)

87
mm.c
View File

@ -5,7 +5,7 @@
pageblock *first_pageblock = (pageblock *) 0; pageblock *first_pageblock = (pageblock *) 0;
dword totalmem = 0; dword mm_totalmem = 0x100000; //assume 1mb
void mm_init() void mm_init()
{ {
@ -16,24 +16,89 @@ void mm_init()
{ {
if (maps[a].attributes == 1) // (1) mem free to OS if (maps[a].attributes == 1) // (1) mem free to OS
{ {
if ((maps[a].base.lowdword + maps[a].limit.lowdword) > (FREERAM_START+4096)) //goes past where we start freeram mm_totalmem += maps[a].limit.lowdword;
if ((maps[a].base.lowdword + maps[a].limit.lowdword) > (FREERAM_START+8192)) //goes past where we start freeram
{ {
if (first_pageblock == 0) //no pageblock page set up yet if (maps[a].base.lowdword < FREERAM_START)
{ {
if (maps[a].base.lowdword < (FREERAM_START+4096)) maps[a].limit.lowdword = maps[a].limit.lowdword - (FREERAM_START - maps[a].base.lowdword);
{ maps[a].base.lowdword = FREERAM_START; //block at least 4kb, starts >= FREERAM_START
first_pageblock = (pageblock *) FREERAM_START;
} }
if (first_pageblock == 0) //no pageblock page set up yet, so set it up here
{
first_pageblock = (pageblock *) maps[a].base.lowdword;
maps[a].base.lowdword += 4096;
maps[a].limit.lowdword -= 4096;
mm_init_pageblockpage(first_pageblock);
first_pageblock->base = maps[a].base.lowdword;
first_pageblock->length = maps[a].limit.lowdword / 4096;
first_pageblock->flags = MM_PB_AVAIL;
} }
else //first_pageblock already set up, add on segment
{
pageblock *pb = first_pageblock;
for (;;)
{
if (pb->flags == MM_PB_NP)
break;
else else
pb++;
}
pb->base = maps[a].base.lowdword;
pb->length = maps[a].limit.lowdword / 4096;
pb->flags = MM_PB_AVAIL;
}
}
}
}
if (first_pageblock == 0)
{ {
printf("ERROR! NO INITIAL PAGE BLOCK COULD BE CREATED.");
asm("cli");
asm("hlt");
} }
} }
totalmem += maps[a].limit.lowdword;
}
}
printf("Total memory available to OS: %x", totalmem);
} void mm_init_pageblockpage(pageblock *pbp)
{
pageblock *pb = pbp;
int a;
for (a=0; a<512; a++)
{
pb->base = 0;
pb->length = 0;
pb->flags = MM_PB_NP;
if (a<511)
pb->link = (dword)++pb + sizeof(pageblock);
else
pb->link = 0;
}
}
void *mm_palloc(dword numpages)
{
}
int mm_pfree(void *ptr)
{
}

14
mm.h
View File

@ -1,9 +1,5 @@
void mm_init();
typedef struct { typedef struct {
qword base; qword base;
qword limit; qword limit;
@ -19,6 +15,16 @@ typedef struct {
} __attribute__ ((packed)) pageblock; //16 byte pageblock entry - 512 entries = 1 page } __attribute__ ((packed)) pageblock; //16 byte pageblock entry - 512 entries = 1 page
void mm_init();
void mm_init_pageblockpage(pageblock *pbp);
void *mm_palloc(dword numpages);
int mm_pfree(void *ptr);
#define MM_PB_FLAGMASK 0x03 //00000011
#define MM_PB_NP 0x00 //00000000
#define MM_PB_AVAIL 0x01 //00000001
#define MM_PB_USED 0x02 //00000010