x86

共 3 篇文章。

FreeBSD上的{rd,wr}msr_safe

• Kernel

这几天改 FreeBSD 的 coretemp(4) 遇到了一个问题。直接使用 rdmsr 的话,如果那个 MSR 不存在,则会触发 #GP(0),不了解 CPU 型号的情况下直接去杵肯定是不行的。后来翻了一下 cpuctl(4) 的代码发现 FreeBSD 上也有 rdmsr_safe。它的实现并不复杂( sys/amd64/amd64/support.S):

阅读全文… ( 本文约 364 字,阅读大致需要 1 分钟 )

重修一门课

• Life

当然,不是在学校学的课。

95年的时候,我比较完整地看了一遍 Intel 的开发手册,这之后对于 Intel 处理器的许多了解都是限于道听途说的小修小补(主要是对于 MMX、SSE 等等),感觉有点跟不上时代了。于是,上周从 Intel 订了一套书,准备重新学习一遍,希望能够在3-5个月之内搞定。我想,恐怕这也是我最近几年以来第一次下决心去好好看看技术书籍了吧。

阅读全文… ( 本文约 337 字,阅读大致需要 1 分钟 )

关于system call

• Kernel

在 FreeBSD 开发手册 中,有一部分内容介绍了关于系统调用。里面有这样一段话:

Linux is a UNIX like system. However, its kernel uses the same system-call convention of passing parameters in registers MS-DOS does. As with the UNIX convention, the function number is placed in EAX. The parameters, however, are not passed on the stack but in EBX, ECX, EDX, ESI, EDI, EBP:

open:
  mov eax, 5
  mov ebx, path
  mov ecx, flags
  mov edx, mode
  int 80h

This convention has a great disadvantage over the UNIX way, at least as far as assembly language programming is concerned: Every time you make a kernel call you must push the registers, then pop them later. This makes your code bulkier and slower. Nevertheless, FreeBSD gives you a choice.

可能有人会问了,为什么说 UNIX way (将参数压栈) 更好呢?

阅读全文… ( 本文约 606 字,阅读大致需要 2 分钟 )