Page 1 of 1
Bootloader freezing
Posted: Mon Mar 26, 2012 9:36 am
by sunjerry
Hello!
I am working on an os
The os freezes after running finished the bootloader.
Any idea why?
Code: Select all
;==========================================
; nasmw boot.asm -o boot.bin
; partcopy boot.bin 0 200 -f0
[ORG 0x7c00] ; add to offsets
jmp start
%include "print.inc"
start: xor ax, ax ; make it zero
mov ds, ax ; DS=0
mov ss, ax ; stack starts at 0
mov sp, 0x9c00 ; 200h past code start
cli ; no interrupt
push ds ; save real mode
mov si, startmsg
call sprint
mov si, gdtmsg
call sprint
lgdt [gdtinfo] ; load gdt register
mov eax, cr0 ; switch to pmode by
or al,1 ; set pmode bit
mov cr0, eax
mov bx, 0x08 ; select descriptor 1
mov ds, bx ; 8h = 1000b
and al,0xFE ; back to realmode
mov cr0, eax ; by toggling bit again
pop ds ; get back old segment
sti
mov si, donemsg
call sprint
jmp 08h:kernelstart
jmp $ ; loop forever
[BITS 32]
kernelstart:
mov ax, 10h ; save data segment
mov ds, ax ; setup data segment
mov ss, ax ; setup stack segment
mov esp, 090000h ; move the stack pointer to 090000h
jmp 08h:1000h ; jump to our kernel
gdtinfo:
dw gdt_end - gdt - 1 ;last byte in table
dd gdt ;start of table
gdt dd 0,0 ; entry 0 is always unused
flatdesc db 0xff, 0xff, 0, 0, 0, 10010010b, 11001111b, 0
startmsg db 'OS Startup.', 0
gdtmsg db 'Test', 0
donemsg db 'Done!', 0
gdt_end:
hlt
times 510-($-$$) db 0 ; fill sector w/ 0's
db 0x55 ; req'd by some BIOSes
db 0xAA
;==========================================
Re: Bootloader freezing
Posted: Mon Mar 26, 2012 10:39 am
by Snake
Probably because you have a bug somewhere. If it is your OS that's freezes why are you posing bootloader code? Have you tried another bootloader like grub? Does it still freeze? Why is your bootloader enabling interrupts?
Re: Bootloader freezing
Posted: Mon Mar 26, 2012 10:51 am
by Gigasoft
Do you think we're fools? No, you're not working on an OS.
I think someone ought to delete all these tutorials, as they only attract trolls. Anyone competent enough to construct an OS is also obviously more than able to figure out how to make a boot sector or how to download IA-32 developer's manuals from Intel.
Re: Bootloader freezing
Posted: Mon Mar 26, 2012 10:55 am
by Gigasoft
Snake wrote:Probably because you have a bug somewhere. If it is your OS that's freezes why are you posing bootloader code? Have you tried another bootloader like grub? Does it still freeze? Why is your bootloader enabling interrupts?
Hint: It's not actually a bootloader, just a random mishmash of lines pasted together from various OS development websites.
Re: Bootloader freezing
Posted: Mon Mar 26, 2012 11:11 am
by Combuster
Although I don't agree with Gigasoft's exact personal sentiments, the consequence of my personal conclusion is the same: you just failed to reach anywhere near the standard required to even post in this forum. Go read the forum rules to find out why (and to save yourself from getting harassed again).
Re: Bootloader freezing
Posted: Mon Mar 26, 2012 11:41 am
by Snake
Gigasoft wrote:Snake wrote:Probably because you have a bug somewhere. If it is your OS that's freezes why are you posing bootloader code? Have you tried another bootloader like grub? Does it still freeze? Why is your bootloader enabling interrupts?
Hint: It's not actually a bootloader, just a random mishmash of lines pasted together from various OS development websites.
Explains why it looks so strange.
Re: Bootloader freezing
Posted: Mon Mar 26, 2012 12:10 pm
by Gigasoft
Explains why it looks so strange.
- Consider the title: boot
loader freezing. Think about that word for a while. What could be the task of a boot
loader? What does this program not do?
- The code makes absolutely no sense. Set DS limit=4GB, jump to blank space at the end of the boot sector, unreachable instructions, spurious BITS 32 directive.
- For extra points, enter each line of the program into Google and have an epiphany.
Re: Bootloader freezing
Posted: Mon Mar 26, 2012 12:25 pm
by bluemoon
It is strange that writing these on same screen/page:
However, his method of flipping the protect mode bit does look like his own work, usually we'll just do
inc al / dec al instead of
and al, 0xFE
I'll give him benefit of doubt.
Anyway, the OP should read this before he engage further for osdev:
Required_Knowledge and
Beginner_Mistakes.
If you are determinate for the real tough (and real fun), show us the effort and we'll be happy to help you.
Re: Bootloader freezing
Posted: Mon Mar 26, 2012 1:34 pm
by DavidCooper
sunjerry wrote:Hello!
I am working on an os
The os freezes after running finished the bootloader.
Any idea why?
Yes, and I can't see what's stopping you from working it out for yourself.
Code: Select all
mov eax, cr0 ; switch to pmode by
or al,1 ; set pmode bit
mov cr0, eax
mov bx, 0x08 ; select descriptor 1
mov ds, bx ; 8h = 1000b
and al,0xFE ; back to realmode
mov cr0, eax ; by toggling bit again
What do you think you've achieved with all that?
Code: Select all
jmp 08h:kernelstart
jmp $ ; loop forever
[BITS 32]
kernelstart:
Does that make sense to you? What mode are you in?
What is that description doing there?
Code: Select all
mov ds, ax ; setup data segment
mov ss, ax ; setup stack segment
Have you got a descriptor for that in your GDT? (I assume you think you're in protected mode by this point, even though you only half entered it earlier and immediately left it again.)
Code: Select all
jmp 08h:1000h ; jump to our kernel
Jump to the kernel which you forgot to...
Re: Bootloader freezing
Posted: Mon Mar 26, 2012 1:47 pm
by Gigasoft
Source 1:
http://wiki.osdev.org/Babystep5
Source 2:
http://wiki.osdev.org/Babystep7
Source 3:
http://code.google.com/p/onyxkernel/wiki/FirstStep
Subtracting everything that comes from those pages, we end up with:
Code: Select all
mov si, startmsg
call sprint
mov si, gdtmsg
call sprint
mov si, donemsg
call sprint
startmsg db 'OS Startup.', 0
gdtmsg db 'Test', 0
donemsg db 'Done!', 0
Re: Bootloader freezing
Posted: Mon Mar 26, 2012 4:28 pm
by brain
Sunjerry, I think you need to understand the tutorials completely before you start to modify them or throw different tutorials together. imho its ok to learn from and adapt tutorials, this is how I learned initially too, however understanding what you're looking at is very much required to progress.
Re: Bootloader freezing
Posted: Sat Apr 07, 2012 5:44 pm
by VolTeK
I find myself repeating, i don't mind it though.
Learn what a debugger is
Learn how to use a debugger
Know what your goal is
Know what steps there are to getting to your goal
Know how to use (in this case) assembler to achieve that goal and each step
If any problems, use the debugger to find out which step freezes or causes a fault in the system
After this, no more questions should be asked. The rest are in the community wiki or in a tutorial you took, re-reading or finding another helps if the current one does not help.
Re: Bootloader freezing
Posted: Sun Apr 08, 2012 3:24 pm
by Combuster
If you look at the date, I think we can stop scaring him away now...
Re: Bootloader freezing
Posted: Sun Apr 08, 2012 3:41 pm
by VolTeK
My apologies, i had just realized how long ago the last post was