13 mov fs, ax ; this will store the original real mode segment
15 ; modify the return to real mode jump segment
16 mov [.jmpcs16 + 3], ax
24 ; calculate GDT linear address
28 mov [tmpsegbase], eax ; save segment base
32 ; set tmp segment bases to match the linear address of our current seg
36 mov word [gdt + 18h + 2], ax ; tmp pm code base
37 mov word [gdt + 20h + 2], ax ; tmp pm data base
38 mov word [gdt + 28h + 2], ax ; ret-to-realmode code
40 mov byte [gdt + 18h + 4], al
41 mov byte [gdt + 20h + 4], al
42 mov byte [gdt + 28h + 4], al
56 .pm: mov ax, 20h ; tmp data selector
59 mov ax, 10h ; dest data selector
74 jmp 42h:.loadcs16 ; 42 seg is modifed at the start (TODO)
84 str_enterpm db 'Entering 32bit protected mode ...',10,0
91 call printstr ; print "Enable A20 line ... "
103 .done: mov si, .okstr
107 .infomsg db 'Enable A20 line:',0
108 .failstr db ' failed.',10,0
109 .okstr db ' success.',10,0
111 ; CF = 1 if A20 test fails (not enabled)
130 .done: mov [ds:si], dl
143 .info db ' fast ...',0
145 KBC_DATA_PORT equ 0x60
146 KBC_CMD_PORT equ 0x64
147 KBC_STATUS_PORT equ 0x64
148 KBC_CMD_WR_OUTPORT equ 0xd1
150 KBC_STAT_IN_FULL equ 2
156 mov al, KBC_CMD_WR_OUTPORT
160 out KBC_DATA_PORT, al
162 .info db ' kbd ...',0
165 in al, KBC_STATUS_PORT
166 and al, KBC_STAT_IN_FULL
174 cmp al, 10 ; check for line-feed and insert CR before it
189 enterpm dd 0xbad00d ; space for linear address for far jump to pmode
190 enterpm_sel dw 8 ; selector for far jump to protected mode
192 gdt_lim dw 47 ; GDT limit
193 gdt_base dd 0xbadf00d ; space for GDT linear address
196 gdt: ; 0: null segment
199 ; 1: code - 0/lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:code/non-conf/rd
202 ; 2: data - 0/lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:data/rw
205 ; 3: tmp code (will set base before entering pmode)
208 ; 4: tmp data (will set base before entering pmode)
211 ; 5: return to real-mode 16bit code segment
216 ; vi:set ts=8 sts=8 sw=8 ft=nasm: