Jump to content

linux

goatedpenguin

I am trying to build an os from scratch and wanted to look at Linux source code for some reference but I do not know where to find the source code ty in advance 🙂

 

Link to comment
Share on other sites

Link to post
Share on other sites

You can also checkout freeBSD: https://cgit.freebsd.org/src/

The Darwin source code is here: https://github.com/apple/darwin-xnu

 

But one thing about all three of these (though less so for Darwin), is that they're huge. 

 

Maybe look for something smaller to start with. Something like Arduino can be an easy way into learning about writing an OS.

Link to comment
Share on other sites

Link to post
Share on other sites

I am assuming you are pretty fresh with programming, since this is a pretty easily searchable question (one of the first results when I search 'Linux source code')

 

Check out OSdev wiki. You honestly are not going to gain much insight into how to develop an os from looking at the linux kernel unless you are already very very knowledgeable about the topic.

 

I also suggest reading Modern Operating Systems.

 

Learn about real/protected mode. How the boot sector works, interrogating the BIOS, VGA text mode. Learn ASM for your target architecture. Cross compiling (you will need to build C for your target arch.)

 

There is a few months of solid work if you are serious about OS architecture before you get to the point of looking up other operating system sources for reference material.

 

 

If your question is answered, mark it so.  | It's probably just coil whine, and it is probably just fine |   LTT Movie Club!

Read the docs. If they don't exist, write them. | Professional Thread Derailer

Desktop: i7-8700K, RTX 2080, 16G 3200Mhz, EndeavourOS(host), win10 (VFIO), Fedora(VFIO)

Server: ryzen 9 5900x, GTX 970, 64G 3200Mhz, Unraid.

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Takumidesh said:

I am assuming you are pretty fresh with programming, since this is a pretty easily searchable question (one of the first results when I search 'Linux source code')

 

Check out OSdev wiki. You honestly are not going to gain much insight into how to develop an os from looking at the linux kernel unless you are already very very knowledgeable about the topic.

 

I also suggest reading Modern Operating Systems.

 

Learn about real/protected mode. How the boot sector works, interrogating the BIOS, VGA text mode. Learn ASM for your target architecture. Cross compiling (you will need to build C for your target arch.)

 

There is a few months of solid work if you are serious about OS architecture before you get to the point of looking up other operating system sources for reference material.

 

 

I did search that on the web but did not find the GitHub repo strangely thanks anyways

Link to comment
Share on other sites

Link to post
Share on other sites

16 hours ago, Takumidesh said:

I am assuming you are pretty fresh with programming, since this is a pretty easily searchable question (one of the first results when I search 'Linux source code')

 

Check out OSdev wiki. You honestly are not going to gain much insight into how to develop an os from looking at the linux kernel unless you are already very very knowledgeable about the topic.

 

I also suggest reading Modern Operating Systems.

 

Learn about real/protected mode. How the boot sector works, interrogating the BIOS, VGA text mode. Learn ASM for your target architecture. Cross compiling (you will need to build C for your target arch.)

 

There is a few months of solid work if you are serious about OS architecture before you get to the point of looking up other operating system sources for reference material.

 

 

tysm for all ur help 

Link to comment
Share on other sites

Link to post
Share on other sites

16 hours ago, Takumidesh said:

I am assuming you are pretty fresh with programming, since this is a pretty easily searchable question (one of the first results when I search 'Linux source code')

 

Check out OSdev wiki. You honestly are not going to gain much insight into how to develop an os from looking at the linux kernel unless you are already very very knowledgeable about the topic.

 

I also suggest reading Modern Operating Systems.

 

Learn about real/protected mode. How the boot sector works, interrogating the BIOS, VGA text mode. Learn ASM for your target architecture. Cross compiling (you will need to build C for your target arch.)

 

There is a few months of solid work if you are serious about OS architecture before you get to the point of looking up other operating system sources for reference material.

 

 

I am not going to be using c at all and will use python and use a coding language that I have been developing from scratch and my target architure is for arm, x86 and amd64, 32 bit etc. basically cross compatibility in every way possible 

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, swabro said:

I am not going to be using c at all and will use python and use a coding language that I have been developing from scratch and my target architure is for arm, x86 and amd64, 32 bit etc. basically cross compatibility in every way possible 

Sorry to burst your bubble but you wont write the kernel in python. You will need A or C to run python so for sure the kernel root will be A or C

Link to comment
Share on other sites

Link to post
Share on other sites

6 hours ago, swabro said:

I am not going to be using c at all and will use python and use a coding language that I have been developing from scratch and my target architure is for arm, x86 and amd64, 32 bit etc. basically cross compatibility in every way possible 

This is such a monumental task.

 

Speaking as someone who has dabbled in kernel development. targeting multiple architectures is difficult, targeting 64 bit is difficult.

 

You need to be comfortable in asm for all of those architectures and unless you are going to be using an existing boot loader you need to be able to get into protected mode and long mode.

 

python will be an absolute nightmare and require so much extra work only to have a kernel that is ultimately in c anyway and several orders of magnitude slower.

 

cross compatibility 'in every way possible' is something that is not even achieved by the biggest names in OS development with all of the time, money, and resources; teams of hundreds of developers are working on those projects.

 

I really suggest you start small. get into vga text mode. display some text on the screen, figure out panic handling.

 

You have to write drivers for every peripheral, you need to write mitigations for vulnerabilities for every architecture, You need to handle all of the edge cases.

 

You need to create stacks, and heaps. Memory managers. Context switching, BIOS interrogation. You need to build an entire network stack and implement IEEE standards.

 

If you want your OS to be useful you need to implement C so that way other software can actually be run on it.

 

I am not saying this to discourage, only to help you understand what you should be focusing on.

 

 

If your question is answered, mark it so.  | It's probably just coil whine, and it is probably just fine |   LTT Movie Club!

Read the docs. If they don't exist, write them. | Professional Thread Derailer

Desktop: i7-8700K, RTX 2080, 16G 3200Mhz, EndeavourOS(host), win10 (VFIO), Fedora(VFIO)

Server: ryzen 9 5900x, GTX 970, 64G 3200Mhz, Unraid.

 

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, swabro said:

I am not going to be using c at all and will use python and use a coding language that I have been developing from scratch and my target architure is for arm, x86 and amd64, 32 bit etc. basically cross compatibility in every way possible 

right.... if i get a dime for every newbie programmer who suddenly post on this subforum and declare they can code up an os in python, i would be a millionare by now. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

I don't want to write my kernel in python but I want to write is a coding language I am going to make from scratch and I don't care if its a monumental task or if its hard or anything like that i will get it done no matter how long it takes sry if u all thought if I am going to write a kernel in python which I wont be doing 🙂

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, swabro said:

I don't want to write my kernel in python but I want to write is a coding language I am going to make from scratch and I don't care if its a monumental task or if its hard or anything like that i will get it done no matter how long it takes sry if u all thought if I am going to write a kernel in python which I wont be doing 🙂

So instead you're going to invent your own programming language and also create a compiler for it that can produce x86, x86_64 and ARM binaries? That would be monumental task #2. You'd be much better off concentrating on one monumental task at a time. Use C, Assembler or maybe even Rust to develop your kernel rather than trying to also invent your own language and compiler at the same time.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

26 minutes ago, Eigenvektor said:

So instead you're going to invent your own programming language and also create a compiler for it that can produce x86, x86_64 and ARM binaries? That would be monumental task #2. You'd be much better off concentrating on one monumental task at a time. Use C, Assembler or maybe even Rust to develop your kernel rather than trying to also invent your own language and compiler at the same time.

nah I don't want to use c or anything like that or make an os forked from Linux or something, ty anyways for all the help though. Someone had to create Linux, windows, mac etc and someone had to create c so I don't care if its a monumental task or not or whether it would take me a decade to do this cuz I am not a 50 year old living his final 20 30 years with his grandchildren and children  

Link to comment
Share on other sites

Link to post
Share on other sites

besides I mean even if it was a monumental task then we wouldn't have the tech here we are using today or gaming and 300+ fps and all that jazz 

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, swabro said:

Someone had to create Linux, windows, mac etc and someone had to create c

It's not 'someone', maybe in the very beginning but even linus torvalds was an accomplished developer before he made linux, which by the way was a clone of minix, so even that wasn't starting from scratch. and linux in its early stages was really primitive.

 

macos is posix compliant, built on existing standards and work of others.

Windows took a lot from xerox in the early days.

 

C was developed by multiple people, and is one of the simplest modern languages containing only 32 keywords. And the development of c over the last 40 years has been by committee.

 

C by the way was also not created from scratch but instead succeeded b, which in turn was derived from bcpl, which itself is derived from cpl, which itself is derived from algol.

 

The most famous example of someone successful doing what you are talking (depending on your definition of success) is Terry Davis and TempleOS, which was a literal life long project that the man spent just about every waking hour working on.

 

As of 2005 over 14,000 individual people have contributed to the linux kernel. That is just the kernel, no Desktop environments or user space software, no compilers, etc.

 

 

I say all of this because I think kernel development and low level programming is fascinating and the fastest way to get burnt out from it is biting more than you can chew.

 

wiki os dev required knowledge

wiki os dev beginner mistakes

 

You should read these articles.

 

And you should follow this guide first.

 

I also suggest trying to do some other low level projects to get used to the environment, like developing emulators for classic systems (nes, gameboy) as well general systems programming, like creating a driver for a device.

 

 

 

 

 

If your question is answered, mark it so.  | It's probably just coil whine, and it is probably just fine |   LTT Movie Club!

Read the docs. If they don't exist, write them. | Professional Thread Derailer

Desktop: i7-8700K, RTX 2080, 16G 3200Mhz, EndeavourOS(host), win10 (VFIO), Fedora(VFIO)

Server: ryzen 9 5900x, GTX 970, 64G 3200Mhz, Unraid.

 

Link to comment
Share on other sites

Link to post
Share on other sites

20 minutes ago, swabro said:

besides I mean even if it was a monumental task then we wouldn't have the tech here we are using today or gaming and 300+ fps and all that jazz

C and the initial Linux kernel may have been designed/written by individuals 50/30 years ago respectively. They were nowhere near the state they are now.

 

All of the awesome tech we have today was built on top of these foundations over decades by thousands of developers. The large majority of modern tech has been built on top of existing things. Very few projects start entirely from scratch.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

At this point I don’t know what to say I mean if u all thinks its a monumental task(s) then let it be just remember me in years to come 

Link to comment
Share on other sites

Link to post
Share on other sites

23 minutes ago, swabro said:

At this point I don’t know what to say I mean if u all thinks its a monumental task(s) then let it be just remember me in years to come 

if you just want to write a simple, rudimentary kernel, it can be done. Linus Torvald wrote the first linux kernel by himself after all but like others said, to be a full feature OS like what you see today, you will need a lot more manpower and labor. This is a difference of building a treehouse/small wooden shred vs building the tallest skyscraper. You can do the former by yourself, the latter, not so much. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, wasab said:

if you just want to write a simple, rudimentary kernel, it can be done. Linus Torvald wrote the first linux kernel by himself after all but like others said, to be a full feature OS like what you see today, you will need a lot more manpower and labor. This is a difference of building a treehouse/small wooden shred vs building the tallest skyscraper. You can do the former by yourself, the latter, not so much. 

I mean I probably will

open source parts of it not the whole thing 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, swabro said:

I mean I probably will

open source parts of it not the whole thing 

open source parts of linux are many, this includes the xorg display server, all the gnu parts like its glibc, its desktop enviornment, package managers, init system, various hardware drivers ect. Much of these are not writen by Linus Torvalds or the team behind the linux kernel for that matter but third parties and all of them are decades long efforts involving countless developers and they are still ongoing projects being actively developed. heck, nowadays, the code written by Linus Torvalds is not even 2% of the total linux kernel code base. you wont be able to reinvent your own version of them all, nor should you.

 

Going back to the skyscrapper ananlogy, this is like you trying to build your own lightbulb factories just so you can install lighting in your building. In real life, such big project involves countless third party contractors; eletricians, plumbers, architects, civil engineers, and ect to complete.  

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, wasab said:

open source parts of linux are many, this includes the xorg display server, all the gnu parts like its glibc, its desktop enviornment, package managers, init system, various hardware drivers ect. Much of these are not writen by Linus Torvalds or the team behind the linux kernel for that matter but third parties and all of them are decades long efforts involving countless developers and they are still ongoing projects being actively developed. heck, nowadays, the code written by Linus Torvalds is not even 2% of the total linux kernel code base. you wont be able to reinvent your own version of them all, nor should you.

 

Going back to the skyscrapper ananlogy, this is like you trying to build your own lightbulb factories just so you can install lighting in your building. In real life, such big project involves countless third party contractors; eletricians, plumbers, architects, civil engineers, and ect to complete.  

Bro I can do

it trust me it’s fine 

Link to comment
Share on other sites

Link to post
Share on other sites

What have you done so far? I am interested to see. Kernel development is fascinating to me.

 

Something that was always difficult for me was testing and getting testing outputs. Since I have to run the tests in a vm, it is tough to get the test output outside of the virtualized environment.

 

I saw a cool rust implementation that utilizes the serial buffer to output to the qemu console.

If your question is answered, mark it so.  | It's probably just coil whine, and it is probably just fine |   LTT Movie Club!

Read the docs. If they don't exist, write them. | Professional Thread Derailer

Desktop: i7-8700K, RTX 2080, 16G 3200Mhz, EndeavourOS(host), win10 (VFIO), Fedora(VFIO)

Server: ryzen 9 5900x, GTX 970, 64G 3200Mhz, Unraid.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×