Page 1 of 1
Reboot the computer using assembly language
Posted: Mon Sep 07, 2015 2:32 pm
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

Re: Reboot the computer using assembly language
Posted: Mon Sep 07, 2015 2:54 pm
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.
Re: Reboot the computer using assembly language
Posted: Wed Sep 09, 2015 12:29 pm
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):
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
Re: Reboot the computer using assembly language
Posted: Wed Sep 09, 2015 4:53 pm
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.
Re: Reboot the computer using assembly language
Posted: Wed Sep 09, 2015 5:27 pm
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.
Re: Reboot the computer using assembly language
Posted: Sat Sep 12, 2015 6:19 am
by sebihepp
Why not just generate a "triple fault"?
Re: Reboot the computer using assembly language
Posted: Sat Sep 12, 2015 6:23 am
by Octocontrabass
A triple fault should be the last resort, since
it won't reboot some PCs.
Re: Reboot the computer using assembly language
Posted: Tue Sep 22, 2015 4:10 am
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:
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.
Re: Reboot the computer using assembly language
Posted: Tue Sep 22, 2015 11:22 am
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:
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
Re: Reboot the computer using assembly language
Posted: Tue Sep 22, 2015 2:06 pm
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:
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?
Re: Reboot the computer using assembly language
Posted: Tue Sep 22, 2015 2:37 pm
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:
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.