Bootloader freezing

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
sunjerry
Posts: 1
Joined: Mon Mar 26, 2012 9:28 am

Bootloader freezing

Post 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
;==========================================
Snake
Posts: 19
Joined: Wed Mar 21, 2012 7:38 pm

Re: Bootloader freezing

Post 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?
Gigasoft
Member
Member
Posts: 871
Joined: Sat Nov 21, 2009 5:11 pm

Re: Bootloader freezing

Post 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.
Gigasoft
Member
Member
Posts: 871
Joined: Sat Nov 21, 2009 5:11 pm

Re: Bootloader freezing

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bootloader freezing

Post 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).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Snake
Posts: 19
Joined: Wed Mar 21, 2012 7:38 pm

Re: Bootloader freezing

Post 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.
Gigasoft
Member
Member
Posts: 871
Joined: Sat Nov 21, 2009 5:11 pm

Re: Bootloader freezing

Post by Gigasoft »

Explains why it looks so strange.
- Consider the title: bootloader freezing. Think about that word for a while. What could be the task of a bootloader? 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Bootloader freezing

Post by bluemoon »

It is strange that writing these on same screen/page:

Code: Select all

mov  bx, 0x08
mov ax, 10h
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.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Bootloader freezing

Post 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?

Code: Select all

	mov ax, 10h             ; save data segment
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...
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Gigasoft
Member
Member
Posts: 871
Joined: Sat Nov 21, 2009 5:11 pm

Re: Bootloader freezing

Post 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
User avatar
brain
Member
Member
Posts: 247
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Discord: https://discord.gg/brainbox
GitHub: https://github.com/braindigitalis
Contact:

Re: Bootloader freezing

Post 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.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Bootloader freezing

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bootloader freezing

Post by Combuster »

If you look at the date, I think we can stop scaring him away now...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Bootloader freezing

Post by VolTeK »

My apologies, i had just realized how long ago the last post was
Post Reply