]>
Commit | Line | Data |
---|---|---|
f1584bb0 JW |
1 | ; realmode.asm |
2 | ; Routines to return the system to real mode | |
3 | ; NetWatch multiboot loader | |
4 | ; | |
5 | ; Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved. | |
6 | ; This program is free software; you can redistribute and/or modify it under | |
7 | ; the terms found in the file LICENSE in the root of this source tree. | |
8 | ||
042eafc7 JW |
9 | [bits 32] ; Starts in 32 bit mode, then will drop back later. |
10 | org 0x4000 | |
11 | entry: | |
12 | cli | |
13 | ; clean up 32 bit regs | |
14 | mov eax, 0x0 | |
15 | mov ebx, 0x0 | |
16 | mov ecx, 0x0 | |
17 | mov edx, 0x0 | |
18 | mov esi, 0x0 | |
19 | mov edi, 0x0 | |
20 | mov ebp, 0x0 | |
21 | mov esp, 0x0 | |
22 | ||
23 | lgdt [gdtp] | |
24 | ||
25 | mov ax, 0x10 | |
26 | mov ds, ax | |
27 | mov es, ax | |
28 | mov fs, ax | |
29 | mov gs, ax | |
30 | mov ss, ax | |
31 | ||
32 | jmp 0x8:nextp ; Clear CS bits now too | |
33 | ||
34 | nextp: | |
35 | ||
36 | mov eax, cr0 | |
37 | xor eax, 0x1 ; Clear PE | |
38 | mov cr0, eax | |
39 | ||
40 | jmp 0x0:nowreal ; and jmp away | |
41 | ||
42 | ||
43 | [bits 16] | |
44 | nowreal: | |
45 | mov long eax, 0x0000 | |
46 | mov ds, ax | |
47 | mov es, ax | |
48 | mov fs, ax | |
49 | mov gs, ax | |
50 | mov ss, ax | |
51 | ||
52 | mov sp, 0xFFFF ; set up the stack | |
53 | ||
54 | mov al, 0xAB | |
55 | out 0x80, al | |
56 | ||
57 | cli | |
58 | lidt [idtp] | |
59 | ||
60 | mov si, RETMSG | |
61 | call disp | |
62 | ||
63 | int 0x19 ; warm boot without clearing RAM. | |
64 | call handload_drive ; hopefully shouldn't happen | |
65 | ; ok, we give up | |
66 | cli | |
67 | halt: hlt | |
68 | jmp halt | |
69 | ||
70 | disp: | |
71 | lodsb | |
72 | or al, al | |
73 | jz .done | |
74 | mov ah, 0x0E | |
75 | mov bx, 0x0007 | |
76 | int 0x10 | |
77 | jmp disp | |
78 | .done: | |
79 | ret | |
80 | ||
81 | ; handload_drive should be unnecessary; int 19 should take care of it for | |
82 | ; us... | |
83 | handload_drive: | |
84 | mov ax, 0x07C0 | |
85 | mov es, ax | |
86 | mov ax, 0x0201 ; read one sector | |
87 | mov bx, 0x0000 ; to the normal location | |
88 | mov cx, 0x0001 ; disk sector 1 | |
89 | mov dx, 0x0080 ; drive 0 | |
90 | int 0x13 | |
91 | jc readerr | |
92 | ||
93 | mov si, READSUCC | |
94 | call disp | |
95 | ||
96 | jmp 0x7C0:0x0 ; and return control to grub! | |
97 | readerr: | |
98 | mov si, READFAIL | |
99 | call disp | |
100 | ret | |
101 | ||
102 | RETMSG db "SMM installer finished, booting your system of choice.",10,13,0 | |
103 | READSUCC db "Read successful; rebooting into boot sector.",10,13,0 | |
104 | READFAIL db "Boot disk read failure; system halted.",10,13,0 | |
105 | ||
106 | ||
107 | idtp db 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00 | |
108 | ||
109 | gdtp dw 0x1F | |
110 | dd gdt | |
111 | ||
112 | gdt dd 0, 0 | |
113 | dd 0x0000FFFF, 0x00009e00 ; CS | |
114 | dd 0x0000FFFF, 0x00009300 ; DS |