1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
   | ; setup.s
  [org 0x7e00]
  kernel_main equ 0x8000 ; this should be same with the ld -Ttext parameter ; then load the code into memory 0x8000
  mov di,greet call printstring
  ; change into video mode mov al,0x13 mov ah,0x00 int 0x10
 
  jmp enterProtected
 
  greet: 	db 'In second sector!' , 0
  %include "helpfuncs.s" %include "gdt.s"
 
  ; things to do ; 1. disable interrupt, when switching mode, interrupt shouldn't be handled ; 2. enable A20gate to obtain larger memory space ; 3. load gdt into gdtr to enable semgmented memory mangagement ; 4. change ControlRegister0 , cr0 ; 5. flush the pipeline with a far jmp, clear those half-way-done 16 bits instructions ; 6. change data segment to 32 bit mode seg enterProtected: 	cli ; 1. 	call enableA20 ; 2. 	lgdt [gdt_discriptor] ; 3. 	call alterCR0  ; 4. 	jmp codeseg:start32 ; 5.
 
 
  enableA20: 	in al,0x92 	or al,0x02 	out 0x92 , al 	ret
  alterCR0: 	mov eax,cr0 	or eax,0x0001 	mov cr0,eax 	ret
 
  [bits 32] ; 32 bits code following, protected mode
  start32: 	; 6. 	mov ax,dataseg 	mov ss,ax 	mov ds,ax 	mov es,ax 	mov fs,ax 	mov gs,ax 	call kernel_main 	hlt
   |