小编RAV*_*eus的帖子

为什么要使用“ret”而不是“call”来调用方法?

在阅读和学习开源操作系统时,我偶然发现了一种在汇编中调用“方法”的极其复杂的方法。它使用“ret”指令来调用库方法来执行以下操作:

push rbp                ; rsp[1] = rbp
mov rbp, .continue      ; save return label to rbp
xchg rbp, QWORD [rsp]   ; restore rbp and set rsp[1] to return label

push rbp ; rsp[0] = rbp
mov rbp, 0x0000700000000000 + LIB_PTR_TABLE.funcOffset ; rbp = pointer to func pointer
mov rbp, QWORD [rbp]    ; rbp = func pointer
xchg rbp, QWORD [rsp]   ; restore rbp and set rsp[0] to func pointer

; "call" library by "returning" to the address we just planted …
Run Code Online (Sandbox Code Playgroud)

assembly x86-64 osdev spectre

5
推荐指数
1
解决办法
465
查看次数

如何更改字符串的前景色(32 位汇编内核)?

我目前正在编写自己的操作系统(只是为了好玩,我 16 岁)并且我创建的 outprint 函数有问题。我想更改文本颜色(不是背景颜色),但它不起作用。

我已经创建了自己的printf函数SystemOutPrint/ln(以 Java 命名,因为那是我的“主要”语言,对于那些受伤的人)并发现我可以通过在 AH 寄存器中写入来更改背景颜色。在此功能之前,我在内核中什么也没做,引导加载程序只将 GDT、LDT 和模式从 16 位设置为 32 位。所以在 mov ebx, 0xb8000 之前,视频内存是不变的。

相关代码

kmain:
mov ebx, 0xb8000    ;Video Memory
mov esi, kernelVersion
mov ah, 0x0
;setting ah to 0x0 is not neccessary, because its the default but if you
;would put in A for example it would be light green, etc.
call SystemOutPrintln

SystemOutPrintln:
mov ecx, ebx

.printChar:
lodsb
test al,al
jz .newLine
or eax,0x0F00
mov word …
Run Code Online (Sandbox Code Playgroud)

x86 assembly kernel osdev vga

2
推荐指数
1
解决办法
297
查看次数

标签 统计

assembly ×2

osdev ×2

kernel ×1

spectre ×1

vga ×1

x86 ×1

x86-64 ×1