Shut Down!

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.
drizzt

Shut Down!

Post by drizzt »

I've written this assembly procedure for my OS...
would have to shut down computer with motherboard with BIOS APM, using int 15h.
It seems to be very useful... ;) Does it works in your computer ? ???

_shutdown:
mov ax, 5301h
xor bx, bx
int 15h??? ; Connect BIOS APM

mov ??? ax, 530fh
mov bx, 1
mov cx, 1
int ???15h ; Engage BIOS APM

mov ax, 5307h
mov bx, 1
mov cx, 3
int 15h ; Shut down !!!

halt:
???jmp ???halt ; for computer without ATX motherboard... just hang!
EclipseOS

Re:Shut Down!

Post by EclipseOS »

I tried the above code in my c++ kernel and like this:

extern "C" void off();

void shutdown()
{
diable();
off();
cout << "You can power off now";
halt();
}

void off is called from the asm code:

[global _off]
_off:
mov ax, 5301h
xor bx, bx
int 15h ; Connect BIOS APM

mov ax, 530fh
mov bx, 1
mov cx, 1
int 15h ; Engage BIOS APM

mov ax, 5307h
mov bx, 1
mov cx, 3
int 15h ; Shut down !!!

My problem is when I run shutdown(), I get an unknown exception. Any takers? Thanx
BI lazy

Re:Shut Down!

Post by BI lazy »

Hi, Eclipse ( ... total eclipse of my heart ... ?bonnie tyler song?)

It is of course helpful if you either return to real mode for this procedure - or have it run in vm86 mode - which is veeery handy for some other nifty things like changing graphics mode.

Because ....

if you attempt to execute this kind of code in protected mode environment, you will find it difficult to convince the CPU in order to obey. exceptions are your best friend then. The excetio you gett might be a GPF exception.
EclipseOS

Re:Shut Down!

Post by EclipseOS »

okay, how do I go back into real mode or v86 mode?
(Remember, I'm new at this)

Thanx for the reply
DennisCGc

Re:Shut Down!

Post by DennisCGc »

drizzt wrote: I've written this assembly procedure for my OS...
would have to shut down computer with motherboard with BIOS APM, using int 15h.
It seems to be very useful... ;) Does it works in your computer ? ???

_shutdown:
mov ax, 5301h
xor bx, bx
int 15h??? ; Connect BIOS APM

mov ??? ax, 530fh
mov bx, 1
mov cx, 1
int ???15h ; Engage BIOS APM

mov ax, 5307h
mov bx, 1
mov cx, 3
int 15h ; Shut down !!!

halt:
???jmp ???halt ; for computer without ATX motherboard... just hang!
No, it doesn't work at all.
EclipseOS

Re:Shut Down!

Post by EclipseOS »

Okay then, could someone show me a code that will bring me into v86 mode or real mode and then shutdown an ATX motherboard that wroks? (I use c++ or c). Thanx
DennisCGc

Re:Shut Down!

Post by DennisCGc »

EclipseOS wrote: Okay then, could someone show me a code that will bring me into v86 mode or real mode and then shutdown an ATX motherboard that wroks? (I use c++ or c). Thanx
For real mode, see this thread: http://www.mega-tokyo.com/forum/index.p ... 30;start=0

Or, do a quick search on this MT board, there's another thread that's related to the return to real mode subject ;)
Schol-R-LEA

Re:Shut Down!

Post by Schol-R-LEA »

Actually, you can use APM from protected mode with some motherboards, but it requires some additional work before going into p-mode. You first need to call Int 15h, ax=5300h to determine if the motherboard supports 32-bit protected mode APM. If it does, you then need to call Int 15h, ax=5303h, which returns three physical segment offsets - one for the 32-bit p-mode BIOS code, one for the 16-bit p-mode code, and one for the 16-bit data. When switching to p-mode, you need to incorporate these into your GDT as segment descriptors. The BIOS code then can be invoked by the kernel (calls must be CPL0) by a far call to the beginning of the 32-bit code segment, using the same register arguments as the real mode Int 15h calls to select the specific service.
EclipseOS

Re:Shut Down!

Post by EclipseOS »

Okay I've been given the above link on APM over and over again, but the truth is, I just don't know assembly as good as I should. Could someone please put the info from the links above into an assembly code for me? I just want to see how it works. Thanx alot.
Schol-R-LEA

Re:Shut Down!

Post by Schol-R-LEA »

Well, part of it is going to depend on how you get into p-mode; offhand, I'm not sure if the APM hooks are part of the information that GRUB passes to you, though I recall that there is a command-line option to return whether APM is supported or not, so I would assume so.

To do it yourself, you'd have to first write a real-mode routine to check for APM 32-bit support, and to retrieve the hooks (code is written for NASM, and is not tested):

Code: Select all

get_apm:
   mov ax, 0x5300
   int 0x15
   jc .apm_error      ; if CF is set,  then there was an error in processing the service
   test ax, 0x0002    ; test bit 1 - if set, then p-mode is supported
   jne .apm32_nosup 
   ; 32-bit APM os supported, now get the descriptors
   mov ax, 0x5303
   int 0x15
   jc .apm_hook_error
   ; no error, so save the returned values in memory
   mov word [pmode_base], ax
   mov dword [pmode_offset], ebx
   mov word [rmode_code], cx
   mov word [rmode_data], dx
   mov word [code_length], si  ; will be garbage if not APM 1.1 or higher
   mov word [data_length], di
   ret

.apm_error:
   ;; do whatever error handling you want to do
   ret

.apm_hook_error
   ;; do whatever error handling you want to do
   ret

.apm32_nosup:
   ;; do whatever you need to do to indicate that there was no p-mode support to the p-mode kernel
After that, you would use the values in pmode_base, rmode_code and rmode_data to create descriptors for your GDT; how you would do this would depend on how you initialize your GDT.

HTH. C&CW.
EclipseOS

Re:Shut Down!

Post by EclipseOS »

I'm not using GRUB and I didn't write the bootloader I am using. Neo wrote it and I'm not very good in asm. You can download Eclipse OS src which comes with the bootloader here: http://www.sourceforge.net/projects/eclipse-os/
Take a look at the bootloader code and see if you can help me develop the code required to get back into real mode.

Thanx
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:Shut Down!

Post by Pype.Clicker »

sounds like learning a bit more of assembly will be required for you before you can actually shut down a machine, no ?

don't take it bad, but even while using an existing bootloader makes things easier (avoiding some early and clumbersome debugging at ultra-low-level), it's not a substitute for knowing and understanding what occurs at bootstrap, when a certain stade is reached ...
EclipseOS

Re:Shut Down!

Post by EclipseOS »

Ya I kinda figured it would be the inebidible (I think I spelled that right). Okay thanx for your patience guys. I guess I'm going to have to bite the bullet and grab an assembly tutorial. Any ideas on where I could find one? Thanx alot
KieranFoot

Re:Shut Down!

Post by KieranFoot »

On my pakard bell computer this code does something really strange. It prints & reprint forever, a load of ascii characters, beeping all the way...
Schol-R-LEA

Re:Shut Down!

Post by Schol-R-LEA »

I really should avoid hardware flames, but I have to ask: did you have some bad karma you wished to atone for when you bought your machine? You have my sympathies; I know from bitter experience how much trouble Packard Bell machines can be. My father, who is a sucker for bad 'bargains', bought four of them in quick succession, and then insisted that I keep them running for him.
Post Reply