Skip to content

Commit

Permalink
Merge pull request yuan-xy#4 from icecity96/master
Browse files Browse the repository at this point in the history
Update Makefile.header
  • Loading branch information
yuan authored Dec 7, 2016
2 parents 2b3ac10 + b981ef5 commit e2fd6f5
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 19 deletions.
133 changes: 133 additions & 0 deletions .gdb_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
target remote :1234
break s
break startup
break quit
exit
q()
quit()
exit
exit()
help
q
target remote : 1234
b init
c
registerinfo
info registers
q
q
continue
c
target remote : 1234
c
q
target remote : 1234
b main
s
ls
l
q
q
target remote : 1234
b init
c
n
n
n
n
n
l
n
n
n
n
n
n
n
n
q
target remote : 1234
b main.c:135
c
n
n
n
n
n
s
n
p
q
target remote : 1234
b main:move_to_user_mode
b main:137
b main.c:137
c
l
n
info registers
n
set follow-fork-mode child
n
n
q
target remote : 1234
b main.c:139
c
n
set follow-fork-mode child
n
n
q
q
target remote : 1234
b main.c:142
set follow-fork-mode child
c
q
target remote : 1234
b main.c:140
b main.c:142
c
n
q
q
target remote : 1234
b main.c:141
c
p pid
n
p pid
attach 1
q
target remote : 1234
b main.c:141
b main.c:143
set follow-fork-mode main.c:143
set follow-fork-mode child main.c:143
c
n
q
target remote : 1234
quit
target remote : 1234
b main.c:122
c
q
target remote : 1234
b main.c:90
c
n
set follow-fork-mode child
n
q
target remote : 1234
b main.c:90
c
n
set follow-fork-mode child
n
q
target remote : 1234
b main.c:175
c
6 changes: 4 additions & 2 deletions Makefile.header
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ ifeq ($(UNAME), Darwin)
LD = i386-elf-ld
#LDFLAGS = -m elf_i386 -x
LDFLAGS = -m elf_i386
CC = i386-elf-gcc-4.3.2
#CC = i386-elf-gcc-4.3.2
CC = i386-elf-gcc
CFLAGS = -gdwarf-2 -g3 -m32 -fno-builtin -fno-stack-protector -fomit-frame-pointer -fstrength-reduce #-Wall

CPP = i386-elf-cpp-4.3.2 -nostdinc
#CPP = i386-elf-cpp-4.3.2 -nostdinc
CPP = i386-elf-cpp -nostdinc
AR =i386-elf-ar
STRIP = i386-elf-strip
OBJCOPY = i386-elf-objcopy
Expand Down
31 changes: 20 additions & 11 deletions boot/bootsect.s
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@

# ROOT_DEV: 0x000 - same type of floppy as boot.
# 0x301 - first partition on first drive etc
#
##和源码不同,源码中是0x306 第2块硬盘的第一个分区
#
.equ ROOT_DEV, 0x301
ljmp $BOOTSEG, $_start
_start:
mov $BOOTSEG, %ax
mov $BOOTSEG, %ax #将ds段寄存器设置为0x7C0
mov %ax, %ds
mov $INITSEG, %ax
mov $INITSEG, %ax #将es段寄存器设置为0x900
mov %ax, %es
mov $256, %cx
sub %si, %si
sub %di, %di
rep
movsw
ljmp $INITSEG, $go
go: mov %cs, %ax
mov $256, %cx #设置移动计数值256字
sub %si, %si #源地址 ds:si = 0x07C0:0x0000
sub %di, %di #目标地址 es:si = 0x9000:0x0000
rep #重复执行并递减cx的值
movsw #从内存[si]处移动cx个字到[di]处
ljmp $INITSEG, $go #段间跳转,这里INITSEG指出跳转到的段地址,解释了cs的值为0x9000
go: mov %cs, %ax #将ds,es,ss都设置成移动后代码所在的段处(0x9000)
mov %ax, %ds
mov %ax, %es
# put stack at 0x9ff00.
Expand All @@ -65,6 +68,12 @@ go: mov %cs, %ax
# load the setup-sectors directly after the bootblock.
# Note that 'es' is already set up.

#
##ah=0x02 读磁盘扇区到内存 al=需要独出的扇区数量
##ch=磁道(柱面)号的低八位 cl=开始扇区(位0-5),磁道号高2位(位6-7)
##dh=磁头号 dl=驱动器号(硬盘则7要置位)
##es:bx ->指向数据缓冲区;如果出错则CF标志置位,ah中是出错码
#
load_setup:
mov $0x0000, %dx # drive 0, head 0
mov $0x0002, %cx # sector 2, track 0
Expand Down Expand Up @@ -97,7 +106,7 @@ ok_load_setup:
xor %bh, %bh
int $0x10

mov $24, %cx
mov $30, %cx
mov $0x0007, %bx # page 0, attribute 7 (normal)
#lea msg1, %bp
mov $msg1, %bp
Expand Down Expand Up @@ -246,7 +255,7 @@ sectors:

msg1:
.byte 13,10
.ascii "Loading system ..."
.ascii "IceCityOS is booting ..."
.byte 13,10,13,10

.org 508
Expand Down
139 changes: 136 additions & 3 deletions boot/setup.s
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,23 @@

ljmp $SETUPSEG, $_start
_start:

mov %cs,%ax
mov %ax,%ds
mov %ax,%es
#
##print some message
#
mov $0x03, %ah
xor %bh, %bh
int $0x10

mov $29, %cx
mov $0x000b,%bx
mov $msg2,%bp
mov $0x1301, %ax
int $0x10
# ok, the read went well so we get current cursor position and save it for
# posterity.

mov $INITSEG, %ax # this is done in bootsect already, but...
mov %ax, %ds
mov $0x03, %ah # read cursor pos
Expand Down Expand Up @@ -87,6 +100,84 @@ _start:
rep
movsb

## modify ds
mov $INITSEG,%ax
mov %ax,%ds
mov $SETUPSEG,%ax
mov %ax,%es

##show cursor pos:
mov $0x03, %ah
xor %bh,%bh
int $0x10
mov $11,%cx
mov $0x000c,%bx
mov $cur,%bp
mov $0x1301,%ax
int $0x10
##show detail
mov %ds:0 ,%ax
call print_hex
call print_nl

##show memory size
mov $0x03, %ah
xor %bh, %bh
int $0x10
mov $12, %cx
mov $0x000a, %bx
mov $mem, %bp
mov $0x1301, %ax
int $0x10

##show detail
mov %ds:2 , %ax
call print_hex

##show
mov $0x03, %ah
xor %bh, %bh
int $0x10
mov $25, %cx
mov $0x000d, %bx
mov $cyl, %bp
mov $0x1301, %ax
int $0x10
##show detail
mov %ds:0x80, %ax
call print_hex
call print_nl

##show
mov $0x03, %ah
xor %bh, %bh
int $0x10
mov $8, %cx
mov $0x000e, %bx
mov $head, %bp
mov $0x1301, %ax
int $0x10
##show detail
mov %ds:0x82, %ax
call print_hex
call print_nl

##show
mov $0x03, %ah
xor %bh, %bh
int $0x10
mov $8, %cx
mov $0x000f, %bx
mov $sect, %bp
mov $0x1301, %ax
int $0x10
##show detail
mov %ds:0x8e, %ax
call print_hex
call print_nl
#l:
# jmp l
##
# Check that there IS a hd1 :-)

mov $0x01500, %ax
Expand Down Expand Up @@ -233,7 +324,49 @@ gdt_48:
.word 0x800 # gdt limit=2048, 256 GDT entries
.word 512+gdt, 0x9 # gdt base = 0X9xxxx,
# 512+gdt is the real gdt after setup is moved to 0x9020 * 0x10

print_hex:
mov $4,%cx
mov %ax,%dx

print_digit:
rol $4,%dx #循环以使低4位用上,高4位移至低4位
mov $0xe0f,%ax #ah = 请求的功能值,al = 半个字节的掩码
and %dl,%al
add $0x30,%al
cmp $0x3a,%al
jl outp
add $0x07,%al

outp:
int $0x10
loop print_digit
ret
#打印回车换行
print_nl:
mov $0xe0d,%ax
int $0x10
mov $0xa,%al
int $0x10
ret

msg2:
.byte 13,10
.ascii "Now we are in setup ..."
.byte 13,10,13,10
cur:
.ascii "Cursor POS:"
mem:
.ascii "Memory SIZE:"
cyl:
.ascii "KB"
.byte 13,10,13,10
.ascii "HD Info"
.byte 13,10
.ascii "Cylinders:"
head:
.ascii "Headers:"
sect:
.ascii "Secotrs:"
.text
endtext:
.data
Expand Down
Binary file modified hdc-0.11.img
Binary file not shown.
4 changes: 3 additions & 1 deletion include/linux/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ extern int sys_sgetmask();
extern int sys_ssetmask();
extern int sys_setreuid();
extern int sys_setregid();
extern int sys_iam();
extern int sys_whoami();

fn_ptr sys_call_table[] = { sys_setup, sys_exit, sys_fork, sys_read,
sys_write, sys_open, sys_close, sys_waitpid, sys_creat, sys_link,
Expand All @@ -83,4 +85,4 @@ sys_getgid, sys_signal, sys_geteuid, sys_getegid, sys_acct, sys_phys,
sys_lock, sys_ioctl, sys_fcntl, sys_mpx, sys_setpgid, sys_ulimit,
sys_uname, sys_umask, sys_chroot, sys_ustat, sys_dup2, sys_getppid,
sys_getpgrp, sys_setsid, sys_sigaction, sys_sgetmask, sys_ssetmask,
sys_setreuid,sys_setregid };
sys_setreuid,sys_setregid, sys_iam, sys_whoami };
2 changes: 2 additions & 0 deletions include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
#define __NR_ssetmask 69
#define __NR_setreuid 70
#define __NR_setregid 71
#define __NR_iam 72
#define __NR_whoami 73

#define _syscall0(type,name) \
type name(void) \
Expand Down
Loading

0 comments on commit e2fd6f5

Please sign in to comment.