]> wirehaze git hosting - BOS.git/blob - kernel/init/bios.asm

wirehaze git hosting

Start of cleanup.
[BOS.git] / kernel / init / bios.asm
1 ;----------------------------------------------------------;
2 ; BOS kernel Christoffer Bubach, 2003-2005. ;
3 ;----------------------------------------------------------;
4 ; ;
5 ; Goes back to realmode to do an INT. ;
6 ; ;
7 ;----------------------------------------------------------;
8
9
10 rmode_int:
11 pushad
12 push eax
13 shr eax, 16 ; move high bits to ax
14 mov word [realmode_ax], ax ; save new ax value
15 pop eax ; restore
16
17 push ebx
18 shr ebx, 16 ; move high bits to bx
19 mov byte [int_number], bl ; save int number to call
20 pop ebx
21
22 mov byte [realmode_error], 0 ; all variables is in the
23 mov word [realmode_bx], bx ; realmode/variables.inc file
24 mov word [realmode_cx], cx
25 mov word [realmode_dx], dx
26 call disable_irqs
27 jmp pword 0x18:do_16pmode ; must substract 0x10000 from
28 ; data addresses becasue of
29 ; fasm strict "org" behavior
30 use16
31 do_16pmode:
32 mov ax, 0x20
33 mov ds, ax
34 mov es, ax
35 mov fs, ax
36 mov gs, ax
37 mov ss, ax
38
39 cli
40 mov eax, cr0
41 and al, 0xFE
42 mov cr0, eax
43
44 jmp 0x1000:(do_realm)
45
46 do_realm:
47 mov ax, cs
48 mov ds, ax
49
50 xor ax, ax
51 mov es, ax
52 mov fs, ax
53 mov gs, ax
54 mov ss, ax
55
56 lidt [ridtr] ; realmode/variables.inc
57 sti
58
59 mov ax, word [realmode_ax]
60 mov bx, word [realmode_bx]
61 mov cx, word [realmode_cx]
62 mov dx, word [realmode_dx]
63
64 push ax ; this is some cool shit.. ;)
65 mov al, [int_number] ; interrupt to preform
66 mov [$+5], al ; move it to right pos.
67 pop ax
68 db 0xCD ; opcode for int.
69 db 0x00 ; move int_number here
70
71 jnc .no_error
72 mov byte [realmode_error], 1
73
74 .no_error:
75 mov word [realmode_ax], ax
76 mov word [realmode_bx], bx
77 mov word [realmode_cx], cx
78 mov word [realmode_dx], dx
79
80 cli
81
82 lgdt [gdtr]
83 lidt [idtr]
84 mov eax, cr0
85 or al, 1
86 mov cr0, eax
87
88 jmp pword 0x08:gobackto_pm
89
90
91 use32
92 gobackto_pm:
93 mov ax, 0x10 ; refresh all segment registers
94 mov ds, ax
95 mov es, ax
96 mov fs, ax
97 mov gs, ax
98 mov ss, ax
99 call enable_irqs
100 sti
101 popad
102 clc ; clear carry.
103 cmp [realmode_error], 1 ; if error, then
104 jne .end
105 stc ; set carry.
106 .end:
107 ret