Switching to realmode using the gcc's gnu assembler syntax

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
SuperGabry64
Posts: 20
Joined: Tue Oct 20, 2020 10:38 am

Switching to realmode using the gcc's gnu assembler syntax

Post 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

User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

SuperGabry64
Posts: 20
Joined: Tue Oct 20, 2020 10:38 am

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

Post 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.'
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

Did you use the .intel_syntax directive?
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

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

Post 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.
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
SuperGabry64
Posts: 20
Joined: Tue Oct 20, 2020 10:38 am

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

Post by SuperGabry64 »

iansjack wrote:Did you use the .intel_syntax directive?
yes
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

What error do you get from the linker with your at&t code?
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

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

Post 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.
SuperGabry64
Posts: 20
Joined: Tue Oct 20, 2020 10:38 am

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

Post 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
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

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

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