981354826ae797aa8f78fcb8f6bb361c832b828e
[reactos.git] / boot / freeldr / freeldr / arch / realmode / helpers.inc
1
2 Empty8042:
3 .word HEX(00eb), HEX(00eb) // jmp $+2, jmp $+2
4 in al, HEX(64)
5 cmp al, HEX(0ff) // legacy-free machine without keyboard
6 jz Empty8042_ret // controllers on Intel Macs read back 0xFF
7 test al, 2
8 jnz Empty8042
9 Empty8042_ret:
10 ret
11
12 EnableA20:
13 pusha
14 call Empty8042
15 mov al, HEX(0D1) // command write
16 out HEX(064), al
17 call Empty8042
18 mov al, HEX(0DF) // A20 on
19 out HEX(060), al
20 call Empty8042
21 mov al, HEX(0FF) // pulse output port
22 out HEX(064), al
23 call Empty8042
24 popa
25 ret
26
27 DisableA20:
28 pusha
29 call Empty8042
30 mov al, HEX(0D1) // command write
31 out HEX(064), al
32 call Empty8042
33 mov al, HEX(0DD) // A20 off
34 out HEX(060), al
35 call Empty8042
36 mov al, HEX(0FF) // pulse output port
37 out HEX(064), al
38 call Empty8042
39 popa
40 ret
41
42 /*
43 * writestr
44 * si = pointer to zero terminated string
45 */
46 writestr:
47 pushfd
48 pushad
49 writestr_top:
50 lodsb
51 and al, al
52 jz writestr_end
53 call writechr
54 jmp short writestr_top
55 writestr_end:
56 popad
57 popfd
58 ret
59
60 /*
61 * writechr
62 * al = character to output
63 */
64 writechr:
65 pushf
66 pusha
67 mov ah, HEX(0E)
68 xor bx, bx
69 int HEX(10)
70 popa
71 popf
72 ret
73
74 //
75 // writehex[248]: Write a hex number in (AL, AX, EAX) to the console
76 //
77 writehex2:
78 pushfd
79 pushad
80 shl eax, 24
81 mov cx, 2
82 jmp short writehex_common
83 writehex4:
84 pushfd
85 pushad
86 shl eax, 16
87 mov cx, 4
88 jmp short writehex_common
89 writehex8:
90 pushfd
91 pushad
92 mov cx, 8
93 writehex_common:
94 .loop:
95 rol eax, 4
96 push eax
97 and al, HEX(0F)
98 cmp al, 10
99 jae .high
100 .low:
101 add al, '0'
102 jmp short .ischar
103 .high:
104 add al, 'A'-10
105 .ischar:
106 call writechr
107 pop eax
108 loop .loop
109 popad
110 popfd
111 ret
112
113 Reboot:
114 cli
115
116 /* Disable A20 address line */
117 call DisableA20
118
119 /* Set the video back to 80x25 text mode */
120 mov ax, HEX(0003)
121 int HEX(10)
122
123 /* Set the word at location 40h:72h to 0 (cold reboot) */
124 mov word ptr ds:[HEX(0472)], HEX(0)
125
126 /* and jump to location F000h:FFF0h in ROM */
127 ljmp16 HEX(0F000), HEX(0FFF0)
128
129
130 ChainLoadBiosBootSectorCode:
131 cli
132
133 /* Disable A20 address line */
134 call DisableA20
135
136 /* Set the video back to 80x25 text mode */
137 mov ax, HEX(0003)
138 int HEX(10)
139
140 /* Load segment registers */
141 xor ax, ax
142 mov ds, ax
143 mov es, ax
144 mov fs, ax
145 mov gs, ax
146 mov ss, ax
147 mov esp, HEX(7C00)
148
149 /* Jump to the bootsector code */
150 ljmp16 HEX(0000), HEX(7C00)