Page 1 of 1

Switching to realmode using the gcc's gnu assembler syntax

Posted: Thu Dec 03, 2020 11:48 am
by SuperGabry64
I was trying to switch into real mode using the osdev tutorial, wich includes an assembly code with intel syntax, what is his at&t corrispondence?

I already come out with this, it compiles but not link:

Code: Select all

.code16

idt_real:
    .word $0x3ff
    .quad $0

savcr0:
    .quad $0

Entry16:
    cli

    mov DATASEL16, %eax
    mov %eax, %ds
    mov %eax, %es
    mov %eax, %fs
    mov %eax, %gs
    mov %eax, %ss

    mov %cr0, %eax
    mov %eax, savcr0
    and $0x7FFFFFFe, %eax
    mov %eax, %cr0

    jmp GoRMode

GoRMode:

    mov $0x8000, %sp
    mov $0, %ax
    mov %ax, %ds
    mov %ax, %es
    mov %ax, %fs
    mov %ax, %gs
    mov %ax, %ss

    lidt idt_real
    sti


Re: Switching to realmode using the gcc's gnu assembler synt

Posted: Thu Dec 03, 2020 12:00 pm
by iansjack

Re: Switching to realmode using the gcc's gnu assembler synt

Posted: Thu Dec 03, 2020 12:05 pm
by SuperGabry64
I tried but that gives these errors:

Code: Select all

arch/i386/real_mode.S: Assembler messages:
arch/i386/real_mode.S:3: Error: junk at end of line, first unrecognized character is `['
arch/i386/real_mode.S:6: Error: no such instruction: `dw 0x3ff'
arch/i386/real_mode.S:6: Error: junk at end of line, first unrecognized character is `2'
arch/i386/real_mode.S:7: Error: no such instruction: `dd 0'
arch/i386/real_mode.S:7: Error: no such instruction: `real Mode IVT@0x0000'
arch/i386/real_mode.S:10: Error: no such instruction: `dd 0'
arch/i386/real_mode.S:10: Error: no such instruction: `storage location for pmode CR0.'
arch/i386/real_mode.S:13: Error: no such instruction: `we are already in 16-bit mode here!'
arch/i386/real_mode.S:15: Error: no such instruction: `disable interrupts.'
arch/i386/real_mode.S:17: Error: no such instruction: `need 16-bit Protected Mode GDT entries!'
arch/i386/real_mode.S:18: Error: junk at end of line, first unrecognized character is `1'
arch/i386/real_mode.S:26: Error: no such instruction: `disable paging (we need everything to be 1:1 mapped).'
arch/i386/real_mode.S:28: Error: no such instruction: `save pmode CR0'
arch/i386/real_mode.S:29: Error: no such instruction: `disable paging bit&disable 16-bit pmode.'
arch/i386/real_mode.S:32: Error: no such instruction: `perform Far jump to set CS.'
arch/i386/real_mode.S:35: Error: no such instruction: `pick a stack pointer.'
arch/i386/real_mode.S:36: Error: no such instruction: `reset segment registers to 0.'
arch/i386/real_mode.S:43: Error: no such instruction: `restore interrupts -- be careful,unhandled int115will kill it.'

Re: Switching to realmode using the gcc's gnu assembler synt

Posted: Thu Dec 03, 2020 12:17 pm
by iansjack
Did you use the .intel_syntax directive?

Re: Switching to realmode using the gcc's gnu assembler synt

Posted: Thu Dec 03, 2020 12:21 pm
by austanss
try changing the file extension to .asm

look, you really shouldn't be doing osdev. if you don't understand how a compiler/assembler works, and all you do is pester forum members for example code, you won't get anywhere, you'll give up, and feel disappointed.

strengthen your knowledge in userspace and lower level userspace before you attempt osdev.

three months before I started osdev, I contemplated making an os. i figured out how complex it was, and how it wasn't my place, and i didn't do it. i didn't "push through it" and pester forum members, no. i got a better understanding over lower level concepts, c, c++, and assembly, and then i came back.

i suggest you do the same, because all you're gonna get from here on out are sneer remarks.

Re: Switching to realmode using the gcc's gnu assembler synt

Posted: Thu Dec 03, 2020 12:25 pm
by SuperGabry64
iansjack wrote:Did you use the .intel_syntax directive?
yes

Re: Switching to realmode using the gcc's gnu assembler synt

Posted: Thu Dec 03, 2020 12:34 pm
by iansjack
What error do you get from the linker with your at&t code?

Re: Switching to realmode using the gcc's gnu assembler synt

Posted: Thu Dec 03, 2020 12:48 pm
by MichaelPetch
When declaring values for data don't use the `$`. So

Code: Select all

    .word $0x3ff
    .quad $0
can be

Code: Select all

    .word 0x3ff
    .quad 0
and then make the similar change elsewhere. I believe you mean to do

Code: Select all

mov $DATASEL16, %eax
and not

Code: Select all

mov DATASEL16, %eax
. If you are getting an error at link time I'd be curious if it was a relocation unable to fit type error. That could be a problem with a linker script or if you aren't using a linker script you may not have used something like `-Ttext=0x####` where #### is the ORG (origin point/starting VMA). That value needs to be <= 0xffff for 16-bit code.

It is hard to tell without a minimal complete verifiable example. We don't see all your code and we don't see how you are assembling/linking.

Re: Switching to realmode using the gcc's gnu assembler synt

Posted: Thu Dec 03, 2020 1:05 pm
by SuperGabry64
MichaelPetch wrote:When declaring values for data don't use the `$`. So

Code: Select all

    .word $0x3ff
    .quad $0
can be

Code: Select all

    .word 0x3ff
    .quad 0
and then make the similar change elsewhere. I believe you mean to do

Code: Select all

mov $DATASEL16, %eax
and not

Code: Select all

mov DATASEL16, %eax
. If you are getting an error at link time I'd be curious if it was a relocation unable to fit type error. That could be a problem with a linker script or if you aren't using a linker script you may not have used something like `-Ttext=0x####` where #### is the ORG (origin point/starting VMA). That value needs to be <= 0xffff for 16-bit code.

It is hard to tell without a minimal complete verifiable example. We don't see all your code and we don't see how you are assembling/linking.
Thanks you, that resolver every problem with compiling and linking, now the only thing i have to do is thesting if it works

Re: Switching to realmode using the gcc's gnu assembler synt

Posted: Thu Dec 03, 2020 1:13 pm
by MichaelPetch
One thing that may cause a problem is this:

Code: Select all

jmp GoRMode
You need a FAR JMP to set the CS register to 0x0000 (to be similar to the OSDev Wiki code). This is a near JMP that doesn't set the segment. What you want in AT&T syntax is:

Code: Select all

jmp $0x0000,$GoRMode