Skip to content

Commit

Permalink
Merge pull request #71 from bassaer/develop
Browse files Browse the repository at this point in the history
[ver 1.14.0] improve time and rename struct
  • Loading branch information
bassaer committed Mar 7, 2020
2 parents e85e002 + fc695a2 commit 777f728
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 85 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## ver 1.14.0
- improve timer intr handler
- rename struct

## ver 1.13.0
- support multiple timer

Expand Down
2 changes: 1 addition & 1 deletion bin/free.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int free() {
"free : %dMB\n"
"used : %dMB";

struct mem_info mem = {
mem_t mem = {
0, 0, 0, 0, 0, 0
};
stats(&mem);
Expand Down
12 changes: 6 additions & 6 deletions bin/sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int max_width = 0;
/**
* 入力情報
*/
struct entry {
typedef struct {
/**
* 入力文字列
*/
Expand All @@ -32,14 +32,14 @@ struct entry {
* 現在の入力位置
*/
int index;
};
} entry_t;

struct entry entries[SCREEN_HEIGHT];
entry_t entries[SCREEN_HEIGHT];

/**
* 入力履歴一時保存用
*/
struct entry cache_entry;
entry_t cache_entry;

void init_shell() {
init_console();
Expand Down Expand Up @@ -78,7 +78,7 @@ void init_entry() {
selected_line = cur_line;
}

void copy_entry(struct entry *src, struct entry *dst) {
void copy_entry(entry_t *src, entry_t *dst) {
dst->index = src->index;
strcpy(src->buf, dst->buf);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ void exec_cmd() {
}
}

void start_shell(struct Queue *queue) {
void start_shell(queue_t *queue) {
unsigned char code;
dequeue(queue, &code);
input_code(code);
Expand Down
4 changes: 2 additions & 2 deletions bin/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ int sleep(char *args[], int size) {
return EXIT_FAILURE;
}

struct Timer *timer = new_timer();
timer_t *timer = new_timer();
if(timer == 0) {
printf("failed to make timer\n");
return EXIT_FAILURE;
}

struct Queue queue;
queue_t queue;
unsigned char buf[8];
init_queue(&queue, 8, buf);

Expand Down
12 changes: 6 additions & 6 deletions include/dsctbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@
#define IDT_ADDR 0x0026f800
#define IDT_LIMIT 0x000007ff

struct SEGMENT_DESCRIPTOR {
typedef struct {
short limit_low;
short base_low;
char base_mid;
char access_right;
char limit_high;
char base_high;
};
} segment_descriptor_t;

struct GATE_DESCRIPTOR {
typedef struct {
short offset_low;
short selector;
char dw_count;
char access_right;
short offset_high;
};
} gate_descriptor_t;

void init_gdtidt();
void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar);
void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar);
void set_segmdesc(segment_descriptor_t *sd, unsigned int limit, int base, int ar);
void set_gatedesc(gate_descriptor_t *gd, int offset, int selector, int ar);

#endif
6 changes: 3 additions & 3 deletions include/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
/**
* 特殊キー
*/
enum Key {
enum key {
UP = 0x48,
DOWN = 0x50,
BACKSPACE = 0x0E
};

#include <lib/queue.h>

struct KEYBUF {
struct keybuffer {
char data;
unsigned char flag;
} keybuf;

void wait_keyboard();
void init_keyboard(struct Queue *q);
void init_keyboard(queue_t *q);

void handle_intr(int *esp);
void handle_intr27(int *esp);
Expand Down
12 changes: 6 additions & 6 deletions include/lib/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

#define FLAGS_OVERRUN 0x0001

struct Queue {
typedef struct {
unsigned char *buf; // 入力バッファ
int next_w; // 次回の書き込み先
int next_r; // 次回の読み込み先
int size; // バッファサイズ
int free; // バッファの空きサイズ
int flags; // 入力あふれフラグ
};
} queue_t;

void init_queue(struct Queue *queue, int size, unsigned char *buf);
void init_queue(queue_t *queue, int size, unsigned char *buf);

int enqueue(struct Queue *queue, unsigned char data);
int enqueue(queue_t *queue, unsigned char data);

int dequeue(struct Queue *queue, unsigned char *data);
int dequeue(queue_t *queue, unsigned char *data);

int queue_status(struct Queue *queue);
int queue_status(queue_t *queue);

#endif
11 changes: 0 additions & 11 deletions include/main.h

This file was deleted.

4 changes: 2 additions & 2 deletions include/mm/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

extern unsigned int _KERN_END;

struct mem_info {
typedef struct {
/** 総メモリサイズ*/
unsigned int total_bytes;
/** 総ブロック数*/
Expand All @@ -34,7 +34,7 @@ struct mem_info {
unsigned int *bitmap;
/** ビットマップ長 */
unsigned int bitmap_size;
};
} mem_t;

unsigned int get_kernel_size();

Expand Down
35 changes: 23 additions & 12 deletions include/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,45 @@

#define TIMER_MAX_NUM 500

enum TimerStatus {
enum timer_status {
STOPPED,
READY,
RUNNING
};

struct Timer {
typedef struct {
unsigned int timeout;
enum TimerStatus status;
struct Queue *queue;
enum timer_status status;
queue_t *queue;
unsigned char data;
};
} timer_t;

struct TimerCtrl {
typedef struct {
// システム起動時間
unsigned int uptime;
struct Timer timers[TIMER_MAX_NUM];
} timerctrl;
// 次回のタイマー
unsigned int next;
// 現在稼働中のタイマー
unsigned int running_num;
// ソート済みタイマーのリスト
timer_t *sorted_timers[TIMER_MAX_NUM];
// すべてのタイマーリスト
timer_t all_timers[TIMER_MAX_NUM];
} timerctrl_t;

// カーネル内部の時間管理
timerctrl_t timerctrl;

void init_pit();

struct Timer* new_timer();
timer_t* new_timer();

void free_timer(struct Timer *timer);
void free_timer(timer_t *timer);

void init_timer(struct Timer *timer, struct Queue *queue, unsigned char data);
void init_timer(timer_t *timer, queue_t *queue, unsigned char data);

void handle_intr20(int *esp);

void set_timer(struct Timer *timer, unsigned int timeout);
void set_timer(timer_t *timer, unsigned int timeout);

#endif
8 changes: 4 additions & 4 deletions kernel/dsctbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <console.h>

void init_gdtidt() {
struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) GDT_ADDR;
struct GATE_DESCRIPTOR *idt = (struct GATE_DESCRIPTOR *) IDT_ADDR;
segment_descriptor_t *gdt = (segment_descriptor_t *) GDT_ADDR;
gate_descriptor_t *idt = (gate_descriptor_t *) IDT_ADDR;

int i;
for (i = 0; i <= GDT_LIMIT / 8; i++) {
Expand Down Expand Up @@ -32,7 +32,7 @@ void init_gdtidt() {
set_gatedesc(idt + 0x27, (int) asm_handle_intr27, 2 * 8, AR_INTGATE32);
}

void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar) {
void set_segmdesc(segment_descriptor_t *sd, unsigned int limit, int base, int ar) {
if (limit > 0xfffff) {
ar |= 0x8000; // Gビットフラグを1すると
limit /= 0x1000; // バイト単位 -> ページ単位に変更(4GBになる)
Expand All @@ -45,7 +45,7 @@ void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, i
sd->base_high = (base >> 24) & 0x0ff;
}

void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar) {
void set_gatedesc(gate_descriptor_t *gd, int offset, int selector, int ar) {
gd->offset_low = offset & 0xffff;
gd->selector = selector;
gd->dw_count = (ar >> 8) & 0xff;
Expand Down
4 changes: 2 additions & 2 deletions kernel/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <console.h>
#include <color.h>

struct Queue *queue;
queue_t *queue;

/**
* キーボードコントローラがデータ送信可能になるまで待つ
Expand All @@ -18,7 +18,7 @@ void wait_keyboard() {
}
}

void init_keyboard(struct Queue *q) {
void init_keyboard(queue_t *q) {
queue = q;
wait_keyboard();
outb_p(PORT_KEYCMD, KEYCMD_WRITE);
Expand Down
4 changes: 1 addition & 3 deletions kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
| |_| |_|\__, |\___/|____/ |
| |___/ |
*---------------------------*/
#include <main.h>

#include <console.h>
#include <dsctbl.h>
#include <intr.h>
Expand All @@ -29,7 +27,7 @@ int main(void) {

init_pit();

struct Queue queue;
queue_t queue;
unsigned char keybuf[KEYBUF_LIMIT];

init_queue(&queue, KEYBUF_LIMIT, keybuf);
Expand Down

0 comments on commit 777f728

Please sign in to comment.