發表文章

Raspberry Pi bare metal OS 筆記

圖片
     最近因為轉職的關係,時間很零碎,年過30體力ok,不過熬夜的能力大減! 入手了一個Raspberry Pi,原因是社群比較多,在台灣也比較好買到,Beagleboard-XM我在官方論壇上問問題,幾乎沒人回應了,大家都玩BeagleBone Black。       持續的學習! 分享學習的筆記,我跟我同年紀的人,程度差太多了,努力跟上領先集團,  因為我是阿宅,沒人要跟我一起開讀書會,人家用黃色小鴨Debug,我就用自由女神學習吧,概念就是,跟著自由女神解釋,自己寫了什麼,藉以review筆記。     試著使用hackpad,比較方便編輯跟備份。     Raspberry Pi bare metal Hello World     中文:https://lbd.hackpad.com/Raspberry-PiHello-world-qivrzCRU6mW  English:https://lbd.hackpad.com/Hello-world-on-qemu-Raspberry-Pi-dUGFyJw9Hva    

自己動手做OS, micro kernel develop on Beagleboard-XM(ARMv7) lab3 Initialize stack pointer and printk

lab3,Happy Moon Festival!!!  We'll study how to initial stack  and add a printk function for debug in lab3. 終於有點空閒時間了,大家中秋節快樂, 這個例子練習了ARM在開機時initial stack的部份, 並加入了一個printk的功能,以便日後debug.  I just give some notes for now. start.S  - __vector_reset will invoke when boot,  it will initialize stack pointer then clear bss section  and then invoke plat_boot function to print helloworld. 開始後會跳到__ vector_reset去進行stack initial的動作 ,然後初始化bss段,跳到 plat_boot去動作。 boots.c It will print helloworld and invoke test_printk function. 會印出helloworld並呼叫 test_printk。 source code download (原始碼下載): https://github.com/tzuCarlos/v1OS.git further study: Jserv's CuRTOS give us a nice ARM boot asm example, we'll need to disable MMU, setup stack, timer, interrupt and some hardwares. though bootloader already did some during boot, but for portal reason, a nice OS still need to initial by itself. 請先看Jserv大,寫的CuRTOS的啟動程式部份,裡面有很詳細的註解,不過今天我們只有做stack的配置。 https://git...

自己動手做OS, micro kernel develop on Beagleboard-XM(ARMv7) lab1

This is a tutorial on bare-metal [OS] development on the Beagleboard-XM. I will show you how to implement a Helloworld image in this article. 在這篇文章中,我會介紹如何寫一個Helloworld的image.  1. From BeagleBoard-xM System Reference Manual, we can get, "A single RS232 port is provided on the BeagleBoard and provides access to the TX and RX lines of UART3 on the processor." 2. From DM3730 Technical Reference Manual- we can get "THR_REG W UART3 base address is 0x49020000"  - 首先我們可以從BeagleBoard-xM System Reference Manual,查到板上子上的RS-232是接在UART3上,再從DM3730 Technical Reference Manual,得知,UART3的THR_REG的位址是0x49020000. I've already added  comments in source file, please refer to source code(github) for details. 我把註解加入到檔案中了,請到github下載source。 1.boot.asm #UART3 THR_REG register address .equ UART3_THR_REG, 0x49020000 .arm _start: ldr r0,=UART3_THR_REG adr r1,.L0 bl helloworld .L1: b .L1 .align 2 .L0: .ascii "helloworld\n\0" 2.Helloworld.c int helloworld(unsigned int...

Assembly - moving data 組合語言,移動資料

圖片
從記憶體中讀資料 load date from memory into register 把暫存器中存資料存進記憶體 store register data into memory                Figure 1. integer registes,                 source:https://www.cs.cmu.edu/~fp/courses/15213-s07/misc/asm64-handout.pdf mov operand combinations(mov的運算整理) mov imm to register, mov $0x11,%eax -> var_a=0x11; mov imm to mem, mov $0x39,(%eax) -> *p=0x39; mov reg to reg, mov %edx,%eax -> var_a=var_b; mov reg to mem, mov %eax,(%edx) -> *p=var_a; mov mem to reg, mov (%eax),%eax -> var_a=*p; *can not do memory to memory transfer in single instruction. Here is an simple swap code: void swap(int *xp, int *yp) {    int a=*xp;    int b=*yp;    *xp=b;    *yp=a; } Let's see how above code done by assembly. Variables store in which memory place and registers is assigned...

C語言,大數運算,階層筆記

如果今天要用C語言計算50!,int都是不夠用的。 要解這樣的問題,必需要用陣列。  32位元系統unsigned int 最大 4,294,967,295 (10位數字) 64位元 uint64_t 18,446,744,073,709,551,615 (20 位數字) /*從array的高位元開始存值*/ void Big_factorial_iteration(int n) { int i=1; /*init array*/ int a[SIZE_A]= {0}; int tail=SIZE_A-1; a[tail]=1; for(i=1; i <= n ; i++) { int j; /* multiply the value */ for(j= tail ; j >= 0 ; j--) { a[j]=a[j]*i; } /*進位留下個位數,其餘的加點前一位 */ for(j= tail ; j >= 0 ; j--) { if (a[j] >= 10) a[j-1]=a[j-1]+(a[j]/10); a[j]=a[j]%10; } } for(i=0; i< SIZE_A ; i++) { printf("%d",a[i]); } printf("\n"); } int main() { printf(" %d \n",factorial_recursion(10)); printf(" %d \n",factorial_iteration(10)); Big_factorial_iteration(20); 計算20階層 } result: [carlos@localhost c_examples]$ ./factorial_2  3628800  3628800  000000000002432902008176640000  原始碼:   https://github.com/tzuCarlo...

安裝Cowday到你的linux歡迎訊息,message of day linux

圖片
1.先安裝 sudo apt-get install fortune cowsay 2接著加入以下指令到 bash.bashrc中,這樣每次開啟terminal 或 ssh 就會有隻牛跟你說話囉 sudo vim    / etc / bash.bashrc   # Spicing up Terminal fortune | cowsay -n echo source: http://xtremediary.blogspot.tw/2010/04/spice-up-ubuntulinux-terminal-with.html

C語言階層的遞迴與迴圈 - example factorial recursion and iteration.

筆記一下C語言階層的遞迴與迴圈寫法,這個範例不考慮溢位的問題。 #include /* * example for recursion and iteration * I know it should return error if n < 0, but this just a simple example for study. * Do not care about overflow issues this example. */ unsigned int factorial_recursion(int n) { /* return n>=1 ? n * factorial_recursion(n-1) : 1; */ if(n==0) return 1; /*Base case */ else return n * factorial_recursion(n-1); /*General case */ } unsigned int factorial_iteration(int n) { int i=1; int result=1; for(i=1; i <= n ; i++) { /*result *= i */ result=result * i; } return result; } int main() { printf(" %d \n",factorial_recursion(10)); printf(" %d \n",factorial_iteration(10)); } 原始碼: https://github.com/tzuCarlos/linux_C/blob/master/c_examples/factorial.c