OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 10:57 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Does Minix require hardware paging?
PostPosted: Tue Feb 06, 2018 9:06 pm 
Offline

Joined: Tue Feb 06, 2018 9:01 pm
Posts: 6
Hi there.

I am designing a CPU and minicomputer system from scratch, using solely the 74HC series of integrated circuits, and when I am finished building it, I want to install the Minix operating system on it.

To this end I need to know if Minix requires any form of hardware memory paging/management ? Or is it possible for it to manage that itself via software?

My address bus itself is 24bits, and my program counter is also 24bits. Any area of memory can be accessed at any time, which means no protection at all for processes.

Does Minix then provide the protection and management ?

Or do I really need to implement paging in hardware?

I know almost nothing about OS design and this is why I ask. I will have to learn from scratch in the future.

I appreciate your help.

Thank you.

Paulo


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Wed Feb 07, 2018 12:49 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
That is an ambitious project!

To port Minix to your custom CPU you are going to have to completely understand the OS. As chance would have it, its implementation is documented in the book "Operating Systems: Design and Implementation". Get a copy and you will find it answers all of your questions.


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Wed Feb 07, 2018 2:39 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
AnalogChipDesigner wrote:
To this end I need to know if Minix requires any form of hardware memory paging/management ?

The original one (for 8086/8088 from 1987) does not. The latest (for 80386+ or ARM) does.

AnalogChipDesigner wrote:
Or is it possible for it to manage that itself via software?

If some 100 times slower is OK with you, sure, you can emulate anything in software.


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Wed Feb 07, 2018 3:13 am 
Offline
Member
Member

Joined: Tue May 13, 2014 3:02 am
Posts: 280
Location: Private, UK
alexfru wrote:
The original one (for 8086/8088 from 1987) does not. The latest (for 80386+ or ARM) does.


Or, to use version numbers; 1.x and 2.x do not, 3.x does. You may also come across "minix-vmd" which was a fork of 2.x that added such things as paging and X11 support. I believe it was i386 only.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Wed Feb 07, 2018 7:25 am 
Offline

Joined: Tue Feb 06, 2018 9:01 pm
Posts: 6
mallard wrote:
alexfru wrote:
The original one (for 8086/8088 from 1987) does not. The latest (for 80386+ or ARM) does.


Or, to use version numbers; 1.x and 2.x do not, 3.x does. You may also come across "minix-vmd" which was a fork of 2.x that added such things as paging and X11 support. I believe it was i386 only.




So Minix version 2 does not require hardware paging then ? I would be happy with installing Minix 2.

Can anyone explain to me how this process works in Minix ? There's no need to go into too much detail about it. I just want to get a feel for how it works.


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Wed Feb 07, 2018 7:52 am 
Offline
Member
Member

Joined: Tue May 13, 2014 3:02 am
Posts: 280
Location: Private, UK
AnalogChipDesigner wrote:
So Minix version 2 does not require hardware paging then ? I would be happy with installing Minix 2.


That's correct. I've personally run Minix 2 on an 80186-based system (paging was only added to the x86 architecture with the 80386). Surprisingly usable considering the limitations of such a system (640KB RAM, 8Mhz CPU).

AnalogChipDesigner wrote:
Can anyone explain to me how this process works in Minix ? There's no need to go into too much detail about it. I just want to get a feel for how it works.


By "this process", do you mean memory management? From memory (a little hazy) of having read Andrew S Tanenbaum's Operating Systems Design and Implementation (aka "the Minix book") revision 2 and having played with Minix a bit quite a number of years ago is that the 2.x version could be compiled for 8086 real-mode and 80386 32-bit protected mode. It didn't use paging in any mode (that only came with the "-vmd" fork and, later, version 3). I believe it used classical segmentation; i.e. each program had one or more code segments and one or more data segments. There was no memory protection in real-mode (it's simply not possible) so the fully-implemented UNIX security model was little more than "advisory". Even in 80386 mode, I wouldn't trust an educational OS to be security hardened (although apparently Intel disagree there, for version 3 anyway...).

I think there was a swapping mechanism that allowed complete segments to be swapped out to disk when not in use, but that's about as advanced as it got.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Wed Feb 07, 2018 9:21 am 
Offline

Joined: Tue Feb 06, 2018 9:01 pm
Posts: 6
mallard wrote:
AnalogChipDesigner wrote:
So Minix version 2 does not require hardware paging then ? I would be happy with installing Minix 2.


That's correct. I've personally run Minix 2 on an 80186-based system (paging was only added to the x86 architecture with the 80386). Surprisingly usable considering the limitations of such a system (640KB RAM, 8Mhz CPU).

AnalogChipDesigner wrote:
Can anyone explain to me how this process works in Minix ? There's no need to go into too much detail about it. I just want to get a feel for how it works.


By "this process", do you mean memory management? From memory (a little hazy) of having read Andrew S Tanenbaum's Operating Systems Design and Implementation (aka "the Minix book") revision 2 and having played with Minix a bit quite a number of years ago is that the 2.x version could be compiled for 8086 real-mode and 80386 32-bit protected mode. It didn't use paging in any mode (that only came with the "-vmd" fork and, later, version 3). I believe it used classical segmentation; i.e. each program had one or more code segments and one or more data segments. There was no memory protection in real-mode (it's simply not possible) so the fully-implemented UNIX security model was little more than "advisory". Even in 80386 mode, I wouldn't trust an educational OS to be security hardened (although apparently Intel disagree there, for version 3 anyway...).

I think there was a swapping mechanism that allowed complete segments to be swapped out to disk when not in use, but that's about as advanced as it got.



Yes my friend I mean memory management.

I am an electronics engineer, and i have little experience in OS design. I have been building CPU's at home as a hobby for about a year now. After having successfully built my first 8bit CPU, I am now designing a new 16bit one. A much more ambitious project, with support for interrupts and traps. It's similar to Bill Buzzbee's Magic-1 design.

Like him, I would love to run Minix 2 on my system, and Bill Buzzbee designed hardware paging in his system, so Minix would run faster I guess.

I do not know much about paging and so I thought Minix required paging in hardware by default.

So I you said it doesn't because it could be compiled to the 8086. And you said minix 2 uses segmentation.

How does segmentation work in terms of processes? Each process has a list of segments that it has access to? And the OS keeps track of what process has access to what segments, and keeps a list of this in memory ? So if I support segmentation in my system, then Minix could use the segments to manage the processes instead of paging ?

When a process is running, the OS loads the required segments into the segment registers, and when required it changes the segments? Sometimes a process needs to change its segment registers, and it's the OS's task to change them?


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Wed Feb 07, 2018 2:08 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

AnalogChipDesigner wrote:
So I you said it doesn't because it could be compiled to the 8086. And you said minix 2 uses segmentation.

How does segmentation work in terms of processes? Each process has a list of segments that it has access to?


For 8086 and 80186, unfortunately not. There was no protection, everything has full access to all segments, and the only thing segments do is effect physical address generation. Specifically, "physical address = segment << 4 + offset" was used so that a pair of 16-bit values can access 1 MiB of physical address space.

For later CPUs (starting with 80286) segmentation got extended to support protection and different segment sizes - the old "segment numbers" got recycled as indexes into tables, where the table provides the base address, limit and attributes for the segment. For that case there's multiple models - a process could have a few segments (e.g. one for code, one for data, one for stack), or a process could use many segments (e.g. one for each separate piece of memory allocated), etc.

AnalogChipDesigner wrote:
And the OS keeps track of what process has access to what segments, and keeps a list of this in memory ? So if I support segmentation in my system, then Minix could use the segments to manage the processes instead of paging ?


There was no paging until 80386; and almost all OSs that use paging and don't use segmentation. I would assume that this is the same for Minix 2 (that if it's compiled for 80386 it uses paging and doesn't use segments, and if it's compiled for 80186 or 8086 it uses segments and doesn't use paging).

AnalogChipDesigner wrote:
When a process is running, the OS loads the required segments into the segment registers, and when required it changes the segments? Sometimes a process needs to change its segment registers, and it's the OS's task to change them?


Does it really matter? If your CPU (and everything else - PIC, PIT, PS/2 controller, firmware/BIOS, ...) is "100% PC compatible" then your hardware is going to be compatible with OSs that were designed for PC and it won't matter how the OS uses things like segments; and if your CPU is not compatible then you're going to have to modify/port (or write) a compiler and an operating systems to make them work and it won't matter how the OS used things like segments on 80x86 (or 680000 or SPARC, which were also supported by different versions of MINIX and had very different memory management).


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Thu Feb 08, 2018 2:21 am 
Offline
Member
Member

Joined: Thu Jul 05, 2007 8:58 am
Posts: 223
Brendan wrote:
AnalogChipDesigner wrote:
And the OS keeps track of what process has access to what segments, and keeps a list of this in memory ? So if I support segmentation in my system, then Minix could use the segments to manage the processes instead of paging ?


There was no paging until 80386; and almost all OSs that use paging and don't use segmentation. I would assume that this is the same for Minix 2 (that if it's compiled for 80386 it uses paging and doesn't use segments, and if it's compiled for 80186 or 8086 it uses segments and doesn't use paging).


Minix does not use paging. Both minix 2 and 3 don't do anything with paging, regardless of whether you run them on 8086/80186 or 80386+, unless you use a variant modified significantly beyond the OS presented in the books.


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Thu Feb 08, 2018 2:46 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

davidv1992 wrote:
Brendan wrote:
AnalogChipDesigner wrote:
And the OS keeps track of what process has access to what segments, and keeps a list of this in memory ? So if I support segmentation in my system, then Minix could use the segments to manage the processes instead of paging ?


There was no paging until 80386; and almost all OSs that use paging and don't use segmentation. I would assume that this is the same for Minix 2 (that if it's compiled for 80386 it uses paging and doesn't use segments, and if it's compiled for 80186 or 8086 it uses segments and doesn't use paging).


Minix does not use paging. Both minix 2 and 3 don't do anything with paging, regardless of whether you run them on 8086/80186 or 80386+, unless you use a variant modified significantly beyond the OS presented in the books.


Here's "pgutils.c" in the official Minix 3 source code, with a whole pile of stuff for paging. I don't know about Minix 2.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Thu Feb 08, 2018 6:58 am 
Offline
Member
Member

Joined: Thu Jul 05, 2007 8:58 am
Posts: 223
Hmm, did some digging, and it seems that was added some point around the 3.1.4 release of minix, right around the point where minix 3 seems to have turned away from the system taught in the books to what was needed for the research done on reliability. The book version (3.1.0), did not have paging. The best reference I have found for this timeline is the wikipedia article on minix3, which unfortunately is terse and relies on references to pages that are cached only on website, and whos originals seem to be long gone. Still, I would count 3.1.4 as a variant significantly modified as the OS presented in the books.


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Thu Feb 08, 2018 7:14 am 
Offline

Joined: Tue Feb 06, 2018 9:01 pm
Posts: 6
davidv1992 wrote:
Brendan wrote:
AnalogChipDesigner wrote:
And the OS keeps track of what process has access to what segments, and keeps a list of this in memory ? So if I support segmentation in my system, then Minix could use the segments to manage the processes instead of paging ?


There was no paging until 80386; and almost all OSs that use paging and don't use segmentation. I would assume that this is the same for Minix 2 (that if it's compiled for 80386 it uses paging and doesn't use segments, and if it's compiled for 80186 or 8086 it uses segments and doesn't use paging).


Minix does not use paging. Both minix 2 and 3 don't do anything with paging, regardless of whether you run them on 8086/80186 or 80386+, unless you use a variant modified significantly beyond the OS presented in the books.




So if it does not use hardware paging, does it require any other hardware feature ? Does it require memory segmentation? Or does it manage everything itself via software? Someone said here that managing things by software will be 100 times slower, specially on my homebrew minicomputer because its maximum clock speed is 4MHz. However, if Minix 2 doesn't even care for paging, which would speed-up its execution, then if I add paging to my MMU then it won't make a difference.

What would be the best solution for my project? Should I simply support segmentation by adding in the four segment registers, CS, DS, SS, and ES, and let Minix 2 do whatever it wants with it?

Will it run at any tolerable speeds in a 4MHz CPU?


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Thu Feb 08, 2018 7:53 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
I'd suggest not to add x86-like segmentation. It provides very weak protection (it can only protect the kernel from the user-space but not different user-space programs in the same address space) and is not used at all in today's OSes.

It is not necessary to support protection at all to get some basic OS running. After that works, you can always add a simple form of paging (e.g. have a certain RAM range contain a linear virtual -> physical mapping, without multi-level page tables).

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Thu Feb 08, 2018 8:04 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

AnalogChipDesigner wrote:
So if it does not use hardware paging, does it require any other hardware feature ? Does it require memory segmentation?


All operating systems for 80x86 require segmentation. Some ancient operating systems (MS-DOS) and all boot code designed for BIOS uses real mode segmentation; and almost all modern operating systems use protected mode segmentation and/or long mode segmentation (even if it's configured for "effectively disabled", with all segment bases set to zero and all segment limits set to "max", it's still used). Most modern operating systems also use two segments (FS and GS) for special purposes (thread local storage and "per CPU" kernel data). This does include 64-bit/long mode (even though often people mistakenly say that long mode doesn't support segmentation, it's still used for determining code size and for those special segments, and is still partially used).

Note that real mode segmentation is very different to protected mode segmentation (and long mode segmentation is like protected mode segmentation with parts of most segments ignored and a few other changes).

AnalogChipDesigner wrote:
Or does it manage everything itself via software? Someone said here that managing things by software will be 100 times slower, specially on my homebrew minicomputer because its maximum clock speed is 4MHz. However, if Minix 2 doesn't even care for paging, which would speed-up its execution, then if I add paging to my MMU then it won't make a difference.


If you add paging to your MMU then it'd make a lot more sense to use a different OS (e.g. a recent version of Minix 3) that does use paging.

AnalogChipDesigner wrote:
What would be the best solution for my project? Should I simply support segmentation by adding in the four segment registers, CS, DS, SS, and ES, and let Minix 2 do whatever it wants with it?

Will it run at any tolerable speeds in a 4MHz CPU?


Realistically the only thing that matters is whether you have fun. It doesn't matter if it never works; doesn't matter if there's never any devices, firmware, OS or other software; and doesn't matter how slow it is.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Does Minix require hardware paging?
PostPosted: Thu Feb 08, 2018 1:13 pm 
Offline

Joined: Tue Feb 06, 2018 9:01 pm
Posts: 6
All I am doing is pre 186. I am bring up a system with power matching the 8086. What I am missing is only the segment registers, which is the last piece of the design. So all I am doing is in real mode. There is no protection anywhere.

What I need to know if Minix 2 used paging and from the replies I am receiving here it seems like it doesn't except in version 3 upwards.

The following question then is, does minix 2 use the segment registers ? Does Minix 2 provide any memory protection between programs at all ? Am I making a confusion here by thinking that it's the OS that should protect processes from each other rather than the CPU itself ?

in other words, is there a way for the OS to isolate processes from each other ? Or is this task only able to be done by the CPU?

I myself don't actually see a way for an OS to protect processes from each other, unless it changes the processes' code and checks memory bounds.

Does Minix check memory bounds in a process and if it goes outside it's allowed zone, blocks it from going there?




If the answer is no, that there is no way to isolate processes via software, then it must mean that Minix 2 does not provide such protection, and that if I simply implement the segment registers DS, CS, SS, ES, then my minicomputer will be able to run Minix 2 without problems.

Can anyone please tell me the answer to those questions? I think the most important thing here is whether Minix 2 can isolate processes itself without needing to rely on the CPU to do this.


Forgive my ignorant in the workings of an OS. I am an electronics engineer and totally ignorant of this area. I will start reading the Minix 2 book, but I appreciate it anyone could help me here.


Thank you!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

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