every body:
i write a boot loader use nasm,and work in real mode,i open a20 line,
after that ,i want access 1M memory,then use follow:
mov esi, 100000h
mov al,byte
,but cpu is run at this ,it is die,i must restart machine,who can help me
Posted on 2003-05-18 10:03:31 by bgcq
I think you have to set-up GDT to access beyond 1M.
Posted on 2003-05-18 10:11:40 by bitRAKE
google for "unreal mode", "voodoo mode", "flat real mode", (et cetera)

Also, http://www.nondot.org/sabre/os/articles
Posted on 2003-05-18 10:31:07 by f0dder
Access it Directly Via-Port. Its uneasy, also painFull. What is limit 17FF mean guys ?




Gdt dw 17FF
dd 00008000


Posted on 2003-05-18 18:16:28 by realvampire
You COULD ask XMS (Extended Memory Service, NOT EMS which is ExPANded Memory Service), if available, to copy data from real memory to extended memory above 1MB.

Some BIOS's also have this service to copy from real to extended memory.

Direct access to extended memory REQUIRES protected mode. In fact, XMS will switch to protected, then switch back to real mode (on 286's, this is done by doing a partial reset, i.e. only the processor is reset without resetting any other chips, via a line controlled by the keyboard controller).

An alternative is to turn on the A20 line, set a seg register (e.g. DS) to 0FFFFh, and set an index register from between 10h to 0FFFFh, this allows you to access 65520 bytes of extended memory.
Posted on 2003-05-18 22:08:03 by AmkG
What is limit 17FF mean guys ?


it means: last byte of last entry in table pointed by next DWORD

entries * sizeof (GDTENTRY) - 1, aka 768 * 8 - 1

but usually you'll need not more than 4 entries in the GDT.
It makes no sense to me, using more than 3 segment types.

Bye Miracle
Posted on 2003-05-19 03:20:00 by miracle
code:--------------------------------------------------------------------------------

Gdt dw 17FF
dd 00008000


--------------------------------------------------------------------------------


Actually, a GDT entry is 8 bytes. What you show here looks like a segment:offset 6 byte value in which case you have entry 2ff in the LDT that has a priority of 3.
__________________
Posted on 2003-05-20 12:42:00 by djinn
I believe the best and easiest way is to use an Extended Memory Manager. But you can't access memory directly so if I were in your position I would use a spare segment in where I can plop all the data from the XMS memory because using HIMEM you can not access memory directly but have to use a interrupt interface.
Posted on 2003-05-20 17:44:23 by x86asm
Sorry miracle, technicaly you are correct. And if the label had been GDTR instead of GDT I would not have contradicted.

The complete answer is that the limit is the byte granular number of entries in the table, up to a max of 64k.

realvampire's example means that his table contains 768 entries.

If there were 3 entries as you prefer, the limit value would be 001f
Posted on 2003-05-20 18:45:51 by djinn
Hi,

its easy using this GDT:



xGlobal: dw 4 * 8 - 1
dd xFlatten + 07E00h

xFlatten: db 0, 0, 0, 0 ; dummy
db 0, 0, 0, 0

dw 0FFFFh ; 4GB code
dw 00000h
dw 09A00h
dw 000CFh

dw 0FFFFh ; 4GB data
dw 00000h
dw 09200h
dw 000CFh

dw 0FFFFh ; 4Gb stack
dw 00000h
dw 09200h
dw 000CFh


consider that 07E00h is the address where this code resides.

This GDT gives you a code, data and stack segment over 4 GigaBytes
load it via lgdt, enable A20, set bit 0 in cr0 and do a jump to enter PMode.
It is without paging and you can access the memory without 1M Limit

ofcourse you have to check first how many physical memory is installed
on your machine.

Bye Miracle
Posted on 2003-05-21 04:32:40 by miracle

Hi,

its easy using this GDT:



xGlobal: dw 4 * 8 - 1
dd xFlatten + 07E00h

xFlatten: db 0, 0, 0, 0 ; dummy
db 0, 0, 0, 0

dw 0FFFFh ; 4GB code
dw 00000h
dw 09A00h
dw 000CFh

dw 0FFFFh ; 4GB data
dw 00000h
dw 09200h
dw 000CFh

dw 0FFFFh ; 4Gb stack
dw 00000h
dw 09200h
dw 000CFh


consider that 07E00h is the address where this code resides.

This GDT gives you a code, data and stack segment over 4 GigaBytes
load it via lgdt, enable A20, set bit 0 in cr0 and do a jump to enter PMode.
It is without paging and you can access the memory without 1M Limit

ofcourse you have to check first how many physical memory is installed
on your machine.

Bye Miracle


The HexCode please. I dont understand this. What is xFlatten Mean ? What about a Com File? To Which address I should pointed it ? so it only 4 entries ? Okay I got it, Thanks.
Posted on 2003-05-21 11:11:25 by realvampire
Hi,

xGlobal is just to pointer to be passed in lgdt. xFlatten is just the start of the descriptor tables.
The example illustrates a dummy (always used) a code segment wit h read and excute priviledges
and a stack/data segment with read-write priviledges. Note that all segments span over the
entire 4 GB. It's up to you to implement paging additionally since using only a GDT like above doesn't
bring any safety at all.

For detailed information on how to construct a GDT refer to: here and
here

Bye Miracle
Posted on 2003-05-22 04:33:47 by miracle
Why it Wont work? I have loa the IDT and GDT, but it still triple fault. Why ?
Posted on 2003-05-22 17:17:57 by realvampire
:cool:

I never had a triple fault :)

Do you know when the triple fault happens?
What is the Opcode being assembled for the final jump?
Why to set the segment registers before the jump, I'd
prefer to do it just after.
What do you want to do with the code between 'lmsw'
and the final jump. I wouldn't place any code there.
I miss a 'cli' before enabling A20 and entering PMode.
If you do that you don't need a IDT that time. This can be
done if you reached the PMode (aka. Elysium)

Keep on trying. My one works great :)

BTW. Its pain to read your source, not because of the code
or the logic but of the layout, arrangement, labelling etc.
Posted on 2003-05-23 04:12:17 by miracle

:cool:

I never had a triple fault :)

Do you know when the triple fault happens?
What is the Opcode being assembled for the final jump?
Why to set the segment registers before the jump, I'd
prefer to do it just after.
What do you want to do with the code between 'lmsw'
and the final jump. I wouldn't place any code there.
I miss a 'cli' before enabling A20 and entering PMode.
If you do that you don't need a IDT that time. This can be
done if you reached the PMode (aka. Elysium)

Keep on trying. My one works great :)

BTW. Its pain to read your source, not because of the code
or the logic but of the layout, arrangement, labelling etc.


Im 'or' the Word status. It always restarted each time It executed LMSW code. Why? is it because the LIDT? can I have your compiled File?. Did you see 5 nop there (db 909090....)? that nop will be modified by it self to be a jump far instruction, thats why the set register I put there, and then jump to the main program at 8000 .
The final jump opcode is CS:IP + 5. Is it okay call a function after turn on the PE ?
Yes My compiler have not able to support label yet.
Posted on 2003-05-23 08:40:30 by realvampire
Hi,

this works, atleast for me :)



:0001.0034 FA cli
:0001.0035 B080 mov al, 80
:0001.0037 E670 out 70, al
:0001.0039 E81E02 call 025A
:0001.003C E84502 call 0284
:0001.003F E8B202 call 02F4

:0001.02F4 66 BYTE 066h
:0001.02F5 660F011E7306 lidt [0673]
:0001.02FB 66 BYTE 066h
:0001.02FC 660F01167906 lgdt [0679]
:0000.0302 66 BYTE 066h
:0001.0303 0F BYTE 0fh
:0001.0304 20C0 and al , al
:0001.0306 0C01 or al, 01
:0000.0308 66 BYTE 066h
:0001.0309 0F BYTE 0fh
:0001.030A 22C0 and al , al
:0001.030C EB00 jmp 030E
:0001.030E 90 nop
:0001.030F 6766EA001001000800 jmp 0008:00011000



disable interrupts even NMI (non mascable interrupt)
lidt only points to three word with zero
lgdt points to the data described in a thread above
66h, 0Fh, 20H, C0h, 0Ch, 01h, 66h, 0Fh, 22h, C0h
means mov eax, cr0 - or eax, 1 - mov cr0, eax

interesting is the last jump:

it uses segment 8 which is my code segment entry in GDT
my kernel resides at 11000h in memory

Bye Miracle
Posted on 2003-05-23 09:13:54 by miracle
Thats what I want. But what is prefix 66 used for before lgdt ?
Posted on 2003-05-23 09:20:23 by realvampire
Hi,

good question, please another one :rolleyes:

Bye Miracle
Posted on 2003-05-23 09:21:54 by miracle
Is LGDT default imm adress is 32-Bit? 0f01E0 [00000000] ? if not why you put 66 prefix ?
Posted on 2003-05-23 09:26:18 by realvampire
Hi

I like real time conversation :)

I got this info from my assembly book. Unfortunately it
does not explain why I have to use it, so I just do it as long
as this works.

Normally I'm not satisfied when I don't understand what some
pieces are for but at this particular point I gave up.

If I understand your question right. My GDT resides as
data in the segmented (64k) memory as part of the loader.
I guess it's not neccessary. My Code is relocated to zero
that why I do xFlatten + 07E00h since my loader is loaded to 0000:7E00h

Bye Miracle
Posted on 2003-05-23 09:33:08 by miracle