flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Help to start my own OS

Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Author
Thread Post new topic Reply to topic
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 30 May 2010, 12:40
Teehee wrote:
about the boot:
it loads at 0:7C00h by default. So it starts with org 7c00h.
Which place should I put my kernel? org 0 (0000:0000)?

I need an answer Smile

_________________
Sorry if bad english.
Post 30 May 2010, 12:40
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 30 May 2010, 13:21
you sould put your kernel where you want.

free segments are:
1000h to 9000h

org the kernel at 100h if you want to test it under dos assuming the entry point in kernel is in real mode, and then, switch to pm in the kernel.

the segment for the kernel can be 1000h for example.

boot = 0:7c00h
kernel = 1000h:0
or kernel = 1000h:100h
Post 30 May 2010, 13:21
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 30 May 2010, 13:31
the org directive organize only the offset, not the segment, right?
but where in the code (bytes) it says to organize in some address?
can i do not use the org?
Post 30 May 2010, 13:31
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 30 May 2010, 13:48
you can code wihout org, in this case, it is equivalent to org 0

in fact org only refer to offsets for datas and labels.


Code:
org 230
mov ax,$ ;ax = $ = 230

org 100h
mov ax,$ ; ax= $ = 256

org 0
mov ax,$ ; ax=$ = 0

    


then, you canuse several org inside the same source, because it will only change the base adress value.
the binary itself will always start at offset 0, but operations on labels inside will assume the code start at a specified location.
Post 30 May 2010, 13:48
View user's profile Send private message Visit poster's website Reply with quote
ass0



Joined: 31 Dec 2008
Posts: 518
Location: ( . Y . )
ass0 30 May 2010, 14:24
It would be simpler and more logic:
Code:
$: 230 
mov ax,$ ;ax = $ = 230 

$: 100h 
mov ax,$ ; ax= $ = 256 

$: 0 
mov ax,$ ; ax=$ = 0
    

=D

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 30 May 2010, 14:24
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 30 May 2010, 15:26
edfed,
Intel SDM vol. 2-A rev. 033 p. 3-595 wrote:
The source operand specifies a 6-byte memory location that contains the base address (a linear address) and the limit (size of table in bytes) of the global descriptor table (GDT)…
…If the operand-size attribute is 16 bits, a 16-bit limit (lower 2 bytes) and a 24-bit base address (third, fourth, and fifth byte) are loaded. Here, the high-order byte of the operand is not used and the high-order byte of the base address in the GDTR or IDTR is filled with zeros.
While technically you're right (operand size is said to be 6 bytes), only 5 of them are really used. Now look here:
Teehee here wrote:
3. The worse step:
Code:
gdtr: dw 23,gdtr-3
      db 0
      dw 0FFFFh,0,9A00h,0CFh
      dw 0FFFFh,0,9200h,0CFh    
GEeeeeezzzzzz what they meannnnnnn Crying or Very sad
Where is the sixth byte? This pseudo-descriptor is useful only for 16-bit lgdt (hence I wrote that it's 16-bit): if 32-bit lgdt is used, GDT base will be 0xFF000000+gdtr-3. Is it clear?

EDIT: Dumb error with lgdt mnemonic.


Last edited by baldr on 30 May 2010, 18:30; edited 2 times in total
Post 30 May 2010, 15:26
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 30 May 2010, 15:26
Teehee wrote:
but where in the code (bytes) it says to organize in some address?

You specify the memory address when reading the sectors from the disk using BIOS interrupt 0x13.
I may be misunderstanding your question though.
Post 30 May 2010, 15:26
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 30 May 2010, 16:35
ManOfSteel wrote:
I may be misunderstanding your question though.

yep Smile but edfed answered:
edfed wrote:
you canuse several org inside the same source, because it will only change the base adress value.


I was thinking that there is some byte to say "hey CPU, from here you organize at address XXXX". But it just put the data (and not code or stack(?)) at specified org position. If i understood.
Post 30 May 2010, 16:35
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 30 May 2010, 16:43
org position is not adress.

when you say org xxxx, you just say to compiler a virtual base adress, something added to all label references.

that's why it is a directive.
Post 30 May 2010, 16:43
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 30 May 2010, 18:29
Teehee,

Have you read 2.2.4 Addressing spaces subchapter of manual? First paragraph describes it all.
Post 30 May 2010, 18:29
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 30 May 2010, 19:47
Quote:
when you say org xxxx, you just say to compiler a virtual base adress, something added to all label references.

I dont know if i undertood. Maybe i'm just cant figure out how it work.

I made this test, but still i can't see why.

i compiled this code and tried to see it in debug:
Code:
org 100h
    nop
one:
    jmp two
    nop

    db 'one',0

;org 200h

    nop
two:
    jmp one
    nop

    db 'two',0    


See img below. The first entry is with org 200h line commented; the second one it was uncommented.


Description:
Filesize: 17.13 KB
Viewed: 5741 Time(s)

cmd.png



_________________
Sorry if bad english.
Post 30 May 2010, 19:47
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 30 May 2010, 20:10
Teehee,

Nothing unusual.
FASM manual wrote:
org directive sets address at which the following code is expected to appear in memory. It should be followed by numerical expression specifying the address. This directive begins the new addressing space, the following code itself is not moved in any way, but all the labels defined within it and the value of $ symbol are affected as if it was put at the given address. However it's the responsibility of programmer to put the code at correct address at run-time.
Code:
org 100h        ; $     file
    nop         ; 100   00
one:
    jmp two     ; 101   01; two==0x201, jmp near
    nop         ; 104   04

    db 'one',0  ; 105   05

org 200h

    nop         ; 200   09
two:
    jmp one     ; 201   0A
    nop         ; 204   0D

    db 'two',0  ; 205   0E
                ; 209   12    
Think of first jump as jmp 201h. It can't be short, because short jump can reach destination only within [83h, 182h] range from 101h. The same for second jmp.

Your code is placed at 100h by OS loader (as usual for .Com executables) as a whole. So if you want to place code below org 200h at offset 200h, you must copy it yourself.
Post 30 May 2010, 20:10
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 30 May 2010, 20:45
baldr wrote:
Think of first jump as jmp 201h.

I can think that, but the code is not really there (is it?). At least debug says no.

Quote:
So if you want to place code below org 200h at offset 200h, you must copy it yourself.
How can I do that?

_________________
Sorry if bad english.
Post 30 May 2010, 20:45
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 30 May 2010, 21:12
Something like this:
Code:
mov si,old_code_location
mov di,new_code_location
mov cx,length_of_code
cld
repnz movsb    
Note this moves using address ds:si -> es:di
Post 30 May 2010, 21:12
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 30 May 2010, 21:21
Teehee,

cod3b453's right. There is a catch:
Code:
    db 'one',0  ; 105   05

; label for source address should be placed here
; because it should refer to address where the code is located now
old_code_location:
org 200h
; label for destination address should be placed here
; because it should be at 200h
new_code_location:
    nop         ; 200   09
two:
    jmp one     ; 201   0A
    nop         ; 204   0D

    db 'two',0  ; 205   0E
                ; 209   12
length_of_code = $-new_code_location    
Though it looks confusing, re-read that paragraph of manual and you'll understand.
Post 30 May 2010, 21:21
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 31 May 2010, 10:22
org is like that:

date 2june2056
start list,activities
1 more day: picnic mountain,family
1 more day: barbecue village,friends
1 more day: beach marseille,girls
1 more day: party monaco,money

if you make the analogy between org and date, you will find that each instruction is located one day after preceding one.
then, for the party, refering to date 2 june 2048, you can say it will be the 6 june 2048.

if you change the origin date, each labels offset will not change, but reference will.
for example:
date 32may3298
here, the party date will be the 32+4= 36 may3298.

it is the same for org.

org 100h
.0: db 0
.1: db 1
.2: db 2
.3: db 3
.4: db 4

then, each label inside this code is located at org+offset


i don't understand why you don't understand that....
Post 31 May 2010, 10:22
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 31 May 2010, 16:03
edfed wrote:
i don't understand why you don't understand that....

hehe, i understood that. What i dont understand is why in debug it showns datas at same code place, if we org it in another place.

e.g:
Code:
org 100h
nop
db 'aaa',0
org 200h
nop
db 'bbb',0    

shows:
Code:
0D346:0100 : 90 61 61 61 00 90 62 62 62 00 .aaa..bbb.    


This is how I imagine how it should be:
Code:
0D346:0100 : 90 61 61 61 00 .aaa.
(...)
0D346:0200 : 90 62 62 62 00 .bbb.    


But, INDEED, if i put some label at second org, it will shows 200h+ address. But the data is not really there. is it copied to there?

hehe I don't know whats happening to me Embarassed Razz

_________________
Sorry if bad english.
Post 31 May 2010, 16:03
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 31 May 2010, 17:03
Teehee wrote:
What i dont understand is why in debug it showns datas at same code place, if we org it in another place.

That's because you don't have any memory offset there, only meaningless data. The only way to do what you want in this case is to use times xyz db 0.

You really should read the fabulous manual:
Quote:
org directive sets address at which the following code is expected to appear in memory. It should be followed by numerical expression specifying the address. This directive begins the new addressing space, the following code itself is not moved in any way, but all the labels defined within it and the value of $ symbol are affected as if it was put at the given address. However it's the responsibility of programmer to put the code at correct address at run–time.
Post 31 May 2010, 17:03
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 31 May 2010, 18:16
yep, ManOfSteel, i've read.
Manual wrote:
but all the labels defined within it and the value of $ symbol are affected as if it was put at the given address

"as if"... ok, they are not there. But then why do we use the org directive? what its utility? I can't see. Image

Take it easy guys. We are coming there!
Post 31 May 2010, 18:16
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 31 May 2010, 19:56
It serves to adapt the addresses used inside your code.

For example, a .com executable is expected to run at 0x100 because MS-DOS copies the contents of the executable at memory address 0x100.
If you omit the org 0x100 at the beginning of the following example, where do you think the second operands of the 2 mov instructions will point? 0x106 and 0x10b where they're expected to be, or 0x6 and 0xb (right in the IVT)?

Code:
org 0x100

mov si,str1
mov di,str2

str1 db 'test1'
str2 db 'test2'
    
Post 31 May 2010, 19:56
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.