16 mov fs, ax ; this will store the original real mode segment
18 ; modify the return to real mode jump segment
19 mov [.jmpcs16 + 3], ax
24 ; check for VM86 and abort
36 ; calculate GDT linear address
43 ; set tmp segment bases to match the linear address of our current seg
47 mov word [gdt + 18h + 2], ax ; tmp pm code base
48 mov word [gdt + 20h + 2], ax ; tmp pm data base
49 mov word [gdt + 28h + 2], ax ; ret-to-realmode code
51 mov byte [gdt + 18h + 4], al
52 mov byte [gdt + 20h + 4], al
53 mov byte [gdt + 28h + 4], al
67 .pm: mov ax, 20h ; tmp data selector
69 mov ax, 10h ; dest data selector
72 ; copy main program high
74 mov esi, _ldr_main_start
76 mov ecx, _main_size + 3
95 jmp 42h:.loadcs16 ; 42 seg is modifed at the start
105 str_errvm86 db 'Error: memory manager detected! Stop it and try again (e.g. emm386 off)',10,0
106 str_enterpm db 'Entering 32bit protected mode ...',10,0
113 call printstr ; print "Enable A20 line ... "
125 .done: mov si, .okstr
129 .infomsg db 'Enable A20 line:',0
130 .failstr db ' failed.',10,0
131 .okstr db ' success.',10,0
133 ; CF = 1 if A20 test fails (not enabled)
152 .done: mov [ds:si], dl
165 .info db ' fast ...',0
167 KBC_DATA_PORT equ 0x60
168 KBC_CMD_PORT equ 0x64
169 KBC_STATUS_PORT equ 0x64
170 KBC_CMD_WR_OUTPORT equ 0xd1
172 KBC_STAT_IN_FULL equ 2
178 mov al, KBC_CMD_WR_OUTPORT
182 out KBC_DATA_PORT, al
184 .info db ' kbd ...',0
187 in al, KBC_STATUS_PORT
188 and al, KBC_STAT_IN_FULL
196 cmp al, 10 ; check for line-feed and insert CR before it
211 enterpm dd 0xbad00d ; space for linear address for far jump to pmode
212 enterpm_sel dw 8 ; selector for far jump to protected mode
214 gdt_lim dw 47 ; GDT limit
215 gdt_base dd 0xbadf00d ; space for GDT linear address
218 gdt: ; 0: null segment
221 ; 1: code - 0/lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:code/non-conf/rd (sel: 8)
224 ; 2: data - 0/lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:data/rw (sel: 10h)
227 ; 3: tmp code (will set base before entering pmode) (sel: 18h)
230 ; 4: tmp data (will set base before entering pmode) (sel: 20h)
233 ; 5: return to real-mode 16bit code segment (sel: 28h)
238 ; vi:set ts=8 sts=8 sw=8 ft=nasm: