Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

protected mode?

Status
Not open for further replies.

Ben3D

Technical User
Apr 22, 2003
6
0
0
GB
Well I'm not having a load of luck mastering protected mode...looked aroudn for some simple tutorials on the subject...but seem to be having problems.

Number of questions...how would I compile a protected mode app using masm and masm's linker?

Also is there a way of creating a binary image..e.g. just the raw binary of the asm...or do I have to compile and link it then use exe2bin?

Well thanx for any help or information to help me :)

Ben
:)
 
Hi Ben3D.

For protected mode examples check out this website:

I think creating a straightforward binary file is dependent on the asm compiler you are using. Sometimes there is an option for doing this in the compiler.
My compiler (TASM) doesn't, which is a pain for writing boot code. Hope that helps.

Adonai :)
 
personally - i have not had any problem in acheiving my aims with TASM v5 - which can be downloaded for free.

alot of protected mode tutorials are quite good but i find alot of them forget to mention the difference between 16bit mode and 32bit mode in regard to the gdt and idt.

when executing a 32bit code segment the gdt and idt can reside anywhere in the 4Gb linear memory (thats logical memory, not physical)

where as...

while executing a 16bit mode code segment the gdt and idt must reside within the 0FFFFFFh boundry. dont know why, dont ask me! it just causes a reset because it cant reference the idt to perform an exception call.

PS - theres no point in programming a protected mode system unless you fully incorporate paged memory. only then you will apreciate the full extent of protected mode memory management.

the OS that i have designed and written puts the GDT and IDT at the very far end of the 4Gb to make available a maximum segment size of 4Gb less 640k per task. how ever for 16bit code segments i designed and wrote a 32bit to 16bit mask capsul that would move the gdt and idt to within the 0FFFFFFh boundary before performing the task switch or far jump to 16bit code segment and ofcorse reverse the process on return from 16bit code segment. using page memory this is a very simple function to perform.

good luck on perfecting you protected mode system :)
any specific questions - just ask :)
straiph


"There are 10 types of people in this world, those who know binary and those who don't!"
 
thinking about it tho - i might redesign the linear map so the gdt and idt start from 0000:0000 so i wouldnt need to juggle the gdtr and idtr around when a change of code size occurs.

this would also bring benifits to the global code area which i have specifically designed to reduce the number of unneccessary task switches.

fantastic!!!! thanks for the little bit of inspiration.

anyway....

i compile my asm to exe.
then use a exe2bin to convert it to pure binary.
i had to remove alot of error checking stuff like no entry point, no stack etc etc.
i then use another program that i wrote - this writes these files to the disk and updates the filing system.
my OS then uses these pure binary files as normal.
once i have written an assembler for my OS the above procedure will become obsolete as the binary will be formated directly to the disk.

my OS tasks require a 16 byte header.
8 bytes - place holders for relative jump to program code.
4 bytes - size of stack in bytes
4 bytes - task status control bits used for comunication between task and system during execution.

upon execution the following are created - TSS:already alotted in global space as all TSS are available at all times. LDT (64k) ,PD (4k) and 2xPTs (8k) created. if 4k pages are used the 76k is reserved for the task skeleton. if page size is set to 64k (default) then 128k of memory is reserved. the stack size is determined and 4 stacks are created (1 for each level of protection) and LDT and TSS updated (additional pages are reserved for the stacks). the code size is determined and addtional memory reserved, LDT updated with code and data selectors - TSS updated with all segments set. code is loaded into memory. EIP is always zero upon first switch to task hence the 16byte header.
the largest code segement executable is 4Gb less 640k.
640k consists of GDT,IDT,TSS definition space and global system code space.

the multiplexer handles either the iret or irq2. will put the current task to bed and wakes the next to be serviced.

ofcorse this isnt exhaustive but im just trying to give you an idea of what is expected for a protected mode system to be able to load and execute 32bit task executable files.

straiph


"There are 10 types of people in this world, those who know binary and those who don't!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top