Problems with the new bootloader

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
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Problems with the new bootloader

Post by Karlosoft »

Hi. I'm here with a new very very hidden error.
I wrote two bootloaders, one is sblold.bin, the newer sbl.bin. With the first all is perfect, with the other one, something doesn't work. To build a floppy and test what I'm saying, you have simply to run the auto.bat file.

So, where is the problem? I suppose it is here in the asm stub of the kernel. I should write that it crashes here, because the problem is surely before.

Code: Select all

[BITS 32]

global start
start:
jmp afterLabel
db "_sys_"
db "kernel",0

afterLabel:

cli
mov ax,0x10

mov ds,ax
mov es,ax
mov fs,ax
mov ss,ax
mov gs,ax
mov esp, 0x7ffff     ; This points the stack to our new stack area


    jmp stublet

; This part MUST be 4byte aligned, so we solve that issue using 'ALIGN 4'
ALIGN 4
mboot:
    
    dd mboot
    dd code
    dd bss
    dd end
    dd start

stublet:
extern start_ctors, end_ctors, start_dtors, end_dtors, _kernel



loader:
   ; Possibly set up a stack here: mov esp, stack   STACKSIZE
   push eax                        ; Multiboot magic number
   push ebx                        ; Multiboot info structure
 
static_ctors_loop:
   mov ebx, start_ctors
   jmp .test
 
.body:
   call [ebx]
   add ebx,4
 
.test:
   cmp ebx, end_ctors
   jb .body


   jmp short cr      ;I tried everything but it doesn't work

cr:
   call _kernel                       ; HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!

static_dtors_loop:
   mov ebx, start_dtors
   jmp .test
 
.body:
   call [ebx]
   add ebx,4
 
.test:
   cmp ebx, end_dtors
   jb .body
    jmp $
Yeah the problem is there, when I call the _kernel function. It's the call itself witch causes the triple fault (I think), because I even if I place an asm("htl") before everything other in the kernel function it doesn't work.

Code: Select all


[org 0x7c00]

[bits 16]

sti
cli

jmp l

l:


lgdt [gdtinfo]


mov eax,cr0
or eax,1
mov cr0,eax

;After it set registers and do a far jump to kernel. If data selector is 10h, code selector is 8 and kernel offset is 100000h do:

mov ax,0x10
mov ds,ax

mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax

jmp dword 0x8:0x100000

hlt

gdtinfo:
   dw gdt_end - gdt - 1   ;last byte in table
   dd gdt                 ;start of table
 
gdt         dd 0,0        ; entry 0 is always unused
; gdt code:	            ; code descriptor
	dw 0FFFFh           ; limit low
	dw 0                ; base low
	db 0                ; base middle
	db 10011010b        ; access
	db 11001111b        ; granularity
	db 0                ; base high

; gdt data:	            ; data descriptor
	dw 0FFFFh           ; limit low (Same as code)
	dw 0                ; base low
	db 0                ; base middle
	db 10010010b        ; access
	db 11001111b        ; granularity
	db 0                ; base high
gdt_end:
This is the stub of code launched by sbl bootloader use to enter in pmode and load a gdt.

All this code works when I load and lauch it from the old version of sbl but not with the newest.

SBL works in real mode with 32bit access data (unreal mode). For any question I'm here. Please help me. I'm getting crazy (more than much I am).
Attachments
sbl.zip
(20.03 KiB) Downloaded 41 times
User avatar
Muneer
Member
Member
Posts: 104
Joined: Tue Nov 02, 2010 2:05 am
Location: India

Re: Problems with the new bootloader

Post by Muneer »

Hello,



Dude, Had the same problem with me and took a whole night to figure out what the **** was going on for I saw No Fault with my code ( But That's What I Always Think when a bug appears)

The call to Kernal Triple Faults because the call cant find the GDT at the correct location.

The LGDT instruction uses the DS Register and the offset provided with LGDT(gdtinfo in this case).
And at the time of boot you cant rely on the value of DS.
So Put This Just Before Your LGDT

Code: Select all

Mov   Ax , 0        ;   Without Which You Can Only Dream Of Getting To Protected Mode
Mov   Ds , Ax
Just to know , how do you load your kernel at 100000h because I don't see your Bootloader loading the second sector ( or is that what the Auto.bat File does?, because I am not much of a sophomore in Debug utility in windows. Well Why cant you use PartCopy Its So simple to setup and dont have to worry about the lot of debug commands like yours ) and I cant See a boot-signature either.
Even the smallest person could change the course of the future - Lord Of The Rings.

In the end all that matters is what you have done - Alexander.

Even after a decade oh god those still gives me the shivers.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Problems with the new bootloader

Post by Karlosoft »

This is how SBL works ;)
no-name: The first sector of the floppy. It loads sbl.bin
sbl.bin: the second stage of the bootloader. It loads the files defined in bootconf.txt.
boot.bin: the protected mode jumper
kernel.bin my kernel image ;)

The piece of code I posted is of boot.bin so kernel.bin is already loaded.
Sorry your solution doesn't work :(

Ps. I know the boot signature is missing. This is because my computers (as many other) don't require it XD. However I'll add it for older BIOSes.

I loaded the kernel with my FAT12 driver ^_^
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: Problems with the new bootloader

Post by Karlosoft »

Solved. I just forgot to write a line of C++ code XD

Code: Select all

f->eof=0;
I'll post asap the new version ^_^
User avatar
Muneer
Member
Member
Posts: 104
Joined: Tue Nov 02, 2010 2:05 am
Location: India

Re: Problems with the new bootloader

Post by Muneer »

Karlosoft wrote:Solved. I just forgot to write a line of C++ code XD


Cheers
Even the smallest person could change the course of the future - Lord Of The Rings.

In the end all that matters is what you have done - Alexander.

Even after a decade oh god those still gives me the shivers.
Post Reply