我发现一个非常奇怪的错误发生在我的程序的一个简单版本。我试图为操作系统添加不同的文件和缓冲区,但是当我尝试测试第5个文件时,我一直得到一个错误,运行第4个文件。为了尝试区分文件段,我有一个简单的print方法来显示字符串。现在文件被配置为显示不同的字符串,但我每次都得到相同的字符串。
我尝试一次调试一个文件,但是当我查看gdb段时,我在第四个文件中更改的内容仍然存在。唯一的其他事情,我可以做的是改变顺序的文件显示第一,但它总是不断取代第5个文件或把一个空的读取这种方式。
以下是我的资料来源,供参考
; ReTimerOS
; Copyright (C) 2022,2023 Christopher Hoy
;
; This file is part of ReTimerOS
; ReTimerOS is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
[org 0x7c00]
[bits 16]
mov cx,0
mov ds,cx
mov es,cx
cld
mov si,msgString
call kprint
mov bx,0x0000_9400
mov cl,5
mov bx,msgString
mov bx,0x0000_9400
mov cl,5
mov al,1
call read_section
mov cx,0x940
mov es,cx
mov bx,0
mov cl,5
mov al,1
call read_section
mov bx,0x0000_9200
mov cl,4
mov bx,msgString
mov bx,0x0000_9200
mov cl,4
mov al,1
call read_section
mov cx,0x920
mov es,cx
mov bx,0
mov cl,4
mov al,1
call read_section
mov bx,0x0000_9000
mov cl,3
mov bx,msgString
mov bx,0x0000_9000
mov cl,3
mov al,1
call read_section
mov cx,0x900
mov es,cx
mov bx,0
mov cl,3
mov al,1
call read_section
mov bx,0x0000_7e00
mov cl,2
mov bx,msgString
mov bx,0x0000_7e00
mov cl,2
mov al,1
call read_section
mov cx,0x7e0
mov es,cx
mov bx,0
mov cl,2
mov al,1
call read_section
mov bx,0x0000_7e00
pusha
;jmp 0x7e00
jmp 0x9200
;jmp 0x9400
;jmp 0x11000
jmp $
kprint:
cld
mov ah,0x0E
kstring:
lodsb
int 0x10
cmp al,0x00
jnz kstring
ret
read_section:
mov ah,0x02
; mov al,1
mov ch,0
mov dh,0
int 0x13
jc .disk_check
ret
.disk_check:
mov si,checkString
call kprint
jmp $
.done:
ret
;section .data
align 4
BOOT_DRIVE: db 0
msgString: db 'Game platform premier',10,13,0
checkString: db 'Section did not load',10,13,0
checkString2: db 'disk complete',10,13,0
times 510 -($-$$) db 0
dw 0xaa55
stage1.asm
; ReTimerOS
; Copyright (C) 2022,2023 Christopher Hoy
;
; This file is part of ReTimerOS
; ReTimerOS is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
;%define REBASE_ADDRESS(A) (0x7E00 + ((A) - protectedGate1))
%define BUILD_GDT_DESC(bounds,base,access,flags) \
((( base & 0x00FFFFFF) << 16) | \
(( base & 0xFF000000) << 32) | \
( bounds & 0x0000FFFF) | \
(( bounds & 0x000F0000) << 32) | \
(( access & 0xFF) << 40) | \
(( flags & 0x0F) << 52))
[ORG 0x7E00]
[BITS 16]
;section .text
protectedGate1:
;mov bx,0x0000_9000
mov si,String
call kprint
; jmp $
; jmp 0x9000
; jmp 0x11000
cld
cli
in al,0x92
or al,2
out 0x92,al
lgdt[gdt32Ptr]
lidt[IdtPipe]
mov eax, cr0
or eax,1
mov cr0, eax
; mov [saved_segment],ds
; jmp code32_post:REBASE_ADDRESS(__protected_mode_32)
jmp code32_post:__protected_mode_32
; jmp $
; jmp code32_post:__protected_mode_32
kprint:
cld
mov ah,0x0E
kstring:
lodsb
int 0x10
cmp al,0x00
jnz kstring
ret
;section .text
[bits 32]
; 32 bit protected mode
__protected_mode_32:use32
; mov ax, 0x10
mov ax,data32_post
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; mov ss, ax
; restate cr3
mov cr3, ebx
; restate esp
mov esp, edx
mov cx,[gate_voucher]
cmp word [gate_voucher],0
jnz loopcheck
mov word [gate_voucher],1
jmp BIOS32_PREP
loopcheck:
hlt
jmp loopcheck
; jmp 0x8000
BIOS32_PREP:use32
pusha
mov edx, esp
cli
; clear cr3 by saving cr3 data in ebx register
xor ecx, ecx
mov ebx, cr3
mov cr3, ecx
jmp code16_post:__protected_mode_16
[bits 16]
; 16 bit protected mode
__protected_mode_16:use16
; jumping to 16 bit real mode
xor eax,eax
xor ecx,ecx
; mov ax, 0x38
mov cx,data16_post
mov ds, cx
mov es, cx
mov fs, cx
mov gs, cx
mov ss, cx
; turn off protected mode
; set bit 0 to 0
mov eax, cr0
and al, ~0x01
mov cr0, eax
jmp 0x9000
;section .data
String: db 'platform 2',10,13,0
checkString: db 'check',10,13,0
gdt32:
dq BUILD_GDT_DESC(0,0,0,0)
gdt32code:
dq BUILD_GDT_DESC(0x0000ffff,0,10011010b,1100b)
gdt32data:
dq BUILD_GDT_DESC(0x0000ffff,0,10010010b,1100b)
gdt16code:
dq BUILD_GDT_DESC(0x0000ffff,0,10011010b,1000b)
gdt16data:
dq BUILD_GDT_DESC(0x0000ffff,0,10010010b,1000b)
.stub1:
code32_post: equ gdt32code -gdt32
data32_post: equ gdt32data -gdt32
;.stub:
code16_post: equ gdt16code -gdt32
data16_post: equ gdt16data -gdt32
; tss32_post: equ gdt32tss -gdt32
gdt32Len: equ $-gdt32
gdt32Ptr: dw gdt32Len-1
dd gdt32
save_cr0 dd 0
save_cr3 dd 0
saved_segment resd 0
gate_voucher dw 0
saved_stack resw 0
IdtPipe:
dw 0x03ff
dd 0
times 512-($-$$) db 0
;%include 'gdt.inc'
stage3.asm
;[org 0x9200]
[BITS 16]
;section .text
; ReTimerOS
; Copyright (C) 2022,2023 Christopher Hoy
;
; This file is part of ReTimerOS
; ReTimerOS is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
%define REBASE_ADDRESS(A) (0x9000 + ((A) - BIOS32_PREP))
%define BUILD_GDT_DESC(bounds,base,access,flags) \
((( base & 0x00FFFFFF) << 16) | \
(( base & 0xFF000000) << 32) | \
( bounds & 0x0000FFFF) | \
(( bounds & 0x000F0000) << 32) | \
(( access & 0xFF) << 40) | \
(( flags & 0x0F) << 52))
;[org 0xA000]
[bits 32]
BIOS32_PREP:use32
pusha
;pushf
; save current esp to edx
mov edx, esp
; jumping to 16 bit protected mode
; disable interrupts
cli
; clear cr3 by saving cr3 data in ebx register
xor ecx, ecx
mov ebx, cr3
mov cr3, ecx
jmp code16_post:REBASE_ADDRESS(__protected_mode_16)
; jmp code16_post:__protected_mode_16
[bits 16]
; 16 bit protected mode
__protected_mode_16:use16
; jumping to 16 bit real mode
xor eax,eax
xor ecx,ecx
; mov ax, 0x38
mov cx,data16_post
; mov ax,0
mov ds, cx
mov es, cx
mov fs, cx
mov gs, cx
mov ss, cx
; turn off protected mode
; set bit 0 to 0
mov eax, cr0
and al, ~0x01
mov cr0, eax
jmp 0x0:REBASE_ADDRESS(__real_mode_16)
__real_mode_16:use16
xor cx, cx
mov ds, cx
mov es, cx
mov fs, cx
mov gs, cx
mov ss, cx
; mov sp, 0x8c00
mov sp, 0x6c00
; enable bios interrupts to call
sti
; save current context, all general, segment registers, flags
pusha
mov cx, ss
push cx
mov cx, gs
push cx
mov cx, fs
push cx
mov cx, es
push cx
mov cx, ds
push cx
pushf
; get current stack pointer & save it to current_esp
mov ax, sp
; mov edi, current_esp
mov di, current_esp
; mov di, far 0001_0000:current_esp
;push ds
; mov eax,0x00010000
; mov ds,eax
; mov edi, current_esp
;pop ds
stosw
; load our custom registers context
mov esp, REBASE_ADDRESS(bios32_in_reg16_ptr)
; mov sp, REBASE_ADDRESS(bios32_in_reg16_ptr)
; only use some general register from the given context
popa
; set a new stack for bios interrupt
; mov sp, 0x9c00
mov sp, 0x7c00
; call immediate interrupt opcode to execute context
pusha
; mov bp,sp
; jmp bios32_GraphicCtrlA
; jmp 0x7e00
; jmp 0x9200
jmp 0x9400
; jmp 0xD000
; jmp 0x10000
; mov cx,0x1000
; mov es,cx
; mov ds,cx
; jmp 0:ds
; mov ebp,0x00010000
; push ebp
; push 0x10000
; retw
poll_function:
; mov si,page_str1
popa
; get our output context here
mov esp, REBASE_ADDRESS(bios32_out_reg16_ptr)
add sp, 28 ; restore stack used for calling our context
; save current context, all general, segment registers, flags
pushf
mov cx, ss
push cx
mov cx, gs
push cx
mov cx, fs
push cx
mov cx, es
push cx
mov cx, ds
push cx
pusha
; restate the current_esp to continue
mov esi, current_esp
; mov si, current_esp
lodsw
mov sp, ax
; restore all current context, all general, segment registers, flags
popf
pop cx
mov ds, cx
pop cx
mov es, cx
pop cx
mov fs, cx
pop cx
mov gs, cx
pop cx
mov ss, cx
popa
;[bits 16]
protectedGate2:use16
cld
cli
in al,0x92
or al,2
out 0x92,al
lgdt[gdt32Ptr]
lidt[IdtPipe]
mov eax, cr0
or eax,1
mov cr0, eax
jmp code32_post:0x0000_7e00
; jmp code32_post:0x0000_9200
bios32_in_reg16_ptr:
resw 14
bios32_out_reg16_ptr:
dd 0xaaaaaaaa
dd 0xaaaaaaaa
dd 0xaaaaaaaa
dd 0xaaaaaaaa
dd 0xaaaaaaaa
dd 0xaaaaaaaa
dd 0xaaaaaaaa
current_esp: dw 0x0000
gdt32:
dq BUILD_GDT_DESC(0,0,0,0)
gdt32code:
dq BUILD_GDT_DESC(0x0000ffff,0,10011010b,1100b)
gdt32data:
dq BUILD_GDT_DESC(0x0000ffff,0,10010010b,1100b)
gdt16code:
dq BUILD_GDT_DESC(0x0000ffff,0,10011010b,1000b)
gdt16data:
dq BUILD_GDT_DESC(0x0000ffff,0,10010010b,1000b)
.stub1:
code32_post: equ gdt32code -gdt32
data32_post: equ gdt32data -gdt32
;.stub:
code16_post: equ gdt16code -gdt32
data16_post: equ gdt16data -gdt32
; tss32_post: equ gdt32tss -gdt32
gdt32Len: equ $-gdt32
gdt32Ptr: dw gdt32Len-1
dd gdt32
IdtPipe:
dw 0x03ff
dd 0
times 512-($-$$) db 0
stage4.asm
;[org 0x9000]
[BITS 16]
;section .text
prep_module2:
; jmp 0xD000
; jmp 0x9400
vm_module:
sub dword [vidmem_ptr],VIDEO_TEXT_ADDR
mov si,String
call printstr_task
loopcheck: jmp $
printstr_task:
push cx
mov bp,0b800h
mov es,bp
mov bp,[vidmem_ptr]
prep:
mov cx,0
mov es,cx
mov ax,ROWS
mov bx,es:0x044a
mul bx
add ax,COLS1
; shl ax,1
mov bp,ax
add bp,[vidmem_ptr]
;check even and odd placements
; wizard tests 1.7
add bp,0x690
times 20 inc bp
;bodary
;check even and odd placements
mov cx,0b800H
mov es,cx
mov ch,COLOR_ATTR_BSC
jmp gettext
output:
; pop word vidmem_address
pop ax
mov dx,ax
mov es:[bp],dx
add bp,byte 2
gettext:
mov cl,byte [ds:si]
inc si
; mov [vidmem_address],cx
push cx
test cl,cl
jnz output
mov [vidmem_ptr],bp
pop word [bp]
pop ax
mov cx,0
mov ds,cx
ret
jmp $
;dw 0xaa55
;section .data
VIDEO_TEXT_ADDR EQU 0XB8000
COLOR_ATTR_PSC EQU 0X6A
COLOR_ATTR_BSC EQU 0X5F
PM_MODE_STACK EQU 0X80000
VM_STACK_SEG EQU 0X0000
VM_STACK_OFS EQU 0X0000
VM_CS_SEG EQU 0X0000
FLAGS_VM_CMP EQU 17
FLAGS_CMP1 EQU 1
FLAGS_CMP_IF EQU 9
RING0_PROC_STACK_SIZE EQU 2048
;TSS_IO_MAP_SIZE EQU 0
TSS_IO_MAP_SIZE EQU 0x400/8
;VM_STACK_ADDRESS EQU vidmem_address
ROWS EQU 25
COLS1 EQU 80
BACK1 EQU 05h
FRONT1 EQU 12h
CHECKER EQU 0
align 4
vidmem_ptr: dd VIDEO_TEXT_ADDR
pm_str: db 'protected mode string ',0
pm_str_length: equ $-pm_str
vm_str: db 'virtual',0
;vidmem_address: dw 0
String: db 'Check',0
;times 512-($-$$) db 0
test_1.asm
;[org 0x9000]
[BITS 16]
;section .text
prep_module2:
; jmp 0xD000
; jmp 0x9400
vm_module:
sub dword [vidmem_ptr],VIDEO_TEXT_ADDR
mov si,vm_str
call printstr_task
loopcheck: jmp $
printstr_task:
push cx
mov bp,0b800h
mov es,bp
mov bp,[vidmem_ptr]
prep:
mov cx,0
mov es,cx
mov ax,ROWS
mov bx,es:0x044a
mul bx
add ax,COLS1
; shl ax,1
mov bp,ax
add bp,[vidmem_ptr]
;check even and odd placements
; wizard tests 1.7
add bp,0x690
times 20 inc bp
;bodary
;check even and odd placements
mov cx,0b800H
mov es,cx
mov ch,COLOR_ATTR_BSC
jmp gettext
output:
; pop word vidmem_address
pop ax
mov dx,ax
mov es:[bp],dx
add bp,byte 2
gettext:
mov cl,byte [ds:si]
inc si
; mov [vidmem_address],cx
push cx
test cl,cl
jnz output
mov [vidmem_ptr],bp
pop word [bp]
pop ax
mov cx,0
mov ds,cx
ret
jmp $
;dw 0xaa55
;section .data
VIDEO_TEXT_ADDR EQU 0XB8000
COLOR_ATTR_PSC EQU 0X6A
COLOR_ATTR_BSC EQU 0X5F
PM_MODE_STACK EQU 0X80000
VM_STACK_SEG EQU 0X0000
VM_STACK_OFS EQU 0X0000
VM_CS_SEG EQU 0X0000
FLAGS_VM_CMP EQU 17
FLAGS_CMP1 EQU 1
FLAGS_CMP_IF EQU 9
RING0_PROC_STACK_SIZE EQU 2048
;TSS_IO_MAP_SIZE EQU 0
TSS_IO_MAP_SIZE EQU 0x400/8
;VM_STACK_ADDRESS EQU vidmem_address
ROWS EQU 25
COLS1 EQU 80
BACK1 EQU 05h
FRONT1 EQU 12h
CHECKER EQU 0
align 4
vidmem_ptr: dd VIDEO_TEXT_ADDR
pm_str: db 'protected mode string ',0
pm_str_length: equ $-pm_str
vm_str: db 'virtual',0
;vidmem_address: dw 0
String: db 'Check',0
;times 512-($-$$) db 0
run.sh
nasm -f bin boot.asm -o boot.bin
nasm -f bin stage1.asm -o stage1.bin
nasm -f elf stage3.asm -o stage3_2.o
ld -g -m elf_i386 -Ttext 0x9000 stage3_2.o -o stage3_2.bin --oformat binary
nasm -f elf stage4.asm -o stage4_2.o
ld -g -m elf_i386 -Ttext 0x9200 stage4_2.o -o stage4_2.bin --oformat binary
nasm -f elf test_1.asm -o test_1.o
ld -g -m elf_i386 -Ttext 0x9400 test_1.o -o test_1.bin --oformat binary
dd if=/dev/zero of=os.bin bs=512 count=2875
cat boot.bin \
stage1.bin \
stage3_2.bin\
stage4_2.bin\
test_1.bin \
os.bin>os.img
rm -rf *\.bin
qemu-system-i386 -hda os.img
下面是我的gdb配置config1文件
define settings1
add-symbol-file boot.o 0x7c00
target remote | qemu-system-i386 -S -hda os.bin -gdb stdio
end
define build1
add-symbol-file boot.o 0x7c00 \
y
end
define build2
target remote | qemu-system-i386 -S -fda os.img -gdb stdio
end
gdb命令
source -s -v config1
build2
b *0x9200
stepi
1条答案
按热度按时间rseugnpd1#
我不确定的部分,但我发现我已经检查了填充命令,完全改变了顺序。包括后面的
应该恢复节目的顺序。现在我正在研究ld链接文件,希望使这个变化更容易。