当前位置: 代码迷 >> 汇编语言 >> 自己动手写操作系统中的有关问题
  详细解决方案

自己动手写操作系统中的有关问题

热度:6880   发布时间:2013-02-26 00:00:00.0
自己动手写操作系统中的问题
随书附带源代码用nasm编译时出现这样的错误:
nasm :fatal:assertion addr <=s->start failed at output/outbin.c:146
当时由于我自己写的代码,成功编译,也没有太过在意。可是当第二天我给自己写的代码加描述符特权级时,同样的问题出现了。
没有加特权级之前一切正常,编译显示都OK,但是在
selectordata equ LABEL_DESC_DATA -LABEL_GDT 这里+SA_RPL3之后显示了同样的错误。实在不明白怎么一回事!
下面是修改前的代码:
%include "pm.inc"
org 0100h
jmp LABEL_BEGIN
[SECTION .gdt]
LABEL_GDT: Descriptor 0, 0, 0
LABEL_DESC_LDT: Descriptor 0, LDTLEN-1, DA_LDT
LABEL_NORMAL: Descriptor 0, 0ffffh, DA_DRW
LABEL_DESC_CODE32: Descriptor 0, SEGCODE32LEN-1, DA_C+DA_32
LABEL_DESC_CODE16: Descriptor 0, 0ffffh, DA_C
LABEL_DESC_DATA: Descriptor 0, DATALEN-1, DA_DRW
LABEL_DESC_STACK: Descriptor 0, TOPOFSTACK, DA_DRWA+DA_32
LABEL_DESC_VIDEO: Descriptor 0B8000H, 0ffffh, DA_DRW
;GDT

gdtlen equ $-LABEL_GDT
gdtptr dw gdtlen-1
dd 0

selectorldt equ LABEL_DESC_LDT -LABEL_GDT
selectornomal equ LABEL_NORMAL -LABEL_GDT
selectorcode32 equ LABEL_DESC_CODE32 -LABEL_GDT
selectorcode16 equ LABEL_DESC_CODE16 -LABEL_GDT
selectordata equ LABEL_DESC_DATA -LABEL_GDT
selectorstack equ LABEL_DESC_STACK -LABEL_GDT
selectortest equ LABEL_DESC_TEST -LABEL_GDT
selectorvideo equ LABEL_DESC_VIDEO -LABEL_GDT
;GDT选择子

[SECTION .data1]
ALIGN 32
[BITS 32]
LABEL_DATA:
inreal_proctect dw 0
pmmassage: db "In Protect Mode now. ^-^",0
offsetpmmassage equ pmmassage - $$
strtest: db "ABCDEFGHIJKLMNOPQRSTUVWXYZ",0
offsetstrtest equ strtest - $$
DATALEN equ $ - LABEL_DATA

[SECTION .gs]
ALIGN 32 
[BITS 32]
LABEL_STACK:
times 512 db 0
TOPOFSTACK equ $ - LABEL_STACK - 1

[SECTION .s16]
[BITS 16]
LABEL_BEGIN:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax

mov sp,0100h

mov [back_real+3],ax
mov [inreal_proctect],sp

mov ax,cs
movzx eax,ax
shl eax,4
add eax,seg_code16
mov word[LABEL_DESC_CODE16+2],ax
shr eax,16
mov byte[LABEL_DESC_CODE16+4],al
mov byte[LABEL_DESC_CODE16+7],ah

xor eax,eax
mov ax,cs
shl eax,4
add eax,seg_code32
mov word[LABEL_DESC_CODE32+2],ax
shr eax,16
mov byte[LABEL_DESC_CODE32+4],al
mov byte[LABEL_DESC_CODE32+7],ah

xor eax,eax
mov ax,ds
shl eax,4
add eax,LABEL_DATA
mov word[LABEL_DESC_DATA+2],ax
shr eax,16
mov byte[LABEL_DESC_DATA+4],al
mov byte[LABEL_DESC_DATA+7],ah

xor eax,eax
mov ax,ds
shl eax,4
add eax,LABEL_STACK
mov word[LABEL_DESC_STACK+2],ax
shr eax,16
mov byte[LABEL_DESC_STACK+4],al
mov byte[LABEL_DESC_STACK+7],ah

xor eax,eax
mov ax,ds
shl eax,4
add eax,LABEL_LDT
mov word[LABEL_DESC_LDT+2],ax
shr eax,16
mov byte[LABEL_DESC_LDT+4],al
mov byte[LABEL_DESC_LDT+7],ah

xor eax,eax
mov ax,ds
shl eax,4
add eax,seg_ldt_codea
mov word[LABEL_LDT_DESC_CODEA+2],ax
shr eax,16
mov byte[LABEL_LDT_DESC_CODEA+4],al
mov byte[LABEL_LDT_DESC_CODEA+7],ah

xor eax,eax
mov ax,ds
shl eax,4
add eax,LABEL_GDT
mov dword[gdtptr+2],eax

lgdt [gdtptr]

cli

in al,92h
or al,00000010b
out 92h,al

mov eax,cr0
or eax,1
mov cr0,eax

jmp dword selectorcode32:0

back_inreal_proctect:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax

mov sp,[inreal_proctect]

in al,92h
and al,11111101b
out 92h,al

sti

mov ax,4c00h
int 21h

[SECTION .s32]
[BITS 32]
seg_code32:
mov ax,selectordata
mov ds,ax
mov ax,selectorstack
mov ss,ax

mov ax,selectorvideo
mov gs,ax
  相关解决方案