Page 1 of 1
Is there a way to tell the OS to use an offset at runtime
Posted: Mon Jul 31, 2023 11:25 am
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
Re: Is there a way to tell the OS to use an offset at runtim
Posted: Mon Jul 31, 2023 12:01 pm
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.
Re: Is there a way to tell the OS to use an offset at runtim
Posted: Mon Jul 31, 2023 12:50 pm
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?
Re: Is there a way to tell the OS to use an offset at runtim
Posted: Mon Jul 31, 2023 12:51 pm
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.
Re: Is there a way to tell the OS to use an offset at runtim
Posted: Mon Jul 31, 2023 1:07 pm
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?
Re: Is there a way to tell the OS to use an offset at runtim
Posted: Mon Jul 31, 2023 1:13 pm
by Octocontrabass
But you can't enforce isolation that way. Any program can access memory that belongs to any other program.
Re: Is there a way to tell the OS to use an offset at runtim
Posted: Mon Jul 31, 2023 1:16 pm
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
Re: Is there a way to tell the OS to use an offset at runtim
Posted: Tue Aug 01, 2023 6:23 am
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.
Re: Is there a way to tell the OS to use an offset at runtim
Posted: Tue Aug 01, 2023 7:47 am
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.
Re: Is there a way to tell the OS to use an offset at runtim
Posted: Thu Aug 03, 2023 1:46 pm
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.