하드 디스크 접근할때...? 밑에 올렸던 질문 추가입니다...^^;

kkojiband의 이미지

먼저 답변해주신 분들 감사드립니다~!

역시 책보고 혼자 하는 것보다 고수님들의 도움을 받으니 진도가 빠르네요^^

밑에 lba mode 에 대한 언급이 있어서 찾아보니까 lba mode 에 대한 접근은 chs 를 lba 로 전환해주면 되는거라서 디스크 콘트롤러 or bios or kernel 등에서 한가지만 허용해도 사용이 가능하다고 하더군요...

그럼 bios 의 int 13h 는 받은 chs정보를 lba mode 로 전환해서 콘트롤러에 넘겨주는 함수인가요? 굳이 트랙당 섹터수를 구해서 입력하는걸 보니 그런거같기도 하고...음...--;

이게 아니라면 bios 에 따로 lba mode 로 접근하는 함수가 있나요??

아...다시 찾아보니까 최근의 bios 들은 lba mode 를 지원하기 위해 확장 int 13h 를 사용한다고 하는데 이건 어떤건가요??

익명 사용자의 이미지

우선 Disk 제어는 방법이 몇가지 있습니다.
첫번째는 Base가 0x1f0, 0x170, (3f0) I/O port를 통해서 접근하는
PIO1 ~ 4 , DMA 방식이 있습니다.
두번째는 RealMode환경에서 사용하는 13h interrupt가 있습니다.
(반드시 RealMode에서만 되는 것은 아니고 보호모드에서도
GDT를 잘 꾸며주면 가능합니다.)

보통 Bootloader의 크기를 줄이기 위해 초기 부팅시에
13h를 사용하고 실제 커널내에서는 DMA를 사용하는게 주를 이룹니다.
꼭 그렇게 할 필요는 없지만 속도면에서 DMA 또는 PIO4가 제일 빠릅니다.

이론적으로 PIO4가 제일 빠르지만 멀티테스크 환경에서는 불리한점이 많아서
잘 사용하지 않는 편입니다.

그리고 PIO/DMA방식은 LBA sector를 직접 받아들이는 제어방식이 있습니다.
즉, CHS <-> LBA상호변환을 할 필요가 없이 LBA 로만 접근하는 방법이
있습니다.

저는 PIO4를 사용해서 드라이버(리눅스가 아닌)를 만든적이 있는데
멀티테스크환경에서는 상당히 타이밍이 중요하다는 것을 깨달았던 적이 있네요.
즉, "DMA로 할걸..." 이라고 반성한적이 있습니다.

밑의 내용은 HelpPC 2.10 에 나와 있는 인터럽트 도움말입니다.
실린더상위 2비트가 어디에 있는지 확인하시면 도움이 될지 모르겠네요.

                     INT 13,2 - Read Disk Sectors

   AH = 02
   AL = number of sectors to read  (1-128 dec.)
   CH = track/cylinder number  (0-1023 dec., see below)
   CL = sector number  (1-17 dec.)
   DH = head number  (0-15 dec.)
   DL = drive number (0=A:, 1=2nd floppy, 80h=drive 0, 81h=drive 1)
   ES:BX = pointer to buffer


   on return:
   AH = status  (see INT 13,STATUS)
   AL = number of sectors read
   CF = 0 if successful
      = 1 if error

 - BIOS disk reads should be retried at least three times and the
   controller should be reset upon error detection
 - be sure ES:BX does not cross a 64K segment boundary or a
   DMA boundary error will occur
 - many programming references list only floppy disk register values
 - only the disk number is checked for validity
 - the parameters in CX change depending on the number of cylinders;
   the track/cylinder number is a 10 bit value taken from the 2 high
   order bits of CL and the 8 bits in CH (low order 8 bits of track):


  │F│E│D│C│B│A│9│8│7│6│5-0│  CX
   │ │ │ │ │ │ │ │ │ │  └─────  sector number
   │ │ │ │ │ │ │ │ └─┴───────  high order 2 bits of track/cylinder
   └─┴─┴─┴─┴─┴─┴─┴──────────  low order 8 bits of track/cyl number

I/O 방식

  1F0-1FF  Fixed disk 0 (AT)
  1F0 disk 0 data
  1F1 disk 0 error
  1F2 disk 0 sector count
  1F3 disk 0 sector number
  1F4 disk 0 cylinder low
  1F5 disk 0 cylinder high
  1F6 disk 0 drive/head
  1F7 disk 0 status

  170-17F  Fixed disk 1 (AT)
  170 disk 1 data
  171 disk 1 error
  172 disk 1 sector count
  173 disk 1 sector number
  174 disk 1 cylinder low
  175 disk 1 cylinder high
  176 disk 1 drive/head
  177 disk 1 status

   3F0-3F7  Floppy disk controller (except PCjr)
   3F0 Diskette controller status A
   3F1 Diskette controller status B
   3F2 controller control port
   3F4 controller status register
   3F5 data register (write 1-9 byte command, see INT 13)
   3F6 Diskette controller data
   3F7 Diskette digital input
Necromancer의 이미지

BIOS도 내부적으로는 리눅스 커널처럼 다 CHS/LBA로 접근합니다.

정 궁금하시다면 INT13h/AH=4xh를 찾아보세요.
이게 BIOS에서 LBA로 하드디스크 접근하는 인터페이스입니다.
AH=42h일 경우 Read, AH=43일 경우 Write이고요.
이때 인수는 DL에 드라이브 번호 넣고,
DS:SI에 LBA접근 정보를 담은 Disk address packet이라는
정보가 위치하는 주소를 담습니다. 구조가 아래와 같지요.

00 [BYTE] : 구조체 크기 (10h, 18h 둘중 하나. 일반적으로는 10h)
01 [BYTE] : 예비 (0)
02 [WORD] : 읽을 섹터수 (보통 최대 0x7f까지만 허용)
04 [DWORD] : 데이터가 들어갈 Segment:Offset
08 [QWORD] : 접근할 LBA섹터번호
10h [QWORD] : 64bit 선형주소(일반 PC에서는 쓰는것은 못봤음. 구조체 크기가 10h일 경우 이 부분은 무효임) 

8G이상 영역을 BIOS로 접근한다면 반드시 이걸 써야합니다.

Written By the Black Knight of Destruction

kkojiband의 이미지

아...이게 확장 int 13h 군요...^^;

책엔 실린더 1024의 한계를 극복하기 위해 확장 int 13h 가 있다는 말만 있고 자세한 내용이 없었는데...

답변 해주신 분들 감사드립니다...^^

이제 졸업이다...사랑하는 SKKULUG 후배들아 안녕~

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.