Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org 7C00h
- jmp short bootmain
- bootmain:
- xor ax, ax ; We want a segment of 0 for DS for this question
- mov ds, ax ; Set AX to appropriate segment value for your situation
- mov bx, 0x8000 ; Stack segment can be any usable memory
- cli ; Disable interrupts to circumvent bug on early 8088 CPUs
- mov ss, bx ; Top of the stack @ 0x80000.
- mov sp, ax ; Set SP=0 so the bottom of stack will be just below 0x90000
- sti ; Re-enable interrupts
- cld ; Set the direction flag to be positive direction
- mov ah, 0x02 ; Read sectors from drive
- mov al, 2 ; Read 1 sector
- mov ch, 0 ; Cylinder 0
- mov cl, 2 ; Sector 2
- mov dh, 0 ; Head 0
- mov bx, CODE_SEG
- mov es, bx ; ES = CODE_SEG
- xor bx, bx ; BX = 0
- int 0x13
- cli
- lgdt [gdt_descriptor]
- mov eax, cr0
- or eax, 0x1
- mov cr0, eax
- jmp CODE_SEG:prekernel_main
- gdt_start:
- gdt_null:
- dd 0x0
- dd 0x0
- gdt_code:
- dw 0xffff
- dw 0x0
- db 0x0
- db 10011010b
- db 11001111b
- db 0x0
- gdt_data:
- dw 0xffff
- dw 0x0
- db 0x0
- db 10010010b
- db 11001111b
- db 0x0
- gdt_end:
- gdt_descriptor:
- dw gdt_end - gdt_start
- dd gdt_start
- CODE_SEG equ gdt_code - gdt_start
- DATA_SEG equ gdt_data - gdt_start
- [bits 32]
- prekernel_main:
- mov ax, DATA_SEG
- mov ds, ax
- mov es, ax
- mov fs, ax
- mov gs, ax
- mov ss, ax
- mov ebp, 0x2000
- mov esp, ebp
- mov eax, 0xB8000
- .loop:
- cmp eax, 0xB8FA0 ;0xB8000 + 4000
- je .end
- mov byte [eax], 'A'
- inc eax
- mov byte [eax], 0x07
- inc eax
- jmp .loop
- .end:
- hlt
- jmp $
- times 0200h - 2 - ($ - $$) db 0
- dw 0AA55h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement