]> git.lizzy.rs Git - loadnothing.git/blob - stage1/boot.asm
Stage1 subdir
[loadnothing.git] / stage1 / boot.asm
1 [bits 16]
2 [org 0x7c00]
3
4 ; Initialize registers
5 xor ax, ax
6 mov ds, ax
7 mov es, ax
8 mov bx, 0x8000
9
10 call boot
11
12 ; Print al register
13 print_al:
14         mov ah, 0x0e ; TTY output
15         mov bh, 0x00 ; Page 0
16         mov bl, 0x07 ; Color: Light grey on black background
17         int 0x10
18
19         ret
20
21 ; Call print_al on all characters in si
22 ; si must be null terminated
23 print_bytes_si:
24         mov cl, 0 ; Start with iteration 0 - equivalent of int i = 0
25 print_bytes_si_loop:
26         lodsb                  ; Load next characet of si into al
27         call print_al
28
29         inc cl
30
31         cmp cl, ch
32         jb print_bytes_si_loop
33
34         ret
35
36 ; APM is not supported
37 apm_error:
38         mov ch, 9           ; Our string is 9 characters long
39         mov si, apm_err
40         call print_bytes_si
41
42         jmp $               ; Infinite loop
43
44 ; Check APM support
45 apm_chk:
46         mov ah, 0x53     ; This is an APM command
47         mov al, 0x00     ; APM: Installation Check
48         mov bx, 0x0000   ; Device ID (0 is APM BIOS)
49         int 0x15         ; Call
50
51         jc apm_error ; Carry flag is set if there was an error
52
53         cmp ah, 1        ; APM major version must be at least one
54         jb apm_error
55
56         cmp al, 1        ; APM minor version must be at least one
57         jb apm_error
58
59         ret
60
61
62 ; Disconnect from any APM interface
63 apm_disco:
64         mov ah, 0x53           ; This is an APM command
65         mov al, 0x04           ; APM: Disconnect
66         mov bx, 0x0000         ; Device ID (0 is APM BIOS)
67         int 0x15               ; Call
68
69         jc .apm_disco_error    ; Carry flag is set if there was an error
70         jmp .apm_disco_success
71
72 ; Disconnecting any APM interface failed
73 .apm_disco_error:
74         cmp ah, 0x03  ; Error code for no interface connected
75         jne apm_error
76
77 ; No interface are connected now
78 .apm_disco_success:
79         ret
80
81 ; Connect to an APM interface
82 apm_connect:
83         mov ah, 0x53   ; This is an APM command
84         mov bx, 0x0000 ; Device ID (0 is APM BIOS)
85         int 0x15       ; Call
86
87         jc apm_error ; Carry flag is set if there was an error
88         ret
89
90 ; Set the APM Driver Version to 1.1
91 apm_drv_init:
92         mov ah, 0x53   ; This is an APM command
93         mov al, 0x0e   ; APM: Set Driver Supported Version
94         mov bx, 0x0000 ; Device ID (0 is APM BIOS)
95         mov ch, 1      ; APM Driver Major Version Number
96         mov cl, 1      ; APM Driver Minor Version Number
97         int 0x15       ; Call
98
99         jc apm_error ; Carry flag is set if there was an error
100         ret
101
102 ; Enable APM Power Management
103 apm_mgmt_on:
104         mov ah, 0x53   ; This is an APM command
105         mov al, 0x08   ; APM: Change power management state
106         mov bx, 0x0001 ; on all devices
107         mov cx, 0x0001 ; to on
108         int 0x15       ; Call
109
110         jc apm_error   ; Carry flag is set if there was an error
111         ret
112
113 ; Power down the system
114 apm_power_off:
115         mov ah, 0x53   ; This is an APM command
116         mov al, 0x07   ; APM: Set power state
117         mov bx, 0x0001 ; on all devices
118         mov cx, 0x0003 ; to off
119         int 0x15       ; Call
120
121         jc apm_error   ; Carry flag is set if there was an error
122         ret
123
124 ; Main
125 boot:
126         call apm_chk        ; Is APM supported?
127         call apm_disco      ; Disconnect from any APM interface
128
129         mov al, 0x01        ; Interface to connect to: Real Mode
130         call apm_connect    ; Connect to APM interface
131
132         call apm_drv_init   ; Set the APM Driver Version to 1.1
133         call apm_mgmt_on    ; Enable Power Management
134
135         ; Clear the screen
136         mov ah, 0x06
137         mov al, 0x00
138         mov bh, 0x07
139         mov ch, 0x00
140         mov cl, 0x00
141         mov dh, 0xff
142         mov dl, 0xff
143         int 0x10
144
145         ; Move cursor to 0, 0 on page 0
146         mov ah, 0x02
147         mov bh, 0           ; Page
148         mov dh, 0           ; Row
149         mov dl, 0           ; Column
150         int 0x10
151
152         mov ch, 5           ; Our string is 5 characters long
153         mov si, hello
154         call print_bytes_si
155
156         mov ch, 29          ; Our string is 29 characters long
157         mov si, paktc       ; paktc: Press any key to continue
158         call print_bytes_si
159
160         mov ah, 0x00        ; Keyboard: Read key press
161         int 0x16            ; Call
162
163         call apm_power_off
164         jmp $               ; Infinite loop
165
166 hello db 'foo', 13, 10                   ; \r\n
167 apm_err db 'APM Error'
168 paktc db 'Press any key to continue... '
169
170 times (446 - ($ - $$)) db 0x00