physical address

Programming, for all ages and all languages.
Post Reply
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

physical address

Post by i586coder »

Hi to all,

it's very long time since my last post here, in fact it's exams :P

anyway, i have some trouble with physical address in memory :shock:

in some modules in my previous kernel (e.g SVGA ) depend on segmentation (real mode), you know in this case i have only less than 1 MB, so i began convert those modules to un-real mode, the code look like this

Code: Select all

enableA20();
initFlat(); //setup GDT,...

asm{ .386p //protected mode
     mov edi, 0xB8000 //<---
     mov FS:[edi],'A'
}
this code will print A in Konsole(where 0xB8000= 0xB800*0x10+offset),
but i don't know how to access the memory beyond 1 MB,
in other word what is the physical address to memory above 1 MB ?

to access the second mega byte in memory what i should type in address

Code: Select all

dword address= 0x???????? ;//pointer to second megaByte and so on
asm{ .386p //protected mode
     mov edi, address
     mov FS:[edi],'A'
}
any suggestion :!: ...

Cheers :mrgreen:
a.T.d
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
Hangin10
Member
Member
Posts: 162
Joined: Wed Feb 27, 2008 12:40 am

Re: physical address

Post by Hangin10 »

If you're in UnReal Mode, accessing physical memory doesn't require the use of segments, but they probably still add to the address, so it's most useful (or just plain easier) to zero the segment registers, and use the address size prefix (the assembler will do this for you) in order to do 32bit addressing (in UnReal Mode, you still have 16bit code).

The physical address for anything is just the physical address. The second megabyte is 0x100000, third 0x200000, etc, all the way up to however many physical address bits the processor supports.

(You speak of unreal mode, and then the comments say protected mode; which is it?)
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: physical address

Post by i586coder »

first of all, thank you for replying,... :D

i will check it right now :idea:
Hangin10 wrote: (You speak of unreal mode, and then the comments say protected mode; which is it?)

hmmm, about the comment

Code: Select all

.386p //protected mode
this directive is necessary to enable 32bit opcode in turbo C++ 3.1 e.g (LIDT,.... FS:[],GS:[],....)
since TC is 16bit compiler, & i need some 32bit opcodes

Cheers: ,
a.T.d
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
Hangin10
Member
Member
Posts: 162
Joined: Wed Feb 27, 2008 12:40 am

Re: physical address

Post by Hangin10 »

i586coder wrote:this directive is necessary to enable 32bit opcode in turbo C++ 3.1 e.g (LIDT,.... FS:[],GS:[],....)
since TC is 16bit compiler, & i need some 32bit opcodes
First, there's no difference in opcodes between 16 and 32 bit. If you're in a 16bit mode, a prefix byte is added before the instruction to make it 32bit, and if you're in a 32bit mode, the same prefix byte makes it a 16bit instruction.

If you're in UnReal Mode, this is going to cause problems, because you've told the assembler to make 32bit code when you're in a 16bit mode so it's not going to use the prefix byte needed. The code is actually using just DI rather than EDI, because you're assembler did not add the prefix byte because it thinks the default is 32 bits, when it's 16.

Sorry if this doesn't make much sense, I'm getting rather hungry and lunch isn't for another .5 hours :)
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: physical address

Post by bewing »

1. To be in Unreal mode, you need to have switched temporarily to 16bit pmode, and set up at least one segment register to point to a 16bit gdt entry, that points to upper memory.

2. When you switch back to Real mode, you cannot overwrite that segment register -- you need to use the values that were saved into it, when it was in pmode.

3. Use the ADDRESS SIZE override prefix (not the opcode override!) AND the segment register to access upper memory, with a 32bit address register (ebx, esi, edi, ebp).
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: physical address

Post by i586coder »

Hangin10 wrote:
i586coder wrote:this directive is necessary to enable 32bit opcode in turbo C++ 3.1 e.g (LIDT,.... FS:[],GS:[],....)
since TC is 16bit compiler, & i need some 32bit opcodes
First, there's no difference in opcodes between 16 and 32 bit. If you're in a 16bit mode, a prefix byte is added before the instruction to make it 32bit, and if you're in a 32bit mode, the same prefix byte makes it a 16bit instruction.
well, i used this code in 16bit compiler

Code: Select all

    asm db  0x66   
    asm mov di,word ptr Address //MOV   EDI,Address   
    asm db  0x67                         //32 bit Address Prefix   
    asm db  0x64                         //FS:   
    asm mov byte ptr [BX],al        //=MOV FS:[EDI],AL   
is the code above solve the problem :?:
bewing wrote: To be in Unreal mode, you need to have switched temporarily to 16bit pmode, and set up at least one segment register to point to a 16bit gdt entry, that points to upper memory.
I think my GDT_Table ,isn't bad to point upper memory :idea:

Code: Select all

unsigned long   GDT_Table[]=   {   
    0,0,                                         //NULL   - 00H   
    0x0000FFFF,0x00CF9A00,      //Code32 - 08H Base=0 Limit=4G-1 Size=4G   
    0x0000FFFF,0x00CF9200       //Data32 - 10H Base=0 Limit=4G-1 Size=4G   
};   


initFlat(){
 ;
 ;
 asm LGDT    GDT_Table
 :
 :
 // jump to protected mode & return
}
CheerS,
a.T.d
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
Post Reply