Load kernel and call it

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
onlshk
Posts: 9
Joined: Wed Sep 24, 2014 2:42 am

Load kernel and call it

Post by onlshk »

Hello,

I loaded kernel.bin from disk with ext2 with:

Code: Select all

	mov bx, buffer
		mov byte [DAP.count],   0x12
		mov word [DAP.offset],  0x10000
		mov word [DAP.segment], 0x0
		mov dword [DAP.lba], esi

		xor esi, esi
		xor eax, eax

		mov si, DAP		 
		mov ah, 0x42		
		mov dl, 0x80		
		int 0x13
My kernel.bin is simple:

Code: Select all

void kmain(){
  unsigned char *vidmem = (unsigned char*) 0x00B8000;
  *vidmem++ = 'K';
}
Now i'm jumping to protected mode and trying to call

Code: Select all

kmain
from there with:

Code: Select all

call 0x10000
After this virtual machine crashes with:

Code: Select all

qemu: fatal: Trying to execute code outside RAM or ROM at 0x00000000000a0000

EAX=00000000 EBX=0000fcd5 ECX=00000007 EDX=00000080
ESI=00007e97 EDI=00000000 EBP=00007bf8 ESP=00007bf8
EIP=0009ffba EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     00007eae 0000001f
IDT=     00000000 000003ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=00000004 CCO=ADDB    
EFER=0000000000000000
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=00000000000000000000000000000000 XMM01=00000000000000000000000000000000
XMM02=00000000000000000000000000000000 XMM03=00000000000000000000000000000000
XMM04=00000000000000000000000000000000 XMM05=00000000000000000000000000000000
XMM06=00000000000000000000000000000000 XMM07=00000000000000000000000000000000
Aborted (core dumped)
Octocontrabass
Member
Member
Posts: 5590
Joined: Mon Mar 25, 2013 7:01 pm

Re: Load kernel and call it

Post by Octocontrabass »

onlshk wrote:

Code: Select all

		mov word [DAP.offset],  0x10000
Don't ignore compiler/assembler warnings.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Load kernel and call it

Post by iansjack »

Have you implemented exception handlers?
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

Re: Load kernel and call it

Post by Bender »

Do you switch (is there a better term for that?) to a 32 bit code segment before performing the jump?
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
onlshk
Posts: 9
Joined: Wed Sep 24, 2014 2:42 am

Re: Load kernel and call it

Post by onlshk »

Have you implemented exception handlers?
Are you about disk reading exceptions? Yes, i have it but reading is successful.
Do you switch (is there a better term for that?) to a 32 bit code segment before performing the jump?
Yes first of all i jumped to protected mode and there i'm executing call.
Don't ignore compiler/assembler warnings.
ah, yes, 65536... But how can i read from there if i want to load my code to 0x10000? I already did it and it works, but i read it from floppy disk and didn't use LBA, there was just ex and bx with 0x1000 and 0x0, but how to load it with LBA...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Load kernel and call it

Post by Combuster »

ah, yes, 65536... But how can i read from there if i want to load my code to 0x10000?
Real Mode, and not using "word" when you mean "dword".

Also, get bochs and try stepping through your code. Instruction by instruction. Check for each of them if it does what you think it does, and if it doesn't, why it doesn't. There are more than a dozen things that could go wrong and it's very likely more than one thing did go wrong. But since the cause is probably going to be very obvious with this simple practice, it's better if you get the hands-on experience to do it yourself.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
onlshk
Posts: 9
Joined: Wed Sep 24, 2014 2:42 am

Re: Load kernel and call it

Post by onlshk »

it's better if you get the hands-on experience to do it yourself
Yes, it is the best advice.

Found a problem, loaded kernel with wrong DAP, now is all right. Thank you all.
Post Reply