1. Sending 0xfe to the PS/2 controller
2. Sending 0x02 and then 0x04 to port 0xcf9
3. Tripple fault
I tested rebooting using these methods as well as with the reset button both on bochs and my real machine.
But in Bochs it seems the RTC timer stops working after rebooting using either the PS/2 or the port 0xcf9 method but not after rebooting using any other method.
Also when the RTC stops working it won't work anymore even after I reboot using either the tripple fault method or the reset button.
I have also tested this on VirtualBox and my real machine, but the problem seems to be specific to Bochs so far.
This is the most important bit of the reboot code:
Code: Select all
.ps2:
mov esi, .ps2msg
call boot_print_default
mov byte [PS2.command], 0xfe ;pulse reset line
call PS2_cscw
jmp .fail
.pci: ;TODO: according to linux source code I should check for the right PCI type to know if this is safe.
mov esi, .pcimsg
call boot_print_default
mov dx, 0cf9h
mov al, 02h
out dx, al
call .wait
mov al, 04h
out dx, al
jmp .fail
.tripple_fault:
mov esi, .triflt
call boot_print_default
lidt [.BAD_IDTR]
int 3 ;debug interrupt
jmp .fail
.BAD_IDTR dw 0, 0, 0
Here is the part responsible for setting up the PIC and RTC:
Code: Select all
;intialize PIC
;ICW1
mov al, 00010001b
out 0020h, al
out 00a0h, al
;ICW 2
mov al, 20h ;after reserved interrupts
out 0021h, al
mov al, 28h
out 00a1h, al
;ICW 3
mov al, 4
out 0021h, al
mov al, 2
out 00a1h, al
;ICW 4
mov al, 1
out 0021h, al
out 00a1h, al
;enable IRQ 8
in al, 0xa1
and al, 11111110b
out 0xa1, al
;enable RTC
mov al, 8bh
out 70h, al
in al, 71h
or al, 01000000b
and al, 11001111b
xchg bl, al
mov al, 8bh
out 70h, al
xchg bl, al
out 71h, al
;set RTC frequency
mov al, 8ah
out 70h, al
in al, 71h
and al, 0xf0
or al, 08h ;256Hz
xchg al, bl
mov al, 8ah
out 70h, al
xchg al, bl
out 71h, al