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

wirehaze git hosting

Added VFS, FAT12 and STDIO placeholders
[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 ; begin our dark journey into 16bit-land
28
29 use16
30 do_16pmode:
31 mov ax, 0x20
32 mov ds, ax
33 mov es, ax
34 mov fs, ax
35 mov gs, ax
36 mov ss, ax
37
38 cli
39 mov eax, cr0
40 and al, 0xFE
41 mov cr0, eax
42
43 jmp 0x0000:(do_realm) ; this should be triple checked!
44
45 do_realm:
46 mov ax, cs
47 mov ds, ax
48
49 xor ax, ax
50 mov es, ax
51 mov fs, ax
52 mov gs, ax
53 mov ss, ax
54
55 lidt [ridtr] ; realmode/variables.inc
56 sti
57
58 mov ax, word [realmode_ax]
59 mov bx, word [realmode_bx]
60 mov cx, word [realmode_cx]
61 mov dx, word [realmode_dx]
62
63 push ax ; this is some cool shit.. ;)
64 mov al, [int_number] ; interrupt to preform
65 mov [$+5], al ; move it to right pos.
66 pop ax
67 db 0xCD ; opcode for int.
68 db 0x00 ; move int_number here
69
70 jnc .no_error
71 mov byte [realmode_error], 1
72
73 .no_error:
74 mov word [realmode_ax], ax
75 mov word [realmode_bx], bx
76 mov word [realmode_cx], cx
77 mov word [realmode_dx], dx
78
79 cli
80
81 lgdt [gdtr]
82 lidt [idtr]
83 mov eax, cr0
84 or al, 1
85 mov cr0, eax
86
87 jmp pword 0x08:gobackto_pm
88
89
90 use32
91 gobackto_pm:
92 mov ax, 0x10 ; refresh all segment registers
93 mov ds, ax
94 mov es, ax
95 mov fs, ax
96 mov gs, ax
97 mov ss, ax
98 call enable_irqs
99 sti
100 popad
101 clc ; clear carry.
102 cmp [realmode_error], 1 ; if error, then
103 jne .end
104 stc ; set carry.
105 .end:
106 ret