编写操作系统有多难_学完C语言再学Linux吗

编写操作系统有多难_学完C语言再学Linux吗先搭环境相关书籍:自备,《30天自制操作系统》,于渊的《自己动手写操作系统》,王爽的《汇编语言》,各位大神的书,请各位自行阅读,俺只是代码的搬运工代码放在git上:https://github.com/qdhjkztm

编写操作系统有多难_学完C语言再学Linux吗"

先搭环境

相关书籍:自备,《30天自制操作系统》,于渊的《自己动手写操作系统》,王爽的《汇编语言》,各位大神的书,请各位自行阅读,俺只是代码的搬运工

代码放在git上:https://github.com/qdhjkztm/study.git,可以作为参考

开发工具:vs code

开发使用操作系统:win10

虚拟机:自备

编译环境:centos7

所需技能:shell,汇编,nasm,makefile,git,c吧

所以,开发流程是win10下使用vs code开发(ctrl-c+ctrl-v),然后提交到github,虚拟机下centos下用git下载代码进行编译。对于编译后的img文件,在虚拟机下查看结果,至于如何调试os,还没学会

参考内容

https://asmtutor.com/,nasm汇编学习

https://github.com/wlmnzf/oranges.git,这个代码应该是来自于渊的《自己动手写操作系统》,若果有问题,请指正,随时候着删除。

linux下代码架构

myAll

—-study(从git上clone)

——–huibian(以前代码全来自https://asmtutor.com/)

—————–lesson1

—————–lesson2

—————–lesson3

—————–等等

——–os

—————-day1

—————-day2

—————-等等

——–make.sh(接收execute.sh传过来的参数,决定编译哪个文件夹下的内容)

—-output(make编译输出)

——–huibian(输出汇编编译结果)

——–os(输出os编译结果)

———execute.sh(负责从git上拉代码,并编译)

编译举例

    cd  /usr/loca/myAll/output

    sh execute.sh h lesson1

    cd huibian

    ./main

execute.sh参考

#!/bin/bash
cd /usr/local/myAll/study
git pull https://github.com/qdhjkztm/study.git
sh make.sh $1 $2

make.sh参考

#!/bin/bash
rootPath=/usr/local/myAll/study
outputFilePath=/usr/local/myAll/output
if [ $1 == "c" ] ;then
        echo "进入c文件夹"
        cd $rootPath/c/release/
        echo "清除可能存在的编译"
        make clean
        echo "开始编译"
        make
        echo "结束编译"
        echo "进入编译后的文件夹"
        cd $outputFilePath/c
        echo "开始执行"
        ./main
elif [ $1 == "h" ] ;then
        echo "进入汇编文件夹"
        cd $rootPath/huibian
        for dir in `ls`
        do
                if [ $dir == $2 ] ; then
                        echo "开始进入:${dir}"
                        cd $dir
                        echo '开始清理'
                        make clean
                        echo '开始编译'
                        make
                        echo '结束编译'
                fi
        done

        echo "进入编译后的文件夹"
        cd $outputFilePath/huibian
        echo "开始执行"
        ./main
elif [ $1 == "o" ] ;then
        echo "进入os文件夹"
        cd $rootPath/os
        for dir in `ls`
        do
                if [ $dir == $2 ];then
                        echo "开始进入:${dir}"
                        cd $dir

                        echo '开始清理'
                        make clean
                        echo '开始编译'
                        make
                        echo '结束编译'
                fi
        done
fi

先来一个hello world,lesson1.asm

section .data
msg:
    db "hello, world", 10
len equ $-msg

section .text
global main
main:
    mov edx, len
    mov ecx, msg
    mov ebx, 1
    mov eax, 4 ;直接使用sys_write系统调用
    int 0x80

    mov ebx, 0
    mov eax, 1
    int 0x80

makefile编译,makefile

outputFilePath=/usr/local/myAll/output/huibian/
OBJ = $(outputFilePath)lesson1.o
TARGET=$(outputFilePath)main
RM = rm -f
$(TARGET):$(OBJ)
	gcc -g -o $@ $<
$(OBJ):$(outputFilePath)%.o:%.asm
	nasm -f elf64 -g $<
clean:
	rm -f $(TARGET) *.o

如果您的文件夹结构和上面的相同:

请执行

    cd  /usr/loca/myAll/output

    sh execute.sh h lesson1

    cd huibian

    ./main

如果不相同,请自行修改outputFilePath路径,也可以默认为当前路径

没讲解,回头改

俺啥也不懂-不知道什么时候才会编写操作系统-再写Hello World-第一版makefile

今天的文章编写操作系统有多难_学完C语言再学Linux吗分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:http://bianchenghao.cn/79409.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注