From ca131c71e82bd70c2b52bacb1ba6eb27a2c33d1d Mon Sep 17 00:00:00 2001 From: Xnoe Date: Wed, 8 Dec 2021 18:48:24 +0000 Subject: [PATCH] Updated hello.c to print the program's PID. Add getPID syscall. --- src/common/common.c | 4 ++++ src/common/common.h | 2 ++ src/program/hello.c | 11 ++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/common/common.c b/src/common/common.c index 28dcfae..bc9b182 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -28,6 +28,10 @@ uint32_t filesize(char* filename) { asm volatile ("mov $6, %%eax; mov %0, %%esi; int $0x7f" : : "m" (filename) : "esi"); } +uint32_t getPID() { + asm volatile ("mov $8, %%eax; int $0x7f" : : :); +} + int int_to_decimal(unsigned int number, char* string_buffer) { for (int i=0; i<11; i++) string_buffer[i] = 0; diff --git a/src/common/common.h b/src/common/common.h index bde0021..b71bb0c 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -11,6 +11,8 @@ void* localalloc(uint32_t size); void localdelete(void* ptr); uint32_t filesize(char* filename); +uint32_t getPID(); + int int_to_decimal(unsigned int number, char* string_buffer); int int_to_hex(unsigned int number, char* string_buffer); diff --git a/src/program/hello.c b/src/program/hello.c index 3dbaccb..717a8aa 100644 --- a/src/program/hello.c +++ b/src/program/hello.c @@ -1,7 +1,16 @@ #include "../common/common.h" int main() { + uint32_t counter = 0; + uint32_t PID = getPID(); + char intbuffer[32]; + uint32_t index = int_to_decimal(PID, intbuffer); while (1) { - // print("Hello"); + counter++; + if (counter == 312500) { + print(intbuffer+index); + print(" "); + counter = 0; + } } } \ No newline at end of file