Page 1 of 2
initializing
Posted: Sat May 02, 2009 12:08 pm
by mobruan
Hi, im using the following bootstrap for initialization, but the computer resets...any ideias?
Code: Select all
org 0x07c00
jmp start
;**********
;gdt
;**********
bits 16
gdt_addr:
lim dw 23
base dd gdt
gdt:
null dd 0
null2 dd 0
c_limit dw 0xffff
c_base dw 0x0000
c_base2 db 0x00
c_type db 0x98
c_limit2 db 0xcf
c_base3 db 0x00
d_limit dw 0xffff
d_base dw 0x0000
d_base2 db 0x00
d_type db 0x92
d_limit2 db 0xcf
d_base3 db 0x00
end_gdt:
start:
;*********
;PE Mode
;*********
cli
lgdt [gdt_addr]
mov eax, cr0
or eax, 0x01
mov cr0, eax
jmp 0x08:code
;**********
;32-bit code
;**********
bits 32
code:
mov ax, word 0x10
mov ds, word ax
spin:
jmp spin
TIMES 510-($-$$) DB 0
DW 0xAA55
thanks,
Ângelo
Re: initializing
Posted: Sat May 02, 2009 12:27 pm
by 01000101
There are a few things you've left out.
You don't set up a stack, init your segment registers (before or after the jump to PMode), align the GDT, or ensure that the BIOS didn't start at 0x07C0:0x000 or 0x0:0x7C00 or any other variation.
I'd also imagine you may have some GDT descriptor issues as well.
Also, next time (or even this time), include a bit more information as it makes it a lot easier for us to help. Do you use BOCHS or any other emulator/virtualization with debugging features? If so, where does it fault, what's in the registers, examine these things and you may find your answer.
Re: initializing
Posted: Sat May 02, 2009 12:36 pm
by mobruan
Hi, im trying on my computer, i used it on bochs some time ago and i remember it worked.
I didnt get the bios address thing...
thanks
Re: initializing
Posted: Sat May 02, 2009 12:39 pm
by geppyfx
Code seems to work fine when I converted it to Fasm (bochs & code2duo).
But I dont fully understand why. First 4 bits of 0x98 constant means its code section for execution. Try chaging it to 9A: code + execute + read
And dont forget to display something on the screen so like "mov word [0b8000h], 0404h" so youknow it does(not) work.
Edit: a bird just told me that Read is required when you keep static data such as constants in the code section and reference them. I guess it would count when you have 4GB data & code starting at the same address.
Re: initializing
Posted: Sat May 02, 2009 12:41 pm
by Troy Martin
Is wrong. It should be:
Code: Select all
mov ax, 0x10
mov ds, ax
mov es, ax
And you should set up a stack using the same selector and a nice offset like 0x9000 or something.
EDIT: What assembler are you using? NASM?
Re: initializing
Posted: Sat May 02, 2009 12:44 pm
by geppyfx
Troy Martin wrote:
Is wrong. It should be:
Code: Select all
mov ax, 0x10
mov ds, ax
mov es, ax
None of his instructions uses ES.
Odd but even fasm allows "mov ds, word ax ". Well same sizes.
Re: initializing
Posted: Sat May 02, 2009 12:58 pm
by Troy Martin
ES should be initialized anyways.
It's probably the GDT. Try putting "align 4" before it.
Re: initializing
Posted: Sat May 02, 2009 1:16 pm
by mobruan
Hi, im using nasm. The code so far is like this.
Code: Select all
org 0x7c00
jmp start
;**********
;gdt
;**********
bits 16
align 4
gdt_addr:
lim dw 23
base dd gdt
gdt:
null dd 0
null2 dd 0
c_limit dw 0xffff
c_base dw 0x0000
c_base2 db 0x00
c_type db 0x9a
c_limit2 db 0xcf
c_base3 db 0x00
d_limit dw 0xffff
d_base dw 0x0000
d_base2 db 0x00
d_type db 0x92
d_limit2 db 0xcf
d_base3 db 0x00
end_gdt:
start:
;*********
;PE Mode
;*********
cli
lgdt [gdt_addr]
mov eax, cr0
or eax, 0x01
mov cr0, eax
jmp 0x08:code
;**********
;32-bit code
;**********
bits 32
code:
mov ax, word 0x10
mov ds, word ax
mov ss, word ax
mov es, word ax
spin:
jmp spin
TIMES 510-($-$$) DB 0
DW 0xAA55
Re: initializing
Posted: Sat May 02, 2009 1:36 pm
by mobruan
"Im going throw a walk, nothing one the dinner kind..." - Bad Religion
Re: initializing
Posted: Sat May 02, 2009 3:56 pm
by mobruan
Hi, i dont know what to do...any ideias? the code dont work...
Thanks,
Ângelo
Re: initializing
Posted: Sat May 02, 2009 4:32 pm
by kay10
Umm... How do you know that it doesn't work, if you don't get any output?
I compiled your code with NASM and tested it with bochs. For me, it works well.
At first I was confused because I don't saw any difference in bochs after running your code,
but then I recognized the infinite loop that you built in at the end of the code without printing anything on the screen.
Print something on the screen so you'll see that it should work.
Re: initializing
Posted: Sat May 02, 2009 4:32 pm
by geppyfx
I have compiled you last source with nasm and written it at the begining of the floppy (you can use usb stick). Works (along with the code in you first post). Image attached.
Show some proof that it doesn't work such as bochs debugging info.
Re: initializing
Posted: Sat May 02, 2009 5:04 pm
by mobruan
This is the problem...in bochs it work but on my machine it dont...im thinking if it not the a20 line...its possible?
i put this output(mov [0xb8000], word 0x0404) before the loop and it didnt appear on the screen before the computer reset...
Any ideias?
Thanks,
Ângelo
Re: initializing
Posted: Sat May 02, 2009 5:22 pm
by kay10
Ah, I hate it if emulators don't act like my real pc, feels like doing something for nothing.
I think you test your code with a floppy, don't you?
Maybe your bios requires a table (forgot the special name for it
) like the following one:
Code: Select all
jmp start
OSName db 'OS '
BytesPerSec dw 512
SecPerClus db 1
RsvdSecCnt dw 2
NumFATs db 2
RootEntCnt dw 224
TotSec dw 2880
MediaType db 0xF0
FATSize dw 9
SecPerTrack dw 18
NumHeads dw 2
HiddenSec dd 0
TotSec32 dd 0
DrvNum db 0x00
Reserved db 0
BootSig db 0x29
VolumeID dd 00000000h
VolumeLabel db 'NO NAME '
FileSysType db 'FAT12 '
Put it at the top of your bootstrap and look if anything has changed on your real pc.
I'm not sure whether (older?) bioses need this piece of code in a bootloader.
I don't think the A20 line is the cause of it because you never try to write something above the 1MB limit.
Re: initializing
Posted: Sat May 02, 2009 5:32 pm
by geppyfx
You may wanna disable
NMI(Non Masked Interrupts) for now
add this anywhere before entering Protected Mode
Code: Select all
in al, 70h
or al, 80h
out 70h, al
I personaly like having another "cli" right after you jumped to protected mode, very first instruction.