Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ORG 0x7C00
- jmp 0x0000:start
- bootdrv db 0
- start:
- cli
- mov ax, 0x9000
- mov ss, ax
- mov sp, 0
- sti
- mov ax, 0x0000
- mov es,ax
- mov ds,ax
- mov [bootdrv],dl
- call load
- call A20
- mov ax, 0x1000
- mov es,ax
- mov ds,ax
- jmp 0x1000:0x0000
- load:
- mov ax,0
- mov dl, [bootdrv]
- int 13h
- jc load
- load1:
- mov ax, 0x1000
- mov es,ax
- mov bx,0
- mov ah,2
- mov al,20
- mov cx,2
- mov dh,0
- mov dl,[bootdrv]
- int 13h
- jc load1
- retn
- A20:
- mov ax,0x2401
- int 0x15
- jc A20OLD
- retn
- A20OLD:
- cli
- call a20wait
- mov al,0xAD
- out 0x64,al
- call a20wait
- mov al,0xD0
- out 0x64,al
- call a20wait2
- in al,0x60
- push ax
- call a20wait
- mov al,0xD1
- out 0x64,al
- call a20wait
- pop ax
- or al,2
- out 0x60,al
- call a20wait
- mov al,0xAE
- out 0x64,al
- call a20wait
- sti
- ret
- a20wait:
- in al,0x64
- test al,2
- jnz a20wait
- ret
- a20wait2:
- in al,0x64
- test al,1
- jz a20wait2
- ret
- times 510-($-$$) db 0
- dw 0x0AA55
- mov ax,0x1000
- mov ds,ax
- mov es,ax
- starts:
- call protected_mode_supported
- jmp pmode
- protected_mode_supported:
- cli
- pushf
- pushf
- pop ax
- mov bx,ax
- and ax,0x0FFF
- or bx,0x7000
- push ax
- popf
- pushf
- pop ax
- push bx
- popf
- pushf
- pop bx
- popf
- and ax,0xF000
- cmp ax,0xF000
- je not_supported
- test bx,0x7000
- je not_supported
- retn
- not_supported:
- mov si,nsstring
- call putstr
- cli
- hang:
- halt
- jmp hang
- putstr:
- lodsb
- or al,al
- jz putstrd
- mov ah,0x0E
- mov bx,0x00F0
- int 0x10
- jmp putstr
- putstrd:
- retn
- pmode:
- cli
- lgdt [gdt]
- mov eax,cr0
- or al,1
- mov cr0,eax
- jmp kcodesel:weiter
- nsstring db "[FATAL] Dies ist ein 32-Bit OS! Sie Benutzen aber einen 8086, 80186 oder 80286er! System wird angehalten!",13,10,0
- [BITS 32]
- weiter:
- call pae
- call lmode
- pae:
- mov eax,0x00000001
- cpuid
- and edx, 0x00000020
- jnz activatepae
- retn
- activatepae:
- mov eax,cr4
- or eax, 0x00000010
- mov cr4,eax
- retn
- lmode:
- mov eax, 0x80000001
- cpuid
- and edx, 0x20000000
- test edx, edx
- jz non64
- mov eax,1
- cpuid
- and edx, 0x00000040
- test edx, edx
- jz non64
- mov edi, 0x300000
- mov eax, 0x30100F
- stosd
- mov ecx, 0x03FF
- xor eax,eax
- rep stosd
- mov eax,0x30200F
- stosd
- mov ecx,0x03FF
- xor eax,eax
- rep stosd
- mov ecx,0x200
- mov esi, 0x8B
- map.loop:
- mov eax,esi
- stosd
- xor eax,eax
- stosd
- add esi,0x200000
- sub ecx,1
- jnz map.loop
- mov eax,0x300000
- mov cr3,eax
- mov ecx,0xC0000080
- rdmsr
- or eax, 0x00000100
- wrmsr
- mov eax,cr0
- or eax,0x80000000
- mov cr0,eax
- jmp 0x30:bootLM
- non64:
- retn
- [bits 64]
- bootLM:
- xor rax,rax
- retn
- [bits 32]
- gdt:
- dw 31
- dd GDTPR
- GDTPR:
- ; NULLSEGMENT
- dw 0 ;Segment Limit 0-15
- dw 0 ;Base Address 0-15
- db 0 ;Base Address 16-23
- db 0 ;Flags
- db 0 ;Sonstiges
- db 0 ;Base Address 24-31
- kcodesel equ $-gdt
- ; CODESEGMENT KERNEL
- dw 0xFFFF
- db 0x0000
- db 0x00
- db 10011010b ; Present, RING 0, Segment, Executable, Readable Bit
- db 01011111b
- db 0x00
- kdatasel equ $-gdt
- ; DATASEGMENT KERNEL
- dw 0xFFFF
- db 0x0000
- db 0x00
- db 10010010b ; Present, RING 0, Segment, RW Bit
- db 01011111b
- db 0x00
- ucodesel equ $-gdt
- ; CODESEGMENT USERSPACE
- dw 0xFFFF
- db 0x0000
- db 0x00
- db 11111010b ; Present, RING 3, Segment, Executable, Readable Bit
- db 01011111b
- db 0x00
- udatasel equ $-gdt
- ; DATASEGMENT USERSPACE
- dw 0xFFFF
- db 0x0000
- db 0x00
- db 11110010b ; Present, RING 3, Segment, RW Bit
- db 01011111b
- db 0x00
Advertisement
Add Comment
Please, Sign In to add comment