chinazi-dictatorship

Ciro Santilli 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
grub 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
hajji 48614b45fa Document hajji working %!s(int64=10) %!d(string=hai) anos
multiboot 01a5e64efa Segment registers %!s(int64=10) %!d(string=hai) anos
nasm cba0757990 Bochs works, failed PIT and beep attempts %!s(int64=10) %!d(string=hai) anos
no-linker-script a8d90ac777 Make osdev example more uniform with the hello world %!s(int64=10) %!d(string=hai) anos
printf a8d90ac777 Make osdev example more uniform with the hello world %!s(int64=10) %!d(string=hai) anos
uefi 173111e0d0 rtc %!s(int64=10) %!d(string=hai) anos
.gitignore 7dc6e56e16 big-img, chainload self %!s(int64=10) %!d(string=hai) anos
Makefile 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
README.md 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
TODO.md 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
apm.md a44b659299 bios keyboard %!s(int64=10) %!d(string=hai) anos
apm_shutdown.S 7cff2a3fc9 Factor out precefaces and postfixes, apm_shutdown2 %!s(int64=10) %!d(string=hai) anos
apm_shutdown2.S 7cff2a3fc9 Factor out precefaces and postfixes, apm_shutdown2 %!s(int64=10) %!d(string=hai) anos
bibliography.md 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
bios.md 01a5e64efa Segment registers %!s(int64=10) %!d(string=hai) anos
bios_background.S 01a5e64efa Segment registers %!s(int64=10) %!d(string=hai) anos
bios_carriage_return.S 25235ad9ba Keyboard input, hex printer %!s(int64=10) %!d(string=hai) anos
bios_clear_screen.S 01a5e64efa Segment registers %!s(int64=10) %!d(string=hai) anos
bios_color.S 01a5e64efa Segment registers %!s(int64=10) %!d(string=hai) anos
bios_cursor_position.S 01a5e64efa Segment registers %!s(int64=10) %!d(string=hai) anos
bios_disk_load.S 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
bios_hello_world.S 4fbe9f2246 Set DS to make work on hardware, more failed UEFI attempts %!s(int64=10) %!d(string=hai) anos
bios_keyboard.S a44b659299 bios keyboard %!s(int64=10) %!d(string=hai) anos
bios_keyboard_loop.S 6606a2647d reboot %!s(int64=10) %!d(string=hai) anos
bios_newline.S 25235ad9ba Keyboard input, hex printer %!s(int64=10) %!d(string=hai) anos
bios_one_char.S 7dc6e56e16 big-img, chainload self %!s(int64=10) %!d(string=hai) anos
bios_pixel.S 1f8c00ec8f BIOS 13h video mode draw pixels %!s(int64=10) %!d(string=hai) anos
bios_pixel_line.S 1f8c00ec8f BIOS 13h video mode draw pixels %!s(int64=10) %!d(string=hai) anos
bios_scroll.S 25235ad9ba Keyboard input, hex printer %!s(int64=10) %!d(string=hai) anos
common.h 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
formats.md d217b180be Split up README %!s(int64=10) %!d(string=hai) anos
in.md 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
in_beep.S 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
in_beep_illinois.S 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
in_keyboard.S 173111e0d0 rtc %!s(int64=10) %!d(string=hai) anos
in_mouse.S 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
in_pit.S 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
in_rtc.S cba0757990 Bochs works, failed PIT and beep attempts %!s(int64=10) %!d(string=hai) anos
infinite_loop.S bf4556b972 Infinite loop, rm .elf output %!s(int64=10) %!d(string=hai) anos
interrupt.S 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
interrupt_keyboard.S 25235ad9ba Keyboard input, hex printer %!s(int64=10) %!d(string=hai) anos
interrupt_loop.S 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
interrupt_zero_divide.S 173111e0d0 rtc %!s(int64=10) %!d(string=hai) anos
io.md a44b659299 bios keyboard %!s(int64=10) %!d(string=hai) anos
linker.ld 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
mbr.md 25235ad9ba Keyboard input, hex printer %!s(int64=10) %!d(string=hai) anos
min.S 349c9bd510 Use xor ax instead of mov 0 %!s(int64=10) %!d(string=hai) anos
modes-of-operation.md 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
not-testable-in-userland.md 01a5e64efa Segment registers %!s(int64=10) %!d(string=hai) anos
protected_mode.S 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
reboot.S 6606a2647d reboot %!s(int64=10) %!d(string=hai) anos
segment_registers_real_mode.S 5c2e547b52 bios_disk_load works %!s(int64=10) %!d(string=hai) anos
ss.S 6add24a0ee Init SS and SP by default %!s(int64=10) %!d(string=hai) anos
template.S 173111e0d0 rtc %!s(int64=10) %!d(string=hai) anos

README.md

x86 Bare Metal Examples

Hello world programs that run without an operating system.

  1. Examples
    1. printf
    2. min
    3. No ld script
    4. BIOS
      1. one char
      2. hello world
        1. NASM
      3. newline
      4. carriage return
      5. cursor position
      6. color
      7. background
      8. scroll
        1. clear screen
      9. pixel
        1. pixel line
      10. keyboard
        1. keyboard loop
      11. disk load
    5. reboot
    6. Not testable in userland
      1. Segment registers real mode
        1. SS (TODO)
      2. Interrupt
        1. Interrupt zero divide
        2. Interrupt loop
      3. in
        1. in keyboard
        2. in RTC
        3. in PIT (TODO)
        4. in beep
        5. in beep_illinois
        6. in mouse (TODO)
      4. Protected mode
    7. APM
      1. APM shutdown
      2. APM shutdown 2
    8. Multiboot
    9. GRUB
    10. TODO not working
      1. UEFI
    11. Misc
      1. hajji
  2. Theory
    1. Modes of operation
    2. Formats
      1. MBR
    3. IO
      1. BIOS
      2. APM
    4. Bibliography
  3. TODO

Getting started

sudo apt-get install bochs bochs-sdl build-essential gnu-efi qemu nasm xorriso

Emulator

Run the default program on QEMU:

make run

Run a given program:

make run RUN=min
make run RUN=bios_one_char

Use Bochs instead of QEMU:

make bochs RUN=min

Tested on Ubuntu 14.04 AMD64.

Real hardware

Insert an USB, determine its device (/dev/sdX) with:

sudo lsblk
sudo fdisk -l

Pick the .img file that you wan to run and:

sudo dd if=bios_hello_world.img of=/dev/sdX

Then:

  • insert the USB in a computer
  • during boot, hit some special hardware dependant key, usually F12, Esc
  • choose to boot from the USB

When you are done, just hit the power button to shutdown.

Tested on: ThinkPad T400.

Big image

Create a big.img that contains all examples that can be booted from GRUB:

make big-img

Now if you do:

sudo dd if=big.img of=/dev/sdX

you can test several examples with a single USB burn, which is much faster.

You will also want to change the boot order to put the USB first from the F12 BIOS menu. This way you don't have to hit F12 like a madman every time.