2022-01-16 08:26:54 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2022-01-26 21:46:30 +00:00
|
|
|
|
2022-01-27 01:46:04 +00:00
|
|
|
#define STAGE2_BASE 0x7e00
|
2022-01-27 18:41:22 +00:00
|
|
|
#define STAGE2_SIZE (STAGE2_BASE + 8)
|
2022-01-26 21:46:30 +00:00
|
|
|
|
2022-01-26 20:19:39 +00:00
|
|
|
.code16
|
2022-01-27 18:27:41 +00:00
|
|
|
.global _start
|
2022-01-26 21:29:18 +00:00
|
|
|
|
2022-01-27 18:50:02 +00:00
|
|
|
.section .rodata
|
2022-01-27 00:29:34 +00:00
|
|
|
hello: .string "Hello from stage 1!\r\n"
|
2022-01-27 02:20:10 +00:00
|
|
|
size_str: .string "Stage 2 size: "
|
2022-01-27 00:47:11 +00:00
|
|
|
number_of_sectors: .string "Number of sectors: "
|
2022-01-27 01:13:37 +00:00
|
|
|
reading_sector: .string "Reading sector "
|
2022-01-27 02:17:59 +00:00
|
|
|
parenth: .string " ("
|
|
|
|
of: .string " of "
|
|
|
|
to_address: .string ") to address "
|
2022-01-26 21:33:27 +00:00
|
|
|
|
2022-01-27 18:50:02 +00:00
|
|
|
.section .text
|
2022-01-27 18:27:41 +00:00
|
|
|
_start:
|
2022-01-27 01:46:04 +00:00
|
|
|
mov $hello, %si
|
2022-01-27 00:21:22 +00:00
|
|
|
call print_str
|
|
|
|
|
2022-01-27 02:17:59 +00:00
|
|
|
mov $1, %ax
|
|
|
|
mov $STAGE2_BASE, %bx
|
|
|
|
xor %cx, %cx
|
|
|
|
call print_reading_state
|
|
|
|
|
2022-01-26 22:58:11 +00:00
|
|
|
mov $0x02, %ah
|
2022-01-27 00:34:06 +00:00
|
|
|
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
|
2022-01-26 20:19:39 +00:00
|
|
|
int $0x13
|
|
|
|
|
2022-01-27 18:09:49 +00:00
|
|
|
mov $STAGE2_SIZE, %bx
|
2022-01-27 00:21:22 +00:00
|
|
|
mov (%bx), %ax
|
2022-01-27 02:20:10 +00:00
|
|
|
call print_stage2_size
|
2022-01-26 23:16:14 +00:00
|
|
|
|
2022-01-27 00:47:11 +00:00
|
|
|
// DX - dividend high (always zero)
|
|
|
|
xor %dx, %dx
|
|
|
|
// AX - dividend low
|
2022-01-27 18:09:49 +00:00
|
|
|
mov $STAGE2_SIZE, %bx
|
2022-01-27 00:47:11 +00:00
|
|
|
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:
|
2022-01-27 00:51:37 +00:00
|
|
|
|
2022-01-27 00:47:11 +00:00
|
|
|
push %ax
|
|
|
|
call print_number_of_sectors
|
2022-01-27 01:26:59 +00:00
|
|
|
pop %cx
|
2022-01-27 02:17:59 +00:00
|
|
|
|
2022-01-27 00:53:49 +00:00
|
|
|
mov $STAGE2_BASE, %bx
|
2022-01-27 02:17:59 +00:00
|
|
|
mov $1, %ax
|
2022-01-27 00:47:11 +00:00
|
|
|
|
2022-01-27 02:17:59 +00:00
|
|
|
// AX - current sector index
|
|
|
|
// BX - current address
|
2022-01-27 01:26:59 +00:00
|
|
|
// CX - total number of sectors
|
2022-01-27 00:51:37 +00:00
|
|
|
read_loop:
|
2022-01-27 02:17:59 +00:00
|
|
|
cmp %ax, %cx
|
|
|
|
je finish
|
|
|
|
|
2022-01-27 00:53:49 +00:00
|
|
|
add $512, %bx
|
2022-01-27 01:26:59 +00:00
|
|
|
inc %ax
|
|
|
|
|
2022-01-27 00:51:37 +00:00
|
|
|
push %ax
|
2022-01-27 00:53:49 +00:00
|
|
|
push %bx
|
2022-01-27 01:26:59 +00:00
|
|
|
push %cx
|
2022-01-27 01:13:37 +00:00
|
|
|
|
2022-01-27 01:59:21 +00:00
|
|
|
call print_reading_state
|
2022-01-27 01:13:37 +00:00
|
|
|
|
2022-01-27 01:26:59 +00:00
|
|
|
pop %cx
|
2022-01-27 00:57:11 +00:00
|
|
|
pop %bx
|
|
|
|
pop %ax
|
|
|
|
push %ax
|
|
|
|
push %bx
|
2022-01-27 01:26:59 +00:00
|
|
|
push %cx
|
|
|
|
|
2022-01-27 02:17:59 +00:00
|
|
|
add $1, %ax
|
2022-01-27 00:57:11 +00:00
|
|
|
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
|
2022-01-27 01:26:59 +00:00
|
|
|
|
|
|
|
pop %cx
|
2022-01-27 00:53:49 +00:00
|
|
|
pop %bx
|
2022-01-27 00:51:37 +00:00
|
|
|
pop %ax
|
|
|
|
jmp read_loop
|
|
|
|
|
|
|
|
finish:
|
2022-01-27 19:32:23 +00:00
|
|
|
mov $newline, %si
|
|
|
|
call print_str
|
2022-01-27 19:24:15 +00:00
|
|
|
call restore_disk_number
|
2022-01-26 23:03:47 +00:00
|
|
|
ljmp $0, $STAGE2_BASE
|
2022-01-26 23:16:14 +00:00
|
|
|
|
2022-01-27 00:33:11 +00:00
|
|
|
// AX - size
|
2022-01-27 02:20:10 +00:00
|
|
|
print_stage2_size:
|
2022-01-27 00:33:11 +00:00
|
|
|
push %ax
|
|
|
|
|
2022-01-27 02:17:59 +00:00
|
|
|
mov $size_str, %si
|
2022-01-27 00:33:11 +00:00
|
|
|
call print_str
|
|
|
|
|
|
|
|
pop %ax
|
|
|
|
call print_number
|
|
|
|
|
2022-01-27 01:46:04 +00:00
|
|
|
mov $newline, %si
|
2022-01-27 00:33:11 +00:00
|
|
|
call print_str
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
2022-01-27 00:47:11 +00:00
|
|
|
// AX - number of sectors
|
|
|
|
print_number_of_sectors:
|
|
|
|
push %ax
|
|
|
|
|
2022-01-27 01:46:04 +00:00
|
|
|
mov $number_of_sectors, %si
|
2022-01-27 00:47:11 +00:00
|
|
|
call print_str
|
|
|
|
|
|
|
|
pop %ax
|
|
|
|
call print_number
|
|
|
|
|
2022-01-27 01:46:04 +00:00
|
|
|
mov $newline, %si
|
2022-01-27 00:47:11 +00:00
|
|
|
call print_str
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
2022-01-27 02:17:59 +00:00
|
|
|
// AX - current sector index
|
2022-01-27 01:59:21 +00:00
|
|
|
// BX - current address
|
2022-01-27 02:17:59 +00:00
|
|
|
// CX - total number of sectors
|
2022-01-27 01:59:21 +00:00
|
|
|
print_reading_state:
|
|
|
|
push %ax
|
|
|
|
push %bx
|
2022-01-27 02:17:59 +00:00
|
|
|
push %cx
|
2022-01-27 01:59:21 +00:00
|
|
|
|
|
|
|
mov $reading_sector, %si
|
|
|
|
call print_str
|
|
|
|
|
2022-01-27 02:17:59 +00:00
|
|
|
pop %cx
|
2022-01-27 01:59:21 +00:00
|
|
|
pop %bx
|
|
|
|
pop %ax
|
|
|
|
push %ax
|
|
|
|
push %bx
|
2022-01-27 02:17:59 +00:00
|
|
|
push %cx
|
2022-01-27 01:59:21 +00:00
|
|
|
|
2022-01-27 02:17:59 +00:00
|
|
|
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
|
2022-01-27 01:59:21 +00:00
|
|
|
call print_number
|
|
|
|
|
|
|
|
mov $to_address, %si
|
|
|
|
call print_str
|
|
|
|
|
2022-01-27 02:17:59 +00:00
|
|
|
pop %cx
|
2022-01-27 01:59:21 +00:00
|
|
|
pop %bx
|
|
|
|
// pop %ax
|
|
|
|
// push %ax
|
|
|
|
push %bx
|
2022-01-27 02:17:59 +00:00
|
|
|
push %cx
|
2022-01-27 01:59:21 +00:00
|
|
|
|
|
|
|
mov %bx, %ax
|
|
|
|
call print_number
|
|
|
|
|
|
|
|
mov $newline, %si
|
|
|
|
call print_str
|
|
|
|
|
2022-01-27 02:17:59 +00:00
|
|
|
pop %cx
|
2022-01-27 01:59:21 +00:00
|
|
|
pop %bx
|
|
|
|
pop %ax
|
|
|
|
ret
|