Loading applications (ELF) Exo/Pico Kernel.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Loading applications (ELF) Exo/Pico Kernel.

Post by BASICFreak »

Okay, before you start yelling at me to read the wiki... I have a working scheduler, can make new threads, and know how to read an ELF (and even relocate and link said ELF)...

The issue I have is a "chicken and egg" scenario.

The goal at the beginning of the design was ExoKernel but I may have a few more features already so it could be Pico also.

My design is simple and straight forward.
KERNEL space is over 0xE0000000; user space is below.
The Kernel has four (4) functions:
0xF0 - IPC Handler (working mostly complete)
0xF1 - TaskManagement Handler (all but exec working and mostly complete)
0xF2 - Memory Handler (working mostly complete)
0xF3 - API Handler (not even started yet)

Now, I want my OS to use ELF - the only issue is I do not want this to be part of the Kernel, but userland code to phase the ELF.

My understanding of ELF is (for i386) we have upto three sections, .Text, .Data, and .Bss.


So here is my theory:
First module to load will be Binary (so we do not have to phase an elf here)
This binary should install an API to phase ELF then start X thread(s) (X - depends on modules loaded at boot)

To access function 0xF1 (INT) we use AL to determine sub-function (in this case 02h is exec), so we have the following registers free to use:
EBX, ECX, EDX, ESI, EDI (and possibly the high 24 bytes of EAX)

The Kernel will default to .Text being at 0x01000000 - 41000000 (1GB), .Data at 0x41000000 - 61000000 (512MB), and .Bss 0x61000000 - 81000000 (512MB)
The user stack will be between 0xCF800000 and 0xD0000000 (8MB Max)

... So I decided I have two choices (that I could come up with so far):
1) ESI - Entry Point (EIP)
EDI - .Text Start (in current directory)
EBX - .Text Size
ECX - .Data Size
EDX - .BSS Size
Have the ELF phaser align the data perfectly so that the sections are on on top of the other

2) Something similar to the DAP of INT 13h 42h and have:
ESI - Entry Point
EDI - Task Name Pointer (char* null terminated)
EDX - DAP like table pointer.


I guess the question I'm trying to ask is what method would be preferred (doesn't have to be above) and why would it be done that way?

NOTE: This is my first attempt to get 90+% of all functionality into userland. (also it is the first time I had to write an operation manual for my Kernel - whole 3 pages thus far.)

Attached is my operation manual (just in case it helps)
Attachments
BOS 0.0.4 VIRTUAL MEMORY MAP.txt
Virtual Memory Map
(594 Bytes) Downloaded 55 times
BOS 0.0.4 KERNEL SYSTEM CALLS.txt
System Calls
(1.88 KiB) Downloaded 58 times
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Loading applications (ELF) Exo/Pico Kernel.

Post by Combuster »

For userspace loaders and exokernels, you might want to have true kernel calls for the following:
- creating a fresh address space (under the caller's control)
- moving/mapping/copying pages in your address space to the target address space
- create a thread in a different address space.
From there on, you can use any loader to create any new process.

Execute calls can then be handled by a call to the loader.


P.S. it's "parse" instead of "phase", the former being a much more friendly way of treating your code :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Loading applications (ELF) Exo/Pico Kernel.

Post by BASICFreak »

Combuster wrote:For userspace loaders and exokernels, you might want to have true kernel calls for the following:
- creating a fresh address space (under the caller's control)
- moving/mapping/copying pages in your address space to the target address space
- create a thread in a different address space.
From there on, you can use any loader to create any new process.

Execute calls can then be handled by a call to the loader.
That would defiantly make this easier... So to make it short:
Create an address space - that the loader can use.
Fill the address space with "data"
Send the task management system the Page Dir address, EIP, and maybe name pointer

Combuster wrote:P.S. it's "parse" instead of "phase", the former being a much more friendly way of treating your code :wink:
I thought it was the wrong word... lol


And as always (COM)Buster you're the man. It would have taken me a week to think of that one.
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Loading applications (ELF) Exo/Pico Kernel.

Post by BASICFreak »

Again thanks (COM)Buster. That Idea works perfectly.

Code: Select all

BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 331	Function "MEM_Handler"
BOS v. 0.0.4	SRC/i386/memory/virtual.c	Compiled at 15:36:25 on Sep 11 2015 Line 46	Function "_VMM_map"
0xC0004006	0x5000000	0x14	0x0
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 331	Function "MEM_Handler"
BOS v. 0.0.4	SRC/i386/memory/virtual.c	Compiled at 15:36:25 on Sep 11 2015 Line 90	Function "_VMM_umap"
PIT FIRED
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 396	Function "IPC_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
This is a test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Yet another test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Testing EXEC
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
This is a test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Yet another test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Testing EXEC
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
This is a test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Yet another test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Testing EXEC
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
This is a test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Yet another test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Testing EXEC
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
This is a test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Yet another test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Testing EXEC
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
This is a test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Yet another test of FORK
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
Testing EXEC
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 270	Function "TM_Handler"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 214	Function "ThreadManager"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 248	Function "LoadThread"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 331	Function "MEM_Handler"
BOS v. 0.0.4	SRC/i386/memory/virtual.c	Compiled at 15:36:25 on Sep 11 2015 Line 46	Function "_VMM_map"
0xC0004006	0x5000000	0x14	0x0
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 135	Function "IDT_HANDLER"
BOS v. 0.0.4	SRC/taskmanagement.c	Compiled at 16:23:00 on Sep 11 2015 Line 331	Function "MEM_Handler"
BOS v. 0.0.4	SRC/i386/memory/virtual.c	Compiled at 15:36:25 on Sep 11 2015 Line 90	Function "_VMM_umap"
PIT FIRED
Turns out even with a (whole) lot of debug output I get several (exactly 18) switches within 1/18th a second.

Only thing missing now is API Handler - then other than debug and optimizing the Kernel will be done :D
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
Post Reply