| 1 | /* ----------------------------------------------------------------------- * |
|---|
| 2 | * |
|---|
| 3 | * Copyright 1998-2008 H. Peter Anvin - All Rights Reserved |
|---|
| 4 | * Copyright 2009 Intel Corporation; author: H. Peter Anvin |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation, Inc., 53 Temple Place Ste 330, |
|---|
| 9 | * Boston MA 02111-1307, USA; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version; incorporated herein by reference. |
|---|
| 11 | * |
|---|
| 12 | * ----------------------------------------------------------------------- */ |
|---|
| 13 | |
|---|
| 14 | /* |
|---|
| 15 | * int 0x25 and 0x26 direct sector access |
|---|
| 16 | * |
|---|
| 17 | * Use assembly wrapper functions for these system calls, since unlike |
|---|
| 18 | * int 0x21 calls they are "dirty" and can destroy unrelated registers. |
|---|
| 19 | * |
|---|
| 20 | * NOTE: these all assume the data buffer is in the data segment, i.e. |
|---|
| 21 | * %ds == %es == dio.bufseg. |
|---|
| 22 | * |
|---|
| 23 | * Usage: int int25_read_sector(drive, dio) |
|---|
| 24 | * Usage: int int26_write_sector(drive, dio) |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | .code16gcc |
|---|
| 28 | .text |
|---|
| 29 | |
|---|
| 30 | .globl int25_read_sector |
|---|
| 31 | .type int25_read_sector, @function |
|---|
| 32 | int25_read_sector: |
|---|
| 33 | pushl %ebp |
|---|
| 34 | pushl %edi |
|---|
| 35 | pushl %esi |
|---|
| 36 | pushl %ebx |
|---|
| 37 | |
|---|
| 38 | decw %ax /* AL = drive number (0 = A:) */ |
|---|
| 39 | movw %dx, %bx /* BX = dio structure */ |
|---|
| 40 | movw 6(%bx), %dx /* DX = data buffer */ |
|---|
| 41 | movw $-1, %cx |
|---|
| 42 | int $0x25 |
|---|
| 43 | jc 1f |
|---|
| 44 | xorw %ax, %ax /* Error code: 0 = no error */ |
|---|
| 45 | 1: |
|---|
| 46 | popfw |
|---|
| 47 | movzwl %ax, %eax |
|---|
| 48 | popl %ebx |
|---|
| 49 | popl %esi |
|---|
| 50 | popl %edi |
|---|
| 51 | popl %ebp |
|---|
| 52 | retl |
|---|
| 53 | .size int25_read_sector, .-int25_read_sector |
|---|
| 54 | |
|---|
| 55 | .globl int26_write_sector |
|---|
| 56 | .type int26_write_sector, @function |
|---|
| 57 | int26_write_sector: |
|---|
| 58 | pushl %ebp |
|---|
| 59 | pushl %edi |
|---|
| 60 | pushl %esi |
|---|
| 61 | pushl %ebx |
|---|
| 62 | |
|---|
| 63 | decw %ax /* AL = drive number (0 = A:) */ |
|---|
| 64 | movw %dx, %bx /* BX = dio structure */ |
|---|
| 65 | movw 6(%bx), %dx /* DX = data buffer */ |
|---|
| 66 | movw $-1, %cx |
|---|
| 67 | int $0x26 |
|---|
| 68 | jc 1f |
|---|
| 69 | xorw %ax, %ax /* Error code: 0 = no error */ |
|---|
| 70 | 1: |
|---|
| 71 | popfw |
|---|
| 72 | movzwl %ax, %eax |
|---|
| 73 | popl %ebx |
|---|
| 74 | popl %esi |
|---|
| 75 | popl %edi |
|---|
| 76 | popl %ebp |
|---|
| 77 | retl |
|---|
| 78 | .size int26_write_sector, .-int26_write_sector |
|---|