init進程調用的init函數
1、setup((void*)&drive_info);
a.setup函數用的是main.c中Line 25的inline _syscall1(int,setup,void *,BIOS),_syscall1()函數調用來自於include/unistd.h中的Line 146
1
#define_syscall1(type,name,atype,a)\
2
typename(atypea)\
3
{\
4
long__res;\
5
__asm__volatile("int$0x80"\
6
:"=a"(__res)\
7
:"0"(__NR_##name),"b"((long)(a)));\
8
if(__res>=0)\
9
return(type)__res;\
10
errno=-__res;\
11
return-1;\
12
}
根據define規則進行替換
1
int setup(void*BIOS)\
2
{\
3
long__res;\
4
__asm__volatile("int$0x80"\
5
:"=a"(__res)\
6
:"0"(__NR_##setup),"b"((long)(BIOS)));\
7
if(__res>=0)\
8
return(int)__res;\
9
errno=-__res;\
10
return-1;\
11
}
b.drive_info
定義:struct drive_info { char dummy[32]; } drive_info;//drive_info結構其實就是個32位的數組而已
#define DRIVE_INFO (*(struct drive_info *)0x90080)//定義DRIVE_INFO為0x90080開始的32位的數據。而在setup.s中已經定義好從0x90080開始存放BIOS兩個硬盤的參數表,0x90080處存放第一個硬盤的表,0x90090處存放第二個硬盤的表。(表的長度是16位)
drive_info = DRIVE_INFO;
因此,setup((void*)&drive_info)的作用就是讀取硬盤參數包括分區表信息並加載虛擬盤(若存在的話)和安裝根文件系統設備。
2、(void) open (“/dev/tty0”,O_RDWR,0)
open函數的定義:
1
intopen(constchar*filename,intflag,...)
2
{
3
registerintres;
4
va_listarg;
5
6
va_start(arg,flag);
7
__asm__("int$0x80"
8
:"=a"(res)
9
:"0"(__NR_op