俺啥也不懂-不知道什么时候才会编写操作系统-先写Hello World

先搭环境

相关书籍:自备,《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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值