Reboot the computer using assembly language

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Kirdow
Member
Member
Posts: 35
Joined: Sun Sep 06, 2015 2:20 pm
Libera.chat IRC: Kirdow
Location: Sweden

Reboot the computer using assembly language

Post by Kirdow »

I want to reboot the computer. I know how to shutdown the computer by connecting to ASM and the shutting down. but now I want to be able to reboot.
I've done some general researched and saw that reboots is done by first shutting down and also sending a "message" to the motherboard that right before you power off, you cancel, reset some values, and instead act if you just pressed the button and powered on the computer.

Remember, If it's possible, I don't want to implement some complicated library and so on. I would want pure assembly and from scratch (if possible). And what I want is when I reboot, I want BIOS to go through the boot order, so if the user has my OS to boot after for example Windows, which means he has to go into bios manually and then start my OS manually, then when my OS performs a reboot, BIOS should go though the boot order and see "aah, I should boot Windows". Get it? So I don't just want to reload my bootloader from scratch. I want the whole system to reboot, kind of the reboot button on Windows XP/7/8/8.1/10 etc... So how do I add a reboot functionality to my code? Please show code to help me understand what to do :)
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Reboot the computer using assembly language

Post by Nable »

In fact, reboot is much simpler than shutdown. You can find general examples here: http://wiki.osdev.org/Reboot .
But you should be careful: all power-related things are highly system-specific (some method could work on your PC and lead to a total mess on another one). Proper ACPI implementation (I'm in doubt whether you have it) covers a high percentage but it's far from 100%, as there are tons of machines with broken ACPI (or even complete absence of it).

tl;dr: one method isn't enough, you should implement many of them and apply them in a right order.
User avatar
micccy
Posts: 11
Joined: Sat Sep 05, 2015 2:10 am
Libera.chat IRC: micccy
Location: Italy

Re: Reboot the computer using assembly language

Post by micccy »

Remember that you can also do a CPU reset via the 8042 keyboard controller.
If you are working in (un)real mode, you can perform a very simple reboot jumping to the POST procedure (FFFF:0000):

Code: Select all

PUSH    0FFFFh
PUSH    0000h
RETF
That puts the address of the POST procedure into the stack and then perfmorms a RETF which read the value to put in CS:IP from the stack.

Sorry if my english isn't very good
You learn more by a single triple fault than by reading the whole Intel specification...
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Reboot the computer using assembly language

Post by Nable »

GiacoMic wrote:Remember that you can also do a CPU reset via the 8042 keyboard controller.
But one should also note that 8042 (and sometimes even its emulation) is absent on recent systems. Attempt to use I/O ports of absent device could lead to unexpected results.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Reboot the computer using assembly language

Post by BrightLight »

Nable wrote:But one should also note that 8042 (and sometimes even its emulation) is absent on recent systems. Attempt to use I/O ports of absent device could lead to unexpected results.
That's why 8042 should be a fallback method, and ACPI reset should be the main method.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
sebihepp
Member
Member
Posts: 256
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: Reboot the computer using assembly language

Post by sebihepp »

Why not just generate a "triple fault"?
Octocontrabass
Member
Member
Posts: 6298
Joined: Mon Mar 25, 2013 7:01 pm

Re: Reboot the computer using assembly language

Post by Octocontrabass »

A triple fault should be the last resort, since it won't reboot some PCs.
User avatar
Kirdow
Member
Member
Posts: 35
Joined: Sun Sep 06, 2015 2:20 pm
Libera.chat IRC: Kirdow
Location: Sweden

Re: Reboot the computer using assembly language

Post by Kirdow »

I know this one is a few weeks old but I think I need to open this one again.
I had this to reboot:

Code: Select all

db 0x0ea
dw 0x0000
dw 0xFFFF
but I've seen on multiple places this is not a good idea and could sometimes fail, like it did for me now after fixing segments.

So how do I reboot using something like APM? and also, I am in 16-bit Real Mode, and if you do CTRL+ALT+DEL it reboots the system. so I wonder, is there a way to manually do that from code?
I would like to have both ways.
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Reboot the computer using assembly language

Post by BASICFreak »

Kirdow wrote:I know this one is a few weeks old but I think I need to open this one again.
I had this to reboot:

Code: Select all

db 0x0ea
dw 0x0000
dw 0xFFFF
but I've seen on multiple places this is not a good idea and could sometimes fail, like it did for me now after fixing segments.

So how do I reboot using something like APM? and also, I am in 16-bit Real Mode, and if you do CTRL+ALT+DEL it reboots the system. so I wonder, is there a way to manually do that from code?
I would like to have both ways.
If you are in real mode, why not look at int 19h (BootStrap Loader) http://www.ctyme.com/intr/rb-2270.htm
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
User avatar
Kirdow
Member
Member
Posts: 35
Joined: Sun Sep 06, 2015 2:20 pm
Libera.chat IRC: Kirdow
Location: Sweden

Re: Reboot the computer using assembly language

Post by Kirdow »

BASICFreak wrote:
Kirdow wrote:I know this one is a few weeks old but I think I need to open this one again.
I had this to reboot:

Code: Select all

db 0x0ea
dw 0x0000
dw 0xFFFF
but I've seen on multiple places this is not a good idea and could sometimes fail, like it did for me now after fixing segments.

So how do I reboot using something like APM? and also, I am in 16-bit Real Mode, and if you do CTRL+ALT+DEL it reboots the system. so I wonder, is there a way to manually do that from code?
I would like to have both ways.
If you are in real mode, why not look at int 19h (BootStrap Loader) http://www.ctyme.com/intr/rb-2270.htm
I don't have time to test it right now, but does this reboot thing go through the boot disk order or does it just reboot the floppy? for example when I develop, I have the harddrive to boot before the floppy, so when I use int 19h, will it in this case boot from the harddrive or the floppy?
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Reboot the computer using assembly language

Post by BASICFreak »

Kirdow wrote:
BASICFreak wrote:
Kirdow wrote:I know this one is a few weeks old but I think I need to open this one again.
I had this to reboot:

Code: Select all

db 0x0ea
dw 0x0000
dw 0xFFFF
but I've seen on multiple places this is not a good idea and could sometimes fail, like it did for me now after fixing segments.

So how do I reboot using something like APM? and also, I am in 16-bit Real Mode, and if you do CTRL+ALT+DEL it reboots the system. so I wonder, is there a way to manually do that from code?
I would like to have both ways.
If you are in real mode, why not look at int 19h (BootStrap Loader) http://www.ctyme.com/intr/rb-2270.htm
I don't have time to test it right now, but does this reboot thing go through the boot disk order or does it just reboot the floppy? for example when I develop, I have the harddrive to boot before the floppy, so when I use int 19h, will it in this case boot from the harddrive or the floppy?

From the link I gave:
(Table 00653)
Values Bootstrap loader is called with (IBM BIOS):.
CS:IP = 0000h:7C00h.
DH = access

bits 7-6,4-0:
Don't care

bit 5:
=0 device supported by INT 13.
DL = boot drive
00h first floppy
80h first hard disk
So, as with reading a disk DL = drive.
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.
Post Reply