very strange behaviour indeed...

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
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

very strange behaviour indeed...

Post by sancho1980 »

hi

i just came across some very strange behaviour of the nasm compiler
take a look at this piece of code:

Code: Select all

lgdt [gdt_desc]

	mov eax, cr0	;Enable

	or eax, 1	;protected

	mov cr0, eax	;mode

	jmp 20h:enter_32 ;where 20h is selector for this very segment




	BITS 32

enter_32:

	hlt	
	jmp enter_32
if i execute this, the screen completely blanks upon the jump to enter_32

now if i leave out "BITS 32", the screen stays as it is!

is there a sensible explanation for this??
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

I think you have to disable interrupts before you enter pmode....
C8H10N4O2 | #446691 | Trust the nodes.
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post by sancho1980 »

yeah i did that! forgot to post that line

Code: Select all

cli
comes just before

Code: Select all

lgdt [gdt_desc]
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

All the 'bits 32' prefix does is modify the opcodes to have a special prefix, iirc.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Have you traced it through bochs?
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post by sancho1980 »

i still havent figured out how to do that
but would a simple "hlt" instruction be compiled differently depending on whether BITS 32 or BITS 16 is enabled??
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Re: very strange behaviour indeed...

Post by XCHG »

sancho1980 wrote:hi

i just came across some very strange behaviour of the nasm compiler
Remember that it is almost never the behavior of NASM that is wrong. You are doing something wrong and unfortunately, given the code snippet that you have put in your post, it is impossible to find the problem.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post by sancho1980 »

Ok, I had attached these files in relation to a less specific question in a different thread already, but I'll attach them yet again so you see exactly what I mean. the code does the following:

-loads 512 byte boot sector (512.asm) (well thats done by the bios)
-the 512 bytes then relocate to 0500h
-then the gdt (gdt.asm) is read from disk into 010700h (gdt-reserved space til 0126ffh)
-012700h-0146ffh shall be used for the idt
-then the c-code shall eventually be loaded at 014700h, but the jump to it is was taken out (because i don get it compiled properly)

there is also a makefile which i cant attach:

Code: Select all

all: Makefile
   make bootdisk.bin
bootdisk.bin: 512.bin gdt.bin boot.bin Makefile
   -rm bootdisk.bin
   touch bootdisk.bin
   dd if=512.bin of=bootdisk.bin count=1 seek=0
   dd if=gdt.bin of=bootdisk.bin count=1 seek=1
   dd if=boot.bin of=bootdisk.bin count=1 seek=3
512.bin: 512.asm Makefile
   -rm 512.bin
   nasm -f bin 512.asm -o 512.bin
gdt.bin: gdt.asm Makefile
   -rm gdt.bin   
   nasm -f bin gdt.asm -o gdt.bin
boot.bin: boot.o Makefile
   -rm boot.bin
   ld -o boot.bin -Ttext 0x0 -e main --oformat binary boot.o
boot.o: boot.c Makefile
   -rm boot.o
   gcc -ffreestanding -c boot.c -o boot.o
If you compile all this and boot from bootdisk.bin, the code will hang (as intended) with a blank screen (unintended)
But if you leave out the line that says "BITS 32" (i.e. just the single line BEFORE enter_32: in "512.asm"), compile again and boot, then the code will hang (as expected) AND you'll still see the output from when the code was still in real mode...just have alook at the code, its very heavily commented and pretty self-explanatory,,i'm really stuck here! it really seems the compiler produces different output for this single near-jump instruction..and funnily, it seems to produce the right output when youre actually using the wrong compiler option!
Attachments
gdt.asm
(4.05 KiB) Downloaded 14 times
boot.c
(1.15 KiB) Downloaded 42 times
512.asm
(3.58 KiB) Downloaded 13 times
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post by sancho1980 »

found the problem! dont bother :-)
yes it was me not the compiler :oops:
such trivial things drive me crazy..i spent 2 days looking for the cause of this!!!!! and it was so trivial...
Post Reply