Running x86 embedded platform in 32bit protected mode.

Started by SteveCurtis, June 10, 2009, 01:21:46 AM

Previous topic - Next topic

SteveCurtis

Hello All,

Interested in setting up PC architecture as an embedded system to run 32 bit protected mode applications. The emphasis is on Digital Signal Processing and the capacity to have hardware interrupts providing input and output, (AtoD, DtoA, Encoders etc) as jitter free as possible, just as I might with a simple 8051 or a DSP system.  Main interest is servo control with 3phase brushless motors with quadrature encoders prviding positionla information. Other interests are DSP control systems and adaptive control systems, using the numerical hardware on the P.C.

Have just got Jean j. Labrosse "MicroKernel/OSII" book with CD and also "Realtime Concepts" by Qing Li and Caroline Yao. These go into quite a bit of detail, so there is some reading there.. Basically I want to be able to boot into my own application that handles all traffic. User information and command I/O will be thru serial port. No display, No keyboard, No disk I-O required. Essentially I want to be able to get to the processing and memory of the PC without having to design a WDM driver for compatibility with Windows.

Running under DOS 6.22 already gives me what I want, but at 16bits with reduced memory, unless I use DPMI. Therefore If I use DPMI, why don't I go the next step and design an assembler boot strapper that will launch me straight into protected mode and be done with it? I'm quite happy to run the system as a crippled device. Many people have not quite understood this in past dealings on the forum. If necessary, screen output could still be arranged as formatters like printf() can be recompiled and also the address of the screen is known. If I wanted keyboard, the kbd interrupt could still be mapped in protected mode using IDT's, so I don't think I will do without everything. Disk IO will be more of a problem, but I am going to boot from DOS 6.22 and from a floppy or memory stick.
After that, when in 32bit PM , disk could be an issue, but that is not my chief concern.

Any ideas or history with this type of project?

Steve

Steve


dedndave

i think i would look at other "minimal" os's and see what they are doing
of course, it is nice just to get into protected mode, for starters

http://www.osdcom.info/content/view/28/38/
http://www.osdever.net/tutorials/pm.php

SteveCurtis

Quote from: dedndave on June 10, 2009, 02:49:05 AM
i think i would look at other "minimal" os's and see what they are doing
of course, it is nice just to get into protected mode, for starters

http://www.osdcom.info/content/view/28/38/
http://www.osdever.net/tutorials/pm.php

Hi Dave,
Thanks for sticking with me on this craziness  :eek So I have plenty of reading and digesting with the 2 books I got plus your links.

These sites are invaluable. THanks heaps fpr these contacts and links. More than I could have hope for. :U

I will start by writing a one way boot into 32bit protected mode. I have no real desire to write a fully functional OS (yet) and this does seem to be something many people have already attempted. I only need enough functionality to go the next step-- boot and run am application in 32 bit protected mode. When I get there, the view may change, of course!!!

I will be off the air from now until a couple of weeks or so. Tomorrow I go into hospital (11th June) to have a melanoma secondary cancer removed from my left lung. Thoracic surgery is often painful, so I may not be able to do much too soon. This is my second metatsitis in the lung from a primary on my right arm (lower bicep), the last one being removed in August 28, 2008. I'm about fed up with surgery, but it beats not being here to play!!  :wink

In the meanwhile, thanks for taking an interest and supporting my 'quest' .... Back in a few weeks, maybe sooner.
Regards,
Steve


dedndave

yah - you'll have your hands full getting a 32-bit app to run
as for the OS, start with the basics
get a command line interpreter going so you can read the keyboard and see text on the screen
that way, you can type in a file name
then, you need some disk i/o to get files
then, get it to load a PE exe file (this will be the fun part)
another approach might be to create your own PE-like file spec
of course, your exe must not have any api calls without a kernel that supports them
i think i would start really simple
write a 32-bit program that adds two numbers together and displays the result
once you have that up and running, you can play with I/O

SteveCurtis

Quote from: dedndave on June 10, 2009, 12:54:59 PM
yah - you'll have your hands full getting a 32-bit app to run
as for the OS, start with the basics
get a command line interpreter going so you can read the keyboard and see text on the screen
that way, you can type in a file name
then, you need some disk i/o to get files
then, get it to load a PE exe file (this will be the fun part)
another approach might be to create your own PE-like file spec
of course, your exe must not have any api calls without a kernel that supports them
i think i would start really simple
write a 32-bit program that adds two numbers together and displays the result
once you have that up and running, you can play with I/O

Dave,
Yep entirely with you on the approach. It's pretty much how I did my 8051 and z80 stuff in the past. Build on 'Hello World' and on then on wards to the stars......

The attendant parts on setting up LDT GDT's and IDT's plus the required instructions sequences to set segment registers and such all seems to be variously documented in many sites. I have read and downloaded some text from a Uni course at University of Illinois at Urbana-Champaign that is quite detailed. I also have  "Comprehensive PMode Tutorials with C & ASM  by Alexei A. Frounze (c) 2000" that does what I want in general. The main thing is to avoid to plagiarisation by 'cut and paste'. The issue is to understand the theory by text book and by example, then to cut your own code. In this way one can have a show of debugging and enhancing what you are doing. Learn by understanding, (not by copy and paste -- as this teaches you little!!)

Cut & Paste is for so called 'script kiddies' :toothy

Turning in now. Away for the next few weeks. See you then.

Regards
Steve










dedndave

i suggest a good BIOS reference also
phoenix has a few docs
and, of course, you are going to want to be an expert on pentiums
intel has a million docs

FORTRANS

Hello,

   I would think that as a first cut, you could try what they call Unreal Mode.
Essentially you boot DOS, go into protected mode, set some segment selectors
to 32-bit mode, and return to real mode.  That way you can use DOS to
handle the hard drive access, and still have large memory access.

   Comp.lang.asm.x86 and alt.os.development should have threads on that.

HTH,

Steve N.

SteveCurtis

Quote from: FORTRANS on June 10, 2009, 03:29:08 PM
Hello,

   I would think that as a first cut, you could try what they call Unreal Mode.
Essentially you boot DOS, go into protected mode, set some segment selectors
to 32-bit mode, and return to real mode.  That way you can use DOS to
handle the hard drive access, and still have large memory access.

   Comp.lang.asm.x86 and alt.os.development should have threads on that.

HTH,

Steve N.

I have seen this mentioned in my travels. Good idea too. I am also interested in the lack of background interrupts and such giving rise to jitter on the timing train when my tick for I-O approaches 20Khz or therebouts.

BTW (Surgery for today has been postponed util next Tuesday [surgeon is ill] so I've got the weekend to read!)

Thanks,
Steve

japheth


Hi Steve,

for DOS+PE the hx dos extender might be interesting:

http://www.japheth.de/HX.html

RDOS (DOS-like OS with PE) is probably worth a look as well:

http://www.rdos.net/rdos/


japheth

Farabi

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

SteveCurtis

Quote from: dedndave on June 10, 2009, 01:25:34 PM
i suggest a good BIOS reference also
phoenix has a few docs
and, of course, you are going to want to be an expert on Pentiums
Intel has a million docs

Hi Dave, Yes I have now downloaded the P4 documents, user manuals, programmers references and a couple of others. I also did the same for the 486/386. You are right about there being zillions of docs, Wholly-cow, so to speak!

I think I have enough Docs for just now, however I'm sure that I will be able to sift the Intel site again in a few weeks, don't need everything at once.

At this point I have finished the Jeff Duntemann book on assembler up to the point where he goes into 32 bits using Linux, I think I may stall there as I really don't want to have to learn a complete other environment just now, although I did load Linux onto one machine and run the examples and have a small play, Linux is not where I will stray just yet.

What I DO have now delivered from Amazon, the day before I had surgery (surgery was last Tuesday 16th June) are two books:

1) "MicroC/OS-II The Real Time Kernel Second Edition". Jean J. Labrosse. A book about a pre-emptive real time operating system ported to the x86 platform. It is just 'so' detailed and goes into all the sorts of things I need to know. There is all the good stuff about registering tasks, event control blocks, hardware interrupts, mutexes, messaging, thread management and outputting data and interfacing to hardware.. the cats whiskers really. Plus the full operational code for a realtime OS so I can code in C++ or assembler and link the whole shebang into a single executable image if I want. Just what I imagined or hoped I might be able to do.

2) "Real-time concepts for embeded systems". Qing Li and Caroline Yao. This is more of a general textbook about the theoretical parts of embedded programming and the breakdown of components in an embedded system. It defines embedded systems and how programming for them differs from normal user programming. As such, it is an invaluable tool as many of the lingering ideas and half baked solutions to potential problems I have flagged for myself are here discussed in formal detail and given names and solutions.

Now there is no excuse!  :lol

I've also found my original "Writing Windows Device Drivers" By Dekker and Newcomer, plus "Undocumented NT" by Prasad Dabak, Sandeep Phadke and Milind Borate. So the retinue of good texts is slowly aggregating. Just now have to spend some time focused on these tasks and not solving the worlds political problems :naughty: ......... :wink

Kind Regards,
Steve










dedndave

there is a lot to the pentium that we don't see in day-to-day programming, even assembler
that is the stuff you will want to learn
control registers, gdt's, security rings, exceptions - all the fun stuff

i think if we had to learn all that stuff to write a program, it would discourage many of us
i am learning it, a little at a time
you need to learn it all at once - lol
i don't envy you, however, you will be a better programmer for it

SteveCurtis

Quote from: dedndave on June 21, 2009, 02:02:11 AM
there is a lot to the pentium that we don't see in day-to-day programming, even assembler
that is the stuff you will want to learn
control registers, gdt's, security rings, exceptions - all the fun stuff

i think if we had to learn all that stuff to write a program, it would discourage many of us
i am learning it, a little at a time
you need to learn it all at once - lol
i don't envy you, however, you will be a better programmer for it

Hi Dave,

I think there is a time for everything too. On the back of what I have done over the years, the 'new stuff' regarding IDT's and GDT's Ring levels and the whole descriptor table scene shows the way of doing things in PM and is where the OS meets the processor.  So cool to find these things come down to recognisable lines of assembler code when they have been hidden from you, the ring 3 applications programmer for so long!!

What I am finding though, as I discover stuff, I start to ask why this, or why that? And that's when I start to feel good becuase we are in real 'learn mode'. The act of finding answers will lead to otherwise unimaginable questions etc... Learning is so much fun really, especially when you have a definite goal at the end. The relief of a discovery that has been bugging for some time is very satisfying.

I did find the Alexei Frounze tutorials about protected mode, a mine of good information. However the code exemples always needs a context to really 'get going'. Like when you learn math (we call it maths -- with an 's' for some reason) you are never told the final usage of your multiplication tables, or the algebraic evaluation rules. But then you discover calculus and without these truths automatically inserted in your brain, the rest would be impossible to see any sense in. I just wish our teachers could have given a glimpse of what was to come so we did not get bored with all those math excersises! (ah well maybe these days it's different..)

In the same vein, the Frounze tutorials are fine but still need to be repeated at a later time. Just running them doesn't prove anything of course. I'm looking forward to writing my own kickoff code and from first principles, setting up a bootable PM application, without cut and paste anywhere. Just me and the programmers manual.. Then I'll break out the champagne!

I agree with you, this will make me a better programmer. The trick is to have the time to 'go the detail'. Our work places are always on about productivity, which can lead to short term-ism and one often ends up going backwards in the 'real skill tool box' department.

Trick and tips are fine and I love using & finding them, but nothing will beat solid understanding. That's what I want to use my time for again now. You probably may know that I'm not actually working just now as I'm getting over an operation. I can still sit and type though and it makes the day go so quickly!

Nice to talk with you Dave,

Kind regards,
Steve





hackerlabs

You might wanna check this book out.
It's a real help - and the author's written this library just for use in embedded environments.

http://www.amazon.com/Fundamentals-Embedded-Software-Where-Assembly/dp/0130615897/ref=sr_1_3?s=books&ie=UTF8&qid=1280152036&sr=1-3

All the best!