In the following POST, Linus describes the process of developing OS itself. . .
-------------------------------------------------- ---- from: torvalds@klaava.helsinki.fi (Linus Benedict Torvalds) NewsGroups: Comp.LinuxSubject: Re: Writing an OS - Questions !! Message-ID: <1992may5.075817.15984@klaava.helsinki.fi> Date: 5 May 92 07:58:17 GMTREFERENCES: <10685@inews.intel.com> Organization: University of Helsinkilines: 136 in article <10685@inews.intel.com> nani@td2cad.intel.com (v. narayanan Writes: >> Hi Folks,> for Quite Some Time this "Novice" HAS BEEN WONDERING As To HOW One Goes> About The Task of Writing An OS from "Scratch". so here all quintions,> and i would Appreciate IF you could take time to answer 'em. Well, I see someone else already answered, but I thought I'd take on thelinux-specific parts. Just my personal experiences, and I do not knowhow normal those are.> 1) How WOULD you Typically Debug The Kernel DURING THE DEVELOPMENT PHASE? Depends on Both the Machine and How Far You Have Gotten on The Kernel: on More Simple Systems It's General ly easier to set up Here's what Ihad to do on a 386 in protected mode The worst part is starting off:.. after you have even a minimal system youcan use printf etc, but moving to protected mode on a 386 is not fun, especially if you at first do not know the architecture very well It'sdistressingly easy to reboot the system at this stage: if the 386notices something is wrong, it shuts down and reboots - you do not evenget a chance to see what's wrong. . Printf () isn't Very Useful - a reboot also clears the screen
t even think about debuggers:. nodebugger I know of can follow a 386 into protected mode A 386 emulatormight do the job, or some heavy hardware, but that is not usuallyfeasible What I used was a simple killing-loop:. I put in statements like die:. jmp die at strategic places If it locked up, you were ok, if it rebooted, youknew at least it happened before the die-loop Alternatively, you mightuse the sound io ports for some sound-clues, but as. I Had No ExperienceWith PC Hardware, I Didn't Even Use. I'm NOT SAYING THIS Theonly Way: I Didn't Start Off To Wanted To Explorethe 386 Task-Switch Primitives etc, and That's how I started off (inabout April-91). After you have a minimal system up and can use the screen for output, itgets a bit easier, but that's when you have to enable interrupts. Bang, instant reboot, and back to the old Way. All in all, IT TOOK ABOUT 2MONTHS for me to get all the 386 things pretty well sorted out sust iNo Longer had count on avoiding rebooting at once, and having thebasic things set up (paging, timer-interrupt and a simple task-switcherto test out the segments etc).> 2) Can you test the kernel functionality by running it as a process on a> different OS? Would not the OS (the development environment) generate> exceptions in cases when the kernel (of the new OS) tries to modify> 'priviledged' registers? Yes, it's generally possible for some things, but eg device driversusually have To Be Tested Out on The Bare Machine. I buy minix Todevelop Linux, SO i Had No Access To Io Registers, Interrupts etc. Under Dos It Would Been Possible To Get Access To All these, Butthen You Don '
. T have 32-bit mode Intel is not that great -. It wouldprobably have been much easier on a 68040 or similar So after getting a simple task-switcher (it switched between twoprocesses that printed AAAA ... and BBBB ... respectively by using thetimer-interrupt - Gods I was proud over that), I still had to continuedebugging basically by using printf The first thing written was thekeyboard driver: that's the reason it's still written completely inassembler (I did not dare move to C. yet - I was still debugging atabout instruction-level) After that I wrote the serial drivers, and voila, I had a simpleterminal program running (well, not that simple actually) It was stillthe same two processes (AAA ..),.. but now they read and wrote to theconsole / serial lines instead I had to reboot to get out of it all, butit was a simple kernel After that is was plain sailing:.. hairy coding still, but I had somedevices, and debugging was easier . I started c at this Stage, Andit Certainly Speeds U P desvelopement. this is also gen i start to getserious about my megalomaniac ideasure letter "a better minix That minix". I Was Hoping I'd Be Able To Recompile GCC Under Linux Some Day ... The Harddisk Driver Was More of To Same: This Time The Problems Withbad Documentation Started To crop up. The PC May Be The MOST USEDADARCHITECTURE IN The World Right Now, But That Doesn't Mean The DOCS Areny Better: in Fact i Haven '
t seen / any / book even mentioning the weird386-387 coupling in an AT etc (Thanks Bruce). After that, a small filesystem, and voila, you have a minimal unix. Twomonths for basic setups, but then only slightly longer until I had adisk-driver (seriously buggy, but it happened to work on my machine) anda small filesystem that was about when I made 0.01 available (lateaugust-91 Something like that?):. it was not pretty, it had no floppydriver, And it couldn't do much anything. I don't thinking. But by Then I WAS HOOKED, And Didn't Want Tostop Until I Could Chuck Out Minix.> 3) Would New Linkers and Loaders Have To BE written before you get a basic> kernel running All versions up to about 0.11 were crosscompiled under minix386 -?. aswere the user programs I got bash and gcc eventually working under0.02, and while a race-condition in the buffer-cache code prevented MEFROM Recompiling GCC with itself, I Was Able To Tackle Smaller Compiles. 0.03 (October? Was Able To Recompile GCC Under Itself, And i thinkthat '