problem with intel->at&t conversion

Programming, for all ages and all languages.
Post Reply
mittwoch
Posts: 4
Joined: Thu Mar 19, 2009 9:14 am

problem with intel->at&t conversion

Post by mittwoch »

hello,

i have a kernel in protected mode and want to set up a gdt, so i read the gdt tutorial and tried to put the code pieces i was given there together. Until now, it didn't work. Since i only know at&t syntax assembly language, and the examples of the tutorial are in intel, i had to convert them first.
I think the reason for my gdt-load to not work lies in the conversion part of the code, but i don't know where.

These are the assembly pieces i converted:

This

Code: Select all

gdtr DW 0 ; For limit storage
     DD 0 ; For base storage

setGdt:
   MOV   EAX, [esp + 4]
   MOV   [gdtr + 2], EAX
   MOV   AX, [ESP + 8]
   MOV   [gdtr], AX
   LGDT  [gdtr]
   RET
into this

Code: Select all

gdtr:
limit:  .word 0 # For limit storage
base:   .long 0 # For base storage

.globl setGdt
setGdt:
        movl    4(%esp),        %eax
        movl    %eax,           base
        movw    8(%esp),        %ax
        movw    %ax,            gdtr
        lgdt    gdtr
        ret
and this

Code: Select all

reloadSegments:
   ; Reload CS register containing code selector:
   JMP   0x08:reload_CS ; 0x08 points at the new code selector
.reload_CS:
   ; Reload data segment registers:
   MOV   AX, 0x10 ; 0x10 points at the new data selector
   MOV   DS, AX
   MOV   ES, AX
   MOV   FS, AX
   MOV   GS, AX
   MOV   SS, AX
   RET
into this

Code: Select all

.globl reloadSegments
reloadSegments:
        # Reload CS register containing code selector:
        ljmp    $0x08,  $reload_CS # 0x08 points at the new code selector
reload_CS:
        # Reload data segment registers:
        movw    $0x10,          %ax    # 0x10 points at the new data selector
        movw    %ax,            %ds
        movw    %ax,            %es
        movw    %ax,            %fs
        movw    %ax,            %gs
        movw    %ax,            %ss
        ret
Do you have any ideas?

Thanks in advance, mittwoch
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:

Re: problem with intel->at&t conversion

Post by pcmattman »

I don't think you are referencing your variables correctly here:

Code: Select all

        movw    %ax,            gdtr
        lgdt    gdtr
... and here ...

Code: Select all

        movl    %eax,           base
For a start, I know that the lgdt line should be

Code: Select all

lgdt (gdtr)
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: problem with intel->at&t conversion

Post by 01000101 »

when referencing memory variables, you need to use "(x)". so to move EAX into BASE, you need to do "movl %eax, (base);" or along those lines.
Post Reply