Lecture 2: Abstractions and boostrapping
Prof. Eggert

Notes prepared by: Nathan Acklander, Terrence Kennedy, Kalvin Huang

"Computing is different because of complexity"

Moore's Law states that the number of transistors you can put on a chip at minimum cost doubles two years. This law has been the driving force for technological innovation in the late 20th and early 21st centuries. Expects however belive that Moore's Law is likely to collapse in the next 10 years due to material limitations.

moore

Kryder's Law is a term for an analysis of the density and capability of hard drive storage media over time. The emergence of smaller and more efficient storage media is key to the larger developments in deployed technology, including fast processors and different kinds of commercial and research application.

kryder

The Univac1 was the 1st successful computer designed. It was used for general purpose computing with large amounts of input and outputs. Almost all circuits had error-correcting because there were no simluators to simulate the computer. However, it was used to simulate the Univac2, which reduced many error-correcting redundancies.

d(technology)/dt = k* technology (the rate of growth of technology is proportional to technology.

An operating system for the parnoid

This is not a commercial OS like Windows, GNU/Linux.

- Things we want:

- Issues::

BIOS- Basic Input/Output System

cpu

By convention, if the first sector of the device looks like a Master Boot Record (MBR) treat it as a bootable device and decide what to do next.

Below is an example MBR layout for x86 (512 Bytes)

MBR layout

PICTURE

Our own OS will put a small program into the MBR which will copy our WC program from disk to RAM, and then jump to WC. This program is known as the Boot Loader.

Boot Process in our OS

BIOS - loads boot loader -->

Boot Loader - loads WC

This is known as chained loading. But in reality, the booting process is a lot more complicated. The booting process of the ubuntu OS is shown below.

BIOS loads MBP boo loader (OS agnostic) -->

MBR loads VBR boot loader (Volume boot loader at start of parition) -->

VBR loads GRUB (Grand Unified Boot Loader) -->

GRUB loads Linux Kernel -->

Linux Kernel loads 'init' (process 1) -->

init loads other programs 

Sample Code

Below is an example of Boot-loader source code:

int main(void){

  for(int i = 1; i < 20; i++){

    read_sector(i,0x100000+(i-1)*512);

    goto 0x100000;

}

We use the following x86 instructions to talk to the bus

inb

outb

insl

For example, to see the status of the disk controller we can look at a special status register, 0x1f7

An example of the READ_SECTOR sourrce code is shown below

void read_sector(int s, intptr_t a){

  while((inb(0x1f7) && 0xc0) != 0x40)

    continuel

  outb(0x1f2,1); // # of sectors we want to read

  outb(0x1f3,s && 0xff); //These are sector offsets

  outb(0x1f4,s>>8 && 0xff);

  outb(0x1f5,s>>16 && 0xff);

  outb(0x1f6,s>>24 && 0xff);

  outb(0x1f7,0x20); // read sector command

  wait_for_disk();

}

We must then wait for the disk to be unbusy again. We can even make a seperate function 

void wait_for_disk(void){

  while(inb(0x1f7) && (0x00) != 0x40)

    continue;

}

We can now write our WC program

int main(void){

  int nwords = 0;

  bool inword = 0;

  int s = 5000000000/512;

  for(;;s++){

    char buf[size];

    read_sector(s,(intptr_t)buf)

    for(int j = 0; j < 512; j++){

      if(!buf[j]){

        write_out(nwords);

        return

      }

        char lc = buf[j]|('a' - 'A');

        bool thisalpha = 'a' <= buf[j] && buf[j] <= 'z';

        nwords += ~inword && thisalpha;

        inword = thisalpha;

    }}}

How do we draw to the screen?

void write_out(int nwords){

  char *[ = (char*)0x8000+24*80;

  do{

  *--p = nwords%10+'\0';

  *--p = 7; 

  } while(nwords /1- 10!= 0)

}