Search (using Google):  Web Karig

 

20 December 2004

Booting from hard disk

STOP: THIS SOFTWARE IS DANGEROUS

(Big nasty skull and crossbones, wreathed in flames)

This software writes to the hard disk in such a way that it will destroy any operating systems installed on it. Therefore, if your machine has any software or data that you don't want to lose, then do not run this software on your machine.

What I've been up to

I've been puttering around over the past four months. One of the things I was doing was writing a Windows application using FASM. The application was a prototype for Karig. It would load precode (pre-parsed ColorForth source code) from a file and display it in the application window, and you could flip through the blocks by pressing the Page Up or Page Down key.

While doing this, I made up my mind that Karig would not be an OS in itself. It would not have multitasking as Chuck Moore's version of ColorForth has. It would be a simple precode editor and interpreter. I'd use Karig to write an OS (or at least a simple kernel and some programs).

My proposed setup is to have my laptop boot into a menu:

Press 1 or 2:

1) Karig
2) Sys2

I'd press 1 to write and test code for my OS, or I'd press 2 to test-run the OS (which I'm calling "Sys2" because it will be the second system on the laptop).

I like this idea because it means that I can take my laptop out somewhere and work on the OS, and if the OS can't run without triple-faulting and rebooting, I can always boot back into Karig to try to fix the problem. As things stand right now, I have to do all my coding on my main computer and then copy the assembled code to the laptop using floppies. Once Karig (the code editor and interpreter) is running on my laptop, I'll be able to code on my laptop. If I can take the laptop out somewhere, I can work on my OS away from home.

So the first thing I have to do is make sure I can install the software to my laptop successfully.

The demo

The software has four parts:

  • The installer (INSTALLER.ASM). This is the boot sector on the floppy. Its function is to copy the other three parts of the software onto the hard disk.
  • The boot menu (OS_MENU.ASM). This will be installed as the new boot sector on the hard disk. It lets me boot either Karig or the other system.
  • Karig (KARIG.ASM). This is 62 sectors of code and data. It will be installed in the first track of the hard disk.
  • Sys2 (SYS2.ASM). This is up to three sectors of code and data. It will be installed in the first sectors of the second track of the hard disk.

The code I have supplied here is only a demo. When I boot Karig, I get a message proving that all of the sectors from the first track of the hard disk did indeed load:

Press 1 or 2:

1) Karig
2) Sys2

Loading Karig   .............................................................
62 sectors loaded.

Booting Sys2 displays a simpler message:

Press 1 or 2:

1) Karig
2) Sys2

Sys2 up.

The code should be pretty self-explanatory, but there are some subtleties.

  • The installer (INSTALLER.ASM) prints a message, waits for you to press the Y key, reads data from the floppy disk into memory, and writes the data from memory onto the hard disk. This is a boot sector, so all the installation code must fit within 512 bytes. The installer copies 65 sectors from the floppy onto the hard disk. This is one sector for the boot menu, 62 for Karig, and two for Sys2.
  • The boot-menu sector (OS_MENU.ASM) prints the menu and boots Karig if you press 1 or Sys2 if you press 2. This boot sector does not investigate the hardware, set up protected mode, or do anything else except display the menu and load and run the chosen system.
  • Karig (KARIG.ASM) is nothing but a demo here. At the beginning of each sector (512 bytes) is code to print part of a message to the screen and then jump to the beginning of the next sector. If the complete message is printed, then this is proof that all 62 sectors loaded. Note that Karig must indeed be padded to exactly 62 sectors (31,744 bytes) long, or Sys2 won't load properly, because it won't be aligned at the beginning of the first sector after Karig.
  • Sys2 (SYS2.ASM) is also nothing but a demo here. It just displays "Sys2 up." and hangs the machine. Note that the first sector in Sys2 is loaded at 0x7C00, because the first sector in an OS is expected to be a boot sector and therefore should be assembled to address 0x7C00. Note also that the installer will not install any more than two sectors for Sys2, which makes sense because the purpose of Karig is to let me write code for Sys2 on my laptop.

Starting with this entry, I am no longer simply saving code to a floppy and running the floppy. Now, to test-run my code, I must install the code onto my laptop's hard disk, remove the floppy, and reboot the laptop.

In future entries I'll be writing real code to replace the demo code in KARIG.ASM and SYS2.ASM. I'll probably keep working until I have a half-finished system on the hard disk before I post again.

Check the index for other entries.