191 lines
3.7 KiB
ArmAsm
191 lines
3.7 KiB
ArmAsm
.arch i8086,jumps
|
|
.code16
|
|
.intel_syntax noprefix
|
|
|
|
.section .init
|
|
.global _start
|
|
_start:
|
|
cli
|
|
mov ax, 0x2000 # stack address
|
|
mov sp, ax # ss should already be 0
|
|
sti
|
|
jmp main
|
|
|
|
|
|
diskpointer = 0x1e*4
|
|
dbtbase = 0x0500
|
|
|
|
.section .text.dosdbt
|
|
.global dosdbt
|
|
dosdbt: # assumes es=0
|
|
push si
|
|
push di
|
|
push ds
|
|
mov si, diskpointer
|
|
lds si, [si]
|
|
mov di, dbtbase
|
|
mov cx, 0x0a # size of the dbt
|
|
cld
|
|
rep movsb # move dbt to dbtbase
|
|
pop ds
|
|
mov al, 9 # sectors per track
|
|
mov si, dbtbase
|
|
mov [si+4], al # set number of sectors
|
|
mov di, diskpointer
|
|
mov [di], si # new int1eh offset
|
|
mov [di+2], ds # and segment
|
|
pop di
|
|
pop si
|
|
ret
|
|
|
|
.section .text.int80stuff
|
|
|
|
# near copy [param 2] bytes, ds:[param 0] -> ds:[param 1]
|
|
copy:
|
|
mov ax, [bp-14] # ds
|
|
mov es, ax
|
|
mov ds, ax
|
|
mov cl, 4
|
|
shl si, cl
|
|
mov si, [bp+0] # source
|
|
mov di, [bp+2] # destination
|
|
mov cx, [bp+4] # length
|
|
cld
|
|
rep movsb
|
|
ret
|
|
|
|
## floppy stuff
|
|
|
|
# same as read but with a different int13h:ah value
|
|
writesector:
|
|
mov ax, 0x0301 # write command, 1 sector
|
|
jmp 0f
|
|
|
|
# params: addr, c, h, s
|
|
# return status in ah, sectors read (1 or 0) in al
|
|
readsector:
|
|
mov ax, 0x0201 # read command, 1 sector
|
|
0:
|
|
mov bx, [bp+0] # addr
|
|
mov ch, [bp+2] # c
|
|
mov dh, [bp+4] # h
|
|
mov cl, [bp+6] # s
|
|
int 0x13
|
|
ret
|
|
|
|
|
|
# params: c, h
|
|
# returns: status in ah, 0 in al?
|
|
|
|
buffer = 0xe000 # buffer needs to be big enough for a whole track
|
|
# (for some reason), so 9 * 512 bytes = 0x1200 bytes
|
|
sectors = 9
|
|
|
|
formattrack:
|
|
mov bx, buffer
|
|
xor cx, cx
|
|
0:
|
|
cmp cl, sectors
|
|
jnl 1f
|
|
mov di, cx
|
|
and di, 0x0f # max 15 sectors
|
|
shl di, 1
|
|
shl di, 1 # di = cl*4
|
|
lea di, [bx+di]
|
|
mov al, [bp+0] # track number
|
|
mov [di+0], al
|
|
mov al, [bp+2] # head number
|
|
mov [di+1], al
|
|
mov al, cl # sector number
|
|
inc al
|
|
mov [di+2], al
|
|
movb [di+3], 0x02 # 512 bytes per sector
|
|
inc cl
|
|
jmp 0b
|
|
1:
|
|
mov ah, 0x05 # format track
|
|
mov al, sectors
|
|
mov dl, 0 # first drive
|
|
mov ch, [bp+0] # track number
|
|
mov dh, [bp+2] # head number
|
|
mov cl, 1 # sector number (first sector?)
|
|
int 0x13
|
|
ret
|
|
|
|
# params: ds:fname, ds:dest
|
|
readfile:
|
|
mov si, [bp-14] # ds
|
|
mov cl, 4
|
|
shl si, cl
|
|
mov ax, [bp+0]
|
|
add ax, si
|
|
mov dx, [bp+2]
|
|
add dx, si
|
|
call fat12_readfile
|
|
ret
|
|
|
|
# params: ds:addr, size
|
|
sendpara:
|
|
mov si, [bp-14] # ds
|
|
mov cl, 4
|
|
shl si, cl
|
|
mov ax, [bp+0]
|
|
add ax, si
|
|
mov dx, [bp+2]
|
|
call parasend
|
|
ret
|
|
|
|
# params: ds:addr, size
|
|
recvpara:
|
|
mov si, [bp-14] # ds
|
|
mov cl, 4
|
|
shl si, cl
|
|
mov ax, [bp+0]
|
|
add ax, si
|
|
mov dx, [bp+2]
|
|
call pararecv
|
|
ret
|
|
|
|
.section .text.int80h
|
|
.global int80h
|
|
int80h:
|
|
push si
|
|
push di
|
|
push bp
|
|
push ds
|
|
push es
|
|
xor cx, cx
|
|
mov es, cx
|
|
mov ds, cx
|
|
shl ah
|
|
cmp ah, offset int80h_entries
|
|
jge 0f
|
|
mov al, ah
|
|
xor ah, ah
|
|
mov si, ax
|
|
mov bp, sp
|
|
lea bp, [bp + 16] # 10 for us, 6 for the interrupt
|
|
call cs:[int80h_table+si]
|
|
jmp 1f
|
|
0:
|
|
mov ax, -1
|
|
1:
|
|
pop es
|
|
pop ds
|
|
pop bp
|
|
pop di
|
|
pop si
|
|
iret
|
|
|
|
.section .rodata.int80h
|
|
int80h_table:
|
|
.word offset copy # 0x00
|
|
.word offset readsector # 0x01
|
|
.word offset writesector # 0x02
|
|
.word offset formattrack # 0x03
|
|
.word offset readfile # 0x04
|
|
.word offset recvpara # 0x05
|
|
.word offset sendpara # 0x06
|
|
|
|
int80h_entries = . - int80h_table
|