Reboot pc (code)

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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Reboot pc (code)

Post by Solar »

marcio.f wrote:
GLneo wrote: also to shut off the computer is very hard (i think) you have to go to real mode or something then comunicate with some protical api something.

p.s. there was a thead about it... somewhere
If there is I haven't found it because I searched the forum before creating this thread ;)
Try this one, found by searching for "ACPI shutdown".

Your google-fu is weak today. ;)
Every good solution is obvious once you've found it.
marcio.f

Re:Reboot pc (code)

Post by marcio.f »

@Solar, GLneo:
It was 3 AM or something when I searched so.. :) sorry for that

[hr]
@Code Slasher:
Your code didn't work on Bochs for me, what version are you using?
To be honest, I didn't use it as assembly, but rather as C code:

Code: Select all

#define KBRD_INTRFC 0x64
#define KBRD_RESET 0xFE /* reset CPU command */
#define KBRD_BIT_UDATA 1 /* user data is in buffer (command buffer is empty) (bit 1) */

#define bit(n) (1<<(n)) /* Set bit n to 1 */

/* Check if bit n in FLAGS is set */
#define check_flag(flags, n) ((flags) & bit(n))

/* Force CPU to wait until the keyboard command buffer is empty */
#define keyboard_comm_wait() while (check_flag(inb(KBRD_INTRFC), KBRD_BIT_UDATA) != 0)

void reboot()
{
   disable(); /* disable all interrupts */
   keyboard_comm_wait();
   outb(KBRD_INTRFC, KBRD_RESET);
   halt(); /* <-- here you have STI instead */
}
Right now I'm using the reboot() function exactly as above with an extra line after "disable()", which is "keyboard_clr_buffer()" to clear both buffers (output and command buffers).
Slasher

Re:Reboot pc (code)

Post by Slasher »

I've been using this since Bochs 1.4
marcio.f

Re:Reboot pc (code)

Post by marcio.f »

Code Slasher wrote: I've been using this since Bochs 1.4
That's strange.. I'm using v2.2.
Have you prepared something before calling the reboot function?
Slasher

Re:Reboot pc (code)

Post by Slasher »

No, nothing special.

I just used it as a means to reboot my pc when I was testing with a computer that didn't have a reset button. Didn't want to kill my hard drive turning the pc on and off every second ;)
oswizard

Re:Reboot pc (code)

Post by oswizard »

This may be irrelevant if a reset fixes this anyways, but if you re-mapped the PIC, try mapping it back. That could explain the strange interrupt messages from bochs.

When I reboot the pc in my OS, I write the value 0x1234 to 0x0472 in the BIOS data area, signalling a warm boot. Perhaps bochs detects a warm boot and resets everything - a20, pic, etc - things that are controlled by hardware that wouldn't be reset by pulsing the reset line.

On a cold boot, as you are doing now by not writing that value, perhaps bochs thinks everything should be initialized...

Or I could be completely wrong... That has been known to happen to me before! :)

Mike
marcio.f

Re:Reboot pc (code)

Post by marcio.f »

@Code Slasher
That's my main reason too ;)

@Mike
Hi,
Mike wrote: if you re-mapped the PIC, try mapping it back. That could explain the strange interrupt messages from bochs.
I've even tried in a kernel with only the reboot code but Bochs still panics.
When I reboot the pc in my OS, I write the value 0x1234 to 0x0472 in the BIOS data area, signalling a warm boot.
The BIOS data area is located at 0040:0000h, right? I'm feeling really dumb here.. but how can I access that location in protected mode?
fraserjgordon

Re:Reboot pc (code)

Post by fraserjgordon »

I don't know if this helps or not but I've found that sometimes when Bochs resets (especially after a PANIC) it has this "Control not ready" error for the floppy disk drive. I think it is because it never properly released the floppy disk drive resource borrowed from the host system, and attempts to read from it again. At this point the drive is still considered busy so the call fails.

This is just total speculation, btw. I don't know enough about the Bochs source code nor the Win32/Unix APIs for drive access to know for sure.
oswizard

Re:Reboot pc (code)

Post by oswizard »

@Fraser - good idea. I run bochs off of an image file, though...

@Marcio -
((segment << 4) + offset)

So, 0x0040:0x0072 --> 0x0472.

0xB800:0x0000 --> 0xB8000.

Just access the physical address 0x0472 and write 0x1234. If paging is enabled and the first page is unmapped (which it should be to catch null-pointer references), just write to whatever linear address is mapped to the first physical page of memory.

Although, I just looked at rombios.c in the bochs source and it zeros out the data area before it does anything else - so my theory is disproven - at least on bochs.

Fraser's theory seems a bit more plausible. I don't know any specifics for it, though.

Good luck,
Mike


PS. Is there any way the escape key can not erase the text input field? This is the second time I've hit the escape key twice to dismiss a menu instead of once - and the second time erased my message!
marcio.f

Re:Reboot pc (code)

Post by marcio.f »

@Fraser Gordon:
It's an interesting idea.. but I'm not using a physical floppy drive. That's because I have a laptop, so it doesn't have one; to address this I use Virtual Floppy Drive (http://chitchat.at.infoseek.co.jp/vmware/vfd.html) instead of an image file because it's much easier to edit its contents. Anyway, I tried using directly an image file on Bochs but the panic is still the same.

[hr]
@Mike:
I'm so sorry about asking, I thought that to access the physical address like segment:offset, only applied to real mode and not to protected mode too :)
I've done what you said but Bochs panics.. but this isn't much of a problem as it works on real hardware though.

PS: Use Firefox ;) (http://www.mozilla.org/products/firefox/)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Reboot pc (code)

Post by Pype.Clicker »

okay, dudes, you now have a nice wiki page to edit those stuff ...

http://www.osdev.org/osfaq2/index.php/PowerManagement

i tried to collect what's already available on the subject. If you write the magic word "PowerManagement" on another page, it will automagically link that new page to the one i point you to.

so feel free to add extra material you might have ...
marcio.f

Re:Reboot pc (code)

Post by marcio.f »

Nice ;) thanks
Can I (or someone else) add a link under "Hardware" in the main page (http://www.osdev.org/osfaq2/index.php/HomePage) to "Power Management" ?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Reboot pc (code)

Post by Pype.Clicker »

Marcio wrote: Nice ;) thanks
Can I (or someone else) add a link under "Hardware" in the main page (http://www.osdev.org/osfaq2/index.php/HomePage) to "Power Management" ?
Only admins can do this because the HomePage is locked ... we'll do quite soon (e.g. asap unless Solar does it first ;). Meanwhile, you can already see it in the HardWare category ...
Post Reply