bloggerads

2013年6月14日 星期五

Intel (x86 Ivy+Panther Point) Power Sequence (開機訊號時序)

這篇介紹的是按下電腦開機按鈕到Bios接手之前的訊號時序邏輯, 以Desktop Motherboard為範例

// 開啟電源後,從SIO(super IO)報到南僑
1. PWRBTN# assert (to SIO)
2. SIO assert SB_PWRBTN# to PCH

// PCH和SIO的handshake
3. PCH assert SUS_WARN# to SIO
4. SIO assert SUS_ACK# to PCH

5. PCH de-assertSLP_LAN# 去叫邏輯電路打開 3.3v_ME
6  PCH de-assertSLP_A# 去叫邏輯電路打開 1.05v_ME
7. PCH  de-assert  SLP_S4# 信號去開啟dual power rail (這個power rail是由standby power轉來的)
8. PCH de-assert  SLP_S3# 信號去開啟ATX power的PSON#
9. ATX power 回 ATX_PWROK給PCH
10. PCH發給CPU, DRAM_pwrok 和 CPU_pwrOK,代表VCORE ready
11. PCH de-assert PLTRST# (有些設計是PCIRST#), 接著就開始Reset一些周邊裝置

done.

2013年6月6日 星期四

C# : Show Version

string FileLocate = @"\\Address\Filename.exe";

if (File.Exists(FileLocate) == true)
{
    var versionInfo = FileVersionInfo.GetVersionInfo(FileLocate);
    string version = versionInfo.ProductVersion; //  "1.0.0" as default
    
    string MessageBoxTitle = "Version";
    string MessageBoxContent = version.ToString() + "\n";
    DialogResult dialogResult = MessageBox.Show(MessageBoxContent, MessageBoxTitle, MessageBoxButtons.OK);
}

2013年3月5日 星期二

x86 Assembly (legacy Bios) 一些指令紀錄

4大Segment的暫存器組合 (參考WIKI x86 Assembly)

CS:IP (CS is Code Segment, IP is Instruction Pointer) points to the address where the processor will fetch the next byte of code.
SS:SP (SS is Stack Segment, SP is Stack Pointer) points to the address of the top of the stack, i.e. the most recently pushed byte.
DS:SI (DS is Data Segment, SI is Source Index) is often used to point to string data that is about to be copied to ES:DI.
ES:DI (ES is Extra Segment, DI is Destination Index) is typically used to point to the destination for a string copy, as mentioned above.

# FLAG register:

Overflow(bit 11)/Direction(bit 10)/Interrupt(bit 9)/Sign(bit 7)/Zero(bit 6)/Auxiliary Carry(bit 4)/Parity(bit 2)/Carry(bit 0)


# 操作Flag register 的指令:

STD  ;Set Direction Flag (STD sets the direction flag to 1, causing all subsequent string operations to decrement the index registers, (E)SI and/or (E)DI, on which they operate.)
CLD  ;Clear Direction Flag
STC  ;Set Carry Flag
CLC  ;Clear Carry Flag 
CLI   ;Clear Interrupt Flag
STI   ;Set Interrupts


# 一些在Bios常使用的指令

PUSHA ;(PUSH ALL):PUSH  ax,cx,dx,bx,sp,bp,si,di 
PUSHAD ;Push EAX, ECX, EDX, EBX, original ESP, EBP, ESI, and EDI PUSHF ; Save the CPU flags on the stack.
POPF   ;Restore the CPU flags from the stack.
POPA  ;(POP ALL):POP  di,si,bp,sp,bx,dx,cx,ax
RET    ;副程式結束,返回,即 pop ip  
RETF  ;遠程副程式結束,返回,即 pop cs 然後 pop ip   
MOVSB ;Move byte at address DS:(E)SI to address ES:(E)DI.

# 標記與跳躍 @F 或 @B (這段是參考小木偶的網頁,感謝他)

除了高階的流程控制之外,MASM 6.x 還接受一種特殊標記,@@:。這種標記是做為跳躍指令的目的地,要用 @@: 做為目的地的跳躍指令,必須配合 @f 或 @b 使用,前者是指往前跳躍,後者是往後跳躍,它們都只向前或向後跳躍到第一個 @@: 標記處。

例如有一個程式片段,是用來使一個佔用 16 個位元組的 key_buffer 陣列所有元素填上 0,一般會這樣寫:

+           mov   cx,16
+           lea     si,key_buffer
+  next: mov   byte ptr ss:[si],0
+           inc     si
+           loop   next

如果 next: 標記只有此處用到,那麼便可以用 @@: 代替,變成下面的程式:

+          mov   cx,16
+          lea     si,key_buffer
+  @@: mov   byte ptr ss:[si],0
+          inc     si
+          loop   @b

2013年1月3日 星期四

C# : Call a exe file without a command prompt blinking

using System.Diagnostics;


private static int RunProcess(string processName, string arguments)
{
    Process process = new Process();
    process.StartInfo.FileName = processName;
    process.StartInfo.Arguments = arguments;
 //* 
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardInput = true;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.RedirectStandardError = true;
    process.StartInfo.CreateNoWindow = true;  //Without a command prompt blinking
 //&
    process.Start();
    process.WaitForExit();
    return process.ExitCode;
}

C# : Basic knowledge notes

// int to string

int iValue = 4;
string sResult = iValue.ToString();
string sResult = iValue.ToString("X16");  // int to Hex string

// string to int

string num = "-105";
int numVal = Int32.Parse(num);

// string array

string[] lines= new string[] { "Param1", "Param2" };

Array.Clear(lines, 0, lines.Length); // Clear all (Won't resize)

2013年1月2日 星期三

C# : Write and Read Binary file

using System.IO;
byte[] content = new byte[] {1, 2};
File.WriteAllBytes(@"E:\12.bin", content);
byte[] bytes = File.ReadAllBytes(@"E:\12.bin");
Console.WriteLine("{0:x3}", bytes[0]); // Hex format and 3 digits
Console.WriteLine("{0:D2}", bytes[1]); // Dec format and 2 digits

2013年1月1日 星期二

C# : Write TXT file

Write a struct to a TXT file

struct test{
    public char a;
    public int x;
    public int y;
    public int z;
}

static void Main(string[] args)
{
    test[] aa = new test[] {
        new test { a = 'a', x = 1, y = 2, z = 3 },
        new test { a = 'b', x = 2, y = 3, z = 4 }
    };
    string path = System.IO.Directory.GetCurrentDirectory() + "\\go.txt";
    
    using (System.IO.StreamWriter file = new System.IO.StreamWriter(path))
    {
        foreach (test x in aa)
        {
            file.WriteLine("{0} {1} {1} {3}", x.a.ToString(), x.x, x.y, x.z);
        }
    }

}