After jumping to the 64 bit and jump to the C language kernel, I should prepare to jump to the 64 bit.
First of all, the output wasn’t satisfying. So I’ve made a plan for that improvement.
After then,
As you can see, that was changed.
And already fixed that miss typing SICCESS to SUCCESS on second.
But you know I’m so lazy for taking a new screenshot that was fixed.
So I’ll use the unfixed image.
I’ve read a lot of code for this.
First, I’ve fixed the 16bit bootloader assembly code for the 1~2 line output function.
Before the output function is:
push HELLO
push 0
push 0
call PRINT
add sp, 6
You cannot display the color on the output.
So, I’ve fixed that. Now it requires four parameters for output.
Currently, the output code is:
push HELLO
push 0x0B
push 30
push 1
call PRINT
add sp, 8
Also, I’ve edited internal of a function.
PRINT:
push bp,
mov bp, sp
push es
push si
push di
push ax
push cx
push dx
mov ax, 0xB800
mov es, ax
mov ax, word[bp + 4]
mov si, 160
mul si
mov di, ax
mov ax, word[bp + 6]
mov si, 2
mul si
add di, ax
mov si, word[bp+10]
mov bl, byte[bp+8]
.PRINTLOOP
mov cl, byte[si]
cmp cl,0
je .ENDPRINTLOOP
mov byte[es:di], cl
mov byte[es:di+1], bl
add si, 1
add di, 2
jmp .PRINTLOOP
Uh, Pretty long line.
I’ve changed this code to use attribute code on bl register.
And then I’ve edited assembly code using 32bit code entry point for printing 32-bit mode change success message on 3 lines.
No big change.
push (SUCCESS - $$ + 0x10000)
push 0x0A
push 4
push 60
call PRINT
add esp, 16
Simply, It has been added attribute code.
Also, I’ve edited the function partly as well.
PRINT:
push ebp
mov ebp, esp
push esi
push edi
push eax
push ecx
push edx
mov eax, dword [ebp + 12]
mov esi, 160
mul esi
mov edi, eax
mov eax, dword[ebp + 8]
mov esi, 2
mul esi
add edi, eax
mov bl, byte[ebp + 16]
mov esi, dword[ebp + 20]
.PRINTLOOP:
mov cl, byte[esi]
cmp cl,0
je PRINTEND
mov byte[edi + 0xB8000], cl
mov byte[edi + 0xB8000+1], bl
add esi,1
add edi,2
jmp .PRINTLOOP
It’s same that inserting value by ‘mov bl, byte[ebp+16]’ and then using that on output code.
And then I added a parameter in function PrintVideoMemory for using C Language.
The Implementation is:
void PrintVideoMemory(int x, int y, BYTE Attribute ,const char* _str)
{
CHARACTER_MEMORY* Address = ( CHARACTER_MEMORY* ) 0xB8000;
int i = 0;
Address+= ( y * 80 ) + x;
for ( i = 0; _str[i] != 0; i++)
{
Address[i].bCharactor = _str[i];
Address
[i].bAttribute = Attribute;
}
}
For my satisfaction, I’ve tried to change a few parts of codes even that hasn’t existed on the book.
The pretty output makes me happy.
Also, I added the code for checking memory and set by 0 in the area for 64-bit kernel memory.
BOOL Initalization64KernelMemoryArea()
{
DWORD* Address
= (DWORD*) 0x100000;
while((DWORD) Address
< 0x600000)
{
*Address
= 0x00;
if( *Address
!= 0 )
return FALSE;
Address
++;
}
return TRUE;
}
BOOL CheckMemorySize()
{
DWORD* Address
= (DWORD*) 0x100000;
while( (DWORD) Address
< 0x4000000 )
{
*Address
= 0x12345678;
if( *Address
!= 0x12345678)
return FALSE;
Address
+= (0x100000 / 4);
}
return TRUE;
}
These functions are used on the entry point for checking and printing messages.
I want to check this code working well. So I’ve changed command line in launch_qemu.sh.
Before change a commend is:
qemu-system-x86_64 -L . -m 64 -fda disk.img -localtime -M pc
If set up like that, Qemu allocates 64 MB memory by -m option.
As you can see, It’s working well.
So, Let me try to allow low memory to VM.
qemu-system-x86_64 -L . -m 32 -fda disk.img -localtime -M pc
I give 32 MB memory to VM by -m 32 option.
Oh yeah!
That’s what I wanna expect about it.
The left things used to turn on the paging, something ready for jumping to the 64 bit.
Also, I want to make the code much pretty. It looks like complex codes.