Page 2 of 2

Re: where is gdt located?

Posted: Fri Jan 09, 2009 7:58 am
by yemista
Im sorry I screwed up the last posting. I meant that a jump to 0x08:0x0010001 wrapped
around to 0x08:0x00000001 , or 0x08:0x00000000, whatever 1 plus the limit is, where 0x08 is the selector in the gdt that contains a base of 0x0000.

Re: where is gdt located?

Posted: Fri Jan 09, 2009 10:08 am
by Brendan
Hi,
yemista wrote:Im sorry I screwed up the last posting. I meant that a jump to 0x08:0x0010001 wrapped
around to 0x08:0x00000001 , or 0x08:0x00000000, whatever 1 plus the limit is, where 0x08 is the selector in the gdt that contains a base of 0x0000.
That won't/can't happen - if you exceed a segment limit you get a general protection fault (even in real mode).

What may have happened if your code is in a "bits 16" section, is that the assembler saw your "jmp 0x08:0x0010001" and decided that addresses are 16-bit, and truncated the address so it became "jmp 0x08:0x0001". In this case then you can tell the assembler to generate a 32-bit jump (even in 16-bit code). For example, for NASM try "jmp dword 0x08:0x0010001" instead.

The only other thing I can think of is the A20 gate, but that's already been mentioned.


Cheers,

Brendan

Re: where is gdt located?

Posted: Fri Jan 09, 2009 11:26 am
by Combuster
0x0010001 (64k + 1) isn't an A20 wrapping address. It does have 7 digits which suggests a (typing) error...

Re: where is gdt located?

Posted: Fri Jan 09, 2009 12:28 pm
by yemista
Well I did not copy and past it because I dont have access to my code from here, but that wasnt the issue. Most likely I was not making the jump in 32 bit code so it was truncated, but also, I couldve been getting a segmentation fault. I just assumed it failed because it tried running the code in that area which not be runnable code. Just to be clear though, here is my code which seems to work properly, but maybe it is not working as I understand it to, and it just so happens to overwrite RAM that doesnt cause a fatal error and executes properly. I want the code to be loaded right after the 1MB mark and then jump to there. If there are slight syntax errors, please understand I just converted it all over from intel syntax to ATT, and have not tried compiling it yet, and dont have the old version, but it compiled and ran this
way under intel syntax(before it was converted anyways)

Code: Select all

.code16

gdt:		.long		$0		# this is the null descriptor
		.long		$0 
code_seg:	.word		$0xffff
		.word		$0x0000
		.byte		$0x10
		.byte		$0x98
		.byte 		$0x4f
		.byte		$0x00
data_seg	             .word		$0xffff
		.word		$0x0000
		.byte		$0x10
		.byte		$0x92
		.byte		$0x4f
		.byte		$0x00
video_seg	.word		$0xffff
		.word		$0x0000
		.word		$0x00
		.word		$0x92
		.word		$0x4f
		.word		$0x00
gdt_end


             # now we setup a temporary gdt and enter pmode
	# this temp gdt gives us flat 4gb address space with cs=ds
	xorl %eax, %eax
	addl gdt, %eax
	movl %eax, 2(gdtr)		# set offset of gdt
	movl gdt_end, %eax
	subl gdt, %eax		# calculate the size of the table
	movw %ax, (gdtr)		# set the size in the entry
	lgdt (gdtr)			# now load it

	

	# now we can finally load the kernel
	movb $0, %dl	# we want floppy drive 1
	movb $0x02, %ah	# read from floppy
	movb $, %dh	# i think 0 is the first head...
	movw $0x02 %cx	# i think this means the second sector...
	movw $0xffff, $bx
	movw %bx, %es
	movw $0x0011, %bx  # we load to start of memory
	int $0x13	# BIOS int loads code to es:bx


	
	cli

	# enter pmode by changing one bit in cr0
	movl %cro, %eax
	orl 0x01, %eax
	movl %eax, %cr0

	
	;; jump to loaded code 
	jmp 0x08:0x00000001