Rewrite modules with C

This commit is contained in:
Alex Kotov 2020-11-25 18:55:20 +05:00
parent a734782062
commit 878250df98
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
6 changed files with 52 additions and 44 deletions

View File

@ -6,13 +6,15 @@ CC = $(CCPREFIX)gcc
MEMGR = memgr
CFLAGS = -std=gnu99 -ffreestanding -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra
all: $(MEMGR)
clean:
rm -f $(MEMGR) main.o
rm -f $(MEMGR) start.o
$(MEMGR): main.o
$(MEMGR): start.o
$(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -lgcc $^
main.o: main.asm
nasm -f elf32 $< -o $@
start.o: start.c
$(CC) -c $< -o $@ $(CFLAGS)

View File

@ -1,6 +0,0 @@
[GLOBAL _start]
_start:
xor eax, eax
xor ebx, ebx
int 0x80

8
memgr/start.c Normal file
View File

@ -0,0 +1,8 @@
void _start()
{
asm(
"mov $0, %eax \n\t"
"mov $0, %ebx \n\t"
"int $0x80 \n\t"
);
}

View File

@ -6,13 +6,15 @@ CC = $(CCPREFIX)gcc
PROCMAN = procman
CFLAGS = -std=gnu99 -ffreestanding -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra
all: $(PROCMAN)
clean:
rm -f $(PROCMAN) main.o
rm -f $(PROCMAN) start.o
$(PROCMAN): main.o
$(PROCMAN): start.o
$(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -lgcc $^
main.o: main.asm
nasm -f elf32 $< -o $@
start.o: start.c
$(CC) -c $< -o $@ $(CFLAGS)

View File

@ -1,30 +0,0 @@
[GLOBAL _start]
_start:
xor eax, eax
xor ebx, ebx
int 0x80
xor eax, eax
mov ebx, 1
int 0x80
mov eax, 1
xor ebx, ebx
int 0x80
mov eax, 2
xor ebx, ebx
int 0x80
mov eax, 256
xor ebx, ebx
int 0x80
mov eax, 257
xor ebx, ebx
int 0x80
mov eax, 258
xor ebx, ebx
int 0x80

32
procman/start.c Normal file
View File

@ -0,0 +1,32 @@
void _start()
{
asm(
"mov $0, %eax \n\t"
"mov $0, %ebx \n\t"
"int $0x80 \n\t"
"mov $0, %eax \n\t"
"mov $1, %ebx \n\t"
"int $0x80 \n\t"
"mov $1, %eax \n\t"
"mov $0, %ebx \n\t"
"int $0x80 \n\t"
"mov $2, %eax \n\t"
"mov $0, %ebx \n\t"
"int $0x80 \n\t"
"mov $256, %eax \n\t"
"mov $0, %ebx \n\t"
"int $0x80 \n\t"
"mov $257, %eax \n\t"
"mov $0, %ebx \n\t"
"int $0x80 \n\t"
"mov $258, %eax \n\t"
"mov $0, %ebx \n\t"
"int $0x80 \n\t"
);
}