Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ORG 0x7C00]
- [BITS 16]
- CODE_OFFSET equ 0x8
- DATA_OFFSET equ 0x10
- KERNEL_POS equ 0x1000 ; 4096 bits dec, 512 bytes
- ; loader - 512 size bytes,
- ; then kernel will placed to 512
- _start:
- xor ax, ax
- mov es, ax
- mov ds, ax
- mov ss, ax
- mov sp, 0x7C00
- mov si, msg ; print message
- call PRINT
- lgdt [gdt_descriptor]
- read_kernel:
- mov bx, KERNEL_POS
- mov dl, 0x80 ; always to int 0x13
- mov cl, 0x02 ; second sector(each 512 bytes)
- mov ch, 0x00 ; first cylinder
- mov ah, 0x02 ; read
- mov al, 8 ; 8 sectors to read
- int 0x13
- prot_mode_switch:
- cli
- mov eax, cr0
- or eax, 0x01
- mov cr0, eax
- jmp CODE_OFFSET:prot_mode_main
- PRINT:
- mov ah, 0x0E
- mov al, [si]
- cmp al, 0
- jz .end
- inc si
- int 0x10
- jmp PRINT
- .end:
- ret
- gdt_start:
- ; NULL descriptor
- dd 0x00000000
- dd 0x00000000
- ;KERNEL MODE:
- ;code segment (0x8)
- dw 0xFFFF ; Limit
- dw 0x0000 ; Base
- db 0x00 ; Base
- db 0b10011010 ; Access byte
- db 0b11001111 ; Flags
- db 0x00 ; Base
- ;data segment (0x10)
- dw 0xFFFF ; Limit
- dw 0x0000 ; Base
- db 0x00 ; Base
- db 0b10010010 ; Access byte
- db 0b11001111 ; Flags
- db 0x00 ; Base
- gdt_end:
- gdt_descriptor:
- dw gdt_end - gdt_start - 1 ; size - 1
- dd gdt_start
- [BITS 32]
- prot_mode_main:
- mov sp, 0x9C00 ; initialize stack for prot mode
- mov bp, sp
- mov ax, 0x10 ; initialize segment registers
- mov ds, ax ; for prot mode
- mov ss, ax
- mov fs, ax
- mov gs, ax
- mov es, ax
- in al, 0x92 ; enabling a20 line
- or al, 0x2
- out 0x92, al
- hlt
- msg: db "Booting", 0
- test: db "Test", 0
- TIMES 510-($-$$) db 0x00
- dw 0xaa55
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement