Page 1 of 1

Wrong DS address

Posted: Sat Oct 19, 2013 7:13 pm
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.

Re: Wrong DS address

Posted: Sun Oct 20, 2013 3:01 am
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.

Re: Wrong DS address

Posted: Sun Oct 20, 2013 3:28 pm
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

Re: Wrong DS address

Posted: Mon Oct 21, 2013 1:28 am
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.

Re: Wrong DS address

Posted: Mon Oct 21, 2013 1:54 am
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.