OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Sep 17, 2019 1:00 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Bloody Beginner 3: loading and executing programs
PostPosted: Mon Jul 14, 2008 8:08 am 
Offline

Joined: Tue Jul 08, 2008 11:30 am
Posts: 19
Back again ;)
however, this time I hope with a more interesting philosophical / design discussion - I think there is no straight-forward answer for this, unless I am just #-o

What I want to tackle next is load code into memory (don't even know how to read a disk yet ;) )and then execute it. However, I want to be able to call OS system methods from this code. This implies however that I know the entry addresses of the respective methods - as the OS is still subject to change and as I may potentially even load it to different locations, these addresses are not static though...

Implicitly I have to find a means of identifying the relevant addresses during load / execution. So far I can think of the following methods:

  • Translate all jump / call addresses from a "unique" identifier into the current method addresses during load. This requires an identifier of some sort (a string?) as well as a means to identify the current addresses of the methods (how?). It furthermore requires that the whole code needs to be searched for the according ids.
  • Use something like a translation table to which all method calls in the code jump and from where the actual procedure would be called (like a header). This makes it easier to "translate" the code, still requires IDs and identification of the method addresses though
  • Export the OS functions into a library and link the library into the code during compilation. This is obviously least desirable, as it duplicates all functions and it is difficult to maintain updates.
  • Execute the code in an interpreted fashion, i.e. load into memory but execute step by step and interpret the calls ("just in time compilation"). This is obviously the slowest version, but it would allow code management in the long run (see C#)

What are your opinions? How did you tackle code loading and execution? Or am I just stupid?

Cheers


Top
 Profile  
 
 Post subject: Re: Bloody Beginner 3: loading and executing programs
PostPosted: Mon Jul 14, 2008 8:22 am 
Offline
Member
Member

Joined: Wed Oct 31, 2007 9:09 am
Posts: 1383
hpclutz wrote:
Back again ;)


A few obeservations. First, on the Intel architecture, an OS usually uses ring 0 for kernel code and ring 3 for user code. From ring 3, one cannot call directly into any ring 0 code. The usual solution is to use software interrupts (or, more typical, a single one), but it would also be possible to use call gates. Using the first solution would not need the application to know any address, only the interrupt number. The kernel will fill the IDT, so the application doesn't need to know anything about the address. For a detailed explanation, read the Intel manuals. Secondly, Windows 95 used a method by which an interrupt was, the first time it was called, replaced by a far call. I believe that they did this for speed reasons, as a far call (even through a call gate) is faster than an interrupt (I'm not sure whether they used this method for kernel calls or DLL calls only, memory is fading). Thirdly, the solutions you give seem to imply you haven't thought (or don't care) about protection. You may want to do that though, unless you want a console-type OS like DexOS.


JAL


Top
 Profile  
 
 Post subject: Re: Bloody Beginner 3: loading and executing programs
PostPosted: Mon Jul 14, 2008 8:24 am 
Offline
Member
Member
User avatar

Joined: Thu Sep 28, 2006 10:32 am
Posts: 1309
Location: Slovakia
Well, e.g. DexOS uses a call-table. That's this point you've mentioned,

Quote:
Use something like a translation table to which all method calls in the code jump and from where the actual procedure would be called (like a header). This makes it easier to "translate" the code, still requires IDs and identification of the method addresses though


But the easiest thing to do is just hook a OS interrupt, e.g. my OS hooks INT 30h, and make your own handler, for example your ISR for your OS INT will check AH for "function index number", like this:

Code:
cmp ah,0
je TextInputFunctions
cmp ah,1
je DiskFunctions
...
TextInputFunctions:
cmp al,0
je PrintString
cmp al,1
je PrintChar
...


etc, etc. And you can in AL check for e.g. a "sub function" or some type. It depends how you'll design it. :)
And then, when you have your own working system interrupt with e.g. "print string" which requires ESI to the string, AH=01 and AL=00, you'll execute this in your program:

Code:
mov ah,01    ;e.g. text output fncs
mov al,0        ;e.g. print string
mov esi,TheString
int 30h
...


and it'll print, if you programmed your functions and ISR handler properly. :)

Regards
inflater

_________________
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)


Top
 Profile  
 
 Post subject: Re: Bloody Beginner 3: loading and executing programs
PostPosted: Mon Jul 14, 2008 8:51 am 
Offline

Joined: Tue Jul 08, 2008 11:30 am
Posts: 19
Cool 8) thanks

I must confess, I did think along the line of a pure command line OS (I won't be going commercial anytime soon ;) ) and I have COMPLETELY forgotten about the option to use interrupts ( #-o indeed).

That gives me something to fiddle around with now, so thanks again for your helpful explanations


Top
 Profile  
 
 Post subject: Re: Bloody Beginner 3: loading and executing programs
PostPosted: Mon Jul 14, 2008 10:30 am 
Offline
Member
Member
User avatar

Joined: Fri Jun 27, 2008 8:05 pm
Posts: 162
Location: ND, USA
LBA hard disk access.

EDIT 1: Deleted The "Use LBA28" suggestion.

_________________
OS-LUX V0.0
Working on...
Memory management: the Pool


Last edited by cr2 on Tue Jul 15, 2008 4:25 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Bloody Beginner 3: loading and executing programs
PostPosted: Mon Jul 14, 2008 8:58 pm 
Offline
Member
Member

Joined: Wed Oct 18, 2006 10:43 pm
Posts: 490
Location: Kansas City, KS, USA
cr2 wrote:
LBA hard disk access. (I suggest you use LBA28, LBA48 isn't supported by bochs)


Bochs 2.3.7 supposedly supports LBA48 now.


Top
 Profile  
 
 Post subject: Re: Bloody Beginner 3: loading and executing programs
PostPosted: Mon Jul 14, 2008 9:24 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 22, 2007 12:47 pm
Posts: 1598
Location: New Hampshire, USA
BOCHS 2.3.7 ChangeLog

Quote:
7 - Implemented LBA48 support in BIOS


sweet. 8)

_________________
Website: https://Joscor.com


Top
 Profile  
 
 Post subject: Re: Bloody Beginner 3: loading and executing programs
PostPosted: Tue Jul 15, 2008 5:02 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 07, 2007 1:45 pm
Posts: 1401
Location: Eugene, OR, US
cr2 wrote:
LBA hard disk access. (I suggest you use LBA28, LBA48 isn't supported by bochs)


Last time I looked at Dragoniz3r's code, it had at least one error in it. I think our wiki article is much better: ATA_PIO_Mode.

And bochs has supported LBA 48 in pmode since at least version 2.3.5.


Top
 Profile  
 
 Post subject: Re: Bloody Beginner 3: loading and executing programs
PostPosted: Tue Jul 15, 2008 8:27 am 
Offline
Member
Member

Joined: Wed Oct 18, 2006 10:43 pm
Posts: 490
Location: Kansas City, KS, USA
bewing wrote:
And bochs has supported LBA 48 in pmode since at least version 2.3.5.


That's what I thought, too, but Changelogs never lie. :wink:


Top
 Profile  
 
 Post subject: Re: Bloody Beginner 3: loading and executing programs
PostPosted: Tue Jul 15, 2008 12:54 pm 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2631
Location: Devon, UK
Quote:
7 - Implemented LBA48 support in BIOS


Wouldn't this simply imply new support for LBA48 via the BIOS extended read functions - it could have been available in PMode for a while.

Cheers,
Adam

[edit - rephrase!]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group