Page 1 of 1

Loading kernel

Posted: Mon Mar 29, 2010 9:27 pm
by exor
hi

i've a problem loading kernel image ...

this is kernel source:

Code: Select all

bits 32
org 0x100000

jmp kernel_main

%include "includes\stdio.inc"

%define TEXT_ATTRIBUTES 00011111b

shellWelcome db "Welcome!", 0
credits.msg db "OS", 0

%define TEXT_ATTRIBUTES 00011111b

kernel_main:

	mov	ax, DATA_DESC		; set data segments to data selector (0x10)
	mov	ds, ax
	mov	ss, ax
	mov	es, ax
	mov	esp, 90000h		; stack begins from 90000h

	mov dl, TEXT_ATTRIBUTES
	call clear_scrn32
	
	mov si, shellWelcome
	call puts32
	
	hlt
the problem is in mov si, shellWelcome

if i write mov al, [shellWelcome], using debugger al is set to ascii code of W.
using mov si, shellWelcome, si is set to a random value, as it was overwritten, and cpu triple faults getting a gdt segment access violation.

how can it be possible ?
is si register used by anyone in protected mode .. ?
trying the same code in stage2, it's worked, so i think it's the usual addressing problem ... -.-

i tried all, i've compared your kernel code and my, and it seems to be right

thanks :)

Re: Loading kernel

Posted: Tue Mar 30, 2010 4:43 am
by Mike
Hello,

mov si, shellWelcome would be correct. - si would be the address of shellWelcome. Make sure hardware interrupts are disabled (CLI) and that the address stored in SI is valid (It should be above your load address by a little bit.)

Re: Loading kernel

Posted: Tue Mar 30, 2010 10:14 am
by exor
using mov si, shellWelcome, si is set to a random value, as it was overwritten, and cpu triple faults getting a gdt segment access violation.
this is the problem ... si isnt set to 100003 i.e. , it is set to some random address as it's overwritten

Code: Select all

bits 32					; protected mode

Stage3:

;******************************************
; DATA_DESC => data descriptor
; CODE_DESC => code descriptor
;******************************************
	mov ax, DATA_DESC			; data descriptor
	mov ds, ax
	mov es, ax
	mov ss, ax
	mov esp, 0x90000

	mov ecx, dword [kernelfile.dim]
	mov esi, RMODE_KERNEL_ADDR
	mov edi, PMODE_KERNEL_ADDR
	.LOOOOP:
		xor ebx, ebx
		mov bl, [esi]
		mov byte [edi], bl
		inc edi
		inc esi
		dec ecx
		cmp ecx, 0
		jg .LOOOOP
	
	jmp CODE_DESC:PMODE_KERNEL_ADDR					; jmp to kernel
if can help, this is my stage3 into stage2 after setting of gdt and pmode bit...

here kernel code (as puts32 or putch32) works fine

Re: Loading kernel

Posted: Tue Mar 30, 2010 6:05 pm
by Andyhhp
two things to note:

1) si should not be 0x100003. Notice that you are including all of stdio.inc before declaring ShellWelcome.

2) if you are using esi in your puts32 function (which i believe you are) then you should be setting esi not si. with "mov si ...", it completely ignores anything in the top half of esi. If the top half is for any reason non-zero, then loading si will appear to be loading junk

~Andrew

Re: Loading kernel

Posted: Tue Mar 30, 2010 10:14 pm
by exor
-.-
tnx Andyhhp .... you've saved me again

talking about use of si, i've tried to write mov si, 0x100002, and nasm has wrote word data exceeds bounds ... so it cut address ...

tnx everyone :D

see you soon

Re: Loading kernel

Posted: Tue Mar 30, 2010 10:15 pm
by Andyhhp
Does that mean you are attempting to run assembled programs which are giving warnings?

Re: Loading kernel

Posted: Tue Mar 30, 2010 10:57 pm
by exor
no :S
it should have referenced to org address on making labels but nasm gave me no warnings :S

i don't know why ... if any, i would have correct them

if you want i write kernel code here in order to compile it XD

Re: Loading kernel

Posted: Tue Mar 30, 2010 11:33 pm
by Andyhhp
Lol - I was just checking to make sure that you were paying due attention to all warnings