Is there a way to tell the OS to use an offset at runtime

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
Marques
Posts: 4
Joined: Mon Mar 06, 2023 10:25 am
Libera.chat IRC: Marques

Is there a way to tell the OS to use an offset at runtime

Post by Marques »

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
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
0x1817 + 0x1000000(the program offset)
Is there a way to fix this
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: Is there a way to tell the OS to use an offset at runtim

Post by Ethin »

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
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
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.
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Is there a way to tell the OS to use an offset at runtim

Post by Octocontrabass »

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?
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: Is there a way to tell the OS to use an offset at runtim

Post by Ethin »

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.
Marques
Posts: 4
Joined: Mon Mar 06, 2023 10:25 am
Libera.chat IRC: Marques

Re: Is there a way to tell the OS to use an offset at runtim

Post by Marques »

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?
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Is there a way to tell the OS to use an offset at runtim

Post by Octocontrabass »

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

Re: Is there a way to tell the OS to use an offset at runtim

Post by Marques »

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
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: Is there a way to tell the OS to use an offset at runtim

Post by Gigasoft »

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.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Is there a way to tell the OS to use an offset at runtim

Post by iansjack »

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.
User avatar
eekee
Member
Member
Posts: 891
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: Is there a way to tell the OS to use an offset at runtim

Post by eekee »

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
Post Reply