Advertisement
Theo_Gaillard

Bootloader HelloWorld

Oct 4th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. /*
  2. * https://stackoverflow.com/questions/32931063/write-a-simple-bootloader-helloworld-error-function-print-string
  3. */
  4.  
  5. asm(".code16gcc");
  6. asm("jmpl $0x0000, $main\n");
  7.  
  8. void getch();
  9. void cout(const char* str);
  10.  
  11. void main()
  12. {
  13.     asm volatile("xor %ax, %ax\n");
  14.     asm volatile("mov %ax, %ds\n");
  15.  
  16.     cout("BootLoader\n\r");
  17.     cout("Hello World\n\n\r");
  18.     cout("Press any keys to continue");
  19.     getch();
  20.     cout("\n\n\rDone\n\r");
  21.     cout("You can now shutdown the computer");
  22.  
  23.     asm volatile("cli\n");
  24.     asm volatile("hlt\n");
  25. }
  26.  
  27. void getch()
  28. {
  29.      asm volatile("xorw %ax, %ax\n" "int $0x16\n");
  30. }
  31.  
  32. void cout(const char* str)
  33. {
  34.     while(*str)
  35.     {
  36.         asm volatile("int $0x10" : : "a"(0x0e00 | *str), "b"(0x0007));
  37.         ++str;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement