Loading kernel

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
exor
Posts:13
Joined:Tue Mar 23, 2010 11:01 am
Loading kernel

Post by exor » Mon Mar 29, 2010 9:27 pm

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 :)

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Re: Loading kernel

Post by Mike » Tue Mar 30, 2010 4:43 am

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.)
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

exor
Posts:13
Joined:Tue Mar 23, 2010 11:01 am

Re: Loading kernel

Post by exor » Tue Mar 30, 2010 10:14 am

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

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Loading kernel

Post by Andyhhp » Tue Mar 30, 2010 6:05 pm

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
Image

exor
Posts:13
Joined:Tue Mar 23, 2010 11:01 am

Re: Loading kernel

Post by exor » Tue Mar 30, 2010 10:14 pm

-.-
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

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Loading kernel

Post by Andyhhp » Tue Mar 30, 2010 10:15 pm

Does that mean you are attempting to run assembled programs which are giving warnings?
Image

exor
Posts:13
Joined:Tue Mar 23, 2010 11:01 am

Re: Loading kernel

Post by exor » Tue Mar 30, 2010 10:57 pm

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

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Loading kernel

Post by Andyhhp » Tue Mar 30, 2010 11:33 pm

Lol - I was just checking to make sure that you were paying due attention to all warnings
Image

Post Reply