From owner-freebsd-hackers@FreeBSD.ORG Mon Dec 10 07:38:11 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9EBC7C7E for ; Mon, 10 Dec 2012 07:38:11 +0000 (UTC) (envelope-from zbeeble@gmail.com) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 160088FC12 for ; Mon, 10 Dec 2012 07:38:10 +0000 (UTC) Received: by mail-la0-f54.google.com with SMTP id j13so2194109lah.13 for ; Sun, 09 Dec 2012 23:38:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=yVRcBAa7XulQDYTZ2tUYOn/n1Z3hZNDwD6z7QtGkK8U=; b=rHDMNugta6MVtGeRfwVBeJafEUf+cuY8zaHk6kC3ity/0KolEzyWBedvVVZRLlGjCH jMh0Qb3VGpJJkwO3fUR/ysFri7wfjWFDSzQrP9b8VFPoOFPktRjhcFL6d9GaXbaxUDrQ 0V5EtyC2EdOjm3RTylTFBiIFrLMakcPW7R4mIzKCSAnbyYkoFUIyoRtW4KqI1E8rwUwh ILMNX71AD7tNpO39xKdS5k//m4SFOpjA1AlDFsl/KUPv0HBtlWM5Fp4973zkjeU3YLe4 bbr8afAiHTZ+DlLtCSSWdrdPr7CZXmxgaJJMf7vt4LuA7RaYTj33Q5fq2mClesOmW8lY 1hbQ== MIME-Version: 1.0 Received: by 10.152.148.129 with SMTP id ts1mr5710833lab.19.1355125083589; Sun, 09 Dec 2012 23:38:03 -0800 (PST) Received: by 10.112.61.33 with HTTP; Sun, 9 Dec 2012 23:38:03 -0800 (PST) In-Reply-To: References: Date: Mon, 10 Dec 2012 02:38:03 -0500 Message-ID: Subject: Re: using FreeBSD to create a completely new OS From: Zaphod Beeblebrox To: Aryeh Friedman Content-Type: text/plain; charset=ISO-8859-1 Cc: FreeBSD Mailing List X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Dec 2012 07:38:11 -0000 On Sun, Dec 9, 2012 at 11:48 PM, Aryeh Friedman wrote: > For personal hobby reasons I want to write an OS completely from > scratch (due to some aspects of the design no existing OS is a > suitable starting place)... what I mean is I want to start with the > MBR (boot0) and go on from there... I only have one *REAL* machine to Well... most would say that the interesting part of an OS has very little to do with the loader, but who am I to judge: maybe a loader is interesting for you. There are quite a few things that can be loaded and useful from an MBR. Pretty much any machine will provide you with a boot environment that has lived longer than any other. It's pretty much DOS without a filesystem, tho. In freebsd, you want to look at /boot/mbr and maybe (later) /boot/loader (or one of it's variants). > work with which means I need to work with something like > emulators/virtualbox-ose... I also want to do as many automated tests > as possible (for example seeing if the installer copied the MBR [and > later other stuff] correctly to the virtual HDD).... for this reason I > have a few questions on vb (or perhaps QEMU if not possible in vb): > > 1. Can it be scripted? > 2. Is there any documentation on the various virtual HDD formats and > such (that way I can check the "physical" drive and not by indirect > query)? The format of an MBR (master boot record) is documented everywhere. I'm pretty sure wikipedia has a good article on it. This mailing list is not google, BTW. > Also can people give me some idea of a good general > development/testing framework.... the one I have in mind so far is: > > 1. Write enough of the OS in FreeBSD to boot and give a command prompt > and then develop using it (assume that there is a working compilor > [note I am doing it completely in Java (note 1) and will be using > either gjava (gcc) or writing my own compiler]) > > Notes: > > 1. Due to OS's needing to address physical RAM directly (DMA mapped > I/O) I will be introducing some form of ptr's into java with the > compiler or native My first thought was the humor of getting java to deal with segment registers. It's hard enough in C. But in all seriousness, most systems go from the firmware to something like a bootblock (often called a stage one boot) to a smarter bootloader (stage two boot) to activating the OS. In a PC-ish world for FreeBSD, that's BIOS->/boot/mbr->/boot/loader->kernel. Specifically locore.s (note: assembly language file). locore.s is one of a few regions of kernels that are generally _not_ written in high level languages. Other's include the very lowest level of the scheduler and the virtual memory manager. In locore's case, you can't express the special instructions (for a PC) to exit real mode and enter virtual mode (or some such transformation --- I really haven't been there in awhile). Note that FreeBSD boots on a number of things and that each boot process is a little bit different. If you're going to write an OS from scratch, you might start with something _way_ simpler than FreeBSD. Minix would be a good choice. I think it still comes as a book you buy with bootable code. If you haven't done OS work before, the book part might get you going faster than diving into the FreeBSD codebase.