Inspired by Olivier Poudade's 42 bytes version.

My 37 bytes version:

push0cfh;gdt descriptor cf=present,ring 0 DPL,data,expand-up,writable
push9300h;gdt descriptor 93h=32-bit page-granularity, accessed
pushss
push-1;gdt descriptor segment limit
pushss
pushss
pushss
push0fh;gdt descriptor gdt size-1 nb:00*=base a00-a15,base a16-a23,segment access rights,limit 19:16+flags,base a24-a31
movbx, sp
mov[bx+2], bx;gdt descriptor gdt address
lgdt[bx];load gdt table
moveax, cr0;switch to pmode
xormode:xoral, 1;1st=>set pmode bit LSbit=1(or al,1;switch to protected mode), set a second bit in CR0
movcr0, eax;set control register 0 LSb
push8;select descriptor 1 aka NULL descriptor entry 0 of Descriptor Table
popds
jpexormode;PF=1=>set pmode bit LSbit=0(and al,0feh;back to real mode)
pushss
popds;pop ds/restore big real mode @here ss=0 (from MBR entry register status) now DS can access 4gb
movbx, 0f01h;excluded from footprint / attrib+character
mov[dword 0b8000h], bx; excluded from footprint / 32-bit offset with default DS descriptor

My 36 bytes version:

push0cfh;gdt descriptor cf=present,ring 0 DPL,data,expand-up,writable
push9300h;gdt descriptor 93h=32-bit page-granularity, accessed
pushss
push-1;gdt descriptor segment limit
pushss
pushss
pushss
moveax, cr0
pushax;gdt descriptor gdt size (10h) nb:00*=base a00-a15,base a16-a23,segment access rights,limit 19:16+flags,base a24-a31
movbx, sp
mov[bx+2], bx;gdt descriptor gdt address
lgdt[bx];load gdt table
xormode:xoral, 1;1st=>set pmode bit LSbit=1(or al,1;switch to protected mode), set a second bit in CR0
movcr0, eax;set control register 0 LSb
push8;select descriptor 1 aka NULL descriptor entry 0 of Descriptor Table
popds
jpexormode;PF=1=>set pmode bit LSbit=0(and al,0feh;back to real mode)
pushss
popds;pop ds/restore big real mode @here ss=0 (from MBR entry register status) now DS can access 4gb
movbx, 0f01h;excluded from footprint / attrib+character
mov[dword 0b8000h], bx; excluded from footprint / 32-bit offset with default DS descriptor

My 35 bytes version:

pushss
incsp
push093cfh;gdt descriptor cf=present,ring 0 DPL,data,expand-up,writable 93h=32-bit page-granularity, accessed
pushss
push-1;gdt descriptor segment limit
pushss
pushss
pushss
moveax, cr0
pushax;gdt descriptor gdt size (10h) nb:00*=base a00-a15,base a16-a23,segment access rights,limit 19:16+flags,base a24-a31
movbx, sp
mov[bx+2], bx;gdt descriptor gdt address
lgdt[bx];load gdt table
xormode:xoral, 1;1st=>set pmode bit LSbit=1(or al,1;switch to protected mode), set a second bit in CR0
movcr0, eax;set control register 0 LSb
push8;select descriptor 1 aka NULL descriptor entry 0 of Descriptor Table
popds
jpexormode;PF=1=>set pmode bit LSbit=0(and al,0feh;back to real mode)
pushss
popds;pop ds/restore big real mode @here ss=0 (from MBR entry register status) now DS can access 4gb
incsp;excluded from footprint / restore stack alignment
movbx, 0f01h;excluded from footprint / attrib+character
mov[dword 0b8000h], bx; excluded from footprint / 32-bit offset with default DS descriptor

My 34 bytes version:

decsp;unsafe - assumes top of stack contains a zero
push093cfh;gdt descriptor cf=present,ring 0 DPL,data,expand-up,writable 93h=32-bit page-granularity, accessed
pushss
push-1;gdt descriptor segment limit
pushss
pushss
pushss
moveax, cr0
pushax;gdt descriptor gdt size (10h) nb:00*=base a00-a15,base a16-a23,segment access rights,limit 19:16+flags,base a24-a31
movbx, sp
mov[bx+2], bx;gdt descriptor gdt address
lgdt[bx];load gdt table
xormode:xoral, 1;1st=>set pmode bit LSbit=1(or al,1;switch to protected mode), set a second bit in CR0
movcr0, eax;set control register 0 LSb
push8;select descriptor 1 aka NULL descriptor entry 0 of Descriptor Table
popds
jpexormode;PF=1=>set pmode bit LSbit=0(and al,0feh;back to real mode)
pushss
popds;pop ds/restore big real mode @here ss=0 (from MBR entry register status) now DS can access 4gb
incsp;excluded from footprint / restore stack alignment
movbx, 0f01h;excluded from footprint / attrib+character
mov[dword 0b8000h], bx; excluded from footprint / 32-bit offset with default DS descriptor

Copyright (c) 2015 Peter Ferrie
All rights reserved

This site is hosted by 000webhost.com



Free web hostingWeb hosting