- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 osdev 新手,正在尝试从头开始制作引导加载程序。我目前正在尝试执行第二阶段。这是我的主要引导加载程序代码
bits 16
org 0x7c00
mov [BOOT_DRIVE], dl
xor ax, ax
mov es, ax
mov ds, ax
mov ss, ax
mov sp, 0x7c00
mov bp, sp
cld
mov bx, boot_msg
call print
mov dx, [0x9000]
call print_hex
mov bx, 0x9000
mov dh, 2
mov dl, [BOOT_DRIVE]
call load_disk
mov dx, [0x9000]
call print_hex
jmp 0x9000
jmp $
boot_msg db "Booting cornoS", 0
%include "print.asm"
%include "print_hex.asm"
%include "load_disk.asm"
BOOT_DRIVE db 0
times 510-($-$$) db 0
dw 0xaa55
这是我的引导加载程序第二阶段的代码:
dw 0xface
stage2:
mov ax, cs
mov ds, ax
mov es, ax
sti
mov bx, stage2_called
call print
call enable_a20
jmp $
%include "a20.asm"
;%include "print.asm"
stage2_called db "Stage two successfully called!", 0
最后这是我读取磁盘的代码:
load_disk:
pusha
push dx
mov ah, 0x02
mov al, dh
mov ch, 0x00
mov cl, 0x02
mov dh, 0x00
int 0x13
jc disk_error
pop dx
cmp al, dh
jne sectors_error
mov bx, read_disk_success
call print
popa
ret
disk_error:
mov bx, read_disk_failed
call print
mov dh, ah
call print_hex
jmp $
sectors_error:
mov bx, incorrect_sectors
call print
jmp $
read_disk_success db "Successfully read disk!", 0
read_disk_failed db "Failed to read disk", 0
incorrect_sectors db "Incorrect number of sectors read", 0
最后我编译并运行:
nasm -f bin -o boot.bin boot.asm
nasm -f elf32 -o stage2.o stage2.asm
ld -melf_i386 -Ttext=0x9000 -nostdlib --nmagic -o stage2.elf stage2.o
objcopy -O binary stage2.elf stage2.bin
dd if=/dev/zero of=corn.img bs=512 count=2880
dd if=boot.bin of=corn.img bs=512 conv=notrunc
dd if=stage2.bin of=corn.img bs=512 seek=1 conv=notrunc
qemu-system-i386 -fda corn.img
第二个 print_hex 输出 0xface 但当我跳转到 0x9000 时什么也没有发生。我尝试过 jmp 0x0000:0x9000 并得到相同的结果。我真的不知道发生了什么。
注意:print.asm 不包含在 stage2.asm 中,因为 a20.asm 已包含 print
最佳答案
这个问题不是一个最小的完整的可验证示例。我必须即兴创作并填补一些空白并清理问题。
值得注意的问题:
gdt.asm
、switch_pm.asm
和 32print_pm.asm
。下面的代码使用这些文件进入保护模式并使用 32 位 print_string_pm
函数进行打印。在保护模式下打印无法使用 BIOS。您的第 2 阶段实际上需要 16 位实模式部分和 32 位保护模式部分。 print
和 print_string
的组合。我已将其全部修改并保持与 print_string
一致。 0xface
。您需要跳到它之外的 2 个字节,以避免将签名作为代码执行。您还依赖于将其复制到 DS 和 ES 时设置的 CS。您需要确保首先设置CS。您可以使用 0x0000:0x9002 纠正 FAR JMP。这会将 CS 设置为 0x0000,将 IP 设置为 0x9002。修改后的代码可能如下所示:
boot.asm:
bits 16
org 0x7c00
xor ax, ax
mov es, ax
mov ds, ax
mov ss, ax
mov sp, 0x7c00
mov bp, sp
mov [BOOT_DRIVE], dl ; Save the boot drive after setting DS, not before
cld
mov bx, boot_msg
call print_string
mov dx, [0x9000]
call print_hex
mov bx, 0x9000
mov dh, 2
mov dl, [BOOT_DRIVE]
call load_disk
mov dx, [0x9000]
call print_hex
jmp 0x0000:0x9002 ; FAR JMP to second stage that sets CS to 0x0000
; We use 9002 since the first 2 bytes are the stage2 sig
boot_msg db "Booting cornoS", 0
%include "print.asm"
%include "print_hex.asm"
%include "load_disk.asm"
BOOT_DRIVE db 0
times 510-($-$$) db 0
dw 0xaa55
stage2.asm:
bits 16
dw 0xface
stage2:
; Still in 16-bit realmode at this point
mov ax, cs
mov ds, ax
mov es, ax
mov bx, stage2_called
call print_string
; Enter protected mode
; Should check for A20 being enabled before enabling it
; For the original poster to clean up
call enable_a20
call switch_to_pm
%include "print.asm"
%include "a20.asm"
%include "switch_pm.asm"
%include "gdt.asm"
bits 32
BEGIN_PM:
mov ebx, stage2_in_pm
call print_string_pm
jmp $
%include "32print_pm.asm"
stage2_called db "Stage two successfully called!", 0
stage2_in_pm db "In protected mode!", 0
load_disk.asm:
load_disk:
pusha
push dx
mov ah, 0x02
mov al, dh
mov ch, 0x00
mov cl, 0x02
mov dh, 0x00
int 0x13
jc disk_error
pop dx
cmp al, dh
jne sectors_error
mov bx, read_disk_success
call print_string
popa
ret
disk_error:
mov bx, read_disk_failed
call print_string
mov dh, ah
call print_hex
jmp $
sectors_error:
mov bx, incorrect_sectors
call print_string
jmp $
read_disk_success db "Successfully read disk!", 0
read_disk_failed db "Failed to read disk", 0
incorrect_sectors db "Incorrect number of sectors read", 0
打印.asm:
print_string:
pusha
; keep this in mind:
; while (string[i] != 0) { print string[i]; i++ }
; the comparison for string end (null byte)
start:
mov al, [bx] ; 'bx' is the base address for the string
cmp al, 0
je done
; the part where we print with the BIOS help
mov ah, 0x0e
int 0x10 ; 'al' already contains the char
; increment pointer and do next loop
add bx, 1
jmp start
done:
popa
ret
print_nl:
pusha
mov ah, 0x0e
mov al, 0x0a ; newline char
int 0x10
mov al, 0x0d ; carriage return
int 0x10
popa
ret
print_hex.asm:
print_hex:
; manipulate chars at HEX_OUT to reflect DX
mov cx, dx
and cx, 0xf000
shr cx, 12
call to_char
mov [HEX_OUT + 2], cx
mov cx, dx
and cx, 0x0f00
shr cx, 8
call to_char
mov [HEX_OUT + 3], cx
mov cx, dx
and cx, 0x00f0
shr cx, 4
call to_char
mov [HEX_OUT + 4], cx
mov cx, dx
and cx, 0x000f
call to_char
mov [HEX_OUT + 5], cx
mov bx, HEX_OUT
call print_string
mov byte [HEX_OUT + 2], '0'
mov byte [HEX_OUT + 3], '0'
mov byte [HEX_OUT + 4], '0'
mov byte [HEX_OUT + 5], '0'
ret
to_char:
cmp cx, 0xa
jl digits
sub cx, 0xa
add cx, 'a'
ret
digits:
add cx, '0'
ret
HEX_OUT: db '0x0000', 0
a20.asm:
;;
;; NASM 32bit assembler
;;
;; From OSDev Wiki
enable_a20:
cli
call a20wait
mov al,0xAD
out 0x64,al
call a20wait
mov al,0xD0
out 0x64,al
call a20wait2
in al,0x60
push eax
call a20wait
mov al,0xD1
out 0x64,al
call a20wait
pop eax
or al,2
out 0x60,al
call a20wait
mov al,0xAE
out 0x64,al
call a20wait
sti
ret
a20wait:
in al,0x64
test al,2
jnz a20wait
ret
a20wait2:
in al,0x64
test al,1
jz a20wait2
ret
gdt.asm:
gdt_start: ; don't remove the labels, they're needed to compute sizes and jumps
; the GDT starts with a null 8-byte
dd 0x0 ; 4 byte
dd 0x0 ; 4 byte
; GDT for code segment. base = 0x00000000, length = 0xfffff
; for flags, refer to os-dev.pdf document, page 36
gdt_code:
dw 0xffff ; segment length, bits 0-15
dw 0x0 ; segment base, bits 0-15
db 0x0 ; segment base, bits 16-23
db 10011010b ; flags (8 bits)
db 11001111b ; flags (4 bits) + segment length, bits 16-19
db 0x0 ; segment base, bits 24-31
; GDT for data segment. base and length identical to code segment
; some flags changed, again, refer to os-dev.pdf
gdt_data:
dw 0xffff
dw 0x0
db 0x0
db 10010010b
db 11001111b
db 0x0
gdt_end:
; GDT descriptor
gdt_descriptor:
dw gdt_end - gdt_start - 1 ; size (16 bit), always one less of its true size
dd gdt_start ; address (32 bit)
; define some constants for later use
CODE_SEG equ gdt_code - gdt_start
DATA_SEG equ gdt_data - gdt_start
switch_pm.asm:
[bits 16]
switch_to_pm:
cli ; 1. disable interrupts
lgdt [gdt_descriptor] ; 2. load the GDT descriptor
mov eax, cr0
or eax, 0x1 ; 3. set 32-bit mode bit in cr0
mov cr0, eax
jmp CODE_SEG:init_pm ; 4. far jump by using a different segment
[bits 32]
init_pm: ; we are now using 32-bit instructions
mov ax, DATA_SEG ; 5. update the segment registers
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000 ; 6. update the stack right at the top of the free space
mov esp, ebp
call BEGIN_PM ; 7. Call a well-known label with useful code
32print_pm.asm:
[bits 32] ; using 32-bit protected mode
; this is how constants are defined
VIDEO_MEMORY equ 0xb8000
WHITE_OB_BLACK equ 0x0f ; the color byte for each character
print_string_pm:
pusha
mov edx, VIDEO_MEMORY
print_string_pm_loop:
mov al, [ebx] ; [ebx] is the address of our character
mov ah, WHITE_OB_BLACK
cmp al, 0 ; check if end of string
je print_string_pm_done
mov [edx], ax ; store character + attribute in video memory
add ebx, 1 ; next char
add edx, 2 ; next video memory position
jmp print_string_pm_loop
print_string_pm_done:
popa
ret
您可以使用之前使用过的相同命令来构建磁盘镜像:
nasm -f bin -o boot.bin boot.asm
nasm -f elf32 -o stage2.o stage2.asm
ld -melf_i386 -Ttext=0x9000 -nostdlib --nmagic -o stage2.elf stage2.o
objcopy -O binary stage2.elf stage2.bin
dd if=/dev/zero of=corn.img bs=512 count=2880
dd if=boot.bin of=corn.img bs=512 conv=notrunc
dd if=stage2.bin of=corn.img bs=512 seek=1 conv=notrunc
qemu-system-i386 -fda corn.img
输出应类似于:
<小时/>大多数教程中的通用 print_string_pm
从屏幕左上角开始打印,非常基础。我为更高级的 print_string_pm
函数编写了一些示例代码:
call update_screen_state_from_bios
一次32print_pm.asm:
bits 32
VIDEO_TEXT_ADDR EQU 0xb8000 ; Hard code beginning of text video memory
CR EQU 0x0d ; Carriage return
LF EQU 0x0a ; Line feed
BS EQU 0x08 ; Back space
TAB EQU 0x09 ; Tab
; Function: update_screen_info_from_bios
; set the hardware cursor position based on the
; current column (cur_col) and current row (cur_row) coordinates
;
; Inputs: None
; Clobbers: EAX
; Returns: None
update_screen_state_from_bios:
xor eax, eax ; Clear EAX for the instructions below
mov al, [0x450] ; Byte at address 0x450 = last BIOS column position
mov [cur_col], eax ; Copy to current column
mov al, [0x451] ; Byte at address 0x451 = last BIOS row position
mov [cur_row], eax ; Copy to current row
mov al, [0x484] ; Word at address 0x484 = # of rows-1 (screen height)
mov [screen_height],eax ; Copy to screen height
mov ax, [0x44a] ; Word at address 0x44a = # of columns (screen width)
mov [screen_width], eax ; Copy to screen width
ret
; Function: set_cursor
; set the hardware cursor position based on the
; current column (cur_col) and current row (cur_row) coordinates
; See: https://wiki.osdev.org/Text_Mode_Cursor#Moving_the_Cursor_2
;
; Inputs: None
; Clobbers: EAX, ECX, EDX
; Returns: None
set_cursor:
mov ecx, [cur_row] ; EAX = cur_row
imul ecx, [screen_width] ; ECX = cur_row * screen_width
add ecx, [cur_col] ; ECX = cur_row * screen_width + cur_col
; Send low byte of cursor position to video card
mov edx, 0x3d4
mov al, 0x0f
out dx, al ; Output 0x0f to 0x3d4
inc edx
mov al, cl
out dx, al ; Output lower byte of cursor pos to 0x3d5
; Send high byte of cursor position to video card
dec edx
mov al, 0x0e
out dx, al ; Output 0x0e to 0x3d4
inc edx
mov al, ch
out dx, al ; Output higher byte of cursor pos to 0x3d5
ret
; Function: print_string_pm
; Display a string to the console on display page 0 in protected mode.
; Handles carriage return, line feed, and backspace. Tab characters
; are not processed. Scrolling and wrapping are supported.
; Backspacing beyond the first line does nothing.
;
; Inputs: ESI = Offset of address to print
; AH = Attribute of string to print
; AL = Attribute to use when filling bottom line during down scrolling
; Clobbers: ECX, EDX
; Returns: None
print_string_pm:
push edi
push esi
push eax
push ebx
push ebp
; Assume base of text video memory is ALWAYS 0xb8000
mov ebx, VIDEO_TEXT_ADDR ; EBX = beginning of video memory
mov cl, al ; CL = attribute to use for clearing while scrolling
call .init ; Initialize register state for use while printing
jmp .getch
.repeat:
cmp al, CR ; Is the character a carriage return?
jne .chk_lf ; If not skip and check for line feed
lea edi, [ebx + edx * 2] ; Set current video memory pointer to beginning of line
mov dword [cur_col], 0 ; Set current column to 0
xor al, al ; AL = 0 = Don't print character
jmp .chk_bounds ; Check screen bounds
.chk_lf:
; Process line feed
cmp al, LF ; Is the character a line feed?
jne .chk_bs ; If not check for backspace
mov ebp, [screen_width]
lea edi, [edi + ebp * 2] ; Set current video memory ptr to same pos on next line
inc dword [cur_row] ; Set current row to next line
xor al, al ; AL = 0 = Don't print character
jmp .chk_bounds ; Check screen bounds
.chk_bs:
; Process back space
cmp al, BS ; Is the character a Back space?
jne .chk_tab ; If not check for tab
cmp edi, ebx
je .getch ; If at beginning of display, ignore and get next char
dec dword [cur_col] ; Set current column to previous column
jmp .chk_bounds ; Check screen bounds
; Process tab - ignore character
.chk_tab:
cmp al, TAB ; Is the character a Tab?
je .getch ; If it is, skip and get next character
; Check row and column boundaries and clip them if necessary
; If we exceed the number of rows on display,scroll down by a line
.chk_bounds:
mov ebp, [screen_width] ; EAX=screen width
cmp [cur_col], ebp ; Have we reached edge of display?
jl .chk_col_start ; If not - continue by checking for beginning of line
mov dword [cur_col], 0 ; Reset current column to beginning of line
inc dword [cur_row] ; Advance to the next row
jmp .chk_rows ; Check number of rows in bounds
.chk_col_start:
cmp dword [cur_col], 0 ; Check if beginning of line
jge .chk_rows ; If not negative (beginning of line) check row bounds
mov dword [cur_col], 0 ; Set column to 0
.chk_rows:
mov ebp, [screen_height] ; EAX=screen width
cmp [cur_row], ebp ; Have we reached edge of display?
jle .test_char ; If not then continue by updating display
dec dword [cur_row] ; Back one row since we will be scrolling down a line
call .scroll_down_one_line ; Scroll display down by a line
call .init ; Reinitialize register state after scroll
; Display character to video memory at current location if not a NUL character
.test_char:
test al, al ; Is the character 0?
jz .getch ; If it is we are finished, get next character
cmp al, BS ; Is the character a Back space?
jne .not_bs ; If not back space print char and advance cursor
mov al, ' '
sub edi, 2 ; Go back one cell in video memory
mov [es:edi], al ; Print a space to clear previous character
jmp .getch ; Don't advance cursor and get next character
.not_bs:
stosw ; Update current character at current location
inc dword [cur_col] ; Advance the current column by 1 position
; Get next character from string parameter
.getch:
lodsb ; Get character from string
test al, al ; Have we reached end of string?
jnz .repeat ; if not process next character
.end:
call set_cursor ; Update hardware cursor position
pop ebp
pop ebx
pop eax
pop esi
pop edi
ret
; Function: print_string_pm.scroll_down_one_line
; Internal function of print_string_pm to scroll the display down
; by a single line. The top line is lost and the bottom line is
; filled with spaces.
;
; Inputs: EBX = Base address of video page
; AH = Attribute to use when clearing last line
; Clobbers: None
; Returns: None, display updated
.scroll_down_one_line:
pusha
mov ebp, [screen_height] ; EBP = (num_rows-1)
mov eax, [screen_width] ; EAX = screen_width
lea esi, [ebx + eax * 2] ; ESI = pointer to second line on screen
mov edi, ebx ; EDI = pointer to first line on screen
mul ebp ; EAX = screen_width * (num_rows-1)
mov ecx, eax ; ECX = number of screen cells to copy
rep movsw
lea edi, [ebx + eax * 2] ; Destination offset =
; last row = screen_width * (num_rows-1)
mov ecx, [screen_width] ; Update a rows worth of word cells
mov ah, cl
mov al, ' ' ; Use a space character with current background attribute
rep stosw ; to clear the last line.
popa
ret
; Function: print_string_pm.init
; Internal function of print_string_pm to compute the video memory
; address of the current cursor location and the address to the
; beginning of the current line
;
; Inputs: EBX = Base address of video page
; Returns: EDI = Current video memory offset of cursor
; EDX = Video memory offset to beginning of line
; Clobbers: None
.init:
push eax
mov eax, [cur_row] ; EAX = cur_row
mul dword [screen_width] ; EAX = cur_row * screen_width
mov edx, eax ; EDX = copy of offset to beginning of line
add eax, [cur_col] ; EAX = cur_row * screen_width + cur_col
lea edi, [ebx + eax * 2] ; EDI = memory location of current screen cell
pop eax
ret
align 4
cur_row: dd 0x00
cur_col: dd 0x00
screen_width: dd 0x00
screen_height:dd 0x00
stage2.asm:
ATTR_WHITE_ON_BLACK EQU 0x07 ; White on black attribute
bits 16
dw 0xface
stage2:
; Still in 16-bit realmode at this point
mov ax, cs
mov ds, ax
mov es, ax
mov bx, stage2_called
call print_string
; Enter protected mode
; Should check for A20 being enabled before enabling it
; For the original poster to clean up
call enable_a20
call switch_to_pm
%include "print.asm"
%include "a20.asm"
%include "switch_pm.asm"
%include "gdt.asm"
bits 32
BEGIN_PM:
; Advanced print_string_pm needs to be initialized with the coordinate and screen
; info from the BIOS to continue here the BIOS left off.
call update_screen_state_from_bios
; Advanced print_string_pm takes the address of the string in ESI and
; attribute information in AX (AL/AH).
mov esi, stage2_in_pm
mov ah, ATTR_WHITE_ON_BLACK ; Attribute to print with
mov al, ah ; Attribute to clear last line when scrolling
call print_string_pm
jmp $
%include "32print_pm.asm"
stage2_called db "Stage two successfully called!", 0
stage2_in_pm db "In protected mode!", 0
输出应类似于:
关于assembly - 第二阶段引导加载程序已加载但未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54698499/
我有一个“有趣”的问题,即以两种不同的方式运行 wine 会导致: $> wine --version /Applications/Wine.app/Contents/Resources/bin/wi
我制作了这个网络抓取工具来获取网页中的表格。我使用 puppeteer (不知道 crontab 有问题)、Python 进行清理并处理数据库的输出 但令我惊讶的是,当我执行它时 */50 * * *
JavaScript 是否被调用或执行取决于什么?准确地说,我有两个函数,它们都以相同的方式调用: [self.mapView stringByEvaluatingJavaScriptFromStri
我目前正在使用 python 做一个机器学习项目(这里是初学者,从头开始学习一切)。 只是想知道 statsmodels 的 OLS 和 scikit 的 PooledOlS 使用我拥有的相同面板数据
在使用集成对象模型 (IOM) 后,我可以执行 SAS 代码并将 SAS 数据集读入 .Net/C# 数据集 here . 只是好奇,使用 .Net 作为 SAS 服务器的客户端与使用 Enterpr
有一些直接的 jQuery 在单击时隐藏打开的 div 未显示,但仍将高度添加到导航中以使其看起来好像要掉下来了。 这个脚本工作正常: $(document).ready(funct
这个问题已经有答案了: How do I compare strings in Java? (23 个回答) 已关闭 4 年前。 这里是 Java 新手,我正在使用 NetBeans 尝试一些简单的代
如果我将它切换到 Python 2.x,它执行 10。这是为什么? 训练逻辑回归模型 import keras.backend as
我有两个脚本,它们包含在 HTML 正文中。在第一个脚本中,我初始化一个 JS 对象,该对象在第二个脚本标记中引用。 ... obj.a = 1000; obj.
每当我运行该方法时,我都会收到一个带有数字的错误 以下是我的代码。 public String getAccount() { String s = "Listing the accounts";
我已经用 do~while(true) 创建了我的菜单;但是每次用户输入一个数字时,它不会运行程序,而是再次显示菜单!你怎么看? //我的主要方法 public static void main(St
执行命令后,如何让IPython通知我?我可以使用铃声/警报还是通过弹出窗口获取它?我正在OS X 10.8.5的iTerm上运行Anaconda。 最佳答案 使用最新版本的iTerm,您可以在she
您好,我刚刚使用菜单栏为 Swing 编写了代码。但是问题出现在运行中。我输入: javac Menu.java java Menu 它没有给出任何错误,但 GUI 没有显示。这是我的源代码以供引用:
我觉得这里缺少明显的东西,但是我看不到它写在任何地方。 我使用Authenticode证书对可执行文件进行签名,但是当我开始学习有关它的更多信息时,我对原样的值(value)提出了质疑。 签名的exe
我正在设计一个应用程序,它使用 DataTables 中的预定义库来创建数据表。我想对数据表执行删除操作,为此应在按钮单击事件上执行 java 脚本。 $(document).ready(functi
我是 Haskell 新手,如果有人愿意帮助我,我会很高兴!我试图让这个程序与 do while 循环一起工作。 第二个 getLine 命令的结果被放入变量 goGlenn 中,如果 goGlenn
我有一个用 swing 实现迷你游戏的程序,在主类中我有一个循环,用于监听游戏 map 中的 boolean 值。使用 while 实现的循环不会执行一条指令,如果它是唯一的一条指令,我不知道为什么。
我正在尝试开发一个连接到 Oracle 数据库并执行函数的 Java 应用程序。如果我在 Eclipse 中运行该应用程序,它可以工作,但是当我尝试在 Windows 命令提示符中运行 .jar 时,
我正在阅读有关 Java 中的 Future 和 javascript 中的 Promises 的内容。下面是我作为示例编写的代码。我的问题是分配给 future 的任务什么时候开始执行? 当如下行创
我有一个常见的情况,您有两个变量(xSpeed 和 ySpeed),当它们低于 minSpeed 时,我想将它们独立设置为零,并在它们都为零时退出。 最有效的方法是什么?目前我有两种方法(方法2更干净
我是一名优秀的程序员,十分优秀!