Skip to content

Instantly share code, notes, and snippets.

@iankronquist
Last active May 4, 2021 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iankronquist/b1a232b533b1f1c33c9dc3141d468579 to your computer and use it in GitHub Desktop.
Save iankronquist/b1a232b533b1f1c33c9dc3141d468579 to your computer and use it in GitHub Desktop.
.intel_syntax noprefix
# GDT:
# 0x00 NULL
# 0x10 32 bit code
# 0x18 32 bit data
# 0x20 16 bit code ; 64kb limit
# 0x28 16 bit data ; 64kb limit
.extern BootDrive
.extern halt
.code32
# void do_bios_call_13(u16 sector=si)
do_bios_call_13:
jmp 0x20:.real
.real:
.code16
mov ax, 0x28
mov ds, ax
mov es, ax
#mov fs, ax
#mov gs, ax
mov ss, ax
#mov eax, cr0
#and eax, ~2#~CRO_PE
xor eax, eax
mov cr0, eax
# AH = 02h
# AL = number of sectors to read (must be nonzero)
# CH = low eight bits of cylinder number
# CL = sector number 1-63 (bits 0-5)
# high two bits of cylinder (bits 6-7, hard disk only)
# DH = head number
# DL = drive number (bit 7 set for hard disk)
# ES:BX -> data buffer
mov ax, 0x0201
xor ch, ch
mov cl, [esp-4]
mov bx, 0x7c00 + 0x200 + 0x200
xor dh, dh
mov dl, [BootDrive]
sti
int 0x13
cli
jc halt
.did_call:
jmp 0x10:.protected
.protected:
.code32
#mov eax, cr0
#or eax, 2#CRO_PE
mov eax, 1
mov cr0, eax
mov ax, 0x18
mov ds, ax
mov es, ax
#mov fs, ax
#mov gs, ax
mov ss, ax
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment