보호 모드 진입시 재부팅되는 문제

gurugio의 이미지

휴.. 아무리 고민해봐도 여기밖에 질문할 곳이 없습니다.

예전에 게시판에 올라온 nasm 소스들을 as로 바꾼건데도

재부팅 돼버립니다.

제가 잘못한 곳 지적해 주시면 감사하겠습니다.

처음에 A20 line 을 활성화해주고 바로 보호 모드로 진입하는 소스입니다.

.code16
.text

.global _start
_start
START_SETUP
# set data segment
movw %cs, %ax
movw %ax, %ds
movw %ax, %es

cli
call ACTIVATE_A20

# set IDT to null
lidt stIDTR

lgdt stGDTR # set gdtr

# set protected mode field in control-register 0
movl %cr0, %eax
orl $0x1, %eax
movl %eax, %cr0

ljmp $0x10, $OK_PMODE

# activate A20 line
ACTIVATE_A20
pushw %ax

ACTIVATE_A20_UPPER
inb $0x64, %al
testb $0x2, %al
jnz ACTIVATE_A20_UPPER
movb $0xd1, %al
outb %al, $0x64

ACTIVATE_A20_BOTTOM
inb $0x64, %al
testb $2, %al
jnz ACTIVATE_A20_BOTTOM
movb $0xdf, %al
outb %al, $0x60

popw %ax
ret

.code32
OK_PMODE
# selector 0x10 => 0001 0000 => index=00010(=0x2), TI=0, RPL=00
# It select OS data segment.
movw $OSDATA, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
movw %ax, %ss

# print test value
movl $0xb8000, %esi
movl $'P', (%esi)

sti

END_SETUP
jmp END_SETUP

.org 512

stGDT
.word 0x0, 0x0, 0x0, 0x0 # NULL descriptor

.word 0xffff, 0x0, 0x9a00, 0xcf # OS code descriptor
.word 0xffff, 0x0, 0x9200, 0xcf # OS data descriptor

.word 0x0, 0x0, 0x0, 0x0 # dummy

.word 0xffff, 0x0, 0xfa00, 0xcf # USER code descriptor
.word 0xffff, 0x0, 0xf200, 0xcf # USER data descriptor

stGDTR
.word 0x1000
.long 0x90400 # set later

stIDTR
.word 0x1000
.long 0x91400 # set later


.org 1024

kuyzer의 이미지

....

lgdt stGDTR # set gdtr

# set protected mode field in control-register 0
movl %cr0, %eax
orl $0x1, %eax
movl %eax, %cr0

ljmp $0x10, $OK_PMODE <-------- 좀 의심스러운 부분이 아닌지...

# activate A20 line
ACTIVATE_A20
pushw %ax

...

stGDT
.word 0x0, 0x0, 0x0, 0x0 # NULL descriptor

.word 0xffff, 0x0, 0x9a00, 0xcf # OS code descriptor
.word 0xffff, 0x0, 0x9200, 0xcf # OS data descriptor

.word 0x0, 0x0, 0x0, 0x0 # dummy

.word 0xffff, 0x0, 0xfa00, 0xcf # USER code descriptor
.word 0xffff, 0x0, 0xf200, 0xcf # USER data descriptor

...

죄송하지만 왕초보인지라.... ^^;;;
역시 AT&T부분은 하나도 모르겠다는... --;

작성하신 부분의 소스중에서 디스크립터 테이블에는 0x8번지가 code segment 디스크립터로
설정이 되어있는것 같은데.

위의 ljmp 부분에서는 0x10:OK_PMODE 부분으로 점프를 시켜주신것 같습니다.

그리고 CPU에서는 실행시키기 전에 항상 예비코드를 읽어주는 것 같습니다.
그러니 ljmp 부분의 바로 윗부분에 근거리 점프와 not operation 코드를 집어넣어 주는것이
훨씬 안정적이지 않나 생각됩니다.

잘 모르지만 저도 한번 부트 스트랩 코드를 만져볼까 생각중에 문득 적었습니다.

그리고 꼭 성공하세요

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.