bloggerads

2016年6月24日 星期五

UEFI : BuildOptions (Compiler Options)

用來access IO的變數若不宣告成volatile,但又怕因為最佳化而沒有實際access到IO的話,可以改Compiler Options 關掉最佳化編譯。更改UEFI 的Compiler Options, 可以選擇一次改全部 modules 或只改單一個 module,在EDK2都是透過修改DSC file。

1. 更改單一個 module 的 compiler options

[Components]

PackageNamePkg/NameOneDxe/NameOneDxe.inf {
    <BuildOptions>
    MSFT:*_*_*_CC_FLAGS = /Od
}

2016年6月5日 星期日

C# : from in where let select, 資料庫語法


public class Example_of_From_In_Let_Select
{
    public static void Main(string[] args)
    {
        string names = "Mr.Adam,Mrs.Eva,Mr.Henry,MS.May";
        var array = names.Split(',');
       
        var result = (
                from name in array
                where (name.Substring(0, name.IndexOf('.')) == "Mr" )
                let new_name = name + "<Male>"
                select new_name
            );
       
        foreach(string x in result)
            Console.WriteLine(x);
    }
}

/////// Output ///////
Mr.Adam<Male>
Mr.Henry<Male>

2016年6月3日 星期五

LeetCode : 169. Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.
You may assume that the array is non-empty and the majority element always exist in the array.


// C++ Solution

class Solution {
public:
    int majorityElement(vector<int>& nums) {
        if (nums.size() == 1) return nums[0];
        map <int, int> m;
        for (int i=0; i<nums.size(); i++) {
            if (m.find(nums[i]) == m.end() )
                m[nums[i]] = 1;
            else {
                m[nums[i]]++;
                if (m[nums[i]] > nums.size()/2)
                    return nums[i];
            }
        }
    }
};

2016年5月28日 星期六

UEFI : Event (事件)

UEFI 基本上是個單核/單工/提供Timer中斷的系統。<note 1>
但因為他提供了Timer中斷, 理論上就有機會做到異步操作以及分時多工。

實現這樣的目標可以透過 Boot Service提供的事件(Event)來達成。

首先使用 gBS->CreateEvent() 註冊一個 NotifyFunction (或稱CallBackFunction) 等待事件的發生或讓事件週期性的在背景執行。關閉Event須要呼叫  gBS->CloseEvent() 。因為是Boot Service所提供的,因此ExitBootServices()被系統呼叫後,BS的service/data都會消失。

先來看看Event的 typedef

2016年5月19日 星期四

AHCI: Index-Data Pair (IDP)

寫AHCI "Legacy" Option Rom的時候,為了要Access MMIO (AHCI Base Address) 得從 real mode 切換到Protect Mode 。但是AHCI其實有定義一種叫做Index Data Pair的機制,透過Access IO來替代MMIO。這種方法就可以在純real mode (<1MB) 底下寫AHCI Driver了

AHCI Spec第2.4章,定義了一個SATA Capability(0x12), 有這個Capability就是代表此AHCI有support Index Data Pair


這個Cap的結構如下

2016年5月12日 星期四

UEFI : Coding after S3 BootScript

做這個實驗的動機是工作上必須在S3 BootScript完成後加patch code, 當時趕時間就把程式直接加在AMI 的 code裡。趁現在有空,就研究看有沒有辦法把她加在公司package code裡。

想想,應該可以註冊個Notify CallBack function在Pei phase結束之前自動呼叫她,實驗結果是可以的。以下是我的作法,在S3 Pei init 的路徑上加上  


(*PeiServices)->NotifyPpi(PeiServices, mTest);

2016年5月2日 星期一

UEFI : SMM Kernel Code 重點整理: (一) Protocols


●
首先定義SMM driver和一般DXE driver:


DXE drivers
  regular DXE phase drivers that loads into system memory by DXE core driver.
SMM drivers  
  SMM Drivers are launched once, directly into SMRAM during SMM phase initialization.
SMM/DXE combined drivers
  Combination of drivers that loaded twice: as DXE driver and as SMM driver.

● 簡單介紹SMM Driver在做什麼