UCHEBA/4 СЕМ/ОПЕРАЦИОННЫЕ СИСТЕМЫ/2 ЛАБА/bootsect.asm

160 lines
3.1 KiB
NASM
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

.intel_syntax noprefix
.code16
.global _start
_start:
xor ax, ax # Clear AX
mov ds, ax # Set DS to 0
mov es, ax # Set ES to 0
mov ss, ax # Set SS to 0
mov sp, 0x7C00 # Set stack pointer
mov ax, 0x1000 # Load the address where the disk is located
mov es, ax # Set ES to point to this location
mov bx, 0 # BX = 0
mov ah, 2 # Read sectors function
mov dl, 1 # Drive number (1 = first floppy)
mov dh, 0 # Head number
mov cl, 1 # Starting sector (1)
mov ch, 0 # Cylinder number
mov al, 88 # Number of sectors to read
int 0x13 # BIOS interrupt to read sectors
mov ax, 0x0003
int 0x10
LOAD:
xor cx, cx
xor dx, dx
mov eax, 0xe801
int 0x15
mov [0x3400], cx # Количество Кб до 16 Мб
mov [0x3420], dx # Количество страниц размером 64 Кб
LOADING_OS_PRINT:
mov ah, 0x0e
mov al, 'L'
int 0x10
mov al, 'o'
int 0x10
mov al, 'a'
int 0x10
mov al, 'd'
int 0x10
mov al, 'i'
int 0x10
mov al, 'n'
int 0x10
mov al, 'g'
int 0x10
mov al, ' '
int 0x10
mov al, 'O'
int 0x10
mov al, 'S'
int 0x10
mov al, '.'
int 0x10
mov al, '.'
int 0x10
mov al, '.'
int 0x10
mov al, ' '
int 0x10
mov al, 'P'
int 0x10
mov al, 'r'
int 0x10
mov al, 'e'
int 0x10
mov al, 's'
int 0x10
mov al, 's'
int 0x10
mov al, ' '
int 0x10
mov al, 's'
int 0x10
mov al, 'p'
int 0x10
mov al, 'a'
int 0x10
mov al, 'c'
int 0x10
mov al, 'e'
int 0x10
mov al, ' '
int 0x10
mov al, 't'
int 0x10
mov al, 'o'
int 0x10
mov al, ' '
int 0x10
mov al, 'c'
int 0x10
mov al, 'o'
int 0x10
mov al, 'n'
int 0x10
mov al, 't'
int 0x10
mov al, 'i'
int 0x10
mov al, 'n'
int 0x10
mov al, 'u'
int 0x10
mov al, 'e'
int 0x10
mov al, '!'
int 0x10
input:
mov ah, 0
int 0x16
cmp al, 0x20
jne input
mov ax, 0x03
int 0x10
COMPLETE:
mov ax, 0x3 # Read character from keyboard
int 0x10 # BIOS interrupt for video services
lgdt gdt_info # Load GDT
cli # Clear interrupts
in al, 0x70 # Read from port 0x70
or al, 0x80 # Set bit 7
out 0x70, al # Write back to port 0x70
mov eax, cr0 # Read control register 0
or al, 1 # Set PE bit to enter protected mode
mov cr0, eax # Write back to CR0
jmp 0x8:protected_mode # Jump to protected mode
.code32
protected_mode:
mov ax, 0x10 # Load data segment selector
mov es, ax # Set ES
mov ds, ax # Set DS
mov ss, ax # Set SS
call 0x10000 # Call code at new segment
inf_loop:
jmp inf_loop # Infinite loop
gdt:
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9A, 0xCF, 0x00
.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xCF, 0x00
gdt_info:
.word gdt_info - gdt
.word gdt, 0
# Reserve space to ensure we have a valid boot sector
.zero (512 - ($ - _start) - 2)
.byte 0x55, 0xAA