Skip to content

Commit

Permalink
PRJ3 주석 달기 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
limdongjin committed May 3, 2019
1 parent 03d2190 commit d84cbc1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
40 changes: 40 additions & 0 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/*
* Struct or Enum Declarations and Definition
*/

// Instruction 정보를 저장함.
typedef struct instruction{
bool extend;
unsigned char opcode;
Expand Down Expand Up @@ -42,6 +44,7 @@ typedef struct instruction{
} param;
} Instruction;

// Operator 이름과 opcode 를 매핑
typedef enum {
LDA = 0x00,
LDB = 0x68,
Expand All @@ -67,6 +70,7 @@ typedef enum {
TIXR = 0xB8
} Operator;

// Addressing mode
typedef enum {
ENUM_IMMEDIATE_ADDRESSING,
ENUM_SIMPLE_ADDRESSING,
Expand All @@ -79,29 +83,64 @@ typedef enum {
*/

/* loader_linker 함수 구현을 위한 함수들 */

// pass1
static bool loader_linker_pass1(Debugger *debugger);

// pass2
static bool loader_linker_pass2(Debugger *debugger, Memories *memories);

// pass1 sub function
static bool loader_linker_pass1_one(Debugger *debugger, int file_num, int *csaddr);

// pass2 sub function
static bool loader_linker_pass2_one(Debugger *debugger, Memories *memories, int file_num , int *csaddr);

// 생성자 함수
static LoadInfoList* construct_load_info_list();

// 소멸자 함수
static bool destroy_load_info_list(LoadInfoList** load_infos);

// load 된 정보를 출력함.
static void print_load_infos(LoadInfoList *load_infos);

/* run 함수를 구현을 위한 함수들 */

// 레지스터 상태를 출력함.
static void print_registers(Registers* registers);

// 명령을 실행함.
static bool execute_operator(Debugger *debugger, Memories *memories, Instruction *instruction);

// TA 계산함.
static uint32_t calculate_TA(Instruction* instruction, Registers* registers);

// Addressing Mode 계산함
static ADDRESSING_MODE calculate_addressing_mode(Instruction* instruction, bool jump_op);

// reg_id 로 레지스터를 찾아서 리턴함.
static uint32_t *get_reg_by_id(Registers *registers, int reg_id);

// BP 를 핸들링함.
static bool handling_bp(Debugger *debugger, int instruction_size);

// 메모리로 부터 값을 가져옴.
static bool load_from_memory(Debugger *debugger, Memories *memories, Instruction *instruction, uint32_t *value,
size_t bytes, bool jump_op);

// 메모리에 값을 저장함.
static bool store_to_memory(Debugger *debugger, Memories *memories, Instruction *instruction, uint32_t value,
size_t bytes);

// 레지터로 부터 값을 가져옴.
static bool load_from_register(Debugger *debugger, int reg_id, uint32_t *val);

// 레지스터에 값을 저장함.
static bool store_to_register(Debugger *debugger, int reg_id, uint32_t val);

/*
* 함수 상세 설명(주석)은 declaration 파트 참고
* Function Definitions (public)
*/
Debugger* construct_debugger(){
Expand Down Expand Up @@ -247,6 +286,7 @@ bool run(Debugger *debugger, Memories *memories){


/*
* 함수 상세 설명(주석)은 declaration 파트 참고
* Static Function Definitions
*/
static bool destroy_load_info_list(LoadInfoList** load_infos){
Expand Down
16 changes: 15 additions & 1 deletion debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <string.h>
#define MAX_BP_NUM (1024 * 1024) // 1MB

// 레지스터 값을 저장함.
typedef struct registers {
uint32_t A;
uint32_t L;
Expand All @@ -22,24 +23,27 @@ typedef struct registers {
uint32_t SW;
}Registers;

// load info 정보의 유형
enum load_info_type {
INFO_TYPE_CONTROL_SECTION,
INFO_TYPE_SYMBOL
} LoadInfoType;

// load info 정보 한 단위
typedef struct load_info_node {
enum load_info_type type;
char name[15];
int addr;
int length;
}LoadInfoNode;

// load 되는 정보를 저장함.
typedef struct load_info_list {
LoadInfoNode list[1001];
int count;
} LoadInfoList;

// [TODO] debugger 구조체 구현
// load, run, bp, 레지스터 관리 등의 역활을함.
typedef struct debugger {
int start_address; // 10 진수로 변환하여 저장함.
int end_address;
Expand All @@ -59,15 +63,25 @@ typedef struct debugger {
bool is_loaded;
} Debugger;

// debugger 의 생성자 함수
Debugger* construct_debugger();

// debugger 의 소멸자 함수
bool destroy_debugger(Debugger** debugger);

// registers 의 생성자 함수
Registers* construct_registers();

// registers 의 소멸자 함수
bool destroy_registers(Registers** registers);

// register 를 리셋함.
void reset_registers(Registers* registers);

// loader 명령을 실행하는 함수
bool loader_linker(Debugger *debugger, Memories *memories);

// run 명령을 실행하는 함수
bool run(Debugger *debugger, Memories *memories);

#endif
1 change: 1 addition & 0 deletions opcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ void print_opcodes(OpcodeTable* table){
}
}

// format 을 매핑하는 함수
enum op_format op_format_by_op_num(int op_num){
bool format3_4[260] = {
[0x00] = true,
Expand Down
1 change: 1 addition & 0 deletions opcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Opcode* find_opcode_by_name(OpcodeTable* table, char* name);
*/
void print_opcodes(OpcodeTable* table);

// format 을 매핑하는 함수
enum op_format op_format_by_op_num(int op_num);

#endif

0 comments on commit d84cbc1

Please sign in to comment.