从零开始搭建环境编写操作系统 AT&T GCC (三)引入C语言

  搁置了几天,继续我们的操作系统,今天我们的主题是引入C语言,毕竟有了C语言这个工具,开发就便捷了很多,我们C语言依然使用GCC编译器,现在我们有几个事情没有完成,中断没有打开,段选择子没有设置,先把中断搁置一下,把段选择子分配了。
一、段选择子segment selector的分配
  在start_protect这个函数中,暂时分配给ds段二号全局描述符,给ss分配三号全局描述符,这里赘述一下寄存器操作方面的知识,可能有些知识是8086的,用在386上不太正确,恳请改正。
  寄存器寻址的方式,因为汇编用的不多,寄存器寻址每次都是最不熟练的,这里给我自己总结一下:
   1. 立即寻址:立即数寻址
   2.寄存器寻址:用寄存器寻址
   3.直接寻址:直接从内存中取数据,前三个都很简单,后边的还能hold住么?
   4.寄存器间接寻址:80386以上cpu可以使用esp之外其他所有通用寄存器,其中ebp的默认段是ss,其他所有的默认段都是ds
   5.寄存器相对寻址:80386以上cpu可以使用esp之外其他所有通用寄存器,其中ebp的默认段是ss,其他所有的默认段都是ds
   6.基址变址寻址:基址寄存器ebx ebp,变址寄存器除了esp都可以用,带有ebp时缺省段是ss,其他情况都是ds
   7.基址变址寻址相对寻址:基址寄存器ebx ebp,变址寄存器除了esp都可以用,带有ebp时缺省段是ss,其他情况都是ds(6.7.的知识还是基于8086的,不知道80386有没有改进)
   另外在 AT&T 汇编格式中,内存操作数的寻址方式是section:disp(base, index, scale)
   32位线性地址下物理地址的计算方式是disp + base + index * scale
   干货就这些,够用了,看代码

start_protect:
.code32
    movw    $0x0010,   %ax
    movw    %ax,        %ds
    movw    $0x0018,   %ax
    movw    %ax,        %s
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一个小型的操作系统,采用gcc进行开发,几千行的代码,方便初学者学习,内含有编译好的映像文件,及bochs模拟器配置文件,可在bochs下模拟运行。如下为源码包内的README文件: # # Snixos Project version 1.0, 2003.6 # (C) Copyright 2003,2004,2005 Jockeyson,KeqianGao # All Rights Reserved. # Distributed under the terms of the GNU General Public License. # # This program is a free and open source software and you can redistribute # it and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation. As no any liability is assumed # for any incidental or consequential damages in connection with the # information or program fragments contained herein,so any exception arised # is at your own risk. It is ABSOLUTELY WITHOUT ANY WARRANTY. # Bug report please send to [email protected] . # 0. What is Snixos Project? Snixos Project is an experimental operating system designed by Jockeyson , KeqianGao aiming at multitask/multithread, Chinese envionment including Chinese characters input and ouput etc... 1. What you need to run Snixos PC with the following minimum configuration: CPU: i386 or above MEM: 2M extended memory or more DISPLAY: VGA or above Floppy Drive: 1.44M 2. Compile Environment RH Linux 7.2 or above (kernel 2.4.7-10 ) NASM 0.98 gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98) 3. Compile and install a. unpack the source package tar zxvf snixos_x.x_YYYYMMDD_HHMMSS.tgz b. cd to snixos cd snixos c. before make insert a 1.44M floppy in drive c.1 to make snixos run in VGA text mode make clean make VIDEO=TEXT diskimg make floppy c.2 to make snixos run VGA graphics mode make clean make diskimg make floppy d. bootup with the floppy just created in step c also you can follow this way to run snixos in bochs either in Windows or Linux a. just as the above b. just as the above c. invoke these command: make clean; make diskimg you'll get a snixos ima

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值