实现64位操作系统的问题解决系列:(三)程序4-11 因为__switch_to符号未定义,编译失败

实现64位操作系统的问题解决系列:(三)程序4-11 因为__switch_to符号未定义,编译失败

ub16或者ub18上实践田宇大佬的64位操作系统的设计与实现,因为环境的原因,书中提供的代码并不能完全编译成功,前面我写了实现64位操作系统的问题解决系列:(一)和(二)基本编译到程序4-10都不会出问题,但是到程序4-11就会 因为__switch_to符号未定义,编译失败。

问题描述

经过实现64位操作系统的问题解决系列:(一)和(二)
修改代码后,如下
代码1

#define switch_to(prev,next)			\
do{							\
	__asm__ __volatile__ (	"pushq	%%rbp	\n\t"	\
				"pushq	%%rax	\n\t"	\
				"movq	%%rsp,	%0	\n\t"	\
				"movq	%2,	%%rsp	\n\t"	\
				"leaq	1f(%%rip),	%%rax	\n\t"	\
				"movq	%%rax,	%1	\n\t"	\
				"pushq	%3		\n\t"	\
				"jmp	__switch_to	\n\t"	\
				"1:	\n\t"	\
				"popq	%%rax	\n\t"	\
				"popq	%%rbp	\n\t"	\
				:"=m"(prev->thread->rsp),"=m"(prev->thread->rip)\
				:"m"(next->thread->rsp),"m"(next->thread->rip),"D"(prev),"S"(next)	\
				:"memory"		\
				);			\
}while(0)

代码2

static inline void __switch_to(struct task_struct *prev,struct task_struct *next) //最初的代码只有inline
{

	init_tss[0].rsp0 = next->thread->rsp0;

	set_tss64(init_tss[0].rsp0, init_tss[0].rsp1, init_tss[0].rsp2, init_tss[0].ist1, init_tss[0].ist2, init_tss[0].ist3, init_tss[0].ist4, init_tss[0].ist5, init_tss[0].ist6, init_tss[0].ist7);

	__asm__ __volatile__("movq	%%fs,	%0 \n\t":"=a"(prev->thread->fs));
	__asm__ __volatile__("movq	%%gs,	%0 \n\t":"=a"(prev->thread->gs));

	__asm__ __volatile__("movq	%0,	%%fs \n\t"::"a"(next->thread->fs));
	__asm__ __volatile__("movq	%0,	%%gs \n\t"::"a"(next->thread->gs));

	color_printk(WHITE,BLACK,"prev->thread->rsp0:%#018lx\n",prev->thread->rsp0);
	color_printk(WHITE,BLACK,"next->thread->rsp0:%#018lx\n",next->thread->rsp0);
}

编译的时候,"jmp __switch_to \n\t" \,中找不到"__switch_to这个函数的定义(尽管我们看起来已经定义了他static inline void __switch_to(struct task_struct *prev,struct task_struct *next)

折中的解决方案

static inline void __switch_to(struct task_struct *prev,struct task_struct *next)函数变成全局函数,让其全局可见。

void __switch_to(struct task_struct *prev,struct task_struct *next)

去掉static inline便可以编译通过

最终结果

如果有其他问题,留言交流
在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值