Page 1 of 1

I can't boot my C kernel

Posted: Fri Sep 20, 2002 4:48 pm
by Nils Schaetti
???

Hi, i am a newbie on OS development.
I can't boot my C kernel, i have find a bootsector on this forum (from frank):

[The Assembly Code]:
org 7c00h
jmp start

start:
mov [drive],dl
; Update the segment registers
; mov ax, cs ; Copy cs into ax
; mov ds, ax ; cs->ax->ds
; mov es, ax ; cs->ax->es
; try this instead:
xor ax,ax
mov ds,ax
; (codesegment is already loaded)
jmp Running
; This is where the boot program runs.
Running:

; Load the second stage loader.
reset:
mov ax, 0x00
mov dl, [drive]
int 13h
jc reset

read:
mov bx, 1000h
mov ah, 0x02
mov al, 5
mov ch, 0
mov cl, 2
mov dh, 0
mov dl, [drive]
int 13h
jc read

cli

lgdt[gdtr]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp dword codesel:pmode

; Start A20
; a20line is more than this see: ;http://www.mega-tokyo.com/os/os-faq-memory.html
; anyway, I don't know if a20 line is necessary....
; (I just folowed the steps :)))

; We are in protected mode here:
[bits 32]
pmode:
mov eax,datasel
mov ss,eax
mov ds,eax
mov es,eax
mov fs,eax
mov gs,eax

mov ax,0x10
mov ss,ax
mov esp,0xFFFF

mov dl,[drive]

jmp dword codesel:0x1000

; jmp 1000h:0000

; Global descriptor table
; this tells the comp where
; all the segments (now selectors) are
gdtr
dw gdt_end-1
dd gdt
gdt
nullsel equ $-gdt
gdt0
dd 0
dd 0

codesel equ $-gdt
dw 0ffffh
dw 0
db 0
db 09ah
db 0cfh
db 0h

datasel equ $-gdt
dw 0ffffh
dw 0h
db 0h
db 092h
db 0cfh
db 0

gdt_end

; This part makes sure the bootsector is 512 bytes.
drive db 0
times 510-($-$$) db 0
dw 0xAA55

[ And my kernel test code ]:
/* main.c: Nilix C Kernel */

/* Cette fonction affiche str ? la premi?re ligne de l'?cran */
void printk(char *str)
{
   char *video = (char *)0xB8000;
   while(*str!='\0')
   {
      *video=*str;
      video++;
      *video=0x57;
      video++;
      str++;
   }
}

asm("jmp start");

void start()
{

   printk("Kernel is speacking\n");

   while(1)
   {

   }

}

Unix Commands:
ls
bootsect.asm boot.bin main.c
gcc -c main.c -o main.o
ld -Ttext=0x1000 -o nilix main.o
objcopy -R .note -R .comment -S -O binary nilix nilix.bin
dd if=boot.bin of=/dev/fd0
dd if=nilix.bin seek=1 of=/dev/fd0

I test and compile my source on:
AMD Athlon XP 2100+ (SuSE Linux 8.0).
But my computer reboot

I aslo test on:
AMD K6-2 (SuSE Linux 7.3)
But my computer reboot again
??? ???

Please, helpl me

Re:I can't boot my C kernel

Posted: Fri Sep 20, 2002 5:23 pm
by Tom
hey, your using my code ;) :D:D ( can't help you now I'm just checking the posts )

Re:I can't boot my C kernel

Posted: Sat Sep 21, 2002 4:08 am
by Nils
Yes, sorry, it's juste for test.
I thing that the bootsector don't work.

Re:I can't boot my C kernel

Posted: Sat Sep 21, 2002 8:10 am
by _Tom
you can use my OS's code all you want

Re:I can't boot my C kernel

Posted: Sat Sep 21, 2002 11:20 am
by Slasher
hi, your code at
xor ax,ax
mov ds,ax
should be
mov ax,7c0h
mov ds,ax ;now ds*16 will be the same as 7c00h which is where bootsector is placed
also when loading your second stage loader, you nee to set ES reg(i think thats what you where trying to do but used DS instead) so either change the
xor ax,ax
mov ds,ax
to
xor ax,ax
mov es,ax
or use

mov ax,7c0h
mov ds,ax ;init ds to same value as cs
xor ax,ax
mov es,ax ; now es set to 0h

setting A20 line is necessary if your plan to use memory above 1mb(which i believe you do,if not why bother with Protected Mode ;D )

change lgdt[gdtr]
to lgdt [gdtr] (need space)

also how did you link the c kernel, you need to use a linker script with ld to get everything in the right place. a tip, if you are using a linker script specify your desired addresses in full eg if you want to load the kernel at 0000:1000 use .text 0x00001000 and not .text 0x1000

try these out first and see what happens

Re:I can't boot my C kernel

Posted: Sat Sep 21, 2002 5:50 pm
by Nilix
Ok, my C kernel boot. Thanks