2023-02-06 00:01:48 -06:00
|
|
|
secreadcnt equ 0x38
|
|
|
|
kernelreads equ 0x10000/(512*secreadcnt) ; 64K / Sector Size FIXME This underestimates when kernel size is not divisible by bytes per read
|
2022-09-14 16:50:44 -05:00
|
|
|
[ORG 0x7c00]
|
|
|
|
[BITS 16]
|
|
|
|
xor ax, ax
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
2023-02-06 00:01:48 -06:00
|
|
|
mov ax, 0x8000
|
|
|
|
mov ss, ax
|
|
|
|
mov sp, 0xFF00
|
2023-02-07 18:52:17 -06:00
|
|
|
mov ah, 0x41 ; int 13 extensions check
|
|
|
|
mov bx, 0x55AA
|
|
|
|
int 0x13
|
|
|
|
jc no_exten
|
2023-02-06 00:01:48 -06:00
|
|
|
mov cx, kernelreads
|
|
|
|
read_loop:
|
|
|
|
xor ax, ax
|
2022-09-14 16:50:44 -05:00
|
|
|
mov ah, 0x42
|
|
|
|
mov si, addr_packet
|
|
|
|
int 0x13
|
2023-02-06 00:01:48 -06:00
|
|
|
jc err
|
|
|
|
add word [addr_packet_transfer_buff_seg], (secreadcnt*512)/16
|
|
|
|
add word [addr_packet_start_block], secreadcnt
|
|
|
|
loop read_loop
|
|
|
|
entry:
|
2023-02-07 18:52:17 -06:00
|
|
|
mov ax,0x2403 ; A20 BIOS Support
|
|
|
|
int 0x15
|
|
|
|
jb .no_a20
|
|
|
|
cmp ah,0
|
|
|
|
jnz .no_a20
|
|
|
|
mov ax,0x2401 ; A20 BIOS Activate
|
|
|
|
int 0x15
|
|
|
|
.no_a20:
|
2023-02-06 00:01:48 -06:00
|
|
|
cli ; no interrupts
|
|
|
|
xor ax,ax
|
|
|
|
mov ds, ax
|
|
|
|
lgdt [gdt_desc] ; load gdt register
|
|
|
|
mov eax, cr0 ; set pmode bit
|
|
|
|
or al, 1
|
|
|
|
mov cr0, eax
|
|
|
|
jmp 08h:Pmode
|
|
|
|
err:
|
2023-02-07 18:52:17 -06:00
|
|
|
mov bx, ax
|
|
|
|
mov si, string
|
|
|
|
mov cx, string_end - string
|
|
|
|
jmp print
|
|
|
|
no_exten:
|
|
|
|
mov bx, ax
|
|
|
|
mov si, no_exten_str
|
|
|
|
mov cx, no_exten_str_end - no_exten_str
|
|
|
|
print:
|
2022-09-14 16:50:44 -05:00
|
|
|
push 0xb800
|
|
|
|
pop es
|
|
|
|
xor di, di
|
|
|
|
mov ah, 0x7
|
|
|
|
err_print:
|
|
|
|
lodsb
|
|
|
|
stosw
|
|
|
|
loop err_print
|
2023-02-07 18:52:17 -06:00
|
|
|
add di, 2
|
|
|
|
mov ax, bx
|
|
|
|
call hexprint
|
2022-09-14 16:50:44 -05:00
|
|
|
hlt_loop:
|
|
|
|
hlt
|
|
|
|
jmp hlt_loop
|
2023-02-07 18:52:17 -06:00
|
|
|
hexprint:
|
|
|
|
xor cx, cx
|
|
|
|
mov bl, al
|
|
|
|
shr al, 4
|
|
|
|
jmp .donibble
|
|
|
|
.nibble2:
|
|
|
|
mov al, bl
|
|
|
|
inc cx
|
|
|
|
.donibble:
|
|
|
|
and al, 0x0F
|
|
|
|
cmp al, 0x0A
|
|
|
|
jl .noadjust
|
|
|
|
add al, 'A' - '0' - 10
|
|
|
|
.noadjust:
|
|
|
|
add al, '0'
|
|
|
|
mov ah, 0x7
|
|
|
|
stosw
|
|
|
|
test cx, cx
|
|
|
|
jz .nibble2
|
|
|
|
ret
|
|
|
|
|
2023-01-31 21:26:43 -06:00
|
|
|
[BITS 32]
|
|
|
|
Pmode:
|
2023-02-01 14:18:27 -06:00
|
|
|
mov eax, 0x10
|
2023-01-31 21:26:43 -06:00
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
2023-02-01 14:18:27 -06:00
|
|
|
mov fs, ax
|
|
|
|
mov gs, ax
|
|
|
|
mov ss, ax
|
2023-02-07 18:52:17 -06:00
|
|
|
; check A20
|
|
|
|
.a20:
|
2023-02-07 23:53:13 -06:00
|
|
|
mov edi, 0x107C00
|
|
|
|
mov esi, 0x007C00
|
2023-02-07 18:52:17 -06:00
|
|
|
mov [esi], esi
|
|
|
|
mov [edi], edi
|
|
|
|
cmpsd
|
|
|
|
jne .kernel
|
|
|
|
in al, 0x92 ; fast A20
|
2023-02-01 14:18:27 -06:00
|
|
|
test al, 2
|
2023-02-07 18:52:17 -06:00
|
|
|
jnz .fa20_end
|
2023-02-01 14:18:27 -06:00
|
|
|
or al, 2
|
|
|
|
and al, 0xFE
|
|
|
|
out 0x92, al
|
2023-02-07 18:52:17 -06:00
|
|
|
.fa20_end:
|
|
|
|
jmp .a20
|
|
|
|
.kernel:
|
2023-01-31 21:26:43 -06:00
|
|
|
mov esi, 0x8000
|
|
|
|
mov edi, 0x100000
|
2023-02-01 20:42:05 -06:00
|
|
|
mov ecx, 0x10000
|
2023-01-31 21:26:43 -06:00
|
|
|
rep movsb
|
|
|
|
jmp 08h:0x100000
|
2023-02-07 18:52:17 -06:00
|
|
|
|
2023-01-31 21:26:43 -06:00
|
|
|
gdt_desc:
|
|
|
|
dw gdt_end - gdt
|
|
|
|
dd gdt
|
|
|
|
gdt:
|
|
|
|
gdt_null: dq 0
|
|
|
|
gdt_code: dw 0xFFFF, 0 ; bits 0-15 limit (4GB), bits 0-15 base address
|
|
|
|
db 0 ; bits 16-23 base address
|
|
|
|
db 10011010b ; access byte
|
|
|
|
db 11001111b ; bits 16-19 limit (4GB), 4 bits flags
|
|
|
|
db 0 ; bits 24-31 base address
|
|
|
|
gdt_data: dw 0xFFFF, 0 ; bits 0-15 limit (4GB), bits 0-15 base address
|
|
|
|
db 0 ; bits 16-23 base address
|
|
|
|
db 10010010b ; access byte
|
|
|
|
db 11001111b ; bits 16-19 limit (4GB), 4 bits flags
|
|
|
|
db 0 ; bits 24-31 base address
|
|
|
|
gdt_end:
|
2022-09-14 16:50:44 -05:00
|
|
|
|
|
|
|
string: db 'DISK ERROR'
|
2023-02-07 18:52:17 -06:00
|
|
|
string_end:
|
|
|
|
no_exten_str: db 'NO INT13 EXTEN'
|
|
|
|
no_exten_str_end:
|
2022-09-14 16:50:44 -05:00
|
|
|
|
|
|
|
addr_packet:
|
|
|
|
db 0x10, 0x00 ; size, reserved
|
2023-02-06 00:01:48 -06:00
|
|
|
dw secreadcnt ; blocks
|
|
|
|
addr_packet_transfer_buff_off: dw 0x0000 ; transfer buffer offset
|
|
|
|
addr_packet_transfer_buff_seg: dw 0x0800 ; transfer buffer segment
|
2023-02-02 21:40:39 -06:00
|
|
|
addr_packet_start_block: dq 1 ; start block
|