mirror of https://github.com/tailix/loadwarka.git
182 lines
2.8 KiB
ArmAsm
182 lines
2.8 KiB
ArmAsm
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#define STAGE2_BASE 0x7e00
|
|
#define STAGE2_SIZE (STAGE2_BASE + 8)
|
|
|
|
.code16
|
|
.global _start
|
|
|
|
.section .rodata
|
|
size_str: .string "Stage 2 size: "
|
|
reading_sector: .string "Reading sector "
|
|
parenth: .string " ("
|
|
of: .string " of "
|
|
to_address: .string ") to address "
|
|
|
|
.section .text
|
|
_start:
|
|
mov $1, %ax
|
|
mov $STAGE2_BASE, %bx
|
|
xor %cx, %cx
|
|
call print_reading_state
|
|
|
|
mov $0x02, %ah
|
|
mov $1, %al // Sectors count
|
|
mov $0x80, %dl // Drive
|
|
mov $0, %ch // Cylinder
|
|
mov $0, %dh // Head
|
|
mov $2, %cl // Cylinder and sector
|
|
mov $STAGE2_BASE, %bx // Address
|
|
int $0x13
|
|
|
|
mov $STAGE2_SIZE, %bx
|
|
mov (%bx), %ax
|
|
call print_stage2_size
|
|
|
|
// DX - dividend high (always zero)
|
|
xor %dx, %dx
|
|
// AX - dividend low
|
|
mov $STAGE2_SIZE, %bx
|
|
mov (%bx), %ax
|
|
// BX - divisor (always 512)
|
|
mov $512, %bx
|
|
// AX - quotient
|
|
// DX - remainder
|
|
div %bx
|
|
|
|
test %dx, %dx
|
|
jz no_rem
|
|
inc %ax
|
|
no_rem:
|
|
|
|
mov %ax, %cx
|
|
mov $STAGE2_BASE, %bx
|
|
mov $1, %ax
|
|
|
|
// AX - current sector index
|
|
// BX - current address
|
|
// CX - total number of sectors
|
|
read_loop:
|
|
cmp %ax, %cx
|
|
je finish
|
|
|
|
add $512, %bx
|
|
inc %ax
|
|
|
|
push %ax
|
|
push %bx
|
|
push %cx
|
|
|
|
call print_reading_state
|
|
|
|
pop %cx
|
|
pop %bx
|
|
pop %ax
|
|
push %ax
|
|
push %bx
|
|
push %cx
|
|
|
|
add $1, %ax
|
|
mov %al, %cl // Cylinder and sector
|
|
mov $0x02, %ah
|
|
mov $1, %al // Sectors count
|
|
mov $0x80, %dl // Drive
|
|
mov $0, %ch // Cylinder
|
|
mov $0, %dh // Head
|
|
int $0x13
|
|
|
|
pop %cx
|
|
pop %bx
|
|
pop %ax
|
|
jmp read_loop
|
|
|
|
finish:
|
|
mov $newline, %si
|
|
call print_str
|
|
call restore_disk_number
|
|
ljmp $0, $STAGE2_BASE
|
|
|
|
// AX - size
|
|
print_stage2_size:
|
|
push %ax
|
|
|
|
mov $size_str, %si
|
|
call print_str
|
|
|
|
pop %ax
|
|
call print_number
|
|
|
|
mov $newline, %si
|
|
call print_str
|
|
|
|
ret
|
|
|
|
// AX - current sector index
|
|
// BX - current address
|
|
// CX - total number of sectors
|
|
print_reading_state:
|
|
push %ax
|
|
push %bx
|
|
push %cx
|
|
|
|
mov $reading_sector, %si
|
|
call print_str
|
|
|
|
pop %cx
|
|
pop %bx
|
|
pop %ax
|
|
push %ax
|
|
push %bx
|
|
push %cx
|
|
|
|
inc %ax
|
|
call print_number
|
|
|
|
mov $parenth, %si
|
|
call print_str
|
|
|
|
pop %cx
|
|
pop %bx
|
|
pop %ax
|
|
push %ax
|
|
push %bx
|
|
push %cx
|
|
|
|
call print_number
|
|
|
|
mov $of, %si
|
|
call print_str
|
|
|
|
pop %cx
|
|
// pop %bx
|
|
// pop %ax
|
|
// push %ax
|
|
// push %bx
|
|
push %cx
|
|
|
|
mov %cx, %ax
|
|
call print_number
|
|
|
|
mov $to_address, %si
|
|
call print_str
|
|
|
|
pop %cx
|
|
pop %bx
|
|
// pop %ax
|
|
// push %ax
|
|
push %bx
|
|
push %cx
|
|
|
|
mov %bx, %ax
|
|
call print_number
|
|
|
|
mov $newline, %si
|
|
call print_str
|
|
|
|
pop %cx
|
|
pop %bx
|
|
pop %ax
|
|
ret
|