flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Int 13h?

Goto page Previous  1, 2, 3  Next
Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 26 Oct 2007, 06:59
it is also the same problem

jmp 60h:0
;the next is org 0 in segment 60h
org 0
;linear 600h, segmented 60h:0
jmp 8:start32
;segment 8 begins at 0
start32:
;start32 is from the org 0
;but org 0 is from 600h linear not from 0 linear

here the problem is jmp 60h:0, org 0

the best is to jmp 0:600h, org 600h

jmp 8:start32 will point to 0+600h+start32 ----- OK
Post 26 Oct 2007, 06:59
View user's profile Send private message Visit poster's website Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 26 Oct 2007, 07:32
All your problems are caused by wrong memory references (remember, your code is assembled at org 0000h):

Code:
gdt_desc: dw gdt_end - gdt - 1
          dd gdt + 0x600

...

jmp 8h:Start32 + 0x600

...

; Print Welcome Message
mov esi, WelcomeStr + 0x600
call PrintF

...

mov ah, [TxtClr + 0x600]
    
Post 26 Oct 2007, 07:32
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 26 Oct 2007, 09:12
You can not use org like that in fasm, you can only have one org at start of program.
Try this, assembly from here:
Code:
org 0000hmov ax, 0060hmov ds, axmov ss, ax;rest of code    

as a separate bin file, called something like "kernel.bin" than add it to the first file like this:

Code:
org 7C00hBootStart:xor ax, axmov ds, axmov ss, axmov sp, 9C00h; Set up VESA text mode 10Ch (132x60)mov ax, 4F02hmov bx, 10Chint 10hmov ax, 0060hmov es, axxor bx, bxmov ah, 02hmov al, 04hmov cl, 02hmov ch, 00hmov dh, 00hint 13hjmp 0060h:0000htimes 510-($-$$) db 0dw 0AA55hfile_area:file  'kernel.bin'    

And then assemble the first file, as normal
Note: Still put the org 0x0000 at top of "kernel.bin"

PS: I have found int 13h read/writing more than 1 sector at a time buggy, and your best waiting and staying in realmode untill you have jumped to the next part eg: "kernel.bin"
Post 26 Oct 2007, 09:12
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 26 Oct 2007, 13:58
YOU CAN PUT MANY ORG DIRECTIVES IN THE CODE IN FASM

but referencing to labels into an other zone (ORG) is always wrong in direct addressing
but is good to write a code that will be on many sectors on disk!!!
or code that is a disk image, like a floppy image, sectors by sectors
this pseudo-code will help to understand

Code:
;entire program stored on sectors1 & 2
org 7C00h
;code loaded at seg1:7C00h from sector1 at boot time
load sector2 @ seg2:0
mov eax,[seg2:data1]
jmp seg2:0
align 512

org 0
;code normally loaded at seg2:0 from sector2
data1 rd 1
jmp seg1:7C00h ;reloop in boot
    


many other applications of org X everywere are possible
for exemple multisegment, multisector, multitable
Code:
org 0
table1:
...
org 0
table2:
...
org 0
table3:
...
    


by evidence table 1 2 & 3 are not all at 0
but by knowing the offset of tablex, we can use the labels in the table
in addition with the real offset

it permitts to build some structures
and accessing them by a constant, not an offset
but the big problem is to know the effective address of the re-ORGed code at compilation time
Post 26 Oct 2007, 13:58
View user's profile Send private message Visit poster's website Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 26 Oct 2007, 15:27
@Dex4u:
Are you sure? Try disassembling the output of this:
Code:
org 0x450
mov eax,testdata1

testdata1 db 1

int3

org 0x900
mov eax,testdata2

testdata2 db 2

int3
    



Of course in a boot loader, it's better to have as many files as there are stages.
Post 26 Oct 2007, 15:27
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 26 Oct 2007, 17:13
This has partially helped, so thanks! I commented out the call to the PrintF function and instead put in a direct access to video memory to put up a green smiley, which worked.

I had to add:

gdt_desc: dw gdt_end - gdt - 1
dd gdt+600h


and add 600h to the far jump to Start32.

EDIT: I added 600h to the addresses I was using that lied before the far jump and the PrintF works! Very Happy

My biggest question is, howcome the memory addresses of everything aren't already added to 0600h after I move the 60h into the data segment?

ie. -

I'd think that TextClr (for example) would have 600h added to the address already after I do the org 0000h and set up the data segment with 0060h.

Or do things change around when I jump into Pmode?
Post 26 Oct 2007, 17:13
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 27 Oct 2007, 00:12
Yes your RIGHT, you CAN use org like that, but you have to make sure that the part is loaded at that address, but i know i read it some where, but i a have check and it was wrong.
Cool that helpfull to me too Wink.
Post 27 Oct 2007, 00:12
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 27 Oct 2007, 01:17
Code:
        org 7C00h
        xor ax,ax
        mov ds,ax
        mov ss,ax
        mov sp,9C00h
        mov ax,4F02h; Set up VESA text mode 10Ch (132x60)
        mov bx,10Ch
        int 10h
        mov ax,60h
        mov es,ax
        xor bx,bx
        mov ax,204h
        mov cx,2
        mov dh,0
        int 13h
        jmp 0:600h
times 510-($-$$) db 0
dw 0aa55h
        org 600h
        push cs cs
        pop ds ss
        mov esi,ok.boot
        mov bx,0b800h
        mov es,bx
        mov bx,0
        mov ah,[txt.col]
@@:
        mov al,[si]
        cmp al,0
        je @f
        inc si
        mov [es:bx],ax
        add bx,2
        jmp @b
@@:
;put some more realmode code there
        cli                ; Clear interrupts for move to 32-bit mode
        lgdt [gdt_desc] ;Load Global Descriptor Table (GDT) Register
        mov eax,cr0       ;Set up control register to get into Protected Mode
        or al,1
        mov cr0,eax
        jmp 8h:Start32     ;Do far jump to first (filled in) selector - the code selector.
; Welcome to the world of 32-Bit mode! =-D
Start32: 
use32 
        mov ebx,10h
        mov ds,bx
        mov es,bx
        mov fs,bx
        mov gs,bx
        mov ss,bx
        mov esp,90000h
@@:
        mov ebx,0B8000h+132
        mov esi,ok.pm
        call PrintF
        in al,60h
        cmp al,1
        jne @b
        inc [txt.col]
        jmp @b
PrintF:
        mov ah,[txt.col]
@@:
        mov al,[esi]
        cmp al,0
        je @f
        inc esi
        mov [ebx],ax
        add bx,2
        jmp @b
@@:
        ret

; Data Goes Here
txt:
.x rd 1
.y rd 1
.col db 71h
ok:
.boot db "boot OK!",0
.pm db "protected mode OK!",0
align 8
gdt_desc:
dw gdt_end - gdt - 1
dd gdt
align 16
gdt:
.null dq 0
.flatcode db 0FFh,0FFh,00h,00h,00h,10011010b,11001111b,00h
.flatdata db 0FFh,0FFh,00h,00h,00h,10010010b,11001111b,00h
.textscreen db 0,0,0,0,0,0,0,0
.graphicscreen db 0,0,0,0,0,0,0,0
gdt_end:                          
    

simply write the image on floppy with rawwrite or anything else

thanks to dex4u, vid, manofsteel and ! rhyno_dagreat !

now serious things begins ! Wink


Description: writes "boot OK!"
wait echap
switch to mode 320*200
switch to pm
load a segment direct to screen
put an image on screen
if echap then inc color

Download
Filename: bootpm.asm
Filesize: 2.85 KB
Downloaded: 1566 Time(s)



Last edited by edfed on 27 Oct 2007, 18:16; edited 1 time in total
Post 27 Oct 2007, 01:17
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 27 Oct 2007, 04:59
This is great, however my biggest question yet still stands which is howcome the memory addresses of everything aren't already added to 0600h after I move the 60h into the data segment?

ie. -

I'd think that TextClr (for example) would have 600h added to the address already after I do the org 0000h and set up the data segment with 0060h.

Or do things change around when I jump into Pmode?
Post 27 Oct 2007, 04:59
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 27 Oct 2007, 08:07
It's the way memory references are assembled. The assembler adds the parameter of the org directive to your memory references which in this case is 0.
The content of DS matters most for those instructions that directly use it like lods*, for instance.
Post 27 Oct 2007, 08:07
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 27 Oct 2007, 11:47
i use org 600h
and segment is set to 0
so to access this code
i just "take a look at the code above"

to reference your method rhyno, you need to set a descriptor that begins at 600h and then you can have a org 0 code

all code after org x will reference memory with its offset from the org plus the value of the org

a memory that is 60h after the org 600h will be accessed like that:

org 600h
mov eax,[label] ; mov eax,[600h+60h]
...
label rd 1 ; supposed to be 60h bytes after the org directive
Post 27 Oct 2007, 11:47
View user's profile Send private message Visit poster's website Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 27 Oct 2007, 13:56
rhyno_dagreat: Maybe my boot sector example can help you? It loads a secondary binary file to memory and jumps to it.

Here's the link: http://board.flatassembler.net/topic.php?t=6529

regads,
Mac2004


Last edited by Mac2004 on 28 Oct 2007, 07:33; edited 1 time in total
Post 27 Oct 2007, 13:56
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 27 Oct 2007, 13:57
Ah! That makes a lot of sense! Thank you all for pointing out that which should have been rather obvious to me!
Post 27 Oct 2007, 13:57
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 27 Oct 2007, 16:21
Thanks Mac! Though it's not so much the real mode I'm having the problem with as it is the PMode.


Last edited by rhyno_dagreat on 27 Oct 2007, 16:22; edited 1 time in total
Post 27 Oct 2007, 16:21
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 27 Oct 2007, 16:21
Hmmm... I recompiled it setting org to 600h, and it didn't work, even though ds and ss were set to 60h... But when I tried pushing the code segment onto the stack and popping it into the data segment and stack segment, like edfed did in his example, it worked. Strange I think, because even though I ORGed it @ 0600h, it still didn't treat it like the data segment was supposed to be there. Can anyone please explain why it didn't work?
Post 27 Oct 2007, 16:21
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 27 Oct 2007, 18:10
in fact cs is set to 0
and all others too
and the org 600h is there to center the loaded references to the presumed destination
here it is the linear 600h

org is for memory accessed in segment
segment set the base address (rm, pm, smm, v86 )
the offset is within the segment
and start at 0
because it is relative addressing, relative to segment base address


org is relative to segment too
so code in the segment can be anywere in the address space
and code segment have only one different with others, it is used implicitly for opcode loading
the else segments are user segments
but they works exactly like code segment
if you access a byte in a segment, you must speciffy an offset inside the segment

the segment have some hidden parts (in pm ) that are memory boundaries and attributes
etc etc...
Post 27 Oct 2007, 18:10
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 27 Oct 2007, 18:16
bootpm.asm updated
Post 27 Oct 2007, 18:16
View user's profile Send private message Visit poster's website Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 27 Oct 2007, 18:32
So you're saying ORG doesn't set the code segment to 0060h? All it does is set up the offset of the segment address to 600h of certain variables so that they'll be added to whatever is in that ORG statement? I thought ORG set up the linear address and not offset address.
Post 27 Oct 2007, 18:32
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 27 Oct 2007, 18:34
Here, this may help you:
Its a simple relocatable file format, normal if you try to load a file in pmode, to a location other than, where the ORG is pointing to, it will not run right.
Now lets make a very simple relocatable file format that can be loaded anywhere.
Code:
org 0use32jmp  start;maybe a simple header herestart:mov eax,[MyVar1 + ebx] ; you need to do thismov [MyVar2 + ebx],edx; same with thismov esi,MyStringadd esi,ebx  you need to do thiscall print ; this is ok like thisjmp LetsGo ;this is ok like this; some more code here, maybeLetsGo:         retprint:;print code hereret;DataMyString: db 'hello world!',13,0MyVar1 rd 1MyVar2 rd 1    

Now for this to work you only need to put the load address into EBX, now as you can see, some address are OK and do not need fix eg: jmp start, as this will just add the distance to the eip, Then we have the call, now this is OK, as it basically the same as a jmp, but it also store the next instruction on the stack, etc for the ret.
But if you look at the rest which point to a address in memory, you need to add the load address.

Now in your example, the printf function would not be the reason you where rebooting, but more likely the string pointer.

NOTE: The above example, is with out paging, etc.
Post 27 Oct 2007, 18:34
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 27 Oct 2007, 18:42
Ah, I see. But I'm loading the linear address into EBX in 32 bit mode, right?

And ORG deals with the SEGMENT:OFFSET addressing scheme, where you're giving it the OFFSET of the code-segment in 16-bit mode, or in 32-bit mode it's the SELECTOR:OFFSET addressing scheme, however you're still giving it the OFFSET. Am I correct on this?
Post 27 Oct 2007, 18:42
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  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.