Wrong DS address

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
yee1
Member
Member
Posts: 42
Joined: Sun Feb 10, 2013 4:02 pm

Wrong DS address

Post by yee1 »

Hey,
My kernel looks like that:

Code: Select all

[org 0x8000]
prog:
mov ax, cs
mov ds, ax

; load gdt and enter PM mode code here

db 0eah
dw con
dw 08h

con:

mov ax, 10h
mov ds, ax

endprog dq $-prog


data:
myTxt db 'Here is my sample text'
enddata dq $-data
My problem is to get myText when in protected mode, probably becouse (for sure...) org 0x8000 it makes 0x8000+tekst to create address when I want to acces it.

I can acces it by [ds:offset_for_myTxt] where offset_for_myTxt = myTxt - endprog but its not ok to access it that way in my opinion. How to deal with it ? How to access myTxt by normal way like
mov si, myTxt
mov byte al, [myTxt]

to get first letter for example ?
Hot to do this ?

Ps. I use tiny memory model.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: Wrong DS address

Post by Gigasoft »

You have set the segments incorrectly. If you wanted to use the tiny memory model, then both segments should have the same base address. Either both segments must start at 0, or both segments must start at 0x8000 and the program should start with org 0.
User avatar
summersong
Member
Member
Posts: 32
Joined: Sat Mar 26, 2011 5:26 am
Location: Moscow

Re: Wrong DS address

Post by summersong »

Maybe, I can help. My kernel is loading at 0001:0000. So:

boot:

Code: Select all

org 7c00h
....
jmp 10000h:0
kernel:

Code: Select all

KERNEL_ORG = 10000h
org KERNEL_ORG

; real mode
start:
mov ax,1000h
mov ds,ax ; 0001:0000

mov si,msg_welcome - KERNEL_ORG
call print - KERNEL_ORG
...

; goto long mode
jmp pword 8:start64

; long mode
start64:
xor rax,rax
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov rsp,STACK_PHYS

mov rsi,msg_welcome
call print64
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Wrong DS address

Post by egos »

Hi,

I'm sorry but I don't understand how the following code can work:

Code: Select all

...
jmp 10000h:0

Code: Select all

KERNEL_ORG = 10000h
org KERNEL_ORG

; real mode
start:
mov ax,1000h
mov ds,ax ; 0001:0000
...
And I think that 1000h:0 is more suitable denotation for address 10000h in RM.
If you have seen bad English in my words, tell me what's wrong, please.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Wrong DS address

Post by egos »

Here is a traditional approach:

Code: Select all

  ...
  jmp 1000h:0

Code: Select all

KERNEL_ORG = 10000h

  org 0
start:
  ...
  jmp pword 8:start32

  use32

  org KERNEL_ORG+$
start32:
  ...
My startup code is located under 10000h so I can use linear addressing in RM as well. Take a look here for example.
If you have seen bad English in my words, tell me what's wrong, please.
Post Reply