where is gdt located?

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.
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: where is gdt located?

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: where is gdt located?

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
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: where is gdt located?

Post by Combuster »

0x0010001 (64k + 1) isn't an A20 wrapping address. It does have 7 digits which suggests a (typing) error...
"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
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: where is gdt located?

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