검색결과 리스트
Programming에 해당되는 글 119건
- 2009.05.11 Stack Frame
- 2009.05.01 Coding Standard
- 2009.03.25 리눅스
- 2009.03.23 1. Red Hat Linux 5 - basic instructions ①
- 2009.03.23 1. Red Hat Linux 5 - basic instructions ①
- 2009.03.11 NASM - 1
- 2009.03.08 Segmant and Offset
- 2009.03.08 Real Mode, Protected Mode
- 2009.03.08 1. 부트스트랩
글
Stack Frame
int Add( int a, int b ) { int c,d,e; c = a + b; return c; } void main() { int result; result = Add( 1, 2 ); printf("result= %d\n", result ); } |
Add 함수에서 중단점을 설정 한 후 View/ Debug Window/ Disassembly 를 선택하면 Assem 코드를 볼 수 있다.
함수를 호출 할 때 ebp 를 먼저 스택에 push 한 뒤에 함수내에서 필요한 정보들을 push 한다.
esp는 함수의 변수와 인자들을 가리키기 위한 기준 번지로써 esp가 바뀌더라도 ebp는 변하지 않는다.
Add 함수의 수행을 마칠 때, 남은 정리 작업을 수행하는 코드를 접미( epilog ) 라고 하는데 이 함수의 경우 다음의 세줄 이다.
mov esp, ebp ; 지역변수를 위해 할당했던 스택 영역을 회수 한다는 뜻.
pop ebp
ret ; 스택에 저장된 복귀 번지를 꺼내서 그 번지로 리턴한다.
함수가 연속적으로 두번 호출될 때 는 다음과 같다.
void Dog( int v ) { int n, m; n = Add( 1, 2 ); ... } |
위의 그림과 같이 각 함수의 스택 프레임이 저장 된다.
main 스택 프레임 위에 Dog 스택 프레임이 올라가고 그 위에 Add의 스택프레임이 올라가게 된다.
Dog 스택프레임은 먼저 인자 값인 v가 들어가고 난 뒤 복귀 번지, 그리고 ebp, 지역변수들 이 들어가고,
Add 함수의 경우도 마찬가지이다.
자세한 내용을 알고 싶으면 Winapi 사이트를 방문하기 바랍니다. 이 글은 Winapi 에서 발췌한 글입니다.
'Programming > OS Development' 카테고리의 다른 글
어셈블러에서 16진수 입력 (0) | 2009.05.15 |
---|---|
naked 함수 (0) | 2009.05.11 |
NASM - 1 (0) | 2009.03.11 |
Segmant and Offset (0) | 2009.03.08 |
Real Mode, Protected Mode (0) | 2009.03.08 |
글
Coding Standard
각 소스 주석 : 프로그램의 시작시
- /*-------------------------------
- ** File Name : test.c
- ** Date : 2007.08.24
- ** Author : ChanSub Shin
- ** Brief : ~~
- ---------------------------------*/
변수 선언을 제외하고는 "//"를 사용하여 위쪽에 주석 달기.
두줄 이상의 주석인 경우 /*-----
**
**
-----*/ 식으로 주석 달기.
변수
변수 선언시 : Tab 사용하여 줄 맞추기.
변수 선언시 주석은 우측편에 Tab으로 띄워서 "// " 사용 하기
헝가리언 표기법
표기법 | 의미 | 표기법 | 의미 |
---|---|---|---|
a | 배열 | l | long 형 변수 |
b | BOOL형 변수( b : bool ) | p | 포인터 변수 |
by | BYTE( unsigned char ) 형 변수 | lp | long 포인터 변수 |
c | 카운터로 사용하는 변수 | st | 구조체 |
cx, cy | x, y 길이를 나타내기 위해 사용하는 변수 | u | unsigned int 형 변수 |
d | double 형 변수 | w | WORD( unsigned short ) 형 변수 |
f | float 형 변수 | dw | DWORD( unsigned long ) 형 변수 |
n | int형 변수 | h | 핸들( HANDLE ) 형 변수 |
ch | char 형 변수 | g_ | 전역 변수 |
함수
대문자로 시작하기 - GetTotalOfStack();
함수 이름으로 충분히 설명이 되지 않을 경우 함수 위에 주석 달기
'Programming > C Language' 카테고리의 다른 글
코딩 스타일 (0) | 2009.08.15 |
---|---|
#ifndef ~ #define ~ #endif (0) | 2009.08.15 |
헤더파일과 소스파일 (0) | 2009.08.02 |
모듈화 프로그래밍 - 2 (0) | 2009.06.28 |
모듈화 프로그래밍 - 1 (0) | 2009.06.28 |
글
리눅스
'Programming > Linux' 카테고리의 다른 글
Vi 편집기 (0) | 2009.09.19 |
---|---|
Virtual Box 게스트 확장 설치 (0) | 2009.09.15 |
vi / vim 단축키 모음 (0) | 2009.09.10 |
1. Red Hat Linux 5 - basic instructions ① (0) | 2009.03.23 |
1. Red Hat Linux 5 - basic instructions ① (0) | 2009.03.23 |
글
1. Red Hat Linux 5 - basic instructions ①
su - It means 'substitue user'. It's used to change another user ID, not to login,to use another new shell. Commonly it's used to change root account for a moment to do management work. then return to the previous login account.
passwd <ID>- used to change password.
-l : Show specific info of files.
-a : Show all files,regardless of the type of files.
mv <original filename> <new filename>: move or rename files.
chmod( permission ) <permission option> <objective file>
d rwx rwx rwx : The first character is either directory or file. 'd' means directory, '-'
means file. The first "rwx" is the authority of an owner. The second one
is the authority of a group. The final one is the authority of other users.
To give an authority
1) rwx(421) add the number. - give owner, all groups, all users an authority.
read + write + execution 7, read + write 6,
read + execution 5, read 4, write + execution 3, write 2, execution 1
2) a( all ), u( user ), g( groups ), o( other ) / r( read ), w( write ), x( execution )
+ ( add permission ), - ( remove permission )
ex ) chmod 777 redhat -> Give all owners, groups, users all authorities.
chmod u+x redhat -> Give owner execution autority.
Link
ex ) ln -s a b : Make b link to point at a file or directory.
cd b : Enter a which a point at
'Programming > Linux' 카테고리의 다른 글
Vi 편집기 (0) | 2009.09.19 |
---|---|
Virtual Box 게스트 확장 설치 (0) | 2009.09.15 |
vi / vim 단축키 모음 (0) | 2009.09.10 |
리눅스 (0) | 2009.03.25 |
1. Red Hat Linux 5 - basic instructions ① (0) | 2009.03.23 |
글
1. Red Hat Linux 5 - basic instructions ①
su - It means 'substitue user'. It's used to change another user ID, not to login,to use another new shell. Commonly it's used to change root account for a moment to do management work. then return to the previous login account.
passwd <ID>- used to change password.
-l : Show specific info of files.
-a : Show all files,regardless of the type of files.
mv <original filename> <new filename>: move or rename files.
chmod( permission ) <permission option> <objective file>
d rwx rwx rwx : The first character is either directory or file. 'd' means directory, '-'
means file. The first "rwx" is the authority of an owner. The second one
is the authority of a group. The final one is the authority of other users.
To give an authority
1) rwx(421) add the number. - give owner, all groups, all users an authority.
read + write + execution 7, read + write 6,
read + execution 5, read 4, write + execution 3, write 2, execution 1
2) a( all ), u( user ), g( groups ), o( other ) / r( read ), w( write ), x( execution )
+ ( add permission ), - ( remove permission )
ex ) chmod 777 redhat -> Give all owners, groups, users all authorities.
chmod u+x redhat -> Give owner execution autority.
Link
ex ) ln -s a b : Make b link to point at a file or directory.
cd b : Enter a which a point at
'Programming > Linux' 카테고리의 다른 글
Vi 편집기 (0) | 2009.09.19 |
---|---|
Virtual Box 게스트 확장 설치 (0) | 2009.09.15 |
vi / vim 단축키 모음 (0) | 2009.09.10 |
리눅스 (0) | 2009.03.25 |
1. Red Hat Linux 5 - basic instructions ① (0) | 2009.03.23 |
글
NASM - 1
-> mov di, 0 : di 에 0을 넣어라.
-> [label], ax : label 의 부분에 ax값을 넣어라.
2. add
-> add di, 2 : di 에 2를 더하라.
3. jnz
-> jnz paint : ZF가 ON이면 다음 줄로, OFF 이면 Paint 로 점프
cx 레지스터 - 화면 전체에 그릴때 값을 저장하는 레지스터(?)
-> byte형의 포인터. ex) mov byte[ es : edi ], 0x06 : es : edi 에 byte만큼 써라. es : edi에서 byte만
큼의 문자
5. inc / dec
-> inc edi : edi 를 1 증가 / dec edi : edi 를 1 감소
6. jmp
-> 특정 위치로 Jump. $ : 현재 행의 주소값.( 현재 줄 )
7. db
8. dw
-> dw 0xFFFF : 2byte 를 0xFFFF 로 쓰기
9. dd
-> dd 0xFFFFFFFF : 4byte 쓰기.
10. int
-> int 0x13 : interupt를 걸어서 BIOS 에 있는 프로그램을 실행하는 BIOS CALL 명령어.
0x13 은 어느 섹터부터 몇 개의 섹터를 읽어라는 뜻.
'Programming > OS Development' 카테고리의 다른 글
naked 함수 (0) | 2009.05.11 |
---|---|
Stack Frame (0) | 2009.05.11 |
Segmant and Offset (0) | 2009.03.08 |
Real Mode, Protected Mode (0) | 2009.03.08 |
1. 부트스트랩 (0) | 2009.03.08 |
글
Segmant and Offset
Logical Address - 0x07c0:0000
When you change from physical address to logical address, you add zero to 16 antilogarithm ( = shift towards left for four times ) then add offset.
0x07C0:0000 Calculation
0x7C00 + 0x0000 = 0x7C00 = 0x07C00
0x2004:0101 Calculation
0x20040 + 0x0101 = 0x20141
'Programming > OS Development' 카테고리의 다른 글
naked 함수 (0) | 2009.05.11 |
---|---|
Stack Frame (0) | 2009.05.11 |
NASM - 1 (0) | 2009.03.11 |
Real Mode, Protected Mode (0) | 2009.03.08 |
1. 부트스트랩 (0) | 2009.03.08 |
글
Real Mode, Protected Mode
그리고 일괄 처리 밖에 할 수가 없다. 모든 커널은 컴퓨터에 전원이 들어온 후 리얼 모드에서 여러가지 하드웨어적인 세팅을 마친 후 Protected Mode로 CPU를 전환한다. 어떤 계열이든 처음에는 Real Mode시에 CPU는 하드웨어 적으로 8086 처럼 동작을 한다. 따라서 OS 첫 부분은 8086과 동일 하게 코딩해야 한다.
Protected Mode 는 Windows, Linux가 CPU에서 동작되고 있는 모드이다.
이 모드는 분할 처리가 가능하다. 그리고 Protected Mode에는 유저모드 와 커널 모드 두 가지가 있다. 커널모드 와 유저모드 를 왔다갔다 하면서 빠르게 실행을 하기 때문에 사용자는 동시에 진행되는 것
처럼 느껴진다. 커널 모드의 영역은 유저 모드 프로그램에서는 정해진 루트 외에는 접근이 불가능하다.
커널 루틴은 자원의 낭비와 메모리의 낭비를 최소화 한다.
'Programming > OS Development' 카테고리의 다른 글
naked 함수 (0) | 2009.05.11 |
---|---|
Stack Frame (0) | 2009.05.11 |
NASM - 1 (0) | 2009.03.11 |
Segmant and Offset (0) | 2009.03.08 |
1. 부트스트랩 (0) | 2009.03.08 |
글
1. 부트스트랩
1. NASM 다운로드 : Netwide Assembler 컴파일러
http://sourceforge.net/projects/nasm 에 가서 download 메뉴를 누른다.
package 아래부분에 win32 binaries 를 다운 받아서 압축을 푼다.
2. NASM 환경변수 추가
"내컴퓨터" 마우스 오른쪽 버튼 눌러서 "속성" 메뉴 선택
"시스템 등록 정보"에서 "고급"탭 클릭
"환경 변수" 버튼 클릭 후 PATH선택하여 편집을 누르고 NASM의 압축이 풀린 경로명을 적어준다. ex) ~~~;c:\nasm
3. 부트 이미지 만들기
책에 있는 소스를 치고, 부트 이미지 만들 소스가 있는 위치로 폴더를 이동해서 ex) c:\OS 컴파일을 한다.
nasm -f bin -o boot.bin boot.txt 와 같이 컴파일을 하여 오류가 없을 경우 실행 파일이 만들어지게 된다.
설명 : -f bin 옵션 -> 제작할 실행 파일이 exe나 com등의 일반 dos실행 파일이 아닌 바이너리 실행파일 이라는 것을 어셈블러에게 알려준다.
exe나 com은 도스에서 램에 로드하고 실행하는 등 운영을 편하기 하기 위해 기계어로 된 실행파일의 머리부분에 헤더를 놓아 정보를 기록해 놓거나 하는 조작을 해놓은 것이다. 우리는 커널을 제작할 것이므로 그런 형식을 사용 안한다.
-o boot.bin 옵션은 실행 파일의 이름을 정해준다.
boot.txt 직접 작성한 소스 파일이름
4. USB 에 쓰기
http://www.chrysocome.net/dd 에 가서 리눅스에서 usb부트 디스크를 만들때 쓰는 dd 명령을 Windows 환경에서도 쓸 수 있게 해주는 프로그램을 다운 받는다. 압축을 풀고 거기 있는 dd.exe와 Disiko.dll 파일을 C:\Windows 로 옮긴다.
그리고 나서 "시작-실행" 에서 cmd를 입력하고, 명령 프롬프트에서 dd --list를 입력한다.
그러면 해당 드라이버를 보면 디바이스 명칭을 볼수 있다.
그럼 이제 USB디바이스에 dd명령을 이용하여 부트이미지를 usb로 옮긴다.
dd if=c:\OS\boot.bin of=\\.\g: 를 입력하면 c:\OS 폴더의 boot.bin 파일이 g:로 복사가 된다.
5. VMware로 실행하기
먼저 OS 개발 환경을 위해 VMWare를 설치한다. 그리고 거기에 OS없는 VM을 만들어서 마지막 부분에서 Customize Hardware 를 선택한다.
그리고 New CD/DVD메뉴 와 NetworkAdapter메뉴에 Connect at power on 에 체크를 해제한다.
Floppy 메뉴를 선택하여 Coonect at power on 에 체크를 한다. 그리고 두번째 Connection 에서 Use floppy image file 을 선택하고
Browse를 선택해서 컴파일한 boot.bin을 선택하여 확인을 한다. 이제 설정한 VM을 수행하면 부팅이 될것이다.
기계어 코드 EA0F00C007 은 바이트 수가 0xEA, 0x0F, 0x00, 0xC0, 0x07 로 5바이트 영역을 차지힌다.
E = 1111, A = 1010 8bit 이므로 1Byte
http://www.haiku-os.org/community/forum/how_to_install_haiku_to_usb_flash_drive_from_windows
http://shounen.ru/soft/flashnul/
'Programming > OS Development' 카테고리의 다른 글
naked 함수 (0) | 2009.05.11 |
---|---|
Stack Frame (0) | 2009.05.11 |
NASM - 1 (0) | 2009.03.11 |
Segmant and Offset (0) | 2009.03.08 |
Real Mode, Protected Mode (0) | 2009.03.08 |