Factor out precefaces and postfixes, apm_shutdown2
This commit is contained in:
5
Makefile
5
Makefile
@@ -5,7 +5,8 @@
|
|||||||
BITS ?= 32
|
BITS ?= 32
|
||||||
IN_EXT ?= .S
|
IN_EXT ?= .S
|
||||||
LD ?= ld
|
LD ?= ld
|
||||||
MYAS ?= as
|
# Use gcc so that the preprocessor will run first.
|
||||||
|
MYAS ?= gcc
|
||||||
OBJ_EXT ?= .o
|
OBJ_EXT ?= .o
|
||||||
OUT_EXT ?= .img
|
OUT_EXT ?= .img
|
||||||
RUN ?= bios_hello_world
|
RUN ?= bios_hello_world
|
||||||
@@ -22,7 +23,7 @@ all: $(OUTS)
|
|||||||
$(LD) --oformat binary -o '$@' '$<' -T a.ld #-Ttext 0x7C00
|
$(LD) --oformat binary -o '$@' '$<' -T a.ld #-Ttext 0x7C00
|
||||||
|
|
||||||
%$(OBJ_EXT): %$(IN_EXT)
|
%$(OBJ_EXT): %$(IN_EXT)
|
||||||
$(MYAS) -o '$@' '$<'
|
$(MYAS) -c -o '$@' '$<'
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *$(OBJ_EXT) *$(OUT_EXT)
|
rm -f *$(OBJ_EXT) *$(OUT_EXT)
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -65,6 +65,20 @@ You cannot use any libraries, so how to do IO? Some ways that this can be done:
|
|||||||
- <https://en.wikipedia.org/wiki/VGA-compatible_text_mode>
|
- <https://en.wikipedia.org/wiki/VGA-compatible_text_mode>
|
||||||
- VBE <https://en.wikipedia.org/wiki/VESA_BIOS_Extensions>
|
- VBE <https://en.wikipedia.org/wiki/VESA_BIOS_Extensions>
|
||||||
|
|
||||||
|
Showdown and restart can be managed with either:
|
||||||
|
|
||||||
|
- ACPI <https://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface>
|
||||||
|
|
||||||
|
Newer and better.
|
||||||
|
|
||||||
|
- APM <https://en.wikipedia.org/wiki/Advanced_Power_Management>
|
||||||
|
|
||||||
|
<http://wiki.osdev.org/APM>
|
||||||
|
|
||||||
|
Older and simpler.
|
||||||
|
|
||||||
|
See also: <http://wiki.osdev.org/Shutdown>
|
||||||
|
|
||||||
## Bibliography
|
## Bibliography
|
||||||
|
|
||||||
- <http://stackoverflow.com/questions/22054578/run-a-program-without-an-operating-system>
|
- <http://stackoverflow.com/questions/22054578/run-a-program-without-an-operating-system>
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
.code16
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
http://wiki.osdev.org/Shutdown
|
http://wiki.osdev.org/Shutdown
|
||||||
|
|
||||||
@@ -8,6 +6,10 @@ http://stackoverflow.com/questions/678458/shutdown-the-computer-using-assembly
|
|||||||
http://stackoverflow.com/questions/3145569/how-to-power-down-the-computer-from-a-freestanding-environment
|
http://stackoverflow.com/questions/3145569/how-to-power-down-the-computer-from-a-freestanding-environment
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
|
||||||
mov $0x5301, %ax
|
mov $0x5301, %ax
|
||||||
xor %bx, %bx
|
xor %bx, %bx
|
||||||
int $0x15
|
int $0x15
|
||||||
@@ -24,5 +26,4 @@ mov $0x0001, %bx
|
|||||||
mov $0x0003, %cx
|
mov $0x0003, %cx
|
||||||
int $0x15
|
int $0x15
|
||||||
|
|
||||||
.org 510
|
END
|
||||||
.word 0xaa55
|
|
||||||
70
apm_shutdown2.S
Normal file
70
apm_shutdown2.S
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
Example from: http://wiki.osdev.org/APM
|
||||||
|
|
||||||
|
Is all of this really needed? Compare to apm_shutdown.S.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
movb $0x53,%ah #this is an APM command
|
||||||
|
movb $0x0,%al #installation check command
|
||||||
|
xorw %bx,%bx #device id (0 = APM BIOS)
|
||||||
|
int $0x15 #call the BIOS function through interrupt 15h
|
||||||
|
jc APM_error #if the carry flag is set there was an error
|
||||||
|
#the function was successful
|
||||||
|
#AX = APM version number
|
||||||
|
#AH = Major revision number (in BCD format)
|
||||||
|
#AL = Minor revision number (also BCD format)
|
||||||
|
#BX = ASCII characters "P" (in BH) and "M" (in BL)
|
||||||
|
#CX = APM flags (see the official documentation for more details)
|
||||||
|
|
||||||
|
#disconnect from any APM interface
|
||||||
|
movb $0x53,%ah #this is an APM command
|
||||||
|
movb $0x4,%al #interface disconnect command
|
||||||
|
xorw %bx,%bx #device id (0 = APM BIOS)
|
||||||
|
int $0x15 #call the BIOS function through interrupt 15h
|
||||||
|
jc .disconnect_error #if the carry flag is set see what the fuss is about.
|
||||||
|
jmp .no_error
|
||||||
|
|
||||||
|
.disconnect_error: #the error code is in ah.
|
||||||
|
cmpb $0x3,%ah #if the error code is anything but 03h there was an error.
|
||||||
|
jne APM_error #the error code 03h means that no interface was connected in the first place.
|
||||||
|
|
||||||
|
.no_error:
|
||||||
|
#the function was successful
|
||||||
|
#Nothing is returned.
|
||||||
|
|
||||||
|
#connect to an APM interface
|
||||||
|
movb $0x53,%ah #this is an APM command
|
||||||
|
movb $0x01,%al #see above description
|
||||||
|
xorw %bx,%bx #device id (0 = APM BIOS)
|
||||||
|
int $0x15 #call the BIOS function through interrupt 15h
|
||||||
|
jc APM_error #if the carry flag is set there was an error
|
||||||
|
#the function was successful
|
||||||
|
#The return values are different for each interface.
|
||||||
|
#The Real Mode Interface returns nothing.
|
||||||
|
#See the official documentation for the
|
||||||
|
#return values for the protected mode interfaces.
|
||||||
|
|
||||||
|
#Enable power management for all devices
|
||||||
|
movb $0x53,%ah #this is an APM command
|
||||||
|
movb $0x8,%al #Change the state of power management...
|
||||||
|
movw $0x001,%bx #...on all devices to...
|
||||||
|
movw $0x001,%cx #...power management on.
|
||||||
|
int $0x15 #call the BIOS function through interrupt 15h
|
||||||
|
jc APM_error #if the carry flag is set there was an error
|
||||||
|
|
||||||
|
#Set the power state for all devices
|
||||||
|
movb $0x53,%ah #this is an APM command
|
||||||
|
movb $0x07,%al #Set the power state...
|
||||||
|
movw $0x0001,%bx #...on all devices to...
|
||||||
|
movw $0x0003,%cx #see above
|
||||||
|
int $0x15 #call the BIOS function through interrupt 15h
|
||||||
|
jc APM_error #if the carry flag is set there was an error
|
||||||
|
|
||||||
|
APM_error:
|
||||||
|
hlt
|
||||||
|
|
||||||
|
END
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
.code16
|
#include "common.h"
|
||||||
|
BEGIN
|
||||||
cli
|
cli
|
||||||
mov $msg, %si
|
mov $msg, %si
|
||||||
mov $0x0e, %ah
|
mov $0x0e, %ah
|
||||||
@@ -12,5 +13,4 @@ halt:
|
|||||||
hlt
|
hlt
|
||||||
msg:
|
msg:
|
||||||
.asciz "hello world"
|
.asciz "hello world"
|
||||||
.org 510
|
END
|
||||||
.word 0xaa55
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# Print a single `@` character with the BIOS.
|
# Print a single `@` character with the BIOS.
|
||||||
# More minimal than the hello world.
|
# More minimal than the hello world.
|
||||||
.code16
|
#include "common.h"
|
||||||
|
BEGIN
|
||||||
cli
|
cli
|
||||||
mov $0x40, %al
|
mov $0x40, %al
|
||||||
mov $0x0e, %ah
|
mov $0x0e, %ah
|
||||||
int $0x10
|
int $0x10
|
||||||
hlt
|
hlt
|
||||||
.org 510
|
END
|
||||||
.word 0xaa55
|
|
||||||
|
|||||||
Reference in New Issue
Block a user