Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions step_3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ LOADER=loader
ROOT=..
FILESYSTEM=filesystem
USER=user
all: $(USER)/stone.bin $(KERNEL)/kernel.bin $(LOADER)/loader.bin build cleangch
STONE=stone
STONE_OBJ=$(USER)/$(STONE)/stoneQ.bin $(USER)/$(STONE)/stoneW.bin $(USER)/$(STONE)/stoneA.bin $(USER)/$(STONE)/stoneS.bin
all: $(STONE_OBJ) $(KERNEL)/kernel.bin $(LOADER)/loader.bin build cleangch

$(KERNEL)/kernel.bin:
echo "\n"
Expand Down Expand Up @@ -43,20 +45,36 @@ $(FILESYSTEM)/datablock.bin:
cd $(FILESYSTEM)/ && make
cd $(ROOT)/

$(USER)/stone.bin:
$(USER)/$(STONE)/stoneQ.bin:
echo "\n"
cd $(USER)/ && make
cd $(ROOT)/
$(USER)/$(STONE)/stoneW.bin:
echo "\n"
cd $(USER)/ && make
cd $(ROOT)/
$(USER)/$(STONE)/stoneA.bin:
echo "\n"
cd $(USER)/ && make
cd $(ROOT)/
$(USER)/$(STONE)/stoneS.bin:
echo "\n"
cd $(USER)/ && make
cd $(ROOT)/


build: $(LOADER)/loader.bin $(FILESYSTEM)/DBR.bin $(FILESYSTEM)/FAT.bin $(FILESYSTEM)/datablock.bin
build: $(LOADER)/loader.bin $(FILESYSTEM)/DBR.bin $(FILESYSTEM)/FAT.bin $(FILESYSTEM)/datablock.bin $(STONE_OBJ)
echo "\n"
dd if=$(LOADER)/loader.bin of=OS.img conv=notrunc
dd if=$(FILESYSTEM)/DBR.bin of=OS.img conv=notrunc oflag=seek_bytes seek=512
dd if=$(FILESYSTEM)/FAT.bin of=OS.img conv=notrunc oflag=seek_bytes seek=1536
dd if=$(FILESYSTEM)/FAT.bin of=OS.img conv=notrunc oflag=seek_bytes seek=3584
dd if=$(FILESYSTEM)/datablock.bin of=OS.img conv=notrunc oflag=seek_bytes seek=6656
dd if=$(KERNEL)/kernel.bin of=OS.img conv=notrunc oflag=seek_bytes seek=7680
dd if=$(USER)/stone.bin of=OS.img conv=notrunc oflag=seek_bytes seek=12800
dd if=$(USER)/$(STONE)/stoneQ.bin of=OS.img conv=notrunc oflag=seek_bytes seek=12800
dd if=$(USER)/$(STONE)/stoneW.bin of=OS.img conv=notrunc oflag=seek_bytes seek=14848
dd if=$(USER)/$(STONE)/stoneA.bin of=OS.img conv=notrunc oflag=seek_bytes seek=16896
dd if=$(USER)/$(STONE)/stoneS.bin of=OS.img conv=notrunc oflag=seek_bytes seek=18944
clean:
echo "\n"
find . -name "*.bin" -type f -delete
Expand Down
29 changes: 28 additions & 1 deletion step_3/filesystem/FAT.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,32 @@ FAT_ITEM_T fat_items[] = {
0xFFFF, // 11
0xFFFF, // 12
0xFFFF, // 13
0xFFFF, //14
0x000F, // 14
0x0010, // 15
0x0011, // 16
0xFFFF, // 17
0x0013, // 18
0x0014, // 19
0x0015, // 20
0xFFFF, // 21
0x0017, // 22
0x0018, // 23
0x0019, // 24
0xFFFF, // 25
0x001B, // 26
0x001C, // 27
0x001D, // 28
0xFFFF, // 29
0xFFFF, // 30
0xFFFF, // 31
0xFFFF, // 32
0xFFFF, // 33
0xFFFF, // 34
0xFFFF, // 35
0xFFFF, // 36
0xFFFF, // 37
0xFFFF, // 38
0xFFFF, // 39
0xFFFF, // 40
0xFFFF, // 41
};
12 changes: 10 additions & 2 deletions step_3/filesystem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ FAT表2 8-11扇区(4个)512*7 = 3584 [e00~1600]
内核程序 16-23 512*15= 7680 [1e00~2e00]
home/ 24 [2e00~3000]
msg 25 [3000~3200]
用户程序 26-29 512*25=12800 [3200~3a00]
用户程序q 26-29 512*25=12800 [3200~3a00]
用户程序w 30-33 512*29=14848 [3a00~4200]
用户程序a 34-37 512*33=16896 [4200~4a00]
用户程序s 38-41 512*37=18944 [4a00~5200]
## 软盘结构
; 磁道 面 扇区
; 0~79 0~1 1~18

1 0 2
逻辑扇区 面 运算后的结果
1~18 0 -1/18-> 0
19~36 1 -1/18-> 1
37~54 0 -1/18-> 2
55~72 1 -1/18-> 3
## 内存结构
1:0x7C00: MBR(loader)
2:0x7E00: DBR
Expand Down
35 changes: 33 additions & 2 deletions step_3/filesystem/datablock.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,44 @@ FAT_ITEM msg = {
13,
0
};
FAT_ITEM user_program = {
"stone",
FAT_ITEM user_programQ = {
"stoneQ",
"bin",
FAT_rw,
0, 0, 0, 0, 0, 0,
0,
0,
14,
512*4 // 4 sectors
};

FAT_ITEM user_programW = {
"stoneW",
"bin",
FAT_rw,
0, 0, 0, 0, 0, 0,
0,
0,
18,
512*4 // 4 sectors
};
FAT_ITEM user_programA = {
"stoneA",
"bin",
FAT_rw,
0, 0, 0, 0, 0, 0,
0,
0,
22,
512*4 // 4 sectors
};
FAT_ITEM user_programS = {
"stoneS",
"bin",
FAT_rw,
0, 0, 0, 0, 0, 0,
0,
0,
26,
512*4 // 4 sectors
};
2 changes: 1 addition & 1 deletion step_3/filesystem/fsutilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __FS_UTILITIES_H_
#include <stdint.h>
#define lgsector2sector(X) (((X-1)%18)+1)
#define lgsector2head(X) ((X-1)/18)
#define lgsector2head(X) (((X-1)/18)%2)
#define lgsector2track(X) ((X-1)/36)
void loadSector(uint16_t track, uint16_t head, uint16_t sector, uint16_t addr, uint16_t num);
static inline void loadLogicSector(uint16_t lgsector, uint16_t addr, uint16_t num) {
Expand Down
6 changes: 5 additions & 1 deletion step_3/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ ROOT=..
INCLUDE=../include
USER=../user
FILESYSTEM=../filesystem
STONE=stone

USER_HEADER=$(USER)/user.h $(USER)/terminal.h
USER_OBJ=$(USER)/user.o $(USER)/terminal.o $(USER)/stone.o
USER_OBJ=$(USER)/user.o $(USER)/terminal.o

all: kernel.bin

Expand All @@ -31,6 +32,9 @@ $(INCLUDE)/mystring.o:
$(FILESYSTEM)/fsutilities.o:
cd $(FILESYSTEM)/ && make
cd ../kernel
$(USER)/$(STONE)/stoneQ.o:
cd $(USER)/ && make
cd ../kernel
clean:
rm *.bin -f
rm *.o -f
Expand Down
1 change: 1 addition & 0 deletions step_3/kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define true 1
#define false 0
int main() {
// __load_program("stoneS");
clear_screen();
draw_str("enter help to get help", 0, 30);
//draw_char_style('A', 0, 10, G_DEFAULT);
Expand Down
29 changes: 23 additions & 6 deletions step_3/user/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,35 @@ AS=nasm
ASFLAGS=

UTILITIES=../include

all: user.o terminal.o stone.bin
STONE=stone
STONE_BIN = $(STONE)/stoneQ.bin $(STONE)/stoneW.bin $(STONE)/stoneA.bin $(STONE)/stoneS.bin
all: user.o terminal.o $(STONE_BIN)

user.o: user.c $(UTILITIES)/utilities.h
$(CC) $(CCFLAGS) -c $^
terminal.o: terminal.c $(UTILITIES)/utilities.h stone.h
terminal.o: terminal.c $(UTILITIES)/utilities.h
$(CC) $(CCFLAGS) -c $^

stone.bin: stone.o $(UTILITIES)/utilities.o
$(STONE)/stoneQ.bin: $(STONE)/stoneQ.o $(UTILITIES)/utilities.o
$(LD) $(LDFLAGS) -Ttext 0x6C00 --oformat binary -o $@ $^
stone.o: stone.c $(UTILITIES)/utilities.h
$(CC) $(CCFLAGS) -c $^
$(STONE)/stoneQ.o: $(STONE)/stone.c $(UTILITIES)/utilities.h
$(CC) $(CCFLAGS) -c $< -D UL -o $@

$(STONE)/stoneW.bin: $(STONE)/stoneW.o $(UTILITIES)/utilities.o
$(LD) $(LDFLAGS) -Ttext 0x6C00 --oformat binary -o $@ $^
$(STONE)/stoneW.o: $(STONE)/stone.c $(UTILITIES)/utilities.h
$(CC) $(CCFLAGS) -c $< -D UR -o $@

$(STONE)/stoneS.bin: $(STONE)/stoneS.o $(UTILITIES)/utilities.o
$(LD) $(LDFLAGS) -Ttext 0x6C00 --oformat binary -o $@ $^
$(STONE)/stoneS.o: $(STONE)/stone.c $(UTILITIES)/utilities.h
$(CC) $(CCFLAGS) -c $< -D DR -o $@

$(STONE)/stoneA.bin: $(STONE)/stoneA.o $(UTILITIES)/utilities.o
$(LD) $(LDFLAGS) -Ttext 0x6C00 --oformat binary -o $@ $^
$(STONE)/stoneA.o: $(STONE)/stone.c $(UTILITIES)/utilities.h
$(CC) $(CCFLAGS) -c $< -D DL -o $@


$(UTILITIES)/utilities.o:
cd $(UTILITIES)/ && make
Expand Down
4 changes: 0 additions & 4 deletions step_3/user/stone.h

This file was deleted.

22 changes: 13 additions & 9 deletions step_3/user/stone.c → step_3/user/stone/stone.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
__asm__("jmpl $0, $stone\n");

#include "../include/utilities.h"
#define DELAY (1e5)
#include "../../include/utilities.h"
#include "stone.h"
#define DELAY (5 * 1e5)
int getKbHit();
void checkBound();

Expand All @@ -11,10 +12,11 @@ int deltax;
int deltay;
int stone() {
// return 0;
x = 5;
y = 5;
x = _X;
y = _Y;
deltax = 1;
deltay = 1;
uint8_t style = 0;

clear_screen();
while(1) {
Expand All @@ -24,11 +26,13 @@ int stone() {
int delay = DELAY;
while ((--delay) >= 0) continue;

draw_str(" ", y, x);
x += deltax;
y += deltay;

checkBound();
draw_str("A", y, x);
draw_str_style("A", y, x, style & 15);
style++;
}
}

Expand All @@ -41,8 +45,8 @@ int getKbHit() {
return 0;
}
void checkBound() {
if (x == 0) deltax = 1;
if (x == 79) deltax = -1;
if (y == 0) deltay = 1;
if (y == 24) deltay = -1;
if (x <= LEFT_B) deltax = 1;
if (x >= RIGHT_B) deltax = -1;
if (y <= UP_B) deltay = 1;
if (y >= DOWN_B) deltay = -1;
}
33 changes: 33 additions & 0 deletions step_3/user/stone/stone.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef __STONE_H_
#define __STONE_H_
#if defined(UL)
#define _X 5
#define _Y 5
#define LEFT_B 1
#define RIGHT_B 40
#define UP_B 1
#define DOWN_B 12
#elif defined(UR)
#define _X 70
#define _Y 5
#define LEFT_B 40
#define RIGHT_B 79
#define UP_B 1
#define DOWN_B 12
#elif defined(DL)
#define _X 5
#define _Y 20
#define LEFT_B 1
#define RIGHT_B 40
#define UP_B 13
#define DOWN_B 24
#elif defined(DR)
#define _X 70
#define _Y 20
#define LEFT_B 40
#define RIGHT_B 79
#define UP_B 13
#define DOWN_B 24
#endif

#endif
5 changes: 4 additions & 1 deletion step_3/user/terminal.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "../include/utilities.h"
#include "../include/mystring.h"
#include "stone.h"
#include "../filesystem/API/fsapi.h"

#define BACK_SPACE 8
Expand Down Expand Up @@ -95,11 +94,15 @@ void parseCMD(int CMDindex) {
FAT_ITEM* pfat = CUR_DIR;
if (__FAT_showable_item(pfat)) {
putln(pfat->filename);
// putiln(pfat->blow_cluster);
// putiln(pfat->filesize);
}
while (__has_next_item(pfat)) {
pfat = __next_item(pfat);
if (__FAT_showable_item(pfat)) {
putln(pfat->filename);
// putiln(pfat->blow_cluster);
// putiln(pfat->filesize);
}
}
}
Expand Down