OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 12:06 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: How to execute PE apps in Kernel?
PostPosted: Fri Nov 29, 2019 11:36 pm 
Offline

Joined: Fri Nov 29, 2019 11:26 pm
Posts: 13
Hello, i am developing an Operating System. Now i want to execute some PE files. I have no idea on the code. Can anyone please help me with the code? I am following OSDEV tutorials. Please help. [-o< [-o< [-o<


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Sat Nov 30, 2019 2:23 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
Which part of these steps do you need help with?

Since you're new here, I recommend reading this post to make sure you're familiar with the fundamentals of OS development. Welcome!


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Tue Dec 03, 2019 9:00 pm 
Offline
User avatar

Joined: Mon Apr 30, 2018 2:24 am
Posts: 3
Location: The Stallion project
Do yourself a favor and start with ELF - much simpler to get a simpler implementation. If you're insistent on PE, though, Microsoft has good docs about the format. Be prepared to use paging to map pages to virtual addresses.

_________________
Another OSDev hopeful, just like you.

Project | Github | Twitter | Website


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Mon Dec 16, 2019 8:15 am 
Offline

Joined: Fri Nov 29, 2019 11:26 pm
Posts: 13
Sorry for late reply....

I have some knowledge on them i read them in Brokenthorn Entertainment and Even in OSdev Wiki, But i donot have idea on code. Please help me in coding it.


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Mon Dec 16, 2019 8:16 am 
Offline

Joined: Fri Nov 29, 2019 11:26 pm
Posts: 13
And sorry, now i migrated to program my OS in assembly.

But it would be helpful if i get assembly code.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Mon Dec 16, 2019 9:05 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
motosftos wrote:
And sorry, now i migrated to program my OS in assembly.

Bad move.


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Mon Dec 16, 2019 11:02 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1590
motosftos wrote:
Sorry for late reply....

I have some knowledge on them i read them in Brokenthorn Entertainment and Even in OSdev Wiki, But i donot have idea on code. Please help me in coding it.

This sounds like the guy who wanted to make a game, and had a good idea, so now he only needs someone to do the artwork, music, sounds, mechanics, and programming for him.

If you have an understanding of the file formats and of your OS, no code is needed, since that would just be a description of how to connect the two. And if you lack understanding of either the file format or your OS, no code can help you fix that.

Executable file formats are mostly about mapping memory and then having the code execute. In order for the code to do anything useful, it needs to talk to your OS. So, in order for this to be important at all, you already need working pmem allocator, paging, vmem allocator, multitasking, FS driver, partition table driver, HDD driver, and this will more than likely include a working interrupt system and DMA allocator. By the time you have all of this, the executable file format should be but a side note.

Also, please be advised that all of this will only work, if you have new executables to run, linked against a libc that works for your OS. Emulating an existing OS's system call interface is going to be difficult at best. I mean, Korona's Managarm is compatible with Linux (no small feat), and ReactOS tries to be compatible with Windows, and that endeavour is still in progress.

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Tue Dec 17, 2019 6:11 am 
Offline

Joined: Fri Nov 29, 2019 11:26 pm
Posts: 13
I migrated to assembly because i don't have much knowledge compared to assembly.

@nullplan, I actually wanted to boot the kernel written in assembly.

I want to boot the kernel from stage2 bootloader.

I used
Code:
extern _osstart
and in Kernel written in assembly i used
Code:
Global _osstart:


but when i compile it with this,:-

ld -melf_i386 -Ttext=0x9000 -nostdlib --nmagic -o stage2.elf stage2.o os.o

i get
boot/stage2.asm:(.text+0xba): undefined reference to `_osstart'

So why i asked it. Please help.


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Tue Dec 17, 2019 7:25 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
Hi,

motosftos wrote:
Hello, i am developing an Operating System.
Please don't get this the wrong way, but you are clearly not up to the task. Do yourself a favour, and start with some smaller projects first. Do experiments on each component, and when you're okay with them, only then try to put everything together into an OS. And learn. There's extremely huge amount of theory behind OSdev you must be familiar with. It is said that OSdev is the most difficult task a programmer can do, and they say that for a good reason.

motosftos wrote:
I have no idea on the code. Can anyone please help me with the code?
No. You must have at least an idea what you want to do, nobody can help you with that. When the idea is clear, then, and only then you can start coding. These things are not magic, nobody is able to code something without knowing what and how it supposed to do. (And in that I don't mean "load the OS", I mean how it should exactly work to the smallest detail.)

A simple thing that loading the kernel can be divided into many steps:
1. how your initializer code gets loaded by the firmware (first sector? EFI executable? to which address? in which CPU mode?)
2. how can you use the available environment to load a file from disk (can you use interrupts? do you need to load raw sectors or does the firmware provide file abstraction?)
3. how to parse that file (is it a PE or ELF executable at all? does it have more segments? what's phdr and bss?)
4. how to set up the environment for that executable (does it need stack? special mapping? is it position independent?)
5. how to pass control to that executable (what ABI? does it differ to the usual one? Linux kernel for example has a special kernel entry ABI, and GRUB gives you another.)

So many things to figure out and solve, and let me remind you, all of the above is needed and must be 100% correct before the CPU could start executing the first instruction at _osstart: label. And I haven't spoken about how to create that kernel executable (which is different to normal user space applications) before you could save it to disk for your loader to find. And everything I wrote so far are totally independent to in which language your kernel was written in. Could be Assembly, or could be C. I've even seen some (pretty good may I add) kernels written in Pascal.

Cheers,
bzt


Last edited by bzt on Tue Dec 17, 2019 7:36 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Tue Dec 17, 2019 7:33 am 
Offline

Joined: Fri Nov 29, 2019 11:26 pm
Posts: 13
Thanks @bzt.

Can you please refer me any sources to learn that in you tube? i have tried many, but they did not satisfy. I use to read OSdev but if they are visual(video), i can easily understand. -Sorry for bad english


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Tue Dec 17, 2019 7:44 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
motosftos wrote:
Can you please refer me any sources to learn that in you tube?
I know that it wasn't your intention, but that's actually an insult. OSdev can't be learned from a youtube tutorial. Most of us spent years if not decades to learn the OSdev things, there are countless hours of painful trial-and-error experiments behind us to get the knowledge you seek. No youtube video can give you that.

Start the old-fashioned way: buy a book, read it, try to understand it, then write small programs putting the theory you've learned into practice. Tannenbaum's Modern Operating Systems would be a good start, but there are many other perfect books. When you've understood the theory, and you gained some experience with it in practice, then start downloading and reading hardware specifications. Those are a different kind of beasts, but you also have to learn them and learn how to control them. Most specification is a PDF book. What is common in all quality OSdev materials, neither of them is a youtube video.

A good collection of related books: https://github.com/concerttttt/books/ (Modern Operating Systems included). Also books on C and C++ programming and compiler theory.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Thu Dec 19, 2019 6:45 am 
Offline

Joined: Fri Nov 29, 2019 11:26 pm
Posts: 13
Thanks


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Thu Dec 19, 2019 10:02 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 18, 2009 5:47 pm
Posts: 208
Location: Alexandria, Egypt | Ottawa, Canada
motosftos wrote:
Please help. [-o< [-o< [-o<

This really touched my heart. This article is a good start.


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Thu Jan 23, 2020 6:26 am 
Offline

Joined: Fri Nov 29, 2019 11:26 pm
Posts: 13
@bzt link is not working


Top
 Profile  
 
 Post subject: Re: How to execute PE apps in Kernel?
PostPosted: Thu Jan 23, 2020 10:15 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
motosftos wrote:
@bzt link is not working

It was when I wrote that post. That's not my repo, I'm afraid there's not much I can do about it. Use your search skills, that's what I did. I'm sure you can find those books elsewhere too.

Cheers,
bzt


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 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