Should I follow Linux structure/functionalities?

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
Thpertic
Member
Member
Posts: 56
Joined: Sun Sep 16, 2018 6:46 am

Should I follow Linux structure/functionalities?

Post by Thpertic »

I've been working on my os for a little, but now I'm thinking about kind of restarting the project following one of the earlier Linux release. I didn't do so much things: I only set up a GDT, initialized the terminal and half of the memory manager (just physical).
Is it insane? I can find something about kernel 2.4 and above but it is still too complicated for now and I'd like a documentation or an explanation about the 1.0 kernel or even 0.x. Thanks to everyone
FusT
Member
Member
Posts: 91
Joined: Wed Sep 19, 2012 3:43 am
Location: The Netherlands

Re: Should I follow Linux structure/functionalities?

Post by FusT »

Documentation on the linux kernel is pretty much non-existing, unfortunately. The code itself is a mix of coding styles and conventions, mostly without any comments.
You can find all versions of the linux kernel on https://www.kernel.org/, download a version you'd like to get familiar with and start reading.

POSIX is pretty well documented so writing a linux-comaptible OS without copying any of the big heap of sh*t the linux kernel actually is might be a lot easier.

I'm not saying I don't like linux, I use and enjoy it daily. It's just that the code is a horrible mess.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Should I follow Linux structure/functionalities?

Post by iansjack »

Perhaps you would find Minix easier to follow. It is very well documented.
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: Should I follow Linux structure/functionalities?

Post by glauxosdever »

Hi,


It depends on your project goals. Do you want to do an OS compatible to Linux (or Linux-based)? Then do that. Maybe following POSIX would be easier for a start, rather than following Linux as a whole. Or maybe, you want to do a Linux distribution; if so, please see Linux From Scratch.

There isn't really any "right" or "wrong" here. A lot of people here are doing Unix-like OSes (which is fine, two of the most popular and admired OSes here, ToaruOS and Sortix, are Unix-like); these people usually do that to learn POSIX and/or to be able to port external software to their OSes, even if it's not optimal. On the other side, some people here are doing custom OS designs (which is fine, and I'm also going to do that after restarting OS development); these people usually want to experiment with something different. How security could be better (or worse), how performance could be better (or worse), how programming could be easier (or harder), etc. It depends on various factors: e.g. what do you feel like doing, how much time do you have, what do you want to achieve from OS development, etc. In short, it's up to you.


Regards,
glauxosdever
Thpertic
Member
Member
Posts: 56
Joined: Sun Sep 16, 2018 6:46 am

Re: Should I follow Linux structure/functionalities?

Post by Thpertic »

I do want to make my own OS, not a Linux distro. I've read some of the POSIX documentation, but there is a list with all the functions source code. I mean, it is right to make a standard, but I started this project to learn not to copy. this means that I shouldn't follow the POSIX rules but should do it all by myself, right?
nullplan
Member
Member
Posts: 1801
Joined: Wed Aug 30, 2017 8:24 am

Re: Should I follow Linux structure/functionalities?

Post by nullplan »

Thpertic wrote:I do want to make my own OS, not a Linux distro. I've read some of the POSIX documentation, but there is a list with all the functions source code. I mean, it is right to make a standard, but I started this project to learn not to copy. this means that I shouldn't follow the POSIX rules but should do it all by myself, right?
POSIX defines an interface. Implementation is up to you. For instance, POSIX does not define which of the interfaces is a system call and which is a library call. They might all be library calls. In fact, Cygwin is a library for implementing POSIX on top of Windows.

For example, POSIX defines that each process has one global working directory. I am a bit torn on this, but I think I'll implement this as a file descriptor: If you ditch open() et al. and only implement openat() as syscalls, then the CWD can just be an FD. As can the root. Only trouble is, most POSIX programs expect to inherit 3 FDs from their parent process, not 5, so either I would use some high-numbered predefined slots for these (which doesn't sit well with me as it imposes a ceiling on the number of FDs that otherwise wouldn't be there), or I have to translate between POSIX FDs and the FDs of my OS. Oh well, I guess for starters the first approach wouldn't be too bad.

POSIX also defines that a process is a container for threads, and the threads are actually running things, but Linux didn't care about this for a long time, and the "tasks" they have currently are some weird pick-and-mix between the two concepts.
Carpe diem!
FusT
Member
Member
Posts: 91
Joined: Wed Sep 19, 2012 3:43 am
Location: The Netherlands

Re: Should I follow Linux structure/functionalities?

Post by FusT »

I don't really see following a standard as "copying" as long as you don't actually copy any sourcecode.
The specification gives you an interface, how you implement it is up to you. That's not copying anything imho.
Thpertic
Member
Member
Posts: 56
Joined: Sun Sep 16, 2018 6:46 am

Re: Should I follow Linux structure/functionalities?

Post by Thpertic »

Ok, but how and where should I start then? It's too big the documentation and I can't start writing a random function and then spread to the others...
nullplan
Member
Member
Posts: 1801
Joined: Wed Aug 30, 2017 8:24 am

Re: Should I follow Linux structure/functionalities?

Post by nullplan »

POSIX deals with userspace, so you should design your userspace such that it will be possible to emulate the basic definitions of POSIX on it. For instance, POSIX defines what a process is, what a thread is, etc., so you need to think about these concepts yourself. How do you want to deal with tasks? Copy POSIX's design wholesale or make some tweaks that a userspace library has to sort out?

As for getting started: Before POSIX becomes important at all, you already need to have:
  • Multitasking
  • VFS
  • Whatever file systems
  • Volumes
  • Disk drives
  • Output devices
  • Input devices
  • System calls
running. That's quite a handful. Only then do you even have an environment any userspace can run in at all. That's quite a bit of ways you can go without looking at POSIX at all.
Carpe diem!
Thpertic
Member
Member
Posts: 56
Joined: Sun Sep 16, 2018 6:46 am

Re: Should I follow Linux structure/functionalities?

Post by Thpertic »

I think that the memory manager should be running too, right?
nullplan
Member
Member
Posts: 1801
Joined: Wed Aug 30, 2017 8:24 am

Re: Should I follow Linux structure/functionalities?

Post by nullplan »

Thpertic wrote:I think that the memory manager should be running too, right?
Well, that kinda goes without saing. The rest really depends on it.
Carpe diem!
User avatar
zaval
Member
Member
Posts: 659
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: Should I follow Linux structure/functionalities?

Post by zaval »

Thpertic wrote:I've been working on my os for a little, but now I'm thinking about kind of restarting the project following one of the earlier Linux release. I didn't do so much things: I only set up a GDT, initialized the terminal and half of the memory manager (just physical).
Is it insane? I can find something about kernel 2.4 and above but it is still too complicated for now and I'd like a documentation or an explanation about the 1.0 kernel or even 0.x. Thanks to everyone
It's a waste of time. Personally, I don't like linux, I think it's a mediocre, of very poor quality piece of bloat. But it doesn't matter what I think, what does - the documentation, there is no such a thing in the "open source" world. they don't care. You would be faced with the mess of its code, and that's all. huge, non-structurized, it's unbearably useless and painfully unsuitable as a reference for an OS developing. Moreover, and it's my opinion, and position, I've told about already here, - I even avoid learning about linux internals to not screw up my understanding of how OSes work. good ones. You know, it's like advices to not learn "bad" languages, or not read "bad" books on the good languages. The same is for OS. linux is a "bad" OS. especially for learning and borrowing from it. One should get his/her hands dirty in the linux source only if they love the latter unconditionally and don't have anything better to do and still want to participate in its "evolving". :mrgreen:
And given this quote of you:
I do want to make my own OS, not a Linux distro.
You seem to have the answer for you question already.

POSIX is not a linux at all. It's an API specification for those who worships unix or wants to make their OS run POSIX programs.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
StudlyCaps
Member
Member
Posts: 232
Joined: Mon Jul 25, 2016 6:54 pm
Location: Adelaide, Australia

Re: Should I follow Linux structure/functionalities?

Post by StudlyCaps »

@Thepertic:
I find that early Linux source can be useful as a reference of an actual implementation of some basic concepts in x86, things like syscalls, page and context management can be difficult to implement when you have no working examples. However to limit yourself to a Linux-like or POSIX system is to neglect the biggest learning experiences in OS-dev IMO, which is to design your own techniques and mechanisms by which system and application interact.

I find this repo https://github.com/kalamangga-net/linux-1.0 to be a decent resource. It's a clone of the original 1.0 release of Linux. Obviously it's not a good example of how things should be done, but seeing one way of solving a problem can sometimes help you to form your own solutions.

@zavel:
I agree with every criticism you raise of Linux. I am curious though what you would consider a "good" OS by comparison?
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Should I follow Linux structure/functionalities?

Post by SpyderTL »

If you want your OS to have compatibility with existing Linux applications, then you should use the POSIX API standards. If you want your OS to have compatibility with existing Linux drivers, you should use the Kernel module driver structure.

Otherwise, you are free to design your own system. I started from scratch, specifically because I wanted my design to make sense to me, rather than be influenced by other designs that may be going on 50 years old. The end result turned out to be something fairly similar to the Linux layout, so I probably would have saved years of effort if I had just started there, but I'm still glad that I went down that road, because I have a much better understanding and appreciation for both Linux and Windows.

I guess the moral is that as long as you are working in ASM and C (or probably even C++), your design will probably resemble Linux to some extent.

Just out of curiosity, what would you guys say is the most "alien" OS design compared to Linux and all of the other typical designs? On the surface, I'd say Haiku looks like it would be fairly different, internally, but I haven't actually looked into the internals that much.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply