1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:37:36 +00:00

Make bash-2.05b build with minimal changes.

This is really neat. :^)
This commit is contained in:
Andreas Kling 2018-11-17 00:11:08 +01:00
parent 2cf477a151
commit 9d05f6b7a7
35 changed files with 326 additions and 176 deletions

View file

@ -3,13 +3,13 @@
namespace CMOS {
BYTE read(BYTE index)
byte read(byte index)
{
IO::out8(0x70, index);
return IO::in8(0x71);
}
void write(BYTE index, BYTE data)
void write(byte index, byte data)
{
IO::out8(0x70, index);
IO::out8(0x71, data);

View file

@ -4,7 +4,7 @@
namespace CMOS {
BYTE read(BYTE index);
void write(BYTE index, BYTE data);
byte read(byte index);
void write(byte index, byte data);
}

View file

@ -50,7 +50,7 @@ void Keyboard::emit(byte ch)
void Keyboard::handleIRQ()
{
while (IO::in8(0x64) & 1) {
BYTE ch = IO::in8(0x60);
byte ch = IO::in8(0x60);
switch (ch) {
case 0x38: m_modifiers |= Mod_Alt; break;
case 0xB8: m_modifiers &= ~Mod_Alt; break;

View file

@ -19,9 +19,9 @@ static bool initialized;
namespace PIC {
void disable(BYTE irq)
void disable(byte irq)
{
BYTE imr;
byte imr;
if (irq & 8) {
imr = IO::in8(PIC1_CMD);
imr |= 1 << (irq - 8);
@ -33,9 +33,9 @@ void disable(BYTE irq)
}
}
void enable(BYTE irq)
void enable(byte irq)
{
BYTE imr;
byte imr;
if (irq & 8) {
imr = IO::in8(PIC1_CMD);
imr &= ~(1 << (irq - 8));
@ -47,7 +47,7 @@ void enable(BYTE irq)
}
}
void eoi(BYTE irq)
void eoi(byte irq)
{
if (irq & 8)
IO::out8(PIC1_CTL, 0x20);

View file

@ -4,9 +4,9 @@
namespace PIC {
void enable(BYTE number);
void disable(BYTE number);
void eoi(BYTE number);
void enable(byte number);
void disable(byte number);
void eoi(byte number);
void initialize();
word getISR();
word get_irr();
@ -15,9 +15,9 @@ word get_irr();
class IRQHandlerScope {
public:
explicit IRQHandlerScope(BYTE irq) : m_irq(irq) { }
explicit IRQHandlerScope(byte irq) : m_irq(irq) { }
~IRQHandlerScope() { PIC::eoi(m_irq); }
private:
BYTE m_irq { 0 };
byte m_irq { 0 };
};

View file

@ -24,7 +24,7 @@
#define SIGNAL_DEBUG
#define MAX_PROCESS_GIDS 32
static const DWORD defaultStackSize = 16384;
static const dword defaultStackSize = 16384;
static pid_t next_pid;
InlineLinkedList<Process>* g_processes;
@ -663,7 +663,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
if (isRing3()) {
// Ring3 processes need a separate stack for Ring0.
m_kernelStack = kmalloc(defaultStackSize);
m_stackTop0 = ((DWORD)m_kernelStack + defaultStackSize) & 0xffffff8;
m_stackTop0 = ((dword)m_kernelStack + defaultStackSize) & 0xffffff8;
m_tss.ss0 = 0x10;
m_tss.esp0 = m_stackTop0;
}
@ -1414,7 +1414,7 @@ void Process::reap(Process& process)
pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
{
//kprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options);
dbgprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options);
// FIXME: Respect options
(void) options;
if (wstatus)
@ -1426,6 +1426,31 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
if (waitee != -1 && !Process::from_pid(waitee))
return -ECHILD;
}
if (options & WNOHANG) {
if (waitee == -1) {
pid_t reaped_pid = 0;
InterruptDisabler disabler;
for_each_child([&reaped_pid] (Process& process) {
if (process.state() == Dead) {
reaped_pid = process.pid();
reap(process);
}
return true;
});
return reaped_pid;
} else {
auto* waitee_process = Process::from_pid(waitee);
if (!waitee_process)
return -ECHILD;
if (waitee_process->state() == Dead) {
reap(*waitee_process);
return waitee;
}
return 0;
}
}
m_waitee = waitee;
m_waitee_status = 0;
block(BlockedWait);
@ -1470,7 +1495,7 @@ void block(Process::State state)
sched_yield();
}
void sleep(DWORD ticks)
void sleep(dword ticks)
{
ASSERT(current->state() == Process::Running);
current->setWakeupTime(system.uptime + ticks);

View file

@ -80,8 +80,8 @@ public:
pid_t pid() const { return m_pid; }
pid_t sid() const { return m_sid; }
pid_t pgid() const { return m_pgid; }
DWORD ticks() const { return m_ticks; }
WORD selector() const { return m_farPtr.selector; }
dword ticks() const { return m_ticks; }
word selector() const { return m_farPtr.selector; }
TSS32& tss() { return m_tss; }
State state() const { return m_state; }
uid_t uid() const { return m_uid; }
@ -98,8 +98,8 @@ public:
void block(Process::State);
void unblock();
void setWakeupTime(DWORD t) { m_wakeupTime = t; }
DWORD wakeupTime() const { return m_wakeupTime; }
void setWakeupTime(dword t) { m_wakeupTime = t; }
dword wakeupTime() const { return m_wakeupTime; }
template<typename Callback> static void for_each(Callback);
template<typename Callback> static void for_each_in_pgrp(pid_t, Callback);
@ -110,7 +110,7 @@ public:
bool tick() { ++m_ticks; return --m_ticksLeft; }
void set_ticks_left(dword t) { m_ticksLeft = t; }
void setSelector(WORD s) { m_farPtr.selector = s; }
void setSelector(word s) { m_farPtr.selector = s; }
void set_state(State s) { m_state = s; }
pid_t sys$setsid();
@ -244,13 +244,13 @@ private:
gid_t m_egid { 0 };
pid_t m_sid { 0 };
pid_t m_pgid { 0 };
DWORD m_ticks { 0 };
DWORD m_ticksLeft { 0 };
DWORD m_stackTop0 { 0 };
DWORD m_stackTop3 { 0 };
dword m_ticks { 0 };
dword m_ticksLeft { 0 };
dword m_stackTop0 { 0 };
dword m_stackTop3 { 0 };
FarPtr m_farPtr;
State m_state { Invalid };
DWORD m_wakeupTime { 0 };
dword m_wakeupTime { 0 };
TSS32 m_tss;
TSS32 m_tss_to_resume_kernel;
struct FileDescriptorAndFlags {
@ -358,7 +358,7 @@ static inline const char* toString(Process::State state)
}
extern void block(Process::State);
extern void sleep(DWORD ticks);
extern void sleep(dword ticks);
extern InlineLinkedList<Process>* g_processes;

View file

@ -5,10 +5,10 @@
extern "C" {
void memcpy(void *dest, const void *src, DWORD n)
void memcpy(void *dest, const void *src, dword n)
{
BYTE* bdest = (BYTE*)dest;
const BYTE* bsrc = (const BYTE*)src;
byte* bdest = (byte*)dest;
const byte* bsrc = (const byte*)src;
for (; n; --n)
*(bdest++) = *(bsrc++);
}
@ -18,9 +18,9 @@ void strcpy(char* dest, const char *src)
while ((*dest++ = *src++) != '\0');
}
void* memset(void* dest, BYTE c, DWORD n)
void* memset(void* dest, byte c, dword n)
{
BYTE *bdest = (BYTE *)dest;
byte *bdest = (byte *)dest;
for (; n; --n)
*(bdest++) = c;
return dest;
@ -37,9 +37,9 @@ char* strrchr(const char* str, int ch)
return last;
}
DWORD strlen(const char* str)
dword strlen(const char* str)
{
DWORD len = 0;
dword len = 0;
while (*(str++))
++len;
return len;
@ -51,12 +51,12 @@ int strcmp(const char *s1, const char *s2)
if (*s1 == 0)
return 0;
}
return *(const BYTE*)s1 < *(const BYTE*)s2 ? -1 : 1;
return *(const byte*)s1 < *(const byte*)s2 ? -1 : 1;
}
char* strdup(const char *str)
{
DWORD len = strlen(str);
dword len = strlen(str);
char *s = (char*)kmalloc(len);
memcpy(s, str, len);
return s;

View file

@ -4,11 +4,11 @@
extern "C" {
void memcpy(void*, const void*, DWORD);
void memcpy(void*, const void*, dword);
void strcpy(char*, const char*);
int strcmp(char const*, const char*);
DWORD strlen(const char*);
void *memset(void*, BYTE, DWORD);
dword strlen(const char*);
void *memset(void*, byte, dword);
char *strdup(const char*);
int memcmp(const void*, const void*, size_t);
char* strrchr(const char* str, int ch);

View file

@ -44,7 +44,7 @@ void initialize()
kprintf("syscall: int 0x80 handler installed\n");
}
static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2, dword arg3)
{
ASSERT_INTERRUPTS_ENABLED();
switch (function) {
@ -184,10 +184,10 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2,
void syscall_entry(RegisterDump& regs)
{
DWORD function = regs.eax;
DWORD arg1 = regs.edx;
DWORD arg2 = regs.ecx;
DWORD arg3 = regs.ebx;
dword function = regs.eax;
dword arg1 = regs.edx;
dword arg2 = regs.ecx;
dword arg3 = regs.ebx;
regs.eax = Syscall::handle(regs, function, arg1, arg2, arg3);
}

View file

@ -10,7 +10,7 @@
//#define PAGE_FAULT_DEBUG
struct DescriptorTablePointer {
WORD size;
word size;
void* address;
} PACKED;
@ -23,7 +23,7 @@ static IRQHandler** s_irqHandler;
static Vector<word, KmallocEternalAllocator>* s_gdt_freelist;
static WORD s_gdtLength;
static word s_gdtLength;
word gdt_alloc_entry()
{
@ -262,7 +262,7 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
static void _exception ## i () \
{ \
kprintf(msg"\n"); \
DWORD cr0, cr2, cr3, cr4; \
dword cr0, cr2, cr3, cr4; \
asm ("movl %%cr0, %%eax":"=a"(cr0)); \
asm ("movl %%cr2, %%eax":"=a"(cr2)); \
asm ("movl %%cr3, %%eax":"=a"(cr3)); \
@ -286,9 +286,9 @@ EH(12, "Stack exception")
EH(15, "Unknown error")
EH(16, "Coprocessor error")
static void writeRawGDTEntry(WORD selector, DWORD low, DWORD high)
static void writeRawGDTEntry(word selector, dword low, dword high)
{
WORD i = (selector & 0xfffc) >> 3;
word i = (selector & 0xfffc) >> 3;
s_gdt[i].low = low;
s_gdt[i].high = high;
@ -297,14 +297,14 @@ static void writeRawGDTEntry(WORD selector, DWORD low, DWORD high)
}
}
void writeGDTEntry(WORD selector, Descriptor& descriptor)
void writeGDTEntry(word selector, Descriptor& descriptor)
{
writeRawGDTEntry(selector, descriptor.low, descriptor.high);
}
Descriptor& getGDTEntry(WORD selector)
Descriptor& getGDTEntry(word selector)
{
WORD i = (selector & 0xfffc) >> 3;
word i = (selector & 0xfffc) >> 3;
return *(Descriptor*)(&s_gdt[i]);
}
@ -357,17 +357,17 @@ void unregisterIRQHandler(byte irq, IRQHandler& handler)
s_irqHandler[irq] = nullptr;
}
void registerInterruptHandler(BYTE index, void (*f)())
void registerInterruptHandler(byte index, void (*f)())
{
s_idt[index].low = 0x00080000 | LSW((f));
s_idt[index].high = ((DWORD)(f) & 0xffff0000) | 0x8e00;
s_idt[index].high = ((dword)(f) & 0xffff0000) | 0x8e00;
flushIDT();
}
void registerUserCallableInterruptHandler(BYTE index, void (*f)())
void registerUserCallableInterruptHandler(byte index, void (*f)())
{
s_idt[index].low = 0x00080000 | LSW((f));
s_idt[index].high = ((DWORD)(f) & 0xffff0000) | 0xef00;
s_idt[index].high = ((dword)(f) & 0xffff0000) | 0xef00;
flushIDT();
}
@ -395,7 +395,7 @@ void idt_init()
s_idtr.address = s_idt;
s_idtr.size = 0x100 * 8;
for (BYTE i = 0xff; i > 0x10; --i)
for (byte i = 0xff; i > 0x10; --i)
registerInterruptHandler(i, unimp_trap);
registerInterruptHandler(0x00, _exception0);
@ -426,14 +426,14 @@ void idt_init()
flushIDT();
}
void load_task_register(WORD selector)
void load_task_register(word selector)
{
asm("ltr %0"::"r"(selector));
}
void handle_irq()
{
WORD isr = PIC::getISR();
word isr = PIC::getISR();
if (!isr) {
kprintf("Spurious IRQ\n");
return;

View file

@ -8,23 +8,23 @@
union Descriptor {
struct {
WORD limit_lo;
WORD base_lo;
BYTE base_hi;
BYTE type : 4;
BYTE descriptor_type : 1;
BYTE dpl : 2;
BYTE segment_present : 1;
BYTE limit_hi : 4;
BYTE : 1;
BYTE zero : 1;
BYTE operation_size : 1;
BYTE granularity : 1;
BYTE base_hi2;
word limit_lo;
word base_lo;
byte base_hi;
byte type : 4;
byte descriptor_type : 1;
byte dpl : 2;
byte segment_present : 1;
byte limit_hi : 4;
byte : 1;
byte zero : 1;
byte operation_size : 1;
byte granularity : 1;
byte base_hi2;
};
struct {
DWORD low;
DWORD high;
dword low;
dword high;
};
enum Type {
@ -45,15 +45,15 @@ union Descriptor {
void setBase(void* b)
{
base_lo = (DWORD)(b) & 0xffff;
base_hi = ((DWORD)(b) >> 16) & 0xff;
base_hi2 = ((DWORD)(b) >> 24) & 0xff;
base_lo = (dword)(b) & 0xffff;
base_hi = ((dword)(b) >> 16) & 0xff;
base_hi2 = ((dword)(b) >> 24) & 0xff;
}
void setLimit(DWORD l)
void setLimit(dword l)
{
limit_lo = (DWORD)l & 0xffff;
limit_hi = ((DWORD)l >> 16) & 0xff;
limit_lo = (dword)l & 0xffff;
limit_hi = ((dword)l >> 16) & 0xff;
}
} PACKED;
@ -61,21 +61,21 @@ class IRQHandler;
void gdt_init();
void idt_init();
void registerInterruptHandler(BYTE number, void (*f)());
void registerUserCallableInterruptHandler(BYTE number, void (*f)());
void registerIRQHandler(BYTE number, IRQHandler&);
void unregisterIRQHandler(BYTE number, IRQHandler&);
void registerInterruptHandler(byte number, void (*f)());
void registerUserCallableInterruptHandler(byte number, void (*f)());
void registerIRQHandler(byte number, IRQHandler&);
void unregisterIRQHandler(byte number, IRQHandler&);
void flushIDT();
void flushGDT();
void load_task_register(WORD selector);
void load_task_register(word selector);
word gdt_alloc_entry();
void gdt_free_entry(word);
Descriptor& getGDTEntry(WORD selector);
void writeGDTEntry(WORD selector, Descriptor&);
Descriptor& getGDTEntry(word selector);
void writeGDTEntry(word selector, Descriptor&);
#define HANG asm volatile( "cli; hlt" );
#define LSW(x) ((DWORD)(x) & 0xFFFF)
#define MSW(x) (((DWORD)(x) >> 16) & 0xFFFF)
#define LSW(x) ((dword)(x) & 0xFFFF)
#define MSW(x) (((dword)(x) >> 16) & 0xFFFF)
#define LSB(x) ((x) & 0xFF)
#define MSB(x) (((x)>>8) & 0xFF)
@ -156,49 +156,49 @@ private:
};
struct RegisterDump {
WORD ss;
WORD gs;
WORD fs;
WORD es;
WORD ds;
DWORD edi;
DWORD esi;
DWORD ebp;
DWORD esp;
DWORD ebx;
DWORD edx;
DWORD ecx;
DWORD eax;
DWORD eip;
WORD cs;
WORD __csPadding;
DWORD eflags;
DWORD esp_if_crossRing;
WORD ss_if_crossRing;
word ss;
word gs;
word fs;
word es;
word ds;
dword edi;
dword esi;
dword ebp;
dword esp;
dword ebx;
dword edx;
dword ecx;
dword eax;
dword eip;
word cs;
word __csPadding;
dword eflags;
dword esp_if_crossRing;
word ss_if_crossRing;
} PACKED;
struct RegisterDumpWithExceptionCode {
WORD ss;
WORD gs;
WORD fs;
WORD es;
WORD ds;
DWORD edi;
DWORD esi;
DWORD ebp;
DWORD esp;
DWORD ebx;
DWORD edx;
DWORD ecx;
DWORD eax;
WORD exception_code;
WORD __exception_code_padding;
DWORD eip;
WORD cs;
WORD __csPadding;
DWORD eflags;
DWORD esp_if_crossRing;
WORD ss_if_crossRing;
word ss;
word gs;
word fs;
word es;
word ds;
dword edi;
dword esi;
dword ebp;
dword esp;
dword ebx;
dword edx;
dword ecx;
dword eax;
word exception_code;
word __exception_code_padding;
dword eip;
word cs;
word __csPadding;
dword eflags;
dword esp_if_crossRing;
word ss_if_crossRing;
} PACKED;
inline constexpr dword pageBaseOf(dword address)

View file

@ -53,7 +53,7 @@ asm(
#define MODE_RATE 0x04
#define MODE_SQUARE_WAVE 0x06
#define WRITE_WORD 0x30
#define WRITE_word 0x30
/* Miscellaneous */
#define BASE_FREQUENCY 1193182
@ -68,9 +68,9 @@ namespace PIT {
void initialize()
{
WORD timer_reload;
word timer_reload;
IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_WORD | MODE_SQUARE_WAVE);
IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_word | MODE_SQUARE_WAVE);
timer_reload = (BASE_FREQUENCY / TICKS_PER_SECOND);

View file

@ -274,8 +274,8 @@ void init()
memset(&system, 0, sizeof(system));
WORD base_memory = (CMOS::read(0x16) << 8) | CMOS::read(0x15);
WORD ext_memory = (CMOS::read(0x18) << 8) | CMOS::read(0x17);
word base_memory = (CMOS::read(0x16) << 8) | CMOS::read(0x15);
word ext_memory = (CMOS::read(0x18) << 8) | CMOS::read(0x17);
kprintf("%u kB base memory\n", base_memory);
kprintf("%u kB extended memory\n", ext_memory);

View file

@ -14,8 +14,8 @@
typedef struct
{
DWORD start;
DWORD nchunk;
dword start;
dword nchunk;
} PACKED allocation_t;
#define CHUNK_SIZE 128
@ -29,8 +29,8 @@ typedef struct
static byte alloc_map[POOL_SIZE / CHUNK_SIZE / 8];
volatile DWORD sum_alloc = 0;
volatile DWORD sum_free = POOL_SIZE;
volatile dword sum_alloc = 0;
volatile dword sum_free = POOL_SIZE;
volatile size_t kmalloc_sum_eternal = 0;
volatile size_t kmalloc_sum_page_aligned = 0;
@ -90,9 +90,9 @@ void* kmalloc(dword size)
{
InterruptDisabler disabler;
DWORD chunks_needed, chunks_here, first_chunk;
DWORD real_size;
DWORD i, j, k;
dword chunks_needed, chunks_here, first_chunk;
dword real_size;
dword i, j, k;
/* We need space for the allocation_t structure at the head of the block. */
real_size = size + sizeof(allocation_t);
@ -133,7 +133,7 @@ void* kmalloc(dword size)
if( chunks_here == chunks_needed )
{
auto* a = (allocation_t *)(BASE_PHYS + (first_chunk * CHUNK_SIZE));
BYTE *ptr = (BYTE *)a;
byte *ptr = (byte *)a;
ptr += sizeof(allocation_t);
a->nchunk = chunks_needed;
a->start = first_chunk;
@ -172,16 +172,16 @@ void kfree(void *ptr)
InterruptDisabler disabler;
allocation_t *a = (allocation_t *)((((BYTE *)ptr) - sizeof(allocation_t)));
allocation_t *a = (allocation_t *)((((byte *)ptr) - sizeof(allocation_t)));
#if 0
DWORD hdr = (DWORD)a;
DWORD mhdr = hdr & ~0x7;
dword hdr = (dword)a;
dword mhdr = hdr & ~0x7;
kprintf("hdr / mhdr %p / %p\n", hdr, mhdr);
ASSERT(hdr == mhdr);
#endif
for (DWORD k = a->start; k < (a->start + a->nchunk); ++k) {
for (dword k = a->start; k < (a->start + a->nchunk); ++k) {
alloc_map[k / 8] &= ~(1 << (k % 8));
}

View file

@ -1,15 +1,15 @@
#pragma once
void kmalloc_init();
void *kmalloc(DWORD size) __attribute__ ((malloc));
void *kmalloc(dword size) __attribute__ ((malloc));
void* kmalloc_eternal(size_t) __attribute__ ((malloc));
void* kmalloc_page_aligned(size_t) __attribute__ ((malloc));
void kfree(void*);
bool is_kmalloc_address(void*);
extern volatile DWORD sum_alloc;
extern volatile DWORD sum_free;
extern volatile dword sum_alloc;
extern volatile dword sum_free;
extern volatile dword kmalloc_sum_eternal;
extern volatile dword kmalloc_sum_page_aligned;

View file

@ -6,5 +6,5 @@ cp ../../figlet-2.2.5/fonts/big.flf mnt/$FIGLET_FONTDIR
cp ../../figlet-2.2.5/fonts/slant.flf mnt/$FIGLET_FONTDIR
cp ../../figlet-2.2.5/fonts/lean.flf mnt/$FIGLET_FONTDIR
cp ../../bash-1.14.7/bash2 mnt/bin/bash
cp ../../bash-2.05b/bash mnt/bin/bash

View file

@ -15,8 +15,8 @@ const KSym* ksymbolicate(dword address) PURE;
struct system_t
{
time_t uptime;
DWORD nprocess;
DWORD nblocked;
dword nprocess;
dword nblocked;
};
extern system_t system;

View file

@ -6,22 +6,18 @@
#define PACKED __attribute__ ((packed))
#define PURE __attribute__ ((pure))
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef DWORD __u32;
typedef WORD __u16;
typedef BYTE __u8;
typedef dword __u32;
typedef word __u16;
typedef byte __u8;
typedef int __s32;
typedef short __s16;
typedef DWORD uid_t;
typedef DWORD gid_t;
typedef dword uid_t;
typedef dword gid_t;
typedef int pid_t;
typedef DWORD time_t;
typedef DWORD suseconds_t;
typedef DWORD size_t;
typedef dword time_t;
typedef dword suseconds_t;
typedef dword size_t;
struct timeval {
time_t tv_sec;
@ -50,8 +46,8 @@ typedef dword time_t;
typedef dword suseconds_t;
struct FarPtr {
DWORD offset { 0 };
WORD selector { 0 };
dword offset { 0 };
word selector { 0 };
} PACKED;
class PhysicalAddress {