flat assembler
Message board for the users of flat assembler.

Index > Main > How to access to flat memory ?

Author
Thread Post new topic Reply to topic
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen 16 Feb 2007, 02:16
Hi, I want to write a byte value in the memory position: 15728640.
I know that first of all I must have at least 15728641 MB of ram in the system, this is ok for me, I have it, but how do I access to this position using something like this:

Code:
mov  edi, 15728640
mov  al, 'X'
mov  [edi], al
    


I want to avoid the use of segmentation becouse all the current processors can access to memory in a flat way.
I don't use DOS at all.
Post 16 Feb 2007, 02:16
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 16 Feb 2007, 02:31
In fact you need no more than 16 MB (15728640/1024^2). The code is correct but it requires protected mode (or unreal mode) and some code that sets DS with a descriptor with full access to the 4 GB address space. There are lots of these codes on OS construction subforum. The sources of FASM (SOURCE\DOS) has code that enters to this unreal mode too.
Post 16 Feb 2007, 02:31
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 16 Feb 2007, 16:27
Something like this would work:
Code:
;************************************; Pmode, by Dex; Assemble with fasm; c:\fasm Pmode.asm Pmode.com;************************************org 0x100use16;****************************; Realmode startup code.;****************************start:        xor   ax,ax        mov   ds,ax        mov   es,ax;****************************; enable  A20 line;****************************        pusha        cli                                    ; Disable all irqs        cld        mov   al,255                           ; Mask all irqs        out   0xa1,al        out   0x21,all.5:    in    al,0x64                          ; Enable A20        test  al,2                             ; Test the buffer full flag        jnz   l.5                              ; Loop until buffer is empty        mov   al,0xD1                          ; Keyboard: write to output port        out   0x64,al                          ; Output command to keyboardl.6:    in    al,0x64        test  al,2        jnz   l.6                              ; Wait 'till buffer is empty again        mov   al,0xDF                          ; keyboard: set A20        out   0x60,al                          ; Send it to the keyboard controller        mov   cx,14hl.7:                                           ; this is approx. a 25uS delay to wait        out   0edh,ax                          ; for the kb controler to execute our        loop  l.7                              ; command.        sti        popa;*****************************; Setting up, to enter pmode.;*****************************        cli        lgdt  [gdtr]        mov   eax, cr0        or    al,0x1        mov   cr0,eax        jmp   0x10: protected;*****************************; Pmode. Wink;*****************************use32protected:        mov   ax,0x8         mov   ds,ax        mov   es,ax        mov   ss,ax;*****************************; Turn floppy off (if space).;*****************************        mov   dx,3F2h        mov   al,0        out   dx,al;*****************************; put your code here;*****************************        jmp   $;*************************************; GDT.;*************************************gdt:        dw    0x0000, 0x0000, 0x0000, 0x0000sys_data:   dw    0xFFFF, 0x0000, 0x9200, 0x00CFsys_code:   dw    0xFFFF, 0x0000, 0x9800, 0x00CFgdt_end:gdtr:       dw gdt_end - gdt - 1            dd gdt    

Note: you should assemble the above code as a com file and run it from dos, but it will not return to Dos.
If you want to return to Dos, you can use some of this demo:
http://www.dex4u.com/tuts/DemoVesa.zip
Post 16 Feb 2007, 16:27
View user's profile Send private message Reply with quote
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen 16 Feb 2007, 20:03
Thanks for the answers.
I forgot to say that I use an AMD64, so the real mode and segmentation is not necesary.
I don't need compatibility with 32 bits, I just want to do this only for 64 bits.
Post 16 Feb 2007, 20:03
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 17 Feb 2007, 17:11
Post 17 Feb 2007, 17:11
View user's profile Send private message Reply with quote
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen 17 Feb 2007, 23:00
Dex4u wrote:
Then you should look here:
http://board.flatassembler.net/topic.php?t=6206


Perfect, this is what I was looking for.

thanks.
Post 17 Feb 2007, 23:00
View user's profile Send private message 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-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.