Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

gthvn1/crashtos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CrashTOS: A Crash Test Operating System

We will follow Amateur Makes an OS. It is really interesting so let's do it.

Code, Build & Test

Code

Currently main assembly files are in src/ and others assembly files that are not build but just included are in include/.

Build will create a bin/ directory with the mini-os that is the concatenation of the bootloader in the boot sector (the first 512 bytes of the disk) and stage2 and other programs on others sectors. See the description of the Floppy for more details.

Build

To build the mini os just run make.

Test

To test it with bochs emulator just run make bochs. Check bochsrc.txt if you need a custom setup.

You can also test it on qemu if you run make qemu.

Some notes

Currently it is not working on real hardware probably because we are reading from floppy. We tried to read from drive but it is not working either. There is probably something more to do if we want to generate an USB image and load programs like stage2 from USB. But it will be cool to see it working on real HW...

Steps

  • In the step3 it is really cool to load the "stage2" using a "bootloader". So create an raw image that has the "bootloader" in its first sector and the stage2 after. A sector is 512 bytes that is the size of the bootloader...
  • To prepare this step we just create an empty stage2 that will fill the second sector so the size of the disk will be related to its geometry.
  • Move the stage2 into sector 3 and add something else on the second sector. Use kind of filesystem to know where things are stored. The "filesystem" will just be a string with the filename of things stored on sectors. For the moment we store segment by segment.
  • Read input from user
  • Instead of reading the key pressed we can store keys pressed in memory and when user press "Enter" then we check if the command starts from "F" and do appropriate thing, if it starts by "Q" we quit, and otherwise we get another input from the user. The cool thing with that is that later we will be able to have a shell :)
    • NOTE: we just store the key press in memory (in fact we save the caracter in then expected index of the input string to have a nice print message).
  • Add warm reboot (it is a far jump to 0xFFFF:0x0000)
  • Load file table from sector 2
  • Add an entry for printing registers
  • After running a command add a "return to menu" message, wait for key input , cleanup the screen and go back to menu.
  • Display registers
  • Display file table
  • Implement a prompt instead of menu
    • > ls: Print file table
    • > regs: Print registers
    • > halt: Halt the computer
    • > reboot: Reboot
  • Load file table at 0x1000:0x0000
  • Load stage2 at 0x1000:0x0200
  • Manage backspace
  • Check that user input doesn't overflow the buffer
  • If we don't find any command look into file table if we find a "txt" file or a "bin" file. If we found a "bin" file execute it, if it is a "txt" file display its contents. If it is another extension do nothing. Example: editor should start the editor
    • NOTE: Still need to display content of txt file.
    • Maybe we should load both text file and binary file in memory. Just have different return value in AX to let the stage2 if we can execute it, display it or of an error occured.
  • Use graphics instead of BIOS Video services (interrupt 10h). We can keep it for bootloader. But for other part remove it because when we will switch to protected mode we won't be able to use it.
    • clear screen
    • print char
  • Setup GDT
    • NOTE: BIOS interrupt are not available after switching to protected mode. there is some workaround but a good solution will probably to remove the usage of BIOS interrupt.

Breaking news... Protected mode is here...

To prepare the transition to protected mode we started to remove the usage of BIOS services in the kernel. It is not so easy to do it properly. So we start the modification in the bootloader to load the kernel. The goal is to put in kernel.asm the same thing that we have in stage2.asm (that is not used any more) but without any BIOS interrupt.

  • In the first step have clean screen, the print of a line and we are trying to get input from user. But this part is not working well.
  • Before going further we did the jump, so we did the setup of the GDT...
  • Now we need to fix the get user input... It is fixed.
  • Manage backspace
  • print registers (in protected mode)
  • Add the print of file table
  • manage the fact that we reach the end of the screen...
  • Use PIO to access disk instead of BIOS Disk services (interrupt 13h)
  • load editor
  • play a little bit with editor
  • set ITV to get interrupt from keyboard
  • jump to C, Rust, Zig ???

Kernel is protected

We fixed the issue to get user input. So now the bootloader is running in real mode. It sets:

  • the video mode
  • load the file table
  • load the kernel
  • setup GDT
  • jump in kernel in protected mode

Once inside the kernel all is in protected mode. Currently we are using PIO to get input from keyboard and the screen is managed using the video memory. We still need to manage disk and once done we will propably use a higer level language than C.

Memory Layout

The memory layout is described in src/bootloader.asm.

Disk geometry

  • cylinders'size is 512 bytes
  • sector numbers start from 1 (cylinder and head start from 0)
    • sector 1 -> bootloader (512 bytes ended with magic)
    • sector 2 -> File table (512 bytes padded with 0s)
    • sector 3-6 -> stage2 (2048 bytes padded with 0s)
    • sector 7 -> user input program

Screenshots

  • These screenshot is after the implementation of the backspace. Command ls is not implemented, regs just display the test register.
    screenshot:513389a

  • ls is working now and regs displays registers: screenshot:767956b

About

CrashTOS: A Crash Test Operating System

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published