OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Apr 28, 2024 1:15 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Is there a way to tell the OS to use an offset at runtime
PostPosted: Mon Jul 31, 2023 11:25 am 
Offline

Joined: Mon Mar 06, 2023 10:25 am
Posts: 4
I am trying to do something like paging but without really using paging, is it possible?
i have created multitasking and process creation,

to give you an idea when i create a task i allocate memory for it for example half a megabyte and put the program there and jump to it, when i allocate the memory it could by for example at 0x1000000

and when i compile a program and install it on my kernel it runs as it should but the addresses for memory as
Quote:
char * str = "RUNNING";
get normal addresses as 0x1817 and when i try to print it (for example) the CPU searches for that address( 0x1817) that is incorrect, it should be
Quote:
0x1817 + 0x1000000(the program offset)


Is there a way to fix this


Top
 Profile  
 
 Post subject: Re: Is there a way to tell the OS to use an offset at runtim
PostPosted: Mon Jul 31, 2023 12:01 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
Marques wrote:
I am trying to do something like paging but without really using paging, is it possible?
i have created multitasking and process creation,

to give you an idea when i create a task i allocate memory for it for example half a megabyte and put the program there and jump to it, when i allocate the memory it could by for example at 0x1000000

and when i compile a program and install it on my kernel it runs as it should but the addresses for memory as
Quote:
char * str = "RUNNING";
get normal addresses as 0x1817 and when i try to print it (for example) the CPU searches for that address( 0x1817) that is incorrect, it should be
Quote:
0x1817 + 0x1000000(the program offset)


Is there a way to fix this

Pretty sure what your trying to do just wouldn't work. Just implement paging. It's confusing and annoying and massively over-engineered and over-complicated (and I feel like there's probably a much better way of doing it that *doesn't* involving confusing recursive data structures that break your brain) but, alas, it's what you have to do.


Top
 Profile  
 
 Post subject: Re: Is there a way to tell the OS to use an offset at runtim
PostPosted: Mon Jul 31, 2023 12:50 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
Marques wrote:
I am trying to do something like paging but without really using paging, is it possible?

Yes, it's possible. It's called relocation. Your binary needs to include appropriate relocation information, and your loader needs to apply that information when it loads your binary.

But why don't you want to use paging?


Top
 Profile  
 
 Post subject: Re: Is there a way to tell the OS to use an offset at runtim
PostPosted: Mon Jul 31, 2023 12:51 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
Octocontrabass wrote:
Marques wrote:
I am trying to do something like paging but without really using paging, is it possible?

Yes, it's possible. It's called relocation. Your binary needs to include appropriate relocation information, and your loader needs to apply that information when it loads your binary.

But why don't you want to use paging?

Oh, I hadn't realized the OP was trying to do reloc, I thought they were trying to hack around paging or do it in some software way.


Top
 Profile  
 
 Post subject: Re: Is there a way to tell the OS to use an offset at runtim
PostPosted: Mon Jul 31, 2023 1:07 pm 
Offline

Joined: Mon Mar 06, 2023 10:25 am
Posts: 4
Octocontrabass wrote:
Marques wrote:
I am trying to do something like paging but without really using paging, is it possible?

Yes, it's possible. It's called relocation. Your binary needs to include appropriate relocation information, and your loader needs to apply that information when it loads your binary.

But why don't you want to use paging?


i dont want to use paging becouse i found it to complex for a simple idea as setting a offset to the cpu, the simple idea of adding a simple offset to all addresses comming into the cpu is enough to create the idea of virtual memory and program isolation.

Can you talk more about relocation please?


Top
 Profile  
 
 Post subject: Re: Is there a way to tell the OS to use an offset at runtim
PostPosted: Mon Jul 31, 2023 1:13 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
But you can't enforce isolation that way. Any program can access memory that belongs to any other program.


Top
 Profile  
 
 Post subject: Re: Is there a way to tell the OS to use an offset at runtim
PostPosted: Mon Jul 31, 2023 1:16 pm 
Offline

Joined: Mon Mar 06, 2023 10:25 am
Posts: 4
Octocontrabass wrote:
But you can't enforce isolation that way. Any program can access memory that belongs to any other program.


yeah thats true thats a thing i will see later for now i would just need to make this work


Top
 Profile  
 
 Post subject: Re: Is there a way to tell the OS to use an offset at runtim
PostPosted: Tue Aug 01, 2023 6:23 am 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 852
Marques wrote:
i dont want to use paging becouse i found it to complex for a simple idea as setting a offset to the cpu, the simple idea of adding a simple offset to all addresses comming into the cpu is enough to create the idea of virtual memory and program isolation.

That's called segmentation. On x86, you implement it by allocating an LDT for every process, which will contain segments for every module in the process. This way, no relocations are needed, but calling functions in other modules becomes more involved.


Top
 Profile  
 
 Post subject: Re: Is there a way to tell the OS to use an offset at runtim
PostPosted: Tue Aug 01, 2023 7:47 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4597
Location: Chichester, UK
Paging is simpler than other ways of doing this. (Relocation is a whole lot more complicated.) Paging has other advantages too.

If you are working with x86 type processors and you want to use 64-bit mode (and who wouldn't?) you have to use paging anyway.

The fun of OS development is working with the things that seem difficult and finding out that they are really rather simple and elegant.


Top
 Profile  
 
 Post subject: Re: Is there a way to tell the OS to use an offset at runtim
PostPosted: Thu Aug 03, 2023 1:46 pm 
Offline
Member
Member
User avatar

Joined: Mon May 22, 2017 5:56 am
Posts: 817
Location: Hyperspace
Some older languages were designed to run directly on hardware and may have built-in multitasking. Some of these have only high-level data types and bounds-check all array access. These in practice create process isolation without hardware support, though the bounds-checking slows down all array accesses.

_________________
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie


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], SemrushBot [Bot] and 30 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