bloggerads

2014年3月22日 星期六

UEFI : Shell Command

首先要準備一個USB隨身碟,將Shell.efi, Bootx64.efi, ShellX64.efi 放到EFI\BOOT這個資料夾

先進到 Bios 選單關掉 secure boot. (若Bios本身就不支援secure boot則這步可省略)

開機Bios自己會到EFI\BOOT\目錄下執行shell, 接著會看到像是下面這個Device mapping table:

fs0: // file system 0
blk0:
blk1:

# 進入隨身碟
Shell>fs0:

# 檢查目錄裡的檔案(-b代表一頁一頁顯示)
fs0:\>ls -b

fs0:\>cd -b

# 查詢指令
fs0:\? -b


*** 好用的 EFI tool ***

UDK2014內含有許多APP可以直接在EFI shell下使用,如
EdkShellBinPkg\ 的 HexEdit.efi, Edit.efi,...等等

2014年3月19日 星期三

ASCII table

因為常在DOS下寫測是程式,總是會加上一些ASCII做的文字方塊,每次都是寫code再一邊查ASCII。
乾脆把表放上來,方便參考

這張圖片取自網站(This photo is originally from the website as follow):
https://commons.wikimedia.org/wiki/File:Ascii-codes-table.png
http://www.theasciicode.com.ar/ascii-printable-characters/lowercase-letter-h-minuscule-ascii-code-104.html

2014年3月6日 星期四

Assembly : 設定 register的 bit為0 or 1

1. 將 eax 的 bit 3 清為 0  

+         test   eax,  1  shl  3
+         jz      @f
+         xor    eax,  1  shl  3
+  @@:                             ;; eax bit 3 is 0 now

2. 將 eax 的 bit 3 設為 1       

+    or     eax,  1  shl  3


2014年3月5日 星期三

SATA Spec

1. 介紹SATA的四個Layer:


•Application Layer:  
  • Overall  ATA  command  execution

•Transport Layer:  
  • Placing control information and data to be transferred between the host and device in a packet/frame (FIS)

•Link Layer:  
  • Taking data from the constructed  frames, encoding  or  decoding each byte using 8b/10b, and inserting control characters such that the 10-bit stream of data may be decoded correctly

•Physical Layer: 
  • Transmitting and receiving the encoded information as a serial data stream on the wire
2. Primitive
    用來控制和提供串列線路的狀態,由4個Byte所組成

3. BURST:  
  • OOB signaling is a pattern of ALIGNP primitives or Dwords composed of D24.3 characters and idle time and is used to initialize the Serial ATA interface (由特定的Primitive或4個D24.3所組成)
4. OOB信號:
  • COMRESET (Originate from Host)/ COMINIT (Originate from Device)
  • COMWAKE (for both host & device)
  • Consists of 6 bursts with different time gap

5. Speed negotiation:



6. SATA FIS:





UEFI C coding stytle

最近接觸UEFI的code, 她是C語言架構所組成並使用VC++或DDK來compiler,coding上跟C幾乎是一樣。但是Intel工程把C的指標發揮到淋漓盡致, coding style很漂亮,所以我寫這篇文章: UEFI C Coding style,用來練習這種coding方式

UEFI Bios 定義許的protocol夾雜許多callback function的prototype。目的是固定函數的輸入輸出型態使其成為spec的一部分,然後將protocol 傳給所需要的driver使用

我也來學學UEFI的方式寫個C程式來試試

#include <cstdio>

int add( int x, int y ) {
   return x+y;
}
int add2( int x ) {
   return x+2;
}

typedef int (*ADD_CALLBACK)(int, int);
typedef int (*ADD2_CALLBACK)(int);

//
// Protocol type of Service
//
typedef struct
{
    unsigned char rev;
    ADD_CALLBACK AddCallBack;
    ADD2_CALLBACK Add2CallBack;    
}SERVICES;

int 
main ()
{
    SERVICES gPS = {0, add, add2};
    //(&gPS)->AddCallBack=add;
    //(&gPS)->Add2CallBack=add2;
    printf("%d\n", (&gPS)->AddCallBack(1,2));
    printf("%d\n", (&gPS)->Add2CallBack(3));

   return 0;
}

2014年1月22日 星期三

Change Code::Blocks theme

1. 關閉 Code::Blocks

2. 到http://wiki.codeblocks.org/index.php?title=Syntax_highlighting_custom_colour_themes 將此網頁提供的XML檔案新增到本地,並複製成一個.config檔

3. 找到 Code::Blocks提供的執行檔 cb_share_config.exe, 填好以下的欄位點Transfer再點Save
  • Source configuration file:  填入step 2存的.config檔位置
  • Destination configuration file: 填入Code::Blocks預設.conf 路徑 (C:\Users\(Your_Name)\AppData\Roaming\CodeBlocks)

2014年1月3日 星期五

WATCOM C 使用教學

Watcom官網download watcom編譯器 (1.9版, 2010),安裝完後會在"開始"出現IDE的圖示, 開啟它


先到File->New Project新增一個project (預設為noname),然後選你要編譯成哪種環境下執行的應用程式。我主要是用Watcom編譯DOS程式,而且我要直接跑在protect mode上,因此選擇DOS - 32 bit。至於要用哪種方法進入32位元,我比較常選的是PMODE/W  Executable(.exe), 這個執行檔執行時會自行先進入protect mode。
另一個選擇是 DOS/4GW Executable(.exe), 編譯成這個執行檔則程式的運行是寄生在DOS/4GW下,因此必須把dos4gw.exe放在同個目錄下程式才能正確執行。


 環境選擇好了就在白色處點右鍵,加入你寫的.c/.h/.cpp/.hpp檔


最後點選紅色框框處來執行,若編譯沒問題,就會產生一個noname.exe檔案了


完成。