]> Joshua Wise's Git repositories - netwatch.git/blob - aseg/aseg.asm
244cafc359f3ae87669952727d914f2d43b9f0ed
[netwatch.git] / aseg / aseg.asm
1         org 0xA8000
2 [bits 16]
3 entry:
4         mov ax, 0xA800
5         mov ds, ax              ; Take us out of flat unreal mode, and
6         mov es, ax              ; put us in true real mode.
7         mov fs, ax
8         mov gs, ax
9         mov ss, ax
10         jmp 0xA800:(entry2-0xA8000)     ; Long jump to a correct cs.
11 entry2:
12         lgdt [(gdtr-0xA8000)]           ; Set up a new GDT.
13         mov eax, 0x1
14         mov cr0, eax                    ; ... and enter pmode!
15         jmp long 0x10:continue          ; Now longjmp into the new code.
16 [bits 32]
17 continue:
18         mov ax, 0x08                    ; Set up segment selectors.
19         mov ds, ax
20         mov es, ax
21         mov fs, ax
22         mov gs, ax
23         mov ss, ax
24         mov esp, [dataptr]
25
26 ;       mov al, [cstat]
27 ;       add al, 1
28 ;       out 0x80, al
29 ;       mov [cstat], al
30         
31         mov dx, 0xCF8                   ; save off the old config value
32         in dword eax, dx
33         mov [esp-4], eax
34         
35         mov eax, 0x80000070             ; load in smramc
36         out dx, eax
37         mov dx, 0xCFC
38         in byte al, dx
39         mov [esp-5], al
40         and al, 0xF3                    ; Allow graphics access
41         or al, 0x08
42         out dx, al
43         
44         xor eax, eax
45         mov dx, 0x3D4
46         in byte al, dx
47         mov [esp-6], al                 ; save off the old VGA command
48         mov al, 0xC
49         out dx, al
50         inc dx
51         in al, dx
52         mov ah, al
53         dec dx
54         mov al, 0xD
55         out dx, al
56         inc dx
57         in al, dx
58         shl eax, 1
59         add eax, 0xB8000                ; yay
60         mov byte [eax+0], '1'
61         mov byte [eax+1], 0x1F
62         mov byte [eax+2], '5'
63         mov byte [eax+3], 0x1F
64         mov byte [eax+4], '-'
65         mov byte [eax+5], 0x1F
66         mov byte [eax+6], '4'
67         mov byte [eax+7], 0x1F
68         mov byte [eax+8], '1'
69         mov byte [eax+9], 0x1F
70         mov byte [eax+10], '2'
71         mov byte [eax+11], 0x1F
72         
73         mov dx, 0x3D4                   ; restore the old stuff
74         mov al, [esp-6]
75         out dx, al
76
77         mov dx, 0xCFC                   ; restore smramc
78         mov al, [esp-5]
79         out dx, al
80
81         mov dx, 0xCF8                   ; restore the old PCI config value
82         mov eax, [esp-4]
83         out dx, eax
84
85         mov al, [needclear]
86         cmp al, 0
87         jz noclear
88         mov al, 0                       ; clear BSS
89         mov edi, [dataptr+4]
90         mov ecx, [dataptr+8]
91         rep stosb
92         mov [needclear], al
93         
94 noclear:
95         mov eax, [dataptr+12]           ; jump into C
96         call eax
97
98         mov al, 0x40                    ; ack the periodic IRQ
99         mov dx, 0x834
100         out dx, al
101         
102         mov dx, 0x830                   ; now ack the SMI itself
103         in al, dx
104         or al, 0x02
105         and al, 0xBF
106         out dx, al
107         or al, 0x40
108         out dx, al
109
110         rsm                             ; and leave SMM
111
112 needclear:
113         db 0x01
114
115         align 0x4
116 gdtr:
117         db 0x27, 0x00
118         dd gdt
119         align 0x4
120 gdt:
121         db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
122         db 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x93, 0xCF, 0x00       ; data segment
123         db 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x9B, 0xCF, 0x00       ; code segment
124         db 0xFF, 0xFF, 0x00, 0x80, 0x0A, 0x9B, 0xCF, 0x00       ; code segment for trampoline
125
126 cstat:
127         db 0x00
128
129 TIMES   512-($-$$) DB 0
130 dataptr:
131         ; 4 bytes of stack top
132         ; 4 bytes of BSS start
133         ; 4 bytes of BSS length
134         ; 4 bytes of C entry point
This page took 0.021475 seconds and 2 git commands to generate.