Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [BITS 16] ; Working in 16-bit mode
- PUSH CS
- POP DS
- MOV SI, boot_msg ; Sets up to print the boot message
- CALL print ; Prints the contents of SI
- CALL enable_a20 ; Enables A20 for OVER 4GB of RAM!
- MOV SI, pmode_msg ; Sets up to print the Entering PMode message
- CALL print ; Prints the contents of SI
- CLI ; Clears those pesky interrupts for GDT!
- XOR AX, AX ; Logical OR (basically resets, I think?)
- MOV DS, AX ; Loads DS register
- lgdt[gdt_desc] ; Loads the GDT.
- MOV EAX, CR0 ; Setting up PMode, dumps CR0 into EAX
- OR EAX, 1 ; Sets bit 0 on CR0
- MOV CR0, EAX ; Dumps EAX into CR0, with bits set
- JMP 08h:clear_pipe ; Jumps to clear 16-bit instructions
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; STAGE2 SUBROUTINES ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; GDT section. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- gdt: ; Address for the GDT
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Null segment, reserved by Intel. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- gdt_null: ; Null Segment
- dd 0
- dd 0
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Code segment, read and execute, nonconforming. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- gdt_code:
- dw 0FFFFh
- dw 0
- db 0
- db 10011010b
- db 11001111b
- db 0
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Data segment, read and write, expand down. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- gdt_data:
- dw 0FFFFh
- dw 0
- db 0
- db 10010010b
- db 11001111b
- db 0
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Calculates the GDT size. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- gdt_end:
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; GDT descriptor. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- gdt_desc:
- dw gdt_end - gdt - 1 ; Limit (size)
- dd gdt ; Address of the GDT
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Prints a string to the screen. ;
- ; Takes the value of SI to do this. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- print: ; Routine: output string in SI to screen
- mov ah, 0Eh ; int 10h 'print char' function
- .repeat:
- lodsb ; Get character from string
- cmp al, 0
- je .done ; If char is zero, end of string
- int 10h ; Otherwise, print it
- jmp .repeat
- .done:
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Sets up the A20 line for up to 4GB of memory. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- enable_a20:
- cli ;Disables interrupts
- push ax ;Saves AX
- mov al, 0xdd ;Look at the command list
- out 0x64, al ;Command Register
- pop ax ;Restore's AX
- sti ;Enables interrupts
- mov si, a20_msg
- call print
- ret
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; 16-bit Declarations. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- boot_msg DB 'Stage Two Loaded.',13,10,0 ; Boot message
- pmode_msg DB 'Now entering Protected Mode...',13,10,0 ; PMode message
- a20_msg DB 'Address line active.',13,10,0 ; A20 active
- [BITS 32] ; Enter 32-bit mode.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Clears previous 16-bit instructions in PMode. ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- clear_pipe:
- MOV AX, 10h ; Sets AX for segments
- MOV DS, AX ; Sets data segment
- MOV SS, AX ; Sets stack segment
- MOV ESP, 090000h ; Sets our stack
- JMP hang
- hang:
- JMP hang
Advertisement
Add Comment
Please, Sign In to add comment