Overclock.net › Forums › Software, Programming and Coding › Operating Systems › How to start an OS from scratch
New Posts  All Forums:Forum Nav:

How to start an OS from scratch

post #1 of 25
Thread Starter 
I have been wondering how computers work for a while and by this I mean how the process of building an operating system from scratch. I've tried reading on wikipedia about computing but I couldn't find the information I was after. I understand the idea of writing an OS and loading it at the BIOS but if I were to build my very own PC where does the process shift from hardware to software? What I mean is if you didn't have a BIOS or any OS how would you be able to start getting characters on the screen?

This is hypothetical question as I'm only just starting to learn C++ and Labview.
THanks to any replies or linksto information in advance.
blue-cat
Orange and White
(16 items)
 
HTPC
(16 items)
 
Orange Ice Mk. 2
(29 photos)
CPUMotherboardGraphicsRAM
Phenom II 965 BE 3.4Ghz Gigabyte 990FXA UD7 KFA2 GTX 970 EXOC Infinity 8 Gb DDRIII 1333 
Hard DriveHard DriveCoolingOS
256GB Crucial M4 Samsung Spinpoint F1 1TB Phanteks TC14PE-OR Windows 7 Ultimate 64 Bit 
MonitorMonitorKeyboardPower
Dell U2515H LG Flatron W2252S Beige Keyboard by "Tiny" Corsair TX750 
CaseMouseMouse PadAudio
Fractal Design Define R4 Cheap "Trust" Mouse Steel Series Steelseries Orange Headphones 
CPUMotherboardGraphicsRAM
Athlon II x2 235e ASUS M5A78L-M HD3850 Patriot 4GB DDR3 1033MHz 
Hard DriveOptical DriveCoolingOS
80GB 2.5" HDD Samsung Bluray Reader Scythe Shuriken + 2x120mm + 1x80mm Win 7 
MonitorPowerCase
Sony 40" TV (1080p) Corsair CX430 Antec Fusion Remote 
  hide details  
Reply
Orange and White
(16 items)
 
HTPC
(16 items)
 
Orange Ice Mk. 2
(29 photos)
CPUMotherboardGraphicsRAM
Phenom II 965 BE 3.4Ghz Gigabyte 990FXA UD7 KFA2 GTX 970 EXOC Infinity 8 Gb DDRIII 1333 
Hard DriveHard DriveCoolingOS
256GB Crucial M4 Samsung Spinpoint F1 1TB Phanteks TC14PE-OR Windows 7 Ultimate 64 Bit 
MonitorMonitorKeyboardPower
Dell U2515H LG Flatron W2252S Beige Keyboard by "Tiny" Corsair TX750 
CaseMouseMouse PadAudio
Fractal Design Define R4 Cheap "Trust" Mouse Steel Series Steelseries Orange Headphones 
CPUMotherboardGraphicsRAM
Athlon II x2 235e ASUS M5A78L-M HD3850 Patriot 4GB DDR3 1033MHz 
Hard DriveOptical DriveCoolingOS
80GB 2.5" HDD Samsung Bluray Reader Scythe Shuriken + 2x120mm + 1x80mm Win 7 
MonitorPowerCase
Sony 40" TV (1080p) Corsair CX430 Antec Fusion Remote 
  hide details  
Reply
post #2 of 25
here's something for ya......your cpu comes preprogrammed ;o
BBW
(9 items)
 
  
CPUMotherboardGraphicsRAM
Bulldozer FX - 8120 Gigabyte GA-990FXA-UD3 Gigabyte Radeon HD 6850 Samsung's Best kept secret 
Hard DriveCoolingOSPower
Mushkin Enhanced Chronos Deluxe Spire TME 3 Windows 7 Ultimate 64 bit Corsair HX-850 
Case
Antec 1200 
  hide details  
Reply
BBW
(9 items)
 
  
CPUMotherboardGraphicsRAM
Bulldozer FX - 8120 Gigabyte GA-990FXA-UD3 Gigabyte Radeon HD 6850 Samsung's Best kept secret 
Hard DriveCoolingOSPower
Mushkin Enhanced Chronos Deluxe Spire TME 3 Windows 7 Ultimate 64 bit Corsair HX-850 
Case
Antec 1200 
  hide details  
Reply
post #3 of 25
You'll need knowledge in C/C++ and the assembly language for the system you are programming for (x68, XOR, HLA, etc). I would pick up a book like "Art of Assembly".

A big thing to remember is there are no debuggers for writing your own OS. You are writing at a lower level than the debugger would run, so it's all trial and error and tons of system restarts.


EDIT: You can read that book online for free as well at http://cs.smith.edu/~thiebaut/ArtOfAssembly/artofasm.html
post #4 of 25
The code in the ROM for the computer that managed the Apollo space craft that visited the moon was done by hand: http://en.wikipedia.org/wiki/Core_rope_memory

Nowadays, your PC has a ROM chip. The ROM chip is wired on the motherboard to show up inside the memory address space at exactly the position the CPU will start reading from when it's powered on. The ROM chip's contents will be flashed on another computer. You can't do that by hand anymore like they did with the Apollo guidance computer. There's too much code for that.

At university studying computer science, there's usually a short seminar where you design and build the circuitry of an 8 bit processor and do something very simple with it that only needs a few hundred bytes of code. The 8 bit processor circuitry is flashed onto an FPGA, which is a slow chip that behaves as if its circuitry can be deleted and rearranged. Your code is flashed onto a ROM chip. That kind of seminar is the closest you can get to experiencing everything from the most basic level by yourself, so you could try to find course material of one such seminar if you are interested.
post #5 of 25
Subbed
DEFCON-3
(22 items)
 
   
CPUMotherboardGraphicsRAM
FX-8350 (4.8GHz) Sabertooth 990FX (R1.01/BIOS1604) ASUS GTX 780Ti 2x8GB G.SKILL TRIDENT-X (2140MHz) 
Hard DriveHard DriveHard DriveHard Drive
Samsung 840 PRO 128GB Samsung 850 EVO 500GB Kingston HyperX 3K 128GB Kingston SSDnow 128GB 
Hard DriveOptical DriveOptical DriveCooling
WD Caviar BLACK 500GB ASUS Blu-ray ASUS LightScribe SILVER ARROW SB-E 
OSMonitorKeyboardPower
Windows 7 PRO 64-bit 3x ASUS VN248H (24" 1080p AH-IPS) Logitech G710+ Seasonic G-750 
CaseMouseMouse PadAudio
CM STORM:Trooper (DEFCON-3 MOD) Logitech MX Master Corsair MM600 CREATIVE Sound Blaster Z 
AudioOther
Audio Technica ATH-m50xbl Chill Factor III 
CPUMotherboardGraphicsRAM
AMD Athlon X4 880k ASRock A88M-G/3.1 ASUS GTX 660ti HyperX Fury 8GB 
Hard DriveOptical DriveOSMonitor
Crucial MX300 750GB LG Blu-ray Windows 10 P502ui-b1 
KeyboardPowerCaseAudio
Logitech k400r Rosewill Hive 550W ROSEWILL SRM-01 Vizio S4251W-b4 
CPUMotherboardGraphicsRAM
AMD Phenom II X2 550 MSI 770-C45 Sparkle GT 220 4GB Corsair XMS3 
Hard DriveHard DriveOptical DriveCooling
Western Digital 500GB Caviar Black Seagate Baracuda 1TB ASUS blu-ray Stock 
OSMonitorKeyboardPower
Windows 7 Proffesional  Acer 24"  Logitech Wave OCZ modXtreme Pro 600W 
CaseMouse
Cooler Master Centurion 5 blue Logitech LX8 
  hide details  
Reply
DEFCON-3
(22 items)
 
   
CPUMotherboardGraphicsRAM
FX-8350 (4.8GHz) Sabertooth 990FX (R1.01/BIOS1604) ASUS GTX 780Ti 2x8GB G.SKILL TRIDENT-X (2140MHz) 
Hard DriveHard DriveHard DriveHard Drive
Samsung 840 PRO 128GB Samsung 850 EVO 500GB Kingston HyperX 3K 128GB Kingston SSDnow 128GB 
Hard DriveOptical DriveOptical DriveCooling
WD Caviar BLACK 500GB ASUS Blu-ray ASUS LightScribe SILVER ARROW SB-E 
OSMonitorKeyboardPower
Windows 7 PRO 64-bit 3x ASUS VN248H (24" 1080p AH-IPS) Logitech G710+ Seasonic G-750 
CaseMouseMouse PadAudio
CM STORM:Trooper (DEFCON-3 MOD) Logitech MX Master Corsair MM600 CREATIVE Sound Blaster Z 
AudioOther
Audio Technica ATH-m50xbl Chill Factor III 
CPUMotherboardGraphicsRAM
AMD Athlon X4 880k ASRock A88M-G/3.1 ASUS GTX 660ti HyperX Fury 8GB 
Hard DriveOptical DriveOSMonitor
Crucial MX300 750GB LG Blu-ray Windows 10 P502ui-b1 
KeyboardPowerCaseAudio
Logitech k400r Rosewill Hive 550W ROSEWILL SRM-01 Vizio S4251W-b4 
CPUMotherboardGraphicsRAM
AMD Phenom II X2 550 MSI 770-C45 Sparkle GT 220 4GB Corsair XMS3 
Hard DriveHard DriveOptical DriveCooling
Western Digital 500GB Caviar Black Seagate Baracuda 1TB ASUS blu-ray Stock 
OSMonitorKeyboardPower
Windows 7 Proffesional  Acer 24"  Logitech Wave OCZ modXtreme Pro 600W 
CaseMouse
Cooler Master Centurion 5 blue Logitech LX8 
  hide details  
Reply
post #6 of 25
All CPUs basically start up the same way.

Once powered up and the clock frequency has stabilized there will be an instruction pointer set to a predefined start position, e.g. address 0. The CPU then executes the instruction that the instruction pointer is pointing to. That address will usually be located in an eeprom (persistent memory that can re-written) containing a bios or some kind of boot sequence.

The CPU auto increments the instruction pointer each time it has executed an instruction (on branch instructions it will jump to start execution in some other area). Some CPUs will execute 1 instruction per clock, others require multiple clock ticks per instruction all depending on architecture.

The instructions being executed are assembly language instructions. But assembly language is not the lowest level. Assembly instructions are build using microcode in the hardware itself and the microcode is build using logical instructions (AND, OR, NAND, NOR etc.) and registers, these logical instructions are then finally implemented using transistors.

Somewhat simplified, but I hope it makes sense smile.gif
post #7 of 25
Thread Starter 
Firstly, thanks for all the replies so far! Some really good guides so I don't get out of my depth biggrin.gif
Quote:
Originally Posted by denman View Post

You'll need knowledge in C/C++ and the assembly language for the system you are programming for (x68, XOR, HLA, etc).

Thanks, I'll throw it in my to read pile and pick at it when I have spare time! smile.gif Seems like everytime I try to read something on wikipedia or elsewhere I end up having to look up every second word to get a definitive definition. I guess that's what I get for trying to dip my foot into a subject I've never studied properly. ^_^
I should probably make it clear that I wasn't intending or expecting to write my own OS. To be honest... the final straw that made me post was that I watched an episode of Revolution where a woman supposedly built a computer in a world where all electricity has been ruined and it got me thinking about how clueless I was about how we got from silicon and metals and ceramics to killing zombies and stressing over courseworks.
Quote:
Originally Posted by deepor View Post

The code in the ROM for the computer that managed the Apollo space craft that visited the moon was done by hand: http://en.wikipedia.org/wiki/Core_rope_memory

Nowadays, your PC has a ROM chip. The ROM chip is wired on the motherboard to show up inside the memory address space at exactly the position the CPU will start reading from when it's powered on. The ROM chip's contents will be flashed on another computer. You can't do that by hand anymore like they did with the Apollo guidance computer. There's too much code for that.

At university studying computer science, there's usually a short seminar where you design and build the circuitry of an 8 bit processor and do something very simple with it that only needs a few hundred bytes of code. The 8 bit processor circuitry is flashed onto an FPGA, which is a slow chip that behaves as if its circuitry can be deleted and rearranged. Your code is flashed onto a ROM chip. That kind of seminar is the closest you can get to experiencing everything from the most basic level by yourself, so you could try to find course material of one such seminar if you are interested.

This is kind of what I was getting at as your literally writing/programming (?) the ROM physically in order to form a basis for your further coding. You say you can't do it by hand because there is too much code but could you not make it simpler (or on a larger scale) ? Or is it that the physical hardware is too complex and therefore requires the more complex base code (assembly language?) and shortening it would render certain components and functionality unusable?

I'll take your advice and ask one of my friends who did computer science whether they studied this sort of thing then I can try and sneak into a course at the start of the new year after I graduate. biggrin.gif
Quote:
Originally Posted by jvjessen View Post

All CPUs basically start up the same way.

Once powered up and the clock frequency has stabilized there will be an instruction pointer set to a predefined start position, e.g. address 0. The CPU then executes the instruction that the instruction pointer is pointing to. That address will usually be located in an eeprom (persistent memory that can re-written) containing a bios or some kind of boot sequence.

The CPU auto increments the instruction pointer each time it has executed an instruction (on branch instructions it will jump to start execution in some other area). Some CPUs will execute 1 instruction per clock, others require multiple clock ticks per instruction all depending on architecture.

The instructions being executed are assembly language instructions. But assembly language is not the lowest level. Assembly instructions are build using microcode in the hardware itself and the microcode is build using logical instructions (AND, OR, NAND, NOR etc.) and registers, these logical instructions are then finally implemented using transistors.

Somewhat simplified, but I hope it makes sense smile.gif

Thanks for breaking down the levels clearly all the way down to the transistors. The explanation of the CPU increments and instructions is obviously why the CPU frequencies are so insanely high otherwise things wouldn't run nearly as well. It also presents the argument for overclocking more simply. It seems that coders and programmers must be very patient and methodical people to have created the systems that work so well.
Thanks again to everyone thus far.
Orange and White
(16 items)
 
HTPC
(16 items)
 
Orange Ice Mk. 2
(29 photos)
CPUMotherboardGraphicsRAM
Phenom II 965 BE 3.4Ghz Gigabyte 990FXA UD7 KFA2 GTX 970 EXOC Infinity 8 Gb DDRIII 1333 
Hard DriveHard DriveCoolingOS
256GB Crucial M4 Samsung Spinpoint F1 1TB Phanteks TC14PE-OR Windows 7 Ultimate 64 Bit 
MonitorMonitorKeyboardPower
Dell U2515H LG Flatron W2252S Beige Keyboard by "Tiny" Corsair TX750 
CaseMouseMouse PadAudio
Fractal Design Define R4 Cheap "Trust" Mouse Steel Series Steelseries Orange Headphones 
CPUMotherboardGraphicsRAM
Athlon II x2 235e ASUS M5A78L-M HD3850 Patriot 4GB DDR3 1033MHz 
Hard DriveOptical DriveCoolingOS
80GB 2.5" HDD Samsung Bluray Reader Scythe Shuriken + 2x120mm + 1x80mm Win 7 
MonitorPowerCase
Sony 40" TV (1080p) Corsair CX430 Antec Fusion Remote 
  hide details  
Reply
Orange and White
(16 items)
 
HTPC
(16 items)
 
Orange Ice Mk. 2
(29 photos)
CPUMotherboardGraphicsRAM
Phenom II 965 BE 3.4Ghz Gigabyte 990FXA UD7 KFA2 GTX 970 EXOC Infinity 8 Gb DDRIII 1333 
Hard DriveHard DriveCoolingOS
256GB Crucial M4 Samsung Spinpoint F1 1TB Phanteks TC14PE-OR Windows 7 Ultimate 64 Bit 
MonitorMonitorKeyboardPower
Dell U2515H LG Flatron W2252S Beige Keyboard by "Tiny" Corsair TX750 
CaseMouseMouse PadAudio
Fractal Design Define R4 Cheap "Trust" Mouse Steel Series Steelseries Orange Headphones 
CPUMotherboardGraphicsRAM
Athlon II x2 235e ASUS M5A78L-M HD3850 Patriot 4GB DDR3 1033MHz 
Hard DriveOptical DriveCoolingOS
80GB 2.5" HDD Samsung Bluray Reader Scythe Shuriken + 2x120mm + 1x80mm Win 7 
MonitorPowerCase
Sony 40" TV (1080p) Corsair CX430 Antec Fusion Remote 
  hide details  
Reply
post #8 of 25
My brain hurts just looking at all of this but I learned something. smile.gif
 
Gsvlip Dudyrm
(15 items)
 
Oda'maksv
(9 items)
 
CPUMotherboardGraphicsRAM
3770k @ 4.5 1.312 load Zotac Z77 ITX Wifi GTX 1070 Gaming 2126/2249 w/ Hybrid cooler TridentX 16GB 2400MHz 
Hard DriveHard DriveCoolingCooling
Samsung 850 Pro 1TB Seagate 2TB H105 EVGA Hybrid GPU cooler 
OSMonitorKeyboardPower
Windows 10 Asus MG279Q - 24" 144Hz 1080p Filco Majestic II w/ Cherry Reds Seasonic X 760W 
CaseMouseMouse PadAudio
Bitfelix Prodigy Logitech G400 Razer Goliath AKG A701 
AudioAudio
JDS Labs Objective 2 JDS Labs ODAC 
CPUMotherboardGraphicsRAM
Core i5 750 3.99 (190x21) 1.376v Load ASUS P7P55d-E Pro GTX 670 FTW <- Poor overclocker :( 8GB (4x2GB) G.Skill DDR3 1600 
Hard DriveHard DriveOptical DriveOS
Samsung 830 Evo 128GB 2x 2TB  Some DVD drive OSX 10.10.4 
MonitorPowerCaseMouse
Asus 1080P Crap TX 750 HAF 922 G400s 
Mouse PadOther
Apple Keyboard Xbox One controler 
CPURAMHard DriveHard Drive
C2D 2,26GHz under volted @ .978v 8GB  Crucial M4 64GB SSD 500GB Scorpio Black 
OSMonitorKeyboardMouse
OS X 10.0 1280x800 Built-in Trackpad 
Audio
Built-in 
  hide details  
Reply
 
Gsvlip Dudyrm
(15 items)
 
Oda'maksv
(9 items)
 
CPUMotherboardGraphicsRAM
3770k @ 4.5 1.312 load Zotac Z77 ITX Wifi GTX 1070 Gaming 2126/2249 w/ Hybrid cooler TridentX 16GB 2400MHz 
Hard DriveHard DriveCoolingCooling
Samsung 850 Pro 1TB Seagate 2TB H105 EVGA Hybrid GPU cooler 
OSMonitorKeyboardPower
Windows 10 Asus MG279Q - 24" 144Hz 1080p Filco Majestic II w/ Cherry Reds Seasonic X 760W 
CaseMouseMouse PadAudio
Bitfelix Prodigy Logitech G400 Razer Goliath AKG A701 
AudioAudio
JDS Labs Objective 2 JDS Labs ODAC 
CPUMotherboardGraphicsRAM
Core i5 750 3.99 (190x21) 1.376v Load ASUS P7P55d-E Pro GTX 670 FTW <- Poor overclocker :( 8GB (4x2GB) G.Skill DDR3 1600 
Hard DriveHard DriveOptical DriveOS
Samsung 830 Evo 128GB 2x 2TB  Some DVD drive OSX 10.10.4 
MonitorPowerCaseMouse
Asus 1080P Crap TX 750 HAF 922 G400s 
Mouse PadOther
Apple Keyboard Xbox One controler 
CPURAMHard DriveHard Drive
C2D 2,26GHz under volted @ .978v 8GB  Crucial M4 64GB SSD 500GB Scorpio Black 
OSMonitorKeyboardMouse
OS X 10.0 1280x800 Built-in Trackpad 
Audio
Built-in 
  hide details  
Reply
post #9 of 25
(Shakes head) write your own OS? Yeah, sure. No, the closest you can come without millions of dollars and/or years of work would be to do a Linux From Scratch install. But really, anyone who 'knows a little C++' but thinks they can write an OS knows nothing. The codebase of most Linux distrobutions was built over years, and by thousands of people writing software from the kernel to the desktop.

If you want to learn more about how an OS works, I suggest you get used to Linux via Ubuntu and then do an Arch Linux install. If you still want to know more after that, you can build your own distro with Linux From Scratch.
post #10 of 25
Thread Starter 
Quote:
Originally Posted by jrl1357 View Post

(Shakes head) write your own OS? Yeah, sure. No, the closest you can come without millions of dollars and/or years of work would be to do a Linux From Scratch install. But really, anyone who 'knows a little C++' but thinks they can write an OS knows nothing. The codebase of most Linux distrobutions was built over years, and by thousands of people writing software from the kernel to the desktop.

If you want to learn more about how an OS works, I suggest you get used to Linux via Ubuntu and then do an Arch Linux install. If you still want to know more after that, you can build your own distro with Linux From Scratch.

As I said this was a hypothetical question about how it was done not a one man mission to create the OS of the future. That said I think that if I ever were to decide to pointlessly dedicate my life to such an unobtainable goal (or if I am just interested like I am now) then your advice is actually useful. Thanks! smile.gif
Orange and White
(16 items)
 
HTPC
(16 items)
 
Orange Ice Mk. 2
(29 photos)
CPUMotherboardGraphicsRAM
Phenom II 965 BE 3.4Ghz Gigabyte 990FXA UD7 KFA2 GTX 970 EXOC Infinity 8 Gb DDRIII 1333 
Hard DriveHard DriveCoolingOS
256GB Crucial M4 Samsung Spinpoint F1 1TB Phanteks TC14PE-OR Windows 7 Ultimate 64 Bit 
MonitorMonitorKeyboardPower
Dell U2515H LG Flatron W2252S Beige Keyboard by "Tiny" Corsair TX750 
CaseMouseMouse PadAudio
Fractal Design Define R4 Cheap "Trust" Mouse Steel Series Steelseries Orange Headphones 
CPUMotherboardGraphicsRAM
Athlon II x2 235e ASUS M5A78L-M HD3850 Patriot 4GB DDR3 1033MHz 
Hard DriveOptical DriveCoolingOS
80GB 2.5" HDD Samsung Bluray Reader Scythe Shuriken + 2x120mm + 1x80mm Win 7 
MonitorPowerCase
Sony 40" TV (1080p) Corsair CX430 Antec Fusion Remote 
  hide details  
Reply
Orange and White
(16 items)
 
HTPC
(16 items)
 
Orange Ice Mk. 2
(29 photos)
CPUMotherboardGraphicsRAM
Phenom II 965 BE 3.4Ghz Gigabyte 990FXA UD7 KFA2 GTX 970 EXOC Infinity 8 Gb DDRIII 1333 
Hard DriveHard DriveCoolingOS
256GB Crucial M4 Samsung Spinpoint F1 1TB Phanteks TC14PE-OR Windows 7 Ultimate 64 Bit 
MonitorMonitorKeyboardPower
Dell U2515H LG Flatron W2252S Beige Keyboard by "Tiny" Corsair TX750 
CaseMouseMouse PadAudio
Fractal Design Define R4 Cheap "Trust" Mouse Steel Series Steelseries Orange Headphones 
CPUMotherboardGraphicsRAM
Athlon II x2 235e ASUS M5A78L-M HD3850 Patriot 4GB DDR3 1033MHz 
Hard DriveOptical DriveCoolingOS
80GB 2.5" HDD Samsung Bluray Reader Scythe Shuriken + 2x120mm + 1x80mm Win 7 
MonitorPowerCase
Sony 40" TV (1080p) Corsair CX430 Antec Fusion Remote 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Operating Systems
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › How to start an OS from scratch