보호 모드 진입시 재부팅되는 문제
휴.. 아무리 고민해봐도 여기밖에 질문할 곳이 없습니다.
예전에 게시판에 올라온 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
좀 의심스러운 부분이 있어서 한번 적어봅니다.
....
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 코드를 집어넣어 주는것이
훨씬 안정적이지 않나 생각됩니다.
잘 모르지만 저도 한번 부트 스트랩 코드를 만져볼까 생각중에 문득 적었습니다.
그리고 꼭 성공하세요
댓글 달기