Clean up crap and get code ready for 64 bit.
This commit is contained in:
parent
e1b29f2966
commit
41c2d8ca2a
|
@ -1,165 +0,0 @@
|
|||
;FAT12ReadFile(ULONG16 Base,ULONG16 Offset,ULONG16 OffsetFileName)
|
||||
|
||||
FAT12ReadFile:
|
||||
.START:
|
||||
push bp
|
||||
mov bp,sp
|
||||
push bp
|
||||
|
||||
xor ah, ah
|
||||
xor dl, dl
|
||||
int 13h
|
||||
|
||||
mov word [wSectorNo], SectorNoOfRootDirectory
|
||||
.LABEL_SEARCH_IN_ROOT_DIR_BEGIN:
|
||||
cmp word [wRootDirSizeForLoop], 0
|
||||
jz .LABEL_NO_LOADERBIN
|
||||
dec word [wRootDirSizeForLoop]
|
||||
mov ax, [ss:bp+4]
|
||||
mov es, ax
|
||||
mov bx, [ss:bp+6]
|
||||
mov ax, [wSectorNo]
|
||||
mov cl, 1
|
||||
|
||||
call ReadSector
|
||||
|
||||
mov si, [ss:bp+8]
|
||||
mov di, [ss:bp+6]
|
||||
cld
|
||||
mov dx, 10h
|
||||
.LABEL_SEARCH_FOR_LOADERBIN:
|
||||
cmp dx, 0
|
||||
jz .LABEL_GOTO_NEXT_SECTOR_IN_ROOT_DIR
|
||||
dec dx
|
||||
mov cx, 11
|
||||
.LABEL_CMP_FILENAME:
|
||||
cmp cx, 0
|
||||
jz .LABEL_FILENAME_FOUND
|
||||
dec cx
|
||||
lodsb
|
||||
cmp al, byte [es:di]
|
||||
jz .LABEL_GO_ON
|
||||
jmp .LABEL_DIFFERENT
|
||||
.LABEL_GO_ON:
|
||||
inc di
|
||||
jmp .LABEL_CMP_FILENAME
|
||||
|
||||
.LABEL_DIFFERENT:
|
||||
and di, 0FFE0h
|
||||
add di, 20h
|
||||
mov si, [ss:bp+8]
|
||||
jmp .LABEL_SEARCH_FOR_LOADERBIN;
|
||||
|
||||
.LABEL_GOTO_NEXT_SECTOR_IN_ROOT_DIR:
|
||||
add word [wSectorNo], 1
|
||||
jmp .LABEL_SEARCH_IN_ROOT_DIR_BEGIN
|
||||
|
||||
.LABEL_NO_LOADERBIN:
|
||||
jmp $
|
||||
|
||||
.LABEL_FILENAME_FOUND:
|
||||
mov ax, RootDirSectors
|
||||
and di, 0FFE0h
|
||||
add di, 01Ah
|
||||
mov cx, word [es:di]
|
||||
push cx
|
||||
add cx, ax
|
||||
add cx, DeltaSectorNo
|
||||
mov ax, [ss:bp+4]
|
||||
mov es, ax
|
||||
mov bx, [ss:bp+6]
|
||||
mov ax, cx
|
||||
|
||||
.LABEL_GOON_LOADING_FILE:
|
||||
mov cl, 1
|
||||
call ReadSector
|
||||
pop ax
|
||||
push word [ss:bp+4]
|
||||
call GetFATEntry
|
||||
add sp,2
|
||||
cmp ax, 0FFFh
|
||||
jz .LABEL_FILE_LOADED
|
||||
push ax
|
||||
mov dx, RootDirSectors
|
||||
add ax, dx
|
||||
add ax, DeltaSectorNo
|
||||
add bx, [BPB_BytsPerSec]
|
||||
jmp .LABEL_GOON_LOADING_FILE
|
||||
|
||||
.LABEL_FILE_LOADED:
|
||||
mov sp,[bp-2]
|
||||
pop bp
|
||||
ret
|
||||
|
||||
wRootDirSizeForLoop dw RootDirSectors
|
||||
wSectorNo dw 0
|
||||
bOdd db 0
|
||||
|
||||
ReadSector:
|
||||
push bp
|
||||
mov bp, sp
|
||||
sub esp, 2
|
||||
mov byte [bp-2], cl
|
||||
push bx
|
||||
mov bl, [BPB_SecPerTrk]
|
||||
div bl
|
||||
inc ah
|
||||
mov cl, ah
|
||||
mov dh, al
|
||||
shr al, 1
|
||||
mov ch, al
|
||||
and dh, 1
|
||||
pop bx
|
||||
mov dl, [BS_DrvNum]
|
||||
.GoOnReading:
|
||||
mov ah, 2
|
||||
mov al, byte [bp-2]
|
||||
int 13h
|
||||
jc .GoOnReading
|
||||
|
||||
add sp, 2
|
||||
pop bp
|
||||
|
||||
ret
|
||||
|
||||
GetFATEntry:
|
||||
push bp
|
||||
mov bp,sp
|
||||
push es
|
||||
push bx
|
||||
push ax
|
||||
mov ax, [ss:bp+4]
|
||||
sub ax, 0100h
|
||||
mov es, ax
|
||||
pop ax
|
||||
mov byte [bOdd], 0
|
||||
mov bx, 3
|
||||
mul bx
|
||||
mov bx, 2
|
||||
div bx
|
||||
cmp dx, 0
|
||||
jz .LABEL_EVEN
|
||||
mov byte [bOdd], 1
|
||||
.LABEL_EVEN:
|
||||
xor dx, dx
|
||||
mov bx, [BPB_BytsPerSec]
|
||||
div bx
|
||||
push dx
|
||||
mov bx, 0
|
||||
add ax, SectorNoOfFAT1
|
||||
mov cl, 2
|
||||
call ReadSector
|
||||
|
||||
pop dx
|
||||
add bx, dx
|
||||
mov ax, [es:bx]
|
||||
cmp byte [bOdd], 1
|
||||
jnz .LABEL_EVEN_2
|
||||
shr ax, 4
|
||||
.LABEL_EVEN_2:
|
||||
and ax, 0FFFh
|
||||
.LABEL_GET_FAT_ENRY_OK:
|
||||
pop bx
|
||||
pop es
|
||||
pop bp
|
||||
ret
|
|
@ -1,318 +0,0 @@
|
|||
GETMEM16:
|
||||
push eax
|
||||
push ebx
|
||||
push ecx
|
||||
push edx
|
||||
push esi
|
||||
push edi
|
||||
mov ax,es
|
||||
push ax
|
||||
mov ax,ds
|
||||
push ax
|
||||
|
||||
mov ax,cs
|
||||
mov es,ax
|
||||
mov ds,ax
|
||||
|
||||
xor ebx,ebx
|
||||
mov di,GETMEMBUFF ;es:di = ASRD
|
||||
.loop:
|
||||
mov eax,0E820h
|
||||
mov ecx,20
|
||||
;edx = 'SMAP'
|
||||
mov edx,0534D4150h
|
||||
int 15h
|
||||
;if (CF!=0)
|
||||
jc .fail
|
||||
inc dword [GETMEMNUM]
|
||||
;forward 20bytes
|
||||
add di,20
|
||||
cmp ebx,0
|
||||
jne .loop
|
||||
jmp .end
|
||||
.fail:
|
||||
mov dword [GETMEMNUM],0
|
||||
.end:
|
||||
|
||||
pop ax
|
||||
mov ds,ax
|
||||
pop ax
|
||||
mov es,ax
|
||||
pop edi
|
||||
pop esi
|
||||
pop edx
|
||||
pop ecx
|
||||
pop ebx
|
||||
pop eax
|
||||
ret
|
||||
|
||||
DISPMEM16:
|
||||
;must include io16.lib
|
||||
push eax
|
||||
push esi
|
||||
push edi
|
||||
push ecx
|
||||
push edx
|
||||
push ebp
|
||||
mov ax,ds
|
||||
push ax
|
||||
mov ax,es
|
||||
push ax
|
||||
|
||||
mov ax,cs
|
||||
mov ds,ax
|
||||
mov es,ax
|
||||
|
||||
xor eax,eax
|
||||
mov eax,RAMTABLE16
|
||||
push eax
|
||||
call near DISPSTR16
|
||||
pop eax
|
||||
|
||||
call DISPRETURN16
|
||||
|
||||
xor ebp,ebp
|
||||
mov esi,GETMEMBUFF
|
||||
mov ecx,[ds:GETMEMNUM]
|
||||
mov edx,5
|
||||
.loop1:
|
||||
mov eax,dword [ds:esi]
|
||||
push eax
|
||||
call near DISPINTEAX16
|
||||
pop eax
|
||||
call near DISPSPACE16
|
||||
inc ebp
|
||||
dec edx
|
||||
add esi,4
|
||||
cmp ebp,5
|
||||
jne .noinfo
|
||||
xor ebp,ebp
|
||||
cmp eax,1
|
||||
je .ava
|
||||
mov eax,RAMRESERVED
|
||||
push eax
|
||||
call near DISPSTR16
|
||||
pop eax
|
||||
jmp .noinfo
|
||||
.ava:
|
||||
mov eax,RAMAVAILABLE
|
||||
push eax
|
||||
call near DISPSTR16
|
||||
pop eax
|
||||
.noinfo:
|
||||
cmp edx,0
|
||||
jne .loop1
|
||||
cmp dword [ds:esi-4],1
|
||||
jne .end2
|
||||
mov eax,dword [ds:esi-20]
|
||||
add eax,dword [ds:esi-12]
|
||||
cmp eax,[ds:DISPMEMTOTAL]
|
||||
jb .end2
|
||||
mov [ds:DISPMEMTOTAL],eax
|
||||
.end2:
|
||||
call near DISPRETURN16
|
||||
dec ecx
|
||||
mov edx,5
|
||||
cmp ecx,0
|
||||
je .end1
|
||||
jmp .loop1
|
||||
.end1:
|
||||
call near DISPRETURN16
|
||||
mov eax,RAMSIZE
|
||||
push eax
|
||||
call near DISPSTR16
|
||||
pop eax
|
||||
push dword [ds:DISPMEMTOTAL]
|
||||
call near DISPINTEAX16
|
||||
pop eax
|
||||
pop ax
|
||||
mov es,ax
|
||||
pop ax
|
||||
mov ds,ax
|
||||
pop ebp
|
||||
pop edx
|
||||
pop ecx
|
||||
pop edi
|
||||
pop esi
|
||||
pop eax
|
||||
ret
|
||||
|
||||
DISPINTEAX16:
|
||||
;Entrance: push eax
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
push eax
|
||||
|
||||
mov eax,dword [ss:ebp+6]
|
||||
shr eax,24
|
||||
mov ah,0Fh
|
||||
push ax
|
||||
call near DISPINTAL16
|
||||
pop ax
|
||||
|
||||
mov eax,dword [ss:ebp+6]
|
||||
shr eax,16
|
||||
mov ah,0Fh
|
||||
push ax
|
||||
call near DISPINTAL16
|
||||
pop ax
|
||||
|
||||
mov eax,dword [ss:ebp+6]
|
||||
shr eax,8
|
||||
mov ah,0Fh
|
||||
push ax
|
||||
call near DISPINTAL16
|
||||
pop ax
|
||||
|
||||
mov eax,dword [ss:ebp+6]
|
||||
mov ah,0Fh
|
||||
push ax
|
||||
call near DISPINTAL16
|
||||
pop ax
|
||||
|
||||
pop eax
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
DISPSTR16:
|
||||
;Entrance: push offset
|
||||
;ds:offset = String
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
push esi
|
||||
push edi
|
||||
push eax
|
||||
push ebx
|
||||
push gs
|
||||
|
||||
mov ax,0b800h
|
||||
mov gs,ax
|
||||
mov esi,dword [ss:ebp+6]
|
||||
mov edi,dword [ds:GRAPHPOS]
|
||||
.loop1:
|
||||
mov al,byte [ds:esi]
|
||||
cmp al,0
|
||||
je .end
|
||||
cmp al,0Ah
|
||||
jne .loop2
|
||||
;let edi point to the next row
|
||||
;edi/(80*2) - every row:80 chars, each char takes 2 bytes.
|
||||
push eax
|
||||
mov eax,edi
|
||||
mov bl,160
|
||||
div bl
|
||||
;only keep the low 8 of eax(al,aka quotion)
|
||||
and eax, 0FFh
|
||||
inc eax
|
||||
;calculate the edi now
|
||||
mov bl,160
|
||||
mul bl
|
||||
mov edi,eax
|
||||
pop eax
|
||||
inc esi
|
||||
jmp .loop1
|
||||
.loop2:
|
||||
mov ah,0Fh
|
||||
mov word [gs:edi],ax
|
||||
add edi,2
|
||||
inc esi
|
||||
jmp .loop1
|
||||
.end:
|
||||
mov dword [ds:GRAPHPOS],edi
|
||||
|
||||
pop gs
|
||||
pop ebx
|
||||
pop eax
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
DISPINTAL16:
|
||||
;Entrance: push ax ,AH=ATTR, AL=Char
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
push eax
|
||||
push gs
|
||||
push ecx
|
||||
push edi
|
||||
push ebx
|
||||
push ds
|
||||
|
||||
mov ax,cs
|
||||
mov ds,ax
|
||||
mov edi,dword [ds:GRAPHPOS]
|
||||
mov ax,0b800h
|
||||
mov gs,ax
|
||||
xor eax,eax
|
||||
mov ax, word [ss:ebp+6]
|
||||
mov bx,ax
|
||||
;keep high 4 bits of al
|
||||
and al,0F0H
|
||||
mov cl,4
|
||||
shr al,cl
|
||||
call near CHANGEAL
|
||||
mov word [gs:edi],ax
|
||||
add edi,2
|
||||
mov dword [ds:GRAPHPOS],edi
|
||||
;keep low 4 bits of al
|
||||
mov ax,bx
|
||||
and al,0Fh
|
||||
call near CHANGEAL
|
||||
mov ah,bh
|
||||
mov word [gs:edi],ax
|
||||
add edi,2
|
||||
mov dword [ds:GRAPHPOS],edi
|
||||
|
||||
pop ds
|
||||
pop ebx
|
||||
pop edi
|
||||
pop ecx
|
||||
pop gs
|
||||
pop eax
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
CHANGEAL:
|
||||
;Entrance:void
|
||||
cmp al,09h
|
||||
jna .l2
|
||||
add al,37h
|
||||
jmp .end
|
||||
.l2:
|
||||
add al,30h
|
||||
.end:
|
||||
ret
|
||||
|
||||
DISPRETURN16:
|
||||
push eax
|
||||
push ds
|
||||
|
||||
mov ax,cs
|
||||
mov ds,ax
|
||||
mov eax,IO16_RETURN
|
||||
push eax
|
||||
call near DISPSTR16
|
||||
pop eax
|
||||
|
||||
pop ds
|
||||
pop eax
|
||||
ret
|
||||
|
||||
DISPSPACE16:
|
||||
push eax
|
||||
push ds
|
||||
|
||||
mov ax,cs
|
||||
mov ds,ax
|
||||
mov eax,IO16_SPACE
|
||||
push eax
|
||||
call near DISPSTR16
|
||||
pop eax
|
||||
|
||||
pop ds
|
||||
pop eax
|
||||
ret
|
||||
|
||||
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
;===================================================================32 BITS=============================================================
|
||||
DISPINTEAX32:
|
||||
;Entrance: push eax
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
push eax
|
||||
|
||||
mov eax,dword [ss:ebp+8]
|
||||
shr eax,24
|
||||
mov ah,0Fh
|
||||
push ax
|
||||
call near DISPINTAL32
|
||||
pop ax
|
||||
|
||||
mov eax,dword [ss:ebp+8]
|
||||
shr eax,16
|
||||
mov ah,0Fh
|
||||
push ax
|
||||
call near DISPINTAL32
|
||||
pop ax
|
||||
|
||||
mov eax,dword [ss:ebp+8]
|
||||
shr eax,8
|
||||
mov ah,0Fh
|
||||
push ax
|
||||
call near DISPINTAL32
|
||||
pop ax
|
||||
|
||||
mov eax,dword [ss:ebp+8]
|
||||
mov ah,0Fh
|
||||
push ax
|
||||
call near DISPINTAL32
|
||||
pop ax
|
||||
|
||||
pop eax
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
DISPSTR32:
|
||||
;Entrance: push offset
|
||||
;ds:offset = String
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
push esi
|
||||
push edi
|
||||
push eax
|
||||
push ebx
|
||||
push gs
|
||||
|
||||
mov ax,SLCT_GRAPH
|
||||
mov gs,ax
|
||||
mov esi,dword [ss:ebp+8]
|
||||
mov edi,dword [ds:GRAPHPOS_32]
|
||||
.loop1:
|
||||
mov al,byte [ds:esi]
|
||||
cmp al,0
|
||||
je .end
|
||||
cmp al,0Ah
|
||||
jne .loop2
|
||||
;let edi point to the next row
|
||||
;edi/(80*2) - every row:80 chars, each char takes 2 bytes.
|
||||
push eax
|
||||
mov eax,edi
|
||||
mov bl,160
|
||||
div bl
|
||||
;only keep the low 8 of eax(al,aka quotion)
|
||||
and eax, 0FFh
|
||||
inc eax
|
||||
;calculate the edi now
|
||||
mov bl,160
|
||||
mul bl
|
||||
mov edi,eax
|
||||
pop eax
|
||||
inc esi
|
||||
jmp .loop1
|
||||
.loop2:
|
||||
mov ah,0Fh
|
||||
mov word [gs:edi],ax
|
||||
add edi,2
|
||||
inc esi
|
||||
jmp .loop1
|
||||
.end:
|
||||
mov dword [ds:GRAPHPOS_32],edi
|
||||
|
||||
pop gs
|
||||
pop ebx
|
||||
pop eax
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
DISPINTAL32:
|
||||
;Entrance: push ax ,AH=ATTR, AL=Char
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
push eax
|
||||
push gs
|
||||
push ecx
|
||||
push edi
|
||||
push ebx
|
||||
|
||||
mov edi,dword [ds:GRAPHPOS_32]
|
||||
mov ax,SLCT_GRAPH
|
||||
mov gs,ax
|
||||
xor eax,eax
|
||||
mov ax, word [ss:ebp+8]
|
||||
mov bx,ax
|
||||
;keep high 4 bits of al
|
||||
and al,0F0H
|
||||
mov cl,4
|
||||
shr al,cl
|
||||
call near CHANGEAL
|
||||
mov word [gs:edi],ax
|
||||
add edi,2
|
||||
mov dword [ds:GRAPHPOS_32],edi
|
||||
;keep low 4 bits of al
|
||||
mov ax,bx
|
||||
and al,0Fh
|
||||
call near CHANGEAL
|
||||
mov ah,bh
|
||||
mov word [gs:edi],ax
|
||||
add edi,2
|
||||
mov dword [ds:GRAPHPOS_32],edi
|
||||
|
||||
pop ebx
|
||||
pop edi
|
||||
pop ecx
|
||||
pop gs
|
||||
pop eax
|
||||
pop ebp
|
||||
ret
|
||||
|
||||
|
||||
DISPRETURN32:
|
||||
push eax
|
||||
|
||||
mov eax,IO32_RETURN
|
||||
push eax
|
||||
call near DISPSTR32
|
||||
pop eax
|
||||
|
||||
pop eax
|
||||
ret
|
||||
|
||||
DISPSPACE32:
|
||||
push eax
|
||||
|
||||
mov eax,IO32_SPACE
|
||||
push eax
|
||||
call near DISPSTR32
|
||||
pop eax
|
||||
|
||||
pop eax
|
||||
ret
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
PAGINGINIT32:
|
||||
;must be called in 32-bits protected mode
|
||||
push eax
|
||||
push edx
|
||||
push ecx
|
||||
push ebx
|
||||
push edi
|
||||
push es
|
||||
|
||||
mov ax,SLCT_FLAT_RW
|
||||
mov es,ax
|
||||
|
||||
xor edx,edx
|
||||
mov eax,dword [ds:DISPMEMTOTAL_32]
|
||||
mov ebx,400000h
|
||||
div ebx
|
||||
mov ecx,eax
|
||||
cmp edx,0
|
||||
je .end
|
||||
inc ecx
|
||||
.end:
|
||||
push ecx
|
||||
;init all PDEs
|
||||
mov eax, PTEBASE | PG_P | PG_USU | PG_RWW
|
||||
mov edi, PDEBASE
|
||||
.loop1:
|
||||
mov dword [es:edi],eax
|
||||
add edi,4
|
||||
dec ecx
|
||||
add eax,4096
|
||||
cmp ecx,0
|
||||
jne .loop1
|
||||
;init all PTEs
|
||||
|
||||
pop eax
|
||||
mov ebx,1024
|
||||
mul ebx
|
||||
mov ecx,eax
|
||||
|
||||
mov eax, PG_P | PG_USU | PG_RWW
|
||||
xor edi,edi
|
||||
mov edi, PTEBASE
|
||||
.loop2:
|
||||
mov dword [es:edi],eax
|
||||
add edi,4
|
||||
add eax,4096
|
||||
dec ecx
|
||||
cmp ecx,0
|
||||
jne .loop2
|
||||
|
||||
mov eax, PDEBASE
|
||||
mov cr3, eax
|
||||
mov eax, cr0
|
||||
or eax, 80000000h
|
||||
mov cr0, eax
|
||||
jmp short .end2
|
||||
.end2:
|
||||
nop
|
||||
pop es
|
||||
pop edi
|
||||
pop ebx
|
||||
pop ecx
|
||||
pop edx
|
||||
pop eax
|
||||
ret
|
||||
|
||||
;void* MEMCPY32(void* Source;void* Destination;ULONG32 Size)
|
||||
MEMCPY32:
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
push esi
|
||||
push edi
|
||||
push ecx
|
||||
push eax
|
||||
|
||||
mov ax,SLCT_FLAT_RW
|
||||
mov es,ax
|
||||
mov esi,dword [ss:ebp+8]
|
||||
mov edi,dword [ss:ebp+12]
|
||||
mov ecx,dword [ss:ebp+16]
|
||||
|
||||
.loop:
|
||||
mov al,byte [es:esi]
|
||||
mov byte [ds:edi],al
|
||||
inc esi
|
||||
inc edi
|
||||
dec ecx
|
||||
cmp ecx,0
|
||||
je .end
|
||||
jmp .loop
|
||||
.end:
|
||||
pop eax
|
||||
pop ecx
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
ret
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
ASM = nasm
|
||||
CC = gcc
|
||||
LD = ld
|
||||
C_SRC_PATH = x86/src/c
|
||||
ASM_SRC_PATH = x86/src/asm
|
||||
OUTPUT_DIR = temp
|
||||
C_FLAGS_32 = -m32 -c -fno-builtin -masm=intel -Wall -Wextra
|
||||
ASM_FLAGS_32 = -f elf32 -I $(ASM_SRC_PATH)/
|
||||
LD_FLAGS_32 = -m elf_i386
|
||||
LD_SCRIPT = build/link.ld
|
||||
GRUB_CFG = build/grub.cfg
|
||||
|
||||
#C source code
|
||||
C_FILES = $(wildcard $(C_SRC_PATH)/*.c)
|
||||
|
||||
#ASM source code
|
||||
ASM_FILES = $(wildcard $(ASM_SRC_PATH)/*.asm)
|
||||
|
||||
#bin files
|
||||
KERNEL_BIN = $(OUTPUT_DIR)/kernel.bin
|
||||
|
||||
#Object files
|
||||
C_OBJ_FILES = $(addprefix $(OUTPUT_DIR)/,$(notdir $(C_FILES:.c=.oc)))
|
||||
ASM_OBJ_FILES = $(addprefix $(OUTPUT_DIR)/,$(notdir $(ASM_FILES:.asm=.oasm)))
|
||||
ALL_OBJ_FILES = $(C_OBJ_FILES) $(ASM_OBJ_FILES)
|
||||
|
||||
|
||||
all : init compile link buildiso clean
|
||||
|
||||
init:
|
||||
sudo mkdir $(OUTPUT_DIR)
|
||||
|
||||
compile: $(C_OBJ_FILES) $(ASM_OBJ_FILES)
|
||||
|
||||
link: $(KERNEL_BIN)
|
||||
|
||||
clean:
|
||||
sudo rm -rf $(OUTPUT_DIR)
|
||||
buildiso:
|
||||
sudo mkdir $(OUTPUT_DIR)/temp_iso
|
||||
sudo mkdir $(OUTPUT_DIR)/temp_iso/HOS
|
||||
sudo mkdir $(OUTPUT_DIR)/temp_iso/boot
|
||||
sudo mkdir $(OUTPUT_DIR)/temp_iso/boot/grub
|
||||
sudo mv $(KERNEL_BIN) $(OUTPUT_DIR)/temp_iso/HOS/kernel.bin
|
||||
sudo cp $(GRUB_CFG) $(OUTPUT_DIR)/temp_iso/boot/grub/
|
||||
sudo grub-mkrescue -o HOS.iso $(OUTPUT_DIR)/temp_iso
|
||||
|
||||
$(OUTPUT_DIR)/%.oc : $(C_SRC_PATH)/%.c
|
||||
sudo $(CC) $(C_FLAGS_32) -o $@ $^
|
||||
|
||||
$(OUTPUT_DIR)/%.oasm : $(ASM_SRC_PATH)/%.asm
|
||||
sudo $(ASM) $(ASM_FLAGS_32) -o $@ $^
|
||||
|
||||
$(KERNEL_BIN): $(ALL_OBJ_FILES)
|
||||
sudo $(LD) $(LD_FLAGS_32) -T $(LD_SCRIPT) -o $(KERNEL_BIN) $(ALL_OBJ_FILES)
|
16
makefile
16
makefile
|
@ -1,12 +1,12 @@
|
|||
ASM = nasm
|
||||
CC = gcc
|
||||
LD = ld
|
||||
C_SRC_PATH = x86/src/c
|
||||
ASM_SRC_PATH = x86/src/asm
|
||||
C_SRC_PATH = x64/src/c
|
||||
ASM_SRC_PATH = x64/src/asm
|
||||
OUTPUT_DIR = temp
|
||||
C_FLAGS_32 = -m32 -c -fno-builtin -masm=intel -Wall -Wextra
|
||||
ASM_FLAGS_32 = -f elf32 -I $(ASM_SRC_PATH)/
|
||||
LD_FLAGS_32 = -m elf_i386
|
||||
C_FLAGS = -m64 -c -fno-builtin -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -masm=intel -Wall -Wextra
|
||||
ASM_FLAGS = -f elf64 -I $(ASM_SRC_PATH)/
|
||||
LD_FLAGS = -melf_x86_64
|
||||
LD_SCRIPT = build/link.ld
|
||||
GRUB_CFG = build/grub.cfg
|
||||
|
||||
|
@ -46,10 +46,10 @@ buildiso:
|
|||
sudo grub-mkrescue -o HOS.iso $(OUTPUT_DIR)/temp_iso
|
||||
|
||||
$(OUTPUT_DIR)/%.oc : $(C_SRC_PATH)/%.c
|
||||
sudo $(CC) $(C_FLAGS_32) -o $@ $^
|
||||
sudo $(CC) $(C_FLAGS) -o $@ $^
|
||||
|
||||
$(OUTPUT_DIR)/%.oasm : $(ASM_SRC_PATH)/%.asm
|
||||
sudo $(ASM) $(ASM_FLAGS_32) -o $@ $^
|
||||
sudo $(ASM) $(ASM_FLAGS) -o $@ $^
|
||||
|
||||
$(KERNEL_BIN): $(ALL_OBJ_FILES)
|
||||
sudo $(LD) $(LD_FLAGS_32) -T $(LD_SCRIPT) -o $(KERNEL_BIN) $(ALL_OBJ_FILES)
|
||||
sudo $(LD) $(LD_FLAGS) -T $(LD_SCRIPT) -o $(KERNEL_BIN) $(ALL_OBJ_FILES)
|
||||
|
|
Loading…
Reference in New Issue