-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
HuSharp
committed
Sep 24, 2020
1 parent
3b9d30a
commit c692734
Showing
365 changed files
with
23,505 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
hello.c | ||
用gcc编译选项为: gcc -m32 -c -o hello.o hello.c | ||
用-m32指定为32位 | ||
print.asm | ||
用nasm汇编选项为: nasm -f elf -o print.o print.asm | ||
用-f elf 指定为32位,64位则为-f elf64 | ||
ld | ||
用ld 连接目标文件: ld -m elf_i386 -o hello.bin hello.o print.o | ||
hello.c中调用了print.asm中函数,链接时一般采用调用在前,实现在后 | ||
|
||
如果有报错找不到32位相关库,则运行以下命令安装升级: | ||
sudo apt-get install gcc-multilib | ||
sudo apt-get install g++-multilib | ||
|
||
作者:MarvinLe | ||
链接:https://www.jianshu.com/p/293f38918b96 | ||
来源:简书 | ||
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
;���������� | ||
;------------------------------------------------------------ | ||
%include "boot.inc" | ||
SECTION MBR vstart=0x7c00 | ||
mov ax,cs | ||
mov ds,ax | ||
mov es,ax | ||
mov ss,ax | ||
mov fs,ax | ||
mov sp,0x7c00 | ||
mov ax,0xb800 | ||
mov gs,ax | ||
|
||
; ���� | ||
;����0x06�Ź��ܣ��Ͼ�ȫ���У���������� | ||
; ----------------------------------------------------------- | ||
;INT 0x10 ���ܺ�:0x06 ��������:�Ͼ����� | ||
;------------------------------------------------------ | ||
;���룺 | ||
;AH ���ܺ�= 0x06 | ||
;AL = �Ͼ�������(���Ϊ0,��ʾȫ��) | ||
;BH = �Ͼ������� | ||
;(CL,CH) = �������Ͻǵ�(X,Y)λ�� | ||
;(DL,DH) = �������½ǵ�(X,Y)λ�� | ||
;����ֵ�� | ||
mov ax, 0600h | ||
mov bx, 0700h | ||
mov cx, 0 ; ���Ͻ�: (0, 0) | ||
mov dx, 184fh ; ���½�: (80,25), | ||
; ��ΪVGA�ı�ģʽ�У�һ��ֻ������80���ַ�,��25�С� | ||
; �±��0��ʼ������0x18=24,0x4f=79 | ||
int 10h ; int 10h | ||
|
||
; ����ַ���:MBR | ||
mov byte [gs:0x00],'1' | ||
mov byte [gs:0x01],0xA4 | ||
|
||
mov byte [gs:0x02],' ' | ||
mov byte [gs:0x03],0xA4 | ||
|
||
mov byte [gs:0x04],'M' | ||
mov byte [gs:0x05],0xA4 ;A��ʾ��ɫ������˸��4��ʾǰ��ɫΪ��ɫ | ||
|
||
mov byte [gs:0x06],'B' | ||
mov byte [gs:0x07],0xA4 | ||
|
||
mov byte [gs:0x08],'R' | ||
mov byte [gs:0x09],0xA4 | ||
|
||
mov eax,LOADER_START_SECTOR ; ��ʼ����lba��ַ | ||
mov bx,LOADER_BASE_ADDR ; д��ĵ�ַ | ||
mov cx,4 ; ������������� | ||
call rd_disk_m_16 ; ���¶�ȡ�������ʼ���֣�һ�������� | ||
|
||
jmp LOADER_BASE_ADDR + 0x300 | ||
|
||
;------------------------------------------------------------------------------- | ||
;����:��ȡӲ��n������ | ||
rd_disk_m_16: | ||
;------------------------------------------------------------------------------- | ||
; eax=LBA������ | ||
; ebx=������д����ڴ��ַ | ||
; ecx=����������� | ||
mov esi,eax ;����eax | ||
mov di,cx ;����cx | ||
;��дӲ��: | ||
;��1��������Ҫ��ȡ�������� | ||
mov dx,0x1f2 | ||
mov al,cl | ||
out dx,al ;��ȡ�������� | ||
|
||
mov eax,esi ;�ָ�ax | ||
|
||
;��2������LBA��ַ����0x1f3 ~ 0x1f6 | ||
|
||
;LBA��ַ7~0λд��˿�0x1f3 | ||
mov dx,0x1f3 | ||
out dx,al | ||
|
||
;LBA��ַ15~8λд��˿�0x1f4 | ||
mov cl,8 | ||
shr eax,cl | ||
mov dx,0x1f4 | ||
out dx,al | ||
|
||
;LBA��ַ23~16λд��˿�0x1f5 | ||
shr eax,cl | ||
mov dx,0x1f5 | ||
out dx,al | ||
|
||
shr eax,cl | ||
and al,0x0f ;lba��24~27λ | ||
or al,0xe0 ; ����7��4λΪ1110,��ʾlbaģʽ | ||
mov dx,0x1f6 | ||
out dx,al | ||
|
||
;��3������0x1f7�˿�д������0x20 | ||
mov dx,0x1f7 | ||
mov al,0x20 | ||
out dx,al | ||
|
||
;��4�������Ӳ��״̬ | ||
.not_ready: | ||
;ͬһ�˿ڣ�дʱ��ʾд�������֣���ʱ��ʾ����Ӳ��״̬ | ||
nop | ||
in al,dx | ||
and al,0x88 ;��4λΪ1��ʾӲ�̿��������������ݴ��䣬��7λΪ1��ʾӲ��æ | ||
cmp al,0x08 | ||
jnz .not_ready ;��δ���ã������ȡ� | ||
|
||
;��5������0x1f0�˿ڶ����� | ||
mov ax, di | ||
mov dx, 256 | ||
mul dx | ||
mov cx, ax ; diΪҪ��ȡ����������һ��������512�ֽڣ�ÿ�ζ���һ���֣� | ||
; ����di*512/2������di*256 | ||
mov dx, 0x1f0 | ||
.go_on_read: | ||
in ax,dx | ||
mov [bx],ax | ||
add bx,2 | ||
loop .go_on_read | ||
ret | ||
|
||
times 510-($-$$) db 0 | ||
db 0x55,0xaa |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.