flat assembler
Message board for the users of flat assembler.

Index > Main > Booting and entering long mode help please

Author
Thread Post new topic Reply to topic
aaa



Joined: 01 Feb 2010
Posts: 1
aaa
Sorry for my english.

Long mode OS development project. Kernel will loaded at 0001:0000. Kernel consist of two parts: 64-bit kernel & 16-bit loader (init). So I want to get something like this:

Code:
org 10000h ; <<<< PROBLEM

use16
start:
jmp loader

use64
kernel:
; 64-bit code here
**********

use16
loader:
; 16-bit init code here
**********
jmp kernel ; go to kernel    


I can't do this because of "org". If I write "org 0", 64-bit code will run with wrong base. If I write "org 10000h", 16-bit code can't be compiled.

Please, help me.
Post 21 Sep 2013, 21:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
In 16-bit mode "0001:0000" is linear address 0x1000 (1 shl 12). But regardless, you need to use org 0 for the 16-bit code because your IP is zero. And use a long mode segment that maps to address 0x1000.

There are already code examples on this board about booting and entering long mode. A search might generate some fruitful source code for you.
Post 21 Sep 2013, 21:52
View user's profile Send private message Visit poster's website Reply with quote
Bargest



Joined: 09 Feb 2012
Posts: 79
Location: Russia
Bargest
I misunderstand why do you need to place loader after kernel. Also, you cannot switch direclty in long-mode without using protected (x32) mode.
About your question, you can use a trick:
Code:
org 0h ; as revolution said - "0001:0000" -> ip == 0
start16:
; code
jmp sel32:code32
end16:

org 1000h + end16 - start16
code32:
; 32-bit code
    
Post 22 Sep 2013, 21:56
View user's profile Send private message Reply with quote
SeproMan



Joined: 11 Oct 2009
Posts: 60
Location: Belgium
SeproMan
revolution wrote :
Quote:

In 16-bit mode "0001:0000" is linear address 0x1000 (1 shl 12).


0001 represents the segment
0000 represents the offset

So this address actually means linear address 16 (NOT 0x1000 = 4096)

_________________
Real Address Mode.
Post 25 Sep 2013, 10:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
SeproMan wrote:
revolution wrote :
Quote:

In 16-bit mode "0001:0000" is linear address 0x1000 (1 shl 12).


0001 represents the segment
0000 represents the offset

So this address actually means linear address 16 (NOT 0x1000 = 4096)
Thank you for the correction.
Post 26 Sep 2013, 07:44
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.