当前位置: 技术问答>linux和unix
请教个vivi启动linux内核的问题
来源: 互联网 发布时间:2015-12-04
本文导语: 在vivi里面第二阶段,main函数里面,最后阶段,应该启动linux内核吧。可我看vivi代码的时候没有看到启动linux内核啊,代码如下: int main(int argc, char *argv[]) { ………… init_builtin_cmds(); update_program...
在vivi里面第二阶段,main函数里面,最后阶段,应该启动linux内核吧。可我看vivi代码的时候没有看到启动linux内核啊,代码如下:
int main(int argc, char *argv[])
{
…………
init_builtin_cmds();
update_program();
/* Step 8:
* 绢叼肺 哎鳖唱?
*/
/* GPDCON = 0xaaa5aaaa;
GPDUP &= 0xfffffdff;
GPDDAT |= ~(0xfffffdff);
*/
boot_or_vivi(); //应该从这里面启动内核吧???
}
void boot_or_vivi(void)
{
char c;
int ret;
ulong boot_delay;
boot_delay = get_param_value("boot_delay", &ret);
if (ret) boot_delay = DEFAULT_BOOT_DELAY;
/* If a value of boot_delay is zero,
* unconditionally call vivi shell */
if (boot_delay == 0) vivi_shell();
/*
* wait for a keystroke (or a button press if you want.)
*/
printk("Press Return to start the LINUX now, any other key for vivi%lxn",boot_delay);
if(boot_delay>0x300) boot_delay=0x300;
// c = awaitkey(boot_delay, NULL);
c = awaitkey(boot_delay, NULL);
if (((c != 'r') && (c != 'n') && (c != '')))
{
printk("type "help" for help.n");
vivi_shell();
}
run_autoboot();
return;
}
void run_autoboot(void)
{
while (1) {
exec_string("boot");
printk("Failed 'boot' command. reentering vivi shelln");
/* if default boot fails, drop into the shell */
vivi_shell();
}
}
void
vivi_shell(void)
{
#ifdef CONFIG_SERIAL_TERM
serial_term();
#else
#error there is no terminal.
#endif
}
void serial_term(void)
{
char cmd_buf[MAX_CMDBUF_SIZE];
for (;;) {
printk("%s> ", prompt);
getcmd(cmd_buf, MAX_CMDBUF_SIZE);
/* execute a user command */
if (cmd_buf[0])
exec_string(cmd_buf);
}
}
————————————————————-
一直没有找到哪里有启动内核的代码啊? 请指教
int main(int argc, char *argv[])
{
…………
init_builtin_cmds();
update_program();
/* Step 8:
* 绢叼肺 哎鳖唱?
*/
/* GPDCON = 0xaaa5aaaa;
GPDUP &= 0xfffffdff;
GPDDAT |= ~(0xfffffdff);
*/
boot_or_vivi(); //应该从这里面启动内核吧???
}
void boot_or_vivi(void)
{
char c;
int ret;
ulong boot_delay;
boot_delay = get_param_value("boot_delay", &ret);
if (ret) boot_delay = DEFAULT_BOOT_DELAY;
/* If a value of boot_delay is zero,
* unconditionally call vivi shell */
if (boot_delay == 0) vivi_shell();
/*
* wait for a keystroke (or a button press if you want.)
*/
printk("Press Return to start the LINUX now, any other key for vivi%lxn",boot_delay);
if(boot_delay>0x300) boot_delay=0x300;
// c = awaitkey(boot_delay, NULL);
c = awaitkey(boot_delay, NULL);
if (((c != 'r') && (c != 'n') && (c != '')))
{
printk("type "help" for help.n");
vivi_shell();
}
run_autoboot();
return;
}
void run_autoboot(void)
{
while (1) {
exec_string("boot");
printk("Failed 'boot' command. reentering vivi shelln");
/* if default boot fails, drop into the shell */
vivi_shell();
}
}
void
vivi_shell(void)
{
#ifdef CONFIG_SERIAL_TERM
serial_term();
#else
#error there is no terminal.
#endif
}
void serial_term(void)
{
char cmd_buf[MAX_CMDBUF_SIZE];
for (;;) {
printk("%s> ", prompt);
getcmd(cmd_buf, MAX_CMDBUF_SIZE);
/* execute a user command */
if (cmd_buf[0])
exec_string(cmd_buf);
}
}
————————————————————-
一直没有找到哪里有启动内核的代码啊? 请指教
|
vivi/lib/exec.c中:
这里启动os
static void go(unsigned long addr, long a0, long a1, long a2, long a3)
{
printk("go to 0x%08lxn", addr);
printk(" argument 0 = 0x%08lxn", a0);
printk(" argument 1 = 0x%08lxn", a1);
printk(" argument 2 = 0x%08lxn", a2);
printk(" argument 3 = 0x%08lxn", a3);
cache_clean_invalidate();
tlb_invalidate();
__asm__(
"mov r0, %0n"
"mov r1, %1n"
"mov r2, %2n"
"mov r3, %3n"
"mov r4, %4n"
"mov ip, #0n"
"mcr p15, 0, ip, c13, c0, 0n" /* zero PID */
"mcr p15, 0, ip, c7, c7, 0n" /* invalidate I,D caches */
"mcr p15, 0, ip, c7, c10, 4n" /* drain write buffer */
"mcr p15, 0, ip, c8, c7, 0n" /* invalidate I,D TLBs */
"mrc p15, 0, ip, c1, c0, 0n" /* get control register */
"bic ip, ip, #0x0001n" /* disable MMU */
"mcr p15, 0, ip, c1, c0, 0n" /* write control register */
"mov pc, r4n"
"nopn"
"nopn"
: /* no outpus */
: "r" (a0), "r" (a1), "r" (a2), "r" (a3), "r" (addr)
);
}
这里启动os
static void go(unsigned long addr, long a0, long a1, long a2, long a3)
{
printk("go to 0x%08lxn", addr);
printk(" argument 0 = 0x%08lxn", a0);
printk(" argument 1 = 0x%08lxn", a1);
printk(" argument 2 = 0x%08lxn", a2);
printk(" argument 3 = 0x%08lxn", a3);
cache_clean_invalidate();
tlb_invalidate();
__asm__(
"mov r0, %0n"
"mov r1, %1n"
"mov r2, %2n"
"mov r3, %3n"
"mov r4, %4n"
"mov ip, #0n"
"mcr p15, 0, ip, c13, c0, 0n" /* zero PID */
"mcr p15, 0, ip, c7, c7, 0n" /* invalidate I,D caches */
"mcr p15, 0, ip, c7, c10, 4n" /* drain write buffer */
"mcr p15, 0, ip, c8, c7, 0n" /* invalidate I,D TLBs */
"mrc p15, 0, ip, c1, c0, 0n" /* get control register */
"bic ip, ip, #0x0001n" /* disable MMU */
"mcr p15, 0, ip, c1, c0, 0n" /* write control register */
"mov pc, r4n"
"nopn"
"nopn"
: /* no outpus */
: "r" (a0), "r" (a1), "r" (a2), "r" (a3), "r" (addr)
);
}
|
/* execute a function */
void execcmd(int argc, const char **argv)
{
user_command_t *cmd = find_cmd(argv[0]);
if (cmd == NULL) {
printk("Could not found '%s' commandn", argv[0]);
printk("If you want to konw available commands, type 'help'n");
return;
}
/*printk("execcmd: cmd=%s, argc=%dn", argv[0], argc);*/
cmd->cmdfunc(argc, argv); //跟不进去了
}
............
我用的是ppcboot,不过看了这段我觉得和ppcboot挺像的
首先就是execcmd 这个函数,在ppcboot中相当于run_command函数
ppcboot中也是这样实现的,通过run_command函数来执行内核启动函数
ppcboot中有do_bootm命令 其实现函数do_bootm_linux是专门负责启动os的
我想vivi应该也差不多吧
void execcmd(int argc, const char **argv)
{
user_command_t *cmd = find_cmd(argv[0]);
if (cmd == NULL) {
printk("Could not found '%s' commandn", argv[0]);
printk("If you want to konw available commands, type 'help'n");
return;
}
/*printk("execcmd: cmd=%s, argc=%dn", argv[0], argc);*/
cmd->cmdfunc(argc, argv); //跟不进去了
}
............
我用的是ppcboot,不过看了这段我觉得和ppcboot挺像的
首先就是execcmd 这个函数,在ppcboot中相当于run_command函数
ppcboot中也是这样实现的,通过run_command函数来执行内核启动函数
ppcboot中有do_bootm命令 其实现函数do_bootm_linux是专门负责启动os的
我想vivi应该也差不多吧
|
就是,这东西要是能调试调试就好了。
execcmd(argc, (const char **)argv);
继续跟下去呗。
execcmd(argc, (const char **)argv);
继续跟下去呗。