mirror of
				https://e.coding.net/weidongshan/01_all_series_quickstart.git
				synced 2025-11-04 13:05:59 +08:00 
			
		
		
		
	发布:驱动大全之同步与互斥
This commit is contained in:
		
							
								
								
									
										6
									
								
								07_驱动大全/source/01_inline_assembly/01_c_code/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								07_驱动大全/source/01_inline_assembly/01_c_code/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
test: main.c
 | 
			
		||||
	arm-linux-gnueabihf-gcc -o $@ $^
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm test
 | 
			
		||||
	
 | 
			
		||||
							
								
								
									
										26
									
								
								07_驱动大全/source/01_inline_assembly/01_c_code/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								07_驱动大全/source/01_inline_assembly/01_c_code/main.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
int add(int a, int b)
 | 
			
		||||
{
 | 
			
		||||
	return a+b;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
	int a;
 | 
			
		||||
	int b;
 | 
			
		||||
	
 | 
			
		||||
	if (argc != 3)
 | 
			
		||||
	{
 | 
			
		||||
		printf("Usage: %s <val1> <val2>\n", argv[0]);
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	a = (int)strtol(argv[1], NULL, 0);	
 | 
			
		||||
	b = (int)strtol(argv[2], NULL, 0);	
 | 
			
		||||
 | 
			
		||||
	printf("%d + %d = %d\n", a, b, add(a, b));
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								07_驱动大全/source/01_inline_assembly/01_c_code/test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								07_驱动大全/source/01_inline_assembly/01_c_code/test
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										1447
									
								
								07_驱动大全/source/01_inline_assembly/01_c_code/test.dis
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1447
									
								
								07_驱动大全/source/01_inline_assembly/01_c_code/test.dis
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										8
									
								
								07_驱动大全/source/01_inline_assembly/02_assembly/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								07_驱动大全/source/01_inline_assembly/02_assembly/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
CROSS=arm-linux-gnueabihf-
 | 
			
		||||
 | 
			
		||||
test: main.c add.S
 | 
			
		||||
	$(CROSS)gcc -o $@ $^
 | 
			
		||||
	$(CROSS)objdump -D $@ > $@.dis
 | 
			
		||||
clean:
 | 
			
		||||
	rm test
 | 
			
		||||
	
 | 
			
		||||
							
								
								
									
										8
									
								
								07_驱动大全/source/01_inline_assembly/02_assembly/add.S
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								07_驱动大全/source/01_inline_assembly/02_assembly/add.S
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.text            // 放在代码段
 | 
			
		||||
.global  add     // 实现全局函数add
 | 
			
		||||
.thumb           // 使用thumb指令, main.c默认使用thumb指令, 所以这里也使用thumb指令
 | 
			
		||||
 | 
			
		||||
add:
 | 
			
		||||
	add r0, r0, r1
 | 
			
		||||
	bx lr
 | 
			
		||||
	
 | 
			
		||||
							
								
								
									
										23
									
								
								07_驱动大全/source/01_inline_assembly/02_assembly/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								07_驱动大全/source/01_inline_assembly/02_assembly/main.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
extern int add(int a, int b);
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
	int a;
 | 
			
		||||
	int b;
 | 
			
		||||
	
 | 
			
		||||
	if (argc != 3)
 | 
			
		||||
	{
 | 
			
		||||
		printf("Usage: %s <val1> <val2>\n", argv[0]);
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	a = (int)strtol(argv[1], NULL, 0);	
 | 
			
		||||
	b = (int)strtol(argv[2], NULL, 0);	
 | 
			
		||||
 | 
			
		||||
	printf("%d + %d = %d\n", a, b, add(a, b));
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								07_驱动大全/source/01_inline_assembly/02_assembly/test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								07_驱动大全/source/01_inline_assembly/02_assembly/test
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										1436
									
								
								07_驱动大全/source/01_inline_assembly/02_assembly/test.dis
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1436
									
								
								07_驱动大全/source/01_inline_assembly/02_assembly/test.dis
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
CROSS=arm-linux-gnueabihf-
 | 
			
		||||
 | 
			
		||||
test: main.c
 | 
			
		||||
	$(CROSS)gcc -o $@ $^
 | 
			
		||||
	$(CROSS)objdump -D $@ > $@.dis
 | 
			
		||||
clean:
 | 
			
		||||
	rm test
 | 
			
		||||
	
 | 
			
		||||
							
								
								
									
										33
									
								
								07_驱动大全/source/01_inline_assembly/03_inline_assembly/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								07_驱动大全/source/01_inline_assembly/03_inline_assembly/main.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
int add(int a, int b)
 | 
			
		||||
{
 | 
			
		||||
	int sum;
 | 
			
		||||
	__asm__ volatile (
 | 
			
		||||
		"add %0, %1, %2"
 | 
			
		||||
		:"=r"(sum)
 | 
			
		||||
		:"r"(a), "r"(b)
 | 
			
		||||
		:"cc"
 | 
			
		||||
	);
 | 
			
		||||
	return sum;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
	int a;
 | 
			
		||||
	int b;
 | 
			
		||||
	
 | 
			
		||||
	if (argc != 3)
 | 
			
		||||
	{
 | 
			
		||||
		printf("Usage: %s <val1> <val2>\n", argv[0]);
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	a = (int)strtol(argv[1], NULL, 0);	
 | 
			
		||||
	b = (int)strtol(argv[2], NULL, 0);	
 | 
			
		||||
 | 
			
		||||
	printf("%d + %d = %d\n", a, b, add(a, b));
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										33
									
								
								07_驱动大全/source/01_inline_assembly/03_inline_assembly/main2.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								07_驱动大全/source/01_inline_assembly/03_inline_assembly/main2.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
int add(int a, int b)
 | 
			
		||||
{
 | 
			
		||||
	int sum;
 | 
			
		||||
	__asm__ volatile (
 | 
			
		||||
		"add %[result], %[val1], %[val2]"
 | 
			
		||||
		:[result]"=r"(sum)
 | 
			
		||||
		:[val1]"r"(a), [val2]"r"(b)
 | 
			
		||||
		:"cc"
 | 
			
		||||
	);
 | 
			
		||||
	return sum;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
	int a;
 | 
			
		||||
	int b;
 | 
			
		||||
	
 | 
			
		||||
	if (argc != 3)
 | 
			
		||||
	{
 | 
			
		||||
		printf("Usage: %s <val1> <val2>\n", argv[0]);
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	a = (int)strtol(argv[1], NULL, 0);	
 | 
			
		||||
	b = (int)strtol(argv[2], NULL, 0);	
 | 
			
		||||
 | 
			
		||||
	printf("%d + %d = %d\n", a, b, add(a, b));
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								07_驱动大全/source/01_inline_assembly/03_inline_assembly/test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								07_驱动大全/source/01_inline_assembly/03_inline_assembly/test
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										1449
									
								
								07_驱动大全/source/01_inline_assembly/03_inline_assembly/test.dis
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1449
									
								
								07_驱动大全/source/01_inline_assembly/03_inline_assembly/test.dis
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
CROSS=arm-linux-gnueabihf-
 | 
			
		||||
 | 
			
		||||
test: main.c
 | 
			
		||||
	$(CROSS)gcc -o $@ $^
 | 
			
		||||
	$(CROSS)objdump -D $@ > $@.dis
 | 
			
		||||
clean:
 | 
			
		||||
	rm test
 | 
			
		||||
	
 | 
			
		||||
							
								
								
									
										35
									
								
								07_驱动大全/source/01_inline_assembly/04_earlyclobber/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								07_驱动大全/source/01_inline_assembly/04_earlyclobber/main.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
int add(int a, int b)
 | 
			
		||||
{
 | 
			
		||||
	int sum;
 | 
			
		||||
	__asm__ volatile (
 | 
			
		||||
		"add %0, %1, %2\n"
 | 
			
		||||
		"add %1, #1\n"
 | 
			
		||||
		"add %2, #1\n"
 | 
			
		||||
		:"=&r"(sum)
 | 
			
		||||
		:"r"(a), "r"(b)
 | 
			
		||||
		:"cc"
 | 
			
		||||
	);
 | 
			
		||||
	return sum;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char **argv)
 | 
			
		||||
{
 | 
			
		||||
	int a;
 | 
			
		||||
	int b;
 | 
			
		||||
	
 | 
			
		||||
	if (argc != 3)
 | 
			
		||||
	{
 | 
			
		||||
		printf("Usage: %s <val1> <val2>\n", argv[0]);
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	a = (int)strtol(argv[1], NULL, 0);	
 | 
			
		||||
	b = (int)strtol(argv[2], NULL, 0);	
 | 
			
		||||
 | 
			
		||||
	printf("%d + %d = %d\n", a, b, add(a, b));
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								07_驱动大全/source/01_inline_assembly/04_earlyclobber/test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								07_驱动大全/source/01_inline_assembly/04_earlyclobber/test
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										1452
									
								
								07_驱动大全/source/01_inline_assembly/04_earlyclobber/test.dis
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1452
									
								
								07_驱动大全/source/01_inline_assembly/04_earlyclobber/test.dis
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								临时文件_驱动大全之同步与互斥.docx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								临时文件_驱动大全之同步与互斥.docx
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user