Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 27, 2012, 12:37 AM   #1
pchipchip
macrumors regular
 
Join Date: Sep 2011
Program a custom OS?

Is it possible to program my own OS from scratch? Don't tell me that it is a stupid idea or anything. I am just wondering if it is possible and if so, where should I start?
pchipchip is offline   0 Reply With Quote
Old Apr 27, 2012, 12:41 AM   #2
throAU
macrumors 68030
 
Join Date: Feb 2012
Location: Perth, Western Australia
Yes you can.

You'll need to start off by learning assembly language for your chosen CPU architecture, so that you are able to program low level device drivers to get something to boot.

You'll also need to learn the low level details of PCI, SATA, etc.


It's not a small task - learning assembly language alone will take you quite some time.

I'd certainly recommend doing this using something like VMware (until you know what you're doing) to contain your efforts to a protected, separate environment from your day to day computer.

Low level device programming gives you the power to cause all sorts of data corruption and even hardware problems, if run on physical hardware and you don't know what you're doing.
__________________
MBP (early 2011) - Core i7 2720 2.2ghz, Hires Glossy, 16GB, Seagate Momentus XT 750GB
Mac Mini (mid 2007) - Core2 Duo 1.8, 2gb, 320gb 7200 rpm
iPhone 4S, iPad 4, iPad Mini, HTC One (eval)
throAU is offline   0 Reply With Quote
Old Apr 27, 2012, 01:28 AM   #3
miles01110
macrumors 604
 
miles01110's Avatar
 
Join Date: Jul 2006
Location: The Ivory Tower (I'm not coming down)
Lots of things are "possible." Whether they're likely is competely different.
__________________
Got a problem? Check here first.
miles01110 is offline   2 Reply With Quote
Old Apr 27, 2012, 01:54 AM   #4
MattInOz
macrumors 68030
 
MattInOz's Avatar
 
Join Date: Jan 2006
Location: Sydney
Depending on why you want to build your own, you might be better to start like NeXT did by farming Open Source and University Research Projects by build out the bones of the OS.

Apple still does this in order to get Low level parts of the OS, generally employing key project staff to ensure they keep moving forward.
__________________
There is no such thing as "Collective Wisdom"
[ iPhone 5s, iPad Mini, 13" MacBookPro 2.7Ghz, 27"Al iMac i7, Black MacBook 13"]
MattInOz is offline   0 Reply With Quote
Old Apr 27, 2012, 02:02 AM   #5
thundersteele
macrumors 68030
 
Join Date: Oct 2011
The answer is obviously yes. Someone had to do it in the past, otherwise there would be no operating systems. So it can be done again.
thundersteele is offline   0 Reply With Quote
Old Apr 27, 2012, 02:07 AM   #6
Comeagain?
macrumors 68020
 
Comeagain?'s Avatar
 
Join Date: Feb 2011
Location: Spokane, WA
I wonder if you could use what apple already has for boot code and drivers, and then build from that? I know you couldn't legally, but is it possible?
__________________
Questions? MRoogle it!
Current iOS 8 "All the little things!"
MR Scavenger Score: 1
Comeagain? is offline   0 Reply With Quote
Old Apr 27, 2012, 02:46 AM   #7
throAU
macrumors 68030
 
Join Date: Feb 2012
Location: Perth, Western Australia
Well, given that the core of OS X is darwin, and Darwin is open source, well yes you could, it is even legal. A few people did just that with the PureDarwin and OpenDarwin projects.


I agree it would certainly be a lot easier to start off with something like Darwin or FreeBSD in a virtual machine to play with and modify/break, than trying to start out from scratch without any experience in operating system design.

Back in the 80s when an OS wasn't expected to do much (like DOS), writing one from scratch would be a lot easier.

I think its an example of just how much work and complexity is involved that it took apple several failed attempts (and they ended up buying NEXT back off Jobs to turn it into OS X) to replace the original Mac OS.

IMHO the only reason to write your own quick and dirty "OS" these days is if you want to program the machine to do a single task as quickly as possible. Essentially you're BYPASSING any operating system and doing everything yourself. E.g., many games in the 80s and 90s for stuff like the Amiga, Atari ST, consoles, etc used to do this. Positive: You have no operating system sucking CPU power you could use for your app. Negative: YOU are responsible for all low level device access - no drivers, no graphics libraries, no UI, etc are available. You're on your own.

Otherwise (if you want to run other people's software in a multi-tasking environment) writing an efficient scheduler and memory manager is not a trivial task to undertake. Even Windows, Linux, OS X and FreeBSD are having regular changes and tweaks made to improve their schedulers and memory managers, after several decades of real world use and refinement. And that's before you even get to the user interface stuff.


Not to poo-poo the idea, it's how Linus started out with Linux, and many others created operating systems before him - but to make anything even remotely comparable to OS X (or even Linux) will take many people a long time, even if they're good, experienced programmers.
__________________
MBP (early 2011) - Core i7 2720 2.2ghz, Hires Glossy, 16GB, Seagate Momentus XT 750GB
Mac Mini (mid 2007) - Core2 Duo 1.8, 2gb, 320gb 7200 rpm
iPhone 4S, iPad 4, iPad Mini, HTC One (eval)

Last edited by throAU; Apr 27, 2012 at 03:01 AM.
throAU is offline   0 Reply With Quote
Old Apr 27, 2012, 04:44 AM   #8
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by pchipchip View Post
Is it possible to program my own OS from scratch? Don't tell me that it is a stupid idea or anything. I am just wondering if it is possible and if so, where should I start?
Linus Torvalds did. But then he didn't ask anyone where to start.
gnasher729 is offline   2 Reply With Quote
Old Apr 27, 2012, 05:25 AM   #9
adrian.oconnor
macrumors 6502
 
Join Date: Jan 2008
Location: Nottingham, England
Quote:
Originally Posted by gnasher729 View Post
Linus Torvalds did. But then he didn't ask anyone where to start.
I think you're wrong about that. Linus was a CS student when he started Linux, and he asked plenty of advice (as any smart person would).

As it happens, you can still read some of his conversations with Andrew Tanenbaum on usenet. Tanenbaum is a professor who specialises in teaching OS design. He even built a teaching OS called Minix. The name Linux is a bastardisation of the Minix name, I guess because Linus was studying Minix at the time.

So here's my advice to OP: If you want to write an operating system, get Andrew Tanenbaum's books on the subject. They're not easy to read, but if you want to write an OS they're going to be a serious help. If you can't make it to the end of those books, you're probably biting off more than you can chew.
adrian.oconnor is offline   0 Reply With Quote
Old Apr 27, 2012, 01:07 PM   #10
mrbash
macrumors 6502
 
Join Date: Aug 2008
Yes, it's easier than you think

Yes! You don't have to know Assembly either. You can write an OS in any high level language including Java.

Probably the best place to start would be to take a course on Operating Systems, and if that's not possible, reading a book on Operating Systems. That will give you an idea of what an OS is, and which parts of an OS you want to write.

Then you simply write the different parts of the OS. Compile it for your architecture, and away you go.

It is easier than you think, and it is a fantastic idea. It gives you a great understanding of computers.
mrbash is offline   0 Reply With Quote
Old Apr 27, 2012, 01:34 PM   #11
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
Quote:
Originally Posted by mrbash View Post
Yes! You don't have to know Assembly either. You can write an OS in any high level language including Java.

Probably the best place to start would be to take a course on Operating Systems, and if that's not possible, reading a book on Operating Systems. That will give you an idea of what an OS is, and which parts of an OS you want to write.

Then you simply write the different parts of the OS. Compile it for your architecture, and away you go.

It is easier than you think, and it is a fantastic idea. It gives you a great understanding of computers.

I'm curious, how does one write an interrupt handler in Java? Or, for that matter, bootstrap the JVM on their OS if their OS is written in Java?
Catfish_Man is offline   0 Reply With Quote
Old Apr 27, 2012, 01:57 PM   #12
wlh99
macrumors 6502
 
Join Date: Feb 2008
Quote:
Originally Posted by Comeagain? View Post
I wonder if you could use what apple already has for boot code and drivers, and then build from that? I know you couldn't legally, but is it possible?
The OS/X kernel (Darwin) is open source and the source code is available from Apple. It would be a good exercise to build it and get it running.

http://en.wikipedia.org/wiki/Darwin_(operating_system)

Here is an Apple support document describing how to obtain and build Darwin.

https://developer.apple.com/library/...ild/build.html
__________________
Warren Holybee
wlh99 is offline   0 Reply With Quote
Old Apr 27, 2012, 05:25 PM   #13
dmz
macrumors regular
 
Join Date: Jan 2007
Location: Canada
OS in Java? Ha-ha-ha-ha-ha - that's rich!

You cannot write an OS in a high-level language, sorry mrbash, no-can-do.

You can write a GUI that way, on top of Darwin or any of the free UNIX-like kernels. Is that perhaps what you meant?

Writing an OS from scratch is a gargantuan task - try picking a small target if you wish to pursue this idea seriously - an 8-bit processor with a small assembler and few device drivers - VDT, keyboard, floppy disk and serial port are a good start. I wrote a DOS for the ZX80 way back in the early 80's, and for one person, it was still a huge task, but very, very educational.

Good luck, and keep learning!

dmz
dmz is offline   0 Reply With Quote
Old Apr 27, 2012, 06:49 PM   #14
Anonymous Freak
macrumors 68040
 
Anonymous Freak's Avatar
 
Join Date: Dec 2002
Location: Cascadia
Quote:
Originally Posted by dmz View Post
You cannot write an OS in a high-level language, sorry mrbash, no-can-do.

You can write a GUI that way, on top of Darwin or any of the free UNIX-like kernels. Is that perhaps what you meant?

Writing an OS from scratch is a gargantuan task - try picking a small target if you wish to pursue this idea seriously - an 8-bit processor with a small assembler and few device drivers - VDT, keyboard, floppy disk and serial port are a good start. I wrote a DOS for the ZX80 way back in the early 80's, and for one person, it was still a huge task, but very, very educational.

Good luck, and keep learning!

dmz
Um, Darwin is written in Objective-C. That is a high-level language. Very little of modern OSes are written in assembly. NONE of the Linux kernel is written in assembly. As long as it is 32-bit, and there is a GNU C compiler for it, Linux will run on it.
__________________

20" Aluminum iMac 7,1 (mid-2007, Santa Rosa,) upgraded to 2.6 GHz Penryn, 6 GB RAM, 1 TB HD, 4 TB total external hard drive
Anonymous Freak is offline   -1 Reply With Quote
Old Apr 27, 2012, 09:23 PM   #15
truehybridx
macrumors member
 
Join Date: Dec 2010
Quote:
Originally Posted by pchipchip View Post
Is it possible to program my own OS from scratch? Don't tell me that it is a stupid idea or anything. I am just wondering if it is possible and if so, where should I start?
try taking a look at BareMetalOS, or a small, very small distro of unix... it will require some good knowledge of C, assembly helps too
truehybridx is offline   0 Reply With Quote
Old Apr 27, 2012, 10:33 PM   #16
adildacoolset
macrumors 65816
 
Join Date: Sep 2011
Location: Lusaka, Zambia(If you know where it is)
okay, you can do it after learning assembly language.A good book is called "The art of assembly language programming" by Randall Hyde. I wouldn't recommend a high-level language as the abstractions would just cause more occupation of size and memory, and less performance.
__________________
Last edited by adildacoolset; Tomorrow at 09:42 AM. Reason: grammar error
adildacoolset is offline   0 Reply With Quote
Old Apr 28, 2012, 10:48 AM   #17
mrbash
macrumors 6502
 
Join Date: Aug 2008
I suspect most of the people claiming that you cannot write an OS in a high level language do not have a formal education in computer Science. And for those who do, shame on you, you should know better.

A first course in OS will shown that the level of the language does not matter, it is only the logic that you implement that matters.

I should also add, that assembly is considered a symbolic language, like object code. The operating system converts Assembly code into machine code, just like the operating system converts object code from a high-level language into machine code. That is to say you can write an OS in assembly, like you can write an OS in object code.

I doubt the OP intends to write a commercial OS. Most likely they want to learn some of the core OS concepts like Process, Scheduling and Memory management.

Also to answer some of the critics of my suggestion that it is possible to write an OS in Java: Java handles signals (the general case of interrupts) quite well.
mrbash is offline   0 Reply With Quote
Old Apr 28, 2012, 10:59 AM   #18
subsonix
macrumors 68030
 
Join Date: Feb 2008
Quote:
Originally Posted by mrbash View Post
I suspect most of the people claiming that you cannot write an OS in a high level language do not have a formal education in computer Science. And for those who do, shame on you, you should know better.

A first course in OS will shown that the level of the language does not matter, it is only the logic that you implement that matters.
The OS will need to interface directly with the hardware, it must not require a runtime or interpreter as there are none. Certain parts of the OS as the bootloader requires assembly, but you will find it in other parts as well.

Quote:
Originally Posted by mrbash View Post
The operating system converts Assembly code into machine code, just like the operating system converts object code from a high-level language into machine code.
Wrong. The assembler converts assembly instructions to machine code, the cpu can run the machine code natively. Java byte code requires a Java runtime, which in turn requires an operating system where it can be executed, there is your chicken and egg problem as you are writing the operating system there are no Java runtime.

Last edited by subsonix; Apr 28, 2012 at 11:09 AM.
subsonix is offline   0 Reply With Quote
Old Apr 28, 2012, 11:29 AM   #19
chown33
macrumors 603
 
Join Date: Aug 2009
http://en.wikipedia.org/wiki/Lisp_ma...nical_overview
All operating system software was written in Lisp. Xerox used InterLisp. Symbolics, LMI and TI used Lisp Machine Lisp (descendant of MacLisp). With the appearance of Common Lisp, Common Lisp was supported on the Lisp Machines and some system software was ported to Common Lisp or later written in Common Lisp. [underline added]
chown33 is offline   0 Reply With Quote
Old Apr 28, 2012, 11:34 AM   #20
subsonix
macrumors 68030
 
Join Date: Feb 2008
What's your point?

Quote:
The processor did not run Lisp directly, but was a stack machine with instructions optimized for compiled Lisp.
subsonix is offline   0 Reply With Quote
Old Apr 28, 2012, 12:10 PM   #21
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by subsonix View Post
What's your point?
It was underlined: All operating system software was written in Lisp. Even if it's compiled to machine code, it's still written in Lisp. Or are you arguing that compilers are forbidden?

Did someone at some point have to write assembler? Maybe, maybe not. It's possible there were existing tools that translated Lisp to other forms, such as assembler, and they used that for bootstrapping. So it's quite possible that no person ever wrote any machine code or even assembler.


Further fanning the flames, see this regarding Java byte code:
http://en.wikipedia.org/wiki/Jazelle

I fully realize this is not a complete JVM in hardware, and still requires software support for some byte-codes.
chown33 is offline   0 Reply With Quote
Old Apr 28, 2012, 12:39 PM   #22
subsonix
macrumors 68030
 
Join Date: Feb 2008
Quote:
Originally Posted by chown33 View Post
It was underlined: All operating system software was written in Lisp. Even if it's compiled to machine code, it's still written in Lisp. Or are you arguing that compilers are forbidden?
Ok, but so what? C is a high level language explicitly created to write operating systems. I'm not arguing that you have to use assembly to write an operating system, but at least for x86 it's required for the boot loader. But that being said it can often be found in other parts as well, if for no other reason to optimize.

There's quite a lot of resources available on this if you are interested, I feel this is moving on to the absurd.
subsonix is offline   0 Reply With Quote
Old Apr 28, 2012, 02:10 PM   #23
knightlie
macrumors 6502a
 
Join Date: Feb 2008
Quote:
Originally Posted by Anonymous Freak View Post
Um, Darwin is written in Objective-C. That is a high-level language. Very little of modern OSes are written in assembly. NONE of the Linux kernel is written in assembly. As long as it is 32-bit, and there is a GNU C compiler for it, Linux will run on it.
Darwin is C & C++.

stackoverflow.com: what-languages-are-windows-mac-os-x-and-linux-written-in
knightlie is offline   1 Reply With Quote
Old Apr 28, 2012, 02:56 PM   #24
Sander
macrumors 6502
 
Join Date: Apr 2008
Re: OS in Java? Ha-ha-ha-ha-ha - that's rich!

Quote:
Originally Posted by dmz View Post
You cannot write an OS in a high-level language, sorry mrbash, no-can-do.
JNode
Sander is offline   0 Reply With Quote
Old Apr 28, 2012, 03:33 PM   #25
subsonix
macrumors 68030
 
Join Date: Feb 2008
The kernel is written in assembly though as well as part of the vm, and it uses GRUB as a boot loader.
subsonix is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Tags
custom, operating system, program

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: custom font for Custom UITableViewCell erdinc27 iPhone/iPad Programming 5 Apr 18, 2014 12:50 PM
Custom Backgrounds Breitling65 iOS 7 6 Sep 13, 2013 08:14 AM
Springtomize 2 Custom Time Mode - Custom String GUILTIE Jailbreaks and iOS Hacks 10 Mar 7, 2013 03:18 PM

Forum Jump

All times are GMT -5. The time now is 06:09 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC